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(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 /* Move all clients out of the physical viewport into negative coordinate space. */
208 /* They will all be put on top of each other. */
209 uint32_t request
[2] = { - (c
->geometries
.internal
.width
+ 2 * c
->border
),
210 - (c
->geometries
.internal
.height
+ 2 * c
->border
) };
212 xcb_configure_window(globalconf
.connection
, c
->win
,
213 XCB_CONFIG_WINDOW_X
| XCB_CONFIG_WINDOW_Y
,
218 if(globalconf
.screens
.tab
[c
->phys_screen
].prev_client_focus
== c
)
219 globalconf
.screens
.tab
[c
->phys_screen
].prev_client_focus
= NULL
;
221 /* Wait until the last moment to take away the focus from the window. */
222 if(globalconf
.screens
.tab
[c
->phys_screen
].client_focus
== c
)
227 /** Record that a client got focus.
228 * \param c Client being focused.
231 client_focus_update(client_t
*c
)
233 if(!client_maybevisible(c
, c
->screen
))
235 /* Focus previously focused client */
236 client_focus(globalconf
.screen_focus
->prev_client_focus
);
240 if(globalconf
.screen_focus
241 && globalconf
.screen_focus
->client_focus
)
243 if (globalconf
.screen_focus
->client_focus
!= c
)
244 client_unfocus_update(globalconf
.screen_focus
->client_focus
);
246 /* Already focused */
249 /* stop hiding client */
251 client_setminimized(c
, false);
253 /* unban the client before focusing for consistency */
256 globalconf
.screen_focus
= &globalconf
.screens
.tab
[c
->phys_screen
];
257 globalconf
.screen_focus
->prev_client_focus
= c
;
258 globalconf
.screen_focus
->client_focus
= c
;
260 /* according to EWMH, we have to remove the urgent state from a client */
261 client_seturgent(c
, false);
263 ewmh_update_net_active_window(c
->phys_screen
);
266 if(globalconf
.hooks
.focus
!= LUA_REFNIL
)
268 client_push(globalconf
.L
, c
);
269 luaA_dofunction(globalconf
.L
, globalconf
.hooks
.focus
, 1, 0);
274 /** Give focus to client, or to first client if client is NULL.
275 * \param c The client or NULL.
278 client_focus(client_t
*c
)
280 /* We have to set focus on first client */
281 if(!c
&& globalconf
.clients
.len
&& !(c
= globalconf
.clients
.tab
[0]))
284 if(!client_maybevisible(c
, c
->screen
))
288 client_focus_update(c
);
290 window_setfocus(c
->win
, !c
->nofocus
);
293 /** Stack a window below.
294 * \param c The client.
295 * \param previous The previous window on the stack.
296 * \param return The next-previous!
299 client_stack_above(client_t
*c
, xcb_window_t previous
)
301 uint32_t config_win_vals
[2];
303 config_win_vals
[0] = previous
;
304 config_win_vals
[1] = XCB_STACK_MODE_ABOVE
;
306 xcb_configure_window(globalconf
.connection
, c
->win
,
307 XCB_CONFIG_WINDOW_SIBLING
| XCB_CONFIG_WINDOW_STACK_MODE
,
310 config_win_vals
[0] = c
->win
;
314 xcb_configure_window(globalconf
.connection
,
315 c
->titlebar
->sw
.window
,
316 XCB_CONFIG_WINDOW_SIBLING
| XCB_CONFIG_WINDOW_STACK_MODE
,
318 previous
= c
->titlebar
->sw
.window
;
323 /* stack transient window on top of their parents */
324 foreach(node
, globalconf
.stack
)
325 if((*node
)->transient_for
== c
)
326 previous
= client_stack_above(*node
, previous
);
331 /** Stacking layout layers */
334 /** This one is a special layer */
342 /** This one only used for counting and is not a real layer */
346 /** Get the real layer of a client according to its attribute (fullscreen, …)
347 * \param c The client.
348 * \return The real layer.
351 client_layer_translator(client_t
*c
)
353 /* first deal with user set attributes */
356 else if(c
->isfullscreen
)
357 return LAYER_FULLSCREEN
;
363 /* check for transient attr */
367 /* then deal with windows type */
370 case WINDOW_TYPE_DESKTOP
:
371 return LAYER_DESKTOP
;
380 * \todo It might be worth stopping to restack everyone and only stack `c'
381 * relatively to the first matching in the list.
384 client_real_stack(void)
386 uint32_t config_win_vals
[2];
389 config_win_vals
[0] = XCB_NONE
;
390 config_win_vals
[1] = XCB_STACK_MODE_ABOVE
;
392 /* stack desktop windows */
393 for(layer
= LAYER_DESKTOP
; layer
< LAYER_BELOW
; layer
++)
394 foreach(node
, globalconf
.stack
)
395 if(client_layer_translator(*node
) == layer
)
396 config_win_vals
[0] = client_stack_above(*node
,
399 /* first stack not ontop wibox window */
400 foreach(_sb
, globalconf
.wiboxes
)
405 xcb_configure_window(globalconf
.connection
,
407 XCB_CONFIG_WINDOW_SIBLING
| XCB_CONFIG_WINDOW_STACK_MODE
,
409 config_win_vals
[0] = sb
->sw
.window
;
413 /* then stack clients */
414 for(layer
= LAYER_BELOW
; layer
< LAYER_COUNT
; layer
++)
415 foreach(node
, globalconf
.stack
)
416 if(client_layer_translator(*node
) == layer
)
417 config_win_vals
[0] = client_stack_above(*node
,
420 /* then stack ontop wibox window */
421 foreach(_sb
, globalconf
.wiboxes
)
426 xcb_configure_window(globalconf
.connection
,
428 XCB_CONFIG_WINDOW_SIBLING
| XCB_CONFIG_WINDOW_STACK_MODE
,
430 config_win_vals
[0] = sb
->sw
.window
;
436 client_stack_refresh()
438 if (!globalconf
.client_need_stack_refresh
)
440 globalconf
.client_need_stack_refresh
= false;
444 /** Manage a new client.
445 * \param w The window.
446 * \param wgeom Window geometry.
447 * \param phys_screen Physical screen number.
448 * \param startup True if we are managing at startup time.
451 client_manage(xcb_window_t w
, xcb_get_geometry_reply_t
*wgeom
, int phys_screen
, bool startup
)
453 xcb_get_property_cookie_t ewmh_icon_cookie
;
454 client_t
*c
, *tc
= NULL
;
456 const uint32_t select_input_val
[] = { CLIENT_SELECT_INPUT_EVENT_MASK
};
458 if(systray_iskdedockapp(w
))
460 systray_request_handle(w
, phys_screen
, NULL
);
464 /* Send request to get NET_WM_ICON property as soon as possible... */
465 ewmh_icon_cookie
= ewmh_window_icon_get_unchecked(w
);
466 xcb_change_window_attributes(globalconf
.connection
, w
, XCB_CW_EVENT_MASK
, select_input_val
);
468 c
= client_new(globalconf
.L
);
469 /* Push client in client list */
470 client_array_push(&globalconf
.clients
, client_ref(globalconf
.L
));
473 screen
= c
->screen
= screen_getbycoord(&globalconf
.screens
.tab
[phys_screen
],
476 c
->phys_screen
= phys_screen
;
480 c
->geometry
.x
= wgeom
->x
;
481 c
->geometry
.y
= wgeom
->y
;
482 /* Border will be added later. */
483 c
->geometry
.width
= wgeom
->width
;
484 c
->geometry
.height
= wgeom
->height
;
485 /* Also set internal geometry (client_ban() needs it). */
486 c
->geometries
.internal
.x
= wgeom
->x
;
487 c
->geometries
.internal
.y
= wgeom
->y
;
488 c
->geometries
.internal
.width
= wgeom
->width
;
489 c
->geometries
.internal
.height
= wgeom
->height
;
490 client_setborder(c
, wgeom
->border_width
);
492 if(ewmh_window_icon_get_reply(ewmh_icon_cookie
))
493 c
->icon
= image_ref(globalconf
.L
);
495 /* we honor size hints by default */
496 c
->size_hints_honor
= true;
499 property_update_wm_normal_hints(c
, NULL
);
500 property_update_wm_hints(c
, NULL
);
501 property_update_wm_transient_for(c
, NULL
);
502 property_update_wm_client_leader(c
, NULL
);
504 /* Recursively find the parent. */
505 for(tc
= c
; tc
->transient_for
; tc
= tc
->transient_for
);
506 if(tc
!= c
&& tc
->phys_screen
== c
->phys_screen
)
509 /* Then check clients hints */
510 ewmh_client_check_hints(c
);
512 /* move client to screen, but do not tag it */
513 screen_client_moveto(c
, screen
, false, true);
515 /* Push client in stack */
518 /* update window title */
519 property_update_wm_name(c
);
520 property_update_wm_icon_name(c
);
521 property_update_wm_class(c
, NULL
);
523 xutil_text_prop_get(globalconf
.connection
, c
->win
, _NET_STARTUP_ID
, &c
->startup_id
, NULL
);
526 ewmh_process_client_strut(c
, NULL
);
528 ewmh_update_net_client_list(c
->phys_screen
);
530 /* Always stay in NORMAL_STATE. Even though iconified seems more
531 * appropriate sometimes. The only possible loss is that clients not using
532 * visibility events may continue to proces data (when banned).
533 * Without any exposes or other events the cost should be fairly limited though.
535 * Some clients may expect the window to be unmapped when STATE_ICONIFIED.
536 * Two conflicting parts of the ICCCM v2.0 (section 4.1.4):
538 * "Normal -> Iconic - The client should send a ClientMessage event as described later in this section."
539 * (note no explicit mention of unmapping, while Normal->Widthdrawn does mention that)
541 * "Once a client's window has left the Withdrawn state, the window will be mapped
542 * if it is in the Normal state and the window will be unmapped if it is in the Iconic state."
544 * At this stage it's just safer to keep it in normal state and avoid confusion.
546 window_state_set(c
->win
, XCB_WM_STATE_NORMAL
);
548 /* Move window outside the viewport before mapping it. */
550 xcb_map_window(globalconf
.connection
, c
->win
);
553 spawn_start_notify(c
);
555 /* Call hook to notify list change */
556 if(globalconf
.hooks
.clients
!= LUA_REFNIL
)
557 luaA_dofunction(globalconf
.L
, globalconf
.hooks
.clients
, 0, 0);
560 if(globalconf
.hooks
.manage
!= LUA_REFNIL
)
562 client_push(globalconf
.L
, c
);
563 lua_pushboolean(globalconf
.L
, startup
);
564 luaA_dofunction(globalconf
.L
, globalconf
.hooks
.manage
, 2, 0);
568 /** Compute client geometry with respect to its geometry hints.
569 * \param c The client.
570 * \param geometry The geometry that the client might receive.
571 * \return The geometry the client must take respecting its hints.
574 client_geometry_hints(client_t
*c
, area_t geometry
)
576 int32_t basew
, baseh
, minw
, minh
;
578 /* base size is substituted with min size if not specified */
579 if(c
->size_hints
.flags
& XCB_SIZE_HINT_P_SIZE
)
581 basew
= c
->size_hints
.base_width
;
582 baseh
= c
->size_hints
.base_height
;
584 else if(c
->size_hints
.flags
& XCB_SIZE_HINT_P_MIN_SIZE
)
586 basew
= c
->size_hints
.min_width
;
587 baseh
= c
->size_hints
.min_height
;
592 /* min size is substituted with base size if not specified */
593 if(c
->size_hints
.flags
& XCB_SIZE_HINT_P_MIN_SIZE
)
595 minw
= c
->size_hints
.min_width
;
596 minh
= c
->size_hints
.min_height
;
598 else if(c
->size_hints
.flags
& XCB_SIZE_HINT_P_SIZE
)
600 minw
= c
->size_hints
.base_width
;
601 minh
= c
->size_hints
.base_height
;
606 if(c
->size_hints
.flags
& XCB_SIZE_HINT_P_ASPECT
607 && c
->size_hints
.min_aspect_num
> 0
608 && c
->size_hints
.min_aspect_den
> 0
609 && geometry
.height
- baseh
> 0
610 && geometry
.width
- basew
> 0)
612 double dx
= (double) (geometry
.width
- basew
);
613 double dy
= (double) (geometry
.height
- baseh
);
614 double min
= (double) c
->size_hints
.min_aspect_num
/ (double) c
->size_hints
.min_aspect_den
;
615 double max
= (double) c
->size_hints
.max_aspect_num
/ (double) c
->size_hints
.min_aspect_den
;
616 double ratio
= dx
/ dy
;
617 if(max
> 0 && min
> 0 && ratio
> 0)
621 dy
= (dx
* min
+ dy
) / (min
* min
+ 1);
623 geometry
.width
= (int) dx
+ basew
;
624 geometry
.height
= (int) dy
+ baseh
;
628 dy
= (dx
* min
+ dy
) / (max
* max
+ 1);
630 geometry
.width
= (int) dx
+ basew
;
631 geometry
.height
= (int) dy
+ baseh
;
637 geometry
.width
= MAX(geometry
.width
, minw
);
639 geometry
.height
= MAX(geometry
.height
, minh
);
641 if(c
->size_hints
.flags
& XCB_SIZE_HINT_P_MAX_SIZE
)
643 if(c
->size_hints
.max_width
)
644 geometry
.width
= MIN(geometry
.width
, c
->size_hints
.max_width
);
645 if(c
->size_hints
.max_height
)
646 geometry
.height
= MIN(geometry
.height
, c
->size_hints
.max_height
);
649 if(c
->size_hints
.flags
& (XCB_SIZE_HINT_P_RESIZE_INC
| XCB_SIZE_HINT_BASE_SIZE
)
650 && c
->size_hints
.width_inc
&& c
->size_hints
.height_inc
)
652 uint16_t t1
= geometry
.width
, t2
= geometry
.height
;
653 unsigned_subtract(t1
, basew
);
654 unsigned_subtract(t2
, baseh
);
655 geometry
.width
-= t1
% c
->size_hints
.width_inc
;
656 geometry
.height
-= t2
% c
->size_hints
.height_inc
;
662 /** Resize client window.
663 * The sizse given as parameters are with titlebar and borders!
664 * \param c Client to resize.
665 * \param geometry New window geometry.
666 * \param hints Use size hints.
667 * \return true if an actual resize occurred.
670 client_resize(client_t
*c
, area_t geometry
, bool hints
)
672 area_t geometry_internal
;
675 /* offscreen appearance fixes */
676 area
= display_area_get(c
->phys_screen
);
678 if(geometry
.x
> area
.width
)
679 geometry
.x
= area
.width
- geometry
.width
;
680 if(geometry
.y
> area
.height
)
681 geometry
.y
= area
.height
- geometry
.height
;
682 if(geometry
.x
+ geometry
.width
< 0)
684 if(geometry
.y
+ geometry
.height
< 0)
687 /* Real client geometry, please keep it contained to C code at the very least. */
688 geometry_internal
= titlebar_geometry_remove(c
->titlebar
, c
->border
, geometry
);
691 geometry_internal
= client_geometry_hints(c
, geometry_internal
);
693 if(geometry_internal
.width
== 0 || geometry_internal
.height
== 0)
696 /* Also let client hints propegate to the "official" geometry. */
697 geometry
= titlebar_geometry_add(c
->titlebar
, c
->border
, geometry_internal
);
699 if(c
->geometries
.internal
.x
!= geometry_internal
.x
700 || c
->geometries
.internal
.y
!= geometry_internal
.y
701 || c
->geometries
.internal
.width
!= geometry_internal
.width
702 || c
->geometries
.internal
.height
!= geometry_internal
.height
)
704 screen_t
*new_screen
= screen_getbycoord(c
->screen
,
705 geometry_internal
.x
, geometry_internal
.y
);
707 /* Values to configure a window is an array where values are
708 * stored according to 'value_mask' */
711 c
->geometries
.internal
.x
= values
[0] = geometry_internal
.x
;
712 c
->geometries
.internal
.y
= values
[1] = geometry_internal
.y
;
713 c
->geometries
.internal
.width
= values
[2] = geometry_internal
.width
;
714 c
->geometries
.internal
.height
= values
[3] = geometry_internal
.height
;
716 /* Also store geometry including border and titlebar. */
717 c
->geometry
= geometry
;
719 titlebar_update_geometry(c
);
721 /* The idea is to give a client a resize even when banned. */
722 /* We just have to move the (x,y) to keep it out of the viewport. */
723 /* This at least doesn't break expectations about events. */
726 geometry_internal
.x
= values
[0] = - (geometry_internal
.width
+ 2 * c
->border
);
727 geometry_internal
.y
= values
[1] = - (geometry_internal
.height
+ 2 * c
->border
);
730 xcb_configure_window(globalconf
.connection
, c
->win
,
731 XCB_CONFIG_WINDOW_X
| XCB_CONFIG_WINDOW_Y
732 | XCB_CONFIG_WINDOW_WIDTH
| XCB_CONFIG_WINDOW_HEIGHT
,
735 screen_client_moveto(c
, new_screen
, true, false);
738 hook_property(client
, c
, "geometry");
746 /** Set a client minimized, or not.
747 * \param c The client.
748 * \param s Set or not the client minimized.
751 client_setminimized(client_t
*c
, bool s
)
753 if(c
->isminimized
!= s
)
755 client_need_arrange(c
);
757 client_need_arrange(c
);
759 window_state_set(c
->win
, XCB_WM_STATE_ICONIC
);
761 window_state_set(c
->win
, XCB_WM_STATE_NORMAL
);
762 ewmh_client_update_hints(c
);
764 hook_property(client
, c
, "minimized");
768 /** Set a client sticky, or not.
769 * \param c The client.
770 * \param s Set or not the client sticky.
773 client_setsticky(client_t
*c
, bool s
)
777 client_need_arrange(c
);
779 client_need_arrange(c
);
780 ewmh_client_update_hints(c
);
781 hook_property(client
, c
, "sticky");
785 /** Set a client fullscreen, or not.
786 * \param c The client.
787 * \param s Set or not the client fullscreen.
790 client_setfullscreen(client_t
*c
, bool s
)
792 if(c
->isfullscreen
!= s
)
796 /* Make sure the current geometry is stored without titlebar. */
798 titlebar_ban(c
->titlebar
);
800 /* become fullscreen! */
801 if((c
->isfullscreen
= s
))
803 /* remove any max state */
804 client_setmaxhoriz(c
, false);
805 client_setmaxvert(c
, false);
806 /* You can only be part of one of the special layers. */
807 client_setbelow(c
, false);
808 client_setabove(c
, false);
809 client_setontop(c
, false);
811 geometry
= screen_area_get(c
->screen
, false);
812 c
->geometries
.fullscreen
= c
->geometry
;
813 c
->border_fs
= c
->border
;
814 client_setborder(c
, 0);
818 geometry
= c
->geometries
.fullscreen
;
819 client_setborder(c
, c
->border_fs
);
821 client_resize(c
, geometry
, false);
823 ewmh_client_update_hints(c
);
824 hook_property(client
, c
, "fullscreen");
828 /** Set a client horizontally maximized.
829 * \param c The client.
830 * \param s The maximized status.
833 client_setmaxhoriz(client_t
*c
, bool s
)
835 if(c
->ismaxhoriz
!= s
)
839 if((c
->ismaxhoriz
= s
))
841 /* remove fullscreen mode */
842 client_setfullscreen(c
, false);
844 geometry
= screen_area_get(c
->screen
, true);
845 geometry
.y
= c
->geometry
.y
;
846 geometry
.height
= c
->geometry
.height
;
847 c
->geometries
.max
.x
= c
->geometry
.x
;
848 c
->geometries
.max
.width
= c
->geometry
.width
;
852 geometry
= c
->geometry
;
853 geometry
.x
= c
->geometries
.max
.x
;
854 geometry
.width
= c
->geometries
.max
.width
;
857 client_resize(c
, geometry
, c
->size_hints_honor
);
859 ewmh_client_update_hints(c
);
860 hook_property(client
, c
, "maximized_horizontal");
864 /** Set a client vertically maximized.
865 * \param c The client.
866 * \param s The maximized status.
869 client_setmaxvert(client_t
*c
, bool s
)
871 if(c
->ismaxvert
!= s
)
875 if((c
->ismaxvert
= s
))
877 /* remove fullscreen mode */
878 client_setfullscreen(c
, false);
880 geometry
= screen_area_get(c
->screen
, true);
881 geometry
.x
= c
->geometry
.x
;
882 geometry
.width
= c
->geometry
.width
;
883 c
->geometries
.max
.y
= c
->geometry
.y
;
884 c
->geometries
.max
.height
= c
->geometry
.height
;
888 geometry
= c
->geometry
;
889 geometry
.y
= c
->geometries
.max
.y
;
890 geometry
.height
= c
->geometries
.max
.height
;
893 client_resize(c
, geometry
, c
->size_hints_honor
);
895 ewmh_client_update_hints(c
);
896 hook_property(client
, c
, "maximized_vertical");
900 /** Set a client above, or not.
901 * \param c The client.
902 * \param s Set or not the client above.
905 client_setabove(client_t
*c
, bool s
)
909 /* You can only be part of one of the special layers. */
912 client_setbelow(c
, false);
913 client_setontop(c
, false);
914 client_setfullscreen(c
, false);
918 ewmh_client_update_hints(c
);
920 hook_property(client
, c
, "above");
924 /** Set a client below, or not.
925 * \param c The client.
926 * \param s Set or not the client below.
929 client_setbelow(client_t
*c
, bool s
)
933 /* You can only be part of one of the special layers. */
936 client_setabove(c
, false);
937 client_setontop(c
, false);
938 client_setfullscreen(c
, false);
942 ewmh_client_update_hints(c
);
944 hook_property(client
, c
, "below");
948 /** Set a client modal, or not.
949 * \param c The client.
950 * \param s Set or not the client moda.
953 client_setmodal(client_t
*c
, bool s
)
959 ewmh_client_update_hints(c
);
961 hook_property(client
, c
, "modal");
965 /** Set a client ontop, or not.
966 * \param c The client.
967 * \param s Set or not the client moda.
970 client_setontop(client_t
*c
, bool s
)
974 /* You can only be part of one of the special layers. */
977 client_setabove(c
, false);
978 client_setbelow(c
, false);
979 client_setfullscreen(c
, false);
984 hook_property(client
, c
, "ontop");
988 /** Unban a client and move it back into the viewport.
989 * \param c The client.
992 client_unban(client_t
*c
)
996 /* Move the client back where it belongs. */
997 uint32_t request
[] = { c
->geometries
.internal
.x
,
998 c
->geometries
.internal
.y
,
999 c
->geometries
.internal
.width
,
1000 c
->geometries
.internal
.height
};
1002 xcb_configure_window(globalconf
.connection
, c
->win
,
1004 | XCB_CONFIG_WINDOW_Y
1005 | XCB_CONFIG_WINDOW_WIDTH
1006 | XCB_CONFIG_WINDOW_HEIGHT
,
1009 c
->isbanned
= false;
1013 /** Unmanage a client.
1014 * \param c The client.
1017 client_unmanage(client_t
*c
)
1019 tag_array_t
*tags
= &c
->screen
->tags
;
1021 /* Reset transient_for attributes of widows that maybe refering to us */
1022 foreach(_tc
, globalconf
.clients
)
1024 client_t
*tc
= *_tc
;
1025 if(tc
->transient_for
== c
)
1026 tc
->transient_for
= NULL
;
1029 if(globalconf
.screens
.tab
[c
->phys_screen
].prev_client_focus
== c
)
1030 globalconf
.screens
.tab
[c
->phys_screen
].prev_client_focus
= NULL
;
1032 if(globalconf
.screens
.tab
[c
->phys_screen
].client_focus
== c
)
1035 /* remove client from global list and everywhere else */
1036 foreach(elem
, globalconf
.clients
)
1039 client_array_remove(&globalconf
.clients
, elem
);
1042 stack_client_remove(c
);
1043 for(int i
= 0; i
< tags
->len
; i
++)
1044 untag_client(c
, tags
->tab
[i
]);
1047 if(globalconf
.hooks
.unmanage
!= LUA_REFNIL
)
1049 client_push(globalconf
.L
, c
);
1050 luaA_dofunction(globalconf
.L
, globalconf
.hooks
.unmanage
, 1, 0);
1053 /* Call hook to notify list change */
1054 if(globalconf
.hooks
.clients
!= LUA_REFNIL
)
1055 luaA_dofunction(globalconf
.L
, globalconf
.hooks
.clients
, 0, 0);
1057 /* The server grab construct avoids race conditions. */
1058 xcb_grab_server(globalconf
.connection
);
1060 xcb_ungrab_button(globalconf
.connection
, XCB_BUTTON_INDEX_ANY
, c
->win
,
1061 XCB_BUTTON_MASK_ANY
);
1062 window_state_set(c
->win
, XCB_WM_STATE_WITHDRAWN
);
1064 xcb_flush(globalconf
.connection
);
1065 xcb_ungrab_server(globalconf
.connection
);
1067 titlebar_client_detach(c
);
1069 ewmh_update_net_client_list(c
->phys_screen
);
1071 /* set client as invalid */
1074 client_unref(globalconf
.L
, c
);
1077 /** Kill a client via a WM_DELETE_WINDOW request or KillClient if not
1079 * \param c The client to kill.
1082 client_kill(client_t
*c
)
1084 if(window_hasproto(c
->win
, WM_DELETE_WINDOW
))
1086 xcb_client_message_event_t ev
;
1088 /* Initialize all of event's fields first */
1091 ev
.response_type
= XCB_CLIENT_MESSAGE
;
1094 ev
.data
.data32
[1] = XCB_CURRENT_TIME
;
1095 ev
.type
= WM_PROTOCOLS
;
1096 ev
.data
.data32
[0] = WM_DELETE_WINDOW
;
1098 xcb_send_event(globalconf
.connection
, false, c
->win
,
1099 XCB_EVENT_MASK_NO_EVENT
, (char *) &ev
);
1102 xcb_kill_client(globalconf
.connection
, c
->win
);
1105 /** Get all clients into a table.
1106 * \param L The Lua VM state.
1107 * \return The number of elements pushed on stack.
1109 * \lparam An optional screen nunmber.
1110 * \lreturn A table with all clients.
1113 luaA_client_get(lua_State
*L
)
1117 screen
= luaL_optnumber(L
, 1, 0) - 1;
1122 foreach(c
, globalconf
.clients
)
1125 lua_rawseti(L
, -2, i
++);
1129 luaA_checkscreen(screen
);
1130 foreach(c
, globalconf
.clients
)
1131 if((*c
)->screen
== &globalconf
.screens
.tab
[screen
])
1134 lua_rawseti(L
, -2, i
++);
1141 /** Check if a client is visible on its screen.
1142 * \param L The Lua VM state.
1143 * \return The number of elements pushed on stack.
1146 * \lreturn A boolean value, true if the client is visible, false otherwise.
1149 luaA_client_isvisible(lua_State
*L
)
1151 client_t
*c
= luaA_client_checkudata(L
, 1);
1152 lua_pushboolean(L
, client_isvisible(c
, c
->screen
));
1156 /** Set client border width.
1157 * \param c The client.
1158 * \param width The border width.
1161 client_setborder(client_t
*c
, int width
)
1165 if(width
> 0 && (c
->type
== WINDOW_TYPE_DOCK
1166 || c
->type
== WINDOW_TYPE_SPLASH
1167 || c
->type
== WINDOW_TYPE_DESKTOP
1168 || c
->isfullscreen
))
1171 if(width
== c
->border
|| width
< 0)
1174 /* Update geometry with the new border. */
1175 c
->geometry
.width
-= 2 * c
->border
;
1176 c
->geometry
.height
-= 2 * c
->border
;
1179 xcb_configure_window(globalconf
.connection
, c
->win
,
1180 XCB_CONFIG_WINDOW_BORDER_WIDTH
, &w
);
1182 c
->geometry
.width
+= 2 * c
->border
;
1183 c
->geometry
.height
+= 2 * c
->border
;
1185 /* Changing border size also affects the size of the titlebar. */
1186 titlebar_update_geometry(c
);
1188 hook_property(client
, c
, "border_width");
1192 * \param L The Lua VM state.
1198 luaA_client_kill(lua_State
*L
)
1200 client_t
*c
= luaA_client_checkudata(L
, 1);
1205 /** Swap a client with another one.
1206 * \param L The Lua VM state.
1209 * \lparam A client to swap with.
1212 luaA_client_swap(lua_State
*L
)
1214 client_t
*c
= luaA_client_checkudata(L
, 1);
1215 client_t
*swap
= luaA_client_checkudata(L
, 2);
1219 client_t
**ref_c
= NULL
, **ref_swap
= NULL
;
1220 foreach(item
, globalconf
.clients
)
1224 else if(*item
== swap
)
1226 if(ref_c
&& ref_swap
)
1233 /* Call hook to notify list change */
1234 if(globalconf
.hooks
.clients
!= LUA_REFNIL
)
1235 luaA_dofunction(L
, globalconf
.hooks
.clients
, 0, 0);
1241 /** Access or set the client tags.
1242 * \param L The Lua VM state.
1243 * \return The number of elements pushed on stack.
1244 * \lparam A table with tags to set, or none to get the current tags table.
1245 * \return The clients tag.
1248 luaA_client_tags(lua_State
*L
)
1250 client_t
*c
= luaA_client_checkudata(L
, 1);
1251 tag_array_t
*tags
= &c
->screen
->tags
;
1254 if(lua_gettop(L
) == 2)
1256 luaA_checktable(L
, 2);
1257 for(int i
= 0; i
< tags
->len
; i
++)
1258 untag_client(c
, tags
->tab
[i
]);
1260 while(lua_next(L
, 2))
1267 if(is_client_tagged(c
, *tag
))
1270 lua_rawseti(L
, -2, ++j
);
1276 /** Raise a client on top of others which are on the same layer.
1277 * \param L The Lua VM state.
1282 luaA_client_raise(lua_State
*L
)
1284 client_t
*c
= luaA_client_checkudata(L
, 1);
1289 /** Lower a client on bottom of others which are on the same layer.
1290 * \param L The Lua VM state.
1295 luaA_client_lower(lua_State
*L
)
1297 client_t
*c
= luaA_client_checkudata(L
, 1);
1302 /** Redraw a client by unmapping and mapping it quickly.
1303 * \param L The Lua VM state.
1309 luaA_client_redraw(lua_State
*L
)
1311 client_t
*c
= luaA_client_checkudata(L
, 1);
1313 xcb_unmap_window(globalconf
.connection
, c
->win
);
1314 xcb_map_window(globalconf
.connection
, c
->win
);
1316 /* Set the focus on the current window if the redraw has been
1317 performed on the window where the pointer is currently on
1318 because after the unmapping/mapping, the focus is lost */
1319 if(globalconf
.screen_focus
->client_focus
== c
)
1328 /** Stop managing a client.
1329 * \param L The Lua VM state.
1330 * \return The number of elements pushed on stack.
1335 luaA_client_unmanage(lua_State
*L
)
1337 client_t
*c
= luaA_client_checkudata(L
, 1);
1342 /** Return client geometry.
1343 * \param L The Lua VM state.
1344 * \return The number of elements pushed on stack.
1346 * \lparam A table with new coordinates, or none.
1347 * \lreturn A table with client coordinates.
1350 luaA_client_geometry(lua_State
*L
)
1352 client_t
*c
= luaA_client_checkudata(L
, 1);
1354 if(lua_gettop(L
) == 2)
1358 luaA_checktable(L
, 2);
1359 geometry
.x
= luaA_getopt_number(L
, 2, "x", c
->geometry
.x
);
1360 geometry
.y
= luaA_getopt_number(L
, 2, "y", c
->geometry
.y
);
1361 if(client_isfixed(c
))
1363 geometry
.width
= c
->geometry
.width
;
1364 geometry
.height
= c
->geometry
.height
;
1368 geometry
.width
= luaA_getopt_number(L
, 2, "width", c
->geometry
.width
);
1369 geometry
.height
= luaA_getopt_number(L
, 2, "height", c
->geometry
.height
);
1372 client_resize(c
, geometry
, c
->size_hints_honor
);
1375 return luaA_pusharea(L
, c
->geometry
);
1378 /** Push a strut type to a table on stack.
1379 * \param L The Lua VM state.
1380 * \param struts The struts to push.
1381 * \return The number of elements pushed on stack.
1384 luaA_pushstruts(lua_State
*L
, strut_t struts
)
1386 lua_createtable(L
, 4, 0);
1387 lua_pushnumber(L
, struts
.left
);
1388 lua_setfield(L
, -2, "left");
1389 lua_pushnumber(L
, struts
.right
);
1390 lua_setfield(L
, -2, "right");
1391 lua_pushnumber(L
, struts
.top
);
1392 lua_setfield(L
, -2, "top");
1393 lua_pushnumber(L
, struts
.bottom
);
1394 lua_setfield(L
, -2, "bottom");
1398 /** Return client struts (reserved space at the edge of the screen).
1399 * \param L The Lua VM state.
1400 * \return The number of elements pushed on stack.
1402 * \lparam A table with new strut values, or none.
1403 * \lreturn A table with strut values.
1406 luaA_client_struts(lua_State
*L
)
1408 client_t
*c
= luaA_client_checkudata(L
, 1);
1410 if(lua_gettop(L
) == 2)
1413 area_t screen_area
= display_area_get(c
->phys_screen
);
1415 struts
.left
= luaA_getopt_number(L
, 2, "left", c
->strut
.left
);
1416 struts
.right
= luaA_getopt_number(L
, 2, "right", c
->strut
.right
);
1417 struts
.top
= luaA_getopt_number(L
, 2, "top", c
->strut
.top
);
1418 struts
.bottom
= luaA_getopt_number(L
, 2, "bottom", c
->strut
.bottom
);
1420 if(struts
.left
!= c
->strut
.left
|| struts
.right
!= c
->strut
.right
||
1421 struts
.top
!= c
->strut
.top
|| struts
.bottom
!= c
->strut
.bottom
) {
1422 /* Struts are not so well defined in the context of xinerama. So we just
1423 * give the entire root window and let the window manager decide. */
1424 struts
.left_start_y
= 0;
1425 struts
.left_end_y
= !struts
.left
? 0 : screen_area
.height
;
1426 struts
.right_start_y
= 0;
1427 struts
.right_end_y
= !struts
.right
? 0 : screen_area
.height
;
1428 struts
.top_start_x
= 0;
1429 struts
.top_end_x
= !struts
.top
? 0 : screen_area
.width
;
1430 struts
.bottom_start_x
= 0;
1431 struts
.bottom_end_x
= !struts
.bottom
? 0 : screen_area
.width
;
1435 ewmh_update_client_strut(c
);
1437 hook_property(client
, c
, "struts");
1441 return luaA_pushstruts(L
, c
->strut
);
1444 /** Client newindex.
1445 * \param L The Lua VM state.
1446 * \return The number of elements pushed on stack.
1449 luaA_client_newindex(lua_State
*L
)
1452 client_t
*c
= luaA_client_checkudata(L
, 1);
1453 const char *buf
= luaL_checklstring(L
, 2, &len
);
1458 switch(a_tokenize(buf
, len
))
1461 if(globalconf
.xinerama_is_active
)
1463 i
= luaL_checknumber(L
, 3) - 1;
1464 luaA_checkscreen(i
);
1465 screen_client_moveto(c
, &globalconf
.screens
.tab
[i
], true, true);
1469 b
= luaA_checkboolean(L
, 3);
1470 if(b
!= c
->ishidden
)
1472 client_need_arrange(c
);
1474 client_need_arrange(c
);
1475 hook_property(client
, c
, "hide");
1478 case A_TK_MINIMIZED
:
1479 client_setminimized(c
, luaA_checkboolean(L
, 3));
1481 case A_TK_FULLSCREEN
:
1482 client_setfullscreen(c
, luaA_checkboolean(L
, 3));
1484 case A_TK_MAXIMIZED_HORIZONTAL
:
1485 client_setmaxhoriz(c
, luaA_checkboolean(L
, 3));
1487 case A_TK_MAXIMIZED_VERTICAL
:
1488 client_setmaxvert(c
, luaA_checkboolean(L
, 3));
1491 image_unref(L
, c
->icon
);
1492 c
->icon
= image_ref(L
);
1494 hook_property(client
, c
, "icon");
1498 window_opacity_set(c
->win
, -1);
1501 d
= luaL_checknumber(L
, 3);
1502 if(d
>= 0 && d
<= 1)
1503 window_opacity_set(c
->win
, d
);
1507 client_setsticky(c
, luaA_checkboolean(L
, 3));
1509 case A_TK_SIZE_HINTS_HONOR
:
1510 c
->size_hints_honor
= luaA_checkboolean(L
, 3);
1511 hook_property(client
, c
, "size_hints_honor");
1513 case A_TK_BORDER_WIDTH
:
1514 client_setborder(c
, luaL_checknumber(L
, 3));
1517 client_setontop(c
, luaA_checkboolean(L
, 3));
1520 client_setabove(c
, luaA_checkboolean(L
, 3));
1523 client_setbelow(c
, luaA_checkboolean(L
, 3));
1526 client_seturgent(c
, luaA_checkboolean(L
, 3));
1528 case A_TK_BORDER_COLOR
:
1529 if((buf
= luaL_checklstring(L
, 3, &len
))
1530 && xcolor_init_reply(xcolor_init_unchecked(&c
->border_color
, buf
, len
)))
1531 xcb_change_window_attributes(globalconf
.connection
, c
->win
,
1532 XCB_CW_BORDER_PIXEL
, &c
->border_color
.pixel
);
1536 titlebar_client_detach(c
);
1538 titlebar_client_attach(c
);
1540 case A_TK_SKIP_TASKBAR
:
1541 c
->skiptb
= luaA_checkboolean(L
, 3);
1542 hook_property(client
, c
, "skip_taskbar");
1552 * \param L The Lua VM state.
1553 * \return The number of elements pushed on stack.
1555 * \lfield id The window X id.
1556 * \lfield name The client title.
1557 * \lfield skip_taskbar If true the client won't be shown in the tasklist.
1558 * \lfield type The window type (desktop, normal, dock, …).
1559 * \lfield class The client class.
1560 * \lfield instance The client instance.
1561 * \lfield pid The client PID, if available.
1562 * \lfield role The window role, if available.
1563 * \lfield machine The machine client is running on.
1564 * \lfield icon_name The client name when iconified.
1565 * \lfield screen Client screen number.
1566 * \lfield hide Define if the client must be hidden, i.e. never mapped,
1567 * invisible in taskbar.
1568 * \lfield minimized Define it the client must be iconify, i.e. only visible in
1570 * \lfield size_hints_honor Honor size hints, i.e. respect size ratio.
1571 * \lfield border_width The client border width.
1572 * \lfield border_color The client border color.
1573 * \lfield titlebar The client titlebar.
1574 * \lfield urgent The client urgent state.
1575 * \lfield content An image representing the client window content (screenshot).
1576 * \lfield focus The focused client.
1577 * \lfield opacity The client opacity between 0 and 1.
1578 * \lfield ontop The client is on top of every other windows.
1579 * \lfield above The client is above normal windows.
1580 * \lfield below The client is below normal windows.
1581 * \lfield fullscreen The client is fullscreen or not.
1582 * \lfield maximized_horizontal The client is maximized horizontally or not.
1583 * \lfield maximized_vertical The client is maximized vertically or not.
1584 * \lfield transient_for Return the client the window is transient for.
1585 * \lfield group_id Identification unique to a group of windows.
1586 * \lfield leader_id Identification unique to windows spawned by the same command.
1587 * \lfield size_hints A table with size hints of the client: user_position,
1588 * user_size, program_position, program_size, etc.
1591 luaA_client_index(lua_State
*L
)
1595 client_t
*c
= luaA_client_checkudata(L
, 1);
1596 const char *buf
= luaL_checklstring(L
, 2, &len
);
1599 xcb_get_property_cookie_t prop_c
;
1600 xcb_get_property_reply_t
*prop_r
= NULL
;
1603 if(luaA_usemetatable(L
, 1, 2))
1606 switch(a_tokenize(buf
, len
))
1609 lua_pushstring(L
, c
->name
);
1611 case A_TK_TRANSIENT_FOR
:
1612 return client_push(globalconf
.L
, c
->transient_for
);
1613 case A_TK_SKIP_TASKBAR
:
1614 lua_pushboolean(L
, c
->skiptb
);
1617 return client_getcontent(c
);
1621 case WINDOW_TYPE_DESKTOP
:
1622 lua_pushliteral(L
, "desktop");
1624 case WINDOW_TYPE_DOCK
:
1625 lua_pushliteral(L
, "dock");
1627 case WINDOW_TYPE_SPLASH
:
1628 lua_pushliteral(L
, "splash");
1630 case WINDOW_TYPE_DIALOG
:
1631 lua_pushliteral(L
, "dialog");
1633 case WINDOW_TYPE_MENU
:
1634 lua_pushliteral(L
, "menu");
1636 case WINDOW_TYPE_TOOLBAR
:
1637 lua_pushliteral(L
, "toolbar");
1639 case WINDOW_TYPE_UTILITY
:
1640 lua_pushliteral(L
, "utility");
1642 case WINDOW_TYPE_DROPDOWN_MENU
:
1643 lua_pushliteral(L
, "dropdown_menu");
1645 case WINDOW_TYPE_POPUP_MENU
:
1646 lua_pushliteral(L
, "popup_menu");
1648 case WINDOW_TYPE_TOOLTIP
:
1649 lua_pushliteral(L
, "tooltip");
1651 case WINDOW_TYPE_NOTIFICATION
:
1652 lua_pushliteral(L
, "notification");
1654 case WINDOW_TYPE_COMBO
:
1655 lua_pushliteral(L
, "combo");
1657 case WINDOW_TYPE_DND
:
1658 lua_pushliteral(L
, "dnd");
1660 case WINDOW_TYPE_NORMAL
:
1661 lua_pushliteral(L
, "normal");
1666 lua_pushstring(L
, c
->class);
1669 lua_pushstring(L
, c
->instance
);
1672 if(!xutil_text_prop_get(globalconf
.connection
, c
->win
,
1673 WM_WINDOW_ROLE
, &value
, &slen
))
1675 lua_pushlstring(L
, value
, slen
);
1679 prop_c
= xcb_get_property_unchecked(globalconf
.connection
, false, c
->win
, _NET_WM_PID
, CARDINAL
, 0L, 1L);
1680 prop_r
= xcb_get_property_reply(globalconf
.connection
, prop_c
, NULL
);
1682 if(prop_r
&& prop_r
->value_len
&& (data
= xcb_get_property_value(prop_r
)))
1683 lua_pushnumber(L
, *(uint32_t *)data
);
1691 lua_pushnumber(L
, c
->win
);
1693 case A_TK_LEADER_ID
:
1694 lua_pushnumber(L
, c
->leader_win
);
1697 if(!xutil_text_prop_get(globalconf
.connection
, c
->win
,
1698 WM_CLIENT_MACHINE
, &value
, &slen
))
1700 lua_pushlstring(L
, value
, slen
);
1703 case A_TK_ICON_NAME
:
1704 lua_pushstring(L
, c
->icon_name
);
1707 lua_pushnumber(L
, 1 + screen_array_indexof(&globalconf
.screens
, c
->screen
));
1710 lua_pushboolean(L
, c
->ishidden
);
1712 case A_TK_MINIMIZED
:
1713 lua_pushboolean(L
, c
->isminimized
);
1715 case A_TK_FULLSCREEN
:
1716 lua_pushboolean(L
, c
->isfullscreen
);
1720 lua_pushnumber(L
, c
->group_win
);
1724 case A_TK_MAXIMIZED_HORIZONTAL
:
1725 lua_pushboolean(L
, c
->ismaxhoriz
);
1727 case A_TK_MAXIMIZED_VERTICAL
:
1728 lua_pushboolean(L
, c
->ismaxvert
);
1731 image_push(L
, c
->icon
);
1734 if((d
= window_opacity_get(c
->win
)) >= 0)
1735 lua_pushnumber(L
, d
);
1740 lua_pushboolean(L
, c
->isontop
);
1743 lua_pushboolean(L
, c
->isabove
);
1746 lua_pushboolean(L
, c
->isbelow
);
1749 lua_pushboolean(L
, c
->issticky
);
1751 case A_TK_SIZE_HINTS_HONOR
:
1752 lua_pushboolean(L
, c
->size_hints_honor
);
1754 case A_TK_BORDER_WIDTH
:
1755 lua_pushnumber(L
, c
->border
);
1757 case A_TK_BORDER_COLOR
:
1758 luaA_pushxcolor(L
, &c
->border_color
);
1761 return wibox_push(L
, c
->titlebar
);
1763 lua_pushboolean(L
, c
->isurgent
);
1765 case A_TK_SIZE_HINTS
:
1767 const char *u_or_p
= NULL
;
1769 lua_createtable(L
, 0, 1);
1771 if(c
->size_hints
.flags
& XCB_SIZE_HINT_US_POSITION
)
1772 u_or_p
= "user_position";
1773 else if(c
->size_hints
.flags
& XCB_SIZE_HINT_P_POSITION
)
1774 u_or_p
= "program_position";
1778 lua_createtable(L
, 0, 2);
1779 lua_pushnumber(L
, c
->size_hints
.x
);
1780 lua_setfield(L
, -2, "x");
1781 lua_pushnumber(L
, c
->size_hints
.y
);
1782 lua_setfield(L
, -2, "y");
1783 lua_setfield(L
, -2, u_or_p
);
1787 if(c
->size_hints
.flags
& XCB_SIZE_HINT_US_SIZE
)
1788 u_or_p
= "user_size";
1789 else if(c
->size_hints
.flags
& XCB_SIZE_HINT_P_SIZE
)
1790 u_or_p
= "program_size";
1794 lua_createtable(L
, 0, 2);
1795 lua_pushnumber(L
, c
->size_hints
.width
);
1796 lua_setfield(L
, -2, "width");
1797 lua_pushnumber(L
, c
->size_hints
.height
);
1798 lua_setfield(L
, -2, "height");
1799 lua_setfield(L
, -2, u_or_p
);
1802 if(c
->size_hints
.flags
& XCB_SIZE_HINT_P_MIN_SIZE
)
1804 lua_pushnumber(L
, c
->size_hints
.min_width
);
1805 lua_setfield(L
, -2, "min_width");
1806 lua_pushnumber(L
, c
->size_hints
.min_height
);
1807 lua_setfield(L
, -2, "min_height");
1810 if(c
->size_hints
.flags
& XCB_SIZE_HINT_P_MAX_SIZE
)
1812 lua_pushnumber(L
, c
->size_hints
.max_width
);
1813 lua_setfield(L
, -2, "max_width");
1814 lua_pushnumber(L
, c
->size_hints
.max_height
);
1815 lua_setfield(L
, -2, "max_height");
1818 if(c
->size_hints
.flags
& XCB_SIZE_HINT_P_RESIZE_INC
)
1820 lua_pushnumber(L
, c
->size_hints
.width_inc
);
1821 lua_setfield(L
, -2, "width_inc");
1822 lua_pushnumber(L
, c
->size_hints
.height_inc
);
1823 lua_setfield(L
, -2, "height_inc");
1826 if(c
->size_hints
.flags
& XCB_SIZE_HINT_P_ASPECT
)
1828 lua_pushnumber(L
, c
->size_hints
.min_aspect_num
);
1829 lua_setfield(L
, -2, "min_aspect_num");
1830 lua_pushnumber(L
, c
->size_hints
.min_aspect_den
);
1831 lua_setfield(L
, -2, "min_aspect_den");
1832 lua_pushnumber(L
, c
->size_hints
.max_aspect_num
);
1833 lua_setfield(L
, -2, "max_aspect_num");
1834 lua_pushnumber(L
, c
->size_hints
.max_aspect_den
);
1835 lua_setfield(L
, -2, "max_aspect_den");
1838 if(c
->size_hints
.flags
& XCB_SIZE_HINT_BASE_SIZE
)
1840 lua_pushnumber(L
, c
->size_hints
.base_width
);
1841 lua_setfield(L
, -2, "base_width");
1842 lua_pushnumber(L
, c
->size_hints
.base_height
);
1843 lua_setfield(L
, -2, "base_height");
1846 if(c
->size_hints
.flags
& XCB_SIZE_HINT_P_WIN_GRAVITY
)
1848 switch(c
->size_hints
.win_gravity
)
1851 lua_pushliteral(L
, "north_west");
1853 case XCB_GRAVITY_NORTH
:
1854 lua_pushliteral(L
, "north");
1856 case XCB_GRAVITY_NORTH_EAST
:
1857 lua_pushliteral(L
, "north_east");
1859 case XCB_GRAVITY_WEST
:
1860 lua_pushliteral(L
, "west");
1862 case XCB_GRAVITY_CENTER
:
1863 lua_pushliteral(L
, "center");
1865 case XCB_GRAVITY_EAST
:
1866 lua_pushliteral(L
, "east");
1868 case XCB_GRAVITY_SOUTH_WEST
:
1869 lua_pushliteral(L
, "south_west");
1871 case XCB_GRAVITY_SOUTH
:
1872 lua_pushliteral(L
, "south");
1874 case XCB_GRAVITY_SOUTH_EAST
:
1875 lua_pushliteral(L
, "south_east");
1877 case XCB_GRAVITY_STATIC
:
1878 lua_pushliteral(L
, "static");
1881 lua_setfield(L
, -2, "win_gravity");
1892 /** Get or set mouse buttons bindings for a client.
1893 * \param L The Lua VM state.
1894 * \return The number of element pushed on stack.
1897 * \lparam An array of mouse button bindings objects, or nothing.
1898 * \return The array of mouse button bindings objects of this client.
1901 luaA_client_buttons(lua_State
*L
)
1903 client_t
*client
= luaA_client_checkudata(L
, 1);
1904 button_array_t
*buttons
= &client
->buttons
;
1906 if(lua_gettop(L
) == 2)
1907 luaA_button_array_set(L
, 2, buttons
);
1909 window_buttons_grab(client
->win
, &client
->buttons
);
1911 return luaA_button_array_get(L
, buttons
);
1914 /** Get or set keys bindings for a client.
1915 * \param L The Lua VM state.
1916 * \return The number of element pushed on stack.
1919 * \lparam An array of key bindings objects, or nothing.
1920 * \return The array of key bindings objects of this client.
1923 luaA_client_keys(lua_State
*L
)
1925 client_t
*c
= luaA_client_checkudata(L
, 1);
1926 key_array_t
*keys
= &c
->keys
;
1928 if(lua_gettop(L
) == 2)
1930 luaA_key_array_set(L
, 2, keys
);
1931 xcb_ungrab_key(globalconf
.connection
, XCB_GRAB_ANY
, c
->win
, XCB_BUTTON_MASK_ANY
);
1932 window_grabkeys(c
->win
, keys
);
1935 return luaA_key_array_get(L
, keys
);
1939 * \param L The Lua VM state.
1940 * \return The number of pushed elements.
1943 luaA_client_module_index(lua_State
*L
)
1946 const char *buf
= luaL_checklstring(L
, 2, &len
);
1948 switch(a_tokenize(buf
, len
))
1951 return client_push(globalconf
.L
, globalconf
.screen_focus
->client_focus
);
1958 /* Client module new index.
1959 * \param L The Lua VM state.
1960 * \return The number of pushed elements.
1963 luaA_client_module_newindex(lua_State
*L
)
1966 const char *buf
= luaL_checklstring(L
, 2, &len
);
1969 switch(a_tokenize(buf
, len
))
1972 c
= luaA_client_checkudata(L
, 3);
1982 const struct luaL_reg awesome_client_methods
[] =
1984 { "get", luaA_client_get
},
1985 { "__index", luaA_client_module_index
},
1986 { "__newindex", luaA_client_module_newindex
},
1989 const struct luaL_reg awesome_client_meta
[] =
1991 { "isvisible", luaA_client_isvisible
},
1992 { "geometry", luaA_client_geometry
},
1993 { "struts", luaA_client_struts
},
1994 { "buttons", luaA_client_buttons
},
1995 { "keys", luaA_client_keys
},
1996 { "tags", luaA_client_tags
},
1997 { "kill", luaA_client_kill
},
1998 { "swap", luaA_client_swap
},
1999 { "raise", luaA_client_raise
},
2000 { "lower", luaA_client_lower
},
2001 { "redraw", luaA_client_redraw
},
2002 { "unmanage", luaA_client_unmanage
},
2003 { "__index", luaA_client_index
},
2004 { "__newindex", luaA_client_newindex
},
2005 { "__gc", luaA_client_gc
},
2006 { "__tostring", luaA_client_tostring
},
2010 // vim: filetype=c:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=80