summaryrefslogtreecommitdiffstats
path: root/dwm.c
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--dwm.c88
1 files changed, 42 insertions, 46 deletions
diff --git a/dwm.c b/dwm.c
index 48785c7..29157de 100644
--- a/dwm.c
+++ b/dwm.c
@@ -63,21 +63,17 @@ enum { WMProtocols, WMDelete, WMName, WMState, WMLast };/* default atoms */
63enum { ClkTagBar, ClkLtSymbol, ClkStatusText, ClkWinTitle, 63enum { ClkTagBar, ClkLtSymbol, ClkStatusText, ClkWinTitle,
64 ClkClientWin, ClkRootWin, ClkLast }; /* clicks */ 64 ClkClientWin, ClkRootWin, ClkLast }; /* clicks */
65 65
66/* typedefs */
67typedef unsigned int uint;
68typedef unsigned long ulong;
69
70typedef union { 66typedef union {
71 int i; 67 int i;
72 uint ui; 68 unsigned int ui;
73 float f; 69 float f;
74 void *v; 70 void *v;
75} Arg; 71} Arg;
76 72
77typedef struct { 73typedef struct {
78 uint click; 74 unsigned int click;
79 uint mask; 75 unsigned int mask;
80 uint button; 76 unsigned int button;
81 void (*func)(const Arg *arg); 77 void (*func)(const Arg *arg);
82 const Arg arg; 78 const Arg arg;
83} Button; 79} Button;
@@ -89,7 +85,7 @@ struct Client {
89 int x, y, w, h; 85 int x, y, w, h;
90 int basew, baseh, incw, inch, maxw, maxh, minw, minh; 86 int basew, baseh, incw, inch, maxw, maxh, minw, minh;
91 int bw, oldbw; 87 int bw, oldbw;
92 uint tags; 88 unsigned int tags;
93 Bool isfixed, isfloating, isurgent; 89 Bool isfixed, isfloating, isurgent;
94 Client *next; 90 Client *next;
95 Client *snext; 91 Client *snext;
@@ -98,8 +94,8 @@ struct Client {
98 94
99typedef struct { 95typedef struct {
100 int x, y, w, h; 96 int x, y, w, h;
101 ulong norm[ColLast]; 97 unsigned long norm[ColLast];
102 ulong sel[ColLast]; 98 unsigned long sel[ColLast];
103 Drawable drawable; 99 Drawable drawable;
104 GC gc; 100 GC gc;
105 struct { 101 struct {
@@ -112,7 +108,7 @@ typedef struct {
112} DC; /* draw context */ 108} DC; /* draw context */
113 109
114typedef struct { 110typedef struct {
115 uint mod; 111 unsigned int mod;
116 KeySym keysym; 112 KeySym keysym;
117 void (*func)(const Arg *); 113 void (*func)(const Arg *);
118 const Arg arg; 114 const Arg arg;
@@ -127,7 +123,7 @@ typedef struct {
127 const char *class; 123 const char *class;
128 const char *instance; 124 const char *instance;
129 const char *title; 125 const char *title;
130 uint tags; 126 unsigned int tags;
131 Bool isfloating; 127 Bool isfloating;
132} Rule; 128} Rule;
133 129
@@ -148,23 +144,23 @@ static void detach(Client *c);
148static void detachstack(Client *c); 144static void detachstack(Client *c);
149static void die(const char *errstr, ...); 145static void die(const char *errstr, ...);
150static void drawbar(void); 146static void drawbar(void);
151static void drawsquare(Bool filled, Bool empty, Bool invert, ulong col[ColLast]); 147static void drawsquare(Bool filled, Bool empty, Bool invert, unsigned long col[ColLast]);
152static void drawtext(const char *text, ulong col[ColLast], Bool invert); 148static void drawtext(const char *text, unsigned long col[ColLast], Bool invert);
153static void enternotify(XEvent *e); 149static void enternotify(XEvent *e);
154static void expose(XEvent *e); 150static void expose(XEvent *e);
155static void focus(Client *c); 151static void focus(Client *c);
156static void focusin(XEvent *e); 152static void focusin(XEvent *e);
157static void focusstack(const Arg *arg); 153static void focusstack(const Arg *arg);
158static Client *getclient(Window w); 154static Client *getclient(Window w);
159static ulong getcolor(const char *colstr); 155static unsigned long getcolor(const char *colstr);
160static long getstate(Window w); 156static long getstate(Window w);
161static Bool gettextprop(Window w, Atom atom, char *text, uint size); 157static Bool gettextprop(Window w, Atom atom, char *text, unsigned int size);
162static void grabbuttons(Client *c, Bool focused); 158static void grabbuttons(Client *c, Bool focused);
163static void grabkeys(void); 159static void grabkeys(void);
164static void initfont(const char *fontstr); 160static void initfont(const char *fontstr);
165static Bool isoccupied(uint t); 161static Bool isoccupied(unsigned int t);
166static Bool isprotodel(Client *c); 162static Bool isprotodel(Client *c);
167static Bool isurgent(uint t); 163static Bool isurgent(unsigned int t);
168static void keypress(XEvent *e); 164static void keypress(XEvent *e);
169static void killclient(const Arg *arg); 165static void killclient(const Arg *arg);
170static void manage(Window w, XWindowAttributes *wa); 166static void manage(Window w, XWindowAttributes *wa);
@@ -186,7 +182,7 @@ static void setmfact(const Arg *arg);
186static void setup(void); 182static void setup(void);
187static void spawn(const Arg *arg); 183static void spawn(const Arg *arg);
188static void tag(const Arg *arg); 184static void tag(const Arg *arg);
189static int textnw(const char *text, uint len); 185static int textnw(const char *text, unsigned int len);
190static void tile(void); 186static void tile(void);
191static void togglebar(const Arg *arg); 187static void togglebar(const Arg *arg);
192static void togglefloating(const Arg *arg); 188static void togglefloating(const Arg *arg);
@@ -209,9 +205,9 @@ static void zoom(const Arg *arg);
209static char stext[256]; 205static char stext[256];
210static int screen, sx, sy, sw, sh; 206static int screen, sx, sy, sw, sh;
211static int by, bh, blw, wx, wy, ww, wh; 207static int by, bh, blw, wx, wy, ww, wh;
212static uint seltags = 0, sellt = 0; 208static unsigned int seltags = 0, sellt = 0;
213static int (*xerrorxlib)(Display *, XErrorEvent *); 209static int (*xerrorxlib)(Display *, XErrorEvent *);
214static uint numlockmask = 0; 210static unsigned int numlockmask = 0;
215static void (*handler[LASTEvent]) (XEvent *) = { 211static void (*handler[LASTEvent]) (XEvent *) = {
216 [ButtonPress] = buttonpress, 212 [ButtonPress] = buttonpress,
217 [ConfigureRequest] = configurerequest, 213 [ConfigureRequest] = configurerequest,
@@ -229,7 +225,7 @@ static void (*handler[LASTEvent]) (XEvent *) = {
229static Atom wmatom[WMLast], netatom[NetLast]; 225static Atom wmatom[WMLast], netatom[NetLast];
230static Bool otherwm, readin; 226static Bool otherwm, readin;
231static Bool running = True; 227static Bool running = True;
232static uint tagset[] = {1, 1}; /* after start, first tag is selected */ 228static unsigned int tagset[] = {1, 1}; /* after start, first tag is selected */
233static Client *clients = NULL; 229static Client *clients = NULL;
234static Client *sel = NULL; 230static Client *sel = NULL;
235static Client *stack = NULL; 231static Client *stack = NULL;
@@ -241,13 +237,13 @@ static Window root, barwin;
241/* configuration, allows nested code to access above variables */ 237/* configuration, allows nested code to access above variables */
242#include "config.h" 238#include "config.h"
243 239
244/* compile-time check if all tags fit into an uint bit array. */ 240/* compile-time check if all tags fit into an unsigned int bit array. */
245struct NumTags { char limitexceeded[sizeof(uint) * 8 < LENGTH(tags) ? -1 : 1]; }; 241struct NumTags { char limitexceeded[sizeof(unsigned int) * 8 < LENGTH(tags) ? -1 : 1]; };
246 242
247/* function implementations */ 243/* function implementations */
248void 244void
249applyrules(Client *c) { 245applyrules(Client *c) {
250 uint i; 246 unsigned int i;
251 Rule *r; 247 Rule *r;
252 XClassHint ch = { 0 }; 248 XClassHint ch = { 0 };
253 249
@@ -304,7 +300,7 @@ attachstack(Client *c) {
304 300
305void 301void
306buttonpress(XEvent *e) { 302buttonpress(XEvent *e) {
307 uint i, x, click; 303 unsigned int i, x, click;
308 Arg arg = {0}; 304 Arg arg = {0};
309 Client *c; 305 Client *c;
310 XButtonPressedEvent *ev = &e->xbutton; 306 XButtonPressedEvent *ev = &e->xbutton;
@@ -546,7 +542,7 @@ drawbar(void) {
546} 542}
547 543
548void 544void
549drawsquare(Bool filled, Bool empty, Bool invert, ulong col[ColLast]) { 545drawsquare(Bool filled, Bool empty, Bool invert, unsigned long col[ColLast]) {
550 int x; 546 int x;
551 XGCValues gcv; 547 XGCValues gcv;
552 XRectangle r = { dc.x, dc.y, dc.w, dc.h }; 548 XRectangle r = { dc.x, dc.y, dc.w, dc.h };
@@ -567,7 +563,7 @@ drawsquare(Bool filled, Bool empty, Bool invert, ulong col[ColLast]) {
567} 563}
568 564
569void 565void
570drawtext(const char *text, ulong col[ColLast], Bool invert) { 566drawtext(const char *text, unsigned long col[ColLast], Bool invert) {
571 int i, x, y, h, len, olen; 567 int i, x, y, h, len, olen;
572 XRectangle r = { dc.x, dc.y, dc.w, dc.h }; 568 XRectangle r = { dc.x, dc.y, dc.w, dc.h };
573 char buf[256]; 569 char buf[256];
@@ -679,7 +675,7 @@ getclient(Window w) {
679 return c; 675 return c;
680} 676}
681 677
682ulong 678unsigned long
683getcolor(const char *colstr) { 679getcolor(const char *colstr) {
684 Colormap cmap = DefaultColormap(dpy, screen); 680 Colormap cmap = DefaultColormap(dpy, screen);
685 XColor color; 681 XColor color;
@@ -694,7 +690,7 @@ getstate(Window w) {
694 int format, status; 690 int format, status;
695 long result = -1; 691 long result = -1;
696 unsigned char *p = NULL; 692 unsigned char *p = NULL;
697 ulong n, extra; 693 unsigned long n, extra;
698 Atom real; 694 Atom real;
699 695
700 status = XGetWindowProperty(dpy, w, wmatom[WMState], 0L, 2L, False, wmatom[WMState], 696 status = XGetWindowProperty(dpy, w, wmatom[WMState], 0L, 2L, False, wmatom[WMState],
@@ -708,7 +704,7 @@ getstate(Window w) {
708} 704}
709 705
710Bool 706Bool
711gettextprop(Window w, Atom atom, char *text, uint size) { 707gettextprop(Window w, Atom atom, char *text, unsigned int size) {
712 char **list = NULL; 708 char **list = NULL;
713 int n; 709 int n;
714 XTextProperty name; 710 XTextProperty name;
@@ -735,8 +731,8 @@ gettextprop(Window w, Atom atom, char *text, uint size) {
735 731
736void 732void
737grabbuttons(Client *c, Bool focused) { 733grabbuttons(Client *c, Bool focused) {
738 uint i, j; 734 unsigned int i, j;
739 uint modifiers[] = { 0, LockMask, numlockmask, numlockmask|LockMask }; 735 unsigned int modifiers[] = { 0, LockMask, numlockmask, numlockmask|LockMask };
740 736
741 XUngrabButton(dpy, AnyButton, AnyModifier, c->win); 737 XUngrabButton(dpy, AnyButton, AnyModifier, c->win);
742 if(focused) { 738 if(focused) {
@@ -751,7 +747,7 @@ grabbuttons(Client *c, Bool focused) {
751 747
752void 748void
753grabkeys(void) { 749grabkeys(void) {
754 uint i, j; 750 unsigned int i, j;
755 KeyCode code; 751 KeyCode code;
756 XModifierKeymap *modmap; 752 XModifierKeymap *modmap;
757 753
@@ -819,7 +815,7 @@ initfont(const char *fontstr) {
819} 815}
820 816
821Bool 817Bool
822isoccupied(uint t) { 818isoccupied(unsigned int t) {
823 Client *c; 819 Client *c;
824 820
825 for(c = clients; c; c = c->next) 821 for(c = clients; c; c = c->next)
@@ -844,7 +840,7 @@ isprotodel(Client *c) {
844} 840}
845 841
846Bool 842Bool
847isurgent(uint t) { 843isurgent(unsigned int t) {
848 Client *c; 844 Client *c;
849 845
850 for(c = clients; c; c = c->next) 846 for(c = clients; c; c = c->next)
@@ -855,7 +851,7 @@ isurgent(uint t) {
855 851
856void 852void
857keypress(XEvent *e) { 853keypress(XEvent *e) {
858 uint i; 854 unsigned int i;
859 KeySym keysym; 855 KeySym keysym;
860 XKeyEvent *ev; 856 XKeyEvent *ev;
861 857
@@ -979,7 +975,7 @@ monocle(void) {
979void 975void
980movemouse(const Arg *arg) { 976movemouse(const Arg *arg) {
981 int x1, y1, ocx, ocy, di, nx, ny; 977 int x1, y1, ocx, ocy, di, nx, ny;
982 uint dui; 978 unsigned int dui;
983 Client *c; 979 Client *c;
984 Window dummy; 980 Window dummy;
985 XEvent ev; 981 XEvent ev;
@@ -1216,7 +1212,7 @@ run(void) {
1216 char sbuf[sizeof stext]; 1212 char sbuf[sizeof stext];
1217 fd_set rd; 1213 fd_set rd;
1218 int r, xfd; 1214 int r, xfd;
1219 uint len, offset; 1215 unsigned int len, offset;
1220 XEvent ev; 1216 XEvent ev;
1221 1217
1222 /* main event loop, also reads status text from stdin */ 1218 /* main event loop, also reads status text from stdin */
@@ -1272,7 +1268,7 @@ run(void) {
1272 1268
1273void 1269void
1274scan(void) { 1270scan(void) {
1275 uint i, num; 1271 unsigned int i, num;
1276 Window *wins, d1, d2; 1272 Window *wins, d1, d2;
1277 XWindowAttributes wa; 1273 XWindowAttributes wa;
1278 1274
@@ -1333,7 +1329,7 @@ setmfact(const Arg *arg) {
1333 1329
1334void 1330void
1335setup(void) { 1331setup(void) {
1336 uint i; 1332 unsigned int i;
1337 int w; 1333 int w;
1338 XSetWindowAttributes wa; 1334 XSetWindowAttributes wa;
1339 1335
@@ -1436,7 +1432,7 @@ tag(const Arg *arg) {
1436} 1432}
1437 1433
1438int 1434int
1439textnw(const char *text, uint len) { 1435textnw(const char *text, unsigned int len) {
1440 XRectangle r; 1436 XRectangle r;
1441 1437
1442 if(dc.font.set) { 1438 if(dc.font.set) {
@@ -1449,7 +1445,7 @@ textnw(const char *text, uint len) {
1449void 1445void
1450tile(void) { 1446tile(void) {
1451 int x, y, h, w, mw; 1447 int x, y, h, w, mw;
1452 uint i, n; 1448 unsigned int i, n;
1453 Client *c; 1449 Client *c;
1454 1450
1455 for(n = 0, c = nexttiled(clients); c; c = nexttiled(c->next), n++); 1451 for(n = 0, c = nexttiled(clients); c; c = nexttiled(c->next), n++);
@@ -1500,7 +1496,7 @@ togglefloating(const Arg *arg) {
1500 1496
1501void 1497void
1502toggletag(const Arg *arg) { 1498toggletag(const Arg *arg) {
1503 uint mask = sel->tags ^ (arg->ui & TAGMASK); 1499 unsigned int mask = sel->tags ^ (arg->ui & TAGMASK);
1504 1500
1505 if(sel && mask) { 1501 if(sel && mask) {
1506 sel->tags = mask; 1502 sel->tags = mask;
@@ -1510,7 +1506,7 @@ toggletag(const Arg *arg) {
1510 1506
1511void 1507void
1512toggleview(const Arg *arg) { 1508toggleview(const Arg *arg) {
1513 uint mask = tagset[seltags] ^ (arg->ui & TAGMASK); 1509 unsigned int mask = tagset[seltags] ^ (arg->ui & TAGMASK);
1514 1510
1515 if(mask) { 1511 if(mask) {
1516 tagset[seltags] = mask; 1512 tagset[seltags] = mask;