Mercurial > dwm-meillo
annotate main.c @ 77:38c8f7f7d401
sanitized other stuff
author | Anselm R. Garbe <garbeam@wmii.de> |
---|---|
date | Sat, 15 Jul 2006 17:19:19 +0200 |
parents | 4bd49f404f10 |
children | 0d71fb80b592 |
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" |
4bd49f404f10
proceeded with cleaning up, sorting functions, etc
Anselm R. Garbe <garbeam@wmii.de>
parents:
75
diff
changeset
|
7 |
59
5d4653de9a1c
implemented dwm reading status text from stdin
Anselm R. Garbe <garbeam@wmii.de>
parents:
58
diff
changeset
|
8 #include <errno.h> |
0 | 9 #include <stdio.h> |
10 #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
|
11 #include <string.h> |
59
5d4653de9a1c
implemented dwm reading status text from stdin
Anselm R. Garbe <garbeam@wmii.de>
parents:
58
diff
changeset
|
12 #include <unistd.h> |
0 | 13 #include <X11/cursorfont.h> |
14 #include <X11/Xatom.h> | |
15 #include <X11/Xproto.h> | |
16 | |
17 Display *dpy; | |
5 | 18 Window root, barwin; |
77 | 19 Atom wmatom[WMLast], netatom[NetLast]; |
0 | 20 Cursor cursor[CurLast]; |
5 | 21 Bool running = True; |
77 | 22 Bool issel = True; |
3
e969f3575b7a
several new changes, made gridmenu working
Anselm R. Garbe <garbeam@wmii.de>
parents:
2
diff
changeset
|
23 |
31 | 24 int tsel = Tdev; /* default tag */ |
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
|
25 int screen, sx, sy, sw, sh, bx, by, bw, bh, mw; |
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
|
26 char stext[1024]; |
3
e969f3575b7a
several new changes, made gridmenu working
Anselm R. Garbe <garbeam@wmii.de>
parents:
2
diff
changeset
|
27 |
34 | 28 DC dc = {0}; |
50
148f25ed0ad7
several other additions/fixes, dwm is quite usable already
Anselm R. Garbe <garbeam@wmii.de>
parents:
49
diff
changeset
|
29 Client *clients = NULL; |
148f25ed0ad7
several other additions/fixes, dwm is quite usable already
Anselm R. Garbe <garbeam@wmii.de>
parents:
49
diff
changeset
|
30 Client *sel = NULL; |
0 | 31 |
75 | 32 static Bool otherwm; |
33 static int (*xerrorxlib)(Display *, XErrorEvent *); | |
0 | 34 |
76
4bd49f404f10
proceeded with cleaning up, sorting functions, etc
Anselm R. Garbe <garbeam@wmii.de>
parents:
75
diff
changeset
|
35 /* static functions */ |
4bd49f404f10
proceeded with cleaning up, sorting functions, etc
Anselm R. Garbe <garbeam@wmii.de>
parents:
75
diff
changeset
|
36 |
0 | 37 static void |
76
4bd49f404f10
proceeded with cleaning up, sorting functions, etc
Anselm R. Garbe <garbeam@wmii.de>
parents:
75
diff
changeset
|
38 cleanup() |
4bd49f404f10
proceeded with cleaning up, sorting functions, etc
Anselm R. Garbe <garbeam@wmii.de>
parents:
75
diff
changeset
|
39 { |
4bd49f404f10
proceeded with cleaning up, sorting functions, etc
Anselm R. Garbe <garbeam@wmii.de>
parents:
75
diff
changeset
|
40 while(sel) { |
4bd49f404f10
proceeded with cleaning up, sorting functions, etc
Anselm R. Garbe <garbeam@wmii.de>
parents:
75
diff
changeset
|
41 resize(sel, True); |
4bd49f404f10
proceeded with cleaning up, sorting functions, etc
Anselm R. Garbe <garbeam@wmii.de>
parents:
75
diff
changeset
|
42 unmanage(sel); |
4bd49f404f10
proceeded with cleaning up, sorting functions, etc
Anselm R. Garbe <garbeam@wmii.de>
parents:
75
diff
changeset
|
43 } |
4bd49f404f10
proceeded with cleaning up, sorting functions, etc
Anselm R. Garbe <garbeam@wmii.de>
parents:
75
diff
changeset
|
44 XSetInputFocus(dpy, PointerRoot, RevertToPointerRoot, CurrentTime); |
4bd49f404f10
proceeded with cleaning up, sorting functions, etc
Anselm R. Garbe <garbeam@wmii.de>
parents:
75
diff
changeset
|
45 } |
0 | 46 |
47 static void | |
75 | 48 scan() |
0 | 49 { |
50 unsigned int i, num; | |
51 Window *wins; | |
52 XWindowAttributes wa; | |
53 Window d1, d2; | |
54 | |
55 if(XQueryTree(dpy, root, &d1, &d2, &wins, &num)) { | |
56 for(i = 0; i < num; i++) { | |
57 if(!XGetWindowAttributes(dpy, wins[i], &wa)) | |
58 continue; | |
59 if(wa.override_redirect || XGetTransientForHint(dpy, wins[i], &d1)) | |
60 continue; | |
61 if(wa.map_state == IsViewable) | |
10
703255003abb
changed how manage client works
Anselm R. Garbe <garbeam@wmii.de>
parents:
9
diff
changeset
|
62 manage(wins[i], &wa); |
0 | 63 } |
64 } | |
65 if(wins) | |
66 XFree(wins); | |
67 } | |
68 | |
13
5cc5e55a132d
added protocol killing stuff
Anselm R. Garbe <garbeam@wmii.de>
parents:
10
diff
changeset
|
69 static int |
5cc5e55a132d
added protocol killing stuff
Anselm R. Garbe <garbeam@wmii.de>
parents:
10
diff
changeset
|
70 win_property(Window w, Atom a, Atom t, long l, unsigned char **prop) |
5cc5e55a132d
added protocol killing stuff
Anselm R. Garbe <garbeam@wmii.de>
parents:
10
diff
changeset
|
71 { |
5cc5e55a132d
added protocol killing stuff
Anselm R. Garbe <garbeam@wmii.de>
parents:
10
diff
changeset
|
72 Atom real; |
5cc5e55a132d
added protocol killing stuff
Anselm R. Garbe <garbeam@wmii.de>
parents:
10
diff
changeset
|
73 int format; |
5cc5e55a132d
added protocol killing stuff
Anselm R. Garbe <garbeam@wmii.de>
parents:
10
diff
changeset
|
74 unsigned long res, extra; |
5cc5e55a132d
added protocol killing stuff
Anselm R. Garbe <garbeam@wmii.de>
parents:
10
diff
changeset
|
75 int status; |
5cc5e55a132d
added protocol killing stuff
Anselm R. Garbe <garbeam@wmii.de>
parents:
10
diff
changeset
|
76 |
5cc5e55a132d
added protocol killing stuff
Anselm R. Garbe <garbeam@wmii.de>
parents:
10
diff
changeset
|
77 status = XGetWindowProperty(dpy, w, a, 0L, l, False, t, &real, &format, |
5cc5e55a132d
added protocol killing stuff
Anselm R. Garbe <garbeam@wmii.de>
parents:
10
diff
changeset
|
78 &res, &extra, prop); |
5cc5e55a132d
added protocol killing stuff
Anselm R. Garbe <garbeam@wmii.de>
parents:
10
diff
changeset
|
79 |
5cc5e55a132d
added protocol killing stuff
Anselm R. Garbe <garbeam@wmii.de>
parents:
10
diff
changeset
|
80 if(status != Success || *prop == 0) { |
5cc5e55a132d
added protocol killing stuff
Anselm R. Garbe <garbeam@wmii.de>
parents:
10
diff
changeset
|
81 return 0; |
5cc5e55a132d
added protocol killing stuff
Anselm R. Garbe <garbeam@wmii.de>
parents:
10
diff
changeset
|
82 } |
5cc5e55a132d
added protocol killing stuff
Anselm R. Garbe <garbeam@wmii.de>
parents:
10
diff
changeset
|
83 if(res == 0) { |
5cc5e55a132d
added protocol killing stuff
Anselm R. Garbe <garbeam@wmii.de>
parents:
10
diff
changeset
|
84 free((void *) *prop); |
5cc5e55a132d
added protocol killing stuff
Anselm R. Garbe <garbeam@wmii.de>
parents:
10
diff
changeset
|
85 } |
5cc5e55a132d
added protocol killing stuff
Anselm R. Garbe <garbeam@wmii.de>
parents:
10
diff
changeset
|
86 return res; |
5cc5e55a132d
added protocol killing stuff
Anselm R. Garbe <garbeam@wmii.de>
parents:
10
diff
changeset
|
87 } |
5cc5e55a132d
added protocol killing stuff
Anselm R. Garbe <garbeam@wmii.de>
parents:
10
diff
changeset
|
88 |
76
4bd49f404f10
proceeded with cleaning up, sorting functions, etc
Anselm R. Garbe <garbeam@wmii.de>
parents:
75
diff
changeset
|
89 /* |
4bd49f404f10
proceeded with cleaning up, sorting functions, etc
Anselm R. Garbe <garbeam@wmii.de>
parents:
75
diff
changeset
|
90 * 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
|
91 * is already running. |
4bd49f404f10
proceeded with cleaning up, sorting functions, etc
Anselm R. Garbe <garbeam@wmii.de>
parents:
75
diff
changeset
|
92 */ |
4bd49f404f10
proceeded with cleaning up, sorting functions, etc
Anselm R. Garbe <garbeam@wmii.de>
parents:
75
diff
changeset
|
93 static int |
4bd49f404f10
proceeded with cleaning up, sorting functions, etc
Anselm R. Garbe <garbeam@wmii.de>
parents:
75
diff
changeset
|
94 xerrorstart(Display *dsply, XErrorEvent *ee) |
4bd49f404f10
proceeded with cleaning up, sorting functions, etc
Anselm R. Garbe <garbeam@wmii.de>
parents:
75
diff
changeset
|
95 { |
4bd49f404f10
proceeded with cleaning up, sorting functions, etc
Anselm R. Garbe <garbeam@wmii.de>
parents:
75
diff
changeset
|
96 otherwm = True; |
4bd49f404f10
proceeded with cleaning up, sorting functions, etc
Anselm R. Garbe <garbeam@wmii.de>
parents:
75
diff
changeset
|
97 return -1; |
4bd49f404f10
proceeded with cleaning up, sorting functions, etc
Anselm R. Garbe <garbeam@wmii.de>
parents:
75
diff
changeset
|
98 } |
4bd49f404f10
proceeded with cleaning up, sorting functions, etc
Anselm R. Garbe <garbeam@wmii.de>
parents:
75
diff
changeset
|
99 |
4bd49f404f10
proceeded with cleaning up, sorting functions, etc
Anselm R. Garbe <garbeam@wmii.de>
parents:
75
diff
changeset
|
100 /* extern functions */ |
4bd49f404f10
proceeded with cleaning up, sorting functions, etc
Anselm R. Garbe <garbeam@wmii.de>
parents:
75
diff
changeset
|
101 |
13
5cc5e55a132d
added protocol killing stuff
Anselm R. Garbe <garbeam@wmii.de>
parents:
10
diff
changeset
|
102 int |
75 | 103 getproto(Window w) |
13
5cc5e55a132d
added protocol killing stuff
Anselm R. Garbe <garbeam@wmii.de>
parents:
10
diff
changeset
|
104 { |
30
2e0fb4130bfb
new stuff, fixed several issues
Anselm R. Garbe <garbeam@wmii.de>
parents:
27
diff
changeset
|
105 unsigned char *protocols; |
13
5cc5e55a132d
added protocol killing stuff
Anselm R. Garbe <garbeam@wmii.de>
parents:
10
diff
changeset
|
106 long res; |
5cc5e55a132d
added protocol killing stuff
Anselm R. Garbe <garbeam@wmii.de>
parents:
10
diff
changeset
|
107 int protos = 0; |
5cc5e55a132d
added protocol killing stuff
Anselm R. Garbe <garbeam@wmii.de>
parents:
10
diff
changeset
|
108 int i; |
5cc5e55a132d
added protocol killing stuff
Anselm R. Garbe <garbeam@wmii.de>
parents:
10
diff
changeset
|
109 |
77 | 110 res = win_property(w, wmatom[WMProtocols], XA_ATOM, 20L, &protocols); |
13
5cc5e55a132d
added protocol killing stuff
Anselm R. Garbe <garbeam@wmii.de>
parents:
10
diff
changeset
|
111 if(res <= 0) { |
5cc5e55a132d
added protocol killing stuff
Anselm R. Garbe <garbeam@wmii.de>
parents:
10
diff
changeset
|
112 return protos; |
5cc5e55a132d
added protocol killing stuff
Anselm R. Garbe <garbeam@wmii.de>
parents:
10
diff
changeset
|
113 } |
5cc5e55a132d
added protocol killing stuff
Anselm R. Garbe <garbeam@wmii.de>
parents:
10
diff
changeset
|
114 for(i = 0; i < res; i++) { |
77 | 115 if(protocols[i] == wmatom[WMDelete]) |
13
5cc5e55a132d
added protocol killing stuff
Anselm R. Garbe <garbeam@wmii.de>
parents:
10
diff
changeset
|
116 protos |= WM_PROTOCOL_DELWIN; |
5cc5e55a132d
added protocol killing stuff
Anselm R. Garbe <garbeam@wmii.de>
parents:
10
diff
changeset
|
117 } |
5cc5e55a132d
added protocol killing stuff
Anselm R. Garbe <garbeam@wmii.de>
parents:
10
diff
changeset
|
118 free((char *) protocols); |
5cc5e55a132d
added protocol killing stuff
Anselm R. Garbe <garbeam@wmii.de>
parents:
10
diff
changeset
|
119 return protos; |
5cc5e55a132d
added protocol killing stuff
Anselm R. Garbe <garbeam@wmii.de>
parents:
10
diff
changeset
|
120 } |
5cc5e55a132d
added protocol killing stuff
Anselm R. Garbe <garbeam@wmii.de>
parents:
10
diff
changeset
|
121 |
5cc5e55a132d
added protocol killing stuff
Anselm R. Garbe <garbeam@wmii.de>
parents:
10
diff
changeset
|
122 void |
74 | 123 sendevent(Window w, Atom a, long value) |
13
5cc5e55a132d
added protocol killing stuff
Anselm R. Garbe <garbeam@wmii.de>
parents:
10
diff
changeset
|
124 { |
5cc5e55a132d
added protocol killing stuff
Anselm R. Garbe <garbeam@wmii.de>
parents:
10
diff
changeset
|
125 XEvent e; |
5cc5e55a132d
added protocol killing stuff
Anselm R. Garbe <garbeam@wmii.de>
parents:
10
diff
changeset
|
126 |
5cc5e55a132d
added protocol killing stuff
Anselm R. Garbe <garbeam@wmii.de>
parents:
10
diff
changeset
|
127 e.type = ClientMessage; |
5cc5e55a132d
added protocol killing stuff
Anselm R. Garbe <garbeam@wmii.de>
parents:
10
diff
changeset
|
128 e.xclient.window = w; |
5cc5e55a132d
added protocol killing stuff
Anselm R. Garbe <garbeam@wmii.de>
parents:
10
diff
changeset
|
129 e.xclient.message_type = a; |
5cc5e55a132d
added protocol killing stuff
Anselm R. Garbe <garbeam@wmii.de>
parents:
10
diff
changeset
|
130 e.xclient.format = 32; |
5cc5e55a132d
added protocol killing stuff
Anselm R. Garbe <garbeam@wmii.de>
parents:
10
diff
changeset
|
131 e.xclient.data.l[0] = value; |
5cc5e55a132d
added protocol killing stuff
Anselm R. Garbe <garbeam@wmii.de>
parents:
10
diff
changeset
|
132 e.xclient.data.l[1] = CurrentTime; |
5cc5e55a132d
added protocol killing stuff
Anselm R. Garbe <garbeam@wmii.de>
parents:
10
diff
changeset
|
133 XSendEvent(dpy, w, False, NoEventMask, &e); |
5cc5e55a132d
added protocol killing stuff
Anselm R. Garbe <garbeam@wmii.de>
parents:
10
diff
changeset
|
134 XFlush(dpy); |
5cc5e55a132d
added protocol killing stuff
Anselm R. Garbe <garbeam@wmii.de>
parents:
10
diff
changeset
|
135 } |
5cc5e55a132d
added protocol killing stuff
Anselm R. Garbe <garbeam@wmii.de>
parents:
10
diff
changeset
|
136 |
76
4bd49f404f10
proceeded with cleaning up, sorting functions, etc
Anselm R. Garbe <garbeam@wmii.de>
parents:
75
diff
changeset
|
137 void |
4bd49f404f10
proceeded with cleaning up, sorting functions, etc
Anselm R. Garbe <garbeam@wmii.de>
parents:
75
diff
changeset
|
138 quit(Arg *arg) |
75 | 139 { |
76
4bd49f404f10
proceeded with cleaning up, sorting functions, etc
Anselm R. Garbe <garbeam@wmii.de>
parents:
75
diff
changeset
|
140 running = False; |
75 | 141 } |
142 | |
143 /* | |
0 | 144 * There's no way to check accesses to destroyed windows, thus |
145 * those cases are ignored (especially on UnmapNotify's). | |
146 * Other types of errors call Xlib's default error handler, which | |
147 * calls exit(). | |
148 */ | |
10
703255003abb
changed how manage client works
Anselm R. Garbe <garbeam@wmii.de>
parents:
9
diff
changeset
|
149 int |
75 | 150 xerror(Display *dpy, XErrorEvent *ee) |
0 | 151 { |
75 | 152 if(ee->error_code == BadWindow |
153 || (ee->request_code == X_SetInputFocus | |
154 && ee->error_code == BadMatch) | |
155 || (ee->request_code == X_PolyText8 | |
156 && ee->error_code == BadDrawable) | |
157 || (ee->request_code == X_PolyFillRectangle | |
158 && ee->error_code == BadDrawable) | |
159 || (ee->request_code == X_PolySegment | |
160 && ee->error_code == BadDrawable) | |
161 || (ee->request_code == X_ConfigureWindow | |
162 && ee->error_code == BadMatch) | |
163 || (ee->request_code == X_GrabKey | |
164 && ee->error_code == BadAccess)) | |
0 | 165 return 0; |
34 | 166 fprintf(stderr, "dwm: fatal error: request code=%d, error code=%d\n", |
75 | 167 ee->request_code, ee->error_code); |
168 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
|
169 } |
f96fb3fd8203
added grid mode on Mod1Mask g
Anselm R. Garbe <garbeam@wmii.de>
parents:
26
diff
changeset
|
170 |
0 | 171 int |
172 main(int argc, char *argv[]) | |
173 { | |
59
5d4653de9a1c
implemented dwm reading status text from stdin
Anselm R. Garbe <garbeam@wmii.de>
parents:
58
diff
changeset
|
174 int i, n; |
5d4653de9a1c
implemented dwm reading status text from stdin
Anselm R. Garbe <garbeam@wmii.de>
parents:
58
diff
changeset
|
175 fd_set rd; |
0 | 176 XSetWindowAttributes wa; |
177 unsigned int mask; | |
65
4f7b232bd72d
if stdin writer stops working, dwm consumed much IO load because it still tried to select on this fd, fixed
Anselm R. Garbe <garbeam@wmii.de>
parents:
64
diff
changeset
|
178 Bool readstdin = True; |
0 | 179 Window w; |
5 | 180 XEvent ev; |
0 | 181 |
182 for(i = 1; (i < argc) && (argv[i][0] == '-'); i++) { | |
183 switch (argv[i][1]) { | |
184 case 'v': | |
77 | 185 fprintf(stdout, "%s", |
186 "dwm-"VERSION", (C)opyright MMVI Anselm R. Garbe\n"); | |
0 | 187 exit(0); |
188 break; | |
189 default: | |
76
4bd49f404f10
proceeded with cleaning up, sorting functions, etc
Anselm R. Garbe <garbeam@wmii.de>
parents:
75
diff
changeset
|
190 eprint("usage: dwm [-v]\n"); |
0 | 191 break; |
192 } | |
193 } | |
194 | |
195 dpy = XOpenDisplay(0); | |
196 if(!dpy) | |
75 | 197 eprint("dwm: cannot connect X server\n"); |
0 | 198 |
199 screen = DefaultScreen(dpy); | |
200 root = RootWindow(dpy, screen); | |
201 | |
202 /* check if another WM is already running */ | |
75 | 203 otherwm = False; |
204 XSetErrorHandler(xerrorstart); | |
0 | 205 /* this causes an error if some other WM is running */ |
206 XSelectInput(dpy, root, SubstructureRedirectMask); | |
3
e969f3575b7a
several new changes, made gridmenu working
Anselm R. Garbe <garbeam@wmii.de>
parents:
2
diff
changeset
|
207 XFlush(dpy); |
0 | 208 |
75 | 209 if(otherwm) |
210 eprint("dwm: another window manager is already running\n"); | |
0 | 211 |
212 XSetErrorHandler(0); | |
75 | 213 xerrorxlib = XSetErrorHandler(xerror); |
0 | 214 |
215 /* init atoms */ | |
77 | 216 wmatom[WMProtocols] = XInternAtom(dpy, "WM_PROTOCOLS", False); |
217 wmatom[WMDelete] = XInternAtom(dpy, "WM_DELETE_WINDOW", False); | |
218 netatom[NetSupported] = XInternAtom(dpy, "_NET_SUPPORTED", False); | |
219 netatom[NetWMName] = XInternAtom(dpy, "_NET_WM_NAME", False); | |
220 XChangeProperty(dpy, root, netatom[NetSupported], XA_ATOM, 32, | |
221 PropModeReplace, (unsigned char *) netatom, NetLast); | |
0 | 222 |
223 /* init cursors */ | |
224 cursor[CurNormal] = XCreateFontCursor(dpy, XC_left_ptr); | |
225 cursor[CurResize] = XCreateFontCursor(dpy, XC_sizing); | |
226 cursor[CurMove] = XCreateFontCursor(dpy, XC_fleur); | |
227 | |
73 | 228 grabkeys(); |
0 | 229 |
5 | 230 /* style */ |
74 | 231 dc.bg = getcolor(BGCOLOR); |
232 dc.fg = getcolor(FGCOLOR); | |
233 dc.border = getcolor(BORDERCOLOR); | |
234 setfont(FONT); | |
5 | 235 |
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
|
236 sx = sy = 0; |
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
|
237 sw = DisplayWidth(dpy, screen); |
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
|
238 sh = DisplayHeight(dpy, screen); |
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
|
239 mw = (sw * MASTERW) / 100; |
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
|
240 |
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
|
241 wa.override_redirect = 1; |
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
|
242 wa.background_pixmap = ParentRelative; |
58
1269bd127551
made barclick to select the specific tag
Anselm R. Garbe <garbeam@wmii.de>
parents:
57
diff
changeset
|
243 wa.event_mask = ButtonPressMask | ExposureMask; |
5 | 244 |
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
|
245 bx = by = 0; |
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
|
246 bw = sw; |
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
|
247 dc.h = bh = dc.font.height + 4; |
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
|
248 barwin = XCreateWindow(dpy, root, bx, by, bw, bh, 0, DefaultDepth(dpy, screen), |
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
|
249 CopyFromParent, DefaultVisual(dpy, screen), |
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
|
250 CWOverrideRedirect | CWBackPixmap | CWEventMask, &wa); |
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
|
251 XDefineCursor(dpy, barwin, cursor[CurNormal]); |
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
|
252 XMapRaised(dpy, barwin); |
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
|
253 |
60
24f9c674d03f
made stdin reader more robust
Anselm R. Garbe <garbeam@wmii.de>
parents:
59
diff
changeset
|
254 dc.drawable = XCreatePixmap(dpy, root, sw, bh, DefaultDepth(dpy, screen)); |
24f9c674d03f
made stdin reader more robust
Anselm R. Garbe <garbeam@wmii.de>
parents:
59
diff
changeset
|
255 dc.gc = XCreateGC(dpy, root, 0, 0); |
74 | 256 drawstatus(); |
60
24f9c674d03f
made stdin reader more robust
Anselm R. Garbe <garbeam@wmii.de>
parents:
59
diff
changeset
|
257 |
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
|
258 issel = XQueryPointer(dpy, root, &w, &w, &i, &i, &i, &i, &mask); |
21
3ef108a5ca0a
implemented draw_client stuff
Anselm R. Garbe <garbeam@wmii.de>
parents:
16
diff
changeset
|
259 |
9
d567f430a81d
fixed several stuff (gridwm gets better and better)
Anselm R. Garbe <garbeam@wmii.de>
parents:
8
diff
changeset
|
260 wa.event_mask = SubstructureRedirectMask | EnterWindowMask \ |
d567f430a81d
fixed several stuff (gridwm gets better and better)
Anselm R. Garbe <garbeam@wmii.de>
parents:
8
diff
changeset
|
261 | LeaveWindowMask; |
0 | 262 wa.cursor = cursor[CurNormal]; |
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
|
263 |
0 | 264 XChangeWindowAttributes(dpy, root, CWEventMask | CWCursor, &wa); |
265 | |
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
|
266 strcpy(stext, "dwm-"VERSION); |
75 | 267 scan(); |
3
e969f3575b7a
several new changes, made gridmenu working
Anselm R. Garbe <garbeam@wmii.de>
parents:
2
diff
changeset
|
268 |
59
5d4653de9a1c
implemented dwm reading status text from stdin
Anselm R. Garbe <garbeam@wmii.de>
parents:
58
diff
changeset
|
269 /* main event loop, reads status text from stdin as well */ |
61 | 270 Mainloop: |
5 | 271 while(running) { |
59
5d4653de9a1c
implemented dwm reading status text from stdin
Anselm R. Garbe <garbeam@wmii.de>
parents:
58
diff
changeset
|
272 FD_ZERO(&rd); |
65
4f7b232bd72d
if stdin writer stops working, dwm consumed much IO load because it still tried to select on this fd, fixed
Anselm R. Garbe <garbeam@wmii.de>
parents:
64
diff
changeset
|
273 if(readstdin) |
4f7b232bd72d
if stdin writer stops working, dwm consumed much IO load because it still tried to select on this fd, fixed
Anselm R. Garbe <garbeam@wmii.de>
parents:
64
diff
changeset
|
274 FD_SET(STDIN_FILENO, &rd); |
59
5d4653de9a1c
implemented dwm reading status text from stdin
Anselm R. Garbe <garbeam@wmii.de>
parents:
58
diff
changeset
|
275 FD_SET(ConnectionNumber(dpy), &rd); |
5d4653de9a1c
implemented dwm reading status text from stdin
Anselm R. Garbe <garbeam@wmii.de>
parents:
58
diff
changeset
|
276 |
5d4653de9a1c
implemented dwm reading status text from stdin
Anselm R. Garbe <garbeam@wmii.de>
parents:
58
diff
changeset
|
277 i = select(ConnectionNumber(dpy) + 1, &rd, 0, 0, 0); |
5d4653de9a1c
implemented dwm reading status text from stdin
Anselm R. Garbe <garbeam@wmii.de>
parents:
58
diff
changeset
|
278 if(i == -1 && errno == EINTR) |
5d4653de9a1c
implemented dwm reading status text from stdin
Anselm R. Garbe <garbeam@wmii.de>
parents:
58
diff
changeset
|
279 continue; |
5d4653de9a1c
implemented dwm reading status text from stdin
Anselm R. Garbe <garbeam@wmii.de>
parents:
58
diff
changeset
|
280 if(i < 0) |
75 | 281 eprint("select failed\n"); |
59
5d4653de9a1c
implemented dwm reading status text from stdin
Anselm R. Garbe <garbeam@wmii.de>
parents:
58
diff
changeset
|
282 else if(i > 0) { |
64 | 283 if(FD_ISSET(ConnectionNumber(dpy), &rd)) { |
284 while(XPending(dpy)) { | |
285 XNextEvent(dpy, &ev); | |
286 if(handler[ev.type]) | |
287 (handler[ev.type])(&ev); /* call handler */ | |
288 } | |
59
5d4653de9a1c
implemented dwm reading status text from stdin
Anselm R. Garbe <garbeam@wmii.de>
parents:
58
diff
changeset
|
289 } |
65
4f7b232bd72d
if stdin writer stops working, dwm consumed much IO load because it still tried to select on this fd, fixed
Anselm R. Garbe <garbeam@wmii.de>
parents:
64
diff
changeset
|
290 if(readstdin && FD_ISSET(STDIN_FILENO, &rd)) { |
59
5d4653de9a1c
implemented dwm reading status text from stdin
Anselm R. Garbe <garbeam@wmii.de>
parents:
58
diff
changeset
|
291 i = n = 0; |
60
24f9c674d03f
made stdin reader more robust
Anselm R. Garbe <garbeam@wmii.de>
parents:
59
diff
changeset
|
292 for(;;) { |
24f9c674d03f
made stdin reader more robust
Anselm R. Garbe <garbeam@wmii.de>
parents:
59
diff
changeset
|
293 if((i = getchar()) == EOF) { |
65
4f7b232bd72d
if stdin writer stops working, dwm consumed much IO load because it still tried to select on this fd, fixed
Anselm R. Garbe <garbeam@wmii.de>
parents:
64
diff
changeset
|
294 /* broken pipe/end of producer */ |
4f7b232bd72d
if stdin writer stops working, dwm consumed much IO load because it still tried to select on this fd, fixed
Anselm R. Garbe <garbeam@wmii.de>
parents:
64
diff
changeset
|
295 readstdin = False; |
4f7b232bd72d
if stdin writer stops working, dwm consumed much IO load because it still tried to select on this fd, fixed
Anselm R. Garbe <garbeam@wmii.de>
parents:
64
diff
changeset
|
296 strcpy(stext, "broken pipe"); |
60
24f9c674d03f
made stdin reader more robust
Anselm R. Garbe <garbeam@wmii.de>
parents:
59
diff
changeset
|
297 goto Mainloop; |
24f9c674d03f
made stdin reader more robust
Anselm R. Garbe <garbeam@wmii.de>
parents:
59
diff
changeset
|
298 } |
24f9c674d03f
made stdin reader more robust
Anselm R. Garbe <garbeam@wmii.de>
parents:
59
diff
changeset
|
299 if(i == '\n' || n >= sizeof(stext) - 1) |
24f9c674d03f
made stdin reader more robust
Anselm R. Garbe <garbeam@wmii.de>
parents:
59
diff
changeset
|
300 break; |
59
5d4653de9a1c
implemented dwm reading status text from stdin
Anselm R. Garbe <garbeam@wmii.de>
parents:
58
diff
changeset
|
301 stext[n++] = i; |
60
24f9c674d03f
made stdin reader more robust
Anselm R. Garbe <garbeam@wmii.de>
parents:
59
diff
changeset
|
302 } |
59
5d4653de9a1c
implemented dwm reading status text from stdin
Anselm R. Garbe <garbeam@wmii.de>
parents:
58
diff
changeset
|
303 stext[n] = 0; |
74 | 304 drawstatus(); |
59
5d4653de9a1c
implemented dwm reading status text from stdin
Anselm R. Garbe <garbeam@wmii.de>
parents:
58
diff
changeset
|
305 } |
5d4653de9a1c
implemented dwm reading status text from stdin
Anselm R. Garbe <garbeam@wmii.de>
parents:
58
diff
changeset
|
306 } |
5 | 307 } |
0 | 308 |
309 cleanup(); | |
310 XCloseDisplay(dpy); | |
311 | |
312 return 0; | |
313 } |