separate program-specific c99 bool and X11 43e82adf
True, False are X11-specific (int), make sure to use c99 stdbool for
program-specific things.
Hiltjo Posthuma · 2015-11-07 14:04 2 file(s) · +77 −75
config.def.h +5 −5
13 13
static const char selfgcolor[]      = "#eeeeee";
14 14
static const unsigned int borderpx  = 1;        /* border pixel of windows */
15 15
static const unsigned int snap      = 32;       /* snap pixel */
16 -
static const Bool showbar           = True;     /* False means no bar */
17 -
static const Bool topbar            = True;     /* False means bottom bar */
16 +
static const bool showbar           = true;     /* false means no bar */
17 +
static const bool topbar            = true;     /* false means bottom bar */
18 18
19 19
/* tagging */
20 20
static const char *tags[] = { "1", "2", "3", "4", "5", "6", "7", "8", "9" };
25 25
	 *	WM_NAME(STRING) = title
26 26
	 */
27 27
	/* class      instance    title       tags mask     isfloating   monitor */
28 -
	{ "Gimp",     NULL,       NULL,       0,            True,        -1 },
29 -
	{ "Firefox",  NULL,       NULL,       1 << 8,       False,       -1 },
28 +
	{ "Gimp",     NULL,       NULL,       0,            true,        -1 },
29 +
	{ "Firefox",  NULL,       NULL,       1 << 8,       false,       -1 },
30 30
};
31 31
32 32
/* layout(s) */
33 33
static const float mfact      = 0.55; /* factor of master area size [0.05..0.95] */
34 34
static const int nmaster      = 1;    /* number of clients in master area */
35 -
static const Bool resizehints = True; /* True means respect size hints in tiled resizals */
35 +
static const bool resizehints = true; /* true means respect size hints in tiled resizals */
36 36
37 37
static const Layout layouts[] = {
38 38
	/* symbol     arrange function */
dwm.c +72 −70
24 24
#include <locale.h>
25 25
#include <stdarg.h>
26 26
#include <signal.h>
27 +
#include <stdbool.h>
27 28
#include <stdio.h>
28 29
#include <stdlib.h>
29 30
#include <string.h>
92 93
	int basew, baseh, incw, inch, maxw, maxh, minw, minh;
93 94
	int bw, oldbw;
94 95
	unsigned int tags;
95 -
	Bool isfixed, isfloating, isurgent, neverfocus, oldstate, isfullscreen;
96 +
	bool isfixed, isfloating, isurgent, neverfocus, oldstate, isfullscreen;
96 97
	Client *next;
97 98
	Client *snext;
98 99
	Monitor *mon;
122 123
	unsigned int seltags;
123 124
	unsigned int sellt;
124 125
	unsigned int tagset[2];
125 -
	Bool showbar;
126 -
	Bool topbar;
126 +
	bool showbar;
127 +
	bool topbar;
127 128
	Client *clients;
128 129
	Client *sel;
129 130
	Client *stack;
137 138
	const char *instance;
138 139
	const char *title;
139 140
	unsigned int tags;
140 -
	Bool isfloating;
141 +
	bool isfloating;
141 142
	int monitor;
142 143
} Rule;
143 144
144 145
/* function declarations */
145 146
static void applyrules(Client *c);
146 -
static Bool applysizehints(Client *c, int *x, int *y, int *w, int *h, Bool interact);
147 +
static bool applysizehints(Client *c, int *x, int *y, int *w, int *h, bool interact);
147 148
static void arrange(Monitor *m);
148 149
static void arrangemon(Monitor *m);
149 150
static void attach(Client *c);
170 171
static void focusin(XEvent *e);
171 172
static void focusmon(const Arg *arg);
172 173
static void focusstack(const Arg *arg);
173 -
static Bool getrootptr(int *x, int *y);
174 +
static bool getrootptr(int *x, int *y);
174 175
static long getstate(Window w);
175 -
static Bool gettextprop(Window w, Atom atom, char *text, unsigned int size);
176 -
static void grabbuttons(Client *c, Bool focused);
176 +
static bool gettextprop(Window w, Atom atom, char *text, unsigned int size);
177 +
static void grabbuttons(Client *c, bool focused);
177 178
static void grabkeys(void);
178 179
static void incnmaster(const Arg *arg);
179 180
static void keypress(XEvent *e);
189 190
static void propertynotify(XEvent *e);
190 191
static void quit(const Arg *arg);
191 192
static Monitor *recttomon(int x, int y, int w, int h);
192 -
static void resize(Client *c, int x, int y, int w, int h, Bool interact);
193 +
static void resize(Client *c, int x, int y, int w, int h, bool interact);
193 194
static void resizeclient(Client *c, int x, int y, int w, int h);
194 195
static void resizemouse(const Arg *arg);
195 196
static void restack(Monitor *m);
196 197
static void run(void);
197 198
static void scan(void);
198 -
static Bool sendevent(Client *c, Atom proto);
199 +
static bool sendevent(Client *c, Atom proto);
199 200
static void sendmon(Client *c, Monitor *m);
200 201
static void setclientstate(Client *c, long state);
201 202
static void setfocus(Client *c);
202 -
static void setfullscreen(Client *c, Bool fullscreen);
203 +
static void setfullscreen(Client *c, bool fullscreen);
203 204
static void setlayout(const Arg *arg);
204 205
static void setmfact(const Arg *arg);
205 206
static void setup(void);
213 214
static void togglefloating(const Arg *arg);
214 215
static void toggletag(const Arg *arg);
215 216
static void toggleview(const Arg *arg);
216 -
static void unfocus(Client *c, Bool setfocus);
217 -
static void unmanage(Client *c, Bool destroyed);
217 +
static void unfocus(Client *c, bool setfocus);
218 +
static void unmanage(Client *c, bool destroyed);
218 219
static void unmapnotify(XEvent *e);
219 -
static Bool updategeom(void);
220 +
static bool updategeom(void);
220 221
static void updatebarpos(Monitor *m);
221 222
static void updatebars(void);
222 223
static void updateclientlist(void);
259 260
	[UnmapNotify] = unmapnotify
