change behaviour of uicb_setlayout: no arg now reset to first/default layout ; add...
[awesome.git] / client.c
blob590de4f00a36c68f80476fd0c457855277f89a85
1 /*
2 * client.c - client management
3 *
4 * Copyright © 2007 Julien Danjou <julien@danjou.info>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License along
17 * with this program; if not, write to the Free Software Foundation, Inc.,
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
22 #include <stdio.h>
23 #include <X11/Xatom.h>
24 #include <X11/Xutil.h>
25 #include <X11/extensions/shape.h>
27 #include "screen.h"
28 #include "awesome.h"
29 #include "layout.h"
30 #include "tag.h"
31 #include "util.h"
32 #include "statusbar.h"
34 #include "layouts/floating.h"
36 /* extern */
37 extern Client *clients, *sel, *stack; /* global client list and stack */
39 /** Attach client stack to clients stacks
40 * \param c the client
41 */
42 static inline void
43 attachstack(Client * c)
45 c->snext = stack;
46 stack = c;
49 /** Detach client from stack
50 * \param c the client
52 static inline void
53 detachstack(Client * c)
55 Client **tc;
57 for(tc = &stack; *tc && *tc != c; tc = &(*tc)->snext);
58 *tc = c->snext;
61 /** Grab or ungrab buttons when a client is focused
62 * \param c client
63 * \param focused True if client is focused
64 * \param modkey Mod key mask
65 * \param numlockmask Numlock mask
67 static void
68 grabbuttons(Client * c, Bool focused, KeySym modkey, unsigned int numlockmask)
70 XUngrabButton(c->display, AnyButton, AnyModifier, c->win);
72 if(focused)
74 XGrabButton(c->display, Button1, modkey, c->win, False, BUTTONMASK,
75 GrabModeAsync, GrabModeSync, None, None);
76 XGrabButton(c->display, Button1, modkey | LockMask, c->win, False,
77 BUTTONMASK, GrabModeAsync, GrabModeSync, None, None);
78 XGrabButton(c->display, Button1, modkey | numlockmask, c->win, False,
79 BUTTONMASK, GrabModeAsync, GrabModeSync, None, None);
80 XGrabButton(c->display, Button1, modkey | numlockmask | LockMask,
81 c->win, False, BUTTONMASK, GrabModeAsync, GrabModeSync, None, None);
83 XGrabButton(c->display, Button2, modkey, c->win, False, BUTTONMASK,
84 GrabModeAsync, GrabModeSync, None, None);
85 XGrabButton(c->display, Button2, modkey | LockMask, c->win, False,
86 BUTTONMASK, GrabModeAsync, GrabModeSync, None, None);
87 XGrabButton(c->display, Button2, modkey | numlockmask, c->win, False,
88 BUTTONMASK, GrabModeAsync, GrabModeSync, None, None);
89 XGrabButton(c->display, Button2, modkey | numlockmask | LockMask,
90 c->win, False, BUTTONMASK, GrabModeAsync, GrabModeSync, None, None);
92 XGrabButton(c->display, Button3, modkey, c->win, False, BUTTONMASK,
93 GrabModeAsync, GrabModeSync, None, None);
94 XGrabButton(c->display, Button3, modkey | LockMask, c->win, False,
95 BUTTONMASK, GrabModeAsync, GrabModeSync, None, None);
96 XGrabButton(c->display, Button3, modkey | numlockmask, c->win, False,
97 BUTTONMASK, GrabModeAsync, GrabModeSync, None, None);
98 XGrabButton(c->display, Button3, modkey | numlockmask | LockMask,
99 c->win, False, BUTTONMASK, GrabModeAsync, GrabModeSync, None, None);
101 XUngrabButton(c->display, AnyButton, AnyModifier, RootWindow(c->display, c->phys_screen));
103 else
105 XGrabButton(c->display, AnyButton, AnyModifier, c->win, False, BUTTONMASK,
106 GrabModeAsync, GrabModeSync, None, None);
107 XGrabButton(c->display, Button4, NoSymbol, RootWindow(c->display, c->phys_screen), False, BUTTONMASK,
108 GrabModeAsync, GrabModeSync, None, None);
109 XGrabButton(c->display, Button4, LockMask, RootWindow(c->display, c->phys_screen), False, BUTTONMASK,
110 GrabModeAsync, GrabModeSync, None, None);
111 XGrabButton(c->display, Button4, numlockmask, RootWindow(c->display, c->phys_screen), False, BUTTONMASK,
112 GrabModeAsync, GrabModeSync, None, None);
113 XGrabButton(c->display, Button4, numlockmask | LockMask, RootWindow(c->display, c->phys_screen), False, BUTTONMASK,
114 GrabModeAsync, GrabModeSync, None, None);
116 XGrabButton(c->display, Button5, NoSymbol, RootWindow(c->display, c->phys_screen), False, BUTTONMASK,
117 GrabModeAsync, GrabModeSync, None, None);
118 XGrabButton(c->display, Button5, LockMask, RootWindow(c->display, c->phys_screen), False, BUTTONMASK,
119 GrabModeAsync, GrabModeSync, None, None);
120 XGrabButton(c->display, Button5, numlockmask, RootWindow(c->display, c->phys_screen), False, BUTTONMASK,
121 GrabModeAsync, GrabModeSync, None, None);
122 XGrabButton(c->display, Button5, numlockmask | LockMask, RootWindow(c->display, c->phys_screen), False, BUTTONMASK,
123 GrabModeAsync, GrabModeSync, None, None);
128 /** Check if client supports protocol WM_DELETE_WINDOW
129 * \param c the client
130 * \return True if client has WM_DELETE_WINDOW
132 static Bool
133 isprotodel(Client * c)
135 int i, n;
136 Atom *protocols;
137 Bool ret = False;
139 if(XGetWMProtocols(c->display, c->win, &protocols, &n))
141 for(i = 0; !ret && i < n; i++)
142 if(protocols[i] == XInternAtom(c->display, "WM_DELETE_WINDOW", False))
143 ret = True;
144 XFree(protocols);
146 return ret;
149 /** Set client WM_STATE property
150 * \param c the client
151 * \param state no idea
153 static void
154 setclientstate(Client * c, long state)
156 long data[] = { state, None };
158 XChangeProperty(c->display, c->win, XInternAtom(c->display, "WM_STATE", False),
159 XInternAtom(c->display, "WM_STATE", False), 32,
160 PropModeReplace, (unsigned char *) data, 2);
163 /** Set client transparency using composite
164 * \param c client
165 * \param opacity opacity percentage
167 static void
168 setclienttrans(Client *c, double opacity)
170 unsigned int real_opacity = 0xffffffff;
172 if(opacity >= 0 && opacity <= 100)
174 real_opacity = ((opacity / 100.0) * 0xffffffff);
175 XChangeProperty(c->display, c->win,
176 XInternAtom(c->display, "_NET_WM_WINDOW_OPACITY", False),
177 XA_CARDINAL, 32, PropModeReplace, (unsigned char *) &real_opacity, 1L);
179 else
180 XDeleteProperty(c->display, c->win, XInternAtom(c->display, "_NET_WM_WINDOW_OPACITY", False));
182 XSync(c->display, False);
185 /** Swap two client in the linked list clients
186 * \param c1 first client
187 * \param c2 second client
189 static void
190 client_swap(Client *c1, Client *c2)
192 Client *tmp;
194 tmp = c1->next;
195 c1->next = c2->next;
196 c2->next = (tmp == c2 ? c1 : tmp);
198 tmp = c2->prev;
199 c2->prev = c1->prev;
200 c1->prev = (tmp == c1 ? c2 : tmp );
202 if(c1->next)
203 c1->next->prev = c1;
205 if(c1->prev)
206 c1->prev->next = c1;
208 if(c2->next)
209 c2->next->prev = c2;
211 if(c2->prev)
212 c2->prev->next = c2;
214 if(clients == c1)
215 clients = c2;
218 /** Attach client to the beginning of the clients stack
219 * \param c the client
221 void
222 attach(Client * c)
224 if(clients)
225 clients->prev = c;
226 c->next = clients;
227 clients = c;
230 void
231 updatetitle(Client * c)
233 if(!xgettextprop(c->display, c->win, XInternAtom(c->display, "_NET_WM_NAME", False), c->name, sizeof c->name))
234 xgettextprop(c->display, c->win, XInternAtom(c->display, "WM_NAME", False), c->name, sizeof c->name);
237 /** Ban client and unmapped it
238 * \param c the client
240 void
241 ban(Client * c)
243 XUnmapWindow(c->display, c->win);
244 setclientstate(c, IconicState);
245 c->isbanned = True;
246 c->unmapped = True;
249 /** Configure client
250 * \param c the client
252 void
253 configure(Client * c)
255 XConfigureEvent ce;
257 ce.type = ConfigureNotify;
258 ce.display = c->display;
259 ce.event = c->win;
260 ce.window = c->win;
261 ce.x = c->x;
262 ce.y = c->y;
263 ce.width = c->w;
264 ce.height = c->h;
265 ce.border_width = c->border;
266 ce.above = None;
267 ce.override_redirect = False;
268 XSendEvent(c->display, c->win, False, StructureNotifyMask, (XEvent *) & ce);
271 void
272 detach(Client * c)
274 if(c->prev)
275 c->prev->next = c->next;
276 if(c->next)
277 c->next->prev = c->prev;
278 if(c == clients)
279 clients = c->next;
280 c->next = c->prev = NULL;
283 /** Give focus to client, or to first client if c is NULL
284 * \param disp Display ref
285 * \param drawcontext drawcontext ref
286 * \param c client
287 * \param selscreen True if current screen is selected
288 * \param awesomeconf awesome config
290 void
291 focus(Display *disp, DC *drawcontext, Client * c, Bool selscreen, awesome_config *awesomeconf)
293 /* if c is NULL or invisible, take next client in the stack */
294 if((!c && selscreen) || (c && !isvisible(c, awesomeconf->screen, awesomeconf->tags, awesomeconf->ntags)))
295 for(c = stack; c && !isvisible(c, awesomeconf->screen, awesomeconf->tags, awesomeconf->ntags); c = c->snext);
297 /* if a client was selected but it's not the current client, unfocus it */
298 if(sel && sel != c)
300 grabbuttons(sel, False, awesomeconf->modkey, awesomeconf->numlockmask);
301 XSetWindowBorder(sel->display, sel->win, drawcontext->norm[ColBorder]);
302 setclienttrans(sel, awesomeconf->opacity_unfocused);
304 if(c)
306 detachstack(c);
307 attachstack(c);
308 grabbuttons(c, True, awesomeconf->modkey, awesomeconf->numlockmask);
310 if(!selscreen)
311 return;
312 sel = c;
313 drawstatusbar(disp, drawcontext, awesomeconf);
314 if(sel)
316 XSetWindowBorder(sel->display, sel->win, drawcontext->sel[ColBorder]);
317 XSetInputFocus(sel->display, sel->win, RevertToPointerRoot, CurrentTime);
318 for(c = stack; c; c = c->snext)
319 if(c != sel)
320 setclienttrans(c, awesomeconf->opacity_unfocused);
321 setclienttrans(sel, -1);
323 else
324 XSetInputFocus(disp, RootWindow(disp, awesomeconf->screen), RevertToPointerRoot, CurrentTime);
328 /** Load windows properties, restoring client's tag
329 * and floating state before awesome was restarted if any
330 * \todo this may bug if number of tags is != than before
331 * \param c Client ref
332 * \param ntags tags number
334 static Bool
335 loadprops(Client * c, int ntags)
337 int i;
338 char *prop;
339 Bool result = False;
341 prop = p_new(char, ntags + 2);
343 if(xgettextprop(c->display, c->win, AWESOMEPROPS_ATOM(c->display), prop, ntags + 2))
345 for(i = 0; i < ntags && prop[i]; i++)
346 if((c->tags[i] = prop[i] == '1'))
347 result = True;
348 if(i <= ntags && prop[i])
349 c->isfloating = prop[i] == '1';
352 p_delete(&prop);
354 return result;
357 /** Manage a new client
358 * \param disp Display ref
359 * \param drawcontext Drawcontext ref
360 * \param w The window
361 * \param wa Window attributes
362 * \param awesomeconf awesome config
364 void
365 manage(Display *disp, DC *drawcontext, Window w, XWindowAttributes *wa, awesome_config *awesomeconf)
367 int i;
368 Client *c, *t = NULL;
369 Window trans;
370 Status rettrans;
371 XWindowChanges wc;
372 ScreenInfo *si = get_display_info(disp, awesomeconf->screen, NULL);
373 ScreenInfo *screen_info;
375 c = p_new(Client, 1);
376 c->win = w;
377 c->ftview = True;
378 c->x = c->rw = wa->x;
379 c->y = c->ry = wa->y;
380 c->w = c->rw = wa->width;
381 c->h = c->rh = wa->height;
382 c->oldborder = wa->border_width;
383 c->display = disp;
384 c->phys_screen = get_phys_screen(c->display, c->screen);
385 screen_info = get_screen_info(c->display, c->screen, NULL);
386 if(c->w == screen_info[c->screen].width && c->h == screen_info[c->screen].height)
388 c->x = 0;
389 c->y = 0;
390 c->border = wa->border_width;
392 else
394 if(c->x + c->w + 2 * c->border > si->x_org + si->width)
395 c->x = c->rx = si->x_org + si->width - c->w - 2 * c->border;
396 if(c->y + c->h + 2 * c->border > si->y_org + si->height)
397 c->y = c->ry = si->y_org + si->height - c->h - 2 * c->border;
398 if(c->x < si->x_org)
399 c->x = c->rx = si->x_org;
400 if(c->y < si->y_org)
401 c->y = c->ry = si->y_org;
402 c->border = awesomeconf->borderpx;
404 XFree(si);
405 wc.border_width = c->border;
406 XConfigureWindow(disp, w, CWBorderWidth, &wc);
407 XSetWindowBorder(disp, w, drawcontext->norm[ColBorder]);
408 configure(c); /* propagates border_width, if size doesn't change */
409 updatesizehints(c);
410 XSelectInput(disp, w, StructureNotifyMask | PropertyChangeMask | EnterWindowMask);
411 if(awesomeconf->have_shape)
413 XShapeSelectInput(disp, w, ShapeNotifyMask);
414 set_shape(c);
416 grabbuttons(c, False, awesomeconf->modkey, awesomeconf->numlockmask);
417 updatetitle(c);
418 move_client_to_screen(c, awesomeconf, False);
419 if((rettrans = XGetTransientForHint(disp, w, &trans) == Success))
420 for(t = clients; t && t->win != trans; t = t->next);
421 if(t)
422 for(i = 0; i < awesomeconf->ntags; i++)
423 c->tags[i] = t->tags[i];
424 if(!loadprops(c, awesomeconf->ntags))
425 applyrules(c, awesomeconf);
426 if(!c->isfloating)
427 c->isfloating = (rettrans == Success) || c->isfixed;
428 saveprops(c, awesomeconf->ntags);
429 attach(c);
430 attachstack(c);
431 XMoveResizeWindow(disp, c->win, c->x, c->y, c->w, c->h); /* some windows require this */
432 c->isbanned = True;
433 arrange(disp, drawcontext, awesomeconf);
436 void
437 resize(Client *c, int x, int y, int w, int h, awesome_config *awesomeconf, Bool sizehints)
439 double dx, dy, max, min, ratio;
440 XWindowChanges wc;
441 ScreenInfo *si;
443 if(sizehints)
445 if(c->minay > 0 && c->maxay > 0 && (h - c->baseh) > 0 && (w - c->basew) > 0)
447 dx = (double) (w - c->basew);
448 dy = (double) (h - c->baseh);
449 min = (double) (c->minax) / (double) (c->minay);
450 max = (double) (c->maxax) / (double) (c->maxay);
451 ratio = dx / dy;
452 if(max > 0 && min > 0 && ratio > 0)
454 if(ratio < min)
456 dy = (dx * min + dy) / (min * min + 1);
457 dx = dy * min;
458 w = (int) dx + c->basew;
459 h = (int) dy + c->baseh;
461 else if(ratio > max)
463 dy = (dx * min + dy) / (max * max + 1);
464 dx = dy * min;
465 w = (int) dx + c->basew;
466 h = (int) dy + c->baseh;
470 if(c->minw && w < c->minw)
471 w = c->minw;
472 if(c->minh && h < c->minh)
473 h = c->minh;
474 if(c->maxw && w > c->maxw)
475 w = c->maxw;
476 if(c->maxh && h > c->maxh)
477 h = c->maxh;
478 if(c->incw)
479 w -= (w - c->basew) % c->incw;
480 if(c->inch)
481 h -= (h - c->baseh) % c->inch;
483 if(w <= 0 || h <= 0)
484 return;
485 /* offscreen appearance fixes */
486 si = get_display_info(c->display, c->phys_screen, NULL);
487 if(x > si->width)
488 x = si->width - w - 2 * c->border;
489 if(y > si->height)
490 y = si->height - h - 2 * c->border;
491 XFree(si);
492 if(x + w + 2 * c->border < 0)
493 x = 0;
494 if(y + h + 2 * c->border < 0)
495 y = 0;
496 if(c->x != x || c->y != y || c->w != w || c->h != h)
498 c->x = wc.x = x;
499 c->y = wc.y = y;
500 c->w = wc.width = w;
501 c->h = wc.height = h;
502 wc.border_width = c->border;
503 XConfigureWindow(c->display, c->win, CWX | CWY | CWWidth | CWHeight | CWBorderWidth, &wc);
504 configure(c);
505 XSync(c->display, False);
506 if(XineramaIsActive(c->display))
508 int new_screen = get_screen_bycoord(c->display, c->x, c->y);
509 if(c->screen != new_screen)
510 move_client_to_screen(c, &awesomeconf[new_screen - awesomeconf->screen], False);
515 void
516 saveprops(Client * c, int ntags)
518 int i;
519 char *prop;
521 prop = p_new(char, ntags + 2);
523 for(i = 0; i < ntags; i++)
524 prop[i] = c->tags[i] ? '1' : '0';
526 if(i <= ntags)
527 prop[i] = c->isfloating ? '1' : '0';
529 prop[++i] = '\0';
531 XChangeProperty(c->display, c->win, AWESOMEPROPS_ATOM(c->display), XA_STRING, 8,
532 PropModeReplace, (unsigned char *) prop, i);
534 p_delete(&prop);
537 void
538 unban(Client * c)
540 XMapWindow(c->display, c->win);
541 setclientstate(c, NormalState);
542 c->isbanned = False;
543 c->unmapped = False;
546 void
547 unmanage(Client * c, DC *drawcontext, long state, awesome_config *awesomeconf)
549 XWindowChanges wc;
551 c->unmapped = True;
552 wc.border_width = c->oldborder;
553 /* The server grab construct avoids race conditions. */
554 XGrabServer(c->display);
555 XConfigureWindow(c->display, c->win, CWBorderWidth, &wc); /* restore border */
556 detach(c);
557 detachstack(c);
558 if(sel == c)
559 focus(c->display, drawcontext, NULL, True, awesomeconf);
560 XUngrabButton(c->display, AnyButton, AnyModifier, c->win);
561 setclientstate(c, state);
562 XSync(c->display, False);
563 XSetErrorHandler(xerror);
564 XUngrabServer(c->display);
565 if(state != NormalState)
566 arrange(c->display, drawcontext, awesomeconf);
567 p_delete(&c->tags);
568 p_delete(&c);
571 void
572 updatesizehints(Client * c)
574 long msize;
575 XSizeHints size;
577 if(!XGetWMNormalHints(c->display, c->win, &size, &msize) || !size.flags)
578 size.flags = PSize;
579 c->flags = size.flags;
580 if(c->flags & PBaseSize)
582 c->basew = size.base_width;
583 c->baseh = size.base_height;
585 else if(c->flags & PMinSize)
587 c->basew = size.min_width;
588 c->baseh = size.min_height;
590 else
591 c->basew = c->baseh = 0;
592 if(c->flags & PResizeInc)
594 c->incw = size.width_inc;
595 c->inch = size.height_inc;
597 else
598 c->incw = c->inch = 0;
600 if(c->flags & PMaxSize)
602 c->maxw = size.max_width;
603 c->maxh = size.max_height;
605 else
606 c->maxw = c->maxh = 0;
608 if(c->flags & PMinSize)
610 c->minw = size.min_width;
611 c->minh = size.min_height;
613 else if(c->flags & PBaseSize)
615 c->minw = size.base_width;
616 c->minh = size.base_height;
618 else
619 c->minw = c->minh = 0;
621 if(c->flags & PAspect)
623 c->minax = size.min_aspect.x;
624 c->maxax = size.max_aspect.x;
625 c->minay = size.min_aspect.y;
626 c->maxay = size.max_aspect.y;
628 else
629 c->minax = c->maxax = c->minay = c->maxay = 0;
631 c->isfixed = (c->maxw && c->minw && c->maxh && c->minh
632 && c->maxw == c->minw && c->maxh == c->minh);
635 void
636 set_shape(Client *c)
638 int bounding_shaped;
639 int i, b; unsigned int u; /* dummies */
640 /* Logic to decide if we have a shaped window cribbed from fvwm-2.5.10. */
641 if (XShapeQueryExtents(c->display, c->win, &bounding_shaped, &i, &i,
642 &u, &u, &b, &i, &i, &u, &u) && bounding_shaped)
643 XShapeCombineShape(c->display, RootWindow(c->display, c->screen), ShapeBounding, 0, 0, c->win, ShapeBounding, ShapeSet);
646 /** Set selected client transparency
647 * \param disp Display ref
648 * \param drawcontext Drawcontext ref
649 * \param awesomeconf awesome config
650 * \param arg unused arg
651 * \ingroup ui_callback
653 void
654 uicb_settrans(Display *disp __attribute__ ((unused)),
655 DC *drawcontext __attribute__ ((unused)),
656 awesome_config *awesomeconf __attribute__ ((unused)),
657 const char *arg)
659 double delta = 100.0, current_opacity = 0.0;
660 unsigned char *data;
661 Atom actual;
662 int format;
663 unsigned long n, left;
664 unsigned int current_opacity_raw = 0;
665 int set_prop = 0;
667 if(!sel)
668 return;
670 XGetWindowProperty(sel->display, sel->win, XInternAtom(sel->display, "_NET_WM_WINDOW_OPACITY", False),
671 0L, 1L, False, XA_CARDINAL, &actual, &format, &n, &left,
672 (unsigned char **) &data);
673 if(data)
675 memcpy(&current_opacity_raw, data, sizeof(unsigned int));
676 XFree(data);
677 current_opacity = (current_opacity_raw * 100.0) / 0xffffffff;
679 else
680 set_prop = 1;
682 delta = compute_new_value_from_arg(arg, current_opacity);
684 if(delta <= 0.0)
685 delta = 0.0;
686 else if(delta > 100.0)
688 delta = 100.0;
689 set_prop = 1;
692 if(delta == 100.0 && !set_prop)
693 setclienttrans(sel, -1);
694 else
695 setclienttrans(sel, delta);
699 /** Set borrder size
700 * \param disp Display ref
701 * \param drawcontext Drawcontext ref
702 * \param awesomeconf awesome config
703 * \param arg X, +X or -X
704 * \ingroup ui_callback
706 void
707 uicb_setborder(Display *disp __attribute__ ((unused)),
708 DC *drawcontext __attribute__ ((unused)),
709 awesome_config *awesomeconf,
710 const char *arg)
712 if(!arg)
713 return;
715 if((awesomeconf->borderpx = (int) compute_new_value_from_arg(arg, (double) awesomeconf->borderpx)) < 0)
716 awesomeconf->borderpx = 0;
719 void
720 uicb_swapnext(Display *disp,
721 DC *drawcontext,
722 awesome_config *awesomeconf,
723 const char *arg __attribute__ ((unused)))
725 Client *next;
727 if(!sel)
728 return;
730 for(next = sel->next; next && !isvisible(next, awesomeconf->screen, awesomeconf->tags, awesomeconf->ntags); next = next->next);
731 if(next)
733 client_swap(sel, next);
734 arrange(disp, drawcontext, awesomeconf);
738 void
739 uicb_swapprev(Display *disp,
740 DC *drawcontext,
741 awesome_config *awesomeconf,
742 const char *arg __attribute__ ((unused)))
744 Client *prev;
746 if(!sel)
747 return;
749 for(prev = sel->prev; prev && !isvisible(prev, awesomeconf->screen, awesomeconf->tags, awesomeconf->ntags); prev = prev->prev);
750 if(prev)
752 client_swap(prev, sel);
753 arrange(disp, drawcontext, awesomeconf);
757 void
758 uicb_moveresize(Display *disp __attribute__ ((unused)),
759 DC *drawcontext __attribute__ ((unused)),
760 awesome_config *awesomeconf,
761 const char *arg)
763 int nx, ny, nw, nh, ox, oy, ow, oh;
764 char x[8], y[8], w[8], h[8];
765 int mx, my, dx, dy, nmx, nmy;
766 unsigned int dui;
767 Window dummy;
769 if(!IS_ARRANGE(layout_floating))
770 if(!sel || !sel->isfloating || sel->isfixed || !arg)
771 return;
772 if(sscanf(arg, "%s %s %s %s", x, y, w, h) != 4)
773 return;
774 nx = (int) compute_new_value_from_arg(x, sel->x);
775 ny = (int) compute_new_value_from_arg(y, sel->y);
776 nw = (int) compute_new_value_from_arg(w, sel->w);
777 nh = (int) compute_new_value_from_arg(h, sel->h);
779 ox = sel->x;
780 oy = sel->y;
781 ow = sel->w;
782 oh = sel->h;
784 Bool xqp = XQueryPointer(sel->display, RootWindow(sel->display, sel->screen), &dummy, &dummy, &mx, &my, &dx, &dy, &dui);
785 resize(sel, nx, ny, nw, nh, awesomeconf, True);
786 if (xqp && ox <= mx && (ox + ow) >= mx && oy <= my && (oy + oh) >= my)
788 nmx = mx-ox+sel->w-ow-1 < 0 ? 0 : mx-ox+sel->w-ow-1;
789 nmy = my-oy+sel->h-oh-1 < 0 ? 0 : my-oy+sel->h-oh-1;
790 XWarpPointer(sel->display, None, sel->win, 0, 0, 0, 0, nmx, nmy);
794 /** Kill selected client
795 * \param disp Display ref
796 * \param drawcontext Drawcontext ref
797 * \param awesomeconf awesome config
798 * \param arg unused
799 * \ingroup ui_callback
801 void
802 uicb_killclient(Display *disp __attribute__ ((unused)),
803 DC *drawcontext __attribute__ ((unused)),
804 awesome_config *awesomeconf __attribute__ ((unused)),
805 const char *arg __attribute__ ((unused)))
807 XEvent ev;
809 if(!sel)
810 return;
811 if(isprotodel(sel))
813 ev.type = ClientMessage;
814 ev.xclient.window = sel->win;
815 ev.xclient.message_type = XInternAtom(disp, "WM_PROTOCOLS", False);
816 ev.xclient.format = 32;
817 ev.xclient.data.l[0] = XInternAtom(disp, "WM_DELETE_WINDOW", False);
818 ev.xclient.data.l[1] = CurrentTime;
819 XSendEvent(sel->display, sel->win, False, NoEventMask, &ev);
821 else
822 XKillClient(sel->display, sel->win);