summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAnselm R. Garbe <arg@suckless.org>2007-02-19 16:40:36 +0100
committerAnselm R. Garbe <arg@suckless.org>2007-02-19 16:40:36 +0100
commitcdbc84b9a87c427b3d0a202475b0f5aae315fb90 (patch)
treed0f12930c9aaafb84d359d263601e2136b61ac74
parentsome more code polishing (diff)
downloaddwm-cdbc84b9a87c427b3d0a202475b0f5aae315fb90.tar.gz
dwm-cdbc84b9a87c427b3d0a202475b0f5aae315fb90.zip
introduced Layout struct
-rw-r--r--client.c8
-rw-r--r--config.arg.h11
-rw-r--r--config.default.h11
-rw-r--r--config.mk4
-rw-r--r--dwm.138
-rw-r--r--dwm.h19
-rw-r--r--event.c12
-rw-r--r--main.c12
-rw-r--r--screen.c82
9 files changed, 115 insertions, 82 deletions
diff --git a/client.c b/client.c
index 4d4c0a8..48b4167 100644
--- a/client.c
+++ b/client.c
@@ -263,7 +263,7 @@ manage(Window w, XWindowAttributes *wa) {
263 setclientstate(c, NormalState); 263 setclientstate(c, NormalState);
264 if(isvisible(c)) 264 if(isvisible(c))
265 focus(c); 265 focus(c);
266 arrange(); 266 lt->arrange();
267} 267}
268 268
269Client * 269Client *
@@ -430,7 +430,7 @@ unmanage(Client *c) {
430 XSync(dpy, False); 430 XSync(dpy, False);
431 XSetErrorHandler(xerror); 431 XSetErrorHandler(xerror);
432 XUngrabServer(dpy); 432 XUngrabServer(dpy);
433 arrange(); 433 lt->arrange();
434} 434}
435 435
436void 436void
@@ -440,7 +440,7 @@ zoom(Arg *arg) {
440 440
441 if(!sel) 441 if(!sel)
442 return; 442 return;
443 if(sel->isfloat || (arrange == dofloat)) { 443 if(sel->isfloat || (lt->arrange == dofloat)) {
444 togglemax(sel); 444 togglemax(sel);
445 return; 445 return;
446 } 446 }
@@ -452,5 +452,5 @@ zoom(Arg *arg) {
452 detach(c); 452 detach(c);
453 attach(c); 453 attach(c);
454 focus(c); 454 focus(c);
455 arrange(); 455 lt->arrange();
456} 456}
diff --git a/config.arg.h b/config.arg.h
index fae30d0..67069a6 100644
--- a/config.arg.h
+++ b/config.arg.h
@@ -5,9 +5,12 @@
5#define TAGS \ 5#define TAGS \
6const char *tags[] = { "1", "2", "3", "4", "5", "6", "7", "8", "9", NULL }; 6const char *tags[] = { "1", "2", "3", "4", "5", "6", "7", "8", "9", NULL };
7 7
8#define DEFMODE dotile /* dofloat */ 8#define LAYOUTS \
9#define FLOATSYMBOL "><>" 9static Layout layout[] = { \
10#define TILESYMBOL "[]=" 10 /* symbol function */ \
11 { "[]=", dotile }, /* first entry is default */ \
12 { "><>", dofloat }, \
13};
11 14
12#define BORDERPX 1 15#define BORDERPX 1
13#define FONT "-*-terminus-medium-r-*-*-14-*-*-*-*-*-*-*" 16#define FONT "-*-terminus-medium-r-*-*-14-*-*-*-*-*-*-*"
@@ -60,7 +63,7 @@ static Key key[] = { \
60 { MODKEY|ControlMask|ShiftMask, XK_8, toggletag, { .i = 7 } }, \ 63 { MODKEY|ControlMask|ShiftMask, XK_8, toggletag, { .i = 7 } }, \
61 { MODKEY|ControlMask|ShiftMask, XK_9, toggletag, { .i = 8 } }, \ 64 { MODKEY|ControlMask|ShiftMask, XK_9, toggletag, { .i = 8 } }, \
62 { MODKEY|ShiftMask, XK_c, killclient, { 0 } }, \ 65 { MODKEY|ShiftMask, XK_c, killclient, { 0 } }, \
63 { MODKEY, XK_space, togglemode, { 0 } }, \ 66 { MODKEY, XK_space, togglelayout, { 0 } }, \
64 { MODKEY|ShiftMask, XK_space, togglefloat, { 0 } }, \ 67 { MODKEY|ShiftMask, XK_space, togglefloat, { 0 } }, \
65 { MODKEY, XK_0, view, { .i = -1 } }, \ 68 { MODKEY, XK_0, view, { .i = -1 } }, \
66 { MODKEY, XK_1, view, { .i = 0 } }, \ 69 { MODKEY, XK_1, view, { .i = 0 } }, \
diff --git a/config.default.h b/config.default.h
index c1274a1..c318973 100644
--- a/config.default.h
+++ b/config.default.h
@@ -5,9 +5,12 @@
5#define TAGS \ 5#define TAGS \
6const char *tags[] = { "1", "2", "3", "4", "5", "6", "7", "8", "9", NULL }; 6const char *tags[] = { "1", "2", "3", "4", "5", "6", "7", "8", "9", NULL };
7 7
8#define DEFMODE dotile /* dofloat */ 8#define LAYOUTS \
9#define FLOATSYMBOL "><>" 9Layout layout[] = { \
10#define TILESYMBOL "[]=" 10 /* symbol function */ \
11 { "[]=", dotile }, /* first entry is default */ \
12 { "><>", dofloat }, \
13};
11 14
12#define BORDERPX 1 15#define BORDERPX 1
13#define FONT "-*-fixed-medium-r-normal-*-13-*-*-*-*-*-*-*" 16#define FONT "-*-fixed-medium-r-normal-*-13-*-*-*-*-*-*-*"
@@ -55,7 +58,7 @@ static Key key[] = { \
55 { MODKEY|ControlMask|ShiftMask, XK_8, toggletag, { .i = 7 } }, \ 58 { MODKEY|ControlMask|ShiftMask, XK_8, toggletag, { .i = 7 } }, \
56 { MODKEY|ControlMask|ShiftMask, XK_9, toggletag, { .i = 8 } }, \ 59 { MODKEY|ControlMask|ShiftMask, XK_9, toggletag, { .i = 8 } }, \
57 { MODKEY|ShiftMask, XK_c, killclient, { 0 } }, \ 60 { MODKEY|ShiftMask, XK_c, killclient, { 0 } }, \
58 { MODKEY, XK_space, togglemode, { 0 } }, \ 61 { MODKEY, XK_space, togglelayout, { 0 } }, \
59 { MODKEY|ShiftMask, XK_space, togglefloat, { 0 } }, \ 62 { MODKEY|ShiftMask, XK_space, togglefloat, { 0 } }, \
60 { MODKEY, XK_0, view, { .i = -1 } }, \ 63 { MODKEY, XK_0, view, { .i = -1 } }, \
61 { MODKEY, XK_1, view, { .i = 0 } }, \ 64 { MODKEY, XK_1, view, { .i = 0 } }, \
diff --git a/config.mk b/config.mk
index d3a6ffd..6a5ae27 100644
--- a/config.mk
+++ b/config.mk
@@ -17,8 +17,8 @@ LIBS = -L/usr/lib -lc -L${X11LIB} -lX11
17# flags 17# flags
18CFLAGS = -Os ${INCS} -DVERSION=\"${VERSION}\" 18CFLAGS = -Os ${INCS} -DVERSION=\"${VERSION}\"
19LDFLAGS = ${LIBS} 19LDFLAGS = ${LIBS}
20#CFLAGS = -g -Wall -O2 ${INCS} -DVERSION=\"${VERSION}\" 20CFLAGS = -g -Wall -O2 ${INCS} -DVERSION=\"${VERSION}\"
21#LDFLAGS = -g ${LIBS} 21LDFLAGS = -g ${LIBS}
22 22
23# Solaris 23# Solaris
24#CFLAGS = -fast ${INCS} -DVERSION=\"${VERSION}\" 24#CFLAGS = -fast ${INCS} -DVERSION=\"${VERSION}\"
diff --git a/dwm.1 b/dwm.1
index fe51264..2024f77 100644
--- a/dwm.1
+++ b/dwm.1
@@ -6,19 +6,19 @@ dwm \- dynamic window manager
6.RB [ \-v ] 6.RB [ \-v ]
7.SH DESCRIPTION 7.SH DESCRIPTION
8dwm is a dynamic window manager for X. It manages windows in tiling and 8dwm is a dynamic window manager for X. It manages windows in tiling and
9floating modes. Either mode can be applied dynamically, optimizing the 9floating layouts. Either layout can be applied dynamically, optimizing the
10environment for the application in use and the task performed. 10environment for the application in use and the task performed.
11.P 11.P
12In tiling mode windows are managed in a master and stacking area. The master 12In tiling layout windows are managed in a master and stacking area. The master
13area contains the windows which currently need most attention, whereas the 13area contains the windows which currently need most attention, whereas the
14stacking area contains all other windows. In floating mode windows can be 14stacking area contains all other windows. In floating layout windows can be
15resized and moved freely. Dialog windows are always managed floating, 15resized and moved freely. Dialog windows are always managed floating,
16regardless of the mode applied. 16regardless of the layout applied.
17.P 17.P
18Windows are grouped by tags. Each window can be tagged with one or multiple 18Windows are grouped by tags. Each window can be tagged with one or multiple
19tags. Selecting certain tags displays all windows with these tags. 19tags. Selecting certain tags displays all windows with these tags.
20.P 20.P
21dwm contains a small status bar which displays all available tags, the mode, 21dwm contains a small status bar which displays all available tags, the layout,
22the title of the focused window, and the text read from standard input. The 22the title of the focused window, and the text read from standard input. The
23selected tags are indicated with a different color. The tags of the focused 23selected tags are indicated with a different color. The tags of the focused
24window are indicated with a filled square in the top left corner. The tags 24window are indicated with a filled square in the top left corner. The tags
@@ -37,17 +37,17 @@ prints version information to standard output, then exits.
37is read and displayed in the status text area. 37is read and displayed in the status text area.
38.TP 38.TP
39.B Button1 39.B Button1
40click on a tag label to display all windows with that tag, click on the mode 40click on a tag label to display all windows with that tag, click on the layout
41label toggles between tiling and floating mode. 41label toggles between tiling and floating layout.
42.TP 42.TP
43.B Button3 43.B Button3
44click on a tag label adds/removes all windows with that tag to/from the view. 44click on a tag label adds/removes all windows with that tag to/from the view.
45.TP 45.TP
46.B Button4 46.B Button4
47click on the mode label increases the number of windows in the master area (tiling mode only). 47click on the layout label increases the number of windows in the master area (tiling layout only).
48.TP 48.TP
49.B Button5 49.B Button5
50click on the mode label decreases the number of windows in the master area (tiling mode only). 50click on the layout label decreases the number of windows in the master area (tiling layout only).
51.TP 51.TP
52.B Mod1-Button1 52.B Mod1-Button1
53click on a tag label applies that tag to the focused window. 53click on a tag label applies that tag to the focused window.
@@ -67,19 +67,19 @@ Focus next window.
67Focus previous window. 67Focus previous window.
68.TP 68.TP
69.B Mod1-Return 69.B Mod1-Return
70Zooms/cycles current window to/from master area (tiling mode), toggles maximization of current window (floating mode). 70Zooms/cycles current window to/from master area (tiling layout), toggles maximization of current window (floating layout).
71.TP 71.TP
72.B Mod1-g 72.B Mod1-g
73Grow master area (tiling mode only). 73Grow master area (tiling layout only).
74.TP 74.TP
75.B Mod1-s 75.B Mod1-s
76Shrink master area (tiling mode only). 76Shrink master area (tiling layout only).
77.TP 77.TP
78.B Mod1-i 78.B Mod1-i
79Increase the number of windows in the master area (tiling mode only). 79Increase the number of windows in the master area (tiling layout only).
80.TP 80.TP
81.B Mod1-d 81.B Mod1-d
82Decrease the number of windows in the master area (tiling mode only). 82Decrease the number of windows in the master area (tiling layout only).
83.TP 83.TP
84.B Mod1-Shift-[1..n] 84.B Mod1-Shift-[1..n]
85Apply 85Apply
@@ -98,10 +98,10 @@ tag to/from current window.
98Close focused window. 98Close focused window.
99.TP 99.TP
100.B Mod1-space 100.B Mod1-space
101Toggle between tiling and floating mode (affects all windows). 101Toggle between tiling and floating layout (affects all windows).
102.TP 102.TP
103.B Mod1-Shift-space 103.B Mod1-Shift-space
104Toggle focused window between floating and non-floating state (tiling mode only). 104Toggle focused window between floating and non-floating state (tiling layout only).
105.TP 105.TP
106.B Mod1-[1..n] 106.B Mod1-[1..n]
107View all windows with 107View all windows with
@@ -121,13 +121,13 @@ Quit dwm.
121.SS Mouse commands 121.SS Mouse commands
122.TP 122.TP
123.B Mod1-Button1 123.B Mod1-Button1
124Move current window while dragging (floating mode only). 124Move current window while dragging (floating layout only).
125.TP 125.TP
126.B Mod1-Button2 126.B Mod1-Button2
127Zooms/cycles current window to/from master area (tiling mode), toggles maximization of current window (floating mode). 127Zooms/cycles current window to/from master area (tiling layout), toggles maximization of current window (floating layout).
128.TP 128.TP
129.B Mod1-Button3 129.B Mod1-Button3
130Resize current window while dragging (floating mode only). 130Resize current window while dragging (floating layout only).
131.SH CUSTOMIZATION 131.SH CUSTOMIZATION
132dwm is customized by creating a custom config.h and (re)compiling the source 132dwm is customized by creating a custom config.h and (re)compiling the source
133code. This keeps it fast, secure and simple. 133code. This keeps it fast, secure and simple.
diff --git a/dwm.h b/dwm.h
index a4dc2ba..822c33b 100644
--- a/dwm.h
+++ b/dwm.h
@@ -24,9 +24,8 @@
24 * 24 *
25 * Keys and tagging rules are organized as arrays and defined in the config.h 25 * Keys and tagging rules are organized as arrays and defined in the config.h
26 * file. These arrays are kept static in event.o and tag.o respectively, 26 * file. These arrays are kept static in event.o and tag.o respectively,
27 * because no other part of dwm needs access to them. The current mode is 27 * because no other part of dwm needs access to them. The current layout is
28 * represented by the arrange() function pointer, which wether points to 28 * represented by the lt pointer.
29 * dofloat() or dotile().
30 * 29 *
31 * To understand everything else, start reading main.c:main(). 30 * To understand everything else, start reading main.c:main().
32 */ 31 */
@@ -81,21 +80,26 @@ struct Client {
81 Window win; 80 Window win;
82}; 81};
83 82
83typedef struct {
84 const char *symbol;
85 void (*arrange)(void);
86} Layout;
87
84extern const char *tags[]; /* all tags */ 88extern const char *tags[]; /* all tags */
85extern char stext[256]; /* status text */ 89extern char stext[256]; /* status text */
86extern int bh, bmw; /* bar height, bar mode label width */
87extern int screen, sx, sy, sw, sh; /* screen geometry */ 90extern int screen, sx, sy, sw, sh; /* screen geometry */
88extern int wax, way, wah, waw; /* windowarea geometry */ 91extern int wax, way, wah, waw; /* windowarea geometry */
92extern unsigned int bh, blw; /* bar height, bar layout label width */
89extern unsigned int master, nmaster; /* master percent, number of master clients */ 93extern unsigned int master, nmaster; /* master percent, number of master clients */
90extern unsigned int ntags, numlockmask; /* number of tags, dynamic lock mask */ 94extern unsigned int ntags, numlockmask; /* number of tags, dynamic lock mask */
91extern void (*handler[LASTEvent])(XEvent *); /* event handler */ 95extern void (*handler[LASTEvent])(XEvent *); /* event handler */
92extern void (*arrange)(void); /* arrange function, indicates mode */
93extern Atom wmatom[WMLast], netatom[NetLast]; 96extern Atom wmatom[WMLast], netatom[NetLast];
94extern Bool running, selscreen, *seltag; /* seltag is array of Bool */ 97extern Bool running, selscreen, *seltag; /* seltag is array of Bool */
95extern Client *clients, *sel, *stack; /* global client list and stack */ 98extern Client *clients, *sel, *stack; /* global client list and stack */
96extern Cursor cursor[CurLast]; 99extern Cursor cursor[CurLast];
97extern DC dc; /* global draw context */ 100extern DC dc; /* global draw context */
98extern Display *dpy; 101extern Display *dpy;
102extern Layout *lt;
99extern Window root, barwin; 103extern Window root, barwin;
100 104
101/* client.c */ 105/* client.c */
@@ -124,17 +128,18 @@ extern void sendevent(Window w, Atom a, long value); /* send synthetic event to
124extern int xerror(Display *dsply, XErrorEvent *ee); /* dwm's X error handler */ 128extern int xerror(Display *dsply, XErrorEvent *ee); /* dwm's X error handler */
125 129
126/* screen.c */ 130/* screen.c */
127extern void compileregexps(void); /* initialize regexps of rules defined in config.h */ 131extern void compileregs(void); /* initialize regexps of rules defined in config.h */
128extern void dofloat(void); /* arranges all windows floating */ 132extern void dofloat(void); /* arranges all windows floating */
129extern void dotile(void); /* arranges all windows tiled */ 133extern void dotile(void); /* arranges all windows tiled */
130extern void incnmaster(Arg *arg); /* increments nmaster with arg's index value */ 134extern void incnmaster(Arg *arg); /* increments nmaster with arg's index value */
135extern void initlayouts(void); /* initialize layout array */
131extern Bool isvisible(Client *c); /* returns True if client is visible */ 136extern Bool isvisible(Client *c); /* returns True if client is visible */
132extern void resizemaster(Arg *arg); /* resizes the master percent with arg's index value */ 137extern void resizemaster(Arg *arg); /* resizes the master percent with arg's index value */
133extern void restack(void); /* restores z layers of all clients */ 138extern void restack(void); /* restores z layers of all clients */
134extern void settags(Client *c, Client *trans); /* sets tags of c */ 139extern void settags(Client *c, Client *trans); /* sets tags of c */
135extern void tag(Arg *arg); /* tags c with arg's index */ 140extern void tag(Arg *arg); /* tags c with arg's index */
136extern void togglefloat(Arg *arg); /* toggles focusesd client between floating/non-floating state */ 141extern void togglefloat(Arg *arg); /* toggles focusesd client between floating/non-floating state */
137extern void togglemode(Arg *arg); /* toggles global arrange function (dotile/dofloat) */ 142extern void togglelayout(Arg *arg); /* toggles layout */
138extern void toggletag(Arg *arg); /* toggles c tags with arg's index */ 143extern void toggletag(Arg *arg); /* toggles c tags with arg's index */
139extern void toggleview(Arg *arg); /* toggles the tag with arg's index (in)visible */ 144extern void toggleview(Arg *arg); /* toggles the tag with arg's index (in)visible */
140extern void view(Arg *arg); /* views the tag with arg's index */ 145extern void view(Arg *arg); /* views the tag with arg's index */
diff --git a/event.c b/event.c
index 4b3c1e3..d200a8d 100644
--- a/event.c
+++ b/event.c
@@ -137,10 +137,10 @@ buttonpress(XEvent *e) {
137 return; 137 return;
138 } 138 }
139 } 139 }
140 if(ev->x < x + bmw) 140 if(ev->x < x + blw)
141 switch(ev->button) { 141 switch(ev->button) {
142 case Button1: 142 case Button1:
143 togglemode(NULL); 143 togglelayout(NULL);
144 break; 144 break;
145 case Button4: 145 case Button4:
146 a.i = 1; 146 a.i = 1;
@@ -156,14 +156,14 @@ buttonpress(XEvent *e) {
156 focus(c); 156 focus(c);
157 if(CLEANMASK(ev->state) != MODKEY) 157 if(CLEANMASK(ev->state) != MODKEY)
158 return; 158 return;
159 if(ev->button == Button1 && (arrange == dofloat || c->isfloat)) { 159 if(ev->button == Button1 && (lt->arrange == dofloat || c->isfloat)) {
160 restack(); 160 restack();
161 movemouse(c); 161 movemouse(c);
162 } 162 }
163 else if(ev->button == Button2) 163 else if(ev->button == Button2)
164 zoom(NULL); 164 zoom(NULL);
165 else if(ev->button == Button3 165 else if(ev->button == Button3
166 && (arrange == dofloat || c->isfloat) && !c->isfixed) 166 && (lt->arrange == dofloat || c->isfloat) && !c->isfixed)
167 { 167 {
168 restack(); 168 restack();
169 resizemouse(c); 169 resizemouse(c);
@@ -181,7 +181,7 @@ configurerequest(XEvent *e) {
181 c->ismax = False; 181 c->ismax = False;
182 if(ev->value_mask & CWBorderWidth) 182 if(ev->value_mask & CWBorderWidth)
183 c->border = ev->border_width; 183 c->border = ev->border_width;
184 if(c->isfixed || c->isfloat || (arrange == dofloat)) { 184 if(c->isfixed || c->isfloat || (lt->arrange == dofloat)) {
185 if(ev->value_mask & CWX) 185 if(ev->value_mask & CWX)
186 c->x = ev->x; 186 c->x = ev->x;
187 if(ev->value_mask & CWY) 187 if(ev->value_mask & CWY)
@@ -310,7 +310,7 @@ propertynotify(XEvent *e) {
310 case XA_WM_TRANSIENT_FOR: 310 case XA_WM_TRANSIENT_FOR:
311 XGetTransientForHint(dpy, c->win, &trans); 311 XGetTransientForHint(dpy, c->win, &trans);
312 if(!c->isfloat && (c->isfloat = (trans != 0))) 312 if(!c->isfloat && (c->isfloat = (trans != 0)))
313 arrange(); 313 lt->arrange();
314 break; 314 break;
315 case XA_WM_NORMAL_HINTS: 315 case XA_WM_NORMAL_HINTS:
316 updatesizehints(c); 316 updatesizehints(c);
diff --git a/main.c b/main.c
index 3453b59..8ecf9fa 100644
--- a/main.c
+++ b/main.c
@@ -18,8 +18,8 @@
18/* extern */ 18/* extern */
19 19
20char stext[256]; 20char stext[256];
21int bh, bmw, screen, sx, sy, sw, sh, wax, way, waw, wah; 21int screen, sx, sy, sw, sh, wax, way, waw, wah;
22unsigned int ntags, numlockmask; 22unsigned int bh, ntags, numlockmask;
23Atom wmatom[WMLast], netatom[NetLast]; 23Atom wmatom[WMLast], netatom[NetLast];
24Bool running = True; 24Bool running = True;
25Bool *seltag; 25Bool *seltag;
@@ -246,7 +246,7 @@ setup(void) {
246 wa.cursor = cursor[CurNormal]; 246 wa.cursor = cursor[CurNormal];
247 XChangeWindowAttributes(dpy, root, CWEventMask | CWCursor, &wa); 247 XChangeWindowAttributes(dpy, root, CWEventMask | CWCursor, &wa);
248 grabkeys(); 248 grabkeys();
249 compileregexps(); 249 compileregs();
250 for(ntags = 0; tags[ntags]; ntags++); 250 for(ntags = 0; tags[ntags]; ntags++);
251 seltag = emallocz(sizeof(Bool) * ntags); 251 seltag = emallocz(sizeof(Bool) * ntags);
252 seltag[0] = True; 252 seltag[0] = True;
@@ -262,7 +262,7 @@ setup(void) {
262 sx = sy = 0; 262 sx = sy = 0;
263 sw = DisplayWidth(dpy, screen); 263 sw = DisplayWidth(dpy, screen);
264 sh = DisplayHeight(dpy, screen); 264 sh = DisplayHeight(dpy, screen);
265 bmw = textw(TILESYMBOL) > textw(FLOATSYMBOL) ? textw(TILESYMBOL) : textw(FLOATSYMBOL); 265 initlayouts();
266 /* bar */ 266 /* bar */
267 dc.h = bh = dc.font.height + 2; 267 dc.h = bh = dc.font.height + 2;
268 wa.override_redirect = 1; 268 wa.override_redirect = 1;
@@ -312,8 +312,8 @@ drawstatus(void) {
312 drawtext(tags[i], dc.norm, sel && sel->tags[i], isoccupied(i)); 312 drawtext(tags[i], dc.norm, sel && sel->tags[i], isoccupied(i));
313 dc.x += dc.w; 313 dc.x += dc.w;
314 } 314 }
315 dc.w = bmw; 315 dc.w = blw;
316 drawtext(arrange == dofloat ? FLOATSYMBOL : TILESYMBOL, dc.norm, False, False); 316 drawtext(lt->symbol, dc.norm, False, False);
317 x = dc.x + dc.w; 317 x = dc.x + dc.w;
318 dc.w = textw(stext); 318 dc.w = textw(stext);
319 dc.x = sw - dc.w; 319 dc.x = sw - dc.w;
diff --git a/screen.c b/screen.c
index 4e97f09..3f186e6 100644
--- a/screen.c
+++ b/screen.c
@@ -9,9 +9,10 @@
9#include <sys/types.h> 9#include <sys/types.h>
10#include <X11/Xutil.h> 10#include <X11/Xutil.h>
11 11
12void (*arrange)(void) = DEFMODE;
13unsigned int master = MASTER; 12unsigned int master = MASTER;
14unsigned int nmaster = NMASTER; 13unsigned int nmaster = NMASTER;
14unsigned int blw = 0;
15Layout *lt = NULL;
15 16
16/* static */ 17/* static */
17 18
@@ -24,39 +25,41 @@ typedef struct {
24typedef struct { 25typedef struct {
25 regex_t *propregex; 26 regex_t *propregex;
26 regex_t *tagregex; 27 regex_t *tagregex;
27} Regexps; 28} Regs;
28 29
30LAYOUTS
29TAGS 31TAGS
30RULES 32RULES
31 33
32static Regexps *regexps = NULL; 34static Regs *regs = NULL;
33static unsigned int len = 0; 35static unsigned int nrules = 0;
36static unsigned int nlayouts = 0;
34 37
35/* extern */ 38/* extern */
36 39
37void 40void
38compileregexps(void) { 41compileregs(void) {
39 unsigned int i; 42 unsigned int i;
40 regex_t *reg; 43 regex_t *reg;
41 44
42 if(regexps) 45 if(regs)
43 return; 46 return;
44 len = sizeof rule / sizeof rule[0]; 47 nrules = sizeof rule / sizeof rule[0];
45 regexps = emallocz(len * sizeof(Regexps)); 48 regs = emallocz(nrules * sizeof(Regs));
46 for(i = 0; i < len; i++) { 49 for(i = 0; i < nrules; i++) {
47 if(rule[i].prop) { 50 if(rule[i].prop) {
48 reg = emallocz(sizeof(regex_t)); 51 reg = emallocz(sizeof(regex_t));
49 if(regcomp(reg, rule[i].prop, REG_EXTENDED)) 52 if(regcomp(reg, rule[i].prop, REG_EXTENDED))
50 free(reg); 53 free(reg);
51 else 54 else
52 regexps[i].propregex = reg; 55 regs[i].propregex = reg;
53 } 56 }
54 if(rule[i].tags) { 57 if(rule[i].tags) {
55 reg = emallocz(sizeof(regex_t)); 58 reg = emallocz(sizeof(regex_t));
56 if(regcomp(reg, rule[i].tags, REG_EXTENDED)) 59 if(regcomp(reg, rule[i].tags, REG_EXTENDED))
57 free(reg); 60 free(reg);
58 else 61 else
59 regexps[i].tagregex = reg; 62 regs[i].tagregex = reg;
60 } 63 }
61 } 64 }
62} 65}
@@ -138,16 +141,29 @@ dotile(void) {
138 141
139void 142void
140incnmaster(Arg *arg) { 143incnmaster(Arg *arg) {
141 if((arrange == dofloat) || (nmaster + arg->i < 1) 144 if((lt->arrange == dofloat) || (nmaster + arg->i < 1)
142 || (wah / (nmaster + arg->i) <= 2 * BORDERPX)) 145 || (wah / (nmaster + arg->i) <= 2 * BORDERPX))
143 return; 146 return;
144 nmaster += arg->i; 147 nmaster += arg->i;
145 if(sel) 148 if(sel)
146 arrange(); 149 lt->arrange();
147 else 150 else
148 drawstatus(); 151 drawstatus();
149} 152}
150 153
154void
155initlayouts(void) {
156 unsigned int i, w;
157
158 lt = &layout[0];
159 nlayouts = sizeof layout / sizeof layout[0];
160 for(blw = i = 0; i < nlayouts; i++) {
161 w = textw(layout[i].symbol);
162 if(w > blw)
163 blw = w;
164 }
165}
166
151Bool 167Bool
152isvisible(Client *c) { 168isvisible(Client *c) {
153 unsigned int i; 169 unsigned int i;
@@ -160,7 +176,7 @@ isvisible(Client *c) {
160 176
161void 177void
162resizemaster(Arg *arg) { 178resizemaster(Arg *arg) {
163 if(arrange != dotile) 179 if(lt->arrange != dotile)
164 return; 180 return;
165 if(arg->i == 0) 181 if(arg->i == 0)
166 master = MASTER; 182 master = MASTER;
@@ -170,7 +186,7 @@ resizemaster(Arg *arg) {
170 return; 186 return;
171 master += arg->i; 187 master += arg->i;
172 } 188 }
173 arrange(); 189 lt->arrange();
174} 190}
175 191
176void 192void
@@ -181,9 +197,9 @@ restack(void) {
181 drawstatus(); 197 drawstatus();
182 if(!sel) 198 if(!sel)
183 return; 199 return;
184 if(sel->isfloat || arrange == dofloat) 200 if(sel->isfloat || lt->arrange == dofloat)
185 XRaiseWindow(dpy, sel->win); 201 XRaiseWindow(dpy, sel->win);
186 if(arrange != dofloat) { 202 if(lt->arrange != dofloat) {
187 if(!sel->isfloat) 203 if(!sel->isfloat)
188 XLowerWindow(dpy, sel->win); 204 XLowerWindow(dpy, sel->win);
189 for(c = nexttiled(clients); c; c = nexttiled(c->next)) { 205 for(c = nexttiled(clients); c; c = nexttiled(c->next)) {
@@ -212,11 +228,11 @@ settags(Client *c, Client *trans) {
212 snprintf(prop, sizeof prop, "%s:%s:%s", 228 snprintf(prop, sizeof prop, "%s:%s:%s",
213 ch.res_class ? ch.res_class : "", 229 ch.res_class ? ch.res_class : "",
214 ch.res_name ? ch.res_name : "", c->name); 230 ch.res_name ? ch.res_name : "", c->name);
215 for(i = 0; i < len; i++) 231 for(i = 0; i < nrules; i++)
216 if(regexps[i].propregex && !regexec(regexps[i].propregex, prop, 1, &tmp, 0)) { 232 if(regs[i].propregex && !regexec(regs[i].propregex, prop, 1, &tmp, 0)) {
217 c->isfloat = rule[i].isfloat; 233 c->isfloat = rule[i].isfloat;
218 for(j = 0; regexps[i].tagregex && j < ntags; j++) { 234 for(j = 0; regs[i].tagregex && j < ntags; j++) {
219 if(!regexec(regexps[i].tagregex, tags[j], 1, &tmp, 0)) { 235 if(!regexec(regs[i].tagregex, tags[j], 1, &tmp, 0)) {
220 matched = True; 236 matched = True;
221 c->tags[j] = True; 237 c->tags[j] = True;
222 } 238 }
@@ -242,15 +258,15 @@ tag(Arg *arg) {
242 sel->tags[i] = (arg->i == -1) ? True : False; 258 sel->tags[i] = (arg->i == -1) ? True : False;
243 if(arg->i >= 0 && arg->i < ntags) 259 if(arg->i >= 0 && arg->i < ntags)
244 sel->tags[arg->i] = True; 260 sel->tags[arg->i] = True;
245 arrange(); 261 lt->arrange();
246} 262}
247 263
248void 264void
249togglefloat(Arg *arg) { 265togglefloat(Arg *arg) {
250 if(!sel || arrange == dofloat) 266 if(!sel || lt->arrange == dofloat)
251 return; 267 return;
252 sel->isfloat = !sel->isfloat; 268 sel->isfloat = !sel->isfloat;
253 arrange(); 269 lt->arrange();
254} 270}
255 271
256void 272void
@@ -263,14 +279,20 @@ toggletag(Arg *arg) {
263 for(i = 0; i < ntags && !sel->tags[i]; i++); 279 for(i = 0; i < ntags && !sel->tags[i]; i++);
264 if(i == ntags) 280 if(i == ntags)
265 sel->tags[arg->i] = True; 281 sel->tags[arg->i] = True;
266 arrange(); 282 lt->arrange();
267} 283}
268 284
269void 285void
270togglemode(Arg *arg) { 286togglelayout(Arg *arg) {
271 arrange = (arrange == dofloat) ? dotile : dofloat; 287 unsigned int i;
288
289 for(i = 0; i < nlayouts && lt != &layout[i]; i++);
290 if(i == nlayouts - 1)
291 lt = &layout[0];
292 else
293 lt = &layout[++i];
272 if(sel) 294 if(sel)
273 arrange(); 295 lt->arrange();
274 else 296 else
275 drawstatus(); 297 drawstatus();
276} 298}
@@ -283,7 +305,7 @@ toggleview(Arg *arg) {
283 for(i = 0; i < ntags && !seltag[i]; i++); 305 for(i = 0; i < ntags && !seltag[i]; i++);
284 if(i == ntags) 306 if(i == ntags)
285 seltag[arg->i] = True; /* cannot toggle last view */ 307 seltag[arg->i] = True; /* cannot toggle last view */
286 arrange(); 308 lt->arrange();
287} 309}
288 310
289void 311void
@@ -294,5 +316,5 @@ view(Arg *arg) {
294 seltag[i] = (arg->i == -1) ? True : False; 316 seltag[i] = (arg->i == -1) ? True : False;
295 if(arg->i >= 0 && arg->i < ntags) 317 if(arg->i >= 0 && arg->i < ntags)
296 seltag[arg->i] = True; 318 seltag[arg->i] = True;
297 arrange(); 319 lt->arrange();
298} 320}