hmm I doubt the usefulness of storing this information...
authorAnselm R. Garbe <garbeam@gmail.com>
Sat, 18 Aug 2007 14:20:56 +0200
changeset 964 777a9d9ce70b
parent 963 7416c26a14db
child 965 b3f4b0b3a5d7
hmm I doubt the usefulness of storing this information...
client.c
config.mk
dwm.h
layout.c
main.c
tag.c
--- a/client.c	Sat Aug 18 13:48:05 2007 +0200
+++ b/client.c	Sat Aug 18 14:20:56 2007 +0200
@@ -7,7 +7,7 @@
 
 /* static */
 
-static char config[128];
+static char prop[128];
 
 static void
 attachstack(Client *c) {
@@ -182,23 +182,23 @@
 }
 
 Bool
-loadconfig(Client *c) {
+loadprops(Client *c) {
 	unsigned int i;
 	Bool result = False;
 	XTextProperty name;
 
 	/* check if window has set a property */
 	name.nitems = 0;
-	XGetTextProperty(dpy, c->win, &name, dwmconfig);
+	XGetTextProperty(dpy, c->win, &name, dwmprops);
 	if(name.nitems && name.encoding == XA_STRING) {
-		strncpy(config, (char *)name.value, sizeof config - 1);
-		config[sizeof config - 1] = '\0';
+		strncpy(prop, (char *)name.value, sizeof prop - 1);
+		prop[sizeof prop - 1] = '\0';
 		XFree(name.value);
-		for(i = 0; i < ntags && i < sizeof config - 1 && config[i] != '\0'; i++)
-			if((c->tags[i] = config[i] == '1'))
+		for(i = 0; i < ntags && i < sizeof prop - 1 && prop[i] != '\0'; i++)
+			if((c->tags[i] = prop[i] == '1'))
 				result = True;
-		if(i < sizeof config - 1 && config[i] != '\0')
-			c->isfloating = config[i] == '1';
+		if(i < sizeof prop - 1 && prop[i] != '\0')
+			c->isfloating = prop[i] == '1';
 	}
 	return result;
 }
@@ -249,11 +249,11 @@
 	if(t)
 		for(i = 0; i < ntags; i++)
 			c->tags[i] = t->tags[i];
-	if(!loadconfig(c))
+	if(!loadprops(c))
 		applyrules(c);
 	if(!c->isfloating)
 		c->isfloating = (rettrans == Success) || c->isfixed;
-	saveconfig(c);
+	saveprops(c);
 	attach(c);
 	attachstack(c);
 	XMoveResizeWindow(dpy, c->win, c->x, c->y, c->w, c->h); /* some windows require this */
@@ -325,16 +325,16 @@
 }
 
 void
