store phys_screen
[awesome.git] / client.c
blob285e91ca73f327591e5356502b1fdf37b4a0ed73
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 inline void
222 attach(Client * c)
224 if(clients)
225 clients->prev = c;
226 c->next = clients;
227 clients = c;
230 inline 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);
327 /** Kill selected client
328 * \param disp Display ref
329 * \param drawcontext Drawcontext ref
330 * \param awesomeconf awesome config
331 * \param arg unused
332 * \ingroup ui_callback
334 void
335 uicb_killclient(Display *disp __attribute__ ((unused)),
336 DC *drawcontext __attribute__ ((unused)),
337 awesome_config *awesomeconf __attribute__ ((unused)),
338 const char *arg __attribute__ ((unused)))
340 XEvent ev;
342 if(!sel)
343 return;
344 if(isprotodel(sel))
346 ev.type = ClientMessage;
347 ev.xclient.window = sel->win;
348 ev.xclient.message_type = XInternAtom(disp, "WM_PROTOCOLS", False);
349 ev.xclient.format = 32;
350 ev.xclient.data.l[0] = XInternAtom(disp, "WM_DELETE_WINDOW", False);
351 ev.xclient.data.l[1] = CurrentTime;
352 XSendEvent(sel->display, sel->win, False, NoEventMask, &ev);
354 else
355 XKillClient(sel->display, sel->win);
359 /** Load windows properties, restoring client's tag
360 * and floating state before awesome was restarted if any
361 * \todo this may bug if number of tags is != than before
362 * \param c Client ref
363 * \param ntags tags number
365 static Bool
366 loadprops(Client * c, int ntags)
368 int i;
369 char *prop;
370 Bool result = False;
372 prop = p_new(char, ntags + 2);
374 if(xgettextprop(c->display, c->win, AWESOMEPROPS_ATOM(c->display), prop, ntags + 2))
376 for(i = 0; i < ntags && prop[i]; i++)
377 if((c->tags[i] = prop[i] == '1'))
378 result = True;
379 if(i <= ntags && prop[i])
380 c->isfloating = prop[i] == '1';
383 p_delete(&prop);
385 return result;
388 /** Manage a new client
389 * \param disp Display ref
390 * \param drawcontext Drawcontext ref
391 * \param w The window
392 * \param wa Window attributes
393 * \param awesomeconf awesome config
395 void
396 manage(Display *disp, DC *drawcontext, Window w, XWindowAttributes *wa, awesome_config *awesomeconf)
398 int i;
399 Client *c, *t = NULL;
400 Window trans;
401 Status rettrans;
402 XWindowChanges wc;
403 ScreenInfo *si = get_display_info(disp, awesomeconf->screen, &awesomeconf->statusbar);
405 c = p_new(Client, 1);
406 c->win = w;
407 c->ftview = True;
408 c->x = c->rw = wa->x;
409 c->y = c->ry = wa->y;
410 c->w = c->rw = wa->width;
411 c->h = c->rh = wa->height;
412 c->oldborder = wa->border_width;
413 c->display = disp;
414 c->phys_screen = get_phys_screen(disp, c->screen);
415 if(c->w == si->width && c->h == si->height)
417 c->x = 0;
418 c->y = 0;
419 c->border = wa->border_width;
421 else
423 if(c->x + c->w + 2 * c->border > si->x_org + si->width)
424 c->x = c->rx = si->x_org + si->width - c->w - 2 * c->border;
425 if(c->y + c->h + 2 * c->border > si->y_org + si->height)
426 c->y = c->ry = si->y_org + si->height - c->h - 2 * c->border;
427 if(c->x < si->x_org)
428 c->x = c->rx = si->x_org;
429 if(c->y < si->y_org)
430 c->y = c->ry = si->y_org;
431 c->border = awesomeconf->borderpx;
433 XFree(si);
434 wc.border_width = c->border;
435 XConfigureWindow(disp, w, CWBorderWidth, &wc);
436 XSetWindowBorder(disp, w, drawcontext->norm[ColBorder]);
437 configure(c); /* propagates border_width, if size doesn't change */
438 updatesizehints(c);
439 XSelectInput(disp, w, StructureNotifyMask | PropertyChangeMask | EnterWindowMask);
440 if(awesomeconf->have_shape)
442 XShapeSelectInput(disp, w, ShapeNotifyMask);
443 set_shape(c);
445 grabbuttons(c, False, awesomeconf->modkey, awesomeconf->numlockmask);
446 updatetitle(c);
447 move_client_to_screen(c, awesomeconf, False);
448 if((rettrans = XGetTransientForHint(disp, w, &trans) == Success))
449 for(t = clients; t && t->win != trans; t = t->next);
450 if(t)
451 for(i = 0; i < awesomeconf->ntags; i++)
452 c->tags[i] = t->tags[i];
453 if(!loadprops(c, awesomeconf->ntags))
454 applyrules(c, awesomeconf);
455 if(!c->isfloating)
456 c->isfloating = (rettrans == Success) || c->isfixed;
457 saveprops(c, awesomeconf->ntags);
458 attach(c);
459 attachstack(c);
460 XMoveResizeWindow(disp, c->win, c->x, c->y, c->w, c->h); /* some windows require this */
461 c->isbanned = True;
462 arrange(disp, drawcontext, awesomeconf);
465 void
466 resize(Client *c, int x, int y, int w, int h, awesome_config *awesomeconf, Bool sizehints)
468 double dx, dy, max, min, ratio;
469 XWindowChanges wc;
470 ScreenInfo *si;
472 if(sizehints)
474 if(c->minay > 0 && c->maxay > 0 && (h - c->baseh) > 0 && (w - c->basew) > 0)
476 dx = (double) (w - c->basew);
477 dy = (double) (h - c->baseh);
478 min = (double) (c->minax) / (double) (c->minay);
479 max = (double) (c->maxax) / (double) (c->maxay);
480 ratio = dx / dy;
481 if(max > 0 && min > 0 && ratio > 0)
483 if(ratio < min)
485 dy = (dx * min + dy) / (min * min + 1);
486 dx = dy * min;
487 w = (int) dx + c->basew;
488 h = (int) dy + c->baseh;
490 else if(ratio > max)
492 dy = (dx * min + dy) / (max * max + 1);
493 dx = dy * min;
494 w = (int) dx + c->basew;
495 h = (int) dy + c->baseh;
499 if(c->minw && w < c->minw)
500 w = c->minw;
501 if(c->minh && h < c->minh)
502 h = c->minh;
503 if(c->maxw && w > c->maxw)
504 w = c->maxw;
505 if(c->maxh && h > c->maxh)
506 h = c->maxh;
507 if(c->incw)
508 w -= (w - c->basew) % c->incw;
509 if(c->inch)
510 h -= (h - c->baseh) % c->inch;
512 if(w <= 0 || h <= 0)
513 return;
514 /* offscreen appearance fixes */
515 if(XineramaIsActive(c->display))
516 si = get_display_info(c->display, DefaultScreen(c->display), NULL);
517 else
518 si = get_display_info(c->display, c->screen, NULL);
519 if(x > si->width)
520 x = si->width - w - 2 * c->border;
521 if(y > si->height)
522 y = si->height - h - 2 * c->border;
523 XFree(si);
524 if(x + w + 2 * c->border < 0)
525 x = 0;
526 if(y + h + 2 * c->border < 0)
527 y = 0;
528 if(c->x != x || c->y != y || c->w != w || c->h != h)
530 c->x = wc.x = x;
531 c->y = wc.y = y;
532 c->w = wc.width = w;
533 c->h = wc.height = h;
534 wc.border_width = c->border;
535 XConfigureWindow(c->display, c->win, CWX | CWY | CWWidth | CWHeight | CWBorderWidth, &wc);
536 configure(c);
537 XSync(c->display, False);
538 if(XineramaIsActive(c->display))
540 int new_screen = get_screen_bycoord(c->display, c->x, c->y);
541 if(c->screen != new_screen)
542 move_client_to_screen(c, &awesomeconf[new_screen - awesomeconf->screen], False);
547 void
548 uicb_moveresize(Display *disp __attribute__ ((unused)),
549 DC *drawcontext __attribute__ ((unused)),
550 awesome_config *awesomeconf,
551 const char *arg)
553 int nx, ny, nw, nh, ox, oy, ow, oh;
554 char x[8], y[8], w[8], h[8];
555 int mx, my, dx, dy, nmx, nmy;
556 unsigned int dui;
557 Window dummy;
559 if(!IS_ARRANGE(layout_floating))
560 if(!sel || !sel->isfloating || sel->isfixed || !arg)
561 return;
562 if(sscanf(arg, "%s %s %s %s", x, y, w, h) != 4)
563 return;
564 nx = (int) compute_new_value_from_arg(x, sel->x);
565 ny = (int) compute_new_value_from_arg(y, sel->y);
566 nw = (int) compute_new_value_from_arg(w, sel->w);
567 nh = (int) compute_new_value_from_arg(h, sel->h);
569 ox = sel->x;
570 oy = sel->y;
571 ow = sel->w;
572 oh = sel->h;
574 Bool xqp = XQueryPointer(sel->display, RootWindow(sel->display, sel->screen), &dummy, &dummy, &mx, &my, &dx, &dy, &dui);
575 resize(sel, nx, ny, nw, nh, awesomeconf, True);
576 if (xqp && ox <= mx && (ox + ow) >= mx && oy <= my && (oy + oh) >= my)
578 nmx = mx-ox+sel->w-ow-1 < 0 ? 0 : mx-ox+sel->w-ow-1;
579 nmy = my-oy+sel->h-oh-1 < 0 ? 0 : my-oy+sel->h-oh-1;
580 XWarpPointer(sel->display, None, sel->win, 0, 0, 0, 0, nmx, nmy);
584 void
585 saveprops(Client * c, int ntags)
587 int i;
588 char *prop;
590 prop = p_new(char, ntags + 2);
592 for(i = 0; i < ntags; i++)
593 prop[i] = c->tags[i] ? '1' : '0';
595 if(i <= ntags)
596 prop[i] = c->isfloating ? '1' : '0';
598 prop[++i] = '\0';
600 XChangeProperty(c->display, c->win, AWESOMEPROPS_ATOM(c->display), XA_STRING, 8,
601 PropModeReplace, (unsigned char *) prop, i);
603 p_delete(&prop);
606 void
607 unban(Client * c)
609 XMapWindow(c->display, c->win);
610 setclientstate(c, NormalState);
611 c->isbanned = False;
612 c->unmapped = False;
615 void
616 unmanage(Client * c, DC *drawcontext, long state, awesome_config *awesomeconf)
618 XWindowChanges wc;
620 c->unmapped = True;
621 wc.border_width = c->oldborder;
622 /* The server grab construct avoids race conditions. */
623 XGrabServer(c->display);
624 XConfigureWindow(c->display, c->win, CWBorderWidth, &wc); /* restore border */
625 detach(c);
626 detachstack(c);
627 if(sel == c)
628 focus(c->display, drawcontext, NULL, True, awesomeconf);
629 XUngrabButton(c->display, AnyButton, AnyModifier, c->win);
630 setclientstate(c, state);
631 XSync(c->display, False);
632 XSetErrorHandler(xerror);
633 XUngrabServer(c->display);
634 if(state != NormalState)
635 arrange(c->display, drawcontext, awesomeconf);
636 p_delete(&c->tags);
637 p_delete(&c);
640 void
641 updatesizehints(Client * c)
643 long msize;
644 XSizeHints size;
646 if(!XGetWMNormalHints(c->display, c->win, &size, &msize) || !size.flags)
647 size.flags = PSize;
648 c->flags = size.flags;
649 if(c->flags & PBaseSize)
651 c->basew = size.base_width;
652 c->baseh = size.base_height;
654 else if(c->flags & PMinSize)
656 c->basew = size.min_width;
657 c->baseh = size.min_height;
659 else
660 c->basew = c->baseh = 0;
661 if(c->flags & PResizeInc)
663 c->incw = size.width_inc;
664 c->inch = size.height_inc;
666 else
667 c->incw = c->inch = 0;
669 if(c->flags & PMaxSize)
671 c->maxw = size.max_width;
672 c->maxh = size.max_height;
674 else
675 c->maxw = c->maxh = 0;
677 if(c->flags & PMinSize)
679 c->minw = size.min_width;
680 c->minh = size.min_height;
682 else if(c->flags & PBaseSize)
684 c->minw = size.base_width;
685 c->minh = size.base_height;
687 else
688 c->minw = c->minh = 0;
690 if(c->flags & PAspect)
692 c->minax = size.min_aspect.x;
693 c->maxax = size.max_aspect.x;
694 c->minay = size.min_aspect.y;
695 c->maxay = size.max_aspect.y;
697 else
698 c->minax = c->maxax = c->minay = c->maxay = 0;
700 c->isfixed = (c->maxw && c->minw && c->maxh && c->minh
701 && c->maxw == c->minw && c->maxh == c->minh);
704 void
705 set_shape(Client *c)
707 int bounding_shaped;
708 int i, b; unsigned int u; /* dummies */
709 /* Logic to decide if we have a shaped window cribbed from fvwm-2.5.10. */
710 if (XShapeQueryExtents(c->display, c->win, &bounding_shaped, &i, &i,
711 &u, &u, &b, &i, &i, &u, &u) && bounding_shaped)
712 XShapeCombineShape(c->display, RootWindow(c->display, c->screen), ShapeBounding, 0, 0, c->win, ShapeBounding, ShapeSet);
715 /** Set selected client transparency
716 * \param disp Display ref
717 * \param drawcontext Drawcontext ref
718 * \param awesomeconf awesome config
719 * \param arg unused arg
720 * \ingroup ui_callback
722 void
723 uicb_settrans(Display *disp __attribute__ ((unused)),
724 DC *drawcontext __attribute__ ((unused)),
725 awesome_config *awesomeconf __attribute__ ((unused)),
726 const char *arg)
728 double delta = 100.0, current_opacity = 0.0;
729 unsigned char *data;
730 Atom actual;
731 int format;
732 unsigned long n, left;
733 unsigned int current_opacity_raw = 0;
734 int set_prop = 0;
736 if(!sel)
737 return;
739 XGetWindowProperty(sel->display, sel->win, XInternAtom(sel->display, "_NET_WM_WINDOW_OPACITY", False),
740 0L, 1L, False, XA_CARDINAL, &actual, &format, &n, &left,
741 (unsigned char **) &data);
742 if(data)
744 memcpy(&current_opacity_raw, data, sizeof(unsigned int));
745 XFree(data);
746 current_opacity = (current_opacity_raw * 100.0) / 0xffffffff;
748 else
749 set_prop = 1;
751 delta = compute_new_value_from_arg(arg, current_opacity);
753 if(delta <= 0.0)
754 delta = 0.0;
755 else if(delta > 100.0)
757 delta = 100.0;
758 set_prop = 1;
761 if(delta == 100.0 && !set_prop)
762 setclienttrans(sel, -1);
763 else
764 setclienttrans(sel, delta);
768 /** Set borrder size
769 * \param disp Display ref
770 * \param drawcontext Drawcontext ref
771 * \param awesomeconf awesome config
772 * \param arg X, +X or -X
773 * \ingroup ui_callback
775 void
776 uicb_setborder(Display *disp __attribute__ ((unused)),
777 DC *drawcontext __attribute__ ((unused)),
778 awesome_config *awesomeconf,
779 const char *arg)
781 if(!arg)
782 return;
784 if((awesomeconf->borderpx = (int) compute_new_value_from_arg(arg, (double) awesomeconf->borderpx)) < 0)
785 awesomeconf->borderpx = 0;
788 void
789 uicb_swapnext(Display *disp,
790 DC *drawcontext,
791 awesome_config *awesomeconf,
792 const char *arg __attribute__ ((unused)))
794 Client *next;
796 if(!sel)
797 return;
799 for(next = sel->next; next && !isvisible(next, awesomeconf->screen, awesomeconf->tags, awesomeconf->ntags); next = next->next);
800 if(next)
802 client_swap(sel, next);
803 arrange(disp, drawcontext, awesomeconf);
807 void
808 uicb_swapprev(Display *disp,
809 DC *drawcontext,
810 awesome_config *awesomeconf,
811 const char *arg __attribute__ ((unused)))
813 Client *prev;
815 if(!sel)
816 return;
818 for(prev = sel->prev; prev && !isvisible(prev, awesomeconf->screen, awesomeconf->tags, awesomeconf->ntags); prev = prev->prev);
819 if(prev)
821 client_swap(prev, sel);
822 arrange(disp, drawcontext, awesomeconf);