Mercurial > aewl
annotate main.c @ 610:29f7d5cc996c
Added tag 2.5 for changeset dcbbfabc8ecc5f33a6cc950584de87da1a368045
author | arg@mig29 |
---|---|
date | Mon, 04 Dec 2006 15:39:43 +0100 |
parents | f4285a97e3e6 |
children | f617c75a8405 |
rev | line source |
---|---|
532
651f2c868b31
code polishing, removed unnecessary newlines
Anselm R. Garbe <arg@10kloc.org>
parents:
530
diff
changeset
|
1 /* (C)opyright MMVI 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> |
0 | 7 #include <stdio.h> |
8 #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
|
9 #include <string.h> |
59
5d4653de9a1c
implemented dwm reading status text from stdin
Anselm R. Garbe <garbeam@wmii.de>
parents:
58
diff
changeset
|
10 #include <unistd.h> |
138
c1185dc7a36e
some cleanups/fixes inspired by Jukka Salmi's feedback
arg@10ksloc.org
parents:
137
diff
changeset
|
11 #include <sys/select.h> |
0 | 12 #include <X11/cursorfont.h> |
291
8e6e0aa5e2ae
removed NUMLOCKMASK, added dynamically calculated numlockmask instead
Anselm R.Garbe <arg@10ksloc.org>
parents:
281
diff
changeset
|
13 #include <X11/keysym.h> |
0 | 14 #include <X11/Xatom.h> |
15 #include <X11/Xproto.h> | |
16 | |
333
827f8f6c9e97
separated setup stuff into main.c:setup() - this makes main() more readable
Anselm R. Garbe <arg@10kloc.org>
parents:
329
diff
changeset
|
17 /* extern */ |
827f8f6c9e97
separated setup stuff into main.c:setup() - this makes main() more readable
Anselm R. Garbe <arg@10kloc.org>
parents:
329
diff
changeset
|
18 |
827f8f6c9e97
separated setup stuff into main.c:setup() - this makes main() more readable
Anselm R. Garbe <arg@10kloc.org>
parents:
329
diff
changeset
|
19 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
|
20 Bool *seltag; |
565 | 21 int bx, by, bw, bh, bmw, masterd, screen, sx, sy, sw, sh, wax, way, waw, wah; |
524
1a9a0877650c
keep master ratio on resizecol -> arrange
Anselm R. Garbe <arg@10kloc.org>
parents:
516
diff
changeset
|
22 unsigned int master, 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]; |
827f8f6c9e97
separated setup stuff into main.c:setup() - this makes main() more readable
Anselm R. Garbe <arg@10kloc.org>
parents:
329
diff
changeset
|
24 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
|
25 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
|
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; |
0 | 38 |
39 static void | |
487 | 40 cleanup(void) { |
302 | 41 close(STDIN_FILENO); |
76
4bd49f404f10
proceeded with cleaning up, sorting functions, etc
Anselm R. Garbe <garbeam@wmii.de>
parents:
75
diff
changeset
|
42 while(sel) { |
99
a19556fe83b5
applied Sanders resize patch, fixed lower bug
arg@10ksloc.org
parents:
95
diff
changeset
|
43 resize(sel, True, TopLeft); |
76
4bd49f404f10
proceeded with cleaning up, sorting functions, etc
Anselm R. Garbe <garbeam@wmii.de>
parents:
75
diff
changeset
|
44 unmanage(sel); |
4bd49f404f10
proceeded with cleaning up, sorting functions, etc
Anselm R. Garbe <garbeam@wmii.de>
parents:
75
diff
changeset
|
45 } |
295 | 46 if(dc.font.set) |
47 XFreeFontSet(dpy, dc.font.set); | |
48 else | |
49 XFreeFont(dpy, dc.font.xfont); | |
292 | 50 XUngrabKey(dpy, AnyKey, AnyModifier, root); |
295 | 51 XFreePixmap(dpy, dc.drawable); |
52 XFreeGC(dpy, dc.gc); | |
309
204427dcc087
corrected order of cleanup code
Anselm R.Garbe <arg@10ksloc.org>
parents:
302
diff
changeset
|
53 XDestroyWindow(dpy, barwin); |
76
4bd49f404f10
proceeded with cleaning up, sorting functions, etc
Anselm R. Garbe <garbeam@wmii.de>
parents:
75
diff
changeset
|
54 XSetInputFocus(dpy, PointerRoot, RevertToPointerRoot, CurrentTime); |
292 | 55 XSync(dpy, False); |
433 | 56 free(seltag); |
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 | |
487 | 60 scan(void) { |
0 | 61 unsigned int i, num; |
123 | 62 Window *wins, d1, d2; |
0 | 63 XWindowAttributes wa; |
64 | |
292 | 65 wins = NULL; |
0 | 66 if(XQueryTree(dpy, root, &d1, &d2, &wins, &num)) { |
67 for(i = 0; i < num; i++) { | |
68 if(!XGetWindowAttributes(dpy, wins[i], &wa)) | |
69 continue; | |
70 if(wa.override_redirect || XGetTransientForHint(dpy, wins[i], &d1)) | |
71 continue; | |
72 if(wa.map_state == IsViewable) | |
10
703255003abb
changed how manage client works
Anselm R. Garbe <garbeam@wmii.de>
parents:
9
diff
changeset
|
73 manage(wins[i], &wa); |
0 | 74 } |
75 } | |
76 if(wins) | |
77 XFree(wins); | |
78 } | |
79 | |
333
827f8f6c9e97
separated setup stuff into main.c:setup() - this makes main() more readable
Anselm R. Garbe <arg@10kloc.org>
parents:
329
diff
changeset
|
80 static void |
487 | 81 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
|
82 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
|
83 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
|
84 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
|
85 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
|
86 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
|
87 |
827f8f6c9e97
separated setup stuff into main.c:setup() - this makes main() more readable
Anselm R. Garbe <arg@10kloc.org>
parents:
329
diff
changeset
|
88 /* 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
|
89 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
|
90 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
|
91 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
|
92 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
|
93 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
|
94 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
|
95 /* 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
|
96 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
|
97 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
|
98 cursor[CurMove] = XCreateFontCursor(dpy, XC_fleur); |
532
651f2c868b31
code polishing, removed unnecessary newlines
Anselm R. Garbe <arg@10kloc.org>
parents:
530
diff
changeset
|
99 /* init modifier map */ |
333
827f8f6c9e97
separated setup stuff into main.c:setup() - this makes main() more readable
Anselm R. Garbe <arg@10kloc.org>
parents:
329
diff
changeset
|
100 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
|
101 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
|
102 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
|
103 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
|
104 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
|
105 } |
827f8f6c9e97
separated setup stuff into main.c:setup() - this makes main() more readable
Anselm R. Garbe <arg@10kloc.org>
parents:
329
diff
changeset
|
106 } |
827f8f6c9e97
separated setup stuff into main.c:setup() - this makes main() more readable
Anselm R. Garbe <arg@10kloc.org>
parents:
329
diff
changeset
|
107 XFree(modmap); |
532
651f2c868b31
code polishing, removed unnecessary newlines
Anselm R. Garbe <arg@10kloc.org>
parents:
530
diff
changeset
|
108 /* 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
|
109 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
|
110 | 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
|
111 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
|
112 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
|
113 grabkeys(); |
827f8f6c9e97
separated setup stuff into main.c:setup() - this makes main() more readable
Anselm R. Garbe <arg@10kloc.org>
parents:
329
diff
changeset
|
114 initrregs(); |
827f8f6c9e97
separated setup stuff into main.c:setup() - this makes main() more readable
Anselm R. Garbe <arg@10kloc.org>
parents:
329
diff
changeset
|
115 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
|
116 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
|
117 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
|
118 /* style */ |
353
8a06efe5b563
new color stuff/new rendering stuff
Anselm R. Garbe <arg@10kloc.org>
parents:
352
diff
changeset
|
119 dc.norm[ColBG] = getcolor(NORMBGCOLOR); |
8a06efe5b563
new color stuff/new rendering stuff
Anselm R. Garbe <arg@10kloc.org>
parents:
352
diff
changeset
|
120 dc.norm[ColFG] = getcolor(NORMFGCOLOR); |
8a06efe5b563
new color stuff/new rendering stuff
Anselm R. Garbe <arg@10kloc.org>
parents:
352
diff
changeset
|
121 dc.sel[ColBG] = getcolor(SELBGCOLOR); |
8a06efe5b563
new color stuff/new rendering stuff
Anselm R. Garbe <arg@10kloc.org>
parents:
352
diff
changeset
|
122 dc.sel[ColFG] = getcolor(SELFGCOLOR); |
8a06efe5b563
new color stuff/new rendering stuff
Anselm R. Garbe <arg@10kloc.org>
parents:
352
diff
changeset
|
123 dc.status[ColBG] = getcolor(STATUSBGCOLOR); |
8a06efe5b563
new color stuff/new rendering stuff
Anselm R. Garbe <arg@10kloc.org>
parents:
352
diff
changeset
|
124 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
|
125 setfont(FONT); |
532
651f2c868b31
code polishing, removed unnecessary newlines
Anselm R. Garbe <arg@10kloc.org>
parents:
530
diff
changeset
|
126 /* geometry */ |
530
451f19d48845
removed the stack position stuff
Anselm R. Garbe <arg@10kloc.org>
parents:
524
diff
changeset
|
127 bmw = textw(TILESYMBOL) > textw(FLOATSYMBOL) ? textw(TILESYMBOL) : textw(FLOATSYMBOL); |
333
827f8f6c9e97
separated setup stuff into main.c:setup() - this makes main() more readable
Anselm R. Garbe <arg@10kloc.org>
parents:
329
diff
changeset
|
128 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
|
129 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
|
130 sh = DisplayHeight(dpy, screen); |
524
1a9a0877650c
keep master ratio on resizecol -> arrange
Anselm R. Garbe <arg@10kloc.org>
parents:
516
diff
changeset
|
131 master = MASTER; |
532
651f2c868b31
code polishing, removed unnecessary newlines
Anselm R. Garbe <arg@10kloc.org>
parents:
530
diff
changeset
|
132 /* bar */ |
570 | 133 bx = sx; |
134 by = sy; | |
333
827f8f6c9e97
separated setup stuff into main.c:setup() - this makes main() more readable
Anselm R. Garbe <arg@10kloc.org>
parents:
329
diff
changeset
|
135 bw = sw; |
353
8a06efe5b563
new color stuff/new rendering stuff
Anselm R. Garbe <arg@10kloc.org>
parents:
352
diff
changeset
|
136 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
|
137 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
|
138 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
|
139 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
|
140 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
|
141 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
|
142 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
|
143 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
|
144 XMapRaised(dpy, barwin); |
532
651f2c868b31
code polishing, removed unnecessary newlines
Anselm R. Garbe <arg@10kloc.org>
parents:
530
diff
changeset
|
145 strcpy(stext, "dwm-"VERSION); |
565 | 146 /* windowarea */ |
147 wax = sx; | |
570 | 148 way = sy + bh; |
565 | 149 wah = sh - bh; |
150 waw = sw; | |
532
651f2c868b31
code polishing, removed unnecessary newlines
Anselm R. Garbe <arg@10kloc.org>
parents:
530
diff
changeset
|
151 /* 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
|
152 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
|
153 dc.gc = XCreateGC(dpy, root, 0, 0); |
344
93192711a36a
changing tag indicator through underline
Anselm R. Garbe <arg@10kloc.org>
parents:
339
diff
changeset
|
154 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
|
155 /* multihead support */ |
333
827f8f6c9e97
separated setup stuff into main.c:setup() - this makes main() more readable
Anselm R. Garbe <arg@10kloc.org>
parents:
329
diff
changeset
|
156 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
|
157 } |
827f8f6c9e97
separated setup stuff into main.c:setup() - this makes main() more readable
Anselm R. Garbe <arg@10kloc.org>
parents:
329
diff
changeset
|
158 |
76
4bd49f404f10
proceeded with cleaning up, sorting functions, etc
Anselm R. Garbe <garbeam@wmii.de>
parents:
75
diff
changeset
|
159 /* |
4bd49f404f10
proceeded with cleaning up, sorting functions, etc
Anselm R. Garbe <garbeam@wmii.de>
parents:
75
diff
changeset
|
160 * 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
|
161 * is already running. |
4bd49f404f10
proceeded with cleaning up, sorting functions, etc
Anselm R. Garbe <garbeam@wmii.de>
parents:
75
diff
changeset
|
162 */ |
4bd49f404f10
proceeded with cleaning up, sorting functions, etc
Anselm R. Garbe <garbeam@wmii.de>
parents:
75
diff
changeset
|
163 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
|
164 xerrorstart(Display *dsply, XErrorEvent *ee) { |
76
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 |
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
|
172 getproto(Window w) { |
329 | 173 int i, format, protos, status; |
328
083f1f3e1e93
removed winprop (merged into getproto)
Anselm R. Garbe <arg@10kloc.org>
parents:
326
diff
changeset
|
174 unsigned long extra, res; |
083f1f3e1e93
removed winprop (merged into getproto)
Anselm R. Garbe <arg@10kloc.org>
parents:
326
diff
changeset
|
175 Atom *protocols, real; |
13
5cc5e55a132d
added protocol killing stuff
Anselm R. Garbe <garbeam@wmii.de>
parents:
10
diff
changeset
|
176 |
329 | 177 protos = 0; |
178 status = XGetWindowProperty(dpy, w, wmatom[WMProtocols], 0L, 20L, False, | |
179 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
|
180 if(status != Success || protocols == 0) |
13
5cc5e55a132d
added protocol killing stuff
Anselm R. Garbe <garbeam@wmii.de>
parents:
10
diff
changeset
|
181 return protos; |
329 | 182 for(i = 0; i < res; i++) |
77 | 183 if(protocols[i] == wmatom[WMDelete]) |
157
93012e947eae
renamed WM_PROTOCOL_DELWIN into PROTODELWIN
arg@10ksloc.org
parents:
146
diff
changeset
|
184 protos |= PROTODELWIN; |
328
083f1f3e1e93
removed winprop (merged into getproto)
Anselm R. Garbe <arg@10kloc.org>
parents:
326
diff
changeset
|
185 free(protocols); |
13
5cc5e55a132d
added protocol killing stuff
Anselm R. Garbe <garbeam@wmii.de>
parents:
10
diff
changeset
|
186 return protos; |
5cc5e55a132d
added protocol killing stuff
Anselm R. Garbe <garbeam@wmii.de>
parents:
10
diff
changeset
|
187 } |
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 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
|
190 sendevent(Window w, Atom a, long value) { |
13
5cc5e55a132d
added protocol killing stuff
Anselm R. Garbe <garbeam@wmii.de>
parents:
10
diff
changeset
|
191 XEvent e; |
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 e.type = ClientMessage; |
5cc5e55a132d
added protocol killing stuff
Anselm R. Garbe <garbeam@wmii.de>
parents:
10
diff
changeset
|
194 e.xclient.window = w; |
5cc5e55a132d
added protocol killing stuff
Anselm R. Garbe <garbeam@wmii.de>
parents:
10
diff
changeset
|
195 e.xclient.message_type = a; |
5cc5e55a132d
added protocol killing stuff
Anselm R. Garbe <garbeam@wmii.de>
parents:
10
diff
changeset
|
196 e.xclient.format = 32; |
5cc5e55a132d
added protocol killing stuff
Anselm R. Garbe <garbeam@wmii.de>
parents:
10
diff
changeset
|
197 e.xclient.data.l[0] = value; |
5cc5e55a132d
added protocol killing stuff
Anselm R. Garbe <garbeam@wmii.de>
parents:
10
diff
changeset
|
198 e.xclient.data.l[1] = CurrentTime; |
5cc5e55a132d
added protocol killing stuff
Anselm R. Garbe <garbeam@wmii.de>
parents:
10
diff
changeset
|
199 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
|
200 XSync(dpy, False); |
13
5cc5e55a132d
added protocol killing stuff
Anselm R. Garbe <garbeam@wmii.de>
parents:
10
diff
changeset
|
201 } |
5cc5e55a132d
added protocol killing stuff
Anselm R. Garbe <garbeam@wmii.de>
parents:
10
diff
changeset
|
202 |
76
4bd49f404f10
proceeded with cleaning up, sorting functions, etc
Anselm R. Garbe <garbeam@wmii.de>
parents:
75
diff
changeset
|
203 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
|
204 quit(Arg *arg) { |
302 | 205 readin = running = False; |
75 | 206 } |
207 | |
532
651f2c868b31
code polishing, removed unnecessary newlines
Anselm R. Garbe <arg@10kloc.org>
parents:
530
diff
changeset
|
208 /* 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
|
209 * 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
|
210 * default error handler, which may call exit. |
0 | 211 */ |
10
703255003abb
changed how manage client works
Anselm R. Garbe <garbeam@wmii.de>
parents:
9
diff
changeset
|
212 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
|
213 xerror(Display *dpy, XErrorEvent *ee) { |
75 | 214 if(ee->error_code == BadWindow |
123 | 215 || (ee->request_code == X_SetInputFocus && ee->error_code == BadMatch) |
216 || (ee->request_code == X_PolyText8 && ee->error_code == BadDrawable) | |
217 || (ee->request_code == X_PolyFillRectangle && ee->error_code == BadDrawable) | |
218 || (ee->request_code == X_PolySegment && ee->error_code == BadDrawable) | |
219 || (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
|
220 || (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
|
221 || (ee->request_code == X_CopyArea && ee->error_code == BadDrawable)) |
0 | 222 return 0; |
34 | 223 fprintf(stderr, "dwm: fatal error: request code=%d, error code=%d\n", |
123 | 224 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
|
225 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
|
226 } |
f96fb3fd8203
added grid mode on Mod1Mask g
Anselm R. Garbe <garbeam@wmii.de>
parents:
26
diff
changeset
|
227 |
0 | 228 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
|
229 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
|
230 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
|
231 int r, xfd; |
59
5d4653de9a1c
implemented dwm reading status text from stdin
Anselm R. Garbe <garbeam@wmii.de>
parents:
58
diff
changeset
|
232 fd_set rd; |
0 | 233 |
137
77922a389fa8
simplified main.c, switching back to single urxvt usage
arg@10ksloc.org
parents:
126
diff
changeset
|
234 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
|
235 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
|
236 exit(EXIT_SUCCESS); |
0 | 237 } |
137
77922a389fa8
simplified main.c, switching back to single urxvt usage
arg@10ksloc.org
parents:
126
diff
changeset
|
238 else if(argc != 1) |
77922a389fa8
simplified main.c, switching back to single urxvt usage
arg@10ksloc.org
parents:
126
diff
changeset
|
239 eprint("usage: dwm [-v]\n"); |
0 | 240 dpy = XOpenDisplay(0); |
241 if(!dpy) | |
197 | 242 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
|
243 xfd = ConnectionNumber(dpy); |
0 | 244 screen = DefaultScreen(dpy); |
245 root = RootWindow(dpy, screen); | |
75 | 246 otherwm = False; |
247 XSetErrorHandler(xerrorstart); | |
197 | 248 /* this causes an error if some other window manager is running */ |
0 | 249 XSelectInput(dpy, root, SubstructureRedirectMask); |
78
0d71fb80b592
changing XFlush into XSync
Anselm R. Garbe <garbeam@wmii.de>
parents:
77
diff
changeset
|
250 XSync(dpy, False); |
75 | 251 if(otherwm) |
252 eprint("dwm: another window manager is already running\n"); | |
0 | 253 |
292 | 254 XSync(dpy, False); |
78
0d71fb80b592
changing XFlush into XSync
Anselm R. Garbe <garbeam@wmii.de>
parents:
77
diff
changeset
|
255 XSetErrorHandler(NULL); |
75 | 256 xerrorxlib = XSetErrorHandler(xerror); |
275 | 257 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
|
258 setup(); |
74 | 259 drawstatus(); |
75 | 260 scan(); |
3
e969f3575b7a
several new changes, made gridmenu working
Anselm R. Garbe <garbeam@wmii.de>
parents:
2
diff
changeset
|
261 |
214 | 262 /* main event loop, also reads status text from stdin */ |
242 | 263 XSync(dpy, False); |
292 | 264 procevent(); |
302 | 265 readin = True; |
5 | 266 while(running) { |
59
5d4653de9a1c
implemented dwm reading status text from stdin
Anselm R. Garbe <garbeam@wmii.de>
parents:
58
diff
changeset
|
267 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
|
268 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
|
269 FD_SET(STDIN_FILENO, &rd); |
265
573b1c4a71a4
reducing ConnectionNumber calls to a bare minimum
Anselm R.Garbe <arg@10ksloc.org>
parents:
262
diff
changeset
|
270 FD_SET(xfd, &rd); |
578 | 271 if(select(xfd + 1, &rd, NULL, NULL, NULL) == -1) { |
272 if(errno == EINTR) | |
273 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
|
274 eprint("select failed\n"); |
578 | 275 } |
276 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
|
277 switch(r = read(STDIN_FILENO, stext, sizeof stext - 1)) { |
578 | 278 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
|
279 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
|
280 stext[sizeof stext - 1] = '\0'; |
578 | 281 readin = False; |
282 break; | |
283 case 0: | |
583
f4285a97e3e6
applied Jukka's patch preventing some cornercases and making the EOF error message correct
arg@mig29
parents:
582
diff
changeset
|
284 strncpy(stext, "EOF", 4); |
578 | 285 readin = False; |
286 break; | |
287 default: | |
582 | 288 for(stext[r] = '\0', p = stext + strlen(stext) - 1; p >= stext && *p == '\n'; *p-- = '\0'); |
289 for(p = stext + strlen(stext) - 1; 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
|
290 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
|
291 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
|
292 } |
578 | 293 drawstatus(); |
59
5d4653de9a1c
implemented dwm reading status text from stdin
Anselm R. Garbe <garbeam@wmii.de>
parents:
58
diff
changeset
|
294 } |
578 | 295 if(FD_ISSET(xfd, &rd)) |
296 procevent(); | |
5 | 297 } |
0 | 298 cleanup(); |
299 XCloseDisplay(dpy); | |
300 return 0; | |
301 } |