dwm-meillo
view tag.c @ 101:17c526ee321c
fixed a typo
author | arg@10ksloc.org |
---|---|
date | Wed, 19 Jul 2006 13:24:58 +0200 |
parents | 1d125cf2925b |
children | 3a708f113f55 |
line source
1 /*
2 * (C)opyright MMVI Anselm R. Garbe <garbeam at gmail dot com>
3 * See LICENSE file for license details.
4 */
5 #include "dwm.h"
7 #include <string.h>
8 #include <X11/Xutil.h>
10 /* static */
12 /* CUSTOMIZE */
13 static Rule rule[] = {
14 /* class instance tags isfloat */
15 { "Firefox-bin", "firefox-bin", { [Twww] = "www" }, False },
16 };
18 /* extern */
20 /* CUSTOMIZE */
21 char *tags[TLast] = {
22 [Tscratch] = "scratch",
23 [Tdev] = "dev",
24 [Twww] = "www",
25 [Twork] = "work",
26 };
27 void (*arrange)(Arg *) = dotile;
29 void
30 appendtag(Arg *arg)
31 {
32 if(!sel)
33 return;
35 sel->tags[arg->i] = tags[arg->i];
36 arrange(NULL);
37 }
39 void
40 dofloat(Arg *arg)
41 {
42 Client *c;
44 arrange = dofloat;
45 for(c = clients; c; c = c->next) {
46 setgeom(c);
47 if(c->tags[tsel]) {
48 resize(c, True, TopLeft);
49 }
50 else
51 ban(c);
52 }
53 if(sel && !sel->tags[tsel]) {
54 if((sel = getnext(clients, tsel))) {
55 higher(sel);
56 focus(sel);
57 }
58 }
59 drawall();
60 }
62 void
63 dotile(Arg *arg)
64 {
65 Client *c;
66 int n, i, w, h;
68 w = sw - mw;
69 arrange = dotile;
70 for(n = 0, c = clients; c; c = c->next)
71 if(c->tags[tsel] && !c->isfloat)
72 n++;
74 if(n > 1)
75 h = (sh - bh) / (n - 1);
76 else
77 h = sh - bh;
79 for(i = 0, c = clients; c; c = c->next) {
80 setgeom(c);
81 if(c->tags[tsel]) {
82 if(c->isfloat) {
83 higher(c);
84 resize(c, True, TopLeft);
85 continue;
86 }
87 if(n == 1) {
88 *c->x = sx;
89 *c->y = sy + bh;
90 *c->w = sw - 2 * c->border;
91 *c->h = sh - 2 * c->border - bh;
92 }
93 else if(i == 0) {
94 *c->x = sx;
95 *c->y = sy + bh;
96 *c->w = mw - 2 * c->border;
97 *c->h = sh - 2 * c->border - bh;
98 }
99 else {
100 *c->x = sx + mw;
101 *c->y = sy + (i - 1) * h + bh;
102 *c->w = w - 2 * c->border;
103 *c->h = h - 2 * c->border;
104 }
105 resize(c, False, TopLeft);
106 i++;
107 }
108 else
109 ban(c);
110 }
111 if(!sel || (sel && !sel->tags[tsel])) {
112 if((sel = getnext(clients, tsel))) {
113 higher(sel);
114 focus(sel);
115 }
116 }
117 drawall();
118 }
120 Client *
121 getnext(Client *c, unsigned int t)
122 {
123 for(; c && !c->tags[t]; c = c->next);
124 return c;
125 }
127 void
128 heretag(Arg *arg)
129 {
130 int i;
131 Client *c;
133 if(arg->i == tsel)
134 return;
136 if(!(c = getnext(clients, arg->i)))
137 return;
139 for(i = 0; i < TLast; i++)
140 c->tags[i] = NULL;
141 c->tags[tsel] = tags[tsel];
142 pop(c);
143 focus(c);
144 }
146 void
147 replacetag(Arg *arg)
148 {
149 int i;
150 if(!sel)
151 return;
153 for(i = 0; i < TLast; i++)
154 sel->tags[i] = NULL;
155 appendtag(arg);
156 }
158 void
159 settags(Client *c)
160 {
161 XClassHint ch;
162 static unsigned int len = rule ? sizeof(rule) / sizeof(rule[0]) : 0;
163 unsigned int i, j;
164 Bool matched = False;
166 if(!len) {
167 c->tags[tsel] = tags[tsel];
168 return;
169 }
171 if(XGetClassHint(dpy, c->win, &ch)) {
172 if(ch.res_class && ch.res_name) {
173 for(i = 0; i < len; i++)
174 if(!strncmp(rule[i].class, ch.res_class, sizeof(rule[i].class))
175 && !strncmp(rule[i].instance, ch.res_name, sizeof(rule[i].instance)))
176 {
177 for(j = 0; j < TLast; j++)
178 c->tags[j] = rule[i].tags[j];
179 c->isfloat = rule[i].isfloat;
180 matched = True;
181 break;
182 }
183 }
184 if(ch.res_class)
185 XFree(ch.res_class);
186 if(ch.res_name)
187 XFree(ch.res_name);
188 }
190 if(!matched)
191 c->tags[tsel] = tags[tsel];
192 }
194 void
195 view(Arg *arg)
196 {
197 tsel = arg->i;
198 arrange(NULL);
199 drawall();
200 }