Xinqi Bao's Git
c7979729517a0c46862e21511f39ad7d1a121517
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
));
73 if(!(c
= getnext(sel
->next
, tsel
)))
74 c
= getnext(clients
, tsel
);
90 if((c
= sel
->revert
&& sel
->revert
->tags
[tsel
] ? sel
->revert
: NULL
)) {
100 for(c
= clients
; c
; c
= c
->next
)
110 for(c
= clients
; c
; c
= c
->next
)
117 gravitate(Client
*c
, Bool invert
)
123 case NorthWestGravity
:
125 case NorthEastGravity
:
131 dy
= -(c
->h
/ 2) + c
->border
;
133 case SouthEastGravity
:
135 case SouthWestGravity
:
144 case NorthWestGravity
:
146 case SouthWestGravity
:
152 dx
= -(c
->w
/ 2) + c
->border
;
154 case NorthEastGravity
:
156 case SouthEastGravity
:
157 dx
= -(c
->w
+ c
->border
);
174 XRaiseWindow(dpy
, c
->win
);
175 XRaiseWindow(dpy
, c
->title
);
183 if(sel
->proto
& WM_PROTOCOL_DELWIN
)
184 sendevent(sel
->win
, wmatom
[WMProtocols
], wmatom
[WMDelete
]);
186 XKillClient(dpy
, sel
->win
);
192 XLowerWindow(dpy
, c
->title
);
193 XLowerWindow(dpy
, c
->win
);
197 manage(Window w
, XWindowAttributes
*wa
)
201 XSetWindowAttributes twa
;
204 c
= emallocz(sizeof(Client
));
206 c
->x
= c
->tx
= wa
->x
;
207 c
->y
= c
->ty
= wa
->y
;
208 c
->w
= c
->tw
= wa
->width
;
216 c
->proto
= getproto(c
->win
);
218 XSelectInput(dpy
, c
->win
,
219 StructureNotifyMask
| PropertyChangeMask
| EnterWindowMask
);
220 XGetTransientForHint(dpy
, c
->win
, &trans
);
221 twa
.override_redirect
= 1;
222 twa
.background_pixmap
= ParentRelative
;
223 twa
.event_mask
= ExposureMask
;
225 c
->title
= XCreateWindow(dpy
, root
, c
->tx
, c
->ty
, c
->tw
, c
->th
,
226 0, DefaultDepth(dpy
, screen
), CopyFromParent
,
227 DefaultVisual(dpy
, screen
),
228 CWOverrideRedirect
| CWBackPixmap
| CWEventMask
, &twa
);
235 XGrabButton(dpy
, Button1
, ControlMask
, c
->win
, False
, ButtonPressMask
,
236 GrabModeAsync
, GrabModeSync
, None
, None
);
237 XGrabButton(dpy
, Button1
, MODKEY
, c
->win
, False
, ButtonPressMask
,
238 GrabModeAsync
, GrabModeSync
, None
, None
);
239 XGrabButton(dpy
, Button2
, MODKEY
, c
->win
, False
, ButtonPressMask
,
240 GrabModeAsync
, GrabModeSync
, None
, None
);
241 XGrabButton(dpy
, Button3
, MODKEY
, c
->win
, False
, ButtonPressMask
,
242 GrabModeAsync
, GrabModeSync
, None
, None
);
245 c
->isfloat
= trans
|| (c
->maxw
&& c
->minw
&&
246 (c
->maxw
== c
->minw
) && (c
->maxh
== c
->minh
));
252 /* mapping the window now prevents flicker */
254 XMapRaised(dpy
, c
->win
);
255 XMapRaised(dpy
, c
->title
);
259 XMapRaised(dpy
, c
->win
);
260 XMapRaised(dpy
, c
->title
);
271 sel
->w
= sw
- 2 * sel
->border
;
272 sel
->h
= sh
- 2 * sel
->border
- bh
;
274 resize(sel
, False
, TopLeft
);
281 for(l
= &clients
; *l
&& *l
!= c
; l
= &(*l
)->next
);
284 c
->next
= clients
; /* pop */
290 resize(Client
*c
, Bool inc
, Corner sticky
)
293 int right
= c
->x
+ c
->w
;
294 int bottom
= c
->y
+ c
->h
;
298 c
->w
-= (c
->w
- c
->basew
) % c
->incw
;
300 c
->h
-= (c
->h
- c
->baseh
) % c
->inch
;
302 if(c
->x
> sw
) /* might happen on restart */
306 if(c
->minw
&& c
->w
< c
->minw
)
308 if(c
->minh
&& c
->h
< c
->minh
)
310 if(c
->maxw
&& c
->w
> c
->maxw
)
312 if(c
->maxh
&& c
->h
> c
->maxh
)
314 if(sticky
== TopRight
|| sticky
== BotRight
)
316 if(sticky
== BotLeft
|| sticky
== BotRight
)
317 c
->y
= bottom
- c
->h
;
320 XSetWindowBorderWidth(dpy
, c
->win
, 1);
321 XMoveResizeWindow(dpy
, c
->win
, c
->x
, c
->y
, c
->w
, c
->h
);
323 e
.type
= ConfigureNotify
;
330 e
.border_width
= c
->border
;
332 e
.override_redirect
= False
;
333 XSendEvent(dpy
, c
->win
, False
, StructureNotifyMask
, (XEvent
*)&e
);
342 if(!XGetWMNormalHints(dpy
, c
->win
, &size
, &msize
) || !size
.flags
)
344 c
->flags
= size
.flags
;
345 if(c
->flags
& PBaseSize
) {
346 c
->basew
= size
.base_width
;
347 c
->baseh
= size
.base_height
;
350 c
->basew
= c
->baseh
= 0;
351 if(c
->flags
& PResizeInc
) {
352 c
->incw
= size
.width_inc
;
353 c
->inch
= size
.height_inc
;
356 c
->incw
= c
->inch
= 0;
357 if(c
->flags
& PMaxSize
) {
358 c
->maxw
= size
.max_width
;
359 c
->maxh
= size
.max_height
;
362 c
->maxw
= c
->maxh
= 0;
363 if(c
->flags
& PMinSize
) {
364 c
->minw
= size
.min_width
;
365 c
->minh
= size
.min_height
;
368 c
->minw
= c
->minh
= 0;
369 if(c
->flags
& PWinGravity
)
370 c
->grav
= size
.win_gravity
;
372 c
->grav
= NorthWestGravity
;
384 XGetTextProperty(dpy
, c
->win
, &name
, netatom
[NetWMName
]);
386 XGetWMName(dpy
, c
->win
, &name
);
389 if(name
.encoding
== XA_STRING
)
390 strncpy(c
->name
, (char *)name
.value
, sizeof(c
->name
));
392 if(XmbTextPropertyToTextList(dpy
, &name
, &list
, &n
) >= Success
395 strncpy(c
->name
, *list
, sizeof(c
->name
));
396 XFreeStringList(list
);
409 XSetErrorHandler(xerrordummy
);
411 XUngrabButton(dpy
, AnyButton
, AnyModifier
, c
->win
);
412 XDestroyWindow(dpy
, c
->title
);
414 for(l
= &clients
; *l
&& *l
!= c
; l
= &(*l
)->next
);
416 for(l
= &clients
; *l
; l
= &(*l
)->next
)
417 if((*l
)->revert
== c
)
420 sel
= sel
->revert
? sel
->revert
: clients
;
425 XSetErrorHandler(xerror
);
440 if(sel
== getnext(clients
, tsel
) && sel
->next
) {
441 if((c
= getnext(sel
->next
, tsel
)))