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"
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 from_mouse
)
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 /* save sel in focus history */
196 if(globalconf
.screens
[c
->screen
].opacity_unfocused
!= -1)
197 window_settrans(c
->win
, globalconf
.screens
[screen
].opacity_unfocused
);
198 XSetWindowBorder(globalconf
.display
, c
->win
,
199 globalconf
.screens
[screen
].colors_selected
[ColBorder
].pixel
);
200 XSetInputFocus(globalconf
.display
, c
->win
, RevertToPointerRoot
, CurrentTime
);
202 || !globalconf
.screens
[screen
].sloppy_focus
203 || globalconf
.screens
[screen
].sloppy_focus_raise
)
204 XRaiseWindow(globalconf
.display
, c
->win
);
205 /* since we're dropping EnterWindow events and sometimes the window
206 * will appear under the mouse, grabbuttons */
207 window_grabbuttons(phys_screen
, c
->win
);
210 XSetInputFocus(globalconf
.display
,
211 RootWindow(globalconf
.display
, phys_screen
),
212 RevertToPointerRoot
, CurrentTime
);
214 widget_invalidate_cache(screen
, WIDGET_CACHE_CLIENTS
);
215 ewmh_update_net_active_window(phys_screen
);
216 globalconf
.drop_events
|= EnterWindowMask
;
219 /** Compute smart coordinates for a client window
220 * \param geometry current/requested client geometry
221 * \param screen screen used
222 * \return new geometry
225 client_get_smart_geometry(Area geometry
, int border
, int screen
)
228 Area newgeometry
= { 0, 0, 0, 0, NULL
};
229 Area
*screen_geometry
, *arealist
= NULL
, *r
;
232 screen_geometry
= p_new(Area
, 1);
234 *screen_geometry
= screen_get_area(screen
,
235 globalconf
.screens
[screen
].statusbar
,
236 &globalconf
.screens
[screen
].padding
);
238 area_list_push(&arealist
, screen_geometry
);
240 for(c
= globalconf
.clients
; c
; c
= c
->next
)
241 if(client_isvisible(c
, screen
))
243 newgeometry
= c
->f_geometry
;
244 newgeometry
.width
+= 2 * c
->border
;
245 newgeometry
.height
+= 2 * c
->border
;
246 area_list_remove(&arealist
, &newgeometry
);
249 newgeometry
.x
= geometry
.x
;
250 newgeometry
.y
= geometry
.y
;
251 newgeometry
.width
= 0;
252 newgeometry
.height
= 0;
254 for(r
= arealist
; r
; r
= r
->next
)
255 if(r
->width
>= geometry
.width
&& r
->height
>= geometry
.height
256 && r
->width
* r
->height
> newgeometry
.width
* newgeometry
.height
)
262 /* we did not found a space with enough space for our size:
263 * just take the biggest available and go in */
265 for(r
= arealist
; r
; r
= r
->next
)
266 if(r
->width
* r
->height
> newgeometry
.width
* newgeometry
.height
)
269 /* restore height and width */
270 newgeometry
.width
= geometry
.width
;
271 newgeometry
.height
= geometry
.height
;
274 if(AREA_RIGHT(newgeometry
) > AREA_RIGHT(*screen_geometry
))
275 newgeometry
.x
= screen_geometry
->x
+ screen_geometry
->width
- newgeometry
.width
- 2 * border
;
277 if(AREA_BOTTOM(newgeometry
) > AREA_BOTTOM(*screen_geometry
))
278 newgeometry
.y
= screen_geometry
->y
+ screen_geometry
->height
- newgeometry
.height
- 2 * border
;
280 area_list_wipe(&arealist
);
285 /** Manage a new client
286 * \param w The window
287 * \param wa Window attributes
288 * \param screen Screen ID
291 client_manage(Window w
, XWindowAttributes
*wa
, int screen
)
293 Client
*c
, *t
= NULL
;
300 int phys_screen
= get_phys_screen(screen
);
303 c
= p_new(Client
, 1);
305 c
->screen
= screen_get_bycoord(wa
->x
, wa
->y
);
307 screen_geom
= screen_get_area(c
->screen
,
308 globalconf
.screens
[screen
].statusbar
,
309 &globalconf
.screens
[screen
].padding
);
312 c
->geometry
.x
= c
->f_geometry
.x
= c
->m_geometry
.x
= MAX(wa
->x
, screen_geom
.x
);
313 c
->geometry
.y
= c
->f_geometry
.y
= c
->m_geometry
.y
= MAX(wa
->y
, screen_geom
.y
);
314 c
->geometry
.width
= c
->f_geometry
.width
= c
->m_geometry
.width
= wa
->width
;
315 c
->geometry
.height
= c
->f_geometry
.height
= c
->m_geometry
.height
= wa
->height
;
316 c
->oldborder
= wa
->border_width
;
319 c
->border
= globalconf
.screens
[screen
].borderpx
;
321 /* Set windows borders */
322 wc
.border_width
= c
->border
;
323 XConfigureWindow(globalconf
.display
, w
, CWBorderWidth
, &wc
);
324 XSetWindowBorder(globalconf
.display
, w
, globalconf
.screens
[screen
].colors_normal
[ColBorder
].pixel
);
325 /* propagates border_width, if size doesn't change */
326 window_configure(c
->win
, c
->geometry
, c
->border
);
328 /* update window title */
329 client_updatetitle(c
);
332 flags
= client_updatesizehints(c
);
333 client_updatewmhints(c
);
335 /* First check clients hints */
336 ewmh_check_client_hints(c
);
338 /* loadprops or apply rules if no props */
339 if(!client_loadprops(c
, screen
))
341 /* Get the client's rule */
342 if((rule
= rule_matching_client(c
)))
344 if(rule
->screen
!= RULE_NOSCREEN
)
345 move_client_to_screen(c
, rule
->screen
, True
);
347 move_client_to_screen(c
, screen
, True
);
348 tag_client_with_rule(c
, rule
);
350 switch(rule
->isfloating
)
355 client_setfloating(c
, True
);
358 client_setfloating(c
, False
);
362 if(rule
->opacity
>= 0.0f
)
363 window_settrans(c
->win
, rule
->opacity
);
366 move_client_to_screen(c
, screen
, True
);
367 /* check for transient and set tags like its parent,
368 * XGetTransientForHint returns 1 on success
370 if((rettrans
= XGetTransientForHint(globalconf
.display
, w
, &trans
))
371 && (t
= client_get_bywin(globalconf
.clients
, trans
)))
372 for(tag
= globalconf
.screens
[c
->screen
].tags
; tag
; tag
= tag
->next
)
373 if(is_client_tagged(t
, tag
))
376 /* should be floating if transsient or fixed */
378 client_setfloating(c
, rettrans
|| c
->isfixed
);
381 if(!(flags
& (USPosition
| PPosition
)))
382 c
->f_geometry
= client_get_smart_geometry(c
->f_geometry
, c
->border
, c
->screen
);
384 XSelectInput(globalconf
.display
, w
, StructureNotifyMask
| PropertyChangeMask
| EnterWindowMask
);
387 if(globalconf
.have_shape
)
389 XShapeSelectInput(globalconf
.display
, w
, ShapeNotifyMask
);
390 window_setshape(phys_screen
, c
->win
);
393 /* attach to the stack */
394 if((rule
= rule_matching_client(c
)))
395 switch(rule
->ismaster
)
398 client_list_push(&globalconf
.clients
, c
);
401 client_list_append(&globalconf
.clients
, c
);
410 if(globalconf
.screens
[c
->screen
].new_become_master
)
411 client_list_push(&globalconf
.clients
, c
);
413 client_list_append(&globalconf
.clients
, c
);
416 /* some windows require this */
417 XMoveResizeWindow(globalconf
.display
, c
->win
, c
->geometry
.x
, c
->geometry
.y
,
418 c
->geometry
.width
, c
->geometry
.height
);
420 widget_invalidate_cache(c
->screen
, WIDGET_CACHE_CLIENTS
);
421 ewmh_update_net_client_list(phys_screen
);
424 /** Resize client window
425 * \param c client to resize
426 * \param geometry new window geometry
427 * \param sizehints respect size hints
428 * \param return True if resize has been done
431 client_resize(Client
*c
, Area geometry
, Bool sizehints
)
434 double dx
, dy
, max
, min
, ratio
;
440 if(c
->minay
> 0 && c
->maxay
> 0 && (geometry
.height
- c
->baseh
) > 0
441 && (geometry
.width
- c
->basew
) > 0)
443 dx
= (double) (geometry
.width
- c
->basew
);
444 dy
= (double) (geometry
.height
- c
->baseh
);
445 min
= (double) (c
->minax
) / (double) (c
->minay
);
446 max
= (double) (c
->maxax
) / (double) (c
->maxay
);
448 if(max
> 0 && min
> 0 && ratio
> 0)
452 dy
= (dx
* min
+ dy
) / (min
* min
+ 1);
454 geometry
.width
= (int) dx
+ c
->basew
;
455 geometry
.height
= (int) dy
+ c
->baseh
;
459 dy
= (dx
* min
+ dy
) / (max
* max
+ 1);
461 geometry
.width
= (int) dx
+ c
->basew
;
462 geometry
.height
= (int) dy
+ c
->baseh
;
466 if(c
->minw
&& geometry
.width
< c
->minw
)
467 geometry
.width
= c
->minw
;
468 if(c
->minh
&& geometry
.height
< c
->minh
)
469 geometry
.height
= c
->minh
;
470 if(c
->maxw
&& geometry
.width
> c
->maxw
)
471 geometry
.width
= c
->maxw
;
472 if(c
->maxh
&& geometry
.height
> c
->maxh
)
473 geometry
.height
= c
->maxh
;
475 geometry
.width
-= (geometry
.width
- c
->basew
) % c
->incw
;
477 geometry
.height
-= (geometry
.height
- c
->baseh
) % c
->inch
;
479 if(geometry
.width
<= 0 || geometry
.height
<= 0)
481 /* offscreen appearance fixes */
482 area
= get_display_area(get_phys_screen(c
->screen
),
484 &globalconf
.screens
[c
->screen
].padding
);
485 if(geometry
.x
> area
.width
)
486 geometry
.x
= area
.width
- geometry
.width
- 2 * c
->border
;
487 if(geometry
.y
> area
.height
)
488 geometry
.y
= area
.height
- geometry
.height
- 2 * c
->border
;
489 if(geometry
.x
+ geometry
.width
+ 2 * c
->border
< 0)
491 if(geometry
.y
+ geometry
.height
+ 2 * c
->border
< 0)
494 if(c
->geometry
.x
!= geometry
.x
|| c
->geometry
.y
!= geometry
.y
495 || c
->geometry
.width
!= geometry
.width
|| c
->geometry
.height
!= geometry
.height
)
497 new_screen
= screen_get_bycoord(geometry
.x
, geometry
.y
);
499 c
->geometry
.x
= wc
.x
= geometry
.x
;
500 c
->geometry
.y
= wc
.y
= geometry
.y
;
501 c
->geometry
.width
= wc
.width
= geometry
.width
;
502 c
->geometry
.height
= wc
.height
= geometry
.height
;
503 wc
.border_width
= c
->border
;
505 /* save the floating geometry if the window is floating but not
508 get_current_layout(new_screen
)->arrange
== layout_floating
) && !c
->ismax
)
509 c
->f_geometry
= geometry
;
511 XConfigureWindow(globalconf
.display
, c
->win
,
512 CWX
| CWY
| CWWidth
| CWHeight
| CWBorderWidth
, &wc
);
513 window_configure(c
->win
, geometry
, c
->border
);
515 if(c
->screen
!= new_screen
)
516 move_client_to_screen(c
, new_screen
, False
);
524 client_setfloating(Client
*c
, Bool floating
)
526 if(c
->isfloating
!= floating
)
528 if((c
->isfloating
= floating
))
529 client_resize(c
, c
->f_geometry
, False
);
533 client_resize(c
, c
->m_geometry
, False
);
535 if(client_isvisible(c
, c
->screen
))
536 globalconf
.screens
[c
->screen
].need_arrange
= True
;
537 widget_invalidate_cache(c
->screen
, WIDGET_CACHE_CLIENTS
);
542 /** Save client properties as an X property
546 client_saveprops(Client
*c
)
548 int i
= 0, ntags
= 0;
552 for(tag
= globalconf
.screens
[c
->screen
].tags
; tag
; tag
= tag
->next
)
555 prop
= p_new(char, ntags
+ 2);
557 for(tag
= globalconf
.screens
[c
->screen
].tags
; tag
; tag
= tag
->next
, i
++)
558 prop
[i
] = is_client_tagged(c
, tag
) ? '1' : '0';
561 prop
[i
] = c
->isfloating
? '1' : '0';
565 XChangeProperty(globalconf
.display
, c
->win
,
566 XInternAtom(globalconf
.display
, "_AWESOME_PROPERTIES", False
),
567 XA_STRING
, 8, PropModeReplace
, (unsigned char *) prop
, i
);
573 client_unban(Client
*c
)
575 XMapWindow(globalconf
.display
, c
->win
);
576 window_setstate(c
->win
, NormalState
);
580 client_unmanage(Client
*c
)
585 wc
.border_width
= c
->oldborder
;
587 /* The server grab construct avoids race conditions. */
588 XGrabServer(globalconf
.display
);
590 XConfigureWindow(globalconf
.display
, c
->win
, CWBorderWidth
, &wc
); /* restore border */
592 /* remove client everywhere */
593 client_list_detach(&globalconf
.clients
, c
);
594 focus_delete_client(c
);
595 for(tag
= globalconf
.screens
[c
->screen
].tags
; tag
; tag
= tag
->next
)
596 untag_client(c
, tag
);
598 if(globalconf
.focus
->client
== c
)
599 client_focus(NULL
, c
->screen
, False
);
601 XUngrabButton(globalconf
.display
, AnyButton
, AnyModifier
, c
->win
);
602 window_setstate(c
->win
, WithdrawnState
);
604 XSync(globalconf
.display
, False
);
605 XUngrabServer(globalconf
.display
);
611 client_updatewmhints(Client
*c
)
615 if((wmh
= XGetWMHints(globalconf
.display
, c
->win
)))
617 if((c
->isurgent
= (wmh
->flags
& XUrgencyHint
)))
618 widget_invalidate_cache(c
->screen
, WIDGET_CACHE_CLIENTS
);
619 if((wmh
->flags
& StateHint
) && wmh
->initial_state
== WithdrawnState
)
629 client_updatesizehints(Client
*c
)
634 if(!XGetWMNormalHints(globalconf
.display
, c
->win
, &size
, &msize
))
637 if(size
.flags
& PBaseSize
)
639 c
->basew
= size
.base_width
;
640 c
->baseh
= size
.base_height
;
642 else if(size
.flags
& PMinSize
)
644 c
->basew
= size
.min_width
;
645 c
->baseh
= size
.min_height
;
648 c
->basew
= c
->baseh
= 0;
649 if(size
.flags
& PResizeInc
)
651 c
->incw
= size
.width_inc
;
652 c
->inch
= size
.height_inc
;
655 c
->incw
= c
->inch
= 0;
657 if(size
.flags
& PMaxSize
)
659 c
->maxw
= size
.max_width
;
660 c
->maxh
= size
.max_height
;
663 c
->maxw
= c
->maxh
= 0;
665 if(size
.flags
& PMinSize
)
667 c
->minw
= size
.min_width
;
668 c
->minh
= size
.min_height
;
670 else if(size
.flags
& PBaseSize
)
672 c
->minw
= size
.base_width
;
673 c
->minh
= size
.base_height
;
676 c
->minw
= c
->minh
= 0;
678 if(size
.flags
& PAspect
)
680 c
->minax
= size
.min_aspect
.x
;
681 c
->maxax
= size
.max_aspect
.x
;
682 c
->minay
= size
.min_aspect
.y
;
683 c
->maxay
= size
.max_aspect
.y
;
686 c
->minax
= c
->maxax
= c
->minay
= c
->maxay
= 0;
688 if(c
->maxw
&& c
->minw
&& c
->maxh
&& c
->minh
689 && c
->maxw
== c
->minw
&& c
->maxh
== c
->minh
)
695 /** Returns True if a client is tagged
696 * with one of the tags
697 * \return True or False
700 client_isvisible(Client
*c
, int screen
)
704 if(!c
|| c
->screen
!= screen
)
707 if(globalconf
.scratch
.client
== c
)
708 return globalconf
.scratch
.isvisible
;
710 for(tag
= globalconf
.screens
[screen
].tags
; tag
; tag
= tag
->next
)
711 if(tag
->selected
&& is_client_tagged(c
, tag
))
716 /** Set selected client transparency
717 * \param screen Screen ID
718 * \param arg unused arg
719 * \ingroup ui_callback
722 uicb_client_settrans(int screen
__attribute__ ((unused
)), char *arg
)
724 double delta
= 100.0, current_opacity
= 100.0;
728 unsigned long n
, left
;
729 unsigned int current_opacity_raw
= 0;
731 Client
*sel
= globalconf
.focus
->client
;
736 XGetWindowProperty(globalconf
.display
, sel
->win
,
737 XInternAtom(globalconf
.display
, "_NET_WM_WINDOW_OPACITY", False
),
738 0L, 1L, False
, XA_CARDINAL
, &actual
, &format
, &n
, &left
,
739 (unsigned char **) &data
);
742 memcpy(¤t_opacity_raw
, data
, sizeof(unsigned int));
744 current_opacity
= (current_opacity_raw
* 100.0) / 0xffffffff;
749 delta
= compute_new_value_from_arg(arg
, current_opacity
);
753 else if(delta
> 100.0)
759 if(delta
== 100.0 && !set_prop
)
760 window_settrans(sel
->win
, -1);
762 window_settrans(sel
->win
, delta
);
766 client_find_prev_visible(Client
*sel
)
770 if(!sel
) return NULL
;
772 /* look for previous starting at sel */
773 for(prev
= client_list_prev_cycle(&globalconf
.clients
, sel
);
774 prev
&& (prev
->skip
|| !client_isvisible(prev
, sel
->screen
));
775 prev
= client_list_prev_cycle(&globalconf
.clients
, prev
));
781 client_find_next_visible(Client
*sel
)
785 if(!sel
) return NULL
;
787 for(next
= sel
->next
; next
&& !client_isvisible(next
, sel
->screen
); next
= next
->next
);
789 for(next
= globalconf
.clients
; next
&& !client_isvisible(next
, sel
->screen
); next
= next
->next
);
794 /** Swap current with previous client
795 * \param screen Screen ID
797 * \ingroup ui_callback
800 uicb_client_swapprev(int screen
__attribute__ ((unused
)),
801 char *arg
__attribute__ ((unused
)))
805 if((prev
= client_find_prev_visible(globalconf
.focus
->client
)))
807 client_list_swap(&globalconf
.clients
, prev
, globalconf
.focus
->client
);
808 globalconf
.screens
[prev
->screen
].need_arrange
= True
;
809 globalconf
.drop_events
|= EnterWindowMask
;
813 /** Swap current with next client
814 * \param screen Screen ID
816 * \ingroup ui_callback
819 uicb_client_swapnext(int screen
__attribute__ ((unused
)),
820 char *arg
__attribute__ ((unused
)))
824 if((next
= client_find_next_visible(globalconf
.focus
->client
)))
826 client_list_swap(&globalconf
.clients
, globalconf
.focus
->client
, next
);
827 globalconf
.screens
[next
->screen
].need_arrange
= True
;
828 globalconf
.drop_events
|= EnterWindowMask
;
832 /** Move and resize client
833 * \param screen Screen ID
835 * \ingroup ui_callback
838 uicb_client_moveresize(int screen
, char *arg
)
841 char x
[8], y
[8], w
[8], h
[8];
842 int mx
, my
, dx
, dy
, nmx
, nmy
;
846 Client
*sel
= globalconf
.focus
->client
;
847 Tag
**curtags
= tags_get_current(screen
);
849 if(curtags
[0]->layout
->arrange
!= layout_floating
)
850 if(!sel
|| !sel
->isfloating
|| sel
->isfixed
|| !arg
)
856 if(sscanf(arg
, "%s %s %s %s", x
, y
, w
, h
) != 4)
858 area
.x
= (int) compute_new_value_from_arg(x
, sel
->geometry
.x
);
859 area
.y
= (int) compute_new_value_from_arg(y
, sel
->geometry
.y
);
860 area
.width
= (int) compute_new_value_from_arg(w
, sel
->geometry
.width
);
861 area
.height
= (int) compute_new_value_from_arg(h
, sel
->geometry
.height
);
863 ox
= sel
->geometry
.x
;
864 oy
= sel
->geometry
.y
;
865 ow
= sel
->geometry
.width
;
866 oh
= sel
->geometry
.height
;
868 Bool xqp
= XQueryPointer(globalconf
.display
,
869 RootWindow(globalconf
.display
,
870 get_phys_screen(screen
)),
871 &dummy
, &dummy
, &mx
, &my
, &dx
, &dy
, &dui
);
872 client_resize(sel
, area
, globalconf
.screens
[sel
->screen
].resize_hints
);
873 if (xqp
&& ox
<= mx
&& (ox
+ ow
) >= mx
&& oy
<= my
&& (oy
+ oh
) >= my
)
875 nmx
= mx
- ox
+ sel
->geometry
.width
- ow
- 1 < 0 ? 0 : mx
- ox
+ sel
->geometry
.width
- ow
- 1;
876 nmy
= my
- oy
+ sel
->geometry
.height
- oh
- 1 < 0 ? 0 : my
- oy
+ sel
->geometry
.height
- oh
- 1;
877 XWarpPointer(globalconf
.display
,
879 0, 0, 0, 0, nmx
, nmy
);
884 client_kill(Client
*c
)
888 if(client_isprotodel(globalconf
.display
, c
->win
))
890 ev
.type
= ClientMessage
;
891 ev
.xclient
.window
= c
->win
;
892 ev
.xclient
.message_type
= XInternAtom(globalconf
.display
, "WM_PROTOCOLS", False
);
893 ev
.xclient
.format
= 32;
894 ev
.xclient
.data
.l
[0] = XInternAtom(globalconf
.display
, "WM_DELETE_WINDOW", False
);
895 ev
.xclient
.data
.l
[1] = CurrentTime
;
896 XSendEvent(globalconf
.display
, c
->win
, False
, NoEventMask
, &ev
);
899 XKillClient(globalconf
.display
, c
->win
);
902 /** Kill selected client
903 * \param screen Screen ID
905 * \ingroup ui_callback
908 uicb_client_kill(int screen
__attribute__ ((unused
)), char *arg
__attribute__ ((unused
)))
910 Client
*sel
= globalconf
.focus
->client
;
917 client_maximize(Client
*c
, Area geometry
)
920 if((c
->ismax
= !c
->ismax
))
922 c
->wasfloating
= c
->isfloating
;
923 c
->m_geometry
= c
->geometry
;
924 if(get_current_layout(c
->screen
)->arrange
!= layout_floating
)
925 client_setfloating(c
, True
);
926 client_resize(c
, geometry
, False
);
927 widget_invalidate_cache(c
->screen
, WIDGET_CACHE_CLIENTS
);
929 else if(c
->wasfloating
)
931 client_setfloating(c
, True
);
932 client_resize(c
, c
->m_geometry
, False
);
933 widget_invalidate_cache(c
->screen
, WIDGET_CACHE_CLIENTS
);
935 else if(get_current_layout(c
->screen
)->arrange
== layout_floating
)
937 client_resize(c
, c
->m_geometry
, False
);
938 widget_invalidate_cache(c
->screen
, WIDGET_CACHE_CLIENTS
);
942 client_setfloating(c
, False
);
943 widget_invalidate_cache(c
->screen
, WIDGET_CACHE_CLIENTS
);
947 /** Toggle maximize for client
948 * \param screen Screen ID
950 * \ingroup ui_callback
953 uicb_client_togglemax(int screen
, char *arg
__attribute__ ((unused
)))
955 Client
*sel
= globalconf
.focus
->client
;
956 Area area
= screen_get_area(screen
,
957 globalconf
.screens
[screen
].statusbar
,
958 &globalconf
.screens
[screen
].padding
);
962 area
.width
-= 2 * sel
->border
;
963 area
.height
-= 2 * sel
->border
;
964 client_maximize(sel
, area
);
968 /** Toggle vertical maximize for client
969 * \param screen Screen ID
971 * \ingroup ui_callback
974 uicb_client_toggleverticalmax(int screen
, char *arg
__attribute__ ((unused
)))
976 Client
*sel
= globalconf
.focus
->client
;
977 Area area
= screen_get_area(screen
,
978 globalconf
.screens
[screen
].statusbar
,
979 &globalconf
.screens
[screen
].padding
);
983 area
.x
= sel
->geometry
.x
;
984 area
.width
= sel
->geometry
.width
;
985 area
.height
-= 2 * sel
->border
;
986 client_maximize(sel
, area
);
991 /** Toggle horizontal maximize for client
992 * \param screen Screen ID
994 * \ingroup ui_callback
997 uicb_client_togglehorizontalmax(int screen
, char *arg
__attribute__ ((unused
)))
999 Client
*sel
= globalconf
.focus
->client
;
1000 Area area
= screen_get_area(screen
,
1001 globalconf
.screens
[screen
].statusbar
,
1002 &globalconf
.screens
[screen
].padding
);
1006 area
.y
= sel
->geometry
.y
;
1007 area
.height
= sel
->geometry
.height
;
1008 area
.width
-= 2 * sel
->border
;
1009 client_maximize(sel
, area
);
1014 * \param screen Screen ID
1016 * \ingroup ui_callback
1019 uicb_client_zoom(int screen
, char *arg
__attribute__ ((unused
)))
1021 Client
*c
, *sel
= globalconf
.focus
->client
;
1026 for(c
= globalconf
.clients
; !client_isvisible(c
, screen
); c
= c
->next
);
1028 for(sel
= sel
->next
; sel
&& !client_isvisible(sel
, screen
); sel
= sel
->next
);
1032 client_list_detach(&globalconf
.clients
, sel
);
1033 client_list_push(&globalconf
.clients
, sel
);
1034 globalconf
.screens
[screen
].need_arrange
= True
;
1035 globalconf
.drop_events
|= EnterWindowMask
;
1039 /** Send focus to next client in stack
1040 * \param screen Screen ID
1042 * \ingroup ui_callback
1045 uicb_client_focusnext(int screen
, char *arg
__attribute__ ((unused
)))
1047 Client
*c
, *sel
= globalconf
.focus
->client
;
1051 for(c
= sel
->next
; c
&& (c
->skip
|| !client_isvisible(c
, screen
)); c
= c
->next
);
1053 for(c
= globalconf
.clients
; c
&& (c
->skip
|| !client_isvisible(c
, screen
)); c
= c
->next
);
1055 client_focus(c
, screen
, False
);
1058 /** Send focus to previous client in stack
1059 * \param screen Screen ID
1061 * \ingroup ui_callback
1064 uicb_client_focusprev(int screen
, char *arg
__attribute__ ((unused
)))
1068 if((prev
= client_find_prev_visible(globalconf
.focus
->client
)))
1069 client_focus(prev
, screen
, False
);
1072 /** Toggle floating state of a client
1073 * \param screen Screen ID
1075 * \ingroup ui_callback
1078 uicb_client_togglefloating(int screen
__attribute__ ((unused
)),
1079 char *arg
__attribute__ ((unused
)))
1081 if(globalconf
.focus
->client
)
1082 client_setfloating(globalconf
.focus
->client
, !globalconf
.focus
->client
->isfloating
);
1085 /** Toggle scratch client attribute
1086 * \param screen screen number
1087 * \param arg unused argument
1088 * \ingroup ui_callback
1091 uicb_client_setscratch(int screen
,
1092 char *arg
__attribute__ ((unused
)))
1094 if(!globalconf
.focus
->client
)
1097 if(globalconf
.scratch
.client
== globalconf
.focus
->client
)
1098 globalconf
.scratch
.client
= NULL
;
1100 globalconf
.scratch
.client
= globalconf
.focus
->client
;
1102 widget_invalidate_cache(screen
, WIDGET_CACHE_CLIENTS
| WIDGET_CACHE_TAGS
);
1103 globalconf
.screens
[screen
].need_arrange
= True
;
1106 /** Toggle scratch client visibility
1107 * \param screen screen number
1108 * \param arg unused argument
1109 * \ingroup ui_callback
1112 uicb_client_togglescratch(int screen
__attribute__ ((unused
)),
1113 char *arg
__attribute__ ((unused
)))
1115 if(globalconf
.scratch
.client
)
1117 globalconf
.scratch
.isvisible
= !globalconf
.scratch
.isvisible
;
1118 globalconf
.screens
[globalconf
.scratch
.client
->screen
].need_arrange
= True
;
1119 widget_invalidate_cache(globalconf
.scratch
.client
->screen
, WIDGET_CACHE_CLIENTS
);
1122 // vim: filetype=c:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=80