summaryrefslogtreecommitdiffstats
path: root/client.c
diff options
context:
space:
mode:
authorAnselm R. Garbe <garbeam@wmii.de>2006-07-13 19:55:07 +0200
committerAnselm R. Garbe <garbeam@wmii.de>2006-07-13 19:55:07 +0200
commit3aad92202d58208c4197857d3f17c535ba0bd56a (patch)
tree9a1b23fcf9a4f8c0810d6893b217f265ebebfda6 /client.c
parentseveral other additions/fixes, dwm is quite usable already (diff)
downloaddwm-3aad92202d58208c4197857d3f17c535ba0bd56a.tar.gz
dwm-3aad92202d58208c4197857d3f17c535ba0bd56a.zip
new stuff
Diffstat (limited to '')
-rw-r--r--client.c122
1 files changed, 78 insertions, 44 deletions
diff --git a/client.c b/client.c
index 2ff1994..3c8825d 100644
--- a/client.c
+++ b/client.c
@@ -3,21 +3,19 @@
3 * See LICENSE file for license details. 3 * See LICENSE file for license details.
4 */ 4 */
5 5
6#include <math.h>
7#include <stdlib.h> 6#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#include "dwm.h"
13 13
14static void (*arrange)(Arg *) = floating; 14static void (*arrange)(Arg *) = tiling;
15 15
16static void 16static Rule rule[] = {
17center(Client *c) 17 { "Firefox-bin", "Gecko", { [Twww] = "www" } },
18{ 18};
19 XWarpPointer(dpy, None, c->win, 0, 0, 0, 0, c->w / 2, c->h / 2);
20}
21 19
22static Client * 20static Client *
23next(Client *c) 21next(Client *c)
@@ -29,18 +27,18 @@ next(Client *c)
29void 27void
30zoom(Arg *arg) 28zoom(Arg *arg)
31{ 29{
32 Client **l; 30 Client **l, *old;
33 31
34 if(!sel) 32 if(!(old = sel))
35 return; 33 return;
36 34
37 for(l = &clients; *l && *l != sel; l = &(*l)->next); 35 for(l = &clients; *l && *l != sel; l = &(*l)->next);
38 *l = sel->next; 36 *l = sel->next;
39 37
40 sel->next = clients; /* pop */ 38 old->next = clients; /* pop */
41 clients = sel; 39 clients = old;
40 sel = old;
42 arrange(NULL); 41 arrange(NULL);
43 center(sel);
44 focus(sel); 42 focus(sel);
45} 43}
46 44
@@ -119,39 +117,38 @@ void
119tiling(Arg *arg) 117tiling(Arg *arg)
120{ 118{
121 Client *c; 119 Client *c;
122 int n, cols, rows, gw, gh, i, j; 120 int n, i, w, h;
123 float rt, fd;
124 121
122 w = sw - mw;
125 arrange = tiling; 123 arrange = tiling;
126 for(n = 0, c = clients; c; c = next(c->next), n++); 124 for(n = 0, c = clients; c; c = c->next)
127 if(n) { 125 if(c->tags[tsel])
128 rt = sqrt(n); 126 n++;
129 if(modff(rt, &fd) < 0.5)
130 rows = floor(rt);
131 else
132 rows = ceil(rt);
133 if(rows * rows < n)
134 cols = rows + 1;
135 else
136 cols = rows;
137 127
138 gw = (sw - 2) / cols; 128 h = (n > 2) ? sh / (n - 2) : sh;
139 gh = (sh - 2) / rows;
140 }
141 else
142 cols = rows = gw = gh = 0;
143 129
144 for(i = j = 0, c = clients; c; c = c->next) { 130 for(i = 0, c = clients; c; c = c->next) {
145 if(c->tags[tsel]) { 131 if(c->tags[tsel]) {
146 c->x = i * gw; 132 if(n == 1) {
147 c->y = j * gh; 133 c->x = sx;
148 c->w = gw; 134 c->y = sy;
149 c->h = gh; 135 c->w = sw;
150 resize(c); 136 c->h = sh;
151 if(++i == cols) {
152 j++;
153 i = 0;
154 } 137 }
138 else if(i == 1) {
139 c->x = sx;
140 c->y = sy;
141 c->w = mw;
142 c->h = sh;
143 }
144 else {
145 c->x = sx + mw;
146 c->y = sy + (i - 2) * h;
147 c->w = w;
148 c->h = h;
149 }
150 resize(c);
151 i++;
155 } 152 }
156 else 153 else
157 ban_client(c); 154 ban_client(c);
@@ -175,7 +172,6 @@ prevc(Arg *arg)
175 172
176 if((c = sel->revert && sel->revert->tags[tsel] ? sel->revert : NULL)) { 173 if((c = sel->revert && sel->revert->tags[tsel] ? sel->revert : NULL)) {
177 craise(c); 174 craise(c);
178 center(c);
179 focus(c); 175 focus(c);
180 } 176 }
181} 177}
@@ -192,7 +188,6 @@ nextc(Arg *arg)
192 c = next(clients); 188 c = next(clients);
193 if(c) { 189 if(c) {
194 craise(c); 190 craise(c);
195 center(c);
196 c->revert = sel; 191 c->revert = sel;
197 focus(c); 192 focus(c);
198 } 193 }
@@ -323,6 +318,43 @@ focus(Client *c)
323 discard_events(EnterWindowMask); 318 discard_events(EnterWindowMask);
324} 319}
325 320
321static void
322init_tags(Client *c)
323{
324 XClassHint ch;
325 static unsigned int len = rule ? sizeof(rule) / sizeof(rule[0]) : 0;
326 unsigned int i, j;
327 Bool matched = False;
328
329 if(!len) {
330 c->tags[tsel] = tags[tsel];
331 return;
332 }
333
334 if(XGetClassHint(dpy, c->win, &ch)) {
335 if(ch.res_class && ch.res_name) {
336 fprintf(stderr, "%s:%s\n", ch.res_class, ch.res_name);
337 for(i = 0; i < len; i++)
338 if(!strncmp(rule[i].class, ch.res_class, sizeof(rule[i].class))
339 && !strncmp(rule[i].instance, ch.res_name, sizeof(rule[i].instance)))
340 {
341 fprintf(stderr, "->>>%s:%s\n", ch.res_class, ch.res_name);
342 for(j = 0; j < TLast; j++)
343 c->tags[j] = rule[i].tags[j];
344 matched = True;
345 break;
346 }
347 }
348 if(ch.res_class)
349 XFree(ch.res_class);
350 if(ch.res_name)
351 XFree(ch.res_name);
352 }
353
354 if(!matched)
355 c->tags[tsel] = tags[tsel];
356}
357
326void 358void
327manage(Window w, XWindowAttributes *wa) 359manage(Window w, XWindowAttributes *wa)
328{ 360{
@@ -346,13 +378,13 @@ manage(Window w, XWindowAttributes *wa)
346 twa.background_pixmap = ParentRelative; 378 twa.background_pixmap = ParentRelative;
347 twa.event_mask = ExposureMask; 379 twa.event_mask = ExposureMask;
348 380
349 c->tags[tsel] = tags[tsel];
350 c->title = XCreateWindow(dpy, root, c->tx, c->ty, c->tw, c->th, 381 c->title = XCreateWindow(dpy, root, c->tx, c->ty, c->tw, c->th,
351 0, DefaultDepth(dpy, screen), CopyFromParent, 382 0, DefaultDepth(dpy, screen), CopyFromParent,
352 DefaultVisual(dpy, screen), 383 DefaultVisual(dpy, screen),
353 CWOverrideRedirect | CWBackPixmap | CWEventMask, &twa); 384 CWOverrideRedirect | CWBackPixmap | CWEventMask, &twa);
354 385
355 update_name(c); 386 update_name(c);
387 init_tags(c);
356 388
357 for(l = &clients; *l; l = &(*l)->next); 389 for(l = &clients; *l; l = &(*l)->next);
358 c->next = *l; /* *l == nil */ 390 c->next = *l; /* *l == nil */
@@ -368,8 +400,10 @@ manage(Window w, XWindowAttributes *wa)
368 XGrabButton(dpy, Button3, Mod1Mask, c->win, False, ButtonPressMask, 400 XGrabButton(dpy, Button3, Mod1Mask, c->win, False, ButtonPressMask,
369 GrabModeAsync, GrabModeSync, None, None); 401 GrabModeAsync, GrabModeSync, None, None);
370 arrange(NULL); 402 arrange(NULL);
371 center(c); 403 if(c->tags[tsel])
372 focus(c); 404 focus(c);
405 else
406 ban_client(c);
373} 407}
374 408
375void 409void