comparison aewl.c @ 761:59ce221b9a37

removed global float (dofloat); number of tags is fixed (2)
author meillo@marmaro.de
date Fri, 05 Dec 2008 15:44:43 +0100
parents 014c4cb1ae4a
children 3f0b245732fc
comparison
equal deleted inserted replaced
760:014c4cb1ae4a 761:59ce221b9a37
25 * 25 *
26 * Keys and tagging rules are organized as arrays and defined in the config.h 26 * Keys and tagging rules are organized as arrays and defined in the config.h
27 * file. These arrays are kept static in event.o and tag.o respectively, 27 * file. These arrays are kept static in event.o and tag.o respectively,
28 * because no other part of dwm needs access to them. The current mode is 28 * because no other part of dwm needs access to them. The current mode is
29 * represented by the arrange() function pointer, which wether points to 29 * represented by the arrange() function pointer, which wether points to
30 * dofloat() or dotile(). 30 * domax() or dotile().
31 * 31 *
32 * To understand everything else, start reading main.c:main(). 32 * To understand everything else, start reading main.c:main().
33 */ 33 */
34 34
35 #include "config.h" 35 #include "config.h"
115 #define CLEANMASK(mask) (mask & ~(numlockmask | LockMask)) 115 #define CLEANMASK(mask) (mask & ~(numlockmask | LockMask))
116 #define MOUSEMASK (BUTTONMASK | PointerMotionMask) 116 #define MOUSEMASK (BUTTONMASK | PointerMotionMask)
117 117
118 118
119 119
120 const char *tags[]; /* all tags */
121 char stext[256]; /* status text */ 120 char stext[256]; /* status text */
122 int bh, bmw; /* bar height, bar mode label width */ 121 int bh, bmw; /* bar height, bar mode label width */
123 int screen, sx, sy, sw, sh; /* screen geometry */ 122 int screen, sx, sy, sw, sh; /* screen geometry */
124 int wax, way, wah, waw; /* windowarea geometry */ 123 int wax, way, wah, waw; /* windowarea geometry */
125 unsigned int nmaster; /* number of master clients */ 124 unsigned int nmaster; /* number of master clients */
126 unsigned int ntags, numlockmask; /* number of tags, dynamic lock mask */ 125 unsigned int numlockmask; /* dynamic lock mask */
127 void (*handler[LASTEvent])(XEvent *); /* event handler */ 126 void (*handler[LASTEvent])(XEvent *); /* event handler */
128 void (*arrange)(void); /* arrange function, indicates mode */ 127 void (*arrange)(void); /* arrange function, indicates mode */
129 Atom wmatom[WMLast], netatom[NetLast]; 128 Atom wmatom[WMLast], netatom[NetLast];
130 Bool running, selscreen, seltag; /* seltag is array of Bool */ 129 Bool running, selscreen, seltag;
131 Client *clients, *sel, *stack; /* global client list and stack */ 130 Client *clients, *sel, *stack; /* global client list and stack */
132 Cursor cursor[CurLast]; 131 Cursor cursor[CurLast];
133 DC dc; /* global draw context */ 132 DC dc; /* global draw context */
134 Display *dpy; 133 Display *dpy;
135 Window root, barwin; 134 Window root, barwin;
145 static Bool otherwm, readin; 144 static Bool otherwm, readin;
146 static RReg *rreg = NULL; 145 static RReg *rreg = NULL;
147 static unsigned int len = 0; 146 static unsigned int len = 0;
148 147
149 148
150 TAGS
151 RULES 149 RULES
152 150
153 151
154 /* client.c */ 152 /* client.c */
155 void configure(Client *c); /* send synthetic configure event */ 153 void configure(Client *c); /* send synthetic configure event */
185 void *emallocz(unsigned int size); /* allocates zero-initialized memory, exits on error */ 183 void *emallocz(unsigned int size); /* allocates zero-initialized memory, exits on error */
186 void eprint(const char *errstr, ...); /* prints errstr and exits with 1 */ 184 void eprint(const char *errstr, ...); /* prints errstr and exits with 1 */
187 185
188 /* view.c */ 186 /* view.c */
189 void detach(Client *c); /* detaches c from global client list */ 187 void detach(Client *c); /* detaches c from global client list */
190 void dofloat(void); /* arranges all windows floating */
191 void dotile(void); /* arranges all windows tiled */ 188 void dotile(void); /* arranges all windows tiled */
192 void domax(void); /* arranges all windows fullscreen */ 189 void domax(void); /* arranges all windows fullscreen */
193 Bool isvisible(Client *c); /* returns True if client is visible */ 190 Bool isvisible(Client *c); /* returns True if client is visible */
194 void restack(void); /* restores z layers of all clients */ 191 void restack(void); /* restores z layers of all clients */
195 192
197 void toggleview(void); /* toggle the viewed tag */ 194 void toggleview(void); /* toggle the viewed tag */
198 void focusnext(void); /* focuses next visible client */ 195 void focusnext(void); /* focuses next visible client */
199 void zoom(void); /* zooms the focused client to master area */ 196 void zoom(void); /* zooms the focused client to master area */
200 void killclient(void); /* kill c nicely */ 197 void killclient(void); /* kill c nicely */
201 void quit(void); /* quit dwm nicely */ 198 void quit(void); /* quit dwm nicely */
202 void togglemode(void); /* toggles global arrange function (dotile/dofloat) */ 199 void togglemode(void); /* toggles global arrange function (dotile/domax) */
203 void togglefloat(void); /* toggles focusesd client between floating/non-floating state */ 200 void togglefloat(void); /* toggles focusesd client between floating/non-floating state */
204 void incnmaster(void); /* increments nmaster */ 201 void incnmaster(void); /* increments nmaster */
205 void decnmaster(void); /* decrements nmaster */ 202 void decnmaster(void); /* decrements nmaster */
206 void toggletag(void); /* toggles c tag */ 203 void toggletag(void); /* toggles c tag */
207 void spawn(const char* cmd); /* forks a new subprocess with cmd */ 204 void spawn(const char* cmd); /* forks a new subprocess with cmd */
258 if(c->next) 255 if(c->next)
259 c->next->prev = c->prev; 256 c->next->prev = c->prev;
260 if(c == clients) 257 if(c == clients)
261 clients = c->next; 258 clients = c->next;
262 c->next = c->prev = NULL; 259 c->next = c->prev = NULL;
263 }
264
265 void
266 dofloat(void) {
267 Client *c;
268
269 for(c = clients; c; c = c->next) {
270 if(isvisible(c)) {
271 resize(c, True);
272 }
273 else
274 XMoveWindow(dpy, c->win, c->x + 2 * sw, c->y);
275 }
276 if(!sel || !isvisible(sel)) {
277 for(c = stack; c && !isvisible(c); c = c->snext);
278 focus(c);
279 }
280 restack();
281 } 260 }
282 261
283 void 262 void
284 dotile(void) { 263 dotile(void) {
285 unsigned int i, n, mw, mh, tw, th; 264 unsigned int i, n, mw, mh, tw, th;
385 } 364 }
386 } 365 }
387 366
388 void 367 void
389 incnmaster() { 368 incnmaster() {
390 if((arrange == dofloat) || (wah / (nmaster + 1) <= 2 * BORDERPX)) 369 if(wah / (nmaster + 1) <= 2 * BORDERPX)
391 return; 370 return;
392 nmaster++; 371 nmaster++;
393 if(sel) 372 if(sel)
394 arrange(); 373 arrange();
395 else 374 else
396 drawstatus(); 375 drawstatus();
397 } 376 }
398 377
399 void 378 void
400 decnmaster() { 379 decnmaster() {
401 if((arrange == dofloat) || (nmaster <= 1)) 380 if(nmaster <= 1)
402 return; 381 return;
403 nmaster--; 382 nmaster--;
404 if(sel) 383 if(sel)
405 arrange(); 384 arrange();
406 else 385 else
407 drawstatus(); 386 drawstatus();
408 } 387 }
409 388
410 Bool 389 Bool
411 isvisible(Client *c) { 390 isvisible(Client *c) {
412 if((c->tag && seltag) || (!c->tag && !seltag)) { 391 if(c->tag == seltag) {
413 return True; 392 return True;
414 } 393 }
415 return False; 394 return False;
416 } 395 }
417 396
421 XEvent ev; 400 XEvent ev;
422 401
423 drawstatus(); 402 drawstatus();
424 if(!sel) 403 if(!sel)
425 return; 404 return;
426 if(sel->isfloat || arrange == dofloat) 405 if(sel->isfloat)
427 XRaiseWindow(dpy, sel->win); 406 XRaiseWindow(dpy, sel->win);
428 407
429 /* begin code by mitch */ 408 /* begin code by mitch */
430 if(arrange == domax) { 409 if(arrange == domax) {
431 for(c = nexttiled(clients); c; c = nexttiled(c->next)) { 410 for(c = nexttiled(clients); c; c = nexttiled(c->next)) {
448 while(XCheckMaskEvent(dpy, EnterWindowMask, &ev)); 427 while(XCheckMaskEvent(dpy, EnterWindowMask, &ev));
449 } 428 }
450 429
451 void 430 void
452 togglefloat() { 431 togglefloat() {
453 if (!sel || arrange == dofloat) 432 if (!sel)
454 return; 433 return;
455 sel->isfloat = !sel->isfloat; 434 sel->isfloat = !sel->isfloat;
456 arrange(); 435 arrange();
457 } 436 }
458 437
477 unsigned int n; 456 unsigned int n;
478 Client *c; 457 Client *c;
479 458
480 if(!sel) 459 if(!sel)
481 return; 460 return;
482 if(sel->isfloat || (arrange == dofloat)) { 461 if(sel->isfloat) {
483 togglemax(sel); 462 togglemax(sel);
484 return; 463 return;
485 } 464 }
486 for(n = 0, c = nexttiled(clients); c; c = nexttiled(c->next)) 465 for(n = 0, c = nexttiled(clients); c; c = nexttiled(c->next))
487 n++; 466 n++;
763 return; 742 return;
764 } else if((c = getclient(ev->window))) { 743 } else if((c = getclient(ev->window))) {
765 focus(c); 744 focus(c);
766 if(CLEANMASK(ev->state) != MODKEY) 745 if(CLEANMASK(ev->state) != MODKEY)
767 return; 746 return;
768 if(ev->button == Button1 && (arrange == dofloat || c->isfloat)) { 747 if(ev->button == Button1 && c->isfloat) {
769 restack(); 748 restack();
770 movemouse(c); 749 movemouse(c);
771 } else if(ev->button == Button3 && (arrange == dofloat || c->isfloat) && !c->isfixed) { 750 } else if(ev->button == Button3 && c->isfloat && !c->isfixed) {
772 restack(); 751 restack();
773 resizemouse(c); 752 resizemouse(c);
774 } 753 }
775 } 754 }
776 } 755 }
1070 1049
1071 1050
1072 void 1051 void
1073 drawstatus(void) { 1052 drawstatus(void) {
1074 int x; 1053 int x;
1075 unsigned int i;
1076 1054
1077 dc.x = dc.y = 0; 1055 dc.x = dc.y = 0;
1078 for(i = 0; i < ntags; i++) { 1056 dc.w = textw(NAMESEL);
1079 dc.w = textw(tags[i]); 1057 drawtext(NAMESEL, ( seltag ? dc.sel : dc.norm ));
1080 drawtext(tags[i], ( ((i == 0 && seltag) || (i == 1 && !seltag)) ? dc.sel : dc.norm)); 1058 dc.x += dc.w + 1;
1081 dc.x += dc.w + 1; 1059 dc.w = textw(NAMENSEL);
1082 } 1060 drawtext(NAMENSEL, ( seltag ? dc.norm : dc.sel ));
1061 dc.x += dc.w + 1;
1083 dc.w = bmw; 1062 dc.w = bmw;
1084 drawtext("", dc.norm); 1063 drawtext("", dc.norm);
1085 x = dc.x + dc.w; 1064 x = dc.x + dc.w;
1086 dc.w = textw(stext); 1065 dc.w = textw(stext);
1087 dc.x = sw - dc.w; 1066 dc.x = sw - dc.w;
1609 | EnterWindowMask | LeaveWindowMask; 1588 | EnterWindowMask | LeaveWindowMask;
1610 wa.cursor = cursor[CurNormal]; 1589 wa.cursor = cursor[CurNormal];
1611 XChangeWindowAttributes(dpy, root, CWEventMask | CWCursor, &wa); 1590 XChangeWindowAttributes(dpy, root, CWEventMask | CWCursor, &wa);
1612 grabkeys(); 1591 grabkeys();
1613 initrregs(); 1592 initrregs();
1614 ntags = 2;
1615 seltag = True; 1593 seltag = True;
1616 /* style */ 1594 /* style */
1617 dc.norm[ColBorder] = getcolor(NORMBORDERCOLOR); 1595 dc.norm[ColBorder] = getcolor(NORMBORDERCOLOR);
1618 dc.norm[ColBG] = getcolor(NORMBGCOLOR); 1596 dc.norm[ColBG] = getcolor(NORMBGCOLOR);
1619 dc.norm[ColFG] = getcolor(NORMFGCOLOR); 1597 dc.norm[ColFG] = getcolor(NORMFGCOLOR);