use draw_color_new()
[awesome.git] / client.c
blobebc5957a7661fcbff8f6da2d9a2861736e4ff3c8
1 /*
2 * client.c - client management
4 * Copyright © 2007-2008 Julien Danjou <julien@danjou.info>
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/extensions/shape.h>
26 #include "client.h"
27 #include "tag.h"
28 #include "rules.h"
29 #include "window.h"
30 #include "focus.h"
31 #include "ewmh.h"
32 #include "screen.h"
33 #include "widget.h"
34 #include "layouts/floating.h"
37 extern AwesomeConf globalconf;
39 /** Load windows properties, restoring client's tag
40 * and floating state before awesome was restarted if any
41 * \todo this may bug if number of tags is != than before
42 * \param c Client ref
43 * \param screen Screen ID
44 * \return true if client had property
46 static Bool
47 client_loadprops(Client * c, int screen)
49 int i, ntags = 0;
50 Tag *tag;
51 char *prop;
52 Bool result = False;
54 for(tag = globalconf.screens[screen].tags; tag; tag = tag->next)
55 ntags++;
57 prop = p_new(char, ntags + 2);
59 if(xgettextprop(c->win,
60 XInternAtom(globalconf.display, "_AWESOME_PROPERTIES", False),
61 prop, ntags + 2))
63 for(i = 0, tag = globalconf.screens[screen].tags; tag && i < ntags && prop[i]; i++, tag = tag->next)
64 if(prop[i] == '1')
66 tag_client(c, tag);
67 result = True;
69 else
70 untag_client(c, tag);
72 if(i <= ntags && prop[i])
73 client_setfloating(c, prop[i] == '1');
76 p_delete(&prop);
78 return result;
81 /** Check if client supports protocol WM_DELETE_WINDOW
82 * \param disp the display
83 * \param win the Window
84 * \return True if client has WM_DELETE_WINDOW
86 static Bool
87 isprotodel(Display *disp, Window win)
89 int i, n;
90 Atom *protocols;
91 Bool ret = False;
93 if(XGetWMProtocols(disp, win, &protocols, &n))
95 for(i = 0; !ret && i < n; i++)
96 if(protocols[i] == XInternAtom(disp, "WM_DELETE_WINDOW", False))
97 ret = True;
98 XFree(protocols);
100 return ret;
103 /** Get a Client by its window
104 * \param list Client list to look info
105 * \param w Client window to find
106 * \return client
108 Client *
109 get_client_bywin(Client *list, Window w)
111 Client *c;
113 for(c = list; c && c->win != w; c = c->next);
114 return c;
117 /** Get a client by its name
118 * \param list Client list
119 * \param name name to search
120 * \return first matching client
122 Client *
123 get_client_byname(Client *list, char *name)
125 Client *c;
127 for(c = list; c; c = c->next)
128 if(strstr(c->name, name))
129 return c;
131 return NULL;
134 /** Update client name attribute with its title
135 * \param c the client
137 void
138 client_updatetitle(Client *c)
140 if(!xgettextprop(c->win, XInternAtom(globalconf.display, "_NET_WM_NAME", False), c->name, sizeof(c->name)))
141 xgettextprop(c->win, XInternAtom(globalconf.display, "WM_NAME", False), c->name, sizeof(c->name));
143 widget_invalidate_cache(c->screen, WIDGET_CACHE_CLIENTS);
146 static void
147 client_unfocus(Client *c)
149 XSetWindowBorder(globalconf.display, c->win,
150 globalconf.screens[c->screen].colors_normal[ColBorder].pixel);
151 widget_invalidate_cache(c->screen, WIDGET_CACHE_CLIENTS);
152 focus_add_client(NULL);
155 /** Ban client and unmap it
156 * \param c the client
158 void
159 client_ban(Client *c)
161 if(globalconf.focus->client == c)
162 client_unfocus(c);
163 XUnmapWindow(globalconf.display, c->win);
164 window_setstate(c->win, IconicState);
167 /** Give focus to client, or to first client if c is NULL
168 * \param c client
169 * \param screen Screen ID
171 void
172 focus(Client *c, int screen, Bool from_mouse)
174 int phys_screen = get_phys_screen(screen);
176 /* if c is NULL or invisible, take next client in the focus history */
177 if(!c || (c && !client_isvisible(c, screen)))
179 c = focus_get_current_client(screen);
180 /* if c is still NULL take next client in the stack */
181 if(!c)
182 for(c = globalconf.clients; c && (c->skip || !client_isvisible(c, screen)); c = c->next);
185 /* unfocus current selected client */
186 if(globalconf.focus->client)
187 client_unfocus(globalconf.focus->client);
189 if(c)
191 /* save sel in focus history */
192 focus_add_client(c);
193 XSetWindowBorder(globalconf.display, c->win,
194 globalconf.screens[screen].colors_selected[ColBorder].pixel);
195 XSetInputFocus(globalconf.display, c->win, RevertToPointerRoot, CurrentTime);
196 if(!from_mouse
197 || !globalconf.screens[screen].sloppy_focus
198 || globalconf.screens[screen].sloppy_focus_raise)
199 XRaiseWindow(globalconf.display, c->win);
200 /* since we're dropping EnterWindow events and sometimes the window
201 * will appear under the mouse, grabbuttons */
202 window_grabbuttons(phys_screen, c->win);
204 else
205 XSetInputFocus(globalconf.display,
206 RootWindow(globalconf.display, phys_screen),
207 RevertToPointerRoot, CurrentTime);
209 widget_invalidate_cache(screen, WIDGET_CACHE_CLIENTS);
210 ewmh_update_net_active_window(phys_screen);
211 globalconf.drop_events |= EnterWindowMask;
214 /** Manage a new client
215 * \param w The window
216 * \param wa Window attributes
217 * \param screen Screen ID
219 void
220 client_manage(Window w, XWindowAttributes *wa, int screen)
222 Client *c, *t = NULL;
223 Window trans;
224 Bool rettrans;
225 XWindowChanges wc;
226 Tag *tag;
227 Rule *rule;
228 Area screen_geom;
229 int phys_screen = get_phys_screen(screen);
231 c = p_new(Client, 1);
233 c->screen = get_screen_bycoord(wa->x, wa->y);
235 screen_geom = get_display_area(phys_screen,
236 globalconf.screens[c->screen].statusbar,
237 &globalconf.screens[c->screen].padding);
238 /* Initial values */
239 c->win = w;
240 c->geometry.x = c->f_geometry.x = c->m_geometry.x = MAX(wa->x, screen_geom.x);
241 c->geometry.y = c->f_geometry.y = c->m_geometry.y = MAX(wa->y, screen_geom.y);
242 c->geometry.width = c->f_geometry.width = c->m_geometry.width = wa->width;
243 c->geometry.height = c->f_geometry.height = c->m_geometry.height = wa->height;
244 c->oldborder = wa->border_width;
245 c->newcomer = True;
247 c->border = globalconf.screens[screen].borderpx;
249 /* Set windows borders */
250 wc.border_width = c->border;
251 XConfigureWindow(globalconf.display, w, CWBorderWidth, &wc);
252 XSetWindowBorder(globalconf.display, w, globalconf.screens[screen].colors_normal[ColBorder].pixel);
253 /* propagates border_width, if size doesn't change */
254 window_configure(c->win, c->geometry, c->border);
256 /* update window title */
257 client_updatetitle(c);
259 /* update hints */
260 client_updatesizehints(c);
261 client_updatewmhints(c);
263 /* First check clients hints */
264 ewmh_check_client_hints(c);
266 /* loadprops or apply rules if no props */
267 if(!client_loadprops(c, screen))
269 /* Get the client's rule */
270 if((rule = rule_matching_client(c)))
272 if(rule->screen != RULE_NOSCREEN)
273 move_client_to_screen(c, rule->screen, True);
274 else
275 move_client_to_screen(c, screen, True);
276 tag_client_with_rule(c, rule);
278 switch(rule->isfloating)
280 case Auto:
281 break;
282 case Float:
283 client_setfloating(c, True);
284 break;
285 case Tile:
286 client_setfloating(c, False);
287 break;
290 if(rule->opacity >= 0.0f)
291 window_settrans(c->win, rule->opacity);
293 else
294 move_client_to_screen(c, screen, True);
295 /* check for transient and set tags like its parent,
296 * XGetTransientForHint returns 1 on success
298 if((rettrans = XGetTransientForHint(globalconf.display, w, &trans))
299 && (t = get_client_bywin(globalconf.clients, trans)))
300 for(tag = globalconf.screens[c->screen].tags; tag; tag = tag->next)
301 if(is_client_tagged(t, tag))
302 tag_client(c, tag);
304 /* should be floating if transsient or fixed */
305 if(!c->isfloating)
306 client_setfloating(c, rettrans || c->isfixed);
309 XSelectInput(globalconf.display, w, StructureNotifyMask | PropertyChangeMask | EnterWindowMask);
311 /* handle xshape */
312 if(globalconf.have_shape)
314 XShapeSelectInput(globalconf.display, w, ShapeNotifyMask);
315 window_setshape(phys_screen, c->win);
318 /* attach to the stack */
319 if((rule = rule_matching_client(c)) && rule->not_master)
320 client_list_append(&globalconf.clients, c);
321 else if(globalconf.screens[c->screen].new_become_master)
322 client_list_push(&globalconf.clients, c);
323 else
324 client_list_append(&globalconf.clients, c);
326 /* some windows require this */
327 XMoveResizeWindow(globalconf.display, c->win, c->geometry.x, c->geometry.y,
328 c->geometry.width, c->geometry.height);
330 widget_invalidate_cache(c->screen, WIDGET_CACHE_CLIENTS);
331 ewmh_update_net_client_list(phys_screen);
334 /** Resize client window
335 * \param c client to resize
336 * \param geometry new window geometry
337 * \param sizehints respect size hints
338 * \param return True if resize has been done
340 Bool
341 client_resize(Client *c, Area geometry, Bool sizehints)
343 int new_screen;
344 double dx, dy, max, min, ratio;
345 Area area;
346 XWindowChanges wc;
348 if(sizehints)
350 if(c->minay > 0 && c->maxay > 0 && (geometry.height - c->baseh) > 0
351 && (geometry.width - c->basew) > 0)
353 dx = (double) (geometry.width - c->basew);
354 dy = (double) (geometry.height - c->baseh);
355 min = (double) (c->minax) / (double) (c->minay);
356 max = (double) (c->maxax) / (double) (c->maxay);
357 ratio = dx / dy;
358 if(max > 0 && min > 0 && ratio > 0)
360 if(ratio < min)
362 dy = (dx * min + dy) / (min * min + 1);
363 dx = dy * min;
364 geometry.width = (int) dx + c->basew;
365 geometry.height = (int) dy + c->baseh;
367 else if(ratio > max)
369 dy = (dx * min + dy) / (max * max + 1);
370 dx = dy * min;
371 geometry.width = (int) dx + c->basew;
372 geometry.height = (int) dy + c->baseh;
376 if(c->minw && geometry.width < c->minw)
377 geometry.width = c->minw;
378 if(c->minh && geometry.height < c->minh)
379 geometry.height = c->minh;
380 if(c->maxw && geometry.width > c->maxw)
381 geometry.width = c->maxw;
382 if(c->maxh && geometry.height > c->maxh)
383 geometry.height = c->maxh;
384 if(c->incw)
385 geometry.width -= (geometry.width - c->basew) % c->incw;
386 if(c->inch)
387 geometry.height -= (geometry.height - c->baseh) % c->inch;
389 if(geometry.width <= 0 || geometry.height <= 0)
390 return False;
391 /* offscreen appearance fixes */
392 area = get_display_area(get_phys_screen(c->screen),
393 NULL,
394 &globalconf.screens[c->screen].padding);
395 if(geometry.x > area.width)
396 geometry.x = area.width - geometry.width - 2 * c->border;
397 if(geometry.y > area.height)
398 geometry.y = area.height - geometry.height - 2 * c->border;
399 if(geometry.x + geometry.width + 2 * c->border < 0)
400 geometry.x = 0;
401 if(geometry.y + geometry.height + 2 * c->border < 0)
402 geometry.y = 0;
404 if(c->geometry.x != geometry.x || c->geometry.y != geometry.y
405 || c->geometry.width != geometry.width || c->geometry.height != geometry.height)
407 new_screen = get_screen_bycoord(geometry.x, geometry.y);
409 c->geometry.x = wc.x = geometry.x;
410 c->geometry.y = wc.y = geometry.y;
411 c->geometry.width = wc.width = geometry.width;
412 c->geometry.height = wc.height = geometry.height;
413 wc.border_width = c->border;
415 /* save the floating geometry if the window is floating but not
416 * maximized */
417 if((c->isfloating ||
418 get_current_layout(new_screen)->arrange == layout_floating) && !c->ismax)
419 c->f_geometry = geometry;
421 XConfigureWindow(globalconf.display, c->win,
422 CWX | CWY | CWWidth | CWHeight | CWBorderWidth, &wc);
423 window_configure(c->win, geometry, c->border);
425 if(c->screen != new_screen)
426 move_client_to_screen(c, new_screen, False);
428 return True;
430 return False;
433 void
434 client_setfloating(Client *c, Bool floating)
436 if(c->isfloating != floating)
438 if((c->isfloating = floating))
439 client_resize(c, c->f_geometry, False);
440 else if(c->ismax)
442 c->ismax = False;
443 client_resize(c, c->m_geometry, False);
445 if(client_isvisible(c, c->screen))
446 globalconf.screens[c->screen].need_arrange = True;
447 widget_invalidate_cache(c->screen, WIDGET_CACHE_CLIENTS);
448 client_saveprops(c);
452 /** Save client properties as an X property
453 * \param c client
455 void
456 client_saveprops(Client *c)
458 int i = 0, ntags = 0;
459 char *prop;
460 Tag *tag;
462 for(tag = globalconf.screens[c->screen].tags; tag; tag = tag->next)
463 ntags++;
465 prop = p_new(char, ntags + 2);
467 for(tag = globalconf.screens[c->screen].tags; tag; tag = tag->next, i++)
468 prop[i] = is_client_tagged(c, tag) ? '1' : '0';
470 if(i <= ntags)
471 prop[i] = c->isfloating ? '1' : '0';
473 prop[++i] = '\0';
475 XChangeProperty(globalconf.display, c->win,
476 XInternAtom(globalconf.display, "_AWESOME_PROPERTIES", False),
477 XA_STRING, 8, PropModeReplace, (unsigned char *) prop, i);
479 p_delete(&prop);
482 void
483 client_unban(Client *c)
485 XMapWindow(globalconf.display, c->win);
486 window_setstate(c->win, NormalState);
489 void
490 client_unmanage(Client *c)
492 XWindowChanges wc;
493 Tag *tag;
495 wc.border_width = c->oldborder;
497 /* The server grab construct avoids race conditions. */
498 XGrabServer(globalconf.display);
500 XConfigureWindow(globalconf.display, c->win, CWBorderWidth, &wc); /* restore border */
502 /* remove client everywhere */
503 client_list_detach(&globalconf.clients, c);
504 focus_delete_client(c);
505 for(tag = globalconf.screens[c->screen].tags; tag; tag = tag->next)
506 untag_client(c, tag);
508 if(globalconf.focus->client == c)
509 focus(NULL, c->screen, False);
511 XUngrabButton(globalconf.display, AnyButton, AnyModifier, c->win);
512 window_setstate(c->win, WithdrawnState);
514 XSync(globalconf.display, False);
515 XUngrabServer(globalconf.display);
517 p_delete(&c);
520 void
521 client_updatewmhints(Client *c)
523 XWMHints *wmh;
525 if((wmh = XGetWMHints(globalconf.display, c->win)))
527 if((c->isurgent = (wmh->flags & XUrgencyHint)))
528 widget_invalidate_cache(c->screen, WIDGET_CACHE_CLIENTS);
529 if((wmh->flags & StateHint) && wmh->initial_state == WithdrawnState)
531 c->border = 0;
532 c->skip = True;
534 XFree(wmh);
538 void
539 client_updatesizehints(Client *c)
541 long msize;
542 XSizeHints size;
544 if(!XGetWMNormalHints(globalconf.display, c->win, &size, &msize) || !size.flags)
545 size.flags = PSize;
546 if(size.flags & PBaseSize)
548 c->basew = size.base_width;
549 c->baseh = size.base_height;
551 else if(size.flags & PMinSize)
553 c->basew = size.min_width;
554 c->baseh = size.min_height;
556 else
557 c->basew = c->baseh = 0;
558 if(size.flags & PResizeInc)
560 c->incw = size.width_inc;
561 c->inch = size.height_inc;
563 else
564 c->incw = c->inch = 0;
566 if(size.flags & PMaxSize)
568 c->maxw = size.max_width;
569 c->maxh = size.max_height;
571 else
572 c->maxw = c->maxh = 0;
574 if(size.flags & PMinSize)
576 c->minw = size.min_width;
577 c->minh = size.min_height;
579 else if(size.flags & PBaseSize)
581 c->minw = size.base_width;
582 c->minh = size.base_height;
584 else
585 c->minw = c->minh = 0;
587 if(size.flags & PAspect)
589 c->minax = size.min_aspect.x;
590 c->maxax = size.max_aspect.x;
591 c->minay = size.min_aspect.y;
592 c->maxay = size.max_aspect.y;
594 else
595 c->minax = c->maxax = c->minay = c->maxay = 0;
597 if(c->maxw && c->minw && c->maxh && c->minh
598 && c->maxw == c->minw && c->maxh == c->minh)
599 c->isfixed = True;
602 /** Returns True if a client is tagged
603 * with one of the tags
604 * \return True or False
606 Bool
607 client_isvisible(Client *c, int screen)
609 Tag *tag;
611 if(!c || c->screen != screen)
612 return False;
614 for(tag = globalconf.screens[screen].tags; tag; tag = tag->next)
615 if(tag->selected && is_client_tagged(c, tag))
616 return True;
617 return False;
620 /** Set selected client transparency
621 * \param screen Screen ID
622 * \param arg unused arg
623 * \ingroup ui_callback
625 void
626 uicb_client_settrans(int screen __attribute__ ((unused)), char *arg)
628 double delta = 100.0, current_opacity = 100.0;
629 unsigned char *data;
630 Atom actual;
631 int format;
632 unsigned long n, left;
633 unsigned int current_opacity_raw = 0;
634 int set_prop = 0;
635 Client *sel = globalconf.focus->client;
637 if(!sel)
638 return;
640 XGetWindowProperty(globalconf.display, sel->win,
641 XInternAtom(globalconf.display, "_NET_WM_WINDOW_OPACITY", False),
642 0L, 1L, False, XA_CARDINAL, &actual, &format, &n, &left,
643 (unsigned char **) &data);
644 if(data)
646 memcpy(&current_opacity_raw, data, sizeof(unsigned int));
647 XFree(data);
648 current_opacity = (current_opacity_raw * 100.0) / 0xffffffff;
650 else
651 set_prop = 1;
653 delta = compute_new_value_from_arg(arg, current_opacity);
655 if(delta <= 0.0)
656 delta = 0.0;
657 else if(delta > 100.0)
659 delta = 100.0;
660 set_prop = 1;
663 if(delta == 100.0 && !set_prop)
664 window_settrans(sel->win, -1);
665 else
666 window_settrans(sel->win, delta);
669 static Client *
670 client_find_prev_visible(Client *sel)
672 Client *prev = NULL;
674 if(!sel) return NULL;
676 /* look for previous starting at sel */
677 for(prev = client_list_prev_cycle(&globalconf.clients, sel);
678 prev && (prev->skip || !client_isvisible(prev, sel->screen));
679 prev = client_list_prev_cycle(&globalconf.clients, prev));
681 return prev;
684 static Client *
685 client_find_next_visible(Client *sel)
687 Client *next = NULL;
689 if(!sel) return NULL;
691 for(next = sel->next; next && !client_isvisible(next, sel->screen); next = next->next);
692 if(!next)
693 for(next = globalconf.clients; next && !client_isvisible(next, sel->screen); next = next->next);
695 return next;
698 /** Swap current with previous client
699 * \param screen Screen ID
700 * \param arg nothing
701 * \ingroup ui_callback
703 void
704 uicb_client_swapprev(int screen __attribute__ ((unused)),
705 char *arg __attribute__ ((unused)))
707 Client *prev;
709 if((prev = client_find_prev_visible(globalconf.focus->client)))
711 client_list_swap(&globalconf.clients, prev, globalconf.focus->client);
712 globalconf.screens[prev->screen].need_arrange = True;
716 /** Swap current with next client
717 * \param screen Screen ID
718 * \param arg nothing
719 * \ingroup ui_callback
721 void
722 uicb_client_swapnext(int screen __attribute__ ((unused)),
723 char *arg __attribute__ ((unused)))
725 Client *next;
727 if((next = client_find_next_visible(globalconf.focus->client)))
729 client_list_swap(&globalconf.clients, globalconf.focus->client, next);
730 globalconf.screens[next->screen].need_arrange = True;
734 /** Move and resize client
735 * \param screen Screen ID
736 * \param arg x y w h
737 * \ingroup ui_callback
739 void
740 uicb_client_moveresize(int screen, char *arg)
742 int ox, oy, ow, oh;
743 char x[8], y[8], w[8], h[8];
744 int mx, my, dx, dy, nmx, nmy;
745 unsigned int dui;
746 Window dummy;
747 Area area;
748 Client *sel = globalconf.focus->client;
749 Tag **curtags = get_current_tags(screen);
751 if(curtags[0]->layout->arrange != layout_floating)
752 if(!sel || !sel->isfloating || sel->isfixed || !arg)
754 p_delete(&curtags);
755 return;
757 p_delete(&curtags);
758 if(sscanf(arg, "%s %s %s %s", x, y, w, h) != 4)
759 return;
760 area.x = (int) compute_new_value_from_arg(x, sel->geometry.x);
761 area.y = (int) compute_new_value_from_arg(y, sel->geometry.y);
762 area.width = (int) compute_new_value_from_arg(w, sel->geometry.width);
763 area.height = (int) compute_new_value_from_arg(h, sel->geometry.height);
765 ox = sel->geometry.x;
766 oy = sel->geometry.y;
767 ow = sel->geometry.width;
768 oh = sel->geometry.height;
770 Bool xqp = XQueryPointer(globalconf.display,
771 RootWindow(globalconf.display,
772 get_phys_screen(screen)),
773 &dummy, &dummy, &mx, &my, &dx, &dy, &dui);
774 client_resize(sel, area, globalconf.screens[sel->screen].resize_hints);
775 if (xqp && ox <= mx && (ox + ow) >= mx && oy <= my && (oy + oh) >= my)
777 nmx = mx - ox + sel->geometry.width - ow - 1 < 0 ? 0 : mx - ox + sel->geometry.width - ow - 1;
778 nmy = my - oy + sel->geometry.height - oh - 1 < 0 ? 0 : my - oy + sel->geometry.height - oh - 1;
779 XWarpPointer(globalconf.display,
780 None, sel->win,
781 0, 0, 0, 0, nmx, nmy);
785 void
786 client_kill(Client *c)
788 XEvent ev;
790 if(isprotodel(globalconf.display, c->win))
792 ev.type = ClientMessage;
793 ev.xclient.window = c->win;
794 ev.xclient.message_type = XInternAtom(globalconf.display, "WM_PROTOCOLS", False);
795 ev.xclient.format = 32;
796 ev.xclient.data.l[0] = XInternAtom(globalconf.display, "WM_DELETE_WINDOW", False);
797 ev.xclient.data.l[1] = CurrentTime;
798 XSendEvent(globalconf.display, c->win, False, NoEventMask, &ev);
800 else
801 XKillClient(globalconf.display, c->win);
804 /** Kill selected client
805 * \param screen Screen ID
806 * \param arg unused
807 * \ingroup ui_callback
809 void
810 uicb_client_kill(int screen __attribute__ ((unused)), char *arg __attribute__ ((unused)))
812 Client *sel = globalconf.focus->client;
814 if(sel)
815 client_kill(sel);
818 static void
819 client_maximize(Client *c, Area geometry)
822 if((c->ismax = !c->ismax))
824 c->wasfloating = c->isfloating;
825 c->m_geometry = c->geometry;
826 if(get_current_layout(c->screen)->arrange != layout_floating)
827 client_setfloating(c, True);
828 client_resize(c, geometry, False);
829 widget_invalidate_cache(c->screen, WIDGET_CACHE_CLIENTS);
831 else if(c->wasfloating)
833 client_setfloating(c, True);
834 client_resize(c, c->m_geometry, False);
835 widget_invalidate_cache(c->screen, WIDGET_CACHE_CLIENTS);
837 else if(get_current_layout(c->screen)->arrange == layout_floating)
839 client_resize(c, c->m_geometry, False);
840 widget_invalidate_cache(c->screen, WIDGET_CACHE_CLIENTS);
842 else
844 client_setfloating(c, False);
845 widget_invalidate_cache(c->screen, WIDGET_CACHE_CLIENTS);
849 /** Toggle maximize for client
850 * \param screen Screen ID
851 * \param arg Unused
852 * \ingroup ui_callback
854 void
855 uicb_client_togglemax(int screen, char *arg __attribute__ ((unused)))
857 Client *sel = globalconf.focus->client;
858 Area area = get_screen_area(screen,
859 globalconf.screens[screen].statusbar,
860 &globalconf.screens[screen].padding);
862 if(sel)
864 area.width -= 2 * sel->border;
865 area.height -= 2 * sel->border;
866 client_maximize(sel, area);
870 /** Toggle vertical maximize for client
871 * \param screen Screen ID
872 * \param arg Unused
873 * \ingroup ui_callback
875 void
876 uicb_client_toggleverticalmax(int screen, char *arg __attribute__ ((unused)))
878 Client *sel = globalconf.focus->client;
879 Area area = get_screen_area(screen,
880 globalconf.screens[screen].statusbar,
881 &globalconf.screens[screen].padding);
883 if(sel)
885 area.x = sel->geometry.x;
886 area.width = sel->geometry.width;
887 area.height -= 2 * sel->border;
888 client_maximize(sel, area);
893 /** Toggle horizontal maximize for client
894 * \param screen Screen ID
895 * \param arg Unused
896 * \ingroup ui_callback
898 void
899 uicb_client_togglehorizontalmax(int screen, char *arg __attribute__ ((unused)))
901 Client *sel = globalconf.focus->client;
902 Area area = get_screen_area(screen,
903 globalconf.screens[screen].statusbar,
904 &globalconf.screens[screen].padding);
906 if(sel)
908 area.y = sel->geometry.y;
909 area.height = sel->geometry.height;
910 area.width -= 2 * sel->border;
911 client_maximize(sel, area);
915 /** Zoom client
916 * \param screen Screen ID
917 * \param arg Unused
918 * \ingroup ui_callback
920 void
921 uicb_client_zoom(int screen, char *arg __attribute__ ((unused)))
923 Client *c, *sel = globalconf.focus->client;
925 for(c = globalconf.clients; !client_isvisible(c, screen); c = c->next);
926 if(c == sel)
927 for(sel = sel->next; sel && !client_isvisible(sel, screen); sel = sel->next);
929 if(!sel)
930 return;
932 client_list_detach(&globalconf.clients, sel);
933 client_list_push(&globalconf.clients, sel);
934 globalconf.screens[screen].need_arrange = True;
937 /** Send focus to next client in stack
938 * \param screen Screen ID
939 * \param arg Unused
940 * \ingroup ui_callback
942 void
943 uicb_client_focusnext(int screen, char *arg __attribute__ ((unused)))
945 Client *c, *sel = globalconf.focus->client;
947 if(!sel)
948 return;
949 for(c = sel->next; c && (c->skip || !client_isvisible(c, screen)); c = c->next);
950 if(!c)
951 for(c = globalconf.clients; c && (c->skip || !client_isvisible(c, screen)); c = c->next);
952 if(c)
953 focus(c, screen, False);
956 /** Send focus to previous client in stack
957 * \param screen Screen ID
958 * \param arg Unused
959 * \ingroup ui_callback
961 void
962 uicb_client_focusprev(int screen, char *arg __attribute__ ((unused)))
964 Client *prev;
966 if((prev = client_find_prev_visible(globalconf.focus->client)))
967 focus(prev, screen, False);
970 /** Toggle floating state of a client
971 * \param screen Screen ID
972 * \param arg unused
973 * \ingroup ui_callback
975 void
976 uicb_client_togglefloating(int screen __attribute__ ((unused)),
977 char *arg __attribute__ ((unused)))
979 if(globalconf.focus->client)
980 client_setfloating(globalconf.focus->client, !globalconf.focus->client->isfloating);
983 // vim: filetype=c:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=80