manpage update (scale, max and awesomerc(1))
[awesome.git] / client.c
bloba663b1399b5fb2a60d8f31d355d35a6bc236a91b
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 "tag.h"
29 #include "rules.h"
30 #include "util.h"
31 #include "xutil.h"
32 #include "statusbar.h"
33 #include "window.h"
34 #include "focus.h"
35 #include "ewmh.h"
36 #include "screen.h"
37 #include "layouts/floating.h"
40 extern AwesomeConf globalconf;
42 /** Load windows properties, restoring client's tag
43 * and floating state before awesome was restarted if any
44 * \todo this may bug if number of tags is != than before
45 * \param c Client ref
46 * \param screen Screen ID
48 static Bool
49 client_loadprops(Client * c, int screen)
51 int i, ntags = 0;
52 Tag *tag;
53 char *prop;
54 Bool result = False;
56 for(tag = globalconf.screens[screen].tags; tag; tag = tag->next)
57 ntags++;
59 prop = p_new(char, ntags + 2);
61 if(xgettextprop(c->win,
62 XInternAtom(globalconf.display, "_AWESOME_PROPERTIES", False),
63 prop, ntags + 2))
65 for(i = 0, tag = globalconf.screens[screen].tags; tag && i < ntags && prop[i]; i++, tag = tag->next)
66 if(prop[i] == '1')
68 tag_client(c, tag);
69 result = True;
71 else
72 untag_client(c, tag);
74 if(i <= ntags && prop[i])
75 c->isfloating = prop[i] == '1';
78 p_delete(&prop);
80 return result;
83 /** Check if client supports protocol WM_DELETE_WINDOW
84 * \param disp the display
85 * \param win the Window
86 * \return True if client has WM_DELETE_WINDOW
88 static Bool
89 isprotodel(Display *disp, Window win)
91 int i, n;
92 Atom *protocols;
93 Bool ret = False;
95 if(XGetWMProtocols(disp, win, &protocols, &n))
97 for(i = 0; !ret && i < n; i++)
98 if(protocols[i] == XInternAtom(disp, "WM_DELETE_WINDOW", False))
99 ret = True;
100 XFree(protocols);
102 return ret;
105 /** Swap two client in the linked list clients
106 * \param head pointer ito the client list head
107 * \param c1 first client
108 * \param c2 second client
110 static void
111 client_swap(Client **head, Client *c1, Client *c2)
113 Client *tmp;
115 tmp = c1->next;
116 c1->next = c2->next;
117 c2->next = (tmp == c2 ? c1 : tmp);
119 tmp = c2->prev;
120 c2->prev = c1->prev;
121 c1->prev = (tmp == c1 ? c2 : tmp );
123 if(c1->next)
124 c1->next->prev = c1;
126 if(c1->prev)
127 c1->prev->next = c1;
129 if(c2->next)
130 c2->next->prev = c2;
132 if(c2->prev)
133 c2->prev->next = c2;
135 if(*head == c1)
136 *head = c2;
139 /** Get a Client by its window
140 * \param list Client list to look info
141 * \param w Client window to find
142 * \return client
144 Client *
145 get_client_bywin(Client *list, Window w)
147 Client *c;
149 for(c = list; c && c->win != w; c = c->next);
150 return c;
154 /** Get a client by its name
155 * \param list Client list
156 * \param name name to search
157 * \return first matching client
159 Client *
160 get_client_byname(Client *list, char *name)
162 Client *c;
164 for(c = list; c; c = c->next)
165 if(strstr(c->name, name))
166 return c;
168 return NULL;
171 /** Update client name attribute with its title
172 * \param c the client
174 void
175 client_updatetitle(Client *c)
177 if(!xgettextprop(c->win, XInternAtom(globalconf.display, "_NET_WM_NAME", False), c->name, sizeof(c->name)))
178 xgettextprop(c->win, XInternAtom(globalconf.display, "WM_NAME", False), c->name, sizeof(c->name));
181 /** Ban client and unmap it
182 * \param c the client
184 void
185 client_ban(Client * c)
187 XUnmapWindow(globalconf.display, c->win);
188 window_setstate(c->win, IconicState);
192 static void
193 client_attach_at_end(Client *c)
195 Client *iter;
196 for(iter = globalconf.clients; iter && iter->next; iter = iter->next);
197 /* stack is empty */
198 if(!iter)
199 globalconf.clients = c;
200 else
202 c->prev = iter;
203 iter->next = c;
207 /** Attach client to the beginning of the clients stack
208 * \param c the client
210 void
211 client_attach(Client *c)
213 if(globalconf.clients)
214 (globalconf.clients)->prev = c;
215 c->next = globalconf.clients;
216 globalconf.clients = c;
219 /** Detach client from clients list
220 * \param c client to detach
222 void
223 client_detach(Client *c)
225 if(c->prev)
226 c->prev->next = c->next;
227 if(c->next)
228 c->next->prev = c->prev;
229 if(c == globalconf.clients)
230 globalconf.clients = c->next;
231 c->next = c->prev = NULL;
234 /** Give focus to client, or to first client if c is NULL
235 * \param c client
236 * \param selscreen True if current screen is selected
237 * \param screen Screen ID
239 void
240 focus(Client *c, Bool selscreen, int screen)
242 int phys_screen = get_phys_screen(screen);
244 /* unfocus current selected client */
245 if(globalconf.focus->client)
247 window_grabbuttons(get_phys_screen(globalconf.focus->client->screen),
248 globalconf.focus->client->win, False, True);
249 XSetWindowBorder(globalconf.display, globalconf.focus->client->win,
250 globalconf.screens[screen].colors_normal[ColBorder].pixel);
251 window_settrans(globalconf.focus->client->win,
252 globalconf.screens[screen].opacity_unfocused);
256 /* if c is NULL or invisible, take next client in the focus history */
257 if((!c && selscreen) || (c && !client_isvisible(c, screen)))
259 c = focus_get_current_client(screen);
260 /* if c is still NULL take next client in the stack */
261 if(!c)
262 for(c = globalconf.clients; c && (c->skip || !client_isvisible(c, screen)); c = c->next);
265 if(c)
267 XSetWindowBorder(globalconf.display, c->win, globalconf.screens[screen].colors_selected[ColBorder].pixel);
268 window_grabbuttons(phys_screen, c->win, True, True);
271 if(!selscreen)
272 return;
274 /* save sel in focus history */
275 focus_add_client(c);
277 statusbar_draw_all(screen);
279 if(globalconf.focus->client)
281 XSetInputFocus(globalconf.display,
282 globalconf.focus->client->win, RevertToPointerRoot, CurrentTime);
283 for(c = globalconf.clients; c; c = c->next)
284 if(c != globalconf.focus->client)
285 window_settrans(globalconf.focus->client->win,
286 globalconf.screens[screen].opacity_unfocused);
287 window_settrans(globalconf.focus->client->win, -1);
289 else
290 XSetInputFocus(globalconf.display,
291 RootWindow(globalconf.display, phys_screen),
292 RevertToPointerRoot, CurrentTime);
294 ewmh_update_net_active_window(phys_screen);
297 /** Manage a new client
298 * \param w The window
299 * \param wa Window attributes
300 * \param screen Screen ID
302 void
303 client_manage(Window w, XWindowAttributes *wa, int screen)
305 Client *c, *t = NULL;
306 Window trans;
307 Status rettrans;
308 XWindowChanges wc;
309 Area area, darea;
310 Tag *tag;
311 Rule *rule;
312 int phys_screen = get_phys_screen(screen);
314 area = get_screen_area(screen, NULL, NULL);
316 c = p_new(Client, 1);
318 c->win = w;
319 c->geometry.x = c->f_geometry.x = c->m_geometry.x = wa->x;
320 c->geometry.y = c->f_geometry.y = c->m_geometry.y = wa->y;
321 c->geometry.width = c->f_geometry.width = c->m_geometry.width = wa->width;
322 c->geometry.height = c->f_geometry.height = c->m_geometry.height = wa->height;
323 c->oldborder = wa->border_width;
325 c->screen = get_screen_bycoord(c->geometry.x, c->geometry.y);
327 move_client_to_screen(c, screen, True);
329 /* update window title */
330 client_updatetitle(c);
332 if(c->geometry.width == area.width && c->geometry.height == area.height)
333 c->border = wa->border_width;
334 else
335 c->border = globalconf.screens[screen].borderpx;
337 ewmh_check_client_hints(c);
338 /* loadprops or apply rules if no props */
339 if(!client_loadprops(c, screen))
340 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, 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->geometry.x, c->geometry.y,
419 c->geometry.width, c->geometry.height);
421 focus(c, True, screen);
423 ewmh_update_net_client_list(phys_screen);
425 /* rearrange to display new window */
426 arrange(c->screen);
429 /** Resize client window
430 * \param c client to resize
431 * \param x x coord
432 * \param y y coord
433 * \param w width
434 * \param h height
435 * \param sizehints respect size hints
436 * \param volatile_coords register coords in rx/ry/rw/rh
437 * \param return True if resize has been done
439 Bool
440 client_resize(Client *c, Area geometry, Bool sizehints)
442 int new_screen;
443 double dx, dy, max, min, ratio;
444 Area area;
445 XWindowChanges wc;
447 if(sizehints)
449 if(c->minay > 0 && c->maxay > 0 && (geometry.height - c->baseh) > 0
450 && (geometry.width - c->basew) > 0)
452 dx = (double) (geometry.width - c->basew);
453 dy = (double) (geometry.height - c->baseh);
454 min = (double) (c->minax) / (double) (c->minay);
455 max = (double) (c->maxax) / (double) (c->maxay);
456 ratio = dx / dy;
457 if(max > 0 && min > 0 && ratio > 0)
459 if(ratio < min)
461 dy = (dx * min + dy) / (min * min + 1);
462 dx = dy * min;
463 geometry.width = (int) dx + c->basew;
464 geometry.height = (int) dy + c->baseh;
466 else if(ratio > max)
468 dy = (dx * min + dy) / (max * max + 1);
469 dx = dy * min;
470 geometry.width = (int) dx + c->basew;
471 geometry.height = (int) dy + c->baseh;
475 if(c->minw && geometry.width < c->minw)
476 geometry.width = c->minw;
477 if(c->minh && geometry.height < c->minh)
478 geometry.height = c->minh;
479 if(c->maxw && geometry.width > c->maxw)
480 geometry.width = c->maxw;
481 if(c->maxh && geometry.height > c->maxh)
482 geometry.height = c->maxh;
483 if(c->incw)
484 geometry.width -= (geometry.width - c->basew) % c->incw;
485 if(c->inch)
486 geometry.height -= (geometry.height - c->baseh) % c->inch;
488 if(geometry.width <= 0 || geometry.height <= 0)
489 return False;
490 /* offscreen appearance fixes */
491 area = get_display_area(get_phys_screen(c->screen),
492 NULL,
493 &globalconf.screens[c->screen].padding);
494 if(geometry.x > area.width)
495 geometry.x = area.width - geometry.width - 2 * c->border;
496 if(geometry.y > area.height)
497 geometry.y = area.height - geometry.height - 2 * c->border;
498 if(geometry.x + geometry.width + 2 * c->border < 0)
499 geometry.x = 0;
500 if(geometry.y + geometry.height + 2 * c->border < 0)
501 geometry.y = 0;
503 if(c->geometry.x != geometry.x || c->geometry.y != geometry.y
504 || c->geometry.width != geometry.width || c->geometry.height != geometry.height)
506 if(XineramaIsActive(globalconf.display))
507 new_screen = get_screen_bycoord(geometry.x, geometry.y);
508 else
509 new_screen = c->screen;
511 c->geometry.x = wc.x = geometry.x;
512 c->geometry.y = wc.y = geometry.y;
513 c->geometry.width = wc.width = geometry.width;
514 c->geometry.height = wc.height = geometry.height;
515 wc.border_width = c->border;
517 if(c->isfloating ||
518 get_current_layout(new_screen)->arrange == layout_floating)
519 c->f_geometry = geometry;
521 XConfigureWindow(globalconf.display, c->win,
522 CWX | CWY | CWWidth | CWHeight | CWBorderWidth, &wc);
523 window_configure(c->win, geometry, c->border);
525 if(c->screen != new_screen)
526 move_client_to_screen(c, new_screen, False);
528 return True;
530 return False;
533 /** Save client properties as an X property
534 * \param c client
536 void
537 client_saveprops(Client *c)
539 int i = 0, ntags = 0;
540 char *prop;
541 Tag *tag;
543 for(tag = globalconf.screens[c->screen].tags; tag; tag = tag->next)
544 ntags++;
546 prop = p_new(char, ntags + 2);
548 for(tag = globalconf.screens[c->screen].tags; tag; tag = tag->next, i++)
549 prop[i] = is_client_tagged(c, tag) ? '1' : '0';
551 if(i <= ntags)
552 prop[i] = c->isfloating ? '1' : '0';
554 prop[++i] = '\0';
556 XChangeProperty(globalconf.display, c->win,
557 XInternAtom(globalconf.display, "_AWESOME_PROPERTIES", False),
558 XA_STRING, 8, PropModeReplace, (unsigned char *) prop, i);
560 p_delete(&prop);
563 void
564 client_unban(Client *c)
566 XMapWindow(globalconf.display, c->win);
567 window_setstate(c->win, NormalState);
570 void
571 client_unmanage(Client *c)
573 XWindowChanges wc;
574 Tag *tag;
576 wc.border_width = c->oldborder;
578 /* The server grab construct avoids race conditions. */
579 XGrabServer(globalconf.display);
581 XConfigureWindow(globalconf.display, c->win, CWBorderWidth, &wc); /* restore border */
583 /* remove client everywhere */
584 client_detach(c);
585 focus_delete_client(c);
586 for(tag = globalconf.screens[c->screen].tags; tag; tag = tag->next)
587 untag_client(c, tag);
589 if(globalconf.focus->client == c)
590 focus(NULL, True, c->screen);
593 XUngrabButton(globalconf.display, AnyButton, AnyModifier, c->win);
594 window_setstate(c->win, WithdrawnState);
596 XSync(globalconf.display, False);
597 XUngrabServer(globalconf.display);
599 arrange(c->screen);
600 p_delete(&c);
603 void
604 client_updatewmhints(Client *c)
606 XWMHints *wmh;
608 if((wmh = XGetWMHints(globalconf.display, c->win)))
610 c->isurgent = (wmh->flags & XUrgencyHint);
611 if((wmh->flags & StateHint) && wmh->initial_state == WithdrawnState)
612 c->skip = True;
613 XFree(wmh);
617 void
618 client_updatesizehints(Client *c)
620 long msize;
621 XSizeHints size;
623 if(!XGetWMNormalHints(globalconf.display, c->win, &size, &msize) || !size.flags)
624 size.flags = PSize;
625 if(size.flags & PBaseSize)
627 c->basew = size.base_width;
628 c->baseh = size.base_height;
630 else if(size.flags & PMinSize)
632 c->basew = size.min_width;
633 c->baseh = size.min_height;
635 else
636 c->basew = c->baseh = 0;
637 if(size.flags & PResizeInc)
639 c->incw = size.width_inc;
640 c->inch = size.height_inc;
642 else
643 c->incw = c->inch = 0;
645 if(size.flags & PMaxSize)
647 c->maxw = size.max_width;
648 c->maxh = size.max_height;
650 else
651 c->maxw = c->maxh = 0;
653 if(size.flags & PMinSize)
655 c->minw = size.min_width;
656 c->minh = size.min_height;
658 else if(size.flags & PBaseSize)
660 c->minw = size.base_width;
661 c->minh = size.base_height;
663 else
664 c->minw = c->minh = 0;
666 if(size.flags & PAspect)
668 c->minax = size.min_aspect.x;
669 c->maxax = size.max_aspect.x;
670 c->minay = size.min_aspect.y;
671 c->maxay = size.max_aspect.y;
673 else
674 c->minax = c->maxax = c->minay = c->maxay = 0;
676 if(c->maxw && c->minw && c->maxh && c->minh
677 && c->maxw == c->minw && c->maxh == c->minh)
678 c->isfixed = True;
681 /** Returns True if a client is tagged
682 * with one of the tags
683 * \return True or False
685 Bool
686 client_isvisible(Client *c, int screen)
688 Tag *tag;
690 if(c->screen != screen)
691 return False;
693 for(tag = globalconf.screens[screen].tags; tag; tag = tag->next)
694 if(tag->selected && is_client_tagged(c, tag))
695 return True;
696 return False;
699 /** Set selected client transparency
700 * \param screen Screen ID
701 * \param arg unused arg
702 * \ingroup ui_callback
704 void
705 uicb_client_settrans(int screen __attribute__ ((unused)), char *arg)
707 double delta = 100.0, current_opacity = 100.0;
708 unsigned char *data;
709 Atom actual;
710 int format;
711 unsigned long n, left;
712 unsigned int current_opacity_raw = 0;
713 int set_prop = 0;
714 Client *sel = globalconf.focus->client;
716 if(!sel)
717 return;
719 XGetWindowProperty(globalconf.display, sel->win,
720 XInternAtom(globalconf.display, "_NET_WM_WINDOW_OPACITY", False),
721 0L, 1L, False, XA_CARDINAL, &actual, &format, &n, &left,
722 (unsigned char **) &data);
723 if(data)
725 memcpy(&current_opacity_raw, data, sizeof(unsigned int));
726 XFree(data);
727 current_opacity = (current_opacity_raw * 100.0) / 0xffffffff;
729 else
730 set_prop = 1;
732 delta = compute_new_value_from_arg(arg, current_opacity);
734 if(delta <= 0.0)
735 delta = 0.0;
736 else if(delta > 100.0)
738 delta = 100.0;
739 set_prop = 1;
742 if(delta == 100.0 && !set_prop)
743 window_settrans(sel->win, -1);
744 else
745 window_settrans(sel->win, delta);
748 /** Swap current with next client
749 * \param screen Screen ID
750 * \param arg nothing
751 * \ingroup ui_callback
753 void
754 uicb_client_swapnext(int screen, char *arg __attribute__ ((unused)))
756 Client *next, *sel = globalconf.focus->client;
758 if(!sel)
759 return;
761 for(next = sel->next; next && !client_isvisible(next, screen); next = next->next);
762 if(next)
764 client_swap(&globalconf.clients, sel, next);
765 arrange(screen);
766 /* restore focus */
767 focus(sel, True, screen);
771 /** Swap current with previous client
772 * \param screen Screen ID
773 * \param arg nothing
774 * \ingroup ui_callback
776 void
777 uicb_client_swapprev(int screen, char *arg __attribute__ ((unused)))
779 Client *prev, *sel = globalconf.focus->client;
781 if(!sel)
782 return;
784 for(prev = sel->prev; prev && !client_isvisible(prev, screen); prev = prev->prev);
785 if(prev)
787 client_swap(&globalconf.clients, prev, sel);
788 arrange(screen);
789 /* restore focus */
790 focus(sel, True, screen);
794 /** Move and resize client
795 * \param screen Screen ID
796 * \param arg x y w h
797 * \ingroup ui_callback
799 void
800 uicb_client_moveresize(int screen, char *arg)
802 int ox, oy, ow, oh;
803 char x[8], y[8], w[8], h[8];
804 int mx, my, dx, dy, nmx, nmy;
805 unsigned int dui;
806 Window dummy;
807 Area area;
808 Client *sel = globalconf.focus->client;
809 Tag **curtags = get_current_tags(screen);
811 if(curtags[0]->layout->arrange != layout_floating)
812 if(!sel || !sel->isfloating || sel->isfixed || !arg)
814 p_delete(&curtags);
815 return;
817 p_delete(&curtags);
818 if(sscanf(arg, "%s %s %s %s", x, y, w, h) != 4)
819 return;
820 area.x = (int) compute_new_value_from_arg(x, sel->geometry.x);
821 area.y = (int) compute_new_value_from_arg(y, sel->geometry.y);
822 area.width = (int) compute_new_value_from_arg(w, sel->geometry.width);
823 area.height = (int) compute_new_value_from_arg(h, sel->geometry.height);
825 ox = sel->geometry.x;
826 oy = sel->geometry.y;
827 ow = sel->geometry.width;
828 oh = sel->geometry.height;
830 Bool xqp = XQueryPointer(globalconf.display,
831 RootWindow(globalconf.display,
832 get_phys_screen(screen)),
833 &dummy, &dummy, &mx, &my, &dx, &dy, &dui);
834 client_resize(sel, area, globalconf.screens[sel->screen].resize_hints);
835 if (xqp && ox <= mx && (ox + ow) >= mx && oy <= my && (oy + oh) >= my)
837 nmx = mx - ox + sel->geometry.width - ow - 1 < 0 ? 0 : mx - ox + sel->geometry.width - ow - 1;
838 nmy = my - oy + sel->geometry.height - oh - 1 < 0 ? 0 : my - oy + sel->geometry.height - oh - 1;
839 XWarpPointer(globalconf.display,
840 None, sel->win,
841 0, 0, 0, 0, nmx, nmy);
846 void
847 client_kill(Client *c)
849 XEvent ev;
851 if(isprotodel(globalconf.display, c->win))
853 ev.type = ClientMessage;
854 ev.xclient.window = c->win;
855 ev.xclient.message_type = XInternAtom(globalconf.display, "WM_PROTOCOLS", False);
856 ev.xclient.format = 32;
857 ev.xclient.data.l[0] = XInternAtom(globalconf.display, "WM_DELETE_WINDOW", False);
858 ev.xclient.data.l[1] = CurrentTime;
859 XSendEvent(globalconf.display, c->win, False, NoEventMask, &ev);
861 else
862 XKillClient(globalconf.display, c->win);
865 /** Kill selected client
866 * \param screen Screen ID
867 * \param arg unused
868 * \ingroup ui_callback
870 void
871 uicb_client_kill(int screen __attribute__ ((unused)), char *arg __attribute__ ((unused)))
873 Client *sel = globalconf.focus->client;
875 if(sel)
876 client_kill(sel);
879 static void
880 client_maximize(Client *c, Area geometry)
883 if((c->ismax = !c->ismax))
885 c->wasfloating = c->isfloating;
886 c->m_geometry = c->geometry;
887 client_resize(c, geometry, False);
888 /* set floating after resizing so it won't save
889 * coords */
890 c->isfloating = True;
891 restack(c->screen);
893 else if(c->wasfloating)
895 c->isfloating = True;
896 client_resize(c, c->m_geometry, False);
897 restack(c->screen);
899 else
901 c->isfloating = False;
902 arrange(c->screen);
904 statusbar_draw_all(c->screen);
907 /** Toggle maximize for client
908 * \param screen Screen ID
909 * \param arg Unused
910 * \ingroup ui_callback
912 void
913 uicb_client_togglemax(int screen, char *arg __attribute__ ((unused)))
915 Client *sel = globalconf.focus->client;
916 Area area = get_screen_area(screen,
917 globalconf.screens[screen].statusbar,
918 &globalconf.screens[screen].padding);
920 if(sel)
922 area.width -= 2 * sel->border;
923 area.height -= 2 * sel->border;
924 client_maximize(sel, area);
928 /** Toggle vertical maximize for client
929 * \param screen Screen ID
930 * \param arg Unused
931 * \ingroup ui_callback
933 void
934 uicb_client_toggleverticalmax(int screen, char *arg __attribute__ ((unused)))
936 Client *sel = globalconf.focus->client;
937 Area area = get_screen_area(screen,
938 globalconf.screens[screen].statusbar,
939 &globalconf.screens[screen].padding);
941 if(sel)
943 area.x = sel->geometry.x;
944 area.height -= 2 * sel->border;
945 client_maximize(sel, area);
950 /** Toggle horizontal maximize for client
951 * \param screen Screen ID
952 * \param arg Unused
953 * \ingroup ui_callback
955 void
956 uicb_client_togglehorizontalmax(int screen, char *arg __attribute__ ((unused)))
958 Client *sel = globalconf.focus->client;
959 Area area = get_screen_area(screen,
960 globalconf.screens[screen].statusbar,
961 &globalconf.screens[screen].padding);
963 if(sel)
965 area.y = sel->geometry.y;
966 area.width -= 2 * sel->border;
967 client_maximize(sel, area);
971 /** Zoom client
972 * \param screen Screen ID
973 * \param arg Unused
974 * \ingroup ui_callback
976 void
977 uicb_client_zoom(int screen, char *arg __attribute__ ((unused)))
979 Client *sel = globalconf.focus->client;
981 if(globalconf.clients == sel)
982 for(sel = sel->next; sel && !client_isvisible(sel, screen); sel = sel->next);
984 if(!sel)
985 return;
987 client_detach(sel);
988 client_attach(sel);
990 focus(sel, True, screen);
991 arrange(screen);
994 // vim: filetype=c:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=80