dwm-meillo

view tag.c @ 345:977585eb2d35

found less intrusive way
author Anselm R. Garbe <arg@10kloc.org>
date Thu, 24 Aug 2006 09:41:41 +0200
parents ae0affabdc02
children fc279cd6c7be
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"
6 #include <regex.h>
7 #include <stdio.h>
8 #include <stdlib.h>
9 #include <string.h>
10 #include <sys/types.h>
11 #include <X11/Xutil.h>
14 typedef struct {
15 const char *clpattern;
16 const char *tpattern;
17 Bool isfloat;
18 } Rule;
20 typedef struct {
21 regex_t *clregex;
22 regex_t *tregex;
23 } RReg;
25 /* static */
27 TAGS
28 RULES
30 static RReg *rreg = NULL;
31 static unsigned int len = 0;
33 /* extern */
35 Client *
36 getnext(Client *c)
37 {
38 for(; c && !isvisible(c); c = c->next);
39 return c;
40 }
42 Client *
43 getprev(Client *c)
44 {
45 for(; c && !isvisible(c); c = c->prev);
46 return c;
47 }
49 void
50 initrregs()
51 {
52 unsigned int i;
53 regex_t *reg;
55 if(rreg)
56 return;
57 len = sizeof(rule) / sizeof(rule[0]);
58 rreg = emallocz(len * sizeof(RReg));
60 for(i = 0; i < len; i++) {
61 if(rule[i].clpattern) {
62 reg = emallocz(sizeof(regex_t));
63 if(regcomp(reg, rule[i].clpattern, 0))
64 free(reg);
65 else
66 rreg[i].clregex = reg;
67 }
68 if(rule[i].tpattern) {
69 reg = emallocz(sizeof(regex_t));
70 if(regcomp(reg, rule[i].tpattern, 0))
71 free(reg);
72 else
73 rreg[i].tregex = reg;
74 }
75 }
76 }
78 void
79 settags(Client *c)
80 {
81 char prop[512];
82 unsigned int i, j;
83 regmatch_t tmp;
84 Bool matched = False;
85 XClassHint ch;
87 if(XGetClassHint(dpy, c->win, &ch)) {
88 snprintf(prop, sizeof(prop), "%s:%s:%s",
89 ch.res_class ? ch.res_class : "",
90 ch.res_name ? ch.res_name : "", c->name);
91 for(i = 0; !matched && i < len; i++)
92 if(rreg[i].clregex && !regexec(rreg[i].clregex, prop, 1, &tmp, 0)) {
93 c->isfloat = rule[i].isfloat;
94 for(j = 0; rreg[i].tregex && j < ntags; j++) {
95 if(!regexec(rreg[i].tregex, tags[j], 1, &tmp, 0)) {
96 matched = True;
97 c->tags[j] = True;
98 }
99 }
100 }
101 if(ch.res_class)
102 XFree(ch.res_class);
103 if(ch.res_name)
104 XFree(ch.res_name);
105 }
106 if(!matched)
107 for(i = 0; i < ntags; i++)
108 c->tags[i] = seltag[i];
109 }
111 void
112 tag(Arg *arg)
113 {
114 unsigned int i;
116 if(!sel)
117 return;
119 for(i = 0; i < ntags; i++)
120 sel->tags[i] = False;
121 sel->tags[arg->i] = True;
122 settitle(sel);
123 if(!isvisible(sel))
124 arrange(NULL);
125 else
126 drawstatus();
127 }
129 void
130 toggletag(Arg *arg)
131 {
132 unsigned int i;
134 if(!sel)
135 return;
137 sel->tags[arg->i] = !sel->tags[arg->i];
138 for(i = 0; i < ntags && !sel->tags[i]; i++);
139 if(i == ntags)
140 sel->tags[arg->i] = True;
141 settitle(sel);
142 if(!isvisible(sel))
143 arrange(NULL);
144 else
145 drawstatus();
146 }