260 261
};
261 262
static Atom wmatom[WMLast], netatom[NetLast];
262 -
static Bool running = True;
263 +
static bool running = true;
263 264
static Cur *cursor[CurLast];
264 265
static ClrScheme scheme[SchemeLast];
265 266
static Display *dpy;
283 284
	XClassHint ch = { NULL, NULL };
284 285
285 286
	/* rule matching */
286 -
	c->isfloating = c->tags = 0;
287 +
	c->isfloating = false;
288 +
	c->tags = 0;
287 289
	XGetClassHint(dpy, c->win, &ch);
288 290
	class    = ch.res_class ? ch.res_class : broken;
289 291
	instance = ch.res_name  ? ch.res_name  : broken;
308 310
	c->tags = c->tags & TAGMASK ? c->tags & TAGMASK : c->mon->tagset[c->mon->seltags];
309 311
}
310 312
311 -
Bool
312 -
applysizehints(Client *c, int *x, int *y, int *w, int *h, Bool interact) {
313 -
	Bool baseismin;
313 +
bool
314 +
applysizehints(Client *c, int *x, int *y, int *w, int *h, bool interact) {
315 +
	bool baseismin;
314 316
	Monitor *m = c->mon;
315 317
316 318
	/* set minimum possible */
417 419
	click = ClkRootWin;
418 420
	/* focus monitor if necessary */
419 421
	if((m = wintomon(ev->window)) && m != selmon) {
420 -
		unfocus(selmon->sel, True);
422 +
		unfocus(selmon->sel, true);
421 423
		selmon = m;
422 424
		focus(NULL);
423 425
	}
468 470
	selmon->lt[selmon->sellt] = &foo;
469 471
	for(m = mons; m; m = m->next)
470 472
		while(m->stack)
471 -
			unmanage(m->stack, False);
473 +
			unmanage(m->stack, false);
472 474
	XUngrabKey(dpy, AnyKey, AnyModifier, root);
473 475
	while(mons)
474 476
		cleanupmon(mons);
504 506
clearurgent(Client *c) {
505 507
	XWMHints *wmh;
506 508
507 -
	c->isurgent = False;
509 +
	c->isurgent = false;
508 510
	if(!(wmh = XGetWMHints(dpy, c->win)))
509 511
		return;
510 512
	wmh->flags &= ~XUrgencyHint;
555 557
configurenotify(XEvent *e) {
556 558
	Monitor *m;
557 559
	XConfigureEvent *ev = &e->xconfigure;
558 -
	Bool dirty;
560 +
	bool dirty;
559 561
560 562
	/* TODO: updategeom handling sucks, needs to be simplified */
561 563
	if(ev->window == root) {
648 650
	XDestroyWindowEvent *ev = &e->xdestroywindow;
649 651
650 652
	if((c = wintoclient(ev->window)))
651 -
		unmanage(c, True);
653 +
		unmanage(c, true);
652 654
}
653 655
654 656
void
759 761
	c = wintoclient(ev->window);
760 762
	m = c ? c->mon : wintomon(ev->window);
761 763
	if(m != selmon) {
762 -
		unfocus(selmon->sel, True);
764 +
		unfocus(selmon->sel, true);
763 765
		selmon = m;
764 766
	}
765 767
	else if(!c || c == selmon->sel)
782 784
		for(c = selmon->stack; c && !ISVISIBLE(c); c = c->snext);
783 785
	/* was if(selmon->sel) */
784 786
	if(selmon->sel && selmon->sel != c)
785 -
		unfocus(selmon->sel, False);
787 +
		unfocus(selmon->sel, false);
786 788
	if(c) {
787 789
		if(c->mon != selmon)
788 790
			selmon = c->mon;
790 792
			clearurgent(c);
791 793
		detachstack(c);
792 794
		attachstack(c);
793 -
		grabbuttons(c, True);
795 +
		grabbuttons(c, true);
794 796
		XSetWindowBorder(dpy, c->win, scheme[SchemeSel].border->pix);
795 797
		setfocus(c);
796 798
	}
818 820
		return;
819 821
	if((m = dirtomon(arg->i)) == selmon)
820 822
		return;
821 -
	unfocus(selmon->sel, False); /* s/True/False/ fixes input focus issues
823 +
	unfocus(selmon->sel, false); /* s/true/false/ fixes input focus issues
822 824
					in gedit and anjuta */
823 825
	selmon = m;
824 826
	focus(NULL);
865 867
	return atom;
866 868
}
867 869
868 -
Bool
870 +
bool
869 871
getrootptr(int *x, int *y) {
870 872
	int di;
871 873
	unsigned int dui;
872 874
	Window dummy;
873 875
874 -
	return XQueryPointer(dpy, root, &dummy, &dummy, x, y, &di, &di, &dui);
876 +
	return XQueryPointer(dpy, root, &dummy, &dummy, x, y, &di, &di, &dui) == True;
875 877
}
876 878
877 879
long
891 893
	return result;
892 894
}
893 895
894 -
Bool
896 +
bool
895 897
gettextprop(Window w, Atom atom, char *text, unsigned int size) {
896 898
	char **list = NULL;
897 899
	int n;
898 900
	XTextProperty name;
899 901
900 902
	if(!text || size == 0)
901 -
		return False;
903 +
		return false;
902 904
	text[0] = '\0';
903 905
	XGetTextProperty(dpy, w, &name, atom);
904 906
	if(!name.nitems)
905 -
		return False;
907 +
		return false;
906 908
	if(name.encoding == XA_STRING)
907 909
		strncpy(text, (char *)name.value, size - 1);
908 910
	else {
913 915
	}
914 916
	text[size - 1] = '\0';
915 917
	XFree(name.value);
916 -
	return True;
918 +
	return true;
917 919
}
918 920
919 921
void
920 -
grabbuttons(Client *c, Bool focused) {
922 +
grabbuttons(Client *c, bool focused) {
921 923
	updatenumlockmask();
922 924
	{
923 925
		unsigned int i, j;
962 964
}
963 965
964 966
#ifdef XINERAMA
965 -
static Bool
967 +
static bool
966 968
isuniquegeom(XineramaScreenInfo *unique, size_t n, XineramaScreenInfo *info) {
967 969
	while(n--)
968 970
		if(unique[n].x_org == info->x_org && unique[n].y_org == info->y_org
969 971
		&& unique[n].width == info->width && unique[n].height == info->height)
970 -
			return False;
971 -
	return True;
972 +
			return false;
973 +
	return true;
972 974
}
973 975
#endif /* XINERAMA */
974 976
1044 1046
	updatesizehints(c);
1045 1047
	updatewmhints(c);
1046 1048
	XSelectInput(dpy, w, EnterWindowMask|FocusChangeMask|PropertyChangeMask|StructureNotifyMask);
1047 -
	grabbuttons(c, False);
1049 +
	grabbuttons(c, false);
1048 1050
	if(!c->isfloating)
1049 1051
		c->isfloating = c->oldstate = trans != None || c->isfixed;
1050 1052
	if(c->isfloating)
1056 1058
	XMoveResizeWindow(dpy, c->win, c->x + 2 * sw, c->y, c->w, c->h); /* some windows require this */
1057 1059
	setclientstate(c, NormalState);
1058 1060
	if (c->mon == selmon)
1059 -
		unfocus(selmon->sel, False);
1061 +
		unfocus(selmon->sel, false);
1060 1062
	c->mon->sel = c;
1061 1063
	arrange(c->mon);
1062 1064
	XMapWindow(dpy, c->win);
1096 1098
	if(n > 0) /* override layout symbol */
1097 1099
		snprintf(m->ltsymbol, sizeof m->ltsymbol, "[%d]", n);
1098 1100
	for(c = nexttiled(m->clients); c; c = nexttiled(c->next))
1099 -
		resize(c, m->wx, m->wy, m->ww - 2 * c->bw, m->wh - 2 * c->bw, False);
1101 +
		resize(c, m->wx, m->wy, m->ww - 2 * c->bw, m->wh - 2 * c->bw, false);
1100 1102
}
1101 1103
1102 1104
void
1108 1110
	if(ev->window != root)
1109 1111
		return;
1110 1112
	if((m = recttomon(ev->x_root, ev->y_root, 1, 1)) != mon && mon) {
1111 -
		unfocus(selmon->sel, True);
1113 +
		unfocus(selmon->sel, true);
1112 1114
		selmon = m;
1113 1115
		focus(NULL);
1114 1116
	}
1165 1167
					togglefloating(NULL);
1166 1168
			}
1167 1169
			if(!selmon->lt[selmon->sellt]->arrange || c->isfloating)
1168 -
				resize(c, nx, ny, c->w, c->h, True);
1170 +
				resize(c, nx, ny, c->w, c->h, true);
1169 1171
			break;
1170 1172
		}
1171 1173
	} while(ev.type != ButtonRelease);