-saveconfig(Client *c) {
+saveprops(Client *c) {
 	unsigned int i;
 
-	for(i = 0; i < ntags && i < sizeof config - 1; i++)
-		config[i] = c->tags[i] ? '1' : '0';
-	if(i < sizeof config - 1)
-		config[i++] = c->isfloating ? '1' : '0';
-	config[i] = '\0';
-	XChangeProperty(dpy, c->win, dwmconfig, XA_STRING, 8,
-			PropModeReplace, (unsigned char *)config, i);
+	for(i = 0; i < ntags && i < sizeof prop - 1; i++)
+		prop[i] = c->tags[i] ? '1' : '0';
+	if(i < sizeof prop - 1)
+		prop[i++] = c->isfloating ? '1' : '0';
+	prop[i] = '\0';
+	XChangeProperty(dpy, c->win, dwmprops, XA_STRING, 8,
+			PropModeReplace, (unsigned char *)prop, i);
 }
 
 void
--- a/config.mk	Sat Aug 18 13:48:05 2007 +0200
+++ b/config.mk	Sat Aug 18 14:20:56 2007 +0200
@@ -20,8 +20,8 @@
 # flags
 CFLAGS = -Os ${INCS} -DVERSION=\"${VERSION}\"
 LDFLAGS = -s ${LIBS}
-#CFLAGS = -g -Wall -O2 ${INCS} -DVERSION=\"${VERSION}\"
-#LDFLAGS = -g ${LIBS}
+CFLAGS = -g -Wall -O2 ${INCS} -DVERSION=\"${VERSION}\"
+LDFLAGS = -g ${LIBS}
 
 # Solaris
 #CFLAGS = -fast ${INCS} -DVERSION=\"${VERSION}\"
--- a/dwm.h	Sat Aug 18 13:48:05 2007 +0200
+++ b/dwm.h	Sat Aug 18 14:20:56 2007 +0200
@@ -81,7 +81,7 @@
 extern unsigned int bh, blw, bpos;		/* bar height, bar layout label width, bar position */
 extern unsigned int ntags, numlockmask;		/* number of tags, numlock mask */
 extern void (*handler[LASTEvent])(XEvent *);	/* event handler */
-extern Atom dwmconfig, wmatom[WMLast], netatom[NetLast];
+extern Atom dwmprops, wmatom[WMLast], netatom[NetLast];
 extern Bool selscreen, *seltags;		/* seltags is array of Bool */
 extern Client *clients, *sel, *stack;		/* global client list and stack */
 extern Cursor cursor[CurLast];
@@ -96,11 +96,11 @@
 void detach(Client *c);			/* detaches c from global client list */
 void focus(Client *c);			/* focus c if visible && !NULL, or focus top visible */
 void killclient(const char *arg);	/* kill sel  nicely */
-Bool loadconfig(Client *c);		/* loads client properties */
+Bool loadprops(Client *c);		/* loads client properties */
 void manage(Window w, XWindowAttributes *wa);	/* manage new client */
 void resize(Client *c, int x, int y,
 		int w, int h, Bool sizehints);	/* resize with given coordinates c*/
-void saveconfig(Client *c);		/* saves client properties */
+void saveprops(Client *c);		/* saves client properties */
 void unban(Client *c);			/* unbans c */
 void unmanage(Client *c, long state);	/* unmanage c */
 void updatesizehints(Client *c);	/* update the size hint variables of c */
@@ -122,8 +122,10 @@
 Bool isfloating(void);			/* returns True if floating layout is enabled */
 Bool isarrange(void (*func)());		/* returns True if func is the layout function in use */
 void initlayouts(void);			/* initialize layout array */
+void loaddwmprops(void);		/* loads dwm properties */
 Client *nexttiled(Client *c);		/* returns tiled successor of c */
 void restack(void);			/* restores z layers of all clients */
+void savedwmprops(void);		/* saves dwm properties */
 void setlayout(const char *arg);	/* sets layout, NULL means next layout */
 void togglebar(const char *arg);	/* shows/hides the bar */
 void togglemax(const char *arg);	/* toggles maximization of floating client */
--- a/layout.c	Sat Aug 18 13:48:05 2007 +0200
+++ b/layout.c	Sat Aug 18 14:20:56 2007 +0200
@@ -1,6 +1,9 @@
 /* See LICENSE file for copyright and license details. */
 #include "dwm.h"
 #include <stdlib.h>
+#include <string.h>
+#include <X11/Xatom.h>
+#include <X11/Xutil.h>
 
 /* static */
 
@@ -10,6 +13,7 @@
 } Layout;
 
 unsigned int blw = 0;
+static char prop[128];
 static unsigned int ltidx = 0; /* default */
 
 static void
@@ -103,6 +107,28 @@
 	}
 }
 
+void
+loaddwmprops(void) {
+	unsigned int i;
+	XTextProperty name;
+
+	/* check if window has set a property */
+	name.nitems = 0;
+	XGetTextProperty(dpy, root, &name, dwmprops);
+	if(name.nitems && name.encoding == XA_STRING) {
+		strncpy(prop, (char *)name.value, sizeof prop - 1);
+		prop[sizeof prop - 1] = '\0';
+		XFree(name.value);
+		for(i = 0; i < ntags && i < sizeof prop - 1 && prop[i] != '\0'; i++)
+			seltags[i] = prop[i] == '1';
+		if(i < sizeof prop - 1 && prop[i] != '\0') {
+			i = prop[i] - '0';
+			if(i < nlayouts)
+				ltidx = i;
+		}
+	}
+}
+
 Client *
 nexttiled(Client *c) {
 	for(; c && (c->isfloating || !isvisible(c)); c = c->next);
@@ -139,6 +165,19 @@
 }
 
 void
