rework headers inclusion
[awesome.git] / client.c
blob8530597066aafa999f0d381f2608cd23377e86ca
1 /*
2 * client.c - client management
4 * Copyright © 2007 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>
25 #include <X11/extensions/Xinerama.h>
27 #include "client.h"
28 #include "awesome.h"
29 #include "tag.h"
30 #include "rules.h"
31 #include "util.h"
32 #include "xutil.h"
33 #include "statusbar.h"
34 #include "window.h"
35 #include "focus.h"
36 #include "ewmh.h"
37 #include "screen.h"
38 #include "layouts/floating.h"
41 extern AwesomeConf globalconf;
43 /** Load windows properties, restoring client's tag
44 * and floating state before awesome was restarted if any
45 * \todo this may bug if number of tags is != than before
46 * \param c Client ref
47 * \param screen Screen ID
49 static Bool
50 client_loadprops(Client * c, int screen)
52 int i, ntags = 0;
53 Tag *tag;
54 char *prop;
55 Bool result = False;
57 for(tag = globalconf.screens[screen].tags; tag; tag = tag->next)
58 ntags++;
60 prop = p_new(char, ntags + 2);
62 if(xgettextprop(globalconf.display, c->win, AWESOMEPROPS_ATOM(globalconf.display), 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 c->isfloating = 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 /** Swap two client in the linked list clients
105 * \param head pointer ito the client list head
106 * \param c1 first client
107 * \param c2 second client
109 static void
110 client_swap(Client **head, Client *c1, Client *c2)
112 Client *tmp;
114 tmp = c1->next;
115 c1->next = c2->next;
116 c2->next = (tmp == c2 ? c1 : tmp);
118 tmp = c2->prev;
119 c2->prev = c1->prev;
120 c1->prev = (tmp == c1 ? c2 : tmp );
122 if(c1->next)
123 c1->next->prev = c1;
125 if(c1->prev)
126 c1->prev->next = c1;
128 if(c2->next)
129 c2->next->prev = c2;
131 if(c2->prev)
132 c2->prev->next = c2;
134 if(*head == c1)
135 *head = c2;
138 /** Get a Client by its window
139 * \param list Client list to look info
140 * \param w Client window to find
141 * \return client
143 Client *
144 get_client_bywin(Client *list, Window w)
146 Client *c;
148 for(c = list; c && c->win != w; c = c->next);
149 return c;
153 /** Get a client by its name
154 * \param list Client list
155 * \param name name to search
156 * \return first matching client
158 Client *
159 get_client_byname(Client *list, char *name)
161 Client *c;
163 for(c = list; c; c = c->next)
164 if(strstr(c->name, name))
165 return c;
167 return NULL;
170 /** Update client name attribute with its title
171 * \param c the client
173 void
174 client_updatetitle(Client *c)
176 if(!xgettextprop(globalconf.display, c->win, XInternAtom(globalconf.display, "_NET_WM_NAME", False), c->name, sizeof(c->name)))
177 xgettextprop(globalconf.display, c->win, XInternAtom(globalconf.display, "WM_NAME", False), c->name, sizeof(c->name));
180 /** Ban client and unmap it
181 * \param c the client
183 void
184 client_ban(Client * c)
186 XUnmapWindow(globalconf.display, c->win);
187 window_setstate(c->win, IconicState);
190 /** Attach client to the beginning of the clients stack
191 * \param c the client
193 void
194 client_attach(Client *c)
196 if(globalconf.clients)
197 (globalconf.clients)->prev = c;
198 c->next = globalconf.clients;
199 globalconf.clients = c;
202 /** Detach client from clients list
203 * \param c client to detach
205 void
206 client_detach(Client *c)
208 if(c->prev)
209 c->prev->next = c->next;
210 if(c->next)
211 c->next->prev = c->prev;
212 if(c == globalconf.clients)
213 globalconf.clients = c->next;
214 c->next = c->prev = NULL;
217 /** Give focus to client, or to first client if c is NULL
218 * \param c client
219 * \param selscreen True if current screen is selected
220 * \param screen Screen ID
222 void
223 focus(Client *c, Bool selscreen, int screen)
225 /* unfocus current selected client */
226 if(globalconf.focus->client)
228 window_grabbuttons(globalconf.focus->client->phys_screen,
229 globalconf.focus->client->win, False, True);
230 XSetWindowBorder(globalconf.display, globalconf.focus->client->win,
231 globalconf.screens[screen].colors_normal[ColBorder].pixel);
232 window_settrans(globalconf.focus->client->win,
233 globalconf.screens[screen].opacity_unfocused);
237 /* if c is NULL or invisible, take next client in the focus history */
238 if((!c && selscreen) || (c && !client_isvisible(c, screen)))
240 c = focus_get_current_client(screen);
241 /* if c is still NULL take next client in the stack */
242 if(!c)
243 for(c = globalconf.clients; c && (c->skip || !client_isvisible(c, screen)); c = c->next);
246 if(c)
248 XSetWindowBorder(globalconf.display, c->win, globalconf.screens[screen].colors_selected[ColBorder].pixel);
249 window_grabbuttons(c->phys_screen, c->win, True, True);
252 if(!selscreen)
253 return;
255 /* save sel in focus history */
256 focus_add_client(c);
258 statusbar_draw_all(screen);
260 if(globalconf.focus->client)
262 XSetInputFocus(globalconf.display,
263 globalconf.focus->client->win, RevertToPointerRoot, CurrentTime);
264 for(c = globalconf.clients; c; c = c->next)
265 if(c != globalconf.focus->client)
266 window_settrans(globalconf.focus->client->win,
267 globalconf.screens[screen].opacity_unfocused);
268 window_settrans(globalconf.focus->client->win, -1);
270 else
271 XSetInputFocus(globalconf.display,
272 RootWindow(globalconf.display, get_phys_screen(screen)),
273 RevertToPointerRoot, CurrentTime);
275 ewmh_update_net_active_window(get_phys_screen(screen));
278 /** Manage a new client
279 * \param w The window
280 * \param wa Window attributes
281 * \param screen Screen ID
283 void
284 client_manage(Window w, XWindowAttributes *wa, int screen)
286 Client *c, *t = NULL;
287 Window trans;
288 Status rettrans;
289 XWindowChanges wc;
290 Area area, darea;
291 Tag *tag;
293 c = p_new(Client, 1);
295 c->win = w;
296 c->x = c->rx = wa->x;
297 c->y = c->ry = wa->y;
298 c->w = c->rw = wa->width;
299 c->h = c->rh = wa->height;
300 c->oldborder = wa->border_width;
302 globalconf.display = globalconf.display;
303 c->screen = get_screen_bycoord(c->x, c->y);
304 c->phys_screen = get_phys_screen(c->screen);
306 move_client_to_screen(c, screen, True);
308 /* update window title */
309 client_updatetitle(c);
311 if(c->w == area.width && c->h == area.height)
312 c->border = wa->border_width;
313 else
314 c->border = globalconf.screens[screen].borderpx;
316 ewmh_check_client_hints(c);
317 /* loadprops or apply rules if no props */
318 if(!client_loadprops(c, screen))
319 tag_client_with_rules(c);
321 area = get_screen_area(screen, NULL, NULL);
323 /* if window request fullscreen mode */
324 if(c->w == area.width && c->h == area.height)
326 c->x = area.x;
327 c->y = area.y;
329 else
331 darea = get_display_area(c->phys_screen,
332 globalconf.screens[screen].statusbar,
333 &globalconf.screens[screen].padding);
335 if(c->x + c->w + 2 * c->border > darea.x + darea.width)
336 c->x = c->rx = darea.x + darea.width - c->w - 2 * c->border;
337 if(c->y + c->h + 2 * c->border > darea.y + darea.height)
338 c->y = c->ry = darea.y + darea.height - c->h - 2 * c->border;
339 if(c->x < darea.x)
340 c->x = c->rx = darea.x;
341 if(c->y < darea.y)
342 c->y = c->ry = darea.y;
345 /* set borders */
346 wc.border_width = c->border;
347 XConfigureWindow(globalconf.display, w, CWBorderWidth, &wc);
348 XSetWindowBorder(globalconf.display, w, globalconf.screens[screen].colors_normal[ColBorder].pixel);
350 /* propagates border_width, if size doesn't change */
351 window_configure(c->win, c->x, c->y, c->w, c->h, c->border);
353 /* update hints */
354 client_updatesizehints(c);
355 client_updatewmhints(c);
357 XSelectInput(globalconf.display, w, StructureNotifyMask | PropertyChangeMask | EnterWindowMask);
359 /* handle xshape */
360 if(globalconf.have_shape)
362 XShapeSelectInput(globalconf.display, w, ShapeNotifyMask);
363 window_setshape(c->phys_screen, c->win);
366 /* grab buttons */
367 window_grabbuttons(c->phys_screen, c->win, False, True);
369 /* check for transient and set tags like its parent */
370 if((rettrans = XGetTransientForHint(globalconf.display, w, &trans) == Success)
371 && (t = get_client_bywin(globalconf.clients, trans)))
372 for(tag = globalconf.screens[c->screen].tags; tag; tag = tag->next)
373 if(is_client_tagged(t, tag))
374 tag_client(c, tag);
376 /* should be floating if transsient or fixed */
377 if(!c->isfloating)
378 c->isfloating = (rettrans == Success) || c->isfixed;
380 /* save new props */
381 client_saveprops(c);
383 /* attach to the stack */
384 client_attach(c);
386 /* some windows require this */
387 XMoveResizeWindow(globalconf.display, c->win, c->x, c->y, c->w, c->h);
389 focus(c, True, screen);
391 ewmh_update_net_client_list(c->phys_screen);
393 /* rearrange to display new window */
394 arrange(screen);
397 /** Resize client window
398 * \param c client to resize
399 * \param x x coord
400 * \param y y coord
401 * \param w width
402 * \param h height
403 * \param sizehints respect size hints
404 * \param volatile_coords register coords in rx/ry/rw/rh
406 void
407 client_resize(Client *c, int x, int y, int w, int h,
408 Bool sizehints, Bool volatile_coords)
410 double dx, dy, max, min, ratio;
411 XWindowChanges wc;
412 Area area;
413 Tag **curtags;
415 if(sizehints)
417 if(c->minay > 0 && c->maxay > 0 && (h - c->baseh) > 0 && (w - c->basew) > 0)
419 dx = (double) (w - c->basew);
420 dy = (double) (h - c->baseh);
421 min = (double) (c->minax) / (double) (c->minay);
422 max = (double) (c->maxax) / (double) (c->maxay);
423 ratio = dx / dy;
424 if(max > 0 && min > 0 && ratio > 0)
426 if(ratio < min)
428 dy = (dx * min + dy) / (min * min + 1);
429 dx = dy * min;
430 w = (int) dx + c->basew;
431 h = (int) dy + c->baseh;
433 else if(ratio > max)
435 dy = (dx * min + dy) / (max * max + 1);
436 dx = dy * min;
437 w = (int) dx + c->basew;
438 h = (int) dy + c->baseh;
442 if(c->minw && w < c->minw)
443 w = c->minw;
444 if(c->minh && h < c->minh)
445 h = c->minh;
446 if(c->maxw && w > c->maxw)
447 w = c->maxw;
448 if(c->maxh && h > c->maxh)
449 h = c->maxh;
450 if(c->incw)
451 w -= (w - c->basew) % c->incw;
452 if(c->inch)
453 h -= (h - c->baseh) % c->inch;
455 if(w <= 0 || h <= 0)
456 return;
457 /* offscreen appearance fixes */
458 area = get_display_area(c->phys_screen,
459 NULL,
460 &globalconf.screens[c->screen].padding);
461 if(x > area.width)
462 x = area.width - w - 2 * c->border;
463 if(y > area.height)
464 y = area.height - h - 2 * c->border;
465 if(x + w + 2 * c->border < 0)
466 x = 0;
467 if(y + h + 2 * c->border < 0)
468 y = 0;
469 if(c->x != x || c->y != y || c->w != w || c->h != h)
471 c->x = wc.x = x;
472 c->y = wc.y = y;
473 c->w = wc.width = w;
474 c->h = wc.height = h;
475 curtags = get_current_tags(c->screen);
476 if(!volatile_coords
477 && (c->isfloating
478 || curtags[0]->layout->arrange == layout_floating))
480 c->rx = c->x;
481 c->ry = c->y;
482 c->rw = c->w;
483 c->rh = c->h;
485 p_delete(&curtags);
486 wc.border_width = c->border;
487 XConfigureWindow(globalconf.display, c->win, CWX | CWY | CWWidth | CWHeight | CWBorderWidth, &wc);
488 window_configure(c->win, c->x, c->y, c->w, c->h, c->border);
489 XSync(globalconf.display, False);
490 if((c->x >= 0 || c->y >= 0) && XineramaIsActive(globalconf.display))
492 int new_screen = get_screen_bycoord(c->x, c->y);
493 if(c->screen != new_screen)
494 move_client_to_screen(c, new_screen, False);
499 /** Save client properties as an X property
500 * \param c client
502 void
503 client_saveprops(Client *c)
505 int i = 0, ntags = 0;
506 char *prop;
507 Tag *tag;
509 for(tag = globalconf.screens[c->screen].tags; tag; tag = tag->next)
510 ntags++;
512 prop = p_new(char, ntags + 2);
514 for(tag = globalconf.screens[c->screen].tags; tag; tag = tag->next, i++)
515 prop[i] = is_client_tagged(c, tag) ? '1' : '0';
517 if(i <= ntags)
518 prop[i] = c->isfloating ? '1' : '0';
520 prop[++i] = '\0';
522 XChangeProperty(globalconf.display, c->win, AWESOMEPROPS_ATOM(globalconf.display), XA_STRING, 8,
523 PropModeReplace, (unsigned char *) prop, i);
525 p_delete(&prop);
528 void
529 client_unban(Client *c)
531 XMapWindow(globalconf.display, c->win);
532 window_setstate(c->win, NormalState);
535 void
536 client_unmanage(Client *c, long state)
538 XWindowChanges wc;
539 Tag *tag;
541 wc.border_width = c->oldborder;
542 /* The server grab construct avoids race conditions. */
543 XGrabServer(globalconf.display);
544 XConfigureWindow(globalconf.display, c->win, CWBorderWidth, &wc); /* restore border */
545 client_detach(c);
546 if(globalconf.focus->client == c)
547 focus(NULL, True, c->screen);
548 focus_delete_client(c);
549 for(tag = globalconf.screens[c->screen].tags; tag; tag = tag->next)
550 untag_client(c, tag);
551 XUngrabButton(globalconf.display, AnyButton, AnyModifier, c->win);
552 window_setstate(c->win, state);
553 XSync(globalconf.display, False);
554 XSetErrorHandler(xerror);
555 XUngrabServer(globalconf.display);
556 if(state != NormalState)
557 arrange(c->screen);
558 p_delete(&c);
561 void
562 client_updatewmhints(Client *c)
564 XWMHints *wmh;
566 if((wmh = XGetWMHints(globalconf.display, c->win)))
568 c->isurgent = (wmh->flags & XUrgencyHint);
569 if((wmh->flags & StateHint) && wmh->initial_state == WithdrawnState)
570 c->skip = True;
571 XFree(wmh);
575 void
576 client_updatesizehints(Client *c)
578 long msize;
579 XSizeHints size;
581 if(!XGetWMNormalHints(globalconf.display, c->win, &size, &msize) || !size.flags)
582 size.flags = PSize;
583 c->flags = size.flags;
584 if(c->flags & PBaseSize)
586 c->basew = size.base_width;
587 c->baseh = size.base_height;
589 else if(c->flags & PMinSize)
591 c->basew = size.min_width;
592 c->baseh = size.min_height;
594 else
595 c->basew = c->baseh = 0;
596 if(c->flags & PResizeInc)
598 c->incw = size.width_inc;
599 c->inch = size.height_inc;
601 else
602 c->incw = c->inch = 0;
604 if(c->flags & PMaxSize)
606 c->maxw = size.max_width;
607 c->maxh = size.max_height;
609 else
610 c->maxw = c->maxh = 0;
612 if(c->flags & PMinSize)
614 c->minw = size.min_width;
615 c->minh = size.min_height;
617 else if(c->flags & PBaseSize)
619 c->minw = size.base_width;
620 c->minh = size.base_height;
622 else
623 c->minw = c->minh = 0;
625 if(c->flags & PAspect)
627 c->minax = size.min_aspect.x;
628 c->maxax = size.max_aspect.x;
629 c->minay = size.min_aspect.y;
630 c->maxay = size.max_aspect.y;
632 else
633 c->minax = c->maxax = c->minay = c->maxay = 0;
635 if(c->maxw && c->minw && c->maxh && c->minh
636 && c->maxw == c->minw && c->maxh == c->minh)
637 c->isfixed = True;
640 /** Returns True if a client is tagged
641 * with one of the tags
642 * \return True or False
644 Bool
645 client_isvisible(Client *c, int screen)
647 Tag *tag;
649 if(c->screen != screen)
650 return False;
652 for(tag = globalconf.screens[screen].tags; tag; tag = tag->next)
653 if(tag->selected && is_client_tagged(c, tag))
654 return True;
655 return False;
658 /** Set selected client transparency
659 * \param screen Screen ID
660 * \param arg unused arg
661 * \ingroup ui_callback
663 void
664 uicb_client_settrans(int screen __attribute__ ((unused)), char *arg)
666 double delta = 100.0, current_opacity = 100.0;
667 unsigned char *data;
668 Atom actual;
669 int format;
670 unsigned long n, left;
671 unsigned int current_opacity_raw = 0;
672 int set_prop = 0;
673 Client *sel = globalconf.focus->client;
675 if(!sel)
676 return;
678 XGetWindowProperty(globalconf.display, sel->win,
679 XInternAtom(globalconf.display, "_NET_WM_WINDOW_OPACITY", False),
680 0L, 1L, False, XA_CARDINAL, &actual, &format, &n, &left,
681 (unsigned char **) &data);
682 if(data)
684 memcpy(&current_opacity_raw, data, sizeof(unsigned int));
685 XFree(data);
686 current_opacity = (current_opacity_raw * 100.0) / 0xffffffff;
688 else
689 set_prop = 1;
691 delta = compute_new_value_from_arg(arg, current_opacity);
693 if(delta <= 0.0)
694 delta = 0.0;
695 else if(delta > 100.0)
697 delta = 100.0;
698 set_prop = 1;
701 if(delta == 100.0 && !set_prop)
702 window_settrans(sel->win, -1);
703 else
704 window_settrans(sel->win, delta);
708 /** Set border size
709 * \param screen Screen ID
710 * \param arg X, +X or -X
711 * \ingroup ui_callback
713 void
714 uicb_setborder(int screen, char *arg)
716 if(!arg)
717 return;
719 if((globalconf.screens[screen].borderpx = (int) compute_new_value_from_arg(arg, (double) globalconf.screens[screen].borderpx)) < 0)
720 globalconf.screens[screen].borderpx = 0;
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, char *arg __attribute__ ((unused)))
731 Client *next, *sel = globalconf.focus->client;
733 if(!sel)
734 return;
736 for(next = sel->next; next && !client_isvisible(next, screen); next = next->next);
737 if(next)
739 client_swap(&globalconf.clients, sel, next);
740 arrange(screen);
741 /* restore focus */
742 focus(sel, True, screen);
746 /** Swap current with previous client
747 * \param screen Screen ID
748 * \param arg nothing
749 * \ingroup ui_callback
751 void
752 uicb_client_swapprev(int screen, char *arg __attribute__ ((unused)))
754 Client *prev, *sel = globalconf.focus->client;
756 if(!sel)
757 return;
759 for(prev = sel->prev; prev && !client_isvisible(prev, screen); prev = prev->prev);
760 if(prev)
762 client_swap(&globalconf.clients, prev, sel);
763 arrange(screen);
764 /* restore focus */
765 focus(sel, True, screen);
769 /** Move and resize client
770 * \param screen Screen ID
771 * \param arg x y w h
772 * \ingroup ui_callback
774 void
775 uicb_client_moveresize(int screen, char *arg)
777 int nx, ny, nw, nh, ox, oy, ow, oh;
778 char x[8], y[8], w[8], h[8];
779 int mx, my, dx, dy, nmx, nmy;
780 unsigned int dui;
781 Window dummy;
782 Client *sel = globalconf.focus->client;
783 Tag **curtags = get_current_tags(screen);
785 if(curtags[0]->layout->arrange != layout_floating)
786 if(!sel || !sel->isfloating || sel->isfixed || !arg)
788 p_delete(&curtags);
789 return;
791 p_delete(&curtags);
792 if(sscanf(arg, "%s %s %s %s", x, y, w, h) != 4)
793 return;
794 nx = (int) compute_new_value_from_arg(x, sel->x);
795 ny = (int) compute_new_value_from_arg(y, sel->y);
796 nw = (int) compute_new_value_from_arg(w, sel->w);
797 nh = (int) compute_new_value_from_arg(h, sel->h);
799 ox = sel->x;
800 oy = sel->y;
801 ow = sel->w;
802 oh = sel->h;
804 Bool xqp = XQueryPointer(globalconf.display,
805 RootWindow(globalconf.display,
806 get_phys_screen(screen)),
807 &dummy, &dummy, &mx, &my, &dx, &dy, &dui);
808 client_resize(sel, nx, ny, nw, nh, True, False);
809 if (xqp && ox <= mx && (ox + ow) >= mx && oy <= my && (oy + oh) >= my)
811 nmx = mx - ox + sel->w - ow - 1 < 0 ? 0 : mx - ox + sel->w - ow - 1;
812 nmy = my - oy + sel->h - oh - 1 < 0 ? 0 : my - oy + sel->h - oh - 1;
813 XWarpPointer(globalconf.display,
814 None, sel->win,
815 0, 0, 0, 0, nmx, nmy);
820 void
821 client_kill(Client *c)
823 XEvent ev;
825 if(isprotodel(globalconf.display, c->win))
827 ev.type = ClientMessage;
828 ev.xclient.window = c->win;
829 ev.xclient.message_type = XInternAtom(globalconf.display, "WM_PROTOCOLS", False);
830 ev.xclient.format = 32;
831 ev.xclient.data.l[0] = XInternAtom(globalconf.display, "WM_DELETE_WINDOW", False);
832 ev.xclient.data.l[1] = CurrentTime;
833 XSendEvent(globalconf.display, c->win, False, NoEventMask, &ev);
835 else
836 XKillClient(globalconf.display, c->win);
839 /** Kill selected client
840 * \param screen Screen ID
841 * \param arg unused
842 * \ingroup ui_callback
844 void
845 uicb_client_kill(int screen __attribute__ ((unused)), char *arg __attribute__ ((unused)))
847 Client *sel = globalconf.focus->client;
849 if(sel)
850 client_kill(sel);
853 void
854 client_maximize(Client *c, int x, int y, int w, int h)
856 if((c->ismax = !c->ismax))
858 c->oldborder = c->border;
859 c->border = 0;
860 c->wasfloating = c->isfloating;
861 c->isfloating = True;
862 client_resize(c, x, y, w, h, False, True);
864 else if(c->wasfloating)
865 client_resize(c, c->rx, c->ry, c->rw, c->rh, True, False);
866 else
867 c->isfloating = False;
869 c->border = c->oldborder;
871 arrange(c->screen);
874 /** Toggle maximize for client
875 * \param screen Screen ID
876 * \param arg Unused
877 * \ingroup ui_callback
879 void
880 uicb_client_togglemax(int screen, char *arg __attribute__ ((unused)))
882 Client *sel = globalconf.focus->client;
883 Area area = get_screen_area(screen,
884 globalconf.screens[screen].statusbar,
885 &globalconf.screens[screen].padding);
886 if(sel)
887 client_maximize(sel, area.x, area.y,
888 area.width - 2 * globalconf.screens[screen].borderpx,
889 area.height - 2 * globalconf.screens[screen].borderpx);
892 /** Toggle vertical maximize for client
893 * \param screen Screen ID
894 * \param arg Unused
895 * \ingroup ui_callback
897 void
898 uicb_client_toggleverticalmax(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)
906 client_maximize(sel, sel->x, area.y,
907 sel->w,
908 area.height - 2 * globalconf.screens[screen].borderpx);
912 /** Toggle horizontal maximize for client
913 * \param screen Screen ID
914 * \param arg Unused
915 * \ingroup ui_callback
917 void
918 uicb_client_togglehorizontalmax(int screen, char *arg __attribute__ ((unused)))
920 Client *sel = globalconf.focus->client;
921 Area area = get_screen_area(screen,
922 globalconf.screens[screen].statusbar,
923 &globalconf.screens[screen].padding);
925 if(sel)
926 client_maximize(sel, area.x, sel->y,
927 area.height - 2 * globalconf.screens[screen].borderpx,
928 sel->h);
931 /** Zoom client
932 * \param screen Screen ID
933 * \param arg Unused
934 * \ingroup ui_callback
936 void
937 uicb_client_zoom(int screen, char *arg __attribute__ ((unused)))
939 Client *sel = globalconf.focus->client;
941 if(globalconf.clients == sel)
942 for(sel = sel->next; sel && !client_isvisible(sel, screen); sel = sel->next);
944 if(!sel)
945 return;
947 client_detach(sel);
948 client_attach(sel);
950 focus(sel, True, screen);
951 arrange(screen);
954 // vim: filetype=c:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=80