58 enum { ColBorder, ColFG, ColBG, ColLast }; /* color */ |
58 enum { ColBorder, ColFG, ColBG, ColLast }; /* color */ |
59 enum { NetSupported, NetWMName, NetLast }; /* EWMH atoms */ |
59 enum { NetSupported, NetWMName, NetLast }; /* EWMH atoms */ |
60 enum { WMProtocols, WMDelete, WMName, WMState, WMLast };/* default atoms */ |
60 enum { WMProtocols, WMDelete, WMName, WMState, WMLast };/* default atoms */ |
61 |
61 |
62 /* typedefs */ |
62 /* typedefs */ |
|
63 typedef unsigned int uint; |
63 typedef struct Client Client; |
64 typedef struct Client Client; |
64 struct Client { |
65 struct Client { |
65 char name[256]; |
66 char name[256]; |
66 int x, y, w, h; |
67 int x, y, w, h; |
67 int basew, baseh, incw, inch, maxw, maxh, minw, minh; |
68 int basew, baseh, incw, inch, maxw, maxh, minw, minh; |
68 int minax, maxax, minay, maxay; |
69 int minax, maxax, minay, maxay; |
69 long flags; |
70 long flags; |
70 unsigned int bw, oldbw; |
71 uint bw, oldbw; |
71 Bool isbanned, isfixed, isfloating, isurgent; |
72 Bool isbanned, isfixed, isfloating, isurgent; |
72 unsigned int tags; |
73 uint tags; |
73 Client *next; |
74 Client *next; |
74 Client *prev; |
75 Client *prev; |
75 Client *snext; |
76 Client *snext; |
76 Window win; |
77 Window win; |
77 }; |
78 }; |
128 void detach(Client *c); |
129 void detach(Client *c); |
129 void detachstack(Client *c); |
130 void detachstack(Client *c); |
130 void drawbar(void); |
131 void drawbar(void); |
131 void drawsquare(Bool filled, Bool empty, Bool invert, unsigned long col[ColLast]); |
132 void drawsquare(Bool filled, Bool empty, Bool invert, unsigned long col[ColLast]); |
132 void drawtext(const char *text, unsigned long col[ColLast], Bool invert); |
133 void drawtext(const char *text, unsigned long col[ColLast], Bool invert); |
133 void *emallocz(unsigned int size); |
134 void *emallocz(uint size); |
134 void enternotify(XEvent *e); |
135 void enternotify(XEvent *e); |
135 void eprint(const char *errstr, ...); |
136 void eprint(const char *errstr, ...); |
136 void expose(XEvent *e); |
137 void expose(XEvent *e); |
137 void focus(Client *c); |
138 void focus(Client *c); |
138 void focusin(XEvent *e); |
139 void focusin(XEvent *e); |
139 void focusnext(const void *arg); |
140 void focusnext(const void *arg); |
140 void focusprev(const void *arg); |
141 void focusprev(const void *arg); |
141 Client *getclient(Window w); |
142 Client *getclient(Window w); |
142 unsigned long getcolor(const char *colstr); |
143 unsigned long getcolor(const char *colstr); |
143 long getstate(Window w); |
144 long getstate(Window w); |
144 Bool gettextprop(Window w, Atom atom, char *text, unsigned int size); |
145 Bool gettextprop(Window w, Atom atom, char *text, uint size); |
145 void grabbuttons(Client *c, Bool focused); |
146 void grabbuttons(Client *c, Bool focused); |
146 void grabkeys(void); |
147 void grabkeys(void); |
147 void initfont(const char *fontstr); |
148 void initfont(const char *fontstr); |
148 Bool isoccupied(unsigned int t); |
149 Bool isoccupied(uint t); |
149 Bool isprotodel(Client *c); |
150 Bool isprotodel(Client *c); |
150 Bool isurgent(unsigned int t); |
151 Bool isurgent(uint t); |
151 Bool isvisible(Client *c); |
152 Bool isvisible(Client *c); |
152 void keypress(XEvent *e); |
153 void keypress(XEvent *e); |
153 void killclient(const void *arg); |
154 void killclient(const void *arg); |
154 void manage(Window w, XWindowAttributes *wa); |
155 void manage(Window w, XWindowAttributes *wa); |
155 void mappingnotify(XEvent *e); |
156 void mappingnotify(XEvent *e); |
166 void setclientstate(Client *c, long state); |
167 void setclientstate(Client *c, long state); |
167 void setmfact(const void *arg); |
168 void setmfact(const void *arg); |
168 void setup(void); |
169 void setup(void); |
169 void spawn(const void *arg); |
170 void spawn(const void *arg); |
170 void tag(const void *arg); |
171 void tag(const void *arg); |
171 unsigned int textnw(const char *text, unsigned int len); |
172 uint textnw(const char *text, uint len); |
172 unsigned int textw(const char *text); |
173 uint textw(const char *text); |
173 void tile(void); |
174 void tile(void); |
174 void tileresize(Client *c, int x, int y, int w, int h); |
175 void tileresize(Client *c, int x, int y, int w, int h); |
175 void togglebar(const void *arg); |
176 void togglebar(const void *arg); |
176 void togglefloating(const void *arg); |
177 void togglefloating(const void *arg); |
177 void togglelayout(const void *arg); |
178 void togglelayout(const void *arg); |
196 /* variables */ |
197 /* variables */ |
197 char stext[256]; |
198 char stext[256]; |
198 int screen, sx, sy, sw, sh; |
199 int screen, sx, sy, sw, sh; |
199 int bx, by, bw, bh, blw, wx, wy, ww, wh; |
200 int bx, by, bw, bh, blw, wx, wy, ww, wh; |
200 int mx, my, mw, mh, tx, ty, tw, th; |
201 int mx, my, mw, mh, tx, ty, tw, th; |
201 unsigned int seltags = 0; |
202 uint seltags = 0; |
202 int (*xerrorxlib)(Display *, XErrorEvent *); |
203 int (*xerrorxlib)(Display *, XErrorEvent *); |
203 unsigned int numlockmask = 0; |
204 uint numlockmask = 0; |
204 void (*handler[LASTEvent]) (XEvent *) = { |
205 void (*handler[LASTEvent]) (XEvent *) = { |
205 [ButtonPress] = buttonpress, |
206 [ButtonPress] = buttonpress, |
206 [ConfigureRequest] = configurerequest, |
207 [ConfigureRequest] = configurerequest, |
207 [ConfigureNotify] = configurenotify, |
208 [ConfigureNotify] = configurenotify, |
208 [DestroyNotify] = destroynotify, |
209 [DestroyNotify] = destroynotify, |
216 [UnmapNotify] = unmapnotify |
217 [UnmapNotify] = unmapnotify |
217 }; |
218 }; |
218 Atom wmatom[WMLast], netatom[NetLast]; |
219 Atom wmatom[WMLast], netatom[NetLast]; |
219 Bool otherwm, readin; |
220 Bool otherwm, readin; |
220 Bool running = True; |
221 Bool running = True; |
221 unsigned int tagset[] = {1, 1}; /* after start, first tag is selected */ |
222 uint tagset[] = {1, 1}; /* after start, first tag is selected */ |
222 Client *clients = NULL; |
223 Client *clients = NULL; |
223 Client *sel = NULL; |
224 Client *sel = NULL; |
224 Client *stack = NULL; |
225 Client *stack = NULL; |
225 Cursor cursor[CurLast]; |
226 Cursor cursor[CurLast]; |
226 Display *dpy; |
227 Display *dpy; |
230 Window root, barwin; |
231 Window root, barwin; |
231 |
232 |
232 /* configuration, allows nested code to access above variables */ |
233 /* configuration, allows nested code to access above variables */ |
233 #include "config.h" |
234 #include "config.h" |
234 |
235 |
235 /* check if all tags will fit into a unsigned int bitarray. */ |
236 /* check if all tags will fit into a uint bitarray. */ |
236 static char tags_is_a_sign_that_your_IQ[sizeof(int) * 8 < LENGTH(tags) ? -1 : 1]; |
237 static char tags_is_a_sign_that_your_IQ[sizeof(int) * 8 < LENGTH(tags) ? -1 : 1]; |
237 |
238 |
238 /* function implementations */ |
239 /* function implementations */ |
239 |
240 |
240 void |
241 void |
241 applyrules(Client *c) { |
242 applyrules(Client *c) { |
242 unsigned int i; |
243 uint i; |
243 Rule *r; |
244 Rule *r; |
244 XClassHint ch = { 0 }; |
245 XClassHint ch = { 0 }; |
245 |
246 |
246 /* rule matching */ |
247 /* rule matching */ |
247 XGetClassHint(dpy, c->win, &ch); |
248 XGetClassHint(dpy, c->win, &ch); |
559 } |
560 } |
560 |
561 |
561 void |
562 void |
562 drawtext(const char *text, unsigned long col[ColLast], Bool invert) { |
563 drawtext(const char *text, unsigned long col[ColLast], Bool invert) { |
563 int x, y, w, h; |
564 int x, y, w, h; |
564 unsigned int len, olen; |
565 uint len, olen; |
565 XRectangle r = { dc.x, dc.y, dc.w, dc.h }; |
566 XRectangle r = { dc.x, dc.y, dc.w, dc.h }; |
566 char buf[256]; |
567 char buf[256]; |
567 |
568 |
568 XSetForeground(dpy, dc.gc, col[invert ? ColFG : ColBG]); |
569 XSetForeground(dpy, dc.gc, col[invert ? ColFG : ColBG]); |
569 XFillRectangles(dpy, dc.drawable, dc.gc, &r, 1); |
570 XFillRectangles(dpy, dc.drawable, dc.gc, &r, 1); |
594 else |
595 else |
595 XDrawString(dpy, dc.drawable, dc.gc, x, y, buf, len); |
596 XDrawString(dpy, dc.drawable, dc.gc, x, y, buf, len); |
596 } |
597 } |
597 |
598 |
598 void * |
599 void * |
599 emallocz(unsigned int size) { |
600 emallocz(uint size) { |
600 void *res = calloc(1, size); |
601 void *res = calloc(1, size); |
601 |
602 |
602 if(!res) |
603 if(!res) |
603 eprint("fatal: could not malloc() %u bytes\n", size); |
604 eprint("fatal: could not malloc() %u bytes\n", size); |
604 return res; |
605 return res; |
761 } |
762 } |
762 |
763 |
763 void |
764 void |
764 grabbuttons(Client *c, Bool focused) { |
765 grabbuttons(Client *c, Bool focused) { |
765 int i, j; |
766 int i, j; |
766 unsigned int buttons[] = { Button1, Button2, Button3 }; |
767 uint buttons[] = { Button1, Button2, Button3 }; |
767 unsigned int modifiers[] = { MODKEY, MODKEY|LockMask, MODKEY|numlockmask, |
768 uint modifiers[] = { MODKEY, MODKEY|LockMask, MODKEY|numlockmask, |
768 MODKEY|numlockmask|LockMask} ; |
769 MODKEY|numlockmask|LockMask} ; |
769 |
770 |
770 XUngrabButton(dpy, AnyButton, AnyModifier, c->win); |
771 XUngrabButton(dpy, AnyButton, AnyModifier, c->win); |
771 if(focused) |
772 if(focused) |
772 for(i = 0; i < LENGTH(buttons); i++) |
773 for(i = 0; i < LENGTH(buttons); i++) |
1439 sel->tags = *(int *)arg & TAGMASK; |
1440 sel->tags = *(int *)arg & TAGMASK; |
1440 arrange(); |
1441 arrange(); |
1441 } |
1442 } |
1442 } |
1443 } |
1443 |
1444 |
1444 unsigned int |
1445 uint |
1445 textnw(const char *text, unsigned int len) { |
1446 textnw(const char *text, uint len) { |
1446 XRectangle r; |
1447 XRectangle r; |
1447 |
1448 |
1448 if(dc.font.set) { |
1449 if(dc.font.set) { |
1449 XmbTextExtents(dc.font.set, text, len, NULL, &r); |
1450 XmbTextExtents(dc.font.set, text, len, NULL, &r); |
1450 return r.width; |
1451 return r.width; |
1451 } |
1452 } |
1452 return XTextWidth(dc.font.xfont, text, len); |
1453 return XTextWidth(dc.font.xfont, text, len); |
1453 } |
1454 } |
1454 |
1455 |
1455 unsigned int |
1456 uint |
1456 textw(const char *text) { |
1457 textw(const char *text) { |
1457 return textnw(text, strlen(text)) + dc.font.height; |
1458 return textnw(text, strlen(text)) + dc.font.height; |
1458 } |
1459 } |
1459 |
1460 |
1460 void |
1461 void |
1461 tile(void) { |
1462 tile(void) { |
1462 int x, y, h, w; |
1463 int x, y, h, w; |
1463 unsigned int i, n; |
1464 uint i, n; |
1464 Client *c; |
1465 Client *c; |
1465 |
1466 |
1466 for(n = 0, c = nextunfloating(clients); c; c = nextunfloating(c->next), n++); |
1467 for(n = 0, c = nextunfloating(clients); c; c = nextunfloating(c->next), n++); |
1467 if(n == 0) |
1468 if(n == 0) |
1468 return; |
1469 return; |