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 persistconfig(Client
*c
) {
34 for(i
= 0; i
< ntags
&& i
< sizeof prop
- 1; i
++)
35 prop
[i
] = c
->tags
[i
] ? '1' : '0';
36 if(i
< sizeof prop
- 1)
37 prop
[i
++] = c
->isfloating
? '1' : '0';
39 XChangeProperty(dpy
, c
->win
, dwmconfig
, XA_STRING
, 8,
40 PropModeReplace
, (unsigned char *)prop
, i
);
52 nrules
= sizeof rule
/ sizeof rule
[0];
53 regs
= emallocz(nrules
* sizeof(Regs
));
54 for(i
= 0; i
< nrules
; i
++) {
56 reg
= emallocz(sizeof(regex_t
));
57 if(regcomp(reg
, rule
[i
].prop
, REG_EXTENDED
))
60 regs
[i
].propregex
= reg
;
63 reg
= emallocz(sizeof(regex_t
));
64 if(regcomp(reg
, rule
[i
].tags
, REG_EXTENDED
))
67 regs
[i
].tagregex
= reg
;
73 isvisible(Client
*c
) {
76 for(i
= 0; i
< ntags
; i
++)
77 if(c
->tags
[i
] && seltag
[i
])
83 settags(Client
*c
, Client
*trans
) {
86 Bool matched
= trans
!= NULL
;
87 XClassHint ch
= { 0 };
91 for(i
= 0; i
< ntags
; i
++)
92 c
->tags
[i
] = trans
->tags
[i
];
95 /* check if window has set a property */
97 XGetTextProperty(dpy
, c
->win
, &name
, dwmconfig
);
98 if(name
.nitems
&& name
.encoding
== XA_STRING
) {
99 strncpy(prop
, (char *)name
.value
, sizeof prop
- 1);
100 prop
[sizeof prop
- 1] = '\0';
102 for(i
= 0; i
< ntags
&& i
< sizeof prop
- 1 && prop
[i
] != '\0'; i
++)
103 if((c
->tags
[i
] = prop
[i
] == '1'))
105 if(i
< sizeof prop
- 1 && prop
[i
] != '\0')
106 c
->isfloating
= prop
[i
] == '1';
111 XGetClassHint(dpy
, c
->win
, &ch
);
112 snprintf(prop
, sizeof prop
, "%s:%s:%s",
113 ch
.res_class
? ch
.res_class
: "",
114 ch
.res_name
? ch
.res_name
: "", c
->name
);
115 for(i
= 0; i
< nrules
; i
++)
116 if(regs
[i
].propregex
&& !regexec(regs
[i
].propregex
, prop
, 1, &tmp
, 0)) {
117 c
->isfloating
= rule
[i
].isfloating
;
118 for(j
= 0; regs
[i
].tagregex
&& j
< ntags
; j
++) {
119 if(!regexec(regs
[i
].tagregex
, tags
[j
], 1, &tmp
, 0)) {
131 for(i
= 0; i
< ntags
; i
++)
132 c
->tags
[i
] = seltag
[i
];
137 tag(const char *arg
) {
142 for(i
= 0; i
< ntags
; i
++)
143 sel
->tags
[i
] = arg
== NULL
;
144 i
= arg
? atoi(arg
) : 0;
145 if(i
>= 0 && i
< ntags
)
153 togglefloating(const char *arg
) {
154 if(!sel
|| isfloating())
156 sel
->isfloating
= !sel
->isfloating
;
158 resize(sel
, sel
->x
, sel
->y
, sel
->w
, sel
->h
, True
);
163 toggletag(const char *arg
) {
168 i
= arg
? atoi(arg
) : 0;
169 sel
->tags
[i
] = !sel
->tags
[i
];
170 for(j
= 0; j
< ntags
&& !sel
->tags
[j
]; j
++);
179 toggleview(const char *arg
) {
182 i
= arg
? atoi(arg
) : 0;
183 seltag
[i
] = !seltag
[i
];
184 for(j
= 0; j
< ntags
&& !seltag
[j
]; j
++);
186 seltag
[i
] = True
; /* cannot toggle last view */
191 view(const char *arg
) {
194 for(i
= 0; i
< ntags
; i
++)
195 seltag
[i
] = arg
== NULL
;
196 i
= arg
? atoi(arg
) : 0;
197 if(i
>= 0 && i
< ntags
)