add new_get_focus option
[awesome.git] / client.c
bloba31f774fb5e3b633a2b33f7ce3b90a09ef09fab7
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));
180 widget_invalidate_cache(c->screen, WIDGET_CACHE_CLIENTS);
183 /** Ban client and unmap it
184 * \param c the client
186 void
187 client_ban(Client * c)
189 XUnmapWindow(globalconf.display, c->win);
190 window_setstate(c->win, IconicState);
194 static void
195 client_attach_at_end(Client *c)
197 Client *iter;
198 for(iter = globalconf.clients; iter && iter->next; iter = iter->next);
199 /* stack is empty */
200 if(!iter)
201 globalconf.clients = c;
202 else
204 c->prev = iter;
205 iter->next = c;
209 /** Attach client to the beginning of the clients stack
210 * \param c the client
212 void
213 client_attach(Client *c)
215 if(globalconf.clients)
216 (globalconf.clients)->prev = c;
217 c->next = globalconf.clients;
218 globalconf.clients = c;
221 /** Detach client from clients list
222 * \param c client to detach
224 void
225 client_detach(Client *c)
227 if(c->prev)
228 c->prev->next = c->next;
229 if(c->next)
230 c->next->prev = c->prev;
231 if(c == globalconf.clients)
232 globalconf.clients = c->next;
233 c->next = c->prev = NULL;
236 /** Give focus to client, or to first client if c is NULL
237 * \param c client
238 * \param selscreen True if current screen is selected
239 * \param screen Screen ID
241 void
242 focus(Client *c, Bool selscreen, int screen)
244 int phys_screen = get_phys_screen(screen);
246 /* unfocus current selected client */
247 if(globalconf.focus->client)
249 widget_invalidate_cache(globalconf.focus->client->screen, WIDGET_CACHE_CLIENTS);
250 window_grabbuttons(get_phys_screen(globalconf.focus->client->screen),
251 globalconf.focus->client->win, False, True);
252 XSetWindowBorder(globalconf.display, globalconf.focus->client->win,
253 globalconf.screens[screen].colors_normal[ColBorder].pixel);
254 window_settrans(globalconf.focus->client->win,
255 globalconf.screens[screen].opacity_unfocused);
259 /* if c is NULL or invisible, take next client in the focus history */
260 if((!c && selscreen) || (c && !client_isvisible(c, screen)))
262 c = focus_get_current_client(screen);
263 /* if c is still NULL take next client in the stack */
264 if(!c)
265 for(c = globalconf.clients; c && (c->skip || !client_isvisible(c, screen)); c = c->next);
268 if(c)
270 XSetWindowBorder(globalconf.display, c->win, globalconf.screens[screen].colors_selected[ColBorder].pixel);
271 window_grabbuttons(phys_screen, c->win, True, True);
274 if(!selscreen)
275 return;
277 /* save sel in focus history */
278 focus_add_client(c);
280 widget_invalidate_cache(screen, WIDGET_CACHE_CLIENTS);
282 if(globalconf.focus->client)
284 XSetInputFocus(globalconf.display,
285 globalconf.focus->client->win, RevertToPointerRoot, CurrentTime);
286 for(c = globalconf.clients; c; c = c->next)
287 if(c != globalconf.focus->client)
288 window_settrans(globalconf.focus->client->win,
289 globalconf.screens[screen].opacity_unfocused);
290 window_settrans(globalconf.focus->client->win, -1);
292 else
293 XSetInputFocus(globalconf.display,
294 RootWindow(globalconf.display, phys_screen),
295 RevertToPointerRoot, CurrentTime);
297 ewmh_update_net_active_window(phys_screen);
300 /** Manage a new client
301 * \param w The window
302 * \param wa Window attributes
303 * \param screen Screen ID
305 void
306 client_manage(Window w, XWindowAttributes *wa, int screen)
308 Client *c, *t = NULL;
309 Window trans;
310 Status rettrans;
311 XWindowChanges wc;
312 Area area, darea;
313 Tag *tag;
314 Rule *rule;
315 int phys_screen = get_phys_screen(screen);
317 area = get_screen_area(screen, NULL, NULL);
319 c = p_new(Client, 1);
321 c->win = w;
322 c->geometry.x = c->f_geometry.x = c->m_geometry.x = wa->x;
323 c->geometry.y = c->f_geometry.y = c->m_geometry.y = wa->y;
324 c->geometry.width = c->f_geometry.width = c->m_geometry.width = wa->width;
325 c->geometry.height = c->f_geometry.height = c->m_geometry.height = wa->height;
326 c->oldborder = wa->border_width;
328 c->screen = get_screen_bycoord(c->geometry.x, c->geometry.y);
330 move_client_to_screen(c, screen, True);
332 /* update window title */
333 client_updatetitle(c);
335 if(c->geometry.width == area.width && c->geometry.height == area.height)
336 c->border = wa->border_width;
337 else
338 c->border = globalconf.screens[screen].borderpx;
340 ewmh_check_client_hints(c);
341 /* loadprops or apply rules if no props */
342 if(!client_loadprops(c, screen))
343 tag_client_with_rules(c);
345 /* if window request fullscreen mode */
346 if(c->geometry.width == area.width && c->geometry.height == area.height)
348 c->geometry.x = area.x;
349 c->geometry.y = area.y;
351 else
353 darea = get_display_area(phys_screen,
354 globalconf.screens[screen].statusbar,
355 &globalconf.screens[screen].padding);
357 if(c->geometry.x + c->geometry.width + 2 * c->border > darea.x + darea.width)
358 c->geometry.x = c->f_geometry.x = darea.x + darea.width - c->geometry.width - 2 * c->border;
359 if(c->geometry.y + c->geometry.height + 2 * c->border > darea.y + darea.height)
360 c->geometry.y = c->f_geometry.y = darea.y + darea.height - c->geometry.height - 2 * c->border;
361 if(c->geometry.x < darea.x)
362 c->geometry.x = c->f_geometry.x = darea.x;
363 if(c->geometry.y < darea.y)
364 c->geometry.y = c->f_geometry.y = darea.y;
367 /* XXX if this necessary ? */
368 /* set borders */
369 wc.border_width = c->border;
370 XConfigureWindow(globalconf.display, w, CWBorderWidth, &wc);
371 XSetWindowBorder(globalconf.display, w, globalconf.screens[screen].colors_normal[ColBorder].pixel);
372 /* propagates border_width, if size doesn't change */
373 window_configure(c->win, c->geometry, c->border);
375 /* update hints */
376 client_updatesizehints(c);
377 client_updatewmhints(c);
379 XSelectInput(globalconf.display, w, StructureNotifyMask | PropertyChangeMask | EnterWindowMask);
381 /* handle xshape */
382 if(globalconf.have_shape)
384 XShapeSelectInput(globalconf.display, w, ShapeNotifyMask);
385 window_setshape(phys_screen, c->win);
388 /* grab buttons */
389 window_grabbuttons(phys_screen, c->win, False, True);
391 /* check for transient and set tags like its parent */
392 if((rettrans = XGetTransientForHint(globalconf.display, w, &trans) == Success)
393 && (t = get_client_bywin(globalconf.clients, trans)))
394 for(tag = globalconf.screens[c->screen].tags; tag; tag = tag->next)
395 if(is_client_tagged(t, tag))
396 tag_client(c, tag);
398 /* should be floating if transsient or fixed */
399 if(!c->isfloating)
400 c->isfloating = (rettrans == Success) || c->isfixed;
402 /* save new props */
403 client_saveprops(c);
405 /* attach to the stack */
406 for(rule = globalconf.rules; rule; rule = rule->next)
407 if(rule->not_master && client_match_rule(c, rule))
409 client_attach_at_end(c);
410 break;
412 if(!rule)
414 if(globalconf.screens[c->screen].new_become_master)
415 client_attach(c);
416 else
417 client_attach_at_end(c);
420 /* some windows require this */
421 XMoveResizeWindow(globalconf.display, c->win, c->geometry.x, c->geometry.y,
422 c->geometry.width, c->geometry.height);
424 if(globalconf.screens[c->screen].new_get_focus)
425 focus(c, True, screen);
426 else
427 widget_invalidate_cache(c->screen, WIDGET_CACHE_CLIENTS);
429 ewmh_update_net_client_list(phys_screen);
431 /* rearrange to display new window */
432 arrange(c->screen);
435 /** Resize client window
436 * \param c client to resize
437 * \param x x coord
438 * \param y y coord
439 * \param w width
440 * \param h height
441 * \param sizehints respect size hints
442 * \param volatile_coords register coords in rx/ry/rw/rh
443 * \param return True if resize has been done
445 Bool
446 client_resize(Client *c, Area geometry, Bool sizehints)
448 int new_screen;
449 double dx, dy, max, min, ratio;
450 Area area;
451 XWindowChanges wc;
453 if(sizehints)
455 if(c->minay > 0 && c->maxay > 0 && (geometry.height - c->baseh) > 0
456 && (geometry.width - c->basew) > 0)
458 dx = (double) (geometry.width - c->basew);
459 dy = (double) (geometry.height - c->baseh);
460 min = (double) (c->minax) / (double) (c->minay);
461 max = (double) (c->maxax) / (double) (c->maxay);
462 ratio = dx / dy;
463 if(max > 0 && min > 0 && ratio > 0)
465 if(ratio < min)
467 dy = (dx * min + dy) / (min * min + 1);
468 dx = dy * min;
469 geometry.width = (int) dx + c->basew;
470 geometry.height = (int) dy + c->baseh;
472 else if(ratio > max)
474 dy = (dx * min + dy) / (max * max + 1);
475 dx = dy * min;
476 geometry.width = (int) dx + c->basew;
477 geometry.height = (int) dy + c->baseh;
481 if(c->minw && geometry.width < c->minw)
482 geometry.width = c->minw;
483 if(c->minh && geometry.height < c->minh)
484 geometry.height = c->minh;
485 if(c->maxw && geometry.width > c->maxw)
486 geometry.width = c->maxw;
487 if(c->maxh && geometry.height > c->maxh)
488 geometry.height = c->maxh;
489 if(c->incw)
490 geometry.width -= (geometry.width - c->basew) % c->incw;
491 if(c->inch)
492 geometry.height -= (geometry.height - c->baseh) % c->inch;
494 if(geometry.width <= 0 || geometry.height <= 0)
495 return False;
496 /* offscreen appearance fixes */
497 area = get_display_area(get_phys_screen(c->screen),
498 NULL,
499 &globalconf.screens[c->screen].padding);
500 if(geometry.x > area.width)
501 geometry.x = area.width - geometry.width - 2 * c->border;
502 if(geometry.y > area.height)
503 geometry.y = area.height - geometry.height - 2 * c->border;
504 if(geometry.x + geometry.width + 2 * c->border < 0)
505 geometry.x = 0;
506 if(geometry.y + geometry.height + 2 * c->border < 0)
507 geometry.y = 0;
509 if(c->geometry.x != geometry.x || c->geometry.y != geometry.y
510 || c->geometry.width != geometry.width || c->geometry.height != geometry.height)
512 if(XineramaIsActive(globalconf.display))
513 new_screen = get_screen_bycoord(geometry.x, geometry.y);
514 else
515 new_screen = c->screen;
517 c->geometry.x = wc.x = geometry.x;
518 c->geometry.y = wc.y = geometry.y;
519 c->geometry.width = wc.width = geometry.width;
520 c->geometry.height = wc.height = geometry.height;
521 wc.border_width = c->border;
523 if(c->isfloating ||
524 get_current_layout(new_screen)->arrange == layout_floating)
525 c->f_geometry = geometry;
527 XConfigureWindow(globalconf.display, c->win,
528 CWX | CWY | CWWidth | CWHeight | CWBorderWidth, &wc);
529 window_configure(c->win, geometry, c->border);
531 if(c->screen != new_screen)
532 move_client_to_screen(c, new_screen, False);
534 return True;
536 return False;
539 /** Save client properties as an X property
540 * \param c client
542 void
543 client_saveprops(Client *c)
545 int i = 0, ntags = 0;
546 char *prop;
547 Tag *tag;
549 for(tag = globalconf.screens[c->screen].tags; tag; tag = tag->next)
550 ntags++;
552 prop = p_new(char, ntags + 2);
554 for(tag = globalconf.screens[c->screen].tags; tag; tag = tag->next, i++)
555 prop[i] = is_client_tagged(c, tag) ? '1' : '0';
557 if(i <= ntags)
558 prop[i] = c->isfloating ? '1' : '0';
560 prop[++i] = '\0';
562 XChangeProperty(globalconf.display, c->win,
563 XInternAtom(globalconf.display, "_AWESOME_PROPERTIES", False),
564 XA_STRING, 8, PropModeReplace, (unsigned char *) prop, i);
566 p_delete(&prop);
569 void
570 client_unban(Client *c)
572 XMapWindow(globalconf.display, c->win);
573 window_setstate(c->win, NormalState);
576 void
577 client_unmanage(Client *c)
579 XWindowChanges wc;
580 Tag *tag;
582 wc.border_width = c->oldborder;
584 /* The server grab construct avoids race conditions. */
585 XGrabServer(globalconf.display);
587 XConfigureWindow(globalconf.display, c->win, CWBorderWidth, &wc); /* restore border */
589 /* remove client everywhere */
590 client_detach(c);
591 focus_delete_client(c);
592 for(tag = globalconf.screens[c->screen].tags; tag; tag = tag->next)
593 untag_client(c, tag);
595 if(globalconf.focus->client == c)
596 focus(NULL, True, c->screen);
599 XUngrabButton(globalconf.display, AnyButton, AnyModifier, c->win);
600 window_setstate(c->win, WithdrawnState);
602 XSync(globalconf.display, False);
603 XUngrabServer(globalconf.display);
605 arrange(c->screen);
606 p_delete(&c);
609 void
610 client_updatewmhints(Client *c)
612 XWMHints *wmh;
614 if((wmh = XGetWMHints(globalconf.display, c->win)))
616 c->isurgent = (wmh->flags & XUrgencyHint);
617 if((wmh->flags & StateHint) && wmh->initial_state == WithdrawnState)
618 c->skip = True;
619 XFree(wmh);
623 void
624 client_updatesizehints(Client *c)
626 long msize;
627 XSizeHints size;
629 if(!XGetWMNormalHints(globalconf.display, c->win, &size, &msize) || !size.flags)
630 size.flags = PSize;
631 if(size.flags & PBaseSize)
633 c->basew = size.base_width;
634 c->baseh = size.base_height;
636 else if(size.flags & PMinSize)
638 c->basew = size.min_width;
639 c->baseh = size.min_height;
641 else
642 c->basew = c->baseh = 0;
643 if(size.flags & PResizeInc)
645 c->incw = size.width_inc;
646 c->inch = size.height_inc;
648 else
649 c->incw = c->inch = 0;
651 if(size.flags & PMaxSize)
653 c->maxw = size.max_width;
654 c->maxh = size.max_height;
656 else
657 c->maxw = c->maxh = 0;
659 if(size.flags & PMinSize)
661 c->minw = size.min_width;
662 c->minh = size.min_height;
664 else if(size.flags & PBaseSize)
666 c->minw = size.base_width;
667 c->minh = size.base_height;
669 else
670 c->minw = c->minh = 0;
672 if(size.flags & PAspect)
674 c->minax = size.min_aspect.x;
675 c->maxax = size.max_aspect.x;
676 c->minay = size.min_aspect.y;
677 c->maxay = size.max_aspect.y;
679 else
680 c->minax = c->maxax = c->minay = c->maxay = 0;
682 if(c->maxw && c->minw && c->maxh && c->minh
683 && c->maxw == c->minw && c->maxh == c->minh)
684 c->isfixed = True;
687 /** Returns True if a client is tagged
688 * with one of the tags
689 * \return True or False
691 Bool
692 client_isvisible(Client *c, int screen)
694 Tag *tag;
696 if(c->screen != screen)
697 return False;
699 for(tag = globalconf.screens[screen].tags; tag; tag = tag->next)
700 if(tag->selected && is_client_tagged(c, tag))
701 return True;
702 return False;
705 /** Set selected client transparency
706 * \param screen Screen ID
707 * \param arg unused arg
708 * \ingroup ui_callback
710 void
711 uicb_client_settrans(int screen __attribute__ ((unused)), char *arg)
713 double delta = 100.0, current_opacity = 100.0;
714 unsigned char *data;
715 Atom actual;
716 int format;
717 unsigned long n, left;
718 unsigned int current_opacity_raw = 0;
719 int set_prop = 0;
720 Client *sel = globalconf.focus->client;
722 if(!sel)
723 return;
725 XGetWindowProperty(globalconf.display, sel->win,
726 XInternAtom(globalconf.display, "_NET_WM_WINDOW_OPACITY", False),
727 0L, 1L, False, XA_CARDINAL, &actual, &format, &n, &left,
728 (unsigned char **) &data);
729 if(data)
731 memcpy(&current_opacity_raw, data, sizeof(unsigned int));
732 XFree(data);
733 current_opacity = (current_opacity_raw * 100.0) / 0xffffffff;
735 else
736 set_prop = 1;
738 delta = compute_new_value_from_arg(arg, current_opacity);
740 if(delta <= 0.0)
741 delta = 0.0;
742 else if(delta > 100.0)
744 delta = 100.0;
745 set_prop = 1;
748 if(delta == 100.0 && !set_prop)
749 window_settrans(sel->win, -1);
750 else
751 window_settrans(sel->win, delta);
754 /** Swap current with next client
755 * \param screen Screen ID
756 * \param arg nothing
757 * \ingroup ui_callback
759 void
760 uicb_client_swapnext(int screen, char *arg __attribute__ ((unused)))
762 Client *next, *sel = globalconf.focus->client;
764 if(!sel)
765 return;
767 for(next = sel->next; next && !client_isvisible(next, screen); next = next->next);
768 if(next)
770 client_swap(&globalconf.clients, sel, next);
771 arrange(screen);
772 /* restore focus */
773 focus(sel, True, screen);
777 /** Swap current with previous client
778 * \param screen Screen ID
779 * \param arg nothing
780 * \ingroup ui_callback
782 void
783 uicb_client_swapprev(int screen, char *arg __attribute__ ((unused)))
785 Client *prev, *sel = globalconf.focus->client;
787 if(!sel)
788 return;
790 for(prev = sel->prev; prev && !client_isvisible(prev, screen); prev = prev->prev);
791 if(prev)
793 client_swap(&globalconf.clients, prev, sel);
794 arrange(screen);
795 /* restore focus */
796 focus(sel, True, screen);
800 /** Move and resize client
801 * \param screen Screen ID
802 * \param arg x y w h
803 * \ingroup ui_callback
805 void
806 uicb_client_moveresize(int screen, char *arg)
808 int ox, oy, ow, oh;
809 char x[8], y[8], w[8], h[8];
810 int mx, my, dx, dy, nmx, nmy;
811 unsigned int dui;
812 Window dummy;
813 Area area;
814 Client *sel = globalconf.focus->client;
815 Tag **curtags = get_current_tags(screen);
817 if(curtags[0]->layout->arrange != layout_floating)
818 if(!sel || !sel->isfloating || sel->isfixed || !arg)
820 p_delete(&curtags);
821 return;
823 p_delete(&curtags);
824 if(sscanf(arg, "%s %s %s %s", x, y, w, h) != 4)
825 return;
826 area.x = (int) compute_new_value_from_arg(x, sel->geometry.x);
827 area.y = (int) compute_new_value_from_arg(y, sel->geometry.y);
828 area.width = (int) compute_new_value_from_arg(w, sel->geometry.width);
829 area.height = (int) compute_new_value_from_arg(h, sel->geometry.height);
831 ox = sel->geometry.x;
832 oy = sel->geometry.y;
833 ow = sel->geometry.width;
834 oh = sel->geometry.height;
836 Bool xqp = XQueryPointer(globalconf.display,
837 RootWindow(globalconf.display,
838 get_phys_screen(screen)),
839 &dummy, &dummy, &mx, &my, &dx, &dy, &dui);
840 client_resize(sel, area, globalconf.screens[sel->screen].resize_hints);
841 if (xqp && ox <= mx && (ox + ow) >= mx && oy <= my && (oy + oh) >= my)
843 nmx = mx - ox + sel->geometry.width - ow - 1 < 0 ? 0 : mx - ox + sel->geometry.width - ow - 1;
844 nmy = my - oy + sel->geometry.height - oh - 1 < 0 ? 0 : my - oy + sel->geometry.height - oh - 1;
845 XWarpPointer(globalconf.display,
846 None, sel->win,
847 0, 0, 0, 0, nmx, nmy);
852 void
853 client_kill(Client *c)
855 XEvent ev;
857 if(isprotodel(globalconf.display, c->win))
859 ev.type = ClientMessage;
860 ev.xclient.window = c->win;
861 ev.xclient.message_type = XInternAtom(globalconf.display, "WM_PROTOCOLS", False);
862 ev.xclient.format = 32;
863 ev.xclient.data.l[0] = XInternAtom(globalconf.display, "WM_DELETE_WINDOW", False);
864 ev.xclient.data.l[1] = CurrentTime;
865 XSendEvent(globalconf.display, c->win, False, NoEventMask, &ev);
867 else
868 XKillClient(globalconf.display, c->win);
871 /** Kill selected client
872 * \param screen Screen ID
873 * \param arg unused
874 * \ingroup ui_callback
876 void
877 uicb_client_kill(int screen __attribute__ ((unused)), char *arg __attribute__ ((unused)))
879 Client *sel = globalconf.focus->client;
881 if(sel)
882 client_kill(sel);
885 static void
886 client_maximize(Client *c, Area geometry)
889 if((c->ismax = !c->ismax))
891 c->wasfloating = c->isfloating;
892 c->m_geometry = c->geometry;
893 client_resize(c, geometry, False);
894 /* set floating after resizing so it won't save
895 * coords */
896 c->isfloating = True;
897 restack(c->screen);
898 widget_invalidate_cache(c->screen, WIDGET_CACHE_CLIENTS);
900 else if(c->wasfloating)
902 c->isfloating = True;
903 client_resize(c, c->m_geometry, False);
904 restack(c->screen);
905 widget_invalidate_cache(c->screen, WIDGET_CACHE_CLIENTS);
907 else
909 c->isfloating = False;
910 arrange(c->screen);
911 widget_invalidate_cache(c->screen, WIDGET_CACHE_CLIENTS);
915 /** Toggle maximize for client
916 * \param screen Screen ID
917 * \param arg Unused
918 * \ingroup ui_callback
920 void
921 uicb_client_togglemax(int screen, char *arg __attribute__ ((unused)))
923 Client *sel = globalconf.focus->client;
924 Area area = get_screen_area(screen,
925 globalconf.screens[screen].statusbar,
926 &globalconf.screens[screen].padding);
928 if(sel)
930 area.width -= 2 * sel->border;
931 area.height -= 2 * sel->border;
932 client_maximize(sel, area);
936 /** Toggle vertical maximize for client
937 * \param screen Screen ID
938 * \param arg Unused
939 * \ingroup ui_callback
941 void
942 uicb_client_toggleverticalmax(int screen, char *arg __attribute__ ((unused)))
944 Client *sel = globalconf.focus->client;
945 Area area = get_screen_area(screen,
946 globalconf.screens[screen].statusbar,
947 &globalconf.screens[screen].padding);
949 if(sel)
951 area.x = sel->geometry.x;
952 area.height -= 2 * sel->border;
953 client_maximize(sel, area);
958 /** Toggle horizontal maximize for client
959 * \param screen Screen ID
960 * \param arg Unused
961 * \ingroup ui_callback
963 void
964 uicb_client_togglehorizontalmax(int screen, char *arg __attribute__ ((unused)))
966 Client *sel = globalconf.focus->client;
967 Area area = get_screen_area(screen,
968 globalconf.screens[screen].statusbar,
969 &globalconf.screens[screen].padding);
971 if(sel)
973 area.y = sel->geometry.y;
974 area.width -= 2 * sel->border;
975 client_maximize(sel, area);
979 /** Zoom client
980 * \param screen Screen ID
981 * \param arg Unused
982 * \ingroup ui_callback
984 void
985 uicb_client_zoom(int screen, char *arg __attribute__ ((unused)))
987 Client *sel = globalconf.focus->client;
989 if(globalconf.clients == sel)
990 for(sel = sel->next; sel && !client_isvisible(sel, screen); sel = sel->next);
992 if(!sel)
993 return;
995 client_detach(sel);
996 client_attach(sel);
998 focus(sel, True, screen);
999 arrange(screen);
1002 // vim: filetype=c:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=80