Xinqi Bao's Git
1 /* © 2006-2007 Anselm R. Garbe <garbeam at gmail dot com>
2 * © 2006-2007 Sander van Dijk <a dot h dot vandijk at gmail dot com>
3 * © 2006-2007 Jukka Salmi <jukka at salmi dot ch>
4 * © 2007 Premysl Hruby <dfenze at gmail dot com>
5 * © 2007 Szabolcs Nagy <nszabolcs at gmail dot com>
6 * See LICENSE file for license details. */
11 #include <X11/Xutil.h>
29 static Regs
*regs
= NULL
;
30 static unsigned int nrules
= 0;
41 nrules
= sizeof rule
/ sizeof rule
[0];
42 regs
= emallocz(nrules
* sizeof(Regs
));
43 for(i
= 0; i
< nrules
; i
++) {
45 reg
= emallocz(sizeof(regex_t
));
46 if(regcomp(reg
, rule
[i
].prop
, REG_EXTENDED
))
49 regs
[i
].propregex
= reg
;
52 reg
= emallocz(sizeof(regex_t
));
53 if(regcomp(reg
, rule
[i
].tags
, REG_EXTENDED
))
56 regs
[i
].tagregex
= reg
;
62 isvisible(Client
*c
) {
65 for(i
= 0; i
< ntags
; i
++)
66 if(c
->tags
[i
] && seltag
[i
])
72 settags(Client
*c
, Client
*trans
) {
76 Bool matched
= trans
!= NULL
;
77 XClassHint ch
= { 0 };
80 for(i
= 0; i
< ntags
; i
++)
81 c
->tags
[i
] = trans
->tags
[i
];
83 XGetClassHint(dpy
, c
->win
, &ch
);
84 snprintf(prop
, sizeof prop
, "%s:%s:%s",
85 ch
.res_class
? ch
.res_class
: "",
86 ch
.res_name
? ch
.res_name
: "", c
->name
);
87 for(i
= 0; i
< nrules
; i
++)
88 if(regs
[i
].propregex
&& !regexec(regs
[i
].propregex
, prop
, 1, &tmp
, 0)) {
89 c
->isfloating
= rule
[i
].isfloating
;
90 for(j
= 0; regs
[i
].tagregex
&& j
< ntags
; j
++) {
91 if(!regexec(regs
[i
].tagregex
, tags
[j
], 1, &tmp
, 0)) {
103 for(i
= 0; i
< ntags
; i
++)
104 c
->tags
[i
] = seltag
[i
];
108 tag(const char *arg
) {
113 for(i
= 0; i
< ntags
; i
++)
114 sel
->tags
[i
] = arg
== NULL
;
115 i
= arg
? atoi(arg
) : 0;
116 if(i
>= 0 && i
< ntags
)
122 toggletag(const char *arg
) {
127 i
= arg
? atoi(arg
) : 0;
128 sel
->tags
[i
] = !sel
->tags
[i
];
129 for(j
= 0; j
< ntags
&& !sel
->tags
[j
]; j
++);
136 toggleview(const char *arg
) {
139 i
= arg
? atoi(arg
) : 0;
140 seltag
[i
] = !seltag
[i
];
141 for(j
= 0; j
< ntags
&& !seltag
[j
]; j
++);
143 seltag
[i
] = True
; /* cannot toggle last view */
148 view(const char *arg
) {
151 for(i
= 0; i
< ntags
; i
++)
152 seltag
[i
] = arg
== NULL
;
153 i
= arg
? atoi(arg
) : 0;
154 if(i
>= 0 && i
< ntags
)