comparison client.c @ 27:f96fb3fd8203

added grid mode on Mod1Mask g
author Anselm R. Garbe <garbeam@wmii.de>
date Wed, 12 Jul 2006 16:00:51 +0200
parents e8f627998d6f
children 3dceb132082d
comparison
equal deleted inserted replaced
26:e8f627998d6f 27:f96fb3fd8203
1 /* 1 /*
2 * (C)opyright MMVI Anselm R. Garbe <garbeam at gmail dot com> 2 * (C)opyright MMVI Anselm R. Garbe <garbeam at gmail dot com>
3 * See LICENSE file for license details. 3 * See LICENSE file for license details.
4 */ 4 */
5 5
6 #include <math.h>
6 #include <stdlib.h> 7 #include <stdlib.h>
7 #include <string.h> 8 #include <string.h>
8 #include <X11/Xatom.h> 9 #include <X11/Xatom.h>
9 10
10 #include "util.h" 11 #include "util.h"
11 #include "wm.h" 12 #include "wm.h"
13
14 void
15 arrange(void *aux)
16 {
17 Client *c;
18 int n, cols, rows, gw, gh, i, j;
19 float rt, fd;
20
21 if(!clients)
22 return;
23 for(n = 0, c = clients; c; c = c->next, n++);
24 rt = sqrt(n);
25 if(modff(rt, &fd) < 0.5)
26 rows = floor(rt);
27 else
28 rows = ceil(rt);
29 if(rows * rows < n)
30 cols = rows + 1;
31 else
32 cols = rows;
33
34 gw = (sw - 1) / cols;
35 gh = (sh - bh - 1) / rows;
36
37 for(i = j = 0, c = clients; c; c = c->next) {
38 c->x = i * gw;
39 c->y = j * gh + bh;
40 c->w = gw;
41 c->h = gh;
42 resize(c);
43 if(++i == cols) {
44 j++;
45 i = 0;
46 }
47 }
48 }
49
50 void
51 sel(void *aux)
52 {
53 const char *arg = aux;
54 Client *c = NULL;
55
56 if(!arg || !stack)
57 return;
58 if(!strncmp(arg, "next", 5))
59 c = stack->snext ? stack->snext : stack;
60 else if(!strncmp(arg, "prev", 5))
61 for(c = stack; c && c->snext; c = c->snext);
62 if(!c)
63 c = stack;
64 raise(c);
65 focus(c);
66 }
67
68 void
69 kill(void *aux)
70 {
71 Client *c = stack;
72
73 if(!c)
74 return;
75 if(c->proto & WM_PROTOCOL_DELWIN)
76 send_message(c->win, wm_atom[WMProtocols], wm_atom[WMDelete]);
77 else
78 XKillClient(dpy, c->win);
79 }
12 80
13 static void 81 static void
14 resize_title(Client *c) 82 resize_title(Client *c)
15 { 83 {
16 c->tw = textw(&brush.font, c->name) + bh; 84 c->tw = textw(&brush.font, c->name) + bh;
111 if(old && old != c) { 179 if(old && old != c) {
112 XMapWindow(dpy, old->title); 180 XMapWindow(dpy, old->title);
113 draw_client(old); 181 draw_client(old);
114 } 182 }
115 XUnmapWindow(dpy, c->title); 183 XUnmapWindow(dpy, c->title);
116 draw_client(old); 184 draw_client(c);
117 XSetInputFocus(dpy, c->win, RevertToPointerRoot, CurrentTime); 185 XSetInputFocus(dpy, c->win, RevertToPointerRoot, CurrentTime);
118 XFlush(dpy); 186 XFlush(dpy);
119 } 187 }
120 188
121 void 189 void