Xinqi Bao's Git
1 /* See LICENSE file for copyright and license details. */
24 static Regs
*regs
= NULL
;
25 static unsigned int nrules
= 0;
36 nrules
= sizeof rule
/ sizeof rule
[0];
37 regs
= emallocz(nrules
* sizeof(Regs
));
38 for(i
= 0; i
< nrules
; i
++) {
40 reg
= emallocz(sizeof(regex_t
));
41 if(regcomp(reg
, rule
[i
].prop
, REG_EXTENDED
))
44 regs
[i
].propregex
= reg
;
47 reg
= emallocz(sizeof(regex_t
));
48 if(regcomp(reg
, rule
[i
].tags
, REG_EXTENDED
))
51 regs
[i
].tagregex
= reg
;
57 isvisible(Client
*c
) {
60 for(i
= 0; i
< ntags
; i
++)
61 if(c
->tags
[i
] && seltag
[i
])
67 settags(Client
*c
, Client
*trans
) {
71 Bool matched
= trans
!= NULL
;
72 XClassHint ch
= { 0 };
75 for(i
= 0; i
< ntags
; i
++)
76 c
->tags
[i
] = trans
->tags
[i
];
78 XGetClassHint(dpy
, c
->win
, &ch
);
79 snprintf(prop
, sizeof prop
, "%s:%s:%s",
80 ch
.res_class
? ch
.res_class
: "",
81 ch
.res_name
? ch
.res_name
: "", c
->name
);
82 for(i
= 0; i
< nrules
; i
++)
83 if(regs
[i
].propregex
&& !regexec(regs
[i
].propregex
, prop
, 1, &tmp
, 0)) {
84 c
->isfloating
= rule
[i
].isfloating
;
85 for(j
= 0; regs
[i
].tagregex
&& j
< ntags
; j
++) {
86 if(!regexec(regs
[i
].tagregex
, tags
[j
], 1, &tmp
, 0)) {
98 for(i
= 0; i
< ntags
; i
++)
99 c
->tags
[i
] = seltag
[i
];
103 shiftview(const char *arg
) {
106 for(i
= 0; !seltag
[i
]; i
++);
107 for(j
= i
+ 1; j
< ntags
&& !seltag
[j
]; j
++);
109 return; /* more than one tag selected */
111 i
+= arg
? atoi(arg
) : 0;
121 tag(const char *arg
) {
126 for(i
= 0; i
< ntags
; i
++)
127 sel
->tags
[i
] = arg
== NULL
;
128 i
= arg
? atoi(arg
) : 0;
129 if(i
>= 0 && i
< ntags
)
135 toggletag(const char *arg
) {
140 i
= arg
? atoi(arg
) : 0;
141 sel
->tags
[i
] = !sel
->tags
[i
];
142 for(j
= 0; j
< ntags
&& !sel
->tags
[j
]; j
++);
149 toggleview(const char *arg
) {
152 i
= arg
? atoi(arg
) : 0;
153 seltag
[i
] = !seltag
[i
];
154 for(j
= 0; j
< ntags
&& !seltag
[j
]; j
++);
156 seltag
[i
] = True
; /* cannot toggle last view */
161 view(const char *arg
) {
164 for(i
= 0; i
< ntags
; i
++)
165 seltag
[i
] = arg
== NULL
;
166 i
= arg
? atoi(arg
) : 0;
167 if(i
>= 0 && i
< ntags
)