9 #include <X11/Xutil.h> |
9 #include <X11/Xutil.h> |
10 |
10 |
11 /* static functions */ |
11 /* static functions */ |
12 |
12 |
13 static void |
13 static void |
14 detachstack(Client *c) |
14 detachstack(Client *c) { |
15 { |
|
16 Client **tc; |
15 Client **tc; |
17 for(tc=&stack; *tc && *tc != c; tc=&(*tc)->snext); |
16 for(tc=&stack; *tc && *tc != c; tc=&(*tc)->snext); |
18 *tc = c->snext; |
17 *tc = c->snext; |
19 } |
18 } |
20 |
19 |
21 static void |
20 static void |
22 grabbuttons(Client *c, Bool focused) |
21 grabbuttons(Client *c, Bool focused) { |
23 { |
|
24 XUngrabButton(dpy, AnyButton, AnyModifier, c->win); |
22 XUngrabButton(dpy, AnyButton, AnyModifier, c->win); |
25 |
23 |
26 if(focused) { |
24 if(focused) { |
27 XGrabButton(dpy, Button1, MODKEY, c->win, False, BUTTONMASK, |
25 XGrabButton(dpy, Button1, MODKEY, c->win, False, BUTTONMASK, |
28 GrabModeAsync, GrabModeSync, None, None); |
26 GrabModeAsync, GrabModeSync, None, None); |
52 GrabModeAsync, GrabModeSync, None, None); |
50 GrabModeAsync, GrabModeSync, None, None); |
53 } |
51 } |
54 else |
52 else |
55 XGrabButton(dpy, AnyButton, AnyModifier, c->win, False, BUTTONMASK, |
53 XGrabButton(dpy, AnyButton, AnyModifier, c->win, False, BUTTONMASK, |
56 GrabModeAsync, GrabModeSync, None, None); |
54 GrabModeAsync, GrabModeSync, None, None); |
57 |
|
58 } |
55 } |
59 |
56 |
60 static void |
57 static void |
61 resizetitle(Client *c) |
58 resizetitle(Client *c) { |
62 { |
|
63 c->tw = textw(c->name); |
59 c->tw = textw(c->name); |
64 if(c->tw > c->w) |
60 if(c->tw > c->w) |
65 c->tw = c->w + 2; |
61 c->tw = c->w + 2; |
66 c->tx = c->x + c->w - c->tw + 2; |
62 c->tx = c->x + c->w - c->tw + 2; |
67 c->ty = c->y; |
63 c->ty = c->y; |
68 if(isvisible(c)) |
64 if(isvisible(c)) |
69 XMoveResizeWindow(dpy, c->twin, c->tx, c->ty, c->tw, c->th); |
65 XMoveResizeWindow(dpy, c->twin, c->tx, c->ty, c->tw, c->th); |
70 else |
66 else |
71 XMoveResizeWindow(dpy, c->twin, c->tx + 2 * sw, c->ty, c->tw, c->th); |
67 XMoveResizeWindow(dpy, c->twin, c->tx + 2 * sw, c->ty, c->tw, c->th); |
72 |
|
73 } |
68 } |
74 |
69 |
75 static int |
70 static int |
76 xerrordummy(Display *dsply, XErrorEvent *ee) |
71 xerrordummy(Display *dsply, XErrorEvent *ee) { |
77 { |
|
78 return 0; |
72 return 0; |
79 } |
73 } |
80 |
74 |
81 /* extern functions */ |
75 /* extern functions */ |
82 |
76 |
83 void |
77 void |
84 ban(Client *c) |
78 ban(Client *c) { |
85 { |
|
86 XMoveWindow(dpy, c->win, c->x + 2 * sw, c->y); |
79 XMoveWindow(dpy, c->win, c->x + 2 * sw, c->y); |
87 XMoveWindow(dpy, c->twin, c->tx + 2 * sw, c->ty); |
80 XMoveWindow(dpy, c->twin, c->tx + 2 * sw, c->ty); |
88 } |
81 } |
89 |
82 |
90 void |
83 void |
91 focus(Client *c) |
84 focus(Client *c) { |
92 { |
|
93 Client *old; |
85 Client *old; |
94 |
86 |
95 if(!issel) |
87 if(!issel) |
96 return; |
88 return; |
97 if(!sel) |
89 if(!sel) |
117 else |
109 else |
118 XSetInputFocus(dpy, root, RevertToPointerRoot, CurrentTime); |
110 XSetInputFocus(dpy, root, RevertToPointerRoot, CurrentTime); |
119 } |
111 } |
120 |
112 |
121 Client * |
113 Client * |
122 getclient(Window w) |
114 getclient(Window w) { |
123 { |
|
124 Client *c; |
115 Client *c; |
125 |
116 |
126 for(c = clients; c; c = c->next) |
117 for(c = clients; c; c = c->next) |
127 if(c->win == w) |
118 if(c->win == w) |
128 return c; |
119 return c; |
129 return NULL; |
120 return NULL; |
130 } |
121 } |
131 |
122 |
132 Client * |
123 Client * |
133 getctitle(Window w) |
124 getctitle(Window w) { |
134 { |
|
135 Client *c; |
125 Client *c; |
136 |
126 |
137 for(c = clients; c; c = c->next) |
127 for(c = clients; c; c = c->next) |
138 if(c->twin == w) |
128 if(c->twin == w) |
139 return c; |
129 return c; |
140 return NULL; |
130 return NULL; |
141 } |
131 } |
142 |
132 |
143 void |
133 void |
144 gravitate(Client *c, Bool invert) |
134 gravitate(Client *c, Bool invert) { |
145 { |
|
146 int dx = 0, dy = 0; |
135 int dx = 0, dy = 0; |
147 |
136 |
148 switch(c->grav) { |
137 switch(c->grav) { |
149 default: |
138 default: |
150 break; |
139 break; |
194 c->x += dx; |
183 c->x += dx; |
195 c->y += dy; |
184 c->y += dy; |
196 } |
185 } |
197 |
186 |
198 void |
187 void |
199 killclient(Arg *arg) |
188 killclient(Arg *arg) { |
200 { |
|
201 if(!sel) |
189 if(!sel) |
202 return; |
190 return; |
203 if(sel->proto & PROTODELWIN) |
191 if(sel->proto & PROTODELWIN) |
204 sendevent(sel->win, wmatom[WMProtocols], wmatom[WMDelete]); |
192 sendevent(sel->win, wmatom[WMProtocols], wmatom[WMDelete]); |
205 else |
193 else |
206 XKillClient(dpy, sel->win); |
194 XKillClient(dpy, sel->win); |
207 } |
195 } |
208 |
196 |
209 void |
197 void |
210 manage(Window w, XWindowAttributes *wa) |
198 manage(Window w, XWindowAttributes *wa) { |
211 { |
|
212 Client *c; |
199 Client *c; |
213 Window trans; |
200 Window trans; |
214 XSetWindowAttributes twa; |
201 XSetWindowAttributes twa; |
215 |
202 |
216 c = emallocz(sizeof(Client)); |
203 c = emallocz(sizeof(Client)); |
307 XConfigureWindow(dpy, c->win, CWX | CWY | CWWidth | CWHeight | CWBorderWidth, &wc); |
293 XConfigureWindow(dpy, c->win, CWX | CWY | CWWidth | CWHeight | CWBorderWidth, &wc); |
308 XSync(dpy, False); |
294 XSync(dpy, False); |
309 } |
295 } |
310 |
296 |
311 void |
297 void |
312 updatesize(Client *c) |
298 updatesize(Client *c) { |
313 { |
|
314 long msize; |
299 long msize; |
315 XSizeHints size; |
300 XSizeHints size; |
316 |
301 |
317 if(!XGetWMNormalHints(dpy, c->win, &size, &msize) || !size.flags) |
302 if(!XGetWMNormalHints(dpy, c->win, &size, &msize) || !size.flags) |
318 size.flags = PSize; |
303 size.flags = PSize; |