dwm-meillo
diff tag.c @ 75:f08271b7cb20
rearranged several stuff
author | Anselm R. Garbe <garbeam@wmii.de> |
---|---|
date | Sat, 15 Jul 2006 16:30:50 +0200 |
parents | |
children | 4bd49f404f10 |
line diff
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/tag.c Sat Jul 15 16:30:50 2006 +0200 1.3 @@ -0,0 +1,171 @@ 1.4 +/* 1.5 + * (C)opyright MMVI Anselm R. Garbe <garbeam at gmail dot com> 1.6 + * See LICENSE file for license details. 1.7 + */ 1.8 + 1.9 +#include <stdlib.h> 1.10 +#include <stdio.h> 1.11 +#include <string.h> 1.12 +#include <X11/Xatom.h> 1.13 +#include <X11/Xutil.h> 1.14 + 1.15 +#include "dwm.h" 1.16 + 1.17 +static Rule rule[] = { 1.18 + /* class instance tags dofloat */ 1.19 + { "Firefox-bin", "Gecko", { [Twww] = "www" }, False }, 1.20 +}; 1.21 + 1.22 +void (*arrange)(Arg *) = dotile; 1.23 + 1.24 +Client * 1.25 +getnext(Client *c) 1.26 +{ 1.27 + for(; c && !c->tags[tsel]; c = c->next); 1.28 + return c; 1.29 +} 1.30 + 1.31 +void 1.32 +settags(Client *c) 1.33 +{ 1.34 + XClassHint ch; 1.35 + static unsigned int len = rule ? sizeof(rule) / sizeof(rule[0]) : 0; 1.36 + unsigned int i, j; 1.37 + Bool matched = False; 1.38 + 1.39 + if(!len) { 1.40 + c->tags[tsel] = tags[tsel]; 1.41 + return; 1.42 + } 1.43 + 1.44 + if(XGetClassHint(dpy, c->win, &ch)) { 1.45 + if(ch.res_class && ch.res_name) { 1.46 + for(i = 0; i < len; i++) 1.47 + if(!strncmp(rule[i].class, ch.res_class, sizeof(rule[i].class)) 1.48 + && !strncmp(rule[i].instance, ch.res_name, sizeof(rule[i].instance))) 1.49 + { 1.50 + for(j = 0; j < TLast; j++) 1.51 + c->tags[j] = rule[i].tags[j]; 1.52 + c->dofloat = rule[i].dofloat; 1.53 + matched = True; 1.54 + break; 1.55 + } 1.56 + } 1.57 + if(ch.res_class) 1.58 + XFree(ch.res_class); 1.59 + if(ch.res_name) 1.60 + XFree(ch.res_name); 1.61 + } 1.62 + 1.63 + if(!matched) 1.64 + c->tags[tsel] = tags[tsel]; 1.65 +} 1.66 + 1.67 +void 1.68 +view(Arg *arg) 1.69 +{ 1.70 + tsel = arg->i; 1.71 + arrange(NULL); 1.72 + drawall(); 1.73 +} 1.74 + 1.75 +void 1.76 +dofloat(Arg *arg) 1.77 +{ 1.78 + Client *c; 1.79 + 1.80 + arrange = dofloat; 1.81 + for(c = clients; c; c = c->next) { 1.82 + if(c->tags[tsel]) 1.83 + resize(c, True); 1.84 + else 1.85 + ban(c); 1.86 + } 1.87 + if(sel && !sel->tags[tsel]) { 1.88 + if((sel = getnext(clients))) { 1.89 + higher(sel); 1.90 + focus(sel); 1.91 + } 1.92 + } 1.93 + drawall(); 1.94 +} 1.95 + 1.96 +void 1.97 +dotile(Arg *arg) 1.98 +{ 1.99 + Client *c; 1.100 + int n, i, w, h; 1.101 + 1.102 + w = sw - mw; 1.103 + arrange = dotile; 1.104 + for(n = 0, c = clients; c; c = c->next) 1.105 + if(c->tags[tsel] && !c->dofloat) 1.106 + n++; 1.107 + 1.108 + if(n > 1) 1.109 + h = (sh - bh) / (n - 1); 1.110 + else 1.111 + h = sh - bh; 1.112 + 1.113 + for(i = 0, c = clients; c; c = c->next) { 1.114 + if(c->tags[tsel]) { 1.115 + if(c->dofloat) { 1.116 + higher(c); 1.117 + resize(c, True); 1.118 + continue; 1.119 + } 1.120 + if(n == 1) { 1.121 + c->x = sx; 1.122 + c->y = sy + bh; 1.123 + c->w = sw - 2 * c->border; 1.124 + c->h = sh - 2 * c->border - bh; 1.125 + } 1.126 + else if(i == 0) { 1.127 + c->x = sx; 1.128 + c->y = sy + bh; 1.129 + c->w = mw - 2 * c->border; 1.130 + c->h = sh - 2 * c->border - bh; 1.131 + } 1.132 + else { 1.133 + c->x = sx + mw; 1.134 + c->y = sy + (i - 1) * h + bh; 1.135 + c->w = w - 2 * c->border; 1.136 + c->h = h - 2 * c->border; 1.137 + } 1.138 + resize(c, False); 1.139 + i++; 1.140 + } 1.141 + else 1.142 + ban(c); 1.143 + } 1.144 + if(!sel || (sel && !sel->tags[tsel])) { 1.145 + if((sel = getnext(clients))) { 1.146 + higher(sel); 1.147 + focus(sel); 1.148 + } 1.149 + } 1.150 + drawall(); 1.151 +} 1.152 + 1.153 +void 1.154 +appendtag(Arg *arg) 1.155 +{ 1.156 + if(!sel) 1.157 + return; 1.158 + 1.159 + sel->tags[arg->i] = tags[arg->i]; 1.160 + arrange(NULL); 1.161 +} 1.162 + 1.163 +void 1.164 +replacetag(Arg *arg) 1.165 +{ 1.166 + int i; 1.167 + if(!sel) 1.168 + return; 1.169 + 1.170 + for(i = 0; i < TLast; i++) 1.171 + sel->tags[i] = NULL; 1.172 + appendtag(arg); 1.173 +} 1.174 +