use Area to store window geoms
[awesome.git] / client.c
blob540efaf82f8e5f61dfdcd20f5be12da03cd65833
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->geometry.x = c->f_geometry.x = c->m_geometry.x = wa->x;
319 c->geometry.y = c->f_geometry.y = c->m_geometry.y = wa->y;
320 c->geometry.width = c->f_geometry.width = c->m_geometry.width = wa->width;
321 c->geometry.height = c->f_geometry.height = c->m_geometry.height = wa->height;
322 c->oldborder = wa->border_width;
324 c->screen = get_screen_bycoord(c->geometry.x, c->geometry.y);
326 move_client_to_screen(c, screen, True);
328 /* update window title */
329 client_updatetitle(c);
331 if(c->geometry.width == area.width && c->geometry.height == 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->geometry.width == area.width && c->geometry.height == area.height)
345 c->geometry.x = area.x;
346 c->geometry.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->geometry.x + c->geometry.width + 2 * c->border > darea.x + darea.width)
355 c->geometry.x = c->f_geometry.x = darea.x + darea.width - c->geometry.width - 2 * c->border;
356 if(c->geometry.y + c->geometry.height + 2 * c->border > darea.y + darea.height)
357 c->geometry.y = c->f_geometry.y = darea.y + darea.height - c->geometry.height - 2 * c->border;
358 if(c->geometry.x < darea.x)
359 c->geometry.x = c->f_geometry.x = darea.x;
360 if(c->geometry.y < darea.y)
361 c->geometry.y = c->f_geometry.y = darea.y;
364 /* XXX if this necessary ? */
365 /* set borders */
366 wc.border_width = c->border;
367 XConfigureWindow(globalconf.display, w, CWBorderWidth, &wc);
368 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->geometry.x, c->geometry.y,
371 c->geometry.width, c->geometry.height, c->border);
373 /* update hints */
374 client_updatesizehints(c);
375 client_updatewmhints(c);
377 XSelectInput(globalconf.display, w, StructureNotifyMask | PropertyChangeMask | EnterWindowMask);
379 /* handle xshape */
380 if(globalconf.have_shape)
382 XShapeSelectInput(globalconf.display, w, ShapeNotifyMask);
383 window_setshape(phys_screen, c->win);
386 /* grab buttons */
387 window_grabbuttons(phys_screen, c->win, False, True);
389 /* check for transient and set tags like its parent */
390 if((rettrans = XGetTransientForHint(globalconf.display, w, &trans) == Success)
391 && (t = get_client_bywin(globalconf.clients, trans)))
392 for(tag = globalconf.screens[c->screen].tags; tag; tag = tag->next)
393 if(is_client_tagged(t, tag))
394 tag_client(c, tag);
396 /* should be floating if transsient or fixed */
397 if(!c->isfloating)
398 c->isfloating = (rettrans == Success) || c->isfixed;
400 /* save new props */
401 client_saveprops(c);
403 /* attach to the stack */
404 for(rule = globalconf.rules; rule; rule = rule->next)
405 if(rule->not_master && client_match_rule(c, rule))
407 client_attach_at_end(c);
408 break;
410 if(!rule)
412 if(globalconf.screens[c->screen].new_become_master)
413 client_attach(c);
414 else
415 client_attach_at_end(c);
418 /* some windows require this */
419 XMoveResizeWindow(globalconf.display, c->win, c->geometry.x, c->geometry.y,
420 c->geometry.width, c->geometry.height);
422 focus(c, True, screen);
424 ewmh_update_net_client_list(phys_screen);
426 /* rearrange to display new window */
427 arrange(screen);
430 /** Resize client window
431 * \param c client to resize
432 * \param x x coord
433 * \param y y coord
434 * \param w width
435 * \param h height
436 * \param sizehints respect size hints
437 * \param volatile_coords register coords in rx/ry/rw/rh
439 void
440 client_resize(Client *c, int x, int y, int w, int h,
441 Bool sizehints, Bool volatile_coords)
443 double dx, dy, max, min, ratio;
444 Area area;
445 Tag **curtags;
447 if(sizehints)
449 if(c->minay > 0 && c->maxay > 0 && (h - c->baseh) > 0 && (w - c->basew) > 0)
451 dx = (double) (w - c->basew);
452 dy = (double) (h - c->baseh);
453 min = (double) (c->minax) / (double) (c->minay);
454 max = (double) (c->maxax) / (double) (c->maxay);
455 ratio = dx / dy;
456 if(max > 0 && min > 0 && ratio > 0)
458 if(ratio < min)
460 dy = (dx * min + dy) / (min * min + 1);
461 dx = dy * min;
462 w = (int) dx + c->basew;
463 h = (int) dy + c->baseh;
465 else if(ratio > max)
467 dy = (dx * min + dy) / (max * max + 1);
468 dx = dy * min;
469 w = (int) dx + c->basew;
470 h = (int) dy + c->baseh;
474 if(c->minw && w < c->minw)
475 w = c->minw;
476 if(c->minh && h < c->minh)
477 h = c->minh;
478 if(c->maxw && w > c->maxw)
479 w = c->maxw;
480 if(c->maxh && h > c->maxh)
481 h = c->maxh;
482 if(c->incw)
483 w -= (w - c->basew) % c->incw;
484 if(c->inch)
485 h -= (h - c->baseh) % c->inch;
487 if(w <= 0 || h <= 0)
488 return;
489 /* offscreen appearance fixes */
490 area = get_display_area(get_phys_screen(c->screen),
491 NULL,
492 &globalconf.screens[c->screen].padding);
493 if(x > area.width)
494 x = area.width - w - 2 * c->border;
495 if(y > area.height)
496 y = area.height - h - 2 * c->border;
497 if(x + w + 2 * c->border < 0)
498 x = 0;
499 if(y + h + 2 * c->border < 0)
500 y = 0;
501 if(c->geometry.x != x || c->geometry.y != y
502 || c->geometry.width != w || c->geometry.height != h)
504 c->geometry.x = x;
505 c->geometry.y = y;
506 c->geometry.width = w;
507 c->geometry.height = h;
508 curtags = get_current_tags(c->screen);
509 if(!volatile_coords && (c->isfloating
510 || curtags[0]->layout->arrange == layout_floating))
512 c->f_geometry.x = x;
513 c->f_geometry.y = y;
514 c->f_geometry.width = w;
515 c->f_geometry.height = h;
517 p_delete(&curtags);
518 XMoveResizeWindow(globalconf.display, c->win, x, y, w, h);
519 window_configure(c->win, x, y, w, h, c->border);
520 if(XineramaIsActive(globalconf.display))
522 int new_screen = get_screen_bycoord(x, y);
523 if(c->screen != new_screen)
524 move_client_to_screen(c, new_screen, False);
529 /** Save client properties as an X property
530 * \param c client
532 void
533 client_saveprops(Client *c)
535 int i = 0, ntags = 0;
536 char *prop;
537 Tag *tag;
539 for(tag = globalconf.screens[c->screen].tags; tag; tag = tag->next)
540 ntags++;
542 prop = p_new(char, ntags + 2);
544 for(tag = globalconf.screens[c->screen].tags; tag; tag = tag->next, i++)
545 prop[i] = is_client_tagged(c, tag) ? '1' : '0';
547 if(i <= ntags)
548 prop[i] = c->isfloating ? '1' : '0';
550 prop[++i] = '\0';
552 XChangeProperty(globalconf.display, c->win, AWESOMEPROPS_ATOM(globalconf.display), XA_STRING, 8,
553 PropModeReplace, (unsigned char *) prop, i);
555 p_delete(&prop);
558 void
559 client_unban(Client *c)
561 XMapWindow(globalconf.display, c->win);
562 window_setstate(c->win, NormalState);
565 void
566 client_unmanage(Client *c, long state)
568 XWindowChanges wc;
569 Tag *tag;
571 wc.border_width = c->oldborder;
572 /* The server grab construct avoids race conditions. */
573 XGrabServer(globalconf.display);
574 XConfigureWindow(globalconf.display, c->win, CWBorderWidth, &wc); /* restore border */
575 client_detach(c);
576 if(globalconf.focus->client == c)
577 focus(NULL, True, c->screen);
578 focus_delete_client(c);
579 for(tag = globalconf.screens[c->screen].tags; tag; tag = tag->next)
580 untag_client(c, tag);
581 XUngrabButton(globalconf.display, AnyButton, AnyModifier, c->win);
582 window_setstate(c->win, state);
583 XSync(globalconf.display, False);
584 XSetErrorHandler(xerror);
585 XUngrabServer(globalconf.display);
586 if(state != NormalState)
587 arrange(c->screen);
588 p_delete(&c);
591 void
592 client_updatewmhints(Client *c)
594 XWMHints *wmh;
596 if((wmh = XGetWMHints(globalconf.display, c->win)))
598 c->isurgent = (wmh->flags & XUrgencyHint);
599 if((wmh->flags & StateHint) && wmh->initial_state == WithdrawnState)
600 c->skip = True;
601 XFree(wmh);
605 void
606 client_updatesizehints(Client *c)
608 long msize;
609 XSizeHints size;
611 if(!XGetWMNormalHints(globalconf.display, c->win, &size, &msize) || !size.flags)
612 size.flags = PSize;
613 if(size.flags & PBaseSize)
615 c->basew = size.base_width;
616 c->baseh = size.base_height;
618 else if(size.flags & PMinSize)
620 c->basew = size.min_width;
621 c->baseh = size.min_height;
623 else
624 c->basew = c->baseh = 0;
625 if(size.flags & PResizeInc)
627 c->incw = size.width_inc;
628 c->inch = size.height_inc;
630 else
631 c->incw = c->inch = 0;
633 if(size.flags & PMaxSize)
635 c->maxw = size.max_width;
636 c->maxh = size.max_height;
638 else
639 c->maxw = c->maxh = 0;
641 if(size.flags & PMinSize)
643 c->minw = size.min_width;
644 c->minh = size.min_height;
646 else if(size.flags & PBaseSize)
648 c->minw = size.base_width;
649 c->minh = size.base_height;
651 else
652 c->minw = c->minh = 0;
654 if(size.flags & PAspect)
656 c->minax = size.min_aspect.x;
657 c->maxax = size.max_aspect.x;
658 c->minay = size.min_aspect.y;
659 c->maxay = size.max_aspect.y;
661 else
662 c->minax = c->maxax = c->minay = c->maxay = 0;
664 if(c->maxw && c->minw && c->maxh && c->minh
665 && c->maxw == c->minw && c->maxh == c->minh)
666 c->isfixed = True;
669 /** Returns True if a client is tagged
670 * with one of the tags
671 * \return True or False
673 Bool
674 client_isvisible(Client *c, int screen)
676 Tag *tag;
678 if(c->screen != screen)
679 return False;
681 for(tag = globalconf.screens[screen].tags; tag; tag = tag->next)
682 if(tag->selected && is_client_tagged(c, tag))
683 return True;
684 return False;
687 /** Set selected client transparency
688 * \param screen Screen ID
689 * \param arg unused arg
690 * \ingroup ui_callback
692 void
693 uicb_client_settrans(int screen __attribute__ ((unused)), char *arg)
695 double delta = 100.0, current_opacity = 100.0;
696 unsigned char *data;
697 Atom actual;
698 int format;
699 unsigned long n, left;
700 unsigned int current_opacity_raw = 0;
701 int set_prop = 0;
702 Client *sel = globalconf.focus->client;
704 if(!sel)
705 return;
707 XGetWindowProperty(globalconf.display, sel->win,
708 XInternAtom(globalconf.display, "_NET_WM_WINDOW_OPACITY", False),
709 0L, 1L, False, XA_CARDINAL, &actual, &format, &n, &left,
710 (unsigned char **) &data);
711 if(data)
713 memcpy(&current_opacity_raw, data, sizeof(unsigned int));
714 XFree(data);
715 current_opacity = (current_opacity_raw * 100.0) / 0xffffffff;
717 else
718 set_prop = 1;
720 delta = compute_new_value_from_arg(arg, current_opacity);
722 if(delta <= 0.0)
723 delta = 0.0;
724 else if(delta > 100.0)
726 delta = 100.0;
727 set_prop = 1;
730 if(delta == 100.0 && !set_prop)
731 window_settrans(sel->win, -1);
732 else
733 window_settrans(sel->win, delta);
736 /** Swap current with next client
737 * \param screen Screen ID
738 * \param arg nothing
739 * \ingroup ui_callback
741 void
742 uicb_client_swapnext(int screen, char *arg __attribute__ ((unused)))
744 Client *next, *sel = globalconf.focus->client;
746 if(!sel)
747 return;
749 for(next = sel->next; next && !client_isvisible(next, screen); next = next->next);
750 if(next)
752 client_swap(&globalconf.clients, sel, next);
753 arrange(screen);
754 /* restore focus */
755 focus(sel, True, screen);
759 /** Swap current with previous client
760 * \param screen Screen ID
761 * \param arg nothing
762 * \ingroup ui_callback
764 void
765 uicb_client_swapprev(int screen, char *arg __attribute__ ((unused)))
767 Client *prev, *sel = globalconf.focus->client;
769 if(!sel)
770 return;
772 for(prev = sel->prev; prev && !client_isvisible(prev, screen); prev = prev->prev);
773 if(prev)
775 client_swap(&globalconf.clients, prev, sel);
776 arrange(screen);
777 /* restore focus */
778 focus(sel, True, screen);
782 /** Move and resize client
783 * \param screen Screen ID
784 * \param arg x y w h
785 * \ingroup ui_callback
787 void
788 uicb_client_moveresize(int screen, char *arg)
790 int nx, ny, nw, nh, ox, oy, ow, oh;
791 char x[8], y[8], w[8], h[8];
792 int mx, my, dx, dy, nmx, nmy;
793 unsigned int dui;
794 Window dummy;
795 Client *sel = globalconf.focus->client;
796 Tag **curtags = get_current_tags(screen);
798 if(curtags[0]->layout->arrange != layout_floating)
799 if(!sel || !sel->isfloating || sel->isfixed || !arg)
801 p_delete(&curtags);
802 return;
804 p_delete(&curtags);
805 if(sscanf(arg, "%s %s %s %s", x, y, w, h) != 4)
806 return;
807 nx = (int) compute_new_value_from_arg(x, sel->geometry.x);
808 ny = (int) compute_new_value_from_arg(y, sel->geometry.y);
809 nw = (int) compute_new_value_from_arg(w, sel->geometry.width);
810 nh = (int) compute_new_value_from_arg(h, sel->geometry.height);
812 ox = sel->geometry.x;
813 oy = sel->geometry.y;
814 ow = sel->geometry.width;
815 oh = sel->geometry.height;
817 Bool xqp = XQueryPointer(globalconf.display,
818 RootWindow(globalconf.display,
819 get_phys_screen(screen)),
820 &dummy, &dummy, &mx, &my, &dx, &dy, &dui);
821 client_resize(sel, nx, ny, nw, nh, True, False);
822 if (xqp && ox <= mx && (ox + ow) >= mx && oy <= my && (oy + oh) >= my)
824 nmx = mx - ox + sel->geometry.width - ow - 1 < 0 ? 0 : mx - ox + sel->geometry.width - ow - 1;
825 nmy = my - oy + sel->geometry.height - oh - 1 < 0 ? 0 : my - oy + sel->geometry.height - oh - 1;
826 XWarpPointer(globalconf.display,
827 None, sel->win,
828 0, 0, 0, 0, nmx, nmy);
833 void
834 client_kill(Client *c)
836 XEvent ev;
838 if(isprotodel(globalconf.display, c->win))
840 ev.type = ClientMessage;
841 ev.xclient.window = c->win;
842 ev.xclient.message_type = XInternAtom(globalconf.display, "WM_PROTOCOLS", False);
843 ev.xclient.format = 32;
844 ev.xclient.data.l[0] = XInternAtom(globalconf.display, "WM_DELETE_WINDOW", False);
845 ev.xclient.data.l[1] = CurrentTime;
846 XSendEvent(globalconf.display, c->win, False, NoEventMask, &ev);
848 else
849 XKillClient(globalconf.display, c->win);
852 /** Kill selected client
853 * \param screen Screen ID
854 * \param arg unused
855 * \ingroup ui_callback
857 void
858 uicb_client_kill(int screen __attribute__ ((unused)), char *arg __attribute__ ((unused)))
860 Client *sel = globalconf.focus->client;
862 if(sel)
863 client_kill(sel);
866 void
867 client_maximize(Client *c, int x, int y, int w, int h, Bool borders)
869 if((c->ismax = !c->ismax))
871 if(borders)
873 c->oldborder = c->border;
874 c->border = 0;
876 c->wasfloating = c->isfloating;
877 c->isfloating = True;
878 client_resize(c, x, y, w, h, False, True);
880 else if(c->wasfloating)
881 client_resize(c, c->f_geometry.x, c->f_geometry.y,
882 c->f_geometry.width, c->f_geometry.height, True, False);
883 else
884 c->isfloating = False;
886 if(borders)
887 c->border = c->oldborder;
889 arrange(c->screen);
892 /** Toggle maximize for client
893 * \param screen Screen ID
894 * \param arg Unused
895 * \ingroup ui_callback
897 void
898 uicb_client_togglemax(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);
904 if(sel)
905 client_maximize(sel, area.x, area.y,
906 area.width - 2 * sel->border,
907 area.height - 2 * sel->border, False);
910 /** Toggle vertical maximize for client
911 * \param screen Screen ID
912 * \param arg Unused
913 * \ingroup ui_callback
915 void
916 uicb_client_toggleverticalmax(int screen, char *arg __attribute__ ((unused)))
918 Client *sel = globalconf.focus->client;
919 Area area = get_screen_area(screen,
920 globalconf.screens[screen].statusbar,
921 &globalconf.screens[screen].padding);
923 if(sel)
924 client_maximize(sel, sel->geometry.x, area.y,
925 sel->geometry.width,
926 area.height - 2 * sel->border, False);
930 /** Toggle horizontal maximize for client
931 * \param screen Screen ID
932 * \param arg Unused
933 * \ingroup ui_callback
935 void
936 uicb_client_togglehorizontalmax(int screen, char *arg __attribute__ ((unused)))
938 Client *sel = globalconf.focus->client;
939 Area area = get_screen_area(screen,
940 globalconf.screens[screen].statusbar,
941 &globalconf.screens[screen].padding);
943 if(sel)
944 client_maximize(sel, area.x, sel->geometry.y,
945 area.height - 2 * sel->border,
946 sel->geometry.height, False);
949 /** Zoom client
950 * \param screen Screen ID
951 * \param arg Unused
952 * \ingroup ui_callback
954 void
955 uicb_client_zoom(int screen, char *arg __attribute__ ((unused)))
957 Client *sel = globalconf.focus->client;
959 if(globalconf.clients == sel)
960 for(sel = sel->next; sel && !client_isvisible(sel, screen); sel = sel->next);
962 if(!sel)
963 return;
965 client_detach(sel);
966 client_attach(sel);
968 focus(sel, True, screen);
969 arrange(screen);
972 // vim: filetype=c:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=80