summaryrefslogtreecommitdiffstats
path: root/client.c
diff options
context:
space:
mode:
authorAnselm R. Garbe <garbeam@wmii.de>2006-07-15 16:30:50 +0200
committerAnselm R. Garbe <garbeam@wmii.de>2006-07-15 16:30:50 +0200
commitdba23062bad40afb1a90f60b6897cf9e1ca5035b (patch)
treea2823b36177e027cf3aa82f764c37cfc6eea4503 /client.c
parentsanitized names (diff)
downloaddwm-dba23062bad40afb1a90f60b6897cf9e1ca5035b.tar.gz
dwm-dba23062bad40afb1a90f60b6897cf9e1ca5035b.zip
rearranged several stuff
Diffstat (limited to 'client.c')
-rw-r--r--client.c145
1 files changed, 87 insertions, 58 deletions
diff --git a/client.c b/client.c
index 7bb8459..169c01e 100644
--- a/client.c
+++ b/client.c
@@ -11,18 +11,6 @@
11 11
12#include "dwm.h" 12#include "dwm.h"
13 13
14static Rule rule[] = {
15 /* class instance tags floating */
16 { "Firefox-bin", "Gecko", { [Twww] = "www" }, False },
17};
18
19Client *
20getnext(Client *c)
21{
22 for(; c && !c->tags[tsel]; c = c->next);
23 return c;
24}
25
26void 14void
27ban(Client *c) 15ban(Client *c)
28{ 16{
@@ -31,7 +19,7 @@ ban(Client *c)
31} 19}
32 20
33static void 21static void
34resize_title(Client *c) 22resizetitle(Client *c)
35{ 23{
36 int i; 24 int i;
37 25
@@ -72,7 +60,7 @@ settitle(Client *c)
72 } 60 }
73 } 61 }
74 XFree(name.value); 62 XFree(name.value);
75 resize_title(c); 63 resizetitle(c);
76} 64}
77 65
78void 66void
@@ -143,42 +131,6 @@ focus(Client *c)
143 while(XCheckMaskEvent(dpy, EnterWindowMask, &ev)); 131 while(XCheckMaskEvent(dpy, EnterWindowMask, &ev));
144} 132}
145 133
146static void
147init_tags(Client *c)
148{
149 XClassHint ch;
150 static unsigned int len = rule ? sizeof(rule) / sizeof(rule[0]) : 0;
151 unsigned int i, j;
152 Bool matched = False;
153
154 if(!len) {
155 c->tags[tsel] = tags[tsel];
156 return;
157 }
158
159 if(XGetClassHint(dpy, c->win, &ch)) {
160 if(ch.res_class && ch.res_name) {
161 for(i = 0; i < len; i++)
162 if(!strncmp(rule[i].class, ch.res_class, sizeof(rule[i].class))
163 && !strncmp(rule[i].instance, ch.res_name, sizeof(rule[i].instance)))
164 {
165 for(j = 0; j < TLast; j++)
166 c->tags[j] = rule[i].tags[j];
167 c->floating = rule[i].floating;
168 matched = True;
169 break;
170 }
171 }
172 if(ch.res_class)
173 XFree(ch.res_class);
174 if(ch.res_name)
175 XFree(ch.res_name);
176 }
177
178 if(!matched)
179 c->tags[tsel] = tags[tsel];
180}
181
182void 134void
183manage(Window w, XWindowAttributes *wa) 135manage(Window w, XWindowAttributes *wa)
184{ 136{
@@ -196,7 +148,7 @@ manage(Window w, XWindowAttributes *wa)
196 c->h = wa->height; 148 c->h = wa->height;
197 c->th = bh; 149 c->th = bh;
198 c->border = 1; 150 c->border = 1;
199 c->proto = proto(c->win); 151 c->proto = getproto(c->win);
200 setsize(c); 152 setsize(c);
201 XSelectInput(dpy, c->win, 153 XSelectInput(dpy, c->win,
202 StructureNotifyMask | PropertyChangeMask | EnterWindowMask); 154 StructureNotifyMask | PropertyChangeMask | EnterWindowMask);
@@ -211,7 +163,7 @@ manage(Window w, XWindowAttributes *wa)
211 CWOverrideRedirect | CWBackPixmap | CWEventMask, &twa); 163 CWOverrideRedirect | CWBackPixmap | CWEventMask, &twa);
212 164
213 settitle(c); 165 settitle(c);
214 init_tags(c); 166 settags(c);
215 167
216 for(l = &clients; *l; l = &(*l)->next); 168 for(l = &clients; *l; l = &(*l)->next);
217 c->next = *l; /* *l == nil */ 169 c->next = *l; /* *l == nil */
@@ -224,8 +176,8 @@ manage(Window w, XWindowAttributes *wa)
224 XGrabButton(dpy, Button3, Mod1Mask, c->win, False, ButtonPressMask, 176 XGrabButton(dpy, Button3, Mod1Mask, c->win, False, ButtonPressMask,
225 GrabModeAsync, GrabModeSync, None, None); 177 GrabModeAsync, GrabModeSync, None, None);
226 178
227 if(!c->floating) 179 if(!c->dofloat)
228 c->floating = trans 180 c->dofloat = trans
229 || ((c->maxw == c->minw) && (c->maxh == c->minh)); 181 || ((c->maxw == c->minw) && (c->maxh == c->minh));
230 182
231 arrange(NULL); 183 arrange(NULL);
@@ -321,7 +273,7 @@ resize(Client *c, Bool inc)
321 c->w = c->maxw; 273 c->w = c->maxw;
322 if(c->maxh && c->h > c->maxh) 274 if(c->maxh && c->h > c->maxh)
323 c->h = c->maxh; 275 c->h = c->maxh;
324 resize_title(c); 276 resizetitle(c);
325 XSetWindowBorderWidth(dpy, c->win, 1); 277 XSetWindowBorderWidth(dpy, c->win, 1);
326 XMoveResizeWindow(dpy, c->win, c->x, c->y, c->w, c->h); 278 XMoveResizeWindow(dpy, c->win, c->x, c->y, c->w, c->h);
327 e.type = ConfigureNotify; 279 e.type = ConfigureNotify;
@@ -339,7 +291,7 @@ resize(Client *c, Bool inc)
339} 291}
340 292
341static int 293static int
342dummy_xerror(Display *dsply, XErrorEvent *err) 294xerrordummy(Display *dsply, XErrorEvent *ee)
343{ 295{
344 return 0; 296 return 0;
345} 297}
@@ -350,7 +302,7 @@ unmanage(Client *c)
350 Client **l; 302 Client **l;
351 303
352 XGrabServer(dpy); 304 XGrabServer(dpy);
353 XSetErrorHandler(dummy_xerror); 305 XSetErrorHandler(xerrordummy);
354 306
355 XUngrabButton(dpy, AnyButton, AnyModifier, c->win); 307 XUngrabButton(dpy, AnyButton, AnyModifier, c->win);
356 XDestroyWindow(dpy, c->title); 308 XDestroyWindow(dpy, c->title);
@@ -374,7 +326,7 @@ unmanage(Client *c)
374} 326}
375 327
376Client * 328Client *
377gettitle(Window w) 329getctitle(Window w)
378{ 330{
379 Client *c; 331 Client *c;
380 for(c = clients; c; c = c->next) 332 for(c = clients; c; c = c->next)
@@ -392,3 +344,80 @@ getclient(Window w)
392 return c; 344 return c;
393 return NULL; 345 return NULL;
394} 346}
347
348void
349zoom(Arg *arg)
350{
351 Client **l, *c;
352
353 if(!sel)
354 return;
355
356 if(sel == getnext(clients) && sel->next) {
357 if((c = getnext(sel->next)))
358 sel = c;
359 }
360
361 for(l = &clients; *l && *l != sel; l = &(*l)->next);
362 *l = sel->next;
363
364 sel->next = clients; /* pop */
365 clients = sel;
366 arrange(NULL);
367 focus(sel);
368}
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}