textbox width is limited to unused space
[awesome.git] / client.c
blobf932f80ad8e36f13627416244b1e003c3c6f67ec
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 /** Ban client and unmap it
148 * \param c the client
150 void
151 client_ban(Client * c)
153 XUnmapWindow(globalconf.display, c->win);
154 window_setstate(c->win, IconicState);
157 /** Give focus to client, or to first client if c is NULL
158 * \param c client
159 * \param selscreen True if current screen is selected
160 * \param screen Screen ID
162 void
163 focus(Client *c, Bool selscreen, int screen)
165 int phys_screen = get_phys_screen(screen);
167 /* unfocus current selected client */
168 if(globalconf.focus->client)
170 widget_invalidate_cache(globalconf.focus->client->screen, WIDGET_CACHE_CLIENTS);
171 window_grabbuttons(get_phys_screen(globalconf.focus->client->screen),
172 globalconf.focus->client->win, False, True);
173 XSetWindowBorder(globalconf.display, globalconf.focus->client->win,
174 globalconf.screens[screen].colors_normal[ColBorder].pixel);
175 window_settrans(globalconf.focus->client->win,
176 globalconf.screens[screen].opacity_unfocused);
180 /* if c is NULL or invisible, take next client in the focus history */
181 if((!c && selscreen) || (c && !client_isvisible(c, screen)))
183 c = focus_get_current_client(screen);
184 /* if c is still NULL take next client in the stack */
185 if(!c)
186 for(c = globalconf.clients; c && (c->skip || !client_isvisible(c, screen)); c = c->next);
189 if(c)
191 XSetWindowBorder(globalconf.display, c->win, globalconf.screens[screen].colors_selected[ColBorder].pixel);
192 window_grabbuttons(phys_screen, c->win, True, True);
195 if(!selscreen)
196 return;
198 /* save sel in focus history */
199 focus_add_client(c);
201 if(globalconf.focus->client)
203 widget_invalidate_cache(screen, WIDGET_CACHE_CLIENTS);
204 XSetInputFocus(globalconf.display,
205 globalconf.focus->client->win, RevertToPointerRoot, CurrentTime);
206 for(c = globalconf.clients; c; c = c->next)
207 if(c != globalconf.focus->client)
208 window_settrans(globalconf.focus->client->win,
209 globalconf.screens[screen].opacity_unfocused);
210 window_settrans(globalconf.focus->client->win, -1);
211 restack(screen);
213 else
214 XSetInputFocus(globalconf.display,
215 RootWindow(globalconf.display, phys_screen),
216 RevertToPointerRoot, CurrentTime);
218 ewmh_update_net_active_window(phys_screen);
219 globalconf.drop_events |= EnterWindowMask;
222 /** Manage a new client
223 * \param w The window
224 * \param wa Window attributes
225 * \param screen Screen ID
227 void
228 client_manage(Window w, XWindowAttributes *wa, int screen)
230 Client *c, *t = NULL;
231 Window trans;
232 Bool rettrans;
233 XWindowChanges wc;
234 Tag *tag;
235 Rule *rule;
236 Area screen_geom;
237 int phys_screen = get_phys_screen(screen);
239 c = p_new(Client, 1);
241 c->screen = get_screen_bycoord(wa->x, wa->y);
243 screen_geom = get_display_area(phys_screen,
244 globalconf.screens[c->screen].statusbar,
245 &globalconf.screens[c->screen].padding);
246 /* Initial values */
247 c->win = w;
248 c->geometry.x = c->f_geometry.x = c->m_geometry.x = MAX(wa->x, screen_geom.x);
249 c->geometry.y = c->f_geometry.y = c->m_geometry.y = MAX(wa->y, screen_geom.y);
250 c->geometry.width = c->f_geometry.width = c->m_geometry.width = wa->width;
251 c->geometry.height = c->f_geometry.height = c->m_geometry.height = wa->height;
252 c->oldborder = wa->border_width;
253 c->newcomer = True;
255 c->border = globalconf.screens[screen].borderpx;
257 /* Set windows borders */
258 wc.border_width = c->border;
259 XConfigureWindow(globalconf.display, w, CWBorderWidth, &wc);
260 XSetWindowBorder(globalconf.display, w, globalconf.screens[screen].colors_normal[ColBorder].pixel);
261 /* propagates border_width, if size doesn't change */
262 window_configure(c->win, c->geometry, c->border);
264 /* update window title */
265 client_updatetitle(c);
267 /* update hints */
268 client_updatesizehints(c);
269 client_updatewmhints(c);
271 /* First check clients hints */
272 ewmh_check_client_hints(c);
274 /* loadprops or apply rules if no props */
275 if(!client_loadprops(c, screen))
277 /* Get the client's rule */
278 if((rule = rule_matching_client(c)))
280 if(rule->screen != RULE_NOSCREEN)
281 move_client_to_screen(c, rule->screen, True);
282 else
283 move_client_to_screen(c, screen, True);
284 tag_client_with_rule(c, rule);
286 switch(rule->isfloating)
288 case Auto:
289 break;
290 case Float:
291 client_setfloating(c, True);
292 break;
293 case Tile:
294 client_setfloating(c, False);
295 break;
298 else
299 move_client_to_screen(c, screen, True);
300 /* check for transient and set tags like its parent,
301 * XGetTransientForHint returns 1 on success
303 if((rettrans = XGetTransientForHint(globalconf.display, w, &trans))
304 && (t = get_client_bywin(globalconf.clients, trans)))
305 for(tag = globalconf.screens[c->screen].tags; tag; tag = tag->next)
306 if(is_client_tagged(t, tag))
307 tag_client(c, tag);
309 /* should be floating if transsient or fixed */
310 if(!c->isfloating)
311 client_setfloating(c, rettrans || c->isfixed);
314 XSelectInput(globalconf.display, w, StructureNotifyMask | PropertyChangeMask | EnterWindowMask);
315 window_grabbuttons(phys_screen, c->win, False, True);
317 /* handle xshape */
318 if(globalconf.have_shape)
320 XShapeSelectInput(globalconf.display, w, ShapeNotifyMask);
321 window_setshape(phys_screen, c->win);
324 /* save new props */
325 client_saveprops(c);
327 /* attach to the stack */
328 if((rule = rule_matching_client(c)) && rule->not_master)
329 client_list_append(&globalconf.clients, c);
330 else if(globalconf.screens[c->screen].new_become_master)
331 client_list_push(&globalconf.clients, c);
332 else
333 client_list_append(&globalconf.clients, c);
335 /* focus ? */
336 if(globalconf.screens[c->screen].new_get_focus)
337 focus(c, True, c->screen);
339 /* some windows require this */
340 XMoveResizeWindow(globalconf.display, c->win, c->geometry.x, c->geometry.y,
341 c->geometry.width, c->geometry.height);
343 widget_invalidate_cache(c->screen, WIDGET_CACHE_CLIENTS);
344 ewmh_update_net_client_list(phys_screen);
347 /** Resize client window
348 * \param c client to resize
349 * \param geometry new window geometry
350 * \param sizehints respect size hints
351 * \param return True if resize has been done
353 Bool
354 client_resize(Client *c, Area geometry, Bool sizehints)
356 int new_screen;
357 double dx, dy, max, min, ratio;
358 Area area;
359 XWindowChanges wc;
361 if(sizehints)
363 if(c->minay > 0 && c->maxay > 0 && (geometry.height - c->baseh) > 0
364 && (geometry.width - c->basew) > 0)
366 dx = (double) (geometry.width - c->basew);
367 dy = (double) (geometry.height - c->baseh);
368 min = (double) (c->minax) / (double) (c->minay);
369 max = (double) (c->maxax) / (double) (c->maxay);
370 ratio = dx / dy;
371 if(max > 0 && min > 0 && ratio > 0)
373 if(ratio < min)
375 dy = (dx * min + dy) / (min * min + 1);
376 dx = dy * min;
377 geometry.width = (int) dx + c->basew;
378 geometry.height = (int) dy + c->baseh;
380 else if(ratio > max)
382 dy = (dx * min + dy) / (max * max + 1);
383 dx = dy * min;
384 geometry.width = (int) dx + c->basew;
385 geometry.height = (int) dy + c->baseh;
389 if(c->minw && geometry.width < c->minw)
390 geometry.width = c->minw;
391 if(c->minh && geometry.height < c->minh)
392 geometry.height = c->minh;
393 if(c->maxw && geometry.width > c->maxw)
394 geometry.width = c->maxw;
395 if(c->maxh && geometry.height > c->maxh)
396 geometry.height = c->maxh;
397 if(c->incw)
398 geometry.width -= (geometry.width - c->basew) % c->incw;
399 if(c->inch)
400 geometry.height -= (geometry.height - c->baseh) % c->inch;
402 if(geometry.width <= 0 || geometry.height <= 0)
403 return False;
404 /* offscreen appearance fixes */
405 area = get_display_area(get_phys_screen(c->screen),
406 NULL,
407 &globalconf.screens[c->screen].padding);
408 if(geometry.x > area.width)
409 geometry.x = area.width - geometry.width - 2 * c->border;
410 if(geometry.y > area.height)
411 geometry.y = area.height - geometry.height - 2 * c->border;
412 if(geometry.x + geometry.width + 2 * c->border < 0)
413 geometry.x = 0;
414 if(geometry.y + geometry.height + 2 * c->border < 0)
415 geometry.y = 0;
417 if(c->geometry.x != geometry.x || c->geometry.y != geometry.y
418 || c->geometry.width != geometry.width || c->geometry.height != geometry.height)
420 new_screen = get_screen_bycoord(geometry.x, geometry.y);
422 c->geometry.x = wc.x = geometry.x;
423 c->geometry.y = wc.y = geometry.y;
424 c->geometry.width = wc.width = geometry.width;
425 c->geometry.height = wc.height = geometry.height;
426 wc.border_width = c->border;
428 /* save the floating geometry if the window is floating but not
429 * maximized */
430 if((c->isfloating ||
431 get_current_layout(new_screen)->arrange == layout_floating) && !c->ismax)
432 c->f_geometry = geometry;
434 XConfigureWindow(globalconf.display, c->win,
435 CWX | CWY | CWWidth | CWHeight | CWBorderWidth, &wc);
436 window_configure(c->win, geometry, c->border);
438 if(c->screen != new_screen)
439 move_client_to_screen(c, new_screen, False);
441 return True;
443 return False;
446 void
447 client_setfloating(Client *c, Bool floating)
449 if(c->isfloating != floating)
451 if((c->isfloating = floating))
452 client_resize(c, c->f_geometry, False);
453 if(client_isvisible(c, c->screen))
454 globalconf.screens[c->screen].need_arrange = True;
455 widget_invalidate_cache(c->screen, WIDGET_CACHE_CLIENTS);
459 /** Save client properties as an X property
460 * \param c client
462 void
463 client_saveprops(Client *c)
465 int i = 0, ntags = 0;
466 char *prop;
467 Tag *tag;
469 for(tag = globalconf.screens[c->screen].tags; tag; tag = tag->next)
470 ntags++;
472 prop = p_new(char, ntags + 2);
474 for(tag = globalconf.screens[c->screen].tags; tag; tag = tag->next, i++)
475 prop[i] = is_client_tagged(c, tag) ? '1' : '0';
477 if(i <= ntags)
478 prop[i] = c->isfloating ? '1' : '0';
480 prop[++i] = '\0';
482 XChangeProperty(globalconf.display, c->win,
483 XInternAtom(globalconf.display, "_AWESOME_PROPERTIES", False),
484 XA_STRING, 8, PropModeReplace, (unsigned char *) prop, i);
486 p_delete(&prop);
489 void
490 client_unban(Client *c)
492 XMapWindow(globalconf.display, c->win);
493 window_setstate(c->win, NormalState);
496 void
497 client_unmanage(Client *c)
499 XWindowChanges wc;
500 Tag *tag;
502 wc.border_width = c->oldborder;
504 /* The server grab construct avoids race conditions. */
505 XGrabServer(globalconf.display);
507 XConfigureWindow(globalconf.display, c->win, CWBorderWidth, &wc); /* restore border */
509 /* remove client everywhere */
510 client_list_detach(&globalconf.clients, c);
511 focus_delete_client(c);
512 for(tag = globalconf.screens[c->screen].tags; tag; tag = tag->next)
513 untag_client(c, tag);
515 if(globalconf.focus->client == c)
516 focus(NULL, True, c->screen);
518 XUngrabButton(globalconf.display, AnyButton, AnyModifier, c->win);
519 window_setstate(c->win, WithdrawnState);
521 XSync(globalconf.display, False);
522 XUngrabServer(globalconf.display);
524 p_delete(&c);
527 void
528 client_updatewmhints(Client *c)
530 XWMHints *wmh;
532 if((wmh = XGetWMHints(globalconf.display, c->win)))
534 if((c->isurgent = (wmh->flags & XUrgencyHint)))
535 widget_invalidate_cache(c->screen, WIDGET_CACHE_CLIENTS);
536 if((wmh->flags & StateHint) && wmh->initial_state == WithdrawnState)
538 c->border = 0;
539 c->skip = True;
541 XFree(wmh);
545 void
546 client_updatesizehints(Client *c)
548 long msize;
549 XSizeHints size;
551 if(!XGetWMNormalHints(globalconf.display, c->win, &size, &msize) || !size.flags)
552 size.flags = PSize;
553 if(size.flags & PBaseSize)
555 c->basew = size.base_width;
556 c->baseh = size.base_height;
558 else if(size.flags & PMinSize)
560 c->basew = size.min_width;
561 c->baseh = size.min_height;
563 else
564 c->basew = c->baseh = 0;
565 if(size.flags & PResizeInc)
567 c->incw = size.width_inc;
568 c->inch = size.height_inc;
570 else
571 c->incw = c->inch = 0;
573 if(size.flags & PMaxSize)
575 c->maxw = size.max_width;
576 c->maxh = size.max_height;
578 else
579 c->maxw = c->maxh = 0;
581 if(size.flags & PMinSize)
583 c->minw = size.min_width;
584 c->minh = size.min_height;
586 else if(size.flags & PBaseSize)
588 c->minw = size.base_width;
589 c->minh = size.base_height;
591 else
592 c->minw = c->minh = 0;
594 if(size.flags & PAspect)
596 c->minax = size.min_aspect.x;
597 c->maxax = size.max_aspect.x;
598 c->minay = size.min_aspect.y;
599 c->maxay = size.max_aspect.y;
601 else
602 c->minax = c->maxax = c->minay = c->maxay = 0;
604 if(c->maxw && c->minw && c->maxh && c->minh
605 && c->maxw == c->minw && c->maxh == c->minh)
606 c->isfixed = True;
609 /** Returns True if a client is tagged
610 * with one of the tags
611 * \return True or False
613 Bool
614 client_isvisible(Client *c, int screen)
616 Tag *tag;
618 if(!c || c->screen != screen)
619 return False;
621 for(tag = globalconf.screens[screen].tags; tag; tag = tag->next)
622 if(tag->selected && is_client_tagged(c, tag))
623 return True;
624 return False;
627 /** Set selected client transparency
628 * \param screen Screen ID
629 * \param arg unused arg
630 * \ingroup ui_callback
632 void
633 uicb_client_settrans(int screen __attribute__ ((unused)), char *arg)
635 double delta = 100.0, current_opacity = 100.0;
636 unsigned char *data;
637 Atom actual;
638 int format;
639 unsigned long n, left;
640 unsigned int current_opacity_raw = 0;
641 int set_prop = 0;
642 Client *sel = globalconf.focus->client;
644 if(!sel)
645 return;
647 XGetWindowProperty(globalconf.display, sel->win,
648 XInternAtom(globalconf.display, "_NET_WM_WINDOW_OPACITY", False),
649 0L, 1L, False, XA_CARDINAL, &actual, &format, &n, &left,
650 (unsigned char **) &data);
651 if(data)
653 memcpy(&current_opacity_raw, data, sizeof(unsigned int));
654 XFree(data);
655 current_opacity = (current_opacity_raw * 100.0) / 0xffffffff;
657 else
658 set_prop = 1;
660 delta = compute_new_value_from_arg(arg, current_opacity);
662 if(delta <= 0.0)
663 delta = 0.0;
664 else if(delta > 100.0)
666 delta = 100.0;
667 set_prop = 1;
670 if(delta == 100.0 && !set_prop)
671 window_settrans(sel->win, -1);
672 else
673 window_settrans(sel->win, delta);
676 static Client *
677 client_find_prev_visible(Client *sel)
679 Client *prev = NULL;
681 if(!sel) return NULL;
683 /* look for previous starting at sel */
684 for(prev = client_list_prev_cycle(&globalconf.clients, sel);
685 prev && (prev->skip || !client_isvisible(prev, sel->screen));
686 prev = client_list_prev_cycle(&globalconf.clients, prev));
688 return prev;
691 static Client *
692 client_find_next_visible(Client *sel)
694 Client *next = NULL;
696 if(!sel) return NULL;
698 for(next = sel->next; next && !client_isvisible(next, sel->screen); next = next->next);
699 if(!next)
700 for(next = globalconf.clients; next && !client_isvisible(next, sel->screen); next = next->next);
702 return next;
705 /** Swap current with previous client
706 * \param screen Screen ID
707 * \param arg nothing
708 * \ingroup ui_callback
710 void
711 uicb_client_swapprev(int screen __attribute__ ((unused)),
712 char *arg __attribute__ ((unused)))
714 Client *prev;
716 if((prev = client_find_prev_visible(globalconf.focus->client)))
718 client_list_swap(&globalconf.clients, prev, globalconf.focus->client);
719 globalconf.screens[prev->screen].need_arrange = True;
723 /** Swap current with next client
724 * \param screen Screen ID
725 * \param arg nothing
726 * \ingroup ui_callback
728 void
729 uicb_client_swapnext(int screen __attribute__ ((unused)),
730 char *arg __attribute__ ((unused)))
732 Client *next;
734 if((next = client_find_next_visible(globalconf.focus->client)))
736 client_list_swap(&globalconf.clients, globalconf.focus->client, next);
737 globalconf.screens[next->screen].need_arrange = True;
741 /** Move and resize client
742 * \param screen Screen ID
743 * \param arg x y w h
744 * \ingroup ui_callback
746 void
747 uicb_client_moveresize(int screen, char *arg)
749 int ox, oy, ow, oh;
750 char x[8], y[8], w[8], h[8];
751 int mx, my, dx, dy, nmx, nmy;
752 unsigned int dui;
753 Window dummy;
754 Area area;
755 Client *sel = globalconf.focus->client;
756 Tag **curtags = get_current_tags(screen);
758 if(curtags[0]->layout->arrange != layout_floating)
759 if(!sel || !sel->isfloating || sel->isfixed || !arg)
761 p_delete(&curtags);
762 return;
764 p_delete(&curtags);
765 if(sscanf(arg, "%s %s %s %s", x, y, w, h) != 4)
766 return;
767 area.x = (int) compute_new_value_from_arg(x, sel->geometry.x);
768 area.y = (int) compute_new_value_from_arg(y, sel->geometry.y);
769 area.width = (int) compute_new_value_from_arg(w, sel->geometry.width);
770 area.height = (int) compute_new_value_from_arg(h, sel->geometry.height);
772 ox = sel->geometry.x;
773 oy = sel->geometry.y;
774 ow = sel->geometry.width;
775 oh = sel->geometry.height;
777 Bool xqp = XQueryPointer(globalconf.display,
778 RootWindow(globalconf.display,
779 get_phys_screen(screen)),
780 &dummy, &dummy, &mx, &my, &dx, &dy, &dui);
781 client_resize(sel, area, globalconf.screens[sel->screen].resize_hints);
782 if (xqp && ox <= mx && (ox + ow) >= mx && oy <= my && (oy + oh) >= my)
784 nmx = mx - ox + sel->geometry.width - ow - 1 < 0 ? 0 : mx - ox + sel->geometry.width - ow - 1;
785 nmy = my - oy + sel->geometry.height - oh - 1 < 0 ? 0 : my - oy + sel->geometry.height - oh - 1;
786 XWarpPointer(globalconf.display,
787 None, sel->win,
788 0, 0, 0, 0, nmx, nmy);
792 void
793 client_kill(Client *c)
795 XEvent ev;
797 if(isprotodel(globalconf.display, c->win))
799 ev.type = ClientMessage;
800 ev.xclient.window = c->win;
801 ev.xclient.message_type = XInternAtom(globalconf.display, "WM_PROTOCOLS", False);
802 ev.xclient.format = 32;
803 ev.xclient.data.l[0] = XInternAtom(globalconf.display, "WM_DELETE_WINDOW", False);
804 ev.xclient.data.l[1] = CurrentTime;
805 XSendEvent(globalconf.display, c->win, False, NoEventMask, &ev);
807 else
808 XKillClient(globalconf.display, c->win);
811 /** Kill selected client
812 * \param screen Screen ID
813 * \param arg unused
814 * \ingroup ui_callback
816 void
817 uicb_client_kill(int screen __attribute__ ((unused)), char *arg __attribute__ ((unused)))
819 Client *sel = globalconf.focus->client;
821 if(sel)
822 client_kill(sel);
825 static void
826 client_maximize(Client *c, Area geometry)
829 if((c->ismax = !c->ismax))
831 c->wasfloating = c->isfloating;
832 c->m_geometry = c->geometry;
833 if(get_current_layout(c->screen)->arrange != layout_floating)
834 client_setfloating(c, True);
835 client_resize(c, geometry, False);
836 widget_invalidate_cache(c->screen, WIDGET_CACHE_CLIENTS);
838 else if(c->wasfloating)
840 client_setfloating(c, True);
841 client_resize(c, c->m_geometry, False);
842 widget_invalidate_cache(c->screen, WIDGET_CACHE_CLIENTS);
844 else if(get_current_layout(c->screen)->arrange == layout_floating)
846 client_resize(c, c->m_geometry, False);
847 widget_invalidate_cache(c->screen, WIDGET_CACHE_CLIENTS);
849 else
851 client_setfloating(c, False);
852 widget_invalidate_cache(c->screen, WIDGET_CACHE_CLIENTS);
856 /** Toggle maximize for client
857 * \param screen Screen ID
858 * \param arg Unused
859 * \ingroup ui_callback
861 void
862 uicb_client_togglemax(int screen, char *arg __attribute__ ((unused)))
864 Client *sel = globalconf.focus->client;
865 Area area = get_screen_area(screen,
866 globalconf.screens[screen].statusbar,
867 &globalconf.screens[screen].padding);
869 if(sel)
871 area.width -= 2 * sel->border;
872 area.height -= 2 * sel->border;
873 client_maximize(sel, area);
877 /** Toggle vertical maximize for client
878 * \param screen Screen ID
879 * \param arg Unused
880 * \ingroup ui_callback
882 void
883 uicb_client_toggleverticalmax(int screen, char *arg __attribute__ ((unused)))
885 Client *sel = globalconf.focus->client;
886 Area area = get_screen_area(screen,
887 globalconf.screens[screen].statusbar,
888 &globalconf.screens[screen].padding);
890 if(sel)
892 area.x = sel->geometry.x;
893 area.width = sel->geometry.width;
894 area.height -= 2 * sel->border;
895 client_maximize(sel, area);
900 /** Toggle horizontal maximize for client
901 * \param screen Screen ID
902 * \param arg Unused
903 * \ingroup ui_callback
905 void
906 uicb_client_togglehorizontalmax(int screen, char *arg __attribute__ ((unused)))
908 Client *sel = globalconf.focus->client;
909 Area area = get_screen_area(screen,
910 globalconf.screens[screen].statusbar,
911 &globalconf.screens[screen].padding);
913 if(sel)
915 area.y = sel->geometry.y;
916 area.height = sel->geometry.height;
917 area.width -= 2 * sel->border;
918 client_maximize(sel, area);
922 /** Zoom client
923 * \param screen Screen ID
924 * \param arg Unused
925 * \ingroup ui_callback
927 void
928 uicb_client_zoom(int screen, char *arg __attribute__ ((unused)))
930 Client *c, *sel = globalconf.focus->client;
932 for(c = globalconf.clients; !client_isvisible(c, screen); c = c->next);
933 if(c == sel)
934 for(sel = sel->next; sel && !client_isvisible(sel, screen); sel = sel->next);
936 if(!sel)
937 return;
939 client_list_detach(&globalconf.clients, sel);
940 client_list_push(&globalconf.clients, sel);
941 globalconf.screens[screen].need_arrange = True;
944 /** Send focus to next client in stack
945 * \param screen Screen ID
946 * \param arg Unused
947 * \ingroup ui_callback
949 void
950 uicb_client_focusnext(int screen, char *arg __attribute__ ((unused)))
952 Client *c, *sel = globalconf.focus->client;
954 if(!sel)
955 return;
956 for(c = sel->next; c && (c->skip || !client_isvisible(c, screen)); c = c->next);
957 if(!c)
958 for(c = globalconf.clients; c && (c->skip || !client_isvisible(c, screen)); c = c->next);
959 if(c)
960 focus(c, True, screen);
963 /** Send focus to previous client in stack
964 * \param screen Screen ID
965 * \param arg Unused
966 * \ingroup ui_callback
968 void
969 uicb_client_focusprev(int screen, char *arg __attribute__ ((unused)))
971 Client *prev;
973 if((prev = client_find_prev_visible(globalconf.focus->client)))
974 focus(prev, True, screen);
977 /** Toggle floating state of a client
978 * \param screen Screen ID
979 * \param arg unused
980 * \ingroup ui_callback
982 void
983 uicb_client_togglefloating(int screen __attribute__ ((unused)),
984 char *arg __attribute__ ((unused)))
986 Client *sel = globalconf.focus->client;
988 if(!sel)
989 return;
991 /* XXX should use client_setfloating */
992 if((sel->isfloating = !sel->isfloating))
993 client_resize(sel, sel->f_geometry, False);
994 else if(sel->ismax)
995 client_resize(sel, sel->m_geometry, False);
996 globalconf.screens[sel->screen].need_arrange = True;
997 widget_invalidate_cache(sel->screen, WIDGET_CACHE_CLIENTS);
1000 // vim: filetype=c:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=80