comparison tag.c @ 76:4bd49f404f10

proceeded with cleaning up, sorting functions, etc
author Anselm R. Garbe <garbeam@wmii.de>
date Sat, 15 Jul 2006 17:00:56 +0200
parents f08271b7cb20
children 8125f908c80c
comparison
equal deleted inserted replaced
75:f08271b7cb20 76:4bd49f404f10
1 /* 1 /*
2 * (C)opyright MMVI Anselm R. Garbe <garbeam at gmail dot com> 2 * (C)opyright MMVI Anselm R. Garbe <garbeam at gmail dot com>
3 * See LICENSE file for license details. 3 * See LICENSE file for license details.
4 */ 4 */
5 #include "dwm.h"
5 6
6 #include <stdlib.h>
7 #include <stdio.h>
8 #include <string.h> 7 #include <string.h>
9 #include <X11/Xatom.h>
10 #include <X11/Xutil.h> 8 #include <X11/Xutil.h>
11 9
12 #include "dwm.h" 10 /********** CUSTOMIZE **********/
11
12 char *tags[TLast] = {
13 [Tscratch] = "scratch",
14 [Tdev] = "dev",
15 [Twww] = "www",
16 [Twork] = "work",
17 };
13 18
14 static Rule rule[] = { 19 static Rule rule[] = {
15 /* class instance tags dofloat */ 20 /* class instance tags dofloat */
16 { "Firefox-bin", "Gecko", { [Twww] = "www" }, False }, 21 { "Firefox-bin", "Gecko", { [Twww] = "www" }, False },
17 }; 22 };
18 23
24 /********** CUSTOMIZE **********/
25
26 /* extern functions */
27
19 void (*arrange)(Arg *) = dotile; 28 void (*arrange)(Arg *) = dotile;
20 29
21 Client * 30 void
22 getnext(Client *c) 31 appendtag(Arg *arg)
23 { 32 {
24 for(; c && !c->tags[tsel]; c = c->next); 33 if(!sel)
25 return c; 34 return;
26 }
27 35
28 void 36 sel->tags[arg->i] = tags[arg->i];
29 settags(Client *c)
30 {
31 XClassHint ch;
32 static unsigned int len = rule ? sizeof(rule) / sizeof(rule[0]) : 0;
33 unsigned int i, j;
34 Bool matched = False;
35
36 if(!len) {
37 c->tags[tsel] = tags[tsel];
38 return;
39 }
40
41 if(XGetClassHint(dpy, c->win, &ch)) {
42 if(ch.res_class && ch.res_name) {
43 for(i = 0; i < len; i++)
44 if(!strncmp(rule[i].class, ch.res_class, sizeof(rule[i].class))
45 && !strncmp(rule[i].instance, ch.res_name, sizeof(rule[i].instance)))
46 {
47 for(j = 0; j < TLast; j++)
48 c->tags[j] = rule[i].tags[j];
49 c->dofloat = rule[i].dofloat;
50 matched = True;
51 break;
52 }
53 }
54 if(ch.res_class)
55 XFree(ch.res_class);
56 if(ch.res_name)
57 XFree(ch.res_name);
58 }
59
60 if(!matched)
61 c->tags[tsel] = tags[tsel];
62 }
63
64 void
65 view(Arg *arg)
66 {
67 tsel = arg->i;
68 arrange(NULL); 37 arrange(NULL);
69 drawall();
70 } 38 }
71 39
72 void 40 void
73 dofloat(Arg *arg) 41 dofloat(Arg *arg)
74 { 42 {
145 } 113 }
146 } 114 }
147 drawall(); 115 drawall();
148 } 116 }
149 117
150 void 118 Client *
151 appendtag(Arg *arg) 119 getnext(Client *c)
152 { 120 {
153 if(!sel) 121 for(; c && !c->tags[tsel]; c = c->next);
154 return; 122 return c;
155
156 sel->tags[arg->i] = tags[arg->i];
157 arrange(NULL);
158 } 123 }
159 124
160 void 125 void
161 replacetag(Arg *arg) 126 replacetag(Arg *arg)
162 { 127 {
167 for(i = 0; i < TLast; i++) 132 for(i = 0; i < TLast; i++)
168 sel->tags[i] = NULL; 133 sel->tags[i] = NULL;
169 appendtag(arg); 134 appendtag(arg);
170 } 135 }
171 136
137 void
138 settags(Client *c)
139 {
140 XClassHint ch;
141 static unsigned int len = rule ? sizeof(rule) / sizeof(rule[0]) : 0;
142 unsigned int i, j;
143 Bool matched = False;
144
145 if(!len) {
146 c->tags[tsel] = tags[tsel];
147 return;
148 }
149
150 if(XGetClassHint(dpy, c->win, &ch)) {
151 if(ch.res_class && ch.res_name) {
152 for(i = 0; i < len; i++)
153 if(!strncmp(rule[i].class, ch.res_class, sizeof(rule[i].class))
154 && !strncmp(rule[i].instance, ch.res_name, sizeof(rule[i].instance)))
155 {
156 for(j = 0; j < TLast; j++)
157 c->tags[j] = rule[i].tags[j];
158 c->dofloat = rule[i].dofloat;
159 matched = True;
160 break;
161 }
162 }
163 if(ch.res_class)
164 XFree(ch.res_class);
165 if(ch.res_name)
166 XFree(ch.res_name);
167 }
168
169 if(!matched)
170 c->tags[tsel] = tags[tsel];
171 }
172
173 void
174 view(Arg *arg)
175 {
176 tsel = arg->i;
177 arrange(NULL);
178 drawall();
179 }