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