hmm I doubt the usefulness of storing this information... 0c606204
Anselm R. Garbe · 2007-08-18 14:20 6 file(s) · +74 −31
client.c +19 −19
7 7
8 8
/* static */
9 9
10 -
static char config[128];
10 +
static char prop[128];
11 11
12 12
static void
13 13
attachstack(Client *c) {
182 182
}
183 183
184 184
Bool
185 -
loadconfig(Client *c) {
185 +
loadprops(Client *c) {
186 186
	unsigned int i;
187 187
	Bool result = False;
188 188
	XTextProperty name;
189 189
190 190
	/* check if window has set a property */
191 191
	name.nitems = 0;
192 -
	XGetTextProperty(dpy, c->win, &name, dwmconfig);
192 +
	XGetTextProperty(dpy, c->win, &name, dwmprops);
193 193
	if(name.nitems && name.encoding == XA_STRING) {
194 -
		strncpy(config, (char *)name.value, sizeof config - 1);
195 -
		config[sizeof config - 1] = '\0';
194 +
		strncpy(prop, (char *)name.value, sizeof prop - 1);
195 +
		prop[sizeof prop - 1] = '\0';
196 196
		XFree(name.value);
197 -
		for(i = 0; i < ntags && i < sizeof config - 1 && config[i] != '\0'; i++)
198 -
			if((c->tags[i] = config[i] == '1'))
197 +
		for(i = 0; i < ntags && i < sizeof prop - 1 && prop[i] != '\0'; i++)
198 +
			if((c->tags[i] = prop[i] == '1'))
199 199
				result = True;
200 -
		if(i < sizeof config - 1 && config[i] != '\0')
201 -
			c->isfloating = config[i] == '1';
200 +
		if(i < sizeof prop - 1 && prop[i] != '\0')
201 +
			c->isfloating = prop[i] == '1';
202 202
	}
203 203
	return result;
204 204
}
249 249
	if(t)
250 250
		for(i = 0; i < ntags; i++)
251 251
			c->tags[i] = t->tags[i];
252 -
	if(!loadconfig(c))
252 +
	if(!loadprops(c))
253 253
		applyrules(c);
254 254
	if(!c->isfloating)
255 255
		c->isfloating = (rettrans == Success) || c->isfixed;
256 -
	saveconfig(c);
256 +
	saveprops(c);
257 257
	attach(c);
258 258
	attachstack(c);
259 259
	XMoveResizeWindow(dpy, c->win, c->x, c->y, c->w, c->h); /* some windows require this */
325 325
}
326 326
327 327
void
328 -
saveconfig(Client *c) {
328 +
saveprops(Client *c) {
329 329
	unsigned int i;
330 330
331 -
	for(i = 0; i < ntags && i < sizeof config - 1; i++)
332 -
		config[i] = c->tags[i] ? '1' : '0';
333 -
	if(i < sizeof config - 1)
334 -
		config[i++] = c->isfloating ? '1' : '0';
335 -
	config[i] = '\0';
336 -
	XChangeProperty(dpy, c->win, dwmconfig, XA_STRING, 8,
337 -
			PropModeReplace, (unsigned char *)config, i);
331 +
	for(i = 0; i < ntags && i < sizeof prop - 1; i++)
332 +
		prop[i] = c->tags[i] ? '1' : '0';
333 +
	if(i < sizeof prop - 1)
334 +
		prop[i++] = c->isfloating ? '1' : '0';
335 +
	prop[i] = '\0';
336 +
	XChangeProperty(dpy, c->win, dwmprops, XA_STRING, 8,
337 +
			PropModeReplace, (unsigned char *)prop, i);
338 338
}
339 339
340 340
void
config.mk +2 −2
20 20
# flags
21 21
CFLAGS = -Os ${INCS} -DVERSION=\"${VERSION}\"
22 22
LDFLAGS = -s ${LIBS}
23 -
#CFLAGS = -g -Wall -O2 ${INCS} -DVERSION=\"${VERSION}\"
24 -
#LDFLAGS = -g ${LIBS}
23 +
CFLAGS = -g -Wall -O2 ${INCS} -DVERSION=\"${VERSION}\"
24 +
LDFLAGS = -g ${LIBS}
25 25
26 26
# Solaris
27 27
#CFLAGS = -fast ${INCS} -DVERSION=\"${VERSION}\"
dwm.h +5 −3
81 81
extern unsigned int bh, blw, bpos;		/* bar height, bar layout label width, bar position */
82 82
extern unsigned int ntags, numlockmask;		/* number of tags, numlock mask */
83 83
extern void (*handler[LASTEvent])(XEvent *);	/* event handler */
84 -
extern Atom dwmconfig, wmatom[WMLast], netatom[NetLast];
84 +
extern Atom dwmprops, wmatom[WMLast], netatom[NetLast];
85 85
extern Bool selscreen, *seltags;		/* seltags is array of Bool */
86 86
extern Client *clients, *sel, *stack;		/* global client list and stack */
87 87
extern Cursor cursor[CurLast];
96 96
void detach(Client *c);			/* detaches c from global client list */
97 97
void focus(Client *c);			/* focus c if visible && !NULL, or focus top visible */
98 98
void killclient(const char *arg);	/* kill sel  nicely */
99 -
Bool loadconfig(Client *c);		/* loads client properties */
99 +
Bool loadprops(Client *c);		/* loads client properties */
100 100
void manage(Window w, XWindowAttributes *wa);	/* manage new client */
101 101
void resize(Client *c, int x, int y,
102 102
		int w, int h, Bool sizehints);	/* resize with given coordinates c*/
103 -
void saveconfig(Client *c);		/* saves client properties */
103 +
void saveprops(Client *c);		/* saves client properties */
104 104
void unban(Client *c);			/* unbans c */
105 105
void unmanage(Client *c, long state);	/* unmanage c */
106 106
void updatesizehints(Client *c);	/* update the size hint variables of c */
122 122
Bool isfloating(void);			/* returns True if floating layout is enabled */
123 123
Bool isarrange(void (*func)());		/* returns True if func is the layout function in use */
124 124
void initlayouts(void);			/* initialize layout array */
125 +
void loaddwmprops(void);		/* loads dwm properties */
125 126
Client *nexttiled(Client *c);		/* returns tiled successor of c */
126 127
void restack(void);			/* restores z layers of all clients */
128 +
void savedwmprops(void);		/* saves dwm properties */
127 129
void setlayout(const char *arg);	/* sets layout, NULL means next layout */
128 130
void togglebar(const char *arg);	/* shows/hides the bar */
129 131
void togglemax(const char *arg);	/* toggles maximization of floating client */
layout.c +40 −0
1 1
/* See LICENSE file for copyright and license details. */
2 2
#include "dwm.h"
3 3
#include <stdlib.h>
4 +
#include <string.h>
5 +
#include <X11/Xatom.h>
6 +
#include <X11/Xutil.h>
4 7
5 8
/* static */
6 9
10 13
} Layout;
11 14
12 15
unsigned int blw = 0;
16 +
static char prop[128];
13 17
static unsigned int ltidx = 0; /* default */
14 18
15 19
static void
103 107
	}