1229 1231
1230 1232
void
1231 1233
quit(const Arg *arg) {
1232 -
	running = False;
1234 +
	running = false;
1233 1235
}
1234 1236
1235 1237
Monitor *
1246 1248
}
1247 1249
1248 1250
void
1249 -
resize(Client *c, int x, int y, int w, int h, Bool interact) {
1251 +
resize(Client *c, int x, int y, int w, int h, bool interact) {
1250 1252
	if(applysizehints(c, &x, &y, &w, &h, interact))
1251 1253
		resizeclient(c, x, y, w, h);
1252 1254
}
1307 1309
					togglefloating(NULL);
1308 1310
			}
1309 1311
			if(!selmon->lt[selmon->sellt]->arrange || c->isfloating)
1310 -
				resize(c, c->x, c->y, nw, nh, True);
1312 +
				resize(c, c->x, c->y, nw, nh, true);
1311 1313
			break;
1312 1314
		}
1313 1315
	} while(ev.type != ButtonRelease);
1385 1387
sendmon(Client *c, Monitor *m) {
1386 1388
	if(c->mon == m)
1387 1389
		return;
1388 -
	unfocus(c, True);
1390 +
	unfocus(c, true);
1389 1391
	detach(c);
1390 1392
	detachstack(c);
1391 1393
	c->mon = m;
1404 1406
			PropModeReplace, (unsigned char *)data, 2);
