summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--client.c50
-rw-r--r--config.mk4
-rw-r--r--dwm.h8
-rw-r--r--event.c8
-rw-r--r--main.c6
-rw-r--r--screen.c48
6 files changed, 23 insertions, 101 deletions
diff --git a/client.c b/client.c
index c03770b..9dd08b1 100644
--- a/client.c
+++ b/client.c
@@ -1,14 +1,11 @@
1/* See LICENSE file for copyright and license details. */ 1/* See LICENSE file for copyright and license details. */
2#include "dwm.h" 2#include "dwm.h"
3#include <stdlib.h> 3#include <stdlib.h>
4#include <string.h>
5#include <X11/Xatom.h> 4#include <X11/Xatom.h>
6#include <X11/Xutil.h> 5#include <X11/Xutil.h>
7 6
8/* static */ 7/* static */
9 8
10static char buf[128];
11
12static void 9static void
13attachstack(Client *c) { 10attachstack(Client *c) {
14 c->snext = stack; 11 c->snext = stack;
@@ -102,10 +99,8 @@ void
102ban(Client *c) { 99ban(Client *c) {
103 if(c->isbanned) 100 if(c->isbanned)
104 return; 101 return;
105 XUnmapWindow(dpy, c->win); 102 XMoveWindow(dpy, c->win, c->x + 2 * sw, c->y);
106 setclientstate(c, IconicState);
107 c->isbanned = True; 103 c->isbanned = True;
108 c->unmapped++;
109} 104}
110 105
111void 106void
@@ -181,21 +176,6 @@ killclient(const char *arg) {
181 XKillClient(dpy, sel->win); 176 XKillClient(dpy, sel->win);
182} 177}
183 178
184Bool
185getprops(Client *c) {
186 unsigned int i;
187 Bool result = False;
188
189 if(gettextprop(c->win, dwmprops, buf, sizeof buf)) {
190 for(i = 0; i < ntags && i < sizeof buf - 1 && buf[i] != '\0'; i++)
191 if((c->tags[i] = buf[i] == '1'))
192 result = True;
193 if(i < sizeof buf - 1 && buf[i] != '\0')
194 c->isfloating = buf[i] == '1';
195 }
196 return result;
197}
198
199void 179void
200manage(Window w, XWindowAttributes *wa) { 180manage(Window w, XWindowAttributes *wa) {
201 unsigned int i; 181 unsigned int i;
@@ -242,15 +222,14 @@ manage(Window w, XWindowAttributes *wa) {
242 if(t) 222 if(t)
243 for(i = 0; i < ntags; i++) 223 for(i = 0; i < ntags; i++)
244 c->tags[i] = t->tags[i]; 224 c->tags[i] = t->tags[i];
245 if(!getprops(c)) 225 applyrules(c);
246 applyrules(c);
247 if(!c->isfloating) 226 if(!c->isfloating)
248 c->isfloating = (rettrans == Success) || c->isfixed; 227 c->isfloating = (rettrans == Success) || c->isfixed;
249 setprops(c);
250 attach(c); 228 attach(c);
251 attachstack(c); 229 attachstack(c);
252 XMoveResizeWindow(dpy, c->win, c->x, c->y, c->w, c->h); /* some windows require this */ 230 XMoveResizeWindow(dpy, c->win, c->x, c->y, c->w, c->h); /* some windows require this */
253 ban(c); 231 ban(c);
232 XMapWindow(dpy, c->win);
254 arrange(); 233 arrange();
255} 234}
256 235
@@ -318,29 +297,15 @@ resize(Client *c, int x, int y, int w, int h, Bool sizehints) {
318} 297}
319 298
320void 299void
321setprops(Client *c) {
322 unsigned int i;
323
324 for(i = 0; i < ntags && i < sizeof buf - 1; i++)
325 buf[i] = c->tags[i] ? '1' : '0';
326 if(i < sizeof buf - 1)
327 buf[i++] = c->isfloating ? '1' : '0';
328 buf[i] = '\0';
329 XChangeProperty(dpy, c->win, dwmprops, XA_STRING, 8,
330 PropModeReplace, (unsigned char *)buf, i);
331}
332
333void
334unban(Client *c) { 300unban(Client *c) {
335 if(!c->isbanned) 301 if(!c->isbanned)
336 return; 302 return;
337 XMapWindow(dpy, c->win); 303 XMoveWindow(dpy, c->win, c->x, c->y);
338 setclientstate(c, NormalState);
339 c->isbanned = False; 304 c->isbanned = False;
340} 305}
341 306
342void 307void
343unmanage(Client *c, long state) { 308unmanage(Client *c) {
344 XWindowChanges wc; 309 XWindowChanges wc;
345 310
346 wc.border_width = c->oldborder; 311 wc.border_width = c->oldborder;
@@ -353,14 +318,13 @@ unmanage(Client *c, long state) {
353 if(sel == c) 318 if(sel == c)
354 focus(NULL); 319 focus(NULL);
355 XUngrabButton(dpy, AnyButton, AnyModifier, c->win); 320 XUngrabButton(dpy, AnyButton, AnyModifier, c->win);
356 setclientstate(c, state); 321 setclientstate(c, WithdrawnState);
357 free(c->tags); 322 free(c->tags);
358 free(c); 323 free(c);
359 XSync(dpy, False); 324 XSync(dpy, False);
360 XSetErrorHandler(xerror); 325 XSetErrorHandler(xerror);
361 XUngrabServer(dpy); 326 XUngrabServer(dpy);
362 if(state != NormalState) 327 arrange();
363 arrange();
364} 328}
365 329
366void 330void
diff --git a/config.mk b/config.mk
index 320aea1..682bb41 100644
--- a/config.mk
+++ b/config.mk
@@ -20,8 +20,8 @@ LIBS = -L/usr/lib -lc -L${X11LIB} -lX11
20# flags 20# flags
21CFLAGS = -Os ${INCS} -DVERSION=\"${VERSION}\" 21CFLAGS = -Os ${INCS} -DVERSION=\"${VERSION}\"
22LDFLAGS = -s ${LIBS} 22LDFLAGS = -s ${LIBS}
23#CFLAGS = -g -Wall -O2 ${INCS} -DVERSION=\"${VERSION}\" 23CFLAGS = -g -Wall -O2 ${INCS} -DVERSION=\"${VERSION}\"
24#LDFLAGS = -g ${LIBS} 24LDFLAGS = -g ${LIBS}
25 25
26# Solaris 26# Solaris
27#CFLAGS = -fast ${INCS} -DVERSION=\"${VERSION}\" 27#CFLAGS = -fast ${INCS} -DVERSION=\"${VERSION}\"
diff --git a/dwm.h b/dwm.h
index 0d55143..1a12322 100644
--- a/dwm.h
+++ b/dwm.h
@@ -48,7 +48,6 @@ struct Client {
48 int rx, ry, rw, rh; /* revert geometry */ 48 int rx, ry, rw, rh; /* revert geometry */
49 int basew, baseh, incw, inch, maxw, maxh, minw, minh; 49 int basew, baseh, incw, inch, maxw, maxh, minw, minh;
50 int minax, maxax, minay, maxay; 50 int minax, maxax, minay, maxay;
51 int unmapped;
52 long flags; 51 long flags;
53 unsigned int border, oldborder; 52 unsigned int border, oldborder;
54 Bool isbanned, isfixed, ismax, isfloating; 53 Bool isbanned, isfixed, ismax, isfloating;
@@ -81,7 +80,7 @@ extern int wax, way, wah, waw; /* windowarea geometry */
81extern unsigned int bh, blw, bpos; /* bar height, bar layout label width, bar position */ 80extern unsigned int bh, blw, bpos; /* bar height, bar layout label width, bar position */
82extern unsigned int ntags, numlockmask; /* number of tags, numlock mask */ 81extern unsigned int ntags, numlockmask; /* number of tags, numlock mask */
83extern void (*handler[LASTEvent])(XEvent *); /* event handler */ 82extern void (*handler[LASTEvent])(XEvent *); /* event handler */
84extern Atom dwmprops, wmatom[WMLast], netatom[NetLast]; 83extern Atom wmatom[WMLast], netatom[NetLast];
85extern Bool selscreen, *seltags; /* seltags is array of Bool */ 84extern Bool selscreen, *seltags; /* seltags is array of Bool */
86extern Client *clients, *sel, *stack; /* global client list and stack */ 85extern Client *clients, *sel, *stack; /* global client list and stack */
87extern Cursor cursor[CurLast]; 86extern Cursor cursor[CurLast];
@@ -96,13 +95,11 @@ void configure(Client *c); /* send synthetic configure event */
96void detach(Client *c); /* detaches c from global client list */ 95void detach(Client *c); /* detaches c from global client list */
97void focus(Client *c); /* focus c if visible && !NULL, or focus top visible */ 96void focus(Client *c); /* focus c if visible && !NULL, or focus top visible */
98void killclient(const char *arg); /* kill sel nicely */ 97void killclient(const char *arg); /* kill sel nicely */
99Bool getprops(Client *c); /* gets client properties */
100void manage(Window w, XWindowAttributes *wa); /* manage new client */ 98void manage(Window w, XWindowAttributes *wa); /* manage new client */
101void resize(Client *c, int x, int y, 99void resize(Client *c, int x, int y,
102 int w, int h, Bool sizehints); /* resize with given coordinates c*/ 100 int w, int h, Bool sizehints); /* resize with given coordinates c*/
103void setprops(Client *c); /* sets client properties */
104void unban(Client *c); /* unbans c */ 101void unban(Client *c); /* unbans c */
105void unmanage(Client *c, long state); /* unmanage c */ 102void unmanage(Client *c); /* unmanage c */
106void updatesizehints(Client *c); /* update the size hint variables of c */ 103void updatesizehints(Client *c); /* update the size hint variables of c */
107void updatetitle(Client *c); /* update the name of c */ 104void updatetitle(Client *c); /* update the name of c */
108 105
@@ -131,7 +128,6 @@ void initlayouts(void); /* initialize layout array */
131Bool isarrange(void (*func)()); /* returns True if func is the layout function in use */ 128Bool isarrange(void (*func)()); /* returns True if func is the layout function in use */
132Bool isfloating(void); /* returns True if floating layout is enabled */ 129Bool isfloating(void); /* returns True if floating layout is enabled */
133Bool isvisible(Client *c); /* returns True if client is visible */ 130Bool isvisible(Client *c); /* returns True if client is visible */
134void getdwmprops(void); /* gets dwm properties */
135Client *nexttiled(Client *c); /* returns tiled successor of c */ 131Client *nexttiled(Client *c); /* returns tiled successor of c */
136void restack(void); /* restores z layers of all clients */ 132void restack(void); /* restores z layers of all clients */
137void setlayout(const char *arg); /* sets layout, NULL means next layout */ 133void setlayout(const char *arg); /* sets layout, NULL means next layout */
diff --git a/event.c b/event.c
index b96aba9..9e83178 100644
--- a/event.c
+++ b/event.c
@@ -221,7 +221,7 @@ destroynotify(XEvent *e) {
221 XDestroyWindowEvent *ev = &e->xdestroywindow; 221 XDestroyWindowEvent *ev = &e->xdestroywindow;
222 222
223 if((c = getclient(ev->window))) 223 if((c = getclient(ev->window)))
224 unmanage(c, WithdrawnState); 224 unmanage(c);
225} 225}
226 226
227static void 227static void
@@ -332,10 +332,8 @@ unmapnotify(XEvent *e) {
332 Client *c; 332 Client *c;
333 XUnmapEvent *ev = &e->xunmap; 333 XUnmapEvent *ev = &e->xunmap;
334 334
335 if((c = getclient(ev->window)) && (ev->event == root)) { 335 if((c = getclient(ev->window)))
336 if(ev->send_event || c->unmapped-- == 0) 336 unmanage(c);
337 unmanage(c, WithdrawnState);
338 }
339} 337}
340 338
341/* extern */ 339/* extern */
diff --git a/main.c b/main.c
index 79b301d..338fed4 100644
--- a/main.c
+++ b/main.c
@@ -20,7 +20,7 @@ int screen, sx, sy, sw, sh, wax, way, waw, wah;
20unsigned int bh, ntags; 20unsigned int bh, ntags;
21unsigned int bpos = BARPOS; 21unsigned int bpos = BARPOS;
22unsigned int numlockmask = 0; 22unsigned int numlockmask = 0;
23Atom dwmprops, wmatom[WMLast], netatom[NetLast]; 23Atom wmatom[WMLast], netatom[NetLast];
24Bool *seltags; 24Bool *seltags;
25Bool selscreen = True; 25Bool selscreen = True;
26Client *clients = NULL; 26Client *clients = NULL;
@@ -42,7 +42,7 @@ cleanup(void) {
42 close(STDIN_FILENO); 42 close(STDIN_FILENO);
43 while(stack) { 43 while(stack) {
44 unban(stack); 44 unban(stack);
45 unmanage(stack, NormalState); 45 unmanage(stack);
46 } 46 }
47 if(dc.font.set) 47 if(dc.font.set)
48 XFreeFontSet(dpy, dc.font.set); 48 XFreeFontSet(dpy, dc.font.set);
@@ -165,7 +165,6 @@ setup(void) {
165 XSetWindowAttributes wa; 165 XSetWindowAttributes wa;
166 166
167 /* init atoms */ 167 /* init atoms */
168 dwmprops = XInternAtom(dpy, "_DWM_PROPERTIES", False);
169 wmatom[WMProtocols] = XInternAtom(dpy, "WM_PROTOCOLS", False); 168 wmatom[WMProtocols] = XInternAtom(dpy, "WM_PROTOCOLS", False);
170 wmatom[WMDelete] = XInternAtom(dpy, "WM_DELETE_WINDOW", False); 169 wmatom[WMDelete] = XInternAtom(dpy, "WM_DELETE_WINDOW", False);
171 wmatom[WMName] = XInternAtom(dpy, "WM_NAME", False); 170 wmatom[WMName] = XInternAtom(dpy, "WM_NAME", False);
@@ -231,7 +230,6 @@ setup(void) {
231 XSetFont(dpy, dc.gc, dc.font.xfont->fid); 230 XSetFont(dpy, dc.gc, dc.font.xfont->fid);
232 /* multihead support */ 231 /* multihead support */
233 selscreen = XQueryPointer(dpy, root, &w, &w, &i, &i, &i, &i, &mask); 232 selscreen = XQueryPointer(dpy, root, &w, &w, &i, &i, &i, &i, &mask);
234 getdwmprops();
235} 233}
236 234
237/* 235/*
diff --git a/screen.c b/screen.c
index ec8637f..b534766 100644
--- a/screen.c
+++ b/screen.c
@@ -3,8 +3,6 @@
3#include <regex.h> 3#include <regex.h>
4#include <stdio.h> 4#include <stdio.h>
5#include <stdlib.h> 5#include <stdlib.h>
6#include <string.h>
7#include <X11/Xatom.h>
8#include <X11/Xutil.h> 6#include <X11/Xutil.h>
9 7
10/* static */ 8/* static */
@@ -28,7 +26,6 @@ typedef struct {
28TAGS 26TAGS
29RULES 27RULES
30 28
31static char buf[512];
32static unsigned int nrules = 0; 29static unsigned int nrules = 0;
33static unsigned int nlayouts = 0; 30static unsigned int nlayouts = 0;
34static unsigned int ltidx = 0; /* default */ 31static unsigned int ltidx = 0; /* default */
@@ -53,19 +50,6 @@ floating(void) { /* default floating layout */
53 resize(c, c->x, c->y, c->w, c->h, True); 50 resize(c, c->x, c->y, c->w, c->h, True);
54} 51}
55 52
56static void
57setdwmprops(void) {
58 unsigned int i;
59
60 for(i = 0; i < ntags && i < sizeof buf - 1; i++)
61 buf[i] = seltags[i] ? '1' : '0';
62 if(i < sizeof buf - 1)
63 buf[i++] = (char)ltidx + '0';
64 buf[i] = '\0';
65 XChangeProperty(dpy, root, dwmprops, XA_STRING, 8,
66 PropModeReplace, (unsigned char *)buf, i);
67}
68
69LAYOUTS 53LAYOUTS
70 54
71/* extern */ 55/* extern */
@@ -74,6 +58,7 @@ unsigned int blw = 0;
74 58
75void 59void
76applyrules(Client *c) { 60applyrules(Client *c) {
61 static char buf[512];
77 unsigned int i, j; 62 unsigned int i, j;
78 regmatch_t tmp; 63 regmatch_t tmp;
79 Bool matched = False; 64 Bool matched = False;
@@ -215,20 +200,6 @@ isvisible(Client *c) {
215 return False; 200 return False;
216} 201}
217 202
218void
219getdwmprops(void) {
220 unsigned int i;
221
222 if(gettextprop(root, dwmprops, buf, sizeof buf)) {
223 for(i = 0; i < ntags && i < sizeof buf - 1 && buf[i] != '\0'; i++)
224 seltags[i] = buf[i] == '1';
225 if(i < sizeof buf - 1 && buf[i] != '\0') {
226 if((unsigned int)(buf[i] - '0') < nlayouts)
227 ltidx = buf[i] - '0';
228 }
229 }
230}
231
232Client * 203Client *
233nexttiled(Client *c) { 204nexttiled(Client *c) {
234 for(; c && (c->isfloating || !isvisible(c)); c = c->next); 205 for(; c && (c->isfloating || !isvisible(c)); c = c->next);
@@ -266,15 +237,17 @@ restack(void) {
266 237
267void 238void
268setlayout(const char *arg) { 239setlayout(const char *arg) {
269 int i; 240 unsigned int i;
270 241
271 if(!arg) { 242 if(!arg) {
272 if(++ltidx == nlayouts) 243 if(++ltidx == nlayouts)
273 ltidx = 0;; 244 ltidx = 0;;
274 } 245 }
275 else { 246 else {
276 i = atoi(arg); 247 for(i = 0; i < nlayouts; i++)
277 if(i < 0 || i >= nlayouts) 248 if(arg == layouts[i].symbol)
249 break;
250 if(i == nlayouts)
278 return; 251 return;
279 ltidx = i; 252 ltidx = i;
280 } 253 }
@@ -282,7 +255,6 @@ setlayout(const char *arg) {
282 arrange(); 255 arrange();
283 else 256 else
284 drawstatus(); 257 drawstatus();
285 setdwmprops();
286} 258}
287 259
288void 260void
@@ -296,7 +268,6 @@ tag(const char *arg) {
296 i = idxoftag(arg); 268 i = idxoftag(arg);
297 if(i >= 0 && i < ntags) 269 if(i >= 0 && i < ntags)
298 sel->tags[i] = True; 270 sel->tags[i] = True;
299 setprops(sel);
300 arrange(); 271 arrange();
301} 272}
302 273
@@ -315,10 +286,8 @@ togglefloating(const char *arg) {
315 if(!sel || isfloating()) 286 if(!sel || isfloating())
316 return; 287 return;
317 sel->isfloating = !sel->isfloating; 288 sel->isfloating = !sel->isfloating;
318 if(sel->isfloating) { 289 if(sel->isfloating)
319 resize(sel, sel->x, sel->y, sel->w, sel->h, True); 290 resize(sel, sel->x, sel->y, sel->w, sel->h, True);
320 setprops(sel);
321 }
322 arrange(); 291 arrange();
323} 292}
324 293
@@ -352,7 +321,6 @@ toggletag(const char *arg) {
352 for(j = 0; j < ntags && !sel->tags[j]; j++); 321 for(j = 0; j < ntags && !sel->tags[j]; j++);
353 if(j == ntags) 322 if(j == ntags)
354 sel->tags[i] = True; 323 sel->tags[i] = True;
355 setprops(sel);
356 arrange(); 324 arrange();
357} 325}
358 326
@@ -365,7 +333,6 @@ toggleview(const char *arg) {
365 for(j = 0; j < ntags && !seltags[j]; j++); 333 for(j = 0; j < ntags && !seltags[j]; j++);
366 if(j == ntags) 334 if(j == ntags)
367 seltags[i] = True; /* cannot toggle last view */ 335 seltags[i] = True; /* cannot toggle last view */
368 setdwmprops();
369 arrange(); 336 arrange();
370} 337}
371 338
@@ -404,6 +371,5 @@ view(const char *arg) {
404 i = idxoftag(arg); 371 i = idxoftag(arg);
405 if(i >= 0 && i < ntags) 372 if(i >= 0 && i < ntags)
406 seltags[i] = True; 373 seltags[i] = True;
407 setdwmprops();
408 arrange(); 374 arrange();
409} 375}