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"
36 luaA_client_checkudata(lua_State
*L
, int ud
)
38 client_t
*c
= luaL_checkudata(L
, ud
, "client");
40 luaL_error(L
, "client is invalid\n");
45 * \param L The Lua VM state.
46 * \return The number of element pushed on stack.
49 luaA_client_gc(lua_State
*L
)
51 client_t
*c
= luaL_checkudata(L
, 1, "client");
52 button_array_wipe(&c
->buttons
);
53 key_array_wipe(&c
->keys
);
54 xcb_get_wm_protocols_reply_wipe(&c
->protocols
);
56 p_delete(&c
->startup_id
);
57 p_delete(&c
->instance
);
58 p_delete(&c
->icon_name
);
60 return luaA_object_gc(L
);
63 /** Change the clients urgency flag.
65 * \param urgent The new flag state
68 client_seturgent(client_t
*c
, bool urgent
)
70 if(c
->isurgent
!= urgent
)
72 xcb_get_property_cookie_t hints
=
73 xcb_get_wm_hints_unchecked(globalconf
.connection
, c
->win
);
76 ewmh_client_update_hints(c
);
78 /* update ICCCM hints */
80 xcb_get_wm_hints_reply(globalconf
.connection
, hints
, &wmh
, NULL
);
83 wmh
.flags
|= XCB_WM_HINT_X_URGENCY
;
85 wmh
.flags
&= ~XCB_WM_HINT_X_URGENCY
;
87 xcb_set_wm_hints(globalconf
.connection
, c
->win
, &wmh
);
89 hook_property(client
, c
, "urgent");
93 /** Returns true if a client is tagged
94 * with one of the tags of the specified screen.
95 * \param c The client to check.
96 * \param screen Virtual screen.
97 * \return true if the client is visible, false otherwise.
100 client_maybevisible(client_t
*c
, screen_t
*screen
)
102 if(c
->screen
== screen
)
104 if(c
->issticky
|| c
->type
== WINDOW_TYPE_DESKTOP
)
107 foreach(tag
, screen
->tags
)
108 if((*tag
)->selected
&& is_client_tagged(c
, *tag
))
114 /** Return the content of a client as an image.
115 * That's just take a screenshot.
116 * \param c The client.
117 * \return 1 if the image has been pushed on stack, false otherwise.
120 client_getcontent(client_t
*c
)
122 xcb_image_t
*ximage
= xcb_image_get(globalconf
.connection
,
125 c
->geometries
.internal
.width
,
126 c
->geometries
.internal
.height
,
127 ~0, XCB_IMAGE_FORMAT_Z_PIXMAP
);
132 if(ximage
->bpp
>= 24)
134 uint32_t *data
= p_alloca(uint32_t, ximage
->width
* ximage
->height
);
136 for(int y
= 0; y
< ximage
->height
; y
++)
137 for(int x
= 0; x
< ximage
->width
; x
++)
139 data
[y
* ximage
->width
+ x
] = xcb_image_get_pixel(ximage
, x
, y
);
140 data
[y
* ximage
->width
+ x
] |= 0xff000000; /* set alpha to 0xff */
143 retval
= image_new_from_argb32(ximage
->width
, ximage
->height
, data
);
145 xcb_image_destroy(ximage
);
151 /** Get a client by its window.
152 * \param w The client window to find.
153 * \return A client pointer if found, NULL otherwise.
156 client_getbywin(xcb_window_t w
)
158 foreach(c
, globalconf
.clients
)
165 /** Record that a client lost focus.
166 * \param c Client being unfocused
169 client_unfocus_update(client_t
*c
)
171 globalconf
.screens
.tab
[c
->phys_screen
].client_focus
= NULL
;
172 ewmh_update_net_active_window(c
->phys_screen
);
175 if(globalconf
.hooks
.unfocus
!= LUA_REFNIL
)
177 client_push(globalconf
.L
, c
);
178 luaA_dofunction_from_registry(globalconf
.L
, globalconf
.hooks
.unfocus
, 1, 0);
183 /** Unfocus a client.
184 * \param c The client.
187 client_unfocus(client_t
*c
)
190 xcb_window_t root_win
= xutil_screen_get(globalconf
.connection
, c
->phys_screen
)->root
;
191 /* Set focus on root window, so no events leak to the current window.
192 * This kind of inlines client_setfocus(), but a root window will never have
193 * the WM_TAKE_FOCUS protocol.
195 xcb_set_input_focus(globalconf
.connection
, XCB_INPUT_FOCUS_PARENT
,
196 root_win
, XCB_CURRENT_TIME
);
198 client_unfocus_update(c
);
201 /** Check if client supports protocol a protocole in WM_PROTOCOL.
202 * \param c The client.
203 * \param atom The protocol atom to check for.
204 * \return True if client has the atom in protocol, false otherwise.
207 client_hasproto(client_t
*c
, xcb_atom_t atom
)
211 for(i
= 0; i
< c
->protocols
.atoms_len
; i
++)
212 if(c
->protocols
.atoms
[i
] == atom
)
217 /** Sets focus on window - using xcb_set_input_focus or WM_TAKE_FOCUS
218 * \param c Client that should get focus
219 * \param set_input_focus Should we call xcb_set_input_focus
222 client_setfocus(client_t
*c
, bool set_input_focus
)
224 bool takefocus
= client_hasproto(c
, WM_TAKE_FOCUS
);
226 xcb_set_input_focus(globalconf
.connection
, XCB_INPUT_FOCUS_PARENT
,
227 c
->win
, XCB_CURRENT_TIME
);
229 window_takefocus(c
->win
);
232 /** Ban client and move it out of the viewport.
233 * \param c The client.
236 client_ban(client_t
*c
)
240 xcb_unmap_window(globalconf
.connection
, c
->win
);
244 if(globalconf
.screens
.tab
[c
->phys_screen
].prev_client_focus
== c
)
245 globalconf
.screens
.tab
[c
->phys_screen
].prev_client_focus
= NULL
;
247 /* Wait until the last moment to take away the focus from the window. */
248 if(globalconf
.screens
.tab
[c
->phys_screen
].client_focus
== c
)
253 /** This is part of The Bob Marley Algorithmm: we ignore enter and leave window
254 * in certain cases, like map/unmap or move, so we don't get spurious events.
257 client_ignore_enterleave_events(void)
259 foreach(c
, globalconf
.clients
)
260 xcb_change_window_attributes(globalconf
.connection
,
263 (const uint32_t []) { CLIENT_SELECT_INPUT_EVENT_MASK
& ~(XCB_EVENT_MASK_ENTER_WINDOW
| XCB_EVENT_MASK_LEAVE_WINDOW
) });
267 client_restore_enterleave_events(void)
269 foreach(c
, globalconf
.clients
)
270 xcb_change_window_attributes(globalconf
.connection
,
273 (const uint32_t []) { CLIENT_SELECT_INPUT_EVENT_MASK
});
276 /** Record that a client got focus.
277 * \param c Client being focused.
280 client_focus_update(client_t
*c
)
282 if(!client_maybevisible(c
, c
->screen
))
284 /* Focus previously focused client */
285 client_focus(globalconf
.screen_focus
->prev_client_focus
);
289 if(globalconf
.screen_focus
290 && globalconf
.screen_focus
->client_focus
)
292 if (globalconf
.screen_focus
->client_focus
!= c
)
293 client_unfocus_update(globalconf
.screen_focus
->client_focus
);
295 /* Already focused */
298 /* stop hiding client */
300 client_setminimized(c
, false);
302 /* unban the client before focusing for consistency */
305 globalconf
.screen_focus
= &globalconf
.screens
.tab
[c
->phys_screen
];
306 globalconf
.screen_focus
->prev_client_focus
= c
;
307 globalconf
.screen_focus
->client_focus
= c
;
309 /* according to EWMH, we have to remove the urgent state from a client */
310 client_seturgent(c
, false);
312 ewmh_update_net_active_window(c
->phys_screen
);
315 if(globalconf
.hooks
.focus
!= LUA_REFNIL
)
317 client_push(globalconf
.L
, c
);
318 luaA_dofunction_from_registry(globalconf
.L
, globalconf
.hooks
.focus
, 1, 0);
323 /** Give focus to client, or to first client if client is NULL.
324 * \param c The client or NULL.
327 client_focus(client_t
*c
)
329 /* We have to set focus on first client */
330 if(!c
&& globalconf
.clients
.len
&& !(c
= globalconf
.clients
.tab
[0]))
333 if(!client_maybevisible(c
, c
->screen
))
337 client_focus_update(c
);
339 client_setfocus(c
, !c
->nofocus
);
342 /** Stack a window below.
343 * \param c The client.
344 * \param previous The previous window on the stack.
345 * \return The next-previous!
348 client_stack_above(client_t
*c
, xcb_window_t previous
)
350 uint32_t config_win_vals
[2];
352 config_win_vals
[0] = previous
;
353 config_win_vals
[1] = XCB_STACK_MODE_ABOVE
;
355 xcb_configure_window(globalconf
.connection
, c
->win
,
356 XCB_CONFIG_WINDOW_SIBLING
| XCB_CONFIG_WINDOW_STACK_MODE
,
359 config_win_vals
[0] = c
->win
;
363 xcb_configure_window(globalconf
.connection
,
365 XCB_CONFIG_WINDOW_SIBLING
| XCB_CONFIG_WINDOW_STACK_MODE
,
367 previous
= c
->titlebar
->window
;
372 /* stack transient window on top of their parents */
373 foreach(node
, globalconf
.stack
)
374 if((*node
)->transient_for
== c
)
375 previous
= client_stack_above(*node
, previous
);
380 /** Stacking layout layers */
383 /** This one is a special layer */
391 /** This one only used for counting and is not a real layer */
395 /** Get the real layer of a client according to its attribute (fullscreen, …)
396 * \param c The client.
397 * \return The real layer.
400 client_layer_translator(client_t
*c
)
402 /* first deal with user set attributes */
405 else if(c
->isfullscreen
)
406 return LAYER_FULLSCREEN
;
412 /* check for transient attr */
416 /* then deal with windows type */
419 case WINDOW_TYPE_DESKTOP
:
420 return LAYER_DESKTOP
;
429 * \todo It might be worth stopping to restack everyone and only stack `c'
430 * relatively to the first matching in the list.
433 client_stack_refresh()
435 uint32_t config_win_vals
[2];
438 if (!globalconf
.client_need_stack_refresh
)
440 globalconf
.client_need_stack_refresh
= false;
442 config_win_vals
[0] = XCB_NONE
;
443 config_win_vals
[1] = XCB_STACK_MODE_ABOVE
;
445 /* stack desktop windows */
446 for(layer
= LAYER_DESKTOP
; layer
< LAYER_BELOW
; layer
++)
447 foreach(node
, globalconf
.stack
)
448 if(client_layer_translator(*node
) == layer
)
449 config_win_vals
[0] = client_stack_above(*node
,
452 /* first stack not ontop wibox window */
453 foreach(_sb
, globalconf
.wiboxes
)
458 xcb_configure_window(globalconf
.connection
,
460 XCB_CONFIG_WINDOW_SIBLING
| XCB_CONFIG_WINDOW_STACK_MODE
,
462 config_win_vals
[0] = sb
->window
;
466 /* then stack clients */
467 for(layer
= LAYER_BELOW
; layer
< LAYER_COUNT
; layer
++)
468 foreach(node
, globalconf
.stack
)
469 if(client_layer_translator(*node
) == layer
)
470 config_win_vals
[0] = client_stack_above(*node
,
473 /* then stack ontop wibox window */
474 foreach(_sb
, globalconf
.wiboxes
)
479 xcb_configure_window(globalconf
.connection
,
481 XCB_CONFIG_WINDOW_SIBLING
| XCB_CONFIG_WINDOW_STACK_MODE
,
483 config_win_vals
[0] = sb
->window
;
488 /** Manage a new client.
489 * \param w The window.
490 * \param wgeom Window geometry.
491 * \param phys_screen Physical screen number.
492 * \param startup True if we are managing at startup time.
495 client_manage(xcb_window_t w
, xcb_get_geometry_reply_t
*wgeom
, int phys_screen
, bool startup
)
497 xcb_get_property_cookie_t ewmh_icon_cookie
;
499 const uint32_t select_input_val
[] = { CLIENT_SELECT_INPUT_EVENT_MASK
};
501 if(systray_iskdedockapp(w
))
503 systray_request_handle(w
, phys_screen
, NULL
);
507 /* Send request to get NET_WM_ICON property as soon as possible... */
508 ewmh_icon_cookie
= ewmh_window_icon_get_unchecked(w
);
509 xcb_change_window_attributes(globalconf
.connection
, w
, XCB_CW_EVENT_MASK
, select_input_val
);
511 client_t
*c
= client_new(globalconf
.L
);
512 /* Push client in client list */
513 client_array_push(&globalconf
.clients
, client_ref(globalconf
.L
, -1));
516 screen
= c
->screen
= screen_getbycoord(&globalconf
.screens
.tab
[phys_screen
],
519 c
->phys_screen
= phys_screen
;
521 /* consider the window banned */
526 c
->geometry
.x
= wgeom
->x
;
527 c
->geometry
.y
= wgeom
->y
;
528 /* Border will be added later. */
529 c
->geometry
.width
= wgeom
->width
;
530 c
->geometry
.height
= wgeom
->height
;
531 /* Also set internal geometry (client_ban() needs it). */
532 c
->geometries
.internal
.x
= wgeom
->x
;
533 c
->geometries
.internal
.y
= wgeom
->y
;
534 c
->geometries
.internal
.width
= wgeom
->width
;
535 c
->geometries
.internal
.height
= wgeom
->height
;
536 client_setborder(c
, wgeom
->border_width
);
538 if(ewmh_window_icon_get_reply(ewmh_icon_cookie
))
540 client_push(globalconf
.L
, c
);
541 c
->icon
= luaA_object_ref_item(globalconf
.L
, -1, -2);
542 lua_pop(globalconf
.L
, 1);
545 /* we honor size hints by default */
546 c
->size_hints_honor
= true;
549 property_update_wm_normal_hints(c
, NULL
);
550 property_update_wm_hints(c
, NULL
);
551 property_update_wm_transient_for(c
, NULL
);
552 property_update_wm_client_leader(c
, NULL
);
553 property_update_wm_client_machine(c
);
554 property_update_wm_window_role(c
);
555 property_update_net_wm_pid(c
, NULL
);
558 c
->opacity
= window_opacity_get(c
->win
);
560 /* Then check clients hints */
561 ewmh_client_check_hints(c
);
563 /* move client to screen, but do not tag it */
564 screen_client_moveto(c
, screen
, false, true);
566 /* Push client in stack */
569 /* update window title */
570 property_update_wm_name(c
);
571 property_update_wm_icon_name(c
);
572 property_update_wm_class(c
, NULL
);
573 property_update_wm_protocols(c
);
575 xutil_text_prop_get(globalconf
.connection
, c
->win
, _NET_STARTUP_ID
, &c
->startup_id
, NULL
);
578 ewmh_process_client_strut(c
, NULL
);
580 ewmh_update_net_client_list(c
->phys_screen
);
582 /* Always stay in NORMAL_STATE. Even though iconified seems more
583 * appropriate sometimes. The only possible loss is that clients not using
584 * visibility events may continue to proces data (when banned).
585 * Without any exposes or other events the cost should be fairly limited though.
587 * Some clients may expect the window to be unmapped when STATE_ICONIFIED.
588 * Two conflicting parts of the ICCCM v2.0 (section 4.1.4):
590 * "Normal -> Iconic - The client should send a ClientMessage event as described later in this section."
591 * (note no explicit mention of unmapping, while Normal->Widthdrawn does mention that)
593 * "Once a client's window has left the Withdrawn state, the window will be mapped
594 * if it is in the Normal state and the window will be unmapped if it is in the Iconic state."
596 * At this stage it's just safer to keep it in normal state and avoid confusion.
598 window_state_set(c
->win
, XCB_WM_STATE_NORMAL
);
600 /* Grab everything */
601 xcb_grab_key(globalconf
.connection
, true, w
,
602 XCB_MOD_MASK_ANY
, XCB_GRAB_ANY
,
603 XCB_GRAB_MODE_ASYNC
, XCB_GRAB_MODE_SYNC
);
605 xcb_grab_button(globalconf
.connection
, false, w
,
606 XCB_EVENT_MASK_BUTTON_PRESS
| XCB_EVENT_MASK_BUTTON_RELEASE
,
607 XCB_GRAB_MODE_SYNC
, XCB_GRAB_MODE_ASYNC
, XCB_NONE
, XCB_NONE
,
608 XCB_GRAB_ANY
, XCB_MOD_MASK_ANY
);
612 spawn_start_notify(c
);
614 /* Call hook to notify list change */
615 if(globalconf
.hooks
.clients
!= LUA_REFNIL
)
616 luaA_dofunction_from_registry(globalconf
.L
, globalconf
.hooks
.clients
, 0, 0);
619 if(globalconf
.hooks
.manage
!= LUA_REFNIL
)
621 client_push(globalconf
.L
, c
);
622 lua_pushboolean(globalconf
.L
, startup
);
623 luaA_dofunction_from_registry(globalconf
.L
, globalconf
.hooks
.manage
, 2, 0);
627 /** Compute client geometry with respect to its geometry hints.
628 * \param c The client.
629 * \param geometry The geometry that the client might receive.
630 * \return The geometry the client must take respecting its hints.
633 client_geometry_hints(client_t
*c
, area_t geometry
)
635 int32_t basew
, baseh
, minw
, minh
;
637 /* base size is substituted with min size if not specified */
638 if(c
->size_hints
.flags
& XCB_SIZE_HINT_P_SIZE
)
640 basew
= c
->size_hints
.base_width
;
641 baseh
= c
->size_hints
.base_height
;
643 else if(c
->size_hints
.flags
& XCB_SIZE_HINT_P_MIN_SIZE
)
645 basew
= c
->size_hints
.min_width
;
646 baseh
= c
->size_hints
.min_height
;
651 /* min size is substituted with base size if not specified */
652 if(c
->size_hints
.flags
& XCB_SIZE_HINT_P_MIN_SIZE
)
654 minw
= c
->size_hints
.min_width
;
655 minh
= c
->size_hints
.min_height
;
657 else if(c
->size_hints
.flags
& XCB_SIZE_HINT_P_SIZE
)
659 minw
= c
->size_hints
.base_width
;
660 minh
= c
->size_hints
.base_height
;
665 if(c
->size_hints
.flags
& XCB_SIZE_HINT_P_ASPECT
666 && c
->size_hints
.min_aspect_num
> 0
667 && c
->size_hints
.min_aspect_den
> 0
668 && geometry
.height
- baseh
> 0
669 && geometry
.width
- basew
> 0)
671 double dx
= (double) (geometry
.width
- basew
);
672 double dy
= (double) (geometry
.height
- baseh
);
673 double min
= (double) c
->size_hints
.min_aspect_num
/ (double) c
->size_hints
.min_aspect_den
;
674 double max
= (double) c
->size_hints
.max_aspect_num
/ (double) c
->size_hints
.min_aspect_den
;
675 double ratio
= dx
/ dy
;
676 if(max
> 0 && min
> 0 && ratio
> 0)
680 dy
= (dx
* min
+ dy
) / (min
* min
+ 1);
682 geometry
.width
= (int) dx
+ basew
;
683 geometry
.height
= (int) dy
+ baseh
;
687 dy
= (dx
* min
+ dy
) / (max
* max
+ 1);
689 geometry
.width
= (int) dx
+ basew
;
690 geometry
.height
= (int) dy
+ baseh
;
696 geometry
.width
= MAX(geometry
.width
, minw
);
698 geometry
.height
= MAX(geometry
.height
, minh
);
700 if(c
->size_hints
.flags
& XCB_SIZE_HINT_P_MAX_SIZE
)
702 if(c
->size_hints
.max_width
)
703 geometry
.width
= MIN(geometry
.width
, c
->size_hints
.max_width
);
704 if(c
->size_hints
.max_height
)
705 geometry
.height
= MIN(geometry
.height
, c
->size_hints
.max_height
);
708 if(c
->size_hints
.flags
& (XCB_SIZE_HINT_P_RESIZE_INC
| XCB_SIZE_HINT_BASE_SIZE
)
709 && c
->size_hints
.width_inc
&& c
->size_hints
.height_inc
)
711 uint16_t t1
= geometry
.width
, t2
= geometry
.height
;
712 unsigned_subtract(t1
, basew
);
713 unsigned_subtract(t2
, baseh
);
714 geometry
.width
-= t1
% c
->size_hints
.width_inc
;
715 geometry
.height
-= t2
% c
->size_hints
.height_inc
;
721 /** Resize client window.
722 * The sizse given as parameters are with titlebar and borders!
723 * \param c Client to resize.
724 * \param geometry New window geometry.
725 * \param hints Use size hints.
726 * \return true if an actual resize occurred.
729 client_resize(client_t
*c
, area_t geometry
, bool hints
)
731 area_t geometry_internal
;
734 /* offscreen appearance fixes */
735 area
= display_area_get(c
->phys_screen
);
737 if(geometry
.x
> area
.width
)
738 geometry
.x
= area
.width
- geometry
.width
;
739 if(geometry
.y
> area
.height
)
740 geometry
.y
= area
.height
- geometry
.height
;
741 if(geometry
.x
+ geometry
.width
< 0)
743 if(geometry
.y
+ geometry
.height
< 0)
746 /* Real client geometry, please keep it contained to C code at the very least. */
747 geometry_internal
= titlebar_geometry_remove(c
->titlebar
, c
->border
, geometry
);
750 geometry_internal
= client_geometry_hints(c
, geometry_internal
);
752 if(geometry_internal
.width
== 0 || geometry_internal
.height
== 0)
755 /* Also let client hints propegate to the "official" geometry. */
756 geometry
= titlebar_geometry_add(c
->titlebar
, c
->border
, geometry_internal
);
758 if(c
->geometries
.internal
.x
!= geometry_internal
.x
759 || c
->geometries
.internal
.y
!= geometry_internal
.y
760 || c
->geometries
.internal
.width
!= geometry_internal
.width
761 || c
->geometries
.internal
.height
!= geometry_internal
.height
)
763 screen_t
*new_screen
= screen_getbycoord(c
->screen
,
764 geometry_internal
.x
, geometry_internal
.y
);
766 /* Values to configure a window is an array where values are
767 * stored according to 'value_mask' */
770 c
->geometries
.internal
.x
= values
[0] = geometry_internal
.x
;
771 c
->geometries
.internal
.y
= values
[1] = geometry_internal
.y
;
772 c
->geometries
.internal
.width
= values
[2] = geometry_internal
.width
;
773 c
->geometries
.internal
.height
= values
[3] = geometry_internal
.height
;
775 /* Also store geometry including border and titlebar. */
776 c
->geometry
= geometry
;
778 titlebar_update_geometry(c
);
780 /* Ignore all spurious enter/leave notify events */
781 client_ignore_enterleave_events();
783 xcb_configure_window(globalconf
.connection
, c
->win
,
784 XCB_CONFIG_WINDOW_X
| XCB_CONFIG_WINDOW_Y
785 | XCB_CONFIG_WINDOW_WIDTH
| XCB_CONFIG_WINDOW_HEIGHT
,
788 client_restore_enterleave_events();
790 screen_client_moveto(c
, new_screen
, true, false);
793 hook_property(client
, c
, "geometry");
801 /** Set a client minimized, or not.
802 * \param c The client.
803 * \param s Set or not the client minimized.
806 client_setminimized(client_t
*c
, bool s
)
808 if(c
->isminimized
!= s
)
810 client_need_reban(c
);
812 client_need_reban(c
);
814 window_state_set(c
->win
, XCB_WM_STATE_ICONIC
);
816 window_state_set(c
->win
, XCB_WM_STATE_NORMAL
);
817 ewmh_client_update_hints(c
);
819 hook_property(client
, c
, "minimized");
823 /** Set a client sticky, or not.
824 * \param c The client.
825 * \param s Set or not the client sticky.
828 client_setsticky(client_t
*c
, bool s
)
832 client_need_reban(c
);
834 client_need_reban(c
);
835 ewmh_client_update_hints(c
);
836 hook_property(client
, c
, "sticky");
840 /** Set a client fullscreen, or not.
841 * \param c The client.
842 * \param s Set or not the client fullscreen.
845 client_setfullscreen(client_t
*c
, bool s
)
847 if(c
->isfullscreen
!= s
)
851 /* Make sure the current geometry is stored without titlebar. */
853 titlebar_ban(c
->titlebar
);
855 /* become fullscreen! */
856 if((c
->isfullscreen
= s
))
858 /* remove any max state */
859 client_setmaxhoriz(c
, false);
860 client_setmaxvert(c
, false);
861 /* You can only be part of one of the special layers. */
862 client_setbelow(c
, false);
863 client_setabove(c
, false);
864 client_setontop(c
, false);
866 geometry
= screen_area_get(c
->screen
, false);
867 c
->geometries
.fullscreen
= c
->geometry
;
868 c
->border_fs
= c
->border
;
869 client_setborder(c
, 0);
873 geometry
= c
->geometries
.fullscreen
;
874 client_setborder(c
, c
->border_fs
);
876 client_resize(c
, geometry
, false);
878 ewmh_client_update_hints(c
);
879 hook_property(client
, c
, "fullscreen");
883 /** Set a client horizontally maximized.
884 * \param c The client.
885 * \param s The maximized status.
888 client_setmaxhoriz(client_t
*c
, bool s
)
890 if(c
->ismaxhoriz
!= s
)
894 if((c
->ismaxhoriz
= s
))
896 /* remove fullscreen mode */
897 client_setfullscreen(c
, false);
899 geometry
= screen_area_get(c
->screen
, true);
900 geometry
.y
= c
->geometry
.y
;
901 geometry
.height
= c
->geometry
.height
;
902 c
->geometries
.max
.x
= c
->geometry
.x
;
903 c
->geometries
.max
.width
= c
->geometry
.width
;
907 geometry
= c
->geometry
;
908 geometry
.x
= c
->geometries
.max
.x
;
909 geometry
.width
= c
->geometries
.max
.width
;
912 client_resize(c
, geometry
, c
->size_hints_honor
);
914 ewmh_client_update_hints(c
);
915 hook_property(client
, c
, "maximized_horizontal");
919 /** Set a client vertically maximized.
920 * \param c The client.
921 * \param s The maximized status.
924 client_setmaxvert(client_t
*c
, bool s
)
926 if(c
->ismaxvert
!= s
)
930 if((c
->ismaxvert
= s
))
932 /* remove fullscreen mode */
933 client_setfullscreen(c
, false);
935 geometry
= screen_area_get(c
->screen
, true);
936 geometry
.x
= c
->geometry
.x
;
937 geometry
.width
= c
->geometry
.width
;
938 c
->geometries
.max
.y
= c
->geometry
.y
;
939 c
->geometries
.max
.height
= c
->geometry
.height
;
943 geometry
= c
->geometry
;
944 geometry
.y
= c
->geometries
.max
.y
;
945 geometry
.height
= c
->geometries
.max
.height
;
948 client_resize(c
, geometry
, c
->size_hints_honor
);
950 ewmh_client_update_hints(c
);
951 hook_property(client
, c
, "maximized_vertical");
955 /** Set a client above, or not.
956 * \param c The client.
957 * \param s Set or not the client above.
960 client_setabove(client_t
*c
, bool s
)
964 /* You can only be part of one of the special layers. */
967 client_setbelow(c
, false);
968 client_setontop(c
, false);
969 client_setfullscreen(c
, false);
973 ewmh_client_update_hints(c
);
975 hook_property(client
, c
, "above");
979 /** Set a client below, or not.
980 * \param c The client.
981 * \param s Set or not the client below.
984 client_setbelow(client_t
*c
, bool s
)
988 /* You can only be part of one of the special layers. */
991 client_setabove(c
, false);
992 client_setontop(c
, false);
993 client_setfullscreen(c
, false);
997 ewmh_client_update_hints(c
);
999 hook_property(client
, c
, "below");
1003 /** Set a client modal, or not.
1004 * \param c The client.
1005 * \param s Set or not the client moda.
1008 client_setmodal(client_t
*c
, bool s
)
1014 ewmh_client_update_hints(c
);
1016 hook_property(client
, c
, "modal");
1020 /** Set a client ontop, or not.
1021 * \param c The client.
1022 * \param s Set or not the client moda.
1025 client_setontop(client_t
*c
, bool s
)
1029 /* You can only be part of one of the special layers. */
1032 client_setabove(c
, false);
1033 client_setbelow(c
, false);
1034 client_setfullscreen(c
, false);
1039 hook_property(client
, c
, "ontop");
1043 /** Unban a client and move it back into the viewport.
1044 * \param c The client.
1047 client_unban(client_t
*c
)
1051 xcb_map_window(globalconf
.connection
, c
->win
);
1053 c
->isbanned
= false;
1057 /** Unmanage a client.
1058 * \param c The client.
1061 client_unmanage(client_t
*c
)
1063 tag_array_t
*tags
= &c
->screen
->tags
;
1065 /* Reset transient_for attributes of widows that maybe refering to us */
1066 foreach(_tc
, globalconf
.clients
)
1068 client_t
*tc
= *_tc
;
1069 if(tc
->transient_for
== c
)
1070 tc
->transient_for
= NULL
;
1073 if(globalconf
.screens
.tab
[c
->phys_screen
].prev_client_focus
== c
)
1074 globalconf
.screens
.tab
[c
->phys_screen
].prev_client_focus
= NULL
;
1076 if(globalconf
.screens
.tab
[c
->phys_screen
].client_focus
== c
)
1079 /* remove client from global list and everywhere else */
1080 foreach(elem
, globalconf
.clients
)
1083 client_array_remove(&globalconf
.clients
, elem
);
1086 stack_client_remove(c
);
1087 for(int i
= 0; i
< tags
->len
; i
++)
1088 untag_client(c
, tags
->tab
[i
]);
1091 if(globalconf
.hooks
.unmanage
!= LUA_REFNIL
)
1093 client_push(globalconf
.L
, c
);
1094 luaA_dofunction_from_registry(globalconf
.L
, globalconf
.hooks
.unmanage
, 1, 0);
1097 /* Call hook to notify list change */
1098 if(globalconf
.hooks
.clients
!= LUA_REFNIL
)
1099 luaA_dofunction_from_registry(globalconf
.L
, globalconf
.hooks
.clients
, 0, 0);
1101 window_state_set(c
->win
, XCB_WM_STATE_WITHDRAWN
);
1103 titlebar_client_detach(c
);
1105 ewmh_update_net_client_list(c
->phys_screen
);
1107 /* set client as invalid */
1110 client_unref(globalconf
.L
, c
);
1113 /** Kill a client via a WM_DELETE_WINDOW request or KillClient if not
1115 * \param c The client to kill.
1118 client_kill(client_t
*c
)
1120 if(client_hasproto(c
, WM_DELETE_WINDOW
))
1122 xcb_client_message_event_t ev
;
1124 /* Initialize all of event's fields first */
1127 ev
.response_type
= XCB_CLIENT_MESSAGE
;
1130 ev
.data
.data32
[1] = XCB_CURRENT_TIME
;
1131 ev
.type
= WM_PROTOCOLS
;
1132 ev
.data
.data32
[0] = WM_DELETE_WINDOW
;
1134 xcb_send_event(globalconf
.connection
, false, c
->win
,
1135 XCB_EVENT_MASK_NO_EVENT
, (char *) &ev
);
1138 xcb_kill_client(globalconf
.connection
, c
->win
);
1141 /** Get all clients into a table.
1142 * \param L The Lua VM state.
1143 * \return The number of elements pushed on stack.
1145 * \lparam An optional screen nunmber.
1146 * \lreturn A table with all clients.
1149 luaA_client_get(lua_State
*L
)
1153 screen
= luaL_optnumber(L
, 1, 0) - 1;
1158 foreach(c
, globalconf
.clients
)
1161 lua_rawseti(L
, -2, i
++);
1165 luaA_checkscreen(screen
);
1166 foreach(c
, globalconf
.clients
)
1167 if((*c
)->screen
== &globalconf
.screens
.tab
[screen
])
1170 lua_rawseti(L
, -2, i
++);
1177 /** Check if a client is visible on its screen.
1178 * \param L The Lua VM state.
1179 * \return The number of elements pushed on stack.
1182 * \lreturn A boolean value, true if the client is visible, false otherwise.
1185 luaA_client_isvisible(lua_State
*L
)
1187 client_t
*c
= luaA_client_checkudata(L
, 1);
1188 lua_pushboolean(L
, client_isvisible(c
, c
->screen
));
1192 /** Set client border width.
1193 * \param c The client.
1194 * \param width The border width.
1197 client_setborder(client_t
*c
, int width
)
1201 if(width
> 0 && (c
->type
== WINDOW_TYPE_DOCK
1202 || c
->type
== WINDOW_TYPE_SPLASH
1203 || c
->type
== WINDOW_TYPE_DESKTOP
1204 || c
->isfullscreen
))
1207 if(width
== c
->border
|| width
< 0)
1210 /* Update geometry with the new border. */
1211 c
->geometry
.width
-= 2 * c
->border
;
1212 c
->geometry
.height
-= 2 * c
->border
;
1215 xcb_configure_window(globalconf
.connection
, c
->win
,
1216 XCB_CONFIG_WINDOW_BORDER_WIDTH
, &w
);
1218 c
->geometry
.width
+= 2 * c
->border
;
1219 c
->geometry
.height
+= 2 * c
->border
;
1221 /* Changing border size also affects the size of the titlebar. */
1222 titlebar_update_geometry(c
);
1224 hook_property(client
, c
, "border_width");
1228 * \param L The Lua VM state.
1234 luaA_client_kill(lua_State
*L
)
1236 client_t
*c
= luaA_client_checkudata(L
, 1);
1241 /** Swap a client with another one.
1242 * \param L The Lua VM state.
1245 * \lparam A client to swap with.
1248 luaA_client_swap(lua_State
*L
)
1250 client_t
*c
= luaA_client_checkudata(L
, 1);
1251 client_t
*swap
= luaA_client_checkudata(L
, 2);
1255 client_t
**ref_c
= NULL
, **ref_swap
= NULL
;
1256 foreach(item
, globalconf
.clients
)
1260 else if(*item
== swap
)
1262 if(ref_c
&& ref_swap
)
1269 /* Call hook to notify list change */
1270 if(globalconf
.hooks
.clients
!= LUA_REFNIL
)
1271 luaA_dofunction_from_registry(L
, globalconf
.hooks
.clients
, 0, 0);
1277 /** Access or set the client tags.
1278 * \param L The Lua VM state.
1279 * \return The number of elements pushed on stack.
1280 * \lparam A table with tags to set, or none to get the current tags table.
1281 * \return The clients tag.
1284 luaA_client_tags(lua_State
*L
)
1286 client_t
*c
= luaA_client_checkudata(L
, 1);
1287 tag_array_t
*tags
= &c
->screen
->tags
;
1290 if(lua_gettop(L
) == 2)
1292 luaA_checktable(L
, 2);
1293 for(int i
= 0; i
< tags
->len
; i
++)
1294 untag_client(c
, tags
->tab
[i
]);
1296 while(lua_next(L
, 2))
1303 if(is_client_tagged(c
, *tag
))
1306 lua_rawseti(L
, -2, ++j
);
1312 /** Raise a client on top of others which are on the same layer.
1313 * \param L The Lua VM state.
1318 luaA_client_raise(lua_State
*L
)
1320 client_t
*c
= luaA_client_checkudata(L
, 1);
1325 /** Lower a client on bottom of others which are on the same layer.
1326 * \param L The Lua VM state.
1331 luaA_client_lower(lua_State
*L
)
1333 client_t
*c
= luaA_client_checkudata(L
, 1);
1338 /** Redraw a client by unmapping and mapping it quickly.
1339 * \param L The Lua VM state.
1345 luaA_client_redraw(lua_State
*L
)
1347 client_t
*c
= luaA_client_checkudata(L
, 1);
1349 xcb_unmap_window(globalconf
.connection
, c
->win
);
1350 xcb_map_window(globalconf
.connection
, c
->win
);
1352 /* Set the focus on the current window if the redraw has been
1353 performed on the window where the pointer is currently on
1354 because after the unmapping/mapping, the focus is lost */
1355 if(globalconf
.screen_focus
->client_focus
== c
)
1364 /** Stop managing a client.
1365 * \param L The Lua VM state.
1366 * \return The number of elements pushed on stack.
1371 luaA_client_unmanage(lua_State
*L
)
1373 client_t
*c
= luaA_client_checkudata(L
, 1);
1378 /** Return client geometry.
1379 * \param L The Lua VM state.
1380 * \return The number of elements pushed on stack.
1382 * \lparam A table with new coordinates, or none.
1383 * \lreturn A table with client coordinates.
1386 luaA_client_geometry(lua_State
*L
)
1388 client_t
*c
= luaA_client_checkudata(L
, 1);
1390 if(lua_gettop(L
) == 2)
1394 luaA_checktable(L
, 2);
1395 geometry
.x
= luaA_getopt_number(L
, 2, "x", c
->geometry
.x
);
1396 geometry
.y
= luaA_getopt_number(L
, 2, "y", c
->geometry
.y
);
1397 if(client_isfixed(c
))
1399 geometry
.width
= c
->geometry
.width
;
1400 geometry
.height
= c
->geometry
.height
;
1404 geometry
.width
= luaA_getopt_number(L
, 2, "width", c
->geometry
.width
);
1405 geometry
.height
= luaA_getopt_number(L
, 2, "height", c
->geometry
.height
);
1408 client_resize(c
, geometry
, c
->size_hints_honor
);
1411 return luaA_pusharea(L
, c
->geometry
);
1414 /** Push a strut type to a table on stack.
1415 * \param L The Lua VM state.
1416 * \param struts The struts to push.
1417 * \return The number of elements pushed on stack.
1420 luaA_pushstruts(lua_State
*L
, strut_t struts
)
1422 lua_createtable(L
, 4, 0);
1423 lua_pushnumber(L
, struts
.left
);
1424 lua_setfield(L
, -2, "left");
1425 lua_pushnumber(L
, struts
.right
);
1426 lua_setfield(L
, -2, "right");
1427 lua_pushnumber(L
, struts
.top
);
1428 lua_setfield(L
, -2, "top");
1429 lua_pushnumber(L
, struts
.bottom
);
1430 lua_setfield(L
, -2, "bottom");
1434 /** Return client struts (reserved space at the edge of the screen).
1435 * \param L The Lua VM state.
1436 * \return The number of elements pushed on stack.
1438 * \lparam A table with new strut values, or none.
1439 * \lreturn A table with strut values.
1442 luaA_client_struts(lua_State
*L
)
1444 client_t
*c
= luaA_client_checkudata(L
, 1);
1446 if(lua_gettop(L
) == 2)
1449 area_t screen_area
= display_area_get(c
->phys_screen
);
1451 struts
.left
= luaA_getopt_number(L
, 2, "left", c
->strut
.left
);
1452 struts
.right
= luaA_getopt_number(L
, 2, "right", c
->strut
.right
);
1453 struts
.top
= luaA_getopt_number(L
, 2, "top", c
->strut
.top
);
1454 struts
.bottom
= luaA_getopt_number(L
, 2, "bottom", c
->strut
.bottom
);
1456 if(struts
.left
!= c
->strut
.left
|| struts
.right
!= c
->strut
.right
||
1457 struts
.top
!= c
->strut
.top
|| struts
.bottom
!= c
->strut
.bottom
) {
1458 /* Struts are not so well defined in the context of xinerama. So we just
1459 * give the entire root window and let the window manager decide. */
1460 struts
.left_start_y
= 0;
1461 struts
.left_end_y
= !struts
.left
? 0 : screen_area
.height
;
1462 struts
.right_start_y
= 0;
1463 struts
.right_end_y
= !struts
.right
? 0 : screen_area
.height
;
1464 struts
.top_start_x
= 0;
1465 struts
.top_end_x
= !struts
.top
? 0 : screen_area
.width
;
1466 struts
.bottom_start_x
= 0;
1467 struts
.bottom_end_x
= !struts
.bottom
? 0 : screen_area
.width
;
1471 ewmh_update_client_strut(c
);
1473 hook_property(client
, c
, "struts");
1477 return luaA_pushstruts(L
, c
->strut
);
1480 /** Client newindex.
1481 * \param L The Lua VM state.
1482 * \return The number of elements pushed on stack.
1485 luaA_client_newindex(lua_State
*L
)
1488 client_t
*c
= luaA_client_checkudata(L
, 1);
1489 const char *buf
= luaL_checklstring(L
, 2, &len
);
1494 switch(a_tokenize(buf
, len
))
1497 if(globalconf
.xinerama_is_active
)
1499 i
= luaL_checknumber(L
, 3) - 1;
1500 luaA_checkscreen(i
);
1501 screen_client_moveto(c
, &globalconf
.screens
.tab
[i
], true, true);
1505 b
= luaA_checkboolean(L
, 3);
1506 if(b
!= c
->ishidden
)
1508 client_need_reban(c
);
1510 client_need_reban(c
);
1511 hook_property(client
, c
, "hide");
1514 case A_TK_MINIMIZED
:
1515 client_setminimized(c
, luaA_checkboolean(L
, 3));
1517 case A_TK_FULLSCREEN
:
1518 client_setfullscreen(c
, luaA_checkboolean(L
, 3));
1520 case A_TK_MAXIMIZED_HORIZONTAL
:
1521 client_setmaxhoriz(c
, luaA_checkboolean(L
, 3));
1523 case A_TK_MAXIMIZED_VERTICAL
:
1524 client_setmaxvert(c
, luaA_checkboolean(L
, 3));
1527 luaA_object_unref_item(L
, 1, c
->icon
);
1529 c
->icon
= luaA_object_ref_item(L
, 1, 3);
1531 hook_property(client
, c
, "icon");
1536 window_opacity_set(c
->win
, -1);
1541 d
= luaL_checknumber(L
, 3);
1542 if(d
>= 0 && d
<= 1)
1544 window_opacity_set(c
->win
, d
);
1550 client_setsticky(c
, luaA_checkboolean(L
, 3));
1552 case A_TK_SIZE_HINTS_HONOR
:
1553 c
->size_hints_honor
= luaA_checkboolean(L
, 3);
1554 hook_property(client
, c
, "size_hints_honor");
1556 case A_TK_BORDER_WIDTH
:
1557 client_setborder(c
, luaL_checknumber(L
, 3));
1560 client_setontop(c
, luaA_checkboolean(L
, 3));
1563 client_setabove(c
, luaA_checkboolean(L
, 3));
1566 client_setbelow(c
, luaA_checkboolean(L
, 3));
1569 client_seturgent(c
, luaA_checkboolean(L
, 3));
1571 case A_TK_BORDER_COLOR
:
1572 if((buf
= luaL_checklstring(L
, 3, &len
))
1573 && xcolor_init_reply(xcolor_init_unchecked(&c
->border_color
, buf
, len
)))
1574 xcb_change_window_attributes(globalconf
.connection
, c
->win
,
1575 XCB_CW_BORDER_PIXEL
, &c
->border_color
.pixel
);
1579 titlebar_client_detach(c
);
1581 titlebar_client_attach(c
);
1583 case A_TK_SKIP_TASKBAR
:
1584 c
->skiptb
= luaA_checkboolean(L
, 3);
1585 hook_property(client
, c
, "skip_taskbar");
1595 * \param L The Lua VM state.
1596 * \return The number of elements pushed on stack.
1598 * \lfield id The window X id.
1599 * \lfield name The client title.
1600 * \lfield skip_taskbar If true the client won't be shown in the tasklist.
1601 * \lfield type The window type (desktop, normal, dock, …).
1602 * \lfield class The client class.
1603 * \lfield instance The client instance.
1604 * \lfield pid The client PID, if available.
1605 * \lfield role The window role, if available.
1606 * \lfield machine The machine client is running on.
1607 * \lfield icon_name The client name when iconified.
1608 * \lfield screen Client screen number.
1609 * \lfield hide Define if the client must be hidden, i.e. never mapped,
1610 * invisible in taskbar.
1611 * \lfield minimized Define it the client must be iconify, i.e. only visible in
1613 * \lfield size_hints_honor Honor size hints, i.e. respect size ratio.
1614 * \lfield border_width The client border width.
1615 * \lfield border_color The client border color.
1616 * \lfield titlebar The client titlebar.
1617 * \lfield urgent The client urgent state.
1618 * \lfield content An image representing the client window content (screenshot).
1619 * \lfield focus The focused client.
1620 * \lfield opacity The client opacity between 0 and 1.
1621 * \lfield ontop The client is on top of every other windows.
1622 * \lfield above The client is above normal windows.
1623 * \lfield below The client is below normal windows.
1624 * \lfield fullscreen The client is fullscreen or not.
1625 * \lfield maximized_horizontal The client is maximized horizontally or not.
1626 * \lfield maximized_vertical The client is maximized vertically or not.
1627 * \lfield transient_for Return the client the window is transient for.
1628 * \lfield group_id Identification unique to a group of windows.
1629 * \lfield leader_id Identification unique to windows spawned by the same command.
1630 * \lfield size_hints A table with size hints of the client: user_position,
1631 * user_size, program_position, program_size, etc.
1634 luaA_client_index(lua_State
*L
)
1637 client_t
*c
= luaA_client_checkudata(L
, 1);
1638 const char *buf
= luaL_checklstring(L
, 2, &len
);
1640 if(luaA_usemetatable(L
, 1, 2))
1643 switch(a_tokenize(buf
, len
))
1646 lua_pushstring(L
, c
->name
);
1648 case A_TK_TRANSIENT_FOR
:
1649 return client_push(globalconf
.L
, c
->transient_for
);
1650 case A_TK_SKIP_TASKBAR
:
1651 lua_pushboolean(L
, c
->skiptb
);
1654 return client_getcontent(c
);
1658 case WINDOW_TYPE_DESKTOP
:
1659 lua_pushliteral(L
, "desktop");
1661 case WINDOW_TYPE_DOCK
:
1662 lua_pushliteral(L
, "dock");
1664 case WINDOW_TYPE_SPLASH
:
1665 lua_pushliteral(L
, "splash");
1667 case WINDOW_TYPE_DIALOG
:
1668 lua_pushliteral(L
, "dialog");
1670 case WINDOW_TYPE_MENU
:
1671 lua_pushliteral(L
, "menu");
1673 case WINDOW_TYPE_TOOLBAR
:
1674 lua_pushliteral(L
, "toolbar");
1676 case WINDOW_TYPE_UTILITY
:
1677 lua_pushliteral(L
, "utility");
1679 case WINDOW_TYPE_DROPDOWN_MENU
:
1680 lua_pushliteral(L
, "dropdown_menu");
1682 case WINDOW_TYPE_POPUP_MENU
:
1683 lua_pushliteral(L
, "popup_menu");
1685 case WINDOW_TYPE_TOOLTIP
:
1686 lua_pushliteral(L
, "tooltip");
1688 case WINDOW_TYPE_NOTIFICATION
:
1689 lua_pushliteral(L
, "notification");
1691 case WINDOW_TYPE_COMBO
:
1692 lua_pushliteral(L
, "combo");
1694 case WINDOW_TYPE_DND
:
1695 lua_pushliteral(L
, "dnd");
1697 case WINDOW_TYPE_NORMAL
:
1698 lua_pushliteral(L
, "normal");
1703 lua_pushstring(L
, c
->class);
1706 lua_pushstring(L
, c
->instance
);
1709 lua_pushstring(L
, c
->role
);
1712 lua_pushnumber(L
, c
->pid
);
1715 lua_pushnumber(L
, c
->win
);
1717 case A_TK_LEADER_ID
:
1718 lua_pushnumber(L
, c
->leader_win
);
1721 lua_pushstring(L
, c
->machine
);
1723 case A_TK_ICON_NAME
:
1724 lua_pushstring(L
, c
->icon_name
);
1727 lua_pushnumber(L
, 1 + screen_array_indexof(&globalconf
.screens
, c
->screen
));
1730 lua_pushboolean(L
, c
->ishidden
);
1732 case A_TK_MINIMIZED
:
1733 lua_pushboolean(L
, c
->isminimized
);
1735 case A_TK_FULLSCREEN
:
1736 lua_pushboolean(L
, c
->isfullscreen
);
1740 lua_pushnumber(L
, c
->group_win
);
1744 case A_TK_MAXIMIZED_HORIZONTAL
:
1745 lua_pushboolean(L
, c
->ismaxhoriz
);
1747 case A_TK_MAXIMIZED_VERTICAL
:
1748 lua_pushboolean(L
, c
->ismaxvert
);
1751 luaA_object_push_item(L
, 1, c
->icon
);
1754 lua_pushnumber(L
, c
->opacity
);
1757 lua_pushboolean(L
, c
->isontop
);
1760 lua_pushboolean(L
, c
->isabove
);
1763 lua_pushboolean(L
, c
->isbelow
);
1766 lua_pushboolean(L
, c
->issticky
);
1768 case A_TK_SIZE_HINTS_HONOR
:
1769 lua_pushboolean(L
, c
->size_hints_honor
);
1771 case A_TK_BORDER_WIDTH
:
1772 lua_pushnumber(L
, c
->border
);
1774 case A_TK_BORDER_COLOR
:
1775 luaA_pushxcolor(L
, &c
->border_color
);
1778 return wibox_push(L
, c
->titlebar
);
1780 lua_pushboolean(L
, c
->isurgent
);
1782 case A_TK_SIZE_HINTS
:
1784 const char *u_or_p
= NULL
;
1786 lua_createtable(L
, 0, 1);
1788 if(c
->size_hints
.flags
& XCB_SIZE_HINT_US_POSITION
)
1789 u_or_p
= "user_position";
1790 else if(c
->size_hints
.flags
& XCB_SIZE_HINT_P_POSITION
)
1791 u_or_p
= "program_position";
1795 lua_createtable(L
, 0, 2);
1796 lua_pushnumber(L
, c
->size_hints
.x
);
1797 lua_setfield(L
, -2, "x");
1798 lua_pushnumber(L
, c
->size_hints
.y
);
1799 lua_setfield(L
, -2, "y");
1800 lua_setfield(L
, -2, u_or_p
);
1804 if(c
->size_hints
.flags
& XCB_SIZE_HINT_US_SIZE
)
1805 u_or_p
= "user_size";
1806 else if(c
->size_hints
.flags
& XCB_SIZE_HINT_P_SIZE
)
1807 u_or_p
= "program_size";
1811 lua_createtable(L
, 0, 2);
1812 lua_pushnumber(L
, c
->size_hints
.width
);
1813 lua_setfield(L
, -2, "width");
1814 lua_pushnumber(L
, c
->size_hints
.height
);
1815 lua_setfield(L
, -2, "height");
1816 lua_setfield(L
, -2, u_or_p
);
1819 if(c
->size_hints
.flags
& XCB_SIZE_HINT_P_MIN_SIZE
)
1821 lua_pushnumber(L
, c
->size_hints
.min_width
);
1822 lua_setfield(L
, -2, "min_width");
1823 lua_pushnumber(L
, c
->size_hints
.min_height
);
1824 lua_setfield(L
, -2, "min_height");
1827 if(c
->size_hints
.flags
& XCB_SIZE_HINT_P_MAX_SIZE
)
1829 lua_pushnumber(L
, c
->size_hints
.max_width
);
1830 lua_setfield(L
, -2, "max_width");
1831 lua_pushnumber(L
, c
->size_hints
.max_height
);
1832 lua_setfield(L
, -2, "max_height");
1835 if(c
->size_hints
.flags
& XCB_SIZE_HINT_P_RESIZE_INC
)
1837 lua_pushnumber(L
, c
->size_hints
.width_inc
);
1838 lua_setfield(L
, -2, "width_inc");
1839 lua_pushnumber(L
, c
->size_hints
.height_inc
);
1840 lua_setfield(L
, -2, "height_inc");
1843 if(c
->size_hints
.flags
& XCB_SIZE_HINT_P_ASPECT
)
1845 lua_pushnumber(L
, c
->size_hints
.min_aspect_num
);
1846 lua_setfield(L
, -2, "min_aspect_num");
1847 lua_pushnumber(L
, c
->size_hints
.min_aspect_den
);
1848 lua_setfield(L
, -2, "min_aspect_den");
1849 lua_pushnumber(L
, c
->size_hints
.max_aspect_num
);
1850 lua_setfield(L
, -2, "max_aspect_num");
1851 lua_pushnumber(L
, c
->size_hints
.max_aspect_den
);
1852 lua_setfield(L
, -2, "max_aspect_den");
1855 if(c
->size_hints
.flags
& XCB_SIZE_HINT_BASE_SIZE
)
1857 lua_pushnumber(L
, c
->size_hints
.base_width
);
1858 lua_setfield(L
, -2, "base_width");
1859 lua_pushnumber(L
, c
->size_hints
.base_height
);
1860 lua_setfield(L
, -2, "base_height");
1863 if(c
->size_hints
.flags
& XCB_SIZE_HINT_P_WIN_GRAVITY
)
1865 switch(c
->size_hints
.win_gravity
)
1868 lua_pushliteral(L
, "north_west");
1870 case XCB_GRAVITY_NORTH
:
1871 lua_pushliteral(L
, "north");
1873 case XCB_GRAVITY_NORTH_EAST
:
1874 lua_pushliteral(L
, "north_east");
1876 case XCB_GRAVITY_WEST
:
1877 lua_pushliteral(L
, "west");
1879 case XCB_GRAVITY_CENTER
:
1880 lua_pushliteral(L
, "center");
1882 case XCB_GRAVITY_EAST
:
1883 lua_pushliteral(L
, "east");
1885 case XCB_GRAVITY_SOUTH_WEST
:
1886 lua_pushliteral(L
, "south_west");
1888 case XCB_GRAVITY_SOUTH
:
1889 lua_pushliteral(L
, "south");
1891 case XCB_GRAVITY_SOUTH_EAST
:
1892 lua_pushliteral(L
, "south_east");
1894 case XCB_GRAVITY_STATIC
:
1895 lua_pushliteral(L
, "static");
1898 lua_setfield(L
, -2, "win_gravity");
1909 /** Get or set mouse buttons bindings for a client.
1910 * \param L The Lua VM state.
1911 * \return The number of element pushed on stack.
1914 * \lparam An array of mouse button bindings objects, or nothing.
1915 * \return The array of mouse button bindings objects of this client.
1918 luaA_client_buttons(lua_State
*L
)
1920 client_t
*client
= luaA_client_checkudata(L
, 1);
1921 button_array_t
*buttons
= &client
->buttons
;
1923 if(lua_gettop(L
) == 2)
1924 luaA_button_array_set(L
, 1, 2, buttons
);
1926 return luaA_button_array_get(L
, 1, buttons
);
1929 /** Get or set keys bindings for a client.
1930 * \param L The Lua VM state.
1931 * \return The number of element pushed on stack.
1934 * \lparam An array of key bindings objects, or nothing.
1935 * \return The array of key bindings objects of this client.
1938 luaA_client_keys(lua_State
*L
)
1940 client_t
*c
= luaA_client_checkudata(L
, 1);
1941 key_array_t
*keys
= &c
->keys
;
1943 if(lua_gettop(L
) == 2)
1944 luaA_key_array_set(L
, 1, 2, keys
);
1946 return luaA_key_array_get(L
, 1, keys
);
1950 * \param L The Lua VM state.
1951 * \return The number of pushed elements.
1954 luaA_client_module_index(lua_State
*L
)
1957 const char *buf
= luaL_checklstring(L
, 2, &len
);
1959 switch(a_tokenize(buf
, len
))
1962 return client_push(globalconf
.L
, globalconf
.screen_focus
->client_focus
);
1969 /* Client module new index.
1970 * \param L The Lua VM state.
1971 * \return The number of pushed elements.
1974 luaA_client_module_newindex(lua_State
*L
)
1977 const char *buf
= luaL_checklstring(L
, 2, &len
);
1980 switch(a_tokenize(buf
, len
))
1983 c
= luaA_client_checkudata(L
, 3);
1993 const struct luaL_reg awesome_client_methods
[] =
1995 LUA_CLASS_METHODS(client
)
1996 { "get", luaA_client_get
},
1997 { "__index", luaA_client_module_index
},
1998 { "__newindex", luaA_client_module_newindex
},
2001 const struct luaL_reg awesome_client_meta
[] =
2003 LUA_OBJECT_META(client
)
2004 { "isvisible", luaA_client_isvisible
},
2005 { "geometry", luaA_client_geometry
},
2006 { "struts", luaA_client_struts
},
2007 { "buttons", luaA_client_buttons
},
2008 { "keys", luaA_client_keys
},
2009 { "tags", luaA_client_tags
},
2010 { "kill", luaA_client_kill
},
2011 { "swap", luaA_client_swap
},
2012 { "raise", luaA_client_raise
},
2013 { "lower", luaA_client_lower
},
2014 { "redraw", luaA_client_redraw
},
2015 { "unmanage", luaA_client_unmanage
},
2016 { "__index", luaA_client_index
},
2017 { "__newindex", luaA_client_newindex
},
2018 { "__gc", luaA_client_gc
},
2022 // vim: filetype=c:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=80