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 else if(globalconf
.screens
[c
->screen
].opacity_focused
!= -1)
158 window_settrans(c
->win
, -1);
159 focus_add_client(NULL
);
160 XSetWindowBorder(globalconf
.display
, c
->win
,
161 globalconf
.screens
[c
->screen
].styles
.normal
.border
.pixel
);
162 widget_invalidate_cache(c
->screen
, WIDGET_CACHE_CLIENTS
);
166 /** Ban client and unmap it
167 * \param c the client
170 client_ban(Client
*c
)
172 if(globalconf
.focus
->client
== c
)
174 XUnmapWindow(globalconf
.display
, c
->win
);
175 window_setstate(c
->win
, IconicState
);
176 if(c
->titlebar
.position
&& c
->titlebar
.sw
)
177 XUnmapWindow(globalconf
.display
, c
->titlebar
.sw
->window
);
180 /** Give focus to client, or to first client if c is NULL
182 * \param screen Screen ID
183 * \param raise raise window if true
184 * \return true if a window (even root) has received focus, false otherwise
187 client_focus(Client
*c
, int screen
, Bool raise
)
191 /* if c is NULL or invisible, take next client in the focus history */
192 if((!c
|| (c
&& (!client_isvisible(c
, screen
))))
193 && !(c
= focus_get_current_client(screen
)))
194 /* if c is still NULL take next client in the stack */
195 for(c
= globalconf
.clients
; c
&& (c
->skip
|| !client_isvisible(c
, screen
)); c
= c
->next
);
197 /* if c is already the focused window, then stop */
198 if(c
== globalconf
.focus
->client
)
201 /* unfocus current selected client */
202 if(globalconf
.focus
->client
)
203 client_unfocus(globalconf
.focus
->client
);
207 /* unban the client before focusing or it will fail */
209 /* save sel in focus history */
211 if(globalconf
.screens
[c
->screen
].opacity_focused
!= -1)
212 window_settrans(c
->win
, globalconf
.screens
[c
->screen
].opacity_focused
);
213 else if(globalconf
.screens
[c
->screen
].opacity_unfocused
!= -1)
214 window_settrans(c
->win
, -1);
215 XSetWindowBorder(globalconf
.display
, c
->win
,
216 globalconf
.screens
[screen
].styles
.focus
.border
.pixel
);
218 XSetInputFocus(globalconf
.display
, c
->win
, RevertToPointerRoot
, CurrentTime
);
221 /* since we're dropping EnterWindow events and sometimes the window
222 * will appear under the mouse, grabbuttons */
223 window_grabbuttons(c
->win
, c
->phys_screen
);
224 phys_screen
= c
->phys_screen
;
228 phys_screen
= screen_virttophys(screen
);
229 XSetInputFocus(globalconf
.display
,
230 RootWindow(globalconf
.display
, phys_screen
),
231 RevertToPointerRoot
, CurrentTime
);
234 ewmh_update_net_active_window(phys_screen
);
235 widget_invalidate_cache(screen
, WIDGET_CACHE_CLIENTS
);
241 client_stack(Client
*c
)
244 Layout
*curlay
= layout_get_current(c
->screen
);
246 if(c
->isfloating
|| curlay
->arrange
== layout_floating
)
248 XRaiseWindow(globalconf
.display
, c
->win
);
249 if(c
->titlebar
.position
&& c
->titlebar
.sw
)
250 XRaiseWindow(globalconf
.display
, c
->titlebar
.sw
->window
);
255 wc
.stack_mode
= Below
;
257 for(client
= globalconf
.clients
; client
; client
= client
->next
)
258 if(client
!= c
&& client_isvisible(client
, c
->screen
) && client
->isfloating
)
260 if(client
->titlebar
.position
&& client
->titlebar
.sw
)
262 XConfigureWindow(globalconf
.display
, client
->titlebar
.sw
->window
,
263 CWSibling
| CWStackMode
, &wc
);
264 wc
.sibling
= client
->titlebar
.sw
->window
;
266 XConfigureWindow(globalconf
.display
, client
->win
, CWSibling
| CWStackMode
, &wc
);
267 wc
.sibling
= client
->win
;
269 if(c
->titlebar
.position
&& c
->titlebar
.sw
)
271 XConfigureWindow(globalconf
.display
, c
->titlebar
.sw
->window
,
272 CWSibling
| CWStackMode
, &wc
);
273 wc
.sibling
= c
->titlebar
.sw
->window
;
275 XConfigureWindow(globalconf
.display
, c
->win
, CWSibling
| CWStackMode
, &wc
);
277 for(client
= globalconf
.clients
; client
; client
= client
->next
)
278 if(client
!= c
&& IS_TILED(client
, c
->screen
))
280 if(client
->titlebar
.position
&& client
->titlebar
.sw
)
282 XConfigureWindow(globalconf
.display
, client
->titlebar
.sw
->window
,
283 CWSibling
| CWStackMode
, &wc
);
284 wc
.sibling
= client
->titlebar
.sw
->window
;
286 XConfigureWindow(globalconf
.display
, client
->win
, CWSibling
| CWStackMode
, &wc
);
287 wc
.sibling
= client
->win
;
292 /** Manage a new client
293 * \param w The window
294 * \param wa Window attributes
295 * \param screen Screen ID
298 client_manage(Window w
, XWindowAttributes
*wa
, int screen
)
300 Client
*c
, *t
= NULL
;
302 Bool rettrans
, retloadprops
;
308 c
= p_new(Client
, 1);
310 c
->screen
= screen_get_bycoord(globalconf
.screens_info
, screen
, wa
->x
, wa
->y
);
312 if(globalconf
.screens_info
->xinerama_is_active
)
313 c
->phys_screen
= DefaultScreen(globalconf
.display
);
315 c
->phys_screen
= c
->screen
;
319 c
->geometry
.x
= c
->f_geometry
.x
= c
->m_geometry
.x
= wa
->x
;
320 c
->geometry
.y
= c
->f_geometry
.y
= c
->m_geometry
.y
= wa
->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
)))
397 if(c
->isfloating
&& !c
->ismax
)
398 client_resize(c
, globalconf
.screens
[c
->screen
].floating_placement(c
), False
);
400 c
->f_geometry
= globalconf
.screens
[c
->screen
].floating_placement(c
);
403 /* update titlebar with real floating info now */
404 titlebar_update_geometry_floating(c
);
406 XSelectInput(globalconf
.display
, w
, StructureNotifyMask
| PropertyChangeMask
| EnterWindowMask
);
409 if(globalconf
.have_shape
)
411 XShapeSelectInput(globalconf
.display
, w
, ShapeNotifyMask
);
412 window_setshape(c
->win
, c
->phys_screen
);
415 /* attach to the stack */
417 switch(rule
->ismaster
)
420 client_list_push(&globalconf
.clients
, c
);
423 client_list_append(&globalconf
.clients
, c
);
432 if(globalconf
.screens
[c
->screen
].new_become_master
)
433 client_list_push(&globalconf
.clients
, c
);
435 client_list_append(&globalconf
.clients
, c
);
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
);
582 client_resize(c
, c
->m_geometry
, False
);
584 if(client_isvisible(c
, c
->screen
))
585 globalconf
.screens
[c
->screen
].need_arrange
= True
;
586 widget_invalidate_cache(c
->screen
, WIDGET_CACHE_CLIENTS
);
591 /** Save client properties as an X property
595 client_saveprops(Client
*c
)
597 int i
= 0, ntags
= 0;
601 for(tag
= globalconf
.screens
[c
->screen
].tags
; tag
; tag
= tag
->next
)
604 prop
= p_new(char, ntags
+ 2);
606 for(tag
= globalconf
.screens
[c
->screen
].tags
; tag
; tag
= tag
->next
, i
++)
607 prop
[i
] = is_client_tagged(c
, tag
) ? '1' : '0';
610 prop
[i
] = c
->isfloating
? '1' : '0';
614 XChangeProperty(globalconf
.display
, c
->win
,
615 XInternAtom(globalconf
.display
, "_AWESOME_PROPERTIES", False
),
616 XA_STRING
, 8, PropModeReplace
, (unsigned char *) prop
, i
);
622 client_unban(Client
*c
)
624 XMapWindow(globalconf
.display
, c
->win
);
625 window_setstate(c
->win
, NormalState
);
626 if(c
->titlebar
.sw
&& c
->titlebar
.position
!= Off
)
627 XMapWindow(globalconf
.display
, c
->titlebar
.sw
->window
);
631 client_unmanage(Client
*c
)
636 wc
.border_width
= c
->oldborder
;
638 /* The server grab construct avoids race conditions. */
639 XGrabServer(globalconf
.display
);
641 XConfigureWindow(globalconf
.display
, c
->win
, CWBorderWidth
, &wc
); /* restore border */
643 /* remove client everywhere */
644 client_list_detach(&globalconf
.clients
, c
);
645 focus_delete_client(c
);
646 if(globalconf
.scratch
.client
== c
)
647 globalconf
.scratch
.client
= NULL
;
648 for(tag
= globalconf
.screens
[c
->screen
].tags
; tag
; tag
= tag
->next
)
649 untag_client(c
, tag
);
651 if(globalconf
.focus
->client
== c
)
652 client_focus(NULL
, c
->screen
, True
);
654 XUngrabButton(globalconf
.display
, AnyButton
, AnyModifier
, c
->win
);
655 window_setstate(c
->win
, WithdrawnState
);
657 XSync(globalconf
.display
, False
);
658 XUngrabServer(globalconf
.display
);
661 simplewindow_delete(&c
->titlebar
.sw
);
667 client_updatewmhints(Client
*c
)
671 if((wmh
= XGetWMHints(globalconf
.display
, c
->win
)))
673 if((c
->isurgent
= ((wmh
->flags
& XUrgencyHint
) && globalconf
.focus
->client
!= c
)))
675 widget_invalidate_cache(c
->screen
, WIDGET_CACHE_CLIENTS
);
678 if((wmh
->flags
& StateHint
) && wmh
->initial_state
== WithdrawnState
)
688 client_updatesizehints(Client
*c
)
693 if(!XGetWMNormalHints(globalconf
.display
, c
->win
, &size
, &msize
))
696 if(size
.flags
& PBaseSize
)
698 c
->basew
= size
.base_width
;
699 c
->baseh
= size
.base_height
;
701 else if(size
.flags
& PMinSize
)
703 c
->basew
= size
.min_width
;
704 c
->baseh
= size
.min_height
;
707 c
->basew
= c
->baseh
= 0;
708 if(size
.flags
& PResizeInc
)
710 c
->incw
= size
.width_inc
;
711 c
->inch
= size
.height_inc
;
714 c
->incw
= c
->inch
= 0;
716 if(size
.flags
& PMaxSize
)
718 c
->maxw
= size
.max_width
;
719 c
->maxh
= size
.max_height
;
722 c
->maxw
= c
->maxh
= 0;
724 if(size
.flags
& PMinSize
)
726 c
->minw
= size
.min_width
;
727 c
->minh
= size
.min_height
;
729 else if(size
.flags
& PBaseSize
)
731 c
->minw
= size
.base_width
;
732 c
->minh
= size
.base_height
;
735 c
->minw
= c
->minh
= 0;
737 if(size
.flags
& PAspect
)
739 c
->minax
= size
.min_aspect
.x
;
740 c
->maxax
= size
.max_aspect
.x
;
741 c
->minay
= size
.min_aspect
.y
;
742 c
->maxay
= size
.max_aspect
.y
;
745 c
->minax
= c
->maxax
= c
->minay
= c
->maxay
= 0;
747 if(c
->maxw
&& c
->minw
&& c
->maxh
&& c
->minh
748 && c
->maxw
== c
->minw
&& c
->maxh
== c
->minh
)
754 /** Returns True if a client is tagged
755 * with one of the tags
756 * \return True or False
759 client_isvisible(Client
*c
, int screen
)
763 if(!c
|| c
->screen
!= screen
)
766 if(globalconf
.scratch
.client
== c
)
767 return globalconf
.scratch
.isvisible
;
769 for(tag
= globalconf
.screens
[screen
].tags
; tag
; tag
= tag
->next
)
770 if(tag
->selected
&& is_client_tagged(c
, tag
))
775 /** Set the transparency of the selected client.
776 * Argument should be a floating between 0 and 100, -1 to disable.
777 * \param screen Screen ID
778 * \param arg unused arg
779 * \ingroup ui_callback
782 uicb_client_settrans(int screen
__attribute__ ((unused
)), char *arg
)
784 double delta
= 1.0, current_opacity
= 1.0;
788 unsigned long n
, left
;
789 unsigned int current_opacity_raw
= 0;
791 Client
*sel
= globalconf
.focus
->client
;
796 XGetWindowProperty(globalconf
.display
, sel
->win
,
797 XInternAtom(globalconf
.display
, "_NET_WM_WINDOW_OPACITY", False
),
798 0L, 1L, False
, XA_CARDINAL
, &actual
, &format
, &n
, &left
,
799 (unsigned char **) &data
);
802 memcpy(¤t_opacity_raw
, data
, sizeof(unsigned int));
804 current_opacity
= current_opacity_raw
/ 0xffffffff;
809 delta
= compute_new_value_from_arg(arg
, current_opacity
);
819 if(delta
== 1.0 && !set_prop
)
820 window_settrans(sel
->win
, -1);
822 window_settrans(sel
->win
, delta
);
825 /** Find a visible client on screen. Return next client or previous client if
827 * \param sel current selected client
828 * \param reverse return previous instead of next if true
829 * \return next or previous client
832 client_find_visible(Client
*sel
, Bool reverse
)
835 Client
*(*client_iter
)(Client
**, Client
*) = client_list_next_cycle
;
837 if(!sel
) return NULL
;
840 client_iter
= client_list_prev_cycle
;
842 /* look for previous or next starting at sel */
844 for(next
= client_iter(&globalconf
.clients
, sel
);
845 next
&& next
!= sel
&& (next
->skip
|| !client_isvisible(next
, sel
->screen
));
846 next
= client_iter(&globalconf
.clients
, next
));
851 /** Swap the currently focused client with the previous visible one.
852 * \param screen Screen ID
854 * \ingroup ui_callback
857 uicb_client_swapprev(int screen
__attribute__ ((unused
)), char *arg
__attribute__ ((unused
)))
861 if((prev
= client_find_visible(globalconf
.focus
->client
, True
)))
863 client_list_swap(&globalconf
.clients
, prev
, globalconf
.focus
->client
);
864 globalconf
.screens
[prev
->screen
].need_arrange
= True
;
868 /** Swap the currently focused client with the next visible one.
869 * \param screen Screen ID
871 * \ingroup ui_callback
874 uicb_client_swapnext(int screen
__attribute__ ((unused
)), char *arg
__attribute__ ((unused
)))
878 if((next
= client_find_visible(globalconf
.focus
->client
, False
)))
880 client_list_swap(&globalconf
.clients
, globalconf
.focus
->client
, next
);
881 globalconf
.screens
[next
->screen
].need_arrange
= True
;
885 /** Move and resize a client. Argument should be in format "x y w h" with
886 * absolute (1, 20, 300, ...) or relative (+10, -200, ...) values.
887 * \param screen Screen ID
889 * \ingroup ui_callback
892 uicb_client_moveresize(int screen
, char *arg
)
894 int ox
, oy
, ow
, oh
; /* old geometry */
895 char x
[8], y
[8], w
[8], h
[8];
896 int mx
, my
, dx
, dy
, nmx
, nmy
;
900 Client
*sel
= globalconf
.focus
->client
;
901 Layout
*curlay
= layout_get_current(screen
);
903 if(!sel
|| sel
->isfixed
|| !arg
||
904 (curlay
->arrange
!= layout_floating
&& !sel
->isfloating
))
907 if(sscanf(arg
, "%s %s %s %s", x
, y
, w
, h
) != 4)
910 geometry
.x
= (int) compute_new_value_from_arg(x
, sel
->geometry
.x
);
911 geometry
.y
= (int) compute_new_value_from_arg(y
, sel
->geometry
.y
);
912 geometry
.width
= (int) compute_new_value_from_arg(w
, sel
->geometry
.width
);
913 geometry
.height
= (int) compute_new_value_from_arg(h
, sel
->geometry
.height
);
915 ox
= sel
->geometry
.x
;
916 oy
= sel
->geometry
.y
;
917 ow
= sel
->geometry
.width
;
918 oh
= sel
->geometry
.height
;
920 Bool xqp
= XQueryPointer(globalconf
.display
,
921 RootWindow(globalconf
.display
,
923 &dummy
, &dummy
, &mx
, &my
, &dx
, &dy
, &dui
);
924 if(globalconf
.screens
[sel
->screen
].resize_hints
)
925 geometry
= client_geometry_hints(sel
, geometry
);
926 client_resize(sel
, geometry
, False
);
927 if (xqp
&& ox
<= mx
&& (ox
+ 2 * sel
->border
+ ow
) >= mx
&&
928 oy
<= my
&& (oy
+ 2 * sel
->border
+ oh
) >= my
)
930 nmx
= mx
- (ox
+ sel
->border
) + sel
->geometry
.width
- ow
;
931 nmy
= my
- (oy
+ sel
->border
) + sel
->geometry
.height
- oh
;
933 if(nmx
< -sel
->border
) /* can happen on a resize */
935 if(nmy
< -sel
->border
)
938 XWarpPointer(globalconf
.display
,
940 0, 0, 0, 0, nmx
, nmy
);
944 /** Kill a client via a WM_DELETE_WINDOW request or XKillClient if not
946 * \param c the client to kill
949 client_kill(Client
*c
)
953 if(client_isprotodel(globalconf
.display
, c
->win
))
955 ev
.type
= ClientMessage
;
956 ev
.xclient
.window
= c
->win
;
957 ev
.xclient
.message_type
= XInternAtom(globalconf
.display
, "WM_PROTOCOLS", False
);
958 ev
.xclient
.format
= 32;
959 ev
.xclient
.data
.l
[0] = XInternAtom(globalconf
.display
, "WM_DELETE_WINDOW", False
);
960 ev
.xclient
.data
.l
[1] = CurrentTime
;
961 XSendEvent(globalconf
.display
, c
->win
, False
, NoEventMask
, &ev
);
964 XKillClient(globalconf
.display
, c
->win
);
967 /** Kill the currently focused client.
968 * \param screen Screen ID
970 * \ingroup ui_callback
973 uicb_client_kill(int screen
__attribute__ ((unused
)), char *arg
__attribute__ ((unused
)))
975 Client
*sel
= globalconf
.focus
->client
;
981 /** Maximize the client to the given geometry.
982 * \param c the client to maximize
983 * \param geometry the geometry to use for maximizing
986 client_maximize(Client
*c
, area_t geometry
)
988 if((c
->ismax
= !c
->ismax
))
990 /* disable titlebar */
991 c
->titlebar
.position
= Off
;
992 c
->wasfloating
= c
->isfloating
;
993 c
->m_geometry
= c
->geometry
;
994 if(layout_get_current(c
->screen
)->arrange
!= layout_floating
)
995 client_setfloating(c
, True
);
996 client_focus(c
, c
->screen
, True
);
997 client_resize(c
, geometry
, False
);
999 else if(c
->wasfloating
)
1001 c
->titlebar
.position
= c
->titlebar
.dposition
;
1002 client_setfloating(c
, True
);
1003 client_resize(c
, c
->m_geometry
, False
);
1005 else if(layout_get_current(c
->screen
)->arrange
== layout_floating
)
1007 c
->titlebar
.position
= c
->titlebar
.dposition
;
1008 client_resize(c
, c
->m_geometry
, False
);
1012 c
->titlebar
.position
= c
->titlebar
.dposition
;
1013 client_setfloating(c
, False
);
1015 widget_invalidate_cache(c
->screen
, WIDGET_CACHE_CLIENTS
);
1018 /** Toggle maximization state for the focused client.
1019 * \param screen Screen ID
1021 * \ingroup ui_callback
1024 uicb_client_togglemax(int screen
, char *arg
__attribute__ ((unused
)))
1026 Client
*sel
= globalconf
.focus
->client
;
1027 area_t area
= screen_get_area(screen
,
1028 globalconf
.screens
[screen
].statusbar
,
1029 &globalconf
.screens
[screen
].padding
);
1033 area
.width
-= 2 * sel
->border
;
1034 area
.height
-= 2 * sel
->border
;
1035 client_maximize(sel
, area
);
1039 /** Toggle vertical maximization for the focused client.
1040 * \param screen Screen ID
1042 * \ingroup ui_callback
1045 uicb_client_toggleverticalmax(int screen
, char *arg
__attribute__ ((unused
)))
1047 Client
*sel
= globalconf
.focus
->client
;
1048 area_t area
= screen_get_area(screen
,
1049 globalconf
.screens
[screen
].statusbar
,
1050 &globalconf
.screens
[screen
].padding
);
1054 area
.x
= sel
->geometry
.x
;
1055 area
.width
= sel
->geometry
.width
;
1056 area
.height
-= 2 * sel
->border
;
1057 client_maximize(sel
, area
);
1062 /** Toggle horizontal maximization for the focused client.
1063 * \param screen Screen ID
1065 * \ingroup ui_callback
1068 uicb_client_togglehorizontalmax(int screen
, char *arg
__attribute__ ((unused
)))
1070 Client
*sel
= globalconf
.focus
->client
;
1071 area_t area
= screen_get_area(screen
,
1072 globalconf
.screens
[screen
].statusbar
,
1073 &globalconf
.screens
[screen
].padding
);
1077 area
.y
= sel
->geometry
.y
;
1078 area
.height
= sel
->geometry
.height
;
1079 area
.width
-= 2 * sel
->border
;
1080 client_maximize(sel
, area
);
1084 /** Move the client to the master area.
1085 * \param screen Screen ID
1087 * \ingroup ui_callback
1090 uicb_client_zoom(int screen
, char *arg
__attribute__ ((unused
)))
1092 Client
*c
, *sel
= globalconf
.focus
->client
;
1097 for(c
= globalconf
.clients
; !client_isvisible(c
, screen
); c
= c
->next
);
1099 for(sel
= sel
->next
; sel
&& !client_isvisible(sel
, screen
); sel
= sel
->next
);
1103 client_list_detach(&globalconf
.clients
, sel
);
1104 client_list_push(&globalconf
.clients
, sel
);
1105 globalconf
.screens
[screen
].need_arrange
= True
;
1109 /** Give focus to the next visible client in the stack.
1110 * \param screen Screen ID
1112 * \ingroup ui_callback
1115 uicb_client_focusnext(int screen
, char *arg
__attribute__ ((unused
)))
1119 if((next
= client_find_visible(globalconf
.focus
->client
, False
)))
1120 client_focus(next
, screen
, True
);
1123 /** Give focus to the previous visible client in the stack.
1124 * \param screen Screen ID
1126 * \ingroup ui_callback
1129 uicb_client_focusprev(int screen
, char *arg
__attribute__ ((unused
)))
1133 if((prev
= client_find_visible(globalconf
.focus
->client
, True
)))
1134 client_focus(prev
, screen
, True
);
1137 /** Toggle the floating state of the focused client.
1138 * \param screen Screen ID
1140 * \ingroup ui_callback
1143 uicb_client_togglefloating(int screen
__attribute__ ((unused
)), char *arg
__attribute__ ((unused
)))
1145 if(globalconf
.focus
->client
)
1146 client_setfloating(globalconf
.focus
->client
, !globalconf
.focus
->client
->isfloating
);
1149 /** Toggle the scratch client attribute on the focused client.
1150 * \param screen screen number
1151 * \param arg unused argument
1152 * \ingroup ui_callback
1155 uicb_client_setscratch(int screen
, char *arg
__attribute__ ((unused
)))
1157 if(!globalconf
.focus
->client
)
1160 if(globalconf
.scratch
.client
== globalconf
.focus
->client
)
1161 globalconf
.scratch
.client
= NULL
;
1163 globalconf
.scratch
.client
= globalconf
.focus
->client
;
1165 widget_invalidate_cache(screen
, WIDGET_CACHE_CLIENTS
| WIDGET_CACHE_TAGS
);
1166 globalconf
.screens
[screen
].need_arrange
= True
;
1169 /** Toggle the scratch client's visibility.
1170 * \param screen screen number
1171 * \param arg unused argument
1172 * \ingroup ui_callback
1175 uicb_client_togglescratch(int screen
, char *arg
__attribute__ ((unused
)))
1177 if(globalconf
.scratch
.client
)
1179 globalconf
.scratch
.isvisible
= !globalconf
.scratch
.isvisible
;
1180 if(globalconf
.scratch
.isvisible
)
1181 client_focus(globalconf
.scratch
.client
, screen
, True
);
1182 globalconf
.screens
[globalconf
.scratch
.client
->screen
].need_arrange
= True
;
1183 widget_invalidate_cache(globalconf
.scratch
.client
->screen
, WIDGET_CACHE_CLIENTS
);
1187 // vim: filetype=c:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=80