1405 1407
}
1406 1408
1407 -
Bool
1409 +
bool
1408 1410
sendevent(Client *c, Atom proto) {
1409 1411
	int n;
1410 1412
	Atom *protocols;
1411 -
	Bool exists = False;
1413 +
	bool exists = false;
1412 1414
	XEvent ev;
1413 1415
1414 1416
	if(XGetWMProtocols(dpy, c->win, &protocols, &n)) {
1440 1442
}
1441 1443
1442 1444
void
1443 -
setfullscreen(Client *c, Bool fullscreen) {
1445 +
setfullscreen(Client *c, bool fullscreen) {
1444 1446
	if(fullscreen && !c->isfullscreen) {
1445 1447
		XChangeProperty(dpy, c->win, netatom[NetWMState], XA_ATOM, 32,
1446 1448
		                PropModeReplace, (unsigned char*)&netatom[NetWMFullscreen], 1);
1447 -
		c->isfullscreen = True;
1449 +
		c->isfullscreen = true;
1448 1450
		c->oldstate = c->isfloating;
1449 1451
		c->oldbw = c->bw;
1450 1452
		c->bw = 0;
1451 -
		c->isfloating = True;
1453 +
		c->isfloating = true;
1452 1454
		resizeclient(c, c->mon->mx, c->mon->my, c->mon->mw, c->mon->mh);
1453 1455
		XRaiseWindow(dpy, c->win);
1454 1456
	}
1455 1457
	else if(!fullscreen && c->isfullscreen){
1456 1458
		XChangeProperty(dpy, c->win, netatom[NetWMState], XA_ATOM, 32,
1457 1459
		                PropModeReplace, (unsigned char*)0, 0);
1458 -
		c->isfullscreen = False;
1460 +
		c->isfullscreen = false;
1459 1461
		c->isfloating = c->oldstate;
1460 1462
		c->bw = c->oldbw;
1461 1463
		c->x = c->oldx;
1560 1562
	if(ISVISIBLE(c)) { /* show clients top down */
1561 1563
		XMoveWindow(dpy, c->win, c->x, c->y);
1562 1564
		if((!c->mon->lt[c->mon->sellt]->arrange || c->isfloating) && !c->isfullscreen)
1563 -
			resize(c, c->x, c->y, c->w, c->h, False);
1565 +
			resize(c, c->x, c->y, c->w, c->h, false);
1564 1566
		showhide(c->snext);
1565 1567
	}
1566 1568
	else { /* hide clients bottom up */
1623 1625
	for(i = my = ty = 0, c = nexttiled(m->clients); c; c = nexttiled(c->next), i++)
1624 1626
		if(i < m->nmaster) {
1625 1627
			h = (m->wh - my) / (MIN(n, m->nmaster) - i);
1626 -
			resize(c, m->wx, m->wy + my, mw - (2*c->bw), h - (2*c->bw), False);
1628 +
			resize(c, m->wx, m->wy + my, mw - (2*c->bw), h - (2*c->bw), false);
1627 1629
			my += HEIGHT(c);
1628 1630
		}
1629 1631
		else {
1630 1632
			h = (m->wh - ty) / (n - i);
1631 -
			resize(c, m->wx + mw, m->wy + ty, m->ww - mw - (2*c->bw), h - (2*c->bw), False);
1633 +
			resize(c, m->wx + mw, m->wy + ty, m->ww - mw - (2*c->bw), h - (2*c->bw), false);
1632 1634
			ty += HEIGHT(c);
1633 1635
		}
1634 1636
}
1650 1652
	selmon->sel->isfloating = !selmon->sel->isfloating || selmon->sel->isfixed;
1651 1653
	if(selmon->sel->isfloating)
1652 1654
		resize(selmon->sel, selmon->sel->x, selmon->sel->y,
1653 -
		       selmon->sel->w, selmon->sel->h, False);
1655 +
		       selmon->sel->w, selmon->sel->h, false);
1654 1656
	arrange(selmon);
1655 1657
}
1656 1658
1680 1682
}
1681 1683
1682 1684
void
1683 -
unfocus(Client *c, Bool setfocus) {
1685 +
unfocus(Client *c, bool setfocus) {
1684 1686
	if(!c)
1685 1687
		return;
1686 -
	grabbuttons(c, False);
1688 +
	grabbuttons(c, false);
1687 1689
	XSetWindowBorder(dpy, c->win, scheme[SchemeNorm].border->pix);
1688 1690
	if(setfocus) {
1689 1691
		XSetInputFocus(dpy, root, RevertToPointerRoot, CurrentTime);
1692 1694
}
1693 1695
1694 1696
void
1695 -
unmanage(Client *c, Bool destroyed) {
1697 +
unmanage(Client *c, bool destroyed) {
1696 1698
	Monitor *m = c->mon;
1697 1699
	XWindowChanges wc;
1698 1700
1725 1727
		if(ev->send_event)
1726 1728
			setclientstate(c, WithdrawnState);
1727 1729
		else
1728 -
			unmanage(c, False);
1730 +
			unmanage(c, false);
1729 1731
	}
1730 1732
}
1731 1733
1774 1776
			                (unsigned char *) &(c->win), 1);
1775 1777
}
1776 1778
1777 -
Bool
1779 +
bool
1778 1780
updategeom(void) {
1779 -
	Bool dirty = False;
1781 +
	bool dirty = false;
1780 1782
1781 1783
#ifdef XINERAMA
1782 1784
	if(XineramaIsActive(dpy)) {
1807 1809
				|| (unique[i].x_org != m->mx || unique[i].y_org != m->my
1808 1810
				    || unique[i].width != m->mw || unique[i].height != m->mh))
1809 1811
				{
1810 -
					dirty = True;
1812 +
					dirty = true;
1811 1813
					m->num = i;
1812 1814
					m->mx = m->wx = unique[i].x_org;
1813 1815
					m->my = m->wy = unique[i].y_org;
1820 1822
			for(i = nn; i < n; i++) {
1821 1823
				for(m = mons; m && m->next; m = m->next);
1822 1824
				while(m->clients) {
1823 -
					dirty = True;
1825 +
					dirty = true;
1824 1826
					c = m->clients;
1825 1827
					m->clients = c->next;
1826 1828
					detachstack(c);
1842 1844
		if(!mons)
1843 1845
			mons = createmon();
1844 1846
		if(mons->mw != sw || mons->mh != sh) {
1845 -
			dirty = True;
1847 +
			dirty = true;
1846 1848
			mons->mw = mons->ww = sw;
1847 1849
			mons->mh = mons->wh = sh;
1848 1850
			updatebarpos(mons);
1941 1943
	Atom wtype = getatomprop(c, netatom[NetWMWindowType]);
1942 1944
1943 1945
	if(state == netatom[NetWMFullscreen])
1944 -
		setfullscreen(c, True);
1946 +
		setfullscreen(c, true);
1945 1947
	if(wtype == netatom[NetWMWindowTypeDialog])
1946 -
		c->isfloating = True;
1948 +
		c->isfloating = true;
1947 1949
}
1948 1950
1949 1951
void
1956 1958
			XSetWMHints(dpy, c->win, wmh);
1957 1959
		}
1958 1960
		else
1959 -
			c->isurgent = (wmh->flags & XUrgencyHint) ? True : False;
1961 +
			c->isurgent = (wmh->flags & XUrgencyHint) ? true : false;
1960 1962
		if(wmh->flags & InputHint)
1961 1963
			c->neverfocus = !wmh->input;
1962 1964
		else
1963 -
			c->neverfocus = False;
1965 +
			c->neverfocus = false;
1964 1966
		XFree(wmh);
1965 1967
	}
1966 1968
}