rework uicb, cosmetic, use a_str functions
[awesome.git] / client.c
blobcea331b9f09cef5cccdc1c58c08a532eeb734c38
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(globalconf.display, c->win, AWESOMEPROPS_ATOM(globalconf.display), prop, ntags + 2))
63 for(i = 0, tag = globalconf.screens[screen].tags; tag && i < ntags && prop[i]; i++, tag = tag->next)
64 if(prop[i] == '1')
66 tag_client(c, tag);
67 result = True;
69 else
70 untag_client(c, tag);
72 if(i <= ntags && prop[i])
73 c->isfloating = prop[i] == '1';
76 p_delete(&prop);
78 return result;
81 /** Check if client supports protocol WM_DELETE_WINDOW
82 * \param disp the display
83 * \param win the Window
84 * \return True if client has WM_DELETE_WINDOW
86 static Bool
87 isprotodel(Display *disp, Window win)
89 int i, n;
90 Atom *protocols;
91 Bool ret = False;
93 if(XGetWMProtocols(disp, win, &protocols, &n))
95 for(i = 0; !ret && i < n; i++)
96 if(protocols[i] == XInternAtom(disp, "WM_DELETE_WINDOW", False))
97 ret = True;
98 XFree(protocols);
100 return ret;
103 /** Swap two client in the linked list clients
104 * \param head pointer ito the client list head
105 * \param c1 first client
106 * \param c2 second client
108 static void
109 client_swap(Client **head, Client *c1, Client *c2)
111 Client *tmp;
113 tmp = c1->next;
114 c1->next = c2->next;
115 c2->next = (tmp == c2 ? c1 : tmp);
117 tmp = c2->prev;
118 c2->prev = c1->prev;
119 c1->prev = (tmp == c1 ? c2 : tmp );
121 if(c1->next)
122 c1->next->prev = c1;
124 if(c1->prev)
125 c1->prev->next = c1;
127 if(c2->next)
128 c2->next->prev = c2;
130 if(c2->prev)
131 c2->prev->next = c2;
133 if(*head == c1)
134 *head = c2;
137 /** Get a Client by its window
138 * \param list Client list to look info
139 * \param w Client window to find
140 * \return client
142 Client *
143 get_client_bywin(Client *list, Window w)
145 Client *c;
147 for(c = list; c && c->win != w; c = c->next);
148 return c;
152 /** Get a client by its name
153 * \param list Client list
154 * \param name name to search
155 * \return first matching client
157 Client *
158 get_client_byname(Client *list, char *name)
160 Client *c;
162 for(c = list; c; c = c->next)
163 if(strstr(c->name, name))
164 return c;
166 return NULL;
169 /** Update client name attribute with its title
170 * \param c the client
172 void
173 client_updatetitle(Client *c)
175 if(!xgettextprop(globalconf.display, c->win, XInternAtom(globalconf.display, "_NET_WM_NAME", False), c->name, sizeof(c->name)))
176 xgettextprop(globalconf.display, c->win, XInternAtom(globalconf.display, "WM_NAME", False), c->name, sizeof(c->name));
179 /** Ban client and unmap it
180 * \param c the client
182 void
183 client_ban(Client * c)
185 XUnmapWindow(globalconf.display, c->win);
186 window_setstate(c->win, IconicState);
190 static void
191 client_attach_at_end(Client *c)
193 Client *iter;
194 for(iter = globalconf.clients; iter && iter->next; iter = iter->next);
195 /* stack is empty */
196 if(!iter)
197 globalconf.clients = c;
198 else
200 c->prev = iter;
201 iter->next = c;
205 /** Attach client to the beginning of the clients stack
206 * \param c the client
208 void
209 client_attach(Client *c)
211 if(globalconf.clients)
212 (globalconf.clients)->prev = c;
213 c->next = globalconf.clients;
214 globalconf.clients = c;
217 /** Detach client from clients list
218 * \param c client to detach
220 void
221 client_detach(Client *c)
223 if(c->prev)
224 c->prev->next = c->next;
225 if(c->next)
226 c->next->prev = c->prev;
227 if(c == globalconf.clients)
228 globalconf.clients = c->next;
229 c->next = c->prev = NULL;
232 /** Give focus to client, or to first client if c is NULL
233 * \param c client
234 * \param selscreen True if current screen is selected
235 * \param screen Screen ID
237 void
238 focus(Client *c, Bool selscreen, int screen)
240 int phys_screen = get_phys_screen(screen);
242 /* unfocus current selected client */
243 if(globalconf.focus->client)
245 window_grabbuttons(get_phys_screen(globalconf.focus->client->screen),
246 globalconf.focus->client->win, False, True);
247 XSetWindowBorder(globalconf.display, globalconf.focus->client->win,
248 globalconf.screens[screen].colors_normal[ColBorder].pixel);
249 window_settrans(globalconf.focus->client->win,
250 globalconf.screens[screen].opacity_unfocused);
254 /* if c is NULL or invisible, take next client in the focus history */
255 if((!c && selscreen) || (c && !client_isvisible(c, screen)))
257 c = focus_get_current_client(screen);
258 /* if c is still NULL take next client in the stack */
259 if(!c)
260 for(c = globalconf.clients; c && (c->skip || !client_isvisible(c, screen)); c = c->next);
263 if(c)
265 XSetWindowBorder(globalconf.display, c->win, globalconf.screens[screen].colors_selected[ColBorder].pixel);
266 window_grabbuttons(phys_screen, c->win, True, True);
269 if(!selscreen)
270 return;
272 /* save sel in focus history */
273 focus_add_client(c);
275 statusbar_draw_all(screen);
277 if(globalconf.focus->client)
279 XSetInputFocus(globalconf.display,
280 globalconf.focus->client->win, RevertToPointerRoot, CurrentTime);
281 for(c = globalconf.clients; c; c = c->next)
282 if(c != globalconf.focus->client)
283 window_settrans(globalconf.focus->client->win,
284 globalconf.screens[screen].opacity_unfocused);
285 window_settrans(globalconf.focus->client->win, -1);
287 else
288 XSetInputFocus(globalconf.display,
289 RootWindow(globalconf.display, phys_screen),
290 RevertToPointerRoot, CurrentTime);
292 ewmh_update_net_active_window(phys_screen);
295 /** Manage a new client
296 * \param w The window
297 * \param wa Window attributes
298 * \param screen Screen ID
300 void
301 client_manage(Window w, XWindowAttributes *wa, int screen)
303 Client *c, *t = NULL;
304 Window trans;
305 Status rettrans;
306 XWindowChanges wc;
307 Area area, darea;
308 Tag *tag;
309 Rule *rule;
310 int phys_screen = get_phys_screen(screen);
312 area = get_screen_area(screen, NULL, NULL);
314 c = p_new(Client, 1);
316 c->win = w;
317 c->geometry.x = c->f_geometry.x = c->m_geometry.x = wa->x;
318 c->geometry.y = c->f_geometry.y = c->m_geometry.y = wa->y;
319 c->geometry.width = c->f_geometry.width = c->m_geometry.width = wa->width;
320 c->geometry.height = c->f_geometry.height = c->m_geometry.height = wa->height;
321 c->oldborder = wa->border_width;
323 c->screen = get_screen_bycoord(c->geometry.x, c->geometry.y);
325 move_client_to_screen(c, screen, True);
327 /* update window title */
328 client_updatetitle(c);
330 if(c->geometry.width == area.width && c->geometry.height == area.height)
331 c->border = wa->border_width;
332 else
333 c->border = globalconf.screens[screen].borderpx;
335 ewmh_check_client_hints(c);
336 /* loadprops or apply rules if no props */
337 if(!client_loadprops(c, screen))
338 tag_client_with_rules(c);
340 /* if window request fullscreen mode */
341 if(c->geometry.width == area.width && c->geometry.height == area.height)
343 c->geometry.x = area.x;
344 c->geometry.y = area.y;
346 else
348 darea = get_display_area(phys_screen,
349 globalconf.screens[screen].statusbar,
350 &globalconf.screens[screen].padding);
352 if(c->geometry.x + c->geometry.width + 2 * c->border > darea.x + darea.width)
353 c->geometry.x = c->f_geometry.x = darea.x + darea.width - c->geometry.width - 2 * c->border;
354 if(c->geometry.y + c->geometry.height + 2 * c->border > darea.y + darea.height)
355 c->geometry.y = c->f_geometry.y = darea.y + darea.height - c->geometry.height - 2 * c->border;
356 if(c->geometry.x < darea.x)
357 c->geometry.x = c->f_geometry.x = darea.x;
358 if(c->geometry.y < darea.y)
359 c->geometry.y = c->f_geometry.y = darea.y;
362 /* XXX if this necessary ? */
363 /* set borders */
364 wc.border_width = c->border;
365 XConfigureWindow(globalconf.display, w, CWBorderWidth, &wc);
366 XSetWindowBorder(globalconf.display, w, globalconf.screens[screen].colors_normal[ColBorder].pixel);
367 /* propagates border_width, if size doesn't change */
368 window_configure(c->win, c->geometry, c->border);
370 /* update hints */
371 client_updatesizehints(c);
372 client_updatewmhints(c);
374 XSelectInput(globalconf.display, w, StructureNotifyMask | PropertyChangeMask | EnterWindowMask);
376 /* handle xshape */
377 if(globalconf.have_shape)
379 XShapeSelectInput(globalconf.display, w, ShapeNotifyMask);
380 window_setshape(phys_screen, c->win);
383 /* grab buttons */
384 window_grabbuttons(phys_screen, c->win, False, True);
386 /* check for transient and set tags like its parent */
387 if((rettrans = XGetTransientForHint(globalconf.display, w, &trans) == Success)
388 && (t = get_client_bywin(globalconf.clients, trans)))
389 for(tag = globalconf.screens[c->screen].tags; tag; tag = tag->next)
390 if(is_client_tagged(t, tag))
391 tag_client(c, tag);
393 /* should be floating if transsient or fixed */
394 if(!c->isfloating)
395 c->isfloating = (rettrans == Success) || c->isfixed;
397 /* save new props */
398 client_saveprops(c);
400 /* attach to the stack */
401 for(rule = globalconf.rules; rule; rule = rule->next)
402 if(rule->not_master && client_match_rule(c, rule))
404 client_attach_at_end(c);
405 break;
407 if(!rule)
409 if(globalconf.screens[c->screen].new_become_master)
410 client_attach(c);
411 else
412 client_attach_at_end(c);
415 /* some windows require this */
416 XMoveResizeWindow(globalconf.display, c->win, c->geometry.x, c->geometry.y,
417 c->geometry.width, c->geometry.height);
419 focus(c, True, screen);
421 ewmh_update_net_client_list(phys_screen);
423 /* rearrange to display new window */
424 arrange(c->screen);
427 /** Resize client window
428 * \param c client to resize
429 * \param x x coord
430 * \param y y coord
431 * \param w width
432 * \param h height
433 * \param sizehints respect size hints
434 * \param volatile_coords register coords in rx/ry/rw/rh
435 * \param return True if resize has been done
437 Bool
438 client_resize(Client *c, Area geometry, Bool sizehints)
440 int new_screen;
441 double dx, dy, max, min, ratio;
442 Area area;
443 XWindowChanges wc;
445 if(sizehints)
447 if(c->minay > 0 && c->maxay > 0 && (geometry.height - c->baseh) > 0
448 && (geometry.width - c->basew) > 0)
450 dx = (double) (geometry.width - c->basew);
451 dy = (double) (geometry.height - 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 geometry.width = (int) dx + c->basew;
462 geometry.height = (int) dy + c->baseh;
464 else if(ratio > max)
466 dy = (dx * min + dy) / (max * max + 1);
467 dx = dy * min;
468 geometry.width = (int) dx + c->basew;
469 geometry.height = (int) dy + c->baseh;
473 if(c->minw && geometry.width < c->minw)
474 geometry.width = c->minw;
475 if(c->minh && geometry.height < c->minh)
476 geometry.height = c->minh;
477 if(c->maxw && geometry.width > c->maxw)
478 geometry.width = c->maxw;
479 if(c->maxh && geometry.height > c->maxh)
480 geometry.height = c->maxh;
481 if(c->incw)
482 geometry.width -= (geometry.width - c->basew) % c->incw;
483 if(c->inch)
484 geometry.height -= (geometry.height - c->baseh) % c->inch;
486 if(geometry.width <= 0 || geometry.height <= 0)
487 return False;
488 /* offscreen appearance fixes */
489 area = get_display_area(get_phys_screen(c->screen),
490 NULL,
491 &globalconf.screens[c->screen].padding);
492 if(geometry.x > area.width)
493 geometry.x = area.width - geometry.width - 2 * c->border;
494 if(geometry.y > area.height)
495 geometry.y = area.height - geometry.height - 2 * c->border;
496 if(geometry.x + geometry.width + 2 * c->border < 0)
497 geometry.x = 0;
498 if(geometry.y + geometry.height + 2 * c->border < 0)
499 geometry.y = 0;
501 if(c->geometry.x != geometry.x || c->geometry.y != geometry.y
502 || c->geometry.width != geometry.width || c->geometry.height != geometry.height)
504 if(XineramaIsActive(globalconf.display))
505 new_screen = get_screen_bycoord(geometry.x, geometry.y);
506 else
507 new_screen = c->screen;
509 c->geometry.x = wc.x = geometry.x;
510 c->geometry.y = wc.y = geometry.y;
511 c->geometry.width = wc.width = geometry.width;
512 c->geometry.height = wc.height = geometry.height;
513 wc.border_width = c->border;
515 if(c->isfloating ||
516 get_current_layout(new_screen)->arrange == layout_floating)
517 c->f_geometry = geometry;
519 XConfigureWindow(globalconf.display, c->win,
520 CWX | CWY | CWWidth | CWHeight | CWBorderWidth, &wc);
521 window_configure(c->win, geometry, c->border);
523 if(c->screen != new_screen)
524 move_client_to_screen(c, new_screen, False);
526 return True;
528 return False;
531 /** Save client properties as an X property
532 * \param c client
534 void
535 client_saveprops(Client *c)
537 int i = 0, ntags = 0;
538 char *prop;
539 Tag *tag;
541 for(tag = globalconf.screens[c->screen].tags; tag; tag = tag->next)
542 ntags++;
544 prop = p_new(char, ntags + 2);
546 for(tag = globalconf.screens[c->screen].tags; tag; tag = tag->next, i++)
547 prop[i] = is_client_tagged(c, tag) ? '1' : '0';
549 if(i <= ntags)
550 prop[i] = c->isfloating ? '1' : '0';
552 prop[++i] = '\0';
554 XChangeProperty(globalconf.display, c->win, AWESOMEPROPS_ATOM(globalconf.display), XA_STRING, 8,
555 PropModeReplace, (unsigned char *) prop, i);
557 p_delete(&prop);
560 void
561 client_unban(Client *c)
563 XMapWindow(globalconf.display, c->win);
564 window_setstate(c->win, NormalState);
567 void
568 client_unmanage(Client *c)
570 XWindowChanges wc;
571 Tag *tag;
573 wc.border_width = c->oldborder;
575 /* The server grab construct avoids race conditions. */
576 XGrabServer(globalconf.display);
578 XConfigureWindow(globalconf.display, c->win, CWBorderWidth, &wc); /* restore border */
580 /* remove client everywhere */
581 client_detach(c);
582 focus_delete_client(c);
583 for(tag = globalconf.screens[c->screen].tags; tag; tag = tag->next)
584 untag_client(c, tag);
586 if(globalconf.focus->client == c)
587 focus(NULL, True, c->screen);
590 XUngrabButton(globalconf.display, AnyButton, AnyModifier, c->win);
591 window_setstate(c->win, WithdrawnState);
593 XSync(globalconf.display, False);
594 XUngrabServer(globalconf.display);
596 arrange(c->screen);
597 p_delete(&c);
600 void
601 client_updatewmhints(Client *c)
603 XWMHints *wmh;
605 if((wmh = XGetWMHints(globalconf.display, c->win)))
607 c->isurgent = (wmh->flags & XUrgencyHint);
608 if((wmh->flags & StateHint) && wmh->initial_state == WithdrawnState)
609 c->skip = True;
610 XFree(wmh);
614 void
615 client_updatesizehints(Client *c)
617 long msize;
618 XSizeHints size;
620 if(!XGetWMNormalHints(globalconf.display, c->win, &size, &msize) || !size.flags)
621 size.flags = PSize;
622 if(size.flags & PBaseSize)
624 c->basew = size.base_width;
625 c->baseh = size.base_height;
627 else if(size.flags & PMinSize)
629 c->basew = size.min_width;
630 c->baseh = size.min_height;
632 else
633 c->basew = c->baseh = 0;
634 if(size.flags & PResizeInc)
636 c->incw = size.width_inc;
637 c->inch = size.height_inc;
639 else
640 c->incw = c->inch = 0;
642 if(size.flags & PMaxSize)
644 c->maxw = size.max_width;
645 c->maxh = size.max_height;
647 else
648 c->maxw = c->maxh = 0;
650 if(size.flags & PMinSize)
652 c->minw = size.min_width;
653 c->minh = size.min_height;
655 else if(size.flags & PBaseSize)
657 c->minw = size.base_width;
658 c->minh = size.base_height;
660 else
661 c->minw = c->minh = 0;
663 if(size.flags & PAspect)
665 c->minax = size.min_aspect.x;
666 c->maxax = size.max_aspect.x;
667 c->minay = size.min_aspect.y;
668 c->maxay = size.max_aspect.y;
670 else
671 c->minax = c->maxax = c->minay = c->maxay = 0;
673 if(c->maxw && c->minw && c->maxh && c->minh
674 && c->maxw == c->minw && c->maxh == c->minh)
675 c->isfixed = True;
678 /** Returns True if a client is tagged
679 * with one of the tags
680 * \return True or False
682 Bool
683 client_isvisible(Client *c, int screen)
685 Tag *tag;
687 if(c->screen != screen)
688 return False;
690 for(tag = globalconf.screens[screen].tags; tag; tag = tag->next)
691 if(tag->selected && is_client_tagged(c, tag))
692 return True;
693 return False;
696 /** Set selected client transparency
697 * \param screen Screen ID
698 * \param arg unused arg
699 * \ingroup ui_callback
701 void
702 uicb_client_settrans(int screen __attribute__ ((unused)), char *arg)
704 double delta = 100.0, current_opacity = 100.0;
705 unsigned char *data;
706 Atom actual;
707 int format;
708 unsigned long n, left;
709 unsigned int current_opacity_raw = 0;
710 int set_prop = 0;
711 Client *sel = globalconf.focus->client;
713 if(!sel)
714 return;
716 XGetWindowProperty(globalconf.display, sel->win,
717 XInternAtom(globalconf.display, "_NET_WM_WINDOW_OPACITY", False),
718 0L, 1L, False, XA_CARDINAL, &actual, &format, &n, &left,
719 (unsigned char **) &data);
720 if(data)
722 memcpy(&current_opacity_raw, data, sizeof(unsigned int));
723 XFree(data);
724 current_opacity = (current_opacity_raw * 100.0) / 0xffffffff;
726 else
727 set_prop = 1;
729 delta = compute_new_value_from_arg(arg, current_opacity);
731 if(delta <= 0.0)
732 delta = 0.0;
733 else if(delta > 100.0)
735 delta = 100.0;
736 set_prop = 1;
739 if(delta == 100.0 && !set_prop)
740 window_settrans(sel->win, -1);
741 else
742 window_settrans(sel->win, delta);
745 /** Swap current with next client
746 * \param screen Screen ID
747 * \param arg nothing
748 * \ingroup ui_callback
750 void
751 uicb_client_swapnext(int screen, char *arg __attribute__ ((unused)))
753 Client *next, *sel = globalconf.focus->client;
755 if(!sel)
756 return;
758 for(next = sel->next; next && !client_isvisible(next, screen); next = next->next);
759 if(next)
761 client_swap(&globalconf.clients, sel, next);
762 arrange(screen);
763 /* restore focus */
764 focus(sel, True, screen);
768 /** Swap current with previous client
769 * \param screen Screen ID
770 * \param arg nothing
771 * \ingroup ui_callback
773 void
774 uicb_client_swapprev(int screen, char *arg __attribute__ ((unused)))
776 Client *prev, *sel = globalconf.focus->client;
778 if(!sel)
779 return;
781 for(prev = sel->prev; prev && !client_isvisible(prev, screen); prev = prev->prev);
782 if(prev)
784 client_swap(&globalconf.clients, prev, sel);
785 arrange(screen);
786 /* restore focus */
787 focus(sel, True, screen);
791 /** Move and resize client
792 * \param screen Screen ID
793 * \param arg x y w h
794 * \ingroup ui_callback
796 void
797 uicb_client_moveresize(int screen, char *arg)
799 int ox, oy, ow, oh;
800 char x[8], y[8], w[8], h[8];
801 int mx, my, dx, dy, nmx, nmy;
802 unsigned int dui;
803 Window dummy;
804 Area area;
805 Client *sel = globalconf.focus->client;
806 Tag **curtags = get_current_tags(screen);
808 if(curtags[0]->layout->arrange != layout_floating)
809 if(!sel || !sel->isfloating || sel->isfixed || !arg)
811 p_delete(&curtags);
812 return;
814 p_delete(&curtags);
815 if(sscanf(arg, "%s %s %s %s", x, y, w, h) != 4)
816 return;
817 area.x = (int) compute_new_value_from_arg(x, sel->geometry.x);
818 area.y = (int) compute_new_value_from_arg(y, sel->geometry.y);
819 area.width = (int) compute_new_value_from_arg(w, sel->geometry.width);
820 area.height = (int) compute_new_value_from_arg(h, sel->geometry.height);
822 ox = sel->geometry.x;
823 oy = sel->geometry.y;
824 ow = sel->geometry.width;
825 oh = sel->geometry.height;
827 Bool xqp = XQueryPointer(globalconf.display,
828 RootWindow(globalconf.display,
829 get_phys_screen(screen)),
830 &dummy, &dummy, &mx, &my, &dx, &dy, &dui);
831 client_resize(sel, area, globalconf.screens[sel->screen].resize_hints);
832 if (xqp && ox <= mx && (ox + ow) >= mx && oy <= my && (oy + oh) >= my)
834 nmx = mx - ox + sel->geometry.width - ow - 1 < 0 ? 0 : mx - ox + sel->geometry.width - ow - 1;
835 nmy = my - oy + sel->geometry.height - oh - 1 < 0 ? 0 : my - oy + sel->geometry.height - oh - 1;
836 XWarpPointer(globalconf.display,
837 None, sel->win,
838 0, 0, 0, 0, nmx, nmy);
843 void
844 client_kill(Client *c)
846 XEvent ev;
848 if(isprotodel(globalconf.display, c->win))
850 ev.type = ClientMessage;
851 ev.xclient.window = c->win;
852 ev.xclient.message_type = XInternAtom(globalconf.display, "WM_PROTOCOLS", False);
853 ev.xclient.format = 32;
854 ev.xclient.data.l[0] = XInternAtom(globalconf.display, "WM_DELETE_WINDOW", False);
855 ev.xclient.data.l[1] = CurrentTime;
856 XSendEvent(globalconf.display, c->win, False, NoEventMask, &ev);
858 else
859 XKillClient(globalconf.display, c->win);
862 /** Kill selected client
863 * \param screen Screen ID
864 * \param arg unused
865 * \ingroup ui_callback
867 void
868 uicb_client_kill(int screen __attribute__ ((unused)), char *arg __attribute__ ((unused)))
870 Client *sel = globalconf.focus->client;
872 if(sel)
873 client_kill(sel);
876 static void
877 client_maximize(Client *c, Area geometry)
880 if((c->ismax = !c->ismax))
882 c->wasfloating = c->isfloating;
883 c->m_geometry = c->geometry;
884 client_resize(c, geometry, False);
885 /* set floating after resizing so it won't save
886 * coords */
887 c->isfloating = True;
889 else if(c->wasfloating)
891 c->isfloating = True;
892 client_resize(c, c->m_geometry, False);
894 else
896 c->isfloating = False;
897 arrange(c->screen);
899 statusbar_draw_all(c->screen);
902 /** Toggle maximize for client
903 * \param screen Screen ID
904 * \param arg Unused
905 * \ingroup ui_callback
907 void
908 uicb_client_togglemax(int screen, char *arg __attribute__ ((unused)))
910 Client *sel = globalconf.focus->client;
911 Area area = get_screen_area(screen,
912 globalconf.screens[screen].statusbar,
913 &globalconf.screens[screen].padding);
915 if(sel)
917 area.width -= 2 * sel->border;
918 area.height -= 2 * sel->border;
919 client_maximize(sel, area);
923 /** Toggle vertical maximize for client
924 * \param screen Screen ID
925 * \param arg Unused
926 * \ingroup ui_callback
928 void
929 uicb_client_toggleverticalmax(int screen, char *arg __attribute__ ((unused)))
931 Client *sel = globalconf.focus->client;
932 Area area = get_screen_area(screen,
933 globalconf.screens[screen].statusbar,
934 &globalconf.screens[screen].padding);
936 if(sel)
938 area.x = sel->geometry.x;
939 area.height -= 2 * sel->border;
940 client_maximize(sel, area);
945 /** Toggle horizontal maximize for client
946 * \param screen Screen ID
947 * \param arg Unused
948 * \ingroup ui_callback
950 void
951 uicb_client_togglehorizontalmax(int screen, char *arg __attribute__ ((unused)))
953 Client *sel = globalconf.focus->client;
954 Area area = get_screen_area(screen,
955 globalconf.screens[screen].statusbar,
956 &globalconf.screens[screen].padding);
958 if(sel)
960 area.y = sel->geometry.y;
961 area.width -= 2 * sel->border;
962 client_maximize(sel, area);
966 /** Zoom client
967 * \param screen Screen ID
968 * \param arg Unused
969 * \ingroup ui_callback
971 void
972 uicb_client_zoom(int screen, char *arg __attribute__ ((unused)))
974 Client *sel = globalconf.focus->client;
976 if(globalconf.clients == sel)
977 for(sel = sel->next; sel && !client_isvisible(sel, screen); sel = sel->next);
979 if(!sel)
980 return;
982 client_detach(sel);
983 client_attach(sel);
985 focus(sel, True, screen);
986 arrange(screen);
989 // vim: filetype=c:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=80