aewl

view tag.c @ 751:743061dbe7f2

made Mod-F4 (shutdown) work on notebook
author meillo@marmaro.de
date Sat, 16 Jun 2007 21:44:00 +0200
parents 6692d7e7e156
children
line source
1 /* (C)opyright MMVI-MMVII Anselm R. Garbe <garbeam at gmail dot com>
2 * See LICENSE file for license details.
3 */
4 #include "dwm.h"
5 #include <regex.h>
6 #include <stdio.h>
7 #include <stdlib.h>
8 #include <string.h>
9 #include <sys/types.h>
10 #include <X11/Xutil.h>
13 typedef struct {
14 const char *clpattern;
15 const char *tpattern;
16 Bool isfloat;
17 } Rule;
19 typedef struct {
20 regex_t *clregex;
21 regex_t *tregex;
22 } RReg;
24 /* static */
26 TAGS
27 RULES
29 static RReg *rreg = NULL;
30 static unsigned int len = 0;
32 /* extern */
34 Client *
35 getnext(Client *c) {
36 for(; c && !isvisible(c); c = c->next);
37 return c;
38 }
40 Client *
41 getprev(Client *c) {
42 for(; c && !isvisible(c); c = c->prev);
43 return c;
44 }
46 void
47 initrregs(void) {
48 unsigned int i;
49 regex_t *reg;
51 if(rreg)
52 return;
53 len = sizeof rule / sizeof rule[0];
54 rreg = emallocz(len * sizeof(RReg));
55 for(i = 0; i < len; i++) {
56 if(rule[i].clpattern) {
57 reg = emallocz(sizeof(regex_t));
58 if(regcomp(reg, rule[i].clpattern, REG_EXTENDED))
59 free(reg);
60 else
61 rreg[i].clregex = reg;
62 }
63 if(rule[i].tpattern) {
64 reg = emallocz(sizeof(regex_t));
65 if(regcomp(reg, rule[i].tpattern, REG_EXTENDED))
66 free(reg);
67 else
68 rreg[i].tregex = reg;
69 }
70 }
71 }
73 void
74 settags(Client *c, Client *trans) {
75 char prop[512];
76 unsigned int i, j;
77 regmatch_t tmp;
78 Bool matched = trans != NULL;
79 XClassHint ch = { 0 };
81 if(matched) {
82 for(i = 0; i < ntags; i++)
83 c->tags[i] = trans->tags[i];
84 }
85 else {
86 XGetClassHint(dpy, c->win, &ch);
87 snprintf(prop, sizeof prop, "%s:%s:%s",
88 ch.res_class ? ch.res_class : "",
89 ch.res_name ? ch.res_name : "", c->name);
90 for(i = 0; i < len; i++)
91 if(rreg[i].clregex && !regexec(rreg[i].clregex, prop, 1, &tmp, 0)) {
92 c->isfloat = rule[i].isfloat;
93 for(j = 0; rreg[i].tregex && j < ntags; j++) {
94 if(!regexec(rreg[i].tregex, tags[j], 1, &tmp, 0)) {
95 matched = True;
96 c->tags[j] = True;
97 }
98 }
99 break; /* perform only the first rule matching */
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 unsigned int i;
115 if(!sel)
116 return;
117 for(i = 0; i < ntags; i++)
118 sel->tags[i] = (arg->i == -1) ? True : False;
119 if(arg->i >= 0 && arg->i < ntags)
120 sel->tags[arg->i] = True;
121 arrange();
122 }
124 void
125 toggletag(Arg *arg) {
126 unsigned int i;
128 if(!sel)
129 return;
130 sel->tags[arg->i] = !sel->tags[arg->i];
131 for(i = 0; i < ntags && !sel->tags[i]; i++);
132 if(i == ntags)
133 sel->tags[arg->i] = True;
134 arrange();
135 }
137 /* begin code by jukka */
138 void
139 viewnext(Arg *arg) {
140 unsigned int i;
141 Bool last = seltag[ntags-1];
143 for (i=ntags-1; i>0; --i)
144 seltag[i] = seltag[i-1];
145 seltag[0] = last;
146 arrange();
147 }
148 /* end code by jukka */