Xinqi Bao's Git
1bdebd2e5b06fa2908bf86ad10637366cb8ecb46
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;
29 XMoveResizeWindow(dpy
, c
->title
, c
->tx
, c
->ty
, c
->tw
, c
->th
);
31 XMoveResizeWindow(dpy
, c
->title
, c
->tx
+ 2 * sw
, c
->ty
, c
->tw
, c
->th
);
36 xerrordummy(Display
*dsply
, XErrorEvent
*ee
)
41 /* extern functions */
46 XMoveWindow(dpy
, c
->win
, c
->x
+ 2 * sw
, c
->y
);
47 XMoveWindow(dpy
, c
->title
, c
->tx
+ 2 * sw
, c
->ty
);
60 XSetInputFocus(dpy
, c
->win
, RevertToPointerRoot
, CurrentTime
);
62 while(XCheckMaskEvent(dpy
, EnterWindowMask
, &ev
));
76 if(!(c
= getnext(sel
->next
, tsel
)))
77 c
= getnext(clients
, tsel
);
96 if((c
= sel
->revert
&& sel
->revert
->tags
[tsel
] ? sel
->revert
: NULL
)) {
107 for(c
= clients
; c
; c
= c
->next
)
118 for(c
= clients
; c
; c
= c
->next
)
125 gravitate(Client
*c
, Bool invert
)
131 case NorthWestGravity
:
133 case NorthEastGravity
:
139 dy
= -(c
->h
/ 2) + c
->border
;
141 case SouthEastGravity
:
143 case SouthWestGravity
:
152 case NorthWestGravity
:
154 case SouthWestGravity
:
160 dx
= -(c
->w
/ 2) + c
->border
;
162 case NorthEastGravity
:
164 case SouthEastGravity
:
165 dx
= -(c
->w
+ c
->border
);
182 XRaiseWindow(dpy
, c
->win
);
183 XRaiseWindow(dpy
, c
->title
);
191 if(sel
->proto
& WM_PROTOCOL_DELWIN
)
192 sendevent(sel
->win
, wmatom
[WMProtocols
], wmatom
[WMDelete
]);
194 XKillClient(dpy
, sel
->win
);
200 XLowerWindow(dpy
, c
->title
);
201 XLowerWindow(dpy
, c
->win
);
205 manage(Window w
, XWindowAttributes
*wa
)
210 XSetWindowAttributes twa
;
212 c
= emallocz(sizeof(Client
));
214 c
->x
= c
->tx
= wa
->x
;
215 c
->y
= c
->ty
= wa
->y
;
216 c
->w
= c
->tw
= wa
->width
;
224 c
->proto
= getproto(c
->win
);
226 XSelectInput(dpy
, c
->win
,
227 StructureNotifyMask
| PropertyChangeMask
| EnterWindowMask
);
228 XGetTransientForHint(dpy
, c
->win
, &trans
);
229 twa
.override_redirect
= 1;
230 twa
.background_pixmap
= ParentRelative
;
231 twa
.event_mask
= ExposureMask
;
233 c
->title
= XCreateWindow(dpy
, root
, c
->tx
, c
->ty
, c
->tw
, c
->th
,
234 0, DefaultDepth(dpy
, screen
), CopyFromParent
,
235 DefaultVisual(dpy
, screen
),
236 CWOverrideRedirect
| CWBackPixmap
| CWEventMask
, &twa
);
243 XGrabButton(dpy
, Button1
, MODKEY
, c
->win
, False
, ButtonPressMask
,
244 GrabModeAsync
, GrabModeSync
, None
, None
);
245 XGrabButton(dpy
, Button2
, MODKEY
, c
->win
, False
, ButtonPressMask
,
246 GrabModeAsync
, GrabModeSync
, None
, None
);
247 XGrabButton(dpy
, Button3
, MODKEY
, c
->win
, False
, ButtonPressMask
,
248 GrabModeAsync
, GrabModeSync
, None
, None
);
251 c
->isfloat
= trans
|| (c
->maxw
&& c
->minw
&&
252 (c
->maxw
== c
->minw
) && (c
->maxh
== c
->minh
));
258 /* mapping the window now prevents flicker */
260 XMapRaised(dpy
, c
->win
);
261 XMapRaised(dpy
, c
->title
);
265 XMapRaised(dpy
, c
->win
);
266 XMapRaised(dpy
, c
->title
);
275 for(l
= &clients
; *l
&& *l
!= c
; l
= &(*l
)->next
);
278 c
->next
= clients
; /* pop */
284 resize(Client
*c
, Bool inc
, Corner sticky
)
286 int bottom
= c
->y
+ c
->h
;
287 int right
= c
->x
+ c
->w
;
292 c
->w
-= (c
->w
- c
->basew
) % c
->incw
;
294 c
->h
-= (c
->h
- c
->baseh
) % c
->inch
;
296 if(c
->x
> sw
) /* might happen on restart */
300 if(c
->minw
&& c
->w
< c
->minw
)
302 if(c
->minh
&& c
->h
< c
->minh
)
304 if(c
->maxw
&& c
->w
> c
->maxw
)
306 if(c
->maxh
&& c
->h
> c
->maxh
)
308 if(sticky
== TopRight
|| sticky
== BotRight
)
310 if(sticky
== BotLeft
|| sticky
== BotRight
)
311 c
->y
= bottom
- c
->h
;
314 XSetWindowBorderWidth(dpy
, c
->win
, 1);
315 XMoveResizeWindow(dpy
, c
->win
, c
->x
, c
->y
, c
->w
, c
->h
);
317 e
.type
= ConfigureNotify
;
324 e
.border_width
= c
->border
;
326 e
.override_redirect
= False
;
327 XSendEvent(dpy
, c
->win
, False
, StructureNotifyMask
, (XEvent
*)&e
);
337 if(!XGetWMNormalHints(dpy
, c
->win
, &size
, &msize
) || !size
.flags
)
339 c
->flags
= size
.flags
;
340 if(c
->flags
& PBaseSize
) {
341 c
->basew
= size
.base_width
;
342 c
->baseh
= size
.base_height
;
345 c
->basew
= c
->baseh
= 0;
346 if(c
->flags
& PResizeInc
) {
347 c
->incw
= size
.width_inc
;
348 c
->inch
= size
.height_inc
;
351 c
->incw
= c
->inch
= 0;
352 if(c
->flags
& PMaxSize
) {
353 c
->maxw
= size
.max_width
;
354 c
->maxh
= size
.max_height
;
357 c
->maxw
= c
->maxh
= 0;
358 if(c
->flags
& PMinSize
) {
359 c
->minw
= size
.min_width
;
360 c
->minh
= size
.min_height
;
363 c
->minw
= c
->minh
= 0;
364 if(c
->flags
& PWinGravity
)
365 c
->grav
= size
.win_gravity
;
367 c
->grav
= NorthWestGravity
;
379 XGetTextProperty(dpy
, c
->win
, &name
, netatom
[NetWMName
]);
381 XGetWMName(dpy
, c
->win
, &name
);
384 if(name
.encoding
== XA_STRING
)
385 strncpy(c
->name
, (char *)name
.value
, sizeof(c
->name
));
387 if(XmbTextPropertyToTextList(dpy
, &name
, &list
, &n
) >= Success
390 strncpy(c
->name
, *list
, sizeof(c
->name
));
391 XFreeStringList(list
);
407 if((sel
->ismax
= !sel
->ismax
)) {
414 sel
->w
= sw
- 2 * sel
->border
;
415 sel
->h
= sh
- 2 * sel
->border
- bh
;
418 resize(sel
, False
, TopLeft
);
426 resize(sel
, False
, TopLeft
);
427 while(XCheckMaskEvent(dpy
, EnterWindowMask
, &ev
));
436 XSetErrorHandler(xerrordummy
);
438 XUngrabButton(dpy
, AnyButton
, AnyModifier
, c
->win
);
439 XDestroyWindow(dpy
, c
->title
);
441 for(l
= &clients
; *l
&& *l
!= c
; l
= &(*l
)->next
);
443 for(l
= &clients
; *l
; l
= &(*l
)->next
)
444 if((*l
)->revert
== c
)
447 sel
= sel
->revert
? sel
->revert
: clients
;
452 XSetErrorHandler(xerror
);
467 if(sel
== getnext(clients
, tsel
) && sel
->next
) {
468 if((c
= getnext(sel
->next
, tsel
)))