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.
23 #include <X11/Xatom.h>
24 #include <X11/extensions/shape.h>
34 #include "layouts/floating.h"
35 #include "common/xutil.h"
36 #include "common/xscreen.h"
38 extern AwesomeConf globalconf
;
40 /** Load windows properties, restoring client's tag
41 * and floating state before awesome was restarted if any
42 * \todo this may bug if number of tags is != than before
44 * \param screen Screen ID
45 * \return true if client had property
48 client_loadprops(Client
* c
, int screen
)
55 for(tag
= globalconf
.screens
[screen
].tags
; tag
; tag
= tag
->next
)
58 prop
= p_new(char, ntags
+ 2);
60 if(xgettextprop(globalconf
.display
, c
->win
,
61 XInternAtom(globalconf
.display
, "_AWESOME_PROPERTIES", False
),
64 for(i
= 0, tag
= globalconf
.screens
[screen
].tags
; tag
&& i
< ntags
&& prop
[i
]; i
++, tag
= tag
->next
)
73 if(i
<= ntags
&& prop
[i
])
74 client_setfloating(c
, prop
[i
] == '1');
82 /** Check if client supports protocol WM_DELETE_WINDOW
83 * \param disp the display
84 * \param win the Window
85 * \return True if client has WM_DELETE_WINDOW
88 client_isprotodel(Display
*disp
, Window win
)
94 if(XGetWMProtocols(disp
, win
, &protocols
, &n
))
96 for(i
= 0; !ret
&& i
< n
; i
++)
97 if(protocols
[i
] == XInternAtom(disp
, "WM_DELETE_WINDOW", False
))
104 /** Get a Client by its window
105 * \param list Client list to look info
106 * \param w Client window to find
110 client_get_bywin(Client
*list
, Window w
)
114 for(c
= list
; c
&& c
->win
!= w
; c
= c
->next
);
118 /** Get a client by its name
119 * \param list Client list
120 * \param name name to search
121 * \return first matching client
124 client_get_byname(Client
*list
, char *name
)
128 for(c
= list
; c
; c
= c
->next
)
129 if(strstr(c
->name
, name
))
135 /** Update client name attribute with its title
136 * \param c the client
139 client_updatetitle(Client
*c
)
141 if(!xgettextprop(globalconf
.display
, c
->win
,
142 XInternAtom(globalconf
.display
, "_NET_WM_NAME", False
), c
->name
, sizeof(c
->name
)))
143 xgettextprop(globalconf
.display
, c
->win
,
144 XInternAtom(globalconf
.display
, "WM_NAME", False
), c
->name
, sizeof(c
->name
));
146 widget_invalidate_cache(c
->screen
, WIDGET_CACHE_CLIENTS
);
150 client_unfocus(Client
*c
)
152 if(globalconf
.screens
[c
->screen
].opacity_unfocused
!= -1)
153 window_settrans(c
->win
, globalconf
.screens
[c
->screen
].opacity_unfocused
);
154 XSetWindowBorder(globalconf
.display
, c
->win
,
155 globalconf
.screens
[c
->screen
].colors
.normal
.border
.pixel
);
156 widget_invalidate_cache(c
->screen
, WIDGET_CACHE_CLIENTS
);
157 focus_add_client(NULL
);
160 /** Ban client and unmap it
161 * \param c the client
164 client_ban(Client
*c
)
166 if(globalconf
.focus
->client
== c
)
168 XUnmapWindow(globalconf
.display
, c
->win
);
169 window_setstate(c
->win
, IconicState
);
172 /** Give focus to client, or to first client if c is NULL
174 * \param screen Screen ID
177 client_focus(Client
*c
, int screen
, Bool raise
)
179 int phys_screen
= get_phys_screen(screen
);
181 /* if c is NULL or invisible, take next client in the focus history */
182 if(!c
|| (c
&& !client_isvisible(c
, screen
)))
184 c
= focus_get_current_client(screen
);
185 /* if c is still NULL take next client in the stack */
187 for(c
= globalconf
.clients
; c
&& (c
->skip
|| !client_isvisible(c
, screen
)); c
= c
->next
);
190 /* unfocus current selected client */
191 if(globalconf
.focus
->client
)
192 client_unfocus(globalconf
.focus
->client
);
196 /* unban the client before focusing or it will fail */
198 /* save sel in focus history */
200 if(globalconf
.screens
[c
->screen
].opacity_unfocused
!= -1)
201 window_settrans(c
->win
, -1);
202 XSetWindowBorder(globalconf
.display
, c
->win
,
203 globalconf
.screens
[screen
].colors
.focus
.border
.pixel
);
204 XSetInputFocus(globalconf
.display
, c
->win
, RevertToPointerRoot
, CurrentTime
);
208 Layout
*curlay
= layout_get_current(screen
);
209 if(c
->isfloating
|| curlay
->arrange
== layout_floating
)
210 XRaiseWindow(globalconf
.display
, c
->win
);
214 wc
.stack_mode
= Below
;
216 for(client
= globalconf
.clients
; client
; client
= client
->next
)
217 if(client
!= c
&& client_isvisible(client
, c
->screen
) && client
->isfloating
)
219 XConfigureWindow(globalconf
.display
, client
->win
, CWSibling
| CWStackMode
, &wc
);
220 wc
.sibling
= client
->win
;
222 XConfigureWindow(globalconf
.display
, c
->win
, CWSibling
| CWStackMode
, &wc
);
224 for(client
= globalconf
.clients
; client
; client
= client
->next
)
225 if(client
!= c
&& IS_TILED(client
, c
->screen
))
227 XConfigureWindow(globalconf
.display
, client
->win
, CWSibling
| CWStackMode
, &wc
);
228 wc
.sibling
= client
->win
;
232 /* since we're dropping EnterWindow events and sometimes the window
233 * will appear under the mouse, grabbuttons */
234 window_grabbuttons(phys_screen
, c
->win
);
237 XSetInputFocus(globalconf
.display
,
238 RootWindow(globalconf
.display
, phys_screen
),
239 RevertToPointerRoot
, CurrentTime
);
241 widget_invalidate_cache(screen
, WIDGET_CACHE_CLIENTS
);
242 ewmh_update_net_active_window(phys_screen
);
245 /** Manage a new client
246 * \param w The window
247 * \param wa Window attributes
248 * \param screen Screen ID
251 client_manage(Window w
, XWindowAttributes
*wa
, int screen
)
253 Client
*c
, *t
= NULL
;
255 Bool rettrans
, retloadprops
;
260 int phys_screen
= get_phys_screen(screen
);
263 c
= p_new(Client
, 1);
265 c
->screen
= screen_get_bycoord(globalconf
.screens_info
, screen
, wa
->x
, wa
->y
);
267 screen_geom
= screen_get_area(c
->screen
,
268 globalconf
.screens
[screen
].statusbar
,
269 &globalconf
.screens
[screen
].padding
);
272 c
->geometry
.x
= c
->f_geometry
.x
= c
->m_geometry
.x
= MAX(wa
->x
, screen_geom
.x
);
273 c
->geometry
.y
= c
->f_geometry
.y
= c
->m_geometry
.y
= MAX(wa
->y
, screen_geom
.y
);
274 c
->geometry
.width
= c
->f_geometry
.width
= c
->m_geometry
.width
= wa
->width
;
275 c
->geometry
.height
= c
->f_geometry
.height
= c
->m_geometry
.height
= wa
->height
;
276 c
->oldborder
= wa
->border_width
;
279 c
->border
= globalconf
.screens
[screen
].borderpx
;
281 /* Set windows borders */
282 wc
.border_width
= c
->border
;
283 XConfigureWindow(globalconf
.display
, w
, CWBorderWidth
, &wc
);
284 XSetWindowBorder(globalconf
.display
, w
, globalconf
.screens
[screen
].colors
.normal
.border
.pixel
);
285 /* propagates border_width, if size doesn't change */
286 window_configure(c
->win
, c
->geometry
, c
->border
);
288 /* update window title */
289 client_updatetitle(c
);
292 flags
= client_updatesizehints(c
);
293 client_updatewmhints(c
);
295 /* Try to load props if any */
296 retloadprops
= client_loadprops(c
, screen
);
298 /* Then check clients hints */
299 ewmh_check_client_hints(c
);
301 /* Then apply rules if no props */
304 /* Get the client's rule */
305 if((rule
= rule_matching_client(c
)))
307 if(rule
->screen
!= RULE_NOSCREEN
)
308 move_client_to_screen(c
, rule
->screen
, True
);
310 move_client_to_screen(c
, screen
, True
);
311 tag_client_with_rule(c
, rule
);
313 switch(rule
->isfloating
)
318 client_setfloating(c
, True
);
321 client_setfloating(c
, False
);
325 if(rule
->opacity
>= 0.0f
)
326 window_settrans(c
->win
, rule
->opacity
);
329 move_client_to_screen(c
, screen
, True
);
332 /* check for transient and set tags like its parent,
333 * XGetTransientForHint returns 1 on success
335 if((rettrans
= XGetTransientForHint(globalconf
.display
, w
, &trans
))
336 && (t
= client_get_bywin(globalconf
.clients
, trans
)))
337 for(tag
= globalconf
.screens
[c
->screen
].tags
; tag
; tag
= tag
->next
)
338 if(is_client_tagged(t
, tag
))
341 /* should be floating if transsient or fixed */
343 client_setfloating(c
, rettrans
|| c
->isfixed
);
345 if(!(flags
& (USPosition
| PPosition
)))
347 globalconf
.screens
[c
->screen
].floating_placement(c
->f_geometry
, c
->border
, c
->screen
);
349 XSelectInput(globalconf
.display
, w
, StructureNotifyMask
| PropertyChangeMask
| EnterWindowMask
);
352 if(globalconf
.have_shape
)
354 XShapeSelectInput(globalconf
.display
, w
, ShapeNotifyMask
);
355 window_setshape(phys_screen
, c
->win
);
358 /* attach to the stack */
359 if((rule
= rule_matching_client(c
)))
360 switch(rule
->ismaster
)
363 client_list_push(&globalconf
.clients
, c
);
366 client_list_append(&globalconf
.clients
, c
);
375 if(globalconf
.screens
[c
->screen
].new_become_master
)
376 client_list_push(&globalconf
.clients
, c
);
378 client_list_append(&globalconf
.clients
, c
);
381 /* some windows require this */
382 XMoveResizeWindow(globalconf
.display
, c
->win
, c
->geometry
.x
, c
->geometry
.y
,
383 c
->geometry
.width
, c
->geometry
.height
);
385 widget_invalidate_cache(c
->screen
, WIDGET_CACHE_CLIENTS
);
386 ewmh_update_net_client_list(phys_screen
);
389 /** Resize client window
390 * \param c client to resize
391 * \param geometry new window geometry
392 * \param sizehints respect size hints
393 * \param return True if resize has been done
396 client_resize(Client
*c
, Area geometry
, Bool sizehints
)
399 double dx
, dy
, max
, min
, ratio
;
405 if(c
->minay
> 0 && c
->maxay
> 0 && (geometry
.height
- c
->baseh
) > 0
406 && (geometry
.width
- c
->basew
) > 0)
408 dx
= (double) (geometry
.width
- c
->basew
);
409 dy
= (double) (geometry
.height
- c
->baseh
);
410 min
= (double) (c
->minax
) / (double) (c
->minay
);
411 max
= (double) (c
->maxax
) / (double) (c
->maxay
);
413 if(max
> 0 && min
> 0 && ratio
> 0)
417 dy
= (dx
* min
+ dy
) / (min
* min
+ 1);
419 geometry
.width
= (int) dx
+ c
->basew
;
420 geometry
.height
= (int) dy
+ c
->baseh
;
424 dy
= (dx
* min
+ dy
) / (max
* max
+ 1);
426 geometry
.width
= (int) dx
+ c
->basew
;
427 geometry
.height
= (int) dy
+ c
->baseh
;
431 if(c
->minw
&& geometry
.width
< c
->minw
)
432 geometry
.width
= c
->minw
;
433 if(c
->minh
&& geometry
.height
< c
->minh
)
434 geometry
.height
= c
->minh
;
435 if(c
->maxw
&& geometry
.width
> c
->maxw
)
436 geometry
.width
= c
->maxw
;
437 if(c
->maxh
&& geometry
.height
> c
->maxh
)
438 geometry
.height
= c
->maxh
;
440 geometry
.width
-= (geometry
.width
- c
->basew
) % c
->incw
;
442 geometry
.height
-= (geometry
.height
- c
->baseh
) % c
->inch
;
444 if(geometry
.width
<= 0 || geometry
.height
<= 0)
446 /* offscreen appearance fixes */
447 area
= get_display_area(get_phys_screen(c
->screen
),
449 &globalconf
.screens
[c
->screen
].padding
);
450 if(geometry
.x
> area
.width
)
451 geometry
.x
= area
.width
- geometry
.width
- 2 * c
->border
;
452 if(geometry
.y
> area
.height
)
453 geometry
.y
= area
.height
- geometry
.height
- 2 * c
->border
;
454 if(geometry
.x
+ geometry
.width
+ 2 * c
->border
< 0)
456 if(geometry
.y
+ geometry
.height
+ 2 * c
->border
< 0)
459 if(c
->geometry
.x
!= geometry
.x
|| c
->geometry
.y
!= geometry
.y
460 || c
->geometry
.width
!= geometry
.width
|| c
->geometry
.height
!= geometry
.height
)
462 new_screen
= screen_get_bycoord(globalconf
.screens_info
, c
->screen
, geometry
.x
, geometry
.y
);
464 c
->geometry
.x
= wc
.x
= geometry
.x
;
465 c
->geometry
.y
= wc
.y
= geometry
.y
;
466 c
->geometry
.width
= wc
.width
= geometry
.width
;
467 c
->geometry
.height
= wc
.height
= geometry
.height
;
468 wc
.border_width
= c
->border
;
470 /* save the floating geometry if the window is floating but not
473 layout_get_current(new_screen
)->arrange
== layout_floating
) && !c
->ismax
)
474 c
->f_geometry
= geometry
;
476 XConfigureWindow(globalconf
.display
, c
->win
,
477 CWX
| CWY
| CWWidth
| CWHeight
| CWBorderWidth
, &wc
);
478 window_configure(c
->win
, geometry
, c
->border
);
480 if(c
->screen
!= new_screen
)
481 move_client_to_screen(c
, new_screen
, False
);
489 client_setfloating(Client
*c
, Bool floating
)
491 if(c
->isfloating
!= floating
)
493 if((c
->isfloating
= floating
))
495 client_resize(c
, c
->f_geometry
, False
);
496 XRaiseWindow(globalconf
.display
, c
->win
);
500 XLowerWindow(globalconf
.display
, c
->win
);
504 client_resize(c
, c
->m_geometry
, False
);
507 if(client_isvisible(c
, c
->screen
))
508 globalconf
.screens
[c
->screen
].need_arrange
= True
;
509 widget_invalidate_cache(c
->screen
, WIDGET_CACHE_CLIENTS
);
514 /** Save client properties as an X property
518 client_saveprops(Client
*c
)
520 int i
= 0, ntags
= 0;
524 for(tag
= globalconf
.screens
[c
->screen
].tags
; tag
; tag
= tag
->next
)
527 prop
= p_new(char, ntags
+ 2);
529 for(tag
= globalconf
.screens
[c
->screen
].tags
; tag
; tag
= tag
->next
, i
++)
530 prop
[i
] = is_client_tagged(c
, tag
) ? '1' : '0';
533 prop
[i
] = c
->isfloating
? '1' : '0';
537 XChangeProperty(globalconf
.display
, c
->win
,
538 XInternAtom(globalconf
.display
, "_AWESOME_PROPERTIES", False
),
539 XA_STRING
, 8, PropModeReplace
, (unsigned char *) prop
, i
);
545 client_unban(Client
*c
)
547 XMapWindow(globalconf
.display
, c
->win
);
548 window_setstate(c
->win
, NormalState
);
552 client_unmanage(Client
*c
)
557 wc
.border_width
= c
->oldborder
;
559 /* The server grab construct avoids race conditions. */
560 XGrabServer(globalconf
.display
);
562 XConfigureWindow(globalconf
.display
, c
->win
, CWBorderWidth
, &wc
); /* restore border */
564 /* remove client everywhere */
565 client_list_detach(&globalconf
.clients
, c
);
566 focus_delete_client(c
);
567 if(globalconf
.scratch
.client
== c
)
568 globalconf
.scratch
.client
= NULL
;
569 for(tag
= globalconf
.screens
[c
->screen
].tags
; tag
; tag
= tag
->next
)
570 untag_client(c
, tag
);
572 if(globalconf
.focus
->client
== c
)
573 client_focus(NULL
, c
->screen
, True
);
575 XUngrabButton(globalconf
.display
, AnyButton
, AnyModifier
, c
->win
);
576 window_setstate(c
->win
, WithdrawnState
);
578 XSync(globalconf
.display
, False
);
579 XUngrabServer(globalconf
.display
);
585 client_updatewmhints(Client
*c
)
589 if((wmh
= XGetWMHints(globalconf
.display
, c
->win
)))
591 if((c
->isurgent
= (wmh
->flags
& XUrgencyHint
)))
592 widget_invalidate_cache(c
->screen
, WIDGET_CACHE_CLIENTS
);
593 if((wmh
->flags
& StateHint
) && wmh
->initial_state
== WithdrawnState
)
603 client_updatesizehints(Client
*c
)
608 if(!XGetWMNormalHints(globalconf
.display
, c
->win
, &size
, &msize
))
611 if(size
.flags
& PBaseSize
)
613 c
->basew
= size
.base_width
;
614 c
->baseh
= size
.base_height
;
616 else if(size
.flags
& PMinSize
)
618 c
->basew
= size
.min_width
;
619 c
->baseh
= size
.min_height
;
622 c
->basew
= c
->baseh
= 0;
623 if(size
.flags
& PResizeInc
)
625 c
->incw
= size
.width_inc
;
626 c
->inch
= size
.height_inc
;
629 c
->incw
= c
->inch
= 0;
631 if(size
.flags
& PMaxSize
)
633 c
->maxw
= size
.max_width
;
634 c
->maxh
= size
.max_height
;
637 c
->maxw
= c
->maxh
= 0;
639 if(size
.flags
& PMinSize
)
641 c
->minw
= size
.min_width
;
642 c
->minh
= size
.min_height
;
644 else if(size
.flags
& PBaseSize
)
646 c
->minw
= size
.base_width
;
647 c
->minh
= size
.base_height
;
650 c
->minw
= c
->minh
= 0;
652 if(size
.flags
& PAspect
)
654 c
->minax
= size
.min_aspect
.x
;
655 c
->maxax
= size
.max_aspect
.x
;
656 c
->minay
= size
.min_aspect
.y
;
657 c
->maxay
= size
.max_aspect
.y
;
660 c
->minax
= c
->maxax
= c
->minay
= c
->maxay
= 0;
662 if(c
->maxw
&& c
->minw
&& c
->maxh
&& c
->minh
663 && c
->maxw
== c
->minw
&& c
->maxh
== c
->minh
)
669 /** Returns True if a client is tagged
670 * with one of the tags
671 * \return True or False
674 client_isvisible(Client
*c
, int screen
)
678 if(!c
|| c
->screen
!= screen
)
681 if(globalconf
.scratch
.client
== c
)
682 return globalconf
.scratch
.isvisible
;
684 for(tag
= globalconf
.screens
[screen
].tags
; tag
; tag
= tag
->next
)
685 if(tag
->selected
&& is_client_tagged(c
, tag
))
690 /** Set selected client transparency
691 * \param screen Screen ID
692 * \param arg unused arg
693 * \ingroup ui_callback
696 uicb_client_settrans(int screen
__attribute__ ((unused
)), char *arg
)
698 double delta
= 100.0, current_opacity
= 100.0;
702 unsigned long n
, left
;
703 unsigned int current_opacity_raw
= 0;
705 Client
*sel
= globalconf
.focus
->client
;
710 XGetWindowProperty(globalconf
.display
, sel
->win
,
711 XInternAtom(globalconf
.display
, "_NET_WM_WINDOW_OPACITY", False
),
712 0L, 1L, False
, XA_CARDINAL
, &actual
, &format
, &n
, &left
,
713 (unsigned char **) &data
);
716 memcpy(¤t_opacity_raw
, data
, sizeof(unsigned int));
718 current_opacity
= (current_opacity_raw
* 100.0) / 0xffffffff;
723 delta
= compute_new_value_from_arg(arg
, current_opacity
);
727 else if(delta
> 100.0)
733 if(delta
== 100.0 && !set_prop
)
734 window_settrans(sel
->win
, -1);
736 window_settrans(sel
->win
, delta
);
740 client_find_prev_visible(Client
*sel
)
744 if(!sel
) return NULL
;
746 /* look for previous starting at sel */
747 for(prev
= client_list_prev_cycle(&globalconf
.clients
, sel
);
748 prev
&& (prev
->skip
|| !client_isvisible(prev
, sel
->screen
));
749 prev
= client_list_prev_cycle(&globalconf
.clients
, prev
));
755 client_find_next_visible(Client
*sel
)
759 if(!sel
) return NULL
;
761 for(next
= sel
->next
; next
&& !client_isvisible(next
, sel
->screen
); next
= next
->next
);
763 for(next
= globalconf
.clients
; next
&& !client_isvisible(next
, sel
->screen
); next
= next
->next
);
768 /** Swap current with previous client
769 * \param screen Screen ID
771 * \ingroup ui_callback
774 uicb_client_swapprev(int screen
__attribute__ ((unused
)),
775 char *arg
__attribute__ ((unused
)))
779 if((prev
= client_find_prev_visible(globalconf
.focus
->client
)))
781 client_list_swap(&globalconf
.clients
, prev
, globalconf
.focus
->client
);
782 globalconf
.screens
[prev
->screen
].need_arrange
= True
;
786 /** Swap current with next client
787 * \param screen Screen ID
789 * \ingroup ui_callback
792 uicb_client_swapnext(int screen
__attribute__ ((unused
)),
793 char *arg
__attribute__ ((unused
)))
797 if((next
= client_find_next_visible(globalconf
.focus
->client
)))
799 client_list_swap(&globalconf
.clients
, globalconf
.focus
->client
, next
);
800 globalconf
.screens
[next
->screen
].need_arrange
= True
;
804 /** Move and resize client
805 * \param screen Screen ID
807 * \ingroup ui_callback
810 uicb_client_moveresize(int screen
, char *arg
)
812 int ox
, oy
, ow
, oh
; /* old geometry */
813 char x
[8], y
[8], w
[8], h
[8];
814 int mx
, my
, dx
, dy
, nmx
, nmy
;
818 Client
*sel
= globalconf
.focus
->client
;
819 Layout
*curlay
= layout_get_current(screen
);
821 if(!sel
|| sel
->isfixed
|| !arg
||
822 (curlay
->arrange
!= layout_floating
&& !sel
->isfloating
))
825 if(sscanf(arg
, "%s %s %s %s", x
, y
, w
, h
) != 4)
828 area
.x
= (int) compute_new_value_from_arg(x
, sel
->geometry
.x
);
829 area
.y
= (int) compute_new_value_from_arg(y
, sel
->geometry
.y
);
830 area
.width
= (int) compute_new_value_from_arg(w
, sel
->geometry
.width
);
831 area
.height
= (int) compute_new_value_from_arg(h
, sel
->geometry
.height
);
833 ox
= sel
->geometry
.x
;
834 oy
= sel
->geometry
.y
;
835 ow
= sel
->geometry
.width
;
836 oh
= sel
->geometry
.height
;
838 Bool xqp
= XQueryPointer(globalconf
.display
,
839 RootWindow(globalconf
.display
,
840 get_phys_screen(screen
)),
841 &dummy
, &dummy
, &mx
, &my
, &dx
, &dy
, &dui
);
842 client_resize(sel
, area
, globalconf
.screens
[sel
->screen
].resize_hints
);
843 if (xqp
&& ox
<= mx
&& (ox
+ 2 * sel
->border
+ ow
) >= mx
&&
844 oy
<= my
&& (oy
+ 2 * sel
->border
+ oh
) >= my
)
846 nmx
= mx
- (ox
+ sel
->border
) + sel
->geometry
.width
- ow
;
847 nmy
= my
- (oy
+ sel
->border
) + sel
->geometry
.height
- oh
;
849 if(nmx
< -sel
->border
) /* can happen on a resize */
851 if(nmy
< -sel
->border
)
854 XWarpPointer(globalconf
.display
,
856 0, 0, 0, 0, nmx
, nmy
);
861 client_kill(Client
*c
)
865 if(client_isprotodel(globalconf
.display
, c
->win
))
867 ev
.type
= ClientMessage
;
868 ev
.xclient
.window
= c
->win
;
869 ev
.xclient
.message_type
= XInternAtom(globalconf
.display
, "WM_PROTOCOLS", False
);
870 ev
.xclient
.format
= 32;
871 ev
.xclient
.data
.l
[0] = XInternAtom(globalconf
.display
, "WM_DELETE_WINDOW", False
);
872 ev
.xclient
.data
.l
[1] = CurrentTime
;
873 XSendEvent(globalconf
.display
, c
->win
, False
, NoEventMask
, &ev
);
876 XKillClient(globalconf
.display
, c
->win
);
879 /** Kill selected client
880 * \param screen Screen ID
882 * \ingroup ui_callback
885 uicb_client_kill(int screen
__attribute__ ((unused
)), char *arg
__attribute__ ((unused
)))
887 Client
*sel
= globalconf
.focus
->client
;
894 client_maximize(Client
*c
, Area geometry
)
897 if((c
->ismax
= !c
->ismax
))
899 c
->wasfloating
= c
->isfloating
;
900 c
->m_geometry
= c
->geometry
;
901 if(layout_get_current(c
->screen
)->arrange
!= layout_floating
)
902 client_setfloating(c
, True
);
903 client_focus(c
, c
->screen
, True
);
904 client_resize(c
, geometry
, False
);
905 widget_invalidate_cache(c
->screen
, WIDGET_CACHE_CLIENTS
);
907 else if(c
->wasfloating
)
909 client_setfloating(c
, True
);
910 client_resize(c
, c
->m_geometry
, False
);
911 widget_invalidate_cache(c
->screen
, WIDGET_CACHE_CLIENTS
);
913 else if(layout_get_current(c
->screen
)->arrange
== layout_floating
)
915 client_resize(c
, c
->m_geometry
, False
);
916 widget_invalidate_cache(c
->screen
, WIDGET_CACHE_CLIENTS
);
920 client_setfloating(c
, False
);
921 widget_invalidate_cache(c
->screen
, WIDGET_CACHE_CLIENTS
);
925 /** Toggle maximize for client
926 * \param screen Screen ID
928 * \ingroup ui_callback
931 uicb_client_togglemax(int screen
, char *arg
__attribute__ ((unused
)))
933 Client
*sel
= globalconf
.focus
->client
;
934 Area area
= screen_get_area(screen
,
935 globalconf
.screens
[screen
].statusbar
,
936 &globalconf
.screens
[screen
].padding
);
940 area
.width
-= 2 * sel
->border
;
941 area
.height
-= 2 * sel
->border
;
942 client_maximize(sel
, area
);
946 /** Toggle vertical maximize for client
947 * \param screen Screen ID
949 * \ingroup ui_callback
952 uicb_client_toggleverticalmax(int screen
, char *arg
__attribute__ ((unused
)))
954 Client
*sel
= globalconf
.focus
->client
;
955 Area area
= screen_get_area(screen
,
956 globalconf
.screens
[screen
].statusbar
,
957 &globalconf
.screens
[screen
].padding
);
961 area
.x
= sel
->geometry
.x
;
962 area
.width
= sel
->geometry
.width
;
963 area
.height
-= 2 * sel
->border
;
964 client_maximize(sel
, area
);
969 /** Toggle horizontal maximize for client
970 * \param screen Screen ID
972 * \ingroup ui_callback
975 uicb_client_togglehorizontalmax(int screen
, char *arg
__attribute__ ((unused
)))
977 Client
*sel
= globalconf
.focus
->client
;
978 Area area
= screen_get_area(screen
,
979 globalconf
.screens
[screen
].statusbar
,
980 &globalconf
.screens
[screen
].padding
);
984 area
.y
= sel
->geometry
.y
;
985 area
.height
= sel
->geometry
.height
;
986 area
.width
-= 2 * sel
->border
;
987 client_maximize(sel
, area
);
992 * \param screen Screen ID
994 * \ingroup ui_callback
997 uicb_client_zoom(int screen
, char *arg
__attribute__ ((unused
)))
999 Client
*c
, *sel
= globalconf
.focus
->client
;
1004 for(c
= globalconf
.clients
; !client_isvisible(c
, screen
); c
= c
->next
);
1006 for(sel
= sel
->next
; sel
&& !client_isvisible(sel
, screen
); sel
= sel
->next
);
1010 client_list_detach(&globalconf
.clients
, sel
);
1011 client_list_push(&globalconf
.clients
, sel
);
1012 globalconf
.screens
[screen
].need_arrange
= True
;
1016 /** Send focus to next client in stack
1017 * \param screen Screen ID
1019 * \ingroup ui_callback
1022 uicb_client_focusnext(int screen
, char *arg
__attribute__ ((unused
)))
1024 Client
*c
, *sel
= globalconf
.focus
->client
;
1028 for(c
= sel
->next
; c
&& (c
->skip
|| !client_isvisible(c
, screen
)); c
= c
->next
);
1030 for(c
= globalconf
.clients
; c
&& (c
->skip
|| !client_isvisible(c
, screen
)); c
= c
->next
);
1032 client_focus(c
, screen
, True
);
1035 /** Send focus to previous client in stack
1036 * \param screen Screen ID
1038 * \ingroup ui_callback
1041 uicb_client_focusprev(int screen
, char *arg
__attribute__ ((unused
)))
1045 if((prev
= client_find_prev_visible(globalconf
.focus
->client
)))
1046 client_focus(prev
, screen
, True
);
1049 /** Toggle floating state of a client
1050 * \param screen Screen ID
1052 * \ingroup ui_callback
1055 uicb_client_togglefloating(int screen
__attribute__ ((unused
)),
1056 char *arg
__attribute__ ((unused
)))
1058 if(globalconf
.focus
->client
)
1059 client_setfloating(globalconf
.focus
->client
, !globalconf
.focus
->client
->isfloating
);
1062 /** Toggle scratch client attribute
1063 * \param screen screen number
1064 * \param arg unused argument
1065 * \ingroup ui_callback
1068 uicb_client_setscratch(int screen
,
1069 char *arg
__attribute__ ((unused
)))
1071 if(!globalconf
.focus
->client
)
1074 if(globalconf
.scratch
.client
== globalconf
.focus
->client
)
1075 globalconf
.scratch
.client
= NULL
;
1077 globalconf
.scratch
.client
= globalconf
.focus
->client
;
1079 widget_invalidate_cache(screen
, WIDGET_CACHE_CLIENTS
| WIDGET_CACHE_TAGS
);
1080 globalconf
.screens
[screen
].need_arrange
= True
;
1083 /** Toggle scratch client visibility
1084 * \param screen screen number
1085 * \param arg unused argument
1086 * \ingroup ui_callback
1089 uicb_client_togglescratch(int screen
,
1090 char *arg
__attribute__ ((unused
)))
1092 if(globalconf
.scratch
.client
)
1094 globalconf
.scratch
.isvisible
= !globalconf
.scratch
.isvisible
;
1095 if(globalconf
.scratch
.isvisible
)
1096 client_focus(globalconf
.scratch
.client
, screen
, True
);
1097 globalconf
.screens
[globalconf
.scratch
.client
->screen
].need_arrange
= True
;
1098 widget_invalidate_cache(globalconf
.scratch
.client
->screen
, WIDGET_CACHE_CLIENTS
);
1101 // vim: filetype=c:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=80