104 108
}
105 109
110 +
void
111 +
loaddwmprops(void) {
112 +
	unsigned int i;
113 +
	XTextProperty name;
114 +
115 +
	/* check if window has set a property */
116 +
	name.nitems = 0;
117 +
	XGetTextProperty(dpy, root, &name, dwmprops);
118 +
	if(name.nitems && name.encoding == XA_STRING) {
119 +
		strncpy(prop, (char *)name.value, sizeof prop - 1);
120 +
		prop[sizeof prop - 1] = '\0';
121 +
		XFree(name.value);
122 +
		for(i = 0; i < ntags && i < sizeof prop - 1 && prop[i] != '\0'; i++)
123 +
			seltags[i] = prop[i] == '1';
124 +
		if(i < sizeof prop - 1 && prop[i] != '\0') {
125 +
			i = prop[i] - '0';
126 +
			if(i < nlayouts)
127 +
				ltidx = i;
128 +
		}
129 +
	}
130 +
}
131 +
106 132
Client *
107 133
nexttiled(Client *c) {
108 134
	for(; c && (c->isfloating || !isvisible(c)); c = c->next);
139 165
}
140 166
141 167
void
168 +
savedwmprops(void) {
169 +
	unsigned int i;
170 +
171 +
	for(i = 0; i < ntags && i < sizeof prop - 1; i++)
172 +
		prop[i] = seltags[i] ? '1' : '0';
173 +
	if(i < sizeof prop - 1)
174 +
		prop[i++] = (char)ltidx;
175 +
	prop[i] = '\0';
176 +
	XChangeProperty(dpy, root, dwmprops, XA_STRING, 8,
177 +
			PropModeReplace, (unsigned char *)prop, i);
178 +
}
179 +
180 +
void
142 181
setlayout(const char *arg) {
143 182
	int i;
144 183
156 195
		arrange();
157 196
	else
158 197
		drawstatus();
198 +
	savedwmprops();
159 199
}
160 200
161 201
void
main.c +3 −2
20 20
unsigned int bh, ntags;
21 21
unsigned int bpos = BARPOS;
22 22
unsigned int numlockmask = 0;
23 -
Atom dwmconfig, wmatom[WMLast], netatom[NetLast];
23 +
Atom dwmprops, wmatom[WMLast], netatom[NetLast];
24 24
Bool *seltags;
25 25
Bool selscreen = True;
26 26
Client *clients = NULL;
140 140
	XSetWindowAttributes wa;
