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 * © 2007 Premysl Hruby <dfenze at gmail dot com>
4 * © 2007 Szabolcs Nagy <nszabolcs at gmail dot com>
5 * See LICENSE file for license details. */
10 #include <X11/Xutil.h>
28 static Regs
*regs
= NULL
;
29 static unsigned int nrules
= 0;
40 nrules
= sizeof rule
/ sizeof rule
[0];
41 regs
= emallocz(nrules
* sizeof(Regs
));
42 for(i
= 0; i
< nrules
; i
++) {
44 reg
= emallocz(sizeof(regex_t
));
45 if(regcomp(reg
, rule
[i
].prop
, REG_EXTENDED
))
48 regs
[i
].propregex
= reg
;
51 reg
= emallocz(sizeof(regex_t
));
52 if(regcomp(reg
, rule
[i
].tags
, REG_EXTENDED
))
55 regs
[i
].tagregex
= reg
;
61 isvisible(Client
*c
) {
64 for(i
= 0; i
< ntags
; i
++)
65 if(c
->tags
[i
] && seltag
[i
])
71 settags(Client
*c
, Client
*trans
) {
75 Bool matched
= trans
!= NULL
;
76 XClassHint ch
= { 0 };
79 for(i
= 0; i
< ntags
; i
++)
80 c
->tags
[i
] = trans
->tags
[i
];
82 XGetClassHint(dpy
, c
->win
, &ch
);
83 snprintf(prop
, sizeof prop
, "%s:%s:%s",
84 ch
.res_class
? ch
.res_class
: "",
85 ch
.res_name
? ch
.res_name
: "", c
->name
);
86 for(i
= 0; i
< nrules
; i
++)
87 if(regs
[i
].propregex
&& !regexec(regs
[i
].propregex
, prop
, 1, &tmp
, 0)) {
88 c
->isfloating
= rule
[i
].isfloating
;
89 for(j
= 0; regs
[i
].tagregex
&& j
< ntags
; j
++) {
90 if(!regexec(regs
[i
].tagregex
, tags
[j
], 1, &tmp
, 0)) {
102 for(i
= 0; i
< ntags
; i
++)
103 c
->tags
[i
] = seltag
[i
];
107 tag(const char *arg
) {
112 for(i
= 0; i
< ntags
; i
++)
113 sel
->tags
[i
] = arg
== NULL
;
114 i
= arg
? atoi(arg
) : 0;
115 if(i
>= 0 && i
< ntags
)
121 toggletag(const char *arg
) {
126 i
= arg
? atoi(arg
) : 0;
127 sel
->tags
[i
] = !sel
->tags
[i
];
128 for(j
= 0; j
< ntags
&& !sel
->tags
[j
]; j
++);
135 toggleview(const char *arg
) {
138 i
= arg
? atoi(arg
) : 0;
139 seltag
[i
] = !seltag
[i
];
140 for(j
= 0; j
< ntags
&& !seltag
[j
]; j
++);
142 seltag
[i
] = True
; /* cannot toggle last view */
147 view(const char *arg
) {
150 for(i
= 0; i
< ntags
; i
++)
151 seltag
[i
] = arg
== NULL
;
152 i
= arg
? atoi(arg
) : 0;
153 if(i
>= 0 && i
< ntags
)