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>
25 #include <X11/extensions/Xinerama.h>
36 #include "layouts/floating.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(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(c
->win
, XInternAtom(globalconf
.display
, "_NET_WM_NAME", False
), c
->name
, sizeof(c
->name
)))
142 xgettextprop(c
->win
, XInternAtom(globalconf
.display
, "WM_NAME", False
), c
->name
, sizeof(c
->name
));
144 widget_invalidate_cache(c
->screen
, WIDGET_CACHE_CLIENTS
);
148 client_unfocus(Client
*c
)
150 if(globalconf
.screens
[c
->screen
].opacity_unfocused
!= -1)
151 window_settrans(c
->win
, globalconf
.screens
[c
->screen
].opacity_unfocused
);
152 XSetWindowBorder(globalconf
.display
, c
->win
,
153 globalconf
.screens
[c
->screen
].colors_normal
[ColBorder
].pixel
);
154 widget_invalidate_cache(c
->screen
, WIDGET_CACHE_CLIENTS
);
155 focus_add_client(NULL
);
158 /** Ban client and unmap it
159 * \param c the client
162 client_ban(Client
*c
)
164 if(globalconf
.focus
->client
== c
)
166 XUnmapWindow(globalconf
.display
, c
->win
);
167 window_setstate(c
->win
, IconicState
);
170 /** Give focus to client, or to first client if c is NULL
172 * \param screen Screen ID
175 client_focus(Client
*c
, int screen
, Bool raise
)
177 int phys_screen
= get_phys_screen(screen
);
179 /* if c is NULL or invisible, take next client in the focus history */
180 if(!c
|| (c
&& !client_isvisible(c
, screen
)))
182 c
= focus_get_current_client(screen
);
183 /* if c is still NULL take next client in the stack */
185 for(c
= globalconf
.clients
; c
&& (c
->skip
|| !client_isvisible(c
, screen
)); c
= c
->next
);
188 /* unfocus current selected client */
189 if(globalconf
.focus
->client
)
190 client_unfocus(globalconf
.focus
->client
);
194 /* unban the client before focusing or it will fail */
196 /* save sel in focus history */
198 if(globalconf
.screens
[c
->screen
].opacity_unfocused
!= -1)
199 window_settrans(c
->win
, -1);
200 XSetWindowBorder(globalconf
.display
, c
->win
,
201 globalconf
.screens
[screen
].colors_selected
[ColBorder
].pixel
);
202 XSetInputFocus(globalconf
.display
, c
->win
, RevertToPointerRoot
, CurrentTime
);
206 Layout
*curlay
= layout_get_current(screen
);
207 if(c
->isfloating
|| curlay
->arrange
== layout_floating
)
208 XRaiseWindow(globalconf
.display
, c
->win
);
212 wc
.stack_mode
= Below
;
214 for(client
= globalconf
.clients
; client
; client
= client
->next
)
215 if(client
!= c
&& client_isvisible(client
, c
->screen
) && client
->isfloating
)
217 XConfigureWindow(globalconf
.display
, client
->win
, CWSibling
| CWStackMode
, &wc
);
218 wc
.sibling
= client
->win
;
220 XConfigureWindow(globalconf
.display
, c
->win
, CWSibling
| CWStackMode
, &wc
);
222 for(client
= globalconf
.clients
; client
; client
= client
->next
)
223 if(client
!= c
&& IS_TILED(client
, c
->screen
))
225 XConfigureWindow(globalconf
.display
, client
->win
, CWSibling
| CWStackMode
, &wc
);
226 wc
.sibling
= client
->win
;
230 /* since we're dropping EnterWindow events and sometimes the window
231 * will appear under the mouse, grabbuttons */
232 window_grabbuttons(phys_screen
, c
->win
);
235 XSetInputFocus(globalconf
.display
,
236 RootWindow(globalconf
.display
, phys_screen
),
237 RevertToPointerRoot
, CurrentTime
);
239 widget_invalidate_cache(screen
, WIDGET_CACHE_CLIENTS
);
240 ewmh_update_net_active_window(phys_screen
);
243 /** Manage a new client
244 * \param w The window
245 * \param wa Window attributes
246 * \param screen Screen ID
249 client_manage(Window w
, XWindowAttributes
*wa
, int screen
)
251 Client
*c
, *t
= NULL
;
253 Bool rettrans
, retloadprops
;
258 int phys_screen
= get_phys_screen(screen
);
261 c
= p_new(Client
, 1);
263 c
->screen
= screen_get_bycoord(screen
, wa
->x
, wa
->y
);
265 screen_geom
= screen_get_area(c
->screen
,
266 globalconf
.screens
[screen
].statusbar
,
267 &globalconf
.screens
[screen
].padding
);
270 c
->geometry
.x
= c
->f_geometry
.x
= c
->m_geometry
.x
= MAX(wa
->x
, screen_geom
.x
);
271 c
->geometry
.y
= c
->f_geometry
.y
= c
->m_geometry
.y
= MAX(wa
->y
, screen_geom
.y
);
272 c
->geometry
.width
= c
->f_geometry
.width
= c
->m_geometry
.width
= wa
->width
;
273 c
->geometry
.height
= c
->f_geometry
.height
= c
->m_geometry
.height
= wa
->height
;
274 c
->oldborder
= wa
->border_width
;
277 c
->border
= globalconf
.screens
[screen
].borderpx
;
279 /* Set windows borders */
280 wc
.border_width
= c
->border
;
281 XConfigureWindow(globalconf
.display
, w
, CWBorderWidth
, &wc
);
282 XSetWindowBorder(globalconf
.display
, w
, globalconf
.screens
[screen
].colors_normal
[ColBorder
].pixel
);
283 /* propagates border_width, if size doesn't change */
284 window_configure(c
->win
, c
->geometry
, c
->border
);
286 /* update window title */
287 client_updatetitle(c
);
290 flags
= client_updatesizehints(c
);
291 client_updatewmhints(c
);
293 /* Try to load props if any */
294 retloadprops
= client_loadprops(c
, screen
);
296 /* Then check clients hints */
297 ewmh_check_client_hints(c
);
299 /* Then apply rules if no props */
302 /* Get the client's rule */
303 if((rule
= rule_matching_client(c
)))
305 if(rule
->screen
!= RULE_NOSCREEN
)
306 move_client_to_screen(c
, rule
->screen
, True
);
308 move_client_to_screen(c
, screen
, True
);
309 tag_client_with_rule(c
, rule
);
311 switch(rule
->isfloating
)
316 client_setfloating(c
, True
);
319 client_setfloating(c
, False
);
323 if(rule
->opacity
>= 0.0f
)
324 window_settrans(c
->win
, rule
->opacity
);
327 move_client_to_screen(c
, screen
, True
);
330 /* check for transient and set tags like its parent,
331 * XGetTransientForHint returns 1 on success
333 if((rettrans
= XGetTransientForHint(globalconf
.display
, w
, &trans
))
334 && (t
= client_get_bywin(globalconf
.clients
, trans
)))
335 for(tag
= globalconf
.screens
[c
->screen
].tags
; tag
; tag
= tag
->next
)
336 if(is_client_tagged(t
, tag
))
339 /* should be floating if transsient or fixed */
341 client_setfloating(c
, rettrans
|| c
->isfixed
);
343 if(!(flags
& (USPosition
| PPosition
)))
345 globalconf
.screens
[c
->screen
].floating_placement(c
->f_geometry
, c
->border
, c
->screen
);
347 XSelectInput(globalconf
.display
, w
, StructureNotifyMask
| PropertyChangeMask
| EnterWindowMask
);
350 if(globalconf
.have_shape
)
352 XShapeSelectInput(globalconf
.display
, w
, ShapeNotifyMask
);
353 window_setshape(phys_screen
, c
->win
);
356 /* attach to the stack */
357 if((rule
= rule_matching_client(c
)))
358 switch(rule
->ismaster
)
361 client_list_push(&globalconf
.clients
, c
);
364 client_list_append(&globalconf
.clients
, c
);
373 if(globalconf
.screens
[c
->screen
].new_become_master
)
374 client_list_push(&globalconf
.clients
, c
);
376 client_list_append(&globalconf
.clients
, c
);
379 /* some windows require this */
380 XMoveResizeWindow(globalconf
.display
, c
->win
, c
->geometry
.x
, c
->geometry
.y
,
381 c
->geometry
.width
, c
->geometry
.height
);
383 widget_invalidate_cache(c
->screen
, WIDGET_CACHE_CLIENTS
);
384 ewmh_update_net_client_list(phys_screen
);
387 /** Resize client window
388 * \param c client to resize
389 * \param geometry new window geometry
390 * \param sizehints respect size hints
391 * \param return True if resize has been done
394 client_resize(Client
*c
, Area geometry
, Bool sizehints
)
397 double dx
, dy
, max
, min
, ratio
;
403 if(c
->minay
> 0 && c
->maxay
> 0 && (geometry
.height
- c
->baseh
) > 0
404 && (geometry
.width
- c
->basew
) > 0)
406 dx
= (double) (geometry
.width
- c
->basew
);
407 dy
= (double) (geometry
.height
- c
->baseh
);
408 min
= (double) (c
->minax
) / (double) (c
->minay
);
409 max
= (double) (c
->maxax
) / (double) (c
->maxay
);
411 if(max
> 0 && min
> 0 && ratio
> 0)
415 dy
= (dx
* min
+ dy
) / (min
* min
+ 1);
417 geometry
.width
= (int) dx
+ c
->basew
;
418 geometry
.height
= (int) dy
+ c
->baseh
;
422 dy
= (dx
* min
+ dy
) / (max
* max
+ 1);
424 geometry
.width
= (int) dx
+ c
->basew
;
425 geometry
.height
= (int) dy
+ c
->baseh
;
429 if(c
->minw
&& geometry
.width
< c
->minw
)
430 geometry
.width
= c
->minw
;
431 if(c
->minh
&& geometry
.height
< c
->minh
)
432 geometry
.height
= c
->minh
;
433 if(c
->maxw
&& geometry
.width
> c
->maxw
)
434 geometry
.width
= c
->maxw
;
435 if(c
->maxh
&& geometry
.height
> c
->maxh
)
436 geometry
.height
= c
->maxh
;
438 geometry
.width
-= (geometry
.width
- c
->basew
) % c
->incw
;
440 geometry
.height
-= (geometry
.height
- c
->baseh
) % c
->inch
;
442 if(geometry
.width
<= 0 || geometry
.height
<= 0)
444 /* offscreen appearance fixes */
445 area
= get_display_area(get_phys_screen(c
->screen
),
447 &globalconf
.screens
[c
->screen
].padding
);
448 if(geometry
.x
> area
.width
)
449 geometry
.x
= area
.width
- geometry
.width
- 2 * c
->border
;
450 if(geometry
.y
> area
.height
)
451 geometry
.y
= area
.height
- geometry
.height
- 2 * c
->border
;
452 if(geometry
.x
+ geometry
.width
+ 2 * c
->border
< 0)
454 if(geometry
.y
+ geometry
.height
+ 2 * c
->border
< 0)
457 if(c
->geometry
.x
!= geometry
.x
|| c
->geometry
.y
!= geometry
.y
458 || c
->geometry
.width
!= geometry
.width
|| c
->geometry
.height
!= geometry
.height
)
460 new_screen
= screen_get_bycoord(c
->screen
, geometry
.x
, geometry
.y
);
462 c
->geometry
.x
= wc
.x
= geometry
.x
;
463 c
->geometry
.y
= wc
.y
= geometry
.y
;
464 c
->geometry
.width
= wc
.width
= geometry
.width
;
465 c
->geometry
.height
= wc
.height
= geometry
.height
;
466 wc
.border_width
= c
->border
;
468 /* save the floating geometry if the window is floating but not
471 layout_get_current(new_screen
)->arrange
== layout_floating
) && !c
->ismax
)
472 c
->f_geometry
= geometry
;
474 XConfigureWindow(globalconf
.display
, c
->win
,
475 CWX
| CWY
| CWWidth
| CWHeight
| CWBorderWidth
, &wc
);
476 window_configure(c
->win
, geometry
, c
->border
);
478 if(c
->screen
!= new_screen
)
479 move_client_to_screen(c
, new_screen
, False
);
487 client_setfloating(Client
*c
, Bool floating
)
489 if(c
->isfloating
!= floating
)
491 if((c
->isfloating
= floating
))
493 client_resize(c
, c
->f_geometry
, False
);
494 XRaiseWindow(globalconf
.display
, c
->win
);
498 XLowerWindow(globalconf
.display
, c
->win
);
502 client_resize(c
, c
->m_geometry
, False
);
505 if(client_isvisible(c
, c
->screen
))
506 globalconf
.screens
[c
->screen
].need_arrange
= True
;
507 widget_invalidate_cache(c
->screen
, WIDGET_CACHE_CLIENTS
);
512 /** Save client properties as an X property
516 client_saveprops(Client
*c
)
518 int i
= 0, ntags
= 0;
522 for(tag
= globalconf
.screens
[c
->screen
].tags
; tag
; tag
= tag
->next
)
525 prop
= p_new(char, ntags
+ 2);
527 for(tag
= globalconf
.screens
[c
->screen
].tags
; tag
; tag
= tag
->next
, i
++)
528 prop
[i
] = is_client_tagged(c
, tag
) ? '1' : '0';
531 prop
[i
] = c
->isfloating
? '1' : '0';
535 XChangeProperty(globalconf
.display
, c
->win
,
536 XInternAtom(globalconf
.display
, "_AWESOME_PROPERTIES", False
),
537 XA_STRING
, 8, PropModeReplace
, (unsigned char *) prop
, i
);
543 client_unban(Client
*c
)
545 XMapWindow(globalconf
.display
, c
->win
);
546 window_setstate(c
->win
, NormalState
);
550 client_unmanage(Client
*c
)
555 wc
.border_width
= c
->oldborder
;
557 /* The server grab construct avoids race conditions. */
558 XGrabServer(globalconf
.display
);
560 XConfigureWindow(globalconf
.display
, c
->win
, CWBorderWidth
, &wc
); /* restore border */
562 /* remove client everywhere */
563 client_list_detach(&globalconf
.clients
, c
);
564 focus_delete_client(c
);
565 if(globalconf
.scratch
.client
== c
)
566 globalconf
.scratch
.client
= NULL
;
567 for(tag
= globalconf
.screens
[c
->screen
].tags
; tag
; tag
= tag
->next
)
568 untag_client(c
, tag
);
570 if(globalconf
.focus
->client
== c
)
571 client_focus(NULL
, c
->screen
, True
);
573 XUngrabButton(globalconf
.display
, AnyButton
, AnyModifier
, c
->win
);
574 window_setstate(c
->win
, WithdrawnState
);
576 XSync(globalconf
.display
, False
);
577 XUngrabServer(globalconf
.display
);
583 client_updatewmhints(Client
*c
)
587 if((wmh
= XGetWMHints(globalconf
.display
, c
->win
)))
589 if((c
->isurgent
= (wmh
->flags
& XUrgencyHint
)))
590 widget_invalidate_cache(c
->screen
, WIDGET_CACHE_CLIENTS
);
591 if((wmh
->flags
& StateHint
) && wmh
->initial_state
== WithdrawnState
)
601 client_updatesizehints(Client
*c
)
606 if(!XGetWMNormalHints(globalconf
.display
, c
->win
, &size
, &msize
))
609 if(size
.flags
& PBaseSize
)
611 c
->basew
= size
.base_width
;
612 c
->baseh
= size
.base_height
;
614 else if(size
.flags
& PMinSize
)
616 c
->basew
= size
.min_width
;
617 c
->baseh
= size
.min_height
;
620 c
->basew
= c
->baseh
= 0;
621 if(size
.flags
& PResizeInc
)
623 c
->incw
= size
.width_inc
;
624 c
->inch
= size
.height_inc
;
627 c
->incw
= c
->inch
= 0;
629 if(size
.flags
& PMaxSize
)
631 c
->maxw
= size
.max_width
;
632 c
->maxh
= size
.max_height
;
635 c
->maxw
= c
->maxh
= 0;
637 if(size
.flags
& PMinSize
)
639 c
->minw
= size
.min_width
;
640 c
->minh
= size
.min_height
;
642 else if(size
.flags
& PBaseSize
)
644 c
->minw
= size
.base_width
;
645 c
->minh
= size
.base_height
;
648 c
->minw
= c
->minh
= 0;
650 if(size
.flags
& PAspect
)
652 c
->minax
= size
.min_aspect
.x
;
653 c
->maxax
= size
.max_aspect
.x
;
654 c
->minay
= size
.min_aspect
.y
;
655 c
->maxay
= size
.max_aspect
.y
;
658 c
->minax
= c
->maxax
= c
->minay
= c
->maxay
= 0;
660 if(c
->maxw
&& c
->minw
&& c
->maxh
&& c
->minh
661 && c
->maxw
== c
->minw
&& c
->maxh
== c
->minh
)
667 /** Returns True if a client is tagged
668 * with one of the tags
669 * \return True or False
672 client_isvisible(Client
*c
, int screen
)
676 if(!c
|| c
->screen
!= screen
)
679 if(globalconf
.scratch
.client
== c
)
680 return globalconf
.scratch
.isvisible
;
682 for(tag
= globalconf
.screens
[screen
].tags
; tag
; tag
= tag
->next
)
683 if(tag
->selected
&& is_client_tagged(c
, tag
))
688 /** Set selected client transparency
689 * \param screen Screen ID
690 * \param arg unused arg
691 * \ingroup ui_callback
694 uicb_client_settrans(int screen
__attribute__ ((unused
)), char *arg
)
696 double delta
= 100.0, current_opacity
= 100.0;
700 unsigned long n
, left
;
701 unsigned int current_opacity_raw
= 0;
703 Client
*sel
= globalconf
.focus
->client
;
708 XGetWindowProperty(globalconf
.display
, sel
->win
,
709 XInternAtom(globalconf
.display
, "_NET_WM_WINDOW_OPACITY", False
),
710 0L, 1L, False
, XA_CARDINAL
, &actual
, &format
, &n
, &left
,
711 (unsigned char **) &data
);
714 memcpy(¤t_opacity_raw
, data
, sizeof(unsigned int));
716 current_opacity
= (current_opacity_raw
* 100.0) / 0xffffffff;
721 delta
= compute_new_value_from_arg(arg
, current_opacity
);
725 else if(delta
> 100.0)
731 if(delta
== 100.0 && !set_prop
)
732 window_settrans(sel
->win
, -1);
734 window_settrans(sel
->win
, delta
);
738 client_find_prev_visible(Client
*sel
)
742 if(!sel
) return NULL
;
744 /* look for previous starting at sel */
745 for(prev
= client_list_prev_cycle(&globalconf
.clients
, sel
);
746 prev
&& (prev
->skip
|| !client_isvisible(prev
, sel
->screen
));
747 prev
= client_list_prev_cycle(&globalconf
.clients
, prev
));
753 client_find_next_visible(Client
*sel
)
757 if(!sel
) return NULL
;
759 for(next
= sel
->next
; next
&& !client_isvisible(next
, sel
->screen
); next
= next
->next
);
761 for(next
= globalconf
.clients
; next
&& !client_isvisible(next
, sel
->screen
); next
= next
->next
);
766 /** Swap current with previous client
767 * \param screen Screen ID
769 * \ingroup ui_callback
772 uicb_client_swapprev(int screen
__attribute__ ((unused
)),
773 char *arg
__attribute__ ((unused
)))
777 if((prev
= client_find_prev_visible(globalconf
.focus
->client
)))
779 client_list_swap(&globalconf
.clients
, prev
, globalconf
.focus
->client
);
780 globalconf
.screens
[prev
->screen
].need_arrange
= True
;
784 /** Swap current with next client
785 * \param screen Screen ID
787 * \ingroup ui_callback
790 uicb_client_swapnext(int screen
__attribute__ ((unused
)),
791 char *arg
__attribute__ ((unused
)))
795 if((next
= client_find_next_visible(globalconf
.focus
->client
)))
797 client_list_swap(&globalconf
.clients
, globalconf
.focus
->client
, next
);
798 globalconf
.screens
[next
->screen
].need_arrange
= True
;
802 /** Move and resize client
803 * \param screen Screen ID
805 * \ingroup ui_callback
808 uicb_client_moveresize(int screen
, char *arg
)
810 int ox
, oy
, ow
, oh
; /* old geometry */
811 char x
[8], y
[8], w
[8], h
[8];
812 int mx
, my
, dx
, dy
, nmx
, nmy
;
816 Client
*sel
= globalconf
.focus
->client
;
817 Layout
*curlay
= layout_get_current(screen
);
819 if(!sel
|| sel
->isfixed
|| !arg
||
820 (curlay
->arrange
!= layout_floating
&& !sel
->isfloating
))
823 if(sscanf(arg
, "%s %s %s %s", x
, y
, w
, h
) != 4)
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
+ 2 * sel
->border
+ ow
) >= mx
&&
842 oy
<= my
&& (oy
+ 2 * sel
->border
+ oh
) >= my
)
844 nmx
= mx
- (ox
+ sel
->border
) + sel
->geometry
.width
- ow
;
845 nmy
= my
- (oy
+ sel
->border
) + sel
->geometry
.height
- oh
;
847 if(nmx
< -sel
->border
) /* can happen on a resize */
849 if(nmy
< -sel
->border
)
852 XWarpPointer(globalconf
.display
,
854 0, 0, 0, 0, nmx
, nmy
);
859 client_kill(Client
*c
)
863 if(client_isprotodel(globalconf
.display
, c
->win
))
865 ev
.type
= ClientMessage
;
866 ev
.xclient
.window
= c
->win
;
867 ev
.xclient
.message_type
= XInternAtom(globalconf
.display
, "WM_PROTOCOLS", False
);
868 ev
.xclient
.format
= 32;
869 ev
.xclient
.data
.l
[0] = XInternAtom(globalconf
.display
, "WM_DELETE_WINDOW", False
);
870 ev
.xclient
.data
.l
[1] = CurrentTime
;
871 XSendEvent(globalconf
.display
, c
->win
, False
, NoEventMask
, &ev
);
874 XKillClient(globalconf
.display
, c
->win
);
877 /** Kill selected client
878 * \param screen Screen ID
880 * \ingroup ui_callback
883 uicb_client_kill(int screen
__attribute__ ((unused
)), char *arg
__attribute__ ((unused
)))
885 Client
*sel
= globalconf
.focus
->client
;
892 client_maximize(Client
*c
, Area geometry
)
895 if((c
->ismax
= !c
->ismax
))
897 c
->wasfloating
= c
->isfloating
;
898 c
->m_geometry
= c
->geometry
;
899 if(layout_get_current(c
->screen
)->arrange
!= layout_floating
)
900 client_setfloating(c
, True
);
901 client_focus(c
, c
->screen
, True
);
902 client_resize(c
, geometry
, False
);
903 widget_invalidate_cache(c
->screen
, WIDGET_CACHE_CLIENTS
);
905 else if(c
->wasfloating
)
907 client_setfloating(c
, True
);
908 client_resize(c
, c
->m_geometry
, False
);
909 widget_invalidate_cache(c
->screen
, WIDGET_CACHE_CLIENTS
);
911 else if(layout_get_current(c
->screen
)->arrange
== layout_floating
)
913 client_resize(c
, c
->m_geometry
, False
);
914 widget_invalidate_cache(c
->screen
, WIDGET_CACHE_CLIENTS
);
918 client_setfloating(c
, False
);
919 widget_invalidate_cache(c
->screen
, WIDGET_CACHE_CLIENTS
);
923 /** Toggle maximize for client
924 * \param screen Screen ID
926 * \ingroup ui_callback
929 uicb_client_togglemax(int screen
, char *arg
__attribute__ ((unused
)))
931 Client
*sel
= globalconf
.focus
->client
;
932 Area area
= screen_get_area(screen
,
933 globalconf
.screens
[screen
].statusbar
,
934 &globalconf
.screens
[screen
].padding
);
938 area
.width
-= 2 * sel
->border
;
939 area
.height
-= 2 * sel
->border
;
940 client_maximize(sel
, area
);
944 /** Toggle vertical maximize for client
945 * \param screen Screen ID
947 * \ingroup ui_callback
950 uicb_client_toggleverticalmax(int screen
, char *arg
__attribute__ ((unused
)))
952 Client
*sel
= globalconf
.focus
->client
;
953 Area area
= screen_get_area(screen
,
954 globalconf
.screens
[screen
].statusbar
,
955 &globalconf
.screens
[screen
].padding
);
959 area
.x
= sel
->geometry
.x
;
960 area
.width
= sel
->geometry
.width
;
961 area
.height
-= 2 * sel
->border
;
962 client_maximize(sel
, area
);
967 /** Toggle horizontal maximize for client
968 * \param screen Screen ID
970 * \ingroup ui_callback
973 uicb_client_togglehorizontalmax(int screen
, char *arg
__attribute__ ((unused
)))
975 Client
*sel
= globalconf
.focus
->client
;
976 Area area
= screen_get_area(screen
,
977 globalconf
.screens
[screen
].statusbar
,
978 &globalconf
.screens
[screen
].padding
);
982 area
.y
= sel
->geometry
.y
;
983 area
.height
= sel
->geometry
.height
;
984 area
.width
-= 2 * sel
->border
;
985 client_maximize(sel
, area
);
990 * \param screen Screen ID
992 * \ingroup ui_callback
995 uicb_client_zoom(int screen
, char *arg
__attribute__ ((unused
)))
997 Client
*c
, *sel
= globalconf
.focus
->client
;
1002 for(c
= globalconf
.clients
; !client_isvisible(c
, screen
); c
= c
->next
);
1004 for(sel
= sel
->next
; sel
&& !client_isvisible(sel
, screen
); sel
= sel
->next
);
1008 client_list_detach(&globalconf
.clients
, sel
);
1009 client_list_push(&globalconf
.clients
, sel
);
1010 globalconf
.screens
[screen
].need_arrange
= True
;
1014 /** Send focus to next client in stack
1015 * \param screen Screen ID
1017 * \ingroup ui_callback
1020 uicb_client_focusnext(int screen
, char *arg
__attribute__ ((unused
)))
1022 Client
*c
, *sel
= globalconf
.focus
->client
;
1026 for(c
= sel
->next
; c
&& (c
->skip
|| !client_isvisible(c
, screen
)); c
= c
->next
);
1028 for(c
= globalconf
.clients
; c
&& (c
->skip
|| !client_isvisible(c
, screen
)); c
= c
->next
);
1030 client_focus(c
, screen
, True
);
1033 /** Send focus to previous client in stack
1034 * \param screen Screen ID
1036 * \ingroup ui_callback
1039 uicb_client_focusprev(int screen
, char *arg
__attribute__ ((unused
)))
1043 if((prev
= client_find_prev_visible(globalconf
.focus
->client
)))
1044 client_focus(prev
, screen
, True
);
1047 /** Toggle floating state of a client
1048 * \param screen Screen ID
1050 * \ingroup ui_callback
1053 uicb_client_togglefloating(int screen
__attribute__ ((unused
)),
1054 char *arg
__attribute__ ((unused
)))
1056 if(globalconf
.focus
->client
)
1057 client_setfloating(globalconf
.focus
->client
, !globalconf
.focus
->client
->isfloating
);
1060 /** Toggle scratch client attribute
1061 * \param screen screen number
1062 * \param arg unused argument
1063 * \ingroup ui_callback
1066 uicb_client_setscratch(int screen
,
1067 char *arg
__attribute__ ((unused
)))
1069 if(!globalconf
.focus
->client
)
1072 if(globalconf
.scratch
.client
== globalconf
.focus
->client
)
1073 globalconf
.scratch
.client
= NULL
;
1075 globalconf
.scratch
.client
= globalconf
.focus
->client
;
1077 widget_invalidate_cache(screen
, WIDGET_CACHE_CLIENTS
| WIDGET_CACHE_TAGS
);
1078 globalconf
.screens
[screen
].need_arrange
= True
;
1081 /** Toggle scratch client visibility
1082 * \param screen screen number
1083 * \param arg unused argument
1084 * \ingroup ui_callback
1087 uicb_client_togglescratch(int screen
,
1088 char *arg
__attribute__ ((unused
)))
1090 if(globalconf
.scratch
.client
)
1092 globalconf
.scratch
.isvisible
= !globalconf
.scratch
.isvisible
;
1093 if(globalconf
.scratch
.isvisible
)
1094 client_focus(globalconf
.scratch
.client
, screen
, True
);
1095 globalconf
.screens
[globalconf
.scratch
.client
->screen
].need_arrange
= True
;
1096 widget_invalidate_cache(globalconf
.scratch
.client
->screen
, WIDGET_CACHE_CLIENTS
);
1099 // vim: filetype=c:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=80