rev |
line source |
garbeam@75
|
1 /*
|
garbeam@75
|
2 * (C)opyright MMVI Anselm R. Garbe <garbeam at gmail dot com>
|
garbeam@75
|
3 * See LICENSE file for license details.
|
garbeam@75
|
4 */
|
garbeam@76
|
5 #include "dwm.h"
|
garbeam@75
|
6
|
arg@114
|
7 #include <regex.h>
|
arg@114
|
8 #include <stdio.h>
|
garbeam@75
|
9 #include <string.h>
|
arg@114
|
10 #include <sys/types.h>
|
garbeam@75
|
11 #include <X11/Xutil.h>
|
garbeam@75
|
12
|
garbeam@84
|
13 /* static */
|
garbeam@76
|
14
|
arg@114
|
15 typedef struct {
|
arg@114
|
16 const char *pattern;
|
arg@114
|
17 char *tags[TLast];
|
arg@114
|
18 Bool isfloat;
|
arg@114
|
19 } Rule;
|
arg@114
|
20
|
garbeam@84
|
21 /* CUSTOMIZE */
|
garbeam@84
|
22 static Rule rule[] = {
|
arg@123
|
23 /* class:instance tags isfloat */
|
arg@123
|
24 { "Firefox.*", { [Twww] = "www" }, False },
|
arg@123
|
25 { "Gimp.*", { 0 }, True},
|
garbeam@84
|
26 };
|
garbeam@84
|
27
|
garbeam@84
|
28 /* extern */
|
garbeam@84
|
29
|
garbeam@84
|
30 /* CUSTOMIZE */
|
garbeam@76
|
31 char *tags[TLast] = {
|
garbeam@76
|
32 [Tscratch] = "scratch",
|
garbeam@76
|
33 [Tdev] = "dev",
|
garbeam@76
|
34 [Twww] = "www",
|
garbeam@76
|
35 [Twork] = "work",
|
garbeam@76
|
36 };
|
garbeam@75
|
37 void (*arrange)(Arg *) = dotile;
|
garbeam@75
|
38
|
garbeam@76
|
39 void
|
garbeam@76
|
40 appendtag(Arg *arg)
|
garbeam@75
|
41 {
|
garbeam@76
|
42 if(!sel)
|
garbeam@76
|
43 return;
|
garbeam@75
|
44
|
garbeam@76
|
45 sel->tags[arg->i] = tags[arg->i];
|
garbeam@75
|
46 arrange(NULL);
|
garbeam@75
|
47 }
|
garbeam@75
|
48
|
garbeam@75
|
49 void
|
garbeam@75
|
50 dofloat(Arg *arg)
|
garbeam@75
|
51 {
|
garbeam@75
|
52 Client *c;
|
garbeam@75
|
53
|
garbeam@75
|
54 for(c = clients; c; c = c->next) {
|
arg@124
|
55 c->ismax = False;
|
garbeam@95
|
56 if(c->tags[tsel]) {
|
arg@99
|
57 resize(c, True, TopLeft);
|
garbeam@95
|
58 }
|
garbeam@75
|
59 else
|
garbeam@75
|
60 ban(c);
|
garbeam@75
|
61 }
|
garbeam@75
|
62 if(sel && !sel->tags[tsel]) {
|
garbeam@93
|
63 if((sel = getnext(clients, tsel))) {
|
garbeam@75
|
64 higher(sel);
|
garbeam@75
|
65 focus(sel);
|
garbeam@75
|
66 }
|
garbeam@75
|
67 }
|
garbeam@75
|
68 drawall();
|
garbeam@75
|
69 }
|
garbeam@75
|
70
|
garbeam@75
|
71 void
|
garbeam@75
|
72 dotile(Arg *arg)
|
garbeam@75
|
73 {
|
arg@123
|
74 int n, i, w, h;
|
garbeam@75
|
75 Client *c;
|
garbeam@75
|
76
|
garbeam@75
|
77 w = sw - mw;
|
garbeam@75
|
78 for(n = 0, c = clients; c; c = c->next)
|
garbeam@80
|
79 if(c->tags[tsel] && !c->isfloat)
|
garbeam@75
|
80 n++;
|
garbeam@75
|
81
|
garbeam@75
|
82 if(n > 1)
|
garbeam@75
|
83 h = (sh - bh) / (n - 1);
|
garbeam@75
|
84 else
|
garbeam@75
|
85 h = sh - bh;
|
garbeam@75
|
86
|
garbeam@75
|
87 for(i = 0, c = clients; c; c = c->next) {
|
arg@124
|
88 c->ismax = False;
|
garbeam@75
|
89 if(c->tags[tsel]) {
|
garbeam@80
|
90 if(c->isfloat) {
|
garbeam@75
|
91 higher(c);
|
arg@99
|
92 resize(c, True, TopLeft);
|
garbeam@75
|
93 continue;
|
garbeam@75
|
94 }
|
garbeam@75
|
95 if(n == 1) {
|
arg@115
|
96 c->x = sx;
|
arg@115
|
97 c->y = sy + bh;
|
arg@115
|
98 c->w = sw - 2 * c->border;
|
arg@115
|
99 c->h = sh - 2 * c->border - bh;
|
garbeam@75
|
100 }
|
garbeam@75
|
101 else if(i == 0) {
|
arg@115
|
102 c->x = sx;
|
arg@115
|
103 c->y = sy + bh;
|
arg@115
|
104 c->w = mw - 2 * c->border;
|
arg@115
|
105 c->h = sh - 2 * c->border - bh;
|
garbeam@75
|
106 }
|
arg@104
|
107 else if(h > bh) {
|
arg@115
|
108 c->x = sx + mw;
|
arg@115
|
109 c->y = sy + (i - 1) * h + bh;
|
arg@115
|
110 c->w = w - 2 * c->border;
|
arg@115
|
111 c->h = h - 2 * c->border;
|
garbeam@75
|
112 }
|
arg@104
|
113 else { /* fallback if h < bh */
|
arg@115
|
114 c->x = sx + mw;
|
arg@115
|
115 c->y = sy + bh;
|
arg@115
|
116 c->w = w - 2 * c->border;
|
arg@115
|
117 c->h = sh - 2 * c->border - bh;
|
arg@104
|
118 }
|
arg@99
|
119 resize(c, False, TopLeft);
|
garbeam@75
|
120 i++;
|
garbeam@75
|
121 }
|
garbeam@75
|
122 else
|
garbeam@75
|
123 ban(c);
|
garbeam@75
|
124 }
|
garbeam@75
|
125 if(!sel || (sel && !sel->tags[tsel])) {
|
garbeam@93
|
126 if((sel = getnext(clients, tsel))) {
|
garbeam@75
|
127 higher(sel);
|
garbeam@75
|
128 focus(sel);
|
garbeam@75
|
129 }
|
garbeam@75
|
130 }
|
garbeam@75
|
131 drawall();
|
garbeam@75
|
132 }
|
garbeam@75
|
133
|
garbeam@76
|
134 Client *
|
garbeam@93
|
135 getnext(Client *c, unsigned int t)
|
garbeam@75
|
136 {
|
garbeam@93
|
137 for(; c && !c->tags[t]; c = c->next);
|
garbeam@76
|
138 return c;
|
garbeam@75
|
139 }
|
garbeam@75
|
140
|
garbeam@75
|
141 void
|
garbeam@93
|
142 heretag(Arg *arg)
|
garbeam@93
|
143 {
|
garbeam@93
|
144 int i;
|
garbeam@93
|
145 Client *c;
|
garbeam@93
|
146
|
garbeam@93
|
147 if(arg->i == tsel)
|
garbeam@93
|
148 return;
|
garbeam@93
|
149
|
garbeam@93
|
150 if(!(c = getnext(clients, arg->i)))
|
garbeam@93
|
151 return;
|
garbeam@93
|
152
|
garbeam@93
|
153 for(i = 0; i < TLast; i++)
|
garbeam@93
|
154 c->tags[i] = NULL;
|
garbeam@93
|
155 c->tags[tsel] = tags[tsel];
|
garbeam@94
|
156 pop(c);
|
garbeam@93
|
157 focus(c);
|
garbeam@93
|
158 }
|
garbeam@93
|
159
|
garbeam@93
|
160 void
|
garbeam@75
|
161 replacetag(Arg *arg)
|
garbeam@75
|
162 {
|
garbeam@75
|
163 int i;
|
arg@123
|
164
|
garbeam@75
|
165 if(!sel)
|
garbeam@75
|
166 return;
|
garbeam@75
|
167
|
garbeam@75
|
168 for(i = 0; i < TLast; i++)
|
garbeam@75
|
169 sel->tags[i] = NULL;
|
garbeam@75
|
170 appendtag(arg);
|
garbeam@75
|
171 }
|
garbeam@75
|
172
|
garbeam@76
|
173 void
|
garbeam@76
|
174 settags(Client *c)
|
garbeam@76
|
175 {
|
arg@114
|
176 char classinst[256];
|
garbeam@76
|
177 static unsigned int len = rule ? sizeof(rule) / sizeof(rule[0]) : 0;
|
garbeam@76
|
178 unsigned int i, j;
|
arg@114
|
179 regex_t regex;
|
arg@114
|
180 regmatch_t tmp;
|
garbeam@76
|
181 Bool matched = False;
|
arg@114
|
182 XClassHint ch;
|
garbeam@76
|
183
|
garbeam@76
|
184 if(!len) {
|
garbeam@76
|
185 c->tags[tsel] = tags[tsel];
|
garbeam@76
|
186 return;
|
garbeam@76
|
187 }
|
garbeam@76
|
188
|
garbeam@76
|
189 if(XGetClassHint(dpy, c->win, &ch)) {
|
arg@114
|
190 snprintf(classinst, sizeof(classinst), "%s:%s",
|
arg@114
|
191 ch.res_class ? ch.res_class : "",
|
arg@114
|
192 ch.res_name ? ch.res_name : "");
|
arg@114
|
193 for(i = 0; !matched && i < len; i++) {
|
arg@114
|
194 if(!regcomp(®ex, rule[i].pattern, 0)) {
|
arg@114
|
195 if(!regexec(®ex, classinst, 1, &tmp, 0)) {
|
arg@114
|
196 for(j = 0; j < TLast; j++) {
|
arg@114
|
197 if(rule[i].tags[j])
|
arg@114
|
198 matched = True;
|
garbeam@76
|
199 c->tags[j] = rule[i].tags[j];
|
arg@114
|
200 }
|
garbeam@80
|
201 c->isfloat = rule[i].isfloat;
|
garbeam@76
|
202 }
|
arg@114
|
203 regfree(®ex);
|
arg@114
|
204 }
|
garbeam@76
|
205 }
|
garbeam@76
|
206 if(ch.res_class)
|
garbeam@76
|
207 XFree(ch.res_class);
|
garbeam@76
|
208 if(ch.res_name)
|
garbeam@76
|
209 XFree(ch.res_name);
|
garbeam@76
|
210 }
|
garbeam@76
|
211 if(!matched)
|
garbeam@76
|
212 c->tags[tsel] = tags[tsel];
|
garbeam@76
|
213 }
|
garbeam@76
|
214
|
garbeam@76
|
215 void
|
arg@124
|
216 togglemode(Arg *arg)
|
arg@124
|
217 {
|
arg@124
|
218 arrange = arrange == dofloat ? dotile : dofloat;
|
arg@124
|
219 arrange(NULL);
|
arg@124
|
220 }
|
arg@124
|
221
|
arg@124
|
222 void
|
garbeam@76
|
223 view(Arg *arg)
|
garbeam@76
|
224 {
|
garbeam@76
|
225 tsel = arg->i;
|
garbeam@76
|
226 arrange(NULL);
|
garbeam@76
|
227 drawall();
|
garbeam@76
|
228 }
|