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>
12 /* static functions */
15 resizetitle(Client
*c
)
20 for(i
= 0; i
< TLast
; i
++)
22 c
->tw
+= textw(c
->tags
[i
]);
23 c
->tw
+= textw(c
->name
);
26 c
->tx
= c
->x
+ c
->w
- c
->tw
+ 2;
28 XMoveResizeWindow(dpy
, c
->title
, c
->tx
, c
->ty
, c
->tw
, c
->th
);
32 xerrordummy(Display
*dsply
, XErrorEvent
*ee
)
37 /* extern functions */
42 XMoveWindow(dpy
, c
->win
, c
->x
+ 2 * sw
, c
->y
);
43 XMoveWindow(dpy
, c
->title
, c
->tx
+ 2 * sw
, c
->ty
);
56 XSetInputFocus(dpy
, c
->win
, RevertToPointerRoot
, CurrentTime
);
58 while(XCheckMaskEvent(dpy
, EnterWindowMask
, &ev
));
69 if(!(c
= getnext(sel
->next
, tsel
)))
70 c
= getnext(clients
, tsel
);
86 if((c
= sel
->revert
&& sel
->revert
->tags
[tsel
] ? sel
->revert
: NULL
)) {
96 for(c
= clients
; c
; c
= c
->next
)
106 for(c
= clients
; c
; c
= c
->next
)
113 gravitate(Client
*c
, Bool invert
)
119 case NorthWestGravity
:
121 case NorthEastGravity
:
127 dy
= -(c
->h
/ 2) + c
->border
;
129 case SouthEastGravity
:
131 case SouthWestGravity
:
140 case NorthWestGravity
:
142 case SouthWestGravity
:
148 dx
= -(c
->w
/ 2) + c
->border
;
150 case NorthEastGravity
:
152 case SouthEastGravity
:
153 dx
= -(c
->w
+ c
->border
);
170 XRaiseWindow(dpy
, c
->win
);
171 XRaiseWindow(dpy
, c
->title
);
179 if(sel
->proto
& WM_PROTOCOL_DELWIN
)
180 sendevent(sel
->win
, wmatom
[WMProtocols
], wmatom
[WMDelete
]);
182 XKillClient(dpy
, sel
->win
);
188 XLowerWindow(dpy
, c
->title
);
189 XLowerWindow(dpy
, c
->win
);
193 manage(Window w
, XWindowAttributes
*wa
)
196 XSetWindowAttributes twa
;
199 c
= emallocz(sizeof(Client
));
201 c
->tx
= c
->x
= wa
->x
;
202 c
->ty
= c
->y
= wa
->y
;
205 c
->tw
= c
->w
= wa
->width
;
209 c
->proto
= getproto(c
->win
);
211 XSelectInput(dpy
, c
->win
,
212 StructureNotifyMask
| PropertyChangeMask
| EnterWindowMask
);
213 XGetTransientForHint(dpy
, c
->win
, &trans
);
214 twa
.override_redirect
= 1;
215 twa
.background_pixmap
= ParentRelative
;
216 twa
.event_mask
= ExposureMask
;
218 c
->title
= XCreateWindow(dpy
, root
, c
->tx
, c
->ty
, c
->tw
, c
->th
,
219 0, DefaultDepth(dpy
, screen
), CopyFromParent
,
220 DefaultVisual(dpy
, screen
),
221 CWOverrideRedirect
| CWBackPixmap
| CWEventMask
, &twa
);
229 XGrabButton(dpy
, Button1
, ControlMask
, c
->win
, False
, ButtonPressMask
,
230 GrabModeAsync
, GrabModeSync
, None
, None
);
231 XGrabButton(dpy
, Button1
, Mod1Mask
, c
->win
, False
, ButtonPressMask
,
232 GrabModeAsync
, GrabModeSync
, None
, None
);
233 XGrabButton(dpy
, Button2
, Mod1Mask
, c
->win
, False
, ButtonPressMask
,
234 GrabModeAsync
, GrabModeSync
, None
, None
);
235 XGrabButton(dpy
, Button3
, Mod1Mask
, c
->win
, False
, ButtonPressMask
,
236 GrabModeAsync
, GrabModeSync
, None
, None
);
240 || ((c
->maxw
== c
->minw
) && (c
->maxh
== c
->minh
));
243 /* mapping the window now prevents flicker */
245 XMapRaised(dpy
, c
->win
);
246 XMapRaised(dpy
, c
->title
);
251 XMapRaised(dpy
, c
->win
);
252 XMapRaised(dpy
, c
->title
);
264 sel
->w
= sw
- 2 * sel
->border
;
265 sel
->h
= sh
- 2 * sel
->border
- bh
;
274 for(l
= &clients
; *l
&& *l
!= c
; l
= &(*l
)->next
);
277 c
->next
= clients
; /* pop */
283 resize(Client
*c
, Bool inc
)
289 c
->w
-= (c
->w
- c
->basew
) % c
->incw
;
291 c
->h
-= (c
->h
- c
->baseh
) % c
->inch
;
293 if(c
->x
> sw
) /* might happen on restart */
296 c
->ty
= c
->y
= sh
- c
->h
;
297 if(c
->minw
&& c
->w
< c
->minw
)
299 if(c
->minh
&& c
->h
< c
->minh
)
301 if(c
->maxw
&& c
->w
> c
->maxw
)
303 if(c
->maxh
&& c
->h
> c
->maxh
)
306 XSetWindowBorderWidth(dpy
, c
->win
, 1);
307 XMoveResizeWindow(dpy
, c
->win
, c
->x
, c
->y
, c
->w
, c
->h
);
308 e
.type
= ConfigureNotify
;
315 e
.border_width
= c
->border
;
317 e
.override_redirect
= False
;
318 XSendEvent(dpy
, c
->win
, False
, StructureNotifyMask
, (XEvent
*)&e
);
327 if(!XGetWMNormalHints(dpy
, c
->win
, &size
, &msize
) || !size
.flags
)
329 c
->flags
= size
.flags
;
330 if(c
->flags
& PBaseSize
) {
331 c
->basew
= size
.base_width
;
332 c
->baseh
= size
.base_height
;
335 c
->basew
= c
->baseh
= 0;
336 if(c
->flags
& PResizeInc
) {
337 c
->incw
= size
.width_inc
;
338 c
->inch
= size
.height_inc
;
341 c
->incw
= c
->inch
= 0;
342 if(c
->flags
& PMaxSize
) {
343 c
->maxw
= size
.max_width
;
344 c
->maxh
= size
.max_height
;
347 c
->maxw
= c
->maxh
= 0;
348 if(c
->flags
& PMinSize
) {
349 c
->minw
= size
.min_width
;
350 c
->minh
= size
.min_height
;
353 c
->minw
= c
->minh
= 0;
354 if(c
->flags
& PWinGravity
)
355 c
->grav
= size
.win_gravity
;
357 c
->grav
= NorthWestGravity
;
369 XGetTextProperty(dpy
, c
->win
, &name
, netatom
[NetWMName
]);
371 XGetWMName(dpy
, c
->win
, &name
);
374 if(name
.encoding
== XA_STRING
)
375 strncpy(c
->name
, (char *)name
.value
, sizeof(c
->name
));
377 if(XmbTextPropertyToTextList(dpy
, &name
, &list
, &n
) >= Success
380 strncpy(c
->name
, *list
, sizeof(c
->name
));
381 XFreeStringList(list
);
394 XSetErrorHandler(xerrordummy
);
396 XUngrabButton(dpy
, AnyButton
, AnyModifier
, c
->win
);
397 XDestroyWindow(dpy
, c
->title
);
399 for(l
= &clients
; *l
&& *l
!= c
; l
= &(*l
)->next
);
401 for(l
= &clients
; *l
; l
= &(*l
)->next
)
402 if((*l
)->revert
== c
)
405 sel
= sel
->revert
? sel
->revert
: clients
;
410 XSetErrorHandler(xerror
);
425 if(sel
== getnext(clients
, tsel
) && sel
->next
) {
426 if((c
= getnext(sel
->next
, tsel
)))