comparison main.c @ 123:61490330e90a

cleaned up code
author arg@10ksloc.org
date Thu, 20 Jul 2006 12:18:06 +0200
parents a19556fe83b5
children 1489f6b97714
comparison
equal deleted inserted replaced
122:f20cea484900 123:61490330e90a
15 #include <X11/Xproto.h> 15 #include <X11/Xproto.h>
16 16
17 17
18 /* static */ 18 /* static */
19 19
20 static int (*xerrorxlib)(Display *, XErrorEvent *);
20 static Bool otherwm; 21 static Bool otherwm;
21 static int (*xerrorxlib)(Display *, XErrorEvent *);
22 22
23 static void 23 static void
24 cleanup() 24 cleanup()
25 { 25 {
26 while(sel) { 26 while(sel) {
32 32
33 static void 33 static void
34 scan() 34 scan()
35 { 35 {
36 unsigned int i, num; 36 unsigned int i, num;
37 Window *wins; 37 Window *wins, d1, d2;
38 XWindowAttributes wa; 38 XWindowAttributes wa;
39 Window d1, d2;
40 39
41 if(XQueryTree(dpy, root, &d1, &d2, &wins, &num)) { 40 if(XQueryTree(dpy, root, &d1, &d2, &wins, &num)) {
42 for(i = 0; i < num; i++) { 41 for(i = 0; i < num; i++) {
43 if(!XGetWindowAttributes(dpy, wins[i], &wa)) 42 if(!XGetWindowAttributes(dpy, wins[i], &wa))
44 continue; 43 continue;
53 } 52 }
54 53
55 static int 54 static int
56 win_property(Window w, Atom a, Atom t, long l, unsigned char **prop) 55 win_property(Window w, Atom a, Atom t, long l, unsigned char **prop)
57 { 56 {
57 int status, format;
58 unsigned long res, extra;
58 Atom real; 59 Atom real;
59 int format;
60 unsigned long res, extra;
61 int status;
62 60
63 status = XGetWindowProperty(dpy, w, a, 0L, l, False, t, &real, &format, 61 status = XGetWindowProperty(dpy, w, a, 0L, l, False, t, &real, &format,
64 &res, &extra, prop); 62 &res, &extra, prop);
65 63
66 if(status != Success || *prop == 0) { 64 if(status != Success || *prop == 0) {
99 Window root, barwin; 97 Window root, barwin;
100 98
101 int 99 int
102 getproto(Window w) 100 getproto(Window w)
103 { 101 {
104 unsigned char *protocols;
105 long res;
106 int protos = 0; 102 int protos = 0;
107 int i; 103 int i;
104 long res;
105 unsigned char *protocols;
108 106
109 res = win_property(w, wmatom[WMProtocols], XA_ATOM, 20L, &protocols); 107 res = win_property(w, wmatom[WMProtocols], XA_ATOM, 20L, &protocols);
110 if(res <= 0) { 108 if(res <= 0) {
111 return protos; 109 return protos;
112 } 110 }
146 */ 144 */
147 int 145 int
148 xerror(Display *dpy, XErrorEvent *ee) 146 xerror(Display *dpy, XErrorEvent *ee)
149 { 147 {
150 if(ee->error_code == BadWindow 148 if(ee->error_code == BadWindow
151 || (ee->request_code == X_SetInputFocus 149 || (ee->request_code == X_SetInputFocus && ee->error_code == BadMatch)
152 && ee->error_code == BadMatch) 150 || (ee->request_code == X_PolyText8 && ee->error_code == BadDrawable)
153 || (ee->request_code == X_PolyText8 151 || (ee->request_code == X_PolyFillRectangle && ee->error_code == BadDrawable)
154 && ee->error_code == BadDrawable) 152 || (ee->request_code == X_PolySegment && ee->error_code == BadDrawable)
155 || (ee->request_code == X_PolyFillRectangle 153 || (ee->request_code == X_ConfigureWindow && ee->error_code == BadMatch)
156 && ee->error_code == BadDrawable) 154 || (ee->request_code == X_GrabKey && ee->error_code == BadAccess))
157 || (ee->request_code == X_PolySegment
158 && ee->error_code == BadDrawable)
159 || (ee->request_code == X_ConfigureWindow
160 && ee->error_code == BadMatch)
161 || (ee->request_code == X_GrabKey
162 && ee->error_code == BadAccess))
163 return 0; 155 return 0;
164 fprintf(stderr, "dwm: fatal error: request code=%d, error code=%d\n", 156 fprintf(stderr, "dwm: fatal error: request code=%d, error code=%d\n",
165 ee->request_code, ee->error_code); 157 ee->request_code, ee->error_code);
166 return xerrorxlib(dpy, ee); /* may call exit() */ 158 return xerrorxlib(dpy, ee); /* may call exit() */
167 } 159 }
168 160
169 int 161 int
170 main(int argc, char *argv[]) 162 main(int argc, char *argv[])
171 { 163 {
172 int i, n; 164 int i, n;
165 unsigned int mask;
173 fd_set rd; 166 fd_set rd;
174 XSetWindowAttributes wa;
175 unsigned int mask;
176 Bool readstdin = True; 167 Bool readstdin = True;
177 Window w; 168 Window w;
178 XEvent ev; 169 XEvent ev;
170 XSetWindowAttributes wa;
179 171
180 for(i = 1; (i < argc) && (argv[i][0] == '-'); i++) { 172 for(i = 1; (i < argc) && (argv[i][0] == '-'); i++) {
181 switch (argv[i][1]) { 173 switch (argv[i][1]) {
182 default: 174 default:
183 eprint("usage: dwm [-v]\n"); 175 eprint("usage: dwm [-v]\n");
252 dc.gc = XCreateGC(dpy, root, 0, 0); 244 dc.gc = XCreateGC(dpy, root, 0, 0);
253 drawstatus(); 245 drawstatus();
254 246
255 issel = XQueryPointer(dpy, root, &w, &w, &i, &i, &i, &i, &mask); 247 issel = XQueryPointer(dpy, root, &w, &w, &i, &i, &i, &i, &mask);
256 248
257 wa.event_mask = SubstructureRedirectMask | EnterWindowMask \ 249 wa.event_mask = SubstructureRedirectMask | EnterWindowMask | LeaveWindowMask;
258 | LeaveWindowMask;
259 wa.cursor = cursor[CurNormal]; 250 wa.cursor = cursor[CurNormal];
260
261 XChangeWindowAttributes(dpy, root, CWEventMask | CWCursor, &wa); 251 XChangeWindowAttributes(dpy, root, CWEventMask | CWCursor, &wa);
262 252
263 strcpy(stext, "dwm-"VERSION); 253 strcpy(stext, "dwm-"VERSION);
264
265 scan(); 254 scan();
266 255
267 /* main event loop, reads status text from stdin as well */ 256 /* main event loop, reads status text from stdin as well */
268 Mainloop: 257 Mainloop:
269 while(running) { 258 while(running) {