Xinqi Bao's Git
b5bebea241478dfee1cb17216e10678a8a3e0486
2 * (C)opyright MMVI Anselm R. Garbe <garbeam at gmail dot com>
3 * See LICENSE file for license details.
10 #include <sys/types.h>
11 #include <X11/Xutil.h>
15 const char *clpattern
;
30 static RReg
*rreg
= NULL
;
31 static unsigned int len
= 0;
33 void (*arrange
)(Arg
*) = DEFMODE
;
45 c
->tags
[arg
->i
] = True
;
56 for(c
= clients
; c
; c
= c
->next
) {
59 resize(c
, True
, TopLeft
);
64 if((sel
= getnext(clients
))) {
69 XSetInputFocus(dpy
, root
, RevertToPointerRoot
, CurrentTime
);
79 for(n
= 0, c
= clients
; c
; c
= c
->next
)
80 if(isvisible(c
) && !c
->isfloat
)
84 h
= (sh
- bh
) / (n
- 1);
88 for(i
= 0, c
= clients
; c
; c
= c
->next
) {
92 resize(c
, True
, TopLeft
);
109 c
->y
= sy
+ (i
- 1) * h
+ bh
;
112 c
->h
= sh
- c
->y
- 2;
116 else { /* fallback if h < bh */
122 resize(c
, False
, TopLeft
);
128 if((sel
= getnext(clients
)))
131 XSetInputFocus(dpy
, root
, RevertToPointerRoot
, CurrentTime
);
138 for(; c
&& !isvisible(c
); c
= c
->next
);
145 for(; c
&& !isvisible(c
); c
= c
->prev
);
157 len
= sizeof(rule
) / sizeof(rule
[0]);
158 rreg
= emallocz(len
* sizeof(RReg
));
160 for(i
= 0; i
< len
; i
++) {
161 if(rule
[i
].clpattern
) {
162 reg
= emallocz(sizeof(regex_t
));
163 if(regcomp(reg
, rule
[i
].clpattern
, 0))
166 rreg
[i
].clregex
= reg
;
168 if(rule
[i
].tpattern
) {
169 reg
= emallocz(sizeof(regex_t
));
170 if(regcomp(reg
, rule
[i
].tpattern
, 0))
173 rreg
[i
].tregex
= reg
;
183 for(i
= 0; i
< ntags
; i
++)
184 if(c
->tags
[i
] && seltag
[i
])
197 for(i
= 0; i
< ntags
; i
++)
198 sel
->tags
[i
] = False
;
205 static unsigned int nwins
= 0;
206 static Window
*wins
= NULL
;
207 unsigned int f
, fi
, m
, mi
, n
;
211 for(f
= 0, m
= 0, c
= clients
; c
; c
= c
->next
)
213 if(c
->isfloat
|| arrange
== dofloat
)
218 if(!(n
= 2 * (f
+ m
))) {
224 wins
= erealloc(wins
, nwins
* sizeof(Window
));
229 if(sel
->isfloat
|| arrange
== dofloat
) {
230 wins
[fi
++] = sel
->title
;
231 wins
[fi
++] = sel
->win
;
234 wins
[mi
++] = sel
->title
;
235 wins
[mi
++] = sel
->win
;
237 for(c
= clients
; c
; c
= c
->next
)
238 if(isvisible(c
) && c
!= sel
) {
239 if(c
->isfloat
|| arrange
== dofloat
) {
240 wins
[fi
++] = c
->title
;
244 wins
[mi
++] = c
->title
;
248 XRestackWindows(dpy
, wins
, n
);
251 while(XCheckMaskEvent(dpy
, EnterWindowMask
, &ev
));
260 Bool matched
= False
;
263 if(XGetClassHint(dpy
, c
->win
, &ch
)) {
264 snprintf(classinst
, sizeof(classinst
), "%s:%s",
265 ch
.res_class
? ch
.res_class
: "",
266 ch
.res_name
? ch
.res_name
: "");
267 for(i
= 0; !matched
&& i
< len
; i
++)
268 if(rreg
[i
].clregex
&& !regexec(rreg
[i
].clregex
, classinst
, 1, &tmp
, 0)) {
269 c
->isfloat
= rule
[i
].isfloat
;
270 for(j
= 0; rreg
[i
].tregex
&& j
< ntags
; j
++) {
271 if(!regexec(rreg
[i
].tregex
, tags
[j
], 1, &tmp
, 0)) {
283 for(i
= 0; i
< ntags
; i
++)
284 c
->tags
[i
] = seltag
[i
];
290 arrange
= arrange
== dofloat
? dotile
: dofloat
;
299 for(i
= 0; i
< ntags
; i
++)
301 seltag
[arg
->i
] = True
;
310 seltag
[arg
->i
] = !seltag
[arg
->i
];
311 for(i
= 0; !seltag
[i
] && i
< ntags
; i
++);
313 seltag
[arg
->i
] = True
; /* cannot toggle last view */