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 mode The mode.
229 * \param previous The previous window on the stack.
230 * \param return The next-previous!
233 client_stack_position(client_t
*c
, xcb_stack_mode_t mode
, xcb_window_t previous
)
235 uint32_t config_win_vals
[2];
237 config_win_vals
[0] = previous
;
238 config_win_vals
[1] = mode
;
242 xcb_configure_window(globalconf
.connection
,
243 c
->titlebar
->sw
.window
,
244 XCB_CONFIG_WINDOW_SIBLING
| XCB_CONFIG_WINDOW_STACK_MODE
,
246 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 /** Stacking layout layers */
257 /** This one is a special layer */
269 /** Get the real layer of a client according to its attribute (fullscreen, …)
270 * \param c The client.
271 * \return The real layer.
274 client_layer_translator(client_t
*c
)
278 else if(c
->isfullscreen
)
279 return LAYER_FULLSCREEN
;
282 else if(c
->isfloating
)
284 else if(c
->transient_for
)
285 return LAYER_TRANSIENT_FOR
;
289 case WINDOW_TYPE_DOCK
:
291 case WINDOW_TYPE_DESKTOP
:
292 return LAYER_DESKTOP
;
299 * \todo It might be worth stopping to restack everyone and only stack `c'
300 * relatively to the first matching in the list.
305 uint32_t config_win_vals
[2];
306 client_node_t
*node
, *last
= *client_node_list_last(&globalconf
.stack
);
310 config_win_vals
[0] = XCB_NONE
;
311 config_win_vals
[1] = XCB_STACK_MODE_ABOVE
;
313 /* first stack not ontop wibox window */
314 for(screen
= 0; screen
< globalconf
.nscreen
; screen
++)
315 for(int i
= 0; i
< globalconf
.screens
[screen
].wiboxes
.len
; i
++)
317 wibox_t
*sb
= globalconf
.screens
[screen
].wiboxes
.tab
[i
];
320 xcb_configure_window(globalconf
.connection
,
322 XCB_CONFIG_WINDOW_SIBLING
| XCB_CONFIG_WINDOW_STACK_MODE
,
324 config_win_vals
[0] = sb
->sw
.window
;
328 /* stack bottom layers */
329 for(layer
= LAYER_DESKTOP
; layer
< LAYER_FULLSCREEN
; layer
++)
330 for(node
= last
; node
; node
= node
->prev
)
331 if(client_layer_translator(node
->client
) == layer
)
332 config_win_vals
[0] = client_stack_position(node
->client
,
333 XCB_STACK_MODE_ABOVE
,
336 /* then stack ontop wibox window */
337 for(screen
= 0; screen
< globalconf
.nscreen
; screen
++)
338 for(int i
= 0; i
< globalconf
.screens
[screen
].wiboxes
.len
; i
++)
340 wibox_t
*sb
= globalconf
.screens
[screen
].wiboxes
.tab
[i
];
343 xcb_configure_window(globalconf
.connection
,
345 XCB_CONFIG_WINDOW_SIBLING
| XCB_CONFIG_WINDOW_STACK_MODE
,
347 config_win_vals
[0] = sb
->sw
.window
;
351 /* finally stack ontop and fullscreen windows */
352 for(layer
= LAYER_FULLSCREEN
; layer
< LAYER_OUTOFSPACE
; layer
++)
353 for(node
= last
; node
; node
= node
->prev
)
354 if(client_layer_translator(node
->client
) == layer
)
355 config_win_vals
[0] = client_stack_position(node
->client
,
356 XCB_STACK_MODE_ABOVE
,
359 /* stack transient window on top of their parents */
360 for(node
= last
; node
; node
= node
->prev
)
361 if(client_layer_translator(node
->client
) == LAYER_TRANSIENT_FOR
)
362 client_stack_position(node
->client
,
363 XCB_STACK_MODE_ABOVE
,
364 node
->client
->transient_for
->win
);
368 /** Manage a new client.
369 * \param w The window.
370 * \param wgeom Window geometry.
371 * \param phys_screen Physical screen number.
372 * \param screen Virtual screen number where to manage client.
375 client_manage(xcb_window_t w
, xcb_get_geometry_reply_t
*wgeom
, int phys_screen
, int screen
)
377 xcb_get_property_cookie_t ewmh_icon_cookie
;
380 const uint32_t select_input_val
[] =
382 XCB_EVENT_MASK_STRUCTURE_NOTIFY
383 | XCB_EVENT_MASK_PROPERTY_CHANGE
384 | XCB_EVENT_MASK_ENTER_WINDOW
387 /* Send request to get NET_WM_ICON property as soon as possible... */
388 ewmh_icon_cookie
= ewmh_window_icon_get_unchecked(w
);
389 xcb_change_window_attributes(globalconf
.connection
, w
, XCB_CW_EVENT_MASK
, select_input_val
);
391 if(systray_iskdedockapp(w
))
393 systray_request_handle(w
, phys_screen
, NULL
);
397 c
= p_new(client_t
, 1);
399 c
->screen
= screen_getbycoord(screen
, wgeom
->x
, wgeom
->y
);
401 c
->phys_screen
= phys_screen
;
405 c
->geometry
.x
= c
->f_geometry
.x
= c
->m_geometry
.x
= wgeom
->x
;
406 c
->geometry
.y
= c
->f_geometry
.y
= c
->m_geometry
.y
= wgeom
->y
;
407 c
->geometry
.width
= c
->f_geometry
.width
= c
->m_geometry
.width
= wgeom
->width
;
408 c
->geometry
.height
= c
->f_geometry
.height
= c
->m_geometry
.height
= wgeom
->height
;
409 client_setborder(c
, wgeom
->border_width
);
410 if((icon
= ewmh_window_icon_get_reply(ewmh_icon_cookie
)))
411 c
->icon
= image_ref(&icon
);
413 /* we honor size hints by default */
414 c
->honorsizehints
= true;
417 property_update_wm_normal_hints(c
, NULL
);
418 property_update_wm_hints(c
, NULL
);
419 property_update_wm_transient_for(c
, NULL
);
422 screen
= c
->transient_for
->screen
;
424 /* Try to load props if any */
425 client_loadprops(c
, &globalconf
.screens
[screen
]);
428 /* Then check clients hints */
429 ewmh_client_check_hints(c
);
431 /* move client to screen, but do not tag it for now */
432 screen_client_moveto(c
, screen
, false, true);
434 /* Check if client has been tagged by loading props, or maybe with its
436 * If not, we tag it with current selected ones.
437 * This could be done on Lua side, but it's a sane behaviour. */
441 tag_array_t
*tags
= &globalconf
.screens
[screen
].tags
;
442 for(i
= 0; i
< tags
->len
; i
++)
443 if(is_client_tagged(c
, tags
->tab
[i
]))
446 /* if no tag, set current selected */
448 for(i
= 0; i
< tags
->len
; i
++)
449 if(tags
->tab
[i
]->selected
)
450 tag_client(c
, tags
->tab
[i
]);
453 /* Push client in client list */
454 client_list_push(&globalconf
.clients
, client_ref(&c
));
456 /* Push client in stack */
459 /* update window title */
460 property_update_wm_name(c
);
461 property_update_wm_icon_name(c
);
464 ewmh_client_strut_update(c
, NULL
);
466 ewmh_update_net_client_list(c
->phys_screen
);
468 /* Call hook to notify list change */
469 luaA_dofunction(globalconf
.L
, globalconf
.hooks
.clients
, 0, 0);
472 luaA_client_userdata_new(globalconf
.L
, c
);
473 luaA_dofunction(globalconf
.L
, globalconf
.hooks
.manage
, 1, 0);
476 /** Compute client geometry with respect to its geometry hints.
477 * \param c The client.
478 * \param geometry The geometry that the client might receive.
479 * \return The geometry the client must take respecting its hints.
482 client_geometry_hints(client_t
*c
, area_t geometry
)
484 double dx
, dy
, max
, min
, ratio
;
486 if(c
->minay
> 0 && c
->maxay
> 0 && (geometry
.height
- c
->baseh
) > 0
487 && (geometry
.width
- c
->basew
) > 0)
489 dx
= (double) (geometry
.width
- c
->basew
);
490 dy
= (double) (geometry
.height
- c
->baseh
);
491 min
= (double) (c
->minax
) / (double) (c
->minay
);
492 max
= (double) (c
->maxax
) / (double) (c
->maxay
);
494 if(max
> 0 && min
> 0 && ratio
> 0)
498 dy
= (dx
* min
+ dy
) / (min
* min
+ 1);
500 geometry
.width
= (int) dx
+ c
->basew
;
501 geometry
.height
= (int) dy
+ c
->baseh
;
505 dy
= (dx
* min
+ dy
) / (max
* max
+ 1);
507 geometry
.width
= (int) dx
+ c
->basew
;
508 geometry
.height
= (int) dy
+ c
->baseh
;
512 if(c
->minw
&& geometry
.width
< c
->minw
)
513 geometry
.width
= c
->minw
;
514 if(c
->minh
&& geometry
.height
< c
->minh
)
515 geometry
.height
= c
->minh
;
516 if(c
->maxw
&& geometry
.width
> c
->maxw
)
517 geometry
.width
= c
->maxw
;
518 if(c
->maxh
&& geometry
.height
> c
->maxh
)
519 geometry
.height
= c
->maxh
;
521 geometry
.width
-= (geometry
.width
- c
->basew
) % c
->incw
;
523 geometry
.height
-= (geometry
.height
- c
->baseh
) % c
->inch
;
528 /** Resize client window.
529 * \param c Client to resize.
530 * \param geometry New window geometry.
531 * \param hints Use size hints.
534 client_resize(client_t
*c
, area_t geometry
, bool hints
)
538 layout_t
*layout
= layout_get_current(c
->screen
);
540 /* Values to configure a window is an array where values are
541 * stored according to 'value_mask' */
544 if(c
->titlebar
&& !c
->ismoving
&& !client_isfloating(c
) && layout
!= layout_floating
)
545 geometry
= titlebar_geometry_remove(c
->titlebar
, c
->border
, geometry
);
548 geometry
= client_geometry_hints(c
, geometry
);
550 if(geometry
.width
<= 0 || geometry
.height
<= 0)
553 /* offscreen appearance fixes */
554 area
= display_area_get(c
->phys_screen
, NULL
,
555 &globalconf
.screens
[c
->screen
].padding
);
557 fixed
= client_isfixed(c
);
559 if(geometry
.x
> area
.width
)
560 geometry
.x
= area
.width
- geometry
.width
- 2 * c
->border
;
561 if(geometry
.y
> area
.height
)
562 geometry
.y
= area
.height
- geometry
.height
- 2 * c
->border
;
563 if(geometry
.x
+ geometry
.width
+ 2 * c
->border
< 0)
565 if(geometry
.y
+ geometry
.height
+ 2 * c
->border
< 0)
568 /* fixed windows can only change their x,y */
569 if((fixed
&& (c
->geometry
.x
!= geometry
.x
|| c
->geometry
.y
!= geometry
.y
))
570 || (!fixed
&& (c
->geometry
.x
!= geometry
.x
571 || c
->geometry
.y
!= geometry
.y
572 || c
->geometry
.width
!= geometry
.width
573 || c
->geometry
.height
!= geometry
.height
)))
575 new_screen
= screen_getbycoord(c
->screen
, geometry
.x
, geometry
.y
);
577 c
->geometry
.x
= values
[0] = geometry
.x
;
578 c
->geometry
.width
= values
[2] = geometry
.width
;
579 c
->geometry
.y
= values
[1] = geometry
.y
;
580 c
->geometry
.height
= values
[3] = geometry
.height
;
581 values
[4] = c
->border
;
583 /* save the floating geometry if the window is floating but not
585 if(c
->ismoving
|| client_isfloating(c
)
586 || layout_get_current(new_screen
) == layout_floating
)
588 c
->f_geometry
= geometry
;
590 titlebar_update_geometry_floating(c
);
592 xcb_configure_window(globalconf
.connection
, c
->win
,
593 XCB_CONFIG_WINDOW_X
| XCB_CONFIG_WINDOW_Y
|
594 XCB_CONFIG_WINDOW_WIDTH
| XCB_CONFIG_WINDOW_HEIGHT
|
595 XCB_CONFIG_WINDOW_BORDER_WIDTH
,
597 window_configure(c
->win
, geometry
, c
->border
);
599 if(c
->screen
!= new_screen
)
600 screen_client_moveto(c
, new_screen
, true, false);
603 hooks_property(c
, "geometry");
607 /** Set a clinet floating.
608 * \param c The client.
609 * \param floating Set floating, or not.
610 * \param layer Layer to put the floating window onto.
613 client_setfloating(client_t
*c
, bool floating
)
615 if(c
->isfloating
!= floating
616 && (c
->type
== WINDOW_TYPE_NORMAL
))
618 if((c
->isfloating
= floating
))
620 client_resize(c
, c
->f_geometry
, false);
621 client_need_arrange(c
);
623 xcb_change_property(globalconf
.connection
,
624 XCB_PROP_MODE_REPLACE
,
625 c
->win
, _AWESOME_FLOATING
, CARDINAL
, 8, 1,
628 hooks_property(c
, "floating");
632 /** Set a client minimized, or not.
633 * \param c The client.
634 * \param s Set or not the client minimized.
637 client_setminimized(client_t
*c
, bool s
)
639 if(c
->isminimized
!= s
)
641 client_need_arrange(c
);
643 client_need_arrange(c
);
644 ewmh_client_update_hints(c
);
646 hooks_property(c
, "minimized");
650 /** Set a client sticky, or not.
651 * \param c The client.
652 * \param s Set or not the client sticky.
655 client_setsticky(client_t
*c
, bool s
)
659 client_need_arrange(c
);
661 client_need_arrange(c
);
662 ewmh_client_update_hints(c
);
663 hooks_property(c
, "sticky");
667 /** Set a client fullscreen, or not.
668 * \param c The client.
669 * \param s Set or not the client fullscreen.
672 client_setfullscreen(client_t
*c
, bool s
)
674 if(c
->isfullscreen
!= s
)
678 /* become fullscreen! */
679 if((c
->isfullscreen
= s
))
681 geometry
= screen_area_get(c
->screen
, NULL
, NULL
, false);
682 c
->m_geometry
= c
->geometry
;
683 c
->oldborder
= c
->border
;
684 client_setborder(c
, 0);
688 geometry
= c
->m_geometry
;
689 client_setborder(c
, c
->oldborder
);
690 client_resize(c
, c
->m_geometry
, false);
692 client_resize(c
, geometry
, false);
693 client_need_arrange(c
);
695 xcb_change_property(globalconf
.connection
,
696 XCB_PROP_MODE_REPLACE
,
697 c
->win
, _AWESOME_FULLSCREEN
, CARDINAL
, 8, 1,
699 ewmh_client_update_hints(c
);
700 hooks_property(c
, "fullscreen");
704 /** Set a client above, or not.
705 * \param c The client.
706 * \param s Set or not the client above.
709 client_setabove(client_t
*c
, bool s
)
715 ewmh_client_update_hints(c
);
717 hooks_property(c
, "above");
721 /** Set a client below, or not.
722 * \param c The client.
723 * \param s Set or not the client below.
726 client_setbelow(client_t
*c
, bool s
)
732 ewmh_client_update_hints(c
);
734 hooks_property(c
, "below");
738 /** Set a client modal, or not.
739 * \param c The client.
740 * \param s Set or not the client moda.
743 client_setmodal(client_t
*c
, bool s
)
749 ewmh_client_update_hints(c
);
751 hooks_property(c
, "modal");
755 /** Set a client ontop, or not.
756 * \param c The client.
757 * \param s Set or not the client moda.
760 client_setontop(client_t
*c
, bool s
)
767 hooks_property(c
, "ontop");
771 /** Save client properties as an X property.
772 * \param c The client.
775 client_saveprops_tags(client_t
*c
)
777 tag_array_t
*tags
= &globalconf
.screens
[c
->screen
].tags
;
778 unsigned char *prop
= p_alloca(unsigned char, tags
->len
+ 1);
781 for(i
= 0; i
< tags
->len
; i
++)
782 prop
[i
] = is_client_tagged(c
, tags
->tab
[i
]) ? '1' : '0';
784 xcb_change_property(globalconf
.connection
, XCB_PROP_MODE_REPLACE
, c
->win
, _AWESOME_TAGS
, STRING
, 8, i
, prop
);
788 * \param c The client.
791 client_unban(client_t
*c
)
793 xcb_map_window(globalconf
.connection
, c
->win
);
794 window_state_set(c
->win
, XCB_WM_STATE_NORMAL
);
797 if(c
->isfullscreen
|| !c
->titlebar
->isvisible
)
798 xcb_unmap_window(globalconf
.connection
, c
->titlebar
->sw
.window
);
800 xcb_map_window(globalconf
.connection
, c
->titlebar
->sw
.window
);
804 /** Unmanage a client.
805 * \param c The client.
808 client_unmanage(client_t
*c
)
810 tag_array_t
*tags
= &globalconf
.screens
[c
->screen
].tags
;
812 if(globalconf
.screens
[c
->phys_screen
].client_focus
== c
)
815 /* remove client everywhere */
816 client_list_detach(&globalconf
.clients
, c
);
817 stack_client_delete(c
);
818 for(int i
= 0; i
< tags
->len
; i
++)
819 untag_client(c
, tags
->tab
[i
]);
822 luaA_client_userdata_new(globalconf
.L
, c
);
823 luaA_dofunction(globalconf
.L
, globalconf
.hooks
.unmanage
, 1, 0);
825 /* Call hook to notify list change */
826 luaA_dofunction(globalconf
.L
, globalconf
.hooks
.clients
, 0, 0);
828 /* The server grab construct avoids race conditions. */
829 xcb_grab_server(globalconf
.connection
);
831 xcb_configure_window(globalconf
.connection
, c
->win
,
832 XCB_CONFIG_WINDOW_BORDER_WIDTH
,
833 (uint32_t *) &c
->oldborder
);
835 xcb_ungrab_button(globalconf
.connection
, XCB_BUTTON_INDEX_ANY
, c
->win
,
836 XCB_BUTTON_MASK_ANY
);
837 window_state_set(c
->win
, XCB_WM_STATE_WITHDRAWN
);
839 xcb_flush(globalconf
.connection
);
840 xcb_ungrab_server(globalconf
.connection
);
842 titlebar_client_detach(c
);
844 ewmh_update_net_client_list(c
->phys_screen
);
846 /* delete properties */
847 xcb_delete_property(globalconf
.connection
, c
->win
, _AWESOME_TAGS
);
848 xcb_delete_property(globalconf
.connection
, c
->win
, _AWESOME_FLOATING
);
850 if(client_hasstrut(c
))
851 /* All the wiboxes (may) need to be repositioned */
852 for(int screen
= 0; screen
< globalconf
.nscreen
; screen
++)
853 for(int i
= 0; i
< globalconf
.screens
[screen
].wiboxes
.len
; i
++)
855 wibox_t
*s
= globalconf
.screens
[screen
].wiboxes
.tab
[i
];
856 wibox_position_update(s
);
859 /* set client as invalid */
865 /** Kill a client via a WM_DELETE_WINDOW request or KillClient if not
867 * \param c The client to kill.
870 client_kill(client_t
*c
)
872 if(window_hasproto(c
->win
, WM_DELETE_WINDOW
))
874 xcb_client_message_event_t ev
;
876 /* Initialize all of event's fields first */
879 ev
.response_type
= XCB_CLIENT_MESSAGE
;
882 ev
.data
.data32
[1] = XCB_CURRENT_TIME
;
883 ev
.type
= WM_PROTOCOLS
;
884 ev
.data
.data32
[0] = WM_DELETE_WINDOW
;
886 xcb_send_event(globalconf
.connection
, false, c
->win
,
887 XCB_EVENT_MASK_NO_EVENT
, (char *) &ev
);
890 xcb_kill_client(globalconf
.connection
, c
->win
);
893 /** Get all clients into a table.
894 * \param L The Lua VM state.
895 * \return The number of elements pushed on stack.
897 * \lparam An optional screen nunmber.
898 * \lreturn A table with all clients.
901 luaA_client_get(lua_State
*L
)
906 screen
= luaL_optnumber(L
, 1, 0) - 1;
910 if(screen
== SCREEN_UNDEF
)
911 for(c
= globalconf
.clients
; c
; c
= c
->next
)
913 luaA_client_userdata_new(globalconf
.L
, c
);
914 lua_rawseti(L
, -2, i
++);
918 luaA_checkscreen(screen
);
919 for(c
= globalconf
.clients
; c
; c
= c
->next
)
920 if(c
->screen
== screen
)
922 luaA_client_userdata_new(globalconf
.L
, c
);
923 lua_rawseti(L
, -2, i
++);
930 /** Get only visible clients for a screen (DEPRECATED).
931 * \param L The Lua VM state.
932 * \return The number of elements pushed on stack.
934 * \lparam A screen number.
935 * \lreturn A table with all visible clients for this screen.
938 luaA_client_visible_get(lua_State
*L
)
942 int screen
= luaL_checknumber(L
, 1) - 1;
944 luaA_checkscreen(screen
);
950 for(c
= globalconf
.clients
; c
; c
= c
->next
)
951 if(client_isvisible(c
, screen
))
953 luaA_client_userdata_new(L
, c
);
954 lua_rawseti(L
, -2, i
++);
960 /** Check if a client is visible on its screen.
961 * \param L The Lua VM state.
962 * \return The number of elements pushed on stack.
965 * \lreturn A boolean value, true if the client is visible, false otherwise.
968 luaA_client_isvisible(lua_State
*L
)
970 client_t
**c
= luaA_checkudata(L
, 1, "client");
971 lua_pushboolean(L
, client_isvisible(*c
, (*c
)->screen
));
975 /** Set client border width.
976 * \param c The client.
977 * \param width The border width.
980 client_setborder(client_t
*c
, int width
)
984 if(width
> 0 && (c
->type
== WINDOW_TYPE_DOCK
985 || c
->type
== WINDOW_TYPE_SPLASH
986 || c
->type
== WINDOW_TYPE_DESKTOP
990 if(width
== c
->border
|| width
< 0)
994 xcb_configure_window(globalconf
.connection
, c
->win
,
995 XCB_CONFIG_WINDOW_BORDER_WIDTH
, &w
);
997 if(client_isvisible(c
, c
->screen
))
999 if(client_isfloating(c
) || layout_get_current(c
->screen
) == layout_floating
)
1000 titlebar_update_geometry_floating(c
);
1002 globalconf
.screens
[c
->screen
].need_arrange
= true;
1005 hooks_property(c
, "border_width");
1009 * \param L The Lua VM state.
1015 luaA_client_kill(lua_State
*L
)
1017 client_t
**c
= luaA_checkudata(L
, 1, "client");
1022 /** Swap a client with another one.
1023 * \param L The Lua VM state.
1026 * \lparam A client to swap with.
1029 luaA_client_swap(lua_State
*L
)
1031 client_t
**c
= luaA_checkudata(L
, 1, "client");
1032 client_t
**swap
= luaA_checkudata(L
, 2, "client");
1033 client_list_swap(&globalconf
.clients
, *swap
, *c
);
1034 client_need_arrange(*c
);
1035 client_need_arrange(*swap
);
1037 /* Call hook to notify list change */
1038 luaA_dofunction(L
, globalconf
.hooks
.clients
, 0, 0);
1043 /** Access or set the client tags.
1044 * \param L The Lua VM state.
1045 * \return The number of elements pushed on stack.
1046 * \lparam A table with tags to set, or none to get the current tags table.
1047 * \return The clients tag.
1050 luaA_client_tags(lua_State
*L
)
1054 client_t
**c
= luaA_checkudata(L
, 1, "client");
1057 if(lua_gettop(L
) == 2)
1059 luaA_checktable(L
, 2);
1060 tags
= &globalconf
.screens
[(*c
)->screen
].tags
;
1061 for(int i
= 0; i
< tags
->len
; i
++)
1062 untag_client(*c
, tags
->tab
[i
]);
1064 while(lua_next(L
, 2))
1066 tag
= luaA_checkudata(L
, -1, "tag");
1067 tag_client(*c
, *tag
);
1073 tags
= &globalconf
.screens
[(*c
)->screen
].tags
;
1075 for(int i
= 0; i
< tags
->len
; i
++)
1076 if(is_client_tagged(*c
, tags
->tab
[i
]))
1078 luaA_tag_userdata_new(L
, tags
->tab
[i
]);
1079 lua_rawseti(L
, -2, ++j
);
1085 /** Raise a client on top of others which are on the same layer.
1086 * \param L The Lua VM state.
1092 luaA_client_raise(lua_State
*L
)
1094 client_t
**c
= luaA_checkudata(L
, 1, "client");
1099 /** Redraw a client by unmapping and mapping it quickly.
1100 * \param L The Lua VM state.
1106 luaA_client_redraw(lua_State
*L
)
1108 client_t
**c
= luaA_checkudata(L
, 1, "client");
1110 xcb_unmap_window(globalconf
.connection
, (*c
)->win
);
1111 xcb_map_window(globalconf
.connection
, (*c
)->win
);
1113 /* Set the focus on the current window if the redraw has been
1114 performed on the window where the pointer is currently on
1115 because after the unmapping/mapping, the focus is lost */
1116 if(globalconf
.screen_focus
->client_focus
== *c
)
1117 xcb_set_input_focus(globalconf
.connection
, XCB_INPUT_FOCUS_POINTER_ROOT
,
1118 (*c
)->win
, XCB_CURRENT_TIME
);
1123 /** Stop managing a client.
1124 * \param L The Lua VM state.
1125 * \return The number of elements pushed on stack.
1130 luaA_client_unmanage(lua_State
*L
)
1132 client_t
**c
= luaA_checkudata(L
, 1, "client");
1133 client_unmanage(*c
);
1137 /** Return client geometry.
1138 * \param L The Lua VM state.
1139 * \return The number of elements pushed on stack.
1141 * \lparam A table with new coordinates, or none.
1142 * \lreturn A table with client coordinates.
1145 luaA_client_geometry(lua_State
*L
)
1147 client_t
**c
= luaA_checkudata(L
, 1, "client");
1149 if(lua_gettop(L
) == 2)
1151 if((*c
)->isfloating
|| layout_get_current((*c
)->screen
) == layout_floating
)
1155 luaA_checktable(L
, 2);
1156 geometry
.x
= luaA_getopt_number(L
, 2, "x", (*c
)->geometry
.x
);
1157 geometry
.y
= luaA_getopt_number(L
, 2, "y", (*c
)->geometry
.y
);
1158 geometry
.width
= luaA_getopt_number(L
, 2, "width", (*c
)->geometry
.width
);
1159 geometry
.height
= luaA_getopt_number(L
, 2, "height", (*c
)->geometry
.height
);
1160 client_resize(*c
, geometry
, false);
1164 return luaA_pusharea(L
, (*c
)->geometry
);
1168 luaA_client_coords(lua_State
*L
)
1171 return luaA_client_geometry(L
);
1174 /** Return client geometry, using also titlebar and border width.
1175 * \param L The Lua VM state.
1176 * \return The number of elements pushed on stack.
1178 * \lparam A table with new coordinates, or none.
1179 * \lreturn A table with client coordinates.
1182 luaA_client_fullgeometry(lua_State
*L
)
1184 client_t
**c
= luaA_checkudata(L
, 1, "client");
1187 if(lua_gettop(L
) == 2)
1189 if((*c
)->isfloating
|| layout_get_current((*c
)->screen
) == layout_floating
)
1191 luaA_checktable(L
, 2);
1192 geometry
.x
= luaA_getopt_number(L
, 2, "x", (*c
)->geometry
.x
);
1193 geometry
.y
= luaA_getopt_number(L
, 2, "y", (*c
)->geometry
.y
);
1194 geometry
.width
= luaA_getopt_number(L
, 2, "width", (*c
)->geometry
.width
);
1195 geometry
.height
= luaA_getopt_number(L
, 2, "height", (*c
)->geometry
.height
);
1196 geometry
= titlebar_geometry_remove((*c
)->titlebar
,
1199 client_resize(*c
, geometry
, false);
1203 return luaA_pusharea(L
, titlebar_geometry_add((*c
)->titlebar
,
1209 luaA_client_fullcoords(lua_State
*L
)
1212 return luaA_client_fullgeometry(L
);
1215 /** Client newindex.
1216 * \param L The Lua VM state.
1217 * \return The number of elements pushed on stack.
1220 luaA_client_newindex(lua_State
*L
)
1223 client_t
**c
= luaA_checkudata(L
, 1, "client");
1224 const char *buf
= luaL_checklstring(L
, 2, &len
);
1232 luaL_error(L
, "client is invalid\n");
1234 switch(a_tokenize(buf
, len
))
1237 if(globalconf
.xinerama_is_active
)
1239 i
= luaL_checknumber(L
, 3) - 1;
1240 luaA_checkscreen(i
);
1241 if(i
!= (*c
)->screen
)
1242 screen_client_moveto(*c
, i
, true, true);
1246 b
= luaA_checkboolean(L
, 3);
1247 if(b
!= (*c
)->ishidden
)
1249 client_need_arrange(*c
);
1251 client_need_arrange(*c
);
1255 client_setminimized(*c
, luaA_checkboolean(L
, 3));
1257 case A_TK_FULLSCREEN
:
1258 client_setfullscreen(*c
, luaA_checkboolean(L
, 3));
1261 image
= luaA_checkudata(L
, 3, "image");
1262 image_unref(&(*c
)->icon
);
1264 (*c
)->icon
= *image
;
1266 hooks_property(*c
, "icon");
1270 window_opacity_set((*c
)->win
, -1);
1273 d
= luaL_checknumber(L
, 3);
1274 if(d
>= 0 && d
<= 1)
1275 window_opacity_set((*c
)->win
, d
);
1279 client_setfloating(*c
, luaA_checkboolean(L
, 3));
1282 client_setsticky(*c
, luaA_checkboolean(L
, 3));
1284 case A_TK_HONORSIZEHINTS
:
1285 (*c
)->honorsizehints
= luaA_checkboolean(L
, 3);
1286 client_need_arrange(*c
);
1288 case A_TK_BORDER_WIDTH
:
1289 client_setborder(*c
, luaL_checknumber(L
, 3));
1292 client_setontop(*c
, luaA_checkboolean(L
, 3));
1294 case A_TK_BORDER_COLOR
:
1295 if((buf
= luaL_checklstring(L
, 3, &len
))
1296 && xcolor_init_reply(xcolor_init_unchecked(&(*c
)->border_color
, buf
, len
)))
1297 xcb_change_window_attributes(globalconf
.connection
, (*c
)->win
,
1298 XCB_CW_BORDER_PIXEL
, &(*c
)->border_color
.pixel
);
1302 titlebar_client_detach(*c
);
1305 t
= luaA_checkudata(L
, 3, "wibox");
1306 titlebar_client_attach(*c
, *t
);
1317 * \param L The Lua VM state.
1318 * \return The number of elements pushed on stack.
1320 * \lfield name The client title.
1321 * \lfield skip_taskbar True if the client does not want to be in taskbar.
1322 * \lfield type The window type (desktop, normal, dock, …).
1323 * \lfield class The client class.
1324 * \lfield instance The client instance.
1325 * \lfield pid The client PID, if available.
1326 * \lfield role The window role, if available.
1327 * \lfield machine The machine client is running on.
1328 * \lfield icon_name The client name when iconified.
1329 * \lfield screen Client screen number.
1330 * \lfield hide Define if the client must be hidden, i.e. never mapped,
1331 * invisible in taskbar.
1332 * \lfield minimize Define it the client must be iconify, i.e. only visible in
1334 * \lfield icon_path Path to the icon used to identify.
1335 * \lfield floating True always floating.
1336 * \lfield honorsizehints Honor size hints, i.e. respect size ratio.
1337 * \lfield border_width The client border width.
1338 * \lfield border_color The client border color.
1339 * \lfield titlebar The client titlebar.
1340 * \lfield urgent The client urgent state.
1341 * \lfield focus The focused client.
1342 * \lfield opacity The client opacity between 0 and 1.
1343 * \lfield ontop The client is on top of every other windows.
1344 * \lfield fullscreen The client is fullscreen or not.
1347 luaA_client_index(lua_State
*L
)
1351 client_t
**c
= luaA_checkudata(L
, 1, "client");
1352 const char *buf
= luaL_checklstring(L
, 2, &len
);
1355 xcb_get_wm_class_reply_t hint
;
1356 xcb_get_property_cookie_t prop_c
;
1357 xcb_get_property_reply_t
*prop_r
= NULL
;
1361 luaL_error(L
, "client is invalid\n");
1363 if(luaA_usemetatable(L
, 1, 2))
1366 switch(a_tokenize(buf
, len
))
1369 lua_pushstring(L
, (*c
)->name
);
1371 case A_TK_SKIP_TASKBAR
:
1372 lua_pushboolean(L
, (*c
)->skiptb
);
1377 case WINDOW_TYPE_DESKTOP
:
1378 lua_pushliteral(L
, "desktop");
1380 case WINDOW_TYPE_DOCK
:
1381 lua_pushliteral(L
, "dock");
1383 case WINDOW_TYPE_SPLASH
:
1384 lua_pushliteral(L
, "splash");
1386 case WINDOW_TYPE_DIALOG
:
1387 lua_pushliteral(L
, "dialog");
1390 lua_pushliteral(L
, "normal");
1395 if(!xcb_get_wm_class_reply(globalconf
.connection
,
1396 xcb_get_wm_class_unchecked(globalconf
.connection
, (*c
)->win
),
1399 lua_pushstring(L
, hint
.class);
1400 xcb_get_wm_class_reply_wipe(&hint
);
1403 if(!xcb_get_wm_class_reply(globalconf
.connection
,
1404 xcb_get_wm_class_unchecked(globalconf
.connection
, (*c
)->win
),
1407 lua_pushstring(L
, hint
.name
);
1408 xcb_get_wm_class_reply_wipe(&hint
);
1411 if(!xutil_text_prop_get(globalconf
.connection
, (*c
)->win
,
1412 WM_WINDOW_ROLE
, &value
, &slen
))
1414 lua_pushlstring(L
, value
, slen
);
1418 prop_c
= xcb_get_property_unchecked(globalconf
.connection
, false, (*c
)->win
, _NET_WM_PID
, CARDINAL
, 0L, 1L);
1419 prop_r
= xcb_get_property_reply(globalconf
.connection
, prop_c
, NULL
);
1421 if(prop_r
&& prop_r
->value_len
&& (data
= xcb_get_property_value(prop_r
)))
1422 lua_pushnumber(L
, *(uint32_t *)data
);
1430 if(!xutil_text_prop_get(globalconf
.connection
, (*c
)->win
,
1431 WM_CLIENT_MACHINE
, &value
, &slen
))
1433 lua_pushlstring(L
, value
, slen
);
1436 case A_TK_ICON_NAME
:
1437 lua_pushstring(L
, (*c
)->icon_name
);
1440 lua_pushnumber(L
, 1 + (*c
)->screen
);
1443 lua_pushboolean(L
, (*c
)->ishidden
);
1446 lua_pushboolean(L
, (*c
)->isminimized
);
1448 case A_TK_FULLSCREEN
:
1449 lua_pushboolean(L
, (*c
)->isfullscreen
);
1453 luaA_image_userdata_new(L
, (*c
)->icon
);
1458 if((d
= window_opacity_get((*c
)->win
)) >= 0)
1459 lua_pushnumber(L
, d
);
1464 lua_pushboolean(L
, (*c
)->isfloating
);
1467 lua_pushboolean(L
, (*c
)->isontop
);
1470 lua_pushboolean(L
, (*c
)->issticky
);
1472 case A_TK_HONORSIZEHINTS
:
1473 lua_pushboolean(L
, (*c
)->honorsizehints
);
1475 case A_TK_BORDER_WIDTH
:
1476 lua_pushnumber(L
, (*c
)->border
);
1478 case A_TK_BORDER_COLOR
:
1479 luaA_pushcolor(L
, &(*c
)->border_color
);
1483 return luaA_wibox_userdata_new(L
, (*c
)->titlebar
);
1486 lua_pushboolean(L
, (*c
)->isurgent
);
1488 case A_TK_SIZEHINTS
:
1490 lua_pushboolean(L
, (*c
)->size_hints
.flags
& XCB_SIZE_HINT_US_POSITION
);
1491 lua_setfield(L
, -2, "user_position");
1492 lua_pushboolean(L
, (*c
)->size_hints
.flags
& XCB_SIZE_HINT_US_SIZE
);
1493 lua_setfield(L
, -2, "user_size");
1494 lua_pushboolean(L
, (*c
)->size_hints
.flags
& XCB_SIZE_HINT_P_POSITION
);
1495 lua_setfield(L
, -2, "program_position");
1496 lua_pushboolean(L
, (*c
)->size_hints
.flags
& XCB_SIZE_HINT_P_SIZE
);
1497 lua_setfield(L
, -2, "program_size");
1506 /** Get or set mouse buttons bindings for a client.
1507 * \param L The Lua VM state.
1508 * \return The number of element pushed on stack.
1511 * \lparam An array of mouse button bindings objects, or nothing.
1512 * \return The array of mouse button bindings objects of this client.
1515 luaA_client_buttons(lua_State
*L
)
1517 client_t
**client
= luaA_checkudata(L
, 1, "client");
1518 button_array_t
*buttons
= &(*client
)->buttons
;
1520 if(lua_gettop(L
) == 2)
1521 luaA_button_array_set(L
, 2, buttons
);
1523 return luaA_button_array_get(L
, buttons
);
1527 * \param L The Lua VM state.
1528 * \return The number of pushed elements.
1531 luaA_client_module_index(lua_State
*L
)
1534 const char *buf
= luaL_checklstring(L
, 2, &len
);
1536 switch(a_tokenize(buf
, len
))
1539 if(globalconf
.screen_focus
->client_focus
)
1540 luaA_client_userdata_new(L
, globalconf
.screen_focus
->client_focus
);
1551 /* Client module new index.
1552 * \param L The Lua VM state.
1553 * \return The number of pushed elements.
1556 luaA_client_module_newindex(lua_State
*L
)
1559 const char *buf
= luaL_checklstring(L
, 2, &len
);
1562 switch(a_tokenize(buf
, len
))
1565 c
= luaA_checkudata(L
, 3, "client");
1575 const struct luaL_reg awesome_client_methods
[] =
1577 { "get", luaA_client_get
},
1578 { "visible_get", luaA_client_visible_get
},
1579 { "__index", luaA_client_module_index
},
1580 { "__newindex", luaA_client_module_newindex
},
1583 const struct luaL_reg awesome_client_meta
[] =
1585 { "isvisible", luaA_client_isvisible
},
1586 { "geometry", luaA_client_geometry
},
1587 { "fullgeometry", luaA_client_fullgeometry
},
1588 { "buttons", luaA_client_buttons
},
1589 { "tags", luaA_client_tags
},
1590 { "kill", luaA_client_kill
},
1591 { "swap", luaA_client_swap
},
1592 { "raise", luaA_client_raise
},
1593 { "redraw", luaA_client_redraw
},
1594 { "mouse_resize", luaA_client_mouse_resize
},
1595 { "mouse_move", luaA_client_mouse_move
},
1596 { "unmanage", luaA_client_unmanage
},
1597 { "__index", luaA_client_index
},
1598 { "__newindex", luaA_client_newindex
},
1599 { "__eq", luaA_client_eq
},
1600 { "__gc", luaA_client_gc
},
1601 { "__tostring", luaA_client_tostring
},
1603 { "coords", luaA_client_coords
},
1604 { "fullcoords", luaA_client_fullcoords
},
1608 // vim: filetype=c:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=80