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
].styles
.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
].styles
.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
,
285 globalconf
.screens
[screen
].styles
.normal
.border
.pixel
);
286 /* propagates border_width, if size doesn't change */
287 window_configure(c
->win
, c
->geometry
, c
->border
);
289 /* update window title */
290 client_updatetitle(c
);
293 flags
= client_updatesizehints(c
);
294 client_updatewmhints(c
);
296 /* Try to load props if any */
297 retloadprops
= client_loadprops(c
, screen
);
299 /* Then check clients hints */
300 ewmh_check_client_hints(c
);
302 /* Then apply rules if no props */
305 /* Get the client's rule */
306 if((rule
= rule_matching_client(c
)))
308 if(rule
->screen
!= RULE_NOSCREEN
)
309 move_client_to_screen(c
, rule
->screen
, True
);
311 move_client_to_screen(c
, screen
, True
);
312 tag_client_with_rule(c
, rule
);
314 switch(rule
->isfloating
)
319 client_setfloating(c
, True
);
322 client_setfloating(c
, False
);
326 if(rule
->opacity
>= 0.0f
)
327 window_settrans(c
->win
, rule
->opacity
);
330 move_client_to_screen(c
, screen
, True
);
333 /* check for transient and set tags like its parent,
334 * XGetTransientForHint returns 1 on success
336 if((rettrans
= XGetTransientForHint(globalconf
.display
, w
, &trans
))
337 && (t
= client_get_bywin(globalconf
.clients
, trans
)))
338 for(tag
= globalconf
.screens
[c
->screen
].tags
; tag
; tag
= tag
->next
)
339 if(is_client_tagged(t
, tag
))
342 /* should be floating if transsient or fixed */
344 client_setfloating(c
, rettrans
|| c
->isfixed
);
346 if(!(flags
& (USPosition
| PPosition
)))
348 globalconf
.screens
[c
->screen
].floating_placement(c
->f_geometry
, c
->border
, c
->screen
);
350 XSelectInput(globalconf
.display
, w
, StructureNotifyMask
| PropertyChangeMask
| EnterWindowMask
);
353 if(globalconf
.have_shape
)
355 XShapeSelectInput(globalconf
.display
, w
, ShapeNotifyMask
);
356 window_setshape(phys_screen
, c
->win
);
359 /* attach to the stack */
360 if((rule
= rule_matching_client(c
)))
361 switch(rule
->ismaster
)
364 client_list_push(&globalconf
.clients
, c
);
367 client_list_append(&globalconf
.clients
, c
);
376 if(globalconf
.screens
[c
->screen
].new_become_master
)
377 client_list_push(&globalconf
.clients
, c
);
379 client_list_append(&globalconf
.clients
, c
);
382 /* some windows require this */
383 XMoveResizeWindow(globalconf
.display
, c
->win
, c
->geometry
.x
, c
->geometry
.y
,
384 c
->geometry
.width
, c
->geometry
.height
);
386 widget_invalidate_cache(c
->screen
, WIDGET_CACHE_CLIENTS
);
387 ewmh_update_net_client_list(phys_screen
);
390 /** Resize client window
391 * \param c client to resize
392 * \param geometry new window geometry
393 * \param sizehints respect size hints
394 * \param return True if resize has been done
397 client_resize(Client
*c
, Area geometry
, Bool sizehints
)
400 double dx
, dy
, max
, min
, ratio
;
406 if(c
->minay
> 0 && c
->maxay
> 0 && (geometry
.height
- c
->baseh
) > 0
407 && (geometry
.width
- c
->basew
) > 0)
409 dx
= (double) (geometry
.width
- c
->basew
);
410 dy
= (double) (geometry
.height
- c
->baseh
);
411 min
= (double) (c
->minax
) / (double) (c
->minay
);
412 max
= (double) (c
->maxax
) / (double) (c
->maxay
);
414 if(max
> 0 && min
> 0 && ratio
> 0)
418 dy
= (dx
* min
+ dy
) / (min
* min
+ 1);
420 geometry
.width
= (int) dx
+ c
->basew
;
421 geometry
.height
= (int) dy
+ c
->baseh
;
425 dy
= (dx
* min
+ dy
) / (max
* max
+ 1);
427 geometry
.width
= (int) dx
+ c
->basew
;
428 geometry
.height
= (int) dy
+ c
->baseh
;
432 if(c
->minw
&& geometry
.width
< c
->minw
)
433 geometry
.width
= c
->minw
;
434 if(c
->minh
&& geometry
.height
< c
->minh
)
435 geometry
.height
= c
->minh
;
436 if(c
->maxw
&& geometry
.width
> c
->maxw
)
437 geometry
.width
= c
->maxw
;
438 if(c
->maxh
&& geometry
.height
> c
->maxh
)
439 geometry
.height
= c
->maxh
;
441 geometry
.width
-= (geometry
.width
- c
->basew
) % c
->incw
;
443 geometry
.height
-= (geometry
.height
- c
->baseh
) % c
->inch
;
445 if(geometry
.width
<= 0 || geometry
.height
<= 0)
447 /* offscreen appearance fixes */
448 area
= get_display_area(get_phys_screen(c
->screen
),
450 &globalconf
.screens
[c
->screen
].padding
);
451 if(geometry
.x
> area
.width
)
452 geometry
.x
= area
.width
- geometry
.width
- 2 * c
->border
;
453 if(geometry
.y
> area
.height
)
454 geometry
.y
= area
.height
- geometry
.height
- 2 * c
->border
;
455 if(geometry
.x
+ geometry
.width
+ 2 * c
->border
< 0)
457 if(geometry
.y
+ geometry
.height
+ 2 * c
->border
< 0)
460 if(c
->geometry
.x
!= geometry
.x
|| c
->geometry
.y
!= geometry
.y
461 || c
->geometry
.width
!= geometry
.width
|| c
->geometry
.height
!= geometry
.height
)
463 new_screen
= screen_get_bycoord(globalconf
.screens_info
, c
->screen
, geometry
.x
, geometry
.y
);
465 c
->geometry
.x
= wc
.x
= geometry
.x
;
466 c
->geometry
.y
= wc
.y
= geometry
.y
;
467 c
->geometry
.width
= wc
.width
= geometry
.width
;
468 c
->geometry
.height
= wc
.height
= geometry
.height
;
469 wc
.border_width
= c
->border
;
471 /* save the floating geometry if the window is floating but not
474 layout_get_current(new_screen
)->arrange
== layout_floating
) && !c
->ismax
)
475 c
->f_geometry
= geometry
;
477 XConfigureWindow(globalconf
.display
, c
->win
,
478 CWX
| CWY
| CWWidth
| CWHeight
| CWBorderWidth
, &wc
);
479 window_configure(c
->win
, geometry
, c
->border
);
481 if(c
->screen
!= new_screen
)
482 move_client_to_screen(c
, new_screen
, False
);
490 client_setfloating(Client
*c
, Bool floating
)
492 if(c
->isfloating
!= floating
)
494 if((c
->isfloating
= floating
))
496 client_resize(c
, c
->f_geometry
, False
);
497 XRaiseWindow(globalconf
.display
, c
->win
);
501 XLowerWindow(globalconf
.display
, c
->win
);
505 client_resize(c
, c
->m_geometry
, False
);
508 if(client_isvisible(c
, c
->screen
))
509 globalconf
.screens
[c
->screen
].need_arrange
= True
;
510 widget_invalidate_cache(c
->screen
, WIDGET_CACHE_CLIENTS
);
515 /** Save client properties as an X property
519 client_saveprops(Client
*c
)
521 int i
= 0, ntags
= 0;
525 for(tag
= globalconf
.screens
[c
->screen
].tags
; tag
; tag
= tag
->next
)
528 prop
= p_new(char, ntags
+ 2);
530 for(tag
= globalconf
.screens
[c
->screen
].tags
; tag
; tag
= tag
->next
, i
++)
531 prop
[i
] = is_client_tagged(c
, tag
) ? '1' : '0';
534 prop
[i
] = c
->isfloating
? '1' : '0';
538 XChangeProperty(globalconf
.display
, c
->win
,
539 XInternAtom(globalconf
.display
, "_AWESOME_PROPERTIES", False
),
540 XA_STRING
, 8, PropModeReplace
, (unsigned char *) prop
, i
);
546 client_unban(Client
*c
)
548 XMapWindow(globalconf
.display
, c
->win
);
549 window_setstate(c
->win
, NormalState
);
553 client_unmanage(Client
*c
)
558 wc
.border_width
= c
->oldborder
;
560 /* The server grab construct avoids race conditions. */
561 XGrabServer(globalconf
.display
);
563 XConfigureWindow(globalconf
.display
, c
->win
, CWBorderWidth
, &wc
); /* restore border */
565 /* remove client everywhere */
566 client_list_detach(&globalconf
.clients
, c
);
567 focus_delete_client(c
);
568 if(globalconf
.scratch
.client
== c
)
569 globalconf
.scratch
.client
= NULL
;
570 for(tag
= globalconf
.screens
[c
->screen
].tags
; tag
; tag
= tag
->next
)
571 untag_client(c
, tag
);
573 if(globalconf
.focus
->client
== c
)
574 client_focus(NULL
, c
->screen
, True
);
576 XUngrabButton(globalconf
.display
, AnyButton
, AnyModifier
, c
->win
);
577 window_setstate(c
->win
, WithdrawnState
);
579 XSync(globalconf
.display
, False
);
580 XUngrabServer(globalconf
.display
);
586 client_updatewmhints(Client
*c
)
590 if((wmh
= XGetWMHints(globalconf
.display
, c
->win
)))
592 if((c
->isurgent
= (wmh
->flags
& XUrgencyHint
)))
593 widget_invalidate_cache(c
->screen
, WIDGET_CACHE_CLIENTS
);
594 if((wmh
->flags
& StateHint
) && wmh
->initial_state
== WithdrawnState
)
604 client_updatesizehints(Client
*c
)
609 if(!XGetWMNormalHints(globalconf
.display
, c
->win
, &size
, &msize
))
612 if(size
.flags
& PBaseSize
)
614 c
->basew
= size
.base_width
;
615 c
->baseh
= size
.base_height
;
617 else if(size
.flags
& PMinSize
)
619 c
->basew
= size
.min_width
;
620 c
->baseh
= size
.min_height
;
623 c
->basew
= c
->baseh
= 0;
624 if(size
.flags
& PResizeInc
)
626 c
->incw
= size
.width_inc
;
627 c
->inch
= size
.height_inc
;
630 c
->incw
= c
->inch
= 0;
632 if(size
.flags
& PMaxSize
)
634 c
->maxw
= size
.max_width
;
635 c
->maxh
= size
.max_height
;
638 c
->maxw
= c
->maxh
= 0;
640 if(size
.flags
& PMinSize
)
642 c
->minw
= size
.min_width
;
643 c
->minh
= size
.min_height
;
645 else if(size
.flags
& PBaseSize
)
647 c
->minw
= size
.base_width
;
648 c
->minh
= size
.base_height
;
651 c
->minw
= c
->minh
= 0;
653 if(size
.flags
& PAspect
)
655 c
->minax
= size
.min_aspect
.x
;
656 c
->maxax
= size
.max_aspect
.x
;
657 c
->minay
= size
.min_aspect
.y
;
658 c
->maxay
= size
.max_aspect
.y
;
661 c
->minax
= c
->maxax
= c
->minay
= c
->maxay
= 0;
663 if(c
->maxw
&& c
->minw
&& c
->maxh
&& c
->minh
664 && c
->maxw
== c
->minw
&& c
->maxh
== c
->minh
)
670 /** Returns True if a client is tagged
671 * with one of the tags
672 * \return True or False
675 client_isvisible(Client
*c
, int screen
)
679 if(!c
|| c
->screen
!= screen
)
682 if(globalconf
.scratch
.client
== c
)
683 return globalconf
.scratch
.isvisible
;
685 for(tag
= globalconf
.screens
[screen
].tags
; tag
; tag
= tag
->next
)
686 if(tag
->selected
&& is_client_tagged(c
, tag
))
691 /** Set selected client transparency
692 * \param screen Screen ID
693 * \param arg unused arg
694 * \ingroup ui_callback
697 uicb_client_settrans(int screen
__attribute__ ((unused
)), char *arg
)
699 double delta
= 100.0, current_opacity
= 100.0;
703 unsigned long n
, left
;
704 unsigned int current_opacity_raw
= 0;
706 Client
*sel
= globalconf
.focus
->client
;
711 XGetWindowProperty(globalconf
.display
, sel
->win
,
712 XInternAtom(globalconf
.display
, "_NET_WM_WINDOW_OPACITY", False
),
713 0L, 1L, False
, XA_CARDINAL
, &actual
, &format
, &n
, &left
,
714 (unsigned char **) &data
);
717 memcpy(¤t_opacity_raw
, data
, sizeof(unsigned int));
719 current_opacity
= (current_opacity_raw
* 100.0) / 0xffffffff;
724 delta
= compute_new_value_from_arg(arg
, current_opacity
);
728 else if(delta
> 100.0)
734 if(delta
== 100.0 && !set_prop
)
735 window_settrans(sel
->win
, -1);
737 window_settrans(sel
->win
, delta
);
741 client_find_prev_visible(Client
*sel
)
745 if(!sel
) return NULL
;
747 /* look for previous starting at sel */
748 for(prev
= client_list_prev_cycle(&globalconf
.clients
, sel
);
749 prev
&& (prev
->skip
|| !client_isvisible(prev
, sel
->screen
));
750 prev
= client_list_prev_cycle(&globalconf
.clients
, prev
));
756 client_find_next_visible(Client
*sel
)
760 if(!sel
) return NULL
;
762 for(next
= sel
->next
; next
&& !client_isvisible(next
, sel
->screen
); next
= next
->next
);
764 for(next
= globalconf
.clients
; next
&& !client_isvisible(next
, sel
->screen
); next
= next
->next
);
769 /** Swap current with previous client
770 * \param screen Screen ID
772 * \ingroup ui_callback
775 uicb_client_swapprev(int screen
__attribute__ ((unused
)),
776 char *arg
__attribute__ ((unused
)))
780 if((prev
= client_find_prev_visible(globalconf
.focus
->client
)))
782 client_list_swap(&globalconf
.clients
, prev
, globalconf
.focus
->client
);
783 globalconf
.screens
[prev
->screen
].need_arrange
= True
;
787 /** Swap current with next client
788 * \param screen Screen ID
790 * \ingroup ui_callback
793 uicb_client_swapnext(int screen
__attribute__ ((unused
)),
794 char *arg
__attribute__ ((unused
)))
798 if((next
= client_find_next_visible(globalconf
.focus
->client
)))
800 client_list_swap(&globalconf
.clients
, globalconf
.focus
->client
, next
);
801 globalconf
.screens
[next
->screen
].need_arrange
= True
;
805 /** Move and resize client
806 * \param screen Screen ID
808 * \ingroup ui_callback
811 uicb_client_moveresize(int screen
, char *arg
)
813 int ox
, oy
, ow
, oh
; /* old geometry */
814 char x
[8], y
[8], w
[8], h
[8];
815 int mx
, my
, dx
, dy
, nmx
, nmy
;
819 Client
*sel
= globalconf
.focus
->client
;
820 Layout
*curlay
= layout_get_current(screen
);
822 if(!sel
|| sel
->isfixed
|| !arg
||
823 (curlay
->arrange
!= layout_floating
&& !sel
->isfloating
))
826 if(sscanf(arg
, "%s %s %s %s", x
, y
, w
, h
) != 4)
829 area
.x
= (int) compute_new_value_from_arg(x
, sel
->geometry
.x
);
830 area
.y
= (int) compute_new_value_from_arg(y
, sel
->geometry
.y
);
831 area
.width
= (int) compute_new_value_from_arg(w
, sel
->geometry
.width
);
832 area
.height
= (int) compute_new_value_from_arg(h
, sel
->geometry
.height
);
834 ox
= sel
->geometry
.x
;
835 oy
= sel
->geometry
.y
;
836 ow
= sel
->geometry
.width
;
837 oh
= sel
->geometry
.height
;
839 Bool xqp
= XQueryPointer(globalconf
.display
,
840 RootWindow(globalconf
.display
,
841 get_phys_screen(screen
)),
842 &dummy
, &dummy
, &mx
, &my
, &dx
, &dy
, &dui
);
843 client_resize(sel
, area
, globalconf
.screens
[sel
->screen
].resize_hints
);
844 if (xqp
&& ox
<= mx
&& (ox
+ 2 * sel
->border
+ ow
) >= mx
&&
845 oy
<= my
&& (oy
+ 2 * sel
->border
+ oh
) >= my
)
847 nmx
= mx
- (ox
+ sel
->border
) + sel
->geometry
.width
- ow
;
848 nmy
= my
- (oy
+ sel
->border
) + sel
->geometry
.height
- oh
;
850 if(nmx
< -sel
->border
) /* can happen on a resize */
852 if(nmy
< -sel
->border
)
855 XWarpPointer(globalconf
.display
,
857 0, 0, 0, 0, nmx
, nmy
);
862 client_kill(Client
*c
)
866 if(client_isprotodel(globalconf
.display
, c
->win
))
868 ev
.type
= ClientMessage
;
869 ev
.xclient
.window
= c
->win
;
870 ev
.xclient
.message_type
= XInternAtom(globalconf
.display
, "WM_PROTOCOLS", False
);
871 ev
.xclient
.format
= 32;
872 ev
.xclient
.data
.l
[0] = XInternAtom(globalconf
.display
, "WM_DELETE_WINDOW", False
);
873 ev
.xclient
.data
.l
[1] = CurrentTime
;
874 XSendEvent(globalconf
.display
, c
->win
, False
, NoEventMask
, &ev
);
877 XKillClient(globalconf
.display
, c
->win
);
880 /** Kill selected client
881 * \param screen Screen ID
883 * \ingroup ui_callback
886 uicb_client_kill(int screen
__attribute__ ((unused
)), char *arg
__attribute__ ((unused
)))
888 Client
*sel
= globalconf
.focus
->client
;
895 client_maximize(Client
*c
, Area geometry
)
898 if((c
->ismax
= !c
->ismax
))
900 c
->wasfloating
= c
->isfloating
;
901 c
->m_geometry
= c
->geometry
;
902 if(layout_get_current(c
->screen
)->arrange
!= layout_floating
)
903 client_setfloating(c
, True
);
904 client_focus(c
, c
->screen
, True
);
905 client_resize(c
, geometry
, False
);
906 widget_invalidate_cache(c
->screen
, WIDGET_CACHE_CLIENTS
);
908 else if(c
->wasfloating
)
910 client_setfloating(c
, True
);
911 client_resize(c
, c
->m_geometry
, False
);
912 widget_invalidate_cache(c
->screen
, WIDGET_CACHE_CLIENTS
);
914 else if(layout_get_current(c
->screen
)->arrange
== layout_floating
)
916 client_resize(c
, c
->m_geometry
, False
);
917 widget_invalidate_cache(c
->screen
, WIDGET_CACHE_CLIENTS
);
921 client_setfloating(c
, False
);
922 widget_invalidate_cache(c
->screen
, WIDGET_CACHE_CLIENTS
);
926 /** Toggle maximize for client
927 * \param screen Screen ID
929 * \ingroup ui_callback
932 uicb_client_togglemax(int screen
, char *arg
__attribute__ ((unused
)))
934 Client
*sel
= globalconf
.focus
->client
;
935 Area area
= screen_get_area(screen
,
936 globalconf
.screens
[screen
].statusbar
,
937 &globalconf
.screens
[screen
].padding
);
941 area
.width
-= 2 * sel
->border
;
942 area
.height
-= 2 * sel
->border
;
943 client_maximize(sel
, area
);
947 /** Toggle vertical maximize for client
948 * \param screen Screen ID
950 * \ingroup ui_callback
953 uicb_client_toggleverticalmax(int screen
, char *arg
__attribute__ ((unused
)))
955 Client
*sel
= globalconf
.focus
->client
;
956 Area area
= screen_get_area(screen
,
957 globalconf
.screens
[screen
].statusbar
,
958 &globalconf
.screens
[screen
].padding
);
962 area
.x
= sel
->geometry
.x
;
963 area
.width
= sel
->geometry
.width
;
964 area
.height
-= 2 * sel
->border
;
965 client_maximize(sel
, area
);
970 /** Toggle horizontal maximize for client
971 * \param screen Screen ID
973 * \ingroup ui_callback
976 uicb_client_togglehorizontalmax(int screen
, char *arg
__attribute__ ((unused
)))
978 Client
*sel
= globalconf
.focus
->client
;
979 Area area
= screen_get_area(screen
,
980 globalconf
.screens
[screen
].statusbar
,
981 &globalconf
.screens
[screen
].padding
);
985 area
.y
= sel
->geometry
.y
;
986 area
.height
= sel
->geometry
.height
;
987 area
.width
-= 2 * sel
->border
;
988 client_maximize(sel
, area
);
993 * \param screen Screen ID
995 * \ingroup ui_callback
998 uicb_client_zoom(int screen
, char *arg
__attribute__ ((unused
)))
1000 Client
*c
, *sel
= globalconf
.focus
->client
;
1005 for(c
= globalconf
.clients
; !client_isvisible(c
, screen
); c
= c
->next
);
1007 for(sel
= sel
->next
; sel
&& !client_isvisible(sel
, screen
); sel
= sel
->next
);
1011 client_list_detach(&globalconf
.clients
, sel
);
1012 client_list_push(&globalconf
.clients
, sel
);
1013 globalconf
.screens
[screen
].need_arrange
= True
;
1017 /** Send focus to next client in stack
1018 * \param screen Screen ID
1020 * \ingroup ui_callback
1023 uicb_client_focusnext(int screen
, char *arg
__attribute__ ((unused
)))
1025 Client
*c
, *sel
= globalconf
.focus
->client
;
1029 for(c
= sel
->next
; c
&& (c
->skip
|| !client_isvisible(c
, screen
)); c
= c
->next
);
1031 for(c
= globalconf
.clients
; c
&& (c
->skip
|| !client_isvisible(c
, screen
)); c
= c
->next
);
1033 client_focus(c
, screen
, True
);
1036 /** Send focus to previous client in stack
1037 * \param screen Screen ID
1039 * \ingroup ui_callback
1042 uicb_client_focusprev(int screen
, char *arg
__attribute__ ((unused
)))
1046 if((prev
= client_find_prev_visible(globalconf
.focus
->client
)))
1047 client_focus(prev
, screen
, True
);
1050 /** Toggle floating state of a client
1051 * \param screen Screen ID
1053 * \ingroup ui_callback
1056 uicb_client_togglefloating(int screen
__attribute__ ((unused
)),
1057 char *arg
__attribute__ ((unused
)))
1059 if(globalconf
.focus
->client
)
1060 client_setfloating(globalconf
.focus
->client
, !globalconf
.focus
->client
->isfloating
);
1063 /** Toggle scratch client attribute
1064 * \param screen screen number
1065 * \param arg unused argument
1066 * \ingroup ui_callback
1069 uicb_client_setscratch(int screen
,
1070 char *arg
__attribute__ ((unused
)))
1072 if(!globalconf
.focus
->client
)
1075 if(globalconf
.scratch
.client
== globalconf
.focus
->client
)
1076 globalconf
.scratch
.client
= NULL
;
1078 globalconf
.scratch
.client
= globalconf
.focus
->client
;
1080 widget_invalidate_cache(screen
, WIDGET_CACHE_CLIENTS
| WIDGET_CACHE_TAGS
);
1081 globalconf
.screens
[screen
].need_arrange
= True
;
1084 /** Toggle scratch client visibility
1085 * \param screen screen number
1086 * \param arg unused argument
1087 * \ingroup ui_callback
1090 uicb_client_togglescratch(int screen
,
1091 char *arg
__attribute__ ((unused
)))
1093 if(globalconf
.scratch
.client
)
1095 globalconf
.scratch
.isvisible
= !globalconf
.scratch
.isvisible
;
1096 if(globalconf
.scratch
.isvisible
)
1097 client_focus(globalconf
.scratch
.client
, screen
, True
);
1098 globalconf
.screens
[globalconf
.scratch
.client
->screen
].need_arrange
= True
;
1099 widget_invalidate_cache(globalconf
.scratch
.client
->screen
, WIDGET_CACHE_CLIENTS
);
1102 // vim: filetype=c:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=80