change default font
[awesome.git] / client.c
blob9f96531ee4919e413db21164ea966064c5b2884e
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 "xutil.h"
30 #include "window.h"
31 #include "focus.h"
32 #include "ewmh.h"
33 #include "screen.h"
34 #include "widget.h"
35 #include "layouts/floating.h"
38 extern AwesomeConf globalconf;
40 /** Load windows properties, restoring client's tag
41 * and floating state before awesome was restarted if any
42 * \todo this may bug if number of tags is != than before
43 * \param c Client ref
44 * \param screen Screen ID
45 * \return true if client had property
47 static Bool
48 client_loadprops(Client * c, int screen)
50 int i, ntags = 0;
51 Tag *tag;
52 char *prop;
53 Bool result = False;
55 for(tag = globalconf.screens[screen].tags; tag; tag = tag->next)
56 ntags++;
58 prop = p_new(char, ntags + 2);
60 if(xgettextprop(c->win,
61 XInternAtom(globalconf.display, "_AWESOME_PROPERTIES", False),
62 prop, ntags + 2))
64 for(i = 0, tag = globalconf.screens[screen].tags; tag && i < ntags && prop[i]; i++, tag = tag->next)
65 if(prop[i] == '1')
67 tag_client(c, tag);
68 result = True;
70 else
71 untag_client(c, tag);
73 if(i <= ntags && prop[i])
74 client_setfloating(c, prop[i] == '1');
77 p_delete(&prop);
79 return result;
82 /** Check if client supports protocol WM_DELETE_WINDOW
83 * \param disp the display
84 * \param win the Window
85 * \return True if client has WM_DELETE_WINDOW
87 static Bool
88 isprotodel(Display *disp, Window win)
90 int i, n;
91 Atom *protocols;
92 Bool ret = False;
94 if(XGetWMProtocols(disp, win, &protocols, &n))
96 for(i = 0; !ret && i < n; i++)
97 if(protocols[i] == XInternAtom(disp, "WM_DELETE_WINDOW", False))
98 ret = True;
99 XFree(protocols);
101 return ret;
104 /** Get a Client by its window
105 * \param list Client list to look info
106 * \param w Client window to find
107 * \return client
109 Client *
110 get_client_bywin(Client *list, Window w)
112 Client *c;
114 for(c = list; c && c->win != w; c = c->next);
115 return c;
118 /** Get a client by its name
119 * \param list Client list
120 * \param name name to search
121 * \return first matching client
123 Client *
124 get_client_byname(Client *list, char *name)
126 Client *c;
128 for(c = list; c; c = c->next)
129 if(strstr(c->name, name))
130 return c;
132 return NULL;
135 /** Update client name attribute with its title
136 * \param c the client
138 void
139 client_updatetitle(Client *c)
141 if(!xgettextprop(c->win, XInternAtom(globalconf.display, "_NET_WM_NAME", False), c->name, sizeof(c->name)))
142 xgettextprop(c->win, XInternAtom(globalconf.display, "WM_NAME", False), c->name, sizeof(c->name));
144 widget_invalidate_cache(c->screen, WIDGET_CACHE_CLIENTS);
147 static void
148 client_unfocus(Client *c)
150 XSetWindowBorder(globalconf.display, c->win,
151 globalconf.screens[c->screen].colors_normal[ColBorder].pixel);
152 widget_invalidate_cache(c->screen, WIDGET_CACHE_CLIENTS);
153 focus_add_client(NULL);
156 /** Ban client and unmap it
157 * \param c the client
159 void
160 client_ban(Client *c)
162 if(globalconf.focus->client == c)
163 client_unfocus(c);
164 XUnmapWindow(globalconf.display, c->win);
165 window_setstate(c->win, IconicState);
168 /** Give focus to client, or to first client if c is NULL
169 * \param c client
170 * \param screen Screen ID
172 void
173 focus(Client *c, int screen, Bool from_mouse)
175 int phys_screen = get_phys_screen(screen);
177 /* if c is NULL or invisible, take next client in the focus history */
178 if(!c || (c && !client_isvisible(c, screen)))
180 c = focus_get_current_client(screen);
181 /* if c is still NULL take next client in the stack */
182 if(!c)
183 for(c = globalconf.clients; c && (c->skip || !client_isvisible(c, screen)); c = c->next);
186 /* unfocus current selected client */
187 if(globalconf.focus->client)
188 client_unfocus(globalconf.focus->client);
191 if(c)
193 /* save sel in focus history */
194 focus_add_client(c);
195 XSetWindowBorder(globalconf.display, c->win,
196 globalconf.screens[screen].colors_selected[ColBorder].pixel);
197 XSetInputFocus(globalconf.display, c->win, RevertToPointerRoot, CurrentTime);
198 if(!from_mouse
199 || !globalconf.screens[screen].sloppy_focus
200 || globalconf.screens[screen].sloppy_focus_raise)
201 XRaiseWindow(globalconf.display, c->win);
203 else
204 XSetInputFocus(globalconf.display,
205 RootWindow(globalconf.display, phys_screen),
206 RevertToPointerRoot, CurrentTime);
208 widget_invalidate_cache(screen, WIDGET_CACHE_CLIENTS);
209 ewmh_update_net_active_window(phys_screen);
210 globalconf.drop_events |= EnterWindowMask;
213 /** Manage a new client
214 * \param w The window
215 * \param wa Window attributes
216 * \param screen Screen ID
218 void
219 client_manage(Window w, XWindowAttributes *wa, int screen)
221 Client *c, *t = NULL;
222 Window trans;
223 Bool rettrans;
224 XWindowChanges wc;
225 Tag *tag;
226 Rule *rule;
227 Area screen_geom;
228 int phys_screen = get_phys_screen(screen);
230 c = p_new(Client, 1);
232 c->screen = get_screen_bycoord(wa->x, wa->y);
234 screen_geom = get_display_area(phys_screen,
235 globalconf.screens[c->screen].statusbar,
236 &globalconf.screens[c->screen].padding);
237 /* Initial values */
238 c->win = w;
239 c->geometry.x = c->f_geometry.x = c->m_geometry.x = MAX(wa->x, screen_geom.x);
240 c->geometry.y = c->f_geometry.y = c->m_geometry.y = MAX(wa->y, screen_geom.y);
241 c->geometry.width = c->f_geometry.width = c->m_geometry.width = wa->width;
242 c->geometry.height = c->f_geometry.height = c->m_geometry.height = wa->height;
243 c->oldborder = wa->border_width;
244 c->newcomer = True;
246 c->border = globalconf.screens[screen].borderpx;
248 /* Set windows borders */
249 wc.border_width = c->border;
250 XConfigureWindow(globalconf.display, w, CWBorderWidth, &wc);
251 XSetWindowBorder(globalconf.display, w, globalconf.screens[screen].colors_normal[ColBorder].pixel);
252 /* propagates border_width, if size doesn't change */
253 window_configure(c->win, c->geometry, c->border);
255 /* update window title */
256 client_updatetitle(c);
258 /* update hints */
259 client_updatesizehints(c);
260 client_updatewmhints(c);
262 /* First check clients hints */
263 ewmh_check_client_hints(c);
265 /* loadprops or apply rules if no props */
266 if(!client_loadprops(c, screen))
268 /* Get the client's rule */
269 if((rule = rule_matching_client(c)))
271 if(rule->screen != RULE_NOSCREEN)
272 move_client_to_screen(c, rule->screen, True);
273 else
274 move_client_to_screen(c, screen, True);
275 tag_client_with_rule(c, rule);
277 switch(rule->isfloating)
279 case Auto:
280 break;
281 case Float:
282 client_setfloating(c, True);
283 break;
284 case Tile:
285 client_setfloating(c, False);
286 break;
289 if(rule->opacity >= 0.0f)
290 window_settrans(c->win, rule->opacity);
292 else
293 move_client_to_screen(c, screen, True);
294 /* check for transient and set tags like its parent,
295 * XGetTransientForHint returns 1 on success
297 if((rettrans = XGetTransientForHint(globalconf.display, w, &trans))
298 && (t = get_client_bywin(globalconf.clients, trans)))
299 for(tag = globalconf.screens[c->screen].tags; tag; tag = tag->next)
300 if(is_client_tagged(t, tag))
301 tag_client(c, tag);
303 /* should be floating if transsient or fixed */
304 if(!c->isfloating)
305 client_setfloating(c, rettrans || c->isfixed);
308 XSelectInput(globalconf.display, w, StructureNotifyMask | PropertyChangeMask | EnterWindowMask);
310 /* handle xshape */
311 if(globalconf.have_shape)
313 XShapeSelectInput(globalconf.display, w, ShapeNotifyMask);
314 window_setshape(phys_screen, c->win);
317 /* attach to the stack */
318 if((rule = rule_matching_client(c)) && rule->not_master)
319 client_list_append(&globalconf.clients, c);
320 else if(globalconf.screens[c->screen].new_become_master)
321 client_list_push(&globalconf.clients, c);
322 else
323 client_list_append(&globalconf.clients, c);
325 /* some windows require this */
326 XMoveResizeWindow(globalconf.display, c->win, c->geometry.x, c->geometry.y,
327 c->geometry.width, c->geometry.height);
329 widget_invalidate_cache(c->screen, WIDGET_CACHE_CLIENTS);
330 ewmh_update_net_client_list(phys_screen);
333 /** Resize client window
334 * \param c client to resize
335 * \param geometry new window geometry
336 * \param sizehints respect size hints
337 * \param return True if resize has been done
339 Bool
340 client_resize(Client *c, Area geometry, Bool sizehints)
342 int new_screen;
343 double dx, dy, max, min, ratio;
344 Area area;
345 XWindowChanges wc;
347 if(sizehints)
349 if(c->minay > 0 && c->maxay > 0 && (geometry.height - c->baseh) > 0
350 && (geometry.width - c->basew) > 0)
352 dx = (double) (geometry.width - c->basew);
353 dy = (double) (geometry.height - c->baseh);
354 min = (double) (c->minax) / (double) (c->minay);
355 max = (double) (c->maxax) / (double) (c->maxay);
356 ratio = dx / dy;
357 if(max > 0 && min > 0 && ratio > 0)
359 if(ratio < min)
361 dy = (dx * min + dy) / (min * min + 1);
362 dx = dy * min;
363 geometry.width = (int) dx + c->basew;
364 geometry.height = (int) dy + c->baseh;
366 else if(ratio > max)
368 dy = (dx * min + dy) / (max * max + 1);
369 dx = dy * min;
370 geometry.width = (int) dx + c->basew;
371 geometry.height = (int) dy + c->baseh;
375 if(c->minw && geometry.width < c->minw)
376 geometry.width = c->minw;
377 if(c->minh && geometry.height < c->minh)
378 geometry.height = c->minh;
379 if(c->maxw && geometry.width > c->maxw)
380 geometry.width = c->maxw;
381 if(c->maxh && geometry.height > c->maxh)
382 geometry.height = c->maxh;
383 if(c->incw)
384 geometry.width -= (geometry.width - c->basew) % c->incw;
385 if(c->inch)
386 geometry.height -= (geometry.height - c->baseh) % c->inch;
388 if(geometry.width <= 0 || geometry.height <= 0)
389 return False;
390 /* offscreen appearance fixes */
391 area = get_display_area(get_phys_screen(c->screen),
392 NULL,
393 &globalconf.screens[c->screen].padding);
394 if(geometry.x > area.width)
395 geometry.x = area.width - geometry.width - 2 * c->border;
396 if(geometry.y > area.height)
397 geometry.y = area.height - geometry.height - 2 * c->border;
398 if(geometry.x + geometry.width + 2 * c->border < 0)
399 geometry.x = 0;
400 if(geometry.y + geometry.height + 2 * c->border < 0)
401 geometry.y = 0;
403 if(c->geometry.x != geometry.x || c->geometry.y != geometry.y
404 || c->geometry.width != geometry.width || c->geometry.height != geometry.height)
406 new_screen = get_screen_bycoord(geometry.x, geometry.y);
408 c->geometry.x = wc.x = geometry.x;
409 c->geometry.y = wc.y = geometry.y;
410 c->geometry.width = wc.width = geometry.width;
411 c->geometry.height = wc.height = geometry.height;
412 wc.border_width = c->border;
414 /* save the floating geometry if the window is floating but not
415 * maximized */
416 if((c->isfloating ||
417 get_current_layout(new_screen)->arrange == layout_floating) && !c->ismax)
418 c->f_geometry = geometry;
420 XConfigureWindow(globalconf.display, c->win,
421 CWX | CWY | CWWidth | CWHeight | CWBorderWidth, &wc);
422 window_configure(c->win, geometry, c->border);
424 if(c->screen != new_screen)
425 move_client_to_screen(c, new_screen, False);
427 return True;
429 return False;
432 void
433 client_setfloating(Client *c, Bool floating)
435 if(c->isfloating != floating)
437 if((c->isfloating = floating))
438 client_resize(c, c->f_geometry, False);
439 else if(c->ismax)
441 c->ismax = False;
442 client_resize(c, c->m_geometry, False);
444 if(client_isvisible(c, c->screen))
445 globalconf.screens[c->screen].need_arrange = True;
446 widget_invalidate_cache(c->screen, WIDGET_CACHE_CLIENTS);
447 client_saveprops(c);
451 /** Save client properties as an X property
452 * \param c client
454 void
455 client_saveprops(Client *c)
457 int i = 0, ntags = 0;
458 char *prop;
459 Tag *tag;
461 for(tag = globalconf.screens[c->screen].tags; tag; tag = tag->next)
462 ntags++;
464 prop = p_new(char, ntags + 2);
466 for(tag = globalconf.screens[c->screen].tags; tag; tag = tag->next, i++)
467 prop[i] = is_client_tagged(c, tag) ? '1' : '0';
469 if(i <= ntags)
470 prop[i] = c->isfloating ? '1' : '0';
472 prop[++i] = '\0';
474 XChangeProperty(globalconf.display, c->win,
475 XInternAtom(globalconf.display, "_AWESOME_PROPERTIES", False),
476 XA_STRING, 8, PropModeReplace, (unsigned char *) prop, i);
478 p_delete(&prop);
481 void
482 client_unban(Client *c)
484 XMapWindow(globalconf.display, c->win);
485 window_setstate(c->win, NormalState);
488 void
489 client_unmanage(Client *c)
491 XWindowChanges wc;
492 Tag *tag;
494 wc.border_width = c->oldborder;
496 /* The server grab construct avoids race conditions. */
497 XGrabServer(globalconf.display);
499 XConfigureWindow(globalconf.display, c->win, CWBorderWidth, &wc); /* restore border */
501 /* remove client everywhere */
502 client_list_detach(&globalconf.clients, c);
503 focus_delete_client(c);
504 for(tag = globalconf.screens[c->screen].tags; tag; tag = tag->next)
505 untag_client(c, tag);
507 if(globalconf.focus->client == c)
508 focus(NULL, c->screen, False);
510 XUngrabButton(globalconf.display, AnyButton, AnyModifier, c->win);
511 window_setstate(c->win, WithdrawnState);
513 XSync(globalconf.display, False);
514 XUngrabServer(globalconf.display);
516 p_delete(&c);
519 void
520 client_updatewmhints(Client *c)
522 XWMHints *wmh;
524 if((wmh = XGetWMHints(globalconf.display, c->win)))
526 if((c->isurgent = (wmh->flags & XUrgencyHint)))
527 widget_invalidate_cache(c->screen, WIDGET_CACHE_CLIENTS);
528 if((wmh->flags & StateHint) && wmh->initial_state == WithdrawnState)
530 c->border = 0;
531 c->skip = True;
533 XFree(wmh);
537 void
538 client_updatesizehints(Client *c)
540 long msize;
541 XSizeHints size;
543 if(!XGetWMNormalHints(globalconf.display, c->win, &size, &msize) || !size.flags)
544 size.flags = PSize;
545 if(size.flags & PBaseSize)
547 c->basew = size.base_width;
548 c->baseh = size.base_height;
550 else if(size.flags & PMinSize)
552 c->basew = size.min_width;
553 c->baseh = size.min_height;
555 else
556 c->basew = c->baseh = 0;
557 if(size.flags & PResizeInc)
559 c->incw = size.width_inc;
560 c->inch = size.height_inc;
562 else
563 c->incw = c->inch = 0;
565 if(size.flags & PMaxSize)
567 c->maxw = size.max_width;
568 c->maxh = size.max_height;
570 else
571 c->maxw = c->maxh = 0;
573 if(size.flags & PMinSize)
575 c->minw = size.min_width;
576 c->minh = size.min_height;
578 else if(size.flags & PBaseSize)
580 c->minw = size.base_width;
581 c->minh = size.base_height;
583 else
584 c->minw = c->minh = 0;
586 if(size.flags & PAspect)
588 c->minax = size.min_aspect.x;
589 c->maxax = size.max_aspect.x;
590 c->minay = size.min_aspect.y;
591 c->maxay = size.max_aspect.y;
593 else
594 c->minax = c->maxax = c->minay = c->maxay = 0;
596 if(c->maxw && c->minw && c->maxh && c->minh
597 && c->maxw == c->minw && c->maxh == c->minh)
598 c->isfixed = True;
601 /** Returns True if a client is tagged
602 * with one of the tags
603 * \return True or False
605 Bool
606 client_isvisible(Client *c, int screen)
608 Tag *tag;
610 if(!c || c->screen != screen)
611 return False;
613 for(tag = globalconf.screens[screen].tags; tag; tag = tag->next)
614 if(tag->selected && is_client_tagged(c, tag))
615 return True;
616 return False;
619 /** Set selected client transparency
620 * \param screen Screen ID
621 * \param arg unused arg
622 * \ingroup ui_callback
624 void
625 uicb_client_settrans(int screen __attribute__ ((unused)), char *arg)
627 double delta = 100.0, current_opacity = 100.0;
628 unsigned char *data;
629 Atom actual;
630 int format;
631 unsigned long n, left;
632 unsigned int current_opacity_raw = 0;
633 int set_prop = 0;
634 Client *sel = globalconf.focus->client;
636 if(!sel)
637 return;
639 XGetWindowProperty(globalconf.display, sel->win,
640 XInternAtom(globalconf.display, "_NET_WM_WINDOW_OPACITY", False),
641 0L, 1L, False, XA_CARDINAL, &actual, &format, &n, &left,
642 (unsigned char **) &data);
643 if(data)
645 memcpy(&current_opacity_raw, data, sizeof(unsigned int));
646 XFree(data);
647 current_opacity = (current_opacity_raw * 100.0) / 0xffffffff;
649 else
650 set_prop = 1;
652 delta = compute_new_value_from_arg(arg, current_opacity);
654 if(delta <= 0.0)
655 delta = 0.0;
656 else if(delta > 100.0)
658 delta = 100.0;
659 set_prop = 1;
662 if(delta == 100.0 && !set_prop)
663 window_settrans(sel->win, -1);
664 else
665 window_settrans(sel->win, delta);
668 static Client *
669 client_find_prev_visible(Client *sel)
671 Client *prev = NULL;
673 if(!sel) return NULL;
675 /* look for previous starting at sel */
676 for(prev = client_list_prev_cycle(&globalconf.clients, sel);
677 prev && (prev->skip || !client_isvisible(prev, sel->screen));
678 prev = client_list_prev_cycle(&globalconf.clients, prev));
680 return prev;
683 static Client *
684 client_find_next_visible(Client *sel)
686 Client *next = NULL;
688 if(!sel) return NULL;
690 for(next = sel->next; next && !client_isvisible(next, sel->screen); next = next->next);
691 if(!next)
692 for(next = globalconf.clients; next && !client_isvisible(next, sel->screen); next = next->next);
694 return next;
697 /** Swap current with previous client
698 * \param screen Screen ID
699 * \param arg nothing
700 * \ingroup ui_callback
702 void
703 uicb_client_swapprev(int screen __attribute__ ((unused)),
704 char *arg __attribute__ ((unused)))
706 Client *prev;
708 if((prev = client_find_prev_visible(globalconf.focus->client)))
710 client_list_swap(&globalconf.clients, prev, globalconf.focus->client);
711 globalconf.screens[prev->screen].need_arrange = True;
715 /** Swap current with next client
716 * \param screen Screen ID
717 * \param arg nothing
718 * \ingroup ui_callback
720 void
721 uicb_client_swapnext(int screen __attribute__ ((unused)),
722 char *arg __attribute__ ((unused)))
724 Client *next;
726 if((next = client_find_next_visible(globalconf.focus->client)))
728 client_list_swap(&globalconf.clients, globalconf.focus->client, next);
729 globalconf.screens[next->screen].need_arrange = True;
733 /** Move and resize client
734 * \param screen Screen ID
735 * \param arg x y w h
736 * \ingroup ui_callback
738 void
739 uicb_client_moveresize(int screen, char *arg)
741 int ox, oy, ow, oh;
742 char x[8], y[8], w[8], h[8];
743 int mx, my, dx, dy, nmx, nmy;
744 unsigned int dui;
745 Window dummy;
746 Area area;
747 Client *sel = globalconf.focus->client;
748 Tag **curtags = get_current_tags(screen);
750 if(curtags[0]->layout->arrange != layout_floating)
751 if(!sel || !sel->isfloating || sel->isfixed || !arg)
753 p_delete(&curtags);
754 return;
756 p_delete(&curtags);
757 if(sscanf(arg, "%s %s %s %s", x, y, w, h) != 4)
758 return;
759 area.x = (int) compute_new_value_from_arg(x, sel->geometry.x);
760 area.y = (int) compute_new_value_from_arg(y, sel->geometry.y);
761 area.width = (int) compute_new_value_from_arg(w, sel->geometry.width);
762 area.height = (int) compute_new_value_from_arg(h, sel->geometry.height);
764 ox = sel->geometry.x;
765 oy = sel->geometry.y;
766 ow = sel->geometry.width;
767 oh = sel->geometry.height;
769 Bool xqp = XQueryPointer(globalconf.display,
770 RootWindow(globalconf.display,
771 get_phys_screen(screen)),
772 &dummy, &dummy, &mx, &my, &dx, &dy, &dui);
773 client_resize(sel, area, globalconf.screens[sel->screen].resize_hints);
774 if (xqp && ox <= mx && (ox + ow) >= mx && oy <= my && (oy + oh) >= my)
776 nmx = mx - ox + sel->geometry.width - ow - 1 < 0 ? 0 : mx - ox + sel->geometry.width - ow - 1;
777 nmy = my - oy + sel->geometry.height - oh - 1 < 0 ? 0 : my - oy + sel->geometry.height - oh - 1;
778 XWarpPointer(globalconf.display,
779 None, sel->win,
780 0, 0, 0, 0, nmx, nmy);
784 void
785 client_kill(Client *c)
787 XEvent ev;
789 if(isprotodel(globalconf.display, c->win))
791 ev.type = ClientMessage;
792 ev.xclient.window = c->win;
793 ev.xclient.message_type = XInternAtom(globalconf.display, "WM_PROTOCOLS", False);
794 ev.xclient.format = 32;
795 ev.xclient.data.l[0] = XInternAtom(globalconf.display, "WM_DELETE_WINDOW", False);
796 ev.xclient.data.l[1] = CurrentTime;
797 XSendEvent(globalconf.display, c->win, False, NoEventMask, &ev);
799 else
800 XKillClient(globalconf.display, c->win);
803 /** Kill selected client
804 * \param screen Screen ID
805 * \param arg unused
806 * \ingroup ui_callback
808 void
809 uicb_client_kill(int screen __attribute__ ((unused)), char *arg __attribute__ ((unused)))
811 Client *sel = globalconf.focus->client;
813 if(sel)
814 client_kill(sel);
817 static void
818 client_maximize(Client *c, Area geometry)
821 if((c->ismax = !c->ismax))
823 c->wasfloating = c->isfloating;
824 c->m_geometry = c->geometry;
825 if(get_current_layout(c->screen)->arrange != layout_floating)
826 client_setfloating(c, True);
827 client_resize(c, geometry, False);
828 widget_invalidate_cache(c->screen, WIDGET_CACHE_CLIENTS);
830 else if(c->wasfloating)
832 client_setfloating(c, True);
833 client_resize(c, c->m_geometry, False);
834 widget_invalidate_cache(c->screen, WIDGET_CACHE_CLIENTS);
836 else if(get_current_layout(c->screen)->arrange == layout_floating)
838 client_resize(c, c->m_geometry, False);
839 widget_invalidate_cache(c->screen, WIDGET_CACHE_CLIENTS);
841 else
843 client_setfloating(c, False);
844 widget_invalidate_cache(c->screen, WIDGET_CACHE_CLIENTS);
848 /** Toggle maximize for client
849 * \param screen Screen ID
850 * \param arg Unused
851 * \ingroup ui_callback
853 void
854 uicb_client_togglemax(int screen, char *arg __attribute__ ((unused)))
856 Client *sel = globalconf.focus->client;
857 Area area = get_screen_area(screen,
858 globalconf.screens[screen].statusbar,
859 &globalconf.screens[screen].padding);
861 if(sel)
863 area.width -= 2 * sel->border;
864 area.height -= 2 * sel->border;
865 client_maximize(sel, area);
869 /** Toggle vertical maximize for client
870 * \param screen Screen ID
871 * \param arg Unused
872 * \ingroup ui_callback
874 void
875 uicb_client_toggleverticalmax(int screen, char *arg __attribute__ ((unused)))
877 Client *sel = globalconf.focus->client;
878 Area area = get_screen_area(screen,
879 globalconf.screens[screen].statusbar,
880 &globalconf.screens[screen].padding);
882 if(sel)
884 area.x = sel->geometry.x;
885 area.width = sel->geometry.width;
886 area.height -= 2 * sel->border;
887 client_maximize(sel, area);
892 /** Toggle horizontal maximize for client
893 * \param screen Screen ID
894 * \param arg Unused
895 * \ingroup ui_callback
897 void
898 uicb_client_togglehorizontalmax(int screen, char *arg __attribute__ ((unused)))
900 Client *sel = globalconf.focus->client;
901 Area area = get_screen_area(screen,
902 globalconf.screens[screen].statusbar,
903 &globalconf.screens[screen].padding);
905 if(sel)
907 area.y = sel->geometry.y;
908 area.height = sel->geometry.height;
909 area.width -= 2 * sel->border;
910 client_maximize(sel, area);
914 /** Zoom client
915 * \param screen Screen ID
916 * \param arg Unused
917 * \ingroup ui_callback
919 void
920 uicb_client_zoom(int screen, char *arg __attribute__ ((unused)))
922 Client *c, *sel = globalconf.focus->client;
924 for(c = globalconf.clients; !client_isvisible(c, screen); c = c->next);
925 if(c == sel)
926 for(sel = sel->next; sel && !client_isvisible(sel, screen); sel = sel->next);
928 if(!sel)
929 return;
931 client_list_detach(&globalconf.clients, sel);
932 client_list_push(&globalconf.clients, sel);
933 globalconf.screens[screen].need_arrange = True;
936 /** Send focus to next client in stack
937 * \param screen Screen ID
938 * \param arg Unused
939 * \ingroup ui_callback
941 void
942 uicb_client_focusnext(int screen, char *arg __attribute__ ((unused)))
944 Client *c, *sel = globalconf.focus->client;
946 if(!sel)
947 return;
948 for(c = sel->next; c && (c->skip || !client_isvisible(c, screen)); c = c->next);
949 if(!c)
950 for(c = globalconf.clients; c && (c->skip || !client_isvisible(c, screen)); c = c->next);
951 if(c)
952 focus(c, screen, False);
955 /** Send focus to previous client in stack
956 * \param screen Screen ID
957 * \param arg Unused
958 * \ingroup ui_callback
960 void
961 uicb_client_focusprev(int screen, char *arg __attribute__ ((unused)))
963 Client *prev;
965 if((prev = client_find_prev_visible(globalconf.focus->client)))
966 focus(prev, screen, False);
969 /** Toggle floating state of a client
970 * \param screen Screen ID
971 * \param arg unused
972 * \ingroup ui_callback
974 void
975 uicb_client_togglefloating(int screen __attribute__ ((unused)),
976 char *arg __attribute__ ((unused)))
978 if(globalconf.focus->client)
979 client_setfloating(globalconf.focus->client, !globalconf.focus->client->isfloating);
982 // vim: filetype=c:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=80