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 /* unban the client before focusing or it will fail */
196 /* save sel in focus history */
198 if(globalconf
.screens
[c
->screen
].opacity_unfocused
!= -1)
199 window_settrans(c
->win
, globalconf
.screens
[screen
].opacity_unfocused
);
200 XSetWindowBorder(globalconf
.display
, c
->win
,
201 globalconf
.screens
[screen
].colors_selected
[ColBorder
].pixel
);
202 XSetInputFocus(globalconf
.display
, c
->win
, RevertToPointerRoot
, CurrentTime
);
204 || (globalconf
.screens
[screen
].sloppy_focus
&& globalconf
.screens
[screen
].sloppy_focus_raise
))
205 XRaiseWindow(globalconf
.display
, c
->win
);
206 /* since we're dropping EnterWindow events and sometimes the window
207 * will appear under the mouse, grabbuttons */
208 window_grabbuttons(phys_screen
, c
->win
);
211 XSetInputFocus(globalconf
.display
,
212 RootWindow(globalconf
.display
, phys_screen
),
213 RevertToPointerRoot
, CurrentTime
);
215 widget_invalidate_cache(screen
, WIDGET_CACHE_CLIENTS
);
216 ewmh_update_net_active_window(phys_screen
);
217 globalconf
.drop_events
|= EnterWindowMask
;
220 /** Compute smart coordinates for a client window
221 * \param geometry current/requested client geometry
222 * \param screen screen used
223 * \return new geometry
226 client_get_smart_geometry(Area geometry
, int border
, int screen
)
229 Area newgeometry
= { 0, 0, 0, 0, NULL
};
230 Area
*screen_geometry
, *arealist
= NULL
, *r
;
233 screen_geometry
= p_new(Area
, 1);
235 *screen_geometry
= screen_get_area(screen
,
236 globalconf
.screens
[screen
].statusbar
,
237 &globalconf
.screens
[screen
].padding
);
239 area_list_push(&arealist
, screen_geometry
);
241 for(c
= globalconf
.clients
; c
; c
= c
->next
)
242 if(client_isvisible(c
, screen
))
244 newgeometry
= c
->f_geometry
;
245 newgeometry
.width
+= 2 * c
->border
;
246 newgeometry
.height
+= 2 * c
->border
;
247 area_list_remove(&arealist
, &newgeometry
);
250 newgeometry
.x
= geometry
.x
;
251 newgeometry
.y
= geometry
.y
;
252 newgeometry
.width
= 0;
253 newgeometry
.height
= 0;
255 for(r
= arealist
; r
; r
= r
->next
)
256 if(r
->width
>= geometry
.width
&& r
->height
>= geometry
.height
257 && r
->width
* r
->height
> newgeometry
.width
* newgeometry
.height
)
263 /* we did not found a space with enough space for our size:
264 * just take the biggest available and go in */
266 for(r
= arealist
; r
; r
= r
->next
)
267 if(r
->width
* r
->height
> newgeometry
.width
* newgeometry
.height
)
270 /* restore height and width */
271 newgeometry
.width
= geometry
.width
;
272 newgeometry
.height
= geometry
.height
;
275 if(AREA_RIGHT(newgeometry
) > AREA_RIGHT(*screen_geometry
))
276 newgeometry
.x
= screen_geometry
->x
+ screen_geometry
->width
- newgeometry
.width
- 2 * border
;
278 if(AREA_BOTTOM(newgeometry
) > AREA_BOTTOM(*screen_geometry
))
279 newgeometry
.y
= screen_geometry
->y
+ screen_geometry
->height
- newgeometry
.height
- 2 * border
;
281 area_list_wipe(&arealist
);
286 /** Manage a new client
287 * \param w The window
288 * \param wa Window attributes
289 * \param screen Screen ID
292 client_manage(Window w
, XWindowAttributes
*wa
, int screen
)
294 Client
*c
, *t
= NULL
;
301 int phys_screen
= get_phys_screen(screen
);
304 c
= p_new(Client
, 1);
306 c
->screen
= screen_get_bycoord(wa
->x
, wa
->y
);
308 screen_geom
= screen_get_area(c
->screen
,
309 globalconf
.screens
[screen
].statusbar
,
310 &globalconf
.screens
[screen
].padding
);
313 c
->geometry
.x
= c
->f_geometry
.x
= c
->m_geometry
.x
= MAX(wa
->x
, screen_geom
.x
);
314 c
->geometry
.y
= c
->f_geometry
.y
= c
->m_geometry
.y
= MAX(wa
->y
, screen_geom
.y
);
315 c
->geometry
.width
= c
->f_geometry
.width
= c
->m_geometry
.width
= wa
->width
;
316 c
->geometry
.height
= c
->f_geometry
.height
= c
->m_geometry
.height
= wa
->height
;
317 c
->oldborder
= wa
->border_width
;
320 c
->border
= globalconf
.screens
[screen
].borderpx
;
322 /* Set windows borders */
323 wc
.border_width
= c
->border
;
324 XConfigureWindow(globalconf
.display
, w
, CWBorderWidth
, &wc
);
325 XSetWindowBorder(globalconf
.display
, w
, globalconf
.screens
[screen
].colors_normal
[ColBorder
].pixel
);
326 /* propagates border_width, if size doesn't change */
327 window_configure(c
->win
, c
->geometry
, c
->border
);
329 /* update window title */
330 client_updatetitle(c
);
333 flags
= client_updatesizehints(c
);
334 client_updatewmhints(c
);
336 /* First check clients hints */
337 ewmh_check_client_hints(c
);
339 /* loadprops or apply rules if no props */
340 if(!client_loadprops(c
, screen
))
342 /* Get the client's rule */
343 if((rule
= rule_matching_client(c
)))
345 if(rule
->screen
!= RULE_NOSCREEN
)
346 move_client_to_screen(c
, rule
->screen
, True
);
348 move_client_to_screen(c
, screen
, True
);
349 tag_client_with_rule(c
, rule
);
351 switch(rule
->isfloating
)
356 client_setfloating(c
, True
);
359 client_setfloating(c
, False
);
363 if(rule
->opacity
>= 0.0f
)
364 window_settrans(c
->win
, rule
->opacity
);
367 move_client_to_screen(c
, screen
, True
);
368 /* check for transient and set tags like its parent,
369 * XGetTransientForHint returns 1 on success
371 if((rettrans
= XGetTransientForHint(globalconf
.display
, w
, &trans
))
372 && (t
= client_get_bywin(globalconf
.clients
, trans
)))
373 for(tag
= globalconf
.screens
[c
->screen
].tags
; tag
; tag
= tag
->next
)
374 if(is_client_tagged(t
, tag
))
377 /* should be floating if transsient or fixed */
379 client_setfloating(c
, rettrans
|| c
->isfixed
);
382 if(!(flags
& (USPosition
| PPosition
)))
383 c
->f_geometry
= client_get_smart_geometry(c
->f_geometry
, c
->border
, c
->screen
);
385 XSelectInput(globalconf
.display
, w
, StructureNotifyMask
| PropertyChangeMask
| EnterWindowMask
);
388 if(globalconf
.have_shape
)
390 XShapeSelectInput(globalconf
.display
, w
, ShapeNotifyMask
);
391 window_setshape(phys_screen
, c
->win
);
394 /* attach to the stack */
395 if((rule
= rule_matching_client(c
)))
396 switch(rule
->ismaster
)
399 client_list_push(&globalconf
.clients
, c
);
402 client_list_append(&globalconf
.clients
, c
);
411 if(globalconf
.screens
[c
->screen
].new_become_master
)
412 client_list_push(&globalconf
.clients
, c
);
414 client_list_append(&globalconf
.clients
, c
);
417 /* some windows require this */
418 XMoveResizeWindow(globalconf
.display
, c
->win
, c
->geometry
.x
, c
->geometry
.y
,
419 c
->geometry
.width
, c
->geometry
.height
);
421 widget_invalidate_cache(c
->screen
, WIDGET_CACHE_CLIENTS
);
422 ewmh_update_net_client_list(phys_screen
);
425 /** Resize client window
426 * \param c client to resize
427 * \param geometry new window geometry
428 * \param sizehints respect size hints
429 * \param return True if resize has been done
432 client_resize(Client
*c
, Area geometry
, Bool sizehints
)
435 double dx
, dy
, max
, min
, ratio
;
441 if(c
->minay
> 0 && c
->maxay
> 0 && (geometry
.height
- c
->baseh
) > 0
442 && (geometry
.width
- c
->basew
) > 0)
444 dx
= (double) (geometry
.width
- c
->basew
);
445 dy
= (double) (geometry
.height
- c
->baseh
);
446 min
= (double) (c
->minax
) / (double) (c
->minay
);
447 max
= (double) (c
->maxax
) / (double) (c
->maxay
);
449 if(max
> 0 && min
> 0 && ratio
> 0)
453 dy
= (dx
* min
+ dy
) / (min
* min
+ 1);
455 geometry
.width
= (int) dx
+ c
->basew
;
456 geometry
.height
= (int) dy
+ c
->baseh
;
460 dy
= (dx
* min
+ dy
) / (max
* max
+ 1);
462 geometry
.width
= (int) dx
+ c
->basew
;
463 geometry
.height
= (int) dy
+ c
->baseh
;
467 if(c
->minw
&& geometry
.width
< c
->minw
)
468 geometry
.width
= c
->minw
;
469 if(c
->minh
&& geometry
.height
< c
->minh
)
470 geometry
.height
= c
->minh
;
471 if(c
->maxw
&& geometry
.width
> c
->maxw
)
472 geometry
.width
= c
->maxw
;
473 if(c
->maxh
&& geometry
.height
> c
->maxh
)
474 geometry
.height
= c
->maxh
;
476 geometry
.width
-= (geometry
.width
- c
->basew
) % c
->incw
;
478 geometry
.height
-= (geometry
.height
- c
->baseh
) % c
->inch
;
480 if(geometry
.width
<= 0 || geometry
.height
<= 0)
482 /* offscreen appearance fixes */
483 area
= get_display_area(get_phys_screen(c
->screen
),
485 &globalconf
.screens
[c
->screen
].padding
);
486 if(geometry
.x
> area
.width
)
487 geometry
.x
= area
.width
- geometry
.width
- 2 * c
->border
;
488 if(geometry
.y
> area
.height
)
489 geometry
.y
= area
.height
- geometry
.height
- 2 * c
->border
;
490 if(geometry
.x
+ geometry
.width
+ 2 * c
->border
< 0)
492 if(geometry
.y
+ geometry
.height
+ 2 * c
->border
< 0)
495 if(c
->geometry
.x
!= geometry
.x
|| c
->geometry
.y
!= geometry
.y
496 || c
->geometry
.width
!= geometry
.width
|| c
->geometry
.height
!= geometry
.height
)
498 new_screen
= screen_get_bycoord(geometry
.x
, geometry
.y
);
500 c
->geometry
.x
= wc
.x
= geometry
.x
;
501 c
->geometry
.y
= wc
.y
= geometry
.y
;
502 c
->geometry
.width
= wc
.width
= geometry
.width
;
503 c
->geometry
.height
= wc
.height
= geometry
.height
;
504 wc
.border_width
= c
->border
;
506 /* save the floating geometry if the window is floating but not
509 get_current_layout(new_screen
)->arrange
== layout_floating
) && !c
->ismax
)
510 c
->f_geometry
= geometry
;
512 XConfigureWindow(globalconf
.display
, c
->win
,
513 CWX
| CWY
| CWWidth
| CWHeight
| CWBorderWidth
, &wc
);
514 window_configure(c
->win
, geometry
, c
->border
);
516 if(c
->screen
!= new_screen
)
517 move_client_to_screen(c
, new_screen
, False
);
525 client_setfloating(Client
*c
, Bool floating
)
527 if(c
->isfloating
!= floating
)
529 if((c
->isfloating
= floating
))
530 client_resize(c
, c
->f_geometry
, False
);
534 client_resize(c
, c
->m_geometry
, False
);
536 if(client_isvisible(c
, c
->screen
))
537 globalconf
.screens
[c
->screen
].need_arrange
= True
;
538 widget_invalidate_cache(c
->screen
, WIDGET_CACHE_CLIENTS
);
543 /** Save client properties as an X property
547 client_saveprops(Client
*c
)
549 int i
= 0, ntags
= 0;
553 for(tag
= globalconf
.screens
[c
->screen
].tags
; tag
; tag
= tag
->next
)
556 prop
= p_new(char, ntags
+ 2);
558 for(tag
= globalconf
.screens
[c
->screen
].tags
; tag
; tag
= tag
->next
, i
++)
559 prop
[i
] = is_client_tagged(c
, tag
) ? '1' : '0';
562 prop
[i
] = c
->isfloating
? '1' : '0';
566 XChangeProperty(globalconf
.display
, c
->win
,
567 XInternAtom(globalconf
.display
, "_AWESOME_PROPERTIES", False
),
568 XA_STRING
, 8, PropModeReplace
, (unsigned char *) prop
, i
);
574 client_unban(Client
*c
)
576 XMapWindow(globalconf
.display
, c
->win
);
577 window_setstate(c
->win
, NormalState
);
581 client_unmanage(Client
*c
)
586 wc
.border_width
= c
->oldborder
;
588 /* The server grab construct avoids race conditions. */
589 XGrabServer(globalconf
.display
);
591 XConfigureWindow(globalconf
.display
, c
->win
, CWBorderWidth
, &wc
); /* restore border */
593 /* remove client everywhere */
594 client_list_detach(&globalconf
.clients
, c
);
595 focus_delete_client(c
);
596 for(tag
= globalconf
.screens
[c
->screen
].tags
; tag
; tag
= tag
->next
)
597 untag_client(c
, tag
);
599 if(globalconf
.focus
->client
== c
)
600 client_focus(NULL
, c
->screen
, False
);
602 XUngrabButton(globalconf
.display
, AnyButton
, AnyModifier
, c
->win
);
603 window_setstate(c
->win
, WithdrawnState
);
605 XSync(globalconf
.display
, False
);
606 XUngrabServer(globalconf
.display
);
612 client_updatewmhints(Client
*c
)
616 if((wmh
= XGetWMHints(globalconf
.display
, c
->win
)))
618 if((c
->isurgent
= (wmh
->flags
& XUrgencyHint
)))
619 widget_invalidate_cache(c
->screen
, WIDGET_CACHE_CLIENTS
);
620 if((wmh
->flags
& StateHint
) && wmh
->initial_state
== WithdrawnState
)
630 client_updatesizehints(Client
*c
)
635 if(!XGetWMNormalHints(globalconf
.display
, c
->win
, &size
, &msize
))
638 if(size
.flags
& PBaseSize
)
640 c
->basew
= size
.base_width
;
641 c
->baseh
= size
.base_height
;
643 else if(size
.flags
& PMinSize
)
645 c
->basew
= size
.min_width
;
646 c
->baseh
= size
.min_height
;
649 c
->basew
= c
->baseh
= 0;
650 if(size
.flags
& PResizeInc
)
652 c
->incw
= size
.width_inc
;
653 c
->inch
= size
.height_inc
;
656 c
->incw
= c
->inch
= 0;
658 if(size
.flags
& PMaxSize
)
660 c
->maxw
= size
.max_width
;
661 c
->maxh
= size
.max_height
;
664 c
->maxw
= c
->maxh
= 0;
666 if(size
.flags
& PMinSize
)
668 c
->minw
= size
.min_width
;
669 c
->minh
= size
.min_height
;
671 else if(size
.flags
& PBaseSize
)
673 c
->minw
= size
.base_width
;
674 c
->minh
= size
.base_height
;
677 c
->minw
= c
->minh
= 0;
679 if(size
.flags
& PAspect
)
681 c
->minax
= size
.min_aspect
.x
;
682 c
->maxax
= size
.max_aspect
.x
;
683 c
->minay
= size
.min_aspect
.y
;
684 c
->maxay
= size
.max_aspect
.y
;
687 c
->minax
= c
->maxax
= c
->minay
= c
->maxay
= 0;
689 if(c
->maxw
&& c
->minw
&& c
->maxh
&& c
->minh
690 && c
->maxw
== c
->minw
&& c
->maxh
== c
->minh
)
696 /** Returns True if a client is tagged
697 * with one of the tags
698 * \return True or False
701 client_isvisible(Client
*c
, int screen
)
705 if(!c
|| c
->screen
!= screen
)
708 if(globalconf
.scratch
.client
== c
)
709 return globalconf
.scratch
.isvisible
;
711 for(tag
= globalconf
.screens
[screen
].tags
; tag
; tag
= tag
->next
)
712 if(tag
->selected
&& is_client_tagged(c
, tag
))
717 /** Set selected client transparency
718 * \param screen Screen ID
719 * \param arg unused arg
720 * \ingroup ui_callback
723 uicb_client_settrans(int screen
__attribute__ ((unused
)), char *arg
)
725 double delta
= 100.0, current_opacity
= 100.0;
729 unsigned long n
, left
;
730 unsigned int current_opacity_raw
= 0;
732 Client
*sel
= globalconf
.focus
->client
;
737 XGetWindowProperty(globalconf
.display
, sel
->win
,
738 XInternAtom(globalconf
.display
, "_NET_WM_WINDOW_OPACITY", False
),
739 0L, 1L, False
, XA_CARDINAL
, &actual
, &format
, &n
, &left
,
740 (unsigned char **) &data
);
743 memcpy(¤t_opacity_raw
, data
, sizeof(unsigned int));
745 current_opacity
= (current_opacity_raw
* 100.0) / 0xffffffff;
750 delta
= compute_new_value_from_arg(arg
, current_opacity
);
754 else if(delta
> 100.0)
760 if(delta
== 100.0 && !set_prop
)
761 window_settrans(sel
->win
, -1);
763 window_settrans(sel
->win
, delta
);
767 client_find_prev_visible(Client
*sel
)
771 if(!sel
) return NULL
;
773 /* look for previous starting at sel */
774 for(prev
= client_list_prev_cycle(&globalconf
.clients
, sel
);
775 prev
&& (prev
->skip
|| !client_isvisible(prev
, sel
->screen
));
776 prev
= client_list_prev_cycle(&globalconf
.clients
, prev
));
782 client_find_next_visible(Client
*sel
)
786 if(!sel
) return NULL
;
788 for(next
= sel
->next
; next
&& !client_isvisible(next
, sel
->screen
); next
= next
->next
);
790 for(next
= globalconf
.clients
; next
&& !client_isvisible(next
, sel
->screen
); next
= next
->next
);
795 /** Swap current with previous client
796 * \param screen Screen ID
798 * \ingroup ui_callback
801 uicb_client_swapprev(int screen
__attribute__ ((unused
)),
802 char *arg
__attribute__ ((unused
)))
806 if((prev
= client_find_prev_visible(globalconf
.focus
->client
)))
808 client_list_swap(&globalconf
.clients
, prev
, globalconf
.focus
->client
);
809 globalconf
.screens
[prev
->screen
].need_arrange
= True
;
810 globalconf
.drop_events
|= EnterWindowMask
;
814 /** Swap current with next client
815 * \param screen Screen ID
817 * \ingroup ui_callback
820 uicb_client_swapnext(int screen
__attribute__ ((unused
)),
821 char *arg
__attribute__ ((unused
)))
825 if((next
= client_find_next_visible(globalconf
.focus
->client
)))
827 client_list_swap(&globalconf
.clients
, globalconf
.focus
->client
, next
);
828 globalconf
.screens
[next
->screen
].need_arrange
= True
;
829 globalconf
.drop_events
|= EnterWindowMask
;
833 /** Move and resize client
834 * \param screen Screen ID
836 * \ingroup ui_callback
839 uicb_client_moveresize(int screen
, char *arg
)
842 char x
[8], y
[8], w
[8], h
[8];
843 int mx
, my
, dx
, dy
, nmx
, nmy
;
847 Client
*sel
= globalconf
.focus
->client
;
848 Tag
**curtags
= tags_get_current(screen
);
850 if(curtags
[0]->layout
->arrange
!= layout_floating
)
851 if(!sel
|| !sel
->isfloating
|| sel
->isfixed
|| !arg
)
857 if(sscanf(arg
, "%s %s %s %s", x
, y
, w
, h
) != 4)
859 area
.x
= (int) compute_new_value_from_arg(x
, sel
->geometry
.x
);
860 area
.y
= (int) compute_new_value_from_arg(y
, sel
->geometry
.y
);
861 area
.width
= (int) compute_new_value_from_arg(w
, sel
->geometry
.width
);
862 area
.height
= (int) compute_new_value_from_arg(h
, sel
->geometry
.height
);
864 ox
= sel
->geometry
.x
;
865 oy
= sel
->geometry
.y
;
866 ow
= sel
->geometry
.width
;
867 oh
= sel
->geometry
.height
;
869 Bool xqp
= XQueryPointer(globalconf
.display
,
870 RootWindow(globalconf
.display
,
871 get_phys_screen(screen
)),
872 &dummy
, &dummy
, &mx
, &my
, &dx
, &dy
, &dui
);
873 client_resize(sel
, area
, globalconf
.screens
[sel
->screen
].resize_hints
);
874 if (xqp
&& ox
<= mx
&& (ox
+ ow
) >= mx
&& oy
<= my
&& (oy
+ oh
) >= my
)
876 nmx
= mx
- ox
+ sel
->geometry
.width
- ow
- 1 < 0 ? 0 : mx
- ox
+ sel
->geometry
.width
- ow
- 1;
877 nmy
= my
- oy
+ sel
->geometry
.height
- oh
- 1 < 0 ? 0 : my
- oy
+ sel
->geometry
.height
- oh
- 1;
878 XWarpPointer(globalconf
.display
,
880 0, 0, 0, 0, nmx
, nmy
);
885 client_kill(Client
*c
)
889 if(client_isprotodel(globalconf
.display
, c
->win
))
891 ev
.type
= ClientMessage
;
892 ev
.xclient
.window
= c
->win
;
893 ev
.xclient
.message_type
= XInternAtom(globalconf
.display
, "WM_PROTOCOLS", False
);
894 ev
.xclient
.format
= 32;
895 ev
.xclient
.data
.l
[0] = XInternAtom(globalconf
.display
, "WM_DELETE_WINDOW", False
);
896 ev
.xclient
.data
.l
[1] = CurrentTime
;
897 XSendEvent(globalconf
.display
, c
->win
, False
, NoEventMask
, &ev
);
900 XKillClient(globalconf
.display
, c
->win
);
903 /** Kill selected client
904 * \param screen Screen ID
906 * \ingroup ui_callback
909 uicb_client_kill(int screen
__attribute__ ((unused
)), char *arg
__attribute__ ((unused
)))
911 Client
*sel
= globalconf
.focus
->client
;
918 client_maximize(Client
*c
, Area geometry
)
921 if((c
->ismax
= !c
->ismax
))
923 c
->wasfloating
= c
->isfloating
;
924 c
->m_geometry
= c
->geometry
;
925 if(get_current_layout(c
->screen
)->arrange
!= layout_floating
)
926 client_setfloating(c
, True
);
927 client_resize(c
, geometry
, False
);
928 widget_invalidate_cache(c
->screen
, WIDGET_CACHE_CLIENTS
);
930 else if(c
->wasfloating
)
932 client_setfloating(c
, True
);
933 client_resize(c
, c
->m_geometry
, False
);
934 widget_invalidate_cache(c
->screen
, WIDGET_CACHE_CLIENTS
);
936 else if(get_current_layout(c
->screen
)->arrange
== layout_floating
)
938 client_resize(c
, c
->m_geometry
, False
);
939 widget_invalidate_cache(c
->screen
, WIDGET_CACHE_CLIENTS
);
943 client_setfloating(c
, False
);
944 widget_invalidate_cache(c
->screen
, WIDGET_CACHE_CLIENTS
);
948 /** Toggle maximize for client
949 * \param screen Screen ID
951 * \ingroup ui_callback
954 uicb_client_togglemax(int screen
, char *arg
__attribute__ ((unused
)))
956 Client
*sel
= globalconf
.focus
->client
;
957 Area area
= screen_get_area(screen
,
958 globalconf
.screens
[screen
].statusbar
,
959 &globalconf
.screens
[screen
].padding
);
963 area
.width
-= 2 * sel
->border
;
964 area
.height
-= 2 * sel
->border
;
965 client_maximize(sel
, area
);
969 /** Toggle vertical maximize for client
970 * \param screen Screen ID
972 * \ingroup ui_callback
975 uicb_client_toggleverticalmax(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
.x
= sel
->geometry
.x
;
985 area
.width
= sel
->geometry
.width
;
986 area
.height
-= 2 * sel
->border
;
987 client_maximize(sel
, area
);
992 /** Toggle horizontal maximize for client
993 * \param screen Screen ID
995 * \ingroup ui_callback
998 uicb_client_togglehorizontalmax(int screen
, char *arg
__attribute__ ((unused
)))
1000 Client
*sel
= globalconf
.focus
->client
;
1001 Area area
= screen_get_area(screen
,
1002 globalconf
.screens
[screen
].statusbar
,
1003 &globalconf
.screens
[screen
].padding
);
1007 area
.y
= sel
->geometry
.y
;
1008 area
.height
= sel
->geometry
.height
;
1009 area
.width
-= 2 * sel
->border
;
1010 client_maximize(sel
, area
);
1015 * \param screen Screen ID
1017 * \ingroup ui_callback
1020 uicb_client_zoom(int screen
, char *arg
__attribute__ ((unused
)))
1022 Client
*c
, *sel
= globalconf
.focus
->client
;
1027 for(c
= globalconf
.clients
; !client_isvisible(c
, screen
); c
= c
->next
);
1029 for(sel
= sel
->next
; sel
&& !client_isvisible(sel
, screen
); sel
= sel
->next
);
1033 client_list_detach(&globalconf
.clients
, sel
);
1034 client_list_push(&globalconf
.clients
, sel
);
1035 globalconf
.screens
[screen
].need_arrange
= True
;
1036 globalconf
.drop_events
|= EnterWindowMask
;
1040 /** Send focus to next client in stack
1041 * \param screen Screen ID
1043 * \ingroup ui_callback
1046 uicb_client_focusnext(int screen
, char *arg
__attribute__ ((unused
)))
1048 Client
*c
, *sel
= globalconf
.focus
->client
;
1052 for(c
= sel
->next
; c
&& (c
->skip
|| !client_isvisible(c
, screen
)); c
= c
->next
);
1054 for(c
= globalconf
.clients
; c
&& (c
->skip
|| !client_isvisible(c
, screen
)); c
= c
->next
);
1056 client_focus(c
, screen
, False
);
1059 /** Send focus to previous client in stack
1060 * \param screen Screen ID
1062 * \ingroup ui_callback
1065 uicb_client_focusprev(int screen
, char *arg
__attribute__ ((unused
)))
1069 if((prev
= client_find_prev_visible(globalconf
.focus
->client
)))
1070 client_focus(prev
, screen
, False
);
1073 /** Toggle floating state of a client
1074 * \param screen Screen ID
1076 * \ingroup ui_callback
1079 uicb_client_togglefloating(int screen
__attribute__ ((unused
)),
1080 char *arg
__attribute__ ((unused
)))
1082 if(globalconf
.focus
->client
)
1083 client_setfloating(globalconf
.focus
->client
, !globalconf
.focus
->client
->isfloating
);
1086 /** Toggle scratch client attribute
1087 * \param screen screen number
1088 * \param arg unused argument
1089 * \ingroup ui_callback
1092 uicb_client_setscratch(int screen
,
1093 char *arg
__attribute__ ((unused
)))
1095 if(!globalconf
.focus
->client
)
1098 if(globalconf
.scratch
.client
== globalconf
.focus
->client
)
1099 globalconf
.scratch
.client
= NULL
;
1101 globalconf
.scratch
.client
= globalconf
.focus
->client
;
1103 widget_invalidate_cache(screen
, WIDGET_CACHE_CLIENTS
| WIDGET_CACHE_TAGS
);
1104 globalconf
.screens
[screen
].need_arrange
= True
;
1107 /** Toggle scratch client visibility
1108 * \param screen screen number
1109 * \param arg unused argument
1110 * \ingroup ui_callback
1113 uicb_client_togglescratch(int screen
,
1114 char *arg
__attribute__ ((unused
)))
1116 if(globalconf
.scratch
.client
)
1118 globalconf
.scratch
.isvisible
= !globalconf
.scratch
.isvisible
;
1119 if(globalconf
.scratch
.isvisible
)
1120 client_focus(globalconf
.scratch
.client
, screen
, False
);
1121 globalconf
.screens
[globalconf
.scratch
.client
->screen
].need_arrange
= True
;
1122 widget_invalidate_cache(globalconf
.scratch
.client
->screen
, WIDGET_CACHE_CLIENTS
);
1125 // vim: filetype=c:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=80