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
;
271 resize(Client
*c
, Bool inc
)
277 c
->w
-= (c
->w
- c
->basew
) % c
->incw
;
279 c
->h
-= (c
->h
- c
->baseh
) % c
->inch
;
281 if(c
->x
> sw
) /* might happen on restart */
284 c
->ty
= c
->y
= sh
- c
->h
;
285 if(c
->minw
&& c
->w
< c
->minw
)
287 if(c
->minh
&& c
->h
< c
->minh
)
289 if(c
->maxw
&& c
->w
> c
->maxw
)
291 if(c
->maxh
&& c
->h
> c
->maxh
)
294 XSetWindowBorderWidth(dpy
, c
->win
, 1);
295 XMoveResizeWindow(dpy
, c
->win
, c
->x
, c
->y
, c
->w
, c
->h
);
296 e
.type
= ConfigureNotify
;
303 e
.border_width
= c
->border
;
305 e
.override_redirect
= False
;
306 XSendEvent(dpy
, c
->win
, False
, StructureNotifyMask
, (XEvent
*)&e
);
315 if(!XGetWMNormalHints(dpy
, c
->win
, &size
, &msize
) || !size
.flags
)
317 c
->flags
= size
.flags
;
318 if(c
->flags
& PBaseSize
) {
319 c
->basew
= size
.base_width
;
320 c
->baseh
= size
.base_height
;
323 c
->basew
= c
->baseh
= 0;
324 if(c
->flags
& PResizeInc
) {
325 c
->incw
= size
.width_inc
;
326 c
->inch
= size
.height_inc
;
329 c
->incw
= c
->inch
= 0;
330 if(c
->flags
& PMaxSize
) {
331 c
->maxw
= size
.max_width
;
332 c
->maxh
= size
.max_height
;
335 c
->maxw
= c
->maxh
= 0;
336 if(c
->flags
& PMinSize
) {
337 c
->minw
= size
.min_width
;
338 c
->minh
= size
.min_height
;
341 c
->minw
= c
->minh
= 0;
342 if(c
->flags
& PWinGravity
)
343 c
->grav
= size
.win_gravity
;
345 c
->grav
= NorthWestGravity
;
357 XGetTextProperty(dpy
, c
->win
, &name
, netatom
[NetWMName
]);
359 XGetWMName(dpy
, c
->win
, &name
);
362 if(name
.encoding
== XA_STRING
)
363 strncpy(c
->name
, (char *)name
.value
, sizeof(c
->name
));
365 if(XmbTextPropertyToTextList(dpy
, &name
, &list
, &n
) >= Success
368 strncpy(c
->name
, *list
, sizeof(c
->name
));
369 XFreeStringList(list
);
382 XSetErrorHandler(xerrordummy
);
384 XUngrabButton(dpy
, AnyButton
, AnyModifier
, c
->win
);
385 XDestroyWindow(dpy
, c
->title
);
387 for(l
= &clients
; *l
&& *l
!= c
; l
= &(*l
)->next
);
389 for(l
= &clients
; *l
; l
= &(*l
)->next
)
390 if((*l
)->revert
== c
)
393 sel
= sel
->revert
? sel
->revert
: clients
;
398 XSetErrorHandler(xerror
);
413 if(sel
== getnext(clients
, tsel
) && sel
->next
) {
414 if((c
= getnext(sel
->next
, tsel
)))
418 for(l
= &clients
; *l
&& *l
!= sel
; l
= &(*l
)->next
);
421 sel
->next
= clients
; /* pop */