On Sat, Feb 7, 2009 at 11:41 PM, Marcin Cieslak <[email protected]> wrote:
> David Tweed wrote:
>>> I think that authors unnecessarily assume that software components are
>>> "black boxes" that need to be kept up at all costs. This is not the right
>>
>> My reading was more to try and avoid the usual software development
>> "tendency" that developers really don't like to think about things
>> going wrong, so they spend time on code that feels "positive" like
>> save routines, etc, and do as little stress testing of things as they
>> can, and certainly with no regard to the users data when a programming
>> error manifests.
>
> To bring the thread back on-topic - I usually restart dwm (after
> configuration change or upgrade) by killing the dwm process and
> restarting my 'while...' loop in the xterm that's left open
> (my X server does not die after this).
>
> The only slight problem that all windows get tagged in the tag 1
> after restart, since dwm has no clue what was the previous tag
> assignement. How this internal dwm 'state' could be passed over
> to the new instance?
>
> --
>              << Marcin Cieslak // [email protected] >>

Here is what I use. Note that it only saves the tags, all the other
stuff like client order still gets reset.

Simon
diff -r 85a78d8afa0f dwm.c
--- a/dwm.c	Sun Feb 08 12:11:22 2009 +0000
+++ b/dwm.c	Thu Feb 26 02:26:08 2009 -0500
@@ -60,6 +60,7 @@ enum { ColBorder, ColFG, ColBG, ColLast 
 enum { ColBorder, ColFG, ColBG, ColLast };              /* color */
 enum { NetSupported, NetWMName, NetLast };              /* EWMH atoms */
 enum { WMProtocols, WMDelete, WMState, WMLast };        /* default atoms */
+enum { DWMTags, DWMLast };                              /* DWM atoms */
 enum { ClkTagBar, ClkLtSymbol, ClkStatusText, ClkWinTitle,
        ClkClientWin, ClkRootWin, ClkLast };             /* clicks */
 
@@ -178,6 +179,7 @@ static void setclientstate(Client *c, lo
 static void setclientstate(Client *c, long state);
 static void setlayout(const Arg *arg);
 static void setmfact(const Arg *arg);
+static void settagsprop(Window w, unsigned int tags);
 static void setup(void);
 static void showhide(Client *c, unsigned int ntiled);
 static void sigchld(int signal);
@@ -227,7 +229,7 @@ static void (*handler[LASTEvent]) (XEven
 	[PropertyNotify] = propertynotify,
 	[UnmapNotify] = unmapnotify
 };
-static Atom wmatom[WMLast], netatom[NetLast];
+static Atom wmatom[WMLast], netatom[NetLast], dwmatom[DWMLast];
 static Bool otherwm;
 static Bool running = True;
 static Client *clients = NULL;
@@ -897,12 +899,20 @@ manage(Window w, XWindowAttributes *wa) 
 	XSelectInput(dpy, w, EnterWindowMask|FocusChangeMask|PropertyChangeMask|StructureNotifyMask);
 	grabbuttons(c, False);
 	updatetitle(c);
-	if(XGetTransientForHint(dpy, w, &trans))
-		t = getclient(trans);
-	if(t)
-		c->tags = t->tags;
-	else
-		applyrules(c);
+	XTextProperty prop;
+	applyrules(c);
+	if(XGetTextProperty(dpy, c->win, &prop, dwmatom[DWMTags])) {
+		c->tags = *(unsigned int *)prop.value;
+		XFree(prop.value);
+	} else {
+		if(XGetTransientForHint(dpy, w, &trans))
+			t = getclient(trans);
+		if(t)
+			c->tags = t->tags;
+	}
+	if(!c->tags)
+		c->tags = tagset[seltags];
+	settagsprop(c->win, c->tags);
 	if(!c->isfloating)
 		c->isfloating = trans != None || c->isfixed;
 	if(c->isfloating)
@@ -1244,6 +1254,17 @@ setclientstate(Client *c, long state) {
 }
 
 void
+settagsprop(Window w, unsigned int tags) {
+	unsigned int v[1] = { tags };
+	XTextProperty p;
+	p.value = (unsigned char *)v;
+	p.encoding = XA_CARDINAL;
+	p.format = 32;
+	p.nitems = LENGTH(v);
+	XSetTextProperty(dpy, w, &p, dwmatom[DWMTags]);
+}
+
+void
 setlayout(const Arg *arg) {
 	if(!arg || !arg->v || arg->v != lt[sellt])
 		sellt ^= 1;
@@ -1294,6 +1315,7 @@ setup(void) {
 	wmatom[WMState] = XInternAtom(dpy, "WM_STATE", False);
 	netatom[NetSupported] = XInternAtom(dpy, "_NET_SUPPORTED", False);
 	netatom[NetWMName] = XInternAtom(dpy, "_NET_WM_NAME", False);
+	dwmatom[DWMTags] = XInternAtom(dpy, "DWM_TAGS", False);
 
 	/* init cursors */
 	wa.cursor = cursor[CurNormal] = XCreateFontCursor(dpy, XC_left_ptr);
@@ -1386,6 +1408,7 @@ tag(const Arg *arg) {
 tag(const Arg *arg) {
 	if(sel && arg->ui & TAGMASK) {
 		sel->tags = arg->ui & TAGMASK;
+		settagsprop(sel->win, sel->tags);
 		arrange();
 	}
 }
@@ -1465,6 +1488,7 @@ toggletag(const Arg *arg) {
 	mask = sel->tags ^ (arg->ui & TAGMASK);
 	if(sel && mask) {
 		sel->tags = mask;
+		settagsprop(sel->win, sel->tags);
 		arrange();
 	}
 }

Reply via email to