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 static void floating(void);
15 static void tiling(void);
16 static void (*arrange)(void) = floating;
25 stack->w = sw - 2 * stack->border;
26 stack->h = sh - 2 * stack->border;
28 discard_events(EnterWindowMask);
36 for(c = stack; c; c = c->snext)
38 discard_events(EnterWindowMask);
45 int n, cols, rows, gw, gh, i, j;
50 for(n = 0, c = clients; c; c = c->next, n++);
52 if(modff(rt, &fd) < 0.5)
64 for(i = j = 0, c = clients; c; c = c->next) {
75 discard_events(EnterWindowMask);
81 if(arrange == floating)
92 const char *arg = aux;
97 if(!strncmp(arg, "next", 5))
98 c = stack->snext ? stack->snext : stack;
99 else if(!strncmp(arg, "prev", 5))
100 for(c = stack; c && c->snext; c = c->snext);
104 XWarpPointer(dpy, None, c->win, 0, 0, 0, 0, c->w / 2, c->h / 2);
115 if(c->proto & WM_PROTOCOL_DELWIN)
116 send_message(c->win, wm_atom[WMProtocols], wm_atom[WMDelete]);
118 XKillClient(dpy, c->win);
122 resize_title(Client *c)
127 for(i = 0; i < TLast; i++)
129 c->tw += textw(c->tags[i]) + dc.font.height;
130 c->tw += textw(c->name) + dc.font.height;
133 c->tx = c->x + c->w - c->tw + 2;
135 XMoveResizeWindow(dpy, c->title, c->tx, c->ty, c->tw, c->th);
139 update_name(Client *c)
147 XGetTextProperty(dpy, c->win, &name, net_atom[NetWMName]);
149 XGetWMName(dpy, c->win, &name);
152 if(name.encoding == XA_STRING)
153 strncpy(c->name, (char *)name.value, sizeof(c->name));
155 if(XmbTextPropertyToTextList(dpy, &name, &list, &n) >= Success
158 strncpy(c->name, *list, sizeof(c->name));
159 XFreeStringList(list);
167 update_size(Client *c)
171 if(!XGetWMNormalHints(dpy, c->win, &size, &msize) || !size.flags)
173 c->flags = size.flags;
174 if(c->flags & PBaseSize) {
175 c->basew = size.base_width;
176 c->baseh = size.base_height;
179 c->basew = c->baseh = 0;
180 if(c->flags & PResizeInc) {
181 c->incw = size.width_inc;
182 c->inch = size.height_inc;
185 c->incw = c->inch = 0;
186 if(c->flags & PMaxSize) {
187 c->maxw = size.max_width;
188 c->maxh = size.max_height;
191 c->maxw = c->maxh = 0;
192 if(c->flags & PMinSize) {
193 c->minw = size.min_width;
194 c->minh = size.min_height;
197 c->minw = c->minh = 0;
198 if(c->flags & PWinGravity)
199 c->grav = size.win_gravity;
201 c->grav = NorthWestGravity;
207 XRaiseWindow(dpy, c->win);
208 XRaiseWindow(dpy, c->title);
214 XLowerWindow(dpy, c->title);
215 XLowerWindow(dpy, c->win);
224 for(l = &stack; *l && *l != c; l = &(*l)->snext);
229 if(old && old != c) {
230 XSetWindowBorder(dpy, old->win, dc.bg);
231 XMapWindow(dpy, old->title);
234 XUnmapWindow(dpy, c->title);
235 XSetWindowBorder(dpy, c->win, dc.fg);
237 XSetInputFocus(dpy, c->win, RevertToPointerRoot, CurrentTime);
239 discard_events(EnterWindowMask);
243 manage(Window w, XWindowAttributes *wa)
246 XSetWindowAttributes twa;
248 c = emallocz(sizeof(Client));
250 c->tx = c->x = wa->x;
251 c->ty = c->y = wa->y;
252 c->tw = c->w = wa->width;
257 XSelectInput(dpy, c->win,
258 StructureNotifyMask | PropertyChangeMask | EnterWindowMask);
259 XGetTransientForHint(dpy, c->win, &c->trans);
260 twa.override_redirect = 1;
261 twa.background_pixmap = ParentRelative;
262 twa.event_mask = ExposureMask;
264 c->tags[tsel] = tags[tsel];
265 c->title = XCreateWindow(dpy, root, c->tx, c->ty, c->tw, c->th,
266 0, DefaultDepth(dpy, screen), CopyFromParent,
267 DefaultVisual(dpy, screen),
268 CWOverrideRedirect | CWBackPixmap | CWEventMask, &twa);
271 for(l=&clients; *l; l=&(*l)->next);
272 c->next = *l; /* *l == nil */
274 XSetWindowBorderWidth(dpy, c->win, 1);
275 XMapRaised(dpy, c->win);
276 XMapRaised(dpy, c->title);
277 XGrabButton(dpy, Button1, Mod1Mask, c->win, False, ButtonPressMask,
278 GrabModeAsync, GrabModeSync, None, None);
279 XGrabButton(dpy, Button2, Mod1Mask, c->win, False, ButtonPressMask,
280 GrabModeAsync, GrabModeSync, None, None);
281 XGrabButton(dpy, Button3, Mod1Mask, c->win, False, ButtonPressMask,
282 GrabModeAsync, GrabModeSync, None, None);
284 XWarpPointer(dpy, None, c->win, 0, 0, 0, 0, c->w / 2, c->h / 2);
289 gravitate(Client *c, Bool invert)
295 case NorthWestGravity:
297 case NorthEastGravity:
303 dy = -(c->h / 2) + c->border;
305 case SouthEastGravity:
307 case SouthWestGravity:
316 case NorthWestGravity:
318 case SouthWestGravity:
324 dx = -(c->w / 2) + c->border;
326 case NorthEastGravity:
328 case SouthEastGravity:
329 dx = -(c->w + c->border);
350 c->w -= (c->w - c->basew) % c->incw;
352 c->h -= (c->h - c->baseh) % c->inch;
353 if(c->minw && c->w < c->minw)
355 if(c->minh && c->h < c->minh)
357 if(c->maxw && c->w > c->maxw)
359 if(c->maxh && c->h > c->maxh)
362 XMoveResizeWindow(dpy, c->win, c->x, c->y, c->w, c->h);
363 e.type = ConfigureNotify;
370 e.border_width = c->border;
372 e.override_redirect = False;
373 XSendEvent(dpy, c->win, False, StructureNotifyMask, (XEvent *)&e);
378 dummy_error_handler(Display *dsply, XErrorEvent *err)
389 XSetErrorHandler(dummy_error_handler);
391 XUngrabButton(dpy, AnyButton, AnyModifier, c->win);
392 XDestroyWindow(dpy, c->title);
394 for(l=&clients; *l && *l != c; l=&(*l)->next);
396 for(l=&stack; *l && *l != c; l=&(*l)->snext);
401 XSetErrorHandler(error_handler);
412 for(c = clients; c; c = c->next)
422 for(c = clients; c; c = c->next)
429 draw_client(Client *c)
439 for(i = 0; i < TLast; i++) {
442 dc.w = textw(c->tags[i]) + dc.font.height;
443 draw(True, c->tags[i]);
447 dc.w = textw(c->name) + dc.font.height;
449 XCopyArea(dpy, dc.drawable, c->title, dc.gc,
450 0, 0, c->tw, c->th, 0, 0);