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 luaA_client_userdata_new(globalconf
.L
, c
);
165 luaA_dofunction(globalconf
.L
, globalconf
.hooks
.unfocus
, 1, 0);
167 ewmh_update_net_active_window(c
->phys_screen
);
170 /** Ban client and unmap it.
171 * \param c The client.
174 client_ban(client_t
*c
)
176 if(globalconf
.screen_focus
->client_focus
== c
)
178 xcb_unmap_window(globalconf
.connection
, c
->win
);
180 window_state_set(c
->win
, XCB_WM_STATE_ICONIC
);
182 window_state_set(c
->win
, XCB_WM_STATE_WITHDRAWN
);
184 xcb_unmap_window(globalconf
.connection
, c
->titlebar
->sw
.window
);
187 /** Give focus to client, or to first client if client is NULL.
188 * \param c The client or NULL.
189 * \return True if a window (even root) has received focus, false otherwise.
192 client_focus(client_t
*c
)
194 if(!client_maybevisible(c
, c
->screen
) || c
->nofocus
)
197 /* unfocus current selected client */
198 if(globalconf
.screen_focus
->client_focus
199 && c
!= globalconf
.screen_focus
->client_focus
)
200 client_unfocus(globalconf
.screen_focus
->client_focus
);
204 client_setminimized(c
, false);
206 /* unban the client before focusing or it will fail */
209 globalconf
.screen_focus
= &globalconf
.screens
[c
->phys_screen
];
210 globalconf
.screen_focus
->client_focus
= c
;
212 xcb_set_input_focus(globalconf
.connection
, XCB_INPUT_FOCUS_POINTER_ROOT
,
213 c
->win
, XCB_CURRENT_TIME
);
215 /* Some layouts use focused client differently, so call them back.
216 * And anyway, we have maybe unhidden */
217 client_need_arrange(c
);
220 luaA_client_userdata_new(globalconf
.L
, globalconf
.screen_focus
->client_focus
);
221 luaA_dofunction(globalconf
.L
, globalconf
.hooks
.focus
, 1, 0);
223 ewmh_update_net_active_window(c
->phys_screen
);
226 /** Stack a window below.
227 * \param c The client.
228 * \param previous The previous window on the stack.
229 * \param return The next-previous!
232 client_stack_above(client_t
*c
, xcb_window_t previous
)
234 uint32_t config_win_vals
[2];
236 config_win_vals
[0] = previous
;
237 config_win_vals
[1] = XCB_STACK_MODE_ABOVE
;
241 xcb_configure_window(globalconf
.connection
,
242 c
->titlebar
->sw
.window
,
243 XCB_CONFIG_WINDOW_SIBLING
| XCB_CONFIG_WINDOW_STACK_MODE
,
245 config_win_vals
[0] = c
->titlebar
->sw
.window
;
248 xcb_configure_window(globalconf
.connection
, c
->win
,
249 XCB_CONFIG_WINDOW_SIBLING
| XCB_CONFIG_WINDOW_STACK_MODE
,
254 /* stack transient window on top of their parents */
255 for(client_node_t
*node
= *client_node_list_last(&globalconf
.stack
);
256 node
; node
= node
->prev
)
257 if(node
->client
->transient_for
== c
)
259 client_stack_above(node
->client
,
261 previous
= node
->client
->win
;
267 /** Stacking layout layers */
270 /** This one is a special layer */
282 /** Get the real layer of a client according to its attribute (fullscreen, …)
283 * \param c The client.
284 * \return The real layer.
287 client_layer_translator(client_t
*c
)
289 /* first deal with user set attributes */
292 else if(c
->isfullscreen
)
293 return LAYER_FULLSCREEN
;
298 else if(c
->isfloating
)
301 /* check for transient attr */
305 /* then deal with windows type */
308 case WINDOW_TYPE_DOCK
:
310 case WINDOW_TYPE_DESKTOP
:
311 return LAYER_DESKTOP
;
312 case WINDOW_TYPE_DIALOG
:
318 if(client_isfixed(c
))
325 * \todo It might be worth stopping to restack everyone and only stack `c'
326 * relatively to the first matching in the list.
331 uint32_t config_win_vals
[2];
332 client_node_t
*node
, *last
= *client_node_list_last(&globalconf
.stack
);
336 config_win_vals
[0] = XCB_NONE
;
337 config_win_vals
[1] = XCB_STACK_MODE_ABOVE
;
339 /* stack desktop windows */
340 for(layer
= LAYER_DESKTOP
; layer
< LAYER_BELOW
; layer
++)
341 for(node
= last
; node
; node
= node
->prev
)
342 if(client_layer_translator(node
->client
) == layer
)
343 config_win_vals
[0] = client_stack_above(node
->client
,
346 /* first stack not ontop wibox window */
347 for(screen
= 0; screen
< globalconf
.nscreen
; screen
++)
348 for(int i
= 0; i
< globalconf
.screens
[screen
].wiboxes
.len
; i
++)
350 wibox_t
*sb
= globalconf
.screens
[screen
].wiboxes
.tab
[i
];
353 xcb_configure_window(globalconf
.connection
,
355 XCB_CONFIG_WINDOW_SIBLING
| XCB_CONFIG_WINDOW_STACK_MODE
,
357 config_win_vals
[0] = sb
->sw
.window
;
361 /* stack bottom layers */
362 for(layer
= LAYER_BELOW
; layer
< LAYER_FULLSCREEN
; layer
++)
363 for(node
= last
; node
; node
= node
->prev
)
364 if(client_layer_translator(node
->client
) == layer
)
365 config_win_vals
[0] = client_stack_above(node
->client
,
368 /* then stack ontop wibox window */
369 for(screen
= 0; screen
< globalconf
.nscreen
; screen
++)
370 for(int i
= 0; i
< globalconf
.screens
[screen
].wiboxes
.len
; i
++)
372 wibox_t
*sb
= globalconf
.screens
[screen
].wiboxes
.tab
[i
];
375 xcb_configure_window(globalconf
.connection
,
377 XCB_CONFIG_WINDOW_SIBLING
| XCB_CONFIG_WINDOW_STACK_MODE
,
379 config_win_vals
[0] = sb
->sw
.window
;
383 /* finally stack ontop and fullscreen windows */
384 for(layer
= LAYER_FULLSCREEN
; layer
< LAYER_OUTOFSPACE
; layer
++)
385 for(node
= last
; node
; node
= node
->prev
)
386 if(client_layer_translator(node
->client
) == layer
)
387 config_win_vals
[0] = client_stack_above(node
->client
,
391 /** Manage a new client.
392 * \param w The window.
393 * \param wgeom Window geometry.
394 * \param phys_screen Physical screen number.
395 * \param screen Virtual screen number where to manage client.
398 client_manage(xcb_window_t w
, xcb_get_geometry_reply_t
*wgeom
, int phys_screen
, int screen
)
400 xcb_get_property_cookie_t ewmh_icon_cookie
;
403 const uint32_t select_input_val
[] =
405 XCB_EVENT_MASK_STRUCTURE_NOTIFY
406 | XCB_EVENT_MASK_PROPERTY_CHANGE
407 | XCB_EVENT_MASK_ENTER_WINDOW
410 /* Send request to get NET_WM_ICON property as soon as possible... */
411 ewmh_icon_cookie
= ewmh_window_icon_get_unchecked(w
);
412 xcb_change_window_attributes(globalconf
.connection
, w
, XCB_CW_EVENT_MASK
, select_input_val
);
414 if(systray_iskdedockapp(w
))
416 systray_request_handle(w
, phys_screen
, NULL
);
420 c
= p_new(client_t
, 1);
422 c
->screen
= screen_getbycoord(screen
, wgeom
->x
, wgeom
->y
);
424 c
->phys_screen
= phys_screen
;
428 c
->geometry
.x
= c
->f_geometry
.x
= c
->m_geometry
.x
= wgeom
->x
;
429 c
->geometry
.y
= c
->f_geometry
.y
= c
->m_geometry
.y
= wgeom
->y
;
430 c
->geometry
.width
= c
->f_geometry
.width
= c
->m_geometry
.width
= wgeom
->width
;
431 c
->geometry
.height
= c
->f_geometry
.height
= c
->m_geometry
.height
= wgeom
->height
;
432 client_setborder(c
, wgeom
->border_width
);
433 if((icon
= ewmh_window_icon_get_reply(ewmh_icon_cookie
)))
434 c
->icon
= image_ref(&icon
);
436 /* we honor size hints by default */
437 c
->honorsizehints
= true;
440 property_update_wm_normal_hints(c
, NULL
);
441 property_update_wm_hints(c
, NULL
);
442 property_update_wm_transient_for(c
, NULL
);
445 screen
= c
->transient_for
->screen
;
447 /* Try to load props if any */
448 client_loadprops(c
, &globalconf
.screens
[screen
]);
451 /* Then check clients hints */
452 ewmh_client_check_hints(c
);
454 /* move client to screen, but do not tag it for now */
455 screen_client_moveto(c
, screen
, false, true);
457 /* Check if client has been tagged by loading props, or maybe with its
459 * If not, we tag it with current selected ones.
460 * This could be done on Lua side, but it's a sane behaviour. */
464 tag_array_t
*tags
= &globalconf
.screens
[screen
].tags
;
465 for(i
= 0; i
< tags
->len
; i
++)
466 if(is_client_tagged(c
, tags
->tab
[i
]))
469 /* if no tag, set current selected */
471 for(i
= 0; i
< tags
->len
; i
++)
472 if(tags
->tab
[i
]->selected
)
473 tag_client(c
, tags
->tab
[i
]);
476 /* Push client in client list */
477 client_list_push(&globalconf
.clients
, client_ref(&c
));
479 /* Push client in stack */
482 /* update window title */
483 property_update_wm_name(c
);
484 property_update_wm_icon_name(c
);
487 ewmh_client_strut_update(c
, NULL
);
489 ewmh_update_net_client_list(c
->phys_screen
);
491 /* Call hook to notify list change */
492 luaA_dofunction(globalconf
.L
, globalconf
.hooks
.clients
, 0, 0);
495 luaA_client_userdata_new(globalconf
.L
, c
);
496 luaA_dofunction(globalconf
.L
, globalconf
.hooks
.manage
, 1, 0);
499 /** Compute client geometry with respect to its geometry hints.
500 * \param c The client.
501 * \param geometry The geometry that the client might receive.
502 * \return The geometry the client must take respecting its hints.
505 client_geometry_hints(client_t
*c
, area_t geometry
)
507 double dx
, dy
, max
, min
, ratio
;
509 if(c
->minay
> 0 && c
->maxay
> 0 && (geometry
.height
- c
->baseh
) > 0
510 && (geometry
.width
- c
->basew
) > 0)
512 dx
= (double) (geometry
.width
- c
->basew
);
513 dy
= (double) (geometry
.height
- c
->baseh
);
514 min
= (double) (c
->minax
) / (double) (c
->minay
);
515 max
= (double) (c
->maxax
) / (double) (c
->maxay
);
517 if(max
> 0 && min
> 0 && ratio
> 0)
521 dy
= (dx
* min
+ dy
) / (min
* min
+ 1);
523 geometry
.width
= (int) dx
+ c
->basew
;
524 geometry
.height
= (int) dy
+ c
->baseh
;
528 dy
= (dx
* min
+ dy
) / (max
* max
+ 1);
530 geometry
.width
= (int) dx
+ c
->basew
;
531 geometry
.height
= (int) dy
+ c
->baseh
;
535 if(c
->minw
&& geometry
.width
< c
->minw
)
536 geometry
.width
= c
->minw
;
537 if(c
->minh
&& geometry
.height
< c
->minh
)
538 geometry
.height
= c
->minh
;
539 if(c
->maxw
&& geometry
.width
> c
->maxw
)
540 geometry
.width
= c
->maxw
;
541 if(c
->maxh
&& geometry
.height
> c
->maxh
)
542 geometry
.height
= c
->maxh
;
544 geometry
.width
-= (geometry
.width
- c
->basew
) % c
->incw
;
546 geometry
.height
-= (geometry
.height
- c
->baseh
) % c
->inch
;
551 /** Resize client window.
552 * \param c Client to resize.
553 * \param geometry New window geometry.
554 * \param hints Use size hints.
557 client_resize(client_t
*c
, area_t geometry
, bool hints
)
561 layout_t
*layout
= layout_get_current(c
->screen
);
563 if(c
->titlebar
&& !c
->ismoving
&& !client_isfloating(c
) && layout
!= layout_floating
)
564 geometry
= titlebar_geometry_remove(c
->titlebar
, c
->border
, geometry
);
567 geometry
= client_geometry_hints(c
, geometry
);
569 if(geometry
.width
<= 0 || geometry
.height
<= 0)
572 /* offscreen appearance fixes */
573 area
= display_area_get(c
->phys_screen
, NULL
,
574 &globalconf
.screens
[c
->screen
].padding
);
576 if(geometry
.x
> area
.width
)
577 geometry
.x
= area
.width
- geometry
.width
- 2 * c
->border
;
578 if(geometry
.y
> area
.height
)
579 geometry
.y
= area
.height
- geometry
.height
- 2 * c
->border
;
580 if(geometry
.x
+ geometry
.width
+ 2 * c
->border
< 0)
582 if(geometry
.y
+ geometry
.height
+ 2 * c
->border
< 0)
585 if(c
->geometry
.x
!= geometry
.x
586 || c
->geometry
.y
!= geometry
.y
587 || c
->geometry
.width
!= geometry
.width
588 || c
->geometry
.height
!= geometry
.height
)
590 new_screen
= screen_getbycoord(c
->screen
, geometry
.x
, geometry
.y
);
592 /* Values to configure a window is an array where values are
593 * stored according to 'value_mask' */
596 c
->geometry
.x
= values
[0] = geometry
.x
;
597 c
->geometry
.y
= values
[1] = geometry
.y
;
598 c
->geometry
.width
= values
[2] = geometry
.width
;
599 c
->geometry
.height
= values
[3] = geometry
.height
;
601 /* save the floating geometry if the window is floating but not
603 if(c
->ismoving
|| client_isfloating(c
)
604 || layout_get_current(new_screen
) == layout_floating
605 || layout_get_current(c
->screen
) == layout_floating
)
607 c
->f_geometry
= geometry
;
609 titlebar_update_geometry_floating(c
);
611 xcb_configure_window(globalconf
.connection
, c
->win
,
612 XCB_CONFIG_WINDOW_X
| XCB_CONFIG_WINDOW_Y
613 | XCB_CONFIG_WINDOW_WIDTH
| XCB_CONFIG_WINDOW_HEIGHT
,
615 window_configure(c
->win
, geometry
, c
->border
);
617 if(c
->screen
!= new_screen
)
618 screen_client_moveto(c
, new_screen
, true, false);
621 hooks_property(c
, "geometry");
625 /** Set a clinet floating.
626 * \param c The client.
627 * \param floating Set floating, or not.
628 * \param layer Layer to put the floating window onto.
631 client_setfloating(client_t
*c
, bool floating
)
633 if(c
->isfloating
!= floating
634 && (c
->type
== WINDOW_TYPE_NORMAL
))
636 if((c
->isfloating
= floating
))
638 client_resize(c
, c
->f_geometry
, false);
639 client_need_arrange(c
);
641 xcb_change_property(globalconf
.connection
,
642 XCB_PROP_MODE_REPLACE
,
643 c
->win
, _AWESOME_FLOATING
, CARDINAL
, 8, 1,
646 hooks_property(c
, "floating");
650 /** Set a client minimized, or not.
651 * \param c The client.
652 * \param s Set or not the client minimized.
655 client_setminimized(client_t
*c
, bool s
)
657 if(c
->isminimized
!= s
)
659 client_need_arrange(c
);
661 client_need_arrange(c
);
662 ewmh_client_update_hints(c
);
664 hooks_property(c
, "minimized");
668 /** Set a client sticky, or not.
669 * \param c The client.
670 * \param s Set or not the client sticky.
673 client_setsticky(client_t
*c
, bool s
)
677 client_need_arrange(c
);
679 client_need_arrange(c
);
680 ewmh_client_update_hints(c
);
681 hooks_property(c
, "sticky");
685 /** Set a client fullscreen, or not.
686 * \param c The client.
687 * \param s Set or not the client fullscreen.
690 client_setfullscreen(client_t
*c
, bool s
)
692 if(c
->isfullscreen
!= s
)
696 /* become fullscreen! */
697 if((c
->isfullscreen
= s
))
699 geometry
= screen_area_get(c
->screen
, NULL
, NULL
, false);
700 c
->m_geometry
= c
->geometry
;
701 c
->oldborder
= c
->border
;
702 client_setborder(c
, 0);
706 geometry
= c
->m_geometry
;
707 client_setborder(c
, c
->oldborder
);
708 client_resize(c
, c
->m_geometry
, false);
710 client_resize(c
, geometry
, false);
711 client_need_arrange(c
);
713 xcb_change_property(globalconf
.connection
,
714 XCB_PROP_MODE_REPLACE
,
715 c
->win
, _AWESOME_FULLSCREEN
, CARDINAL
, 8, 1,
717 ewmh_client_update_hints(c
);
718 hooks_property(c
, "fullscreen");
722 /** Set a client above, or not.
723 * \param c The client.
724 * \param s Set or not the client above.
727 client_setabove(client_t
*c
, bool s
)
733 ewmh_client_update_hints(c
);
735 hooks_property(c
, "above");
739 /** Set a client below, or not.
740 * \param c The client.
741 * \param s Set or not the client below.
744 client_setbelow(client_t
*c
, bool s
)
750 ewmh_client_update_hints(c
);
752 hooks_property(c
, "below");
756 /** Set a client modal, or not.
757 * \param c The client.
758 * \param s Set or not the client moda.
761 client_setmodal(client_t
*c
, bool s
)
767 ewmh_client_update_hints(c
);
769 hooks_property(c
, "modal");
773 /** Set a client ontop, or not.
774 * \param c The client.
775 * \param s Set or not the client moda.
778 client_setontop(client_t
*c
, bool s
)
785 hooks_property(c
, "ontop");
789 /** Save client properties as an X property.
790 * \param c The client.
793 client_saveprops_tags(client_t
*c
)
795 tag_array_t
*tags
= &globalconf
.screens
[c
->screen
].tags
;
796 unsigned char *prop
= p_alloca(unsigned char, tags
->len
+ 1);
799 for(i
= 0; i
< tags
->len
; i
++)
800 prop
[i
] = is_client_tagged(c
, tags
->tab
[i
]) ? '1' : '0';
802 xcb_change_property(globalconf
.connection
, XCB_PROP_MODE_REPLACE
, c
->win
, _AWESOME_TAGS
, STRING
, 8, i
, prop
);
806 * \param c The client.
809 client_unban(client_t
*c
)
811 xcb_map_window(globalconf
.connection
, c
->win
);
812 window_state_set(c
->win
, XCB_WM_STATE_NORMAL
);
815 if(c
->isfullscreen
|| !c
->titlebar
->isvisible
)
816 xcb_unmap_window(globalconf
.connection
, c
->titlebar
->sw
.window
);
818 xcb_map_window(globalconf
.connection
, c
->titlebar
->sw
.window
);
822 /** Unmanage a client.
823 * \param c The client.
826 client_unmanage(client_t
*c
)
828 tag_array_t
*tags
= &globalconf
.screens
[c
->screen
].tags
;
830 if(globalconf
.screens
[c
->phys_screen
].client_focus
== c
)
833 /* remove client everywhere */
834 client_list_detach(&globalconf
.clients
, c
);
835 stack_client_delete(c
);
836 for(int i
= 0; i
< tags
->len
; i
++)
837 untag_client(c
, tags
->tab
[i
]);
840 luaA_client_userdata_new(globalconf
.L
, c
);
841 luaA_dofunction(globalconf
.L
, globalconf
.hooks
.unmanage
, 1, 0);
843 /* Call hook to notify list change */
844 luaA_dofunction(globalconf
.L
, globalconf
.hooks
.clients
, 0, 0);
846 /* The server grab construct avoids race conditions. */
847 xcb_grab_server(globalconf
.connection
);
849 xcb_configure_window(globalconf
.connection
, c
->win
,
850 XCB_CONFIG_WINDOW_BORDER_WIDTH
,
851 (uint32_t *) &c
->oldborder
);
853 xcb_ungrab_button(globalconf
.connection
, XCB_BUTTON_INDEX_ANY
, c
->win
,
854 XCB_BUTTON_MASK_ANY
);
855 window_state_set(c
->win
, XCB_WM_STATE_WITHDRAWN
);
857 xcb_flush(globalconf
.connection
);
858 xcb_ungrab_server(globalconf
.connection
);
860 titlebar_client_detach(c
);
862 ewmh_update_net_client_list(c
->phys_screen
);
864 /* delete properties */
865 xcb_delete_property(globalconf
.connection
, c
->win
, _AWESOME_TAGS
);
866 xcb_delete_property(globalconf
.connection
, c
->win
, _AWESOME_FLOATING
);
868 if(client_hasstrut(c
))
869 /* All the wiboxes (may) need to be repositioned */
870 for(int screen
= 0; screen
< globalconf
.nscreen
; screen
++)
871 for(int i
= 0; i
< globalconf
.screens
[screen
].wiboxes
.len
; i
++)
873 wibox_t
*s
= globalconf
.screens
[screen
].wiboxes
.tab
[i
];
874 wibox_position_update(s
);
877 /* set client as invalid */
883 /** Kill a client via a WM_DELETE_WINDOW request or KillClient if not
885 * \param c The client to kill.
888 client_kill(client_t
*c
)
890 if(window_hasproto(c
->win
, WM_DELETE_WINDOW
))
892 xcb_client_message_event_t ev
;
894 /* Initialize all of event's fields first */
897 ev
.response_type
= XCB_CLIENT_MESSAGE
;
900 ev
.data
.data32
[1] = XCB_CURRENT_TIME
;
901 ev
.type
= WM_PROTOCOLS
;
902 ev
.data
.data32
[0] = WM_DELETE_WINDOW
;
904 xcb_send_event(globalconf
.connection
, false, c
->win
,
905 XCB_EVENT_MASK_NO_EVENT
, (char *) &ev
);
908 xcb_kill_client(globalconf
.connection
, c
->win
);
911 /** Get all clients into a table.
912 * \param L The Lua VM state.
913 * \return The number of elements pushed on stack.
915 * \lparam An optional screen nunmber.
916 * \lreturn A table with all clients.
919 luaA_client_get(lua_State
*L
)
924 screen
= luaL_optnumber(L
, 1, 0) - 1;
928 if(screen
== SCREEN_UNDEF
)
929 for(c
= globalconf
.clients
; c
; c
= c
->next
)
931 luaA_client_userdata_new(globalconf
.L
, c
);
932 lua_rawseti(L
, -2, i
++);
936 luaA_checkscreen(screen
);
937 for(c
= globalconf
.clients
; c
; c
= c
->next
)
938 if(c
->screen
== screen
)
940 luaA_client_userdata_new(globalconf
.L
, c
);
941 lua_rawseti(L
, -2, i
++);
948 /** Get only visible clients for a screen (DEPRECATED).
949 * \param L The Lua VM state.
950 * \return The number of elements pushed on stack.
952 * \lparam A screen number.
953 * \lreturn A table with all visible clients for this screen.
956 luaA_client_visible_get(lua_State
*L
)
960 int screen
= luaL_checknumber(L
, 1) - 1;
962 luaA_checkscreen(screen
);
964 deprecate(L
, "awful.client.visible()");
968 for(c
= globalconf
.clients
; c
; c
= c
->next
)
969 if(client_isvisible(c
, screen
))
971 luaA_client_userdata_new(L
, c
);
972 lua_rawseti(L
, -2, i
++);
978 /** Check if a client is visible on its screen.
979 * \param L The Lua VM state.
980 * \return The number of elements pushed on stack.
983 * \lreturn A boolean value, true if the client is visible, false otherwise.
986 luaA_client_isvisible(lua_State
*L
)
988 client_t
**c
= luaA_checkudata(L
, 1, "client");
989 lua_pushboolean(L
, client_isvisible(*c
, (*c
)->screen
));
993 /** Set client border width.
994 * \param c The client.
995 * \param width The border width.
998 client_setborder(client_t
*c
, int width
)
1002 if(width
> 0 && (c
->type
== WINDOW_TYPE_DOCK
1003 || c
->type
== WINDOW_TYPE_SPLASH
1004 || c
->type
== WINDOW_TYPE_DESKTOP
1005 || c
->isfullscreen
))
1008 if(width
== c
->border
|| width
< 0)
1012 xcb_configure_window(globalconf
.connection
, c
->win
,
1013 XCB_CONFIG_WINDOW_BORDER_WIDTH
, &w
);
1015 if(client_isvisible(c
, c
->screen
))
1017 if(client_isfloating(c
) || layout_get_current(c
->screen
) == layout_floating
)
1018 titlebar_update_geometry_floating(c
);
1020 globalconf
.screens
[c
->screen
].need_arrange
= true;
1023 hooks_property(c
, "border_width");
1027 * \param L The Lua VM state.
1033 luaA_client_kill(lua_State
*L
)
1035 client_t
**c
= luaA_checkudata(L
, 1, "client");
1040 /** Swap a client with another one.
1041 * \param L The Lua VM state.
1044 * \lparam A client to swap with.
1047 luaA_client_swap(lua_State
*L
)
1049 client_t
**c
= luaA_checkudata(L
, 1, "client");
1050 client_t
**swap
= luaA_checkudata(L
, 2, "client");
1051 client_list_swap(&globalconf
.clients
, *swap
, *c
);
1052 client_need_arrange(*c
);
1053 client_need_arrange(*swap
);
1055 /* Call hook to notify list change */
1056 luaA_dofunction(L
, globalconf
.hooks
.clients
, 0, 0);
1061 /** Access or set the client tags.
1062 * \param L The Lua VM state.
1063 * \return The number of elements pushed on stack.
1064 * \lparam A table with tags to set, or none to get the current tags table.
1065 * \return The clients tag.
1068 luaA_client_tags(lua_State
*L
)
1072 client_t
**c
= luaA_checkudata(L
, 1, "client");
1075 if(lua_gettop(L
) == 2)
1077 luaA_checktable(L
, 2);
1078 tags
= &globalconf
.screens
[(*c
)->screen
].tags
;
1079 for(int i
= 0; i
< tags
->len
; i
++)
1080 untag_client(*c
, tags
->tab
[i
]);
1082 while(lua_next(L
, 2))
1084 tag
= luaA_checkudata(L
, -1, "tag");
1085 tag_client(*c
, *tag
);
1091 tags
= &globalconf
.screens
[(*c
)->screen
].tags
;
1093 for(int i
= 0; i
< tags
->len
; i
++)
1094 if(is_client_tagged(*c
, tags
->tab
[i
]))
1096 luaA_tag_userdata_new(L
, tags
->tab
[i
]);
1097 lua_rawseti(L
, -2, ++j
);
1103 /** Raise a client on top of others which are on the same layer.
1104 * \param L The Lua VM state.
1109 luaA_client_raise(lua_State
*L
)
1111 client_t
**c
= luaA_checkudata(L
, 1, "client");
1116 /** Lower a client on bottom of others which are on the same layer.
1117 * \param L The Lua VM state.
1122 luaA_client_lower(lua_State
*L
)
1124 client_t
**c
= luaA_checkudata(L
, 1, "client");
1129 /** Redraw a client by unmapping and mapping it quickly.
1130 * \param L The Lua VM state.
1136 luaA_client_redraw(lua_State
*L
)
1138 client_t
**c
= luaA_checkudata(L
, 1, "client");
1140 xcb_unmap_window(globalconf
.connection
, (*c
)->win
);
1141 xcb_map_window(globalconf
.connection
, (*c
)->win
);
1143 /* Set the focus on the current window if the redraw has been
1144 performed on the window where the pointer is currently on
1145 because after the unmapping/mapping, the focus is lost */
1146 if(globalconf
.screen_focus
->client_focus
== *c
)
1147 xcb_set_input_focus(globalconf
.connection
, XCB_INPUT_FOCUS_POINTER_ROOT
,
1148 (*c
)->win
, XCB_CURRENT_TIME
);
1153 /** Stop managing a client.
1154 * \param L The Lua VM state.
1155 * \return The number of elements pushed on stack.
1160 luaA_client_unmanage(lua_State
*L
)
1162 client_t
**c
= luaA_checkudata(L
, 1, "client");
1163 client_unmanage(*c
);
1167 /** Return client geometry.
1168 * \param L The Lua VM state.
1169 * \param full Use titlebar also.
1170 * \return The number of elements pushed on stack.
1173 luaA_client_handlegeom(lua_State
*L
, bool full
)
1175 client_t
**c
= luaA_checkudata(L
, 1, "client");
1177 if(lua_gettop(L
) == 2)
1178 if(client_isfloating(*c
)
1179 || layout_get_current((*c
)->screen
) == layout_floating
)
1183 luaA_checktable(L
, 2);
1184 geometry
.x
= luaA_getopt_number(L
, 2, "x", (*c
)->geometry
.x
);
1185 geometry
.y
= luaA_getopt_number(L
, 2, "y", (*c
)->geometry
.y
);
1186 if(client_isfixed(*c
))
1188 geometry
.width
= (*c
)->geometry
.width
;
1189 geometry
.height
= (*c
)->geometry
.height
;
1193 geometry
.width
= luaA_getopt_number(L
, 2, "width", (*c
)->geometry
.width
);
1194 geometry
.height
= luaA_getopt_number(L
, 2, "height", (*c
)->geometry
.height
);
1197 geometry
= titlebar_geometry_remove((*c
)->titlebar
,
1200 client_resize(*c
, geometry
, (*c
)->honorsizehints
);
1204 return luaA_pusharea(L
, titlebar_geometry_add((*c
)->titlebar
,
1208 return luaA_pusharea(L
, (*c
)->geometry
);
1211 /** Return client geometry.
1212 * \param L The Lua VM state.
1213 * \return The number of elements pushed on stack.
1215 * \lparam A table with new coordinates, or none.
1216 * \lreturn A table with client coordinates.
1219 luaA_client_geometry(lua_State
*L
)
1221 return luaA_client_handlegeom(L
, false);
1225 luaA_client_coords(lua_State
*L
)
1227 deprecate(L
, "client:geometry()");
1228 return luaA_client_geometry(L
);
1231 /** Return client geometry, using also titlebar and border width.
1232 * \param L The Lua VM state.
1233 * \return The number of elements pushed on stack.
1235 * \lparam A table with new coordinates, or none.
1236 * \lreturn A table with client coordinates.
1239 luaA_client_fullgeometry(lua_State
*L
)
1241 return luaA_client_handlegeom(L
, true);
1245 luaA_client_fullcoords(lua_State
*L
)
1247 deprecate(L
, "client:fullgeometry()");
1248 return luaA_client_fullgeometry(L
);
1251 /** Client newindex.
1252 * \param L The Lua VM state.
1253 * \return The number of elements pushed on stack.
1256 luaA_client_newindex(lua_State
*L
)
1259 client_t
**c
= luaA_checkudata(L
, 1, "client");
1260 const char *buf
= luaL_checklstring(L
, 2, &len
);
1268 luaL_error(L
, "client is invalid\n");
1270 switch(a_tokenize(buf
, len
))
1273 if(globalconf
.xinerama_is_active
)
1275 i
= luaL_checknumber(L
, 3) - 1;
1276 luaA_checkscreen(i
);
1277 if(i
!= (*c
)->screen
)
1278 screen_client_moveto(*c
, i
, true, true);
1282 b
= luaA_checkboolean(L
, 3);
1283 if(b
!= (*c
)->ishidden
)
1285 client_need_arrange(*c
);
1287 client_need_arrange(*c
);
1291 client_setminimized(*c
, luaA_checkboolean(L
, 3));
1293 case A_TK_FULLSCREEN
:
1294 client_setfullscreen(*c
, luaA_checkboolean(L
, 3));
1297 image
= luaA_checkudata(L
, 3, "image");
1298 image_unref(&(*c
)->icon
);
1300 (*c
)->icon
= *image
;
1302 hooks_property(*c
, "icon");
1306 window_opacity_set((*c
)->win
, -1);
1309 d
= luaL_checknumber(L
, 3);
1310 if(d
>= 0 && d
<= 1)
1311 window_opacity_set((*c
)->win
, d
);
1315 client_setfloating(*c
, luaA_checkboolean(L
, 3));
1318 client_setsticky(*c
, luaA_checkboolean(L
, 3));
1320 case A_TK_HONORSIZEHINTS
:
1321 (*c
)->honorsizehints
= luaA_checkboolean(L
, 3);
1322 client_need_arrange(*c
);
1324 case A_TK_BORDER_WIDTH
:
1325 client_setborder(*c
, luaL_checknumber(L
, 3));
1328 client_setontop(*c
, luaA_checkboolean(L
, 3));
1330 case A_TK_BORDER_COLOR
:
1331 if((buf
= luaL_checklstring(L
, 3, &len
))
1332 && xcolor_init_reply(xcolor_init_unchecked(&(*c
)->border_color
, buf
, len
)))
1333 xcb_change_window_attributes(globalconf
.connection
, (*c
)->win
,
1334 XCB_CW_BORDER_PIXEL
, &(*c
)->border_color
.pixel
);
1338 titlebar_client_detach(*c
);
1341 t
= luaA_checkudata(L
, 3, "wibox");
1342 titlebar_client_attach(*c
, *t
);
1353 * \param L The Lua VM state.
1354 * \return The number of elements pushed on stack.
1356 * \lfield name The client title.
1357 * \lfield skip_taskbar True if the client does not want to be in taskbar.
1358 * \lfield type The window type (desktop, normal, dock, …).
1359 * \lfield class The client class.
1360 * \lfield instance The client instance.
1361 * \lfield pid The client PID, if available.
1362 * \lfield role The window role, if available.
1363 * \lfield machine The machine client is running on.
1364 * \lfield icon_name The client name when iconified.
1365 * \lfield screen Client screen number.
1366 * \lfield hide Define if the client must be hidden, i.e. never mapped,
1367 * invisible in taskbar.
1368 * \lfield minimize Define it the client must be iconify, i.e. only visible in
1370 * \lfield icon_path Path to the icon used to identify.
1371 * \lfield floating True always floating.
1372 * \lfield honorsizehints Honor size hints, i.e. respect size ratio.
1373 * \lfield border_width The client border width.
1374 * \lfield border_color The client border color.
1375 * \lfield titlebar The client titlebar.
1376 * \lfield urgent The client urgent state.
1377 * \lfield focus The focused client.
1378 * \lfield opacity The client opacity between 0 and 1.
1379 * \lfield ontop The client is on top of every other windows.
1380 * \lfield fullscreen The client is fullscreen or not.
1381 * \lfield transient_for Return the client the window is transient for.
1382 * \lfield size_hints A table with size hints of the client: user_position,
1383 * user_size, program_position and program_size.
1386 luaA_client_index(lua_State
*L
)
1390 client_t
**c
= luaA_checkudata(L
, 1, "client");
1391 const char *buf
= luaL_checklstring(L
, 2, &len
);
1394 xcb_get_wm_class_reply_t hint
;
1395 xcb_get_property_cookie_t prop_c
;
1396 xcb_get_property_reply_t
*prop_r
= NULL
;
1400 luaL_error(L
, "client is invalid\n");
1402 if(luaA_usemetatable(L
, 1, 2))
1405 switch(a_tokenize(buf
, len
))
1408 lua_pushstring(L
, (*c
)->name
);
1410 case A_TK_TRANSIENT_FOR
:
1411 if((*c
)->transient_for
)
1412 return luaA_client_userdata_new(L
, (*c
)->transient_for
);
1413 case A_TK_SKIP_TASKBAR
:
1414 lua_pushboolean(L
, (*c
)->skiptb
);
1419 case WINDOW_TYPE_DESKTOP
:
1420 lua_pushliteral(L
, "desktop");
1422 case WINDOW_TYPE_DOCK
:
1423 lua_pushliteral(L
, "dock");
1425 case WINDOW_TYPE_SPLASH
:
1426 lua_pushliteral(L
, "splash");
1428 case WINDOW_TYPE_DIALOG
:
1429 lua_pushliteral(L
, "dialog");
1432 lua_pushliteral(L
, "normal");
1437 if(!xcb_get_wm_class_reply(globalconf
.connection
,
1438 xcb_get_wm_class_unchecked(globalconf
.connection
, (*c
)->win
),
1441 lua_pushstring(L
, hint
.class);
1442 xcb_get_wm_class_reply_wipe(&hint
);
1445 if(!xcb_get_wm_class_reply(globalconf
.connection
,
1446 xcb_get_wm_class_unchecked(globalconf
.connection
, (*c
)->win
),
1449 lua_pushstring(L
, hint
.name
);
1450 xcb_get_wm_class_reply_wipe(&hint
);
1453 if(!xutil_text_prop_get(globalconf
.connection
, (*c
)->win
,
1454 WM_WINDOW_ROLE
, &value
, &slen
))
1456 lua_pushlstring(L
, value
, slen
);
1460 prop_c
= xcb_get_property_unchecked(globalconf
.connection
, false, (*c
)->win
, _NET_WM_PID
, CARDINAL
, 0L, 1L);
1461 prop_r
= xcb_get_property_reply(globalconf
.connection
, prop_c
, NULL
);
1463 if(prop_r
&& prop_r
->value_len
&& (data
= xcb_get_property_value(prop_r
)))
1464 lua_pushnumber(L
, *(uint32_t *)data
);
1472 if(!xutil_text_prop_get(globalconf
.connection
, (*c
)->win
,
1473 WM_CLIENT_MACHINE
, &value
, &slen
))
1475 lua_pushlstring(L
, value
, slen
);
1478 case A_TK_ICON_NAME
:
1479 lua_pushstring(L
, (*c
)->icon_name
);
1482 lua_pushnumber(L
, 1 + (*c
)->screen
);
1485 lua_pushboolean(L
, (*c
)->ishidden
);
1488 lua_pushboolean(L
, (*c
)->isminimized
);
1490 case A_TK_FULLSCREEN
:
1491 lua_pushboolean(L
, (*c
)->isfullscreen
);
1495 luaA_image_userdata_new(L
, (*c
)->icon
);
1500 if((d
= window_opacity_get((*c
)->win
)) >= 0)
1501 lua_pushnumber(L
, d
);
1506 lua_pushboolean(L
, client_isfloating(*c
));
1509 lua_pushboolean(L
, (*c
)->isontop
);
1512 lua_pushboolean(L
, (*c
)->issticky
);
1514 case A_TK_HONORSIZEHINTS
:
1515 lua_pushboolean(L
, (*c
)->honorsizehints
);
1517 case A_TK_BORDER_WIDTH
:
1518 lua_pushnumber(L
, (*c
)->border
);
1520 case A_TK_BORDER_COLOR
:
1521 luaA_pushcolor(L
, &(*c
)->border_color
);
1525 return luaA_wibox_userdata_new(L
, (*c
)->titlebar
);
1528 lua_pushboolean(L
, (*c
)->isurgent
);
1530 case A_TK_SIZE_HINTS
:
1532 lua_pushboolean(L
, (*c
)->size_hints
.flags
& XCB_SIZE_HINT_US_POSITION
);
1533 lua_setfield(L
, -2, "user_position");
1534 lua_pushboolean(L
, (*c
)->size_hints
.flags
& XCB_SIZE_HINT_US_SIZE
);
1535 lua_setfield(L
, -2, "user_size");
1536 lua_pushboolean(L
, (*c
)->size_hints
.flags
& XCB_SIZE_HINT_P_POSITION
);
1537 lua_setfield(L
, -2, "program_position");
1538 lua_pushboolean(L
, (*c
)->size_hints
.flags
& XCB_SIZE_HINT_P_SIZE
);
1539 lua_setfield(L
, -2, "program_size");
1548 /** Get or set mouse buttons bindings for a client.
1549 * \param L The Lua VM state.
1550 * \return The number of element pushed on stack.
1553 * \lparam An array of mouse button bindings objects, or nothing.
1554 * \return The array of mouse button bindings objects of this client.
1557 luaA_client_buttons(lua_State
*L
)
1559 client_t
**client
= luaA_checkudata(L
, 1, "client");
1560 button_array_t
*buttons
= &(*client
)->buttons
;
1562 if(lua_gettop(L
) == 2)
1563 luaA_button_array_set(L
, 2, buttons
);
1565 return luaA_button_array_get(L
, buttons
);
1569 * \param L The Lua VM state.
1570 * \return The number of pushed elements.
1573 luaA_client_module_index(lua_State
*L
)
1576 const char *buf
= luaL_checklstring(L
, 2, &len
);
1578 switch(a_tokenize(buf
, len
))
1581 if(globalconf
.screen_focus
->client_focus
)
1582 luaA_client_userdata_new(L
, globalconf
.screen_focus
->client_focus
);
1593 /* Client module new index.
1594 * \param L The Lua VM state.
1595 * \return The number of pushed elements.
1598 luaA_client_module_newindex(lua_State
*L
)
1601 const char *buf
= luaL_checklstring(L
, 2, &len
);
1604 switch(a_tokenize(buf
, len
))
1607 c
= luaA_checkudata(L
, 3, "client");
1617 const struct luaL_reg awesome_client_methods
[] =
1619 { "get", luaA_client_get
},
1620 { "visible_get", luaA_client_visible_get
},
1621 { "__index", luaA_client_module_index
},
1622 { "__newindex", luaA_client_module_newindex
},
1625 const struct luaL_reg awesome_client_meta
[] =
1627 { "isvisible", luaA_client_isvisible
},
1628 { "geometry", luaA_client_geometry
},
1629 { "fullgeometry", luaA_client_fullgeometry
},
1630 { "buttons", luaA_client_buttons
},
1631 { "tags", luaA_client_tags
},
1632 { "kill", luaA_client_kill
},
1633 { "swap", luaA_client_swap
},
1634 { "raise", luaA_client_raise
},
1635 { "lower", luaA_client_lower
},
1636 { "redraw", luaA_client_redraw
},
1637 { "mouse_resize", luaA_client_mouse_resize
},
1638 { "mouse_move", luaA_client_mouse_move
},
1639 { "unmanage", luaA_client_unmanage
},
1640 { "__index", luaA_client_index
},
1641 { "__newindex", luaA_client_newindex
},
1642 { "__eq", luaA_client_eq
},
1643 { "__gc", luaA_client_gc
},
1644 { "__tostring", luaA_client_tostring
},
1646 { "coords", luaA_client_coords
},
1647 { "fullcoords", luaA_client_fullcoords
},
1651 // vim: filetype=c:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=80