Xinqi Bao's Git

separated layout-specific stuff into separate .h and .c files which are included...
[dwm.git] / layout.c
1 /* See LICENSE file for copyright and license details. */
2 #include "dwm.h"
3 #include <stdlib.h>
4
5 unsigned int blw = 0;
6 Layout *lt = NULL;
7
8 /* static */
9
10 static unsigned int nlayouts = 0;
11
12 LAYOUTS
13
14 /* extern */
15
16 void
17 focusclient(const char *arg) {
18 Client *c;
19
20 if(!sel || !arg)
21 return;
22 if(atoi(arg) < 0) {
23 for(c = sel->prev; c && !isvisible(c); c = c->prev);
24 if(!c) {
25 for(c = clients; c && c->next; c = c->next);
26 for(; c && !isvisible(c); c = c->prev);
27 }
28 }
29 else {
30 for(c = sel->next; c && !isvisible(c); c = c->next);
31 if(!c)
32 for(c = clients; c && !isvisible(c); c = c->next);
33 }
34 if(c) {
35 focus(c);
36 restack();
37 }
38 }
39
40 void
41 initlayouts(void) {
42 unsigned int i, w;
43
44 lt = &layout[0];
45 nlayouts = sizeof layout / sizeof layout[0];
46 for(blw = i = 0; i < nlayouts; i++) {
47 w = textw(layout[i].symbol);
48 if(w > blw)
49 blw = w;
50 }
51 }
52
53 Client *
54 nexttiled(Client *c) {
55 for(; c && (c->isfloating || !isvisible(c)); c = c->next);
56 return c;
57 }
58
59 void
60 restack(void) {
61 Client *c;
62 XEvent ev;
63 XWindowChanges wc;
64
65 drawstatus();
66 if(!sel)
67 return;
68 if(sel->isfloating || lt->arrange == floating)
69 XRaiseWindow(dpy, sel->win);
70 if(lt->arrange != floating) {
71 wc.stack_mode = Below;
72 wc.sibling = barwin;
73 if(!sel->isfloating) {
74 XConfigureWindow(dpy, sel->win, CWSibling | CWStackMode, &wc);
75 wc.sibling = sel->win;
76 }
77 for(c = nexttiled(clients); c; c = nexttiled(c->next)) {
78 if(c == sel)
79 continue;
80 XConfigureWindow(dpy, c->win, CWSibling | CWStackMode, &wc);
81 wc.sibling = c->win;
82 }
83 }
84 XSync(dpy, False);
85 while(XCheckMaskEvent(dpy, EnterWindowMask, &ev));
86 }
87
88 void
89 setlayout(const char *arg) {
90 int i;
91
92 if(!arg) {
93 lt++;
94 if(lt == layout + nlayouts)
95 lt = layout;
96 }
97 else {
98 i = atoi(arg);
99 if(i < 0 || i >= nlayouts)
100 return;
101 lt = &layout[i];
102 }
103 if(sel)
104 lt->arrange();
105 else
106 drawstatus();
107 }
108
109 void
110 togglebar(const char *arg) {
111 if(bpos == BarOff)
112 bpos = (BARPOS == BarOff) ? BarTop : BARPOS;
113 else
114 bpos = BarOff;
115 updatebarpos();
116 lt->arrange();
117 }