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.
22 #include <xcb/xcb_atom.h>
32 #include "layouts/floating.h"
33 #include "common/markup.h"
34 #include "common/atoms.h"
36 extern awesome_t globalconf
;
38 DO_LUA_NEW(extern, client_t
, client
, "client", client_ref
)
39 DO_LUA_EQ(client_t
, client
, "client")
40 DO_LUA_GC(client_t
, client
, "client", client_unref
)
42 /** Load windows properties, restoring client's tag
43 * and floating state before awesome was restarted if any.
44 * \param c A client pointer.
45 * \param screen A virtual screen.
46 * \return True if client had property, false otherwise.
49 client_loadprops(client_t
* c
, screen_t
*screen
)
52 tag_array_t
*tags
= &screen
->tags
;
54 xcb_get_property_cookie_t floating_q
, fullscreen_q
;
55 xcb_get_property_reply_t
*reply
;
58 if(!xutil_text_prop_get(globalconf
.connection
, c
->win
, _AWESOME_TAGS
,
62 /* Send the GetProperty requests which will be processed later */
63 floating_q
= xcb_get_property_unchecked(globalconf
.connection
, false, c
->win
,
64 _AWESOME_FLOATING
, CARDINAL
, 0, 1);
66 fullscreen_q
= xcb_get_property_unchecked(globalconf
.connection
, false, c
->win
,
67 _AWESOME_FULLSCREEN
, CARDINAL
, 0, 1);
69 /* ignore property if the tag count isn't matching */
71 for(int i
= 0; i
< tags
->len
; i
++)
73 tag_client(c
, tags
->tab
[i
]);
75 untag_client(c
, tags
->tab
[i
]);
79 /* check for floating */
80 reply
= xcb_get_property_reply(globalconf
.connection
, floating_q
, NULL
);
82 if(reply
&& reply
->value_len
&& (data
= xcb_get_property_value(reply
)))
83 client_setfloating(c
, *(bool *) data
);
86 /* check for fullscreen */
87 reply
= xcb_get_property_reply(globalconf
.connection
, fullscreen_q
, NULL
);
89 if(reply
&& reply
->value_len
&& (data
= xcb_get_property_value(reply
)))
90 client_setfullscreen(c
, *(bool *) data
);
96 /** Check if client supports protocol a protocole in WM_PROTOCOL.
97 * \param win The window.
98 * \return True if client has the atom in protocol, false otherwise.
101 window_hasproto(xcb_window_t win
, xcb_atom_t atom
)
104 xcb_get_wm_protocols_reply_t protocols
;
107 if(xcb_get_wm_protocols_reply(globalconf
.connection
,
108 xcb_get_wm_protocols_unchecked(globalconf
.connection
,
112 for(i
= 0; !ret
&& i
< protocols
.atoms_len
; i
++)
113 if(protocols
.atoms
[i
] == atom
)
115 xcb_get_wm_protocols_reply_wipe(&protocols
);
120 /** Returns true if a client is tagged
121 * with one of the tags of the specified screen.
122 * \param c The client to check.
123 * \param screen Virtual screen number.
124 * \return true if the client is visible, false otherwise.
127 client_maybevisible(client_t
*c
, int screen
)
129 if(c
->screen
== screen
)
131 if(c
->issticky
|| c
->type
== WINDOW_TYPE_DESKTOP
)
134 tag_array_t
*tags
= &globalconf
.screens
[screen
].tags
;
136 for(int i
= 0; i
< tags
->len
; i
++)
137 if(tags
->tab
[i
]->selected
&& is_client_tagged(c
, tags
->tab
[i
]))
143 /** Get a client by its window.
144 * \param w The client window to find.
145 * \return A client pointer if found, NULL otherwise.
148 client_getbywin(xcb_window_t w
)
151 for(c
= globalconf
.clients
; c
&& c
->win
!= w
; c
= c
->next
);
155 /** Unfocus a client.
156 * \param c The client.
159 client_unfocus(client_t
*c
)
161 globalconf
.screens
[c
->phys_screen
].client_focus
= NULL
;
164 if(globalconf
.hooks
.unfocus
!= LUA_REFNIL
)
166 luaA_client_userdata_new(globalconf
.L
, c
);
167 luaA_dofunction(globalconf
.L
, globalconf
.hooks
.unfocus
, 1, 0);
170 ewmh_update_net_active_window(c
->phys_screen
);
173 /** Ban client and unmap it.
174 * \param c The client.
177 client_ban(client_t
*c
)
179 if(globalconf
.screen_focus
->client_focus
== c
)
181 xcb_unmap_window(globalconf
.connection
, c
->win
);
183 window_state_set(c
->win
, XCB_WM_STATE_ICONIC
);
185 window_state_set(c
->win
, XCB_WM_STATE_WITHDRAWN
);
187 xcb_unmap_window(globalconf
.connection
, c
->titlebar
->sw
.window
);
190 /** Give focus to client, or to first client if client is NULL.
191 * \param c The client or NULL.
192 * \return True if a window (even root) has received focus, false otherwise.
195 client_focus(client_t
*c
)
197 if(!client_maybevisible(c
, c
->screen
) || c
->nofocus
)
200 /* unfocus current selected client */
201 if(globalconf
.screen_focus
->client_focus
202 && c
!= globalconf
.screen_focus
->client_focus
)
203 client_unfocus(globalconf
.screen_focus
->client_focus
);
207 client_setminimized(c
, false);
209 /* unban the client before focusing or it will fail */
212 globalconf
.screen_focus
= &globalconf
.screens
[c
->phys_screen
];
213 globalconf
.screen_focus
->client_focus
= c
;
215 xcb_set_input_focus(globalconf
.connection
, XCB_INPUT_FOCUS_POINTER_ROOT
,
216 c
->win
, XCB_CURRENT_TIME
);
218 /* Some layouts use focused client differently, so call them back.
219 * And anyway, we have maybe unhidden */
220 client_need_arrange(c
);
223 if(globalconf
.hooks
.focus
!= LUA_REFNIL
)
225 luaA_client_userdata_new(globalconf
.L
, globalconf
.screen_focus
->client_focus
);
226 luaA_dofunction(globalconf
.L
, globalconf
.hooks
.focus
, 1, 0);
229 ewmh_update_net_active_window(c
->phys_screen
);
232 /** Stack a window below.
233 * \param c The client.
234 * \param previous The previous window on the stack.
235 * \param return The next-previous!
238 client_stack_above(client_t
*c
, xcb_window_t previous
)
240 uint32_t config_win_vals
[2];
242 config_win_vals
[0] = previous
;
243 config_win_vals
[1] = XCB_STACK_MODE_ABOVE
;
245 xcb_configure_window(globalconf
.connection
, c
->win
,
246 XCB_CONFIG_WINDOW_SIBLING
| XCB_CONFIG_WINDOW_STACK_MODE
,
249 config_win_vals
[0] = c
->win
;
253 xcb_configure_window(globalconf
.connection
,
254 c
->titlebar
->sw
.window
,
255 XCB_CONFIG_WINDOW_SIBLING
| XCB_CONFIG_WINDOW_STACK_MODE
,
257 previous
= c
->titlebar
->sw
.window
;
262 /* stack transient window on top of their parents */
263 for(client_node_t
*node
= *client_node_list_last(&globalconf
.stack
);
264 node
; node
= node
->prev
)
265 if(node
->client
->transient_for
== c
)
267 client_stack_above(node
->client
,
269 previous
= node
->client
->win
;
275 /** Stacking layout layers */
278 /** This one is a special layer */
290 /** Get the real layer of a client according to its attribute (fullscreen, …)
291 * \param c The client.
292 * \return The real layer.
295 client_layer_translator(client_t
*c
)
297 /* first deal with user set attributes */
300 else if(c
->isfullscreen
)
301 return LAYER_FULLSCREEN
;
306 else if(c
->isfloating
)
309 /* check for transient attr */
313 /* then deal with windows type */
316 case WINDOW_TYPE_DOCK
:
318 case WINDOW_TYPE_DESKTOP
:
319 return LAYER_DESKTOP
;
320 case WINDOW_TYPE_DIALOG
:
326 if(client_isfixed(c
))
333 * \todo It might be worth stopping to restack everyone and only stack `c'
334 * relatively to the first matching in the list.
339 uint32_t config_win_vals
[2];
340 client_node_t
*node
, *last
= *client_node_list_last(&globalconf
.stack
);
344 config_win_vals
[0] = XCB_NONE
;
345 config_win_vals
[1] = XCB_STACK_MODE_ABOVE
;
347 /* stack desktop windows */
348 for(layer
= LAYER_DESKTOP
; layer
< LAYER_BELOW
; layer
++)
349 for(node
= last
; node
; node
= node
->prev
)
350 if(client_layer_translator(node
->client
) == layer
)
351 config_win_vals
[0] = client_stack_above(node
->client
,
354 /* first stack not ontop wibox window */
355 for(screen
= 0; screen
< globalconf
.nscreen
; screen
++)
356 for(int i
= 0; i
< globalconf
.screens
[screen
].wiboxes
.len
; i
++)
358 wibox_t
*sb
= globalconf
.screens
[screen
].wiboxes
.tab
[i
];
361 xcb_configure_window(globalconf
.connection
,
363 XCB_CONFIG_WINDOW_SIBLING
| XCB_CONFIG_WINDOW_STACK_MODE
,
365 config_win_vals
[0] = sb
->sw
.window
;
369 /* stack bottom layers */
370 for(layer
= LAYER_BELOW
; layer
< LAYER_FULLSCREEN
; layer
++)
371 for(node
= last
; node
; node
= node
->prev
)
372 if(client_layer_translator(node
->client
) == layer
)
373 config_win_vals
[0] = client_stack_above(node
->client
,
376 /* then stack ontop wibox window */
377 for(screen
= 0; screen
< globalconf
.nscreen
; screen
++)
378 for(int i
= 0; i
< globalconf
.screens
[screen
].wiboxes
.len
; i
++)
380 wibox_t
*sb
= globalconf
.screens
[screen
].wiboxes
.tab
[i
];
383 xcb_configure_window(globalconf
.connection
,
385 XCB_CONFIG_WINDOW_SIBLING
| XCB_CONFIG_WINDOW_STACK_MODE
,
387 config_win_vals
[0] = sb
->sw
.window
;
391 /* finally stack ontop and fullscreen windows */
392 for(layer
= LAYER_FULLSCREEN
; layer
< LAYER_OUTOFSPACE
; layer
++)
393 for(node
= last
; node
; node
= node
->prev
)
394 if(client_layer_translator(node
->client
) == layer
)
395 config_win_vals
[0] = client_stack_above(node
->client
,
399 /** Manage a new client.
400 * \param w The window.
401 * \param wgeom Window geometry.
402 * \param phys_screen Physical screen number.
403 * \param screen Virtual screen number where to manage client.
406 client_manage(xcb_window_t w
, xcb_get_geometry_reply_t
*wgeom
, int phys_screen
, int screen
)
408 xcb_get_property_cookie_t ewmh_icon_cookie
;
411 const uint32_t select_input_val
[] =
413 XCB_EVENT_MASK_STRUCTURE_NOTIFY
414 | XCB_EVENT_MASK_PROPERTY_CHANGE
415 | XCB_EVENT_MASK_ENTER_WINDOW
418 /* Send request to get NET_WM_ICON property as soon as possible... */
419 ewmh_icon_cookie
= ewmh_window_icon_get_unchecked(w
);
420 xcb_change_window_attributes(globalconf
.connection
, w
, XCB_CW_EVENT_MASK
, select_input_val
);
422 if(systray_iskdedockapp(w
))
424 systray_request_handle(w
, phys_screen
, NULL
);
428 c
= p_new(client_t
, 1);
430 c
->screen
= screen_getbycoord(screen
, wgeom
->x
, wgeom
->y
);
432 c
->phys_screen
= phys_screen
;
436 c
->geometry
.x
= c
->f_geometry
.x
= c
->m_geometry
.x
= wgeom
->x
;
437 c
->geometry
.y
= c
->f_geometry
.y
= c
->m_geometry
.y
= wgeom
->y
;
438 c
->geometry
.width
= c
->f_geometry
.width
= c
->m_geometry
.width
= wgeom
->width
;
439 c
->geometry
.height
= c
->f_geometry
.height
= c
->m_geometry
.height
= wgeom
->height
;
440 client_setborder(c
, wgeom
->border_width
);
441 if((icon
= ewmh_window_icon_get_reply(ewmh_icon_cookie
)))
442 c
->icon
= image_ref(&icon
);
444 /* we honor size hints by default */
445 c
->honorsizehints
= true;
448 property_update_wm_normal_hints(c
, NULL
);
449 property_update_wm_hints(c
, NULL
);
450 property_update_wm_transient_for(c
, NULL
);
453 screen
= c
->transient_for
->screen
;
455 /* Try to load props if any */
456 client_loadprops(c
, &globalconf
.screens
[screen
]);
459 /* Then check clients hints */
460 ewmh_client_check_hints(c
);
462 /* move client to screen, but do not tag it for now */
463 screen_client_moveto(c
, screen
, false, true);
465 /* Check if client has been tagged by loading props, or maybe with its
467 * If not, we tag it with current selected ones.
468 * This could be done on Lua side, but it's a sane behaviour. */
472 tag_array_t
*tags
= &globalconf
.screens
[screen
].tags
;
473 for(i
= 0; i
< tags
->len
; i
++)
474 if(is_client_tagged(c
, tags
->tab
[i
]))
477 /* if no tag, set current selected */
479 for(i
= 0; i
< tags
->len
; i
++)
480 if(tags
->tab
[i
]->selected
)
481 tag_client(c
, tags
->tab
[i
]);
484 /* Push client in client list */
485 client_list_push(&globalconf
.clients
, client_ref(&c
));
487 /* Push client in stack */
490 /* update window title */
491 property_update_wm_name(c
);
492 property_update_wm_icon_name(c
);
495 ewmh_client_strut_update(c
, NULL
);
497 ewmh_update_net_client_list(c
->phys_screen
);
499 /* Call hook to notify list change */
500 if(globalconf
.hooks
.clients
!= LUA_REFNIL
)
501 luaA_dofunction(globalconf
.L
, globalconf
.hooks
.clients
, 0, 0);
504 if(globalconf
.hooks
.manage
!= LUA_REFNIL
)
506 luaA_client_userdata_new(globalconf
.L
, c
);
507 luaA_dofunction(globalconf
.L
, globalconf
.hooks
.manage
, 1, 0);
511 /** Compute client geometry with respect to its geometry hints.
512 * \param c The client.
513 * \param geometry The geometry that the client might receive.
514 * \return The geometry the client must take respecting its hints.
517 client_geometry_hints(client_t
*c
, area_t geometry
)
519 double dx
, dy
, max
, min
, ratio
;
521 if(c
->minay
> 0 && c
->maxay
> 0 && (geometry
.height
- c
->baseh
) > 0
522 && (geometry
.width
- c
->basew
) > 0)
524 dx
= (double) (geometry
.width
- c
->basew
);
525 dy
= (double) (geometry
.height
- c
->baseh
);
526 min
= (double) (c
->minax
) / (double) (c
->minay
);
527 max
= (double) (c
->maxax
) / (double) (c
->maxay
);
529 if(max
> 0 && min
> 0 && ratio
> 0)
533 dy
= (dx
* min
+ dy
) / (min
* min
+ 1);
535 geometry
.width
= (int) dx
+ c
->basew
;
536 geometry
.height
= (int) dy
+ c
->baseh
;
540 dy
= (dx
* min
+ dy
) / (max
* max
+ 1);
542 geometry
.width
= (int) dx
+ c
->basew
;
543 geometry
.height
= (int) dy
+ c
->baseh
;
547 if(c
->minw
&& geometry
.width
< c
->minw
)
548 geometry
.width
= c
->minw
;
549 if(c
->minh
&& geometry
.height
< c
->minh
)
550 geometry
.height
= c
->minh
;
551 if(c
->maxw
&& geometry
.width
> c
->maxw
)
552 geometry
.width
= c
->maxw
;
553 if(c
->maxh
&& geometry
.height
> c
->maxh
)
554 geometry
.height
= c
->maxh
;
556 geometry
.width
-= (geometry
.width
- c
->basew
) % c
->incw
;
558 geometry
.height
-= (geometry
.height
- c
->baseh
) % c
->inch
;
563 /** Resize client window.
564 * \param c Client to resize.
565 * \param geometry New window geometry.
566 * \param hints Use size hints.
569 client_resize(client_t
*c
, area_t geometry
, bool hints
)
573 layout_t
*layout
= layout_get_current(c
->screen
);
575 if(c
->titlebar
&& !c
->ismoving
&& c
->titlebar
->isvisible
&& !client_isfloating(c
) && layout
!= layout_floating
)
576 geometry
= titlebar_geometry_remove(c
->titlebar
, c
->border
, geometry
);
579 geometry
= client_geometry_hints(c
, geometry
);
581 if(geometry
.width
<= 0 || geometry
.height
<= 0)
584 /* offscreen appearance fixes */
585 area
= display_area_get(c
->phys_screen
, NULL
,
586 &globalconf
.screens
[c
->screen
].padding
);
588 if(geometry
.x
> area
.width
)
589 geometry
.x
= area
.width
- geometry
.width
- 2 * c
->border
;
590 if(geometry
.y
> area
.height
)
591 geometry
.y
= area
.height
- geometry
.height
- 2 * c
->border
;
592 if(geometry
.x
+ geometry
.width
+ 2 * c
->border
< 0)
594 if(geometry
.y
+ geometry
.height
+ 2 * c
->border
< 0)
597 if(c
->geometry
.x
!= geometry
.x
598 || c
->geometry
.y
!= geometry
.y
599 || c
->geometry
.width
!= geometry
.width
600 || c
->geometry
.height
!= geometry
.height
)
602 new_screen
= screen_getbycoord(c
->screen
, geometry
.x
, geometry
.y
);
604 /* Values to configure a window is an array where values are
605 * stored according to 'value_mask' */
608 c
->geometry
.x
= values
[0] = geometry
.x
;
609 c
->geometry
.y
= values
[1] = geometry
.y
;
610 c
->geometry
.width
= values
[2] = geometry
.width
;
611 c
->geometry
.height
= values
[3] = geometry
.height
;
613 /* save the floating geometry if the window is floating but not
615 if(c
->ismoving
|| client_isfloating(c
)
616 || layout_get_current(new_screen
) == layout_floating
617 || layout_get_current(c
->screen
) == layout_floating
)
619 c
->f_geometry
= geometry
;
621 titlebar_update_geometry_floating(c
);
623 xcb_configure_window(globalconf
.connection
, c
->win
,
624 XCB_CONFIG_WINDOW_X
| XCB_CONFIG_WINDOW_Y
625 | XCB_CONFIG_WINDOW_WIDTH
| XCB_CONFIG_WINDOW_HEIGHT
,
627 window_configure(c
->win
, geometry
, c
->border
);
629 if(c
->screen
!= new_screen
)
630 screen_client_moveto(c
, new_screen
, true, false);
633 hooks_property(c
, "geometry");
637 /** Set a client floating.
638 * \param c The client.
639 * \param floating Set floating, or not.
640 * \param layer Layer to put the floating window onto.
643 client_setfloating(client_t
*c
, bool floating
)
645 if(c
->isfloating
!= floating
646 && (c
->type
== WINDOW_TYPE_NORMAL
))
648 if((c
->isfloating
= floating
))
650 client_resize(c
, c
->f_geometry
, false);
651 client_need_arrange(c
);
653 xcb_change_property(globalconf
.connection
,
654 XCB_PROP_MODE_REPLACE
,
655 c
->win
, _AWESOME_FLOATING
, CARDINAL
, 8, 1,
658 hooks_property(c
, "floating");
662 /** Set a client minimized, or not.
663 * \param c The client.
664 * \param s Set or not the client minimized.
667 client_setminimized(client_t
*c
, bool s
)
669 if(c
->isminimized
!= s
)
671 client_need_arrange(c
);
673 client_need_arrange(c
);
674 ewmh_client_update_hints(c
);
676 hooks_property(c
, "minimized");
680 /** Set a client sticky, or not.
681 * \param c The client.
682 * \param s Set or not the client sticky.
685 client_setsticky(client_t
*c
, bool s
)
689 client_need_arrange(c
);
691 client_need_arrange(c
);
692 ewmh_client_update_hints(c
);
693 hooks_property(c
, "sticky");
697 /** Set a client fullscreen, or not.
698 * \param c The client.
699 * \param s Set or not the client fullscreen.
702 client_setfullscreen(client_t
*c
, bool s
)
704 if(c
->isfullscreen
!= s
)
708 /* become fullscreen! */
709 if((c
->isfullscreen
= s
))
711 geometry
= screen_area_get(c
->screen
, NULL
, NULL
, false);
712 c
->m_geometry
= c
->geometry
;
713 c
->oldborder
= c
->border
;
714 client_setborder(c
, 0);
718 geometry
= c
->m_geometry
;
719 client_setborder(c
, c
->oldborder
);
721 client_resize(c
, geometry
, false);
722 client_need_arrange(c
);
724 xcb_change_property(globalconf
.connection
,
725 XCB_PROP_MODE_REPLACE
,
726 c
->win
, _AWESOME_FULLSCREEN
, CARDINAL
, 8, 1,
728 ewmh_client_update_hints(c
);
729 hooks_property(c
, "fullscreen");
733 /** Set a client above, or not.
734 * \param c The client.
735 * \param s Set or not the client above.
738 client_setabove(client_t
*c
, bool s
)
744 ewmh_client_update_hints(c
);
746 hooks_property(c
, "above");
750 /** Set a client below, or not.
751 * \param c The client.
752 * \param s Set or not the client below.
755 client_setbelow(client_t
*c
, bool s
)
761 ewmh_client_update_hints(c
);
763 hooks_property(c
, "below");
767 /** Set a client modal, or not.
768 * \param c The client.
769 * \param s Set or not the client moda.
772 client_setmodal(client_t
*c
, bool s
)
778 ewmh_client_update_hints(c
);
780 hooks_property(c
, "modal");
784 /** Set a client ontop, or not.
785 * \param c The client.
786 * \param s Set or not the client moda.
789 client_setontop(client_t
*c
, bool s
)
796 hooks_property(c
, "ontop");
800 /** Save client properties as an X property.
801 * \param c The client.
804 client_saveprops_tags(client_t
*c
)
806 tag_array_t
*tags
= &globalconf
.screens
[c
->screen
].tags
;
807 unsigned char *prop
= p_alloca(unsigned char, tags
->len
+ 1);
810 for(i
= 0; i
< tags
->len
; i
++)
811 prop
[i
] = is_client_tagged(c
, tags
->tab
[i
]) ? '1' : '0';
813 xcb_change_property(globalconf
.connection
, XCB_PROP_MODE_REPLACE
, c
->win
, _AWESOME_TAGS
, STRING
, 8, i
, prop
);
817 * \param c The client.
820 client_unban(client_t
*c
)
822 xcb_map_window(globalconf
.connection
, c
->win
);
823 window_state_set(c
->win
, XCB_WM_STATE_NORMAL
);
826 if(c
->isfullscreen
|| !c
->titlebar
->isvisible
)
827 xcb_unmap_window(globalconf
.connection
, c
->titlebar
->sw
.window
);
829 xcb_map_window(globalconf
.connection
, c
->titlebar
->sw
.window
);
833 /** Unmanage a client.
834 * \param c The client.
837 client_unmanage(client_t
*c
)
839 tag_array_t
*tags
= &globalconf
.screens
[c
->screen
].tags
;
841 if(globalconf
.screens
[c
->phys_screen
].client_focus
== c
)
844 /* remove client everywhere */
845 client_list_detach(&globalconf
.clients
, c
);
846 stack_client_delete(c
);
847 for(int i
= 0; i
< tags
->len
; i
++)
848 untag_client(c
, tags
->tab
[i
]);
851 if(globalconf
.hooks
.unmanage
!= LUA_REFNIL
)
853 luaA_client_userdata_new(globalconf
.L
, c
);
854 luaA_dofunction(globalconf
.L
, globalconf
.hooks
.unmanage
, 1, 0);
857 /* Call hook to notify list change */
858 if(globalconf
.hooks
.clients
!= LUA_REFNIL
)
859 luaA_dofunction(globalconf
.L
, globalconf
.hooks
.clients
, 0, 0);
861 /* The server grab construct avoids race conditions. */
862 xcb_grab_server(globalconf
.connection
);
864 xcb_configure_window(globalconf
.connection
, c
->win
,
865 XCB_CONFIG_WINDOW_BORDER_WIDTH
,
866 (uint32_t *) &c
->oldborder
);
868 xcb_ungrab_button(globalconf
.connection
, XCB_BUTTON_INDEX_ANY
, c
->win
,
869 XCB_BUTTON_MASK_ANY
);
870 window_state_set(c
->win
, XCB_WM_STATE_WITHDRAWN
);
872 xcb_flush(globalconf
.connection
);
873 xcb_ungrab_server(globalconf
.connection
);
875 titlebar_client_detach(c
);
877 ewmh_update_net_client_list(c
->phys_screen
);
879 /* delete properties */
880 xcb_delete_property(globalconf
.connection
, c
->win
, _AWESOME_TAGS
);
881 xcb_delete_property(globalconf
.connection
, c
->win
, _AWESOME_FLOATING
);
883 if(client_hasstrut(c
))
884 /* All the wiboxes (may) need to be repositioned */
885 for(int screen
= 0; screen
< globalconf
.nscreen
; screen
++)
886 for(int i
= 0; i
< globalconf
.screens
[screen
].wiboxes
.len
; i
++)
888 wibox_t
*s
= globalconf
.screens
[screen
].wiboxes
.tab
[i
];
889 wibox_position_update(s
);
892 /* set client as invalid */
898 /** Kill a client via a WM_DELETE_WINDOW request or KillClient if not
900 * \param c The client to kill.
903 client_kill(client_t
*c
)
905 if(window_hasproto(c
->win
, WM_DELETE_WINDOW
))
907 xcb_client_message_event_t ev
;
909 /* Initialize all of event's fields first */
912 ev
.response_type
= XCB_CLIENT_MESSAGE
;
915 ev
.data
.data32
[1] = XCB_CURRENT_TIME
;
916 ev
.type
= WM_PROTOCOLS
;
917 ev
.data
.data32
[0] = WM_DELETE_WINDOW
;
919 xcb_send_event(globalconf
.connection
, false, c
->win
,
920 XCB_EVENT_MASK_NO_EVENT
, (char *) &ev
);
923 xcb_kill_client(globalconf
.connection
, c
->win
);
926 /** Get all clients into a table.
927 * \param L The Lua VM state.
928 * \return The number of elements pushed on stack.
930 * \lparam An optional screen nunmber.
931 * \lreturn A table with all clients.
934 luaA_client_get(lua_State
*L
)
939 screen
= luaL_optnumber(L
, 1, 0) - 1;
943 if(screen
== SCREEN_UNDEF
)
944 for(c
= globalconf
.clients
; c
; c
= c
->next
)
946 luaA_client_userdata_new(globalconf
.L
, c
);
947 lua_rawseti(L
, -2, i
++);
951 luaA_checkscreen(screen
);
952 for(c
= globalconf
.clients
; c
; c
= c
->next
)
953 if(c
->screen
== screen
)
955 luaA_client_userdata_new(globalconf
.L
, c
);
956 lua_rawseti(L
, -2, i
++);
963 /** Get only visible clients for a screen (DEPRECATED).
964 * \param L The Lua VM state.
965 * \return The number of elements pushed on stack.
967 * \lparam A screen number.
968 * \lreturn A table with all visible clients for this screen.
971 luaA_client_visible_get(lua_State
*L
)
975 int screen
= luaL_checknumber(L
, 1) - 1;
977 luaA_checkscreen(screen
);
979 deprecate(L
, "awful.client.visible()");
983 for(c
= globalconf
.clients
; c
; c
= c
->next
)
984 if(client_isvisible(c
, screen
))
986 luaA_client_userdata_new(L
, c
);
987 lua_rawseti(L
, -2, i
++);
993 /** Check if a client is visible on its screen.
994 * \param L The Lua VM state.
995 * \return The number of elements pushed on stack.
998 * \lreturn A boolean value, true if the client is visible, false otherwise.
1001 luaA_client_isvisible(lua_State
*L
)
1003 client_t
**c
= luaA_checkudata(L
, 1, "client");
1004 lua_pushboolean(L
, client_isvisible(*c
, (*c
)->screen
));
1008 /** Set client border width.
1009 * \param c The client.
1010 * \param width The border width.
1013 client_setborder(client_t
*c
, int width
)
1017 if(width
> 0 && (c
->type
== WINDOW_TYPE_DOCK
1018 || c
->type
== WINDOW_TYPE_SPLASH
1019 || c
->type
== WINDOW_TYPE_DESKTOP
1020 || c
->isfullscreen
))
1023 if(width
== c
->border
|| width
< 0)
1027 xcb_configure_window(globalconf
.connection
, c
->win
,
1028 XCB_CONFIG_WINDOW_BORDER_WIDTH
, &w
);
1030 if(client_isvisible(c
, c
->screen
))
1032 if(client_isfloating(c
) || layout_get_current(c
->screen
) == layout_floating
)
1033 titlebar_update_geometry_floating(c
);
1035 globalconf
.screens
[c
->screen
].need_arrange
= true;
1038 hooks_property(c
, "border_width");
1042 * \param L The Lua VM state.
1048 luaA_client_kill(lua_State
*L
)
1050 client_t
**c
= luaA_checkudata(L
, 1, "client");
1055 /** Swap a client with another one.
1056 * \param L The Lua VM state.
1059 * \lparam A client to swap with.
1062 luaA_client_swap(lua_State
*L
)
1064 client_t
**c
= luaA_checkudata(L
, 1, "client");
1065 client_t
**swap
= luaA_checkudata(L
, 2, "client");
1066 client_list_swap(&globalconf
.clients
, *swap
, *c
);
1067 client_need_arrange(*c
);
1068 client_need_arrange(*swap
);
1070 /* Call hook to notify list change */
1071 if(globalconf
.hooks
.clients
!= LUA_REFNIL
)
1072 luaA_dofunction(L
, globalconf
.hooks
.clients
, 0, 0);
1077 /** Access or set the client tags.
1078 * \param L The Lua VM state.
1079 * \return The number of elements pushed on stack.
1080 * \lparam A table with tags to set, or none to get the current tags table.
1081 * \return The clients tag.
1084 luaA_client_tags(lua_State
*L
)
1088 client_t
**c
= luaA_checkudata(L
, 1, "client");
1091 if(lua_gettop(L
) == 2)
1093 luaA_checktable(L
, 2);
1094 tags
= &globalconf
.screens
[(*c
)->screen
].tags
;
1095 for(int i
= 0; i
< tags
->len
; i
++)
1096 untag_client(*c
, tags
->tab
[i
]);
1098 while(lua_next(L
, 2))
1100 tag
= luaA_checkudata(L
, -1, "tag");
1101 tag_client(*c
, *tag
);
1107 tags
= &globalconf
.screens
[(*c
)->screen
].tags
;
1109 for(int i
= 0; i
< tags
->len
; i
++)
1110 if(is_client_tagged(*c
, tags
->tab
[i
]))
1112 luaA_tag_userdata_new(L
, tags
->tab
[i
]);
1113 lua_rawseti(L
, -2, ++j
);
1119 /** Raise a client on top of others which are on the same layer.
1120 * \param L The Lua VM state.
1125 luaA_client_raise(lua_State
*L
)
1127 client_t
**c
= luaA_checkudata(L
, 1, "client");
1132 /** Lower a client on bottom of others which are on the same layer.
1133 * \param L The Lua VM state.
1138 luaA_client_lower(lua_State
*L
)
1140 client_t
**c
= luaA_checkudata(L
, 1, "client");
1145 /** Redraw a client by unmapping and mapping it quickly.
1146 * \param L The Lua VM state.
1152 luaA_client_redraw(lua_State
*L
)
1154 client_t
**c
= luaA_checkudata(L
, 1, "client");
1156 xcb_unmap_window(globalconf
.connection
, (*c
)->win
);
1157 xcb_map_window(globalconf
.connection
, (*c
)->win
);
1159 /* Set the focus on the current window if the redraw has been
1160 performed on the window where the pointer is currently on
1161 because after the unmapping/mapping, the focus is lost */
1162 if(globalconf
.screen_focus
->client_focus
== *c
)
1163 xcb_set_input_focus(globalconf
.connection
, XCB_INPUT_FOCUS_POINTER_ROOT
,
1164 (*c
)->win
, XCB_CURRENT_TIME
);
1169 /** Stop managing a client.
1170 * \param L The Lua VM state.
1171 * \return The number of elements pushed on stack.
1176 luaA_client_unmanage(lua_State
*L
)
1178 client_t
**c
= luaA_checkudata(L
, 1, "client");
1179 client_unmanage(*c
);
1183 /** Return client geometry.
1184 * \param L The Lua VM state.
1185 * \param full Use titlebar also.
1186 * \return The number of elements pushed on stack.
1189 luaA_client_handlegeom(lua_State
*L
, bool full
)
1191 client_t
**c
= luaA_checkudata(L
, 1, "client");
1193 if(lua_gettop(L
) == 2)
1194 if(client_isfloating(*c
)
1195 || layout_get_current((*c
)->screen
) == layout_floating
)
1199 luaA_checktable(L
, 2);
1200 geometry
.x
= luaA_getopt_number(L
, 2, "x", (*c
)->geometry
.x
);
1201 geometry
.y
= luaA_getopt_number(L
, 2, "y", (*c
)->geometry
.y
);
1202 if(client_isfixed(*c
))
1204 geometry
.width
= (*c
)->geometry
.width
;
1205 geometry
.height
= (*c
)->geometry
.height
;
1209 geometry
.width
= luaA_getopt_number(L
, 2, "width", (*c
)->geometry
.width
);
1210 geometry
.height
= luaA_getopt_number(L
, 2, "height", (*c
)->geometry
.height
);
1213 geometry
= titlebar_geometry_remove((*c
)->titlebar
,
1216 client_resize(*c
, geometry
, (*c
)->honorsizehints
);
1220 return luaA_pusharea(L
, titlebar_geometry_add((*c
)->titlebar
,
1224 return luaA_pusharea(L
, (*c
)->geometry
);
1227 /** Return client geometry.
1228 * \param L The Lua VM state.
1229 * \return The number of elements pushed on stack.
1231 * \lparam A table with new coordinates, or none.
1232 * \lreturn A table with client coordinates.
1235 luaA_client_geometry(lua_State
*L
)
1237 return luaA_client_handlegeom(L
, false);
1241 luaA_client_coords(lua_State
*L
)
1243 deprecate(L
, "client:geometry()");
1244 return luaA_client_geometry(L
);
1247 /** Return client geometry, using also titlebar and border width.
1248 * \param L The Lua VM state.
1249 * \return The number of elements pushed on stack.
1251 * \lparam A table with new coordinates, or none.
1252 * \lreturn A table with client coordinates.
1255 luaA_client_fullgeometry(lua_State
*L
)
1257 return luaA_client_handlegeom(L
, true);
1261 luaA_client_fullcoords(lua_State
*L
)
1263 deprecate(L
, "client:fullgeometry()");
1264 return luaA_client_fullgeometry(L
);
1267 /** Client newindex.
1268 * \param L The Lua VM state.
1269 * \return The number of elements pushed on stack.
1272 luaA_client_newindex(lua_State
*L
)
1275 client_t
**c
= luaA_checkudata(L
, 1, "client");
1276 const char *buf
= luaL_checklstring(L
, 2, &len
);
1284 luaL_error(L
, "client is invalid\n");
1286 switch(a_tokenize(buf
, len
))
1289 if(globalconf
.xinerama_is_active
)
1291 i
= luaL_checknumber(L
, 3) - 1;
1292 luaA_checkscreen(i
);
1293 if(i
!= (*c
)->screen
)
1294 screen_client_moveto(*c
, i
, true, true);
1298 b
= luaA_checkboolean(L
, 3);
1299 if(b
!= (*c
)->ishidden
)
1301 client_need_arrange(*c
);
1303 client_need_arrange(*c
);
1307 client_setminimized(*c
, luaA_checkboolean(L
, 3));
1309 case A_TK_FULLSCREEN
:
1310 client_setfullscreen(*c
, luaA_checkboolean(L
, 3));
1313 image
= luaA_checkudata(L
, 3, "image");
1314 image_unref(&(*c
)->icon
);
1316 (*c
)->icon
= *image
;
1318 hooks_property(*c
, "icon");
1322 window_opacity_set((*c
)->win
, -1);
1325 d
= luaL_checknumber(L
, 3);
1326 if(d
>= 0 && d
<= 1)
1327 window_opacity_set((*c
)->win
, d
);
1331 client_setfloating(*c
, luaA_checkboolean(L
, 3));
1334 client_setsticky(*c
, luaA_checkboolean(L
, 3));
1336 case A_TK_HONORSIZEHINTS
:
1337 (*c
)->honorsizehints
= luaA_checkboolean(L
, 3);
1338 client_need_arrange(*c
);
1340 case A_TK_BORDER_WIDTH
:
1341 client_setborder(*c
, luaL_checknumber(L
, 3));
1344 client_setontop(*c
, luaA_checkboolean(L
, 3));
1346 case A_TK_BORDER_COLOR
:
1347 if((buf
= luaL_checklstring(L
, 3, &len
))
1348 && xcolor_init_reply(xcolor_init_unchecked(&(*c
)->border_color
, buf
, len
)))
1349 xcb_change_window_attributes(globalconf
.connection
, (*c
)->win
,
1350 XCB_CW_BORDER_PIXEL
, &(*c
)->border_color
.pixel
);
1354 titlebar_client_detach(*c
);
1357 t
= luaA_checkudata(L
, 3, "wibox");
1358 titlebar_client_attach(*c
, *t
);
1369 * \param L The Lua VM state.
1370 * \return The number of elements pushed on stack.
1372 * \lfield name The client title.
1373 * \lfield skip_taskbar True if the client does not want to be in taskbar.
1374 * \lfield type The window type (desktop, normal, dock, …).
1375 * \lfield class The client class.
1376 * \lfield instance The client instance.
1377 * \lfield pid The client PID, if available.
1378 * \lfield role The window role, if available.
1379 * \lfield machine The machine client is running on.
1380 * \lfield icon_name The client name when iconified.
1381 * \lfield screen Client screen number.
1382 * \lfield hide Define if the client must be hidden, i.e. never mapped,
1383 * invisible in taskbar.
1384 * \lfield minimize Define it the client must be iconify, i.e. only visible in
1386 * \lfield icon_path Path to the icon used to identify.
1387 * \lfield floating True always floating.
1388 * \lfield honorsizehints Honor size hints, i.e. respect size ratio.
1389 * \lfield border_width The client border width.
1390 * \lfield border_color The client border color.
1391 * \lfield titlebar The client titlebar.
1392 * \lfield urgent The client urgent state.
1393 * \lfield focus The focused client.
1394 * \lfield opacity The client opacity between 0 and 1.
1395 * \lfield ontop The client is on top of every other windows.
1396 * \lfield fullscreen The client is fullscreen or not.
1397 * \lfield transient_for Return the client the window is transient for.
1398 * \lfield size_hints A table with size hints of the client: user_position,
1399 * user_size, program_position and program_size.
1402 luaA_client_index(lua_State
*L
)
1406 client_t
**c
= luaA_checkudata(L
, 1, "client");
1407 const char *buf
= luaL_checklstring(L
, 2, &len
);
1410 xcb_get_wm_class_reply_t hint
;
1411 xcb_get_property_cookie_t prop_c
;
1412 xcb_get_property_reply_t
*prop_r
= NULL
;
1416 luaL_error(L
, "client is invalid\n");
1418 if(luaA_usemetatable(L
, 1, 2))
1421 switch(a_tokenize(buf
, len
))
1424 lua_pushstring(L
, (*c
)->name
);
1426 case A_TK_TRANSIENT_FOR
:
1427 if((*c
)->transient_for
)
1428 return luaA_client_userdata_new(L
, (*c
)->transient_for
);
1429 case A_TK_SKIP_TASKBAR
:
1430 lua_pushboolean(L
, (*c
)->skiptb
);
1435 case WINDOW_TYPE_DESKTOP
:
1436 lua_pushliteral(L
, "desktop");
1438 case WINDOW_TYPE_DOCK
:
1439 lua_pushliteral(L
, "dock");
1441 case WINDOW_TYPE_SPLASH
:
1442 lua_pushliteral(L
, "splash");
1444 case WINDOW_TYPE_DIALOG
:
1445 lua_pushliteral(L
, "dialog");
1448 lua_pushliteral(L
, "normal");
1453 if(!xcb_get_wm_class_reply(globalconf
.connection
,
1454 xcb_get_wm_class_unchecked(globalconf
.connection
, (*c
)->win
),
1457 lua_pushstring(L
, hint
.class);
1458 xcb_get_wm_class_reply_wipe(&hint
);
1461 if(!xcb_get_wm_class_reply(globalconf
.connection
,
1462 xcb_get_wm_class_unchecked(globalconf
.connection
, (*c
)->win
),
1465 lua_pushstring(L
, hint
.name
);
1466 xcb_get_wm_class_reply_wipe(&hint
);
1469 if(!xutil_text_prop_get(globalconf
.connection
, (*c
)->win
,
1470 WM_WINDOW_ROLE
, &value
, &slen
))
1472 lua_pushlstring(L
, value
, slen
);
1476 prop_c
= xcb_get_property_unchecked(globalconf
.connection
, false, (*c
)->win
, _NET_WM_PID
, CARDINAL
, 0L, 1L);
1477 prop_r
= xcb_get_property_reply(globalconf
.connection
, prop_c
, NULL
);
1479 if(prop_r
&& prop_r
->value_len
&& (data
= xcb_get_property_value(prop_r
)))
1480 lua_pushnumber(L
, *(uint32_t *)data
);
1488 if(!xutil_text_prop_get(globalconf
.connection
, (*c
)->win
,
1489 WM_CLIENT_MACHINE
, &value
, &slen
))
1491 lua_pushlstring(L
, value
, slen
);
1494 case A_TK_ICON_NAME
:
1495 lua_pushstring(L
, (*c
)->icon_name
);
1498 lua_pushnumber(L
, 1 + (*c
)->screen
);
1501 lua_pushboolean(L
, (*c
)->ishidden
);
1504 lua_pushboolean(L
, (*c
)->isminimized
);
1506 case A_TK_FULLSCREEN
:
1507 lua_pushboolean(L
, (*c
)->isfullscreen
);
1511 luaA_image_userdata_new(L
, (*c
)->icon
);
1516 if((d
= window_opacity_get((*c
)->win
)) >= 0)
1517 lua_pushnumber(L
, d
);
1522 lua_pushboolean(L
, client_isfloating(*c
));
1525 lua_pushboolean(L
, (*c
)->isontop
);
1528 lua_pushboolean(L
, (*c
)->issticky
);
1530 case A_TK_HONORSIZEHINTS
:
1531 lua_pushboolean(L
, (*c
)->honorsizehints
);
1533 case A_TK_BORDER_WIDTH
:
1534 lua_pushnumber(L
, (*c
)->border
);
1536 case A_TK_BORDER_COLOR
:
1537 luaA_pushcolor(L
, &(*c
)->border_color
);
1541 return luaA_wibox_userdata_new(L
, (*c
)->titlebar
);
1544 lua_pushboolean(L
, (*c
)->isurgent
);
1546 case A_TK_SIZE_HINTS
:
1548 lua_pushboolean(L
, (*c
)->size_hints
.flags
& XCB_SIZE_HINT_US_POSITION
);
1549 lua_setfield(L
, -2, "user_position");
1550 lua_pushboolean(L
, (*c
)->size_hints
.flags
& XCB_SIZE_HINT_US_SIZE
);
1551 lua_setfield(L
, -2, "user_size");
1552 lua_pushboolean(L
, (*c
)->size_hints
.flags
& XCB_SIZE_HINT_P_POSITION
);
1553 lua_setfield(L
, -2, "program_position");
1554 lua_pushboolean(L
, (*c
)->size_hints
.flags
& XCB_SIZE_HINT_P_SIZE
);
1555 lua_setfield(L
, -2, "program_size");
1564 /** Get or set mouse buttons bindings for a client.
1565 * \param L The Lua VM state.
1566 * \return The number of element pushed on stack.
1569 * \lparam An array of mouse button bindings objects, or nothing.
1570 * \return The array of mouse button bindings objects of this client.
1573 luaA_client_buttons(lua_State
*L
)
1575 client_t
**client
= luaA_checkudata(L
, 1, "client");
1576 button_array_t
*buttons
= &(*client
)->buttons
;
1578 if(lua_gettop(L
) == 2)
1579 luaA_button_array_set(L
, 2, buttons
);
1581 return luaA_button_array_get(L
, buttons
);
1585 * \param L The Lua VM state.
1586 * \return The number of pushed elements.
1589 luaA_client_module_index(lua_State
*L
)
1592 const char *buf
= luaL_checklstring(L
, 2, &len
);
1594 switch(a_tokenize(buf
, len
))
1597 if(globalconf
.screen_focus
->client_focus
)
1598 luaA_client_userdata_new(L
, globalconf
.screen_focus
->client_focus
);
1609 /* Client module new index.
1610 * \param L The Lua VM state.
1611 * \return The number of pushed elements.
1614 luaA_client_module_newindex(lua_State
*L
)
1617 const char *buf
= luaL_checklstring(L
, 2, &len
);
1620 switch(a_tokenize(buf
, len
))
1623 c
= luaA_checkudata(L
, 3, "client");
1633 const struct luaL_reg awesome_client_methods
[] =
1635 { "get", luaA_client_get
},
1636 { "visible_get", luaA_client_visible_get
},
1637 { "__index", luaA_client_module_index
},
1638 { "__newindex", luaA_client_module_newindex
},
1641 const struct luaL_reg awesome_client_meta
[] =
1643 { "isvisible", luaA_client_isvisible
},
1644 { "geometry", luaA_client_geometry
},
1645 { "fullgeometry", luaA_client_fullgeometry
},
1646 { "buttons", luaA_client_buttons
},
1647 { "tags", luaA_client_tags
},
1648 { "kill", luaA_client_kill
},
1649 { "swap", luaA_client_swap
},
1650 { "raise", luaA_client_raise
},
1651 { "lower", luaA_client_lower
},
1652 { "redraw", luaA_client_redraw
},
1653 { "mouse_resize", luaA_client_mouse_resize
},
1654 { "mouse_move", luaA_client_mouse_move
},
1655 { "unmanage", luaA_client_unmanage
},
1656 { "__index", luaA_client_index
},
1657 { "__newindex", luaA_client_newindex
},
1658 { "__eq", luaA_client_eq
},
1659 { "__gc", luaA_client_gc
},
1660 { "__tostring", luaA_client_tostring
},
1662 { "coords", luaA_client_coords
},
1663 { "fullcoords", luaA_client_fullcoords
},
1667 // vim: filetype=c:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=80