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_focused
!= -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
;
304 c
= p_new(Client
, 1);
306 c
->screen
= screen_get_bycoord(globalconf
.screens_info
, screen
, wa
->x
, wa
->y
);
308 if(globalconf
.screens_info
->xinerama_is_active
)
309 c
->phys_screen
= DefaultScreen(globalconf
.display
);
311 c
->phys_screen
= c
->screen
;
315 c
->geometry
.x
= c
->f_geometry
.x
= c
->m_geometry
.x
= wa
->x
;
316 c
->geometry
.y
= c
->f_geometry
.y
= c
->m_geometry
.y
= wa
->y
;
317 c
->geometry
.width
= c
->f_geometry
.width
= c
->m_geometry
.width
= wa
->width
;
318 c
->geometry
.height
= c
->f_geometry
.height
= c
->m_geometry
.height
= wa
->height
;
319 c
->oldborder
= wa
->border_width
;
322 /* Set windows borders */
323 wc
.border_width
= c
->border
= globalconf
.screens
[screen
].borderpx
;
324 XConfigureWindow(globalconf
.display
, w
, CWBorderWidth
, &wc
);
325 XSetWindowBorder(globalconf
.display
, w
, c
->border
);
326 /* propagates border_width, if size doesn't change */
327 window_configure(c
->win
, c
->geometry
, c
->border
);
329 /* update window title */
330 client_updatetitle(c
);
333 flags
= client_updatesizehints(c
);
334 client_updatewmhints(c
);
336 /* Try to load props if any */
337 if(!(retloadprops
= client_loadprops(c
, screen
)))
338 move_client_to_screen(c
, screen
, True
);
340 /* Then check clients hints */
341 ewmh_check_client_hints(c
);
343 /* default titlebar position */
344 c
->titlebar
= globalconf
.screens
[screen
].titlebar_default
;
346 /* get the matching rule if any */
347 rule
= rule_matching_client(c
);
349 /* Then apply rules if no props */
350 if(!retloadprops
&& rule
)
352 if(rule
->screen
!= RULE_NOSCREEN
)
353 move_client_to_screen(c
, rule
->screen
, True
);
354 tag_client_with_rule(c
, rule
);
356 switch(rule
->isfloating
)
361 client_setfloating(c
, True
);
364 client_setfloating(c
, False
);
368 if(rule
->opacity
>= 0.0f
)
369 window_settrans(c
->win
, rule
->opacity
);
372 /* check for transient and set tags like its parent,
373 * XGetTransientForHint returns 1 on success
375 if((rettrans
= XGetTransientForHint(globalconf
.display
, w
, &trans
))
376 && (t
= client_get_bywin(globalconf
.clients
, trans
)))
377 for(tag
= globalconf
.screens
[c
->screen
].tags
; tag
; tag
= tag
->next
)
378 if(is_client_tagged(t
, tag
))
381 /* should be floating if transsient or fixed */
382 if(rettrans
|| c
->isfixed
)
383 client_setfloating(c
, True
);
386 if(rule
&& rule
->titlebar
.position
!= Auto
)
387 c
->titlebar
= rule
->titlebar
;
391 if(!retloadprops
&& !(flags
& (USPosition
| PPosition
)))
393 if(c
->isfloating
&& !c
->ismax
)
394 client_resize(c
, globalconf
.screens
[c
->screen
].floating_placement(c
), False
);
396 c
->f_geometry
= globalconf
.screens
[c
->screen
].floating_placement(c
);
399 /* 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 widget_invalidate_cache(c
->screen
, WIDGET_CACHE_CLIENTS
);
435 ewmh_update_net_client_list(c
->phys_screen
);
439 client_geometry_hints(Client
*c
, area_t geometry
)
441 double dx
, dy
, max
, min
, ratio
;
443 if(c
->minay
> 0 && c
->maxay
> 0 && (geometry
.height
- c
->baseh
) > 0
444 && (geometry
.width
- c
->basew
) > 0)
446 dx
= (double) (geometry
.width
- c
->basew
);
447 dy
= (double) (geometry
.height
- c
->baseh
);
448 min
= (double) (c
->minax
) / (double) (c
->minay
);
449 max
= (double) (c
->maxax
) / (double) (c
->maxay
);
451 if(max
> 0 && min
> 0 && ratio
> 0)
455 dy
= (dx
* min
+ dy
) / (min
* min
+ 1);
457 geometry
.width
= (int) dx
+ c
->basew
;
458 geometry
.height
= (int) dy
+ c
->baseh
;
462 dy
= (dx
* min
+ dy
) / (max
* max
+ 1);
464 geometry
.width
= (int) dx
+ c
->basew
;
465 geometry
.height
= (int) dy
+ c
->baseh
;
469 if(c
->minw
&& geometry
.width
< c
->minw
)
470 geometry
.width
= c
->minw
;
471 if(c
->minh
&& geometry
.height
< c
->minh
)
472 geometry
.height
= c
->minh
;
473 if(c
->maxw
&& geometry
.width
> c
->maxw
)
474 geometry
.width
= c
->maxw
;
475 if(c
->maxh
&& geometry
.height
> c
->maxh
)
476 geometry
.height
= c
->maxh
;
478 geometry
.width
-= (geometry
.width
- c
->basew
) % c
->incw
;
480 geometry
.height
-= (geometry
.height
- c
->baseh
) % c
->inch
;
485 /** Resize client window
486 * \param c client to resize
487 * \param geometry new window geometry
488 * \param hints use resize hints
489 * \param return True if resize has been done
492 client_resize(Client
*c
, area_t geometry
, Bool hints
)
497 Layout
*layout
= layout_get_current(c
->screen
);
498 Bool resized
= False
;
500 if(!c
->ismoving
&& !c
->isfloating
&& layout
->arrange
!= layout_floating
)
502 titlebar_update_geometry(c
, geometry
);
503 geometry
= titlebar_geometry_remove(&c
->titlebar
, geometry
);
507 geometry
= client_geometry_hints(c
, geometry
);
509 if(geometry
.width
<= 0 || geometry
.height
<= 0)
512 /* offscreen appearance fixes */
513 area
= get_display_area(c
->phys_screen
, NULL
,
514 &globalconf
.screens
[c
->screen
].padding
);
516 if(geometry
.x
> area
.width
)
517 geometry
.x
= area
.width
- geometry
.width
- 2 * c
->border
;
518 if(geometry
.y
> area
.height
)
519 geometry
.y
= area
.height
- geometry
.height
- 2 * c
->border
;
520 if(geometry
.x
+ geometry
.width
+ 2 * c
->border
< 0)
522 if(geometry
.y
+ geometry
.height
+ 2 * c
->border
< 0)
525 if(c
->geometry
.x
!= geometry
.x
|| c
->geometry
.y
!= geometry
.y
526 || c
->geometry
.width
!= geometry
.width
|| c
->geometry
.height
!= geometry
.height
)
529 screen_get_bycoord(globalconf
.screens_info
, c
->screen
, geometry
.x
, geometry
.y
);
531 c
->geometry
.x
= wc
.x
= geometry
.x
;
532 c
->geometry
.width
= wc
.width
= geometry
.width
;
533 c
->geometry
.y
= wc
.y
= geometry
.y
;
534 c
->geometry
.height
= wc
.height
= geometry
.height
;
535 wc
.border_width
= c
->border
;
537 /* save the floating geometry if the window is floating but not
539 if(c
->ismoving
|| c
->isfloating
540 || layout_get_current(new_screen
)->arrange
== layout_floating
)
543 c
->f_geometry
= geometry
;
544 titlebar_update_geometry_floating(c
);
547 XConfigureWindow(globalconf
.display
, c
->win
,
548 CWX
| CWY
| CWWidth
| CWHeight
| CWBorderWidth
, &wc
);
549 window_configure(c
->win
, geometry
, c
->border
);
551 if(c
->screen
!= new_screen
)
552 move_client_to_screen(c
, new_screen
, False
);
557 /* call it again like it was floating,
558 * we want it to be sticked to the window */
559 if(!c
->ismoving
&& !c
->isfloating
&& layout
->arrange
!= layout_floating
)
560 titlebar_update_geometry_floating(c
);
566 client_setfloating(Client
*c
, Bool floating
)
568 if(c
->isfloating
!= floating
)
570 if((c
->isfloating
= floating
))
572 client_resize(c
, c
->f_geometry
, False
);
573 XRaiseWindow(globalconf
.display
, c
->win
);
578 client_resize(c
, c
->m_geometry
, False
);
580 if(client_isvisible(c
, c
->screen
))
581 globalconf
.screens
[c
->screen
].need_arrange
= True
;
582 widget_invalidate_cache(c
->screen
, WIDGET_CACHE_CLIENTS
);
587 /** Save client properties as an X property
591 client_saveprops(Client
*c
)
593 int i
= 0, ntags
= 0;
597 for(tag
= globalconf
.screens
[c
->screen
].tags
; tag
; tag
= tag
->next
)
600 prop
= p_new(char, ntags
+ 2);
602 for(tag
= globalconf
.screens
[c
->screen
].tags
; tag
; tag
= tag
->next
, i
++)
603 prop
[i
] = is_client_tagged(c
, tag
) ? '1' : '0';
606 prop
[i
] = c
->isfloating
? '1' : '0';
610 XChangeProperty(globalconf
.display
, c
->win
,
611 XInternAtom(globalconf
.display
, "_AWESOME_PROPERTIES", False
),
612 XA_STRING
, 8, PropModeReplace
, (unsigned char *) prop
, i
);
618 client_unban(Client
*c
)
620 XMapWindow(globalconf
.display
, c
->win
);
621 window_setstate(c
->win
, NormalState
);
622 if(c
->titlebar
.sw
&& c
->titlebar
.position
!= Off
)
623 XMapWindow(globalconf
.display
, c
->titlebar
.sw
->window
);
627 client_unmanage(Client
*c
)
632 wc
.border_width
= c
->oldborder
;
634 /* The server grab construct avoids race conditions. */
635 XGrabServer(globalconf
.display
);
637 XConfigureWindow(globalconf
.display
, c
->win
, CWBorderWidth
, &wc
); /* restore border */
639 /* remove client everywhere */
640 client_list_detach(&globalconf
.clients
, c
);
641 focus_delete_client(c
);
642 if(globalconf
.scratch
.client
== c
)
643 globalconf
.scratch
.client
= NULL
;
644 for(tag
= globalconf
.screens
[c
->screen
].tags
; tag
; tag
= tag
->next
)
645 untag_client(c
, tag
);
647 if(globalconf
.focus
->client
== c
)
648 client_focus(NULL
, c
->screen
, True
);
650 XUngrabButton(globalconf
.display
, AnyButton
, AnyModifier
, c
->win
);
651 window_setstate(c
->win
, WithdrawnState
);
653 XSync(globalconf
.display
, False
);
654 XUngrabServer(globalconf
.display
);
657 simplewindow_delete(&c
->titlebar
.sw
);
663 client_updatewmhints(Client
*c
)
667 if((wmh
= XGetWMHints(globalconf
.display
, c
->win
)))
669 if((c
->isurgent
= ((wmh
->flags
& XUrgencyHint
) && globalconf
.focus
->client
!= c
)))
671 widget_invalidate_cache(c
->screen
, WIDGET_CACHE_CLIENTS
);
674 if((wmh
->flags
& StateHint
) && wmh
->initial_state
== WithdrawnState
)
684 client_updatesizehints(Client
*c
)
689 if(!XGetWMNormalHints(globalconf
.display
, c
->win
, &size
, &msize
))
692 if(size
.flags
& PBaseSize
)
694 c
->basew
= size
.base_width
;
695 c
->baseh
= size
.base_height
;
697 else if(size
.flags
& PMinSize
)
699 c
->basew
= size
.min_width
;
700 c
->baseh
= size
.min_height
;
703 c
->basew
= c
->baseh
= 0;
704 if(size
.flags
& PResizeInc
)
706 c
->incw
= size
.width_inc
;
707 c
->inch
= size
.height_inc
;
710 c
->incw
= c
->inch
= 0;
712 if(size
.flags
& PMaxSize
)
714 c
->maxw
= size
.max_width
;
715 c
->maxh
= size
.max_height
;
718 c
->maxw
= c
->maxh
= 0;
720 if(size
.flags
& PMinSize
)
722 c
->minw
= size
.min_width
;
723 c
->minh
= size
.min_height
;
725 else if(size
.flags
& PBaseSize
)
727 c
->minw
= size
.base_width
;
728 c
->minh
= size
.base_height
;
731 c
->minw
= c
->minh
= 0;
733 if(size
.flags
& PAspect
)
735 c
->minax
= size
.min_aspect
.x
;
736 c
->maxax
= size
.max_aspect
.x
;
737 c
->minay
= size
.min_aspect
.y
;
738 c
->maxay
= size
.max_aspect
.y
;
741 c
->minax
= c
->maxax
= c
->minay
= c
->maxay
= 0;
743 if(c
->maxw
&& c
->minw
&& c
->maxh
&& c
->minh
744 && c
->maxw
== c
->minw
&& c
->maxh
== c
->minh
)
750 /** Returns True if a client is tagged
751 * with one of the tags
752 * \return True or False
755 client_isvisible(Client
*c
, int screen
)
759 if(!c
|| c
->screen
!= screen
)
762 if(globalconf
.scratch
.client
== c
)
763 return globalconf
.scratch
.isvisible
;
765 for(tag
= globalconf
.screens
[screen
].tags
; tag
; tag
= tag
->next
)
766 if(tag
->selected
&& is_client_tagged(c
, tag
))
771 /** Set selected client transparency.
772 * Argument should be a floating between 0 and 100, -1 to disable.
773 * \param screen Screen ID
774 * \param arg unused arg
775 * \ingroup ui_callback
778 uicb_client_settrans(int screen
__attribute__ ((unused
)), char *arg
)
780 double delta
= 1.0, current_opacity
= 1.0;
784 unsigned long n
, left
;
785 unsigned int current_opacity_raw
= 0;
787 Client
*sel
= globalconf
.focus
->client
;
792 XGetWindowProperty(globalconf
.display
, sel
->win
,
793 XInternAtom(globalconf
.display
, "_NET_WM_WINDOW_OPACITY", False
),
794 0L, 1L, False
, XA_CARDINAL
, &actual
, &format
, &n
, &left
,
795 (unsigned char **) &data
);
798 memcpy(¤t_opacity_raw
, data
, sizeof(unsigned int));
800 current_opacity
= current_opacity_raw
/ 0xffffffff;
805 delta
= compute_new_value_from_arg(arg
, current_opacity
);
815 if(delta
== 1.0 && !set_prop
)
816 window_settrans(sel
->win
, -1);
818 window_settrans(sel
->win
, delta
);
821 /** Find a visible client on screen. Return next client or previous client if
823 * \param sel current selected client
824 * \param reverse return previous instead of next if true
825 * \return next or previous client
828 client_find_visible(Client
*sel
, Bool reverse
)
831 Client
*(*client_iter
)(Client
**, Client
*) = client_list_next_cycle
;
833 if(!sel
) return NULL
;
836 client_iter
= client_list_prev_cycle
;
838 /* look for previous or next starting at sel */
840 for(next
= client_iter(&globalconf
.clients
, sel
);
841 next
&& next
!= sel
&& (next
->skip
|| !client_isvisible(next
, sel
->screen
));
842 next
= client_iter(&globalconf
.clients
, next
));
847 /** Swap currently focused client with previous visible.
848 * \param screen Screen ID
850 * \ingroup ui_callback
853 uicb_client_swapprev(int screen
__attribute__ ((unused
)), char *arg
__attribute__ ((unused
)))
857 if((prev
= client_find_visible(globalconf
.focus
->client
, True
)))
859 client_list_swap(&globalconf
.clients
, prev
, globalconf
.focus
->client
);
860 globalconf
.screens
[prev
->screen
].need_arrange
= True
;
864 /** Swap currently focused client with next visible.
865 * \param screen Screen ID
867 * \ingroup ui_callback
870 uicb_client_swapnext(int screen
__attribute__ ((unused
)), char *arg
__attribute__ ((unused
)))
874 if((next
= client_find_visible(globalconf
.focus
->client
, False
)))
876 client_list_swap(&globalconf
.clients
, globalconf
.focus
->client
, next
);
877 globalconf
.screens
[next
->screen
].need_arrange
= True
;
881 /** Move and resize a client. Argument should be in format "x y w h" with
882 * absolute (1, 20, 300, ...) or relatives (+10, -200, ...) values.
883 * \param screen Screen ID
885 * \ingroup ui_callback
888 uicb_client_moveresize(int screen
, char *arg
)
890 int ox
, oy
, ow
, oh
; /* old geometry */
891 char x
[8], y
[8], w
[8], h
[8];
892 int mx
, my
, dx
, dy
, nmx
, nmy
;
896 Client
*sel
= globalconf
.focus
->client
;
897 Layout
*curlay
= layout_get_current(screen
);
899 if(!sel
|| sel
->isfixed
|| !arg
||
900 (curlay
->arrange
!= layout_floating
&& !sel
->isfloating
))
903 if(sscanf(arg
, "%s %s %s %s", x
, y
, w
, h
) != 4)
906 geometry
.x
= (int) compute_new_value_from_arg(x
, sel
->geometry
.x
);
907 geometry
.y
= (int) compute_new_value_from_arg(y
, sel
->geometry
.y
);
908 geometry
.width
= (int) compute_new_value_from_arg(w
, sel
->geometry
.width
);
909 geometry
.height
= (int) compute_new_value_from_arg(h
, sel
->geometry
.height
);
911 ox
= sel
->geometry
.x
;
912 oy
= sel
->geometry
.y
;
913 ow
= sel
->geometry
.width
;
914 oh
= sel
->geometry
.height
;
916 Bool xqp
= XQueryPointer(globalconf
.display
,
917 RootWindow(globalconf
.display
,
919 &dummy
, &dummy
, &mx
, &my
, &dx
, &dy
, &dui
);
920 if(globalconf
.screens
[sel
->screen
].resize_hints
)
921 geometry
= client_geometry_hints(sel
, geometry
);
922 client_resize(sel
, geometry
, False
);
923 if (xqp
&& ox
<= mx
&& (ox
+ 2 * sel
->border
+ ow
) >= mx
&&
924 oy
<= my
&& (oy
+ 2 * sel
->border
+ oh
) >= my
)
926 nmx
= mx
- (ox
+ sel
->border
) + sel
->geometry
.width
- ow
;
927 nmy
= my
- (oy
+ sel
->border
) + sel
->geometry
.height
- oh
;
929 if(nmx
< -sel
->border
) /* can happen on a resize */
931 if(nmy
< -sel
->border
)
934 XWarpPointer(globalconf
.display
,
936 0, 0, 0, 0, nmx
, nmy
);
940 /** Kill a client via a WM_DELETE_WINDOW request or XKillClient if not
942 * \param c the client to kill
945 client_kill(Client
*c
)
949 if(client_isprotodel(globalconf
.display
, c
->win
))
951 ev
.type
= ClientMessage
;
952 ev
.xclient
.window
= c
->win
;
953 ev
.xclient
.message_type
= XInternAtom(globalconf
.display
, "WM_PROTOCOLS", False
);
954 ev
.xclient
.format
= 32;
955 ev
.xclient
.data
.l
[0] = XInternAtom(globalconf
.display
, "WM_DELETE_WINDOW", False
);
956 ev
.xclient
.data
.l
[1] = CurrentTime
;
957 XSendEvent(globalconf
.display
, c
->win
, False
, NoEventMask
, &ev
);
960 XKillClient(globalconf
.display
, c
->win
);
963 /** Kill the currently focused client.
964 * \param screen Screen ID
966 * \ingroup ui_callback
969 uicb_client_kill(int screen
__attribute__ ((unused
)), char *arg
__attribute__ ((unused
)))
971 Client
*sel
= globalconf
.focus
->client
;
977 /** Maximize the client to the given geometry.
978 * \param c the client to maximize
979 * \param geometry the geometry to use for maximizing
982 client_maximize(Client
*c
, area_t geometry
)
984 if((c
->ismax
= !c
->ismax
))
986 /* disable titlebar */
987 c
->titlebar
.position
= Off
;
988 c
->wasfloating
= c
->isfloating
;
989 c
->m_geometry
= c
->geometry
;
990 if(layout_get_current(c
->screen
)->arrange
!= layout_floating
)
991 client_setfloating(c
, True
);
992 client_focus(c
, c
->screen
, True
);
993 client_resize(c
, geometry
, False
);
995 else if(c
->wasfloating
)
997 c
->titlebar
.position
= c
->titlebar
.dposition
;
998 client_setfloating(c
, True
);
999 client_resize(c
, c
->m_geometry
, False
);
1001 else if(layout_get_current(c
->screen
)->arrange
== layout_floating
)
1003 c
->titlebar
.position
= c
->titlebar
.dposition
;
1004 client_resize(c
, c
->m_geometry
, False
);
1008 c
->titlebar
.position
= c
->titlebar
.dposition
;
1009 client_setfloating(c
, False
);
1011 widget_invalidate_cache(c
->screen
, WIDGET_CACHE_CLIENTS
);
1014 /** Toggle maximization state for the focused client.
1015 * \param screen Screen ID
1017 * \ingroup ui_callback
1020 uicb_client_togglemax(int screen
, char *arg
__attribute__ ((unused
)))
1022 Client
*sel
= globalconf
.focus
->client
;
1023 area_t area
= screen_get_area(screen
,
1024 globalconf
.screens
[screen
].statusbar
,
1025 &globalconf
.screens
[screen
].padding
);
1029 area
.width
-= 2 * sel
->border
;
1030 area
.height
-= 2 * sel
->border
;
1031 client_maximize(sel
, area
);
1035 /** Toggle vertical maximization for the focused client.
1036 * \param screen Screen ID
1038 * \ingroup ui_callback
1041 uicb_client_toggleverticalmax(int screen
, char *arg
__attribute__ ((unused
)))
1043 Client
*sel
= globalconf
.focus
->client
;
1044 area_t area
= screen_get_area(screen
,
1045 globalconf
.screens
[screen
].statusbar
,
1046 &globalconf
.screens
[screen
].padding
);
1050 area
.x
= sel
->geometry
.x
;
1051 area
.width
= sel
->geometry
.width
;
1052 area
.height
-= 2 * sel
->border
;
1053 client_maximize(sel
, area
);
1058 /** Toggle horizontal maximization for the focused client.
1059 * \param screen Screen ID
1061 * \ingroup ui_callback
1064 uicb_client_togglehorizontalmax(int screen
, char *arg
__attribute__ ((unused
)))
1066 Client
*sel
= globalconf
.focus
->client
;
1067 area_t area
= screen_get_area(screen
,
1068 globalconf
.screens
[screen
].statusbar
,
1069 &globalconf
.screens
[screen
].padding
);
1073 area
.y
= sel
->geometry
.y
;
1074 area
.height
= sel
->geometry
.height
;
1075 area
.width
-= 2 * sel
->border
;
1076 client_maximize(sel
, area
);
1080 /** Set the client the master window.
1081 * \param screen Screen ID
1083 * \ingroup ui_callback
1086 uicb_client_zoom(int screen
, char *arg
__attribute__ ((unused
)))
1088 Client
*c
, *sel
= globalconf
.focus
->client
;
1093 for(c
= globalconf
.clients
; !client_isvisible(c
, screen
); c
= c
->next
);
1095 for(sel
= sel
->next
; sel
&& !client_isvisible(sel
, screen
); sel
= sel
->next
);
1099 client_list_detach(&globalconf
.clients
, sel
);
1100 client_list_push(&globalconf
.clients
, sel
);
1101 globalconf
.screens
[screen
].need_arrange
= True
;
1105 /** Setfocus to the next visible client in the stack.
1106 * \param screen Screen ID
1108 * \ingroup ui_callback
1111 uicb_client_focusnext(int screen
, char *arg
__attribute__ ((unused
)))
1115 if((next
= client_find_visible(globalconf
.focus
->client
, False
)))
1116 client_focus(next
, screen
, True
);
1119 /** Setfocus to the previous visible client in the stack.
1120 * \param screen Screen ID
1122 * \ingroup ui_callback
1125 uicb_client_focusprev(int screen
, char *arg
__attribute__ ((unused
)))
1129 if((prev
= client_find_visible(globalconf
.focus
->client
, True
)))
1130 client_focus(prev
, screen
, True
);
1133 /** Toggle the floating state of the focused client.
1134 * \param screen Screen ID
1136 * \ingroup ui_callback
1139 uicb_client_togglefloating(int screen
__attribute__ ((unused
)), char *arg
__attribute__ ((unused
)))
1141 if(globalconf
.focus
->client
)
1142 client_setfloating(globalconf
.focus
->client
, !globalconf
.focus
->client
->isfloating
);
1145 /** Toggle the scratch client attribute on the focused client.
1146 * \param screen screen number
1147 * \param arg unused argument
1148 * \ingroup ui_callback
1151 uicb_client_setscratch(int screen
, char *arg
__attribute__ ((unused
)))
1153 if(!globalconf
.focus
->client
)
1156 if(globalconf
.scratch
.client
== globalconf
.focus
->client
)
1157 globalconf
.scratch
.client
= NULL
;
1159 globalconf
.scratch
.client
= globalconf
.focus
->client
;
1161 widget_invalidate_cache(screen
, WIDGET_CACHE_CLIENTS
| WIDGET_CACHE_TAGS
);
1162 globalconf
.screens
[screen
].need_arrange
= True
;
1165 /** Toggle scratch client visibility.
1166 * \param screen screen number
1167 * \param arg unused argument
1168 * \ingroup ui_callback
1171 uicb_client_togglescratch(int screen
, char *arg
__attribute__ ((unused
)))
1173 if(globalconf
.scratch
.client
)
1175 globalconf
.scratch
.isvisible
= !globalconf
.scratch
.isvisible
;
1176 if(globalconf
.scratch
.isvisible
)
1177 client_focus(globalconf
.scratch
.client
, screen
, True
);
1178 globalconf
.screens
[globalconf
.scratch
.client
->screen
].need_arrange
= True
;
1179 widget_invalidate_cache(globalconf
.scratch
.client
->screen
, WIDGET_CACHE_CLIENTS
);
1183 // vim: filetype=c:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=80