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
;
239 xcb_configure_window(globalconf
.connection
, c
->win
,
240 XCB_CONFIG_WINDOW_SIBLING
| XCB_CONFIG_WINDOW_STACK_MODE
,
243 config_win_vals
[0] = c
->win
;
247 xcb_configure_window(globalconf
.connection
,
248 c
->titlebar
->sw
.window
,
249 XCB_CONFIG_WINDOW_SIBLING
| XCB_CONFIG_WINDOW_STACK_MODE
,
251 previous
= c
->titlebar
->sw
.window
;
256 /* stack transient window on top of their parents */
257 for(client_node_t
*node
= *client_node_list_last(&globalconf
.stack
);
258 node
; node
= node
->prev
)
259 if(node
->client
->transient_for
== c
)
261 client_stack_above(node
->client
,
263 previous
= node
->client
->win
;
269 /** Stacking layout layers */
272 /** This one is a special layer */
284 /** Get the real layer of a client according to its attribute (fullscreen, …)
285 * \param c The client.
286 * \return The real layer.
289 client_layer_translator(client_t
*c
)
291 /* first deal with user set attributes */
294 else if(c
->isfullscreen
)
295 return LAYER_FULLSCREEN
;
300 else if(c
->isfloating
)
303 /* check for transient attr */
307 /* then deal with windows type */
310 case WINDOW_TYPE_DOCK
:
312 case WINDOW_TYPE_DESKTOP
:
313 return LAYER_DESKTOP
;
314 case WINDOW_TYPE_DIALOG
:
320 if(client_isfixed(c
))
327 * \todo It might be worth stopping to restack everyone and only stack `c'
328 * relatively to the first matching in the list.
333 uint32_t config_win_vals
[2];
334 client_node_t
*node
, *last
= *client_node_list_last(&globalconf
.stack
);
338 config_win_vals
[0] = XCB_NONE
;
339 config_win_vals
[1] = XCB_STACK_MODE_ABOVE
;
341 /* stack desktop windows */
342 for(layer
= LAYER_DESKTOP
; layer
< LAYER_BELOW
; layer
++)
343 for(node
= last
; node
; node
= node
->prev
)
344 if(client_layer_translator(node
->client
) == layer
)
345 config_win_vals
[0] = client_stack_above(node
->client
,
348 /* first stack not ontop wibox window */
349 for(screen
= 0; screen
< globalconf
.nscreen
; screen
++)
350 for(int i
= 0; i
< globalconf
.screens
[screen
].wiboxes
.len
; i
++)
352 wibox_t
*sb
= globalconf
.screens
[screen
].wiboxes
.tab
[i
];
355 xcb_configure_window(globalconf
.connection
,
357 XCB_CONFIG_WINDOW_SIBLING
| XCB_CONFIG_WINDOW_STACK_MODE
,
359 config_win_vals
[0] = sb
->sw
.window
;
363 /* stack bottom layers */
364 for(layer
= LAYER_BELOW
; layer
< LAYER_FULLSCREEN
; layer
++)
365 for(node
= last
; node
; node
= node
->prev
)
366 if(client_layer_translator(node
->client
) == layer
)
367 config_win_vals
[0] = client_stack_above(node
->client
,
370 /* then stack ontop wibox window */
371 for(screen
= 0; screen
< globalconf
.nscreen
; screen
++)
372 for(int i
= 0; i
< globalconf
.screens
[screen
].wiboxes
.len
; i
++)
374 wibox_t
*sb
= globalconf
.screens
[screen
].wiboxes
.tab
[i
];
377 xcb_configure_window(globalconf
.connection
,
379 XCB_CONFIG_WINDOW_SIBLING
| XCB_CONFIG_WINDOW_STACK_MODE
,
381 config_win_vals
[0] = sb
->sw
.window
;
385 /* finally stack ontop and fullscreen windows */
386 for(layer
= LAYER_FULLSCREEN
; layer
< LAYER_OUTOFSPACE
; layer
++)
387 for(node
= last
; node
; node
= node
->prev
)
388 if(client_layer_translator(node
->client
) == layer
)
389 config_win_vals
[0] = client_stack_above(node
->client
,
393 /** Manage a new client.
394 * \param w The window.
395 * \param wgeom Window geometry.
396 * \param phys_screen Physical screen number.
397 * \param screen Virtual screen number where to manage client.
400 client_manage(xcb_window_t w
, xcb_get_geometry_reply_t
*wgeom
, int phys_screen
, int screen
)
402 xcb_get_property_cookie_t ewmh_icon_cookie
;
405 const uint32_t select_input_val
[] =
407 XCB_EVENT_MASK_STRUCTURE_NOTIFY
408 | XCB_EVENT_MASK_PROPERTY_CHANGE
409 | XCB_EVENT_MASK_ENTER_WINDOW
412 /* Send request to get NET_WM_ICON property as soon as possible... */
413 ewmh_icon_cookie
= ewmh_window_icon_get_unchecked(w
);
414 xcb_change_window_attributes(globalconf
.connection
, w
, XCB_CW_EVENT_MASK
, select_input_val
);
416 if(systray_iskdedockapp(w
))
418 systray_request_handle(w
, phys_screen
, NULL
);
422 c
= p_new(client_t
, 1);
424 c
->screen
= screen_getbycoord(screen
, wgeom
->x
, wgeom
->y
);
426 c
->phys_screen
= phys_screen
;
430 c
->geometry
.x
= c
->f_geometry
.x
= c
->m_geometry
.x
= wgeom
->x
;
431 c
->geometry
.y
= c
->f_geometry
.y
= c
->m_geometry
.y
= wgeom
->y
;
432 c
->geometry
.width
= c
->f_geometry
.width
= c
->m_geometry
.width
= wgeom
->width
;
433 c
->geometry
.height
= c
->f_geometry
.height
= c
->m_geometry
.height
= wgeom
->height
;
434 client_setborder(c
, wgeom
->border_width
);
435 if((icon
= ewmh_window_icon_get_reply(ewmh_icon_cookie
)))
436 c
->icon
= image_ref(&icon
);
438 /* we honor size hints by default */
439 c
->honorsizehints
= true;
442 property_update_wm_normal_hints(c
, NULL
);
443 property_update_wm_hints(c
, NULL
);
444 property_update_wm_transient_for(c
, NULL
);
447 screen
= c
->transient_for
->screen
;
449 /* Try to load props if any */
450 client_loadprops(c
, &globalconf
.screens
[screen
]);
453 /* Then check clients hints */
454 ewmh_client_check_hints(c
);
456 /* move client to screen, but do not tag it for now */
457 screen_client_moveto(c
, screen
, false, true);
459 /* Check if client has been tagged by loading props, or maybe with its
461 * If not, we tag it with current selected ones.
462 * This could be done on Lua side, but it's a sane behaviour. */
466 tag_array_t
*tags
= &globalconf
.screens
[screen
].tags
;
467 for(i
= 0; i
< tags
->len
; i
++)
468 if(is_client_tagged(c
, tags
->tab
[i
]))
471 /* if no tag, set current selected */
473 for(i
= 0; i
< tags
->len
; i
++)
474 if(tags
->tab
[i
]->selected
)
475 tag_client(c
, tags
->tab
[i
]);
478 /* Push client in client list */
479 client_list_push(&globalconf
.clients
, client_ref(&c
));
481 /* Push client in stack */
484 /* update window title */
485 property_update_wm_name(c
);
486 property_update_wm_icon_name(c
);
489 ewmh_client_strut_update(c
, NULL
);
491 ewmh_update_net_client_list(c
->phys_screen
);
493 /* Call hook to notify list change */
494 luaA_dofunction(globalconf
.L
, globalconf
.hooks
.clients
, 0, 0);
497 luaA_client_userdata_new(globalconf
.L
, c
);
498 luaA_dofunction(globalconf
.L
, globalconf
.hooks
.manage
, 1, 0);
501 /** Compute client geometry with respect to its geometry hints.
502 * \param c The client.
503 * \param geometry The geometry that the client might receive.
504 * \return The geometry the client must take respecting its hints.
507 client_geometry_hints(client_t
*c
, area_t geometry
)
509 double dx
, dy
, max
, min
, ratio
;
511 if(c
->minay
> 0 && c
->maxay
> 0 && (geometry
.height
- c
->baseh
) > 0
512 && (geometry
.width
- c
->basew
) > 0)
514 dx
= (double) (geometry
.width
- c
->basew
);
515 dy
= (double) (geometry
.height
- c
->baseh
);
516 min
= (double) (c
->minax
) / (double) (c
->minay
);
517 max
= (double) (c
->maxax
) / (double) (c
->maxay
);
519 if(max
> 0 && min
> 0 && ratio
> 0)
523 dy
= (dx
* min
+ dy
) / (min
* min
+ 1);
525 geometry
.width
= (int) dx
+ c
->basew
;
526 geometry
.height
= (int) dy
+ c
->baseh
;
530 dy
= (dx
* min
+ dy
) / (max
* max
+ 1);
532 geometry
.width
= (int) dx
+ c
->basew
;
533 geometry
.height
= (int) dy
+ c
->baseh
;
537 if(c
->minw
&& geometry
.width
< c
->minw
)
538 geometry
.width
= c
->minw
;
539 if(c
->minh
&& geometry
.height
< c
->minh
)
540 geometry
.height
= c
->minh
;
541 if(c
->maxw
&& geometry
.width
> c
->maxw
)
542 geometry
.width
= c
->maxw
;
543 if(c
->maxh
&& geometry
.height
> c
->maxh
)
544 geometry
.height
= c
->maxh
;
546 geometry
.width
-= (geometry
.width
- c
->basew
) % c
->incw
;
548 geometry
.height
-= (geometry
.height
- c
->baseh
) % c
->inch
;
553 /** Resize client window.
554 * \param c Client to resize.
555 * \param geometry New window geometry.
556 * \param hints Use size hints.
559 client_resize(client_t
*c
, area_t geometry
, bool hints
)
563 layout_t
*layout
= layout_get_current(c
->screen
);
565 if(c
->titlebar
&& !c
->ismoving
&& c
->titlebar
->isvisible
&& !client_isfloating(c
) && layout
!= layout_floating
)
566 geometry
= titlebar_geometry_remove(c
->titlebar
, c
->border
, geometry
);
569 geometry
= client_geometry_hints(c
, geometry
);
571 if(geometry
.width
<= 0 || geometry
.height
<= 0)
574 /* offscreen appearance fixes */
575 area
= display_area_get(c
->phys_screen
, NULL
,
576 &globalconf
.screens
[c
->screen
].padding
);
578 if(geometry
.x
> area
.width
)
579 geometry
.x
= area
.width
- geometry
.width
- 2 * c
->border
;
580 if(geometry
.y
> area
.height
)
581 geometry
.y
= area
.height
- geometry
.height
- 2 * c
->border
;
582 if(geometry
.x
+ geometry
.width
+ 2 * c
->border
< 0)
584 if(geometry
.y
+ geometry
.height
+ 2 * c
->border
< 0)
587 if(c
->geometry
.x
!= geometry
.x
588 || c
->geometry
.y
!= geometry
.y
589 || c
->geometry
.width
!= geometry
.width
590 || c
->geometry
.height
!= geometry
.height
)
592 new_screen
= screen_getbycoord(c
->screen
, geometry
.x
, geometry
.y
);
594 /* Values to configure a window is an array where values are
595 * stored according to 'value_mask' */
598 c
->geometry
.x
= values
[0] = geometry
.x
;
599 c
->geometry
.y
= values
[1] = geometry
.y
;
600 c
->geometry
.width
= values
[2] = geometry
.width
;
601 c
->geometry
.height
= values
[3] = geometry
.height
;
603 /* save the floating geometry if the window is floating but not
605 if(c
->ismoving
|| client_isfloating(c
)
606 || layout_get_current(new_screen
) == layout_floating
607 || layout_get_current(c
->screen
) == layout_floating
)
609 c
->f_geometry
= geometry
;
611 titlebar_update_geometry_floating(c
);
613 xcb_configure_window(globalconf
.connection
, c
->win
,
614 XCB_CONFIG_WINDOW_X
| XCB_CONFIG_WINDOW_Y
615 | XCB_CONFIG_WINDOW_WIDTH
| XCB_CONFIG_WINDOW_HEIGHT
,
617 window_configure(c
->win
, geometry
, c
->border
);
619 if(c
->screen
!= new_screen
)
620 screen_client_moveto(c
, new_screen
, true, false);
623 hooks_property(c
, "geometry");
627 /** Set a client floating.
628 * \param c The client.
629 * \param floating Set floating, or not.
630 * \param layer Layer to put the floating window onto.
633 client_setfloating(client_t
*c
, bool floating
)
635 if(c
->isfloating
!= floating
636 && (c
->type
== WINDOW_TYPE_NORMAL
))
638 if((c
->isfloating
= floating
))
640 client_resize(c
, c
->f_geometry
, false);
641 client_need_arrange(c
);
643 xcb_change_property(globalconf
.connection
,
644 XCB_PROP_MODE_REPLACE
,
645 c
->win
, _AWESOME_FLOATING
, CARDINAL
, 8, 1,
648 hooks_property(c
, "floating");
652 /** Set a client minimized, or not.
653 * \param c The client.
654 * \param s Set or not the client minimized.
657 client_setminimized(client_t
*c
, bool s
)
659 if(c
->isminimized
!= s
)
661 client_need_arrange(c
);
663 client_need_arrange(c
);
664 ewmh_client_update_hints(c
);
666 hooks_property(c
, "minimized");
670 /** Set a client sticky, or not.
671 * \param c The client.
672 * \param s Set or not the client sticky.
675 client_setsticky(client_t
*c
, bool s
)
679 client_need_arrange(c
);
681 client_need_arrange(c
);
682 ewmh_client_update_hints(c
);
683 hooks_property(c
, "sticky");
687 /** Set a client fullscreen, or not.
688 * \param c The client.
689 * \param s Set or not the client fullscreen.
692 client_setfullscreen(client_t
*c
, bool s
)
694 if(c
->isfullscreen
!= s
)
698 /* become fullscreen! */
699 if((c
->isfullscreen
= s
))
701 geometry
= screen_area_get(c
->screen
, NULL
, NULL
, false);
702 c
->m_geometry
= c
->geometry
;
703 c
->oldborder
= c
->border
;
704 client_setborder(c
, 0);
708 geometry
= c
->m_geometry
;
709 client_setborder(c
, c
->oldborder
);
711 client_resize(c
, geometry
, false);
712 client_need_arrange(c
);
714 xcb_change_property(globalconf
.connection
,
715 XCB_PROP_MODE_REPLACE
,
716 c
->win
, _AWESOME_FULLSCREEN
, CARDINAL
, 8, 1,
718 ewmh_client_update_hints(c
);
719 hooks_property(c
, "fullscreen");
723 /** Set a client above, or not.
724 * \param c The client.
725 * \param s Set or not the client above.
728 client_setabove(client_t
*c
, bool s
)
734 ewmh_client_update_hints(c
);
736 hooks_property(c
, "above");
740 /** Set a client below, or not.
741 * \param c The client.
742 * \param s Set or not the client below.
745 client_setbelow(client_t
*c
, bool s
)
751 ewmh_client_update_hints(c
);
753 hooks_property(c
, "below");
757 /** Set a client modal, or not.
758 * \param c The client.
759 * \param s Set or not the client moda.
762 client_setmodal(client_t
*c
, bool s
)
768 ewmh_client_update_hints(c
);
770 hooks_property(c
, "modal");
774 /** Set a client ontop, or not.
775 * \param c The client.
776 * \param s Set or not the client moda.
779 client_setontop(client_t
*c
, bool s
)
786 hooks_property(c
, "ontop");
790 /** Save client properties as an X property.
791 * \param c The client.
794 client_saveprops_tags(client_t
*c
)
796 tag_array_t
*tags
= &globalconf
.screens
[c
->screen
].tags
;
797 unsigned char *prop
= p_alloca(unsigned char, tags
->len
+ 1);
800 for(i
= 0; i
< tags
->len
; i
++)
801 prop
[i
] = is_client_tagged(c
, tags
->tab
[i
]) ? '1' : '0';
803 xcb_change_property(globalconf
.connection
, XCB_PROP_MODE_REPLACE
, c
->win
, _AWESOME_TAGS
, STRING
, 8, i
, prop
);
807 * \param c The client.
810 client_unban(client_t
*c
)
812 xcb_map_window(globalconf
.connection
, c
->win
);
813 window_state_set(c
->win
, XCB_WM_STATE_NORMAL
);
816 if(c
->isfullscreen
|| !c
->titlebar
->isvisible
)
817 xcb_unmap_window(globalconf
.connection
, c
->titlebar
->sw
.window
);
819 xcb_map_window(globalconf
.connection
, c
->titlebar
->sw
.window
);
823 /** Unmanage a client.
824 * \param c The client.
827 client_unmanage(client_t
*c
)
829 tag_array_t
*tags
= &globalconf
.screens
[c
->screen
].tags
;
831 if(globalconf
.screens
[c
->phys_screen
].client_focus
== c
)
834 /* remove client everywhere */
835 client_list_detach(&globalconf
.clients
, c
);
836 stack_client_delete(c
);
837 for(int i
= 0; i
< tags
->len
; i
++)
838 untag_client(c
, tags
->tab
[i
]);
841 luaA_client_userdata_new(globalconf
.L
, c
);
842 luaA_dofunction(globalconf
.L
, globalconf
.hooks
.unmanage
, 1, 0);
844 /* Call hook to notify list change */
845 luaA_dofunction(globalconf
.L
, globalconf
.hooks
.clients
, 0, 0);
847 /* The server grab construct avoids race conditions. */
848 xcb_grab_server(globalconf
.connection
);
850 xcb_configure_window(globalconf
.connection
, c
->win
,
851 XCB_CONFIG_WINDOW_BORDER_WIDTH
,
852 (uint32_t *) &c
->oldborder
);
854 xcb_ungrab_button(globalconf
.connection
, XCB_BUTTON_INDEX_ANY
, c
->win
,
855 XCB_BUTTON_MASK_ANY
);
856 window_state_set(c
->win
, XCB_WM_STATE_WITHDRAWN
);
858 xcb_flush(globalconf
.connection
);
859 xcb_ungrab_server(globalconf
.connection
);
861 titlebar_client_detach(c
);
863 ewmh_update_net_client_list(c
->phys_screen
);
865 /* delete properties */
866 xcb_delete_property(globalconf
.connection
, c
->win
, _AWESOME_TAGS
);
867 xcb_delete_property(globalconf
.connection
, c
->win
, _AWESOME_FLOATING
);
869 if(client_hasstrut(c
))
870 /* All the wiboxes (may) need to be repositioned */
871 for(int screen
= 0; screen
< globalconf
.nscreen
; screen
++)
872 for(int i
= 0; i
< globalconf
.screens
[screen
].wiboxes
.len
; i
++)
874 wibox_t
*s
= globalconf
.screens
[screen
].wiboxes
.tab
[i
];
875 wibox_position_update(s
);
878 /* set client as invalid */
884 /** Kill a client via a WM_DELETE_WINDOW request or KillClient if not
886 * \param c The client to kill.
889 client_kill(client_t
*c
)
891 if(window_hasproto(c
->win
, WM_DELETE_WINDOW
))
893 xcb_client_message_event_t ev
;
895 /* Initialize all of event's fields first */
898 ev
.response_type
= XCB_CLIENT_MESSAGE
;
901 ev
.data
.data32
[1] = XCB_CURRENT_TIME
;
902 ev
.type
= WM_PROTOCOLS
;
903 ev
.data
.data32
[0] = WM_DELETE_WINDOW
;
905 xcb_send_event(globalconf
.connection
, false, c
->win
,
906 XCB_EVENT_MASK_NO_EVENT
, (char *) &ev
);
909 xcb_kill_client(globalconf
.connection
, c
->win
);
912 /** Get all clients into a table.
913 * \param L The Lua VM state.
914 * \return The number of elements pushed on stack.
916 * \lparam An optional screen nunmber.
917 * \lreturn A table with all clients.
920 luaA_client_get(lua_State
*L
)
925 screen
= luaL_optnumber(L
, 1, 0) - 1;
929 if(screen
== SCREEN_UNDEF
)
930 for(c
= globalconf
.clients
; c
; c
= c
->next
)
932 luaA_client_userdata_new(globalconf
.L
, c
);
933 lua_rawseti(L
, -2, i
++);
937 luaA_checkscreen(screen
);
938 for(c
= globalconf
.clients
; c
; c
= c
->next
)
939 if(c
->screen
== screen
)
941 luaA_client_userdata_new(globalconf
.L
, c
);
942 lua_rawseti(L
, -2, i
++);
949 /** Get only visible clients for a screen (DEPRECATED).
950 * \param L The Lua VM state.
951 * \return The number of elements pushed on stack.
953 * \lparam A screen number.
954 * \lreturn A table with all visible clients for this screen.
957 luaA_client_visible_get(lua_State
*L
)
961 int screen
= luaL_checknumber(L
, 1) - 1;
963 luaA_checkscreen(screen
);
965 deprecate(L
, "awful.client.visible()");
969 for(c
= globalconf
.clients
; c
; c
= c
->next
)
970 if(client_isvisible(c
, screen
))
972 luaA_client_userdata_new(L
, c
);
973 lua_rawseti(L
, -2, i
++);
979 /** Check if a client is visible on its screen.
980 * \param L The Lua VM state.
981 * \return The number of elements pushed on stack.
984 * \lreturn A boolean value, true if the client is visible, false otherwise.
987 luaA_client_isvisible(lua_State
*L
)
989 client_t
**c
= luaA_checkudata(L
, 1, "client");
990 lua_pushboolean(L
, client_isvisible(*c
, (*c
)->screen
));
994 /** Set client border width.
995 * \param c The client.
996 * \param width The border width.
999 client_setborder(client_t
*c
, int width
)
1003 if(width
> 0 && (c
->type
== WINDOW_TYPE_DOCK
1004 || c
->type
== WINDOW_TYPE_SPLASH
1005 || c
->type
== WINDOW_TYPE_DESKTOP
1006 || c
->isfullscreen
))
1009 if(width
== c
->border
|| width
< 0)
1013 xcb_configure_window(globalconf
.connection
, c
->win
,
1014 XCB_CONFIG_WINDOW_BORDER_WIDTH
, &w
);
1016 if(client_isvisible(c
, c
->screen
))
1018 if(client_isfloating(c
) || layout_get_current(c
->screen
) == layout_floating
)
1019 titlebar_update_geometry_floating(c
);
1021 globalconf
.screens
[c
->screen
].need_arrange
= true;
1024 hooks_property(c
, "border_width");
1028 * \param L The Lua VM state.
1034 luaA_client_kill(lua_State
*L
)
1036 client_t
**c
= luaA_checkudata(L
, 1, "client");
1041 /** Swap a client with another one.
1042 * \param L The Lua VM state.
1045 * \lparam A client to swap with.
1048 luaA_client_swap(lua_State
*L
)
1050 client_t
**c
= luaA_checkudata(L
, 1, "client");
1051 client_t
**swap
= luaA_checkudata(L
, 2, "client");
1052 client_list_swap(&globalconf
.clients
, *swap
, *c
);
1053 client_need_arrange(*c
);
1054 client_need_arrange(*swap
);
1056 /* Call hook to notify list change */
1057 luaA_dofunction(L
, globalconf
.hooks
.clients
, 0, 0);
1062 /** Access or set the client tags.
1063 * \param L The Lua VM state.
1064 * \return The number of elements pushed on stack.
1065 * \lparam A table with tags to set, or none to get the current tags table.
1066 * \return The clients tag.
1069 luaA_client_tags(lua_State
*L
)
1073 client_t
**c
= luaA_checkudata(L
, 1, "client");
1076 if(lua_gettop(L
) == 2)
1078 luaA_checktable(L
, 2);
1079 tags
= &globalconf
.screens
[(*c
)->screen
].tags
;
1080 for(int i
= 0; i
< tags
->len
; i
++)
1081 untag_client(*c
, tags
->tab
[i
]);
1083 while(lua_next(L
, 2))
1085 tag
= luaA_checkudata(L
, -1, "tag");
1086 tag_client(*c
, *tag
);
1092 tags
= &globalconf
.screens
[(*c
)->screen
].tags
;
1094 for(int i
= 0; i
< tags
->len
; i
++)
1095 if(is_client_tagged(*c
, tags
->tab
[i
]))
1097 luaA_tag_userdata_new(L
, tags
->tab
[i
]);
1098 lua_rawseti(L
, -2, ++j
);
1104 /** Raise a client on top of others which are on the same layer.
1105 * \param L The Lua VM state.
1110 luaA_client_raise(lua_State
*L
)
1112 client_t
**c
= luaA_checkudata(L
, 1, "client");
1117 /** Lower a client on bottom of others which are on the same layer.
1118 * \param L The Lua VM state.
1123 luaA_client_lower(lua_State
*L
)
1125 client_t
**c
= luaA_checkudata(L
, 1, "client");
1130 /** Redraw a client by unmapping and mapping it quickly.
1131 * \param L The Lua VM state.
1137 luaA_client_redraw(lua_State
*L
)
1139 client_t
**c
= luaA_checkudata(L
, 1, "client");
1141 xcb_unmap_window(globalconf
.connection
, (*c
)->win
);
1142 xcb_map_window(globalconf
.connection
, (*c
)->win
);
1144 /* Set the focus on the current window if the redraw has been
1145 performed on the window where the pointer is currently on
1146 because after the unmapping/mapping, the focus is lost */
1147 if(globalconf
.screen_focus
->client_focus
== *c
)
1148 xcb_set_input_focus(globalconf
.connection
, XCB_INPUT_FOCUS_POINTER_ROOT
,
1149 (*c
)->win
, XCB_CURRENT_TIME
);
1154 /** Stop managing a client.
1155 * \param L The Lua VM state.
1156 * \return The number of elements pushed on stack.
1161 luaA_client_unmanage(lua_State
*L
)
1163 client_t
**c
= luaA_checkudata(L
, 1, "client");
1164 client_unmanage(*c
);
1168 /** Return client geometry.
1169 * \param L The Lua VM state.
1170 * \param full Use titlebar also.
1171 * \return The number of elements pushed on stack.
1174 luaA_client_handlegeom(lua_State
*L
, bool full
)
1176 client_t
**c
= luaA_checkudata(L
, 1, "client");
1178 if(lua_gettop(L
) == 2)
1179 if(client_isfloating(*c
)
1180 || layout_get_current((*c
)->screen
) == layout_floating
)
1184 luaA_checktable(L
, 2);
1185 geometry
.x
= luaA_getopt_number(L
, 2, "x", (*c
)->geometry
.x
);
1186 geometry
.y
= luaA_getopt_number(L
, 2, "y", (*c
)->geometry
.y
);
1187 if(client_isfixed(*c
))
1189 geometry
.width
= (*c
)->geometry
.width
;
1190 geometry
.height
= (*c
)->geometry
.height
;
1194 geometry
.width
= luaA_getopt_number(L
, 2, "width", (*c
)->geometry
.width
);
1195 geometry
.height
= luaA_getopt_number(L
, 2, "height", (*c
)->geometry
.height
);
1198 geometry
= titlebar_geometry_remove((*c
)->titlebar
,
1201 client_resize(*c
, geometry
, (*c
)->honorsizehints
);
1205 return luaA_pusharea(L
, titlebar_geometry_add((*c
)->titlebar
,
1209 return luaA_pusharea(L
, (*c
)->geometry
);
1212 /** Return client geometry.
1213 * \param L The Lua VM state.
1214 * \return The number of elements pushed on stack.
1216 * \lparam A table with new coordinates, or none.
1217 * \lreturn A table with client coordinates.
1220 luaA_client_geometry(lua_State
*L
)
1222 return luaA_client_handlegeom(L
, false);
1226 luaA_client_coords(lua_State
*L
)
1228 deprecate(L
, "client:geometry()");
1229 return luaA_client_geometry(L
);
1232 /** Return client geometry, using also titlebar and border width.
1233 * \param L The Lua VM state.
1234 * \return The number of elements pushed on stack.
1236 * \lparam A table with new coordinates, or none.
1237 * \lreturn A table with client coordinates.
1240 luaA_client_fullgeometry(lua_State
*L
)
1242 return luaA_client_handlegeom(L
, true);
1246 luaA_client_fullcoords(lua_State
*L
)
1248 deprecate(L
, "client:fullgeometry()");
1249 return luaA_client_fullgeometry(L
);
1252 /** Client newindex.
1253 * \param L The Lua VM state.
1254 * \return The number of elements pushed on stack.
1257 luaA_client_newindex(lua_State
*L
)
1260 client_t
**c
= luaA_checkudata(L
, 1, "client");
1261 const char *buf
= luaL_checklstring(L
, 2, &len
);
1269 luaL_error(L
, "client is invalid\n");
1271 switch(a_tokenize(buf
, len
))
1274 if(globalconf
.xinerama_is_active
)
1276 i
= luaL_checknumber(L
, 3) - 1;
1277 luaA_checkscreen(i
);
1278 if(i
!= (*c
)->screen
)
1279 screen_client_moveto(*c
, i
, true, true);
1283 b
= luaA_checkboolean(L
, 3);
1284 if(b
!= (*c
)->ishidden
)
1286 client_need_arrange(*c
);
1288 client_need_arrange(*c
);
1292 client_setminimized(*c
, luaA_checkboolean(L
, 3));
1294 case A_TK_FULLSCREEN
:
1295 client_setfullscreen(*c
, luaA_checkboolean(L
, 3));
1298 image
= luaA_checkudata(L
, 3, "image");
1299 image_unref(&(*c
)->icon
);
1301 (*c
)->icon
= *image
;
1303 hooks_property(*c
, "icon");
1307 window_opacity_set((*c
)->win
, -1);
1310 d
= luaL_checknumber(L
, 3);
1311 if(d
>= 0 && d
<= 1)
1312 window_opacity_set((*c
)->win
, d
);
1316 client_setfloating(*c
, luaA_checkboolean(L
, 3));
1319 client_setsticky(*c
, luaA_checkboolean(L
, 3));
1321 case A_TK_HONORSIZEHINTS
:
1322 (*c
)->honorsizehints
= luaA_checkboolean(L
, 3);
1323 client_need_arrange(*c
);
1325 case A_TK_BORDER_WIDTH
:
1326 client_setborder(*c
, luaL_checknumber(L
, 3));
1329 client_setontop(*c
, luaA_checkboolean(L
, 3));
1331 case A_TK_BORDER_COLOR
:
1332 if((buf
= luaL_checklstring(L
, 3, &len
))
1333 && xcolor_init_reply(xcolor_init_unchecked(&(*c
)->border_color
, buf
, len
)))
1334 xcb_change_window_attributes(globalconf
.connection
, (*c
)->win
,
1335 XCB_CW_BORDER_PIXEL
, &(*c
)->border_color
.pixel
);
1339 titlebar_client_detach(*c
);
1342 t
= luaA_checkudata(L
, 3, "wibox");
1343 titlebar_client_attach(*c
, *t
);
1354 * \param L The Lua VM state.
1355 * \return The number of elements pushed on stack.
1357 * \lfield name The client title.
1358 * \lfield skip_taskbar True if the client does not want to be in taskbar.
1359 * \lfield type The window type (desktop, normal, dock, …).
1360 * \lfield class The client class.
1361 * \lfield instance The client instance.
1362 * \lfield pid The client PID, if available.
1363 * \lfield role The window role, if available.
1364 * \lfield machine The machine client is running on.
1365 * \lfield icon_name The client name when iconified.
1366 * \lfield screen Client screen number.
1367 * \lfield hide Define if the client must be hidden, i.e. never mapped,
1368 * invisible in taskbar.
1369 * \lfield minimize Define it the client must be iconify, i.e. only visible in
1371 * \lfield icon_path Path to the icon used to identify.
1372 * \lfield floating True always floating.
1373 * \lfield honorsizehints Honor size hints, i.e. respect size ratio.
1374 * \lfield border_width The client border width.
1375 * \lfield border_color The client border color.
1376 * \lfield titlebar The client titlebar.
1377 * \lfield urgent The client urgent state.
1378 * \lfield focus The focused client.
1379 * \lfield opacity The client opacity between 0 and 1.
1380 * \lfield ontop The client is on top of every other windows.
1381 * \lfield fullscreen The client is fullscreen or not.
1382 * \lfield transient_for Return the client the window is transient for.
1383 * \lfield size_hints A table with size hints of the client: user_position,
1384 * user_size, program_position and program_size.
1387 luaA_client_index(lua_State
*L
)
1391 client_t
**c
= luaA_checkudata(L
, 1, "client");
1392 const char *buf
= luaL_checklstring(L
, 2, &len
);
1395 xcb_get_wm_class_reply_t hint
;
1396 xcb_get_property_cookie_t prop_c
;
1397 xcb_get_property_reply_t
*prop_r
= NULL
;
1401 luaL_error(L
, "client is invalid\n");
1403 if(luaA_usemetatable(L
, 1, 2))
1406 switch(a_tokenize(buf
, len
))
1409 lua_pushstring(L
, (*c
)->name
);
1411 case A_TK_TRANSIENT_FOR
:
1412 if((*c
)->transient_for
)
1413 return luaA_client_userdata_new(L
, (*c
)->transient_for
);
1414 case A_TK_SKIP_TASKBAR
:
1415 lua_pushboolean(L
, (*c
)->skiptb
);
1420 case WINDOW_TYPE_DESKTOP
:
1421 lua_pushliteral(L
, "desktop");
1423 case WINDOW_TYPE_DOCK
:
1424 lua_pushliteral(L
, "dock");
1426 case WINDOW_TYPE_SPLASH
:
1427 lua_pushliteral(L
, "splash");
1429 case WINDOW_TYPE_DIALOG
:
1430 lua_pushliteral(L
, "dialog");
1433 lua_pushliteral(L
, "normal");
1438 if(!xcb_get_wm_class_reply(globalconf
.connection
,
1439 xcb_get_wm_class_unchecked(globalconf
.connection
, (*c
)->win
),
1442 lua_pushstring(L
, hint
.class);
1443 xcb_get_wm_class_reply_wipe(&hint
);
1446 if(!xcb_get_wm_class_reply(globalconf
.connection
,
1447 xcb_get_wm_class_unchecked(globalconf
.connection
, (*c
)->win
),
1450 lua_pushstring(L
, hint
.name
);
1451 xcb_get_wm_class_reply_wipe(&hint
);
1454 if(!xutil_text_prop_get(globalconf
.connection
, (*c
)->win
,
1455 WM_WINDOW_ROLE
, &value
, &slen
))
1457 lua_pushlstring(L
, value
, slen
);
1461 prop_c
= xcb_get_property_unchecked(globalconf
.connection
, false, (*c
)->win
, _NET_WM_PID
, CARDINAL
, 0L, 1L);
1462 prop_r
= xcb_get_property_reply(globalconf
.connection
, prop_c
, NULL
);
1464 if(prop_r
&& prop_r
->value_len
&& (data
= xcb_get_property_value(prop_r
)))
1465 lua_pushnumber(L
, *(uint32_t *)data
);
1473 if(!xutil_text_prop_get(globalconf
.connection
, (*c
)->win
,
1474 WM_CLIENT_MACHINE
, &value
, &slen
))
1476 lua_pushlstring(L
, value
, slen
);
1479 case A_TK_ICON_NAME
:
1480 lua_pushstring(L
, (*c
)->icon_name
);
1483 lua_pushnumber(L
, 1 + (*c
)->screen
);
1486 lua_pushboolean(L
, (*c
)->ishidden
);
1489 lua_pushboolean(L
, (*c
)->isminimized
);
1491 case A_TK_FULLSCREEN
:
1492 lua_pushboolean(L
, (*c
)->isfullscreen
);
1496 luaA_image_userdata_new(L
, (*c
)->icon
);
1501 if((d
= window_opacity_get((*c
)->win
)) >= 0)
1502 lua_pushnumber(L
, d
);
1507 lua_pushboolean(L
, client_isfloating(*c
));
1510 lua_pushboolean(L
, (*c
)->isontop
);
1513 lua_pushboolean(L
, (*c
)->issticky
);
1515 case A_TK_HONORSIZEHINTS
:
1516 lua_pushboolean(L
, (*c
)->honorsizehints
);
1518 case A_TK_BORDER_WIDTH
:
1519 lua_pushnumber(L
, (*c
)->border
);
1521 case A_TK_BORDER_COLOR
:
1522 luaA_pushcolor(L
, &(*c
)->border_color
);
1526 return luaA_wibox_userdata_new(L
, (*c
)->titlebar
);
1529 lua_pushboolean(L
, (*c
)->isurgent
);
1531 case A_TK_SIZE_HINTS
:
1533 lua_pushboolean(L
, (*c
)->size_hints
.flags
& XCB_SIZE_HINT_US_POSITION
);
1534 lua_setfield(L
, -2, "user_position");
1535 lua_pushboolean(L
, (*c
)->size_hints
.flags
& XCB_SIZE_HINT_US_SIZE
);
1536 lua_setfield(L
, -2, "user_size");
1537 lua_pushboolean(L
, (*c
)->size_hints
.flags
& XCB_SIZE_HINT_P_POSITION
);
1538 lua_setfield(L
, -2, "program_position");
1539 lua_pushboolean(L
, (*c
)->size_hints
.flags
& XCB_SIZE_HINT_P_SIZE
);
1540 lua_setfield(L
, -2, "program_size");
1549 /** Get or set mouse buttons bindings for a client.
1550 * \param L The Lua VM state.
1551 * \return The number of element pushed on stack.
1554 * \lparam An array of mouse button bindings objects, or nothing.
1555 * \return The array of mouse button bindings objects of this client.
1558 luaA_client_buttons(lua_State
*L
)
1560 client_t
**client
= luaA_checkudata(L
, 1, "client");
1561 button_array_t
*buttons
= &(*client
)->buttons
;
1563 if(lua_gettop(L
) == 2)
1564 luaA_button_array_set(L
, 2, buttons
);
1566 return luaA_button_array_get(L
, buttons
);
1570 * \param L The Lua VM state.
1571 * \return The number of pushed elements.
1574 luaA_client_module_index(lua_State
*L
)
1577 const char *buf
= luaL_checklstring(L
, 2, &len
);
1579 switch(a_tokenize(buf
, len
))
1582 if(globalconf
.screen_focus
->client_focus
)
1583 luaA_client_userdata_new(L
, globalconf
.screen_focus
->client_focus
);
1594 /* Client module new index.
1595 * \param L The Lua VM state.
1596 * \return The number of pushed elements.
1599 luaA_client_module_newindex(lua_State
*L
)
1602 const char *buf
= luaL_checklstring(L
, 2, &len
);
1605 switch(a_tokenize(buf
, len
))
1608 c
= luaA_checkudata(L
, 3, "client");
1618 const struct luaL_reg awesome_client_methods
[] =
1620 { "get", luaA_client_get
},
1621 { "visible_get", luaA_client_visible_get
},
1622 { "__index", luaA_client_module_index
},
1623 { "__newindex", luaA_client_module_newindex
},
1626 const struct luaL_reg awesome_client_meta
[] =
1628 { "isvisible", luaA_client_isvisible
},
1629 { "geometry", luaA_client_geometry
},
1630 { "fullgeometry", luaA_client_fullgeometry
},
1631 { "buttons", luaA_client_buttons
},
1632 { "tags", luaA_client_tags
},
1633 { "kill", luaA_client_kill
},
1634 { "swap", luaA_client_swap
},
1635 { "raise", luaA_client_raise
},
1636 { "lower", luaA_client_lower
},
1637 { "redraw", luaA_client_redraw
},
1638 { "mouse_resize", luaA_client_mouse_resize
},
1639 { "mouse_move", luaA_client_mouse_move
},
1640 { "unmanage", luaA_client_unmanage
},
1641 { "__index", luaA_client_index
},
1642 { "__newindex", luaA_client_newindex
},
1643 { "__eq", luaA_client_eq
},
1644 { "__gc", luaA_client_gc
},
1645 { "__tostring", luaA_client_tostring
},
1647 { "coords", luaA_client_coords
},
1648 { "fullcoords", luaA_client_fullcoords
},
1652 // vim: filetype=c:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=80