2 * client.c - client management
4 * Copyright © 2007-2009 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>
23 #include <xcb/xcb_image.h>
32 #include "common/atoms.h"
33 #include "common/xutil.h"
35 DO_LUA_TOSTRING(client_t
, client
, "client")
38 luaA_client_checkudata(lua_State
*L
, int ud
)
40 client_t
*c
= luaL_checkudata(L
, ud
, "client");
42 luaL_error(L
, "client is invalid\n");
47 * \param L The Lua VM state.
48 * \return The number of element pushed on stack.
51 luaA_client_gc(lua_State
*L
)
53 client_t
*c
= luaL_checkudata(L
, 1, "client");
54 luaA_ref_array_wipe(&c
->refs
);
55 button_array_wipe(&c
->buttons
);
56 image_unref(L
, c
->icon
);
58 p_delete(&c
->startup_id
);
59 p_delete(&c
->instance
);
60 p_delete(&c
->icon_name
);
65 /** Change the clients urgency flag.
67 * \param urgent The new flag state
70 client_seturgent(client_t
*c
, bool urgent
)
72 if(c
->isurgent
!= urgent
)
74 xcb_get_property_cookie_t hints
=
75 xcb_get_wm_hints_unchecked(globalconf
.connection
, c
->win
);
78 ewmh_client_update_hints(c
);
80 /* update ICCCM hints */
82 xcb_get_wm_hints_reply(globalconf
.connection
, hints
, &wmh
, NULL
);
85 wmh
.flags
|= XCB_WM_HINT_X_URGENCY
;
87 wmh
.flags
&= ~XCB_WM_HINT_X_URGENCY
;
89 xcb_set_wm_hints(globalconf
.connection
, c
->win
, &wmh
);
91 hook_property(client
, c
, "urgent");
95 /** Returns true if a client is tagged
96 * with one of the tags of the specified screen.
97 * \param c The client to check.
98 * \param screen Virtual screen.
99 * \return true if the client is visible, false otherwise.
102 client_maybevisible(client_t
*c
, screen_t
*screen
)
104 if(c
->screen
== screen
)
106 if(c
->issticky
|| c
->type
== WINDOW_TYPE_DESKTOP
)
109 foreach(tag
, screen
->tags
)
110 if((*tag
)->selected
&& is_client_tagged(c
, *tag
))
116 /** Return the content of a client as an image.
117 * That's just take a screenshot.
118 * \param c The client.
119 * \return 1 if the image has been pushed on stack, false otherwise.
122 client_getcontent(client_t
*c
)
124 xcb_image_t
*ximage
= xcb_image_get(globalconf
.connection
,
127 c
->geometries
.internal
.width
,
128 c
->geometries
.internal
.height
,
129 ~0, XCB_IMAGE_FORMAT_Z_PIXMAP
);
134 if(ximage
->bpp
>= 24)
136 uint32_t *data
= p_alloca(uint32_t, ximage
->width
* ximage
->height
);
138 for(int y
= 0; y
< ximage
->height
; y
++)
139 for(int x
= 0; x
< ximage
->width
; x
++)
141 data
[y
* ximage
->width
+ x
] = xcb_image_get_pixel(ximage
, x
, y
);
142 data
[y
* ximage
->width
+ x
] |= 0xff000000; /* set alpha to 0xff */
145 retval
= image_new_from_argb32(ximage
->width
, ximage
->height
, data
);
147 xcb_image_destroy(ximage
);
153 /** Get a client by its window.
154 * \param w The client window to find.
155 * \return A client pointer if found, NULL otherwise.
158 client_getbywin(xcb_window_t w
)
160 foreach(c
, globalconf
.clients
)
167 /** Record that a client lost focus.
168 * \param c Client being unfocused
171 client_unfocus_update(client_t
*c
)
173 globalconf
.screens
.tab
[c
->phys_screen
].client_focus
= NULL
;
174 ewmh_update_net_active_window(c
->phys_screen
);
177 if(globalconf
.hooks
.unfocus
!= LUA_REFNIL
)
179 client_push(globalconf
.L
, c
);
180 luaA_dofunction_from_registry(globalconf
.L
, globalconf
.hooks
.unfocus
, 1, 0);
185 /** Unfocus a client.
186 * \param c The client.
189 client_unfocus(client_t
*c
)
192 xcb_window_t root_win
= xutil_screen_get(globalconf
.connection
, c
->phys_screen
)->root
;
193 /* Set focus on root window, so no events leak to the current window. */
194 window_setfocus(root_win
, true);
196 client_unfocus_update(c
);
199 /** Ban client and move it out of the viewport.
200 * \param c The client.
203 client_ban(client_t
*c
)
207 xcb_unmap_window(globalconf
.connection
, c
->win
);
211 if(globalconf
.screens
.tab
[c
->phys_screen
].prev_client_focus
== c
)
212 globalconf
.screens
.tab
[c
->phys_screen
].prev_client_focus
= NULL
;
214 /* Wait until the last moment to take away the focus from the window. */
215 if(globalconf
.screens
.tab
[c
->phys_screen
].client_focus
== c
)
220 /** Record that a client got focus.
221 * \param c Client being focused.
224 client_focus_update(client_t
*c
)
226 if(!client_maybevisible(c
, c
->screen
))
228 /* Focus previously focused client */
229 client_focus(globalconf
.screen_focus
->prev_client_focus
);
233 if(globalconf
.screen_focus
234 && globalconf
.screen_focus
->client_focus
)
236 if (globalconf
.screen_focus
->client_focus
!= c
)
237 client_unfocus_update(globalconf
.screen_focus
->client_focus
);
239 /* Already focused */
242 /* stop hiding client */
244 client_setminimized(c
, false);
246 /* unban the client before focusing for consistency */
249 globalconf
.screen_focus
= &globalconf
.screens
.tab
[c
->phys_screen
];
250 globalconf
.screen_focus
->prev_client_focus
= c
;
251 globalconf
.screen_focus
->client_focus
= c
;
253 /* according to EWMH, we have to remove the urgent state from a client */
254 client_seturgent(c
, false);
256 ewmh_update_net_active_window(c
->phys_screen
);
259 if(globalconf
.hooks
.focus
!= LUA_REFNIL
)
261 client_push(globalconf
.L
, c
);
262 luaA_dofunction_from_registry(globalconf
.L
, globalconf
.hooks
.focus
, 1, 0);
267 /** Give focus to client, or to first client if client is NULL.
268 * \param c The client or NULL.
271 client_focus(client_t
*c
)
273 /* We have to set focus on first client */
274 if(!c
&& globalconf
.clients
.len
&& !(c
= globalconf
.clients
.tab
[0]))
277 if(!client_maybevisible(c
, c
->screen
))
281 client_focus_update(c
);
283 window_setfocus(c
->win
, !c
->nofocus
);
286 /** Stack a window below.
287 * \param c The client.
288 * \param previous The previous window on the stack.
289 * \param return The next-previous!
292 client_stack_above(client_t
*c
, xcb_window_t previous
)
294 uint32_t config_win_vals
[2];
296 config_win_vals
[0] = previous
;
297 config_win_vals
[1] = XCB_STACK_MODE_ABOVE
;
299 xcb_configure_window(globalconf
.connection
, c
->win
,
300 XCB_CONFIG_WINDOW_SIBLING
| XCB_CONFIG_WINDOW_STACK_MODE
,
303 config_win_vals
[0] = c
->win
;
307 xcb_configure_window(globalconf
.connection
,
308 c
->titlebar
->sw
.window
,
309 XCB_CONFIG_WINDOW_SIBLING
| XCB_CONFIG_WINDOW_STACK_MODE
,
311 previous
= c
->titlebar
->sw
.window
;
316 /* stack transient window on top of their parents */
317 foreach(node
, globalconf
.stack
)
318 if((*node
)->transient_for
== c
)
319 previous
= client_stack_above(*node
, previous
);
324 /** Stacking layout layers */
327 /** This one is a special layer */
335 /** This one only used for counting and is not a real layer */
339 /** Get the real layer of a client according to its attribute (fullscreen, …)
340 * \param c The client.
341 * \return The real layer.
344 client_layer_translator(client_t
*c
)
346 /* first deal with user set attributes */
349 else if(c
->isfullscreen
)
350 return LAYER_FULLSCREEN
;
356 /* check for transient attr */
360 /* then deal with windows type */
363 case WINDOW_TYPE_DESKTOP
:
364 return LAYER_DESKTOP
;
373 * \todo It might be worth stopping to restack everyone and only stack `c'
374 * relatively to the first matching in the list.
377 client_real_stack(void)
379 uint32_t config_win_vals
[2];
382 config_win_vals
[0] = XCB_NONE
;
383 config_win_vals
[1] = XCB_STACK_MODE_ABOVE
;
385 /* stack desktop windows */
386 for(layer
= LAYER_DESKTOP
; layer
< LAYER_BELOW
; layer
++)
387 foreach(node
, globalconf
.stack
)
388 if(client_layer_translator(*node
) == layer
)
389 config_win_vals
[0] = client_stack_above(*node
,
392 /* first stack not ontop wibox window */
393 foreach(_sb
, globalconf
.wiboxes
)
398 xcb_configure_window(globalconf
.connection
,
400 XCB_CONFIG_WINDOW_SIBLING
| XCB_CONFIG_WINDOW_STACK_MODE
,
402 config_win_vals
[0] = sb
->sw
.window
;
406 /* then stack clients */
407 for(layer
= LAYER_BELOW
; layer
< LAYER_COUNT
; layer
++)
408 foreach(node
, globalconf
.stack
)
409 if(client_layer_translator(*node
) == layer
)
410 config_win_vals
[0] = client_stack_above(*node
,
413 /* then stack ontop wibox window */
414 foreach(_sb
, globalconf
.wiboxes
)
419 xcb_configure_window(globalconf
.connection
,
421 XCB_CONFIG_WINDOW_SIBLING
| XCB_CONFIG_WINDOW_STACK_MODE
,
423 config_win_vals
[0] = sb
->sw
.window
;
429 client_stack_refresh()
431 if (!globalconf
.client_need_stack_refresh
)
433 globalconf
.client_need_stack_refresh
= false;
437 /** Manage a new client.
438 * \param w The window.
439 * \param wgeom Window geometry.
440 * \param phys_screen Physical screen number.
441 * \param startup True if we are managing at startup time.
444 client_manage(xcb_window_t w
, xcb_get_geometry_reply_t
*wgeom
, int phys_screen
, bool startup
)
446 xcb_get_property_cookie_t ewmh_icon_cookie
;
447 client_t
*c
, *tc
= NULL
;
449 const uint32_t select_input_val
[] = { CLIENT_SELECT_INPUT_EVENT_MASK
};
451 if(systray_iskdedockapp(w
))
453 systray_request_handle(w
, phys_screen
, NULL
);
457 /* Send request to get NET_WM_ICON property as soon as possible... */
458 ewmh_icon_cookie
= ewmh_window_icon_get_unchecked(w
);
459 xcb_change_window_attributes(globalconf
.connection
, w
, XCB_CW_EVENT_MASK
, select_input_val
);
461 c
= client_new(globalconf
.L
);
462 /* Push client in client list */
463 client_array_push(&globalconf
.clients
, client_ref(globalconf
.L
));
466 screen
= c
->screen
= screen_getbycoord(&globalconf
.screens
.tab
[phys_screen
],
469 c
->phys_screen
= phys_screen
;
471 /* consider the window banned */
476 c
->geometry
.x
= wgeom
->x
;
477 c
->geometry
.y
= wgeom
->y
;
478 /* Border will be added later. */
479 c
->geometry
.width
= wgeom
->width
;
480 c
->geometry
.height
= wgeom
->height
;
481 /* Also set internal geometry (client_ban() needs it). */
482 c
->geometries
.internal
.x
= wgeom
->x
;
483 c
->geometries
.internal
.y
= wgeom
->y
;
484 c
->geometries
.internal
.width
= wgeom
->width
;
485 c
->geometries
.internal
.height
= wgeom
->height
;
486 client_setborder(c
, wgeom
->border_width
);
488 if(ewmh_window_icon_get_reply(ewmh_icon_cookie
))
489 c
->icon
= image_ref(globalconf
.L
);
491 /* we honor size hints by default */
492 c
->size_hints_honor
= true;
495 property_update_wm_normal_hints(c
, NULL
);
496 property_update_wm_hints(c
, NULL
);
497 property_update_wm_transient_for(c
, NULL
);
498 property_update_wm_client_leader(c
, NULL
);
500 /* Recursively find the parent. */
501 for(tc
= c
; tc
->transient_for
; tc
= tc
->transient_for
);
502 if(tc
!= c
&& tc
->phys_screen
== c
->phys_screen
)
505 /* Then check clients hints */
506 ewmh_client_check_hints(c
);
508 /* move client to screen, but do not tag it */
509 screen_client_moveto(c
, screen
, false, true);
511 /* Push client in stack */
514 /* update window title */
515 property_update_wm_name(c
);
516 property_update_wm_icon_name(c
);
517 property_update_wm_class(c
, NULL
);
519 xutil_text_prop_get(globalconf
.connection
, c
->win
, _NET_STARTUP_ID
, &c
->startup_id
, NULL
);
522 ewmh_process_client_strut(c
, NULL
);
524 ewmh_update_net_client_list(c
->phys_screen
);
526 /* Always stay in NORMAL_STATE. Even though iconified seems more
527 * appropriate sometimes. The only possible loss is that clients not using
528 * visibility events may continue to proces data (when banned).
529 * Without any exposes or other events the cost should be fairly limited though.
531 * Some clients may expect the window to be unmapped when STATE_ICONIFIED.
532 * Two conflicting parts of the ICCCM v2.0 (section 4.1.4):
534 * "Normal -> Iconic - The client should send a ClientMessage event as described later in this section."
535 * (note no explicit mention of unmapping, while Normal->Widthdrawn does mention that)
537 * "Once a client's window has left the Withdrawn state, the window will be mapped
538 * if it is in the Normal state and the window will be unmapped if it is in the Iconic state."
540 * At this stage it's just safer to keep it in normal state and avoid confusion.
542 window_state_set(c
->win
, XCB_WM_STATE_NORMAL
);
545 spawn_start_notify(c
);
547 /* Call hook to notify list change */
548 if(globalconf
.hooks
.clients
!= LUA_REFNIL
)
549 luaA_dofunction_from_registry(globalconf
.L
, globalconf
.hooks
.clients
, 0, 0);
552 if(globalconf
.hooks
.manage
!= LUA_REFNIL
)
554 client_push(globalconf
.L
, c
);
555 lua_pushboolean(globalconf
.L
, startup
);
556 luaA_dofunction_from_registry(globalconf
.L
, globalconf
.hooks
.manage
, 2, 0);
560 /** Compute client geometry with respect to its geometry hints.
561 * \param c The client.
562 * \param geometry The geometry that the client might receive.
563 * \return The geometry the client must take respecting its hints.
566 client_geometry_hints(client_t
*c
, area_t geometry
)
568 int32_t basew
, baseh
, minw
, minh
;
570 /* base size is substituted with min size if not specified */
571 if(c
->size_hints
.flags
& XCB_SIZE_HINT_P_SIZE
)
573 basew
= c
->size_hints
.base_width
;
574 baseh
= c
->size_hints
.base_height
;
576 else if(c
->size_hints
.flags
& XCB_SIZE_HINT_P_MIN_SIZE
)
578 basew
= c
->size_hints
.min_width
;
579 baseh
= c
->size_hints
.min_height
;
584 /* min size is substituted with base size if not specified */
585 if(c
->size_hints
.flags
& XCB_SIZE_HINT_P_MIN_SIZE
)
587 minw
= c
->size_hints
.min_width
;
588 minh
= c
->size_hints
.min_height
;
590 else if(c
->size_hints
.flags
& XCB_SIZE_HINT_P_SIZE
)
592 minw
= c
->size_hints
.base_width
;
593 minh
= c
->size_hints
.base_height
;
598 if(c
->size_hints
.flags
& XCB_SIZE_HINT_P_ASPECT
599 && c
->size_hints
.min_aspect_num
> 0
600 && c
->size_hints
.min_aspect_den
> 0
601 && geometry
.height
- baseh
> 0
602 && geometry
.width
- basew
> 0)
604 double dx
= (double) (geometry
.width
- basew
);
605 double dy
= (double) (geometry
.height
- baseh
);
606 double min
= (double) c
->size_hints
.min_aspect_num
/ (double) c
->size_hints
.min_aspect_den
;
607 double max
= (double) c
->size_hints
.max_aspect_num
/ (double) c
->size_hints
.min_aspect_den
;
608 double ratio
= dx
/ dy
;
609 if(max
> 0 && min
> 0 && ratio
> 0)
613 dy
= (dx
* min
+ dy
) / (min
* min
+ 1);
615 geometry
.width
= (int) dx
+ basew
;
616 geometry
.height
= (int) dy
+ baseh
;
620 dy
= (dx
* min
+ dy
) / (max
* max
+ 1);
622 geometry
.width
= (int) dx
+ basew
;
623 geometry
.height
= (int) dy
+ baseh
;
629 geometry
.width
= MAX(geometry
.width
, minw
);
631 geometry
.height
= MAX(geometry
.height
, minh
);
633 if(c
->size_hints
.flags
& XCB_SIZE_HINT_P_MAX_SIZE
)
635 if(c
->size_hints
.max_width
)
636 geometry
.width
= MIN(geometry
.width
, c
->size_hints
.max_width
);
637 if(c
->size_hints
.max_height
)
638 geometry
.height
= MIN(geometry
.height
, c
->size_hints
.max_height
);
641 if(c
->size_hints
.flags
& (XCB_SIZE_HINT_P_RESIZE_INC
| XCB_SIZE_HINT_BASE_SIZE
)
642 && c
->size_hints
.width_inc
&& c
->size_hints
.height_inc
)
644 uint16_t t1
= geometry
.width
, t2
= geometry
.height
;
645 unsigned_subtract(t1
, basew
);
646 unsigned_subtract(t2
, baseh
);
647 geometry
.width
-= t1
% c
->size_hints
.width_inc
;
648 geometry
.height
-= t2
% c
->size_hints
.height_inc
;
654 /** Resize client window.
655 * The sizse given as parameters are with titlebar and borders!
656 * \param c Client to resize.
657 * \param geometry New window geometry.
658 * \param hints Use size hints.
659 * \return true if an actual resize occurred.
662 client_resize(client_t
*c
, area_t geometry
, bool hints
)
664 area_t geometry_internal
;
667 /* offscreen appearance fixes */
668 area
= display_area_get(c
->phys_screen
);
670 if(geometry
.x
> area
.width
)
671 geometry
.x
= area
.width
- geometry
.width
;
672 if(geometry
.y
> area
.height
)
673 geometry
.y
= area
.height
- geometry
.height
;
674 if(geometry
.x
+ geometry
.width
< 0)
676 if(geometry
.y
+ geometry
.height
< 0)
679 /* Real client geometry, please keep it contained to C code at the very least. */
680 geometry_internal
= titlebar_geometry_remove(c
->titlebar
, c
->border
, geometry
);
683 geometry_internal
= client_geometry_hints(c
, geometry_internal
);
685 if(geometry_internal
.width
== 0 || geometry_internal
.height
== 0)
688 /* Also let client hints propegate to the "official" geometry. */
689 geometry
= titlebar_geometry_add(c
->titlebar
, c
->border
, geometry_internal
);
691 if(c
->geometries
.internal
.x
!= geometry_internal
.x
692 || c
->geometries
.internal
.y
!= geometry_internal
.y
693 || c
->geometries
.internal
.width
!= geometry_internal
.width
694 || c
->geometries
.internal
.height
!= geometry_internal
.height
)
696 screen_t
*new_screen
= screen_getbycoord(c
->screen
,
697 geometry_internal
.x
, geometry_internal
.y
);
699 /* Values to configure a window is an array where values are
700 * stored according to 'value_mask' */
703 c
->geometries
.internal
.x
= values
[0] = geometry_internal
.x
;
704 c
->geometries
.internal
.y
= values
[1] = geometry_internal
.y
;
705 c
->geometries
.internal
.width
= values
[2] = geometry_internal
.width
;
706 c
->geometries
.internal
.height
= values
[3] = geometry_internal
.height
;
708 /* Also store geometry including border and titlebar. */
709 c
->geometry
= geometry
;
711 titlebar_update_geometry(c
);
713 xcb_configure_window(globalconf
.connection
, c
->win
,
714 XCB_CONFIG_WINDOW_X
| XCB_CONFIG_WINDOW_Y
715 | XCB_CONFIG_WINDOW_WIDTH
| XCB_CONFIG_WINDOW_HEIGHT
,
718 screen_client_moveto(c
, new_screen
, true, false);
721 hook_property(client
, c
, "geometry");
729 /** Set a client minimized, or not.
730 * \param c The client.
731 * \param s Set or not the client minimized.
734 client_setminimized(client_t
*c
, bool s
)
736 if(c
->isminimized
!= s
)
738 client_need_reban(c
);
740 client_need_reban(c
);
742 window_state_set(c
->win
, XCB_WM_STATE_ICONIC
);
744 window_state_set(c
->win
, XCB_WM_STATE_NORMAL
);
745 ewmh_client_update_hints(c
);
747 hook_property(client
, c
, "minimized");
751 /** Set a client sticky, or not.
752 * \param c The client.
753 * \param s Set or not the client sticky.
756 client_setsticky(client_t
*c
, bool s
)
760 client_need_reban(c
);
762 client_need_reban(c
);
763 ewmh_client_update_hints(c
);
764 hook_property(client
, c
, "sticky");
768 /** Set a client fullscreen, or not.
769 * \param c The client.
770 * \param s Set or not the client fullscreen.
773 client_setfullscreen(client_t
*c
, bool s
)
775 if(c
->isfullscreen
!= s
)
779 /* Make sure the current geometry is stored without titlebar. */
781 titlebar_ban(c
->titlebar
);
783 /* become fullscreen! */
784 if((c
->isfullscreen
= s
))
786 /* remove any max state */
787 client_setmaxhoriz(c
, false);
788 client_setmaxvert(c
, false);
789 /* You can only be part of one of the special layers. */
790 client_setbelow(c
, false);
791 client_setabove(c
, false);
792 client_setontop(c
, false);
794 geometry
= screen_area_get(c
->screen
, false);
795 c
->geometries
.fullscreen
= c
->geometry
;
796 c
->border_fs
= c
->border
;
797 client_setborder(c
, 0);
801 geometry
= c
->geometries
.fullscreen
;
802 client_setborder(c
, c
->border_fs
);
804 client_resize(c
, geometry
, false);
806 ewmh_client_update_hints(c
);
807 hook_property(client
, c
, "fullscreen");
811 /** Set a client horizontally maximized.
812 * \param c The client.
813 * \param s The maximized status.
816 client_setmaxhoriz(client_t
*c
, bool s
)
818 if(c
->ismaxhoriz
!= s
)
822 if((c
->ismaxhoriz
= s
))
824 /* remove fullscreen mode */
825 client_setfullscreen(c
, false);
827 geometry
= screen_area_get(c
->screen
, true);
828 geometry
.y
= c
->geometry
.y
;
829 geometry
.height
= c
->geometry
.height
;
830 c
->geometries
.max
.x
= c
->geometry
.x
;
831 c
->geometries
.max
.width
= c
->geometry
.width
;
835 geometry
= c
->geometry
;
836 geometry
.x
= c
->geometries
.max
.x
;
837 geometry
.width
= c
->geometries
.max
.width
;
840 client_resize(c
, geometry
, c
->size_hints_honor
);
842 ewmh_client_update_hints(c
);
843 hook_property(client
, c
, "maximized_horizontal");
847 /** Set a client vertically maximized.
848 * \param c The client.
849 * \param s The maximized status.
852 client_setmaxvert(client_t
*c
, bool s
)
854 if(c
->ismaxvert
!= s
)
858 if((c
->ismaxvert
= s
))
860 /* remove fullscreen mode */
861 client_setfullscreen(c
, false);
863 geometry
= screen_area_get(c
->screen
, true);
864 geometry
.x
= c
->geometry
.x
;
865 geometry
.width
= c
->geometry
.width
;
866 c
->geometries
.max
.y
= c
->geometry
.y
;
867 c
->geometries
.max
.height
= c
->geometry
.height
;
871 geometry
= c
->geometry
;
872 geometry
.y
= c
->geometries
.max
.y
;
873 geometry
.height
= c
->geometries
.max
.height
;
876 client_resize(c
, geometry
, c
->size_hints_honor
);
878 ewmh_client_update_hints(c
);
879 hook_property(client
, c
, "maximized_vertical");
883 /** Set a client above, or not.
884 * \param c The client.
885 * \param s Set or not the client above.
888 client_setabove(client_t
*c
, bool s
)
892 /* You can only be part of one of the special layers. */
895 client_setbelow(c
, false);
896 client_setontop(c
, false);
897 client_setfullscreen(c
, false);
901 ewmh_client_update_hints(c
);
903 hook_property(client
, c
, "above");
907 /** Set a client below, or not.
908 * \param c The client.
909 * \param s Set or not the client below.
912 client_setbelow(client_t
*c
, bool s
)
916 /* You can only be part of one of the special layers. */
919 client_setabove(c
, false);
920 client_setontop(c
, false);
921 client_setfullscreen(c
, false);
925 ewmh_client_update_hints(c
);
927 hook_property(client
, c
, "below");
931 /** Set a client modal, or not.
932 * \param c The client.
933 * \param s Set or not the client moda.
936 client_setmodal(client_t
*c
, bool s
)
942 ewmh_client_update_hints(c
);
944 hook_property(client
, c
, "modal");
948 /** Set a client ontop, or not.
949 * \param c The client.
950 * \param s Set or not the client moda.
953 client_setontop(client_t
*c
, bool s
)
957 /* You can only be part of one of the special layers. */
960 client_setabove(c
, false);
961 client_setbelow(c
, false);
962 client_setfullscreen(c
, false);
967 hook_property(client
, c
, "ontop");
971 /** Unban a client and move it back into the viewport.
972 * \param c The client.
975 client_unban(client_t
*c
)
979 xcb_map_window(globalconf
.connection
, c
->win
);
985 /** Unmanage a client.
986 * \param c The client.
989 client_unmanage(client_t
*c
)
991 tag_array_t
*tags
= &c
->screen
->tags
;
993 /* Reset transient_for attributes of widows that maybe refering to us */
994 foreach(_tc
, globalconf
.clients
)
997 if(tc
->transient_for
== c
)
998 tc
->transient_for
= NULL
;
1001 if(globalconf
.screens
.tab
[c
->phys_screen
].prev_client_focus
== c
)
1002 globalconf
.screens
.tab
[c
->phys_screen
].prev_client_focus
= NULL
;
1004 if(globalconf
.screens
.tab
[c
->phys_screen
].client_focus
== c
)
1007 /* remove client from global list and everywhere else */
1008 foreach(elem
, globalconf
.clients
)
1011 client_array_remove(&globalconf
.clients
, elem
);
1014 stack_client_remove(c
);
1015 for(int i
= 0; i
< tags
->len
; i
++)
1016 untag_client(c
, tags
->tab
[i
]);
1019 if(globalconf
.hooks
.unmanage
!= LUA_REFNIL
)
1021 client_push(globalconf
.L
, c
);
1022 luaA_dofunction_from_registry(globalconf
.L
, globalconf
.hooks
.unmanage
, 1, 0);
1025 /* Call hook to notify list change */
1026 if(globalconf
.hooks
.clients
!= LUA_REFNIL
)
1027 luaA_dofunction_from_registry(globalconf
.L
, globalconf
.hooks
.clients
, 0, 0);
1029 /* The server grab construct avoids race conditions. */
1030 xcb_grab_server(globalconf
.connection
);
1032 xcb_ungrab_button(globalconf
.connection
, XCB_BUTTON_INDEX_ANY
, c
->win
,
1033 XCB_BUTTON_MASK_ANY
);
1034 window_state_set(c
->win
, XCB_WM_STATE_WITHDRAWN
);
1036 xcb_flush(globalconf
.connection
);
1037 xcb_ungrab_server(globalconf
.connection
);
1039 titlebar_client_detach(c
);
1041 ewmh_update_net_client_list(c
->phys_screen
);
1043 /* set client as invalid */
1046 client_unref(globalconf
.L
, c
);
1049 /** Kill a client via a WM_DELETE_WINDOW request or KillClient if not
1051 * \param c The client to kill.
1054 client_kill(client_t
*c
)
1056 if(window_hasproto(c
->win
, WM_DELETE_WINDOW
))
1058 xcb_client_message_event_t ev
;
1060 /* Initialize all of event's fields first */
1063 ev
.response_type
= XCB_CLIENT_MESSAGE
;
1066 ev
.data
.data32
[1] = XCB_CURRENT_TIME
;
1067 ev
.type
= WM_PROTOCOLS
;
1068 ev
.data
.data32
[0] = WM_DELETE_WINDOW
;
1070 xcb_send_event(globalconf
.connection
, false, c
->win
,
1071 XCB_EVENT_MASK_NO_EVENT
, (char *) &ev
);
1074 xcb_kill_client(globalconf
.connection
, c
->win
);
1077 /** Get all clients into a table.
1078 * \param L The Lua VM state.
1079 * \return The number of elements pushed on stack.
1081 * \lparam An optional screen nunmber.
1082 * \lreturn A table with all clients.
1085 luaA_client_get(lua_State
*L
)
1089 screen
= luaL_optnumber(L
, 1, 0) - 1;
1094 foreach(c
, globalconf
.clients
)
1097 lua_rawseti(L
, -2, i
++);
1101 luaA_checkscreen(screen
);
1102 foreach(c
, globalconf
.clients
)
1103 if((*c
)->screen
== &globalconf
.screens
.tab
[screen
])
1106 lua_rawseti(L
, -2, i
++);
1113 /** Check if a client is visible on its screen.
1114 * \param L The Lua VM state.
1115 * \return The number of elements pushed on stack.
1118 * \lreturn A boolean value, true if the client is visible, false otherwise.
1121 luaA_client_isvisible(lua_State
*L
)
1123 client_t
*c
= luaA_client_checkudata(L
, 1);
1124 lua_pushboolean(L
, client_isvisible(c
, c
->screen
));
1128 /** Set client border width.
1129 * \param c The client.
1130 * \param width The border width.
1133 client_setborder(client_t
*c
, int width
)
1137 if(width
> 0 && (c
->type
== WINDOW_TYPE_DOCK
1138 || c
->type
== WINDOW_TYPE_SPLASH
1139 || c
->type
== WINDOW_TYPE_DESKTOP
1140 || c
->isfullscreen
))
1143 if(width
== c
->border
|| width
< 0)
1146 /* Update geometry with the new border. */
1147 c
->geometry
.width
-= 2 * c
->border
;
1148 c
->geometry
.height
-= 2 * c
->border
;
1151 xcb_configure_window(globalconf
.connection
, c
->win
,
1152 XCB_CONFIG_WINDOW_BORDER_WIDTH
, &w
);
1154 c
->geometry
.width
+= 2 * c
->border
;
1155 c
->geometry
.height
+= 2 * c
->border
;
1157 /* Changing border size also affects the size of the titlebar. */
1158 titlebar_update_geometry(c
);
1160 hook_property(client
, c
, "border_width");
1164 * \param L The Lua VM state.
1170 luaA_client_kill(lua_State
*L
)
1172 client_t
*c
= luaA_client_checkudata(L
, 1);
1177 /** Swap a client with another one.
1178 * \param L The Lua VM state.
1181 * \lparam A client to swap with.
1184 luaA_client_swap(lua_State
*L
)
1186 client_t
*c
= luaA_client_checkudata(L
, 1);
1187 client_t
*swap
= luaA_client_checkudata(L
, 2);
1191 client_t
**ref_c
= NULL
, **ref_swap
= NULL
;
1192 foreach(item
, globalconf
.clients
)
1196 else if(*item
== swap
)
1198 if(ref_c
&& ref_swap
)
1205 /* Call hook to notify list change */
1206 if(globalconf
.hooks
.clients
!= LUA_REFNIL
)
1207 luaA_dofunction_from_registry(L
, globalconf
.hooks
.clients
, 0, 0);
1213 /** Access or set the client tags.
1214 * \param L The Lua VM state.
1215 * \return The number of elements pushed on stack.
1216 * \lparam A table with tags to set, or none to get the current tags table.
1217 * \return The clients tag.
1220 luaA_client_tags(lua_State
*L
)
1222 client_t
*c
= luaA_client_checkudata(L
, 1);
1223 tag_array_t
*tags
= &c
->screen
->tags
;
1226 if(lua_gettop(L
) == 2)
1228 luaA_checktable(L
, 2);
1229 for(int i
= 0; i
< tags
->len
; i
++)
1230 untag_client(c
, tags
->tab
[i
]);
1232 while(lua_next(L
, 2))
1239 if(is_client_tagged(c
, *tag
))
1242 lua_rawseti(L
, -2, ++j
);
1248 /** Raise a client on top of others which are on the same layer.
1249 * \param L The Lua VM state.
1254 luaA_client_raise(lua_State
*L
)
1256 client_t
*c
= luaA_client_checkudata(L
, 1);
1261 /** Lower a client on bottom of others which are on the same layer.
1262 * \param L The Lua VM state.
1267 luaA_client_lower(lua_State
*L
)
1269 client_t
*c
= luaA_client_checkudata(L
, 1);
1274 /** Redraw a client by unmapping and mapping it quickly.
1275 * \param L The Lua VM state.
1281 luaA_client_redraw(lua_State
*L
)
1283 client_t
*c
= luaA_client_checkudata(L
, 1);
1285 xcb_unmap_window(globalconf
.connection
, c
->win
);
1286 xcb_map_window(globalconf
.connection
, c
->win
);
1288 /* Set the focus on the current window if the redraw has been
1289 performed on the window where the pointer is currently on
1290 because after the unmapping/mapping, the focus is lost */
1291 if(globalconf
.screen_focus
->client_focus
== c
)
1300 /** Stop managing a client.
1301 * \param L The Lua VM state.
1302 * \return The number of elements pushed on stack.
1307 luaA_client_unmanage(lua_State
*L
)
1309 client_t
*c
= luaA_client_checkudata(L
, 1);
1314 /** Return client geometry.
1315 * \param L The Lua VM state.
1316 * \return The number of elements pushed on stack.
1318 * \lparam A table with new coordinates, or none.
1319 * \lreturn A table with client coordinates.
1322 luaA_client_geometry(lua_State
*L
)
1324 client_t
*c
= luaA_client_checkudata(L
, 1);
1326 if(lua_gettop(L
) == 2)
1330 luaA_checktable(L
, 2);
1331 geometry
.x
= luaA_getopt_number(L
, 2, "x", c
->geometry
.x
);
1332 geometry
.y
= luaA_getopt_number(L
, 2, "y", c
->geometry
.y
);
1333 if(client_isfixed(c
))
1335 geometry
.width
= c
->geometry
.width
;
1336 geometry
.height
= c
->geometry
.height
;
1340 geometry
.width
= luaA_getopt_number(L
, 2, "width", c
->geometry
.width
);
1341 geometry
.height
= luaA_getopt_number(L
, 2, "height", c
->geometry
.height
);
1344 client_resize(c
, geometry
, c
->size_hints_honor
);
1347 return luaA_pusharea(L
, c
->geometry
);
1350 /** Push a strut type to a table on stack.
1351 * \param L The Lua VM state.
1352 * \param struts The struts to push.
1353 * \return The number of elements pushed on stack.
1356 luaA_pushstruts(lua_State
*L
, strut_t struts
)
1358 lua_createtable(L
, 4, 0);
1359 lua_pushnumber(L
, struts
.left
);
1360 lua_setfield(L
, -2, "left");
1361 lua_pushnumber(L
, struts
.right
);
1362 lua_setfield(L
, -2, "right");
1363 lua_pushnumber(L
, struts
.top
);
1364 lua_setfield(L
, -2, "top");
1365 lua_pushnumber(L
, struts
.bottom
);
1366 lua_setfield(L
, -2, "bottom");
1370 /** Return client struts (reserved space at the edge of the screen).
1371 * \param L The Lua VM state.
1372 * \return The number of elements pushed on stack.
1374 * \lparam A table with new strut values, or none.
1375 * \lreturn A table with strut values.
1378 luaA_client_struts(lua_State
*L
)
1380 client_t
*c
= luaA_client_checkudata(L
, 1);
1382 if(lua_gettop(L
) == 2)
1385 area_t screen_area
= display_area_get(c
->phys_screen
);
1387 struts
.left
= luaA_getopt_number(L
, 2, "left", c
->strut
.left
);
1388 struts
.right
= luaA_getopt_number(L
, 2, "right", c
->strut
.right
);
1389 struts
.top
= luaA_getopt_number(L
, 2, "top", c
->strut
.top
);
1390 struts
.bottom
= luaA_getopt_number(L
, 2, "bottom", c
->strut
.bottom
);
1392 if(struts
.left
!= c
->strut
.left
|| struts
.right
!= c
->strut
.right
||
1393 struts
.top
!= c
->strut
.top
|| struts
.bottom
!= c
->strut
.bottom
) {
1394 /* Struts are not so well defined in the context of xinerama. So we just
1395 * give the entire root window and let the window manager decide. */
1396 struts
.left_start_y
= 0;
1397 struts
.left_end_y
= !struts
.left
? 0 : screen_area
.height
;
1398 struts
.right_start_y
= 0;
1399 struts
.right_end_y
= !struts
.right
? 0 : screen_area
.height
;
1400 struts
.top_start_x
= 0;
1401 struts
.top_end_x
= !struts
.top
? 0 : screen_area
.width
;
1402 struts
.bottom_start_x
= 0;
1403 struts
.bottom_end_x
= !struts
.bottom
? 0 : screen_area
.width
;
1407 ewmh_update_client_strut(c
);
1409 hook_property(client
, c
, "struts");
1413 return luaA_pushstruts(L
, c
->strut
);
1416 /** Client newindex.
1417 * \param L The Lua VM state.
1418 * \return The number of elements pushed on stack.
1421 luaA_client_newindex(lua_State
*L
)
1424 client_t
*c
= luaA_client_checkudata(L
, 1);
1425 const char *buf
= luaL_checklstring(L
, 2, &len
);
1430 switch(a_tokenize(buf
, len
))
1433 if(globalconf
.xinerama_is_active
)
1435 i
= luaL_checknumber(L
, 3) - 1;
1436 luaA_checkscreen(i
);
1437 screen_client_moveto(c
, &globalconf
.screens
.tab
[i
], true, true);
1441 b
= luaA_checkboolean(L
, 3);
1442 if(b
!= c
->ishidden
)
1444 client_need_reban(c
);
1446 client_need_reban(c
);
1447 hook_property(client
, c
, "hide");
1450 case A_TK_MINIMIZED
:
1451 client_setminimized(c
, luaA_checkboolean(L
, 3));
1453 case A_TK_FULLSCREEN
:
1454 client_setfullscreen(c
, luaA_checkboolean(L
, 3));
1456 case A_TK_MAXIMIZED_HORIZONTAL
:
1457 client_setmaxhoriz(c
, luaA_checkboolean(L
, 3));
1459 case A_TK_MAXIMIZED_VERTICAL
:
1460 client_setmaxvert(c
, luaA_checkboolean(L
, 3));
1463 image_unref(L
, c
->icon
);
1464 c
->icon
= image_ref(L
);
1466 hook_property(client
, c
, "icon");
1470 window_opacity_set(c
->win
, -1);
1473 d
= luaL_checknumber(L
, 3);
1474 if(d
>= 0 && d
<= 1)
1475 window_opacity_set(c
->win
, d
);
1479 client_setsticky(c
, luaA_checkboolean(L
, 3));
1481 case A_TK_SIZE_HINTS_HONOR
:
1482 c
->size_hints_honor
= luaA_checkboolean(L
, 3);
1483 hook_property(client
, c
, "size_hints_honor");
1485 case A_TK_BORDER_WIDTH
:
1486 client_setborder(c
, luaL_checknumber(L
, 3));
1489 client_setontop(c
, luaA_checkboolean(L
, 3));
1492 client_setabove(c
, luaA_checkboolean(L
, 3));
1495 client_setbelow(c
, luaA_checkboolean(L
, 3));
1498 client_seturgent(c
, luaA_checkboolean(L
, 3));
1500 case A_TK_BORDER_COLOR
:
1501 if((buf
= luaL_checklstring(L
, 3, &len
))
1502 && xcolor_init_reply(xcolor_init_unchecked(&c
->border_color
, buf
, len
)))
1503 xcb_change_window_attributes(globalconf
.connection
, c
->win
,
1504 XCB_CW_BORDER_PIXEL
, &c
->border_color
.pixel
);
1508 titlebar_client_detach(c
);
1510 titlebar_client_attach(c
);
1512 case A_TK_SKIP_TASKBAR
:
1513 c
->skiptb
= luaA_checkboolean(L
, 3);
1514 hook_property(client
, c
, "skip_taskbar");
1524 * \param L The Lua VM state.
1525 * \return The number of elements pushed on stack.
1527 * \lfield id The window X id.
1528 * \lfield name The client title.
1529 * \lfield skip_taskbar If true the client won't be shown in the tasklist.
1530 * \lfield type The window type (desktop, normal, dock, …).
1531 * \lfield class The client class.
1532 * \lfield instance The client instance.
1533 * \lfield pid The client PID, if available.
1534 * \lfield role The window role, if available.
1535 * \lfield machine The machine client is running on.
1536 * \lfield icon_name The client name when iconified.
1537 * \lfield screen Client screen number.
1538 * \lfield hide Define if the client must be hidden, i.e. never mapped,
1539 * invisible in taskbar.
1540 * \lfield minimized Define it the client must be iconify, i.e. only visible in
1542 * \lfield size_hints_honor Honor size hints, i.e. respect size ratio.
1543 * \lfield border_width The client border width.
1544 * \lfield border_color The client border color.
1545 * \lfield titlebar The client titlebar.
1546 * \lfield urgent The client urgent state.
1547 * \lfield content An image representing the client window content (screenshot).
1548 * \lfield focus The focused client.
1549 * \lfield opacity The client opacity between 0 and 1.
1550 * \lfield ontop The client is on top of every other windows.
1551 * \lfield above The client is above normal windows.
1552 * \lfield below The client is below normal windows.
1553 * \lfield fullscreen The client is fullscreen or not.
1554 * \lfield maximized_horizontal The client is maximized horizontally or not.
1555 * \lfield maximized_vertical The client is maximized vertically or not.
1556 * \lfield transient_for Return the client the window is transient for.
1557 * \lfield group_id Identification unique to a group of windows.
1558 * \lfield leader_id Identification unique to windows spawned by the same command.
1559 * \lfield size_hints A table with size hints of the client: user_position,
1560 * user_size, program_position, program_size, etc.
1563 luaA_client_index(lua_State
*L
)
1567 client_t
*c
= luaA_client_checkudata(L
, 1);
1568 const char *buf
= luaL_checklstring(L
, 2, &len
);
1571 xcb_get_property_cookie_t prop_c
;
1572 xcb_get_property_reply_t
*prop_r
= NULL
;
1575 if(luaA_usemetatable(L
, 1, 2))
1578 switch(a_tokenize(buf
, len
))
1581 lua_pushstring(L
, c
->name
);
1583 case A_TK_TRANSIENT_FOR
:
1584 return client_push(globalconf
.L
, c
->transient_for
);
1585 case A_TK_SKIP_TASKBAR
:
1586 lua_pushboolean(L
, c
->skiptb
);
1589 return client_getcontent(c
);
1593 case WINDOW_TYPE_DESKTOP
:
1594 lua_pushliteral(L
, "desktop");
1596 case WINDOW_TYPE_DOCK
:
1597 lua_pushliteral(L
, "dock");
1599 case WINDOW_TYPE_SPLASH
:
1600 lua_pushliteral(L
, "splash");
1602 case WINDOW_TYPE_DIALOG
:
1603 lua_pushliteral(L
, "dialog");
1605 case WINDOW_TYPE_MENU
:
1606 lua_pushliteral(L
, "menu");
1608 case WINDOW_TYPE_TOOLBAR
:
1609 lua_pushliteral(L
, "toolbar");
1611 case WINDOW_TYPE_UTILITY
:
1612 lua_pushliteral(L
, "utility");
1614 case WINDOW_TYPE_DROPDOWN_MENU
:
1615 lua_pushliteral(L
, "dropdown_menu");
1617 case WINDOW_TYPE_POPUP_MENU
:
1618 lua_pushliteral(L
, "popup_menu");
1620 case WINDOW_TYPE_TOOLTIP
:
1621 lua_pushliteral(L
, "tooltip");
1623 case WINDOW_TYPE_NOTIFICATION
:
1624 lua_pushliteral(L
, "notification");
1626 case WINDOW_TYPE_COMBO
:
1627 lua_pushliteral(L
, "combo");
1629 case WINDOW_TYPE_DND
:
1630 lua_pushliteral(L
, "dnd");
1632 case WINDOW_TYPE_NORMAL
:
1633 lua_pushliteral(L
, "normal");
1638 lua_pushstring(L
, c
->class);
1641 lua_pushstring(L
, c
->instance
);
1644 if(!xutil_text_prop_get(globalconf
.connection
, c
->win
,
1645 WM_WINDOW_ROLE
, &value
, &slen
))
1647 lua_pushlstring(L
, value
, slen
);
1651 prop_c
= xcb_get_property_unchecked(globalconf
.connection
, false, c
->win
, _NET_WM_PID
, CARDINAL
, 0L, 1L);
1652 prop_r
= xcb_get_property_reply(globalconf
.connection
, prop_c
, NULL
);
1654 if(prop_r
&& prop_r
->value_len
&& (data
= xcb_get_property_value(prop_r
)))
1655 lua_pushnumber(L
, *(uint32_t *)data
);
1663 lua_pushnumber(L
, c
->win
);
1665 case A_TK_LEADER_ID
:
1666 lua_pushnumber(L
, c
->leader_win
);
1669 if(!xutil_text_prop_get(globalconf
.connection
, c
->win
,
1670 WM_CLIENT_MACHINE
, &value
, &slen
))
1672 lua_pushlstring(L
, value
, slen
);
1675 case A_TK_ICON_NAME
:
1676 lua_pushstring(L
, c
->icon_name
);
1679 lua_pushnumber(L
, 1 + screen_array_indexof(&globalconf
.screens
, c
->screen
));
1682 lua_pushboolean(L
, c
->ishidden
);
1684 case A_TK_MINIMIZED
:
1685 lua_pushboolean(L
, c
->isminimized
);
1687 case A_TK_FULLSCREEN
:
1688 lua_pushboolean(L
, c
->isfullscreen
);
1692 lua_pushnumber(L
, c
->group_win
);
1696 case A_TK_MAXIMIZED_HORIZONTAL
:
1697 lua_pushboolean(L
, c
->ismaxhoriz
);
1699 case A_TK_MAXIMIZED_VERTICAL
:
1700 lua_pushboolean(L
, c
->ismaxvert
);
1703 image_push(L
, c
->icon
);
1706 if((d
= window_opacity_get(c
->win
)) >= 0)
1707 lua_pushnumber(L
, d
);
1712 lua_pushboolean(L
, c
->isontop
);
1715 lua_pushboolean(L
, c
->isabove
);
1718 lua_pushboolean(L
, c
->isbelow
);
1721 lua_pushboolean(L
, c
->issticky
);
1723 case A_TK_SIZE_HINTS_HONOR
:
1724 lua_pushboolean(L
, c
->size_hints_honor
);
1726 case A_TK_BORDER_WIDTH
:
1727 lua_pushnumber(L
, c
->border
);
1729 case A_TK_BORDER_COLOR
:
1730 luaA_pushxcolor(L
, &c
->border_color
);
1733 return wibox_push(L
, c
->titlebar
);
1735 lua_pushboolean(L
, c
->isurgent
);
1737 case A_TK_SIZE_HINTS
:
1739 const char *u_or_p
= NULL
;
1741 lua_createtable(L
, 0, 1);
1743 if(c
->size_hints
.flags
& XCB_SIZE_HINT_US_POSITION
)
1744 u_or_p
= "user_position";
1745 else if(c
->size_hints
.flags
& XCB_SIZE_HINT_P_POSITION
)
1746 u_or_p
= "program_position";
1750 lua_createtable(L
, 0, 2);
1751 lua_pushnumber(L
, c
->size_hints
.x
);
1752 lua_setfield(L
, -2, "x");
1753 lua_pushnumber(L
, c
->size_hints
.y
);
1754 lua_setfield(L
, -2, "y");
1755 lua_setfield(L
, -2, u_or_p
);
1759 if(c
->size_hints
.flags
& XCB_SIZE_HINT_US_SIZE
)
1760 u_or_p
= "user_size";
1761 else if(c
->size_hints
.flags
& XCB_SIZE_HINT_P_SIZE
)
1762 u_or_p
= "program_size";
1766 lua_createtable(L
, 0, 2);
1767 lua_pushnumber(L
, c
->size_hints
.width
);
1768 lua_setfield(L
, -2, "width");
1769 lua_pushnumber(L
, c
->size_hints
.height
);
1770 lua_setfield(L
, -2, "height");
1771 lua_setfield(L
, -2, u_or_p
);
1774 if(c
->size_hints
.flags
& XCB_SIZE_HINT_P_MIN_SIZE
)
1776 lua_pushnumber(L
, c
->size_hints
.min_width
);
1777 lua_setfield(L
, -2, "min_width");
1778 lua_pushnumber(L
, c
->size_hints
.min_height
);
1779 lua_setfield(L
, -2, "min_height");
1782 if(c
->size_hints
.flags
& XCB_SIZE_HINT_P_MAX_SIZE
)
1784 lua_pushnumber(L
, c
->size_hints
.max_width
);
1785 lua_setfield(L
, -2, "max_width");
1786 lua_pushnumber(L
, c
->size_hints
.max_height
);
1787 lua_setfield(L
, -2, "max_height");
1790 if(c
->size_hints
.flags
& XCB_SIZE_HINT_P_RESIZE_INC
)
1792 lua_pushnumber(L
, c
->size_hints
.width_inc
);
1793 lua_setfield(L
, -2, "width_inc");
1794 lua_pushnumber(L
, c
->size_hints
.height_inc
);
1795 lua_setfield(L
, -2, "height_inc");
1798 if(c
->size_hints
.flags
& XCB_SIZE_HINT_P_ASPECT
)
1800 lua_pushnumber(L
, c
->size_hints
.min_aspect_num
);
1801 lua_setfield(L
, -2, "min_aspect_num");
1802 lua_pushnumber(L
, c
->size_hints
.min_aspect_den
);
1803 lua_setfield(L
, -2, "min_aspect_den");
1804 lua_pushnumber(L
, c
->size_hints
.max_aspect_num
);
1805 lua_setfield(L
, -2, "max_aspect_num");
1806 lua_pushnumber(L
, c
->size_hints
.max_aspect_den
);
1807 lua_setfield(L
, -2, "max_aspect_den");
1810 if(c
->size_hints
.flags
& XCB_SIZE_HINT_BASE_SIZE
)
1812 lua_pushnumber(L
, c
->size_hints
.base_width
);
1813 lua_setfield(L
, -2, "base_width");
1814 lua_pushnumber(L
, c
->size_hints
.base_height
);
1815 lua_setfield(L
, -2, "base_height");
1818 if(c
->size_hints
.flags
& XCB_SIZE_HINT_P_WIN_GRAVITY
)
1820 switch(c
->size_hints
.win_gravity
)
1823 lua_pushliteral(L
, "north_west");
1825 case XCB_GRAVITY_NORTH
:
1826 lua_pushliteral(L
, "north");
1828 case XCB_GRAVITY_NORTH_EAST
:
1829 lua_pushliteral(L
, "north_east");
1831 case XCB_GRAVITY_WEST
:
1832 lua_pushliteral(L
, "west");
1834 case XCB_GRAVITY_CENTER
:
1835 lua_pushliteral(L
, "center");
1837 case XCB_GRAVITY_EAST
:
1838 lua_pushliteral(L
, "east");
1840 case XCB_GRAVITY_SOUTH_WEST
:
1841 lua_pushliteral(L
, "south_west");
1843 case XCB_GRAVITY_SOUTH
:
1844 lua_pushliteral(L
, "south");
1846 case XCB_GRAVITY_SOUTH_EAST
:
1847 lua_pushliteral(L
, "south_east");
1849 case XCB_GRAVITY_STATIC
:
1850 lua_pushliteral(L
, "static");
1853 lua_setfield(L
, -2, "win_gravity");
1864 /** Get or set mouse buttons bindings for a client.
1865 * \param L The Lua VM state.
1866 * \return The number of element pushed on stack.
1869 * \lparam An array of mouse button bindings objects, or nothing.
1870 * \return The array of mouse button bindings objects of this client.
1873 luaA_client_buttons(lua_State
*L
)
1875 client_t
*client
= luaA_client_checkudata(L
, 1);
1876 button_array_t
*buttons
= &client
->buttons
;
1878 if(lua_gettop(L
) == 2)
1879 luaA_button_array_set(L
, 2, buttons
);
1881 window_buttons_grab(client
->win
, &client
->buttons
);
1883 return luaA_button_array_get(L
, buttons
);
1886 /** Get or set keys bindings for a client.
1887 * \param L The Lua VM state.
1888 * \return The number of element pushed on stack.
1891 * \lparam An array of key bindings objects, or nothing.
1892 * \return The array of key bindings objects of this client.
1895 luaA_client_keys(lua_State
*L
)
1897 client_t
*c
= luaA_client_checkudata(L
, 1);
1898 key_array_t
*keys
= &c
->keys
;
1900 if(lua_gettop(L
) == 2)
1902 luaA_key_array_set(L
, 2, keys
);
1903 xcb_ungrab_key(globalconf
.connection
, XCB_GRAB_ANY
, c
->win
, XCB_BUTTON_MASK_ANY
);
1904 window_grabkeys(c
->win
, keys
);
1907 return luaA_key_array_get(L
, keys
);
1911 * \param L The Lua VM state.
1912 * \return The number of pushed elements.
1915 luaA_client_module_index(lua_State
*L
)
1918 const char *buf
= luaL_checklstring(L
, 2, &len
);
1920 switch(a_tokenize(buf
, len
))
1923 return client_push(globalconf
.L
, globalconf
.screen_focus
->client_focus
);
1930 /* Client module new index.
1931 * \param L The Lua VM state.
1932 * \return The number of pushed elements.
1935 luaA_client_module_newindex(lua_State
*L
)
1938 const char *buf
= luaL_checklstring(L
, 2, &len
);
1941 switch(a_tokenize(buf
, len
))
1944 c
= luaA_client_checkudata(L
, 3);
1954 const struct luaL_reg awesome_client_methods
[] =
1956 { "get", luaA_client_get
},
1957 { "__index", luaA_client_module_index
},
1958 { "__newindex", luaA_client_module_newindex
},
1961 const struct luaL_reg awesome_client_meta
[] =
1963 { "isvisible", luaA_client_isvisible
},
1964 { "geometry", luaA_client_geometry
},
1965 { "struts", luaA_client_struts
},
1966 { "buttons", luaA_client_buttons
},
1967 { "keys", luaA_client_keys
},
1968 { "tags", luaA_client_tags
},
1969 { "kill", luaA_client_kill
},
1970 { "swap", luaA_client_swap
},
1971 { "raise", luaA_client_raise
},
1972 { "lower", luaA_client_lower
},
1973 { "redraw", luaA_client_redraw
},
1974 { "unmanage", luaA_client_unmanage
},
1975 { "__index", luaA_client_index
},
1976 { "__newindex", luaA_client_newindex
},
1977 { "__gc", luaA_client_gc
},
1978 { "__tostring", luaA_client_tostring
},
1982 // vim: filetype=c:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=80