Xinqi Bao's Git
fb366bed028579cc3de2e3518b670dc907d5643d
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 * See LICENSE file for license details. */
27 static Regs
*regs
= NULL
;
28 static unsigned int nrules
= 0;
39 nrules
= sizeof rule
/ sizeof rule
[0];
40 regs
= emallocz(nrules
* sizeof(Regs
));
41 for(i
= 0; i
< nrules
; i
++) {
43 reg
= emallocz(sizeof(regex_t
));
44 if(regcomp(reg
, rule
[i
].prop
, REG_EXTENDED
))
47 regs
[i
].propregex
= reg
;
50 reg
= emallocz(sizeof(regex_t
));
51 if(regcomp(reg
, rule
[i
].tags
, REG_EXTENDED
))
54 regs
[i
].tagregex
= reg
;
60 isvisible(Client
*c
) {
63 for(i
= 0; i
< ntags
; i
++)
64 if(c
->tags
[i
] && seltag
[i
])
70 settags(Client
*c
, Client
*trans
) {
74 Bool matched
= trans
!= NULL
;
75 XClassHint ch
= { 0 };
78 for(i
= 0; i
< ntags
; i
++)
79 c
->tags
[i
] = trans
->tags
[i
];
81 XGetClassHint(dpy
, c
->win
, &ch
);
82 snprintf(prop
, sizeof prop
, "%s:%s:%s",
83 ch
.res_class
? ch
.res_class
: "",
84 ch
.res_name
? ch
.res_name
: "", c
->name
);
85 for(i
= 0; i
< nrules
; i
++)
86 if(regs
[i
].propregex
&& !regexec(regs
[i
].propregex
, prop
, 1, &tmp
, 0)) {
87 c
->isfloating
= rule
[i
].isfloating
;
88 for(j
= 0; regs
[i
].tagregex
&& j
< ntags
; j
++) {
89 if(!regexec(regs
[i
].tagregex
, tags
[j
], 1, &tmp
, 0)) {
101 for(i
= 0; i
< ntags
; i
++)
102 c
->tags
[i
] = seltag
[i
];
106 tag(const char *arg
) {
111 for(i
= 0; i
< ntags
; i
++)
112 sel
->tags
[i
] = arg
== NULL
;
113 i
= arg
? atoi(arg
) : 0;
114 if(i
>= 0 && i
< ntags
)
120 toggletag(const char *arg
) {
125 i
= arg
? atoi(arg
) : 0;
126 sel
->tags
[i
] = !sel
->tags
[i
];
127 for(j
= 0; j
< ntags
&& !sel
->tags
[j
]; j
++);
134 toggleview(const char *arg
) {
137 i
= arg
? atoi(arg
) : 0;
138 seltag
[i
] = !seltag
[i
];
139 for(j
= 0; j
< ntags
&& !seltag
[j
]; j
++);
141 seltag
[i
] = True
; /* cannot toggle last view */
146 view(const char *arg
) {
149 for(i
= 0; i
< ntags
; i
++)
150 seltag
[i
] = arg
== NULL
;
151 i
= arg
? atoi(arg
) : 0;
152 if(i
>= 0 && i
< ntags
)