add various autostuff to ignore
[awesome.git] / client.c
blobff848eaab168a81c19172e3f323255af07c9811f
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>
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);
191 static void
192 client_attach_at_end(Client *c)
194 Client *iter;
195 for(iter = globalconf.clients; iter && iter->next; iter = iter->next);
196 /* stack is empty */
197 if(!iter)
198 globalconf.clients = c;
199 else
201 c->prev = iter;
202 iter->next = c;
206 /** Attach client to the beginning of the clients stack
207 * \param c the client
209 void
210 client_attach(Client *c)
212 if(globalconf.clients)
213 (globalconf.clients)->prev = c;
214 c->next = globalconf.clients;
215 globalconf.clients = c;
218 /** Detach client from clients list
219 * \param c client to detach
221 void
222 client_detach(Client *c)
224 if(c->prev)
225 c->prev->next = c->next;
226 if(c->next)
227 c->next->prev = c->prev;
228 if(c == globalconf.clients)
229 globalconf.clients = c->next;
230 c->next = c->prev = NULL;
233 /** Give focus to client, or to first client if c is NULL
234 * \param c client
235 * \param selscreen True if current screen is selected
236 * \param screen Screen ID
238 void
239 focus(Client *c, Bool selscreen, int screen)
241 int phys_screen = get_phys_screen(screen);
243 /* unfocus current selected client */
244 if(globalconf.focus->client)
246 window_grabbuttons(get_phys_screen(globalconf.focus->client->screen),
247 globalconf.focus->client->win, False, True);
248 XSetWindowBorder(globalconf.display, globalconf.focus->client->win,
249 globalconf.screens[screen].colors_normal[ColBorder].pixel);
250 window_settrans(globalconf.focus->client->win,
251 globalconf.screens[screen].opacity_unfocused);
255 /* if c is NULL or invisible, take next client in the focus history */
256 if((!c && selscreen) || (c && !client_isvisible(c, screen)))
258 c = focus_get_current_client(screen);
259 /* if c is still NULL take next client in the stack */
260 if(!c)
261 for(c = globalconf.clients; c && (c->skip || !client_isvisible(c, screen)); c = c->next);
264 if(c)
266 XSetWindowBorder(globalconf.display, c->win, globalconf.screens[screen].colors_selected[ColBorder].pixel);
267 window_grabbuttons(phys_screen, c->win, True, True);
270 if(!selscreen)
271 return;
273 /* save sel in focus history */
274 focus_add_client(c);
276 statusbar_draw_all(screen);
278 if(globalconf.focus->client)
280 XSetInputFocus(globalconf.display,
281 globalconf.focus->client->win, RevertToPointerRoot, CurrentTime);
282 for(c = globalconf.clients; c; c = c->next)
283 if(c != globalconf.focus->client)
284 window_settrans(globalconf.focus->client->win,
285 globalconf.screens[screen].opacity_unfocused);
286 window_settrans(globalconf.focus->client->win, -1);
288 else
289 XSetInputFocus(globalconf.display,
290 RootWindow(globalconf.display, phys_screen),
291 RevertToPointerRoot, CurrentTime);
293 ewmh_update_net_active_window(phys_screen);
296 /** Manage a new client
297 * \param w The window
298 * \param wa Window attributes
299 * \param screen Screen ID
301 void
302 client_manage(Window w, XWindowAttributes *wa, int screen)
304 Client *c, *t = NULL;
305 Window trans;
306 Status rettrans;
307 XWindowChanges wc;
308 Area area, darea;
309 Tag *tag;
310 Rule *rule;
311 int phys_screen = get_phys_screen(screen);
313 area = get_screen_area(screen, NULL, NULL);
315 c = p_new(Client, 1);
317 c->win = w;
318 c->x = c->rx = wa->x;
319 c->y = c->ry = wa->y;
320 c->w = c->rw = wa->width;
321 c->h = c->rh = wa->height;
322 c->oldborder = wa->border_width;
324 c->screen = get_screen_bycoord(c->x, c->y);
326 move_client_to_screen(c, screen, True);
328 /* update window title */
329 client_updatetitle(c);
331 if(c->w == area.width && c->h == area.height)
332 c->border = wa->border_width;
333 else
334 c->border = globalconf.screens[screen].borderpx;
336 ewmh_check_client_hints(c);
337 /* loadprops or apply rules if no props */
338 if(!client_loadprops(c, screen))
339 tag_client_with_rules(c);
342 /* if window request fullscreen mode */
343 if(c->w == area.width && c->h == area.height)
345 c->x = area.x;
346 c->y = area.y;
348 else
350 darea = get_display_area(phys_screen,
351 globalconf.screens[screen].statusbar,
352 &globalconf.screens[screen].padding);
354 if(c->x + c->w + 2 * c->border > darea.x + darea.width)
355 c->x = c->rx = darea.x + darea.width - c->w - 2 * c->border;
356 if(c->y + c->h + 2 * c->border > darea.y + darea.height)
357 c->y = c->ry = darea.y + darea.height - c->h - 2 * c->border;
358 if(c->x < darea.x)
359 c->x = c->rx = darea.x;
360 if(c->y < darea.y)
361 c->y = c->ry = darea.y;
364 /* set borders */
365 wc.border_width = c->border;
366 XConfigureWindow(globalconf.display, w, CWBorderWidth, &wc);
367 XSetWindowBorder(globalconf.display, w, globalconf.screens[screen].colors_normal[ColBorder].pixel);
369 /* propagates border_width, if size doesn't change */
370 window_configure(c->win, c->x, c->y, c->w, c->h, c->border);
372 /* update hints */
373 client_updatesizehints(c);
374 client_updatewmhints(c);
376 XSelectInput(globalconf.display, w, StructureNotifyMask | PropertyChangeMask | EnterWindowMask);
378 /* handle xshape */
379 if(globalconf.have_shape)
381 XShapeSelectInput(globalconf.display, w, ShapeNotifyMask);
382 window_setshape(phys_screen, c->win);
385 /* grab buttons */
386 window_grabbuttons(phys_screen, c->win, False, True);
388 /* check for transient and set tags like its parent */
389 if((rettrans = XGetTransientForHint(globalconf.display, w, &trans) == Success)
390 && (t = get_client_bywin(globalconf.clients, trans)))
391 for(tag = globalconf.screens[c->screen].tags; tag; tag = tag->next)
392 if(is_client_tagged(t, tag))
393 tag_client(c, tag);
395 /* should be floating if transsient or fixed */
396 if(!c->isfloating)
397 c->isfloating = (rettrans == Success) || c->isfixed;
399 /* save new props */
400 client_saveprops(c);
402 /* attach to the stack */
403 for(rule = globalconf.rules; rule; rule = rule->next)
404 if(rule->not_master && client_match_rule(c, rule))
406 client_attach_at_end(c);
407 break;
409 if(!rule)
411 if(globalconf.screens[c->screen].new_become_master)
412 client_attach(c);
413 else
414 client_attach_at_end(c);
417 /* some windows require this */
418 XMoveResizeWindow(globalconf.display, c->win, c->x, c->y, c->w, c->h);
420 focus(c, True, screen);
422 ewmh_update_net_client_list(phys_screen);
424 /* rearrange to display new window */
425 arrange(screen);
428 /** Resize client window
429 * \param c client to resize
430 * \param x x coord
431 * \param y y coord
432 * \param w width
433 * \param h height
434 * \param sizehints respect size hints
435 * \param volatile_coords register coords in rx/ry/rw/rh
437 void
438 client_resize(Client *c, int x, int y, int w, int h,
439 Bool sizehints, Bool volatile_coords)
441 double dx, dy, max, min, ratio;
442 XWindowChanges wc;
443 Area area;
444 Tag **curtags;
446 if(sizehints)
448 if(c->minay > 0 && c->maxay > 0 && (h - c->baseh) > 0 && (w - c->basew) > 0)
450 dx = (double) (w - c->basew);
451 dy = (double) (h - c->baseh);
452 min = (double) (c->minax) / (double) (c->minay);
453 max = (double) (c->maxax) / (double) (c->maxay);
454 ratio = dx / dy;
455 if(max > 0 && min > 0 && ratio > 0)
457 if(ratio < min)
459 dy = (dx * min + dy) / (min * min + 1);
460 dx = dy * min;
461 w = (int) dx + c->basew;
462 h = (int) dy + c->baseh;
464 else if(ratio > max)
466 dy = (dx * min + dy) / (max * max + 1);
467 dx = dy * min;
468 w = (int) dx + c->basew;
469 h = (int) dy + c->baseh;
473 if(c->minw && w < c->minw)
474 w = c->minw;
475 if(c->minh && h < c->minh)
476 h = c->minh;
477 if(c->maxw && w > c->maxw)
478 w = c->maxw;
479 if(c->maxh && h > c->maxh)
480 h = c->maxh;
481 if(c->incw)
482 w -= (w - c->basew) % c->incw;
483 if(c->inch)
484 h -= (h - c->baseh) % c->inch;
486 if(w <= 0 || h <= 0)
487 return;
488 /* offscreen appearance fixes */
489 area = get_display_area(get_phys_screen(c->screen),
490 NULL,
491 &globalconf.screens[c->screen].padding);
492 if(x > area.width)
493 x = area.width - w - 2 * c->border;
494 if(y > area.height)
495 y = area.height - h - 2 * c->border;
496 if(x + w + 2 * c->border < 0)
497 x = 0;
498 if(y + h + 2 * c->border < 0)
499 y = 0;
500 if(c->x != x || c->y != y || c->w != w || c->h != h)
502 c->x = wc.x = x;
503 c->y = wc.y = y;
504 c->w = wc.width = w;
505 c->h = wc.height = h;
506 curtags = get_current_tags(c->screen);
507 if(!volatile_coords
508 && (c->isfloating
509 || curtags[0]->layout->arrange == layout_floating))
511 c->rx = c->x;
512 c->ry = c->y;
513 c->rw = c->w;
514 c->rh = c->h;
516 p_delete(&curtags);
517 wc.border_width = c->border;
518 XConfigureWindow(globalconf.display, c->win, CWX | CWY | CWWidth | CWHeight | CWBorderWidth, &wc);
519 window_configure(c->win, c->x, c->y, c->w, c->h, c->border);
520 XSync(globalconf.display, False);
521 if((c->x >= 0 || c->y >= 0) && XineramaIsActive(globalconf.display))
523 int new_screen = get_screen_bycoord(c->x, c->y);
524 if(c->screen != new_screen)
525 move_client_to_screen(c, new_screen, False);
530 /** Save client properties as an X property
531 * \param c client
533 void
534 client_saveprops(Client *c)
536 int i = 0, ntags = 0;
537 char *prop;
538 Tag *tag;
540 for(tag = globalconf.screens[c->screen].tags; tag; tag = tag->next)
541 ntags++;
543 prop = p_new(char, ntags + 2);
545 for(tag = globalconf.screens[c->screen].tags; tag; tag = tag->next, i++)
546 prop[i] = is_client_tagged(c, tag) ? '1' : '0';
548 if(i <= ntags)
549 prop[i] = c->isfloating ? '1' : '0';
551 prop[++i] = '\0';
553 XChangeProperty(globalconf.display, c->win, AWESOMEPROPS_ATOM(globalconf.display), XA_STRING, 8,
554 PropModeReplace, (unsigned char *) prop, i);
556 p_delete(&prop);
559 void
560 client_unban(Client *c)
562 XMapWindow(globalconf.display, c->win);
563 window_setstate(c->win, NormalState);
566 void
567 client_unmanage(Client *c, long state)
569 XWindowChanges wc;
570 Tag *tag;
572 wc.border_width = c->oldborder;
573 /* The server grab construct avoids race conditions. */
574 XGrabServer(globalconf.display);
575 XConfigureWindow(globalconf.display, c->win, CWBorderWidth, &wc); /* restore border */
576 client_detach(c);
577 if(globalconf.focus->client == c)
578 focus(NULL, True, c->screen);
579 focus_delete_client(c);
580 for(tag = globalconf.screens[c->screen].tags; tag; tag = tag->next)
581 untag_client(c, tag);
582 XUngrabButton(globalconf.display, AnyButton, AnyModifier, c->win);
583 window_setstate(c->win, state);
584 XSync(globalconf.display, False);
585 XSetErrorHandler(xerror);
586 XUngrabServer(globalconf.display);
587 if(state != NormalState)
588 arrange(c->screen);
589 p_delete(&c);
592 void
593 client_updatewmhints(Client *c)
595 XWMHints *wmh;
597 if((wmh = XGetWMHints(globalconf.display, c->win)))
599 c->isurgent = (wmh->flags & XUrgencyHint);
600 if((wmh->flags & StateHint) && wmh->initial_state == WithdrawnState)
601 c->skip = True;
602 XFree(wmh);
606 void
607 client_updatesizehints(Client *c)
609 long msize;
610 XSizeHints size;
612 if(!XGetWMNormalHints(globalconf.display, c->win, &size, &msize) || !size.flags)
613 size.flags = PSize;
614 c->flags = size.flags;
615 if(c->flags & PBaseSize)
617 c->basew = size.base_width;
618 c->baseh = size.base_height;
620 else if(c->flags & PMinSize)
622 c->basew = size.min_width;
623 c->baseh = size.min_height;
625 else
626 c->basew = c->baseh = 0;
627 if(c->flags & PResizeInc)
629 c->incw = size.width_inc;
630 c->inch = size.height_inc;
632 else
633 c->incw = c->inch = 0;
635 if(c->flags & PMaxSize)
637 c->maxw = size.max_width;
638 c->maxh = size.max_height;
640 else
641 c->maxw = c->maxh = 0;
643 if(c->flags & PMinSize)
645 c->minw = size.min_width;
646 c->minh = size.min_height;
648 else if(c->flags & PBaseSize)
650 c->minw = size.base_width;
651 c->minh = size.base_height;
653 else
654 c->minw = c->minh = 0;
656 if(c->flags & PAspect)
658 c->minax = size.min_aspect.x;
659 c->maxax = size.max_aspect.x;
660 c->minay = size.min_aspect.y;
661 c->maxay = size.max_aspect.y;
663 else
664 c->minax = c->maxax = c->minay = c->maxay = 0;
666 if(c->maxw && c->minw && c->maxh && c->minh
667 && c->maxw == c->minw && c->maxh == c->minh)
668 c->isfixed = True;
671 /** Returns True if a client is tagged
672 * with one of the tags
673 * \return True or False
675 Bool
676 client_isvisible(Client *c, int screen)
678 Tag *tag;
680 if(c->screen != screen)
681 return False;
683 for(tag = globalconf.screens[screen].tags; tag; tag = tag->next)
684 if(tag->selected && is_client_tagged(c, tag))
685 return True;
686 return False;
689 /** Set selected client transparency
690 * \param screen Screen ID
691 * \param arg unused arg
692 * \ingroup ui_callback
694 void
695 uicb_client_settrans(int screen __attribute__ ((unused)), char *arg)
697 double delta = 100.0, current_opacity = 100.0;
698 unsigned char *data;
699 Atom actual;
700 int format;
701 unsigned long n, left;
702 unsigned int current_opacity_raw = 0;
703 int set_prop = 0;
704 Client *sel = globalconf.focus->client;
706 if(!sel)
707 return;
709 XGetWindowProperty(globalconf.display, sel->win,
710 XInternAtom(globalconf.display, "_NET_WM_WINDOW_OPACITY", False),
711 0L, 1L, False, XA_CARDINAL, &actual, &format, &n, &left,
712 (unsigned char **) &data);
713 if(data)
715 memcpy(&current_opacity_raw, data, sizeof(unsigned int));
716 XFree(data);
717 current_opacity = (current_opacity_raw * 100.0) / 0xffffffff;
719 else
720 set_prop = 1;
722 delta = compute_new_value_from_arg(arg, current_opacity);
724 if(delta <= 0.0)
725 delta = 0.0;
726 else if(delta > 100.0)
728 delta = 100.0;
729 set_prop = 1;
732 if(delta == 100.0 && !set_prop)
733 window_settrans(sel->win, -1);
734 else
735 window_settrans(sel->win, delta);
738 /** Swap current with next client
739 * \param screen Screen ID
740 * \param arg nothing
741 * \ingroup ui_callback
743 void
744 uicb_client_swapnext(int screen, char *arg __attribute__ ((unused)))
746 Client *next, *sel = globalconf.focus->client;
748 if(!sel)
749 return;
751 for(next = sel->next; next && !client_isvisible(next, screen); next = next->next);
752 if(next)
754 client_swap(&globalconf.clients, sel, next);
755 arrange(screen);
756 /* restore focus */
757 focus(sel, True, screen);
761 /** Swap current with previous client
762 * \param screen Screen ID
763 * \param arg nothing
764 * \ingroup ui_callback
766 void
767 uicb_client_swapprev(int screen, char *arg __attribute__ ((unused)))
769 Client *prev, *sel = globalconf.focus->client;
771 if(!sel)
772 return;
774 for(prev = sel->prev; prev && !client_isvisible(prev, screen); prev = prev->prev);
775 if(prev)
777 client_swap(&globalconf.clients, prev, sel);
778 arrange(screen);
779 /* restore focus */
780 focus(sel, True, screen);
784 /** Move and resize client
785 * \param screen Screen ID
786 * \param arg x y w h
787 * \ingroup ui_callback
789 void
790 uicb_client_moveresize(int screen, char *arg)
792 int nx, ny, nw, nh, ox, oy, ow, oh;
793 char x[8], y[8], w[8], h[8];
794 int mx, my, dx, dy, nmx, nmy;
795 unsigned int dui;
796 Window dummy;
797 Client *sel = globalconf.focus->client;
798 Tag **curtags = get_current_tags(screen);
800 if(curtags[0]->layout->arrange != layout_floating)
801 if(!sel || !sel->isfloating || sel->isfixed || !arg)
803 p_delete(&curtags);
804 return;
806 p_delete(&curtags);
807 if(sscanf(arg, "%s %s %s %s", x, y, w, h) != 4)
808 return;
809 nx = (int) compute_new_value_from_arg(x, sel->x);
810 ny = (int) compute_new_value_from_arg(y, sel->y);
811 nw = (int) compute_new_value_from_arg(w, sel->w);
812 nh = (int) compute_new_value_from_arg(h, sel->h);
814 ox = sel->x;
815 oy = sel->y;
816 ow = sel->w;
817 oh = sel->h;
819 Bool xqp = XQueryPointer(globalconf.display,
820 RootWindow(globalconf.display,
821 get_phys_screen(screen)),
822 &dummy, &dummy, &mx, &my, &dx, &dy, &dui);
823 client_resize(sel, nx, ny, nw, nh, True, False);
824 if (xqp && ox <= mx && (ox + ow) >= mx && oy <= my && (oy + oh) >= my)
826 nmx = mx - ox + sel->w - ow - 1 < 0 ? 0 : mx - ox + sel->w - ow - 1;
827 nmy = my - oy + sel->h - oh - 1 < 0 ? 0 : my - oy + sel->h - oh - 1;
828 XWarpPointer(globalconf.display,
829 None, sel->win,
830 0, 0, 0, 0, nmx, nmy);
835 void
836 client_kill(Client *c)
838 XEvent ev;
840 if(isprotodel(globalconf.display, c->win))
842 ev.type = ClientMessage;
843 ev.xclient.window = c->win;
844 ev.xclient.message_type = XInternAtom(globalconf.display, "WM_PROTOCOLS", False);
845 ev.xclient.format = 32;
846 ev.xclient.data.l[0] = XInternAtom(globalconf.display, "WM_DELETE_WINDOW", False);
847 ev.xclient.data.l[1] = CurrentTime;
848 XSendEvent(globalconf.display, c->win, False, NoEventMask, &ev);
850 else
851 XKillClient(globalconf.display, c->win);
854 /** Kill selected client
855 * \param screen Screen ID
856 * \param arg unused
857 * \ingroup ui_callback
859 void
860 uicb_client_kill(int screen __attribute__ ((unused)), char *arg __attribute__ ((unused)))
862 Client *sel = globalconf.focus->client;
864 if(sel)
865 client_kill(sel);
868 void
869 client_maximize(Client *c, int x, int y, int w, int h, Bool borders)
871 if((c->ismax = !c->ismax))
873 if(borders)
875 c->oldborder = c->border;
876 c->border = 0;
878 c->wasfloating = c->isfloating;
879 c->isfloating = True;
880 client_resize(c, x, y, w, h, False, True);
882 else if(c->wasfloating)
883 client_resize(c, c->rx, c->ry, c->rw, c->rh, True, False);
884 else
885 c->isfloating = False;
887 if(borders)
888 c->border = c->oldborder;
890 arrange(c->screen);
893 /** Toggle maximize for client
894 * \param screen Screen ID
895 * \param arg Unused
896 * \ingroup ui_callback
898 void
899 uicb_client_togglemax(int screen, char *arg __attribute__ ((unused)))
901 Client *sel = globalconf.focus->client;
902 Area area = get_screen_area(screen,
903 globalconf.screens[screen].statusbar,
904 &globalconf.screens[screen].padding);
905 if(sel)
906 client_maximize(sel, area.x, area.y,
907 area.width - 2 * sel->border,
908 area.height - 2 * sel->border, False);
911 /** Toggle vertical maximize for client
912 * \param screen Screen ID
913 * \param arg Unused
914 * \ingroup ui_callback
916 void
917 uicb_client_toggleverticalmax(int screen, char *arg __attribute__ ((unused)))
919 Client *sel = globalconf.focus->client;
920 Area area = get_screen_area(screen,
921 globalconf.screens[screen].statusbar,
922 &globalconf.screens[screen].padding);
924 if(sel)
925 client_maximize(sel, sel->x, area.y,
926 sel->w,
927 area.height - 2 * sel->border, False);
931 /** Toggle horizontal maximize for client
932 * \param screen Screen ID
933 * \param arg Unused
934 * \ingroup ui_callback
936 void
937 uicb_client_togglehorizontalmax(int screen, char *arg __attribute__ ((unused)))
939 Client *sel = globalconf.focus->client;
940 Area area = get_screen_area(screen,
941 globalconf.screens[screen].statusbar,
942 &globalconf.screens[screen].padding);
944 if(sel)
945 client_maximize(sel, area.x, sel->y,
946 area.height - 2 * sel->border,
947 sel->h, False);
950 /** Zoom client
951 * \param screen Screen ID
952 * \param arg Unused
953 * \ingroup ui_callback
955 void
956 uicb_client_zoom(int screen, char *arg __attribute__ ((unused)))
958 Client *sel = globalconf.focus->client;
960 if(globalconf.clients == sel)
961 for(sel = sel->next; sel && !client_isvisible(sel, screen); sel = sel->next);
963 if(!sel)
964 return;
966 client_detach(sel);
967 client_attach(sel);
969 focus(sel, True, screen);
970 arrange(screen);
973 // vim: filetype=c:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=80