author | Anselm R. Garbe <arg@suckless.org> |
Wed, 21 Feb 2007 11:45:51 +0100 | |
changeset 800 | 6133edf536de |
parent 795 | 3b23c75920a3 |
child 801 | 9f2426241f09 |
permissions | -rw-r--r-- |
644 | 1 |
/* (C)opyright MMVI-MMVII Anselm R. Garbe <garbeam at gmail dot com> |
0 | 2 |
* See LICENSE file for license details. |
3 |
*/ |
|
4 |
||
76
4bd49f404f10
proceeded with cleaning up, sorting functions, etc
Anselm R. Garbe <garbeam@wmii.de>
parents:
75
diff
changeset
|
5 |
#include "dwm.h" |
59
5d4653de9a1c
implemented dwm reading status text from stdin
Anselm R. Garbe <garbeam@wmii.de>
parents:
58
diff
changeset
|
6 |
#include <errno.h> |
619 | 7 |
#include <locale.h> |
0 | 8 |
#include <stdio.h> |
9 |
#include <stdlib.h> |
|
57
f005d46462e8
implemented bar for dwm (I miss status text), I plan that status text is read from stdin in dwm
Anselm R. Garbe <garbeam@wmii.de>
parents:
52
diff
changeset
|
10 |
#include <string.h> |
59
5d4653de9a1c
implemented dwm reading status text from stdin
Anselm R. Garbe <garbeam@wmii.de>
parents:
58
diff
changeset
|
11 |
#include <unistd.h> |
138
c1185dc7a36e
some cleanups/fixes inspired by Jukka Salmi's feedback
arg@10ksloc.org
parents:
137
diff
changeset
|
12 |
#include <sys/select.h> |
0 | 13 |
#include <X11/cursorfont.h> |
291
8e6e0aa5e2ae
removed NUMLOCKMASK, added dynamically calculated numlockmask instead
Anselm R.Garbe <arg@10ksloc.org>
parents:
281
diff
changeset
|
14 |
#include <X11/keysym.h> |
0 | 15 |
#include <X11/Xatom.h> |
16 |
#include <X11/Xproto.h> |
|
17 |
||
333
827f8f6c9e97
separated setup stuff into main.c:setup() - this makes main() more readable
Anselm R. Garbe <arg@10kloc.org>
parents:
329
diff
changeset
|
18 |
/* extern */ |
827f8f6c9e97
separated setup stuff into main.c:setup() - this makes main() more readable
Anselm R. Garbe <arg@10kloc.org>
parents:
329
diff
changeset
|
19 |
|
688
39fa5308d73f
removed mode label stuff
Anselm R. Garbe <arg@suckless.org>
parents:
679
diff
changeset
|
20 |
char stext[256]; |
800
6133edf536de
removed some global vars which should be static instead
Anselm R. Garbe <arg@suckless.org>
parents:
795
diff
changeset
|
21 |
int screen, sw, sh, wax, way, waw, wah; |
782
92862ab407d5
introduced Layout struct
Anselm R. Garbe <arg@suckless.org>
parents:
778
diff
changeset
|
22 |
unsigned int bh, ntags, numlockmask; |
333
827f8f6c9e97
separated setup stuff into main.c:setup() - this makes main() more readable
Anselm R. Garbe <arg@10kloc.org>
parents:
329
diff
changeset
|
23 |
Atom wmatom[WMLast], netatom[NetLast]; |
740
1cb9ae0a0104
fixed order of Bool declarations
Anselm R. Garbe <arg@suckless.org>
parents:
739
diff
changeset
|
24 |
Bool *seltag; |
716
4ce65f61f01b
renamed activescreen into selscreen
Anselm R. Garbe <arg@suckless.org>
parents:
714
diff
changeset
|
25 |
Bool selscreen = True; |
333
827f8f6c9e97
separated setup stuff into main.c:setup() - this makes main() more readable
Anselm R. Garbe <arg@10kloc.org>
parents:
329
diff
changeset
|
26 |
Client *clients = NULL; |
827f8f6c9e97
separated setup stuff into main.c:setup() - this makes main() more readable
Anselm R. Garbe <arg@10kloc.org>
parents:
329
diff
changeset
|
27 |
Client *sel = NULL; |
446
a2e587651c79
using a global stack for focus recovery on arrange() - seems to work great
Anselm R. Garbe <arg@10kloc.org>
parents:
433
diff
changeset
|
28 |
Client *stack = NULL; |
333
827f8f6c9e97
separated setup stuff into main.c:setup() - this makes main() more readable
Anselm R. Garbe <arg@10kloc.org>
parents:
329
diff
changeset
|
29 |
Cursor cursor[CurLast]; |
827f8f6c9e97
separated setup stuff into main.c:setup() - this makes main() more readable
Anselm R. Garbe <arg@10kloc.org>
parents:
329
diff
changeset
|
30 |
Display *dpy; |
827f8f6c9e97
separated setup stuff into main.c:setup() - this makes main() more readable
Anselm R. Garbe <arg@10kloc.org>
parents:
329
diff
changeset
|
31 |
DC dc = {0}; |
827f8f6c9e97
separated setup stuff into main.c:setup() - this makes main() more readable
Anselm R. Garbe <arg@10kloc.org>
parents:
329
diff
changeset
|
32 |
Window root, barwin; |
827f8f6c9e97
separated setup stuff into main.c:setup() - this makes main() more readable
Anselm R. Garbe <arg@10kloc.org>
parents:
329
diff
changeset
|
33 |
|
84
052fe7498930
ordered variables in structs and source files alphabetically
Anselm R. Garbe <garbeam@wmii.de>
parents:
79
diff
changeset
|
34 |
/* static */ |
0 | 35 |
|
123 | 36 |
static int (*xerrorxlib)(Display *, XErrorEvent *); |
302 | 37 |
static Bool otherwm, readin; |
800
6133edf536de
removed some global vars which should be static instead
Anselm R. Garbe <arg@suckless.org>
parents:
795
diff
changeset
|
38 |
static Bool running = True; |
0 | 39 |
|
40 |
static void |
|
487 | 41 |
cleanup(void) { |
302 | 42 |
close(STDIN_FILENO); |
645 | 43 |
while(stack) { |
762
140bcd4782d8
removed ugly ban(), extended resize() that it only resets the size if necessary, added border_width commit to manage()
Anselm R. Garbe <arg@suckless.org>
parents:
757
diff
changeset
|
44 |
if(stack->isbanned) |
140bcd4782d8
removed ugly ban(), extended resize() that it only resets the size if necessary, added border_width commit to manage()
Anselm R. Garbe <arg@suckless.org>
parents:
757
diff
changeset
|
45 |
XMoveWindow(dpy, stack->win, stack->x, stack->y); |
645 | 46 |
unmanage(stack); |
76
4bd49f404f10
proceeded with cleaning up, sorting functions, etc
Anselm R. Garbe <garbeam@wmii.de>
parents:
75
diff
changeset
|
47 |
} |
295 | 48 |
if(dc.font.set) |
49 |
XFreeFontSet(dpy, dc.font.set); |
|
50 |
else |
|
51 |
XFreeFont(dpy, dc.font.xfont); |
|
292 | 52 |
XUngrabKey(dpy, AnyKey, AnyModifier, root); |
295 | 53 |
XFreePixmap(dpy, dc.drawable); |
54 |
XFreeGC(dpy, dc.gc); |
|
309
204427dcc087
corrected order of cleanup code
Anselm R.Garbe <arg@10ksloc.org>
parents:
302
diff
changeset
|
55 |
XDestroyWindow(dpy, barwin); |
616 | 56 |
XFreeCursor(dpy, cursor[CurNormal]); |
57 |
XFreeCursor(dpy, cursor[CurResize]); |
|
58 |
XFreeCursor(dpy, cursor[CurMove]); |
|
76
4bd49f404f10
proceeded with cleaning up, sorting functions, etc
Anselm R. Garbe <garbeam@wmii.de>
parents:
75
diff
changeset
|
59 |
XSetInputFocus(dpy, PointerRoot, RevertToPointerRoot, CurrentTime); |
292 | 60 |
XSync(dpy, False); |
433 | 61 |
free(seltag); |
76
4bd49f404f10
proceeded with cleaning up, sorting functions, etc
Anselm R. Garbe <garbeam@wmii.de>
parents:
75
diff
changeset
|
62 |
} |
0 | 63 |
|
777
469dc170f833
draw.c is useless (belongs to main.c now)
Anselm R. Garbe <arg@suckless.org>
parents:
770
diff
changeset
|
64 |
static unsigned long |
795
3b23c75920a3
renamed setfont to initfont, getcolor to initcolor
Anselm R. Garbe <arg@suckless.org>
parents:
793
diff
changeset
|
65 |
initcolor(const char *colstr) { |
777
469dc170f833
draw.c is useless (belongs to main.c now)
Anselm R. Garbe <arg@suckless.org>
parents:
770
diff
changeset
|
66 |
Colormap cmap = DefaultColormap(dpy, screen); |
469dc170f833
draw.c is useless (belongs to main.c now)
Anselm R. Garbe <arg@suckless.org>
parents:
770
diff
changeset
|
67 |
XColor color; |
469dc170f833
draw.c is useless (belongs to main.c now)
Anselm R. Garbe <arg@suckless.org>
parents:
770
diff
changeset
|
68 |
|
469dc170f833
draw.c is useless (belongs to main.c now)
Anselm R. Garbe <arg@suckless.org>
parents:
770
diff
changeset
|
69 |
if(!XAllocNamedColor(dpy, cmap, colstr, &color, &color)) |
469dc170f833
draw.c is useless (belongs to main.c now)
Anselm R. Garbe <arg@suckless.org>
parents:
770
diff
changeset
|
70 |
eprint("error, cannot allocate color '%s'\n", colstr); |
469dc170f833
draw.c is useless (belongs to main.c now)
Anselm R. Garbe <arg@suckless.org>
parents:
770
diff
changeset
|
71 |
return color.pixel; |
469dc170f833
draw.c is useless (belongs to main.c now)
Anselm R. Garbe <arg@suckless.org>
parents:
770
diff
changeset
|
72 |
} |
469dc170f833
draw.c is useless (belongs to main.c now)
Anselm R. Garbe <arg@suckless.org>
parents:
770
diff
changeset
|
73 |
|
0 | 74 |
static void |
795
3b23c75920a3
renamed setfont to initfont, getcolor to initcolor
Anselm R. Garbe <arg@suckless.org>
parents:
793
diff
changeset
|
75 |
initfont(const char *fontstr) { |
777
469dc170f833
draw.c is useless (belongs to main.c now)
Anselm R. Garbe <arg@suckless.org>
parents:
770
diff
changeset
|
76 |
char *def, **missing; |
469dc170f833
draw.c is useless (belongs to main.c now)
Anselm R. Garbe <arg@suckless.org>
parents:
770
diff
changeset
|
77 |
int i, n; |
469dc170f833
draw.c is useless (belongs to main.c now)
Anselm R. Garbe <arg@suckless.org>
parents:
770
diff
changeset
|
78 |
|
469dc170f833
draw.c is useless (belongs to main.c now)
Anselm R. Garbe <arg@suckless.org>
parents:
770
diff
changeset
|
79 |
missing = NULL; |
469dc170f833
draw.c is useless (belongs to main.c now)
Anselm R. Garbe <arg@suckless.org>
parents:
770
diff
changeset
|
80 |
if(dc.font.set) |
469dc170f833
draw.c is useless (belongs to main.c now)
Anselm R. Garbe <arg@suckless.org>
parents:
770
diff
changeset
|
81 |
XFreeFontSet(dpy, dc.font.set); |
469dc170f833
draw.c is useless (belongs to main.c now)
Anselm R. Garbe <arg@suckless.org>
parents:
770
diff
changeset
|
82 |
dc.font.set = XCreateFontSet(dpy, fontstr, &missing, &n, &def); |
469dc170f833
draw.c is useless (belongs to main.c now)
Anselm R. Garbe <arg@suckless.org>
parents:
770
diff
changeset
|
83 |
if(missing) { |
469dc170f833
draw.c is useless (belongs to main.c now)
Anselm R. Garbe <arg@suckless.org>
parents:
770
diff
changeset
|
84 |
while(n--) |
469dc170f833
draw.c is useless (belongs to main.c now)
Anselm R. Garbe <arg@suckless.org>
parents:
770
diff
changeset
|
85 |
fprintf(stderr, "missing fontset: %s\n", missing[n]); |
469dc170f833
draw.c is useless (belongs to main.c now)
Anselm R. Garbe <arg@suckless.org>
parents:
770
diff
changeset
|
86 |
XFreeStringList(missing); |
469dc170f833
draw.c is useless (belongs to main.c now)
Anselm R. Garbe <arg@suckless.org>
parents:
770
diff
changeset
|
87 |
} |
469dc170f833
draw.c is useless (belongs to main.c now)
Anselm R. Garbe <arg@suckless.org>
parents:
770
diff
changeset
|
88 |
if(dc.font.set) { |
469dc170f833
draw.c is useless (belongs to main.c now)
Anselm R. Garbe <arg@suckless.org>
parents:
770
diff
changeset
|
89 |
XFontSetExtents *font_extents; |
469dc170f833
draw.c is useless (belongs to main.c now)
Anselm R. Garbe <arg@suckless.org>
parents:
770
diff
changeset
|
90 |
XFontStruct **xfonts; |
469dc170f833
draw.c is useless (belongs to main.c now)
Anselm R. Garbe <arg@suckless.org>
parents:
770
diff
changeset
|
91 |
char **font_names; |
469dc170f833
draw.c is useless (belongs to main.c now)
Anselm R. Garbe <arg@suckless.org>
parents:
770
diff
changeset
|
92 |
dc.font.ascent = dc.font.descent = 0; |
469dc170f833
draw.c is useless (belongs to main.c now)
Anselm R. Garbe <arg@suckless.org>
parents:
770
diff
changeset
|
93 |
font_extents = XExtentsOfFontSet(dc.font.set); |
469dc170f833
draw.c is useless (belongs to main.c now)
Anselm R. Garbe <arg@suckless.org>
parents:
770
diff
changeset
|
94 |
n = XFontsOfFontSet(dc.font.set, &xfonts, &font_names); |
469dc170f833
draw.c is useless (belongs to main.c now)
Anselm R. Garbe <arg@suckless.org>
parents:
770
diff
changeset
|
95 |
for(i = 0, dc.font.ascent = 0, dc.font.descent = 0; i < n; i++) { |
469dc170f833
draw.c is useless (belongs to main.c now)
Anselm R. Garbe <arg@suckless.org>
parents:
770
diff
changeset
|
96 |
if(dc.font.ascent < (*xfonts)->ascent) |
469dc170f833
draw.c is useless (belongs to main.c now)
Anselm R. Garbe <arg@suckless.org>
parents:
770
diff
changeset
|
97 |
dc.font.ascent = (*xfonts)->ascent; |
469dc170f833
draw.c is useless (belongs to main.c now)
Anselm R. Garbe <arg@suckless.org>
parents:
770
diff
changeset
|
98 |
if(dc.font.descent < (*xfonts)->descent) |
469dc170f833
draw.c is useless (belongs to main.c now)
Anselm R. Garbe <arg@suckless.org>
parents:
770
diff
changeset
|
99 |
dc.font.descent = (*xfonts)->descent; |
469dc170f833
draw.c is useless (belongs to main.c now)
Anselm R. Garbe <arg@suckless.org>
parents:
770
diff
changeset
|
100 |
xfonts++; |
469dc170f833
draw.c is useless (belongs to main.c now)
Anselm R. Garbe <arg@suckless.org>
parents:
770
diff
changeset
|
101 |
} |
469dc170f833
draw.c is useless (belongs to main.c now)
Anselm R. Garbe <arg@suckless.org>
parents:
770
diff
changeset
|
102 |
} |
469dc170f833
draw.c is useless (belongs to main.c now)
Anselm R. Garbe <arg@suckless.org>
parents:
770
diff
changeset
|
103 |
else { |
469dc170f833
draw.c is useless (belongs to main.c now)
Anselm R. Garbe <arg@suckless.org>
parents:
770
diff
changeset
|
104 |
if(dc.font.xfont) |
469dc170f833
draw.c is useless (belongs to main.c now)
Anselm R. Garbe <arg@suckless.org>
parents:
770
diff
changeset
|
105 |
XFreeFont(dpy, dc.font.xfont); |
469dc170f833
draw.c is useless (belongs to main.c now)
Anselm R. Garbe <arg@suckless.org>
parents:
770
diff
changeset
|
106 |
dc.font.xfont = NULL; |
469dc170f833
draw.c is useless (belongs to main.c now)
Anselm R. Garbe <arg@suckless.org>
parents:
770
diff
changeset
|
107 |
if(!(dc.font.xfont = XLoadQueryFont(dpy, fontstr))) |
469dc170f833
draw.c is useless (belongs to main.c now)
Anselm R. Garbe <arg@suckless.org>
parents:
770
diff
changeset
|
108 |
eprint("error, cannot load font: '%s'\n", fontstr); |
469dc170f833
draw.c is useless (belongs to main.c now)
Anselm R. Garbe <arg@suckless.org>
parents:
770
diff
changeset
|
109 |
dc.font.ascent = dc.font.xfont->ascent; |
469dc170f833
draw.c is useless (belongs to main.c now)
Anselm R. Garbe <arg@suckless.org>
parents:
770
diff
changeset
|
110 |
dc.font.descent = dc.font.xfont->descent; |
469dc170f833
draw.c is useless (belongs to main.c now)
Anselm R. Garbe <arg@suckless.org>
parents:
770
diff
changeset
|
111 |
} |
469dc170f833
draw.c is useless (belongs to main.c now)
Anselm R. Garbe <arg@suckless.org>
parents:
770
diff
changeset
|
112 |
dc.font.height = dc.font.ascent + dc.font.descent; |
469dc170f833
draw.c is useless (belongs to main.c now)
Anselm R. Garbe <arg@suckless.org>
parents:
770
diff
changeset
|
113 |
} |
469dc170f833
draw.c is useless (belongs to main.c now)
Anselm R. Garbe <arg@suckless.org>
parents:
770
diff
changeset
|
114 |
|
469dc170f833
draw.c is useless (belongs to main.c now)
Anselm R. Garbe <arg@suckless.org>
parents:
770
diff
changeset
|
115 |
static void |
795
3b23c75920a3
renamed setfont to initfont, getcolor to initcolor
Anselm R. Garbe <arg@suckless.org>
parents:
793
diff
changeset
|
116 |
scan(void) { |
3b23c75920a3
renamed setfont to initfont, getcolor to initcolor
Anselm R. Garbe <arg@suckless.org>
parents:
793
diff
changeset
|
117 |
unsigned int i, num; |
3b23c75920a3
renamed setfont to initfont, getcolor to initcolor
Anselm R. Garbe <arg@suckless.org>
parents:
793
diff
changeset
|
118 |
Window *wins, d1, d2; |
3b23c75920a3
renamed setfont to initfont, getcolor to initcolor
Anselm R. Garbe <arg@suckless.org>
parents:
793
diff
changeset
|
119 |
XWindowAttributes wa; |
3b23c75920a3
renamed setfont to initfont, getcolor to initcolor
Anselm R. Garbe <arg@suckless.org>
parents:
793
diff
changeset
|
120 |
|
3b23c75920a3
renamed setfont to initfont, getcolor to initcolor
Anselm R. Garbe <arg@suckless.org>
parents:
793
diff
changeset
|
121 |
wins = NULL; |
3b23c75920a3
renamed setfont to initfont, getcolor to initcolor
Anselm R. Garbe <arg@suckless.org>
parents:
793
diff
changeset
|
122 |
if(XQueryTree(dpy, root, &d1, &d2, &wins, &num)) { |
3b23c75920a3
renamed setfont to initfont, getcolor to initcolor
Anselm R. Garbe <arg@suckless.org>
parents:
793
diff
changeset
|
123 |
for(i = 0; i < num; i++) { |
3b23c75920a3
renamed setfont to initfont, getcolor to initcolor
Anselm R. Garbe <arg@suckless.org>
parents:
793
diff
changeset
|
124 |
if(!XGetWindowAttributes(dpy, wins[i], &wa) |
3b23c75920a3
renamed setfont to initfont, getcolor to initcolor
Anselm R. Garbe <arg@suckless.org>
parents:
793
diff
changeset
|
125 |
|| wa.override_redirect || XGetTransientForHint(dpy, wins[i], &d1)) |
3b23c75920a3
renamed setfont to initfont, getcolor to initcolor
Anselm R. Garbe <arg@suckless.org>
parents:
793
diff
changeset
|
126 |
continue; |
3b23c75920a3
renamed setfont to initfont, getcolor to initcolor
Anselm R. Garbe <arg@suckless.org>
parents:
793
diff
changeset
|
127 |
if(wa.map_state == IsViewable) |
3b23c75920a3
renamed setfont to initfont, getcolor to initcolor
Anselm R. Garbe <arg@suckless.org>
parents:
793
diff
changeset
|
128 |
manage(wins[i], &wa); |
3b23c75920a3
renamed setfont to initfont, getcolor to initcolor
Anselm R. Garbe <arg@suckless.org>
parents:
793
diff
changeset
|
129 |
} |
3b23c75920a3
renamed setfont to initfont, getcolor to initcolor
Anselm R. Garbe <arg@suckless.org>
parents:
793
diff
changeset
|
130 |
} |
3b23c75920a3
renamed setfont to initfont, getcolor to initcolor
Anselm R. Garbe <arg@suckless.org>
parents:
793
diff
changeset
|
131 |
if(wins) |
3b23c75920a3
renamed setfont to initfont, getcolor to initcolor
Anselm R. Garbe <arg@suckless.org>
parents:
793
diff
changeset
|
132 |
XFree(wins); |
3b23c75920a3
renamed setfont to initfont, getcolor to initcolor
Anselm R. Garbe <arg@suckless.org>
parents:
793
diff
changeset
|
133 |
} |
3b23c75920a3
renamed setfont to initfont, getcolor to initcolor
Anselm R. Garbe <arg@suckless.org>
parents:
793
diff
changeset
|
134 |
|
3b23c75920a3
renamed setfont to initfont, getcolor to initcolor
Anselm R. Garbe <arg@suckless.org>
parents:
793
diff
changeset
|
135 |
static void |
487 | 136 |
setup(void) { |
333
827f8f6c9e97
separated setup stuff into main.c:setup() - this makes main() more readable
Anselm R. Garbe <arg@10kloc.org>
parents:
329
diff
changeset
|
137 |
int i, j; |
827f8f6c9e97
separated setup stuff into main.c:setup() - this makes main() more readable
Anselm R. Garbe <arg@10kloc.org>
parents:
329
diff
changeset
|
138 |
unsigned int mask; |
827f8f6c9e97
separated setup stuff into main.c:setup() - this makes main() more readable
Anselm R. Garbe <arg@10kloc.org>
parents:
329
diff
changeset
|
139 |
Window w; |
827f8f6c9e97
separated setup stuff into main.c:setup() - this makes main() more readable
Anselm R. Garbe <arg@10kloc.org>
parents:
329
diff
changeset
|
140 |
XModifierKeymap *modmap; |
827f8f6c9e97
separated setup stuff into main.c:setup() - this makes main() more readable
Anselm R. Garbe <arg@10kloc.org>
parents:
329
diff
changeset
|
141 |
XSetWindowAttributes wa; |
827f8f6c9e97
separated setup stuff into main.c:setup() - this makes main() more readable
Anselm R. Garbe <arg@10kloc.org>
parents:
329
diff
changeset
|
142 |
|
827f8f6c9e97
separated setup stuff into main.c:setup() - this makes main() more readable
Anselm R. Garbe <arg@10kloc.org>
parents:
329
diff
changeset
|
143 |
/* init atoms */ |
827f8f6c9e97
separated setup stuff into main.c:setup() - this makes main() more readable
Anselm R. Garbe <arg@10kloc.org>
parents:
329
diff
changeset
|
144 |
wmatom[WMProtocols] = XInternAtom(dpy, "WM_PROTOCOLS", False); |
827f8f6c9e97
separated setup stuff into main.c:setup() - this makes main() more readable
Anselm R. Garbe <arg@10kloc.org>
parents:
329
diff
changeset
|
145 |
wmatom[WMDelete] = XInternAtom(dpy, "WM_DELETE_WINDOW", False); |
725
d99be681d502
handling WM_STATE seems to make DnD in gtk/qt apps working, well let's handle this in dwm as well
Anselm R. Garbe <arg@suckless.org>
parents:
716
diff
changeset
|
146 |
wmatom[WMState] = XInternAtom(dpy, "WM_STATE", False); |
333
827f8f6c9e97
separated setup stuff into main.c:setup() - this makes main() more readable
Anselm R. Garbe <arg@10kloc.org>
parents:
329
diff
changeset
|
147 |
netatom[NetSupported] = XInternAtom(dpy, "_NET_SUPPORTED", False); |
827f8f6c9e97
separated setup stuff into main.c:setup() - this makes main() more readable
Anselm R. Garbe <arg@10kloc.org>
parents:
329
diff
changeset
|
148 |
netatom[NetWMName] = XInternAtom(dpy, "_NET_WM_NAME", False); |
827f8f6c9e97
separated setup stuff into main.c:setup() - this makes main() more readable
Anselm R. Garbe <arg@10kloc.org>
parents:
329
diff
changeset
|
149 |
XChangeProperty(dpy, root, netatom[NetSupported], XA_ATOM, 32, |
827f8f6c9e97
separated setup stuff into main.c:setup() - this makes main() more readable
Anselm R. Garbe <arg@10kloc.org>
parents:
329
diff
changeset
|
150 |
PropModeReplace, (unsigned char *) netatom, NetLast); |
827f8f6c9e97
separated setup stuff into main.c:setup() - this makes main() more readable
Anselm R. Garbe <arg@10kloc.org>
parents:
329
diff
changeset
|
151 |
/* init cursors */ |
827f8f6c9e97
separated setup stuff into main.c:setup() - this makes main() more readable
Anselm R. Garbe <arg@10kloc.org>
parents:
329
diff
changeset
|
152 |
cursor[CurNormal] = XCreateFontCursor(dpy, XC_left_ptr); |
827f8f6c9e97
separated setup stuff into main.c:setup() - this makes main() more readable
Anselm R. Garbe <arg@10kloc.org>
parents:
329
diff
changeset
|
153 |
cursor[CurResize] = XCreateFontCursor(dpy, XC_sizing); |
827f8f6c9e97
separated setup stuff into main.c:setup() - this makes main() more readable
Anselm R. Garbe <arg@10kloc.org>
parents:
329
diff
changeset
|
154 |
cursor[CurMove] = XCreateFontCursor(dpy, XC_fleur); |
532
651f2c868b31
code polishing, removed unnecessary newlines
Anselm R. Garbe <arg@10kloc.org>
parents:
530
diff
changeset
|
155 |
/* init modifier map */ |
679
5f0134b88b8d
small fix of initial numlockmask value
Anselm R. Garbe <arg@suckless.org>
parents:
675
diff
changeset
|
156 |
numlockmask = 0; |
333
827f8f6c9e97
separated setup stuff into main.c:setup() - this makes main() more readable
Anselm R. Garbe <arg@10kloc.org>
parents:
329
diff
changeset
|
157 |
modmap = XGetModifierMapping(dpy); |
757
22dfaeb82491
made for/if/else constructs more consistent, some code polishing
Anselm R. Garbe <arg@suckless.org>
parents:
744
diff
changeset
|
158 |
for (i = 0; i < 8; i++) |
333
827f8f6c9e97
separated setup stuff into main.c:setup() - this makes main() more readable
Anselm R. Garbe <arg@10kloc.org>
parents:
329
diff
changeset
|
159 |
for (j = 0; j < modmap->max_keypermod; j++) { |
757
22dfaeb82491
made for/if/else constructs more consistent, some code polishing
Anselm R. Garbe <arg@suckless.org>
parents:
744
diff
changeset
|
160 |
if(modmap->modifiermap[i * modmap->max_keypermod + j] |
22dfaeb82491
made for/if/else constructs more consistent, some code polishing
Anselm R. Garbe <arg@suckless.org>
parents:
744
diff
changeset
|
161 |
== XKeysymToKeycode(dpy, XK_Num_Lock)) |
333
827f8f6c9e97
separated setup stuff into main.c:setup() - this makes main() more readable
Anselm R. Garbe <arg@10kloc.org>
parents:
329
diff
changeset
|
162 |
numlockmask = (1 << i); |
827f8f6c9e97
separated setup stuff into main.c:setup() - this makes main() more readable
Anselm R. Garbe <arg@10kloc.org>
parents:
329
diff
changeset
|
163 |
} |
616 | 164 |
XFreeModifiermap(modmap); |
532
651f2c868b31
code polishing, removed unnecessary newlines
Anselm R. Garbe <arg@10kloc.org>
parents:
530
diff
changeset
|
165 |
/* select for events */ |
461
9d23330a5268
removed a bunch of lines through making function signatures more consistent with my style ( { does not belong to a new line, if function args are single-lined)
Anselm R. Garbe <arg@10kloc.org>
parents:
458
diff
changeset
|
166 |
wa.event_mask = SubstructureRedirectMask | SubstructureNotifyMask |
9d23330a5268
removed a bunch of lines through making function signatures more consistent with my style ( { does not belong to a new line, if function args are single-lined)
Anselm R. Garbe <arg@10kloc.org>
parents:
458
diff
changeset
|
167 |
| EnterWindowMask | LeaveWindowMask; |
333
827f8f6c9e97
separated setup stuff into main.c:setup() - this makes main() more readable
Anselm R. Garbe <arg@10kloc.org>
parents:
329
diff
changeset
|
168 |
wa.cursor = cursor[CurNormal]; |
827f8f6c9e97
separated setup stuff into main.c:setup() - this makes main() more readable
Anselm R. Garbe <arg@10kloc.org>
parents:
329
diff
changeset
|
169 |
XChangeWindowAttributes(dpy, root, CWEventMask | CWCursor, &wa); |
827f8f6c9e97
separated setup stuff into main.c:setup() - this makes main() more readable
Anselm R. Garbe <arg@10kloc.org>
parents:
329
diff
changeset
|
170 |
grabkeys(); |
782
92862ab407d5
introduced Layout struct
Anselm R. Garbe <arg@suckless.org>
parents:
778
diff
changeset
|
171 |
compileregs(); |
333
827f8f6c9e97
separated setup stuff into main.c:setup() - this makes main() more readable
Anselm R. Garbe <arg@10kloc.org>
parents:
329
diff
changeset
|
172 |
for(ntags = 0; tags[ntags]; ntags++); |
827f8f6c9e97
separated setup stuff into main.c:setup() - this makes main() more readable
Anselm R. Garbe <arg@10kloc.org>
parents:
329
diff
changeset
|
173 |
seltag = emallocz(sizeof(Bool) * ntags); |
827f8f6c9e97
separated setup stuff into main.c:setup() - this makes main() more readable
Anselm R. Garbe <arg@10kloc.org>
parents:
329
diff
changeset
|
174 |
seltag[0] = True; |
827f8f6c9e97
separated setup stuff into main.c:setup() - this makes main() more readable
Anselm R. Garbe <arg@10kloc.org>
parents:
329
diff
changeset
|
175 |
/* style */ |
795
3b23c75920a3
renamed setfont to initfont, getcolor to initcolor
Anselm R. Garbe <arg@suckless.org>
parents:
793
diff
changeset
|
176 |
dc.norm[ColBorder] = initcolor(NORMBORDERCOLOR); |
3b23c75920a3
renamed setfont to initfont, getcolor to initcolor
Anselm R. Garbe <arg@suckless.org>
parents:
793
diff
changeset
|
177 |
dc.norm[ColBG] = initcolor(NORMBGCOLOR); |
3b23c75920a3
renamed setfont to initfont, getcolor to initcolor
Anselm R. Garbe <arg@suckless.org>
parents:
793
diff
changeset
|
178 |
dc.norm[ColFG] = initcolor(NORMFGCOLOR); |
3b23c75920a3
renamed setfont to initfont, getcolor to initcolor
Anselm R. Garbe <arg@suckless.org>
parents:
793
diff
changeset
|
179 |
dc.sel[ColBorder] = initcolor(SELBORDERCOLOR); |
3b23c75920a3
renamed setfont to initfont, getcolor to initcolor
Anselm R. Garbe <arg@suckless.org>
parents:
793
diff
changeset
|
180 |
dc.sel[ColBG] = initcolor(SELBGCOLOR); |
3b23c75920a3
renamed setfont to initfont, getcolor to initcolor
Anselm R. Garbe <arg@suckless.org>
parents:
793
diff
changeset
|
181 |
dc.sel[ColFG] = initcolor(SELFGCOLOR); |
3b23c75920a3
renamed setfont to initfont, getcolor to initcolor
Anselm R. Garbe <arg@suckless.org>
parents:
793
diff
changeset
|
182 |
initfont(FONT); |
532
651f2c868b31
code polishing, removed unnecessary newlines
Anselm R. Garbe <arg@10kloc.org>
parents:
530
diff
changeset
|
183 |
/* geometry */ |
333
827f8f6c9e97
separated setup stuff into main.c:setup() - this makes main() more readable
Anselm R. Garbe <arg@10kloc.org>
parents:
329
diff
changeset
|
184 |
sw = DisplayWidth(dpy, screen); |
827f8f6c9e97
separated setup stuff into main.c:setup() - this makes main() more readable
Anselm R. Garbe <arg@10kloc.org>
parents:
329
diff
changeset
|
185 |
sh = DisplayHeight(dpy, screen); |
782
92862ab407d5
introduced Layout struct
Anselm R. Garbe <arg@suckless.org>
parents:
778
diff
changeset
|
186 |
initlayouts(); |
532
651f2c868b31
code polishing, removed unnecessary newlines
Anselm R. Garbe <arg@10kloc.org>
parents:
530
diff
changeset
|
187 |
/* bar */ |
353
8a06efe5b563
new color stuff/new rendering stuff
Anselm R. Garbe <arg@10kloc.org>
parents:
352
diff
changeset
|
188 |
dc.h = bh = dc.font.height + 2; |
333
827f8f6c9e97
separated setup stuff into main.c:setup() - this makes main() more readable
Anselm R. Garbe <arg@10kloc.org>
parents:
329
diff
changeset
|
189 |
wa.override_redirect = 1; |
827f8f6c9e97
separated setup stuff into main.c:setup() - this makes main() more readable
Anselm R. Garbe <arg@10kloc.org>
parents:
329
diff
changeset
|
190 |
wa.background_pixmap = ParentRelative; |
827f8f6c9e97
separated setup stuff into main.c:setup() - this makes main() more readable
Anselm R. Garbe <arg@10kloc.org>
parents:
329
diff
changeset
|
191 |
wa.event_mask = ButtonPressMask | ExposureMask; |
800
6133edf536de
removed some global vars which should be static instead
Anselm R. Garbe <arg@suckless.org>
parents:
795
diff
changeset
|
192 |
barwin = XCreateWindow(dpy, root, 0, (TOPBAR ? 0 : sh - bh), sw, bh, 0, |
739
7834ffd650d5
added TOPBAR option for making the bar appear what the user likes
Anselm R. Garbe <arg@suckless.org>
parents:
737
diff
changeset
|
193 |
DefaultDepth(dpy, screen), CopyFromParent, DefaultVisual(dpy, screen), |
333
827f8f6c9e97
separated setup stuff into main.c:setup() - this makes main() more readable
Anselm R. Garbe <arg@10kloc.org>
parents:
329
diff
changeset
|
194 |
CWOverrideRedirect | CWBackPixmap | CWEventMask, &wa); |
827f8f6c9e97
separated setup stuff into main.c:setup() - this makes main() more readable
Anselm R. Garbe <arg@10kloc.org>
parents:
329
diff
changeset
|
195 |
XDefineCursor(dpy, barwin, cursor[CurNormal]); |
827f8f6c9e97
separated setup stuff into main.c:setup() - this makes main() more readable
Anselm R. Garbe <arg@10kloc.org>
parents:
329
diff
changeset
|
196 |
XMapRaised(dpy, barwin); |
532
651f2c868b31
code polishing, removed unnecessary newlines
Anselm R. Garbe <arg@10kloc.org>
parents:
530
diff
changeset
|
197 |
strcpy(stext, "dwm-"VERSION); |
565 | 198 |
/* windowarea */ |
800
6133edf536de
removed some global vars which should be static instead
Anselm R. Garbe <arg@suckless.org>
parents:
795
diff
changeset
|
199 |
wax = 0; |
6133edf536de
removed some global vars which should be static instead
Anselm R. Garbe <arg@suckless.org>
parents:
795
diff
changeset
|
200 |
way = (TOPBAR ? bh : 0); |
565 | 201 |
wah = sh - bh; |
202 |
waw = sw; |
|
532
651f2c868b31
code polishing, removed unnecessary newlines
Anselm R. Garbe <arg@10kloc.org>
parents:
530
diff
changeset
|
203 |
/* pixmap for everything */ |
333
827f8f6c9e97
separated setup stuff into main.c:setup() - this makes main() more readable
Anselm R. Garbe <arg@10kloc.org>
parents:
329
diff
changeset
|
204 |
dc.drawable = XCreatePixmap(dpy, root, sw, bh, DefaultDepth(dpy, screen)); |
827f8f6c9e97
separated setup stuff into main.c:setup() - this makes main() more readable
Anselm R. Garbe <arg@10kloc.org>
parents:
329
diff
changeset
|
205 |
dc.gc = XCreateGC(dpy, root, 0, 0); |
344
93192711a36a
changing tag indicator through underline
Anselm R. Garbe <arg@10kloc.org>
parents:
339
diff
changeset
|
206 |
XSetLineAttributes(dpy, dc.gc, 1, LineSolid, CapButt, JoinMiter); |
532
651f2c868b31
code polishing, removed unnecessary newlines
Anselm R. Garbe <arg@10kloc.org>
parents:
530
diff
changeset
|
207 |
/* multihead support */ |
716
4ce65f61f01b
renamed activescreen into selscreen
Anselm R. Garbe <arg@suckless.org>
parents:
714
diff
changeset
|
208 |
selscreen = XQueryPointer(dpy, root, &w, &w, &i, &i, &i, &i, &mask); |
333
827f8f6c9e97
separated setup stuff into main.c:setup() - this makes main() more readable
Anselm R. Garbe <arg@10kloc.org>
parents:
329
diff
changeset
|
209 |
} |
827f8f6c9e97
separated setup stuff into main.c:setup() - this makes main() more readable
Anselm R. Garbe <arg@10kloc.org>
parents:
329
diff
changeset
|
210 |
|
76
4bd49f404f10
proceeded with cleaning up, sorting functions, etc
Anselm R. Garbe <garbeam@wmii.de>
parents:
75
diff
changeset
|
211 |
/* |
4bd49f404f10
proceeded with cleaning up, sorting functions, etc
Anselm R. Garbe <garbeam@wmii.de>
parents:
75
diff
changeset
|
212 |
* Startup Error handler to check if another window manager |
4bd49f404f10
proceeded with cleaning up, sorting functions, etc
Anselm R. Garbe <garbeam@wmii.de>
parents:
75
diff
changeset
|
213 |
* is already running. |
4bd49f404f10
proceeded with cleaning up, sorting functions, etc
Anselm R. Garbe <garbeam@wmii.de>
parents:
75
diff
changeset
|
214 |
*/ |
4bd49f404f10
proceeded with cleaning up, sorting functions, etc
Anselm R. Garbe <garbeam@wmii.de>
parents:
75
diff
changeset
|
215 |
static int |
461
9d23330a5268
removed a bunch of lines through making function signatures more consistent with my style ( { does not belong to a new line, if function args are single-lined)
Anselm R. Garbe <arg@10kloc.org>
parents:
458
diff
changeset
|
216 |
xerrorstart(Display *dsply, XErrorEvent *ee) { |
76
4bd49f404f10
proceeded with cleaning up, sorting functions, etc
Anselm R. Garbe <garbeam@wmii.de>
parents:
75
diff
changeset
|
217 |
otherwm = True; |
4bd49f404f10
proceeded with cleaning up, sorting functions, etc
Anselm R. Garbe <garbeam@wmii.de>
parents:
75
diff
changeset
|
218 |
return -1; |
4bd49f404f10
proceeded with cleaning up, sorting functions, etc
Anselm R. Garbe <garbeam@wmii.de>
parents:
75
diff
changeset
|
219 |
} |
4bd49f404f10
proceeded with cleaning up, sorting functions, etc
Anselm R. Garbe <garbeam@wmii.de>
parents:
75
diff
changeset
|
220 |
|
84
052fe7498930
ordered variables in structs and source files alphabetically
Anselm R. Garbe <garbeam@wmii.de>
parents:
79
diff
changeset
|
221 |
/* extern */ |
052fe7498930
ordered variables in structs and source files alphabetically
Anselm R. Garbe <garbeam@wmii.de>
parents:
79
diff
changeset
|
222 |
|
13
5cc5e55a132d
added protocol killing stuff
Anselm R. Garbe <garbeam@wmii.de>
parents:
10
diff
changeset
|
223 |
void |
461
9d23330a5268
removed a bunch of lines through making function signatures more consistent with my style ( { does not belong to a new line, if function args are single-lined)
Anselm R. Garbe <arg@10kloc.org>
parents:
458
diff
changeset
|
224 |
sendevent(Window w, Atom a, long value) { |
13
5cc5e55a132d
added protocol killing stuff
Anselm R. Garbe <garbeam@wmii.de>
parents:
10
diff
changeset
|
225 |
XEvent e; |
5cc5e55a132d
added protocol killing stuff
Anselm R. Garbe <garbeam@wmii.de>
parents:
10
diff
changeset
|
226 |
|
5cc5e55a132d
added protocol killing stuff
Anselm R. Garbe <garbeam@wmii.de>
parents:
10
diff
changeset
|
227 |
e.type = ClientMessage; |
5cc5e55a132d
added protocol killing stuff
Anselm R. Garbe <garbeam@wmii.de>
parents:
10
diff
changeset
|
228 |
e.xclient.window = w; |
5cc5e55a132d
added protocol killing stuff
Anselm R. Garbe <garbeam@wmii.de>
parents:
10
diff
changeset
|
229 |
e.xclient.message_type = a; |
5cc5e55a132d
added protocol killing stuff
Anselm R. Garbe <garbeam@wmii.de>
parents:
10
diff
changeset
|
230 |
e.xclient.format = 32; |
5cc5e55a132d
added protocol killing stuff
Anselm R. Garbe <garbeam@wmii.de>
parents:
10
diff
changeset
|
231 |
e.xclient.data.l[0] = value; |
5cc5e55a132d
added protocol killing stuff
Anselm R. Garbe <garbeam@wmii.de>
parents:
10
diff
changeset
|
232 |
e.xclient.data.l[1] = CurrentTime; |
5cc5e55a132d
added protocol killing stuff
Anselm R. Garbe <garbeam@wmii.de>
parents:
10
diff
changeset
|
233 |
XSendEvent(dpy, w, False, NoEventMask, &e); |
79
aabebd6e61f3
fixed XSync handling and finished man page
Anselm R. Garbe <garbeam@wmii.de>
parents:
78
diff
changeset
|
234 |
XSync(dpy, False); |
13
5cc5e55a132d
added protocol killing stuff
Anselm R. Garbe <garbeam@wmii.de>
parents:
10
diff
changeset
|
235 |
} |
5cc5e55a132d
added protocol killing stuff
Anselm R. Garbe <garbeam@wmii.de>
parents:
10
diff
changeset
|
236 |
|
76
4bd49f404f10
proceeded with cleaning up, sorting functions, etc
Anselm R. Garbe <garbeam@wmii.de>
parents:
75
diff
changeset
|
237 |
void |
461
9d23330a5268
removed a bunch of lines through making function signatures more consistent with my style ( { does not belong to a new line, if function args are single-lined)
Anselm R. Garbe <arg@10kloc.org>
parents:
458
diff
changeset
|
238 |
quit(Arg *arg) { |
302 | 239 |
readin = running = False; |
75 | 240 |
} |
241 |
||
532
651f2c868b31
code polishing, removed unnecessary newlines
Anselm R. Garbe <arg@10kloc.org>
parents:
530
diff
changeset
|
242 |
/* There's no way to check accesses to destroyed windows, thus those cases are |
84
052fe7498930
ordered variables in structs and source files alphabetically
Anselm R. Garbe <garbeam@wmii.de>
parents:
79
diff
changeset
|
243 |
* ignored (especially on UnmapNotify's). Other types of errors call Xlibs |
455
4e3e22673073
fixed some other comments, now also the code side seems to be at a level to be reviewed by experienced programmers
Anselm R. Garbe <arg@10kloc.org>
parents:
446
diff
changeset
|
244 |
* default error handler, which may call exit. |
0 | 245 |
*/ |
10
703255003abb
changed how manage client works
Anselm R. Garbe <garbeam@wmii.de>
parents:
9
diff
changeset
|
246 |
int |
461
9d23330a5268
removed a bunch of lines through making function signatures more consistent with my style ( { does not belong to a new line, if function args are single-lined)
Anselm R. Garbe <arg@10kloc.org>
parents:
458
diff
changeset
|
247 |
xerror(Display *dpy, XErrorEvent *ee) { |
75 | 248 |
if(ee->error_code == BadWindow |
123 | 249 |
|| (ee->request_code == X_SetInputFocus && ee->error_code == BadMatch) |
250 |
|| (ee->request_code == X_PolyText8 && ee->error_code == BadDrawable) |
|
251 |
|| (ee->request_code == X_PolyFillRectangle && ee->error_code == BadDrawable) |
|
252 |
|| (ee->request_code == X_PolySegment && ee->error_code == BadDrawable) |
|
253 |
|| (ee->request_code == X_ConfigureWindow && ee->error_code == BadMatch) |
|
458
81fcd7ddafee
applied Christof Musik's multihead patch for a pathologic cornercase
Anselm R. Garbe <arg@10kloc.org>
parents:
455
diff
changeset
|
254 |
|| (ee->request_code == X_GrabKey && ee->error_code == BadAccess) |
81fcd7ddafee
applied Christof Musik's multihead patch for a pathologic cornercase
Anselm R. Garbe <arg@10kloc.org>
parents:
455
diff
changeset
|
255 |
|| (ee->request_code == X_CopyArea && ee->error_code == BadDrawable)) |
0 | 256 |
return 0; |
34 | 257 |
fprintf(stderr, "dwm: fatal error: request code=%d, error code=%d\n", |
123 | 258 |
ee->request_code, ee->error_code); |
455
4e3e22673073
fixed some other comments, now also the code side seems to be at a level to be reviewed by experienced programmers
Anselm R. Garbe <arg@10kloc.org>
parents:
446
diff
changeset
|
259 |
return xerrorxlib(dpy, ee); /* may call exit */ |
27
f96fb3fd8203
added grid mode on Mod1Mask g
Anselm R. Garbe <garbeam@wmii.de>
parents:
26
diff
changeset
|
260 |
} |
f96fb3fd8203
added grid mode on Mod1Mask g
Anselm R. Garbe <garbeam@wmii.de>
parents:
26
diff
changeset
|
261 |
|
0 | 262 |
int |
461
9d23330a5268
removed a bunch of lines through making function signatures more consistent with my style ( { does not belong to a new line, if function args are single-lined)
Anselm R. Garbe <arg@10kloc.org>
parents:
458
diff
changeset
|
263 |
main(int argc, char *argv[]) { |
581
601842ee4484
applied Jukka's sizeof K&R compliance patch, applied Manuels' last-line printage proposal for stdin reading.
arg@mig29
parents:
580
diff
changeset
|
264 |
char *p; |
333
827f8f6c9e97
separated setup stuff into main.c:setup() - this makes main() more readable
Anselm R. Garbe <arg@10kloc.org>
parents:
329
diff
changeset
|
265 |
int r, xfd; |
59
5d4653de9a1c
implemented dwm reading status text from stdin
Anselm R. Garbe <garbeam@wmii.de>
parents:
58
diff
changeset
|
266 |
fd_set rd; |
778
2ec66bdbb8ad
removed procevent, more refactoring
Anselm R. Garbe <arg@suckless.org>
parents:
777
diff
changeset
|
267 |
XEvent ev; |
0 | 268 |
|
789
3edec0a35000
using eprint instead of fputs
Anselm R. Garbe <arg@suckless.org>
parents:
782
diff
changeset
|
269 |
if(argc == 2 && !strncmp("-v", argv[1], 3)) |
3edec0a35000
using eprint instead of fputs
Anselm R. Garbe <arg@suckless.org>
parents:
782
diff
changeset
|
270 |
eprint("dwm-"VERSION", (C)opyright MMVI-MMVII Anselm R. Garbe\n"); |
137
77922a389fa8
simplified main.c, switching back to single urxvt usage
arg@10ksloc.org
parents:
126
diff
changeset
|
271 |
else if(argc != 1) |
77922a389fa8
simplified main.c, switching back to single urxvt usage
arg@10ksloc.org
parents:
126
diff
changeset
|
272 |
eprint("usage: dwm [-v]\n"); |
619 | 273 |
setlocale(LC_CTYPE, ""); |
789
3edec0a35000
using eprint instead of fputs
Anselm R. Garbe <arg@suckless.org>
parents:
782
diff
changeset
|
274 |
if(!(dpy = XOpenDisplay(0))) |
197 | 275 |
eprint("dwm: cannot open display\n"); |
265
573b1c4a71a4
reducing ConnectionNumber calls to a bare minimum
Anselm R.Garbe <arg@10ksloc.org>
parents:
262
diff
changeset
|
276 |
xfd = ConnectionNumber(dpy); |
0 | 277 |
screen = DefaultScreen(dpy); |
278 |
root = RootWindow(dpy, screen); |
|
75 | 279 |
otherwm = False; |
280 |
XSetErrorHandler(xerrorstart); |
|
197 | 281 |
/* this causes an error if some other window manager is running */ |
0 | 282 |
XSelectInput(dpy, root, SubstructureRedirectMask); |
78
0d71fb80b592
changing XFlush into XSync
Anselm R. Garbe <garbeam@wmii.de>
parents:
77
diff
changeset
|
283 |
XSync(dpy, False); |
75 | 284 |
if(otherwm) |
285 |
eprint("dwm: another window manager is already running\n"); |
|
0 | 286 |
|
292 | 287 |
XSync(dpy, False); |
78
0d71fb80b592
changing XFlush into XSync
Anselm R. Garbe <garbeam@wmii.de>
parents:
77
diff
changeset
|
288 |
XSetErrorHandler(NULL); |
75 | 289 |
xerrorxlib = XSetErrorHandler(xerror); |
275 | 290 |
XSync(dpy, False); |
333
827f8f6c9e97
separated setup stuff into main.c:setup() - this makes main() more readable
Anselm R. Garbe <arg@10kloc.org>
parents:
329
diff
changeset
|
291 |
setup(); |
74 | 292 |
drawstatus(); |
75 | 293 |
scan(); |
3
e969f3575b7a
several new changes, made gridmenu working
Anselm R. Garbe <garbeam@wmii.de>
parents:
2
diff
changeset
|
294 |
|
214 | 295 |
/* main event loop, also reads status text from stdin */ |
242 | 296 |
XSync(dpy, False); |
302 | 297 |
readin = True; |
5 | 298 |
while(running) { |
59
5d4653de9a1c
implemented dwm reading status text from stdin
Anselm R. Garbe <garbeam@wmii.de>
parents:
58
diff
changeset
|
299 |
FD_ZERO(&rd); |
164
21071ae1fe68
made fullscreen apps working fine in floating mode (there is no sane way to make them work in tiled mode, thus I switch to floating mode if I run such kind of app), also fixed the xterm issue reported by Sander
arg@10ksloc.org
parents:
162
diff
changeset
|
300 |
if(readin) |
21071ae1fe68
made fullscreen apps working fine in floating mode (there is no sane way to make them work in tiled mode, thus I switch to floating mode if I run such kind of app), also fixed the xterm issue reported by Sander
arg@10ksloc.org
parents:
162
diff
changeset
|
301 |
FD_SET(STDIN_FILENO, &rd); |
265
573b1c4a71a4
reducing ConnectionNumber calls to a bare minimum
Anselm R.Garbe <arg@10ksloc.org>
parents:
262
diff
changeset
|
302 |
FD_SET(xfd, &rd); |
578 | 303 |
if(select(xfd + 1, &rd, NULL, NULL, NULL) == -1) { |
304 |
if(errno == EINTR) |
|
305 |
continue; |
|
581
601842ee4484
applied Jukka's sizeof K&R compliance patch, applied Manuels' last-line printage proposal for stdin reading.
arg@mig29
parents:
580
diff
changeset
|
306 |
eprint("select failed\n"); |
578 | 307 |
} |
308 |
if(FD_ISSET(STDIN_FILENO, &rd)) { |
|
581
601842ee4484
applied Jukka's sizeof K&R compliance patch, applied Manuels' last-line printage proposal for stdin reading.
arg@mig29
parents:
580
diff
changeset
|
309 |
switch(r = read(STDIN_FILENO, stext, sizeof stext - 1)) { |
578 | 310 |
case -1: |
581
601842ee4484
applied Jukka's sizeof K&R compliance patch, applied Manuels' last-line printage proposal for stdin reading.
arg@mig29
parents:
580
diff
changeset
|
311 |
strncpy(stext, strerror(errno), sizeof stext - 1); |
583
f4285a97e3e6
applied Jukka's patch preventing some cornercases and making the EOF error message correct
arg@mig29
parents:
582
diff
changeset
|
312 |
stext[sizeof stext - 1] = '\0'; |
578 | 313 |
readin = False; |
314 |
break; |
|
315 |
case 0: |
|
583
f4285a97e3e6
applied Jukka's patch preventing some cornercases and making the EOF error message correct
arg@mig29
parents:
582
diff
changeset
|
316 |
strncpy(stext, "EOF", 4); |
578 | 317 |
readin = False; |
318 |
break; |
|
319 |
default: |
|
582 | 320 |
for(stext[r] = '\0', p = stext + strlen(stext) - 1; p >= stext && *p == '\n'; *p-- = '\0'); |
744
628c5bac7f3b
pneubeck pointed out an obvious thing, that a second p = stext + strlen(stext) - 1 is unnecessary
Anselm R. Garbe <arg@suckless.org>
parents:
740
diff
changeset
|
321 |
for(; p >= stext && *p != '\n'; --p); |
581
601842ee4484
applied Jukka's sizeof K&R compliance patch, applied Manuels' last-line printage proposal for stdin reading.
arg@mig29
parents:
580
diff
changeset
|
322 |
if(p > stext) |
601842ee4484
applied Jukka's sizeof K&R compliance patch, applied Manuels' last-line printage proposal for stdin reading.
arg@mig29
parents:
580
diff
changeset
|
323 |
strncpy(stext, p + 1, sizeof stext); |
59
5d4653de9a1c
implemented dwm reading status text from stdin
Anselm R. Garbe <garbeam@wmii.de>
parents:
58
diff
changeset
|
324 |
} |
578 | 325 |
drawstatus(); |
59
5d4653de9a1c
implemented dwm reading status text from stdin
Anselm R. Garbe <garbeam@wmii.de>
parents:
58
diff
changeset
|
326 |
} |
578 | 327 |
if(FD_ISSET(xfd, &rd)) |
778
2ec66bdbb8ad
removed procevent, more refactoring
Anselm R. Garbe <arg@suckless.org>
parents:
777
diff
changeset
|
328 |
while(XPending(dpy)) { |
2ec66bdbb8ad
removed procevent, more refactoring
Anselm R. Garbe <arg@suckless.org>
parents:
777
diff
changeset
|
329 |
XNextEvent(dpy, &ev); |
2ec66bdbb8ad
removed procevent, more refactoring
Anselm R. Garbe <arg@suckless.org>
parents:
777
diff
changeset
|
330 |
if(handler[ev.type]) |
2ec66bdbb8ad
removed procevent, more refactoring
Anselm R. Garbe <arg@suckless.org>
parents:
777
diff
changeset
|
331 |
(handler[ev.type])(&ev); /* call handler */ |
2ec66bdbb8ad
removed procevent, more refactoring
Anselm R. Garbe <arg@suckless.org>
parents:
777
diff
changeset
|
332 |
} |
5 | 333 |
} |
0 | 334 |
cleanup(); |
335 |
XCloseDisplay(dpy); |
|
336 |
return 0; |
|
337 |
} |