+savedwmprops(void) {
+	unsigned int i;
+
+	for(i = 0; i < ntags && i < sizeof prop - 1; i++)
+		prop[i] = seltags[i] ? '1' : '0';
+	if(i < sizeof prop - 1)
+		prop[i++] = (char)ltidx;
+	prop[i] = '\0';
+	XChangeProperty(dpy, root, dwmprops, XA_STRING, 8,
+			PropModeReplace, (unsigned char *)prop, i);
+}
+
+void
 setlayout(const char *arg) {
 	int i;
 
@@ -156,6 +195,7 @@
 		arrange();
 	else
 		drawstatus();
+	savedwmprops();
 }
 
 void
--- a/main.c	Sat Aug 18 13:48:05 2007 +0200
+++ b/main.c	Sat Aug 18 14:20:56 2007 +0200
@@ -20,7 +20,7 @@
 unsigned int bh, ntags;
 unsigned int bpos = BARPOS;
 unsigned int numlockmask = 0;
-Atom dwmconfig, wmatom[WMLast], netatom[NetLast];
+Atom dwmprops, wmatom[WMLast], netatom[NetLast];
 Bool *seltags;
 Bool selscreen = True;
 Client *clients = NULL;
@@ -140,7 +140,7 @@
 	XSetWindowAttributes wa;
 
 	/* init atoms */
-	dwmconfig = XInternAtom(dpy, "_DWM_CONFIG", False);
+	dwmprops = XInternAtom(dpy, "_DWM_PROPERTIES", False);
 	wmatom[WMProtocols] = XInternAtom(dpy, "WM_PROTOCOLS", False);
 	wmatom[WMDelete] = XInternAtom(dpy, "WM_DELETE_WINDOW", False);
 	wmatom[WMState] = XInternAtom(dpy, "WM_STATE", False);
@@ -205,6 +205,7 @@
 		XSetFont(dpy, dc.gc, dc.font.xfont->fid);
 	/* multihead support */
 	selscreen = XQueryPointer(dpy, root, &w, &w, &i, &i, &i, &i, &mask);
+	loaddwmprops();
 }
 
 /*
--- a/tag.c	Sat Aug 18 13:48:05 2007 +0200
+++ b/tag.c	Sat Aug 18 14:20:56 2007 +0200
@@ -3,8 +3,6 @@
 #include <regex.h>
 #include <stdio.h>
 #include <stdlib.h>
-#include <string.h>
-#include <X11/Xatom.h>
 #include <X11/Xutil.h>
 
 /* static */
@@ -118,7 +116,7 @@
 	i = idxoftag(arg);
 	if(i >= 0 && i < ntags)
 		sel->tags[i] = True;
-	saveconfig(sel);
+	saveprops(sel);
 	arrange();
 }
 
@@ -129,7 +127,7 @@
 	sel->isfloating = !sel->isfloating;
 	if(sel->isfloating) {
 		resize(sel, sel->x, sel->y, sel->w, sel->h, True);
-		saveconfig(sel);
+		saveprops(sel);
 	}
 	arrange();
 }
@@ -145,7 +143,7 @@
 	for(j = 0; j < ntags && !sel->tags[j]; j++);
 	if(j == ntags)
 		sel->tags[i] = True;
-	saveconfig(sel);
+	saveprops(sel);
 	arrange();
 }
 
@@ -158,6 +156,7 @@
 	for(j = 0; j < ntags && !seltags[j]; j++);
 	if(j == ntags)
 		seltags[i] = True; /* cannot toggle last view */
+	savedwmprops();
 	arrange();
 }
 
@@ -170,5 +169,6 @@
 	i = idxoftag(arg);
 	if(i >= 0 && i < ntags)
 		seltags[i] = True;
+	savedwmprops();
 	arrange();
 }