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 /* first stack not ontop wibox window */
340 for(screen
= 0; screen
< globalconf
.nscreen
; screen
++)
341 for(int i
= 0; i
< globalconf
.screens
[screen
].wiboxes
.len
; i
++)
343 wibox_t
*sb
= globalconf
.screens
[screen
].wiboxes
.tab
[i
];
346 xcb_configure_window(globalconf
.connection
,
348 XCB_CONFIG_WINDOW_SIBLING
| XCB_CONFIG_WINDOW_STACK_MODE
,
350 config_win_vals
[0] = sb
->sw
.window
;
354 /* stack bottom layers */
355 for(layer
= LAYER_DESKTOP
; layer
< LAYER_FULLSCREEN
; layer
++)
356 for(node
= last
; node
; node
= node
->prev
)
357 if(client_layer_translator(node
->client
) == layer
)
358 config_win_vals
[0] = client_stack_above(node
->client
,
361 /* then stack ontop wibox window */
362 for(screen
= 0; screen
< globalconf
.nscreen
; screen
++)
363 for(int i
= 0; i
< globalconf
.screens
[screen
].wiboxes
.len
; i
++)
365 wibox_t
*sb
= globalconf
.screens
[screen
].wiboxes
.tab
[i
];
368 xcb_configure_window(globalconf
.connection
,
370 XCB_CONFIG_WINDOW_SIBLING
| XCB_CONFIG_WINDOW_STACK_MODE
,
372 config_win_vals
[0] = sb
->sw
.window
;
376 /* finally stack ontop and fullscreen windows */
377 for(layer
= LAYER_FULLSCREEN
; layer
< LAYER_OUTOFSPACE
; layer
++)
378 for(node
= last
; node
; node
= node
->prev
)
379 if(client_layer_translator(node
->client
) == layer
)
380 config_win_vals
[0] = client_stack_above(node
->client
,
384 /** Manage a new client.
385 * \param w The window.
386 * \param wgeom Window geometry.
387 * \param phys_screen Physical screen number.
388 * \param screen Virtual screen number where to manage client.
391 client_manage(xcb_window_t w
, xcb_get_geometry_reply_t
*wgeom
, int phys_screen
, int screen
)
393 xcb_get_property_cookie_t ewmh_icon_cookie
;
396 const uint32_t select_input_val
[] =
398 XCB_EVENT_MASK_STRUCTURE_NOTIFY
399 | XCB_EVENT_MASK_PROPERTY_CHANGE
400 | XCB_EVENT_MASK_ENTER_WINDOW
403 /* Send request to get NET_WM_ICON property as soon as possible... */
404 ewmh_icon_cookie
= ewmh_window_icon_get_unchecked(w
);
405 xcb_change_window_attributes(globalconf
.connection
, w
, XCB_CW_EVENT_MASK
, select_input_val
);
407 if(systray_iskdedockapp(w
))
409 systray_request_handle(w
, phys_screen
, NULL
);
413 c
= p_new(client_t
, 1);
415 c
->screen
= screen_getbycoord(screen
, wgeom
->x
, wgeom
->y
);
417 c
->phys_screen
= phys_screen
;
421 c
->geometry
.x
= c
->f_geometry
.x
= c
->m_geometry
.x
= wgeom
->x
;
422 c
->geometry
.y
= c
->f_geometry
.y
= c
->m_geometry
.y
= wgeom
->y
;
423 c
->geometry
.width
= c
->f_geometry
.width
= c
->m_geometry
.width
= wgeom
->width
;
424 c
->geometry
.height
= c
->f_geometry
.height
= c
->m_geometry
.height
= wgeom
->height
;
425 client_setborder(c
, wgeom
->border_width
);
426 if((icon
= ewmh_window_icon_get_reply(ewmh_icon_cookie
)))
427 c
->icon
= image_ref(&icon
);
429 /* we honor size hints by default */
430 c
->honorsizehints
= true;
433 property_update_wm_normal_hints(c
, NULL
);
434 property_update_wm_hints(c
, NULL
);
435 property_update_wm_transient_for(c
, NULL
);
438 screen
= c
->transient_for
->screen
;
440 /* Try to load props if any */
441 client_loadprops(c
, &globalconf
.screens
[screen
]);
444 /* Then check clients hints */
445 ewmh_client_check_hints(c
);
447 /* move client to screen, but do not tag it for now */
448 screen_client_moveto(c
, screen
, false, true);
450 /* Check if client has been tagged by loading props, or maybe with its
452 * If not, we tag it with current selected ones.
453 * This could be done on Lua side, but it's a sane behaviour. */
457 tag_array_t
*tags
= &globalconf
.screens
[screen
].tags
;
458 for(i
= 0; i
< tags
->len
; i
++)
459 if(is_client_tagged(c
, tags
->tab
[i
]))
462 /* if no tag, set current selected */
464 for(i
= 0; i
< tags
->len
; i
++)
465 if(tags
->tab
[i
]->selected
)
466 tag_client(c
, tags
->tab
[i
]);
469 /* Push client in client list */
470 client_list_push(&globalconf
.clients
, client_ref(&c
));
472 /* Push client in stack */
475 /* update window title */
476 property_update_wm_name(c
);
477 property_update_wm_icon_name(c
);
480 ewmh_client_strut_update(c
, NULL
);
482 ewmh_update_net_client_list(c
->phys_screen
);
484 /* Call hook to notify list change */
485 luaA_dofunction(globalconf
.L
, globalconf
.hooks
.clients
, 0, 0);
488 luaA_client_userdata_new(globalconf
.L
, c
);
489 luaA_dofunction(globalconf
.L
, globalconf
.hooks
.manage
, 1, 0);
492 /** Compute client geometry with respect to its geometry hints.
493 * \param c The client.
494 * \param geometry The geometry that the client might receive.
495 * \return The geometry the client must take respecting its hints.
498 client_geometry_hints(client_t
*c
, area_t geometry
)
500 double dx
, dy
, max
, min
, ratio
;
502 if(c
->minay
> 0 && c
->maxay
> 0 && (geometry
.height
- c
->baseh
) > 0
503 && (geometry
.width
- c
->basew
) > 0)
505 dx
= (double) (geometry
.width
- c
->basew
);
506 dy
= (double) (geometry
.height
- c
->baseh
);
507 min
= (double) (c
->minax
) / (double) (c
->minay
);
508 max
= (double) (c
->maxax
) / (double) (c
->maxay
);
510 if(max
> 0 && min
> 0 && ratio
> 0)
514 dy
= (dx
* min
+ dy
) / (min
* min
+ 1);
516 geometry
.width
= (int) dx
+ c
->basew
;
517 geometry
.height
= (int) dy
+ c
->baseh
;
521 dy
= (dx
* min
+ dy
) / (max
* max
+ 1);
523 geometry
.width
= (int) dx
+ c
->basew
;
524 geometry
.height
= (int) dy
+ c
->baseh
;
528 if(c
->minw
&& geometry
.width
< c
->minw
)
529 geometry
.width
= c
->minw
;
530 if(c
->minh
&& geometry
.height
< c
->minh
)
531 geometry
.height
= c
->minh
;
532 if(c
->maxw
&& geometry
.width
> c
->maxw
)
533 geometry
.width
= c
->maxw
;
534 if(c
->maxh
&& geometry
.height
> c
->maxh
)
535 geometry
.height
= c
->maxh
;
537 geometry
.width
-= (geometry
.width
- c
->basew
) % c
->incw
;
539 geometry
.height
-= (geometry
.height
- c
->baseh
) % c
->inch
;
544 /** Resize client window.
545 * \param c Client to resize.
546 * \param geometry New window geometry.
547 * \param hints Use size hints.
550 client_resize(client_t
*c
, area_t geometry
, bool hints
)
554 layout_t
*layout
= layout_get_current(c
->screen
);
556 if(c
->titlebar
&& !c
->ismoving
&& !client_isfloating(c
) && layout
!= layout_floating
)
557 geometry
= titlebar_geometry_remove(c
->titlebar
, c
->border
, geometry
);
560 geometry
= client_geometry_hints(c
, geometry
);
562 if(geometry
.width
<= 0 || geometry
.height
<= 0)
565 /* offscreen appearance fixes */
566 area
= display_area_get(c
->phys_screen
, NULL
,
567 &globalconf
.screens
[c
->screen
].padding
);
569 if(geometry
.x
> area
.width
)
570 geometry
.x
= area
.width
- geometry
.width
- 2 * c
->border
;
571 if(geometry
.y
> area
.height
)
572 geometry
.y
= area
.height
- geometry
.height
- 2 * c
->border
;
573 if(geometry
.x
+ geometry
.width
+ 2 * c
->border
< 0)
575 if(geometry
.y
+ geometry
.height
+ 2 * c
->border
< 0)
578 if(c
->geometry
.x
!= geometry
.x
579 || c
->geometry
.y
!= geometry
.y
580 || c
->geometry
.width
!= geometry
.width
581 || c
->geometry
.height
!= geometry
.height
)
583 new_screen
= screen_getbycoord(c
->screen
, geometry
.x
, geometry
.y
);
585 /* Values to configure a window is an array where values are
586 * stored according to 'value_mask' */
589 c
->geometry
.x
= values
[0] = geometry
.x
;
590 c
->geometry
.y
= values
[1] = geometry
.y
;
591 c
->geometry
.width
= values
[2] = geometry
.width
;
592 c
->geometry
.height
= values
[3] = geometry
.height
;
594 /* save the floating geometry if the window is floating but not
596 if(c
->ismoving
|| client_isfloating(c
)
597 || layout_get_current(new_screen
) == layout_floating
598 || layout_get_current(c
->screen
) == layout_floating
)
600 c
->f_geometry
= geometry
;
602 titlebar_update_geometry_floating(c
);
604 xcb_configure_window(globalconf
.connection
, c
->win
,
605 XCB_CONFIG_WINDOW_X
| XCB_CONFIG_WINDOW_Y
606 | XCB_CONFIG_WINDOW_WIDTH
| XCB_CONFIG_WINDOW_HEIGHT
,
608 window_configure(c
->win
, geometry
, c
->border
);
610 if(c
->screen
!= new_screen
)
611 screen_client_moveto(c
, new_screen
, true, false);
614 hooks_property(c
, "geometry");
618 /** Set a clinet floating.
619 * \param c The client.
620 * \param floating Set floating, or not.
621 * \param layer Layer to put the floating window onto.
624 client_setfloating(client_t
*c
, bool floating
)
626 if(c
->isfloating
!= floating
627 && (c
->type
== WINDOW_TYPE_NORMAL
))
629 if((c
->isfloating
= floating
))
631 client_resize(c
, c
->f_geometry
, false);
632 client_need_arrange(c
);
634 xcb_change_property(globalconf
.connection
,
635 XCB_PROP_MODE_REPLACE
,
636 c
->win
, _AWESOME_FLOATING
, CARDINAL
, 8, 1,
639 hooks_property(c
, "floating");
643 /** Set a client minimized, or not.
644 * \param c The client.
645 * \param s Set or not the client minimized.
648 client_setminimized(client_t
*c
, bool s
)
650 if(c
->isminimized
!= s
)
652 client_need_arrange(c
);
654 client_need_arrange(c
);
655 ewmh_client_update_hints(c
);
657 hooks_property(c
, "minimized");
661 /** Set a client sticky, or not.
662 * \param c The client.
663 * \param s Set or not the client sticky.
666 client_setsticky(client_t
*c
, bool s
)
670 client_need_arrange(c
);
672 client_need_arrange(c
);
673 ewmh_client_update_hints(c
);
674 hooks_property(c
, "sticky");
678 /** Set a client fullscreen, or not.
679 * \param c The client.
680 * \param s Set or not the client fullscreen.
683 client_setfullscreen(client_t
*c
, bool s
)
685 if(c
->isfullscreen
!= s
)
689 /* become fullscreen! */
690 if((c
->isfullscreen
= s
))
692 geometry
= screen_area_get(c
->screen
, NULL
, NULL
, false);
693 c
->m_geometry
= c
->geometry
;
694 c
->oldborder
= c
->border
;
695 client_setborder(c
, 0);
699 geometry
= c
->m_geometry
;
700 client_setborder(c
, c
->oldborder
);
701 client_resize(c
, c
->m_geometry
, false);
703 client_resize(c
, geometry
, false);
704 client_need_arrange(c
);
706 xcb_change_property(globalconf
.connection
,
707 XCB_PROP_MODE_REPLACE
,
708 c
->win
, _AWESOME_FULLSCREEN
, CARDINAL
, 8, 1,
710 ewmh_client_update_hints(c
);
711 hooks_property(c
, "fullscreen");
715 /** Set a client above, or not.
716 * \param c The client.
717 * \param s Set or not the client above.
720 client_setabove(client_t
*c
, bool s
)
726 ewmh_client_update_hints(c
);
728 hooks_property(c
, "above");
732 /** Set a client below, or not.
733 * \param c The client.
734 * \param s Set or not the client below.
737 client_setbelow(client_t
*c
, bool s
)
743 ewmh_client_update_hints(c
);
745 hooks_property(c
, "below");
749 /** Set a client modal, or not.
750 * \param c The client.
751 * \param s Set or not the client moda.
754 client_setmodal(client_t
*c
, bool s
)
760 ewmh_client_update_hints(c
);
762 hooks_property(c
, "modal");
766 /** Set a client ontop, or not.
767 * \param c The client.
768 * \param s Set or not the client moda.
771 client_setontop(client_t
*c
, bool s
)
778 hooks_property(c
, "ontop");
782 /** Save client properties as an X property.
783 * \param c The client.
786 client_saveprops_tags(client_t
*c
)
788 tag_array_t
*tags
= &globalconf
.screens
[c
->screen
].tags
;
789 unsigned char *prop
= p_alloca(unsigned char, tags
->len
+ 1);
792 for(i
= 0; i
< tags
->len
; i
++)
793 prop
[i
] = is_client_tagged(c
, tags
->tab
[i
]) ? '1' : '0';
795 xcb_change_property(globalconf
.connection
, XCB_PROP_MODE_REPLACE
, c
->win
, _AWESOME_TAGS
, STRING
, 8, i
, prop
);
799 * \param c The client.
802 client_unban(client_t
*c
)
804 xcb_map_window(globalconf
.connection
, c
->win
);
805 window_state_set(c
->win
, XCB_WM_STATE_NORMAL
);
808 if(c
->isfullscreen
|| !c
->titlebar
->isvisible
)
809 xcb_unmap_window(globalconf
.connection
, c
->titlebar
->sw
.window
);
811 xcb_map_window(globalconf
.connection
, c
->titlebar
->sw
.window
);
815 /** Unmanage a client.
816 * \param c The client.
819 client_unmanage(client_t
*c
)
821 tag_array_t
*tags
= &globalconf
.screens
[c
->screen
].tags
;
823 if(globalconf
.screens
[c
->phys_screen
].client_focus
== c
)
826 /* remove client everywhere */
827 client_list_detach(&globalconf
.clients
, c
);
828 stack_client_delete(c
);
829 for(int i
= 0; i
< tags
->len
; i
++)
830 untag_client(c
, tags
->tab
[i
]);
833 luaA_client_userdata_new(globalconf
.L
, c
);
834 luaA_dofunction(globalconf
.L
, globalconf
.hooks
.unmanage
, 1, 0);
836 /* Call hook to notify list change */
837 luaA_dofunction(globalconf
.L
, globalconf
.hooks
.clients
, 0, 0);
839 /* The server grab construct avoids race conditions. */
840 xcb_grab_server(globalconf
.connection
);
842 xcb_configure_window(globalconf
.connection
, c
->win
,
843 XCB_CONFIG_WINDOW_BORDER_WIDTH
,
844 (uint32_t *) &c
->oldborder
);
846 xcb_ungrab_button(globalconf
.connection
, XCB_BUTTON_INDEX_ANY
, c
->win
,
847 XCB_BUTTON_MASK_ANY
);
848 window_state_set(c
->win
, XCB_WM_STATE_WITHDRAWN
);
850 xcb_flush(globalconf
.connection
);
851 xcb_ungrab_server(globalconf
.connection
);
853 titlebar_client_detach(c
);
855 ewmh_update_net_client_list(c
->phys_screen
);
857 /* delete properties */
858 xcb_delete_property(globalconf
.connection
, c
->win
, _AWESOME_TAGS
);
859 xcb_delete_property(globalconf
.connection
, c
->win
, _AWESOME_FLOATING
);
861 if(client_hasstrut(c
))
862 /* All the wiboxes (may) need to be repositioned */
863 for(int screen
= 0; screen
< globalconf
.nscreen
; screen
++)
864 for(int i
= 0; i
< globalconf
.screens
[screen
].wiboxes
.len
; i
++)
866 wibox_t
*s
= globalconf
.screens
[screen
].wiboxes
.tab
[i
];
867 wibox_position_update(s
);
870 /* set client as invalid */
876 /** Kill a client via a WM_DELETE_WINDOW request or KillClient if not
878 * \param c The client to kill.
881 client_kill(client_t
*c
)
883 if(window_hasproto(c
->win
, WM_DELETE_WINDOW
))
885 xcb_client_message_event_t ev
;
887 /* Initialize all of event's fields first */
890 ev
.response_type
= XCB_CLIENT_MESSAGE
;
893 ev
.data
.data32
[1] = XCB_CURRENT_TIME
;
894 ev
.type
= WM_PROTOCOLS
;
895 ev
.data
.data32
[0] = WM_DELETE_WINDOW
;
897 xcb_send_event(globalconf
.connection
, false, c
->win
,
898 XCB_EVENT_MASK_NO_EVENT
, (char *) &ev
);
901 xcb_kill_client(globalconf
.connection
, c
->win
);
904 /** Get all clients into a table.
905 * \param L The Lua VM state.
906 * \return The number of elements pushed on stack.
908 * \lparam An optional screen nunmber.
909 * \lreturn A table with all clients.
912 luaA_client_get(lua_State
*L
)
917 screen
= luaL_optnumber(L
, 1, 0) - 1;
921 if(screen
== SCREEN_UNDEF
)
922 for(c
= globalconf
.clients
; c
; c
= c
->next
)
924 luaA_client_userdata_new(globalconf
.L
, c
);
925 lua_rawseti(L
, -2, i
++);
929 luaA_checkscreen(screen
);
930 for(c
= globalconf
.clients
; c
; c
= c
->next
)
931 if(c
->screen
== screen
)
933 luaA_client_userdata_new(globalconf
.L
, c
);
934 lua_rawseti(L
, -2, i
++);
941 /** Get only visible clients for a screen (DEPRECATED).
942 * \param L The Lua VM state.
943 * \return The number of elements pushed on stack.
945 * \lparam A screen number.
946 * \lreturn A table with all visible clients for this screen.
949 luaA_client_visible_get(lua_State
*L
)
953 int screen
= luaL_checknumber(L
, 1) - 1;
955 luaA_checkscreen(screen
);
957 deprecate(L
, "awful.client.visible()");
961 for(c
= globalconf
.clients
; c
; c
= c
->next
)
962 if(client_isvisible(c
, screen
))
964 luaA_client_userdata_new(L
, c
);
965 lua_rawseti(L
, -2, i
++);
971 /** Check if a client is visible on its screen.
972 * \param L The Lua VM state.
973 * \return The number of elements pushed on stack.
976 * \lreturn A boolean value, true if the client is visible, false otherwise.
979 luaA_client_isvisible(lua_State
*L
)
981 client_t
**c
= luaA_checkudata(L
, 1, "client");
982 lua_pushboolean(L
, client_isvisible(*c
, (*c
)->screen
));
986 /** Set client border width.
987 * \param c The client.
988 * \param width The border width.
991 client_setborder(client_t
*c
, int width
)
995 if(width
> 0 && (c
->type
== WINDOW_TYPE_DOCK
996 || c
->type
== WINDOW_TYPE_SPLASH
997 || c
->type
== WINDOW_TYPE_DESKTOP
1001 if(width
== c
->border
|| width
< 0)
1005 xcb_configure_window(globalconf
.connection
, c
->win
,
1006 XCB_CONFIG_WINDOW_BORDER_WIDTH
, &w
);
1008 if(client_isvisible(c
, c
->screen
))
1010 if(client_isfloating(c
) || layout_get_current(c
->screen
) == layout_floating
)
1011 titlebar_update_geometry_floating(c
);
1013 globalconf
.screens
[c
->screen
].need_arrange
= true;
1016 hooks_property(c
, "border_width");
1020 * \param L The Lua VM state.
1026 luaA_client_kill(lua_State
*L
)
1028 client_t
**c
= luaA_checkudata(L
, 1, "client");
1033 /** Swap a client with another one.
1034 * \param L The Lua VM state.
1037 * \lparam A client to swap with.
1040 luaA_client_swap(lua_State
*L
)
1042 client_t
**c
= luaA_checkudata(L
, 1, "client");
1043 client_t
**swap
= luaA_checkudata(L
, 2, "client");
1044 client_list_swap(&globalconf
.clients
, *swap
, *c
);
1045 client_need_arrange(*c
);
1046 client_need_arrange(*swap
);
1048 /* Call hook to notify list change */
1049 luaA_dofunction(L
, globalconf
.hooks
.clients
, 0, 0);
1054 /** Access or set the client tags.
1055 * \param L The Lua VM state.
1056 * \return The number of elements pushed on stack.
1057 * \lparam A table with tags to set, or none to get the current tags table.
1058 * \return The clients tag.
1061 luaA_client_tags(lua_State
*L
)
1065 client_t
**c
= luaA_checkudata(L
, 1, "client");
1068 if(lua_gettop(L
) == 2)
1070 luaA_checktable(L
, 2);
1071 tags
= &globalconf
.screens
[(*c
)->screen
].tags
;
1072 for(int i
= 0; i
< tags
->len
; i
++)
1073 untag_client(*c
, tags
->tab
[i
]);
1075 while(lua_next(L
, 2))
1077 tag
= luaA_checkudata(L
, -1, "tag");
1078 tag_client(*c
, *tag
);
1084 tags
= &globalconf
.screens
[(*c
)->screen
].tags
;
1086 for(int i
= 0; i
< tags
->len
; i
++)
1087 if(is_client_tagged(*c
, tags
->tab
[i
]))
1089 luaA_tag_userdata_new(L
, tags
->tab
[i
]);
1090 lua_rawseti(L
, -2, ++j
);
1096 /** Raise a client on top of others which are on the same layer.
1097 * \param L The Lua VM state.
1102 luaA_client_raise(lua_State
*L
)
1104 client_t
**c
= luaA_checkudata(L
, 1, "client");
1109 /** Lower a client on bottom of others which are on the same layer.
1110 * \param L The Lua VM state.
1115 luaA_client_lower(lua_State
*L
)
1117 client_t
**c
= luaA_checkudata(L
, 1, "client");
1122 /** Redraw a client by unmapping and mapping it quickly.
1123 * \param L The Lua VM state.
1129 luaA_client_redraw(lua_State
*L
)
1131 client_t
**c
= luaA_checkudata(L
, 1, "client");
1133 xcb_unmap_window(globalconf
.connection
, (*c
)->win
);
1134 xcb_map_window(globalconf
.connection
, (*c
)->win
);
1136 /* Set the focus on the current window if the redraw has been
1137 performed on the window where the pointer is currently on
1138 because after the unmapping/mapping, the focus is lost */
1139 if(globalconf
.screen_focus
->client_focus
== *c
)
1140 xcb_set_input_focus(globalconf
.connection
, XCB_INPUT_FOCUS_POINTER_ROOT
,
1141 (*c
)->win
, XCB_CURRENT_TIME
);
1146 /** Stop managing a client.
1147 * \param L The Lua VM state.
1148 * \return The number of elements pushed on stack.
1153 luaA_client_unmanage(lua_State
*L
)
1155 client_t
**c
= luaA_checkudata(L
, 1, "client");
1156 client_unmanage(*c
);
1160 /** Return client geometry.
1161 * \param L The Lua VM state.
1162 * \param full Use titlebar also.
1163 * \return The number of elements pushed on stack.
1166 luaA_client_handlegeom(lua_State
*L
, bool full
)
1168 client_t
**c
= luaA_checkudata(L
, 1, "client");
1170 if(lua_gettop(L
) == 2)
1171 if(client_isfloating(*c
)
1172 || layout_get_current((*c
)->screen
) == layout_floating
)
1176 luaA_checktable(L
, 2);
1177 geometry
.x
= luaA_getopt_number(L
, 2, "x", (*c
)->geometry
.x
);
1178 geometry
.y
= luaA_getopt_number(L
, 2, "y", (*c
)->geometry
.y
);
1179 if(client_isfixed(*c
))
1181 geometry
.width
= (*c
)->geometry
.width
;
1182 geometry
.height
= (*c
)->geometry
.height
;
1186 geometry
.width
= luaA_getopt_number(L
, 2, "width", (*c
)->geometry
.width
);
1187 geometry
.height
= luaA_getopt_number(L
, 2, "height", (*c
)->geometry
.height
);
1190 geometry
= titlebar_geometry_remove((*c
)->titlebar
,
1193 client_resize(*c
, geometry
, false);
1197 return luaA_pusharea(L
, titlebar_geometry_add((*c
)->titlebar
,
1201 return luaA_pusharea(L
, (*c
)->geometry
);
1204 /** Return client geometry.
1205 * \param L The Lua VM state.
1206 * \return The number of elements pushed on stack.
1208 * \lparam A table with new coordinates, or none.
1209 * \lreturn A table with client coordinates.
1212 luaA_client_geometry(lua_State
*L
)
1214 return luaA_client_handlegeom(L
, false);
1218 luaA_client_coords(lua_State
*L
)
1220 deprecate(L
, "client:geometry()");
1221 return luaA_client_geometry(L
);
1224 /** Return client geometry, using also titlebar and border width.
1225 * \param L The Lua VM state.
1226 * \return The number of elements pushed on stack.
1228 * \lparam A table with new coordinates, or none.
1229 * \lreturn A table with client coordinates.
1232 luaA_client_fullgeometry(lua_State
*L
)
1234 return luaA_client_handlegeom(L
, true);
1238 luaA_client_fullcoords(lua_State
*L
)
1240 deprecate(L
, "client:fullgeometry()");
1241 return luaA_client_fullgeometry(L
);
1244 /** Client newindex.
1245 * \param L The Lua VM state.
1246 * \return The number of elements pushed on stack.
1249 luaA_client_newindex(lua_State
*L
)
1252 client_t
**c
= luaA_checkudata(L
, 1, "client");
1253 const char *buf
= luaL_checklstring(L
, 2, &len
);
1261 luaL_error(L
, "client is invalid\n");
1263 switch(a_tokenize(buf
, len
))
1266 if(globalconf
.xinerama_is_active
)
1268 i
= luaL_checknumber(L
, 3) - 1;
1269 luaA_checkscreen(i
);
1270 if(i
!= (*c
)->screen
)
1271 screen_client_moveto(*c
, i
, true, true);
1275 b
= luaA_checkboolean(L
, 3);
1276 if(b
!= (*c
)->ishidden
)
1278 client_need_arrange(*c
);
1280 client_need_arrange(*c
);
1284 client_setminimized(*c
, luaA_checkboolean(L
, 3));
1286 case A_TK_FULLSCREEN
:
1287 client_setfullscreen(*c
, luaA_checkboolean(L
, 3));
1290 image
= luaA_checkudata(L
, 3, "image");
1291 image_unref(&(*c
)->icon
);
1293 (*c
)->icon
= *image
;
1295 hooks_property(*c
, "icon");
1299 window_opacity_set((*c
)->win
, -1);
1302 d
= luaL_checknumber(L
, 3);
1303 if(d
>= 0 && d
<= 1)
1304 window_opacity_set((*c
)->win
, d
);
1308 client_setfloating(*c
, luaA_checkboolean(L
, 3));
1311 client_setsticky(*c
, luaA_checkboolean(L
, 3));
1313 case A_TK_HONORSIZEHINTS
:
1314 (*c
)->honorsizehints
= luaA_checkboolean(L
, 3);
1315 client_need_arrange(*c
);
1317 case A_TK_BORDER_WIDTH
:
1318 client_setborder(*c
, luaL_checknumber(L
, 3));
1321 client_setontop(*c
, luaA_checkboolean(L
, 3));
1323 case A_TK_BORDER_COLOR
:
1324 if((buf
= luaL_checklstring(L
, 3, &len
))
1325 && xcolor_init_reply(xcolor_init_unchecked(&(*c
)->border_color
, buf
, len
)))
1326 xcb_change_window_attributes(globalconf
.connection
, (*c
)->win
,
1327 XCB_CW_BORDER_PIXEL
, &(*c
)->border_color
.pixel
);
1331 titlebar_client_detach(*c
);
1334 t
= luaA_checkudata(L
, 3, "wibox");
1335 titlebar_client_attach(*c
, *t
);
1346 * \param L The Lua VM state.
1347 * \return The number of elements pushed on stack.
1349 * \lfield name The client title.
1350 * \lfield skip_taskbar True if the client does not want to be in taskbar.
1351 * \lfield type The window type (desktop, normal, dock, …).
1352 * \lfield class The client class.
1353 * \lfield instance The client instance.
1354 * \lfield pid The client PID, if available.
1355 * \lfield role The window role, if available.
1356 * \lfield machine The machine client is running on.
1357 * \lfield icon_name The client name when iconified.
1358 * \lfield screen Client screen number.
1359 * \lfield hide Define if the client must be hidden, i.e. never mapped,
1360 * invisible in taskbar.
1361 * \lfield minimize Define it the client must be iconify, i.e. only visible in
1363 * \lfield icon_path Path to the icon used to identify.
1364 * \lfield floating True always floating.
1365 * \lfield honorsizehints Honor size hints, i.e. respect size ratio.
1366 * \lfield border_width The client border width.
1367 * \lfield border_color The client border color.
1368 * \lfield titlebar The client titlebar.
1369 * \lfield urgent The client urgent state.
1370 * \lfield focus The focused client.
1371 * \lfield opacity The client opacity between 0 and 1.
1372 * \lfield ontop The client is on top of every other windows.
1373 * \lfield fullscreen The client is fullscreen or not.
1374 * \lfield transient_for Return the client the window is transient for.
1375 * \lfield size_hints A table with size hints of the client: user_position,
1376 * user_size, program_position and program_size.
1379 luaA_client_index(lua_State
*L
)
1383 client_t
**c
= luaA_checkudata(L
, 1, "client");
1384 const char *buf
= luaL_checklstring(L
, 2, &len
);
1387 xcb_get_wm_class_reply_t hint
;
1388 xcb_get_property_cookie_t prop_c
;
1389 xcb_get_property_reply_t
*prop_r
= NULL
;
1393 luaL_error(L
, "client is invalid\n");
1395 if(luaA_usemetatable(L
, 1, 2))
1398 switch(a_tokenize(buf
, len
))
1401 lua_pushstring(L
, (*c
)->name
);
1403 case A_TK_TRANSIENT_FOR
:
1404 if((*c
)->transient_for
)
1405 return luaA_client_userdata_new(L
, (*c
)->transient_for
);
1406 case A_TK_SKIP_TASKBAR
:
1407 lua_pushboolean(L
, (*c
)->skiptb
);
1412 case WINDOW_TYPE_DESKTOP
:
1413 lua_pushliteral(L
, "desktop");
1415 case WINDOW_TYPE_DOCK
:
1416 lua_pushliteral(L
, "dock");
1418 case WINDOW_TYPE_SPLASH
:
1419 lua_pushliteral(L
, "splash");
1421 case WINDOW_TYPE_DIALOG
:
1422 lua_pushliteral(L
, "dialog");
1425 lua_pushliteral(L
, "normal");
1430 if(!xcb_get_wm_class_reply(globalconf
.connection
,
1431 xcb_get_wm_class_unchecked(globalconf
.connection
, (*c
)->win
),
1434 lua_pushstring(L
, hint
.class);
1435 xcb_get_wm_class_reply_wipe(&hint
);
1438 if(!xcb_get_wm_class_reply(globalconf
.connection
,
1439 xcb_get_wm_class_unchecked(globalconf
.connection
, (*c
)->win
),
1442 lua_pushstring(L
, hint
.name
);
1443 xcb_get_wm_class_reply_wipe(&hint
);
1446 if(!xutil_text_prop_get(globalconf
.connection
, (*c
)->win
,
1447 WM_WINDOW_ROLE
, &value
, &slen
))
1449 lua_pushlstring(L
, value
, slen
);
1453 prop_c
= xcb_get_property_unchecked(globalconf
.connection
, false, (*c
)->win
, _NET_WM_PID
, CARDINAL
, 0L, 1L);
1454 prop_r
= xcb_get_property_reply(globalconf
.connection
, prop_c
, NULL
);
1456 if(prop_r
&& prop_r
->value_len
&& (data
= xcb_get_property_value(prop_r
)))
1457 lua_pushnumber(L
, *(uint32_t *)data
);
1465 if(!xutil_text_prop_get(globalconf
.connection
, (*c
)->win
,
1466 WM_CLIENT_MACHINE
, &value
, &slen
))
1468 lua_pushlstring(L
, value
, slen
);
1471 case A_TK_ICON_NAME
:
1472 lua_pushstring(L
, (*c
)->icon_name
);
1475 lua_pushnumber(L
, 1 + (*c
)->screen
);
1478 lua_pushboolean(L
, (*c
)->ishidden
);
1481 lua_pushboolean(L
, (*c
)->isminimized
);
1483 case A_TK_FULLSCREEN
:
1484 lua_pushboolean(L
, (*c
)->isfullscreen
);
1488 luaA_image_userdata_new(L
, (*c
)->icon
);
1493 if((d
= window_opacity_get((*c
)->win
)) >= 0)
1494 lua_pushnumber(L
, d
);
1499 lua_pushboolean(L
, client_isfloating(*c
));
1502 lua_pushboolean(L
, (*c
)->isontop
);
1505 lua_pushboolean(L
, (*c
)->issticky
);
1507 case A_TK_HONORSIZEHINTS
:
1508 lua_pushboolean(L
, (*c
)->honorsizehints
);
1510 case A_TK_BORDER_WIDTH
:
1511 lua_pushnumber(L
, (*c
)->border
);
1513 case A_TK_BORDER_COLOR
:
1514 luaA_pushcolor(L
, &(*c
)->border_color
);
1518 return luaA_wibox_userdata_new(L
, (*c
)->titlebar
);
1521 lua_pushboolean(L
, (*c
)->isurgent
);
1523 case A_TK_SIZE_HINTS
:
1525 lua_pushboolean(L
, (*c
)->size_hints
.flags
& XCB_SIZE_HINT_US_POSITION
);
1526 lua_setfield(L
, -2, "user_position");
1527 lua_pushboolean(L
, (*c
)->size_hints
.flags
& XCB_SIZE_HINT_US_SIZE
);
1528 lua_setfield(L
, -2, "user_size");
1529 lua_pushboolean(L
, (*c
)->size_hints
.flags
& XCB_SIZE_HINT_P_POSITION
);
1530 lua_setfield(L
, -2, "program_position");
1531 lua_pushboolean(L
, (*c
)->size_hints
.flags
& XCB_SIZE_HINT_P_SIZE
);
1532 lua_setfield(L
, -2, "program_size");
1541 /** Get or set mouse buttons bindings for a client.
1542 * \param L The Lua VM state.
1543 * \return The number of element pushed on stack.
1546 * \lparam An array of mouse button bindings objects, or nothing.
1547 * \return The array of mouse button bindings objects of this client.
1550 luaA_client_buttons(lua_State
*L
)
1552 client_t
**client
= luaA_checkudata(L
, 1, "client");
1553 button_array_t
*buttons
= &(*client
)->buttons
;
1555 if(lua_gettop(L
) == 2)
1556 luaA_button_array_set(L
, 2, buttons
);
1558 return luaA_button_array_get(L
, buttons
);
1562 * \param L The Lua VM state.
1563 * \return The number of pushed elements.
1566 luaA_client_module_index(lua_State
*L
)
1569 const char *buf
= luaL_checklstring(L
, 2, &len
);
1571 switch(a_tokenize(buf
, len
))
1574 if(globalconf
.screen_focus
->client_focus
)
1575 luaA_client_userdata_new(L
, globalconf
.screen_focus
->client_focus
);
1586 /* Client module new index.
1587 * \param L The Lua VM state.
1588 * \return The number of pushed elements.
1591 luaA_client_module_newindex(lua_State
*L
)
1594 const char *buf
= luaL_checklstring(L
, 2, &len
);
1597 switch(a_tokenize(buf
, len
))
1600 c
= luaA_checkudata(L
, 3, "client");
1610 const struct luaL_reg awesome_client_methods
[] =
1612 { "get", luaA_client_get
},
1613 { "visible_get", luaA_client_visible_get
},
1614 { "__index", luaA_client_module_index
},
1615 { "__newindex", luaA_client_module_newindex
},
1618 const struct luaL_reg awesome_client_meta
[] =
1620 { "isvisible", luaA_client_isvisible
},
1621 { "geometry", luaA_client_geometry
},
1622 { "fullgeometry", luaA_client_fullgeometry
},
1623 { "buttons", luaA_client_buttons
},
1624 { "tags", luaA_client_tags
},
1625 { "kill", luaA_client_kill
},
1626 { "swap", luaA_client_swap
},
1627 { "raise", luaA_client_raise
},
1628 { "lower", luaA_client_lower
},
1629 { "redraw", luaA_client_redraw
},
1630 { "mouse_resize", luaA_client_mouse_resize
},
1631 { "mouse_move", luaA_client_mouse_move
},
1632 { "unmanage", luaA_client_unmanage
},
1633 { "__index", luaA_client_index
},
1634 { "__newindex", luaA_client_newindex
},
1635 { "__eq", luaA_client_eq
},
1636 { "__gc", luaA_client_gc
},
1637 { "__tostring", luaA_client_tostring
},
1639 { "coords", luaA_client_coords
},
1640 { "fullcoords", luaA_client_fullcoords
},
1644 // vim: filetype=c:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=80