Xinqi Bao's Git
3f186e65575046bd7174fda3f84cf31d82d373fb
1 /* (C)opyright MMVI-MMVII Anselm R. Garbe <garbeam at gmail dot com>
2 * See LICENSE file for license details.
10 #include <X11/Xutil.h>
12 unsigned int master
= MASTER
;
13 unsigned int nmaster
= NMASTER
;
34 static Regs
*regs
= NULL
;
35 static unsigned int nrules
= 0;
36 static unsigned int nlayouts
= 0;
47 nrules
= sizeof rule
/ sizeof rule
[0];
48 regs
= emallocz(nrules
* sizeof(Regs
));
49 for(i
= 0; i
< nrules
; i
++) {
51 reg
= emallocz(sizeof(regex_t
));
52 if(regcomp(reg
, rule
[i
].prop
, REG_EXTENDED
))
55 regs
[i
].propregex
= reg
;
58 reg
= emallocz(sizeof(regex_t
));
59 if(regcomp(reg
, rule
[i
].tags
, REG_EXTENDED
))
62 regs
[i
].tagregex
= reg
;
71 for(c
= clients
; c
; c
= c
->next
) {
74 XMoveWindow(dpy
, c
->win
, c
->x
, c
->y
);
76 resize(c
, c
->x
, c
->y
, c
->w
, c
->h
, True
);
80 XMoveWindow(dpy
, c
->win
, c
->x
+ 2 * sw
, c
->y
);
83 if(!sel
|| !isvisible(sel
)) {
84 for(c
= stack
; c
&& !isvisible(c
); c
= c
->snext
);
92 unsigned int i
, n
, nx
, ny
, nw
, nh
, mw
, mh
, tw
, th
;
95 for(n
= 0, c
= nexttiled(clients
); c
; c
= nexttiled(c
->next
))
98 mh
= (n
> nmaster
) ? wah
/ nmaster
: wah
/ (n
> 0 ? n
: 1);
99 mw
= (n
> nmaster
) ? (waw
* master
) / 1000 : waw
;
100 th
= (n
> nmaster
) ? wah
/ (n
- nmaster
) : 0;
103 for(i
= 0, c
= clients
; c
; c
= c
->next
)
106 XMoveWindow(dpy
, c
->win
, c
->x
, c
->y
);
115 nw
= mw
- 2 * BORDERPX
;
116 nh
= mh
- 2 * BORDERPX
;
118 else { /* tile window */
120 nw
= tw
- 2 * BORDERPX
;
121 if(th
> 2 * BORDERPX
) {
122 ny
+= (i
- nmaster
) * th
;
123 nh
= th
- 2 * BORDERPX
;
125 else /* fallback if th <= 2 * BORDERPX */
126 nh
= wah
- 2 * BORDERPX
;
128 resize(c
, nx
, ny
, nw
, nh
, False
);
133 XMoveWindow(dpy
, c
->win
, c
->x
+ 2 * sw
, c
->y
);
135 if(!sel
|| !isvisible(sel
)) {
136 for(c
= stack
; c
&& !isvisible(c
); c
= c
->snext
);
143 incnmaster(Arg
*arg
) {
144 if((lt
->arrange
== dofloat
) || (nmaster
+ arg
->i
< 1)
145 || (wah
/ (nmaster
+ arg
->i
) <= 2 * BORDERPX
))
159 nlayouts
= sizeof layout
/ sizeof layout
[0];
160 for(blw
= i
= 0; i
< nlayouts
; i
++) {
161 w
= textw(layout
[i
].symbol
);
168 isvisible(Client
*c
) {
171 for(i
= 0; i
< ntags
; i
++)
172 if(c
->tags
[i
] && seltag
[i
])
178 resizemaster(Arg
*arg
) {
179 if(lt
->arrange
!= dotile
)
184 if(waw
* (master
+ arg
->i
) / 1000 >= waw
- 2 * BORDERPX
185 || waw
* (master
+ arg
->i
) / 1000 <= 2 * BORDERPX
)
200 if(sel
->isfloat
|| lt
->arrange
== dofloat
)
201 XRaiseWindow(dpy
, sel
->win
);
202 if(lt
->arrange
!= dofloat
) {
204 XLowerWindow(dpy
, sel
->win
);
205 for(c
= nexttiled(clients
); c
; c
= nexttiled(c
->next
)) {
208 XLowerWindow(dpy
, c
->win
);
212 while(XCheckMaskEvent(dpy
, EnterWindowMask
, &ev
));
216 settags(Client
*c
, Client
*trans
) {
220 Bool matched
= trans
!= NULL
;
221 XClassHint ch
= { 0 };
224 for(i
= 0; i
< ntags
; i
++)
225 c
->tags
[i
] = trans
->tags
[i
];
227 XGetClassHint(dpy
, c
->win
, &ch
);
228 snprintf(prop
, sizeof prop
, "%s:%s:%s",
229 ch
.res_class
? ch
.res_class
: "",
230 ch
.res_name
? ch
.res_name
: "", c
->name
);
231 for(i
= 0; i
< nrules
; i
++)
232 if(regs
[i
].propregex
&& !regexec(regs
[i
].propregex
, prop
, 1, &tmp
, 0)) {
233 c
->isfloat
= rule
[i
].isfloat
;
234 for(j
= 0; regs
[i
].tagregex
&& j
< ntags
; j
++) {
235 if(!regexec(regs
[i
].tagregex
, tags
[j
], 1, &tmp
, 0)) {
247 for(i
= 0; i
< ntags
; i
++)
248 c
->tags
[i
] = seltag
[i
];
257 for(i
= 0; i
< ntags
; i
++)
258 sel
->tags
[i
] = (arg
->i
== -1) ? True
: False
;
259 if(arg
->i
>= 0 && arg
->i
< ntags
)
260 sel
->tags
[arg
->i
] = True
;
265 togglefloat(Arg
*arg
) {
266 if(!sel
|| lt
->arrange
== dofloat
)
268 sel
->isfloat
= !sel
->isfloat
;
273 toggletag(Arg
*arg
) {
278 sel
->tags
[arg
->i
] = !sel
->tags
[arg
->i
];
279 for(i
= 0; i
< ntags
&& !sel
->tags
[i
]; i
++);
281 sel
->tags
[arg
->i
] = True
;
286 togglelayout(Arg
*arg
) {
289 for(i
= 0; i
< nlayouts
&& lt
!= &layout
[i
]; i
++);
290 if(i
== nlayouts
- 1)
301 toggleview(Arg
*arg
) {
304 seltag
[arg
->i
] = !seltag
[arg
->i
];
305 for(i
= 0; i
< ntags
&& !seltag
[i
]; i
++);
307 seltag
[arg
->i
] = True
; /* cannot toggle last view */
315 for(i
= 0; i
< ntags
; i
++)
316 seltag
[i
] = (arg
->i
== -1) ? True
: False
;
317 if(arg
->i
>= 0 && arg
->i
< ntags
)
318 seltag
[arg
->i
] = True
;