Xinqi Bao's Git
2 * (C)opyright MMVI Anselm R. Garbe <garbeam at gmail dot com>
3 * See LICENSE file for license details.
10 #include <X11/Xutil.h>
14 void (*arrange
)(Arg
*) = tiling
;
16 static Rule rule
[] = {
17 /* class instance tags floating */
18 { "Firefox-bin", "Gecko", { [Twww
] = "www" }, False
},
24 for(; c
&& !c
->tags
[tsel
]; c
= c
->next
);
36 if(sel
== next(clients
))
37 sel
= next(sel
->next
);
39 for(l
= &clients
; *l
&& *l
!= sel
; l
= &(*l
)->next
);
42 sel
->next
= clients
; /* pop */
55 sel
->w
= sw
- 2 * sel
->border
;
56 sel
->h
= sh
- 2 * sel
->border
- bh
;
69 for(c
= clients
; c
; c
= next(c
->next
))
80 sel
->tags
[arg
->i
] = tags
[arg
->i
];
91 for(i
= 0; i
< TLast
; i
++)
99 XMoveWindow(dpy
, c
->win
, c
->x
+ 2 * sw
, c
->y
);
100 XMoveWindow(dpy
, c
->title
, c
->tx
+ 2 * sw
, c
->ty
);
109 for(c
= clients
; c
; c
= c
->next
) {
115 if(sel
&& !sel
->tags
[tsel
]) {
116 if((sel
= next(clients
))) {
131 for(n
= 0, c
= clients
; c
; c
= c
->next
)
132 if(c
->tags
[tsel
] && !c
->floating
)
136 h
= (sh
- bh
) / (n
- 1);
140 for(i
= 0, c
= clients
; c
; c
= c
->next
) {
150 c
->w
= sw
- 2 * c
->border
;
151 c
->h
= sh
- 2 * c
->border
- bh
;
156 c
->w
= mw
- 2 * c
->border
;
157 c
->h
= sh
- 2 * c
->border
- bh
;
161 c
->y
= sy
+ (i
- 1) * h
+ bh
;
162 c
->w
= w
- 2 * c
->border
;
163 c
->h
= h
- 2 * c
->border
;
171 if(!sel
|| (sel
&& !sel
->tags
[tsel
])) {
172 if((sel
= next(clients
))) {
187 if((c
= sel
->revert
&& sel
->revert
->tags
[tsel
] ? sel
->revert
: NULL
)) {
201 if(!(c
= next(sel
->next
)))
215 if(sel
->proto
& WM_PROTOCOL_DELWIN
)
216 send_message(sel
->win
, wm_atom
[WMProtocols
], wm_atom
[WMDelete
]);
218 XKillClient(dpy
, sel
->win
);
222 resize_title(Client
*c
)
227 for(i
= 0; i
< TLast
; i
++)
229 c
->tw
+= textw(c
->tags
[i
]) + dc
.font
.height
;
230 c
->tw
+= textw(c
->name
) + dc
.font
.height
;
233 c
->tx
= c
->x
+ c
->w
- c
->tw
+ 2;
235 XMoveResizeWindow(dpy
, c
->title
, c
->tx
, c
->ty
, c
->tw
, c
->th
);
239 update_name(Client
*c
)
247 XGetTextProperty(dpy
, c
->win
, &name
, net_atom
[NetWMName
]);
249 XGetWMName(dpy
, c
->win
, &name
);
252 if(name
.encoding
== XA_STRING
)
253 strncpy(c
->name
, (char *)name
.value
, sizeof(c
->name
));
255 if(XmbTextPropertyToTextList(dpy
, &name
, &list
, &n
) >= Success
258 strncpy(c
->name
, *list
, sizeof(c
->name
));
259 XFreeStringList(list
);
267 update_size(Client
*c
)
271 if(!XGetWMNormalHints(dpy
, c
->win
, &size
, &msize
) || !size
.flags
)
273 c
->flags
= size
.flags
;
274 if(c
->flags
& PBaseSize
) {
275 c
->basew
= size
.base_width
;
276 c
->baseh
= size
.base_height
;
279 c
->basew
= c
->baseh
= 0;
280 if(c
->flags
& PResizeInc
) {
281 c
->incw
= size
.width_inc
;
282 c
->inch
= size
.height_inc
;
285 c
->incw
= c
->inch
= 0;
286 if(c
->flags
& PMaxSize
) {
287 c
->maxw
= size
.max_width
;
288 c
->maxh
= size
.max_height
;
291 c
->maxw
= c
->maxh
= 0;
292 if(c
->flags
& PMinSize
) {
293 c
->minw
= size
.min_width
;
294 c
->minh
= size
.min_height
;
297 c
->minw
= c
->minh
= 0;
298 if(c
->flags
& PWinGravity
)
299 c
->grav
= size
.win_gravity
;
301 c
->grav
= NorthWestGravity
;
307 XRaiseWindow(dpy
, c
->win
);
308 XRaiseWindow(dpy
, c
->title
);
314 XLowerWindow(dpy
, c
->title
);
315 XLowerWindow(dpy
, c
->win
);
329 XSetInputFocus(dpy
, c
->win
, RevertToPointerRoot
, CurrentTime
);
331 while(XCheckMaskEvent(dpy
, EnterWindowMask
, &ev
));
338 static unsigned int len
= rule
? sizeof(rule
) / sizeof(rule
[0]) : 0;
340 Bool matched
= False
;
343 c
->tags
[tsel
] = tags
[tsel
];
347 if(XGetClassHint(dpy
, c
->win
, &ch
)) {
348 if(ch
.res_class
&& ch
.res_name
) {
349 for(i
= 0; i
< len
; i
++)
350 if(!strncmp(rule
[i
].class, ch
.res_class
, sizeof(rule
[i
].class))
351 && !strncmp(rule
[i
].instance
, ch
.res_name
, sizeof(rule
[i
].instance
)))
353 for(j
= 0; j
< TLast
; j
++)
354 c
->tags
[j
] = rule
[i
].tags
[j
];
355 c
->floating
= rule
[i
].floating
;
367 c
->tags
[tsel
] = tags
[tsel
];
371 manage(Window w
, XWindowAttributes
*wa
)
374 XSetWindowAttributes twa
;
377 c
= emallocz(sizeof(Client
));
379 c
->tx
= c
->x
= wa
->x
;
380 c
->ty
= c
->y
= wa
->y
;
383 c
->tw
= c
->w
= wa
->width
;
387 c
->proto
= win_proto(c
->win
);
389 XSelectInput(dpy
, c
->win
,
390 StructureNotifyMask
| PropertyChangeMask
| EnterWindowMask
);
391 XGetTransientForHint(dpy
, c
->win
, &trans
);
392 twa
.override_redirect
= 1;
393 twa
.background_pixmap
= ParentRelative
;
394 twa
.event_mask
= ExposureMask
;
396 c
->title
= XCreateWindow(dpy
, root
, c
->tx
, c
->ty
, c
->tw
, c
->th
,
397 0, DefaultDepth(dpy
, screen
), CopyFromParent
,
398 DefaultVisual(dpy
, screen
),
399 CWOverrideRedirect
| CWBackPixmap
| CWEventMask
, &twa
);
404 for(l
= &clients
; *l
; l
= &(*l
)->next
);
405 c
->next
= *l
; /* *l == nil */
408 XGrabButton(dpy
, Button1
, Mod1Mask
, c
->win
, False
, ButtonPressMask
,
409 GrabModeAsync
, GrabModeSync
, None
, None
);
410 XGrabButton(dpy
, Button2
, Mod1Mask
, c
->win
, False
, ButtonPressMask
,
411 GrabModeAsync
, GrabModeSync
, None
, None
);
412 XGrabButton(dpy
, Button3
, Mod1Mask
, c
->win
, False
, ButtonPressMask
,
413 GrabModeAsync
, GrabModeSync
, None
, None
);
417 || ((c
->maxw
== c
->minw
) && (c
->maxh
== c
->minh
));
420 /* mapping the window now prevents flicker */
422 XMapRaised(dpy
, c
->win
);
423 XMapRaised(dpy
, c
->title
);
428 XMapRaised(dpy
, c
->win
);
429 XMapRaised(dpy
, c
->title
);
434 gravitate(Client
*c
, Bool invert
)
440 case NorthWestGravity
:
442 case NorthEastGravity
:
448 dy
= -(c
->h
/ 2) + c
->border
;
450 case SouthEastGravity
:
452 case SouthWestGravity
:
461 case NorthWestGravity
:
463 case SouthWestGravity
:
469 dx
= -(c
->w
/ 2) + c
->border
;
471 case NorthEastGravity
:
473 case SouthEastGravity
:
474 dx
= -(c
->w
+ c
->border
);
490 resize(Client
*c
, Bool inc
)
496 c
->w
-= (c
->w
- c
->basew
) % c
->incw
;
498 c
->h
-= (c
->h
- c
->baseh
) % c
->inch
;
500 if(c
->minw
&& c
->w
< c
->minw
)
502 if(c
->minh
&& c
->h
< c
->minh
)
504 if(c
->maxw
&& c
->w
> c
->maxw
)
506 if(c
->maxh
&& c
->h
> c
->maxh
)
509 XSetWindowBorderWidth(dpy
, c
->win
, 1);
510 XMoveResizeWindow(dpy
, c
->win
, c
->x
, c
->y
, c
->w
, c
->h
);
511 e
.type
= ConfigureNotify
;
518 e
.border_width
= c
->border
;
520 e
.override_redirect
= False
;
521 XSendEvent(dpy
, c
->win
, False
, StructureNotifyMask
, (XEvent
*)&e
);
526 dummy_error_handler(Display
*dsply
, XErrorEvent
*err
)
537 XSetErrorHandler(dummy_error_handler
);
539 XUngrabButton(dpy
, AnyButton
, AnyModifier
, c
->win
);
540 XDestroyWindow(dpy
, c
->title
);
542 for(l
= &clients
; *l
&& *l
!= c
; l
= &(*l
)->next
);
544 for(l
= &clients
; *l
; l
= &(*l
)->next
)
545 if((*l
)->revert
== c
)
548 sel
= sel
->revert
? sel
->revert
: clients
;
553 XSetErrorHandler(error_handler
);
564 for(c
= clients
; c
; c
= c
->next
)
574 for(c
= clients
; c
; c
= c
->next
)
581 draw_client(Client
*c
)
586 XUnmapWindow(dpy
, c
->title
);
587 XSetWindowBorder(dpy
, c
->win
, dc
.fg
);
591 XSetWindowBorder(dpy
, c
->win
, dc
.bg
);
592 XMapWindow(dpy
, c
->title
);
597 for(i
= 0; i
< TLast
; i
++) {
600 dc
.w
= textw(c
->tags
[i
]) + dc
.font
.height
;
601 drawtext(c
->tags
[i
], True
);
605 dc
.w
= textw(c
->name
) + dc
.font
.height
;
606 drawtext(c
->name
, True
);
607 XCopyArea(dpy
, dc
.drawable
, c
->title
, dc
.gc
,
608 0, 0, c
->tw
, c
->th
, 0, 0);