awesome-client send now everything in one message
[awesome.git] / client.c
blobb5c52d4b0872235169f9ffcdf3c08fe83af48ef0
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 "window.h"
33 #include "focus.h"
34 #include "ewmh.h"
35 #include "screen.h"
36 #include "widget.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 widget_invalidate_cache(globalconf.focus->client->screen, WIDGET_CACHE_CLIENTS);
248 window_grabbuttons(get_phys_screen(globalconf.focus->client->screen),
249 globalconf.focus->client->win, False, True);
250 XSetWindowBorder(globalconf.display, globalconf.focus->client->win,
251 globalconf.screens[screen].colors_normal[ColBorder].pixel);
252 window_settrans(globalconf.focus->client->win,
253 globalconf.screens[screen].opacity_unfocused);
257 /* if c is NULL or invisible, take next client in the focus history */
258 if((!c && selscreen) || (c && !client_isvisible(c, screen)))
260 c = focus_get_current_client(screen);
261 /* if c is still NULL take next client in the stack */
262 if(!c)
263 for(c = globalconf.clients; c && (c->skip || !client_isvisible(c, screen)); c = c->next);
266 if(c)
268 XSetWindowBorder(globalconf.display, c->win, globalconf.screens[screen].colors_selected[ColBorder].pixel);
269 window_grabbuttons(phys_screen, c->win, True, True);
272 if(!selscreen)
273 return;
275 /* save sel in focus history */
276 focus_add_client(c);
278 widget_invalidate_cache(screen, WIDGET_CACHE_CLIENTS);
280 if(globalconf.focus->client)
282 XSetInputFocus(globalconf.display,
283 globalconf.focus->client->win, RevertToPointerRoot, CurrentTime);
284 for(c = globalconf.clients; c; c = c->next)
285 if(c != globalconf.focus->client)
286 window_settrans(globalconf.focus->client->win,
287 globalconf.screens[screen].opacity_unfocused);
288 window_settrans(globalconf.focus->client->win, -1);
290 else
291 XSetInputFocus(globalconf.display,
292 RootWindow(globalconf.display, phys_screen),
293 RevertToPointerRoot, CurrentTime);
295 ewmh_update_net_active_window(phys_screen);
298 /** Manage a new client
299 * \param w The window
300 * \param wa Window attributes
301 * \param screen Screen ID
303 void
304 client_manage(Window w, XWindowAttributes *wa, int screen)
306 Client *c, *t = NULL;
307 Window trans;
308 Status rettrans;
309 XWindowChanges wc;
310 Area area, darea;
311 Tag *tag;
312 Rule *rule;
313 int phys_screen = get_phys_screen(screen);
315 area = get_screen_area(screen, NULL, NULL);
317 c = p_new(Client, 1);
319 c->win = w;
320 c->geometry.x = c->f_geometry.x = c->m_geometry.x = wa->x;
321 c->geometry.y = c->f_geometry.y = c->m_geometry.y = wa->y;
322 c->geometry.width = c->f_geometry.width = c->m_geometry.width = wa->width;
323 c->geometry.height = c->f_geometry.height = c->m_geometry.height = wa->height;
324 c->oldborder = wa->border_width;
326 c->screen = get_screen_bycoord(c->geometry.x, c->geometry.y);
328 move_client_to_screen(c, screen, True);
330 /* update window title */
331 client_updatetitle(c);
333 if(c->geometry.width == area.width && c->geometry.height == area.height)
334 c->border = wa->border_width;
335 else
336 c->border = globalconf.screens[screen].borderpx;
338 ewmh_check_client_hints(c);
339 /* loadprops or apply rules if no props */
340 if(!client_loadprops(c, screen))
341 tag_client_with_rules(c);
343 /* if window request fullscreen mode */
344 if(c->geometry.width == area.width && c->geometry.height == area.height)
346 c->geometry.x = area.x;
347 c->geometry.y = area.y;
349 else
351 darea = get_display_area(phys_screen,
352 globalconf.screens[screen].statusbar,
353 &globalconf.screens[screen].padding);
355 if(c->geometry.x + c->geometry.width + 2 * c->border > darea.x + darea.width)
356 c->geometry.x = c->f_geometry.x = darea.x + darea.width - c->geometry.width - 2 * c->border;
357 if(c->geometry.y + c->geometry.height + 2 * c->border > darea.y + darea.height)
358 c->geometry.y = c->f_geometry.y = darea.y + darea.height - c->geometry.height - 2 * c->border;
359 if(c->geometry.x < darea.x)
360 c->geometry.x = c->f_geometry.x = darea.x;
361 if(c->geometry.y < darea.y)
362 c->geometry.y = c->f_geometry.y = darea.y;
365 /* XXX if this necessary ? */
366 /* set borders */
367 wc.border_width = c->border;
368 XConfigureWindow(globalconf.display, w, CWBorderWidth, &wc);
369 XSetWindowBorder(globalconf.display, w, globalconf.screens[screen].colors_normal[ColBorder].pixel);
370 /* propagates border_width, if size doesn't change */
371 window_configure(c->win, c->geometry, 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(c->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
438 * \param return True if resize has been done
440 Bool
441 client_resize(Client *c, Area geometry, Bool sizehints)
443 int new_screen;
444 double dx, dy, max, min, ratio;
445 Area area;
446 XWindowChanges wc;
448 if(sizehints)
450 if(c->minay > 0 && c->maxay > 0 && (geometry.height - c->baseh) > 0
451 && (geometry.width - c->basew) > 0)
453 dx = (double) (geometry.width - c->basew);
454 dy = (double) (geometry.height - c->baseh);
455 min = (double) (c->minax) / (double) (c->minay);
456 max = (double) (c->maxax) / (double) (c->maxay);
457 ratio = dx / dy;
458 if(max > 0 && min > 0 && ratio > 0)
460 if(ratio < min)
462 dy = (dx * min + dy) / (min * min + 1);
463 dx = dy * min;
464 geometry.width = (int) dx + c->basew;
465 geometry.height = (int) dy + c->baseh;
467 else if(ratio > max)
469 dy = (dx * min + dy) / (max * max + 1);
470 dx = dy * min;
471 geometry.width = (int) dx + c->basew;
472 geometry.height = (int) dy + c->baseh;
476 if(c->minw && geometry.width < c->minw)
477 geometry.width = c->minw;
478 if(c->minh && geometry.height < c->minh)
479 geometry.height = c->minh;
480 if(c->maxw && geometry.width > c->maxw)
481 geometry.width = c->maxw;
482 if(c->maxh && geometry.height > c->maxh)
483 geometry.height = c->maxh;
484 if(c->incw)
485 geometry.width -= (geometry.width - c->basew) % c->incw;
486 if(c->inch)
487 geometry.height -= (geometry.height - c->baseh) % c->inch;
489 if(geometry.width <= 0 || geometry.height <= 0)
490 return False;
491 /* offscreen appearance fixes */
492 area = get_display_area(get_phys_screen(c->screen),
493 NULL,
494 &globalconf.screens[c->screen].padding);
495 if(geometry.x > area.width)
496 geometry.x = area.width - geometry.width - 2 * c->border;
497 if(geometry.y > area.height)
498 geometry.y = area.height - geometry.height - 2 * c->border;
499 if(geometry.x + geometry.width + 2 * c->border < 0)
500 geometry.x = 0;
501 if(geometry.y + geometry.height + 2 * c->border < 0)
502 geometry.y = 0;
504 if(c->geometry.x != geometry.x || c->geometry.y != geometry.y
505 || c->geometry.width != geometry.width || c->geometry.height != geometry.height)
507 if(XineramaIsActive(globalconf.display))
508 new_screen = get_screen_bycoord(geometry.x, geometry.y);
509 else
510 new_screen = c->screen;
512 c->geometry.x = wc.x = geometry.x;
513 c->geometry.y = wc.y = geometry.y;
514 c->geometry.width = wc.width = geometry.width;
515 c->geometry.height = wc.height = geometry.height;
516 wc.border_width = c->border;
518 if(c->isfloating ||
519 get_current_layout(new_screen)->arrange == layout_floating)
520 c->f_geometry = geometry;
522 XConfigureWindow(globalconf.display, c->win,
523 CWX | CWY | CWWidth | CWHeight | CWBorderWidth, &wc);
524 window_configure(c->win, geometry, c->border);
526 if(c->screen != new_screen)
527 move_client_to_screen(c, new_screen, False);
529 return True;
531 return False;
534 /** Save client properties as an X property
535 * \param c client
537 void
538 client_saveprops(Client *c)
540 int i = 0, ntags = 0;
541 char *prop;
542 Tag *tag;
544 for(tag = globalconf.screens[c->screen].tags; tag; tag = tag->next)
545 ntags++;
547 prop = p_new(char, ntags + 2);
549 for(tag = globalconf.screens[c->screen].tags; tag; tag = tag->next, i++)
550 prop[i] = is_client_tagged(c, tag) ? '1' : '0';
552 if(i <= ntags)
553 prop[i] = c->isfloating ? '1' : '0';
555 prop[++i] = '\0';
557 XChangeProperty(globalconf.display, c->win,
558 XInternAtom(globalconf.display, "_AWESOME_PROPERTIES", False),
559 XA_STRING, 8, PropModeReplace, (unsigned char *) prop, i);
561 p_delete(&prop);
564 void
565 client_unban(Client *c)
567 XMapWindow(globalconf.display, c->win);
568 window_setstate(c->win, NormalState);
571 void
572 client_unmanage(Client *c)
574 XWindowChanges wc;
575 Tag *tag;
577 wc.border_width = c->oldborder;
579 /* The server grab construct avoids race conditions. */
580 XGrabServer(globalconf.display);
582 XConfigureWindow(globalconf.display, c->win, CWBorderWidth, &wc); /* restore border */
584 /* remove client everywhere */
585 client_detach(c);
586 focus_delete_client(c);
587 for(tag = globalconf.screens[c->screen].tags; tag; tag = tag->next)
588 untag_client(c, tag);
590 if(globalconf.focus->client == c)
591 focus(NULL, True, c->screen);
594 XUngrabButton(globalconf.display, AnyButton, AnyModifier, c->win);
595 window_setstate(c->win, WithdrawnState);
597 XSync(globalconf.display, False);
598 XUngrabServer(globalconf.display);
600 arrange(c->screen);
601 p_delete(&c);
604 void
605 client_updatewmhints(Client *c)
607 XWMHints *wmh;
609 if((wmh = XGetWMHints(globalconf.display, c->win)))
611 c->isurgent = (wmh->flags & XUrgencyHint);
612 if((wmh->flags & StateHint) && wmh->initial_state == WithdrawnState)
613 c->skip = True;
614 XFree(wmh);
618 void
619 client_updatesizehints(Client *c)
621 long msize;
622 XSizeHints size;
624 if(!XGetWMNormalHints(globalconf.display, c->win, &size, &msize) || !size.flags)
625 size.flags = PSize;
626 if(size.flags & PBaseSize)
628 c->basew = size.base_width;
629 c->baseh = size.base_height;
631 else if(size.flags & PMinSize)
633 c->basew = size.min_width;
634 c->baseh = size.min_height;
636 else
637 c->basew = c->baseh = 0;
638 if(size.flags & PResizeInc)
640 c->incw = size.width_inc;
641 c->inch = size.height_inc;
643 else
644 c->incw = c->inch = 0;
646 if(size.flags & PMaxSize)
648 c->maxw = size.max_width;
649 c->maxh = size.max_height;
651 else
652 c->maxw = c->maxh = 0;
654 if(size.flags & PMinSize)
656 c->minw = size.min_width;
657 c->minh = size.min_height;
659 else if(size.flags & PBaseSize)
661 c->minw = size.base_width;
662 c->minh = size.base_height;
664 else
665 c->minw = c->minh = 0;
667 if(size.flags & PAspect)
669 c->minax = size.min_aspect.x;
670 c->maxax = size.max_aspect.x;
671 c->minay = size.min_aspect.y;
672 c->maxay = size.max_aspect.y;
674 else
675 c->minax = c->maxax = c->minay = c->maxay = 0;
677 if(c->maxw && c->minw && c->maxh && c->minh
678 && c->maxw == c->minw && c->maxh == c->minh)
679 c->isfixed = True;
682 /** Returns True if a client is tagged
683 * with one of the tags
684 * \return True or False
686 Bool
687 client_isvisible(Client *c, int screen)
689 Tag *tag;
691 if(c->screen != screen)
692 return False;
694 for(tag = globalconf.screens[screen].tags; tag; tag = tag->next)
695 if(tag->selected && is_client_tagged(c, tag))
696 return True;
697 return False;
700 /** Set selected client transparency
701 * \param screen Screen ID
702 * \param arg unused arg
703 * \ingroup ui_callback
705 void
706 uicb_client_settrans(int screen __attribute__ ((unused)), char *arg)
708 double delta = 100.0, current_opacity = 100.0;
709 unsigned char *data;
710 Atom actual;
711 int format;
712 unsigned long n, left;
713 unsigned int current_opacity_raw = 0;
714 int set_prop = 0;
715 Client *sel = globalconf.focus->client;
717 if(!sel)
718 return;
720 XGetWindowProperty(globalconf.display, sel->win,
721 XInternAtom(globalconf.display, "_NET_WM_WINDOW_OPACITY", False),
722 0L, 1L, False, XA_CARDINAL, &actual, &format, &n, &left,
723 (unsigned char **) &data);
724 if(data)
726 memcpy(&current_opacity_raw, data, sizeof(unsigned int));
727 XFree(data);
728 current_opacity = (current_opacity_raw * 100.0) / 0xffffffff;
730 else
731 set_prop = 1;
733 delta = compute_new_value_from_arg(arg, current_opacity);
735 if(delta <= 0.0)
736 delta = 0.0;
737 else if(delta > 100.0)
739 delta = 100.0;
740 set_prop = 1;
743 if(delta == 100.0 && !set_prop)
744 window_settrans(sel->win, -1);
745 else
746 window_settrans(sel->win, delta);
749 /** Swap current with next client
750 * \param screen Screen ID
751 * \param arg nothing
752 * \ingroup ui_callback
754 void
755 uicb_client_swapnext(int screen, char *arg __attribute__ ((unused)))
757 Client *next, *sel = globalconf.focus->client;
759 if(!sel)
760 return;
762 for(next = sel->next; next && !client_isvisible(next, screen); next = next->next);
763 if(next)
765 client_swap(&globalconf.clients, sel, next);
766 arrange(screen);
767 /* restore focus */
768 focus(sel, True, screen);
772 /** Swap current with previous client
773 * \param screen Screen ID
774 * \param arg nothing
775 * \ingroup ui_callback
777 void
778 uicb_client_swapprev(int screen, char *arg __attribute__ ((unused)))
780 Client *prev, *sel = globalconf.focus->client;
782 if(!sel)
783 return;
785 for(prev = sel->prev; prev && !client_isvisible(prev, screen); prev = prev->prev);
786 if(prev)
788 client_swap(&globalconf.clients, prev, sel);
789 arrange(screen);
790 /* restore focus */
791 focus(sel, True, screen);
795 /** Move and resize client
796 * \param screen Screen ID
797 * \param arg x y w h
798 * \ingroup ui_callback
800 void
801 uicb_client_moveresize(int screen, char *arg)
803 int ox, oy, ow, oh;
804 char x[8], y[8], w[8], h[8];
805 int mx, my, dx, dy, nmx, nmy;
806 unsigned int dui;
807 Window dummy;
808 Area area;
809 Client *sel = globalconf.focus->client;
810 Tag **curtags = get_current_tags(screen);
812 if(curtags[0]->layout->arrange != layout_floating)
813 if(!sel || !sel->isfloating || sel->isfixed || !arg)
815 p_delete(&curtags);
816 return;
818 p_delete(&curtags);
819 if(sscanf(arg, "%s %s %s %s", x, y, w, h) != 4)
820 return;
821 area.x = (int) compute_new_value_from_arg(x, sel->geometry.x);
822 area.y = (int) compute_new_value_from_arg(y, sel->geometry.y);
823 area.width = (int) compute_new_value_from_arg(w, sel->geometry.width);
824 area.height = (int) compute_new_value_from_arg(h, sel->geometry.height);
826 ox = sel->geometry.x;
827 oy = sel->geometry.y;
828 ow = sel->geometry.width;
829 oh = sel->geometry.height;
831 Bool xqp = XQueryPointer(globalconf.display,
832 RootWindow(globalconf.display,
833 get_phys_screen(screen)),
834 &dummy, &dummy, &mx, &my, &dx, &dy, &dui);
835 client_resize(sel, area, globalconf.screens[sel->screen].resize_hints);
836 if (xqp && ox <= mx && (ox + ow) >= mx && oy <= my && (oy + oh) >= my)
838 nmx = mx - ox + sel->geometry.width - ow - 1 < 0 ? 0 : mx - ox + sel->geometry.width - ow - 1;
839 nmy = my - oy + sel->geometry.height - oh - 1 < 0 ? 0 : my - oy + sel->geometry.height - oh - 1;
840 XWarpPointer(globalconf.display,
841 None, sel->win,
842 0, 0, 0, 0, nmx, nmy);
847 void
848 client_kill(Client *c)
850 XEvent ev;
852 if(isprotodel(globalconf.display, c->win))
854 ev.type = ClientMessage;
855 ev.xclient.window = c->win;
856 ev.xclient.message_type = XInternAtom(globalconf.display, "WM_PROTOCOLS", False);
857 ev.xclient.format = 32;
858 ev.xclient.data.l[0] = XInternAtom(globalconf.display, "WM_DELETE_WINDOW", False);
859 ev.xclient.data.l[1] = CurrentTime;
860 XSendEvent(globalconf.display, c->win, False, NoEventMask, &ev);
862 else
863 XKillClient(globalconf.display, c->win);
866 /** Kill selected client
867 * \param screen Screen ID
868 * \param arg unused
869 * \ingroup ui_callback
871 void
872 uicb_client_kill(int screen __attribute__ ((unused)), char *arg __attribute__ ((unused)))
874 Client *sel = globalconf.focus->client;
876 if(sel)
877 client_kill(sel);
880 static void
881 client_maximize(Client *c, Area geometry)
884 if((c->ismax = !c->ismax))
886 c->wasfloating = c->isfloating;
887 c->m_geometry = c->geometry;
888 client_resize(c, geometry, False);
889 /* set floating after resizing so it won't save
890 * coords */
891 c->isfloating = True;
892 restack(c->screen);
893 widget_invalidate_cache(c->screen, WIDGET_CACHE_CLIENTS);
895 else if(c->wasfloating)
897 c->isfloating = True;
898 client_resize(c, c->m_geometry, False);
899 restack(c->screen);
900 widget_invalidate_cache(c->screen, WIDGET_CACHE_CLIENTS);
902 else
904 c->isfloating = False;
905 arrange(c->screen);
906 widget_invalidate_cache(c->screen, WIDGET_CACHE_CLIENTS);
910 /** Toggle maximize for client
911 * \param screen Screen ID
912 * \param arg Unused
913 * \ingroup ui_callback
915 void
916 uicb_client_togglemax(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)
925 area.width -= 2 * sel->border;
926 area.height -= 2 * sel->border;
927 client_maximize(sel, area);
931 /** Toggle vertical maximize for client
932 * \param screen Screen ID
933 * \param arg Unused
934 * \ingroup ui_callback
936 void
937 uicb_client_toggleverticalmax(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)
946 area.x = sel->geometry.x;
947 area.height -= 2 * sel->border;
948 client_maximize(sel, area);
953 /** Toggle horizontal maximize for client
954 * \param screen Screen ID
955 * \param arg Unused
956 * \ingroup ui_callback
958 void
959 uicb_client_togglehorizontalmax(int screen, char *arg __attribute__ ((unused)))
961 Client *sel = globalconf.focus->client;
962 Area area = get_screen_area(screen,
963 globalconf.screens[screen].statusbar,
964 &globalconf.screens[screen].padding);
966 if(sel)
968 area.y = sel->geometry.y;
969 area.width -= 2 * sel->border;
970 client_maximize(sel, area);
974 /** Zoom client
975 * \param screen Screen ID
976 * \param arg Unused
977 * \ingroup ui_callback
979 void
980 uicb_client_zoom(int screen, char *arg __attribute__ ((unused)))
982 Client *sel = globalconf.focus->client;
984 if(globalconf.clients == sel)
985 for(sel = sel->next; sel && !client_isvisible(sel, screen); sel = sel->next);
987 if(!sel)
988 return;
990 client_detach(sel);
991 client_attach(sel);
993 focus(sel, True, screen);
994 arrange(screen);
997 // vim: filetype=c:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=80