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 XSetWindowBorder(globalconf
.display
, c
->win
,
151 globalconf
.screens
[c
->screen
].colors_normal
[ColBorder
].pixel
);
152 widget_invalidate_cache(c
->screen
, WIDGET_CACHE_CLIENTS
);
153 focus_add_client(NULL
);
156 /** Ban client and unmap it
157 * \param c the client
160 client_ban(Client
*c
)
162 if(globalconf
.focus
->client
== c
)
164 XUnmapWindow(globalconf
.display
, c
->win
);
165 window_setstate(c
->win
, IconicState
);
168 /** Give focus to client, or to first client if c is NULL
170 * \param screen Screen ID
173 client_focus(Client
*c
, int screen
, Bool from_mouse
)
175 int phys_screen
= get_phys_screen(screen
);
177 /* if c is NULL or invisible, take next client in the focus history */
178 if(!c
|| (c
&& !client_isvisible(c
, screen
)))
180 c
= focus_get_current_client(screen
);
181 /* if c is still NULL take next client in the stack */
183 for(c
= globalconf
.clients
; c
&& (c
->skip
|| !client_isvisible(c
, screen
)); c
= c
->next
);
186 /* unfocus current selected client */
187 if(globalconf
.focus
->client
)
188 client_unfocus(globalconf
.focus
->client
);
192 /* save sel in focus history */
194 XSetWindowBorder(globalconf
.display
, c
->win
,
195 globalconf
.screens
[screen
].colors_selected
[ColBorder
].pixel
);
196 XSetInputFocus(globalconf
.display
, c
->win
, RevertToPointerRoot
, CurrentTime
);
198 || !globalconf
.screens
[screen
].sloppy_focus
199 || globalconf
.screens
[screen
].sloppy_focus_raise
)
200 XRaiseWindow(globalconf
.display
, c
->win
);
201 /* since we're dropping EnterWindow events and sometimes the window
202 * will appear under the mouse, grabbuttons */
203 window_grabbuttons(phys_screen
, c
->win
);
206 XSetInputFocus(globalconf
.display
,
207 RootWindow(globalconf
.display
, phys_screen
),
208 RevertToPointerRoot
, CurrentTime
);
210 widget_invalidate_cache(screen
, WIDGET_CACHE_CLIENTS
);
211 ewmh_update_net_active_window(phys_screen
);
212 globalconf
.drop_events
|= EnterWindowMask
;
215 /** Compute smart coordinates for a client window
216 * \param geometry current/requested client geometry
217 * \param screen screen used
218 * \return new geometry
221 client_get_smart_geometry(Area geometry
, int border
, int screen
)
224 Area newgeometry
= { 0, 0, 0, 0, NULL
};
225 Area
*screen_geometry
, *arealist
= NULL
, *r
;
228 screen_geometry
= p_new(Area
, 1);
230 *screen_geometry
= screen_get_area(screen
,
231 globalconf
.screens
[screen
].statusbar
,
232 &globalconf
.screens
[screen
].padding
);
234 area_list_push(&arealist
, screen_geometry
);
236 for(c
= globalconf
.clients
; c
; c
= c
->next
)
237 if(client_isvisible(c
, screen
))
239 newgeometry
= c
->f_geometry
;
240 newgeometry
.width
+= 2 * c
->border
;
241 newgeometry
.height
+= 2 * c
->border
;
242 area_list_remove(&arealist
, &newgeometry
);
245 newgeometry
.x
= geometry
.x
;
246 newgeometry
.y
= geometry
.y
;
247 newgeometry
.width
= 0;
248 newgeometry
.height
= 0;
250 for(r
= arealist
; r
; r
= r
->next
)
251 if(r
->width
>= geometry
.width
&& r
->height
>= geometry
.height
252 && r
->width
* r
->height
> newgeometry
.width
* newgeometry
.height
)
258 /* we did not found a space with enough space for our size:
259 * just take the biggest available and go in */
261 for(r
= arealist
; r
; r
= r
->next
)
262 if(r
->width
* r
->height
> newgeometry
.width
* newgeometry
.height
)
265 /* restore height and width */
266 newgeometry
.width
= geometry
.width
;
267 newgeometry
.height
= geometry
.height
;
270 if(AREA_RIGHT(newgeometry
) > AREA_RIGHT(*screen_geometry
))
271 newgeometry
.x
= screen_geometry
->x
+ screen_geometry
->width
- newgeometry
.width
- 2 * border
;
273 if(AREA_BOTTOM(newgeometry
) > AREA_BOTTOM(*screen_geometry
))
274 newgeometry
.y
= screen_geometry
->y
+ screen_geometry
->height
- newgeometry
.height
- 2 * border
;
276 area_list_wipe(&arealist
);
281 /** Manage a new client
282 * \param w The window
283 * \param wa Window attributes
284 * \param screen Screen ID
287 client_manage(Window w
, XWindowAttributes
*wa
, int screen
)
289 Client
*c
, *t
= NULL
;
296 int phys_screen
= get_phys_screen(screen
);
299 c
= p_new(Client
, 1);
301 c
->screen
= screen_get_bycoord(wa
->x
, wa
->y
);
303 screen_geom
= screen_get_area(c
->screen
,
304 globalconf
.screens
[screen
].statusbar
,
305 &globalconf
.screens
[screen
].padding
);
308 c
->geometry
.x
= c
->f_geometry
.x
= c
->m_geometry
.x
= MAX(wa
->x
, screen_geom
.x
);
309 c
->geometry
.y
= c
->f_geometry
.y
= c
->m_geometry
.y
= MAX(wa
->y
, screen_geom
.y
);
310 c
->geometry
.width
= c
->f_geometry
.width
= c
->m_geometry
.width
= wa
->width
;
311 c
->geometry
.height
= c
->f_geometry
.height
= c
->m_geometry
.height
= wa
->height
;
312 c
->oldborder
= wa
->border_width
;
315 c
->border
= globalconf
.screens
[screen
].borderpx
;
317 /* Set windows borders */
318 wc
.border_width
= c
->border
;
319 XConfigureWindow(globalconf
.display
, w
, CWBorderWidth
, &wc
);
320 XSetWindowBorder(globalconf
.display
, w
, globalconf
.screens
[screen
].colors_normal
[ColBorder
].pixel
);
321 /* propagates border_width, if size doesn't change */
322 window_configure(c
->win
, c
->geometry
, c
->border
);
324 /* update window title */
325 client_updatetitle(c
);
328 flags
= client_updatesizehints(c
);
329 client_updatewmhints(c
);
331 /* First check clients hints */
332 ewmh_check_client_hints(c
);
334 /* loadprops or apply rules if no props */
335 if(!client_loadprops(c
, screen
))
337 /* Get the client's rule */
338 if((rule
= rule_matching_client(c
)))
340 if(rule
->screen
!= RULE_NOSCREEN
)
341 move_client_to_screen(c
, rule
->screen
, True
);
343 move_client_to_screen(c
, screen
, True
);
344 tag_client_with_rule(c
, rule
);
346 switch(rule
->isfloating
)
351 client_setfloating(c
, True
);
354 client_setfloating(c
, False
);
358 if(rule
->opacity
>= 0.0f
)
359 window_settrans(c
->win
, rule
->opacity
);
362 move_client_to_screen(c
, screen
, True
);
363 /* check for transient and set tags like its parent,
364 * XGetTransientForHint returns 1 on success
366 if((rettrans
= XGetTransientForHint(globalconf
.display
, w
, &trans
))
367 && (t
= client_get_bywin(globalconf
.clients
, trans
)))
368 for(tag
= globalconf
.screens
[c
->screen
].tags
; tag
; tag
= tag
->next
)
369 if(is_client_tagged(t
, tag
))
372 /* should be floating if transsient or fixed */
374 client_setfloating(c
, rettrans
|| c
->isfixed
);
377 if(!(flags
& (USPosition
| PPosition
)))
378 c
->f_geometry
= client_get_smart_geometry(c
->f_geometry
, c
->border
, c
->screen
);
380 XSelectInput(globalconf
.display
, w
, StructureNotifyMask
| PropertyChangeMask
| EnterWindowMask
);
383 if(globalconf
.have_shape
)
385 XShapeSelectInput(globalconf
.display
, w
, ShapeNotifyMask
);
386 window_setshape(phys_screen
, c
->win
);
389 /* attach to the stack */
390 if((rule
= rule_matching_client(c
)) && rule
->not_master
)
391 client_list_append(&globalconf
.clients
, c
);
392 else if(globalconf
.screens
[c
->screen
].new_become_master
)
393 client_list_push(&globalconf
.clients
, c
);
395 client_list_append(&globalconf
.clients
, c
);
397 /* some windows require this */
398 XMoveResizeWindow(globalconf
.display
, c
->win
, c
->geometry
.x
, c
->geometry
.y
,
399 c
->geometry
.width
, c
->geometry
.height
);
401 widget_invalidate_cache(c
->screen
, WIDGET_CACHE_CLIENTS
);
402 ewmh_update_net_client_list(phys_screen
);
405 /** Resize client window
406 * \param c client to resize
407 * \param geometry new window geometry
408 * \param sizehints respect size hints
409 * \param return True if resize has been done
412 client_resize(Client
*c
, Area geometry
, Bool sizehints
)
415 double dx
, dy
, max
, min
, ratio
;
421 if(c
->minay
> 0 && c
->maxay
> 0 && (geometry
.height
- c
->baseh
) > 0
422 && (geometry
.width
- c
->basew
) > 0)
424 dx
= (double) (geometry
.width
- c
->basew
);
425 dy
= (double) (geometry
.height
- c
->baseh
);
426 min
= (double) (c
->minax
) / (double) (c
->minay
);
427 max
= (double) (c
->maxax
) / (double) (c
->maxay
);
429 if(max
> 0 && min
> 0 && ratio
> 0)
433 dy
= (dx
* min
+ dy
) / (min
* min
+ 1);
435 geometry
.width
= (int) dx
+ c
->basew
;
436 geometry
.height
= (int) dy
+ c
->baseh
;
440 dy
= (dx
* min
+ dy
) / (max
* max
+ 1);
442 geometry
.width
= (int) dx
+ c
->basew
;
443 geometry
.height
= (int) dy
+ c
->baseh
;
447 if(c
->minw
&& geometry
.width
< c
->minw
)
448 geometry
.width
= c
->minw
;
449 if(c
->minh
&& geometry
.height
< c
->minh
)
450 geometry
.height
= c
->minh
;
451 if(c
->maxw
&& geometry
.width
> c
->maxw
)
452 geometry
.width
= c
->maxw
;
453 if(c
->maxh
&& geometry
.height
> c
->maxh
)
454 geometry
.height
= c
->maxh
;
456 geometry
.width
-= (geometry
.width
- c
->basew
) % c
->incw
;
458 geometry
.height
-= (geometry
.height
- c
->baseh
) % c
->inch
;
460 if(geometry
.width
<= 0 || geometry
.height
<= 0)
462 /* offscreen appearance fixes */
463 area
= get_display_area(get_phys_screen(c
->screen
),
465 &globalconf
.screens
[c
->screen
].padding
);
466 if(geometry
.x
> area
.width
)
467 geometry
.x
= area
.width
- geometry
.width
- 2 * c
->border
;
468 if(geometry
.y
> area
.height
)
469 geometry
.y
= area
.height
- geometry
.height
- 2 * c
->border
;
470 if(geometry
.x
+ geometry
.width
+ 2 * c
->border
< 0)
472 if(geometry
.y
+ geometry
.height
+ 2 * c
->border
< 0)
475 if(c
->geometry
.x
!= geometry
.x
|| c
->geometry
.y
!= geometry
.y
476 || c
->geometry
.width
!= geometry
.width
|| c
->geometry
.height
!= geometry
.height
)
478 new_screen
= screen_get_bycoord(geometry
.x
, geometry
.y
);
480 c
->geometry
.x
= wc
.x
= geometry
.x
;
481 c
->geometry
.y
= wc
.y
= geometry
.y
;
482 c
->geometry
.width
= wc
.width
= geometry
.width
;
483 c
->geometry
.height
= wc
.height
= geometry
.height
;
484 wc
.border_width
= c
->border
;
486 /* save the floating geometry if the window is floating but not
489 get_current_layout(new_screen
)->arrange
== layout_floating
) && !c
->ismax
)
490 c
->f_geometry
= geometry
;
492 XConfigureWindow(globalconf
.display
, c
->win
,
493 CWX
| CWY
| CWWidth
| CWHeight
| CWBorderWidth
, &wc
);
494 window_configure(c
->win
, geometry
, c
->border
);
496 if(c
->screen
!= new_screen
)
497 move_client_to_screen(c
, new_screen
, False
);
505 client_setfloating(Client
*c
, Bool floating
)
507 if(c
->isfloating
!= floating
)
509 if((c
->isfloating
= floating
))
510 client_resize(c
, c
->f_geometry
, False
);
514 client_resize(c
, c
->m_geometry
, False
);
516 if(client_isvisible(c
, c
->screen
))
517 globalconf
.screens
[c
->screen
].need_arrange
= True
;
518 widget_invalidate_cache(c
->screen
, WIDGET_CACHE_CLIENTS
);
523 /** Save client properties as an X property
527 client_saveprops(Client
*c
)
529 int i
= 0, ntags
= 0;
533 for(tag
= globalconf
.screens
[c
->screen
].tags
; tag
; tag
= tag
->next
)
536 prop
= p_new(char, ntags
+ 2);
538 for(tag
= globalconf
.screens
[c
->screen
].tags
; tag
; tag
= tag
->next
, i
++)
539 prop
[i
] = is_client_tagged(c
, tag
) ? '1' : '0';
542 prop
[i
] = c
->isfloating
? '1' : '0';
546 XChangeProperty(globalconf
.display
, c
->win
,
547 XInternAtom(globalconf
.display
, "_AWESOME_PROPERTIES", False
),
548 XA_STRING
, 8, PropModeReplace
, (unsigned char *) prop
, i
);
554 client_unban(Client
*c
)
556 XMapWindow(globalconf
.display
, c
->win
);
557 window_setstate(c
->win
, NormalState
);
561 client_unmanage(Client
*c
)
566 wc
.border_width
= c
->oldborder
;
568 /* The server grab construct avoids race conditions. */
569 XGrabServer(globalconf
.display
);
571 XConfigureWindow(globalconf
.display
, c
->win
, CWBorderWidth
, &wc
); /* restore border */
573 /* remove client everywhere */
574 client_list_detach(&globalconf
.clients
, c
);
575 focus_delete_client(c
);
576 for(tag
= globalconf
.screens
[c
->screen
].tags
; tag
; tag
= tag
->next
)
577 untag_client(c
, tag
);
579 if(globalconf
.focus
->client
== c
)
580 client_focus(NULL
, c
->screen
, False
);
582 XUngrabButton(globalconf
.display
, AnyButton
, AnyModifier
, c
->win
);
583 window_setstate(c
->win
, WithdrawnState
);
585 XSync(globalconf
.display
, False
);
586 XUngrabServer(globalconf
.display
);
592 client_updatewmhints(Client
*c
)
596 if((wmh
= XGetWMHints(globalconf
.display
, c
->win
)))
598 if((c
->isurgent
= (wmh
->flags
& XUrgencyHint
)))
599 widget_invalidate_cache(c
->screen
, WIDGET_CACHE_CLIENTS
);
600 if((wmh
->flags
& StateHint
) && wmh
->initial_state
== WithdrawnState
)
610 client_updatesizehints(Client
*c
)
615 if(!XGetWMNormalHints(globalconf
.display
, c
->win
, &size
, &msize
))
618 if(size
.flags
& PBaseSize
)
620 c
->basew
= size
.base_width
;
621 c
->baseh
= size
.base_height
;
623 else if(size
.flags
& PMinSize
)
625 c
->basew
= size
.min_width
;
626 c
->baseh
= size
.min_height
;
629 c
->basew
= c
->baseh
= 0;
630 if(size
.flags
& PResizeInc
)
632 c
->incw
= size
.width_inc
;
633 c
->inch
= size
.height_inc
;
636 c
->incw
= c
->inch
= 0;
638 if(size
.flags
& PMaxSize
)
640 c
->maxw
= size
.max_width
;
641 c
->maxh
= size
.max_height
;
644 c
->maxw
= c
->maxh
= 0;
646 if(size
.flags
& PMinSize
)
648 c
->minw
= size
.min_width
;
649 c
->minh
= size
.min_height
;
651 else if(size
.flags
& PBaseSize
)
653 c
->minw
= size
.base_width
;
654 c
->minh
= size
.base_height
;
657 c
->minw
= c
->minh
= 0;
659 if(size
.flags
& PAspect
)
661 c
->minax
= size
.min_aspect
.x
;
662 c
->maxax
= size
.max_aspect
.x
;
663 c
->minay
= size
.min_aspect
.y
;
664 c
->maxay
= size
.max_aspect
.y
;
667 c
->minax
= c
->maxax
= c
->minay
= c
->maxay
= 0;
669 if(c
->maxw
&& c
->minw
&& c
->maxh
&& c
->minh
670 && c
->maxw
== c
->minw
&& c
->maxh
== c
->minh
)
676 /** Returns True if a client is tagged
677 * with one of the tags
678 * \return True or False
681 client_isvisible(Client
*c
, int screen
)
685 if(!c
|| c
->screen
!= screen
)
688 for(tag
= globalconf
.screens
[screen
].tags
; tag
; tag
= tag
->next
)
689 if(tag
->selected
&& is_client_tagged(c
, tag
))
694 /** Set selected client transparency
695 * \param screen Screen ID
696 * \param arg unused arg
697 * \ingroup ui_callback
700 uicb_client_settrans(int screen
__attribute__ ((unused
)), char *arg
)
702 double delta
= 100.0, current_opacity
= 100.0;
706 unsigned long n
, left
;
707 unsigned int current_opacity_raw
= 0;
709 Client
*sel
= globalconf
.focus
->client
;
714 XGetWindowProperty(globalconf
.display
, sel
->win
,
715 XInternAtom(globalconf
.display
, "_NET_WM_WINDOW_OPACITY", False
),
716 0L, 1L, False
, XA_CARDINAL
, &actual
, &format
, &n
, &left
,
717 (unsigned char **) &data
);
720 memcpy(¤t_opacity_raw
, data
, sizeof(unsigned int));
722 current_opacity
= (current_opacity_raw
* 100.0) / 0xffffffff;
727 delta
= compute_new_value_from_arg(arg
, current_opacity
);
731 else if(delta
> 100.0)
737 if(delta
== 100.0 && !set_prop
)
738 window_settrans(sel
->win
, -1);
740 window_settrans(sel
->win
, delta
);
744 client_find_prev_visible(Client
*sel
)
748 if(!sel
) return NULL
;
750 /* look for previous starting at sel */
751 for(prev
= client_list_prev_cycle(&globalconf
.clients
, sel
);
752 prev
&& (prev
->skip
|| !client_isvisible(prev
, sel
->screen
));
753 prev
= client_list_prev_cycle(&globalconf
.clients
, prev
));
759 client_find_next_visible(Client
*sel
)
763 if(!sel
) return NULL
;
765 for(next
= sel
->next
; next
&& !client_isvisible(next
, sel
->screen
); next
= next
->next
);
767 for(next
= globalconf
.clients
; next
&& !client_isvisible(next
, sel
->screen
); next
= next
->next
);
772 /** Swap current with previous client
773 * \param screen Screen ID
775 * \ingroup ui_callback
778 uicb_client_swapprev(int screen
__attribute__ ((unused
)),
779 char *arg
__attribute__ ((unused
)))
783 if((prev
= client_find_prev_visible(globalconf
.focus
->client
)))
785 client_list_swap(&globalconf
.clients
, prev
, globalconf
.focus
->client
);
786 globalconf
.screens
[prev
->screen
].need_arrange
= True
;
787 globalconf
.drop_events
|= EnterWindowMask
;
791 /** Swap current with next client
792 * \param screen Screen ID
794 * \ingroup ui_callback
797 uicb_client_swapnext(int screen
__attribute__ ((unused
)),
798 char *arg
__attribute__ ((unused
)))
802 if((next
= client_find_next_visible(globalconf
.focus
->client
)))
804 client_list_swap(&globalconf
.clients
, globalconf
.focus
->client
, next
);
805 globalconf
.screens
[next
->screen
].need_arrange
= True
;
806 globalconf
.drop_events
|= EnterWindowMask
;
810 /** Move and resize client
811 * \param screen Screen ID
813 * \ingroup ui_callback
816 uicb_client_moveresize(int screen
, char *arg
)
819 char x
[8], y
[8], w
[8], h
[8];
820 int mx
, my
, dx
, dy
, nmx
, nmy
;
824 Client
*sel
= globalconf
.focus
->client
;
825 Tag
**curtags
= tags_get_current(screen
);
827 if(curtags
[0]->layout
->arrange
!= layout_floating
)
828 if(!sel
|| !sel
->isfloating
|| sel
->isfixed
|| !arg
)
834 if(sscanf(arg
, "%s %s %s %s", x
, y
, w
, h
) != 4)
836 area
.x
= (int) compute_new_value_from_arg(x
, sel
->geometry
.x
);
837 area
.y
= (int) compute_new_value_from_arg(y
, sel
->geometry
.y
);
838 area
.width
= (int) compute_new_value_from_arg(w
, sel
->geometry
.width
);
839 area
.height
= (int) compute_new_value_from_arg(h
, sel
->geometry
.height
);
841 ox
= sel
->geometry
.x
;
842 oy
= sel
->geometry
.y
;
843 ow
= sel
->geometry
.width
;
844 oh
= sel
->geometry
.height
;
846 Bool xqp
= XQueryPointer(globalconf
.display
,
847 RootWindow(globalconf
.display
,
848 get_phys_screen(screen
)),
849 &dummy
, &dummy
, &mx
, &my
, &dx
, &dy
, &dui
);
850 client_resize(sel
, area
, globalconf
.screens
[sel
->screen
].resize_hints
);
851 if (xqp
&& ox
<= mx
&& (ox
+ ow
) >= mx
&& oy
<= my
&& (oy
+ oh
) >= my
)
853 nmx
= mx
- ox
+ sel
->geometry
.width
- ow
- 1 < 0 ? 0 : mx
- ox
+ sel
->geometry
.width
- ow
- 1;
854 nmy
= my
- oy
+ sel
->geometry
.height
- oh
- 1 < 0 ? 0 : my
- oy
+ sel
->geometry
.height
- oh
- 1;
855 XWarpPointer(globalconf
.display
,
857 0, 0, 0, 0, nmx
, nmy
);
862 client_kill(Client
*c
)
866 if(client_isprotodel(globalconf
.display
, c
->win
))
868 ev
.type
= ClientMessage
;
869 ev
.xclient
.window
= c
->win
;
870 ev
.xclient
.message_type
= XInternAtom(globalconf
.display
, "WM_PROTOCOLS", False
);
871 ev
.xclient
.format
= 32;
872 ev
.xclient
.data
.l
[0] = XInternAtom(globalconf
.display
, "WM_DELETE_WINDOW", False
);
873 ev
.xclient
.data
.l
[1] = CurrentTime
;
874 XSendEvent(globalconf
.display
, c
->win
, False
, NoEventMask
, &ev
);
877 XKillClient(globalconf
.display
, c
->win
);
880 /** Kill selected client
881 * \param screen Screen ID
883 * \ingroup ui_callback
886 uicb_client_kill(int screen
__attribute__ ((unused
)), char *arg
__attribute__ ((unused
)))
888 Client
*sel
= globalconf
.focus
->client
;
895 client_maximize(Client
*c
, Area geometry
)
898 if((c
->ismax
= !c
->ismax
))
900 c
->wasfloating
= c
->isfloating
;
901 c
->m_geometry
= c
->geometry
;
902 if(get_current_layout(c
->screen
)->arrange
!= layout_floating
)
903 client_setfloating(c
, True
);
904 client_resize(c
, geometry
, False
);
905 widget_invalidate_cache(c
->screen
, WIDGET_CACHE_CLIENTS
);
907 else if(c
->wasfloating
)
909 client_setfloating(c
, True
);
910 client_resize(c
, c
->m_geometry
, False
);
911 widget_invalidate_cache(c
->screen
, WIDGET_CACHE_CLIENTS
);
913 else if(get_current_layout(c
->screen
)->arrange
== layout_floating
)
915 client_resize(c
, c
->m_geometry
, False
);
916 widget_invalidate_cache(c
->screen
, WIDGET_CACHE_CLIENTS
);
920 client_setfloating(c
, False
);
921 widget_invalidate_cache(c
->screen
, WIDGET_CACHE_CLIENTS
);
925 /** Toggle maximize for client
926 * \param screen Screen ID
928 * \ingroup ui_callback
931 uicb_client_togglemax(int screen
, char *arg
__attribute__ ((unused
)))
933 Client
*sel
= globalconf
.focus
->client
;
934 Area area
= screen_get_area(screen
,
935 globalconf
.screens
[screen
].statusbar
,
936 &globalconf
.screens
[screen
].padding
);
940 area
.width
-= 2 * sel
->border
;
941 area
.height
-= 2 * sel
->border
;
942 client_maximize(sel
, area
);
946 /** Toggle vertical maximize for client
947 * \param screen Screen ID
949 * \ingroup ui_callback
952 uicb_client_toggleverticalmax(int screen
, char *arg
__attribute__ ((unused
)))
954 Client
*sel
= globalconf
.focus
->client
;
955 Area area
= screen_get_area(screen
,
956 globalconf
.screens
[screen
].statusbar
,
957 &globalconf
.screens
[screen
].padding
);
961 area
.x
= sel
->geometry
.x
;
962 area
.width
= sel
->geometry
.width
;
963 area
.height
-= 2 * sel
->border
;
964 client_maximize(sel
, area
);
969 /** Toggle horizontal maximize for client
970 * \param screen Screen ID
972 * \ingroup ui_callback
975 uicb_client_togglehorizontalmax(int screen
, char *arg
__attribute__ ((unused
)))
977 Client
*sel
= globalconf
.focus
->client
;
978 Area area
= screen_get_area(screen
,
979 globalconf
.screens
[screen
].statusbar
,
980 &globalconf
.screens
[screen
].padding
);
984 area
.y
= sel
->geometry
.y
;
985 area
.height
= sel
->geometry
.height
;
986 area
.width
-= 2 * sel
->border
;
987 client_maximize(sel
, area
);
992 * \param screen Screen ID
994 * \ingroup ui_callback
997 uicb_client_zoom(int screen
, char *arg
__attribute__ ((unused
)))
999 Client
*c
, *sel
= globalconf
.focus
->client
;
1001 for(c
= globalconf
.clients
; !client_isvisible(c
, screen
); c
= c
->next
);
1003 for(sel
= sel
->next
; sel
&& !client_isvisible(sel
, screen
); sel
= sel
->next
);
1008 client_list_detach(&globalconf
.clients
, sel
);
1009 client_list_push(&globalconf
.clients
, sel
);
1010 globalconf
.screens
[screen
].need_arrange
= True
;
1011 globalconf
.drop_events
|= EnterWindowMask
;
1014 /** Send focus to next client in stack
1015 * \param screen Screen ID
1017 * \ingroup ui_callback
1020 uicb_client_focusnext(int screen
, char *arg
__attribute__ ((unused
)))
1022 Client
*c
, *sel
= globalconf
.focus
->client
;
1026 for(c
= sel
->next
; c
&& (c
->skip
|| !client_isvisible(c
, screen
)); c
= c
->next
);
1028 for(c
= globalconf
.clients
; c
&& (c
->skip
|| !client_isvisible(c
, screen
)); c
= c
->next
);
1030 client_focus(c
, screen
, False
);
1033 /** Send focus to previous client in stack
1034 * \param screen Screen ID
1036 * \ingroup ui_callback
1039 uicb_client_focusprev(int screen
, char *arg
__attribute__ ((unused
)))
1043 if((prev
= client_find_prev_visible(globalconf
.focus
->client
)))
1044 client_focus(prev
, screen
, False
);
1047 /** Toggle floating state of a client
1048 * \param screen Screen ID
1050 * \ingroup ui_callback
1053 uicb_client_togglefloating(int screen
__attribute__ ((unused
)),
1054 char *arg
__attribute__ ((unused
)))
1056 if(globalconf
.focus
->client
)
1057 client_setfloating(globalconf
.focus
->client
, !globalconf
.focus
->client
->isfloating
);
1060 // vim: filetype=c:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=80