15 #include <X11/cursorfont.h> |
15 #include <X11/cursorfont.h> |
16 #include <X11/Xatom.h> |
16 #include <X11/Xatom.h> |
17 #include <X11/Xproto.h> |
17 #include <X11/Xproto.h> |
18 |
18 |
19 #include "wm.h" |
19 #include "wm.h" |
|
20 |
|
21 /********** CUSTOMIZE **********/ |
|
22 |
|
23 char *tags[TLast] = { |
|
24 [Tscratch] = "scratch", |
|
25 [Tdev] = "dev", |
|
26 [Tirc] = "irc", |
|
27 [Twww] = "www", |
|
28 [Twork] = "work", |
|
29 }; |
|
30 |
|
31 /* commands */ |
|
32 static char *cmdwallpaper[] = { |
|
33 "feh", "--bg-scale", "/home/garbeam/wallpaper/bg.jpg", NULL |
|
34 }; |
|
35 |
|
36 static char *cmdstatus[] = { |
|
37 "sh", "-c", "echo -n `date '+%Y-%m-%d %H:%M'`" |
|
38 " `uptime | sed 's/.*://; s/,//g'`" |
|
39 " `acpi | awk '{print $4}' | sed 's/,//'`", NULL |
|
40 }; |
|
41 |
|
42 /********** CUSTOMIZE **********/ |
20 |
43 |
21 /* X structs */ |
44 /* X structs */ |
22 Display *dpy; |
45 Display *dpy; |
23 Window root, barwin; |
46 Window root, barwin; |
24 Atom wm_atom[WMLast], net_atom[NetLast]; |
47 Atom wm_atom[WMLast], net_atom[NetLast]; |
25 Cursor cursor[CurLast]; |
48 Cursor cursor[CurLast]; |
26 Bool running = True; |
49 Bool running = True; |
27 Bool sel_screen; |
50 Bool issel; |
28 |
51 |
29 char statustext[1024], tag[256]; |
52 char stext[1024]; |
|
53 int tsel = Tdev; /* default tag */ |
30 int screen, sx, sy, sw, sh, bx, by, bw, bh; |
54 int screen, sx, sy, sw, sh, bx, by, bw, bh; |
31 |
55 |
32 Brush brush = {0}; |
56 Brush brush = {0}; |
33 Client *clients = NULL; |
57 Client *clients = NULL; |
34 Client *stack = NULL; |
58 Client *stack = NULL; |
35 |
59 |
36 static Bool other_wm_running; |
60 static Bool other_wm_running; |
37 static const char version[] = "gridwm - " VERSION ", (C)opyright MMVI Anselm R. Garbe\n"; |
61 static const char version[] = |
|
62 "gridwm - " VERSION ", (C)opyright MMVI Anselm R. Garbe\n"; |
38 static int (*x_error_handler) (Display *, XErrorEvent *); |
63 static int (*x_error_handler) (Display *, XErrorEvent *); |
39 |
64 |
40 static const char *status[] = { |
|
41 "sh", "-c", "echo -n `date '+%Y-%m-%d %H:%M'`" |
|
42 " `uptime | sed 's/.*://; s/,//g'`" |
|
43 " `acpi | awk '{print $4}' | sed 's/,//'`", 0 |
|
44 }; |
|
45 |
|
46 static void |
65 static void |
47 usage() |
66 usage() { error("usage: gridwm [-v]\n"); } |
48 { |
|
49 fputs("usage: gridwm [-v]\n", stderr); |
|
50 exit(1); |
|
51 } |
|
52 |
67 |
53 static void |
68 static void |
54 scan_wins() |
69 scan_wins() |
55 { |
70 { |
56 unsigned int i, num; |
71 unsigned int i, num; |
228 XFlush(dpy); |
243 XFlush(dpy); |
229 |
244 |
230 if(other_wm_running) |
245 if(other_wm_running) |
231 error("gridwm: another window manager is already running\n"); |
246 error("gridwm: another window manager is already running\n"); |
232 |
247 |
|
248 spawn(dpy, cmdwallpaper); |
233 sx = sy = 0; |
249 sx = sy = 0; |
234 sw = DisplayWidth(dpy, screen); |
250 sw = DisplayWidth(dpy, screen); |
235 sh = DisplayHeight(dpy, screen); |
251 sh = DisplayHeight(dpy, screen); |
236 sel_screen = XQueryPointer(dpy, root, &w, &w, &i, &i, &i, &i, &mask); |
252 issel = XQueryPointer(dpy, root, &w, &w, &i, &i, &i, &i, &mask); |
237 |
253 |
238 XSetErrorHandler(0); |
254 XSetErrorHandler(0); |
239 x_error_handler = XSetErrorHandler(error_handler); |
255 x_error_handler = XSetErrorHandler(error_handler); |
240 |
256 |
241 /* init atoms */ |
257 /* init atoms */ |
273 XMapRaised(dpy, barwin); |
289 XMapRaised(dpy, barwin); |
274 |
290 |
275 brush.drawable = XCreatePixmap(dpy, root, sw, bh, DefaultDepth(dpy, screen)); |
291 brush.drawable = XCreatePixmap(dpy, root, sw, bh, DefaultDepth(dpy, screen)); |
276 brush.gc = XCreateGC(dpy, root, 0, 0); |
292 brush.gc = XCreateGC(dpy, root, 0, 0); |
277 |
293 |
278 pipe_spawn(statustext, sizeof(statustext), dpy, (char **)status); |
294 pipe_spawn(stext, sizeof(stext), dpy, cmdstatus); |
279 draw_bar(); |
295 draw_bar(); |
280 |
296 |
281 wa.event_mask = SubstructureRedirectMask | EnterWindowMask \ |
297 wa.event_mask = SubstructureRedirectMask | EnterWindowMask \ |
282 | LeaveWindowMask; |
298 | LeaveWindowMask; |
283 wa.cursor = cursor[CurNormal]; |
299 wa.cursor = cursor[CurNormal]; |
284 XChangeWindowAttributes(dpy, root, CWEventMask | CWCursor, &wa); |
300 XChangeWindowAttributes(dpy, root, CWEventMask | CWCursor, &wa); |
285 |
301 |
|
302 arrange = grid; |
286 scan_wins(); |
303 scan_wins(); |
287 |
304 |
288 while(running) { |
305 while(running) { |
289 if(XPending(dpy) > 0) { |
306 if(XPending(dpy) > 0) { |
290 XNextEvent(dpy, &ev); |
307 XNextEvent(dpy, &ev); |
296 FD_SET(ConnectionNumber(dpy), &fds); |
313 FD_SET(ConnectionNumber(dpy), &fds); |
297 t = timeout; |
314 t = timeout; |
298 if(select(ConnectionNumber(dpy) + 1, &fds, NULL, NULL, &t) > 0) |
315 if(select(ConnectionNumber(dpy) + 1, &fds, NULL, NULL, &t) > 0) |
299 continue; |
316 continue; |
300 else if(errno != EINTR) { |
317 else if(errno != EINTR) { |
301 pipe_spawn(statustext, sizeof(statustext), dpy, (char **)status); |
318 pipe_spawn(stext, sizeof(stext), dpy, cmdstatus); |
302 draw_bar(); |
319 draw_bar(); |
303 } |
320 } |
304 } |
321 } |
305 |
322 |
306 cleanup(); |
323 cleanup(); |