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 hooks_property(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 /* All the wiboxes (may) need to be repositioned. */
219 if(client_hasstrut(c
))
220 wibox_update_positions();
222 if(globalconf
.screens
.tab
[c
->phys_screen
].prev_client_focus
== c
)
223 globalconf
.screens
.tab
[c
->phys_screen
].prev_client_focus
= NULL
;
225 /* Wait until the last moment to take away the focus from the window. */
226 if(globalconf
.screens
.tab
[c
->phys_screen
].client_focus
== c
)
231 /** Record that a client got focus.
232 * \param c Client being focused.
235 client_focus_update(client_t
*c
)
237 if(!client_maybevisible(c
, c
->screen
))
239 /* Focus previously focused client */
240 client_focus(globalconf
.screen_focus
->prev_client_focus
);
244 if(globalconf
.screen_focus
245 && globalconf
.screen_focus
->client_focus
)
247 if (globalconf
.screen_focus
->client_focus
!= c
)
248 client_unfocus_update(globalconf
.screen_focus
->client_focus
);
250 /* Already focused */
253 /* stop hiding client */
255 client_setminimized(c
, false);
257 /* unban the client before focusing for consistency */
260 globalconf
.screen_focus
= &globalconf
.screens
.tab
[c
->phys_screen
];
261 globalconf
.screen_focus
->prev_client_focus
= c
;
262 globalconf
.screen_focus
->client_focus
= c
;
264 /* Some layouts use focused client differently, so call them back.
265 * And anyway, we have maybe unhidden */
266 client_need_arrange(c
);
268 /* according to EWMH, we have to remove the urgent state from a client */
269 client_seturgent(c
, false);
271 ewmh_update_net_active_window(c
->phys_screen
);
274 if(globalconf
.hooks
.focus
!= LUA_REFNIL
)
276 client_push(globalconf
.L
, c
);
277 luaA_dofunction(globalconf
.L
, globalconf
.hooks
.focus
, 1, 0);
282 /** Give focus to client, or to first client if client is NULL.
283 * \param c The client or NULL.
286 client_focus(client_t
*c
)
288 /* We have to set focus on first client */
289 if(!c
&& globalconf
.clients
.len
&& !(c
= globalconf
.clients
.tab
[0]))
292 if(!client_maybevisible(c
, c
->screen
))
296 client_focus_update(c
);
298 window_setfocus(c
->win
, !c
->nofocus
);
301 /** Stack a window below.
302 * \param c The client.
303 * \param previous The previous window on the stack.
304 * \param return The next-previous!
307 client_stack_above(client_t
*c
, xcb_window_t previous
)
309 uint32_t config_win_vals
[2];
311 config_win_vals
[0] = previous
;
312 config_win_vals
[1] = XCB_STACK_MODE_ABOVE
;
314 xcb_configure_window(globalconf
.connection
, c
->win
,
315 XCB_CONFIG_WINDOW_SIBLING
| XCB_CONFIG_WINDOW_STACK_MODE
,
318 config_win_vals
[0] = c
->win
;
322 xcb_configure_window(globalconf
.connection
,
323 c
->titlebar
->sw
.window
,
324 XCB_CONFIG_WINDOW_SIBLING
| XCB_CONFIG_WINDOW_STACK_MODE
,
326 previous
= c
->titlebar
->sw
.window
;
331 /* stack transient window on top of their parents */
332 foreach(node
, globalconf
.stack
)
333 if((*node
)->transient_for
== c
)
334 previous
= client_stack_above(*node
, previous
);
339 /** Stacking layout layers */
342 /** This one is a special layer */
350 /** This one only used for counting and is not a real layer */
354 /** Get the real layer of a client according to its attribute (fullscreen, …)
355 * \param c The client.
356 * \return The real layer.
359 client_layer_translator(client_t
*c
)
361 /* first deal with user set attributes */
364 else if(c
->isfullscreen
)
365 return LAYER_FULLSCREEN
;
371 /* check for transient attr */
375 /* then deal with windows type */
378 case WINDOW_TYPE_DESKTOP
:
379 return LAYER_DESKTOP
;
388 * \todo It might be worth stopping to restack everyone and only stack `c'
389 * relatively to the first matching in the list.
392 client_real_stack(void)
394 uint32_t config_win_vals
[2];
397 config_win_vals
[0] = XCB_NONE
;
398 config_win_vals
[1] = XCB_STACK_MODE_ABOVE
;
400 /* stack desktop windows */
401 for(layer
= LAYER_DESKTOP
; layer
< LAYER_BELOW
; layer
++)
402 foreach(node
, globalconf
.stack
)
403 if(client_layer_translator(*node
) == layer
)
404 config_win_vals
[0] = client_stack_above(*node
,
407 /* first stack not ontop wibox window */
408 foreach(s
, globalconf
.screens
)
409 foreach(_sb
, s
->wiboxes
)
414 xcb_configure_window(globalconf
.connection
,
416 XCB_CONFIG_WINDOW_SIBLING
| XCB_CONFIG_WINDOW_STACK_MODE
,
418 config_win_vals
[0] = sb
->sw
.window
;
422 /* then stack clients */
423 for(layer
= LAYER_BELOW
; layer
< LAYER_COUNT
; layer
++)
424 foreach(node
, globalconf
.stack
)
425 if(client_layer_translator(*node
) == layer
)
426 config_win_vals
[0] = client_stack_above(*node
,
429 /* then stack ontop wibox window */
430 foreach(s
, globalconf
.screens
)
431 foreach(_sb
, s
->wiboxes
)
436 xcb_configure_window(globalconf
.connection
,
438 XCB_CONFIG_WINDOW_SIBLING
| XCB_CONFIG_WINDOW_STACK_MODE
,
440 config_win_vals
[0] = sb
->sw
.window
;
446 client_stack_refresh()
448 if (!globalconf
.client_need_stack_refresh
)
450 globalconf
.client_need_stack_refresh
= false;
454 /** Manage a new client.
455 * \param w The window.
456 * \param wgeom Window geometry.
457 * \param phys_screen Physical screen number.
458 * \param startup True if we are managing at startup time.
461 client_manage(xcb_window_t w
, xcb_get_geometry_reply_t
*wgeom
, int phys_screen
, bool startup
)
463 xcb_get_property_cookie_t ewmh_icon_cookie
;
464 client_t
*c
, *tc
= NULL
;
466 const uint32_t select_input_val
[] = { CLIENT_SELECT_INPUT_EVENT_MASK
};
468 if(systray_iskdedockapp(w
))
470 systray_request_handle(w
, phys_screen
, NULL
);
474 /* Send request to get NET_WM_ICON property as soon as possible... */
475 ewmh_icon_cookie
= ewmh_window_icon_get_unchecked(w
);
476 xcb_change_window_attributes(globalconf
.connection
, w
, XCB_CW_EVENT_MASK
, select_input_val
);
478 c
= client_new(globalconf
.L
);
479 /* Push client in client list */
480 client_array_push(&globalconf
.clients
, client_ref(globalconf
.L
));
483 screen
= c
->screen
= screen_getbycoord(&globalconf
.screens
.tab
[phys_screen
],
486 c
->phys_screen
= phys_screen
;
490 c
->geometry
.x
= wgeom
->x
;
491 c
->geometry
.y
= wgeom
->y
;
492 /* Border will be added later. */
493 c
->geometry
.width
= wgeom
->width
;
494 c
->geometry
.height
= wgeom
->height
;
495 /* Also set internal geometry (client_ban() needs it). */
496 c
->geometries
.internal
.x
= wgeom
->x
;
497 c
->geometries
.internal
.y
= wgeom
->y
;
498 c
->geometries
.internal
.width
= wgeom
->width
;
499 c
->geometries
.internal
.height
= wgeom
->height
;
500 client_setborder(c
, wgeom
->border_width
);
502 if(ewmh_window_icon_get_reply(ewmh_icon_cookie
))
503 c
->icon
= image_ref(globalconf
.L
);
505 /* we honor size hints by default */
506 c
->size_hints_honor
= true;
509 property_update_wm_normal_hints(c
, NULL
);
510 property_update_wm_hints(c
, NULL
);
511 property_update_wm_transient_for(c
, NULL
);
512 property_update_wm_client_leader(c
, NULL
);
514 /* Recursively find the parent. */
515 for(tc
= c
; tc
->transient_for
; tc
= tc
->transient_for
);
516 if(tc
!= c
&& tc
->phys_screen
== c
->phys_screen
)
519 /* Then check clients hints */
520 ewmh_client_check_hints(c
);
522 /* move client to screen, but do not tag it */
523 screen_client_moveto(c
, screen
, false, true);
525 /* Push client in stack */
528 /* update window title */
529 property_update_wm_name(c
);
530 property_update_wm_icon_name(c
);
531 property_update_wm_class(c
, NULL
);
533 xutil_text_prop_get(globalconf
.connection
, c
->win
, _NET_STARTUP_ID
, &c
->startup_id
, NULL
);
536 ewmh_process_client_strut(c
, NULL
);
538 ewmh_update_net_client_list(c
->phys_screen
);
540 /* Always stay in NORMAL_STATE. Even though iconified seems more
541 * appropriate sometimes. The only possible loss is that clients not using
542 * visibility events may continue to proces data (when banned).
543 * Without any exposes or other events the cost should be fairly limited though.
545 * Some clients may expect the window to be unmapped when STATE_ICONIFIED.
546 * Two conflicting parts of the ICCCM v2.0 (section 4.1.4):
548 * "Normal -> Iconic - The client should send a ClientMessage event as described later in this section."
549 * (note no explicit mention of unmapping, while Normal->Widthdrawn does mention that)
551 * "Once a client's window has left the Withdrawn state, the window will be mapped
552 * if it is in the Normal state and the window will be unmapped if it is in the Iconic state."
554 * At this stage it's just safer to keep it in normal state and avoid confusion.
556 window_state_set(c
->win
, XCB_WM_STATE_NORMAL
);
558 /* Move window outside the viewport before mapping it. */
560 xcb_map_window(globalconf
.connection
, c
->win
);
563 spawn_start_notify(c
);
565 /* Call hook to notify list change */
566 if(globalconf
.hooks
.clients
!= LUA_REFNIL
)
567 luaA_dofunction(globalconf
.L
, globalconf
.hooks
.clients
, 0, 0);
570 if(globalconf
.hooks
.manage
!= LUA_REFNIL
)
572 client_push(globalconf
.L
, c
);
573 lua_pushboolean(globalconf
.L
, startup
);
574 luaA_dofunction(globalconf
.L
, globalconf
.hooks
.manage
, 2, 0);
578 /** Compute client geometry with respect to its geometry hints.
579 * \param c The client.
580 * \param geometry The geometry that the client might receive.
581 * \return The geometry the client must take respecting its hints.
584 client_geometry_hints(client_t
*c
, area_t geometry
)
586 int32_t basew
, baseh
, minw
, minh
;
588 /* base size is substituted with min size if not specified */
589 if(c
->size_hints
.flags
& XCB_SIZE_HINT_P_SIZE
)
591 basew
= c
->size_hints
.base_width
;
592 baseh
= c
->size_hints
.base_height
;
594 else if(c
->size_hints
.flags
& XCB_SIZE_HINT_P_MIN_SIZE
)
596 basew
= c
->size_hints
.min_width
;
597 baseh
= c
->size_hints
.min_height
;
602 /* min size is substituted with base size if not specified */
603 if(c
->size_hints
.flags
& XCB_SIZE_HINT_P_MIN_SIZE
)
605 minw
= c
->size_hints
.min_width
;
606 minh
= c
->size_hints
.min_height
;
608 else if(c
->size_hints
.flags
& XCB_SIZE_HINT_P_SIZE
)
610 minw
= c
->size_hints
.base_width
;
611 minh
= c
->size_hints
.base_height
;
616 if(c
->size_hints
.flags
& XCB_SIZE_HINT_P_ASPECT
617 && c
->size_hints
.min_aspect_num
> 0
618 && c
->size_hints
.min_aspect_den
> 0
619 && geometry
.height
- baseh
> 0
620 && geometry
.width
- basew
> 0)
622 double dx
= (double) (geometry
.width
- basew
);
623 double dy
= (double) (geometry
.height
- baseh
);
624 double min
= (double) c
->size_hints
.min_aspect_num
/ (double) c
->size_hints
.min_aspect_den
;
625 double max
= (double) c
->size_hints
.max_aspect_num
/ (double) c
->size_hints
.min_aspect_den
;
626 double ratio
= dx
/ dy
;
627 if(max
> 0 && min
> 0 && ratio
> 0)
631 dy
= (dx
* min
+ dy
) / (min
* min
+ 1);
633 geometry
.width
= (int) dx
+ basew
;
634 geometry
.height
= (int) dy
+ baseh
;
638 dy
= (dx
* min
+ dy
) / (max
* max
+ 1);
640 geometry
.width
= (int) dx
+ basew
;
641 geometry
.height
= (int) dy
+ baseh
;
647 geometry
.width
= MAX(geometry
.width
, minw
);
649 geometry
.height
= MAX(geometry
.height
, minh
);
651 if(c
->size_hints
.flags
& XCB_SIZE_HINT_P_MAX_SIZE
)
653 if(c
->size_hints
.max_width
)
654 geometry
.width
= MIN(geometry
.width
, c
->size_hints
.max_width
);
655 if(c
->size_hints
.max_height
)
656 geometry
.height
= MIN(geometry
.height
, c
->size_hints
.max_height
);
659 if(c
->size_hints
.flags
& (XCB_SIZE_HINT_P_RESIZE_INC
| XCB_SIZE_HINT_BASE_SIZE
)
660 && c
->size_hints
.width_inc
&& c
->size_hints
.height_inc
)
662 uint16_t t1
= geometry
.width
, t2
= geometry
.height
;
663 unsigned_subtract(t1
, basew
);
664 unsigned_subtract(t2
, baseh
);
665 geometry
.width
-= t1
% c
->size_hints
.width_inc
;
666 geometry
.height
-= t2
% c
->size_hints
.height_inc
;
672 /** Resize client window.
673 * The sizse given as parameters are with titlebar and borders!
674 * \param c Client to resize.
675 * \param geometry New window geometry.
676 * \param hints Use size hints.
677 * \return true if an actual resize occurred.
680 client_resize(client_t
*c
, area_t geometry
, bool hints
)
682 area_t geometry_internal
;
685 /* offscreen appearance fixes */
686 area
= display_area_get(c
->phys_screen
, NULL
,
687 &c
->screen
->padding
);
689 if(geometry
.x
> area
.width
)
690 geometry
.x
= area
.width
- geometry
.width
;
691 if(geometry
.y
> area
.height
)
692 geometry
.y
= area
.height
- geometry
.height
;
693 if(geometry
.x
+ geometry
.width
< 0)
695 if(geometry
.y
+ geometry
.height
< 0)
698 /* Real client geometry, please keep it contained to C code at the very least. */
699 geometry_internal
= titlebar_geometry_remove(c
->titlebar
, c
->border
, geometry
);
702 geometry_internal
= client_geometry_hints(c
, geometry_internal
);
704 if(geometry_internal
.width
== 0 || geometry_internal
.height
== 0)
707 /* Also let client hints propegate to the "official" geometry. */
708 geometry
= titlebar_geometry_add(c
->titlebar
, c
->border
, geometry_internal
);
710 if(c
->geometries
.internal
.x
!= geometry_internal
.x
711 || c
->geometries
.internal
.y
!= geometry_internal
.y
712 || c
->geometries
.internal
.width
!= geometry_internal
.width
713 || c
->geometries
.internal
.height
!= geometry_internal
.height
)
715 screen_t
*new_screen
= screen_getbycoord(c
->screen
,
716 geometry_internal
.x
, geometry_internal
.y
);
718 /* Values to configure a window is an array where values are
719 * stored according to 'value_mask' */
722 c
->geometries
.internal
.x
= values
[0] = geometry_internal
.x
;
723 c
->geometries
.internal
.y
= values
[1] = geometry_internal
.y
;
724 c
->geometries
.internal
.width
= values
[2] = geometry_internal
.width
;
725 c
->geometries
.internal
.height
= values
[3] = geometry_internal
.height
;
727 /* Also store geometry including border and titlebar. */
728 c
->geometry
= geometry
;
730 titlebar_update_geometry(c
);
732 /* The idea is to give a client a resize even when banned. */
733 /* We just have to move the (x,y) to keep it out of the viewport. */
734 /* This at least doesn't break expectations about events. */
737 geometry_internal
.x
= values
[0] = - (geometry_internal
.width
+ 2 * c
->border
);
738 geometry_internal
.y
= values
[1] = - (geometry_internal
.height
+ 2 * c
->border
);
741 xcb_configure_window(globalconf
.connection
, c
->win
,
742 XCB_CONFIG_WINDOW_X
| XCB_CONFIG_WINDOW_Y
743 | XCB_CONFIG_WINDOW_WIDTH
| XCB_CONFIG_WINDOW_HEIGHT
,
746 screen_client_moveto(c
, new_screen
, true, false);
749 hooks_property(c
, "geometry");
757 /** Set a client minimized, or not.
758 * \param c The client.
759 * \param s Set or not the client minimized.
762 client_setminimized(client_t
*c
, bool s
)
764 if(c
->isminimized
!= s
)
766 client_need_arrange(c
);
768 client_need_arrange(c
);
769 ewmh_client_update_hints(c
);
771 hooks_property(c
, "minimized");
775 /** Set a client sticky, or not.
776 * \param c The client.
777 * \param s Set or not the client sticky.
780 client_setsticky(client_t
*c
, bool s
)
784 client_need_arrange(c
);
786 client_need_arrange(c
);
787 ewmh_client_update_hints(c
);
788 hooks_property(c
, "sticky");
792 /** Set a client fullscreen, or not.
793 * \param c The client.
794 * \param s Set or not the client fullscreen.
797 client_setfullscreen(client_t
*c
, bool s
)
799 if(c
->isfullscreen
!= s
)
803 /* Make sure the current geometry is stored without titlebar. */
805 titlebar_ban(c
->titlebar
);
807 /* become fullscreen! */
808 if((c
->isfullscreen
= s
))
810 /* remove any max state */
811 client_setmaxhoriz(c
, false);
812 client_setmaxvert(c
, false);
813 /* You can only be part of one of the special layers. */
814 client_setbelow(c
, false);
815 client_setabove(c
, false);
816 client_setontop(c
, false);
818 geometry
= screen_area_get(c
->screen
, NULL
, NULL
, false);
819 c
->geometries
.fullscreen
= c
->geometry
;
820 c
->border_fs
= c
->border
;
821 client_setborder(c
, 0);
825 geometry
= c
->geometries
.fullscreen
;
826 client_setborder(c
, c
->border_fs
);
828 client_resize(c
, geometry
, false);
829 client_need_arrange(c
);
831 ewmh_client_update_hints(c
);
832 hooks_property(c
, "fullscreen");
836 /** Set a client horizontally maximized.
837 * \param c The client.
838 * \param s The maximized status.
841 client_setmaxhoriz(client_t
*c
, bool s
)
843 if(c
->ismaxhoriz
!= s
)
847 if((c
->ismaxhoriz
= s
))
849 /* remove fullscreen mode */
850 client_setfullscreen(c
, false);
852 geometry
= screen_area_get(c
->screen
,
856 geometry
.y
= c
->geometry
.y
;
857 geometry
.height
= c
->geometry
.height
;
858 c
->geometries
.max
.x
= c
->geometry
.x
;
859 c
->geometries
.max
.width
= c
->geometry
.width
;
863 geometry
= c
->geometry
;
864 geometry
.x
= c
->geometries
.max
.x
;
865 geometry
.width
= c
->geometries
.max
.width
;
868 client_resize(c
, geometry
, c
->size_hints_honor
);
869 client_need_arrange(c
);
871 ewmh_client_update_hints(c
);
872 hooks_property(c
, "maximized_horizontal");
876 /** Set a client vertically maximized.
877 * \param c The client.
878 * \param s The maximized status.
881 client_setmaxvert(client_t
*c
, bool s
)
883 if(c
->ismaxvert
!= s
)
887 if((c
->ismaxvert
= s
))
889 /* remove fullscreen mode */
890 client_setfullscreen(c
, false);
892 geometry
= screen_area_get(c
->screen
,
896 geometry
.x
= c
->geometry
.x
;
897 geometry
.width
= c
->geometry
.width
;
898 c
->geometries
.max
.y
= c
->geometry
.y
;
899 c
->geometries
.max
.height
= c
->geometry
.height
;
903 geometry
= c
->geometry
;
904 geometry
.y
= c
->geometries
.max
.y
;
905 geometry
.height
= c
->geometries
.max
.height
;
908 client_resize(c
, geometry
, c
->size_hints_honor
);
909 client_need_arrange(c
);
911 ewmh_client_update_hints(c
);
912 hooks_property(c
, "maximized_vertical");
916 /** Set a client above, or not.
917 * \param c The client.
918 * \param s Set or not the client above.
921 client_setabove(client_t
*c
, bool s
)
925 /* You can only be part of one of the special layers. */
928 client_setbelow(c
, false);
929 client_setontop(c
, false);
930 client_setfullscreen(c
, false);
934 ewmh_client_update_hints(c
);
936 hooks_property(c
, "above");
940 /** Set a client below, or not.
941 * \param c The client.
942 * \param s Set or not the client below.
945 client_setbelow(client_t
*c
, bool s
)
949 /* You can only be part of one of the special layers. */
952 client_setabove(c
, false);
953 client_setontop(c
, false);
954 client_setfullscreen(c
, false);
958 ewmh_client_update_hints(c
);
960 hooks_property(c
, "below");
964 /** Set a client modal, or not.
965 * \param c The client.
966 * \param s Set or not the client moda.
969 client_setmodal(client_t
*c
, bool s
)
975 ewmh_client_update_hints(c
);
977 hooks_property(c
, "modal");
981 /** Set a client ontop, or not.
982 * \param c The client.
983 * \param s Set or not the client moda.
986 client_setontop(client_t
*c
, bool s
)
990 /* You can only be part of one of the special layers. */
993 client_setabove(c
, false);
994 client_setbelow(c
, false);
995 client_setfullscreen(c
, false);
1000 hooks_property(c
, "ontop");
1004 /** Unban a client and move it back into the viewport.
1005 * \param c The client.
1008 client_unban(client_t
*c
)
1012 /* Move the client back where it belongs. */
1013 uint32_t request
[] = { c
->geometries
.internal
.x
,
1014 c
->geometries
.internal
.y
,
1015 c
->geometries
.internal
.width
,
1016 c
->geometries
.internal
.height
};
1018 xcb_configure_window(globalconf
.connection
, c
->win
,
1020 | XCB_CONFIG_WINDOW_Y
1021 | XCB_CONFIG_WINDOW_WIDTH
1022 | XCB_CONFIG_WINDOW_HEIGHT
,
1025 c
->isbanned
= false;
1027 /* All the wiboxes (may) need to be repositioned. */
1028 if(client_hasstrut(c
))
1029 wibox_update_positions();
1033 /** Unmanage a client.
1034 * \param c The client.
1037 client_unmanage(client_t
*c
)
1039 tag_array_t
*tags
= &c
->screen
->tags
;
1041 /* Reset transient_for attributes of widows that maybe refering to us */
1042 foreach(_tc
, globalconf
.clients
)
1044 client_t
*tc
= *_tc
;
1045 if(tc
->transient_for
== c
)
1046 tc
->transient_for
= NULL
;
1049 if(globalconf
.screens
.tab
[c
->phys_screen
].prev_client_focus
== c
)
1050 globalconf
.screens
.tab
[c
->phys_screen
].prev_client_focus
= NULL
;
1052 if(globalconf
.screens
.tab
[c
->phys_screen
].client_focus
== c
)
1055 /* remove client from global list and everywhere else */
1056 foreach(elem
, globalconf
.clients
)
1059 client_array_remove(&globalconf
.clients
, elem
);
1062 stack_client_remove(c
);
1063 for(int i
= 0; i
< tags
->len
; i
++)
1064 untag_client(c
, tags
->tab
[i
]);
1067 if(globalconf
.hooks
.unmanage
!= LUA_REFNIL
)
1069 client_push(globalconf
.L
, c
);
1070 luaA_dofunction(globalconf
.L
, globalconf
.hooks
.unmanage
, 1, 0);
1073 /* Call hook to notify list change */
1074 if(globalconf
.hooks
.clients
!= LUA_REFNIL
)
1075 luaA_dofunction(globalconf
.L
, globalconf
.hooks
.clients
, 0, 0);
1077 /* The server grab construct avoids race conditions. */
1078 xcb_grab_server(globalconf
.connection
);
1080 xcb_ungrab_button(globalconf
.connection
, XCB_BUTTON_INDEX_ANY
, c
->win
,
1081 XCB_BUTTON_MASK_ANY
);
1082 window_state_set(c
->win
, XCB_WM_STATE_WITHDRAWN
);
1084 xcb_flush(globalconf
.connection
);
1085 xcb_ungrab_server(globalconf
.connection
);
1087 titlebar_client_detach(c
);
1089 ewmh_update_net_client_list(c
->phys_screen
);
1091 /* All the wiboxes (may) need to be repositioned. */
1092 if(client_hasstrut(c
))
1093 wibox_update_positions();
1095 /* set client as invalid */
1098 client_unref(globalconf
.L
, c
);
1101 /** Kill a client via a WM_DELETE_WINDOW request or KillClient if not
1103 * \param c The client to kill.
1106 client_kill(client_t
*c
)
1108 if(window_hasproto(c
->win
, WM_DELETE_WINDOW
))
1110 xcb_client_message_event_t ev
;
1112 /* Initialize all of event's fields first */
1115 ev
.response_type
= XCB_CLIENT_MESSAGE
;
1118 ev
.data
.data32
[1] = XCB_CURRENT_TIME
;
1119 ev
.type
= WM_PROTOCOLS
;
1120 ev
.data
.data32
[0] = WM_DELETE_WINDOW
;
1122 xcb_send_event(globalconf
.connection
, false, c
->win
,
1123 XCB_EVENT_MASK_NO_EVENT
, (char *) &ev
);
1126 xcb_kill_client(globalconf
.connection
, c
->win
);
1129 /** Get all clients into a table.
1130 * \param L The Lua VM state.
1131 * \return The number of elements pushed on stack.
1133 * \lparam An optional screen nunmber.
1134 * \lreturn A table with all clients.
1137 luaA_client_get(lua_State
*L
)
1141 screen
= luaL_optnumber(L
, 1, 0) - 1;
1146 foreach(c
, globalconf
.clients
)
1149 lua_rawseti(L
, -2, i
++);
1153 luaA_checkscreen(screen
);
1154 foreach(c
, globalconf
.clients
)
1155 if((*c
)->screen
== &globalconf
.screens
.tab
[screen
])
1158 lua_rawseti(L
, -2, i
++);
1165 /** Check if a client is visible on its screen.
1166 * \param L The Lua VM state.
1167 * \return The number of elements pushed on stack.
1170 * \lreturn A boolean value, true if the client is visible, false otherwise.
1173 luaA_client_isvisible(lua_State
*L
)
1175 client_t
*c
= luaA_client_checkudata(L
, 1);
1176 lua_pushboolean(L
, client_isvisible(c
, c
->screen
));
1180 /** Set client border width.
1181 * \param c The client.
1182 * \param width The border width.
1185 client_setborder(client_t
*c
, int width
)
1189 if(width
> 0 && (c
->type
== WINDOW_TYPE_DOCK
1190 || c
->type
== WINDOW_TYPE_SPLASH
1191 || c
->type
== WINDOW_TYPE_DESKTOP
1192 || c
->isfullscreen
))
1195 if(width
== c
->border
|| width
< 0)
1198 /* Update geometry with the new border. */
1199 c
->geometry
.width
-= 2 * c
->border
;
1200 c
->geometry
.height
-= 2 * c
->border
;
1203 xcb_configure_window(globalconf
.connection
, c
->win
,
1204 XCB_CONFIG_WINDOW_BORDER_WIDTH
, &w
);
1206 c
->geometry
.width
+= 2 * c
->border
;
1207 c
->geometry
.height
+= 2 * c
->border
;
1208 /* Tiled clients will be resized by the layout functions. */
1209 client_need_arrange(c
);
1211 /* Changing border size also affects the size of the titlebar. */
1212 titlebar_update_geometry(c
);
1214 hooks_property(c
, "border_width");
1218 * \param L The Lua VM state.
1224 luaA_client_kill(lua_State
*L
)
1226 client_t
*c
= luaA_client_checkudata(L
, 1);
1231 /** Swap a client with another one.
1232 * \param L The Lua VM state.
1235 * \lparam A client to swap with.
1238 luaA_client_swap(lua_State
*L
)
1240 client_t
*c
= luaA_client_checkudata(L
, 1);
1241 client_t
*swap
= luaA_client_checkudata(L
, 2);
1245 client_t
**ref_c
= NULL
, **ref_swap
= NULL
;
1246 foreach(item
, globalconf
.clients
)
1250 else if(*item
== swap
)
1252 if(ref_c
&& ref_swap
)
1259 client_need_arrange(c
);
1260 client_need_arrange(swap
);
1262 /* Call hook to notify list change */
1263 if(globalconf
.hooks
.clients
!= LUA_REFNIL
)
1264 luaA_dofunction(L
, globalconf
.hooks
.clients
, 0, 0);
1270 /** Access or set the client tags.
1271 * \param L The Lua VM state.
1272 * \return The number of elements pushed on stack.
1273 * \lparam A table with tags to set, or none to get the current tags table.
1274 * \return The clients tag.
1277 luaA_client_tags(lua_State
*L
)
1279 client_t
*c
= luaA_client_checkudata(L
, 1);
1280 tag_array_t
*tags
= &c
->screen
->tags
;
1283 if(lua_gettop(L
) == 2)
1285 luaA_checktable(L
, 2);
1286 for(int i
= 0; i
< tags
->len
; i
++)
1287 untag_client(c
, tags
->tab
[i
]);
1289 while(lua_next(L
, 2))
1296 if(is_client_tagged(c
, *tag
))
1299 lua_rawseti(L
, -2, ++j
);
1305 /** Raise a client on top of others which are on the same layer.
1306 * \param L The Lua VM state.
1311 luaA_client_raise(lua_State
*L
)
1313 client_t
*c
= luaA_client_checkudata(L
, 1);
1318 /** Lower a client on bottom of others which are on the same layer.
1319 * \param L The Lua VM state.
1324 luaA_client_lower(lua_State
*L
)
1326 client_t
*c
= luaA_client_checkudata(L
, 1);
1331 /** Redraw a client by unmapping and mapping it quickly.
1332 * \param L The Lua VM state.
1338 luaA_client_redraw(lua_State
*L
)
1340 client_t
*c
= luaA_client_checkudata(L
, 1);
1342 xcb_unmap_window(globalconf
.connection
, c
->win
);
1343 xcb_map_window(globalconf
.connection
, c
->win
);
1345 /* Set the focus on the current window if the redraw has been
1346 performed on the window where the pointer is currently on
1347 because after the unmapping/mapping, the focus is lost */
1348 if(globalconf
.screen_focus
->client_focus
== c
)
1357 /** Stop managing a client.
1358 * \param L The Lua VM state.
1359 * \return The number of elements pushed on stack.
1364 luaA_client_unmanage(lua_State
*L
)
1366 client_t
*c
= luaA_client_checkudata(L
, 1);
1371 /** Return client geometry.
1372 * \param L The Lua VM state.
1373 * \return The number of elements pushed on stack.
1375 * \lparam A table with new coordinates, or none.
1376 * \lreturn A table with client coordinates.
1379 luaA_client_geometry(lua_State
*L
)
1381 client_t
*c
= luaA_client_checkudata(L
, 1);
1383 if(lua_gettop(L
) == 2)
1387 luaA_checktable(L
, 2);
1388 geometry
.x
= luaA_getopt_number(L
, 2, "x", c
->geometry
.x
);
1389 geometry
.y
= luaA_getopt_number(L
, 2, "y", c
->geometry
.y
);
1390 if(client_isfixed(c
))
1392 geometry
.width
= c
->geometry
.width
;
1393 geometry
.height
= c
->geometry
.height
;
1397 geometry
.width
= luaA_getopt_number(L
, 2, "width", c
->geometry
.width
);
1398 geometry
.height
= luaA_getopt_number(L
, 2, "height", c
->geometry
.height
);
1401 client_resize(c
, geometry
, c
->size_hints_honor
);
1404 return luaA_pusharea(L
, c
->geometry
);
1407 /** Push a strut type to a table on stack.
1408 * \param L The Lua VM state.
1409 * \param struts The struts to push.
1410 * \return The number of elements pushed on stack.
1413 luaA_pushstruts(lua_State
*L
, strut_t struts
)
1415 lua_createtable(L
, 4, 0);
1416 lua_pushnumber(L
, struts
.left
);
1417 lua_setfield(L
, -2, "left");
1418 lua_pushnumber(L
, struts
.right
);
1419 lua_setfield(L
, -2, "right");
1420 lua_pushnumber(L
, struts
.top
);
1421 lua_setfield(L
, -2, "top");
1422 lua_pushnumber(L
, struts
.bottom
);
1423 lua_setfield(L
, -2, "bottom");
1427 /** Return client struts (reserved space at the edge of the screen).
1428 * \param L The Lua VM state.
1429 * \return The number of elements pushed on stack.
1431 * \lparam A table with new strut values, or none.
1432 * \lreturn A table with strut values.
1435 luaA_client_struts(lua_State
*L
)
1437 client_t
*c
= luaA_client_checkudata(L
, 1);
1439 if(lua_gettop(L
) == 2)
1442 area_t screen_area
= display_area_get(c
->phys_screen
, NULL
, NULL
);
1444 struts
.left
= luaA_getopt_number(L
, 2, "left", c
->strut
.left
);
1445 struts
.right
= luaA_getopt_number(L
, 2, "right", c
->strut
.right
);
1446 struts
.top
= luaA_getopt_number(L
, 2, "top", c
->strut
.top
);
1447 struts
.bottom
= luaA_getopt_number(L
, 2, "bottom", c
->strut
.bottom
);
1449 if(struts
.left
!= c
->strut
.left
|| struts
.right
!= c
->strut
.right
||
1450 struts
.top
!= c
->strut
.top
|| struts
.bottom
!= c
->strut
.bottom
) {
1451 /* Struts are not so well defined in the context of xinerama. So we just
1452 * give the entire root window and let the window manager decide. */
1453 struts
.left_start_y
= 0;
1454 struts
.left_end_y
= !struts
.left
? 0 : screen_area
.height
;
1455 struts
.right_start_y
= 0;
1456 struts
.right_end_y
= !struts
.right
? 0 : screen_area
.height
;
1457 struts
.top_start_x
= 0;
1458 struts
.top_end_x
= !struts
.top
? 0 : screen_area
.width
;
1459 struts
.bottom_start_x
= 0;
1460 struts
.bottom_end_x
= !struts
.bottom
? 0 : screen_area
.width
;
1464 ewmh_update_client_strut(c
);
1466 client_need_arrange(c
);
1467 /* All the wiboxes (may) need to be repositioned. */
1468 wibox_update_positions();
1470 hooks_property(c
, "struts");
1474 return luaA_pushstruts(L
, c
->strut
);
1477 /** Client newindex.
1478 * \param L The Lua VM state.
1479 * \return The number of elements pushed on stack.
1482 luaA_client_newindex(lua_State
*L
)
1485 client_t
*c
= luaA_client_checkudata(L
, 1);
1486 const char *buf
= luaL_checklstring(L
, 2, &len
);
1491 switch(a_tokenize(buf
, len
))
1494 if(globalconf
.xinerama_is_active
)
1496 i
= luaL_checknumber(L
, 3) - 1;
1497 luaA_checkscreen(i
);
1498 screen_client_moveto(c
, &globalconf
.screens
.tab
[i
], true, true);
1502 b
= luaA_checkboolean(L
, 3);
1503 if(b
!= c
->ishidden
)
1505 client_need_arrange(c
);
1507 client_need_arrange(c
);
1510 case A_TK_MINIMIZED
:
1511 client_setminimized(c
, luaA_checkboolean(L
, 3));
1513 case A_TK_FULLSCREEN
:
1514 client_setfullscreen(c
, luaA_checkboolean(L
, 3));
1516 case A_TK_MAXIMIZED_HORIZONTAL
:
1517 client_setmaxhoriz(c
, luaA_checkboolean(L
, 3));
1519 case A_TK_MAXIMIZED_VERTICAL
:
1520 client_setmaxvert(c
, luaA_checkboolean(L
, 3));
1523 image_unref(L
, c
->icon
);
1524 c
->icon
= image_ref(L
);
1526 hooks_property(c
, "icon");
1530 window_opacity_set(c
->win
, -1);
1533 d
= luaL_checknumber(L
, 3);
1534 if(d
>= 0 && d
<= 1)
1535 window_opacity_set(c
->win
, d
);
1539 client_setsticky(c
, luaA_checkboolean(L
, 3));
1541 case A_TK_SIZE_HINTS_HONOR
:
1542 c
->size_hints_honor
= luaA_checkboolean(L
, 3);
1543 hooks_property(c
, "size_hints_honor");
1545 case A_TK_BORDER_WIDTH
:
1546 client_setborder(c
, luaL_checknumber(L
, 3));
1549 client_setontop(c
, luaA_checkboolean(L
, 3));
1552 client_setabove(c
, luaA_checkboolean(L
, 3));
1555 client_setbelow(c
, luaA_checkboolean(L
, 3));
1558 client_seturgent(c
, luaA_checkboolean(L
, 3));
1560 case A_TK_BORDER_COLOR
:
1561 if((buf
= luaL_checklstring(L
, 3, &len
))
1562 && xcolor_init_reply(xcolor_init_unchecked(&c
->border_color
, buf
, len
)))
1563 xcb_change_window_attributes(globalconf
.connection
, c
->win
,
1564 XCB_CW_BORDER_PIXEL
, &c
->border_color
.pixel
);
1568 titlebar_client_detach(c
);
1570 titlebar_client_attach(c
);
1580 * \param L The Lua VM state.
1581 * \return The number of elements pushed on stack.
1583 * \lfield id The window X id.
1584 * \lfield name The client title.
1585 * \lfield skip_taskbar True if the client does not want to be in taskbar.
1586 * \lfield type The window type (desktop, normal, dock, …).
1587 * \lfield class The client class.
1588 * \lfield instance The client instance.
1589 * \lfield pid The client PID, if available.
1590 * \lfield role The window role, if available.
1591 * \lfield machine The machine client is running on.
1592 * \lfield icon_name The client name when iconified.
1593 * \lfield screen Client screen number.
1594 * \lfield hide Define if the client must be hidden, i.e. never mapped,
1595 * invisible in taskbar.
1596 * \lfield minimized Define it the client must be iconify, i.e. only visible in
1598 * \lfield size_hints_honor Honor size hints, i.e. respect size ratio.
1599 * \lfield border_width The client border width.
1600 * \lfield border_color The client border color.
1601 * \lfield titlebar The client titlebar.
1602 * \lfield urgent The client urgent state.
1603 * \lfield content An image representing the client window content (screenshot).
1604 * \lfield focus The focused client.
1605 * \lfield opacity The client opacity between 0 and 1.
1606 * \lfield ontop The client is on top of every other windows.
1607 * \lfield above The client is above normal windows.
1608 * \lfield below The client is below normal windows.
1609 * \lfield fullscreen The client is fullscreen or not.
1610 * \lfield maximized_horizontal The client is maximized horizontally or not.
1611 * \lfield maximized_vertical The client is maximized vertically or not.
1612 * \lfield transient_for Return the client the window is transient for.
1613 * \lfield group_id Identification unique to a group of windows.
1614 * \lfield leader_id Identification unique to windows spawned by the same command.
1615 * \lfield size_hints A table with size hints of the client: user_position,
1616 * user_size, program_position, program_size, etc.
1619 luaA_client_index(lua_State
*L
)
1623 client_t
*c
= luaA_client_checkudata(L
, 1);
1624 const char *buf
= luaL_checklstring(L
, 2, &len
);
1627 xcb_get_property_cookie_t prop_c
;
1628 xcb_get_property_reply_t
*prop_r
= NULL
;
1631 if(luaA_usemetatable(L
, 1, 2))
1634 switch(a_tokenize(buf
, len
))
1637 lua_pushstring(L
, c
->name
);
1639 case A_TK_TRANSIENT_FOR
:
1640 return client_push(globalconf
.L
, c
->transient_for
);
1641 case A_TK_SKIP_TASKBAR
:
1642 lua_pushboolean(L
, c
->skiptb
);
1645 return client_getcontent(c
);
1649 case WINDOW_TYPE_DESKTOP
:
1650 lua_pushliteral(L
, "desktop");
1652 case WINDOW_TYPE_DOCK
:
1653 lua_pushliteral(L
, "dock");
1655 case WINDOW_TYPE_SPLASH
:
1656 lua_pushliteral(L
, "splash");
1658 case WINDOW_TYPE_DIALOG
:
1659 lua_pushliteral(L
, "dialog");
1661 case WINDOW_TYPE_MENU
:
1662 lua_pushliteral(L
, "menu");
1664 case WINDOW_TYPE_TOOLBAR
:
1665 lua_pushliteral(L
, "toolbar");
1667 case WINDOW_TYPE_UTILITY
:
1668 lua_pushliteral(L
, "utility");
1670 case WINDOW_TYPE_DROPDOWN_MENU
:
1671 lua_pushliteral(L
, "dropdown_menu");
1673 case WINDOW_TYPE_POPUP_MENU
:
1674 lua_pushliteral(L
, "popup_menu");
1676 case WINDOW_TYPE_TOOLTIP
:
1677 lua_pushliteral(L
, "tooltip");
1679 case WINDOW_TYPE_NOTIFICATION
:
1680 lua_pushliteral(L
, "notification");
1682 case WINDOW_TYPE_COMBO
:
1683 lua_pushliteral(L
, "combo");
1685 case WINDOW_TYPE_DND
:
1686 lua_pushliteral(L
, "dnd");
1688 case WINDOW_TYPE_NORMAL
:
1689 lua_pushliteral(L
, "normal");
1694 lua_pushstring(L
, c
->class);
1697 lua_pushstring(L
, c
->instance
);
1700 if(!xutil_text_prop_get(globalconf
.connection
, c
->win
,
1701 WM_WINDOW_ROLE
, &value
, &slen
))
1703 lua_pushlstring(L
, value
, slen
);
1707 prop_c
= xcb_get_property_unchecked(globalconf
.connection
, false, c
->win
, _NET_WM_PID
, CARDINAL
, 0L, 1L);
1708 prop_r
= xcb_get_property_reply(globalconf
.connection
, prop_c
, NULL
);
1710 if(prop_r
&& prop_r
->value_len
&& (data
= xcb_get_property_value(prop_r
)))
1711 lua_pushnumber(L
, *(uint32_t *)data
);
1719 lua_pushnumber(L
, c
->win
);
1721 case A_TK_LEADER_ID
:
1722 lua_pushnumber(L
, c
->leader_win
);
1725 if(!xutil_text_prop_get(globalconf
.connection
, c
->win
,
1726 WM_CLIENT_MACHINE
, &value
, &slen
))
1728 lua_pushlstring(L
, value
, slen
);
1731 case A_TK_ICON_NAME
:
1732 lua_pushstring(L
, c
->icon_name
);
1735 lua_pushnumber(L
, 1 + screen_array_indexof(&globalconf
.screens
, c
->screen
));
1738 lua_pushboolean(L
, c
->ishidden
);
1740 case A_TK_MINIMIZED
:
1741 lua_pushboolean(L
, c
->isminimized
);
1743 case A_TK_FULLSCREEN
:
1744 lua_pushboolean(L
, c
->isfullscreen
);
1748 lua_pushnumber(L
, c
->group_win
);
1752 case A_TK_MAXIMIZED_HORIZONTAL
:
1753 lua_pushboolean(L
, c
->ismaxhoriz
);
1755 case A_TK_MAXIMIZED_VERTICAL
:
1756 lua_pushboolean(L
, c
->ismaxvert
);
1759 image_push(L
, c
->icon
);
1762 if((d
= window_opacity_get(c
->win
)) >= 0)
1763 lua_pushnumber(L
, d
);
1768 lua_pushboolean(L
, c
->isontop
);
1771 lua_pushboolean(L
, c
->isabove
);
1774 lua_pushboolean(L
, c
->isbelow
);
1777 lua_pushboolean(L
, c
->issticky
);
1779 case A_TK_SIZE_HINTS_HONOR
:
1780 lua_pushboolean(L
, c
->size_hints_honor
);
1782 case A_TK_BORDER_WIDTH
:
1783 lua_pushnumber(L
, c
->border
);
1785 case A_TK_BORDER_COLOR
:
1786 luaA_pushxcolor(L
, &c
->border_color
);
1789 return wibox_push(L
, c
->titlebar
);
1791 lua_pushboolean(L
, c
->isurgent
);
1793 case A_TK_SIZE_HINTS
:
1795 const char *u_or_p
= NULL
;
1797 lua_createtable(L
, 0, 1);
1799 if(c
->size_hints
.flags
& XCB_SIZE_HINT_US_POSITION
)
1800 u_or_p
= "user_position";
1801 else if(c
->size_hints
.flags
& XCB_SIZE_HINT_P_POSITION
)
1802 u_or_p
= "program_position";
1806 lua_createtable(L
, 0, 2);
1807 lua_pushnumber(L
, c
->size_hints
.x
);
1808 lua_setfield(L
, -2, "x");
1809 lua_pushnumber(L
, c
->size_hints
.y
);
1810 lua_setfield(L
, -2, "y");
1811 lua_setfield(L
, -2, u_or_p
);
1815 if(c
->size_hints
.flags
& XCB_SIZE_HINT_US_SIZE
)
1816 u_or_p
= "user_size";
1817 else if(c
->size_hints
.flags
& XCB_SIZE_HINT_P_SIZE
)
1818 u_or_p
= "program_size";
1822 lua_createtable(L
, 0, 2);
1823 lua_pushnumber(L
, c
->size_hints
.width
);
1824 lua_setfield(L
, -2, "width");
1825 lua_pushnumber(L
, c
->size_hints
.height
);
1826 lua_setfield(L
, -2, "height");
1827 lua_setfield(L
, -2, u_or_p
);
1830 if(c
->size_hints
.flags
& XCB_SIZE_HINT_P_MIN_SIZE
)
1832 lua_pushnumber(L
, c
->size_hints
.min_width
);
1833 lua_setfield(L
, -2, "min_width");
1834 lua_pushnumber(L
, c
->size_hints
.min_height
);
1835 lua_setfield(L
, -2, "min_height");
1838 if(c
->size_hints
.flags
& XCB_SIZE_HINT_P_MAX_SIZE
)
1840 lua_pushnumber(L
, c
->size_hints
.max_width
);
1841 lua_setfield(L
, -2, "max_width");
1842 lua_pushnumber(L
, c
->size_hints
.max_height
);
1843 lua_setfield(L
, -2, "max_height");
1846 if(c
->size_hints
.flags
& XCB_SIZE_HINT_P_RESIZE_INC
)
1848 lua_pushnumber(L
, c
->size_hints
.width_inc
);
1849 lua_setfield(L
, -2, "width_inc");
1850 lua_pushnumber(L
, c
->size_hints
.height_inc
);
1851 lua_setfield(L
, -2, "height_inc");
1854 if(c
->size_hints
.flags
& XCB_SIZE_HINT_P_ASPECT
)
1856 lua_pushnumber(L
, c
->size_hints
.min_aspect_num
);
1857 lua_setfield(L
, -2, "min_aspect_num");
1858 lua_pushnumber(L
, c
->size_hints
.min_aspect_den
);
1859 lua_setfield(L
, -2, "min_aspect_den");
1860 lua_pushnumber(L
, c
->size_hints
.max_aspect_num
);
1861 lua_setfield(L
, -2, "max_aspect_num");
1862 lua_pushnumber(L
, c
->size_hints
.max_aspect_den
);
1863 lua_setfield(L
, -2, "max_aspect_den");
1866 if(c
->size_hints
.flags
& XCB_SIZE_HINT_BASE_SIZE
)
1868 lua_pushnumber(L
, c
->size_hints
.base_width
);
1869 lua_setfield(L
, -2, "base_width");
1870 lua_pushnumber(L
, c
->size_hints
.base_height
);
1871 lua_setfield(L
, -2, "base_height");
1874 if(c
->size_hints
.flags
& XCB_SIZE_HINT_P_WIN_GRAVITY
)
1876 switch(c
->size_hints
.win_gravity
)
1879 lua_pushliteral(L
, "north_west");
1881 case XCB_GRAVITY_NORTH
:
1882 lua_pushliteral(L
, "north");
1884 case XCB_GRAVITY_NORTH_EAST
:
1885 lua_pushliteral(L
, "north_east");
1887 case XCB_GRAVITY_WEST
:
1888 lua_pushliteral(L
, "west");
1890 case XCB_GRAVITY_CENTER
:
1891 lua_pushliteral(L
, "center");
1893 case XCB_GRAVITY_EAST
:
1894 lua_pushliteral(L
, "east");
1896 case XCB_GRAVITY_SOUTH_WEST
:
1897 lua_pushliteral(L
, "south_west");
1899 case XCB_GRAVITY_SOUTH
:
1900 lua_pushliteral(L
, "south");
1902 case XCB_GRAVITY_SOUTH_EAST
:
1903 lua_pushliteral(L
, "south_east");
1905 case XCB_GRAVITY_STATIC
:
1906 lua_pushliteral(L
, "static");
1909 lua_setfield(L
, -2, "win_gravity");
1920 /** Get or set mouse buttons bindings for a client.
1921 * \param L The Lua VM state.
1922 * \return The number of element pushed on stack.
1925 * \lparam An array of mouse button bindings objects, or nothing.
1926 * \return The array of mouse button bindings objects of this client.
1929 luaA_client_buttons(lua_State
*L
)
1931 client_t
*client
= luaA_client_checkudata(L
, 1);
1932 button_array_t
*buttons
= &client
->buttons
;
1934 if(lua_gettop(L
) == 2)
1935 luaA_button_array_set(L
, 2, buttons
);
1937 window_buttons_grab(client
->win
, &client
->buttons
);
1939 return luaA_button_array_get(L
, buttons
);
1942 /** Get or set keys bindings for a client.
1943 * \param L The Lua VM state.
1944 * \return The number of element pushed on stack.
1947 * \lparam An array of key bindings objects, or nothing.
1948 * \return The array of key bindings objects of this client.
1951 luaA_client_keys(lua_State
*L
)
1953 client_t
*c
= luaA_client_checkudata(L
, 1);
1954 key_array_t
*keys
= &c
->keys
;
1956 if(lua_gettop(L
) == 2)
1958 luaA_key_array_set(L
, 2, keys
);
1959 xcb_ungrab_key(globalconf
.connection
, XCB_GRAB_ANY
, c
->win
, XCB_BUTTON_MASK_ANY
);
1960 window_grabkeys(c
->win
, keys
);
1963 return luaA_key_array_get(L
, keys
);
1967 * \param L The Lua VM state.
1968 * \return The number of pushed elements.
1971 luaA_client_module_index(lua_State
*L
)
1974 const char *buf
= luaL_checklstring(L
, 2, &len
);
1976 switch(a_tokenize(buf
, len
))
1979 return client_push(globalconf
.L
, globalconf
.screen_focus
->client_focus
);
1986 /* Client module new index.
1987 * \param L The Lua VM state.
1988 * \return The number of pushed elements.
1991 luaA_client_module_newindex(lua_State
*L
)
1994 const char *buf
= luaL_checklstring(L
, 2, &len
);
1997 switch(a_tokenize(buf
, len
))
2000 c
= luaA_client_checkudata(L
, 3);
2010 const struct luaL_reg awesome_client_methods
[] =
2012 { "get", luaA_client_get
},
2013 { "__index", luaA_client_module_index
},
2014 { "__newindex", luaA_client_module_newindex
},
2017 const struct luaL_reg awesome_client_meta
[] =
2019 { "isvisible", luaA_client_isvisible
},
2020 { "geometry", luaA_client_geometry
},
2021 { "struts", luaA_client_struts
},
2022 { "buttons", luaA_client_buttons
},
2023 { "keys", luaA_client_keys
},
2024 { "tags", luaA_client_tags
},
2025 { "kill", luaA_client_kill
},
2026 { "swap", luaA_client_swap
},
2027 { "raise", luaA_client_raise
},
2028 { "lower", luaA_client_lower
},
2029 { "redraw", luaA_client_redraw
},
2030 { "unmanage", luaA_client_unmanage
},
2031 { "__index", luaA_client_index
},
2032 { "__newindex", luaA_client_newindex
},
2033 { "__gc", luaA_client_gc
},
2034 { "__tostring", luaA_client_tostring
},
2038 // vim: filetype=c:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=80