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 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 get_client_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 get_client_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
);
147 /** Ban client and unmap it
148 * \param c the client
151 client_ban(Client
* c
)
153 XUnmapWindow(globalconf
.display
, c
->win
);
154 window_setstate(c
->win
, IconicState
);
157 /** Give focus to client, or to first client if c is NULL
159 * \param selscreen True if current screen is selected
160 * \param screen Screen ID
163 focus(Client
*c
, Bool selscreen
, int screen
)
165 int phys_screen
= get_phys_screen(screen
);
167 /* unfocus current selected client */
168 if(globalconf
.focus
->client
)
170 widget_invalidate_cache(globalconf
.focus
->client
->screen
, WIDGET_CACHE_CLIENTS
);
171 window_grabbuttons(get_phys_screen(globalconf
.focus
->client
->screen
),
172 globalconf
.focus
->client
->win
, False
, True
);
173 XSetWindowBorder(globalconf
.display
, globalconf
.focus
->client
->win
,
174 globalconf
.screens
[screen
].colors_normal
[ColBorder
].pixel
);
175 window_settrans(globalconf
.focus
->client
->win
,
176 globalconf
.screens
[screen
].opacity_unfocused
);
180 /* if c is NULL or invisible, take next client in the focus history */
181 if((!c
&& selscreen
) || (c
&& !client_isvisible(c
, screen
)))
183 c
= focus_get_current_client(screen
);
184 /* if c is still NULL take next client in the stack */
186 for(c
= globalconf
.clients
; c
&& (c
->skip
|| !client_isvisible(c
, screen
)); c
= c
->next
);
191 XSetWindowBorder(globalconf
.display
, c
->win
, globalconf
.screens
[screen
].colors_selected
[ColBorder
].pixel
);
192 window_grabbuttons(phys_screen
, c
->win
, True
, True
);
198 /* save sel in focus history */
201 if(globalconf
.focus
->client
)
203 widget_invalidate_cache(screen
, WIDGET_CACHE_CLIENTS
);
204 XSetInputFocus(globalconf
.display
,
205 globalconf
.focus
->client
->win
, RevertToPointerRoot
, CurrentTime
);
206 for(c
= globalconf
.clients
; c
; c
= c
->next
)
207 if(c
!= globalconf
.focus
->client
)
208 window_settrans(globalconf
.focus
->client
->win
,
209 globalconf
.screens
[screen
].opacity_unfocused
);
210 window_settrans(globalconf
.focus
->client
->win
, -1);
214 XSetInputFocus(globalconf
.display
,
215 RootWindow(globalconf
.display
, phys_screen
),
216 RevertToPointerRoot
, CurrentTime
);
218 ewmh_update_net_active_window(phys_screen
);
219 globalconf
.drop_events
|= EnterWindowMask
;
222 /** Manage a new client
223 * \param w The window
224 * \param wa Window attributes
225 * \param screen Screen ID
228 client_manage(Window w
, XWindowAttributes
*wa
, int screen
)
230 Client
*c
, *t
= NULL
;
237 int phys_screen
= get_phys_screen(screen
);
239 c
= p_new(Client
, 1);
241 c
->screen
= get_screen_bycoord(wa
->x
, wa
->y
);
243 screen_geom
= get_display_area(phys_screen
,
244 globalconf
.screens
[c
->screen
].statusbar
,
245 &globalconf
.screens
[c
->screen
].padding
);
248 c
->geometry
.x
= c
->f_geometry
.x
= c
->m_geometry
.x
= MAX(wa
->x
, screen_geom
.x
);
249 c
->geometry
.y
= c
->f_geometry
.y
= c
->m_geometry
.y
= MAX(wa
->y
, screen_geom
.y
);
250 c
->geometry
.width
= c
->f_geometry
.width
= c
->m_geometry
.width
= wa
->width
;
251 c
->geometry
.height
= c
->f_geometry
.height
= c
->m_geometry
.height
= wa
->height
;
252 c
->oldborder
= wa
->border_width
;
255 c
->border
= globalconf
.screens
[screen
].borderpx
;
257 /* Set windows borders */
258 wc
.border_width
= c
->border
;
259 XConfigureWindow(globalconf
.display
, w
, CWBorderWidth
, &wc
);
260 XSetWindowBorder(globalconf
.display
, w
, globalconf
.screens
[screen
].colors_normal
[ColBorder
].pixel
);
261 /* propagates border_width, if size doesn't change */
262 window_configure(c
->win
, c
->geometry
, c
->border
);
264 /* update window title */
265 client_updatetitle(c
);
268 client_updatesizehints(c
);
269 client_updatewmhints(c
);
271 /* First check clients hints */
272 ewmh_check_client_hints(c
);
274 /* loadprops or apply rules if no props */
275 if(!client_loadprops(c
, screen
))
277 /* Get the client's rule */
278 if((rule
= rule_matching_client(c
)))
280 if(rule
->screen
!= RULE_NOSCREEN
)
281 move_client_to_screen(c
, rule
->screen
, True
);
283 move_client_to_screen(c
, screen
, True
);
284 tag_client_with_rule(c
, rule
);
286 switch(rule
->isfloating
)
291 client_setfloating(c
, True
);
294 client_setfloating(c
, False
);
299 move_client_to_screen(c
, screen
, True
);
300 /* check for transient and set tags like its parent,
301 * XGetTransientForHint returns 1 on success
303 if((rettrans
= XGetTransientForHint(globalconf
.display
, w
, &trans
))
304 && (t
= get_client_bywin(globalconf
.clients
, trans
)))
305 for(tag
= globalconf
.screens
[c
->screen
].tags
; tag
; tag
= tag
->next
)
306 if(is_client_tagged(t
, tag
))
309 /* should be floating if transsient or fixed */
311 client_setfloating(c
, rettrans
|| c
->isfixed
);
314 XSelectInput(globalconf
.display
, w
, StructureNotifyMask
| PropertyChangeMask
| EnterWindowMask
);
315 window_grabbuttons(phys_screen
, c
->win
, False
, True
);
318 if(globalconf
.have_shape
)
320 XShapeSelectInput(globalconf
.display
, w
, ShapeNotifyMask
);
321 window_setshape(phys_screen
, c
->win
);
327 /* attach to the stack */
328 if((rule
= rule_matching_client(c
)) && rule
->not_master
)
329 client_list_append(&globalconf
.clients
, c
);
330 else if(globalconf
.screens
[c
->screen
].new_become_master
)
331 client_list_push(&globalconf
.clients
, c
);
333 client_list_append(&globalconf
.clients
, c
);
336 if(globalconf
.screens
[c
->screen
].new_get_focus
)
337 focus(c
, True
, c
->screen
);
339 /* some windows require this */
340 XMoveResizeWindow(globalconf
.display
, c
->win
, c
->geometry
.x
, c
->geometry
.y
,
341 c
->geometry
.width
, c
->geometry
.height
);
343 widget_invalidate_cache(c
->screen
, WIDGET_CACHE_CLIENTS
);
344 ewmh_update_net_client_list(phys_screen
);
347 /** Resize client window
348 * \param c client to resize
349 * \param geometry new window geometry
350 * \param sizehints respect size hints
351 * \param return True if resize has been done
354 client_resize(Client
*c
, Area geometry
, Bool sizehints
)
357 double dx
, dy
, max
, min
, ratio
;
363 if(c
->minay
> 0 && c
->maxay
> 0 && (geometry
.height
- c
->baseh
) > 0
364 && (geometry
.width
- c
->basew
) > 0)
366 dx
= (double) (geometry
.width
- c
->basew
);
367 dy
= (double) (geometry
.height
- c
->baseh
);
368 min
= (double) (c
->minax
) / (double) (c
->minay
);
369 max
= (double) (c
->maxax
) / (double) (c
->maxay
);
371 if(max
> 0 && min
> 0 && ratio
> 0)
375 dy
= (dx
* min
+ dy
) / (min
* min
+ 1);
377 geometry
.width
= (int) dx
+ c
->basew
;
378 geometry
.height
= (int) dy
+ c
->baseh
;
382 dy
= (dx
* min
+ dy
) / (max
* max
+ 1);
384 geometry
.width
= (int) dx
+ c
->basew
;
385 geometry
.height
= (int) dy
+ c
->baseh
;
389 if(c
->minw
&& geometry
.width
< c
->minw
)
390 geometry
.width
= c
->minw
;
391 if(c
->minh
&& geometry
.height
< c
->minh
)
392 geometry
.height
= c
->minh
;
393 if(c
->maxw
&& geometry
.width
> c
->maxw
)
394 geometry
.width
= c
->maxw
;
395 if(c
->maxh
&& geometry
.height
> c
->maxh
)
396 geometry
.height
= c
->maxh
;
398 geometry
.width
-= (geometry
.width
- c
->basew
) % c
->incw
;
400 geometry
.height
-= (geometry
.height
- c
->baseh
) % c
->inch
;
402 if(geometry
.width
<= 0 || geometry
.height
<= 0)
404 /* offscreen appearance fixes */
405 area
= get_display_area(get_phys_screen(c
->screen
),
407 &globalconf
.screens
[c
->screen
].padding
);
408 if(geometry
.x
> area
.width
)
409 geometry
.x
= area
.width
- geometry
.width
- 2 * c
->border
;
410 if(geometry
.y
> area
.height
)
411 geometry
.y
= area
.height
- geometry
.height
- 2 * c
->border
;
412 if(geometry
.x
+ geometry
.width
+ 2 * c
->border
< 0)
414 if(geometry
.y
+ geometry
.height
+ 2 * c
->border
< 0)
417 if(c
->geometry
.x
!= geometry
.x
|| c
->geometry
.y
!= geometry
.y
418 || c
->geometry
.width
!= geometry
.width
|| c
->geometry
.height
!= geometry
.height
)
420 new_screen
= get_screen_bycoord(geometry
.x
, geometry
.y
);
422 c
->geometry
.x
= wc
.x
= geometry
.x
;
423 c
->geometry
.y
= wc
.y
= geometry
.y
;
424 c
->geometry
.width
= wc
.width
= geometry
.width
;
425 c
->geometry
.height
= wc
.height
= geometry
.height
;
426 wc
.border_width
= c
->border
;
428 /* save the floating geometry if the window is floating but not
431 get_current_layout(new_screen
)->arrange
== layout_floating
) && !c
->ismax
)
432 c
->f_geometry
= geometry
;
434 XConfigureWindow(globalconf
.display
, c
->win
,
435 CWX
| CWY
| CWWidth
| CWHeight
| CWBorderWidth
, &wc
);
436 window_configure(c
->win
, geometry
, c
->border
);
438 if(c
->screen
!= new_screen
)
439 move_client_to_screen(c
, new_screen
, False
);
447 client_setfloating(Client
*c
, Bool floating
)
449 if(c
->isfloating
!= floating
)
451 if((c
->isfloating
= floating
))
452 client_resize(c
, c
->f_geometry
, False
);
453 if(client_isvisible(c
, c
->screen
))
454 globalconf
.screens
[c
->screen
].need_arrange
= True
;
455 widget_invalidate_cache(c
->screen
, WIDGET_CACHE_CLIENTS
);
459 /** Save client properties as an X property
463 client_saveprops(Client
*c
)
465 int i
= 0, ntags
= 0;
469 for(tag
= globalconf
.screens
[c
->screen
].tags
; tag
; tag
= tag
->next
)
472 prop
= p_new(char, ntags
+ 2);
474 for(tag
= globalconf
.screens
[c
->screen
].tags
; tag
; tag
= tag
->next
, i
++)
475 prop
[i
] = is_client_tagged(c
, tag
) ? '1' : '0';
478 prop
[i
] = c
->isfloating
? '1' : '0';
482 XChangeProperty(globalconf
.display
, c
->win
,
483 XInternAtom(globalconf
.display
, "_AWESOME_PROPERTIES", False
),
484 XA_STRING
, 8, PropModeReplace
, (unsigned char *) prop
, i
);
490 client_unban(Client
*c
)
492 XMapWindow(globalconf
.display
, c
->win
);
493 window_setstate(c
->win
, NormalState
);
497 client_unmanage(Client
*c
)
502 wc
.border_width
= c
->oldborder
;
504 /* The server grab construct avoids race conditions. */
505 XGrabServer(globalconf
.display
);
507 XConfigureWindow(globalconf
.display
, c
->win
, CWBorderWidth
, &wc
); /* restore border */
509 /* remove client everywhere */
510 client_list_detach(&globalconf
.clients
, c
);
511 focus_delete_client(c
);
512 for(tag
= globalconf
.screens
[c
->screen
].tags
; tag
; tag
= tag
->next
)
513 untag_client(c
, tag
);
515 if(globalconf
.focus
->client
== c
)
516 focus(NULL
, True
, c
->screen
);
518 XUngrabButton(globalconf
.display
, AnyButton
, AnyModifier
, c
->win
);
519 window_setstate(c
->win
, WithdrawnState
);
521 XSync(globalconf
.display
, False
);
522 XUngrabServer(globalconf
.display
);
528 client_updatewmhints(Client
*c
)
532 if((wmh
= XGetWMHints(globalconf
.display
, c
->win
)))
534 if((c
->isurgent
= (wmh
->flags
& XUrgencyHint
)))
535 widget_invalidate_cache(c
->screen
, WIDGET_CACHE_CLIENTS
);
536 if((wmh
->flags
& StateHint
) && wmh
->initial_state
== WithdrawnState
)
546 client_updatesizehints(Client
*c
)
551 if(!XGetWMNormalHints(globalconf
.display
, c
->win
, &size
, &msize
) || !size
.flags
)
553 if(size
.flags
& PBaseSize
)
555 c
->basew
= size
.base_width
;
556 c
->baseh
= size
.base_height
;
558 else if(size
.flags
& PMinSize
)
560 c
->basew
= size
.min_width
;
561 c
->baseh
= size
.min_height
;
564 c
->basew
= c
->baseh
= 0;
565 if(size
.flags
& PResizeInc
)
567 c
->incw
= size
.width_inc
;
568 c
->inch
= size
.height_inc
;
571 c
->incw
= c
->inch
= 0;
573 if(size
.flags
& PMaxSize
)
575 c
->maxw
= size
.max_width
;
576 c
->maxh
= size
.max_height
;
579 c
->maxw
= c
->maxh
= 0;
581 if(size
.flags
& PMinSize
)
583 c
->minw
= size
.min_width
;
584 c
->minh
= size
.min_height
;
586 else if(size
.flags
& PBaseSize
)
588 c
->minw
= size
.base_width
;
589 c
->minh
= size
.base_height
;
592 c
->minw
= c
->minh
= 0;
594 if(size
.flags
& PAspect
)
596 c
->minax
= size
.min_aspect
.x
;
597 c
->maxax
= size
.max_aspect
.x
;
598 c
->minay
= size
.min_aspect
.y
;
599 c
->maxay
= size
.max_aspect
.y
;
602 c
->minax
= c
->maxax
= c
->minay
= c
->maxay
= 0;
604 if(c
->maxw
&& c
->minw
&& c
->maxh
&& c
->minh
605 && c
->maxw
== c
->minw
&& c
->maxh
== c
->minh
)
609 /** Returns True if a client is tagged
610 * with one of the tags
611 * \return True or False
614 client_isvisible(Client
*c
, int screen
)
618 if(!c
|| c
->screen
!= screen
)
621 for(tag
= globalconf
.screens
[screen
].tags
; tag
; tag
= tag
->next
)
622 if(tag
->selected
&& is_client_tagged(c
, tag
))
627 /** Set selected client transparency
628 * \param screen Screen ID
629 * \param arg unused arg
630 * \ingroup ui_callback
633 uicb_client_settrans(int screen
__attribute__ ((unused
)), char *arg
)
635 double delta
= 100.0, current_opacity
= 100.0;
639 unsigned long n
, left
;
640 unsigned int current_opacity_raw
= 0;
642 Client
*sel
= globalconf
.focus
->client
;
647 XGetWindowProperty(globalconf
.display
, sel
->win
,
648 XInternAtom(globalconf
.display
, "_NET_WM_WINDOW_OPACITY", False
),
649 0L, 1L, False
, XA_CARDINAL
, &actual
, &format
, &n
, &left
,
650 (unsigned char **) &data
);
653 memcpy(¤t_opacity_raw
, data
, sizeof(unsigned int));
655 current_opacity
= (current_opacity_raw
* 100.0) / 0xffffffff;
660 delta
= compute_new_value_from_arg(arg
, current_opacity
);
664 else if(delta
> 100.0)
670 if(delta
== 100.0 && !set_prop
)
671 window_settrans(sel
->win
, -1);
673 window_settrans(sel
->win
, delta
);
677 client_find_prev_visible(Client
*sel
)
681 if(!sel
) return NULL
;
683 /* look for previous starting at sel */
684 for(prev
= client_list_prev_cycle(&globalconf
.clients
, sel
);
685 prev
&& (prev
->skip
|| !client_isvisible(prev
, sel
->screen
));
686 prev
= client_list_prev_cycle(&globalconf
.clients
, prev
));
692 client_find_next_visible(Client
*sel
)
696 if(!sel
) return NULL
;
698 for(next
= sel
->next
; next
&& !client_isvisible(next
, sel
->screen
); next
= next
->next
);
700 for(next
= globalconf
.clients
; next
&& !client_isvisible(next
, sel
->screen
); next
= next
->next
);
705 /** Swap current with previous client
706 * \param screen Screen ID
708 * \ingroup ui_callback
711 uicb_client_swapprev(int screen
__attribute__ ((unused
)),
712 char *arg
__attribute__ ((unused
)))
716 if((prev
= client_find_prev_visible(globalconf
.focus
->client
)))
718 client_list_swap(&globalconf
.clients
, prev
, globalconf
.focus
->client
);
719 globalconf
.screens
[prev
->screen
].need_arrange
= True
;
723 /** Swap current with next client
724 * \param screen Screen ID
726 * \ingroup ui_callback
729 uicb_client_swapnext(int screen
__attribute__ ((unused
)),
730 char *arg
__attribute__ ((unused
)))
734 if((next
= client_find_next_visible(globalconf
.focus
->client
)))
736 client_list_swap(&globalconf
.clients
, globalconf
.focus
->client
, next
);
737 globalconf
.screens
[next
->screen
].need_arrange
= True
;
741 /** Move and resize client
742 * \param screen Screen ID
744 * \ingroup ui_callback
747 uicb_client_moveresize(int screen
, char *arg
)
750 char x
[8], y
[8], w
[8], h
[8];
751 int mx
, my
, dx
, dy
, nmx
, nmy
;
755 Client
*sel
= globalconf
.focus
->client
;
756 Tag
**curtags
= get_current_tags(screen
);
758 if(curtags
[0]->layout
->arrange
!= layout_floating
)
759 if(!sel
|| !sel
->isfloating
|| sel
->isfixed
|| !arg
)
765 if(sscanf(arg
, "%s %s %s %s", x
, y
, w
, h
) != 4)
767 area
.x
= (int) compute_new_value_from_arg(x
, sel
->geometry
.x
);
768 area
.y
= (int) compute_new_value_from_arg(y
, sel
->geometry
.y
);
769 area
.width
= (int) compute_new_value_from_arg(w
, sel
->geometry
.width
);
770 area
.height
= (int) compute_new_value_from_arg(h
, sel
->geometry
.height
);
772 ox
= sel
->geometry
.x
;
773 oy
= sel
->geometry
.y
;
774 ow
= sel
->geometry
.width
;
775 oh
= sel
->geometry
.height
;
777 Bool xqp
= XQueryPointer(globalconf
.display
,
778 RootWindow(globalconf
.display
,
779 get_phys_screen(screen
)),
780 &dummy
, &dummy
, &mx
, &my
, &dx
, &dy
, &dui
);
781 client_resize(sel
, area
, globalconf
.screens
[sel
->screen
].resize_hints
);
782 if (xqp
&& ox
<= mx
&& (ox
+ ow
) >= mx
&& oy
<= my
&& (oy
+ oh
) >= my
)
784 nmx
= mx
- ox
+ sel
->geometry
.width
- ow
- 1 < 0 ? 0 : mx
- ox
+ sel
->geometry
.width
- ow
- 1;
785 nmy
= my
- oy
+ sel
->geometry
.height
- oh
- 1 < 0 ? 0 : my
- oy
+ sel
->geometry
.height
- oh
- 1;
786 XWarpPointer(globalconf
.display
,
788 0, 0, 0, 0, nmx
, nmy
);
793 client_kill(Client
*c
)
797 if(isprotodel(globalconf
.display
, c
->win
))
799 ev
.type
= ClientMessage
;
800 ev
.xclient
.window
= c
->win
;
801 ev
.xclient
.message_type
= XInternAtom(globalconf
.display
, "WM_PROTOCOLS", False
);
802 ev
.xclient
.format
= 32;
803 ev
.xclient
.data
.l
[0] = XInternAtom(globalconf
.display
, "WM_DELETE_WINDOW", False
);
804 ev
.xclient
.data
.l
[1] = CurrentTime
;
805 XSendEvent(globalconf
.display
, c
->win
, False
, NoEventMask
, &ev
);
808 XKillClient(globalconf
.display
, c
->win
);
811 /** Kill selected client
812 * \param screen Screen ID
814 * \ingroup ui_callback
817 uicb_client_kill(int screen
__attribute__ ((unused
)), char *arg
__attribute__ ((unused
)))
819 Client
*sel
= globalconf
.focus
->client
;
826 client_maximize(Client
*c
, Area geometry
)
829 if((c
->ismax
= !c
->ismax
))
831 c
->wasfloating
= c
->isfloating
;
832 c
->m_geometry
= c
->geometry
;
833 if(get_current_layout(c
->screen
)->arrange
!= layout_floating
)
834 client_setfloating(c
, True
);
835 client_resize(c
, geometry
, False
);
836 widget_invalidate_cache(c
->screen
, WIDGET_CACHE_CLIENTS
);
838 else if(c
->wasfloating
)
840 client_setfloating(c
, True
);
841 client_resize(c
, c
->m_geometry
, False
);
842 widget_invalidate_cache(c
->screen
, WIDGET_CACHE_CLIENTS
);
844 else if(get_current_layout(c
->screen
)->arrange
== layout_floating
)
846 client_resize(c
, c
->m_geometry
, False
);
847 widget_invalidate_cache(c
->screen
, WIDGET_CACHE_CLIENTS
);
851 client_setfloating(c
, False
);
852 widget_invalidate_cache(c
->screen
, WIDGET_CACHE_CLIENTS
);
856 /** Toggle maximize for client
857 * \param screen Screen ID
859 * \ingroup ui_callback
862 uicb_client_togglemax(int screen
, char *arg
__attribute__ ((unused
)))
864 Client
*sel
= globalconf
.focus
->client
;
865 Area area
= get_screen_area(screen
,
866 globalconf
.screens
[screen
].statusbar
,
867 &globalconf
.screens
[screen
].padding
);
871 area
.width
-= 2 * sel
->border
;
872 area
.height
-= 2 * sel
->border
;
873 client_maximize(sel
, area
);
877 /** Toggle vertical maximize for client
878 * \param screen Screen ID
880 * \ingroup ui_callback
883 uicb_client_toggleverticalmax(int screen
, char *arg
__attribute__ ((unused
)))
885 Client
*sel
= globalconf
.focus
->client
;
886 Area area
= get_screen_area(screen
,
887 globalconf
.screens
[screen
].statusbar
,
888 &globalconf
.screens
[screen
].padding
);
892 area
.x
= sel
->geometry
.x
;
893 area
.width
= sel
->geometry
.width
;
894 area
.height
-= 2 * sel
->border
;
895 client_maximize(sel
, area
);
900 /** Toggle horizontal maximize for client
901 * \param screen Screen ID
903 * \ingroup ui_callback
906 uicb_client_togglehorizontalmax(int screen
, char *arg
__attribute__ ((unused
)))
908 Client
*sel
= globalconf
.focus
->client
;
909 Area area
= get_screen_area(screen
,
910 globalconf
.screens
[screen
].statusbar
,
911 &globalconf
.screens
[screen
].padding
);
915 area
.y
= sel
->geometry
.y
;
916 area
.height
= sel
->geometry
.height
;
917 area
.width
-= 2 * sel
->border
;
918 client_maximize(sel
, area
);
923 * \param screen Screen ID
925 * \ingroup ui_callback
928 uicb_client_zoom(int screen
, char *arg
__attribute__ ((unused
)))
930 Client
*c
, *sel
= globalconf
.focus
->client
;
932 for(c
= globalconf
.clients
; !client_isvisible(c
, screen
); c
= c
->next
);
934 for(sel
= sel
->next
; sel
&& !client_isvisible(sel
, screen
); sel
= sel
->next
);
939 client_list_detach(&globalconf
.clients
, sel
);
940 client_list_push(&globalconf
.clients
, sel
);
941 globalconf
.screens
[screen
].need_arrange
= True
;
944 /** Send focus to next client in stack
945 * \param screen Screen ID
947 * \ingroup ui_callback
950 uicb_client_focusnext(int screen
, char *arg
__attribute__ ((unused
)))
952 Client
*c
, *sel
= globalconf
.focus
->client
;
956 for(c
= sel
->next
; c
&& (c
->skip
|| !client_isvisible(c
, screen
)); c
= c
->next
);
958 for(c
= globalconf
.clients
; c
&& (c
->skip
|| !client_isvisible(c
, screen
)); c
= c
->next
);
960 focus(c
, True
, screen
);
963 /** Send focus to previous client in stack
964 * \param screen Screen ID
966 * \ingroup ui_callback
969 uicb_client_focusprev(int screen
, char *arg
__attribute__ ((unused
)))
973 if((prev
= client_find_prev_visible(globalconf
.focus
->client
)))
974 focus(prev
, True
, screen
);
977 /** Toggle floating state of a client
978 * \param screen Screen ID
980 * \ingroup ui_callback
983 uicb_client_togglefloating(int screen
__attribute__ ((unused
)),
984 char *arg
__attribute__ ((unused
)))
986 Client
*sel
= globalconf
.focus
->client
;
991 /* XXX should use client_setfloating */
992 if((sel
->isfloating
= !sel
->isfloating
))
993 client_resize(sel
, sel
->f_geometry
, False
);
995 client_resize(sel
, sel
->m_geometry
, False
);
996 globalconf
.screens
[sel
->screen
].need_arrange
= True
;
997 widget_invalidate_cache(sel
->screen
, WIDGET_CACHE_CLIENTS
);
1000 // vim: filetype=c:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=80