dwm-meillo
diff client.c @ 51:035617ee18d1
new stuff
author | Anselm R. Garbe <garbeam@wmii.de> |
---|---|
date | Thu, 13 Jul 2006 19:55:07 +0200 |
parents | 148f25ed0ad7 |
children | d18f6dd0cf23 |
line diff
1.1 --- a/client.c Thu Jul 13 18:21:38 2006 +0200 1.2 +++ b/client.c Thu Jul 13 19:55:07 2006 +0200 1.3 @@ -3,21 +3,19 @@ 1.4 * See LICENSE file for license details. 1.5 */ 1.6 1.7 -#include <math.h> 1.8 #include <stdlib.h> 1.9 +#include <stdio.h> 1.10 #include <string.h> 1.11 #include <X11/Xatom.h> 1.12 #include <X11/Xutil.h> 1.13 1.14 #include "dwm.h" 1.15 1.16 -static void (*arrange)(Arg *) = floating; 1.17 +static void (*arrange)(Arg *) = tiling; 1.18 1.19 -static void 1.20 -center(Client *c) 1.21 -{ 1.22 - XWarpPointer(dpy, None, c->win, 0, 0, 0, 0, c->w / 2, c->h / 2); 1.23 -} 1.24 +static Rule rule[] = { 1.25 + { "Firefox-bin", "Gecko", { [Twww] = "www" } }, 1.26 +}; 1.27 1.28 static Client * 1.29 next(Client *c) 1.30 @@ -29,18 +27,18 @@ 1.31 void 1.32 zoom(Arg *arg) 1.33 { 1.34 - Client **l; 1.35 + Client **l, *old; 1.36 1.37 - if(!sel) 1.38 + if(!(old = sel)) 1.39 return; 1.40 1.41 for(l = &clients; *l && *l != sel; l = &(*l)->next); 1.42 *l = sel->next; 1.43 1.44 - sel->next = clients; /* pop */ 1.45 - clients = sel; 1.46 + old->next = clients; /* pop */ 1.47 + clients = old; 1.48 + sel = old; 1.49 arrange(NULL); 1.50 - center(sel); 1.51 focus(sel); 1.52 } 1.53 1.54 @@ -119,39 +117,38 @@ 1.55 tiling(Arg *arg) 1.56 { 1.57 Client *c; 1.58 - int n, cols, rows, gw, gh, i, j; 1.59 - float rt, fd; 1.60 + int n, i, w, h; 1.61 1.62 + w = sw - mw; 1.63 arrange = tiling; 1.64 - for(n = 0, c = clients; c; c = next(c->next), n++); 1.65 - if(n) { 1.66 - rt = sqrt(n); 1.67 - if(modff(rt, &fd) < 0.5) 1.68 - rows = floor(rt); 1.69 - else 1.70 - rows = ceil(rt); 1.71 - if(rows * rows < n) 1.72 - cols = rows + 1; 1.73 - else 1.74 - cols = rows; 1.75 + for(n = 0, c = clients; c; c = c->next) 1.76 + if(c->tags[tsel]) 1.77 + n++; 1.78 1.79 - gw = (sw - 2) / cols; 1.80 - gh = (sh - 2) / rows; 1.81 - } 1.82 - else 1.83 - cols = rows = gw = gh = 0; 1.84 + h = (n > 2) ? sh / (n - 2) : sh; 1.85 1.86 - for(i = j = 0, c = clients; c; c = c->next) { 1.87 + for(i = 0, c = clients; c; c = c->next) { 1.88 if(c->tags[tsel]) { 1.89 - c->x = i * gw; 1.90 - c->y = j * gh; 1.91 - c->w = gw; 1.92 - c->h = gh; 1.93 + if(n == 1) { 1.94 + c->x = sx; 1.95 + c->y = sy; 1.96 + c->w = sw; 1.97 + c->h = sh; 1.98 + } 1.99 + else if(i == 1) { 1.100 + c->x = sx; 1.101 + c->y = sy; 1.102 + c->w = mw; 1.103 + c->h = sh; 1.104 + } 1.105 + else { 1.106 + c->x = sx + mw; 1.107 + c->y = sy + (i - 2) * h; 1.108 + c->w = w; 1.109 + c->h = h; 1.110 + } 1.111 resize(c); 1.112 - if(++i == cols) { 1.113 - j++; 1.114 - i = 0; 1.115 - } 1.116 + i++; 1.117 } 1.118 else 1.119 ban_client(c); 1.120 @@ -175,7 +172,6 @@ 1.121 1.122 if((c = sel->revert && sel->revert->tags[tsel] ? sel->revert : NULL)) { 1.123 craise(c); 1.124 - center(c); 1.125 focus(c); 1.126 } 1.127 } 1.128 @@ -192,7 +188,6 @@ 1.129 c = next(clients); 1.130 if(c) { 1.131 craise(c); 1.132 - center(c); 1.133 c->revert = sel; 1.134 focus(c); 1.135 } 1.136 @@ -323,6 +318,43 @@ 1.137 discard_events(EnterWindowMask); 1.138 } 1.139 1.140 +static void 1.141 +init_tags(Client *c) 1.142 +{ 1.143 + XClassHint ch; 1.144 + static unsigned int len = rule ? sizeof(rule) / sizeof(rule[0]) : 0; 1.145 + unsigned int i, j; 1.146 + Bool matched = False; 1.147 + 1.148 + if(!len) { 1.149 + c->tags[tsel] = tags[tsel]; 1.150 + return; 1.151 + } 1.152 + 1.153 + if(XGetClassHint(dpy, c->win, &ch)) { 1.154 + if(ch.res_class && ch.res_name) { 1.155 + fprintf(stderr, "%s:%s\n", ch.res_class, ch.res_name); 1.156 + for(i = 0; i < len; i++) 1.157 + if(!strncmp(rule[i].class, ch.res_class, sizeof(rule[i].class)) 1.158 + && !strncmp(rule[i].instance, ch.res_name, sizeof(rule[i].instance))) 1.159 + { 1.160 + fprintf(stderr, "->>>%s:%s\n", ch.res_class, ch.res_name); 1.161 + for(j = 0; j < TLast; j++) 1.162 + c->tags[j] = rule[i].tags[j]; 1.163 + matched = True; 1.164 + break; 1.165 + } 1.166 + } 1.167 + if(ch.res_class) 1.168 + XFree(ch.res_class); 1.169 + if(ch.res_name) 1.170 + XFree(ch.res_name); 1.171 + } 1.172 + 1.173 + if(!matched) 1.174 + c->tags[tsel] = tags[tsel]; 1.175 +} 1.176 + 1.177 void 1.178 manage(Window w, XWindowAttributes *wa) 1.179 { 1.180 @@ -346,13 +378,13 @@ 1.181 twa.background_pixmap = ParentRelative; 1.182 twa.event_mask = ExposureMask; 1.183 1.184 - c->tags[tsel] = tags[tsel]; 1.185 c->title = XCreateWindow(dpy, root, c->tx, c->ty, c->tw, c->th, 1.186 0, DefaultDepth(dpy, screen), CopyFromParent, 1.187 DefaultVisual(dpy, screen), 1.188 CWOverrideRedirect | CWBackPixmap | CWEventMask, &twa); 1.189 1.190 update_name(c); 1.191 + init_tags(c); 1.192 1.193 for(l = &clients; *l; l = &(*l)->next); 1.194 c->next = *l; /* *l == nil */ 1.195 @@ -368,8 +400,10 @@ 1.196 XGrabButton(dpy, Button3, Mod1Mask, c->win, False, ButtonPressMask, 1.197 GrabModeAsync, GrabModeSync, None, None); 1.198 arrange(NULL); 1.199 - center(c); 1.200 - focus(c); 1.201 + if(c->tags[tsel]) 1.202 + focus(c); 1.203 + else 1.204 + ban_client(c); 1.205 } 1.206 1.207 void