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 button_array_wipe(&c
->buttons
);
55 key_array_wipe(&c
->keys
);
56 image_unref(L
, c
->icon
);
57 xcb_get_wm_protocols_reply_wipe(&c
->protocols
);
59 p_delete(&c
->startup_id
);
60 p_delete(&c
->instance
);
61 p_delete(&c
->icon_name
);
63 return luaA_object_gc(L
);
66 /** Change the clients urgency flag.
68 * \param urgent The new flag state
71 client_seturgent(client_t
*c
, bool urgent
)
73 if(c
->isurgent
!= urgent
)
75 xcb_get_property_cookie_t hints
=
76 xcb_get_wm_hints_unchecked(globalconf
.connection
, c
->win
);
79 ewmh_client_update_hints(c
);
81 /* update ICCCM hints */
83 xcb_get_wm_hints_reply(globalconf
.connection
, hints
, &wmh
, NULL
);
86 wmh
.flags
|= XCB_WM_HINT_X_URGENCY
;
88 wmh
.flags
&= ~XCB_WM_HINT_X_URGENCY
;
90 xcb_set_wm_hints(globalconf
.connection
, c
->win
, &wmh
);
92 hook_property(client
, c
, "urgent");
96 /** Returns true if a client is tagged
97 * with one of the tags of the specified screen.
98 * \param c The client to check.
99 * \param screen Virtual screen.
100 * \return true if the client is visible, false otherwise.
103 client_maybevisible(client_t
*c
, screen_t
*screen
)
105 if(c
->screen
== screen
)
107 if(c
->issticky
|| c
->type
== WINDOW_TYPE_DESKTOP
)
110 foreach(tag
, screen
->tags
)
111 if((*tag
)->selected
&& is_client_tagged(c
, *tag
))
117 /** Return the content of a client as an image.
118 * That's just take a screenshot.
119 * \param c The client.
120 * \return 1 if the image has been pushed on stack, false otherwise.
123 client_getcontent(client_t
*c
)
125 xcb_image_t
*ximage
= xcb_image_get(globalconf
.connection
,
128 c
->geometries
.internal
.width
,
129 c
->geometries
.internal
.height
,
130 ~0, XCB_IMAGE_FORMAT_Z_PIXMAP
);
135 if(ximage
->bpp
>= 24)
137 uint32_t *data
= p_alloca(uint32_t, ximage
->width
* ximage
->height
);
139 for(int y
= 0; y
< ximage
->height
; y
++)
140 for(int x
= 0; x
< ximage
->width
; x
++)
142 data
[y
* ximage
->width
+ x
] = xcb_image_get_pixel(ximage
, x
, y
);
143 data
[y
* ximage
->width
+ x
] |= 0xff000000; /* set alpha to 0xff */
146 retval
= image_new_from_argb32(ximage
->width
, ximage
->height
, data
);
148 xcb_image_destroy(ximage
);
154 /** Get a client by its window.
155 * \param w The client window to find.
156 * \return A client pointer if found, NULL otherwise.
159 client_getbywin(xcb_window_t w
)
161 foreach(c
, globalconf
.clients
)
168 /** Record that a client lost focus.
169 * \param c Client being unfocused
172 client_unfocus_update(client_t
*c
)
174 globalconf
.screens
.tab
[c
->phys_screen
].client_focus
= NULL
;
175 ewmh_update_net_active_window(c
->phys_screen
);
178 if(globalconf
.hooks
.unfocus
!= LUA_REFNIL
)
180 client_push(globalconf
.L
, c
);
181 luaA_dofunction_from_registry(globalconf
.L
, globalconf
.hooks
.unfocus
, 1, 0);
186 /** Unfocus a client.
187 * \param c The client.
190 client_unfocus(client_t
*c
)
193 xcb_window_t root_win
= xutil_screen_get(globalconf
.connection
, c
->phys_screen
)->root
;
194 /* Set focus on root window, so no events leak to the current window.
195 * This kind of inlines client_setfocus(), but a root window will never have
196 * the WM_TAKE_FOCUS protocol.
198 xcb_set_input_focus(globalconf
.connection
, XCB_INPUT_FOCUS_PARENT
,
199 root_win
, XCB_CURRENT_TIME
);
201 client_unfocus_update(c
);
204 /** Check if client supports protocol a protocole in WM_PROTOCOL.
205 * \param c The client.
206 * \return True if client has the atom in protocol, false otherwise.
209 client_hasproto(client_t
*c
, xcb_atom_t atom
)
213 for(i
= 0; i
< c
->protocols
.atoms_len
; i
++)
214 if(c
->protocols
.atoms
[i
] == atom
)
219 /** Sets focus on window - using xcb_set_input_focus or WM_TAKE_FOCUS
220 * \param c Client that should get focus
221 * \param set_input_focus Should we call xcb_set_input_focus
224 client_setfocus(client_t
*c
, bool set_input_focus
)
226 bool takefocus
= client_hasproto(c
, WM_TAKE_FOCUS
);
228 xcb_set_input_focus(globalconf
.connection
, XCB_INPUT_FOCUS_PARENT
,
229 c
->win
, XCB_CURRENT_TIME
);
231 window_takefocus(c
->win
);
234 /** Ban client and move it out of the viewport.
235 * \param c The client.
238 client_ban(client_t
*c
)
242 xcb_unmap_window(globalconf
.connection
, c
->win
);
246 if(globalconf
.screens
.tab
[c
->phys_screen
].prev_client_focus
== c
)
247 globalconf
.screens
.tab
[c
->phys_screen
].prev_client_focus
= NULL
;
249 /* Wait until the last moment to take away the focus from the window. */
250 if(globalconf
.screens
.tab
[c
->phys_screen
].client_focus
== c
)
255 /** Record that a client got focus.
256 * \param c Client being focused.
259 client_focus_update(client_t
*c
)
261 if(!client_maybevisible(c
, c
->screen
))
263 /* Focus previously focused client */
264 client_focus(globalconf
.screen_focus
->prev_client_focus
);
268 if(globalconf
.screen_focus
269 && globalconf
.screen_focus
->client_focus
)
271 if (globalconf
.screen_focus
->client_focus
!= c
)
272 client_unfocus_update(globalconf
.screen_focus
->client_focus
);
274 /* Already focused */
277 /* stop hiding client */
279 client_setminimized(c
, false);
281 /* unban the client before focusing for consistency */
284 globalconf
.screen_focus
= &globalconf
.screens
.tab
[c
->phys_screen
];
285 globalconf
.screen_focus
->prev_client_focus
= c
;
286 globalconf
.screen_focus
->client_focus
= c
;
288 /* according to EWMH, we have to remove the urgent state from a client */
289 client_seturgent(c
, false);
291 ewmh_update_net_active_window(c
->phys_screen
);
294 if(globalconf
.hooks
.focus
!= LUA_REFNIL
)
296 client_push(globalconf
.L
, c
);
297 luaA_dofunction_from_registry(globalconf
.L
, globalconf
.hooks
.focus
, 1, 0);
302 /** Give focus to client, or to first client if client is NULL.
303 * \param c The client or NULL.
306 client_focus(client_t
*c
)
308 /* We have to set focus on first client */
309 if(!c
&& globalconf
.clients
.len
&& !(c
= globalconf
.clients
.tab
[0]))
312 if(!client_maybevisible(c
, c
->screen
))
316 client_focus_update(c
);
318 client_setfocus(c
, !c
->nofocus
);
321 /** Stack a window below.
322 * \param c The client.
323 * \param previous The previous window on the stack.
324 * \param return The next-previous!
327 client_stack_above(client_t
*c
, xcb_window_t previous
)
329 uint32_t config_win_vals
[2];
331 config_win_vals
[0] = previous
;
332 config_win_vals
[1] = XCB_STACK_MODE_ABOVE
;
334 xcb_configure_window(globalconf
.connection
, c
->win
,
335 XCB_CONFIG_WINDOW_SIBLING
| XCB_CONFIG_WINDOW_STACK_MODE
,
338 config_win_vals
[0] = c
->win
;
342 xcb_configure_window(globalconf
.connection
,
343 c
->titlebar
->sw
.window
,
344 XCB_CONFIG_WINDOW_SIBLING
| XCB_CONFIG_WINDOW_STACK_MODE
,
346 previous
= c
->titlebar
->sw
.window
;
351 /* stack transient window on top of their parents */
352 foreach(node
, globalconf
.stack
)
353 if((*node
)->transient_for
== c
)
354 previous
= client_stack_above(*node
, previous
);
359 /** Stacking layout layers */
362 /** This one is a special layer */
370 /** This one only used for counting and is not a real layer */
374 /** Get the real layer of a client according to its attribute (fullscreen, …)
375 * \param c The client.
376 * \return The real layer.
379 client_layer_translator(client_t
*c
)
381 /* first deal with user set attributes */
384 else if(c
->isfullscreen
)
385 return LAYER_FULLSCREEN
;
391 /* check for transient attr */
395 /* then deal with windows type */
398 case WINDOW_TYPE_DESKTOP
:
399 return LAYER_DESKTOP
;
408 * \todo It might be worth stopping to restack everyone and only stack `c'
409 * relatively to the first matching in the list.
412 client_stack_refresh()
414 uint32_t config_win_vals
[2];
417 if (!globalconf
.client_need_stack_refresh
)
419 globalconf
.client_need_stack_refresh
= false;
421 config_win_vals
[0] = XCB_NONE
;
422 config_win_vals
[1] = XCB_STACK_MODE_ABOVE
;
424 /* stack desktop windows */
425 for(layer
= LAYER_DESKTOP
; layer
< LAYER_BELOW
; layer
++)
426 foreach(node
, globalconf
.stack
)
427 if(client_layer_translator(*node
) == layer
)
428 config_win_vals
[0] = client_stack_above(*node
,
431 /* first stack not ontop wibox window */
432 foreach(_sb
, globalconf
.wiboxes
)
437 xcb_configure_window(globalconf
.connection
,
439 XCB_CONFIG_WINDOW_SIBLING
| XCB_CONFIG_WINDOW_STACK_MODE
,
441 config_win_vals
[0] = sb
->sw
.window
;
445 /* then stack clients */
446 for(layer
= LAYER_BELOW
; layer
< LAYER_COUNT
; layer
++)
447 foreach(node
, globalconf
.stack
)
448 if(client_layer_translator(*node
) == layer
)
449 config_win_vals
[0] = client_stack_above(*node
,
452 /* then stack 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
->sw
.window
;
467 /** Manage a new client.
468 * \param w The window.
469 * \param wgeom Window geometry.
470 * \param phys_screen Physical screen number.
471 * \param startup True if we are managing at startup time.
474 client_manage(xcb_window_t w
, xcb_get_geometry_reply_t
*wgeom
, int phys_screen
, bool startup
)
476 xcb_get_property_cookie_t ewmh_icon_cookie
;
477 client_t
*c
, *tc
= NULL
;
479 const uint32_t select_input_val
[] = { CLIENT_SELECT_INPUT_EVENT_MASK
};
481 if(systray_iskdedockapp(w
))
483 systray_request_handle(w
, phys_screen
, NULL
);
487 /* Send request to get NET_WM_ICON property as soon as possible... */
488 ewmh_icon_cookie
= ewmh_window_icon_get_unchecked(w
);
489 xcb_change_window_attributes(globalconf
.connection
, w
, XCB_CW_EVENT_MASK
, select_input_val
);
491 c
= client_new(globalconf
.L
);
492 /* Push client in client list */
493 client_array_push(&globalconf
.clients
, client_ref(globalconf
.L
, -1));
496 screen
= c
->screen
= screen_getbycoord(&globalconf
.screens
.tab
[phys_screen
],
499 c
->phys_screen
= phys_screen
;
501 /* consider the window banned */
506 c
->geometry
.x
= wgeom
->x
;
507 c
->geometry
.y
= wgeom
->y
;
508 /* Border will be added later. */
509 c
->geometry
.width
= wgeom
->width
;
510 c
->geometry
.height
= wgeom
->height
;
511 /* Also set internal geometry (client_ban() needs it). */
512 c
->geometries
.internal
.x
= wgeom
->x
;
513 c
->geometries
.internal
.y
= wgeom
->y
;
514 c
->geometries
.internal
.width
= wgeom
->width
;
515 c
->geometries
.internal
.height
= wgeom
->height
;
516 client_setborder(c
, wgeom
->border_width
);
518 if(ewmh_window_icon_get_reply(ewmh_icon_cookie
))
519 c
->icon
= image_ref(globalconf
.L
, -1);
521 /* we honor size hints by default */
522 c
->size_hints_honor
= true;
525 property_update_wm_normal_hints(c
, NULL
);
526 property_update_wm_hints(c
, NULL
);
527 property_update_wm_transient_for(c
, NULL
);
528 property_update_wm_client_leader(c
, NULL
);
530 /* Recursively find the parent. */
531 for(tc
= c
; tc
->transient_for
; tc
= tc
->transient_for
);
532 if(tc
!= c
&& tc
->phys_screen
== c
->phys_screen
)
535 /* Then check clients hints */
536 ewmh_client_check_hints(c
);
538 /* move client to screen, but do not tag it */
539 screen_client_moveto(c
, screen
, false, true);
541 /* Push client in stack */
544 /* update window title */
545 property_update_wm_name(c
);
546 property_update_wm_icon_name(c
);
547 property_update_wm_class(c
, NULL
);
548 property_update_wm_protocols(c
);
550 xutil_text_prop_get(globalconf
.connection
, c
->win
, _NET_STARTUP_ID
, &c
->startup_id
, NULL
);
553 ewmh_process_client_strut(c
, NULL
);
555 ewmh_update_net_client_list(c
->phys_screen
);
557 /* Always stay in NORMAL_STATE. Even though iconified seems more
558 * appropriate sometimes. The only possible loss is that clients not using
559 * visibility events may continue to proces data (when banned).
560 * Without any exposes or other events the cost should be fairly limited though.
562 * Some clients may expect the window to be unmapped when STATE_ICONIFIED.
563 * Two conflicting parts of the ICCCM v2.0 (section 4.1.4):
565 * "Normal -> Iconic - The client should send a ClientMessage event as described later in this section."
566 * (note no explicit mention of unmapping, while Normal->Widthdrawn does mention that)
568 * "Once a client's window has left the Withdrawn state, the window will be mapped
569 * if it is in the Normal state and the window will be unmapped if it is in the Iconic state."
571 * At this stage it's just safer to keep it in normal state and avoid confusion.
573 window_state_set(c
->win
, XCB_WM_STATE_NORMAL
);
576 spawn_start_notify(c
);
578 /* Call hook to notify list change */
579 if(globalconf
.hooks
.clients
!= LUA_REFNIL
)
580 luaA_dofunction_from_registry(globalconf
.L
, globalconf
.hooks
.clients
, 0, 0);
583 if(globalconf
.hooks
.manage
!= LUA_REFNIL
)
585 client_push(globalconf
.L
, c
);
586 lua_pushboolean(globalconf
.L
, startup
);
587 luaA_dofunction_from_registry(globalconf
.L
, globalconf
.hooks
.manage
, 2, 0);
591 /** Compute client geometry with respect to its geometry hints.
592 * \param c The client.
593 * \param geometry The geometry that the client might receive.
594 * \return The geometry the client must take respecting its hints.
597 client_geometry_hints(client_t
*c
, area_t geometry
)
599 int32_t basew
, baseh
, minw
, minh
;
601 /* base size is substituted with min size if not specified */
602 if(c
->size_hints
.flags
& XCB_SIZE_HINT_P_SIZE
)
604 basew
= c
->size_hints
.base_width
;
605 baseh
= c
->size_hints
.base_height
;
607 else if(c
->size_hints
.flags
& XCB_SIZE_HINT_P_MIN_SIZE
)
609 basew
= c
->size_hints
.min_width
;
610 baseh
= c
->size_hints
.min_height
;
615 /* min size is substituted with base size if not specified */
616 if(c
->size_hints
.flags
& XCB_SIZE_HINT_P_MIN_SIZE
)
618 minw
= c
->size_hints
.min_width
;
619 minh
= c
->size_hints
.min_height
;
621 else if(c
->size_hints
.flags
& XCB_SIZE_HINT_P_SIZE
)
623 minw
= c
->size_hints
.base_width
;
624 minh
= c
->size_hints
.base_height
;
629 if(c
->size_hints
.flags
& XCB_SIZE_HINT_P_ASPECT
630 && c
->size_hints
.min_aspect_num
> 0
631 && c
->size_hints
.min_aspect_den
> 0
632 && geometry
.height
- baseh
> 0
633 && geometry
.width
- basew
> 0)
635 double dx
= (double) (geometry
.width
- basew
);
636 double dy
= (double) (geometry
.height
- baseh
);
637 double min
= (double) c
->size_hints
.min_aspect_num
/ (double) c
->size_hints
.min_aspect_den
;
638 double max
= (double) c
->size_hints
.max_aspect_num
/ (double) c
->size_hints
.min_aspect_den
;
639 double ratio
= dx
/ dy
;
640 if(max
> 0 && min
> 0 && ratio
> 0)
644 dy
= (dx
* min
+ dy
) / (min
* min
+ 1);
646 geometry
.width
= (int) dx
+ basew
;
647 geometry
.height
= (int) dy
+ baseh
;
651 dy
= (dx
* min
+ dy
) / (max
* max
+ 1);
653 geometry
.width
= (int) dx
+ basew
;
654 geometry
.height
= (int) dy
+ baseh
;
660 geometry
.width
= MAX(geometry
.width
, minw
);
662 geometry
.height
= MAX(geometry
.height
, minh
);
664 if(c
->size_hints
.flags
& XCB_SIZE_HINT_P_MAX_SIZE
)
666 if(c
->size_hints
.max_width
)
667 geometry
.width
= MIN(geometry
.width
, c
->size_hints
.max_width
);
668 if(c
->size_hints
.max_height
)
669 geometry
.height
= MIN(geometry
.height
, c
->size_hints
.max_height
);
672 if(c
->size_hints
.flags
& (XCB_SIZE_HINT_P_RESIZE_INC
| XCB_SIZE_HINT_BASE_SIZE
)
673 && c
->size_hints
.width_inc
&& c
->size_hints
.height_inc
)
675 uint16_t t1
= geometry
.width
, t2
= geometry
.height
;
676 unsigned_subtract(t1
, basew
);
677 unsigned_subtract(t2
, baseh
);
678 geometry
.width
-= t1
% c
->size_hints
.width_inc
;
679 geometry
.height
-= t2
% c
->size_hints
.height_inc
;
685 /** Resize client window.
686 * The sizse given as parameters are with titlebar and borders!
687 * \param c Client to resize.
688 * \param geometry New window geometry.
689 * \param hints Use size hints.
690 * \return true if an actual resize occurred.
693 client_resize(client_t
*c
, area_t geometry
, bool hints
)
695 area_t geometry_internal
;
698 /* offscreen appearance fixes */
699 area
= display_area_get(c
->phys_screen
);
701 if(geometry
.x
> area
.width
)
702 geometry
.x
= area
.width
- geometry
.width
;
703 if(geometry
.y
> area
.height
)
704 geometry
.y
= area
.height
- geometry
.height
;
705 if(geometry
.x
+ geometry
.width
< 0)
707 if(geometry
.y
+ geometry
.height
< 0)
710 /* Real client geometry, please keep it contained to C code at the very least. */
711 geometry_internal
= titlebar_geometry_remove(c
->titlebar
, c
->border
, geometry
);
714 geometry_internal
= client_geometry_hints(c
, geometry_internal
);
716 if(geometry_internal
.width
== 0 || geometry_internal
.height
== 0)
719 /* Also let client hints propegate to the "official" geometry. */
720 geometry
= titlebar_geometry_add(c
->titlebar
, c
->border
, geometry_internal
);
722 if(c
->geometries
.internal
.x
!= geometry_internal
.x
723 || c
->geometries
.internal
.y
!= geometry_internal
.y
724 || c
->geometries
.internal
.width
!= geometry_internal
.width
725 || c
->geometries
.internal
.height
!= geometry_internal
.height
)
727 screen_t
*new_screen
= screen_getbycoord(c
->screen
,
728 geometry_internal
.x
, geometry_internal
.y
);
730 /* Values to configure a window is an array where values are
731 * stored according to 'value_mask' */
734 c
->geometries
.internal
.x
= values
[0] = geometry_internal
.x
;
735 c
->geometries
.internal
.y
= values
[1] = geometry_internal
.y
;
736 c
->geometries
.internal
.width
= values
[2] = geometry_internal
.width
;
737 c
->geometries
.internal
.height
= values
[3] = geometry_internal
.height
;
739 /* Also store geometry including border and titlebar. */
740 c
->geometry
= geometry
;
742 titlebar_update_geometry(c
);
744 xcb_configure_window(globalconf
.connection
, c
->win
,
745 XCB_CONFIG_WINDOW_X
| XCB_CONFIG_WINDOW_Y
746 | XCB_CONFIG_WINDOW_WIDTH
| XCB_CONFIG_WINDOW_HEIGHT
,
749 screen_client_moveto(c
, new_screen
, true, false);
752 hook_property(client
, c
, "geometry");
760 /** Set a client minimized, or not.
761 * \param c The client.
762 * \param s Set or not the client minimized.
765 client_setminimized(client_t
*c
, bool s
)
767 if(c
->isminimized
!= s
)
769 client_need_reban(c
);
771 client_need_reban(c
);
773 window_state_set(c
->win
, XCB_WM_STATE_ICONIC
);
775 window_state_set(c
->win
, XCB_WM_STATE_NORMAL
);
776 ewmh_client_update_hints(c
);
778 hook_property(client
, c
, "minimized");
782 /** Set a client sticky, or not.
783 * \param c The client.
784 * \param s Set or not the client sticky.
787 client_setsticky(client_t
*c
, bool s
)
791 client_need_reban(c
);
793 client_need_reban(c
);
794 ewmh_client_update_hints(c
);
795 hook_property(client
, c
, "sticky");
799 /** Set a client fullscreen, or not.
800 * \param c The client.
801 * \param s Set or not the client fullscreen.
804 client_setfullscreen(client_t
*c
, bool s
)
806 if(c
->isfullscreen
!= s
)
810 /* Make sure the current geometry is stored without titlebar. */
812 titlebar_ban(c
->titlebar
);
814 /* become fullscreen! */
815 if((c
->isfullscreen
= s
))
817 /* remove any max state */
818 client_setmaxhoriz(c
, false);
819 client_setmaxvert(c
, false);
820 /* You can only be part of one of the special layers. */
821 client_setbelow(c
, false);
822 client_setabove(c
, false);
823 client_setontop(c
, false);
825 geometry
= screen_area_get(c
->screen
, false);
826 c
->geometries
.fullscreen
= c
->geometry
;
827 c
->border_fs
= c
->border
;
828 client_setborder(c
, 0);
832 geometry
= c
->geometries
.fullscreen
;
833 client_setborder(c
, c
->border_fs
);
835 client_resize(c
, geometry
, false);
837 ewmh_client_update_hints(c
);
838 hook_property(client
, c
, "fullscreen");
842 /** Set a client horizontally maximized.
843 * \param c The client.
844 * \param s The maximized status.
847 client_setmaxhoriz(client_t
*c
, bool s
)
849 if(c
->ismaxhoriz
!= s
)
853 if((c
->ismaxhoriz
= s
))
855 /* remove fullscreen mode */
856 client_setfullscreen(c
, false);
858 geometry
= screen_area_get(c
->screen
, true);
859 geometry
.y
= c
->geometry
.y
;
860 geometry
.height
= c
->geometry
.height
;
861 c
->geometries
.max
.x
= c
->geometry
.x
;
862 c
->geometries
.max
.width
= c
->geometry
.width
;
866 geometry
= c
->geometry
;
867 geometry
.x
= c
->geometries
.max
.x
;
868 geometry
.width
= c
->geometries
.max
.width
;
871 client_resize(c
, geometry
, c
->size_hints_honor
);
873 ewmh_client_update_hints(c
);
874 hook_property(client
, c
, "maximized_horizontal");
878 /** Set a client vertically maximized.
879 * \param c The client.
880 * \param s The maximized status.
883 client_setmaxvert(client_t
*c
, bool s
)
885 if(c
->ismaxvert
!= s
)
889 if((c
->ismaxvert
= s
))
891 /* remove fullscreen mode */
892 client_setfullscreen(c
, false);
894 geometry
= screen_area_get(c
->screen
, true);
895 geometry
.x
= c
->geometry
.x
;
896 geometry
.width
= c
->geometry
.width
;
897 c
->geometries
.max
.y
= c
->geometry
.y
;
898 c
->geometries
.max
.height
= c
->geometry
.height
;
902 geometry
= c
->geometry
;
903 geometry
.y
= c
->geometries
.max
.y
;
904 geometry
.height
= c
->geometries
.max
.height
;
907 client_resize(c
, geometry
, c
->size_hints_honor
);
909 ewmh_client_update_hints(c
);
910 hook_property(client
, c
, "maximized_vertical");
914 /** Set a client above, or not.
915 * \param c The client.
916 * \param s Set or not the client above.
919 client_setabove(client_t
*c
, bool s
)
923 /* You can only be part of one of the special layers. */
926 client_setbelow(c
, false);
927 client_setontop(c
, false);
928 client_setfullscreen(c
, false);
932 ewmh_client_update_hints(c
);
934 hook_property(client
, c
, "above");
938 /** Set a client below, or not.
939 * \param c The client.
940 * \param s Set or not the client below.
943 client_setbelow(client_t
*c
, bool s
)
947 /* You can only be part of one of the special layers. */
950 client_setabove(c
, false);
951 client_setontop(c
, false);
952 client_setfullscreen(c
, false);
956 ewmh_client_update_hints(c
);
958 hook_property(client
, c
, "below");
962 /** Set a client modal, or not.
963 * \param c The client.
964 * \param s Set or not the client moda.
967 client_setmodal(client_t
*c
, bool s
)
973 ewmh_client_update_hints(c
);
975 hook_property(client
, c
, "modal");
979 /** Set a client ontop, or not.
980 * \param c The client.
981 * \param s Set or not the client moda.
984 client_setontop(client_t
*c
, bool s
)
988 /* You can only be part of one of the special layers. */
991 client_setabove(c
, false);
992 client_setbelow(c
, false);
993 client_setfullscreen(c
, false);
998 hook_property(client
, c
, "ontop");
1002 /** Unban a client and move it back into the viewport.
1003 * \param c The client.
1006 client_unban(client_t
*c
)
1010 xcb_map_window(globalconf
.connection
, c
->win
);
1012 c
->isbanned
= false;
1016 /** Unmanage a client.
1017 * \param c The client.
1020 client_unmanage(client_t
*c
)
1022 tag_array_t
*tags
= &c
->screen
->tags
;
1024 /* Reset transient_for attributes of widows that maybe refering to us */
1025 foreach(_tc
, globalconf
.clients
)
1027 client_t
*tc
= *_tc
;
1028 if(tc
->transient_for
== c
)
1029 tc
->transient_for
= NULL
;
1032 if(globalconf
.screens
.tab
[c
->phys_screen
].prev_client_focus
== c
)
1033 globalconf
.screens
.tab
[c
->phys_screen
].prev_client_focus
= NULL
;
1035 if(globalconf
.screens
.tab
[c
->phys_screen
].client_focus
== c
)
1038 /* remove client from global list and everywhere else */
1039 foreach(elem
, globalconf
.clients
)
1042 client_array_remove(&globalconf
.clients
, elem
);
1045 stack_client_remove(c
);
1046 for(int i
= 0; i
< tags
->len
; i
++)
1047 untag_client(c
, tags
->tab
[i
]);
1050 if(globalconf
.hooks
.unmanage
!= LUA_REFNIL
)
1052 client_push(globalconf
.L
, c
);
1053 luaA_dofunction_from_registry(globalconf
.L
, globalconf
.hooks
.unmanage
, 1, 0);
1056 /* Call hook to notify list change */
1057 if(globalconf
.hooks
.clients
!= LUA_REFNIL
)
1058 luaA_dofunction_from_registry(globalconf
.L
, globalconf
.hooks
.clients
, 0, 0);
1060 /* The server grab construct avoids race conditions. */
1061 xcb_grab_server(globalconf
.connection
);
1063 xcb_ungrab_button(globalconf
.connection
, XCB_BUTTON_INDEX_ANY
, c
->win
,
1064 XCB_BUTTON_MASK_ANY
);
1065 window_state_set(c
->win
, XCB_WM_STATE_WITHDRAWN
);
1067 xcb_flush(globalconf
.connection
);
1068 xcb_ungrab_server(globalconf
.connection
);
1070 titlebar_client_detach(c
);
1072 ewmh_update_net_client_list(c
->phys_screen
);
1074 /* set client as invalid */
1077 client_unref(globalconf
.L
, c
);
1080 /** Kill a client via a WM_DELETE_WINDOW request or KillClient if not
1082 * \param c The client to kill.
1085 client_kill(client_t
*c
)
1087 if(client_hasproto(c
, WM_DELETE_WINDOW
))
1089 xcb_client_message_event_t ev
;
1091 /* Initialize all of event's fields first */
1094 ev
.response_type
= XCB_CLIENT_MESSAGE
;
1097 ev
.data
.data32
[1] = XCB_CURRENT_TIME
;
1098 ev
.type
= WM_PROTOCOLS
;
1099 ev
.data
.data32
[0] = WM_DELETE_WINDOW
;
1101 xcb_send_event(globalconf
.connection
, false, c
->win
,
1102 XCB_EVENT_MASK_NO_EVENT
, (char *) &ev
);
1105 xcb_kill_client(globalconf
.connection
, c
->win
);
1108 /** Get all clients into a table.
1109 * \param L The Lua VM state.
1110 * \return The number of elements pushed on stack.
1112 * \lparam An optional screen nunmber.
1113 * \lreturn A table with all clients.
1116 luaA_client_get(lua_State
*L
)
1120 screen
= luaL_optnumber(L
, 1, 0) - 1;
1125 foreach(c
, globalconf
.clients
)
1128 lua_rawseti(L
, -2, i
++);
1132 luaA_checkscreen(screen
);
1133 foreach(c
, globalconf
.clients
)
1134 if((*c
)->screen
== &globalconf
.screens
.tab
[screen
])
1137 lua_rawseti(L
, -2, i
++);
1144 /** Check if a client is visible on its screen.
1145 * \param L The Lua VM state.
1146 * \return The number of elements pushed on stack.
1149 * \lreturn A boolean value, true if the client is visible, false otherwise.
1152 luaA_client_isvisible(lua_State
*L
)
1154 client_t
*c
= luaA_client_checkudata(L
, 1);
1155 lua_pushboolean(L
, client_isvisible(c
, c
->screen
));
1159 /** Set client border width.
1160 * \param c The client.
1161 * \param width The border width.
1164 client_setborder(client_t
*c
, int width
)
1168 if(width
> 0 && (c
->type
== WINDOW_TYPE_DOCK
1169 || c
->type
== WINDOW_TYPE_SPLASH
1170 || c
->type
== WINDOW_TYPE_DESKTOP
1171 || c
->isfullscreen
))
1174 if(width
== c
->border
|| width
< 0)
1177 /* Update geometry with the new border. */
1178 c
->geometry
.width
-= 2 * c
->border
;
1179 c
->geometry
.height
-= 2 * c
->border
;
1182 xcb_configure_window(globalconf
.connection
, c
->win
,
1183 XCB_CONFIG_WINDOW_BORDER_WIDTH
, &w
);
1185 c
->geometry
.width
+= 2 * c
->border
;
1186 c
->geometry
.height
+= 2 * c
->border
;
1188 /* Changing border size also affects the size of the titlebar. */
1189 titlebar_update_geometry(c
);
1191 hook_property(client
, c
, "border_width");
1195 * \param L The Lua VM state.
1201 luaA_client_kill(lua_State
*L
)
1203 client_t
*c
= luaA_client_checkudata(L
, 1);
1208 /** Swap a client with another one.
1209 * \param L The Lua VM state.
1212 * \lparam A client to swap with.
1215 luaA_client_swap(lua_State
*L
)
1217 client_t
*c
= luaA_client_checkudata(L
, 1);
1218 client_t
*swap
= luaA_client_checkudata(L
, 2);
1222 client_t
**ref_c
= NULL
, **ref_swap
= NULL
;
1223 foreach(item
, globalconf
.clients
)
1227 else if(*item
== swap
)
1229 if(ref_c
&& ref_swap
)
1236 /* Call hook to notify list change */
1237 if(globalconf
.hooks
.clients
!= LUA_REFNIL
)
1238 luaA_dofunction_from_registry(L
, globalconf
.hooks
.clients
, 0, 0);
1244 /** Access or set the client tags.
1245 * \param L The Lua VM state.
1246 * \return The number of elements pushed on stack.
1247 * \lparam A table with tags to set, or none to get the current tags table.
1248 * \return The clients tag.
1251 luaA_client_tags(lua_State
*L
)
1253 client_t
*c
= luaA_client_checkudata(L
, 1);
1254 tag_array_t
*tags
= &c
->screen
->tags
;
1257 if(lua_gettop(L
) == 2)
1259 luaA_checktable(L
, 2);
1260 for(int i
= 0; i
< tags
->len
; i
++)
1261 untag_client(c
, tags
->tab
[i
]);
1263 while(lua_next(L
, 2))
1270 if(is_client_tagged(c
, *tag
))
1273 lua_rawseti(L
, -2, ++j
);
1279 /** Raise a client on top of others which are on the same layer.
1280 * \param L The Lua VM state.
1285 luaA_client_raise(lua_State
*L
)
1287 client_t
*c
= luaA_client_checkudata(L
, 1);
1292 /** Lower a client on bottom of others which are on the same layer.
1293 * \param L The Lua VM state.
1298 luaA_client_lower(lua_State
*L
)
1300 client_t
*c
= luaA_client_checkudata(L
, 1);
1305 /** Redraw a client by unmapping and mapping it quickly.
1306 * \param L The Lua VM state.
1312 luaA_client_redraw(lua_State
*L
)
1314 client_t
*c
= luaA_client_checkudata(L
, 1);
1316 xcb_unmap_window(globalconf
.connection
, c
->win
);
1317 xcb_map_window(globalconf
.connection
, c
->win
);
1319 /* Set the focus on the current window if the redraw has been
1320 performed on the window where the pointer is currently on
1321 because after the unmapping/mapping, the focus is lost */
1322 if(globalconf
.screen_focus
->client_focus
== c
)
1331 /** Stop managing a client.
1332 * \param L The Lua VM state.
1333 * \return The number of elements pushed on stack.
1338 luaA_client_unmanage(lua_State
*L
)
1340 client_t
*c
= luaA_client_checkudata(L
, 1);
1345 /** Return client geometry.
1346 * \param L The Lua VM state.
1347 * \return The number of elements pushed on stack.
1349 * \lparam A table with new coordinates, or none.
1350 * \lreturn A table with client coordinates.
1353 luaA_client_geometry(lua_State
*L
)
1355 client_t
*c
= luaA_client_checkudata(L
, 1);
1357 if(lua_gettop(L
) == 2)
1361 luaA_checktable(L
, 2);
1362 geometry
.x
= luaA_getopt_number(L
, 2, "x", c
->geometry
.x
);
1363 geometry
.y
= luaA_getopt_number(L
, 2, "y", c
->geometry
.y
);
1364 if(client_isfixed(c
))
1366 geometry
.width
= c
->geometry
.width
;
1367 geometry
.height
= c
->geometry
.height
;
1371 geometry
.width
= luaA_getopt_number(L
, 2, "width", c
->geometry
.width
);
1372 geometry
.height
= luaA_getopt_number(L
, 2, "height", c
->geometry
.height
);
1375 client_resize(c
, geometry
, c
->size_hints_honor
);
1378 return luaA_pusharea(L
, c
->geometry
);
1381 /** Push a strut type to a table on stack.
1382 * \param L The Lua VM state.
1383 * \param struts The struts to push.
1384 * \return The number of elements pushed on stack.
1387 luaA_pushstruts(lua_State
*L
, strut_t struts
)
1389 lua_createtable(L
, 4, 0);
1390 lua_pushnumber(L
, struts
.left
);
1391 lua_setfield(L
, -2, "left");
1392 lua_pushnumber(L
, struts
.right
);
1393 lua_setfield(L
, -2, "right");
1394 lua_pushnumber(L
, struts
.top
);
1395 lua_setfield(L
, -2, "top");
1396 lua_pushnumber(L
, struts
.bottom
);
1397 lua_setfield(L
, -2, "bottom");
1401 /** Return client struts (reserved space at the edge of the screen).
1402 * \param L The Lua VM state.
1403 * \return The number of elements pushed on stack.
1405 * \lparam A table with new strut values, or none.
1406 * \lreturn A table with strut values.
1409 luaA_client_struts(lua_State
*L
)
1411 client_t
*c
= luaA_client_checkudata(L
, 1);
1413 if(lua_gettop(L
) == 2)
1416 area_t screen_area
= display_area_get(c
->phys_screen
);
1418 struts
.left
= luaA_getopt_number(L
, 2, "left", c
->strut
.left
);
1419 struts
.right
= luaA_getopt_number(L
, 2, "right", c
->strut
.right
);
1420 struts
.top
= luaA_getopt_number(L
, 2, "top", c
->strut
.top
);
1421 struts
.bottom
= luaA_getopt_number(L
, 2, "bottom", c
->strut
.bottom
);
1423 if(struts
.left
!= c
->strut
.left
|| struts
.right
!= c
->strut
.right
||
1424 struts
.top
!= c
->strut
.top
|| struts
.bottom
!= c
->strut
.bottom
) {
1425 /* Struts are not so well defined in the context of xinerama. So we just
1426 * give the entire root window and let the window manager decide. */
1427 struts
.left_start_y
= 0;
1428 struts
.left_end_y
= !struts
.left
? 0 : screen_area
.height
;
1429 struts
.right_start_y
= 0;
1430 struts
.right_end_y
= !struts
.right
? 0 : screen_area
.height
;
1431 struts
.top_start_x
= 0;
1432 struts
.top_end_x
= !struts
.top
? 0 : screen_area
.width
;
1433 struts
.bottom_start_x
= 0;
1434 struts
.bottom_end_x
= !struts
.bottom
? 0 : screen_area
.width
;
1438 ewmh_update_client_strut(c
);
1440 hook_property(client
, c
, "struts");
1444 return luaA_pushstruts(L
, c
->strut
);
1447 /** Client newindex.
1448 * \param L The Lua VM state.
1449 * \return The number of elements pushed on stack.
1452 luaA_client_newindex(lua_State
*L
)
1455 client_t
*c
= luaA_client_checkudata(L
, 1);
1456 const char *buf
= luaL_checklstring(L
, 2, &len
);
1461 switch(a_tokenize(buf
, len
))
1464 if(globalconf
.xinerama_is_active
)
1466 i
= luaL_checknumber(L
, 3) - 1;
1467 luaA_checkscreen(i
);
1468 screen_client_moveto(c
, &globalconf
.screens
.tab
[i
], true, true);
1472 b
= luaA_checkboolean(L
, 3);
1473 if(b
!= c
->ishidden
)
1475 client_need_reban(c
);
1477 client_need_reban(c
);
1478 hook_property(client
, c
, "hide");
1481 case A_TK_MINIMIZED
:
1482 client_setminimized(c
, luaA_checkboolean(L
, 3));
1484 case A_TK_FULLSCREEN
:
1485 client_setfullscreen(c
, luaA_checkboolean(L
, 3));
1487 case A_TK_MAXIMIZED_HORIZONTAL
:
1488 client_setmaxhoriz(c
, luaA_checkboolean(L
, 3));
1490 case A_TK_MAXIMIZED_VERTICAL
:
1491 client_setmaxvert(c
, luaA_checkboolean(L
, 3));
1494 image_unref(L
, c
->icon
);
1496 c
->icon
= image_ref(L
, 3);
1498 hook_property(client
, c
, "icon");
1502 window_opacity_set(c
->win
, -1);
1505 d
= luaL_checknumber(L
, 3);
1506 if(d
>= 0 && d
<= 1)
1507 window_opacity_set(c
->win
, d
);
1511 client_setsticky(c
, luaA_checkboolean(L
, 3));
1513 case A_TK_SIZE_HINTS_HONOR
:
1514 c
->size_hints_honor
= luaA_checkboolean(L
, 3);
1515 hook_property(client
, c
, "size_hints_honor");
1517 case A_TK_BORDER_WIDTH
:
1518 client_setborder(c
, luaL_checknumber(L
, 3));
1521 client_setontop(c
, luaA_checkboolean(L
, 3));
1524 client_setabove(c
, luaA_checkboolean(L
, 3));
1527 client_setbelow(c
, luaA_checkboolean(L
, 3));
1530 client_seturgent(c
, luaA_checkboolean(L
, 3));
1532 case A_TK_BORDER_COLOR
:
1533 if((buf
= luaL_checklstring(L
, 3, &len
))
1534 && xcolor_init_reply(xcolor_init_unchecked(&c
->border_color
, buf
, len
)))
1535 xcb_change_window_attributes(globalconf
.connection
, c
->win
,
1536 XCB_CW_BORDER_PIXEL
, &c
->border_color
.pixel
);
1540 titlebar_client_detach(c
);
1542 titlebar_client_attach(c
);
1544 case A_TK_SKIP_TASKBAR
:
1545 c
->skiptb
= luaA_checkboolean(L
, 3);
1546 hook_property(client
, c
, "skip_taskbar");
1556 * \param L The Lua VM state.
1557 * \return The number of elements pushed on stack.
1559 * \lfield id The window X id.
1560 * \lfield name The client title.
1561 * \lfield skip_taskbar If true the client won't be shown in the tasklist.
1562 * \lfield type The window type (desktop, normal, dock, …).
1563 * \lfield class The client class.
1564 * \lfield instance The client instance.
1565 * \lfield pid The client PID, if available.
1566 * \lfield role The window role, if available.
1567 * \lfield machine The machine client is running on.
1568 * \lfield icon_name The client name when iconified.
1569 * \lfield screen Client screen number.
1570 * \lfield hide Define if the client must be hidden, i.e. never mapped,
1571 * invisible in taskbar.
1572 * \lfield minimized Define it the client must be iconify, i.e. only visible in
1574 * \lfield size_hints_honor Honor size hints, i.e. respect size ratio.
1575 * \lfield border_width The client border width.
1576 * \lfield border_color The client border color.
1577 * \lfield titlebar The client titlebar.
1578 * \lfield urgent The client urgent state.
1579 * \lfield content An image representing the client window content (screenshot).
1580 * \lfield focus The focused client.
1581 * \lfield opacity The client opacity between 0 and 1.
1582 * \lfield ontop The client is on top of every other windows.
1583 * \lfield above The client is above normal windows.
1584 * \lfield below The client is below normal windows.
1585 * \lfield fullscreen The client is fullscreen or not.
1586 * \lfield maximized_horizontal The client is maximized horizontally or not.
1587 * \lfield maximized_vertical The client is maximized vertically or not.
1588 * \lfield transient_for Return the client the window is transient for.
1589 * \lfield group_id Identification unique to a group of windows.
1590 * \lfield leader_id Identification unique to windows spawned by the same command.
1591 * \lfield size_hints A table with size hints of the client: user_position,
1592 * user_size, program_position, program_size, etc.
1595 luaA_client_index(lua_State
*L
)
1599 client_t
*c
= luaA_client_checkudata(L
, 1);
1600 const char *buf
= luaL_checklstring(L
, 2, &len
);
1603 xcb_get_property_cookie_t prop_c
;
1604 xcb_get_property_reply_t
*prop_r
= NULL
;
1607 if(luaA_usemetatable(L
, 1, 2))
1610 switch(a_tokenize(buf
, len
))
1613 lua_pushstring(L
, c
->name
);
1615 case A_TK_TRANSIENT_FOR
:
1616 return client_push(globalconf
.L
, c
->transient_for
);
1617 case A_TK_SKIP_TASKBAR
:
1618 lua_pushboolean(L
, c
->skiptb
);
1621 return client_getcontent(c
);
1625 case WINDOW_TYPE_DESKTOP
:
1626 lua_pushliteral(L
, "desktop");
1628 case WINDOW_TYPE_DOCK
:
1629 lua_pushliteral(L
, "dock");
1631 case WINDOW_TYPE_SPLASH
:
1632 lua_pushliteral(L
, "splash");
1634 case WINDOW_TYPE_DIALOG
:
1635 lua_pushliteral(L
, "dialog");
1637 case WINDOW_TYPE_MENU
:
1638 lua_pushliteral(L
, "menu");
1640 case WINDOW_TYPE_TOOLBAR
:
1641 lua_pushliteral(L
, "toolbar");
1643 case WINDOW_TYPE_UTILITY
:
1644 lua_pushliteral(L
, "utility");
1646 case WINDOW_TYPE_DROPDOWN_MENU
:
1647 lua_pushliteral(L
, "dropdown_menu");
1649 case WINDOW_TYPE_POPUP_MENU
:
1650 lua_pushliteral(L
, "popup_menu");
1652 case WINDOW_TYPE_TOOLTIP
:
1653 lua_pushliteral(L
, "tooltip");
1655 case WINDOW_TYPE_NOTIFICATION
:
1656 lua_pushliteral(L
, "notification");
1658 case WINDOW_TYPE_COMBO
:
1659 lua_pushliteral(L
, "combo");
1661 case WINDOW_TYPE_DND
:
1662 lua_pushliteral(L
, "dnd");
1664 case WINDOW_TYPE_NORMAL
:
1665 lua_pushliteral(L
, "normal");
1670 lua_pushstring(L
, c
->class);
1673 lua_pushstring(L
, c
->instance
);
1676 if(!xutil_text_prop_get(globalconf
.connection
, c
->win
,
1677 WM_WINDOW_ROLE
, &value
, &slen
))
1679 lua_pushlstring(L
, value
, slen
);
1683 prop_c
= xcb_get_property_unchecked(globalconf
.connection
, false, c
->win
, _NET_WM_PID
, CARDINAL
, 0L, 1L);
1684 prop_r
= xcb_get_property_reply(globalconf
.connection
, prop_c
, NULL
);
1686 if(prop_r
&& prop_r
->value_len
&& (data
= xcb_get_property_value(prop_r
)))
1687 lua_pushnumber(L
, *(uint32_t *)data
);
1695 lua_pushnumber(L
, c
->win
);
1697 case A_TK_LEADER_ID
:
1698 lua_pushnumber(L
, c
->leader_win
);
1701 if(!xutil_text_prop_get(globalconf
.connection
, c
->win
,
1702 WM_CLIENT_MACHINE
, &value
, &slen
))
1704 lua_pushlstring(L
, value
, slen
);
1707 case A_TK_ICON_NAME
:
1708 lua_pushstring(L
, c
->icon_name
);
1711 lua_pushnumber(L
, 1 + screen_array_indexof(&globalconf
.screens
, c
->screen
));
1714 lua_pushboolean(L
, c
->ishidden
);
1716 case A_TK_MINIMIZED
:
1717 lua_pushboolean(L
, c
->isminimized
);
1719 case A_TK_FULLSCREEN
:
1720 lua_pushboolean(L
, c
->isfullscreen
);
1724 lua_pushnumber(L
, c
->group_win
);
1728 case A_TK_MAXIMIZED_HORIZONTAL
:
1729 lua_pushboolean(L
, c
->ismaxhoriz
);
1731 case A_TK_MAXIMIZED_VERTICAL
:
1732 lua_pushboolean(L
, c
->ismaxvert
);
1735 image_push(L
, c
->icon
);
1738 if((d
= window_opacity_get(c
->win
)) >= 0)
1739 lua_pushnumber(L
, d
);
1744 lua_pushboolean(L
, c
->isontop
);
1747 lua_pushboolean(L
, c
->isabove
);
1750 lua_pushboolean(L
, c
->isbelow
);
1753 lua_pushboolean(L
, c
->issticky
);
1755 case A_TK_SIZE_HINTS_HONOR
:
1756 lua_pushboolean(L
, c
->size_hints_honor
);
1758 case A_TK_BORDER_WIDTH
:
1759 lua_pushnumber(L
, c
->border
);
1761 case A_TK_BORDER_COLOR
:
1762 luaA_pushxcolor(L
, &c
->border_color
);
1765 return wibox_push(L
, c
->titlebar
);
1767 lua_pushboolean(L
, c
->isurgent
);
1769 case A_TK_SIZE_HINTS
:
1771 const char *u_or_p
= NULL
;
1773 lua_createtable(L
, 0, 1);
1775 if(c
->size_hints
.flags
& XCB_SIZE_HINT_US_POSITION
)
1776 u_or_p
= "user_position";
1777 else if(c
->size_hints
.flags
& XCB_SIZE_HINT_P_POSITION
)
1778 u_or_p
= "program_position";
1782 lua_createtable(L
, 0, 2);
1783 lua_pushnumber(L
, c
->size_hints
.x
);
1784 lua_setfield(L
, -2, "x");
1785 lua_pushnumber(L
, c
->size_hints
.y
);
1786 lua_setfield(L
, -2, "y");
1787 lua_setfield(L
, -2, u_or_p
);
1791 if(c
->size_hints
.flags
& XCB_SIZE_HINT_US_SIZE
)
1792 u_or_p
= "user_size";
1793 else if(c
->size_hints
.flags
& XCB_SIZE_HINT_P_SIZE
)
1794 u_or_p
= "program_size";
1798 lua_createtable(L
, 0, 2);
1799 lua_pushnumber(L
, c
->size_hints
.width
);
1800 lua_setfield(L
, -2, "width");
1801 lua_pushnumber(L
, c
->size_hints
.height
);
1802 lua_setfield(L
, -2, "height");
1803 lua_setfield(L
, -2, u_or_p
);
1806 if(c
->size_hints
.flags
& XCB_SIZE_HINT_P_MIN_SIZE
)
1808 lua_pushnumber(L
, c
->size_hints
.min_width
);
1809 lua_setfield(L
, -2, "min_width");
1810 lua_pushnumber(L
, c
->size_hints
.min_height
);
1811 lua_setfield(L
, -2, "min_height");
1814 if(c
->size_hints
.flags
& XCB_SIZE_HINT_P_MAX_SIZE
)
1816 lua_pushnumber(L
, c
->size_hints
.max_width
);
1817 lua_setfield(L
, -2, "max_width");
1818 lua_pushnumber(L
, c
->size_hints
.max_height
);
1819 lua_setfield(L
, -2, "max_height");
1822 if(c
->size_hints
.flags
& XCB_SIZE_HINT_P_RESIZE_INC
)
1824 lua_pushnumber(L
, c
->size_hints
.width_inc
);
1825 lua_setfield(L
, -2, "width_inc");
1826 lua_pushnumber(L
, c
->size_hints
.height_inc
);
1827 lua_setfield(L
, -2, "height_inc");
1830 if(c
->size_hints
.flags
& XCB_SIZE_HINT_P_ASPECT
)
1832 lua_pushnumber(L
, c
->size_hints
.min_aspect_num
);
1833 lua_setfield(L
, -2, "min_aspect_num");
1834 lua_pushnumber(L
, c
->size_hints
.min_aspect_den
);
1835 lua_setfield(L
, -2, "min_aspect_den");
1836 lua_pushnumber(L
, c
->size_hints
.max_aspect_num
);
1837 lua_setfield(L
, -2, "max_aspect_num");
1838 lua_pushnumber(L
, c
->size_hints
.max_aspect_den
);
1839 lua_setfield(L
, -2, "max_aspect_den");
1842 if(c
->size_hints
.flags
& XCB_SIZE_HINT_BASE_SIZE
)
1844 lua_pushnumber(L
, c
->size_hints
.base_width
);
1845 lua_setfield(L
, -2, "base_width");
1846 lua_pushnumber(L
, c
->size_hints
.base_height
);
1847 lua_setfield(L
, -2, "base_height");
1850 if(c
->size_hints
.flags
& XCB_SIZE_HINT_P_WIN_GRAVITY
)
1852 switch(c
->size_hints
.win_gravity
)
1855 lua_pushliteral(L
, "north_west");
1857 case XCB_GRAVITY_NORTH
:
1858 lua_pushliteral(L
, "north");
1860 case XCB_GRAVITY_NORTH_EAST
:
1861 lua_pushliteral(L
, "north_east");
1863 case XCB_GRAVITY_WEST
:
1864 lua_pushliteral(L
, "west");
1866 case XCB_GRAVITY_CENTER
:
1867 lua_pushliteral(L
, "center");
1869 case XCB_GRAVITY_EAST
:
1870 lua_pushliteral(L
, "east");
1872 case XCB_GRAVITY_SOUTH_WEST
:
1873 lua_pushliteral(L
, "south_west");
1875 case XCB_GRAVITY_SOUTH
:
1876 lua_pushliteral(L
, "south");
1878 case XCB_GRAVITY_SOUTH_EAST
:
1879 lua_pushliteral(L
, "south_east");
1881 case XCB_GRAVITY_STATIC
:
1882 lua_pushliteral(L
, "static");
1885 lua_setfield(L
, -2, "win_gravity");
1896 /** Get or set mouse buttons bindings for a client.
1897 * \param L The Lua VM state.
1898 * \return The number of element pushed on stack.
1901 * \lparam An array of mouse button bindings objects, or nothing.
1902 * \return The array of mouse button bindings objects of this client.
1905 luaA_client_buttons(lua_State
*L
)
1907 client_t
*client
= luaA_client_checkudata(L
, 1);
1908 button_array_t
*buttons
= &client
->buttons
;
1910 if(lua_gettop(L
) == 2)
1911 luaA_button_array_set(L
, 2, buttons
);
1913 window_buttons_grab(client
->win
, &client
->buttons
);
1915 return luaA_button_array_get(L
, buttons
);
1918 /** Get or set keys bindings for a client.
1919 * \param L The Lua VM state.
1920 * \return The number of element pushed on stack.
1923 * \lparam An array of key bindings objects, or nothing.
1924 * \return The array of key bindings objects of this client.
1927 luaA_client_keys(lua_State
*L
)
1929 client_t
*c
= luaA_client_checkudata(L
, 1);
1930 key_array_t
*keys
= &c
->keys
;
1932 if(lua_gettop(L
) == 2)
1934 luaA_key_array_set(L
, 2, keys
);
1935 xcb_ungrab_key(globalconf
.connection
, XCB_GRAB_ANY
, c
->win
, XCB_BUTTON_MASK_ANY
);
1936 window_grabkeys(c
->win
, keys
);
1939 return luaA_key_array_get(L
, keys
);
1943 * \param L The Lua VM state.
1944 * \return The number of pushed elements.
1947 luaA_client_module_index(lua_State
*L
)
1950 const char *buf
= luaL_checklstring(L
, 2, &len
);
1952 switch(a_tokenize(buf
, len
))
1955 return client_push(globalconf
.L
, globalconf
.screen_focus
->client_focus
);
1962 /* Client module new index.
1963 * \param L The Lua VM state.
1964 * \return The number of pushed elements.
1967 luaA_client_module_newindex(lua_State
*L
)
1970 const char *buf
= luaL_checklstring(L
, 2, &len
);
1973 switch(a_tokenize(buf
, len
))
1976 c
= luaA_client_checkudata(L
, 3);
1986 const struct luaL_reg awesome_client_methods
[] =
1988 { "get", luaA_client_get
},
1989 { "__index", luaA_client_module_index
},
1990 { "__newindex", luaA_client_module_newindex
},
1993 const struct luaL_reg awesome_client_meta
[] =
1995 { "isvisible", luaA_client_isvisible
},
1996 { "geometry", luaA_client_geometry
},
1997 { "struts", luaA_client_struts
},
1998 { "buttons", luaA_client_buttons
},
1999 { "keys", luaA_client_keys
},
2000 { "tags", luaA_client_tags
},
2001 { "kill", luaA_client_kill
},
2002 { "swap", luaA_client_swap
},
2003 { "raise", luaA_client_raise
},
2004 { "lower", luaA_client_lower
},
2005 { "redraw", luaA_client_redraw
},
2006 { "unmanage", luaA_client_unmanage
},
2007 { "__index", luaA_client_index
},
2008 { "__newindex", luaA_client_newindex
},
2009 { "__gc", luaA_client_gc
},
2010 { "__tostring", luaA_client_tostring
},
2014 // vim: filetype=c:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=80