141 141
142 142
	/* init atoms */
143 -
	dwmconfig = XInternAtom(dpy, "_DWM_CONFIG", False);
143 +
	dwmprops = XInternAtom(dpy, "_DWM_PROPERTIES", False);
144 144
	wmatom[WMProtocols] = XInternAtom(dpy, "WM_PROTOCOLS", False);
145 145
	wmatom[WMDelete] = XInternAtom(dpy, "WM_DELETE_WINDOW", False);
146 146
	wmatom[WMState] = XInternAtom(dpy, "WM_STATE", False);
205 205
		XSetFont(dpy, dc.gc, dc.font.xfont->fid);
206 206
	/* multihead support */
207 207
	selscreen = XQueryPointer(dpy, root, &w, &w, &i, &i, &i, &i, &mask);
208 +
	loaddwmprops();
208 209
}
209 210
210 211
/*
tag.c +5 −5
3 3
#include <regex.h>
4 4
#include <stdio.h>
5 5
#include <stdlib.h>
6 -
#include <string.h>
7 -
#include <X11/Xatom.h>
8 6
#include <X11/Xutil.h>
9 7
10 8
/* static */
118 116
	i = idxoftag(arg);
119 117
	if(i >= 0 && i < ntags)
120 118
		sel->tags[i] = True;
121 -
	saveconfig(sel);
119 +
	saveprops(sel);
122 120
	arrange();
123 121
}
124 122
129 127
	sel->isfloating = !sel->isfloating;
130 128
	if(sel->isfloating) {
131 129
		resize(sel, sel->x, sel->y, sel->w, sel->h, True);
132 -
		saveconfig(sel);
130 +
		saveprops(sel);
133 131
	}
134 132
	arrange();
135 133
}
145 143
	for(j = 0; j < ntags && !sel->tags[j]; j++);
146 144
	if(j == ntags)
147 145
		sel->tags[i] = True;
148 -
	saveconfig(sel);
146 +
	saveprops(sel);
149 147
	arrange();
150 148
}
151 149
158 156
	for(j = 0; j < ntags && !seltags[j]; j++);
159 157
	if(j == ntags)
160 158
		seltags[i] = True; /* cannot toggle last view */
159 +
	savedwmprops();
161 160
	arrange();
162 161
}
163 162
170 169
	i = idxoftag(arg);
171 170
	if(i >= 0 && i < ntags)
172 171
		seltags[i] = True;
172 +
	savedwmprops();
173 173
	arrange();
174 174
}