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>
35 #include "layouts/floating.h"
36 #include "common/xutil.h"
37 #include "common/xscreen.h"
39 extern AwesomeConf globalconf
;
41 /** Load windows properties, restoring client's tag
42 * and floating state before awesome was restarted if any
43 * \todo this may bug if number of tags is != than before
45 * \param screen Screen ID
46 * \return true if client had property
49 client_loadprops(Client
* c
, int screen
)
56 for(tag
= globalconf
.screens
[screen
].tags
; tag
; tag
= tag
->next
)
59 prop
= p_new(char, ntags
+ 2);
61 if(xgettextprop(globalconf
.display
, c
->win
,
62 XInternAtom(globalconf
.display
, "_AWESOME_PROPERTIES", False
),
65 for(i
= 0, tag
= globalconf
.screens
[screen
].tags
; tag
&& i
< ntags
&& prop
[i
]; i
++, tag
= tag
->next
)
74 if(i
<= ntags
&& prop
[i
])
75 client_setfloating(c
, prop
[i
] == '1');
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
89 client_isprotodel(Display
*disp
, Window win
)
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
))
105 /** Get a Client by its window
106 * \param list Client list to look info
107 * \param w Client window to find
111 client_get_bywin(Client
*list
, Window w
)
115 for(c
= list
; c
&& c
->win
!= w
; c
= c
->next
);
119 /** Get a client by its name
120 * \param list Client list
121 * \param name name to search
122 * \return first matching client
125 client_get_byname(Client
*list
, char *name
)
129 for(c
= list
; c
; c
= c
->next
)
130 if(strstr(c
->name
, name
))
136 /** Update client name attribute with its title
137 * \param c the client
140 client_updatetitle(Client
*c
)
142 if(!xgettextprop(globalconf
.display
, c
->win
,
143 XInternAtom(globalconf
.display
, "_NET_WM_NAME", False
), c
->name
, sizeof(c
->name
)))
144 xgettextprop(globalconf
.display
, c
->win
,
145 XInternAtom(globalconf
.display
, "WM_NAME", False
), c
->name
, sizeof(c
->name
));
149 widget_invalidate_cache(c
->screen
, WIDGET_CACHE_CLIENTS
);
153 client_unfocus(Client
*c
)
155 if(globalconf
.screens
[c
->screen
].opacity_unfocused
!= -1)
156 window_settrans(c
->win
, globalconf
.screens
[c
->screen
].opacity_unfocused
);
157 focus_add_client(NULL
);
158 XSetWindowBorder(globalconf
.display
, c
->win
,
159 globalconf
.screens
[c
->screen
].styles
.normal
.border
.pixel
);
160 widget_invalidate_cache(c
->screen
, WIDGET_CACHE_CLIENTS
);
164 /** Ban client and unmap it
165 * \param c the client
168 client_ban(Client
*c
)
170 if(globalconf
.focus
->client
== c
)
172 XUnmapWindow(globalconf
.display
, c
->win
);
173 window_setstate(c
->win
, IconicState
);
174 if(c
->titlebar
.position
&& c
->titlebar
.sw
)
175 XUnmapWindow(globalconf
.display
, c
->titlebar
.sw
->window
);
178 /** Give focus to client, or to first client if c is NULL
180 * \param screen Screen ID
181 * \param raise raise window if true
182 * \return true if a window (even root) has received focus, false otherwise
185 client_focus(Client
*c
, int screen
, Bool raise
)
189 /* if c is NULL or invisible, take next client in the focus history */
190 if((!c
|| (c
&& (!client_isvisible(c
, screen
))))
191 && !(c
= focus_get_current_client(screen
)))
192 /* if c is still NULL take next client in the stack */
193 for(c
= globalconf
.clients
; c
&& (c
->skip
|| !client_isvisible(c
, screen
)); c
= c
->next
);
195 /* if c is already the focused window, then stop */
196 if(c
== globalconf
.focus
->client
)
199 /* unfocus current selected client */
200 if(globalconf
.focus
->client
)
201 client_unfocus(globalconf
.focus
->client
);
205 /* unban the client before focusing or it will fail */
207 /* save sel in focus history */
209 if(globalconf
.screens
[c
->screen
].opacity_unfocused
!= -1)
210 window_settrans(c
->win
, globalconf
.screens
[c
->screen
].opacity_focused
);
211 XSetWindowBorder(globalconf
.display
, c
->win
,
212 globalconf
.screens
[screen
].styles
.focus
.border
.pixel
);
214 XSetInputFocus(globalconf
.display
, c
->win
, RevertToPointerRoot
, CurrentTime
);
217 /* since we're dropping EnterWindow events and sometimes the window
218 * will appear under the mouse, grabbuttons */
219 window_grabbuttons(c
->win
, c
->phys_screen
);
220 phys_screen
= c
->phys_screen
;
224 phys_screen
= screen_virttophys(screen
);
225 XSetInputFocus(globalconf
.display
,
226 RootWindow(globalconf
.display
, phys_screen
),
227 RevertToPointerRoot
, CurrentTime
);
230 ewmh_update_net_active_window(phys_screen
);
231 widget_invalidate_cache(screen
, WIDGET_CACHE_CLIENTS
);
237 client_stack(Client
*c
)
240 Layout
*curlay
= layout_get_current(c
->screen
);
242 if(c
->isfloating
|| curlay
->arrange
== layout_floating
)
244 XRaiseWindow(globalconf
.display
, c
->win
);
245 if(c
->titlebar
.position
&& c
->titlebar
.sw
)
246 XRaiseWindow(globalconf
.display
, c
->titlebar
.sw
->window
);
251 wc
.stack_mode
= Below
;
253 for(client
= globalconf
.clients
; client
; client
= client
->next
)
254 if(client
!= c
&& client_isvisible(client
, c
->screen
) && client
->isfloating
)
256 if(client
->titlebar
.position
&& client
->titlebar
.sw
)
258 XConfigureWindow(globalconf
.display
, client
->titlebar
.sw
->window
,
259 CWSibling
| CWStackMode
, &wc
);
260 wc
.sibling
= client
->titlebar
.sw
->window
;
262 XConfigureWindow(globalconf
.display
, client
->win
, CWSibling
| CWStackMode
, &wc
);
263 wc
.sibling
= client
->win
;
265 if(c
->titlebar
.position
&& c
->titlebar
.sw
)
267 XConfigureWindow(globalconf
.display
, c
->titlebar
.sw
->window
,
268 CWSibling
| CWStackMode
, &wc
);
269 wc
.sibling
= c
->titlebar
.sw
->window
;
271 XConfigureWindow(globalconf
.display
, c
->win
, CWSibling
| CWStackMode
, &wc
);
273 for(client
= globalconf
.clients
; client
; client
= client
->next
)
274 if(client
!= c
&& IS_TILED(client
, c
->screen
))
276 if(client
->titlebar
.position
&& client
->titlebar
.sw
)
278 XConfigureWindow(globalconf
.display
, client
->titlebar
.sw
->window
,
279 CWSibling
| CWStackMode
, &wc
);
280 wc
.sibling
= client
->titlebar
.sw
->window
;
282 XConfigureWindow(globalconf
.display
, client
->win
, CWSibling
| CWStackMode
, &wc
);
283 wc
.sibling
= client
->win
;
288 /** Manage a new client
289 * \param w The window
290 * \param wa Window attributes
291 * \param screen Screen ID
294 client_manage(Window w
, XWindowAttributes
*wa
, int screen
)
296 Client
*c
, *t
= NULL
;
298 Bool rettrans
, retloadprops
;
305 c
= p_new(Client
, 1);
307 c
->screen
= screen_get_bycoord(globalconf
.screens_info
, screen
, wa
->x
, wa
->y
);
309 if(globalconf
.screens_info
->xinerama_is_active
)
310 c
->phys_screen
= DefaultScreen(globalconf
.display
);
312 c
->phys_screen
= c
->screen
;
314 screen_geom
= screen_get_area(c
->screen
,
315 globalconf
.screens
[screen
].statusbar
,
316 &globalconf
.screens
[screen
].padding
);
319 c
->geometry
.x
= c
->f_geometry
.x
= c
->m_geometry
.x
= MAX(wa
->x
, screen_geom
.x
);
320 c
->geometry
.y
= c
->f_geometry
.y
= c
->m_geometry
.y
= MAX(wa
->y
, screen_geom
.y
);
321 c
->geometry
.width
= c
->f_geometry
.width
= c
->m_geometry
.width
= wa
->width
;
322 c
->geometry
.height
= c
->f_geometry
.height
= c
->m_geometry
.height
= wa
->height
;
323 c
->oldborder
= wa
->border_width
;
326 /* Set windows borders */
327 wc
.border_width
= c
->border
= globalconf
.screens
[screen
].borderpx
;
328 XConfigureWindow(globalconf
.display
, w
, CWBorderWidth
, &wc
);
329 XSetWindowBorder(globalconf
.display
, w
, c
->border
);
330 /* propagates border_width, if size doesn't change */
331 window_configure(c
->win
, c
->geometry
, c
->border
);
333 /* update window title */
334 client_updatetitle(c
);
337 flags
= client_updatesizehints(c
);
338 client_updatewmhints(c
);
340 /* Try to load props if any */
341 if(!(retloadprops
= client_loadprops(c
, screen
)))
342 move_client_to_screen(c
, screen
, True
);
344 /* Then check clients hints */
345 ewmh_check_client_hints(c
);
347 /* default titlebar position */
348 c
->titlebar
= globalconf
.screens
[screen
].titlebar_default
;
350 /* get the matching rule if any */
351 rule
= rule_matching_client(c
);
353 /* Then apply rules if no props */
354 if(!retloadprops
&& rule
)
356 if(rule
->screen
!= RULE_NOSCREEN
)
357 move_client_to_screen(c
, rule
->screen
, True
);
358 tag_client_with_rule(c
, rule
);
360 switch(rule
->isfloating
)
365 client_setfloating(c
, True
);
368 client_setfloating(c
, False
);
372 if(rule
->opacity
>= 0.0f
)
373 window_settrans(c
->win
, rule
->opacity
);
376 /* check for transient and set tags like its parent,
377 * XGetTransientForHint returns 1 on success
379 if((rettrans
= XGetTransientForHint(globalconf
.display
, w
, &trans
))
380 && (t
= client_get_bywin(globalconf
.clients
, trans
)))
381 for(tag
= globalconf
.screens
[c
->screen
].tags
; tag
; tag
= tag
->next
)
382 if(is_client_tagged(t
, tag
))
385 /* should be floating if transsient or fixed */
386 if(rettrans
|| c
->isfixed
)
387 client_setfloating(c
, True
);
390 if(rule
&& rule
->titlebar
.position
!= Auto
)
391 c
->titlebar
= rule
->titlebar
;
395 if(!retloadprops
&& !(flags
& (USPosition
| PPosition
)))
396 c
->f_geometry
= globalconf
.screens
[c
->screen
].floating_placement(c
);
398 /* update titlebar with real floating info now */
400 titlebar_update_geometry_floating(c
);
402 XSelectInput(globalconf
.display
, w
, StructureNotifyMask
| PropertyChangeMask
| EnterWindowMask
);
405 if(globalconf
.have_shape
)
407 XShapeSelectInput(globalconf
.display
, w
, ShapeNotifyMask
);
408 window_setshape(c
->win
, c
->phys_screen
);
411 /* attach to the stack */
413 switch(rule
->ismaster
)
416 client_list_push(&globalconf
.clients
, c
);
419 client_list_append(&globalconf
.clients
, c
);
428 if(globalconf
.screens
[c
->screen
].new_become_master
)
429 client_list_push(&globalconf
.clients
, c
);
431 client_list_append(&globalconf
.clients
, c
);
434 /* some windows require this */
435 XMoveResizeWindow(globalconf
.display
, c
->win
, c
->geometry
.x
, c
->geometry
.y
,
436 c
->geometry
.width
, c
->geometry
.height
);
438 widget_invalidate_cache(c
->screen
, WIDGET_CACHE_CLIENTS
);
439 ewmh_update_net_client_list(c
->phys_screen
);
443 client_geometry_hints(Client
*c
, area_t geometry
)
445 double dx
, dy
, max
, min
, ratio
;
447 if(c
->minay
> 0 && c
->maxay
> 0 && (geometry
.height
- c
->baseh
) > 0
448 && (geometry
.width
- c
->basew
) > 0)
450 dx
= (double) (geometry
.width
- c
->basew
);
451 dy
= (double) (geometry
.height
- c
->baseh
);
452 min
= (double) (c
->minax
) / (double) (c
->minay
);
453 max
= (double) (c
->maxax
) / (double) (c
->maxay
);
455 if(max
> 0 && min
> 0 && ratio
> 0)
459 dy
= (dx
* min
+ dy
) / (min
* min
+ 1);
461 geometry
.width
= (int) dx
+ c
->basew
;
462 geometry
.height
= (int) dy
+ c
->baseh
;
466 dy
= (dx
* min
+ dy
) / (max
* max
+ 1);
468 geometry
.width
= (int) dx
+ c
->basew
;
469 geometry
.height
= (int) dy
+ c
->baseh
;
473 if(c
->minw
&& geometry
.width
< c
->minw
)
474 geometry
.width
= c
->minw
;
475 if(c
->minh
&& geometry
.height
< c
->minh
)
476 geometry
.height
= c
->minh
;
477 if(c
->maxw
&& geometry
.width
> c
->maxw
)
478 geometry
.width
= c
->maxw
;
479 if(c
->maxh
&& geometry
.height
> c
->maxh
)
480 geometry
.height
= c
->maxh
;
482 geometry
.width
-= (geometry
.width
- c
->basew
) % c
->incw
;
484 geometry
.height
-= (geometry
.height
- c
->baseh
) % c
->inch
;
489 /** Resize client window
490 * \param c client to resize
491 * \param geometry new window geometry
492 * \param hints use resize hints
493 * \param return True if resize has been done
496 client_resize(Client
*c
, area_t geometry
, Bool hints
)
501 Layout
*layout
= layout_get_current(c
->screen
);
502 Bool resized
= False
;
504 if(!c
->ismoving
&& !c
->isfloating
&& layout
->arrange
!= layout_floating
)
506 titlebar_update_geometry(c
, geometry
);
507 geometry
= titlebar_geometry_remove(&c
->titlebar
, geometry
);
511 geometry
= client_geometry_hints(c
, geometry
);
513 if(geometry
.width
<= 0 || geometry
.height
<= 0)
516 /* offscreen appearance fixes */
517 area
= get_display_area(c
->phys_screen
, NULL
,
518 &globalconf
.screens
[c
->screen
].padding
);
520 if(geometry
.x
> area
.width
)
521 geometry
.x
= area
.width
- geometry
.width
- 2 * c
->border
;
522 if(geometry
.y
> area
.height
)
523 geometry
.y
= area
.height
- geometry
.height
- 2 * c
->border
;
524 if(geometry
.x
+ geometry
.width
+ 2 * c
->border
< 0)
526 if(geometry
.y
+ geometry
.height
+ 2 * c
->border
< 0)
529 if(c
->geometry
.x
!= geometry
.x
|| c
->geometry
.y
!= geometry
.y
530 || c
->geometry
.width
!= geometry
.width
|| c
->geometry
.height
!= geometry
.height
)
533 screen_get_bycoord(globalconf
.screens_info
, c
->screen
, geometry
.x
, geometry
.y
);
535 c
->geometry
.x
= wc
.x
= geometry
.x
;
536 c
->geometry
.width
= wc
.width
= geometry
.width
;
537 c
->geometry
.y
= wc
.y
= geometry
.y
;
538 c
->geometry
.height
= wc
.height
= geometry
.height
;
539 wc
.border_width
= c
->border
;
541 /* save the floating geometry if the window is floating but not
543 if(c
->ismoving
|| c
->isfloating
544 || layout_get_current(new_screen
)->arrange
== layout_floating
)
547 c
->f_geometry
= geometry
;
548 titlebar_update_geometry_floating(c
);
551 XConfigureWindow(globalconf
.display
, c
->win
,
552 CWX
| CWY
| CWWidth
| CWHeight
| CWBorderWidth
, &wc
);
553 window_configure(c
->win
, geometry
, c
->border
);
555 if(c
->screen
!= new_screen
)
556 move_client_to_screen(c
, new_screen
, False
);
561 /* call it again like it was floating,
562 * we want it to be sticked to the window */
563 if(!c
->ismoving
&& !c
->isfloating
&& layout
->arrange
!= layout_floating
)
564 titlebar_update_geometry_floating(c
);
570 client_setfloating(Client
*c
, Bool floating
)
572 if(c
->isfloating
!= floating
)
574 if((c
->isfloating
= floating
))
576 client_resize(c
, c
->f_geometry
, False
);
577 XRaiseWindow(globalconf
.display
, c
->win
);
581 XLowerWindow(globalconf
.display
, c
->win
);
585 client_resize(c
, c
->m_geometry
, False
);
588 if(client_isvisible(c
, c
->screen
))
589 globalconf
.screens
[c
->screen
].need_arrange
= True
;
590 widget_invalidate_cache(c
->screen
, WIDGET_CACHE_CLIENTS
);
595 /** Save client properties as an X property
599 client_saveprops(Client
*c
)
601 int i
= 0, ntags
= 0;
605 for(tag
= globalconf
.screens
[c
->screen
].tags
; tag
; tag
= tag
->next
)
608 prop
= p_new(char, ntags
+ 2);
610 for(tag
= globalconf
.screens
[c
->screen
].tags
; tag
; tag
= tag
->next
, i
++)
611 prop
[i
] = is_client_tagged(c
, tag
) ? '1' : '0';
614 prop
[i
] = c
->isfloating
? '1' : '0';
618 XChangeProperty(globalconf
.display
, c
->win
,
619 XInternAtom(globalconf
.display
, "_AWESOME_PROPERTIES", False
),
620 XA_STRING
, 8, PropModeReplace
, (unsigned char *) prop
, i
);
626 client_unban(Client
*c
)
628 XMapWindow(globalconf
.display
, c
->win
);
629 window_setstate(c
->win
, NormalState
);
630 if(c
->titlebar
.sw
&& c
->titlebar
.position
!= Off
)
631 XMapWindow(globalconf
.display
, c
->titlebar
.sw
->window
);
635 client_unmanage(Client
*c
)
640 wc
.border_width
= c
->oldborder
;
642 /* The server grab construct avoids race conditions. */
643 XGrabServer(globalconf
.display
);
645 XConfigureWindow(globalconf
.display
, c
->win
, CWBorderWidth
, &wc
); /* restore border */
647 /* remove client everywhere */
648 client_list_detach(&globalconf
.clients
, c
);
649 focus_delete_client(c
);
650 if(globalconf
.scratch
.client
== c
)
651 globalconf
.scratch
.client
= NULL
;
652 for(tag
= globalconf
.screens
[c
->screen
].tags
; tag
; tag
= tag
->next
)
653 untag_client(c
, tag
);
655 if(globalconf
.focus
->client
== c
)
656 client_focus(NULL
, c
->screen
, True
);
658 XUngrabButton(globalconf
.display
, AnyButton
, AnyModifier
, c
->win
);
659 window_setstate(c
->win
, WithdrawnState
);
661 XSync(globalconf
.display
, False
);
662 XUngrabServer(globalconf
.display
);
665 simplewindow_delete(&c
->titlebar
.sw
);
671 client_updatewmhints(Client
*c
)
675 if((wmh
= XGetWMHints(globalconf
.display
, c
->win
)))
677 if((c
->isurgent
= ((wmh
->flags
& XUrgencyHint
) && globalconf
.focus
->client
!= c
)))
678 widget_invalidate_cache(c
->screen
, WIDGET_CACHE_CLIENTS
);
679 if((wmh
->flags
& StateHint
) && wmh
->initial_state
== WithdrawnState
)
689 client_updatesizehints(Client
*c
)
694 if(!XGetWMNormalHints(globalconf
.display
, c
->win
, &size
, &msize
))
697 if(size
.flags
& PBaseSize
)
699 c
->basew
= size
.base_width
;
700 c
->baseh
= size
.base_height
;
702 else if(size
.flags
& PMinSize
)
704 c
->basew
= size
.min_width
;
705 c
->baseh
= size
.min_height
;
708 c
->basew
= c
->baseh
= 0;
709 if(size
.flags
& PResizeInc
)
711 c
->incw
= size
.width_inc
;
712 c
->inch
= size
.height_inc
;
715 c
->incw
= c
->inch
= 0;
717 if(size
.flags
& PMaxSize
)
719 c
->maxw
= size
.max_width
;
720 c
->maxh
= size
.max_height
;
723 c
->maxw
= c
->maxh
= 0;
725 if(size
.flags
& PMinSize
)
727 c
->minw
= size
.min_width
;
728 c
->minh
= size
.min_height
;
730 else if(size
.flags
& PBaseSize
)
732 c
->minw
= size
.base_width
;
733 c
->minh
= size
.base_height
;
736 c
->minw
= c
->minh
= 0;
738 if(size
.flags
& PAspect
)
740 c
->minax
= size
.min_aspect
.x
;
741 c
->maxax
= size
.max_aspect
.x
;
742 c
->minay
= size
.min_aspect
.y
;
743 c
->maxay
= size
.max_aspect
.y
;
746 c
->minax
= c
->maxax
= c
->minay
= c
->maxay
= 0;
748 if(c
->maxw
&& c
->minw
&& c
->maxh
&& c
->minh
749 && c
->maxw
== c
->minw
&& c
->maxh
== c
->minh
)
755 /** Returns True if a client is tagged
756 * with one of the tags
757 * \return True or False
760 client_isvisible(Client
*c
, int screen
)
764 if(!c
|| c
->screen
!= screen
)
767 if(globalconf
.scratch
.client
== c
)
768 return globalconf
.scratch
.isvisible
;
770 for(tag
= globalconf
.screens
[screen
].tags
; tag
; tag
= tag
->next
)
771 if(tag
->selected
&& is_client_tagged(c
, tag
))
776 /** Set selected client transparency.
777 * Argument should be a floating between 0 and 100, -1 to disable.
778 * \param screen Screen ID
779 * \param arg unused arg
780 * \ingroup ui_callback
783 uicb_client_settrans(int screen
__attribute__ ((unused
)), char *arg
)
785 double delta
= 1.0, current_opacity
= 1.0;
789 unsigned long n
, left
;
790 unsigned int current_opacity_raw
= 0;
792 Client
*sel
= globalconf
.focus
->client
;
797 XGetWindowProperty(globalconf
.display
, sel
->win
,
798 XInternAtom(globalconf
.display
, "_NET_WM_WINDOW_OPACITY", False
),
799 0L, 1L, False
, XA_CARDINAL
, &actual
, &format
, &n
, &left
,
800 (unsigned char **) &data
);
803 memcpy(¤t_opacity_raw
, data
, sizeof(unsigned int));
805 current_opacity
= current_opacity_raw
/ 0xffffffff;
810 delta
= compute_new_value_from_arg(arg
, current_opacity
);
820 if(delta
== 1.0 && !set_prop
)
821 window_settrans(sel
->win
, -1);
823 window_settrans(sel
->win
, delta
);
826 /** Find a visible client on screen. Return next client or previous client if
828 * \param sel current selected client
829 * \param reverse return previous instead of next if true
830 * \return next or previous client
833 client_find_visible(Client
*sel
, Bool reverse
)
836 Client
*(*client_iter
)(Client
**, Client
*) = client_list_next_cycle
;
838 if(!sel
) return NULL
;
841 client_iter
= client_list_prev_cycle
;
843 /* look for previous or next starting at sel */
845 for(next
= client_iter(&globalconf
.clients
, sel
);
846 next
&& next
!= sel
&& (next
->skip
|| !client_isvisible(next
, sel
->screen
));
847 next
= client_iter(&globalconf
.clients
, next
));
852 /** Swap currently focused client with previous visible.
853 * \param screen Screen ID
855 * \ingroup ui_callback
858 uicb_client_swapprev(int screen
__attribute__ ((unused
)), char *arg
__attribute__ ((unused
)))
862 if((prev
= client_find_visible(globalconf
.focus
->client
, True
)))
864 client_list_swap(&globalconf
.clients
, prev
, globalconf
.focus
->client
);
865 globalconf
.screens
[prev
->screen
].need_arrange
= True
;
869 /** Swap currently focused client with next visible.
870 * \param screen Screen ID
872 * \ingroup ui_callback
875 uicb_client_swapnext(int screen
__attribute__ ((unused
)), char *arg
__attribute__ ((unused
)))
879 if((next
= client_find_visible(globalconf
.focus
->client
, False
)))
881 client_list_swap(&globalconf
.clients
, globalconf
.focus
->client
, next
);
882 globalconf
.screens
[next
->screen
].need_arrange
= True
;
886 /** Move and resize a client. Argument should be in format "x y w h" with
887 * absolute (1, 20, 300, ...) or relatives (+10, -200, ...) values.
888 * \param screen Screen ID
890 * \ingroup ui_callback
893 uicb_client_moveresize(int screen
, char *arg
)
895 int ox
, oy
, ow
, oh
; /* old geometry */
896 char x
[8], y
[8], w
[8], h
[8];
897 int mx
, my
, dx
, dy
, nmx
, nmy
;
901 Client
*sel
= globalconf
.focus
->client
;
902 Layout
*curlay
= layout_get_current(screen
);
904 if(!sel
|| sel
->isfixed
|| !arg
||
905 (curlay
->arrange
!= layout_floating
&& !sel
->isfloating
))
908 if(sscanf(arg
, "%s %s %s %s", x
, y
, w
, h
) != 4)
911 geometry
.x
= (int) compute_new_value_from_arg(x
, sel
->geometry
.x
);
912 geometry
.y
= (int) compute_new_value_from_arg(y
, sel
->geometry
.y
);
913 geometry
.width
= (int) compute_new_value_from_arg(w
, sel
->geometry
.width
);
914 geometry
.height
= (int) compute_new_value_from_arg(h
, sel
->geometry
.height
);
916 ox
= sel
->geometry
.x
;
917 oy
= sel
->geometry
.y
;
918 ow
= sel
->geometry
.width
;
919 oh
= sel
->geometry
.height
;
921 Bool xqp
= XQueryPointer(globalconf
.display
,
922 RootWindow(globalconf
.display
,
924 &dummy
, &dummy
, &mx
, &my
, &dx
, &dy
, &dui
);
925 if(globalconf
.screens
[sel
->screen
].resize_hints
)
926 geometry
= client_geometry_hints(sel
, geometry
);
927 client_resize(sel
, geometry
, False
);
928 if (xqp
&& ox
<= mx
&& (ox
+ 2 * sel
->border
+ ow
) >= mx
&&
929 oy
<= my
&& (oy
+ 2 * sel
->border
+ oh
) >= my
)
931 nmx
= mx
- (ox
+ sel
->border
) + sel
->geometry
.width
- ow
;
932 nmy
= my
- (oy
+ sel
->border
) + sel
->geometry
.height
- oh
;
934 if(nmx
< -sel
->border
) /* can happen on a resize */
936 if(nmy
< -sel
->border
)
939 XWarpPointer(globalconf
.display
,
941 0, 0, 0, 0, nmx
, nmy
);
945 /** Kill a client via a WM_DELETE_WINDOW request or XKillClient if not
947 * \param c the client to kill
950 client_kill(Client
*c
)
954 if(client_isprotodel(globalconf
.display
, c
->win
))
956 ev
.type
= ClientMessage
;
957 ev
.xclient
.window
= c
->win
;
958 ev
.xclient
.message_type
= XInternAtom(globalconf
.display
, "WM_PROTOCOLS", False
);
959 ev
.xclient
.format
= 32;
960 ev
.xclient
.data
.l
[0] = XInternAtom(globalconf
.display
, "WM_DELETE_WINDOW", False
);
961 ev
.xclient
.data
.l
[1] = CurrentTime
;
962 XSendEvent(globalconf
.display
, c
->win
, False
, NoEventMask
, &ev
);
965 XKillClient(globalconf
.display
, c
->win
);
968 /** Kill the currently focused client.
969 * \param screen Screen ID
971 * \ingroup ui_callback
974 uicb_client_kill(int screen
__attribute__ ((unused
)), char *arg
__attribute__ ((unused
)))
976 Client
*sel
= globalconf
.focus
->client
;
982 /** Maximize the client to the given geometry.
983 * \param c the client to maximize
984 * \param geometry the geometry to use for maximizing
987 client_maximize(Client
*c
, area_t geometry
)
989 if((c
->ismax
= !c
->ismax
))
991 /* disable titlebar */
992 c
->titlebar
.position
= Off
;
993 c
->wasfloating
= c
->isfloating
;
994 c
->m_geometry
= c
->geometry
;
995 if(layout_get_current(c
->screen
)->arrange
!= layout_floating
)
996 client_setfloating(c
, True
);
997 client_focus(c
, c
->screen
, True
);
998 client_resize(c
, geometry
, False
);
1000 else if(c
->wasfloating
)
1002 c
->titlebar
.position
= c
->titlebar
.dposition
;
1003 client_setfloating(c
, True
);
1004 client_resize(c
, c
->m_geometry
, False
);
1006 else if(layout_get_current(c
->screen
)->arrange
== layout_floating
)
1008 c
->titlebar
.position
= c
->titlebar
.dposition
;
1009 client_resize(c
, c
->m_geometry
, False
);
1013 c
->titlebar
.position
= c
->titlebar
.dposition
;
1014 client_setfloating(c
, False
);
1016 widget_invalidate_cache(c
->screen
, WIDGET_CACHE_CLIENTS
);
1019 /** Toggle maximization state for the focused client.
1020 * \param screen Screen ID
1022 * \ingroup ui_callback
1025 uicb_client_togglemax(int screen
, char *arg
__attribute__ ((unused
)))
1027 Client
*sel
= globalconf
.focus
->client
;
1028 area_t area
= screen_get_area(screen
,
1029 globalconf
.screens
[screen
].statusbar
,
1030 &globalconf
.screens
[screen
].padding
);
1034 area
.width
-= 2 * sel
->border
;
1035 area
.height
-= 2 * sel
->border
;
1036 client_maximize(sel
, area
);
1040 /** Toggle vertical maximization for the focused client.
1041 * \param screen Screen ID
1043 * \ingroup ui_callback
1046 uicb_client_toggleverticalmax(int screen
, char *arg
__attribute__ ((unused
)))
1048 Client
*sel
= globalconf
.focus
->client
;
1049 area_t area
= screen_get_area(screen
,
1050 globalconf
.screens
[screen
].statusbar
,
1051 &globalconf
.screens
[screen
].padding
);
1055 area
.x
= sel
->geometry
.x
;
1056 area
.width
= sel
->geometry
.width
;
1057 area
.height
-= 2 * sel
->border
;
1058 client_maximize(sel
, area
);
1063 /** Toggle horizontal maximization for the focused client.
1064 * \param screen Screen ID
1066 * \ingroup ui_callback
1069 uicb_client_togglehorizontalmax(int screen
, char *arg
__attribute__ ((unused
)))
1071 Client
*sel
= globalconf
.focus
->client
;
1072 area_t area
= screen_get_area(screen
,
1073 globalconf
.screens
[screen
].statusbar
,
1074 &globalconf
.screens
[screen
].padding
);
1078 area
.y
= sel
->geometry
.y
;
1079 area
.height
= sel
->geometry
.height
;
1080 area
.width
-= 2 * sel
->border
;
1081 client_maximize(sel
, area
);
1085 /** Set the client the master window.
1086 * \param screen Screen ID
1088 * \ingroup ui_callback
1091 uicb_client_zoom(int screen
, char *arg
__attribute__ ((unused
)))
1093 Client
*c
, *sel
= globalconf
.focus
->client
;
1098 for(c
= globalconf
.clients
; !client_isvisible(c
, screen
); c
= c
->next
);
1100 for(sel
= sel
->next
; sel
&& !client_isvisible(sel
, screen
); sel
= sel
->next
);
1104 client_list_detach(&globalconf
.clients
, sel
);
1105 client_list_push(&globalconf
.clients
, sel
);
1106 globalconf
.screens
[screen
].need_arrange
= True
;
1110 /** Setfocus to the next visible client in the stack.
1111 * \param screen Screen ID
1113 * \ingroup ui_callback
1116 uicb_client_focusnext(int screen
, char *arg
__attribute__ ((unused
)))
1120 if((next
= client_find_visible(globalconf
.focus
->client
, False
)))
1121 client_focus(next
, screen
, True
);
1124 /** Setfocus to the previous visible client in the stack.
1125 * \param screen Screen ID
1127 * \ingroup ui_callback
1130 uicb_client_focusprev(int screen
, char *arg
__attribute__ ((unused
)))
1134 if((prev
= client_find_visible(globalconf
.focus
->client
, True
)))
1135 client_focus(prev
, screen
, True
);
1138 /** Toggle the floating state of the focused client.
1139 * \param screen Screen ID
1141 * \ingroup ui_callback
1144 uicb_client_togglefloating(int screen
__attribute__ ((unused
)), char *arg
__attribute__ ((unused
)))
1146 if(globalconf
.focus
->client
)
1147 client_setfloating(globalconf
.focus
->client
, !globalconf
.focus
->client
->isfloating
);
1150 /** Toggle the scratch client attribute on the focused client.
1151 * \param screen screen number
1152 * \param arg unused argument
1153 * \ingroup ui_callback
1156 uicb_client_setscratch(int screen
, char *arg
__attribute__ ((unused
)))
1158 if(!globalconf
.focus
->client
)
1161 if(globalconf
.scratch
.client
== globalconf
.focus
->client
)
1162 globalconf
.scratch
.client
= NULL
;
1164 globalconf
.scratch
.client
= globalconf
.focus
->client
;
1166 widget_invalidate_cache(screen
, WIDGET_CACHE_CLIENTS
| WIDGET_CACHE_TAGS
);
1167 globalconf
.screens
[screen
].need_arrange
= True
;
1170 /** Toggle scratch client visibility.
1171 * \param screen screen number
1172 * \param arg unused argument
1173 * \ingroup ui_callback
1176 uicb_client_togglescratch(int screen
, char *arg
__attribute__ ((unused
)))
1178 if(globalconf
.scratch
.client
)
1180 globalconf
.scratch
.isvisible
= !globalconf
.scratch
.isvisible
;
1181 if(globalconf
.scratch
.isvisible
)
1182 client_focus(globalconf
.scratch
.client
, screen
, True
);
1183 globalconf
.screens
[globalconf
.scratch
.client
->screen
].need_arrange
= True
;
1184 widget_invalidate_cache(globalconf
.scratch
.client
->screen
, WIDGET_CACHE_CLIENTS
);
1188 // vim: filetype=c:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=80