Xinqi Bao's Git
1 /* See LICENSE file for copyright and license details. */
26 static Regs
*regs
= NULL
;
27 static unsigned int nrules
= 0;
28 static char prop
[512];
31 persisttags(Client
*c
)
35 for(i
= 0; i
< ntags
&& i
< sizeof prop
- 1; i
++)
36 prop
[i
] = c
->tags
[i
] ? '+' : '-';
38 XChangeProperty(dpy
, c
->win
, dwmtags
, XA_STRING
, 8,
39 PropModeReplace
, (unsigned char *)prop
, i
);
51 nrules
= sizeof rule
/ sizeof rule
[0];
52 regs
= emallocz(nrules
* sizeof(Regs
));
53 for(i
= 0; i
< nrules
; i
++) {
55 reg
= emallocz(sizeof(regex_t
));
56 if(regcomp(reg
, rule
[i
].prop
, REG_EXTENDED
))
59 regs
[i
].propregex
= reg
;
62 reg
= emallocz(sizeof(regex_t
));
63 if(regcomp(reg
, rule
[i
].tags
, REG_EXTENDED
))
66 regs
[i
].tagregex
= reg
;
72 isvisible(Client
*c
) {
75 for(i
= 0; i
< ntags
; i
++)
76 if(c
->tags
[i
] && seltag
[i
])
82 settags(Client
*c
, Client
*trans
) {
85 Bool matched
= trans
!= NULL
;
86 XClassHint ch
= { 0 };
90 for(i
= 0; i
< ntags
; i
++)
91 c
->tags
[i
] = trans
->tags
[i
];
94 /* check if window has set a property */
96 XGetTextProperty(dpy
, c
->win
, &name
, dwmtags
);
97 if(name
.nitems
&& name
.encoding
== XA_STRING
) {
98 strncpy(prop
, (char *)name
.value
, sizeof prop
- 1);
99 prop
[sizeof prop
- 1] = '\0';
101 for(i
= 0; i
< ntags
&& i
< sizeof prop
- 1 && prop
[i
] != '\0'; i
++)
102 if((c
->tags
[i
] = prop
[i
] == '+'))
108 XGetClassHint(dpy
, c
->win
, &ch
);
109 snprintf(prop
, sizeof prop
, "%s:%s:%s",
110 ch
.res_class
? ch
.res_class
: "",
111 ch
.res_name
? ch
.res_name
: "", c
->name
);
112 for(i
= 0; i
< nrules
; i
++)
113 if(regs
[i
].propregex
&& !regexec(regs
[i
].propregex
, prop
, 1, &tmp
, 0)) {
114 c
->isfloating
= rule
[i
].isfloating
;
115 for(j
= 0; regs
[i
].tagregex
&& j
< ntags
; j
++) {
116 if(!regexec(regs
[i
].tagregex
, tags
[j
], 1, &tmp
, 0)) {
128 for(i
= 0; i
< ntags
; i
++)
129 c
->tags
[i
] = seltag
[i
];
134 tag(const char *arg
) {
139 for(i
= 0; i
< ntags
; i
++)
140 sel
->tags
[i
] = arg
== NULL
;
141 i
= arg
? atoi(arg
) : 0;
142 if(i
>= 0 && i
< ntags
)
150 toggletag(const char *arg
) {
155 i
= arg
? atoi(arg
) : 0;
156 sel
->tags
[i
] = !sel
->tags
[i
];
157 for(j
= 0; j
< ntags
&& !sel
->tags
[j
]; j
++);
166 toggleview(const char *arg
) {
169 i
= arg
? atoi(arg
) : 0;
170 seltag
[i
] = !seltag
[i
];
171 for(j
= 0; j
< ntags
&& !seltag
[j
]; j
++);
173 seltag
[i
] = True
; /* cannot toggle last view */
178 view(const char *arg
) {
181 for(i
= 0; i
< ntags
; i
++)
182 seltag
[i
] = arg
== NULL
;
183 i
= arg
? atoi(arg
) : 0;
184 if(i
>= 0 && i
< ntags
)