Xinqi Bao's Git
1 /* See LICENSE file for copyright and license details. */
13 void (*arrange
)(void);
30 static unsigned int nrules
= 0;
31 static unsigned int nlayouts
= 0;
32 static unsigned int ltidx
= 0; /* default */
33 static Regs
*regs
= NULL
;
36 idxoftag(const char *tag
) {
39 for(i
= 0; i
< ntags
; i
++)
46 floating(void) { /* default floating layout */
49 for(c
= clients
; c
; c
= c
->next
)
51 resize(c
, c
->x
, c
->y
, c
->w
, c
->h
, True
);
61 applyrules(Client
*c
) {
66 XClassHint ch
= { 0 };
69 XGetClassHint(dpy
, c
->win
, &ch
);
70 snprintf(buf
, sizeof buf
, "%s:%s:%s",
71 ch
.res_class
? ch
.res_class
: "",
72 ch
.res_name
? ch
.res_name
: "", c
->name
);
73 for(i
= 0; i
< nrules
; i
++)
74 if(regs
[i
].propregex
&& !regexec(regs
[i
].propregex
, buf
, 1, &tmp
, 0)) {
75 c
->isfloating
= rules
[i
].isfloating
;
76 for(j
= 0; regs
[i
].tagregex
&& j
< ntags
; j
++) {
77 if(!regexec(regs
[i
].tagregex
, tags
[j
], 1, &tmp
, 0)) {
88 for(i
= 0; i
< ntags
; i
++)
89 c
->tags
[i
] = seltags
[i
];
96 for(c
= clients
; c
; c
= c
->next
)
101 layouts
[ltidx
].arrange();
113 nrules
= sizeof rules
/ sizeof rules
[0];
114 regs
= emallocz(nrules
* sizeof(Regs
));
115 for(i
= 0; i
< nrules
; i
++) {
117 reg
= emallocz(sizeof(regex_t
));
118 if(regcomp(reg
, rules
[i
].prop
, REG_EXTENDED
))
121 regs
[i
].propregex
= reg
;
124 reg
= emallocz(sizeof(regex_t
));
125 if(regcomp(reg
, rules
[i
].tags
, REG_EXTENDED
))
128 regs
[i
].tagregex
= reg
;
134 focusnext(const char *arg
) {
139 for(c
= sel
->next
; c
&& !isvisible(c
); c
= c
->next
);
141 for(c
= clients
; c
&& !isvisible(c
); c
= c
->next
);
149 focusprev(const char *arg
) {
154 for(c
= sel
->prev
; c
&& !isvisible(c
); c
= c
->prev
);
156 for(c
= clients
; c
&& c
->next
; c
= c
->next
);
157 for(; c
&& !isvisible(c
); c
= c
->prev
);
168 return layouts
[ltidx
].symbol
;
175 nlayouts
= sizeof layouts
/ sizeof layouts
[0];
176 for(blw
= i
= 0; i
< nlayouts
; i
++) {
177 w
= textw(layouts
[i
].symbol
);
185 return layouts
[ltidx
].arrange
== floating
;
189 isarrange(void (*func
)())
191 return func
== layouts
[ltidx
].arrange
;
195 isvisible(Client
*c
) {
198 for(i
= 0; i
< ntags
; i
++)
199 if(c
->tags
[i
] && seltags
[i
])
205 nexttiled(Client
*c
) {
206 for(; c
&& (c
->isfloating
|| !isvisible(c
)); c
= c
->next
);
219 if(sel
->isfloating
|| isfloating())
220 XRaiseWindow(dpy
, sel
->win
);
222 wc
.stack_mode
= Below
;
224 if(!sel
->isfloating
) {
225 XConfigureWindow(dpy
, sel
->win
, CWSibling
| CWStackMode
, &wc
);
226 wc
.sibling
= sel
->win
;
228 for(c
= nexttiled(clients
); c
; c
= nexttiled(c
->next
)) {
231 XConfigureWindow(dpy
, c
->win
, CWSibling
| CWStackMode
, &wc
);
236 while(XCheckMaskEvent(dpy
, EnterWindowMask
, &ev
));
240 setlayout(const char *arg
) {
244 if(++ltidx
== nlayouts
)
248 for(i
= 0; i
< nlayouts
; i
++)
249 if(!strcmp(arg
, layouts
[i
].symbol
))
262 tag(const char *arg
) {
267 for(i
= 0; i
< ntags
; i
++)
268 sel
->tags
[i
] = arg
== NULL
;
270 if(i
>= 0 && i
< ntags
)
276 togglebar(const char *arg
) {
278 bpos
= (BARPOS
== BarOff
) ? BarTop
: BARPOS
;
286 togglefloating(const char *arg
) {
289 sel
->isfloating
= !sel
->isfloating
;
291 resize(sel
, sel
->x
, sel
->y
, sel
->w
, sel
->h
, True
);
296 togglemax(const char *arg
) {
299 if(!sel
|| (!isfloating() && !sel
->isfloating
) || sel
->isfixed
)
301 if((sel
->ismax
= !sel
->ismax
)) {
306 resize(sel
, wax
, way
, waw
- 2 * sel
->border
, wah
- 2 * sel
->border
, True
);
309 resize(sel
, sel
->rx
, sel
->ry
, sel
->rw
, sel
->rh
, True
);
311 while(XCheckMaskEvent(dpy
, EnterWindowMask
, &ev
));
315 toggletag(const char *arg
) {
321 sel
->tags
[i
] = !sel
->tags
[i
];
322 for(j
= 0; j
< ntags
&& !sel
->tags
[j
]; j
++);
329 toggleview(const char *arg
) {
333 seltags
[i
] = !seltags
[i
];
334 for(j
= 0; j
< ntags
&& !seltags
[j
]; j
++);
336 seltags
[i
] = True
; /* cannot toggle last view */
352 XMoveWindow(dpy
, barwin
, sx
, sy
);
356 XMoveWindow(dpy
, barwin
, sx
, sy
+ wah
);
359 XMoveWindow(dpy
, barwin
, sx
, sy
- bh
);
363 while(XCheckMaskEvent(dpy
, EnterWindowMask
, &ev
));
367 view(const char *arg
) {
370 for(i
= 0; i
< ntags
; i
++)
371 seltags
[i
] = arg
== NULL
;
373 if(i
>= 0 && i
< ntags
)