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.
25 #include <xcb/xcb_atom.h>
40 #include "layouts/floating.h"
41 #include "common/markup.h"
42 #include "common/atoms.h"
44 extern awesome_t globalconf
;
46 /** Create a new client userdata.
47 * \param L The Lua VM state.
48 * \param p A client pointer.
49 * \param The number of elements pushed on the stack.
52 luaA_client_userdata_new(lua_State
*L
, client_t
*p
)
54 client_t
**pp
= lua_newuserdata(L
, sizeof(client_t
*));
57 return luaA_settype(L
, "client");
60 DO_LUA_EQ(client_t
, client
, "client")
61 DO_LUA_GC(client_t
, client
, "client", client_unref
)
63 /** Load windows properties, restoring client's tag
64 * and floating state before awesome was restarted if any.
65 * \param c A client pointer.
66 * \param screen A virtual screen.
67 * \return True if client had property, false otherwise.
70 client_loadprops(client_t
* c
, screen_t
*screen
)
73 tag_array_t
*tags
= &screen
->tags
;
75 xcb_get_property_cookie_t floating_q
, fullscreen_q
;
76 xcb_get_property_reply_t
*reply
;
79 if(!xutil_text_prop_get(globalconf
.connection
, c
->win
, _AWESOME_TAGS
,
83 /* Send the GetProperty requests which will be processed later */
84 floating_q
= xcb_get_property_unchecked(globalconf
.connection
, false, c
->win
,
85 _AWESOME_FLOATING
, CARDINAL
, 0, 1);
87 fullscreen_q
= xcb_get_property_unchecked(globalconf
.connection
, false, c
->win
,
88 _AWESOME_FULLSCREEN
, CARDINAL
, 0, 1);
90 /* ignore property if the tag count isn't matching */
92 for(int i
= 0; i
< tags
->len
; i
++)
94 tag_client(c
, tags
->tab
[i
]);
96 untag_client(c
, tags
->tab
[i
]);
100 /* check for floating */
101 reply
= xcb_get_property_reply(globalconf
.connection
, floating_q
, NULL
);
103 if(reply
&& reply
->value_len
&& (data
= xcb_get_property_value(reply
)))
104 client_setfloating(c
, *(bool *) data
);
107 /* check for fullscreen */
108 reply
= xcb_get_property_reply(globalconf
.connection
, fullscreen_q
, NULL
);
110 if(reply
&& reply
->value_len
&& (data
= xcb_get_property_value(reply
)))
111 client_setfullscreen(c
, *(bool *) data
);
117 /** Check if client supports protocol WM_DELETE_WINDOW.
118 * \param win The window.
119 * \return True if client has WM_DELETE_WINDOW, false otherwise.
122 window_isprotodel(xcb_window_t win
)
125 xcb_get_wm_protocols_reply_t protocols
;
128 if(xcb_get_wm_protocols_reply(globalconf
.connection
,
129 xcb_get_wm_protocols_unchecked(globalconf
.connection
,
133 for(i
= 0; !ret
&& i
< protocols
.atoms_len
; i
++)
134 if(protocols
.atoms
[i
] == WM_DELETE_WINDOW
)
136 xcb_get_wm_protocols_reply_wipe(&protocols
);
141 /** Returns true if a client is tagged
142 * with one of the tags of the specified screen.
143 * \param c The client to check.
144 * \param screen Virtual screen number.
145 * \return true if the client is visible, false otherwise.
148 client_maybevisible(client_t
*c
, int screen
)
150 if(c
->screen
== screen
)
152 if(c
->issticky
|| c
->type
== WINDOW_TYPE_DESKTOP
)
155 tag_array_t
*tags
= &globalconf
.screens
[screen
].tags
;
157 for(int i
= 0; i
< tags
->len
; i
++)
158 if(tags
->tab
[i
]->selected
&& is_client_tagged(c
, tags
->tab
[i
]))
164 /** Get a client by its window.
165 * \param w The client window to find.
166 * \return A client pointer if found, NULL otherwise.
169 client_getbywin(xcb_window_t w
)
172 for(c
= globalconf
.clients
; c
&& c
->win
!= w
; c
= c
->next
);
176 /** Unfocus a client.
177 * \param c The client.
180 client_unfocus(client_t
*c
)
182 globalconf
.screens
[c
->phys_screen
].client_focus
= NULL
;
185 luaA_client_userdata_new(globalconf
.L
, c
);
186 luaA_dofunction(globalconf
.L
, globalconf
.hooks
.unfocus
, 1, 0);
188 widget_invalidate_cache(c
->screen
, WIDGET_CACHE_CLIENTS
);
189 ewmh_update_net_active_window(c
->phys_screen
);
192 /** Ban client and unmap it.
193 * \param c The client.
196 client_ban(client_t
*c
)
198 if(globalconf
.screen_focus
->client_focus
== c
)
200 xcb_unmap_window(globalconf
.connection
, c
->win
);
202 window_state_set(c
->win
, XCB_WM_STATE_ICONIC
);
204 window_state_set(c
->win
, XCB_WM_STATE_WITHDRAWN
);
206 xcb_unmap_window(globalconf
.connection
, c
->titlebar
->sw
.window
);
209 /** Give focus to client, or to first client if client is NULL.
210 * \param c The client or NULL.
211 * \return True if a window (even root) has received focus, false otherwise.
214 client_focus(client_t
*c
)
216 if(!client_maybevisible(c
, c
->screen
) || c
->nofocus
)
219 /* unfocus current selected client */
220 if(globalconf
.screen_focus
->client_focus
221 && c
!= globalconf
.screen_focus
->client_focus
)
222 client_unfocus(globalconf
.screen_focus
->client_focus
);
226 client_setminimized(c
, false);
228 /* unban the client before focusing or it will fail */
231 globalconf
.screen_focus
= &globalconf
.screens
[c
->phys_screen
];
232 globalconf
.screen_focus
->client_focus
= c
;
234 xcb_set_input_focus(globalconf
.connection
, XCB_INPUT_FOCUS_POINTER_ROOT
,
235 c
->win
, XCB_CURRENT_TIME
);
237 /* Some layouts use focused client differently, so call them back.
238 * And anyway, we have maybe unhidden */
239 client_need_arrange(c
);
242 luaA_client_userdata_new(globalconf
.L
, globalconf
.screen_focus
->client_focus
);
243 luaA_dofunction(globalconf
.L
, globalconf
.hooks
.focus
, 1, 0);
245 ewmh_update_net_active_window(c
->phys_screen
);
246 widget_invalidate_cache(c
->screen
, WIDGET_CACHE_CLIENTS
);
249 /** Stack a window below.
250 * \param c The client.
251 * \param previous The previous window on the stack.
252 * \param return The next-previous!
255 client_stack_below(client_t
*c
, xcb_window_t previous
)
257 uint32_t config_win_vals
[2];
259 config_win_vals
[0] = previous
;
260 config_win_vals
[1] = XCB_STACK_MODE_BELOW
;
264 xcb_configure_window(globalconf
.connection
,
265 c
->titlebar
->sw
.window
,
266 XCB_CONFIG_WINDOW_SIBLING
| XCB_CONFIG_WINDOW_STACK_MODE
,
268 config_win_vals
[0] = c
->titlebar
->sw
.window
;
270 xcb_configure_window(globalconf
.connection
, c
->win
,
271 XCB_CONFIG_WINDOW_SIBLING
| XCB_CONFIG_WINDOW_STACK_MODE
,
273 config_win_vals
[0] = c
->win
;
278 /** Get the real layer of a client according to its attribute (fullscreen, …)
279 * \param c The client.
280 * \return The real layer.
283 client_layer_translator(client_t
*c
)
289 else if(c
->isfullscreen
)
290 return LAYER_FULLSCREEN
;
293 else if(c
->isfloating
)
298 case WINDOW_TYPE_DOCK
:
300 case WINDOW_TYPE_SPLASH
:
301 case WINDOW_TYPE_DIALOG
:
303 case WINDOW_TYPE_DESKTOP
:
304 return LAYER_DESKTOP
;
311 * \todo It might be worth stopping to restack everyone and only stack `c'
312 * relatively to the first matching in the list.
317 uint32_t config_win_vals
[2];
322 config_win_vals
[0] = XCB_NONE
;
323 config_win_vals
[1] = XCB_STACK_MODE_BELOW
;
325 /* first stack modal and fullscreen windows */
326 for(layer
= LAYER_OUTOFSPACE
- 1; layer
>= LAYER_FULLSCREEN
; layer
--)
327 for(node
= globalconf
.stack
; node
; node
= node
->next
)
328 if(client_layer_translator(node
->client
) == layer
)
329 config_win_vals
[0] = client_stack_below(node
->client
, config_win_vals
[0]);
331 /* then stack ontop wibox window */
332 for(screen
= 0; screen
< globalconf
.nscreen
; screen
++)
333 for(int i
= 0; i
< globalconf
.screens
[screen
].wiboxes
.len
; i
++)
335 wibox_t
*sb
= globalconf
.screens
[screen
].wiboxes
.tab
[i
];
338 xcb_configure_window(globalconf
.connection
,
340 XCB_CONFIG_WINDOW_SIBLING
| XCB_CONFIG_WINDOW_STACK_MODE
,
342 config_win_vals
[0] = sb
->sw
.window
;
346 /* finally stack everything else */
347 for(layer
= LAYER_FULLSCREEN
- 1; layer
>= LAYER_TILE
; layer
--)
348 for(node
= globalconf
.stack
; node
; node
= node
->next
)
349 if(client_layer_translator(node
->client
) == layer
)
350 config_win_vals
[0] = client_stack_below(node
->client
, config_win_vals
[0]);
352 /* then stack not ontop wibox window */
353 for(screen
= 0; screen
< globalconf
.nscreen
; screen
++)
354 for(int i
= 0; i
< globalconf
.screens
[screen
].wiboxes
.len
; i
++)
356 wibox_t
*sb
= globalconf
.screens
[screen
].wiboxes
.tab
[i
];
359 xcb_configure_window(globalconf
.connection
,
361 XCB_CONFIG_WINDOW_SIBLING
| XCB_CONFIG_WINDOW_STACK_MODE
,
363 config_win_vals
[0] = sb
->sw
.window
;
367 /* finally stack everything else */
368 for(layer
= LAYER_TILE
- 1; layer
>= LAYER_DESKTOP
; layer
--)
369 for(node
= globalconf
.stack
; node
; node
= node
->next
)
370 if(client_layer_translator(node
->client
) == layer
)
371 config_win_vals
[0] = client_stack_below(node
->client
, config_win_vals
[0]);
374 /** Manage a new client.
375 * \param w The window.
376 * \param wgeom Window geometry.
377 * \param phys_screen Physical screen number.
378 * \param screen Virtual screen number where to manage client.
381 client_manage(xcb_window_t w
, xcb_get_geometry_reply_t
*wgeom
, int phys_screen
, int screen
)
383 xcb_get_property_cookie_t ewmh_icon_cookie
;
386 const uint32_t select_input_val
[] =
388 XCB_EVENT_MASK_STRUCTURE_NOTIFY
389 | XCB_EVENT_MASK_PROPERTY_CHANGE
390 | XCB_EVENT_MASK_ENTER_WINDOW
393 /* Send request to get NET_WM_ICON property as soon as possible... */
394 ewmh_icon_cookie
= ewmh_window_icon_get_unchecked(w
);
395 xcb_change_window_attributes(globalconf
.connection
, w
, XCB_CW_EVENT_MASK
, select_input_val
);
397 if(systray_iskdedockapp(w
))
399 systray_request_handle(w
, phys_screen
, NULL
);
403 c
= p_new(client_t
, 1);
405 c
->screen
= screen_getbycoord(screen
, wgeom
->x
, wgeom
->y
);
407 c
->phys_screen
= phys_screen
;
411 c
->geometry
.x
= c
->f_geometry
.x
= c
->m_geometry
.x
= wgeom
->x
;
412 c
->geometry
.y
= c
->f_geometry
.y
= c
->m_geometry
.y
= wgeom
->y
;
413 c
->geometry
.width
= c
->f_geometry
.width
= c
->m_geometry
.width
= wgeom
->width
;
414 c
->geometry
.height
= c
->f_geometry
.height
= c
->m_geometry
.height
= wgeom
->height
;
415 client_setborder(c
, wgeom
->border_width
);
416 if((icon
= ewmh_window_icon_get_reply(ewmh_icon_cookie
)))
417 c
->icon
= image_ref(&icon
);
419 /* we honor size hints by default */
420 c
->honorsizehints
= true;
423 property_update_wm_normal_hints(c
, NULL
);
424 property_update_wm_hints(c
, NULL
);
425 property_update_wm_transient_for(c
, NULL
);
428 screen
= c
->transient_for
->screen
;
430 /* Try to load props if any */
431 client_loadprops(c
, &globalconf
.screens
[screen
]);
433 /* move client to screen, but do not tag it for now */
434 screen_client_moveto(c
, screen
, false, true);
436 /* Then check clients hints */
437 ewmh_client_check_hints(c
);
439 /* Check if client has been tagged by loading props, or maybe with its
441 * If not, we tag it with current selected ones.
442 * This could be done on Lua side, but it's a sane behaviour. */
446 tag_array_t
*tags
= &globalconf
.screens
[screen
].tags
;
447 for(i
= 0; i
< tags
->len
; i
++)
448 if(is_client_tagged(c
, tags
->tab
[i
]))
451 /* if no tag, set current selected */
453 for(i
= 0; i
< tags
->len
; i
++)
454 if(tags
->tab
[i
]->selected
)
455 tag_client(c
, tags
->tab
[i
]);
458 /* Push client in client list */
459 client_list_push(&globalconf
.clients
, c
);
461 /* Push client in stack */
464 /* update window title */
465 property_update_wm_name(c
);
468 ewmh_client_strut_update(c
, NULL
);
470 ewmh_update_net_client_list(c
->phys_screen
);
471 widget_invalidate_cache(c
->screen
, WIDGET_CACHE_CLIENTS
);
474 luaA_client_userdata_new(globalconf
.L
, c
);
475 luaA_dofunction(globalconf
.L
, globalconf
.hooks
.manage
, 1, 0);
478 /** Compute client geometry with respect to its geometry hints.
479 * \param c The client.
480 * \param geometry The geometry that the client might receive.
481 * \return The geometry the client must take respecting its hints.
484 client_geometry_hints(client_t
*c
, area_t geometry
)
486 double dx
, dy
, max
, min
, ratio
;
488 if(c
->minay
> 0 && c
->maxay
> 0 && (geometry
.height
- c
->baseh
) > 0
489 && (geometry
.width
- c
->basew
) > 0)
491 dx
= (double) (geometry
.width
- c
->basew
);
492 dy
= (double) (geometry
.height
- c
->baseh
);
493 min
= (double) (c
->minax
) / (double) (c
->minay
);
494 max
= (double) (c
->maxax
) / (double) (c
->maxay
);
496 if(max
> 0 && min
> 0 && ratio
> 0)
500 dy
= (dx
* min
+ dy
) / (min
* min
+ 1);
502 geometry
.width
= (int) dx
+ c
->basew
;
503 geometry
.height
= (int) dy
+ c
->baseh
;
507 dy
= (dx
* min
+ dy
) / (max
* max
+ 1);
509 geometry
.width
= (int) dx
+ c
->basew
;
510 geometry
.height
= (int) dy
+ c
->baseh
;
514 if(c
->minw
&& geometry
.width
< c
->minw
)
515 geometry
.width
= c
->minw
;
516 if(c
->minh
&& geometry
.height
< c
->minh
)
517 geometry
.height
= c
->minh
;
518 if(c
->maxw
&& geometry
.width
> c
->maxw
)
519 geometry
.width
= c
->maxw
;
520 if(c
->maxh
&& geometry
.height
> c
->maxh
)
521 geometry
.height
= c
->maxh
;
523 geometry
.width
-= (geometry
.width
- c
->basew
) % c
->incw
;
525 geometry
.height
-= (geometry
.height
- c
->baseh
) % c
->inch
;
530 /** Resize client window.
531 * \param c Client to resize.
532 * \param geometry New window geometry.
533 * \param hints Use size hints.
536 client_resize(client_t
*c
, area_t geometry
, bool hints
)
540 layout_t
*layout
= layout_get_current(c
->screen
);
542 /* Values to configure a window is an array where values are
543 * stored according to 'value_mask' */
546 if(c
->titlebar
&& !c
->ismoving
&& !client_isfloating(c
) && layout
!= layout_floating
)
547 geometry
= titlebar_geometry_remove(c
->titlebar
, c
->border
, geometry
);
550 geometry
= client_geometry_hints(c
, geometry
);
552 if(geometry
.width
<= 0 || geometry
.height
<= 0)
555 /* offscreen appearance fixes */
556 area
= display_area_get(c
->phys_screen
, NULL
,
557 &globalconf
.screens
[c
->screen
].padding
);
559 fixed
= client_isfixed(c
);
561 if(geometry
.x
> area
.width
)
562 geometry
.x
= area
.width
- geometry
.width
- 2 * c
->border
;
563 if(geometry
.y
> area
.height
)
564 geometry
.y
= area
.height
- geometry
.height
- 2 * c
->border
;
565 if(geometry
.x
+ geometry
.width
+ 2 * c
->border
< 0)
567 if(geometry
.y
+ geometry
.height
+ 2 * c
->border
< 0)
570 /* fixed windows can only change their x,y */
571 if((fixed
&& (c
->geometry
.x
!= geometry
.x
|| c
->geometry
.y
!= geometry
.y
))
572 || (!fixed
&& (c
->geometry
.x
!= geometry
.x
573 || c
->geometry
.y
!= geometry
.y
574 || c
->geometry
.width
!= geometry
.width
575 || c
->geometry
.height
!= geometry
.height
)))
577 new_screen
= screen_getbycoord(c
->screen
, geometry
.x
, geometry
.y
);
579 c
->geometry
.x
= values
[0] = geometry
.x
;
580 c
->geometry
.width
= values
[2] = geometry
.width
;
581 c
->geometry
.y
= values
[1] = geometry
.y
;
582 c
->geometry
.height
= values
[3] = geometry
.height
;
583 values
[4] = c
->border
;
585 /* save the floating geometry if the window is floating but not
587 if(c
->ismoving
|| client_isfloating(c
)
588 || layout_get_current(new_screen
) == layout_floating
)
590 c
->f_geometry
= geometry
;
592 titlebar_update_geometry_floating(c
);
594 xcb_configure_window(globalconf
.connection
, c
->win
,
595 XCB_CONFIG_WINDOW_X
| XCB_CONFIG_WINDOW_Y
|
596 XCB_CONFIG_WINDOW_WIDTH
| XCB_CONFIG_WINDOW_HEIGHT
|
597 XCB_CONFIG_WINDOW_BORDER_WIDTH
,
599 window_configure(c
->win
, geometry
, c
->border
);
601 if(c
->screen
!= new_screen
)
602 screen_client_moveto(c
, new_screen
, true, false);
605 hooks_property(c
, "geometry");
609 /** Set a clinet floating.
610 * \param c The client.
611 * \param floating Set floating, or not.
612 * \param layer Layer to put the floating window onto.
615 client_setfloating(client_t
*c
, bool floating
)
617 if(c
->isfloating
!= floating
618 && (c
->type
== WINDOW_TYPE_NORMAL
))
620 if((c
->isfloating
= floating
))
622 client_resize(c
, c
->f_geometry
, false);
623 client_need_arrange(c
);
624 widget_invalidate_cache(c
->screen
, WIDGET_CACHE_CLIENTS
);
626 xcb_change_property(globalconf
.connection
,
627 XCB_PROP_MODE_REPLACE
,
628 c
->win
, _AWESOME_FLOATING
, CARDINAL
, 8, 1,
631 hooks_property(c
, "floating");
635 /** Set a client minimized, or not.
636 * \param c The client.
637 * \param s Set or not the client minimized.
640 client_setminimized(client_t
*c
, bool s
)
642 if(c
->isminimized
!= s
)
644 client_need_arrange(c
);
646 client_need_arrange(c
);
647 ewmh_client_update_hints(c
);
649 hooks_property(c
, "minimized");
653 /** Set a client sticky, or not.
654 * \param c The client.
655 * \param s Set or not the client sticky.
658 client_setsticky(client_t
*c
, bool s
)
662 client_need_arrange(c
);
664 client_need_arrange(c
);
665 ewmh_client_update_hints(c
);
666 hooks_property(c
, "sticky");
670 /** Set a client fullscreen, or not.
671 * \param c The client.
672 * \param s Set or not the client fullscreen.
675 client_setfullscreen(client_t
*c
, bool s
)
677 if(c
->isfullscreen
!= s
)
681 /* become fullscreen! */
682 if((c
->isfullscreen
= s
))
684 geometry
= screen_area_get(c
->screen
, NULL
, &globalconf
.screens
[c
->screen
].padding
, false);
685 c
->m_geometry
= c
->geometry
;
686 c
->oldborder
= c
->border
;
687 client_setborder(c
, 0);
691 geometry
= c
->m_geometry
;
692 client_setborder(c
, c
->oldborder
);
693 client_resize(c
, c
->m_geometry
, false);
695 client_resize(c
, geometry
, false);
696 client_need_arrange(c
);
698 xcb_change_property(globalconf
.connection
,
699 XCB_PROP_MODE_REPLACE
,
700 c
->win
, _AWESOME_FULLSCREEN
, CARDINAL
, 8, 1,
702 ewmh_client_update_hints(c
);
703 hooks_property(c
, "fullscreen");
707 /** Set a client above, or not.
708 * \param c The client.
709 * \param s Set or not the client above.
712 client_setabove(client_t
*c
, bool s
)
718 ewmh_client_update_hints(c
);
720 hooks_property(c
, "above");
724 /** Set a client below, or not.
725 * \param c The client.
726 * \param s Set or not the client below.
729 client_setbelow(client_t
*c
, bool s
)
735 ewmh_client_update_hints(c
);
737 hooks_property(c
, "below");
741 /** Set a client modal, or not.
742 * \param c The client.
743 * \param s Set or not the client moda.
746 client_setmodal(client_t
*c
, bool s
)
752 ewmh_client_update_hints(c
);
754 hooks_property(c
, "modal");
758 /** Set a client ontop, or not.
759 * \param c The client.
760 * \param s Set or not the client moda.
763 client_setontop(client_t
*c
, bool s
)
770 hooks_property(c
, "ontop");
774 /** Save client properties as an X property.
775 * \param c The client.
778 client_saveprops_tags(client_t
*c
)
780 tag_array_t
*tags
= &globalconf
.screens
[c
->screen
].tags
;
781 unsigned char *prop
= p_alloca(unsigned char, tags
->len
+ 1);
784 for(i
= 0; i
< tags
->len
; i
++)
785 prop
[i
] = is_client_tagged(c
, tags
->tab
[i
]) ? '1' : '0';
787 xcb_change_property(globalconf
.connection
, XCB_PROP_MODE_REPLACE
, c
->win
, _AWESOME_TAGS
, STRING
, 8, i
, prop
);
791 * \param c The client.
794 client_unban(client_t
*c
)
796 xcb_map_window(globalconf
.connection
, c
->win
);
797 window_state_set(c
->win
, XCB_WM_STATE_NORMAL
);
800 if(c
->isfullscreen
|| !c
->titlebar
->isvisible
)
801 xcb_unmap_window(globalconf
.connection
, c
->titlebar
->sw
.window
);
803 xcb_map_window(globalconf
.connection
, c
->titlebar
->sw
.window
);
807 /** Unmanage a client.
808 * \param c The client.
811 client_unmanage(client_t
*c
)
813 tag_array_t
*tags
= &globalconf
.screens
[c
->screen
].tags
;
815 if(globalconf
.screens
[c
->phys_screen
].client_focus
== c
)
819 luaA_client_userdata_new(globalconf
.L
, c
);
820 luaA_dofunction(globalconf
.L
, globalconf
.hooks
.unmanage
, 1, 0);
822 /* The server grab construct avoids race conditions. */
823 xcb_grab_server(globalconf
.connection
);
825 xcb_configure_window(globalconf
.connection
, c
->win
,
826 XCB_CONFIG_WINDOW_BORDER_WIDTH
,
827 (uint32_t *) &c
->oldborder
);
829 xcb_ungrab_button(globalconf
.connection
, XCB_BUTTON_INDEX_ANY
, c
->win
,
830 XCB_BUTTON_MASK_ANY
);
831 window_state_set(c
->win
, XCB_WM_STATE_WITHDRAWN
);
833 xcb_flush(globalconf
.connection
);
834 xcb_ungrab_server(globalconf
.connection
);
836 /* remove client everywhere */
837 client_list_detach(&globalconf
.clients
, c
);
838 stack_client_delete(c
);
839 for(int i
= 0; i
< tags
->len
; i
++)
840 untag_client(c
, tags
->tab
[i
]);
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 XKillClient if not
867 * \param c The client to kill.
870 client_kill(client_t
*c
)
872 xcb_client_message_event_t ev
;
874 if(window_isprotodel(c
->win
))
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
);
1036 widget_invalidate_cache((*c
)->screen
, WIDGET_CACHE_CLIENTS
);
1037 widget_invalidate_cache((*swap
)->screen
, WIDGET_CACHE_CLIENTS
);
1041 /** Access or set the client tags.
1042 * \param L The Lua VM state.
1043 * \return The number of elements pushed on stack.
1044 * \lparam A table with tags to set, or none to get the current tags table.
1045 * \return The clients tag.
1048 luaA_client_tags(lua_State
*L
)
1052 client_t
**c
= luaA_checkudata(L
, 1, "client");
1055 if(lua_gettop(L
) == 2)
1057 luaA_checktable(L
, 2);
1058 tags
= &globalconf
.screens
[(*c
)->screen
].tags
;
1059 for(int i
= 0; i
< tags
->len
; i
++)
1060 untag_client(*c
, tags
->tab
[i
]);
1062 while(lua_next(L
, 2))
1064 tag
= luaA_checkudata(L
, -1, "tag");
1065 tag_client(*c
, *tag
);
1071 tags
= &globalconf
.screens
[(*c
)->screen
].tags
;
1073 for(int i
= 0; i
< tags
->len
; i
++)
1074 if(is_client_tagged(*c
, tags
->tab
[i
]))
1076 luaA_tag_userdata_new(L
, tags
->tab
[i
]);
1077 lua_rawseti(L
, -2, ++j
);
1083 /** Raise a client on top of others which are on the same layer.
1084 * \param L The Lua VM state.
1090 luaA_client_raise(lua_State
*L
)
1092 client_t
**c
= luaA_checkudata(L
, 1, "client");
1097 /** Redraw a client by unmapping and mapping it quickly.
1098 * \param L The Lua VM state.
1104 luaA_client_redraw(lua_State
*L
)
1106 client_t
**c
= luaA_checkudata(L
, 1, "client");
1108 xcb_unmap_window(globalconf
.connection
, (*c
)->win
);
1109 xcb_map_window(globalconf
.connection
, (*c
)->win
);
1111 /* Set the focus on the current window if the redraw has been
1112 performed on the window where the pointer is currently on
1113 because after the unmapping/mapping, the focus is lost */
1114 if(globalconf
.screen_focus
->client_focus
== *c
)
1115 xcb_set_input_focus(globalconf
.connection
, XCB_INPUT_FOCUS_POINTER_ROOT
,
1116 (*c
)->win
, XCB_CURRENT_TIME
);
1121 /** Return a formated string for a client.
1122 * \param L The Lua VM state.
1125 * \lreturn A string.
1128 luaA_client_tostring(lua_State
*L
)
1130 client_t
**p
= luaA_checkudata(L
, 1, "client");
1131 lua_pushfstring(L
, "[client udata(%p) name(%s)]", *p
, (*p
)->name
);
1135 /** Stop managing a client.
1136 * \param L The Lua VM state.
1137 * \return The number of elements pushed on stack.
1142 luaA_client_unmanage(lua_State
*L
)
1144 client_t
**c
= luaA_checkudata(L
, 1, "client");
1145 client_unmanage(*c
);
1149 /** Return client coordinates.
1150 * \param L The Lua VM state.
1151 * \return The number of elements pushed on stack.
1153 * \lparam A table with new coordinates, or none.
1154 * \lreturn A table with client coordinates.
1157 luaA_client_coords(lua_State
*L
)
1159 client_t
**c
= luaA_checkudata(L
, 1, "client");
1161 if(lua_gettop(L
) == 2)
1163 if((*c
)->isfloating
|| layout_get_current((*c
)->screen
) == layout_floating
)
1167 luaA_checktable(L
, 2);
1168 geometry
.x
= luaA_getopt_number(L
, 2, "x", (*c
)->geometry
.x
);
1169 geometry
.y
= luaA_getopt_number(L
, 2, "y", (*c
)->geometry
.y
);
1170 geometry
.width
= luaA_getopt_number(L
, 2, "width", (*c
)->geometry
.width
);
1171 geometry
.height
= luaA_getopt_number(L
, 2, "height", (*c
)->geometry
.height
);
1172 client_resize(*c
, geometry
, false);
1176 return luaA_pusharea(L
, (*c
)->geometry
);
1179 /** Return client coordinates, using also titlebar and border width.
1180 * \param L The Lua VM state.
1181 * \return The number of elements pushed on stack.
1183 * \lparam A table with new coordinates, or none.
1184 * \lreturn A table with client coordinates.
1187 luaA_client_fullcoords(lua_State
*L
)
1189 client_t
**c
= luaA_checkudata(L
, 1, "client");
1192 if(lua_gettop(L
) == 2)
1194 if((*c
)->isfloating
|| layout_get_current((*c
)->screen
) == layout_floating
)
1196 luaA_checktable(L
, 2);
1197 geometry
.x
= luaA_getopt_number(L
, 2, "x", (*c
)->geometry
.x
);
1198 geometry
.y
= luaA_getopt_number(L
, 2, "y", (*c
)->geometry
.y
);
1199 geometry
.width
= luaA_getopt_number(L
, 2, "width", (*c
)->geometry
.width
);
1200 geometry
.height
= luaA_getopt_number(L
, 2, "height", (*c
)->geometry
.height
);
1201 geometry
= titlebar_geometry_remove((*c
)->titlebar
,
1204 client_resize(*c
, geometry
, false);
1208 return luaA_pusharea(L
, titlebar_geometry_add((*c
)->titlebar
,
1213 /** Client newindex.
1214 * \param L The Lua VM state.
1215 * \return The number of elements pushed on stack.
1218 luaA_client_newindex(lua_State
*L
)
1221 client_t
**c
= luaA_checkudata(L
, 1, "client");
1222 const char *buf
= luaL_checklstring(L
, 2, &len
);
1230 luaL_error(L
, "client is invalid\n");
1232 switch(a_tokenize(buf
, len
))
1235 buf
= luaL_checklstring(L
, 3, &len
);
1236 p_delete(&(*c
)->name
);
1237 a_iso2utf8(&(*c
)->name
, buf
, len
);
1238 widget_invalidate_cache((*c
)->screen
, WIDGET_CACHE_CLIENTS
);
1241 if(globalconf
.xinerama_is_active
)
1243 i
= luaL_checknumber(L
, 3) - 1;
1244 luaA_checkscreen(i
);
1245 if(i
!= (*c
)->screen
)
1246 screen_client_moveto(*c
, i
, true, true);
1250 b
= luaA_checkboolean(L
, 3);
1251 if(b
!= (*c
)->ishidden
)
1253 client_need_arrange(*c
);
1255 client_need_arrange(*c
);
1259 client_setminimized(*c
, luaA_checkboolean(L
, 3));
1261 case A_TK_FULLSCREEN
:
1262 client_setfullscreen(*c
, luaA_checkboolean(L
, 3));
1265 image
= luaA_checkudata(L
, 3, "image");
1266 image_unref(&(*c
)->icon
);
1268 (*c
)->icon
= *image
;
1269 widget_invalidate_cache((*c
)->screen
, WIDGET_CACHE_CLIENTS
);
1273 window_opacity_set((*c
)->win
, -1);
1276 d
= luaL_checknumber(L
, 3);
1277 if(d
>= 0 && d
<= 1)
1278 window_opacity_set((*c
)->win
, d
);
1282 client_setfloating(*c
, luaA_checkboolean(L
, 3));
1285 client_setsticky(*c
, luaA_checkboolean(L
, 3));
1287 case A_TK_HONORSIZEHINTS
:
1288 (*c
)->honorsizehints
= luaA_checkboolean(L
, 3);
1289 client_need_arrange(*c
);
1291 case A_TK_BORDER_WIDTH
:
1292 client_setborder(*c
, luaL_checknumber(L
, 3));
1295 client_setontop(*c
, luaA_checkboolean(L
, 3));
1297 case A_TK_BORDER_COLOR
:
1298 if((buf
= luaL_checklstring(L
, 3, &len
))
1299 && xcolor_init_reply(xcolor_init_unchecked(&(*c
)->border_color
, buf
, len
)))
1300 xcb_change_window_attributes(globalconf
.connection
, (*c
)->win
,
1301 XCB_CW_BORDER_PIXEL
, &(*c
)->border_color
.pixel
);
1305 titlebar_client_detach(*c
);
1308 t
= luaA_checkudata(L
, 3, "wibox");
1309 titlebar_client_attach(*c
, *t
);
1320 * \param L The Lua VM state.
1321 * \return The number of elements pushed on stack.
1323 * \lfield name The client title.
1324 * \lfield type The window type (desktop, normal, dock, …).
1325 * \lfield class The client class.
1326 * \lfield instance The client instance.
1327 * \lfield pid The client PID, if available.
1328 * \lfield role The window role, if available.
1329 * \lfield machine The machine client is running on.
1330 * \lfield icon_name The client name when iconified.
1331 * \lfield screen Client screen number.
1332 * \lfield hide Define if the client must be hidden, i.e. never mapped, not
1333 * visible in taskbar.
1334 * invisible in taskbar.
1335 * \lfield minimize Define it the client must be iconify, i.e. only visible in
1337 * \lfield icon_path Path to the icon used to identify.
1338 * \lfield floating True always floating.
1339 * \lfield honorsizehints Honor size hints, i.e. respect size ratio.
1340 * \lfield border_width The client border width.
1341 * \lfield border_color The client border color.
1342 * \lfield titlebar The client titlebar.
1343 * \lfield urgent The client urgent state.
1344 * \lfield focus The focused client.
1345 * \lfield opacity The client opacity between 0 and 1.
1346 * \lfield ontop The client is on top of every other windows.
1347 * \lfield fullscreen The client is fullscreen or not.
1350 luaA_client_index(lua_State
*L
)
1354 client_t
**c
= luaA_checkudata(L
, 1, "client");
1355 const char *buf
= luaL_checklstring(L
, 2, &len
);
1358 xcb_get_wm_class_reply_t hint
;
1359 xcb_get_property_cookie_t prop_c
;
1360 xcb_get_property_reply_t
*prop_r
= NULL
;
1364 luaL_error(L
, "client is invalid\n");
1366 if(luaA_usemetatable(L
, 1, 2))
1369 switch(a_tokenize(buf
, len
))
1372 lua_pushstring(L
, (*c
)->name
);
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 if(!xutil_text_prop_get(globalconf
.connection
, (*c
)->win
,
1438 _NET_WM_ICON_NAME
, &value
, &slen
))
1439 if(!xutil_text_prop_get(globalconf
.connection
, (*c
)->win
,
1440 WM_ICON_NAME
, &value
, &slen
))
1442 lua_pushlstring(L
, value
, slen
);
1446 lua_pushnumber(L
, 1 + (*c
)->screen
);
1449 lua_pushboolean(L
, (*c
)->ishidden
);
1452 lua_pushboolean(L
, (*c
)->isminimized
);
1454 case A_TK_FULLSCREEN
:
1455 lua_pushboolean(L
, (*c
)->isfullscreen
);
1459 luaA_image_userdata_new(L
, (*c
)->icon
);
1464 if((d
= window_opacity_get((*c
)->win
)) >= 0)
1465 lua_pushnumber(L
, d
);
1470 lua_pushboolean(L
, (*c
)->isfloating
);
1473 lua_pushboolean(L
, (*c
)->isontop
);
1476 lua_pushboolean(L
, (*c
)->issticky
);
1478 case A_TK_HONORSIZEHINTS
:
1479 lua_pushboolean(L
, (*c
)->honorsizehints
);
1481 case A_TK_BORDER_WIDTH
:
1482 lua_pushnumber(L
, (*c
)->border
);
1484 case A_TK_BORDER_COLOR
:
1485 luaA_pushcolor(L
, &(*c
)->border_color
);
1489 return luaA_wibox_userdata_new(L
, (*c
)->titlebar
);
1492 lua_pushboolean(L
, (*c
)->isurgent
);
1501 /** Get or set mouse buttons bindings for a client.
1502 * \param L The Lua VM state.
1503 * \return The number of element pushed on stack.
1506 * \lparam An array of mouse button bindings objects, or nothing.
1507 * \return The array of mouse button bindings objects of this client.
1510 luaA_client_buttons(lua_State
*L
)
1512 client_t
**client
= luaA_checkudata(L
, 1, "client");
1513 button_array_t
*buttons
= &(*client
)->buttons
;
1515 if(lua_gettop(L
) == 2)
1516 luaA_button_array_set(L
, 2, buttons
);
1518 return luaA_button_array_get(L
, buttons
);
1522 * \param L The Lua VM state.
1523 * \return The number of pushed elements.
1526 luaA_client_module_index(lua_State
*L
)
1529 const char *buf
= luaL_checklstring(L
, 2, &len
);
1531 switch(a_tokenize(buf
, len
))
1534 if(globalconf
.screen_focus
->client_focus
)
1535 luaA_client_userdata_new(L
, globalconf
.screen_focus
->client_focus
);
1546 /* Client module new index.
1547 * \param L The Lua VM state.
1548 * \return The number of pushed elements.
1551 luaA_client_module_newindex(lua_State
*L
)
1554 const char *buf
= luaL_checklstring(L
, 2, &len
);
1557 switch(a_tokenize(buf
, len
))
1560 c
= luaA_checkudata(L
, 3, "client");
1570 const struct luaL_reg awesome_client_methods
[] =
1572 { "get", luaA_client_get
},
1573 { "visible_get", luaA_client_visible_get
},
1574 { "__index", luaA_client_module_index
},
1575 { "__newindex", luaA_client_module_newindex
},
1578 const struct luaL_reg awesome_client_meta
[] =
1580 { "isvisible", luaA_client_isvisible
},
1581 { "coords", luaA_client_coords
},
1582 { "fullcoords", luaA_client_fullcoords
},
1583 { "buttons", luaA_client_buttons
},
1584 { "tags", luaA_client_tags
},
1585 { "kill", luaA_client_kill
},
1586 { "swap", luaA_client_swap
},
1587 { "raise", luaA_client_raise
},
1588 { "redraw", luaA_client_redraw
},
1589 { "mouse_resize", luaA_client_mouse_resize
},
1590 { "mouse_move", luaA_client_mouse_move
},
1591 { "unmanage", luaA_client_unmanage
},
1592 { "__index", luaA_client_index
},
1593 { "__newindex", luaA_client_newindex
},
1594 { "__eq", luaA_client_eq
},
1595 { "__gc", luaA_client_gc
},
1596 { "__tostring", luaA_client_tostring
},
1600 // vim: filetype=c:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=80