Mercurial > dwm-meillo
annotate main.c @ 376:201acf925788
changed config.arg.h - I really need the 4th tag
author | Anselm R. Garbe <arg@10kloc.org> |
---|---|
date | Mon, 28 Aug 2006 12:27:00 +0200 |
parents | ba6c55e1b9b2 |
children | 052657ff2e7b |
rev | line source |
---|---|
0 | 1 /* |
2 * (C)opyright MMVI Anselm R. Garbe <garbeam at gmail dot com> | |
3 * See LICENSE file for license details. | |
4 */ | |
5 | |
76
4bd49f404f10
proceeded with cleaning up, sorting functions, etc
Anselm R. Garbe <garbeam@wmii.de>
parents:
75
diff
changeset
|
6 #include "dwm.h" |
59
5d4653de9a1c
implemented dwm reading status text from stdin
Anselm R. Garbe <garbeam@wmii.de>
parents:
58
diff
changeset
|
7 #include <errno.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 |
827f8f6c9e97
separated setup stuff into main.c:setup() - this makes main() more readable
Anselm R. Garbe <arg@10kloc.org>
parents:
329
diff
changeset
|
20 char stext[1024]; |
827f8f6c9e97
separated setup stuff into main.c:setup() - this makes main() more readable
Anselm R. Garbe <arg@10kloc.org>
parents:
329
diff
changeset
|
21 Bool *seltag; |
362
ba6c55e1b9b2
trying a different configuration
Anselm R. Garbe <arg@10kloc.org>
parents:
359
diff
changeset
|
22 int bx, by, bw, bh, bmw, mw, screen, sx, sy, sw, sh; |
ba6c55e1b9b2
trying a different configuration
Anselm R. Garbe <arg@10kloc.org>
parents:
359
diff
changeset
|
23 unsigned int 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
|
24 Atom wmatom[WMLast], 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
|
25 Bool running = True; |
827f8f6c9e97
separated setup stuff into main.c:setup() - this makes main() more readable
Anselm R. Garbe <arg@10kloc.org>
parents:
329
diff
changeset
|
26 Bool issel = True; |
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 *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
|
28 Client *sel = NULL; |
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; |
0 | 38 |
39 static void | |
76
4bd49f404f10
proceeded with cleaning up, sorting functions, etc
Anselm R. Garbe <garbeam@wmii.de>
parents:
75
diff
changeset
|
40 cleanup() |
4bd49f404f10
proceeded with cleaning up, sorting functions, etc
Anselm R. Garbe <garbeam@wmii.de>
parents:
75
diff
changeset
|
41 { |
302 | 42 close(STDIN_FILENO); |
76
4bd49f404f10
proceeded with cleaning up, sorting functions, etc
Anselm R. Garbe <garbeam@wmii.de>
parents:
75
diff
changeset
|
43 while(sel) { |
99
a19556fe83b5
applied Sanders resize patch, fixed lower bug
arg@10ksloc.org
parents:
95
diff
changeset
|
44 resize(sel, True, TopLeft); |
76
4bd49f404f10
proceeded with cleaning up, sorting functions, etc
Anselm R. Garbe <garbeam@wmii.de>
parents:
75
diff
changeset
|
45 unmanage(sel); |
4bd49f404f10
proceeded with cleaning up, sorting functions, etc
Anselm R. Garbe <garbeam@wmii.de>
parents:
75
diff
changeset
|
46 } |
295 | 47 if(dc.font.set) |
48 XFreeFontSet(dpy, dc.font.set); | |
49 else | |
50 XFreeFont(dpy, dc.font.xfont); | |
292 | 51 XUngrabKey(dpy, AnyKey, AnyModifier, root); |
295 | 52 XFreePixmap(dpy, dc.drawable); |
53 XFreeGC(dpy, dc.gc); | |
309
204427dcc087
corrected order of cleanup code
Anselm R.Garbe <arg@10ksloc.org>
parents:
302
diff
changeset
|
54 XDestroyWindow(dpy, barwin); |
76
4bd49f404f10
proceeded with cleaning up, sorting functions, etc
Anselm R. Garbe <garbeam@wmii.de>
parents:
75
diff
changeset
|
55 XSetInputFocus(dpy, PointerRoot, RevertToPointerRoot, CurrentTime); |
292 | 56 XSync(dpy, False); |
76
4bd49f404f10
proceeded with cleaning up, sorting functions, etc
Anselm R. Garbe <garbeam@wmii.de>
parents:
75
diff
changeset
|
57 } |
0 | 58 |
59 static void | |
75 | 60 scan() |
0 | 61 { |
62 unsigned int i, num; | |
123 | 63 Window *wins, d1, d2; |
0 | 64 XWindowAttributes wa; |
65 | |
292 | 66 wins = NULL; |
0 | 67 if(XQueryTree(dpy, root, &d1, &d2, &wins, &num)) { |
68 for(i = 0; i < num; i++) { | |
69 if(!XGetWindowAttributes(dpy, wins[i], &wa)) | |
70 continue; | |
71 if(wa.override_redirect || XGetTransientForHint(dpy, wins[i], &d1)) | |
72 continue; | |
73 if(wa.map_state == IsViewable) | |
10
703255003abb
changed how manage client works
Anselm R. Garbe <garbeam@wmii.de>
parents:
9
diff
changeset
|
74 manage(wins[i], &wa); |
0 | 75 } |
76 } | |
77 if(wins) | |
78 XFree(wins); | |
79 } | |
80 | |
333
827f8f6c9e97
separated setup stuff into main.c:setup() - this makes main() more readable
Anselm R. Garbe <arg@10kloc.org>
parents:
329
diff
changeset
|
81 static void |
827f8f6c9e97
separated setup stuff into main.c:setup() - this makes main() more readable
Anselm R. Garbe <arg@10kloc.org>
parents:
329
diff
changeset
|
82 setup() |
827f8f6c9e97
separated setup stuff into main.c:setup() - this makes main() more readable
Anselm R. Garbe <arg@10kloc.org>
parents:
329
diff
changeset
|
83 { |
827f8f6c9e97
separated setup stuff into main.c:setup() - this makes main() more readable
Anselm R. Garbe <arg@10kloc.org>
parents:
329
diff
changeset
|
84 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
|
85 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
|
86 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
|
87 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
|
88 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
|
89 |
827f8f6c9e97
separated setup stuff into main.c:setup() - this makes main() more readable
Anselm R. Garbe <arg@10kloc.org>
parents:
329
diff
changeset
|
90 /* 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
|
91 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
|
92 wmatom[WMDelete] = XInternAtom(dpy, "WM_DELETE_WINDOW", False); |
827f8f6c9e97
separated setup stuff into main.c:setup() - this makes main() more readable
Anselm R. Garbe <arg@10kloc.org>
parents:
329
diff
changeset
|
93 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
|
94 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
|
95 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
|
96 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
|
97 |
827f8f6c9e97
separated setup stuff into main.c:setup() - this makes main() more readable
Anselm R. Garbe <arg@10kloc.org>
parents:
329
diff
changeset
|
98 /* 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
|
99 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
|
100 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
|
101 cursor[CurMove] = XCreateFontCursor(dpy, XC_fleur); |
827f8f6c9e97
separated setup stuff into main.c:setup() - this makes main() more readable
Anselm R. Garbe <arg@10kloc.org>
parents:
329
diff
changeset
|
102 |
827f8f6c9e97
separated setup stuff into main.c:setup() - this makes main() more readable
Anselm R. Garbe <arg@10kloc.org>
parents:
329
diff
changeset
|
103 modmap = XGetModifierMapping(dpy); |
827f8f6c9e97
separated setup stuff into main.c:setup() - this makes main() more readable
Anselm R. Garbe <arg@10kloc.org>
parents:
329
diff
changeset
|
104 for (i = 0; i < 8; i++) { |
827f8f6c9e97
separated setup stuff into main.c:setup() - this makes main() more readable
Anselm R. Garbe <arg@10kloc.org>
parents:
329
diff
changeset
|
105 for (j = 0; j < modmap->max_keypermod; j++) { |
827f8f6c9e97
separated setup stuff into main.c:setup() - this makes main() more readable
Anselm R. Garbe <arg@10kloc.org>
parents:
329
diff
changeset
|
106 if(modmap->modifiermap[i * modmap->max_keypermod + j] == XKeysymToKeycode(dpy, XK_Num_Lock)) |
827f8f6c9e97
separated setup stuff into main.c:setup() - this makes main() more readable
Anselm R. Garbe <arg@10kloc.org>
parents:
329
diff
changeset
|
107 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
|
108 } |
827f8f6c9e97
separated setup stuff into main.c:setup() - this makes main() more readable
Anselm R. Garbe <arg@10kloc.org>
parents:
329
diff
changeset
|
109 } |
827f8f6c9e97
separated setup stuff into main.c:setup() - this makes main() more readable
Anselm R. Garbe <arg@10kloc.org>
parents:
329
diff
changeset
|
110 XFree(modmap); |
827f8f6c9e97
separated setup stuff into main.c:setup() - this makes main() more readable
Anselm R. Garbe <arg@10kloc.org>
parents:
329
diff
changeset
|
111 |
827f8f6c9e97
separated setup stuff into main.c:setup() - this makes main() more readable
Anselm R. Garbe <arg@10kloc.org>
parents:
329
diff
changeset
|
112 wa.event_mask = SubstructureRedirectMask | SubstructureNotifyMask | EnterWindowMask | LeaveWindowMask; |
827f8f6c9e97
separated setup stuff into main.c:setup() - this makes main() more readable
Anselm R. Garbe <arg@10kloc.org>
parents:
329
diff
changeset
|
113 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
|
114 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
|
115 |
827f8f6c9e97
separated setup stuff into main.c:setup() - this makes main() more readable
Anselm R. Garbe <arg@10kloc.org>
parents:
329
diff
changeset
|
116 grabkeys(); |
827f8f6c9e97
separated setup stuff into main.c:setup() - this makes main() more readable
Anselm R. Garbe <arg@10kloc.org>
parents:
329
diff
changeset
|
117 initrregs(); |
827f8f6c9e97
separated setup stuff into main.c:setup() - this makes main() more readable
Anselm R. Garbe <arg@10kloc.org>
parents:
329
diff
changeset
|
118 |
827f8f6c9e97
separated setup stuff into main.c:setup() - this makes main() more readable
Anselm R. Garbe <arg@10kloc.org>
parents:
329
diff
changeset
|
119 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
|
120 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
|
121 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
|
122 |
827f8f6c9e97
separated setup stuff into main.c:setup() - this makes main() more readable
Anselm R. Garbe <arg@10kloc.org>
parents:
329
diff
changeset
|
123 /* style */ |
353
8a06efe5b563
new color stuff/new rendering stuff
Anselm R. Garbe <arg@10kloc.org>
parents:
352
diff
changeset
|
124 dc.norm[ColBG] = getcolor(NORMBGCOLOR); |
8a06efe5b563
new color stuff/new rendering stuff
Anselm R. Garbe <arg@10kloc.org>
parents:
352
diff
changeset
|
125 dc.norm[ColFG] = getcolor(NORMFGCOLOR); |
8a06efe5b563
new color stuff/new rendering stuff
Anselm R. Garbe <arg@10kloc.org>
parents:
352
diff
changeset
|
126 dc.sel[ColBG] = getcolor(SELBGCOLOR); |
8a06efe5b563
new color stuff/new rendering stuff
Anselm R. Garbe <arg@10kloc.org>
parents:
352
diff
changeset
|
127 dc.sel[ColFG] = getcolor(SELFGCOLOR); |
8a06efe5b563
new color stuff/new rendering stuff
Anselm R. Garbe <arg@10kloc.org>
parents:
352
diff
changeset
|
128 dc.status[ColBG] = getcolor(STATUSBGCOLOR); |
8a06efe5b563
new color stuff/new rendering stuff
Anselm R. Garbe <arg@10kloc.org>
parents:
352
diff
changeset
|
129 dc.status[ColFG] = getcolor(STATUSFGCOLOR); |
333
827f8f6c9e97
separated setup stuff into main.c:setup() - this makes main() more readable
Anselm R. Garbe <arg@10kloc.org>
parents:
329
diff
changeset
|
130 setfont(FONT); |
827f8f6c9e97
separated setup stuff into main.c:setup() - this makes main() more readable
Anselm R. Garbe <arg@10kloc.org>
parents:
329
diff
changeset
|
131 |
362
ba6c55e1b9b2
trying a different configuration
Anselm R. Garbe <arg@10kloc.org>
parents:
359
diff
changeset
|
132 bmw = textw(FLOATSYMBOL) > textw(TILESYMBOL) ? textw(FLOATSYMBOL) : textw(TILESYMBOL); |
333
827f8f6c9e97
separated setup stuff into main.c:setup() - this makes main() more readable
Anselm R. Garbe <arg@10kloc.org>
parents:
329
diff
changeset
|
133 sx = sy = 0; |
827f8f6c9e97
separated setup stuff into main.c:setup() - this makes main() more readable
Anselm R. Garbe <arg@10kloc.org>
parents:
329
diff
changeset
|
134 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
|
135 sh = DisplayHeight(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
|
136 mw = (sw * MASTERW) / 100; |
827f8f6c9e97
separated setup stuff into main.c:setup() - this makes main() more readable
Anselm R. Garbe <arg@10kloc.org>
parents:
329
diff
changeset
|
137 |
827f8f6c9e97
separated setup stuff into main.c:setup() - this makes main() more readable
Anselm R. Garbe <arg@10kloc.org>
parents:
329
diff
changeset
|
138 bx = by = 0; |
827f8f6c9e97
separated setup stuff into main.c:setup() - this makes main() more readable
Anselm R. Garbe <arg@10kloc.org>
parents:
329
diff
changeset
|
139 bw = sw; |
353
8a06efe5b563
new color stuff/new rendering stuff
Anselm R. Garbe <arg@10kloc.org>
parents:
352
diff
changeset
|
140 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
|
141 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
|
142 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
|
143 wa.event_mask = ButtonPressMask | ExposureMask; |
827f8f6c9e97
separated setup stuff into main.c:setup() - this makes main() more readable
Anselm R. Garbe <arg@10kloc.org>
parents:
329
diff
changeset
|
144 barwin = XCreateWindow(dpy, root, bx, by, bw, bh, 0, 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
|
145 CopyFromParent, DefaultVisual(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
|
146 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
|
147 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
|
148 XMapRaised(dpy, barwin); |
827f8f6c9e97
separated setup stuff into main.c:setup() - this makes main() more readable
Anselm R. Garbe <arg@10kloc.org>
parents:
329
diff
changeset
|
149 |
827f8f6c9e97
separated setup stuff into main.c:setup() - this makes main() more readable
Anselm R. Garbe <arg@10kloc.org>
parents:
329
diff
changeset
|
150 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
|
151 dc.gc = XCreateGC(dpy, root, 0, 0); |
344
93192711a36a
changing tag indicator through underline
Anselm R. Garbe <arg@10kloc.org>
parents:
339
diff
changeset
|
152 XSetLineAttributes(dpy, dc.gc, 1, LineSolid, CapButt, JoinMiter); |
333
827f8f6c9e97
separated setup stuff into main.c:setup() - this makes main() more readable
Anselm R. Garbe <arg@10kloc.org>
parents:
329
diff
changeset
|
153 |
827f8f6c9e97
separated setup stuff into main.c:setup() - this makes main() more readable
Anselm R. Garbe <arg@10kloc.org>
parents:
329
diff
changeset
|
154 issel = XQueryPointer(dpy, root, &w, &w, &i, &i, &i, &i, &mask); |
827f8f6c9e97
separated setup stuff into main.c:setup() - this makes main() more readable
Anselm R. Garbe <arg@10kloc.org>
parents:
329
diff
changeset
|
155 strcpy(stext, "dwm-"VERSION); |
827f8f6c9e97
separated setup stuff into main.c:setup() - this makes main() more readable
Anselm R. Garbe <arg@10kloc.org>
parents:
329
diff
changeset
|
156 } |
827f8f6c9e97
separated setup stuff into main.c:setup() - this makes main() more readable
Anselm R. Garbe <arg@10kloc.org>
parents:
329
diff
changeset
|
157 |
76
4bd49f404f10
proceeded with cleaning up, sorting functions, etc
Anselm R. Garbe <garbeam@wmii.de>
parents:
75
diff
changeset
|
158 /* |
4bd49f404f10
proceeded with cleaning up, sorting functions, etc
Anselm R. Garbe <garbeam@wmii.de>
parents:
75
diff
changeset
|
159 * 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
|
160 * is already running. |
4bd49f404f10
proceeded with cleaning up, sorting functions, etc
Anselm R. Garbe <garbeam@wmii.de>
parents:
75
diff
changeset
|
161 */ |
4bd49f404f10
proceeded with cleaning up, sorting functions, etc
Anselm R. Garbe <garbeam@wmii.de>
parents:
75
diff
changeset
|
162 static int |
4bd49f404f10
proceeded with cleaning up, sorting functions, etc
Anselm R. Garbe <garbeam@wmii.de>
parents:
75
diff
changeset
|
163 xerrorstart(Display *dsply, XErrorEvent *ee) |
4bd49f404f10
proceeded with cleaning up, sorting functions, etc
Anselm R. Garbe <garbeam@wmii.de>
parents:
75
diff
changeset
|
164 { |
4bd49f404f10
proceeded with cleaning up, sorting functions, etc
Anselm R. Garbe <garbeam@wmii.de>
parents:
75
diff
changeset
|
165 otherwm = True; |
4bd49f404f10
proceeded with cleaning up, sorting functions, etc
Anselm R. Garbe <garbeam@wmii.de>
parents:
75
diff
changeset
|
166 return -1; |
4bd49f404f10
proceeded with cleaning up, sorting functions, etc
Anselm R. Garbe <garbeam@wmii.de>
parents:
75
diff
changeset
|
167 } |
4bd49f404f10
proceeded with cleaning up, sorting functions, etc
Anselm R. Garbe <garbeam@wmii.de>
parents:
75
diff
changeset
|
168 |
84
052fe7498930
ordered variables in structs and source files alphabetically
Anselm R. Garbe <garbeam@wmii.de>
parents:
79
diff
changeset
|
169 /* extern */ |
052fe7498930
ordered variables in structs and source files alphabetically
Anselm R. Garbe <garbeam@wmii.de>
parents:
79
diff
changeset
|
170 |
13
5cc5e55a132d
added protocol killing stuff
Anselm R. Garbe <garbeam@wmii.de>
parents:
10
diff
changeset
|
171 int |
75 | 172 getproto(Window w) |
13
5cc5e55a132d
added protocol killing stuff
Anselm R. Garbe <garbeam@wmii.de>
parents:
10
diff
changeset
|
173 { |
329 | 174 int i, format, protos, status; |
328
083f1f3e1e93
removed winprop (merged into getproto)
Anselm R. Garbe <arg@10kloc.org>
parents:
326
diff
changeset
|
175 unsigned long extra, res; |
083f1f3e1e93
removed winprop (merged into getproto)
Anselm R. Garbe <arg@10kloc.org>
parents:
326
diff
changeset
|
176 Atom *protocols, real; |
13
5cc5e55a132d
added protocol killing stuff
Anselm R. Garbe <garbeam@wmii.de>
parents:
10
diff
changeset
|
177 |
329 | 178 protos = 0; |
179 status = XGetWindowProperty(dpy, w, wmatom[WMProtocols], 0L, 20L, False, | |
180 XA_ATOM, &real, &format, &res, &extra, (unsigned char **)&protocols); | |
328
083f1f3e1e93
removed winprop (merged into getproto)
Anselm R. Garbe <arg@10kloc.org>
parents:
326
diff
changeset
|
181 if(status != Success || protocols == 0) |
13
5cc5e55a132d
added protocol killing stuff
Anselm R. Garbe <garbeam@wmii.de>
parents:
10
diff
changeset
|
182 return protos; |
329 | 183 for(i = 0; i < res; i++) |
77 | 184 if(protocols[i] == wmatom[WMDelete]) |
157
93012e947eae
renamed WM_PROTOCOL_DELWIN into PROTODELWIN
arg@10ksloc.org
parents:
146
diff
changeset
|
185 protos |= PROTODELWIN; |
328
083f1f3e1e93
removed winprop (merged into getproto)
Anselm R. Garbe <arg@10kloc.org>
parents:
326
diff
changeset
|
186 free(protocols); |
13
5cc5e55a132d
added protocol killing stuff
Anselm R. Garbe <garbeam@wmii.de>
parents:
10
diff
changeset
|
187 return protos; |
5cc5e55a132d
added protocol killing stuff
Anselm R. Garbe <garbeam@wmii.de>
parents:
10
diff
changeset
|
188 } |
5cc5e55a132d
added protocol killing stuff
Anselm R. Garbe <garbeam@wmii.de>
parents:
10
diff
changeset
|
189 |
5cc5e55a132d
added protocol killing stuff
Anselm R. Garbe <garbeam@wmii.de>
parents:
10
diff
changeset
|
190 void |
74 | 191 sendevent(Window w, Atom a, long value) |
13
5cc5e55a132d
added protocol killing stuff
Anselm R. Garbe <garbeam@wmii.de>
parents:
10
diff
changeset
|
192 { |
5cc5e55a132d
added protocol killing stuff
Anselm R. Garbe <garbeam@wmii.de>
parents:
10
diff
changeset
|
193 XEvent e; |
5cc5e55a132d
added protocol killing stuff
Anselm R. Garbe <garbeam@wmii.de>
parents:
10
diff
changeset
|
194 |
5cc5e55a132d
added protocol killing stuff
Anselm R. Garbe <garbeam@wmii.de>
parents:
10
diff
changeset
|
195 e.type = ClientMessage; |
5cc5e55a132d
added protocol killing stuff
Anselm R. Garbe <garbeam@wmii.de>
parents:
10
diff
changeset
|
196 e.xclient.window = w; |
5cc5e55a132d
added protocol killing stuff
Anselm R. Garbe <garbeam@wmii.de>
parents:
10
diff
changeset
|
197 e.xclient.message_type = a; |
5cc5e55a132d
added protocol killing stuff
Anselm R. Garbe <garbeam@wmii.de>
parents:
10
diff
changeset
|
198 e.xclient.format = 32; |
5cc5e55a132d
added protocol killing stuff
Anselm R. Garbe <garbeam@wmii.de>
parents:
10
diff
changeset
|
199 e.xclient.data.l[0] = value; |
5cc5e55a132d
added protocol killing stuff
Anselm R. Garbe <garbeam@wmii.de>
parents:
10
diff
changeset
|
200 e.xclient.data.l[1] = CurrentTime; |
5cc5e55a132d
added protocol killing stuff
Anselm R. Garbe <garbeam@wmii.de>
parents:
10
diff
changeset
|
201 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
|
202 XSync(dpy, False); |
13
5cc5e55a132d
added protocol killing stuff
Anselm R. Garbe <garbeam@wmii.de>
parents:
10
diff
changeset
|
203 } |
5cc5e55a132d
added protocol killing stuff
Anselm R. Garbe <garbeam@wmii.de>
parents:
10
diff
changeset
|
204 |
76
4bd49f404f10
proceeded with cleaning up, sorting functions, etc
Anselm R. Garbe <garbeam@wmii.de>
parents:
75
diff
changeset
|
205 void |
4bd49f404f10
proceeded with cleaning up, sorting functions, etc
Anselm R. Garbe <garbeam@wmii.de>
parents:
75
diff
changeset
|
206 quit(Arg *arg) |
75 | 207 { |
302 | 208 readin = running = False; |
75 | 209 } |
210 | |
211 /* | |
84
052fe7498930
ordered variables in structs and source files alphabetically
Anselm R. Garbe <garbeam@wmii.de>
parents:
79
diff
changeset
|
212 * There's no way to check accesses to destroyed windows, thus those cases are |
052fe7498930
ordered variables in structs and source files alphabetically
Anselm R. Garbe <garbeam@wmii.de>
parents:
79
diff
changeset
|
213 * ignored (especially on UnmapNotify's). Other types of errors call Xlibs |
052fe7498930
ordered variables in structs and source files alphabetically
Anselm R. Garbe <garbeam@wmii.de>
parents:
79
diff
changeset
|
214 * default error handler, which calls exit(). |
0 | 215 */ |
10
703255003abb
changed how manage client works
Anselm R. Garbe <garbeam@wmii.de>
parents:
9
diff
changeset
|
216 int |
75 | 217 xerror(Display *dpy, XErrorEvent *ee) |
0 | 218 { |
75 | 219 if(ee->error_code == BadWindow |
123 | 220 || (ee->request_code == X_SetInputFocus && ee->error_code == BadMatch) |
221 || (ee->request_code == X_PolyText8 && ee->error_code == BadDrawable) | |
222 || (ee->request_code == X_PolyFillRectangle && ee->error_code == BadDrawable) | |
223 || (ee->request_code == X_PolySegment && ee->error_code == BadDrawable) | |
224 || (ee->request_code == X_ConfigureWindow && ee->error_code == BadMatch) | |
225 || (ee->request_code == X_GrabKey && ee->error_code == BadAccess)) | |
0 | 226 return 0; |
34 | 227 fprintf(stderr, "dwm: fatal error: request code=%d, error code=%d\n", |
123 | 228 ee->request_code, ee->error_code); |
75 | 229 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
|
230 } |
f96fb3fd8203
added grid mode on Mod1Mask g
Anselm R. Garbe <garbeam@wmii.de>
parents:
26
diff
changeset
|
231 |
0 | 232 int |
233 main(int argc, char *argv[]) | |
234 { | |
333
827f8f6c9e97
separated setup stuff into main.c:setup() - this makes main() more readable
Anselm R. Garbe <arg@10kloc.org>
parents:
329
diff
changeset
|
235 int r, xfd; |
59
5d4653de9a1c
implemented dwm reading status text from stdin
Anselm R. Garbe <garbeam@wmii.de>
parents:
58
diff
changeset
|
236 fd_set rd; |
0 | 237 |
137
77922a389fa8
simplified main.c, switching back to single urxvt usage
arg@10ksloc.org
parents:
126
diff
changeset
|
238 if(argc == 2 && !strncmp("-v", argv[1], 3)) { |
77922a389fa8
simplified main.c, switching back to single urxvt usage
arg@10ksloc.org
parents:
126
diff
changeset
|
239 fputs("dwm-"VERSION", (C)opyright MMVI Anselm R. Garbe\n", stdout); |
77922a389fa8
simplified main.c, switching back to single urxvt usage
arg@10ksloc.org
parents:
126
diff
changeset
|
240 exit(EXIT_SUCCESS); |
0 | 241 } |
137
77922a389fa8
simplified main.c, switching back to single urxvt usage
arg@10ksloc.org
parents:
126
diff
changeset
|
242 else if(argc != 1) |
77922a389fa8
simplified main.c, switching back to single urxvt usage
arg@10ksloc.org
parents:
126
diff
changeset
|
243 eprint("usage: dwm [-v]\n"); |
0 | 244 |
245 dpy = XOpenDisplay(0); | |
246 if(!dpy) | |
197 | 247 eprint("dwm: cannot open display\n"); |
0 | 248 |
265
573b1c4a71a4
reducing ConnectionNumber calls to a bare minimum
Anselm R.Garbe <arg@10ksloc.org>
parents:
262
diff
changeset
|
249 xfd = ConnectionNumber(dpy); |
0 | 250 screen = DefaultScreen(dpy); |
251 root = RootWindow(dpy, screen); | |
252 | |
75 | 253 otherwm = False; |
254 XSetErrorHandler(xerrorstart); | |
197 | 255 /* this causes an error if some other window manager is running */ |
0 | 256 XSelectInput(dpy, root, SubstructureRedirectMask); |
78
0d71fb80b592
changing XFlush into XSync
Anselm R. Garbe <garbeam@wmii.de>
parents:
77
diff
changeset
|
257 XSync(dpy, False); |
0 | 258 |
75 | 259 if(otherwm) |
260 eprint("dwm: another window manager is already running\n"); | |
0 | 261 |
292 | 262 XSync(dpy, False); |
78
0d71fb80b592
changing XFlush into XSync
Anselm R. Garbe <garbeam@wmii.de>
parents:
77
diff
changeset
|
263 XSetErrorHandler(NULL); |
75 | 264 xerrorxlib = XSetErrorHandler(xerror); |
275 | 265 XSync(dpy, False); |
0 | 266 |
333
827f8f6c9e97
separated setup stuff into main.c:setup() - this makes main() more readable
Anselm R. Garbe <arg@10kloc.org>
parents:
329
diff
changeset
|
267 setup(); |
74 | 268 drawstatus(); |
75 | 269 scan(); |
3
e969f3575b7a
several new changes, made gridmenu working
Anselm R. Garbe <garbeam@wmii.de>
parents:
2
diff
changeset
|
270 |
214 | 271 /* main event loop, also reads status text from stdin */ |
242 | 272 XSync(dpy, False); |
292 | 273 procevent(); |
302 | 274 readin = True; |
5 | 275 while(running) { |
59
5d4653de9a1c
implemented dwm reading status text from stdin
Anselm R. Garbe <garbeam@wmii.de>
parents:
58
diff
changeset
|
276 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
|
277 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
|
278 FD_SET(STDIN_FILENO, &rd); |
265
573b1c4a71a4
reducing ConnectionNumber calls to a bare minimum
Anselm R.Garbe <arg@10ksloc.org>
parents:
262
diff
changeset
|
279 FD_SET(xfd, &rd); |
333
827f8f6c9e97
separated setup stuff into main.c:setup() - this makes main() more readable
Anselm R. Garbe <arg@10kloc.org>
parents:
329
diff
changeset
|
280 r = select(xfd + 1, &rd, NULL, NULL, NULL); |
827f8f6c9e97
separated setup stuff into main.c:setup() - this makes main() more readable
Anselm R. Garbe <arg@10kloc.org>
parents:
329
diff
changeset
|
281 if((r == -1) && (errno == EINTR)) |
59
5d4653de9a1c
implemented dwm reading status text from stdin
Anselm R. Garbe <garbeam@wmii.de>
parents:
58
diff
changeset
|
282 continue; |
333
827f8f6c9e97
separated setup stuff into main.c:setup() - this makes main() more readable
Anselm R. Garbe <arg@10kloc.org>
parents:
329
diff
changeset
|
283 if(r > 0) { |
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
|
284 if(readin && FD_ISSET(STDIN_FILENO, &rd)) { |
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
|
285 readin = NULL != fgets(stext, sizeof(stext), stdin); |
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
|
286 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
|
287 stext[strlen(stext) - 1] = 0; |
162
a6a31e485fbd
dwm is now exit, if stdin is closed due broken pipe
arg@10ksloc.org
parents:
157
diff
changeset
|
288 else |
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
|
289 strcpy(stext, "broken pipe"); |
74 | 290 drawstatus(); |
59
5d4653de9a1c
implemented dwm reading status text from stdin
Anselm R. Garbe <garbeam@wmii.de>
parents:
58
diff
changeset
|
291 } |
5d4653de9a1c
implemented dwm reading status text from stdin
Anselm R. Garbe <garbeam@wmii.de>
parents:
58
diff
changeset
|
292 } |
333
827f8f6c9e97
separated setup stuff into main.c:setup() - this makes main() more readable
Anselm R. Garbe <arg@10kloc.org>
parents:
329
diff
changeset
|
293 else if(r < 0) |
316
d69cdb180a3e
small changes to dwm.1, rearranged order within main event loop
Anselm R.Garbe <arg@10ksloc.org>
parents:
309
diff
changeset
|
294 eprint("select failed\n"); |
293 | 295 procevent(); |
5 | 296 } |
0 | 297 cleanup(); |
298 XCloseDisplay(dpy); | |
299 | |
300 return 0; | |
301 } |