missing include
[awesome.git] / client.c
blobe91c51d2f69bb1fa57b5756ab95ecda6b6be584a
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 "xutil.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 client_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);
190 if(c)
192 /* save sel in focus history */
193 focus_add_client(c);
194 XSetWindowBorder(globalconf.display, c->win,
195 globalconf.screens[screen].colors_selected[ColBorder].pixel);
196 XSetInputFocus(globalconf.display, c->win, RevertToPointerRoot, CurrentTime);
197 if(!from_mouse
198 || !globalconf.screens[screen].sloppy_focus
199 || globalconf.screens[screen].sloppy_focus_raise)
200 XRaiseWindow(globalconf.display, c->win);
201 /* since we're dropping EnterWindow events and sometimes the window
202 * will appear under the mouse, grabbuttons */
203 window_grabbuttons(phys_screen, c->win);
205 else
206 XSetInputFocus(globalconf.display,
207 RootWindow(globalconf.display, phys_screen),
208 RevertToPointerRoot, CurrentTime);
210 widget_invalidate_cache(screen, WIDGET_CACHE_CLIENTS);
211 ewmh_update_net_active_window(phys_screen);
212 globalconf.drop_events |= EnterWindowMask;
215 /** Manage a new client
216 * \param w The window
217 * \param wa Window attributes
218 * \param screen Screen ID
220 void
221 client_manage(Window w, XWindowAttributes *wa, int screen)
223 Client *c, *t = NULL;
224 Window trans;
225 Bool rettrans;
226 XWindowChanges wc;
227 Tag *tag;
228 Rule *rule;
229 Area screen_geom;
230 int phys_screen = get_phys_screen(screen);
232 c = p_new(Client, 1);
234 c->screen = get_screen_bycoord(wa->x, wa->y);
236 screen_geom = get_display_area(phys_screen,
237 globalconf.screens[c->screen].statusbar,
238 &globalconf.screens[c->screen].padding);
239 /* Initial values */
240 c->win = w;
241 c->geometry.x = c->f_geometry.x = c->m_geometry.x = MAX(wa->x, screen_geom.x);
242 c->geometry.y = c->f_geometry.y = c->m_geometry.y = MAX(wa->y, screen_geom.y);
243 c->geometry.width = c->f_geometry.width = c->m_geometry.width = wa->width;
244 c->geometry.height = c->f_geometry.height = c->m_geometry.height = wa->height;
245 c->oldborder = wa->border_width;
246 c->newcomer = True;
248 c->border = globalconf.screens[screen].borderpx;
250 /* Set windows borders */
251 wc.border_width = c->border;
252 XConfigureWindow(globalconf.display, w, CWBorderWidth, &wc);
253 XSetWindowBorder(globalconf.display, w, globalconf.screens[screen].colors_normal[ColBorder].pixel);
254 /* propagates border_width, if size doesn't change */
255 window_configure(c->win, c->geometry, c->border);
257 /* update window title */
258 client_updatetitle(c);
260 /* update hints */
261 client_updatesizehints(c);
262 client_updatewmhints(c);
264 /* First check clients hints */
265 ewmh_check_client_hints(c);
267 /* loadprops or apply rules if no props */
268 if(!client_loadprops(c, screen))
270 /* Get the client's rule */
271 if((rule = rule_matching_client(c)))
273 if(rule->screen != RULE_NOSCREEN)
274 move_client_to_screen(c, rule->screen, True);
275 else
276 move_client_to_screen(c, screen, True);
277 tag_client_with_rule(c, rule);
279 switch(rule->isfloating)
281 case Auto:
282 break;
283 case Float:
284 client_setfloating(c, True);
285 break;
286 case Tile:
287 client_setfloating(c, False);
288 break;
291 if(rule->opacity >= 0.0f)
292 window_settrans(c->win, rule->opacity);
294 else
295 move_client_to_screen(c, screen, True);
296 /* check for transient and set tags like its parent,
297 * XGetTransientForHint returns 1 on success
299 if((rettrans = XGetTransientForHint(globalconf.display, w, &trans))
300 && (t = get_client_bywin(globalconf.clients, trans)))
301 for(tag = globalconf.screens[c->screen].tags; tag; tag = tag->next)
302 if(is_client_tagged(t, tag))
303 tag_client(c, tag);
305 /* should be floating if transsient or fixed */
306 if(!c->isfloating)
307 client_setfloating(c, rettrans || c->isfixed);
310 XSelectInput(globalconf.display, w, StructureNotifyMask | PropertyChangeMask | EnterWindowMask);
312 /* handle xshape */
313 if(globalconf.have_shape)
315 XShapeSelectInput(globalconf.display, w, ShapeNotifyMask);
316 window_setshape(phys_screen, c->win);
319 /* attach to the stack */
320 if((rule = rule_matching_client(c)) && rule->not_master)
321 client_list_append(&globalconf.clients, c);
322 else if(globalconf.screens[c->screen].new_become_master)
323 client_list_push(&globalconf.clients, c);
324 else
325 client_list_append(&globalconf.clients, c);
327 /* some windows require this */
328 XMoveResizeWindow(globalconf.display, c->win, c->geometry.x, c->geometry.y,
329 c->geometry.width, c->geometry.height);
331 widget_invalidate_cache(c->screen, WIDGET_CACHE_CLIENTS);
332 ewmh_update_net_client_list(phys_screen);
335 /** Resize client window
336 * \param c client to resize
337 * \param geometry new window geometry
338 * \param sizehints respect size hints
339 * \param return True if resize has been done
341 Bool
342 client_resize(Client *c, Area geometry, Bool sizehints)
344 int new_screen;
345 double dx, dy, max, min, ratio;
346 Area area;
347 XWindowChanges wc;
349 if(sizehints)
351 if(c->minay > 0 && c->maxay > 0 && (geometry.height - c->baseh) > 0
352 && (geometry.width - c->basew) > 0)
354 dx = (double) (geometry.width - c->basew);
355 dy = (double) (geometry.height - c->baseh);
356 min = (double) (c->minax) / (double) (c->minay);
357 max = (double) (c->maxax) / (double) (c->maxay);
358 ratio = dx / dy;
359 if(max > 0 && min > 0 && ratio > 0)
361 if(ratio < min)
363 dy = (dx * min + dy) / (min * min + 1);
364 dx = dy * min;
365 geometry.width = (int) dx + c->basew;
366 geometry.height = (int) dy + c->baseh;
368 else if(ratio > max)
370 dy = (dx * min + dy) / (max * max + 1);
371 dx = dy * min;
372 geometry.width = (int) dx + c->basew;
373 geometry.height = (int) dy + c->baseh;
377 if(c->minw && geometry.width < c->minw)
378 geometry.width = c->minw;
379 if(c->minh && geometry.height < c->minh)
380 geometry.height = c->minh;
381 if(c->maxw && geometry.width > c->maxw)
382 geometry.width = c->maxw;
383 if(c->maxh && geometry.height > c->maxh)
384 geometry.height = c->maxh;
385 if(c->incw)
386 geometry.width -= (geometry.width - c->basew) % c->incw;
387 if(c->inch)
388 geometry.height -= (geometry.height - c->baseh) % c->inch;
390 if(geometry.width <= 0 || geometry.height <= 0)
391 return False;
392 /* offscreen appearance fixes */
393 area = get_display_area(get_phys_screen(c->screen),
394 NULL,
395 &globalconf.screens[c->screen].padding);
396 if(geometry.x > area.width)
397 geometry.x = area.width - geometry.width - 2 * c->border;
398 if(geometry.y > area.height)
399 geometry.y = area.height - geometry.height - 2 * c->border;
400 if(geometry.x + geometry.width + 2 * c->border < 0)
401 geometry.x = 0;
402 if(geometry.y + geometry.height + 2 * c->border < 0)
403 geometry.y = 0;
405 if(c->geometry.x != geometry.x || c->geometry.y != geometry.y
406 || c->geometry.width != geometry.width || c->geometry.height != geometry.height)
408 new_screen = get_screen_bycoord(geometry.x, geometry.y);
410 c->geometry.x = wc.x = geometry.x;
411 c->geometry.y = wc.y = geometry.y;
412 c->geometry.width = wc.width = geometry.width;
413 c->geometry.height = wc.height = geometry.height;
414 wc.border_width = c->border;
416 /* save the floating geometry if the window is floating but not
417 * maximized */
418 if((c->isfloating ||
419 get_current_layout(new_screen)->arrange == layout_floating) && !c->ismax)
420 c->f_geometry = geometry;
422 XConfigureWindow(globalconf.display, c->win,
423 CWX | CWY | CWWidth | CWHeight | CWBorderWidth, &wc);
424 window_configure(c->win, geometry, c->border);
426 if(c->screen != new_screen)
427 move_client_to_screen(c, new_screen, False);
429 return True;
431 return False;
434 void
435 client_setfloating(Client *c, Bool floating)
437 if(c->isfloating != floating)
439 if((c->isfloating = floating))
440 client_resize(c, c->f_geometry, False);
441 else if(c->ismax)
443 c->ismax = False;
444 client_resize(c, c->m_geometry, False);
446 if(client_isvisible(c, c->screen))
447 globalconf.screens[c->screen].need_arrange = True;
448 widget_invalidate_cache(c->screen, WIDGET_CACHE_CLIENTS);
449 client_saveprops(c);
453 /** Save client properties as an X property
454 * \param c client
456 void
457 client_saveprops(Client *c)
459 int i = 0, ntags = 0;
460 char *prop;
461 Tag *tag;
463 for(tag = globalconf.screens[c->screen].tags; tag; tag = tag->next)
464 ntags++;
466 prop = p_new(char, ntags + 2);
468 for(tag = globalconf.screens[c->screen].tags; tag; tag = tag->next, i++)
469 prop[i] = is_client_tagged(c, tag) ? '1' : '0';
471 if(i <= ntags)
472 prop[i] = c->isfloating ? '1' : '0';
474 prop[++i] = '\0';
476 XChangeProperty(globalconf.display, c->win,
477 XInternAtom(globalconf.display, "_AWESOME_PROPERTIES", False),
478 XA_STRING, 8, PropModeReplace, (unsigned char *) prop, i);
480 p_delete(&prop);
483 void
484 client_unban(Client *c)
486 XMapWindow(globalconf.display, c->win);
487 window_setstate(c->win, NormalState);
490 void
491 client_unmanage(Client *c)
493 XWindowChanges wc;
494 Tag *tag;
496 wc.border_width = c->oldborder;
498 /* The server grab construct avoids race conditions. */
499 XGrabServer(globalconf.display);
501 XConfigureWindow(globalconf.display, c->win, CWBorderWidth, &wc); /* restore border */
503 /* remove client everywhere */
504 client_list_detach(&globalconf.clients, c);
505 focus_delete_client(c);
506 for(tag = globalconf.screens[c->screen].tags; tag; tag = tag->next)
507 untag_client(c, tag);
509 if(globalconf.focus->client == c)
510 client_focus(NULL, c->screen, False);
512 XUngrabButton(globalconf.display, AnyButton, AnyModifier, c->win);
513 window_setstate(c->win, WithdrawnState);
515 XSync(globalconf.display, False);
516 XUngrabServer(globalconf.display);
518 p_delete(&c);
521 void
522 client_updatewmhints(Client *c)
524 XWMHints *wmh;
526 if((wmh = XGetWMHints(globalconf.display, c->win)))
528 if((c->isurgent = (wmh->flags & XUrgencyHint)))
529 widget_invalidate_cache(c->screen, WIDGET_CACHE_CLIENTS);
530 if((wmh->flags & StateHint) && wmh->initial_state == WithdrawnState)
532 c->border = 0;
533 c->skip = True;
535 XFree(wmh);
539 void
540 client_updatesizehints(Client *c)
542 long msize;
543 XSizeHints size;
545 if(!XGetWMNormalHints(globalconf.display, c->win, &size, &msize) || !size.flags)
546 size.flags = PSize;
547 if(size.flags & PBaseSize)
549 c->basew = size.base_width;
550 c->baseh = size.base_height;
552 else if(size.flags & PMinSize)
554 c->basew = size.min_width;
555 c->baseh = size.min_height;
557 else
558 c->basew = c->baseh = 0;
559 if(size.flags & PResizeInc)
561 c->incw = size.width_inc;
562 c->inch = size.height_inc;
564 else
565 c->incw = c->inch = 0;
567 if(size.flags & PMaxSize)
569 c->maxw = size.max_width;
570 c->maxh = size.max_height;
572 else
573 c->maxw = c->maxh = 0;
575 if(size.flags & PMinSize)
577 c->minw = size.min_width;
578 c->minh = size.min_height;
580 else if(size.flags & PBaseSize)
582 c->minw = size.base_width;
583 c->minh = size.base_height;
585 else
586 c->minw = c->minh = 0;
588 if(size.flags & PAspect)
590 c->minax = size.min_aspect.x;
591 c->maxax = size.max_aspect.x;
592 c->minay = size.min_aspect.y;
593 c->maxay = size.max_aspect.y;
595 else
596 c->minax = c->maxax = c->minay = c->maxay = 0;
598 if(c->maxw && c->minw && c->maxh && c->minh
599 && c->maxw == c->minw && c->maxh == c->minh)
600 c->isfixed = True;
603 /** Returns True if a client is tagged
604 * with one of the tags
605 * \return True or False
607 Bool
608 client_isvisible(Client *c, int screen)
610 Tag *tag;
612 if(!c || c->screen != screen)
613 return False;
615 for(tag = globalconf.screens[screen].tags; tag; tag = tag->next)
616 if(tag->selected && is_client_tagged(c, tag))
617 return True;
618 return False;
621 /** Set selected client transparency
622 * \param screen Screen ID
623 * \param arg unused arg
624 * \ingroup ui_callback
626 void
627 uicb_client_settrans(int screen __attribute__ ((unused)), char *arg)
629 double delta = 100.0, current_opacity = 100.0;
630 unsigned char *data;
631 Atom actual;
632 int format;
633 unsigned long n, left;
634 unsigned int current_opacity_raw = 0;
635 int set_prop = 0;
636 Client *sel = globalconf.focus->client;
638 if(!sel)
639 return;
641 XGetWindowProperty(globalconf.display, sel->win,
642 XInternAtom(globalconf.display, "_NET_WM_WINDOW_OPACITY", False),
643 0L, 1L, False, XA_CARDINAL, &actual, &format, &n, &left,
644 (unsigned char **) &data);
645 if(data)
647 memcpy(&current_opacity_raw, data, sizeof(unsigned int));
648 XFree(data);
649 current_opacity = (current_opacity_raw * 100.0) / 0xffffffff;
651 else
652 set_prop = 1;
654 delta = compute_new_value_from_arg(arg, current_opacity);
656 if(delta <= 0.0)
657 delta = 0.0;
658 else if(delta > 100.0)
660 delta = 100.0;
661 set_prop = 1;
664 if(delta == 100.0 && !set_prop)
665 window_settrans(sel->win, -1);
666 else
667 window_settrans(sel->win, delta);
670 static Client *
671 client_find_prev_visible(Client *sel)
673 Client *prev = NULL;
675 if(!sel) return NULL;
677 /* look for previous starting at sel */
678 for(prev = client_list_prev_cycle(&globalconf.clients, sel);
679 prev && (prev->skip || !client_isvisible(prev, sel->screen));
680 prev = client_list_prev_cycle(&globalconf.clients, prev));
682 return prev;
685 static Client *
686 client_find_next_visible(Client *sel)
688 Client *next = NULL;
690 if(!sel) return NULL;
692 for(next = sel->next; next && !client_isvisible(next, sel->screen); next = next->next);
693 if(!next)
694 for(next = globalconf.clients; next && !client_isvisible(next, sel->screen); next = next->next);
696 return next;
699 /** Swap current with previous client
700 * \param screen Screen ID
701 * \param arg nothing
702 * \ingroup ui_callback
704 void
705 uicb_client_swapprev(int screen __attribute__ ((unused)),
706 char *arg __attribute__ ((unused)))
708 Client *prev;
710 if((prev = client_find_prev_visible(globalconf.focus->client)))
712 client_list_swap(&globalconf.clients, prev, globalconf.focus->client);
713 globalconf.screens[prev->screen].need_arrange = True;
717 /** Swap current with next client
718 * \param screen Screen ID
719 * \param arg nothing
720 * \ingroup ui_callback
722 void
723 uicb_client_swapnext(int screen __attribute__ ((unused)),
724 char *arg __attribute__ ((unused)))
726 Client *next;
728 if((next = client_find_next_visible(globalconf.focus->client)))
730 client_list_swap(&globalconf.clients, globalconf.focus->client, next);
731 globalconf.screens[next->screen].need_arrange = True;
735 /** Move and resize client
736 * \param screen Screen ID
737 * \param arg x y w h
738 * \ingroup ui_callback
740 void
741 uicb_client_moveresize(int screen, char *arg)
743 int ox, oy, ow, oh;
744 char x[8], y[8], w[8], h[8];
745 int mx, my, dx, dy, nmx, nmy;
746 unsigned int dui;
747 Window dummy;
748 Area area;
749 Client *sel = globalconf.focus->client;
750 Tag **curtags = get_current_tags(screen);
752 if(curtags[0]->layout->arrange != layout_floating)
753 if(!sel || !sel->isfloating || sel->isfixed || !arg)
755 p_delete(&curtags);
756 return;
758 p_delete(&curtags);
759 if(sscanf(arg, "%s %s %s %s", x, y, w, h) != 4)
760 return;
761 area.x = (int) compute_new_value_from_arg(x, sel->geometry.x);
762 area.y = (int) compute_new_value_from_arg(y, sel->geometry.y);
763 area.width = (int) compute_new_value_from_arg(w, sel->geometry.width);
764 area.height = (int) compute_new_value_from_arg(h, sel->geometry.height);
766 ox = sel->geometry.x;
767 oy = sel->geometry.y;
768 ow = sel->geometry.width;
769 oh = sel->geometry.height;
771 Bool xqp = XQueryPointer(globalconf.display,
772 RootWindow(globalconf.display,
773 get_phys_screen(screen)),
774 &dummy, &dummy, &mx, &my, &dx, &dy, &dui);
775 client_resize(sel, area, globalconf.screens[sel->screen].resize_hints);
776 if (xqp && ox <= mx && (ox + ow) >= mx && oy <= my && (oy + oh) >= my)
778 nmx = mx - ox + sel->geometry.width - ow - 1 < 0 ? 0 : mx - ox + sel->geometry.width - ow - 1;
779 nmy = my - oy + sel->geometry.height - oh - 1 < 0 ? 0 : my - oy + sel->geometry.height - oh - 1;
780 XWarpPointer(globalconf.display,
781 None, sel->win,
782 0, 0, 0, 0, nmx, nmy);
786 void
787 client_kill(Client *c)
789 XEvent ev;
791 if(isprotodel(globalconf.display, c->win))
793 ev.type = ClientMessage;
794 ev.xclient.window = c->win;
795 ev.xclient.message_type = XInternAtom(globalconf.display, "WM_PROTOCOLS", False);
796 ev.xclient.format = 32;
797 ev.xclient.data.l[0] = XInternAtom(globalconf.display, "WM_DELETE_WINDOW", False);
798 ev.xclient.data.l[1] = CurrentTime;
799 XSendEvent(globalconf.display, c->win, False, NoEventMask, &ev);
801 else
802 XKillClient(globalconf.display, c->win);
805 /** Kill selected client
806 * \param screen Screen ID
807 * \param arg unused
808 * \ingroup ui_callback
810 void
811 uicb_client_kill(int screen __attribute__ ((unused)), char *arg __attribute__ ((unused)))
813 Client *sel = globalconf.focus->client;
815 if(sel)
816 client_kill(sel);
819 static void
820 client_maximize(Client *c, Area geometry)
823 if((c->ismax = !c->ismax))
825 c->wasfloating = c->isfloating;
826 c->m_geometry = c->geometry;
827 if(get_current_layout(c->screen)->arrange != layout_floating)
828 client_setfloating(c, True);
829 client_resize(c, geometry, False);
830 widget_invalidate_cache(c->screen, WIDGET_CACHE_CLIENTS);
832 else if(c->wasfloating)
834 client_setfloating(c, True);
835 client_resize(c, c->m_geometry, False);
836 widget_invalidate_cache(c->screen, WIDGET_CACHE_CLIENTS);
838 else if(get_current_layout(c->screen)->arrange == layout_floating)
840 client_resize(c, c->m_geometry, False);
841 widget_invalidate_cache(c->screen, WIDGET_CACHE_CLIENTS);
843 else
845 client_setfloating(c, False);
846 widget_invalidate_cache(c->screen, WIDGET_CACHE_CLIENTS);
850 /** Toggle maximize for client
851 * \param screen Screen ID
852 * \param arg Unused
853 * \ingroup ui_callback
855 void
856 uicb_client_togglemax(int screen, char *arg __attribute__ ((unused)))
858 Client *sel = globalconf.focus->client;
859 Area area = get_screen_area(screen,
860 globalconf.screens[screen].statusbar,
861 &globalconf.screens[screen].padding);
863 if(sel)
865 area.width -= 2 * sel->border;
866 area.height -= 2 * sel->border;
867 client_maximize(sel, area);
871 /** Toggle vertical maximize for client
872 * \param screen Screen ID
873 * \param arg Unused
874 * \ingroup ui_callback
876 void
877 uicb_client_toggleverticalmax(int screen, char *arg __attribute__ ((unused)))
879 Client *sel = globalconf.focus->client;
880 Area area = get_screen_area(screen,
881 globalconf.screens[screen].statusbar,
882 &globalconf.screens[screen].padding);
884 if(sel)
886 area.x = sel->geometry.x;
887 area.width = sel->geometry.width;
888 area.height -= 2 * sel->border;
889 client_maximize(sel, area);
894 /** Toggle horizontal maximize for client
895 * \param screen Screen ID
896 * \param arg Unused
897 * \ingroup ui_callback
899 void
900 uicb_client_togglehorizontalmax(int screen, char *arg __attribute__ ((unused)))
902 Client *sel = globalconf.focus->client;
903 Area area = get_screen_area(screen,
904 globalconf.screens[screen].statusbar,
905 &globalconf.screens[screen].padding);
907 if(sel)
909 area.y = sel->geometry.y;
910 area.height = sel->geometry.height;
911 area.width -= 2 * sel->border;
912 client_maximize(sel, area);
916 /** Zoom client
917 * \param screen Screen ID
918 * \param arg Unused
919 * \ingroup ui_callback
921 void
922 uicb_client_zoom(int screen, char *arg __attribute__ ((unused)))
924 Client *c, *sel = globalconf.focus->client;
926 for(c = globalconf.clients; !client_isvisible(c, screen); c = c->next);
927 if(c == sel)
928 for(sel = sel->next; sel && !client_isvisible(sel, screen); sel = sel->next);
930 if(!sel)
931 return;
933 client_list_detach(&globalconf.clients, sel);
934 client_list_push(&globalconf.clients, sel);
935 globalconf.screens[screen].need_arrange = True;
938 /** Send focus to next client in stack
939 * \param screen Screen ID
940 * \param arg Unused
941 * \ingroup ui_callback
943 void
944 uicb_client_focusnext(int screen, char *arg __attribute__ ((unused)))
946 Client *c, *sel = globalconf.focus->client;
948 if(!sel)
949 return;
950 for(c = sel->next; c && (c->skip || !client_isvisible(c, screen)); c = c->next);
951 if(!c)
952 for(c = globalconf.clients; c && (c->skip || !client_isvisible(c, screen)); c = c->next);
953 if(c)
954 client_focus(c, screen, False);
957 /** Send focus to previous client in stack
958 * \param screen Screen ID
959 * \param arg Unused
960 * \ingroup ui_callback
962 void
963 uicb_client_focusprev(int screen, char *arg __attribute__ ((unused)))
965 Client *prev;
967 if((prev = client_find_prev_visible(globalconf.focus->client)))
968 client_focus(prev, screen, False);
971 /** Toggle floating state of a client
972 * \param screen Screen ID
973 * \param arg unused
974 * \ingroup ui_callback
976 void
977 uicb_client_togglefloating(int screen __attribute__ ((unused)),
978 char *arg __attribute__ ((unused)))
980 if(globalconf.focus->client)
981 client_setfloating(globalconf.focus->client, !globalconf.focus->client->isfloating);
984 // vim: filetype=c:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=80