Xinqi Bao's Git
c4d3b345b27b80f5dcb8bd7c66d3be2104c6229d
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
;
43 sel
->tags
[arg
->i
] = True
;
52 for(c
= clients
; c
; c
= c
->next
) {
55 resize(c
, True
, TopLeft
);
60 if((sel
= getnext(clients
))) {
65 XSetInputFocus(dpy
, root
, RevertToPointerRoot
, CurrentTime
);
75 for(n
= 0, c
= clients
; c
; c
= c
->next
)
76 if(isvisible(c
) && !c
->isfloat
)
80 h
= (sh
- bh
) / (n
- 1);
84 for(i
= 0, c
= clients
; c
; c
= c
->next
) {
88 resize(c
, True
, TopLeft
);
105 c
->y
= sy
+ (i
- 1) * h
+ bh
;
108 c
->h
= sh
- c
->y
- 2;
112 else { /* fallback if h < bh */
118 resize(c
, False
, TopLeft
);
124 if((sel
= getnext(clients
)))
127 XSetInputFocus(dpy
, root
, RevertToPointerRoot
, CurrentTime
);
134 for(; c
&& !isvisible(c
); c
= c
->next
);
141 for(; c
&& !isvisible(c
); c
= c
->prev
);
153 len
= sizeof(rule
) / sizeof(rule
[0]);
154 rreg
= emallocz(len
* sizeof(RReg
));
156 for(i
= 0; i
< len
; i
++) {
157 if(rule
[i
].clpattern
) {
158 reg
= emallocz(sizeof(regex_t
));
159 if(regcomp(reg
, rule
[i
].clpattern
, 0))
162 rreg
[i
].clregex
= reg
;
164 if(rule
[i
].tpattern
) {
165 reg
= emallocz(sizeof(regex_t
));
166 if(regcomp(reg
, rule
[i
].tpattern
, 0))
169 rreg
[i
].tregex
= reg
;
179 for(i
= 0; i
< ntags
; i
++)
180 if(c
->tags
[i
] && seltag
[i
])
193 for(i
= 0; i
< ntags
; i
++)
194 sel
->tags
[i
] = False
;
201 static unsigned int nwins
= 0;
202 static Window
*wins
= NULL
;
203 unsigned int f
, fi
, m
, mi
, n
;
207 for(f
= 0, m
= 0, c
= clients
; c
; c
= c
->next
)
209 if(c
->isfloat
|| arrange
== dofloat
)
214 if(!(n
= 2 * (f
+ m
))) {
220 wins
= erealloc(wins
, nwins
* sizeof(Window
));
225 if(sel
->isfloat
|| arrange
== dofloat
) {
226 wins
[fi
++] = sel
->title
;
227 wins
[fi
++] = sel
->win
;
230 wins
[mi
++] = sel
->title
;
231 wins
[mi
++] = sel
->win
;
233 for(c
= clients
; c
; c
= c
->next
)
234 if(isvisible(c
) && c
!= sel
) {
235 if(c
->isfloat
|| arrange
== dofloat
) {
236 wins
[fi
++] = c
->title
;
240 wins
[mi
++] = c
->title
;
244 XRestackWindows(dpy
, wins
, n
);
247 while(XCheckMaskEvent(dpy
, EnterWindowMask
, &ev
));
256 Bool matched
= False
;
259 if(XGetClassHint(dpy
, c
->win
, &ch
)) {
260 snprintf(classinst
, sizeof(classinst
), "%s:%s",
261 ch
.res_class
? ch
.res_class
: "",
262 ch
.res_name
? ch
.res_name
: "");
263 for(i
= 0; !matched
&& i
< len
; i
++)
264 if(rreg
[i
].clregex
&& !regexec(rreg
[i
].clregex
, classinst
, 1, &tmp
, 0)) {
265 c
->isfloat
= rule
[i
].isfloat
;
266 for(j
= 0; rreg
[i
].tregex
&& j
< ntags
; j
++) {
267 if(!regexec(rreg
[i
].tregex
, tags
[j
], 1, &tmp
, 0)) {
279 for(i
= 0; i
< ntags
; i
++)
280 c
->tags
[i
] = seltag
[i
];
286 arrange
= arrange
== dofloat
? dotile
: dofloat
;
295 for(i
= 0; i
< ntags
; i
++)
297 seltag
[arg
->i
] = True
;
306 seltag
[arg
->i
] = !seltag
[arg
->i
];
307 for(i
= 0; !seltag
[i
] && i
< ntags
; i
++);
309 seltag
[arg
->i
] = True
; /* cannot toggle last view */