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>
34 #include "layouts/floating.h"
35 #include "common/xutil.h"
36 #include "common/xscreen.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(globalconf
.display
, 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(globalconf
.display
, c
->win
,
142 XInternAtom(globalconf
.display
, "_NET_WM_NAME", False
), c
->name
, sizeof(c
->name
)))
143 xgettextprop(globalconf
.display
, c
->win
,
144 XInternAtom(globalconf
.display
, "WM_NAME", False
), c
->name
, sizeof(c
->name
));
146 widget_invalidate_cache(c
->screen
, WIDGET_CACHE_CLIENTS
);
150 client_unfocus(Client
*c
)
152 if(globalconf
.screens
[c
->screen
].opacity_unfocused
!= -1)
153 window_settrans(c
->win
, globalconf
.screens
[c
->screen
].opacity_unfocused
);
154 XSetWindowBorder(globalconf
.display
, c
->win
,
155 globalconf
.screens
[c
->screen
].styles
.normal
.border
.pixel
);
156 widget_invalidate_cache(c
->screen
, WIDGET_CACHE_CLIENTS
);
157 focus_add_client(NULL
);
160 /** Ban client and unmap it
161 * \param c the client
164 client_ban(Client
*c
)
166 if(globalconf
.focus
->client
== c
)
168 XUnmapWindow(globalconf
.display
, c
->win
);
169 window_setstate(c
->win
, IconicState
);
172 /** Give focus to client, or to first client if c is NULL
174 * \param screen Screen ID
177 client_focus(Client
*c
, int screen
, Bool raise
)
179 int phys_screen
= get_phys_screen(screen
);
181 /* if c is NULL or invisible, take next client in the focus history */
182 if(!c
|| (c
&& !client_isvisible(c
, screen
)))
184 c
= focus_get_current_client(screen
);
185 /* if c is still NULL take next client in the stack */
187 for(c
= globalconf
.clients
; c
&& (c
->skip
|| !client_isvisible(c
, screen
)); c
= c
->next
);
190 /* unfocus current selected client */
191 if(globalconf
.focus
->client
)
192 client_unfocus(globalconf
.focus
->client
);
196 /* unban the client before focusing or it will fail */
198 /* save sel in focus history */
200 if(globalconf
.screens
[c
->screen
].opacity_unfocused
!= -1)
201 window_settrans(c
->win
, -1);
202 XSetWindowBorder(globalconf
.display
, c
->win
,
203 globalconf
.screens
[screen
].styles
.focus
.border
.pixel
);
204 XSetInputFocus(globalconf
.display
, c
->win
, RevertToPointerRoot
, CurrentTime
);
208 Layout
*curlay
= layout_get_current(screen
);
209 if(c
->isfloating
|| curlay
->arrange
== layout_floating
)
210 XRaiseWindow(globalconf
.display
, c
->win
);
214 wc
.stack_mode
= Below
;
216 for(client
= globalconf
.clients
; client
; client
= client
->next
)
217 if(client
!= c
&& client_isvisible(client
, c
->screen
) && client
->isfloating
)
219 XConfigureWindow(globalconf
.display
, client
->win
, CWSibling
| CWStackMode
, &wc
);
220 wc
.sibling
= client
->win
;
222 XConfigureWindow(globalconf
.display
, c
->win
, CWSibling
| CWStackMode
, &wc
);
224 for(client
= globalconf
.clients
; client
; client
= client
->next
)
225 if(client
!= c
&& IS_TILED(client
, c
->screen
))
227 XConfigureWindow(globalconf
.display
, client
->win
, CWSibling
| CWStackMode
, &wc
);
228 wc
.sibling
= client
->win
;
232 /* since we're dropping EnterWindow events and sometimes the window
233 * will appear under the mouse, grabbuttons */
234 window_grabbuttons(phys_screen
, c
->win
);
237 XSetInputFocus(globalconf
.display
,
238 RootWindow(globalconf
.display
, phys_screen
),
239 RevertToPointerRoot
, CurrentTime
);
241 widget_invalidate_cache(screen
, WIDGET_CACHE_CLIENTS
);
242 ewmh_update_net_active_window(phys_screen
);
245 /** Manage a new client
246 * \param w The window
247 * \param wa Window attributes
248 * \param screen Screen ID
251 client_manage(Window w
, XWindowAttributes
*wa
, int screen
)
253 Client
*c
, *t
= NULL
;
255 Bool rettrans
, retloadprops
;
260 int phys_screen
= get_phys_screen(screen
);
263 c
= p_new(Client
, 1);
265 c
->screen
= screen_get_bycoord(globalconf
.screens_info
, screen
, wa
->x
, wa
->y
);
267 screen_geom
= screen_get_area(c
->screen
,
268 globalconf
.screens
[screen
].statusbar
,
269 &globalconf
.screens
[screen
].padding
);
272 c
->geometry
.x
= c
->f_geometry
.x
= c
->m_geometry
.x
= MAX(wa
->x
, screen_geom
.x
);
273 c
->geometry
.y
= c
->f_geometry
.y
= c
->m_geometry
.y
= MAX(wa
->y
, screen_geom
.y
);
274 c
->geometry
.width
= c
->f_geometry
.width
= c
->m_geometry
.width
= wa
->width
;
275 c
->geometry
.height
= c
->f_geometry
.height
= c
->m_geometry
.height
= wa
->height
;
276 c
->oldborder
= wa
->border_width
;
279 c
->border
= globalconf
.screens
[screen
].borderpx
;
281 /* Set windows borders */
282 wc
.border_width
= c
->border
;
283 XConfigureWindow(globalconf
.display
, w
, CWBorderWidth
, &wc
);
284 XSetWindowBorder(globalconf
.display
, w
,
285 globalconf
.screens
[screen
].styles
.normal
.border
.pixel
);
286 /* propagates border_width, if size doesn't change */
287 window_configure(c
->win
, c
->geometry
, c
->border
);
289 /* update window title */
290 client_updatetitle(c
);
293 flags
= client_updatesizehints(c
);
294 client_updatewmhints(c
);
296 /* Try to load props if any */
297 retloadprops
= client_loadprops(c
, screen
);
299 /* Then check clients hints */
300 ewmh_check_client_hints(c
);
302 /* Then apply rules if no props */
305 /* Get the client's rule */
306 if((rule
= rule_matching_client(c
)))
308 if(rule
->screen
!= RULE_NOSCREEN
)
309 move_client_to_screen(c
, rule
->screen
, True
);
311 move_client_to_screen(c
, screen
, True
);
312 tag_client_with_rule(c
, rule
);
314 switch(rule
->isfloating
)
319 client_setfloating(c
, True
);
322 client_setfloating(c
, False
);
326 if(rule
->opacity
>= 0.0f
)
327 window_settrans(c
->win
, rule
->opacity
);
330 move_client_to_screen(c
, screen
, True
);
333 /* check for transient and set tags like its parent,
334 * XGetTransientForHint returns 1 on success
336 if((rettrans
= XGetTransientForHint(globalconf
.display
, w
, &trans
))
337 && (t
= client_get_bywin(globalconf
.clients
, trans
)))
338 for(tag
= globalconf
.screens
[c
->screen
].tags
; tag
; tag
= tag
->next
)
339 if(is_client_tagged(t
, tag
))
342 /* should be floating if transsient or fixed */
344 client_setfloating(c
, rettrans
|| c
->isfixed
);
346 if(!(flags
& (USPosition
| PPosition
)))
348 globalconf
.screens
[c
->screen
].floating_placement(c
->f_geometry
, c
->border
, c
->screen
);
350 XSelectInput(globalconf
.display
, w
, StructureNotifyMask
| PropertyChangeMask
| EnterWindowMask
);
353 if(globalconf
.have_shape
)
355 XShapeSelectInput(globalconf
.display
, w
, ShapeNotifyMask
);
356 window_setshape(phys_screen
, c
->win
);
359 /* attach to the stack */
360 if((rule
= rule_matching_client(c
)))
361 switch(rule
->ismaster
)
364 client_list_push(&globalconf
.clients
, c
);
367 client_list_append(&globalconf
.clients
, c
);
376 if(globalconf
.screens
[c
->screen
].new_become_master
)
377 client_list_push(&globalconf
.clients
, c
);
379 client_list_append(&globalconf
.clients
, c
);
382 /* some windows require this */
383 XMoveResizeWindow(globalconf
.display
, c
->win
, c
->geometry
.x
, c
->geometry
.y
,
384 c
->geometry
.width
, c
->geometry
.height
);
386 widget_invalidate_cache(c
->screen
, WIDGET_CACHE_CLIENTS
);
387 ewmh_update_net_client_list(phys_screen
);
390 /** Resize client window
391 * \param c client to resize
392 * \param geometry new window geometry
393 * \param sizehints respect size hints
394 * \param return True if resize has been done
397 client_resize(Client
*c
, area_t geometry
, Bool sizehints
)
400 double dx
, dy
, max
, min
, ratio
;
406 if(c
->minay
> 0 && c
->maxay
> 0 && (geometry
.height
- c
->baseh
) > 0
407 && (geometry
.width
- c
->basew
) > 0)
409 dx
= (double) (geometry
.width
- c
->basew
);
410 dy
= (double) (geometry
.height
- c
->baseh
);
411 min
= (double) (c
->minax
) / (double) (c
->minay
);
412 max
= (double) (c
->maxax
) / (double) (c
->maxay
);
414 if(max
> 0 && min
> 0 && ratio
> 0)
418 dy
= (dx
* min
+ dy
) / (min
* min
+ 1);
420 geometry
.width
= (int) dx
+ c
->basew
;
421 geometry
.height
= (int) dy
+ c
->baseh
;
425 dy
= (dx
* min
+ dy
) / (max
* max
+ 1);
427 geometry
.width
= (int) dx
+ c
->basew
;
428 geometry
.height
= (int) dy
+ c
->baseh
;
432 if(c
->minw
&& geometry
.width
< c
->minw
)
433 geometry
.width
= c
->minw
;
434 if(c
->minh
&& geometry
.height
< c
->minh
)
435 geometry
.height
= c
->minh
;
436 if(c
->maxw
&& geometry
.width
> c
->maxw
)
437 geometry
.width
= c
->maxw
;
438 if(c
->maxh
&& geometry
.height
> c
->maxh
)
439 geometry
.height
= c
->maxh
;
441 geometry
.width
-= (geometry
.width
- c
->basew
) % c
->incw
;
443 geometry
.height
-= (geometry
.height
- c
->baseh
) % c
->inch
;
445 if(geometry
.width
<= 0 || geometry
.height
<= 0)
447 /* offscreen appearance fixes */
448 area
= get_display_area(get_phys_screen(c
->screen
),
450 &globalconf
.screens
[c
->screen
].padding
);
451 if(geometry
.x
> area
.width
)
452 geometry
.x
= area
.width
- geometry
.width
- 2 * c
->border
;
453 if(geometry
.y
> area
.height
)
454 geometry
.y
= area
.height
- geometry
.height
- 2 * c
->border
;
455 if(geometry
.x
+ geometry
.width
+ 2 * c
->border
< 0)
457 if(geometry
.y
+ geometry
.height
+ 2 * c
->border
< 0)
460 if(c
->geometry
.x
!= geometry
.x
|| c
->geometry
.y
!= geometry
.y
461 || c
->geometry
.width
!= geometry
.width
|| c
->geometry
.height
!= geometry
.height
)
463 new_screen
= screen_get_bycoord(globalconf
.screens_info
, c
->screen
, geometry
.x
, geometry
.y
);
465 c
->geometry
.x
= wc
.x
= geometry
.x
;
466 c
->geometry
.y
= wc
.y
= geometry
.y
;
467 c
->geometry
.width
= wc
.width
= geometry
.width
;
468 c
->geometry
.height
= wc
.height
= geometry
.height
;
469 wc
.border_width
= c
->border
;
471 /* save the floating geometry if the window is floating but not
474 layout_get_current(new_screen
)->arrange
== layout_floating
) && !c
->ismax
)
475 c
->f_geometry
= geometry
;
477 XConfigureWindow(globalconf
.display
, c
->win
,
478 CWX
| CWY
| CWWidth
| CWHeight
| CWBorderWidth
, &wc
);
479 window_configure(c
->win
, geometry
, c
->border
);
481 if(c
->screen
!= new_screen
)
482 move_client_to_screen(c
, new_screen
, False
);
490 client_setfloating(Client
*c
, Bool floating
)
492 if(c
->isfloating
!= floating
)
494 if((c
->isfloating
= floating
))
496 client_resize(c
, c
->f_geometry
, False
);
497 XRaiseWindow(globalconf
.display
, c
->win
);
501 XLowerWindow(globalconf
.display
, c
->win
);
505 client_resize(c
, c
->m_geometry
, False
);
508 if(client_isvisible(c
, c
->screen
))
509 globalconf
.screens
[c
->screen
].need_arrange
= True
;
510 widget_invalidate_cache(c
->screen
, WIDGET_CACHE_CLIENTS
);
515 /** Save client properties as an X property
519 client_saveprops(Client
*c
)
521 int i
= 0, ntags
= 0;
525 for(tag
= globalconf
.screens
[c
->screen
].tags
; tag
; tag
= tag
->next
)
528 prop
= p_new(char, ntags
+ 2);
530 for(tag
= globalconf
.screens
[c
->screen
].tags
; tag
; tag
= tag
->next
, i
++)
531 prop
[i
] = is_client_tagged(c
, tag
) ? '1' : '0';
534 prop
[i
] = c
->isfloating
? '1' : '0';
538 XChangeProperty(globalconf
.display
, c
->win
,
539 XInternAtom(globalconf
.display
, "_AWESOME_PROPERTIES", False
),
540 XA_STRING
, 8, PropModeReplace
, (unsigned char *) prop
, i
);
546 client_unban(Client
*c
)
548 XMapWindow(globalconf
.display
, c
->win
);
549 window_setstate(c
->win
, NormalState
);
553 client_unmanage(Client
*c
)
558 wc
.border_width
= c
->oldborder
;
560 /* The server grab construct avoids race conditions. */
561 XGrabServer(globalconf
.display
);
563 XConfigureWindow(globalconf
.display
, c
->win
, CWBorderWidth
, &wc
); /* restore border */
565 /* remove client everywhere */
566 client_list_detach(&globalconf
.clients
, c
);
567 focus_delete_client(c
);
568 if(globalconf
.scratch
.client
== c
)
569 globalconf
.scratch
.client
= NULL
;
570 for(tag
= globalconf
.screens
[c
->screen
].tags
; tag
; tag
= tag
->next
)
571 untag_client(c
, tag
);
573 if(globalconf
.focus
->client
== c
)
574 client_focus(NULL
, c
->screen
, True
);
576 XUngrabButton(globalconf
.display
, AnyButton
, AnyModifier
, c
->win
);
577 window_setstate(c
->win
, WithdrawnState
);
579 XSync(globalconf
.display
, False
);
580 XUngrabServer(globalconf
.display
);
586 client_updatewmhints(Client
*c
)
590 if((wmh
= XGetWMHints(globalconf
.display
, c
->win
)))
592 if((c
->isurgent
= (wmh
->flags
& XUrgencyHint
)))
593 widget_invalidate_cache(c
->screen
, WIDGET_CACHE_CLIENTS
);
594 if((wmh
->flags
& StateHint
) && wmh
->initial_state
== WithdrawnState
)
604 client_updatesizehints(Client
*c
)
609 if(!XGetWMNormalHints(globalconf
.display
, c
->win
, &size
, &msize
))
612 if(size
.flags
& PBaseSize
)
614 c
->basew
= size
.base_width
;
615 c
->baseh
= size
.base_height
;
617 else if(size
.flags
& PMinSize
)
619 c
->basew
= size
.min_width
;
620 c
->baseh
= size
.min_height
;
623 c
->basew
= c
->baseh
= 0;
624 if(size
.flags
& PResizeInc
)
626 c
->incw
= size
.width_inc
;
627 c
->inch
= size
.height_inc
;
630 c
->incw
= c
->inch
= 0;
632 if(size
.flags
& PMaxSize
)
634 c
->maxw
= size
.max_width
;
635 c
->maxh
= size
.max_height
;
638 c
->maxw
= c
->maxh
= 0;
640 if(size
.flags
& PMinSize
)
642 c
->minw
= size
.min_width
;
643 c
->minh
= size
.min_height
;
645 else if(size
.flags
& PBaseSize
)
647 c
->minw
= size
.base_width
;
648 c
->minh
= size
.base_height
;
651 c
->minw
= c
->minh
= 0;
653 if(size
.flags
& PAspect
)
655 c
->minax
= size
.min_aspect
.x
;
656 c
->maxax
= size
.max_aspect
.x
;
657 c
->minay
= size
.min_aspect
.y
;
658 c
->maxay
= size
.max_aspect
.y
;
661 c
->minax
= c
->maxax
= c
->minay
= c
->maxay
= 0;
663 if(c
->maxw
&& c
->minw
&& c
->maxh
&& c
->minh
664 && c
->maxw
== c
->minw
&& c
->maxh
== c
->minh
)
670 /** Returns True if a client is tagged
671 * with one of the tags
672 * \return True or False
675 client_isvisible(Client
*c
, int screen
)
679 if(!c
|| c
->screen
!= screen
)
682 if(globalconf
.scratch
.client
== c
)
683 return globalconf
.scratch
.isvisible
;
685 for(tag
= globalconf
.screens
[screen
].tags
; tag
; tag
= tag
->next
)
686 if(tag
->selected
&& is_client_tagged(c
, tag
))
691 /** Set selected client transparency
692 * \param screen Screen ID
693 * \param arg unused arg
694 * \ingroup ui_callback
697 uicb_client_settrans(int screen
__attribute__ ((unused
)), char *arg
)
699 double delta
= 100.0, current_opacity
= 100.0;
703 unsigned long n
, left
;
704 unsigned int current_opacity_raw
= 0;
706 Client
*sel
= globalconf
.focus
->client
;
711 XGetWindowProperty(globalconf
.display
, sel
->win
,
712 XInternAtom(globalconf
.display
, "_NET_WM_WINDOW_OPACITY", False
),
713 0L, 1L, False
, XA_CARDINAL
, &actual
, &format
, &n
, &left
,
714 (unsigned char **) &data
);
717 memcpy(¤t_opacity_raw
, data
, sizeof(unsigned int));
719 current_opacity
= (current_opacity_raw
* 100.0) / 0xffffffff;
724 delta
= compute_new_value_from_arg(arg
, current_opacity
);
728 else if(delta
> 100.0)
734 if(delta
== 100.0 && !set_prop
)
735 window_settrans(sel
->win
, -1);
737 window_settrans(sel
->win
, delta
);
741 client_find_visible(Client
*sel
, Bool reverse
)
744 Client
*(*client_iter
)(Client
**, Client
*) = client_list_next_cycle
;
746 if(!sel
) return NULL
;
749 client_iter
= client_list_prev_cycle
;
751 /* look for previous or next starting at sel */
753 for(next
= client_iter(&globalconf
.clients
, sel
);
754 next
&& (next
->skip
|| !client_isvisible(next
, sel
->screen
));
755 next
= client_iter(&globalconf
.clients
, next
));
760 /** Swap current with previous client
761 * \param screen Screen ID
763 * \ingroup ui_callback
766 uicb_client_swapprev(int screen
__attribute__ ((unused
)),
767 char *arg
__attribute__ ((unused
)))
771 if((prev
= client_find_visible(globalconf
.focus
->client
, True
)))
773 client_list_swap(&globalconf
.clients
, prev
, globalconf
.focus
->client
);
774 globalconf
.screens
[prev
->screen
].need_arrange
= True
;
778 /** Swap current with next client
779 * \param screen Screen ID
781 * \ingroup ui_callback
784 uicb_client_swapnext(int screen
__attribute__ ((unused
)),
785 char *arg
__attribute__ ((unused
)))
789 if((next
= client_find_visible(globalconf
.focus
->client
, False
)))
791 client_list_swap(&globalconf
.clients
, globalconf
.focus
->client
, next
);
792 globalconf
.screens
[next
->screen
].need_arrange
= True
;
796 /** Move and resize client
797 * \param screen Screen ID
799 * \ingroup ui_callback
802 uicb_client_moveresize(int screen
, char *arg
)
804 int ox
, oy
, ow
, oh
; /* old geometry */
805 char x
[8], y
[8], w
[8], h
[8];
806 int mx
, my
, dx
, dy
, nmx
, nmy
;
810 Client
*sel
= globalconf
.focus
->client
;
811 Layout
*curlay
= layout_get_current(screen
);
813 if(!sel
|| sel
->isfixed
|| !arg
||
814 (curlay
->arrange
!= layout_floating
&& !sel
->isfloating
))
817 if(sscanf(arg
, "%s %s %s %s", x
, y
, w
, h
) != 4)
820 area
.x
= (int) compute_new_value_from_arg(x
, sel
->geometry
.x
);
821 area
.y
= (int) compute_new_value_from_arg(y
, sel
->geometry
.y
);
822 area
.width
= (int) compute_new_value_from_arg(w
, sel
->geometry
.width
);
823 area
.height
= (int) compute_new_value_from_arg(h
, sel
->geometry
.height
);
825 ox
= sel
->geometry
.x
;
826 oy
= sel
->geometry
.y
;
827 ow
= sel
->geometry
.width
;
828 oh
= sel
->geometry
.height
;
830 Bool xqp
= XQueryPointer(globalconf
.display
,
831 RootWindow(globalconf
.display
,
832 get_phys_screen(screen
)),
833 &dummy
, &dummy
, &mx
, &my
, &dx
, &dy
, &dui
);
834 client_resize(sel
, area
, globalconf
.screens
[sel
->screen
].resize_hints
);
835 if (xqp
&& ox
<= mx
&& (ox
+ 2 * sel
->border
+ ow
) >= mx
&&
836 oy
<= my
&& (oy
+ 2 * sel
->border
+ oh
) >= my
)
838 nmx
= mx
- (ox
+ sel
->border
) + sel
->geometry
.width
- ow
;
839 nmy
= my
- (oy
+ sel
->border
) + sel
->geometry
.height
- oh
;
841 if(nmx
< -sel
->border
) /* can happen on a resize */
843 if(nmy
< -sel
->border
)
846 XWarpPointer(globalconf
.display
,
848 0, 0, 0, 0, nmx
, nmy
);
853 client_kill(Client
*c
)
857 if(client_isprotodel(globalconf
.display
, c
->win
))
859 ev
.type
= ClientMessage
;
860 ev
.xclient
.window
= c
->win
;
861 ev
.xclient
.message_type
= XInternAtom(globalconf
.display
, "WM_PROTOCOLS", False
);
862 ev
.xclient
.format
= 32;
863 ev
.xclient
.data
.l
[0] = XInternAtom(globalconf
.display
, "WM_DELETE_WINDOW", False
);
864 ev
.xclient
.data
.l
[1] = CurrentTime
;
865 XSendEvent(globalconf
.display
, c
->win
, False
, NoEventMask
, &ev
);
868 XKillClient(globalconf
.display
, c
->win
);
871 /** Kill selected client
872 * \param screen Screen ID
874 * \ingroup ui_callback
877 uicb_client_kill(int screen
__attribute__ ((unused
)), char *arg
__attribute__ ((unused
)))
879 Client
*sel
= globalconf
.focus
->client
;
886 client_maximize(Client
*c
, area_t geometry
)
889 if((c
->ismax
= !c
->ismax
))
891 c
->wasfloating
= c
->isfloating
;
892 c
->m_geometry
= c
->geometry
;
893 if(layout_get_current(c
->screen
)->arrange
!= layout_floating
)
894 client_setfloating(c
, True
);
895 client_focus(c
, c
->screen
, True
);
896 client_resize(c
, geometry
, False
);
897 widget_invalidate_cache(c
->screen
, WIDGET_CACHE_CLIENTS
);
899 else if(c
->wasfloating
)
901 client_setfloating(c
, True
);
902 client_resize(c
, c
->m_geometry
, False
);
903 widget_invalidate_cache(c
->screen
, WIDGET_CACHE_CLIENTS
);
905 else if(layout_get_current(c
->screen
)->arrange
== layout_floating
)
907 client_resize(c
, c
->m_geometry
, False
);
908 widget_invalidate_cache(c
->screen
, WIDGET_CACHE_CLIENTS
);
912 client_setfloating(c
, False
);
913 widget_invalidate_cache(c
->screen
, WIDGET_CACHE_CLIENTS
);
917 /** Toggle maximize for client
918 * \param screen Screen ID
920 * \ingroup ui_callback
923 uicb_client_togglemax(int screen
, char *arg
__attribute__ ((unused
)))
925 Client
*sel
= globalconf
.focus
->client
;
926 area_t area
= screen_get_area(screen
,
927 globalconf
.screens
[screen
].statusbar
,
928 &globalconf
.screens
[screen
].padding
);
932 area
.width
-= 2 * sel
->border
;
933 area
.height
-= 2 * sel
->border
;
934 client_maximize(sel
, area
);
938 /** Toggle vertical maximize for client
939 * \param screen Screen ID
941 * \ingroup ui_callback
944 uicb_client_toggleverticalmax(int screen
, char *arg
__attribute__ ((unused
)))
946 Client
*sel
= globalconf
.focus
->client
;
947 area_t area
= screen_get_area(screen
,
948 globalconf
.screens
[screen
].statusbar
,
949 &globalconf
.screens
[screen
].padding
);
953 area
.x
= sel
->geometry
.x
;
954 area
.width
= sel
->geometry
.width
;
955 area
.height
-= 2 * sel
->border
;
956 client_maximize(sel
, area
);
961 /** Toggle horizontal maximize for client
962 * \param screen Screen ID
964 * \ingroup ui_callback
967 uicb_client_togglehorizontalmax(int screen
, char *arg
__attribute__ ((unused
)))
969 Client
*sel
= globalconf
.focus
->client
;
970 area_t area
= screen_get_area(screen
,
971 globalconf
.screens
[screen
].statusbar
,
972 &globalconf
.screens
[screen
].padding
);
976 area
.y
= sel
->geometry
.y
;
977 area
.height
= sel
->geometry
.height
;
978 area
.width
-= 2 * sel
->border
;
979 client_maximize(sel
, area
);
984 * \param screen Screen ID
986 * \ingroup ui_callback
989 uicb_client_zoom(int screen
, char *arg
__attribute__ ((unused
)))
991 Client
*c
, *sel
= globalconf
.focus
->client
;
996 for(c
= globalconf
.clients
; !client_isvisible(c
, screen
); c
= c
->next
);
998 for(sel
= sel
->next
; sel
&& !client_isvisible(sel
, screen
); sel
= sel
->next
);
1002 client_list_detach(&globalconf
.clients
, sel
);
1003 client_list_push(&globalconf
.clients
, sel
);
1004 globalconf
.screens
[screen
].need_arrange
= True
;
1008 /** Send focus to next client in stack
1009 * \param screen Screen ID
1011 * \ingroup ui_callback
1014 uicb_client_focusnext(int screen
, char *arg
__attribute__ ((unused
)))
1018 if((next
= client_find_visible(globalconf
.focus
->client
, False
)))
1019 client_focus(next
, screen
, True
);
1022 /** Send focus to previous client in stack
1023 * \param screen Screen ID
1025 * \ingroup ui_callback
1028 uicb_client_focusprev(int screen
, char *arg
__attribute__ ((unused
)))
1032 if((prev
= client_find_visible(globalconf
.focus
->client
, True
)))
1033 client_focus(prev
, screen
, True
);
1036 /** Toggle floating state of a client
1037 * \param screen Screen ID
1039 * \ingroup ui_callback
1042 uicb_client_togglefloating(int screen
__attribute__ ((unused
)),
1043 char *arg
__attribute__ ((unused
)))
1045 if(globalconf
.focus
->client
)
1046 client_setfloating(globalconf
.focus
->client
, !globalconf
.focus
->client
->isfloating
);
1049 /** Toggle scratch client attribute
1050 * \param screen screen number
1051 * \param arg unused argument
1052 * \ingroup ui_callback
1055 uicb_client_setscratch(int screen
,
1056 char *arg
__attribute__ ((unused
)))
1058 if(!globalconf
.focus
->client
)
1061 if(globalconf
.scratch
.client
== globalconf
.focus
->client
)
1062 globalconf
.scratch
.client
= NULL
;
1064 globalconf
.scratch
.client
= globalconf
.focus
->client
;
1066 widget_invalidate_cache(screen
, WIDGET_CACHE_CLIENTS
| WIDGET_CACHE_TAGS
);
1067 globalconf
.screens
[screen
].need_arrange
= True
;
1070 /** Toggle scratch client visibility
1071 * \param screen screen number
1072 * \param arg unused argument
1073 * \ingroup ui_callback
1076 uicb_client_togglescratch(int screen
,
1077 char *arg
__attribute__ ((unused
)))
1079 if(globalconf
.scratch
.client
)
1081 globalconf
.scratch
.isvisible
= !globalconf
.scratch
.isvisible
;
1082 if(globalconf
.scratch
.isvisible
)
1083 client_focus(globalconf
.scratch
.client
, screen
, True
);
1084 globalconf
.screens
[globalconf
.scratch
.client
->screen
].need_arrange
= True
;
1085 widget_invalidate_cache(globalconf
.scratch
.client
->screen
, WIDGET_CACHE_CLIENTS
);
1088 // vim: filetype=c:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=80