summaryrefslogtreecommitdiffstats
path: root/client.c
diff options
context:
space:
mode:
authorAnselm R. Garbe <garbeam@wmii.de>2006-07-15 17:00:56 +0200
committerAnselm R. Garbe <garbeam@wmii.de>2006-07-15 17:00:56 +0200
commitadaa28a6e600f636f5e86244ccef69e98419ba1a (patch)
treea7373162dabedbc0edf809559781489eca5a3fbb /client.c
parentrearranged several stuff (diff)
downloaddwm-adaa28a6e600f636f5e86244ccef69e98419ba1a.tar.gz
dwm-adaa28a6e600f636f5e86244ccef69e98419ba1a.zip
proceeded with cleaning up, sorting functions, etc
Diffstat (limited to 'client.c')
-rw-r--r--client.c411
1 files changed, 206 insertions, 205 deletions
diff --git a/client.c b/client.c
index 169c01e..1e3216e 100644
--- a/client.c
+++ b/client.c
@@ -2,21 +2,14 @@
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#include "dwm.h"
5 6
6#include <stdlib.h> 7#include <stdlib.h>
7#include <stdio.h>
8#include <string.h> 8#include <string.h>
9#include <X11/Xatom.h> 9#include <X11/Xatom.h>
10#include <X11/Xutil.h> 10#include <X11/Xutil.h>
11 11
12#include "dwm.h" 12/* static functions */
13
14void
15ban(Client *c)
16{
17 XMoveWindow(dpy, c->win, c->x + 2 * sw, c->y);
18 XMoveWindow(dpy, c->title, c->tx + 2 * sw, c->ty);
19}
20 13
21static void 14static void
22resizetitle(Client *c) 15resizetitle(Client *c)
@@ -35,70 +28,141 @@ resizetitle(Client *c)
35 XMoveResizeWindow(dpy, c->title, c->tx, c->ty, c->tw, c->th); 28 XMoveResizeWindow(dpy, c->title, c->tx, c->ty, c->tw, c->th);
36} 29}
37 30
31static int
32xerrordummy(Display *dsply, XErrorEvent *ee)
33{
34 return 0;
35}
36
37/* extern functions */
38
38void 39void
39settitle(Client *c) 40ban(Client *c)
40{ 41{
41 XTextProperty name; 42 XMoveWindow(dpy, c->win, c->x + 2 * sw, c->y);
42 int n; 43 XMoveWindow(dpy, c->title, c->tx + 2 * sw, c->ty);
43 char **list = NULL; 44}
44 45
45 name.nitems = 0; 46void
46 c->name[0] = 0; 47focus(Client *c)
47 XGetTextProperty(dpy, c->win, &name, net_atom[NetWMName]); 48{
48 if(!name.nitems) 49 Client *old = sel;
49 XGetWMName(dpy, c->win, &name); 50 XEvent ev;
50 if(!name.nitems) 51
52 XFlush(dpy);
53 sel = c;
54 if(old && old != c)
55 drawtitle(old);
56 drawtitle(c);
57 XSetInputFocus(dpy, c->win, RevertToPointerRoot, CurrentTime);
58 XFlush(dpy);
59 while(XCheckMaskEvent(dpy, EnterWindowMask, &ev));
60}
61
62void
63focusnext(Arg *arg)
64{
65 Client *c;
66
67 if(!sel)
51 return; 68 return;
52 if(name.encoding == XA_STRING) 69
53 strncpy(c->name, (char *)name.value, sizeof(c->name)); 70 if(!(c = getnext(sel->next)))
54 else { 71 c = getnext(clients);
55 if(XmbTextPropertyToTextList(dpy, &name, &list, &n) >= Success 72 if(c) {
56 && n > 0 && *list) 73 higher(c);
57 { 74 c->revert = sel;
58 strncpy(c->name, *list, sizeof(c->name)); 75 focus(c);
59 XFreeStringList(list);
60 }
61 } 76 }
62 XFree(name.value);
63 resizetitle(c);
64} 77}
65 78
66void 79void
67setsize(Client *c) 80focusprev(Arg *arg)
68{ 81{
69 XSizeHints size; 82 Client *c;
70 long msize; 83
71 if(!XGetWMNormalHints(dpy, c->win, &size, &msize) || !size.flags) 84 if(!sel)
72 size.flags = PSize; 85 return;
73 c->flags = size.flags; 86
74 if(c->flags & PBaseSize) { 87 if((c = sel->revert && sel->revert->tags[tsel] ? sel->revert : NULL)) {
75 c->basew = size.base_width; 88 higher(c);
76 c->baseh = size.base_height; 89 focus(c);
77 } 90 }
78 else 91}
79 c->basew = c->baseh = 0; 92
80 if(c->flags & PResizeInc) { 93Client *
81 c->incw = size.width_inc; 94getclient(Window w)
82 c->inch = size.height_inc; 95{
96 Client *c;
97 for(c = clients; c; c = c->next)
98 if(c->win == w)
99 return c;
100 return NULL;
101}
102
103Client *
104getctitle(Window w)
105{
106 Client *c;
107 for(c = clients; c; c = c->next)
108 if(c->title == w)
109 return c;
110 return NULL;
111}
112
113void
114gravitate(Client *c, Bool invert)
115{
116 int dx = 0, dy = 0;
117
118 switch(c->grav) {
119 case StaticGravity:
120 case NorthWestGravity:
121 case NorthGravity:
122 case NorthEastGravity:
123 dy = c->border;
124 break;
125 case EastGravity:
126 case CenterGravity:
127 case WestGravity:
128 dy = -(c->h / 2) + c->border;
129 break;
130 case SouthEastGravity:
131 case SouthGravity:
132 case SouthWestGravity:
133 dy = -c->h;
134 break;
135 default:
136 break;
83 } 137 }
84 else 138
85 c->incw = c->inch = 0; 139 switch (c->grav) {
86 if(c->flags & PMaxSize) { 140 case StaticGravity:
87 c->maxw = size.max_width; 141 case NorthWestGravity:
88 c->maxh = size.max_height; 142 case WestGravity:
143 case SouthWestGravity:
144 dx = c->border;
145 break;
146 case NorthGravity:
147 case CenterGravity:
148 case SouthGravity:
149 dx = -(c->w / 2) + c->border;
150 break;
151 case NorthEastGravity:
152 case EastGravity:
153 case SouthEastGravity:
154 dx = -(c->w + c->border);
155 break;
156 default:
157 break;
89 } 158 }
90 else 159
91 c->maxw = c->maxh = 0; 160 if(invert) {
92 if(c->flags & PMinSize) { 161 dx = -dx;
93 c->minw = size.min_width; 162 dy = -dy;
94 c->minh = size.min_height;
95 } 163 }
96 else 164 c->x += dx;
97 c->minw = c->minh = 0; 165 c->y += dy;
98 if(c->flags & PWinGravity)
99 c->grav = size.win_gravity;
100 else
101 c->grav = NorthWestGravity;
102} 166}
103 167
104void 168void
@@ -109,26 +173,21 @@ higher(Client *c)
109} 173}
110 174
111void 175void
112lower(Client *c) 176killclient(Arg *arg)
113{ 177{
114 XLowerWindow(dpy, c->title); 178 if(!sel)
115 XLowerWindow(dpy, c->win); 179 return;
180 if(sel->proto & WM_PROTOCOL_DELWIN)
181 sendevent(sel->win, wm_atom[WMProtocols], wm_atom[WMDelete]);
182 else
183 XKillClient(dpy, sel->win);
116} 184}
117 185
118void 186void
119focus(Client *c) 187lower(Client *c)
120{ 188{
121 Client *old = sel; 189 XLowerWindow(dpy, c->title);
122 XEvent ev; 190 XLowerWindow(dpy, c->win);
123
124 XFlush(dpy);
125 sel = c;
126 if(old && old != c)
127 drawtitle(old);
128 drawtitle(c);
129 XSetInputFocus(dpy, c->win, RevertToPointerRoot, CurrentTime);
130 XFlush(dpy);
131 while(XCheckMaskEvent(dpy, EnterWindowMask, &ev));
132} 191}
133 192
134void 193void
@@ -195,61 +254,18 @@ manage(Window w, XWindowAttributes *wa)
195} 254}
196 255
197void 256void
198gravitate(Client *c, Bool invert) 257maximize(Arg *arg)
199{ 258{
200 int dx = 0, dy = 0; 259 if(!sel)
201 260 return;
202 switch(c->grav) { 261 sel->x = sx;
203 case StaticGravity: 262 sel->y = sy + bh;
204 case NorthWestGravity: 263 sel->w = sw - 2 * sel->border;
205 case NorthGravity: 264 sel->h = sh - 2 * sel->border - bh;
206 case NorthEastGravity: 265 higher(sel);
207 dy = c->border; 266 resize(sel, False);
208 break;
209 case EastGravity:
210 case CenterGravity:
211 case WestGravity:
212 dy = -(c->h / 2) + c->border;
213 break;
214 case SouthEastGravity:
215 case SouthGravity:
216 case SouthWestGravity:
217 dy = -c->h;
218 break;
219 default:
220 break;
221 }
222
223 switch (c->grav) {
224 case StaticGravity:
225 case NorthWestGravity:
226 case WestGravity:
227 case SouthWestGravity:
228 dx = c->border;
229 break;
230 case NorthGravity:
231 case CenterGravity:
232 case SouthGravity:
233 dx = -(c->w / 2) + c->border;
234 break;
235 case NorthEastGravity:
236 case EastGravity:
237 case SouthEastGravity:
238 dx = -(c->w + c->border);
239 break;
240 default:
241 break;
242 }
243
244 if(invert) {
245 dx = -dx;
246 dy = -dy;
247 }
248 c->x += dx;
249 c->y += dy;
250} 267}
251 268
252
253void 269void
254resize(Client *c, Bool inc) 270resize(Client *c, Bool inc)
255{ 271{
@@ -290,10 +306,70 @@ resize(Client *c, Bool inc)
290 XFlush(dpy); 306 XFlush(dpy);
291} 307}
292 308
293static int 309void
294xerrordummy(Display *dsply, XErrorEvent *ee) 310setsize(Client *c)
295{ 311{
296 return 0; 312 XSizeHints size;
313 long msize;
314 if(!XGetWMNormalHints(dpy, c->win, &size, &msize) || !size.flags)
315 size.flags = PSize;
316 c->flags = size.flags;
317 if(c->flags & PBaseSize) {
318 c->basew = size.base_width;
319 c->baseh = size.base_height;
320 }
321 else
322 c->basew = c->baseh = 0;
323 if(c->flags & PResizeInc) {
324 c->incw = size.width_inc;
325 c->inch = size.height_inc;
326 }
327 else
328 c->incw = c->inch = 0;
329 if(c->flags & PMaxSize) {
330 c->maxw = size.max_width;
331 c->maxh = size.max_height;
332 }
333 else
334 c->maxw = c->maxh = 0;
335 if(c->flags & PMinSize) {
336 c->minw = size.min_width;
337 c->minh = size.min_height;
338 }
339 else
340 c->minw = c->minh = 0;
341 if(c->flags & PWinGravity)
342 c->grav = size.win_gravity;
343 else
344 c->grav = NorthWestGravity;
345}
346
347void
348settitle(Client *c)
349{
350 XTextProperty name;
351 int n;
352 char **list = NULL;
353
354 name.nitems = 0;
355 c->name[0] = 0;
356 XGetTextProperty(dpy, c->win, &name, net_atom[NetWMName]);
357 if(!name.nitems)
358 XGetWMName(dpy, c->win, &name);
359 if(!name.nitems)
360 return;
361 if(name.encoding == XA_STRING)
362 strncpy(c->name, (char *)name.value, sizeof(c->name));
363 else {
364 if(XmbTextPropertyToTextList(dpy, &name, &list, &n) >= Success
365 && n > 0 && *list)
366 {
367 strncpy(c->name, *list, sizeof(c->name));
368 XFreeStringList(list);
369 }
370 }
371 XFree(name.value);
372 resizetitle(c);
297} 373}
298 374
299void 375void
@@ -325,26 +401,6 @@ unmanage(Client *c)
325 focus(sel); 401 focus(sel);
326} 402}
327 403
328Client *
329getctitle(Window w)
330{
331 Client *c;
332 for(c = clients; c; c = c->next)
333 if(c->title == w)
334 return c;
335 return NULL;
336}
337
338Client *
339getclient(Window w)
340{
341 Client *c;
342 for(c = clients; c; c = c->next)
343 if(c->win == w)
344 return c;
345 return NULL;
346}
347
348void 404void
349zoom(Arg *arg) 405zoom(Arg *arg)
350{ 406{
@@ -366,58 +422,3 @@ zoom(Arg *arg)
366 arrange(NULL); 422 arrange(NULL);
367 focus(sel); 423 focus(sel);
368} 424}
369
370void
371maximize(Arg *arg)
372{
373 if(!sel)
374 return;
375 sel->x = sx;
376 sel->y = sy + bh;
377 sel->w = sw - 2 * sel->border;
378 sel->h = sh - 2 * sel->border - bh;
379 higher(sel);
380 resize(sel, False);
381}
382
383void
384focusprev(Arg *arg)
385{
386 Client *c;
387
388 if(!sel)
389 return;
390
391 if((c = sel->revert && sel->revert->tags[tsel] ? sel->revert : NULL)) {
392 higher(c);
393 focus(c);
394 }
395}
396
397void
398focusnext(Arg *arg)
399{
400 Client *c;
401
402 if(!sel)
403 return;
404
405 if(!(c = getnext(sel->next)))
406 c = getnext(clients);
407 if(c) {
408 higher(c);
409 c->revert = sel;
410 focus(c);
411 }
412}
413
414void
415killclient(Arg *arg)
416{
417 if(!sel)
418 return;
419 if(sel->proto & WM_PROTOCOL_DELWIN)
420 sendevent(sel->win, wm_atom[WMProtocols], wm_atom[WMDelete]);
421 else
422 XKillClient(dpy, sel->win);
423}