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 xcb_get_wm_protocols_reply_wipe(&c
->protocols
);
54 p_delete(&c
->startup_id
);
55 p_delete(&c
->instance
);
56 p_delete(&c
->icon_name
);
58 return luaA_object_gc(L
);
61 /** Change the clients urgency flag.
63 * \param urgent The new flag state
66 client_seturgent(client_t
*c
, bool urgent
)
68 if(c
->isurgent
!= urgent
)
70 xcb_get_property_cookie_t hints
=
71 xcb_get_wm_hints_unchecked(globalconf
.connection
, c
->win
);
74 ewmh_client_update_hints(c
);
76 /* update ICCCM hints */
78 xcb_get_wm_hints_reply(globalconf
.connection
, hints
, &wmh
, NULL
);
81 wmh
.flags
|= XCB_WM_HINT_X_URGENCY
;
83 wmh
.flags
&= ~XCB_WM_HINT_X_URGENCY
;
85 xcb_set_wm_hints(globalconf
.connection
, c
->win
, &wmh
);
87 hook_property(client
, c
, "urgent");
91 /** Returns true if a client is tagged
92 * with one of the tags of the specified screen.
93 * \param c The client to check.
94 * \param screen Virtual screen.
95 * \return true if the client is visible, false otherwise.
98 client_maybevisible(client_t
*c
, screen_t
*screen
)
100 if(c
->screen
== screen
)
102 if(c
->issticky
|| c
->type
== WINDOW_TYPE_DESKTOP
)
105 foreach(tag
, screen
->tags
)
106 if((*tag
)->selected
&& is_client_tagged(c
, *tag
))
112 /** Return the content of a client as an image.
113 * That's just take a screenshot.
114 * \param c The client.
115 * \return 1 if the image has been pushed on stack, false otherwise.
118 client_getcontent(client_t
*c
)
120 xcb_image_t
*ximage
= xcb_image_get(globalconf
.connection
,
123 c
->geometries
.internal
.width
,
124 c
->geometries
.internal
.height
,
125 ~0, XCB_IMAGE_FORMAT_Z_PIXMAP
);
130 if(ximage
->bpp
>= 24)
132 uint32_t *data
= p_alloca(uint32_t, ximage
->width
* ximage
->height
);
134 for(int y
= 0; y
< ximage
->height
; y
++)
135 for(int x
= 0; x
< ximage
->width
; x
++)
137 data
[y
* ximage
->width
+ x
] = xcb_image_get_pixel(ximage
, x
, y
);
138 data
[y
* ximage
->width
+ x
] |= 0xff000000; /* set alpha to 0xff */
141 retval
= image_new_from_argb32(ximage
->width
, ximage
->height
, data
);
143 xcb_image_destroy(ximage
);
149 /** Get a client by its window.
150 * \param w The client window to find.
151 * \return A client pointer if found, NULL otherwise.
154 client_getbywin(xcb_window_t w
)
156 foreach(c
, globalconf
.clients
)
163 /** Record that a client lost focus.
164 * \param c Client being unfocused
167 client_unfocus_update(client_t
*c
)
169 globalconf
.screens
.tab
[c
->phys_screen
].client_focus
= NULL
;
170 ewmh_update_net_active_window(c
->phys_screen
);
173 if(globalconf
.hooks
.unfocus
!= LUA_REFNIL
)
175 client_push(globalconf
.L
, c
);
176 luaA_dofunction_from_registry(globalconf
.L
, globalconf
.hooks
.unfocus
, 1, 0);
181 /** Unfocus a client.
182 * \param c The client.
185 client_unfocus(client_t
*c
)
188 xcb_window_t root_win
= xutil_screen_get(globalconf
.connection
, c
->phys_screen
)->root
;
189 /* Set focus on root window, so no events leak to the current window.
190 * This kind of inlines client_setfocus(), but a root window will never have
191 * the WM_TAKE_FOCUS protocol.
193 xcb_set_input_focus(globalconf
.connection
, XCB_INPUT_FOCUS_PARENT
,
194 root_win
, XCB_CURRENT_TIME
);
196 client_unfocus_update(c
);
199 /** Check if client supports protocol a protocole in WM_PROTOCOL.
200 * \param c The client.
201 * \param atom The protocol atom to check for.
202 * \return True if client has the atom in protocol, false otherwise.
205 client_hasproto(client_t
*c
, xcb_atom_t atom
)
209 for(i
= 0; i
< c
->protocols
.atoms_len
; i
++)
210 if(c
->protocols
.atoms
[i
] == atom
)
215 /** Sets focus on window - using xcb_set_input_focus or WM_TAKE_FOCUS
216 * \param c Client that should get focus
217 * \param set_input_focus Should we call xcb_set_input_focus
220 client_setfocus(client_t
*c
, bool set_input_focus
)
222 bool takefocus
= client_hasproto(c
, WM_TAKE_FOCUS
);
224 xcb_set_input_focus(globalconf
.connection
, XCB_INPUT_FOCUS_PARENT
,
225 c
->win
, XCB_CURRENT_TIME
);
227 window_takefocus(c
->win
);
230 /** Ban client and move it out of the viewport.
231 * \param c The client.
234 client_ban(client_t
*c
)
238 xcb_unmap_window(globalconf
.connection
, c
->win
);
242 if(globalconf
.screens
.tab
[c
->phys_screen
].prev_client_focus
== c
)
243 globalconf
.screens
.tab
[c
->phys_screen
].prev_client_focus
= NULL
;
245 /* Wait until the last moment to take away the focus from the window. */
246 if(globalconf
.screens
.tab
[c
->phys_screen
].client_focus
== c
)
251 /** This is part of The Bob Marley Algorithmm: we ignore enter and leave window
252 * in certain cases, like map/unmap or move, so we don't get spurious events.
255 client_ignore_enterleave_events(void)
257 foreach(c
, globalconf
.clients
)
258 xcb_change_window_attributes(globalconf
.connection
,
261 (const uint32_t []) { CLIENT_SELECT_INPUT_EVENT_MASK
& ~(XCB_EVENT_MASK_ENTER_WINDOW
| XCB_EVENT_MASK_LEAVE_WINDOW
) });
265 client_restore_enterleave_events(void)
267 foreach(c
, globalconf
.clients
)
268 xcb_change_window_attributes(globalconf
.connection
,
271 (const uint32_t []) { CLIENT_SELECT_INPUT_EVENT_MASK
});
274 /** Record that a client got focus.
275 * \param c Client being focused.
278 client_focus_update(client_t
*c
)
280 if(!client_maybevisible(c
, c
->screen
))
282 /* Focus previously focused client */
283 client_focus(globalconf
.screen_focus
->prev_client_focus
);
287 if(globalconf
.screen_focus
288 && globalconf
.screen_focus
->client_focus
)
290 if (globalconf
.screen_focus
->client_focus
!= c
)
291 client_unfocus_update(globalconf
.screen_focus
->client_focus
);
293 /* Already focused */
296 /* stop hiding client */
298 client_setminimized(c
, false);
300 /* unban the client before focusing for consistency */
303 globalconf
.screen_focus
= &globalconf
.screens
.tab
[c
->phys_screen
];
304 globalconf
.screen_focus
->prev_client_focus
= c
;
305 globalconf
.screen_focus
->client_focus
= c
;
307 /* according to EWMH, we have to remove the urgent state from a client */
308 client_seturgent(c
, false);
310 ewmh_update_net_active_window(c
->phys_screen
);
313 if(globalconf
.hooks
.focus
!= LUA_REFNIL
)
315 client_push(globalconf
.L
, c
);
316 luaA_dofunction_from_registry(globalconf
.L
, globalconf
.hooks
.focus
, 1, 0);
321 /** Give focus to client, or to first client if client is NULL.
322 * \param c The client or NULL.
325 client_focus(client_t
*c
)
327 /* We have to set focus on first client */
328 if(!c
&& globalconf
.clients
.len
&& !(c
= globalconf
.clients
.tab
[0]))
331 if(!client_maybevisible(c
, c
->screen
))
335 client_focus_update(c
);
337 client_setfocus(c
, !c
->nofocus
);
340 /** Stack a window below.
341 * \param c The client.
342 * \param previous The previous window on the stack.
343 * \return The next-previous!
346 client_stack_above(client_t
*c
, xcb_window_t previous
)
348 uint32_t config_win_vals
[2];
350 config_win_vals
[0] = previous
;
351 config_win_vals
[1] = XCB_STACK_MODE_ABOVE
;
353 xcb_configure_window(globalconf
.connection
, c
->win
,
354 XCB_CONFIG_WINDOW_SIBLING
| XCB_CONFIG_WINDOW_STACK_MODE
,
357 config_win_vals
[0] = c
->win
;
361 xcb_configure_window(globalconf
.connection
,
363 XCB_CONFIG_WINDOW_SIBLING
| XCB_CONFIG_WINDOW_STACK_MODE
,
365 previous
= c
->titlebar
->window
;
370 /* stack transient window on top of their parents */
371 foreach(node
, globalconf
.stack
)
372 if((*node
)->transient_for
== c
)
373 previous
= client_stack_above(*node
, previous
);
378 /** Stacking layout layers */
381 /** This one is a special layer */
389 /** This one only used for counting and is not a real layer */
393 /** Get the real layer of a client according to its attribute (fullscreen, …)
394 * \param c The client.
395 * \return The real layer.
398 client_layer_translator(client_t
*c
)
400 /* first deal with user set attributes */
403 else if(c
->isfullscreen
)
404 return LAYER_FULLSCREEN
;
410 /* check for transient attr */
414 /* then deal with windows type */
417 case WINDOW_TYPE_DESKTOP
:
418 return LAYER_DESKTOP
;
427 * \todo It might be worth stopping to restack everyone and only stack `c'
428 * relatively to the first matching in the list.
431 client_stack_refresh()
433 uint32_t config_win_vals
[2];
436 if (!globalconf
.client_need_stack_refresh
)
438 globalconf
.client_need_stack_refresh
= false;
440 config_win_vals
[0] = XCB_NONE
;
441 config_win_vals
[1] = XCB_STACK_MODE_ABOVE
;
443 /* stack desktop windows */
444 for(layer
= LAYER_DESKTOP
; layer
< LAYER_BELOW
; layer
++)
445 foreach(node
, globalconf
.stack
)
446 if(client_layer_translator(*node
) == layer
)
447 config_win_vals
[0] = client_stack_above(*node
,
450 /* first stack not ontop wibox window */
451 foreach(_sb
, globalconf
.wiboxes
)
456 xcb_configure_window(globalconf
.connection
,
458 XCB_CONFIG_WINDOW_SIBLING
| XCB_CONFIG_WINDOW_STACK_MODE
,
460 config_win_vals
[0] = sb
->window
;
464 /* then stack clients */
465 for(layer
= LAYER_BELOW
; layer
< LAYER_COUNT
; layer
++)
466 foreach(node
, globalconf
.stack
)
467 if(client_layer_translator(*node
) == layer
)
468 config_win_vals
[0] = client_stack_above(*node
,
471 /* then stack ontop wibox window */
472 foreach(_sb
, globalconf
.wiboxes
)
477 xcb_configure_window(globalconf
.connection
,
479 XCB_CONFIG_WINDOW_SIBLING
| XCB_CONFIG_WINDOW_STACK_MODE
,
481 config_win_vals
[0] = sb
->window
;
486 /** Manage a new client.
487 * \param w The window.
488 * \param wgeom Window geometry.
489 * \param phys_screen Physical screen number.
490 * \param startup True if we are managing at startup time.
493 client_manage(xcb_window_t w
, xcb_get_geometry_reply_t
*wgeom
, int phys_screen
, bool startup
)
495 xcb_get_property_cookie_t ewmh_icon_cookie
;
496 client_t
*c
, *tc
= NULL
;
498 const uint32_t select_input_val
[] = { CLIENT_SELECT_INPUT_EVENT_MASK
};
500 if(systray_iskdedockapp(w
))
502 systray_request_handle(w
, phys_screen
, NULL
);
506 /* Send request to get NET_WM_ICON property as soon as possible... */
507 ewmh_icon_cookie
= ewmh_window_icon_get_unchecked(w
);
508 xcb_change_window_attributes(globalconf
.connection
, w
, XCB_CW_EVENT_MASK
, select_input_val
);
510 c
= client_new(globalconf
.L
);
511 /* Push client in client list */
512 client_array_push(&globalconf
.clients
, client_ref(globalconf
.L
, -1));
515 screen
= c
->screen
= screen_getbycoord(&globalconf
.screens
.tab
[phys_screen
],
518 c
->phys_screen
= phys_screen
;
520 /* consider the window banned */
525 c
->geometry
.x
= wgeom
->x
;
526 c
->geometry
.y
= wgeom
->y
;
527 /* Border will be added later. */
528 c
->geometry
.width
= wgeom
->width
;
529 c
->geometry
.height
= wgeom
->height
;
530 /* Also set internal geometry (client_ban() needs it). */
531 c
->geometries
.internal
.x
= wgeom
->x
;
532 c
->geometries
.internal
.y
= wgeom
->y
;
533 c
->geometries
.internal
.width
= wgeom
->width
;
534 c
->geometries
.internal
.height
= wgeom
->height
;
535 client_setborder(c
, wgeom
->border_width
);
537 if(ewmh_window_icon_get_reply(ewmh_icon_cookie
))
539 client_push(globalconf
.L
, c
);
540 c
->icon
= luaA_object_ref_item(globalconf
.L
, -1, -2);
541 lua_pop(globalconf
.L
, 1);
544 /* we honor size hints by default */
545 c
->size_hints_honor
= true;
548 property_update_wm_normal_hints(c
, NULL
);
549 property_update_wm_hints(c
, NULL
);
550 property_update_wm_transient_for(c
, NULL
);
551 property_update_wm_client_leader(c
, NULL
);
553 /* Recursively find the parent. */
554 for(tc
= c
; tc
->transient_for
; tc
= tc
->transient_for
);
555 if(tc
!= c
&& tc
->phys_screen
== c
->phys_screen
)
558 /* Then check clients hints */
559 ewmh_client_check_hints(c
);
561 /* move client to screen, but do not tag it */
562 screen_client_moveto(c
, screen
, false, true);
564 /* Push client in stack */
567 /* update window title */
568 property_update_wm_name(c
);
569 property_update_wm_icon_name(c
);
570 property_update_wm_class(c
, NULL
);
571 property_update_wm_protocols(c
);
573 xutil_text_prop_get(globalconf
.connection
, c
->win
, _NET_STARTUP_ID
, &c
->startup_id
, NULL
);
576 ewmh_process_client_strut(c
, NULL
);
578 ewmh_update_net_client_list(c
->phys_screen
);
580 /* Always stay in NORMAL_STATE. Even though iconified seems more
581 * appropriate sometimes. The only possible loss is that clients not using
582 * visibility events may continue to proces data (when banned).
583 * Without any exposes or other events the cost should be fairly limited though.
585 * Some clients may expect the window to be unmapped when STATE_ICONIFIED.
586 * Two conflicting parts of the ICCCM v2.0 (section 4.1.4):
588 * "Normal -> Iconic - The client should send a ClientMessage event as described later in this section."
589 * (note no explicit mention of unmapping, while Normal->Widthdrawn does mention that)
591 * "Once a client's window has left the Withdrawn state, the window will be mapped
592 * if it is in the Normal state and the window will be unmapped if it is in the Iconic state."
594 * At this stage it's just safer to keep it in normal state and avoid confusion.
596 window_state_set(c
->win
, XCB_WM_STATE_NORMAL
);
598 /* Grab everything */
599 xcb_grab_key(globalconf
.connection
, true, w
,
600 XCB_MOD_MASK_ANY
, XCB_GRAB_ANY
,
601 XCB_GRAB_MODE_ASYNC
, XCB_GRAB_MODE_SYNC
);
603 xcb_grab_button(globalconf
.connection
, false, w
,
604 XCB_EVENT_MASK_BUTTON_PRESS
| XCB_EVENT_MASK_BUTTON_RELEASE
,
605 XCB_GRAB_MODE_SYNC
, XCB_GRAB_MODE_ASYNC
, XCB_NONE
, XCB_NONE
,
606 XCB_GRAB_ANY
, XCB_MOD_MASK_ANY
);
610 spawn_start_notify(c
);
612 /* Call hook to notify list change */
613 if(globalconf
.hooks
.clients
!= LUA_REFNIL
)
614 luaA_dofunction_from_registry(globalconf
.L
, globalconf
.hooks
.clients
, 0, 0);
617 if(globalconf
.hooks
.manage
!= LUA_REFNIL
)
619 client_push(globalconf
.L
, c
);
620 lua_pushboolean(globalconf
.L
, startup
);
621 luaA_dofunction_from_registry(globalconf
.L
, globalconf
.hooks
.manage
, 2, 0);
625 /** Compute client geometry with respect to its geometry hints.
626 * \param c The client.
627 * \param geometry The geometry that the client might receive.
628 * \return The geometry the client must take respecting its hints.
631 client_geometry_hints(client_t
*c
, area_t geometry
)
633 int32_t basew
, baseh
, minw
, minh
;
635 /* base size is substituted with min size if not specified */
636 if(c
->size_hints
.flags
& XCB_SIZE_HINT_P_SIZE
)
638 basew
= c
->size_hints
.base_width
;
639 baseh
= c
->size_hints
.base_height
;
641 else if(c
->size_hints
.flags
& XCB_SIZE_HINT_P_MIN_SIZE
)
643 basew
= c
->size_hints
.min_width
;
644 baseh
= c
->size_hints
.min_height
;
649 /* min size is substituted with base size if not specified */
650 if(c
->size_hints
.flags
& XCB_SIZE_HINT_P_MIN_SIZE
)
652 minw
= c
->size_hints
.min_width
;
653 minh
= c
->size_hints
.min_height
;
655 else if(c
->size_hints
.flags
& XCB_SIZE_HINT_P_SIZE
)
657 minw
= c
->size_hints
.base_width
;
658 minh
= c
->size_hints
.base_height
;
663 if(c
->size_hints
.flags
& XCB_SIZE_HINT_P_ASPECT
664 && c
->size_hints
.min_aspect_num
> 0
665 && c
->size_hints
.min_aspect_den
> 0
666 && geometry
.height
- baseh
> 0
667 && geometry
.width
- basew
> 0)
669 double dx
= (double) (geometry
.width
- basew
);
670 double dy
= (double) (geometry
.height
- baseh
);
671 double min
= (double) c
->size_hints
.min_aspect_num
/ (double) c
->size_hints
.min_aspect_den
;
672 double max
= (double) c
->size_hints
.max_aspect_num
/ (double) c
->size_hints
.min_aspect_den
;
673 double ratio
= dx
/ dy
;
674 if(max
> 0 && min
> 0 && ratio
> 0)
678 dy
= (dx
* min
+ dy
) / (min
* min
+ 1);
680 geometry
.width
= (int) dx
+ basew
;
681 geometry
.height
= (int) dy
+ baseh
;
685 dy
= (dx
* min
+ dy
) / (max
* max
+ 1);
687 geometry
.width
= (int) dx
+ basew
;
688 geometry
.height
= (int) dy
+ baseh
;
694 geometry
.width
= MAX(geometry
.width
, minw
);
696 geometry
.height
= MAX(geometry
.height
, minh
);
698 if(c
->size_hints
.flags
& XCB_SIZE_HINT_P_MAX_SIZE
)
700 if(c
->size_hints
.max_width
)
701 geometry
.width
= MIN(geometry
.width
, c
->size_hints
.max_width
);
702 if(c
->size_hints
.max_height
)
703 geometry
.height
= MIN(geometry
.height
, c
->size_hints
.max_height
);
706 if(c
->size_hints
.flags
& (XCB_SIZE_HINT_P_RESIZE_INC
| XCB_SIZE_HINT_BASE_SIZE
)
707 && c
->size_hints
.width_inc
&& c
->size_hints
.height_inc
)
709 uint16_t t1
= geometry
.width
, t2
= geometry
.height
;
710 unsigned_subtract(t1
, basew
);
711 unsigned_subtract(t2
, baseh
);
712 geometry
.width
-= t1
% c
->size_hints
.width_inc
;
713 geometry
.height
-= t2
% c
->size_hints
.height_inc
;
719 /** Resize client window.
720 * The sizse given as parameters are with titlebar and borders!
721 * \param c Client to resize.
722 * \param geometry New window geometry.
723 * \param hints Use size hints.
724 * \return true if an actual resize occurred.
727 client_resize(client_t
*c
, area_t geometry
, bool hints
)
729 area_t geometry_internal
;
732 /* offscreen appearance fixes */
733 area
= display_area_get(c
->phys_screen
);
735 if(geometry
.x
> area
.width
)
736 geometry
.x
= area
.width
- geometry
.width
;
737 if(geometry
.y
> area
.height
)
738 geometry
.y
= area
.height
- geometry
.height
;
739 if(geometry
.x
+ geometry
.width
< 0)
741 if(geometry
.y
+ geometry
.height
< 0)
744 /* Real client geometry, please keep it contained to C code at the very least. */
745 geometry_internal
= titlebar_geometry_remove(c
->titlebar
, c
->border
, geometry
);
748 geometry_internal
= client_geometry_hints(c
, geometry_internal
);
750 if(geometry_internal
.width
== 0 || geometry_internal
.height
== 0)
753 /* Also let client hints propegate to the "official" geometry. */
754 geometry
= titlebar_geometry_add(c
->titlebar
, c
->border
, geometry_internal
);
756 if(c
->geometries
.internal
.x
!= geometry_internal
.x
757 || c
->geometries
.internal
.y
!= geometry_internal
.y
758 || c
->geometries
.internal
.width
!= geometry_internal
.width
759 || c
->geometries
.internal
.height
!= geometry_internal
.height
)
761 screen_t
*new_screen
= screen_getbycoord(c
->screen
,
762 geometry_internal
.x
, geometry_internal
.y
);
764 /* Values to configure a window is an array where values are
765 * stored according to 'value_mask' */
768 c
->geometries
.internal
.x
= values
[0] = geometry_internal
.x
;
769 c
->geometries
.internal
.y
= values
[1] = geometry_internal
.y
;
770 c
->geometries
.internal
.width
= values
[2] = geometry_internal
.width
;
771 c
->geometries
.internal
.height
= values
[3] = geometry_internal
.height
;
773 /* Also store geometry including border and titlebar. */
774 c
->geometry
= geometry
;
776 titlebar_update_geometry(c
);
778 /* Ignore all spurious enter/leave notify events */
779 client_ignore_enterleave_events();
781 xcb_configure_window(globalconf
.connection
, c
->win
,
782 XCB_CONFIG_WINDOW_X
| XCB_CONFIG_WINDOW_Y
783 | XCB_CONFIG_WINDOW_WIDTH
| XCB_CONFIG_WINDOW_HEIGHT
,
786 client_restore_enterleave_events();
788 screen_client_moveto(c
, new_screen
, true, false);
791 hook_property(client
, c
, "geometry");
799 /** Set a client minimized, or not.
800 * \param c The client.
801 * \param s Set or not the client minimized.
804 client_setminimized(client_t
*c
, bool s
)
806 if(c
->isminimized
!= s
)
808 client_need_reban(c
);
810 client_need_reban(c
);
812 window_state_set(c
->win
, XCB_WM_STATE_ICONIC
);
814 window_state_set(c
->win
, XCB_WM_STATE_NORMAL
);
815 ewmh_client_update_hints(c
);
817 hook_property(client
, c
, "minimized");
821 /** Set a client sticky, or not.
822 * \param c The client.
823 * \param s Set or not the client sticky.
826 client_setsticky(client_t
*c
, bool s
)
830 client_need_reban(c
);
832 client_need_reban(c
);
833 ewmh_client_update_hints(c
);
834 hook_property(client
, c
, "sticky");
838 /** Set a client fullscreen, or not.
839 * \param c The client.
840 * \param s Set or not the client fullscreen.
843 client_setfullscreen(client_t
*c
, bool s
)
845 if(c
->isfullscreen
!= s
)
849 /* Make sure the current geometry is stored without titlebar. */
851 titlebar_ban(c
->titlebar
);
853 /* become fullscreen! */
854 if((c
->isfullscreen
= s
))
856 /* remove any max state */
857 client_setmaxhoriz(c
, false);
858 client_setmaxvert(c
, false);
859 /* You can only be part of one of the special layers. */
860 client_setbelow(c
, false);
861 client_setabove(c
, false);
862 client_setontop(c
, false);
864 geometry
= screen_area_get(c
->screen
, false);
865 c
->geometries
.fullscreen
= c
->geometry
;
866 c
->border_fs
= c
->border
;
867 client_setborder(c
, 0);
871 geometry
= c
->geometries
.fullscreen
;
872 client_setborder(c
, c
->border_fs
);
874 client_resize(c
, geometry
, false);
876 ewmh_client_update_hints(c
);
877 hook_property(client
, c
, "fullscreen");
881 /** Set a client horizontally maximized.
882 * \param c The client.
883 * \param s The maximized status.
886 client_setmaxhoriz(client_t
*c
, bool s
)
888 if(c
->ismaxhoriz
!= s
)
892 if((c
->ismaxhoriz
= s
))
894 /* remove fullscreen mode */
895 client_setfullscreen(c
, false);
897 geometry
= screen_area_get(c
->screen
, true);
898 geometry
.y
= c
->geometry
.y
;
899 geometry
.height
= c
->geometry
.height
;
900 c
->geometries
.max
.x
= c
->geometry
.x
;
901 c
->geometries
.max
.width
= c
->geometry
.width
;
905 geometry
= c
->geometry
;
906 geometry
.x
= c
->geometries
.max
.x
;
907 geometry
.width
= c
->geometries
.max
.width
;
910 client_resize(c
, geometry
, c
->size_hints_honor
);
912 ewmh_client_update_hints(c
);
913 hook_property(client
, c
, "maximized_horizontal");
917 /** Set a client vertically maximized.
918 * \param c The client.
919 * \param s The maximized status.
922 client_setmaxvert(client_t
*c
, bool s
)
924 if(c
->ismaxvert
!= s
)
928 if((c
->ismaxvert
= s
))
930 /* remove fullscreen mode */
931 client_setfullscreen(c
, false);
933 geometry
= screen_area_get(c
->screen
, true);
934 geometry
.x
= c
->geometry
.x
;
935 geometry
.width
= c
->geometry
.width
;
936 c
->geometries
.max
.y
= c
->geometry
.y
;
937 c
->geometries
.max
.height
= c
->geometry
.height
;
941 geometry
= c
->geometry
;
942 geometry
.y
= c
->geometries
.max
.y
;
943 geometry
.height
= c
->geometries
.max
.height
;
946 client_resize(c
, geometry
, c
->size_hints_honor
);
948 ewmh_client_update_hints(c
);
949 hook_property(client
, c
, "maximized_vertical");
953 /** Set a client above, or not.
954 * \param c The client.
955 * \param s Set or not the client above.
958 client_setabove(client_t
*c
, bool s
)
962 /* You can only be part of one of the special layers. */
965 client_setbelow(c
, false);
966 client_setontop(c
, false);
967 client_setfullscreen(c
, false);
971 ewmh_client_update_hints(c
);
973 hook_property(client
, c
, "above");
977 /** Set a client below, or not.
978 * \param c The client.
979 * \param s Set or not the client below.
982 client_setbelow(client_t
*c
, bool s
)
986 /* You can only be part of one of the special layers. */
989 client_setabove(c
, false);
990 client_setontop(c
, false);
991 client_setfullscreen(c
, false);
995 ewmh_client_update_hints(c
);
997 hook_property(client
, c
, "below");
1001 /** Set a client modal, or not.
1002 * \param c The client.
1003 * \param s Set or not the client moda.
1006 client_setmodal(client_t
*c
, bool s
)
1012 ewmh_client_update_hints(c
);
1014 hook_property(client
, c
, "modal");
1018 /** Set a client ontop, or not.
1019 * \param c The client.
1020 * \param s Set or not the client moda.
1023 client_setontop(client_t
*c
, bool s
)
1027 /* You can only be part of one of the special layers. */
1030 client_setabove(c
, false);
1031 client_setbelow(c
, false);
1032 client_setfullscreen(c
, false);
1037 hook_property(client
, c
, "ontop");
1041 /** Unban a client and move it back into the viewport.
1042 * \param c The client.
1045 client_unban(client_t
*c
)
1049 xcb_map_window(globalconf
.connection
, c
->win
);
1051 c
->isbanned
= false;
1055 /** Unmanage a client.
1056 * \param c The client.
1059 client_unmanage(client_t
*c
)
1061 tag_array_t
*tags
= &c
->screen
->tags
;
1063 /* Reset transient_for attributes of widows that maybe refering to us */
1064 foreach(_tc
, globalconf
.clients
)
1066 client_t
*tc
= *_tc
;
1067 if(tc
->transient_for
== c
)
1068 tc
->transient_for
= NULL
;
1071 if(globalconf
.screens
.tab
[c
->phys_screen
].prev_client_focus
== c
)
1072 globalconf
.screens
.tab
[c
->phys_screen
].prev_client_focus
= NULL
;
1074 if(globalconf
.screens
.tab
[c
->phys_screen
].client_focus
== c
)
1077 /* remove client from global list and everywhere else */
1078 foreach(elem
, globalconf
.clients
)
1081 client_array_remove(&globalconf
.clients
, elem
);
1084 stack_client_remove(c
);
1085 for(int i
= 0; i
< tags
->len
; i
++)
1086 untag_client(c
, tags
->tab
[i
]);
1089 if(globalconf
.hooks
.unmanage
!= LUA_REFNIL
)
1091 client_push(globalconf
.L
, c
);
1092 luaA_dofunction_from_registry(globalconf
.L
, globalconf
.hooks
.unmanage
, 1, 0);
1095 /* Call hook to notify list change */
1096 if(globalconf
.hooks
.clients
!= LUA_REFNIL
)
1097 luaA_dofunction_from_registry(globalconf
.L
, globalconf
.hooks
.clients
, 0, 0);
1099 window_state_set(c
->win
, XCB_WM_STATE_WITHDRAWN
);
1101 titlebar_client_detach(c
);
1103 ewmh_update_net_client_list(c
->phys_screen
);
1105 /* set client as invalid */
1108 client_unref(globalconf
.L
, c
);
1111 /** Kill a client via a WM_DELETE_WINDOW request or KillClient if not
1113 * \param c The client to kill.
1116 client_kill(client_t
*c
)
1118 if(client_hasproto(c
, WM_DELETE_WINDOW
))
1120 xcb_client_message_event_t ev
;
1122 /* Initialize all of event's fields first */
1125 ev
.response_type
= XCB_CLIENT_MESSAGE
;
1128 ev
.data
.data32
[1] = XCB_CURRENT_TIME
;
1129 ev
.type
= WM_PROTOCOLS
;
1130 ev
.data
.data32
[0] = WM_DELETE_WINDOW
;
1132 xcb_send_event(globalconf
.connection
, false, c
->win
,
1133 XCB_EVENT_MASK_NO_EVENT
, (char *) &ev
);
1136 xcb_kill_client(globalconf
.connection
, c
->win
);
1139 /** Get all clients into a table.
1140 * \param L The Lua VM state.
1141 * \return The number of elements pushed on stack.
1143 * \lparam An optional screen nunmber.
1144 * \lreturn A table with all clients.
1147 luaA_client_get(lua_State
*L
)
1151 screen
= luaL_optnumber(L
, 1, 0) - 1;
1156 foreach(c
, globalconf
.clients
)
1159 lua_rawseti(L
, -2, i
++);
1163 luaA_checkscreen(screen
);
1164 foreach(c
, globalconf
.clients
)
1165 if((*c
)->screen
== &globalconf
.screens
.tab
[screen
])
1168 lua_rawseti(L
, -2, i
++);
1175 /** Check if a client is visible on its screen.
1176 * \param L The Lua VM state.
1177 * \return The number of elements pushed on stack.
1180 * \lreturn A boolean value, true if the client is visible, false otherwise.
1183 luaA_client_isvisible(lua_State
*L
)
1185 client_t
*c
= luaA_client_checkudata(L
, 1);
1186 lua_pushboolean(L
, client_isvisible(c
, c
->screen
));
1190 /** Set client border width.
1191 * \param c The client.
1192 * \param width The border width.
1195 client_setborder(client_t
*c
, int width
)
1199 if(width
> 0 && (c
->type
== WINDOW_TYPE_DOCK
1200 || c
->type
== WINDOW_TYPE_SPLASH
1201 || c
->type
== WINDOW_TYPE_DESKTOP
1202 || c
->isfullscreen
))
1205 if(width
== c
->border
|| width
< 0)
1208 /* Update geometry with the new border. */
1209 c
->geometry
.width
-= 2 * c
->border
;
1210 c
->geometry
.height
-= 2 * c
->border
;
1213 xcb_configure_window(globalconf
.connection
, c
->win
,
1214 XCB_CONFIG_WINDOW_BORDER_WIDTH
, &w
);
1216 c
->geometry
.width
+= 2 * c
->border
;
1217 c
->geometry
.height
+= 2 * c
->border
;
1219 /* Changing border size also affects the size of the titlebar. */
1220 titlebar_update_geometry(c
);
1222 hook_property(client
, c
, "border_width");
1226 * \param L The Lua VM state.
1232 luaA_client_kill(lua_State
*L
)
1234 client_t
*c
= luaA_client_checkudata(L
, 1);
1239 /** Swap a client with another one.
1240 * \param L The Lua VM state.
1243 * \lparam A client to swap with.
1246 luaA_client_swap(lua_State
*L
)
1248 client_t
*c
= luaA_client_checkudata(L
, 1);
1249 client_t
*swap
= luaA_client_checkudata(L
, 2);
1253 client_t
**ref_c
= NULL
, **ref_swap
= NULL
;
1254 foreach(item
, globalconf
.clients
)
1258 else if(*item
== swap
)
1260 if(ref_c
&& ref_swap
)
1267 /* Call hook to notify list change */
1268 if(globalconf
.hooks
.clients
!= LUA_REFNIL
)
1269 luaA_dofunction_from_registry(L
, globalconf
.hooks
.clients
, 0, 0);
1275 /** Access or set the client tags.
1276 * \param L The Lua VM state.
1277 * \return The number of elements pushed on stack.
1278 * \lparam A table with tags to set, or none to get the current tags table.
1279 * \return The clients tag.
1282 luaA_client_tags(lua_State
*L
)
1284 client_t
*c
= luaA_client_checkudata(L
, 1);
1285 tag_array_t
*tags
= &c
->screen
->tags
;
1288 if(lua_gettop(L
) == 2)
1290 luaA_checktable(L
, 2);
1291 for(int i
= 0; i
< tags
->len
; i
++)
1292 untag_client(c
, tags
->tab
[i
]);
1294 while(lua_next(L
, 2))
1301 if(is_client_tagged(c
, *tag
))
1304 lua_rawseti(L
, -2, ++j
);
1310 /** Raise a client on top of others which are on the same layer.
1311 * \param L The Lua VM state.
1316 luaA_client_raise(lua_State
*L
)
1318 client_t
*c
= luaA_client_checkudata(L
, 1);
1323 /** Lower a client on bottom of others which are on the same layer.
1324 * \param L The Lua VM state.
1329 luaA_client_lower(lua_State
*L
)
1331 client_t
*c
= luaA_client_checkudata(L
, 1);
1336 /** Redraw a client by unmapping and mapping it quickly.
1337 * \param L The Lua VM state.
1343 luaA_client_redraw(lua_State
*L
)
1345 client_t
*c
= luaA_client_checkudata(L
, 1);
1347 xcb_unmap_window(globalconf
.connection
, c
->win
);
1348 xcb_map_window(globalconf
.connection
, c
->win
);
1350 /* Set the focus on the current window if the redraw has been
1351 performed on the window where the pointer is currently on
1352 because after the unmapping/mapping, the focus is lost */
1353 if(globalconf
.screen_focus
->client_focus
== c
)
1362 /** Stop managing a client.
1363 * \param L The Lua VM state.
1364 * \return The number of elements pushed on stack.
1369 luaA_client_unmanage(lua_State
*L
)
1371 client_t
*c
= luaA_client_checkudata(L
, 1);
1376 /** Return client geometry.
1377 * \param L The Lua VM state.
1378 * \return The number of elements pushed on stack.
1380 * \lparam A table with new coordinates, or none.
1381 * \lreturn A table with client coordinates.
1384 luaA_client_geometry(lua_State
*L
)
1386 client_t
*c
= luaA_client_checkudata(L
, 1);
1388 if(lua_gettop(L
) == 2)
1392 luaA_checktable(L
, 2);
1393 geometry
.x
= luaA_getopt_number(L
, 2, "x", c
->geometry
.x
);
1394 geometry
.y
= luaA_getopt_number(L
, 2, "y", c
->geometry
.y
);
1395 if(client_isfixed(c
))
1397 geometry
.width
= c
->geometry
.width
;
1398 geometry
.height
= c
->geometry
.height
;
1402 geometry
.width
= luaA_getopt_number(L
, 2, "width", c
->geometry
.width
);
1403 geometry
.height
= luaA_getopt_number(L
, 2, "height", c
->geometry
.height
);
1406 client_resize(c
, geometry
, c
->size_hints_honor
);
1409 return luaA_pusharea(L
, c
->geometry
);
1412 /** Push a strut type to a table on stack.
1413 * \param L The Lua VM state.
1414 * \param struts The struts to push.
1415 * \return The number of elements pushed on stack.
1418 luaA_pushstruts(lua_State
*L
, strut_t struts
)
1420 lua_createtable(L
, 4, 0);
1421 lua_pushnumber(L
, struts
.left
);
1422 lua_setfield(L
, -2, "left");
1423 lua_pushnumber(L
, struts
.right
);
1424 lua_setfield(L
, -2, "right");
1425 lua_pushnumber(L
, struts
.top
);
1426 lua_setfield(L
, -2, "top");
1427 lua_pushnumber(L
, struts
.bottom
);
1428 lua_setfield(L
, -2, "bottom");
1432 /** Return client struts (reserved space at the edge of the screen).
1433 * \param L The Lua VM state.
1434 * \return The number of elements pushed on stack.
1436 * \lparam A table with new strut values, or none.
1437 * \lreturn A table with strut values.
1440 luaA_client_struts(lua_State
*L
)
1442 client_t
*c
= luaA_client_checkudata(L
, 1);
1444 if(lua_gettop(L
) == 2)
1447 area_t screen_area
= display_area_get(c
->phys_screen
);
1449 struts
.left
= luaA_getopt_number(L
, 2, "left", c
->strut
.left
);
1450 struts
.right
= luaA_getopt_number(L
, 2, "right", c
->strut
.right
);
1451 struts
.top
= luaA_getopt_number(L
, 2, "top", c
->strut
.top
);
1452 struts
.bottom
= luaA_getopt_number(L
, 2, "bottom", c
->strut
.bottom
);
1454 if(struts
.left
!= c
->strut
.left
|| struts
.right
!= c
->strut
.right
||
1455 struts
.top
!= c
->strut
.top
|| struts
.bottom
!= c
->strut
.bottom
) {
1456 /* Struts are not so well defined in the context of xinerama. So we just
1457 * give the entire root window and let the window manager decide. */
1458 struts
.left_start_y
= 0;
1459 struts
.left_end_y
= !struts
.left
? 0 : screen_area
.height
;
1460 struts
.right_start_y
= 0;
1461 struts
.right_end_y
= !struts
.right
? 0 : screen_area
.height
;
1462 struts
.top_start_x
= 0;
1463 struts
.top_end_x
= !struts
.top
? 0 : screen_area
.width
;
1464 struts
.bottom_start_x
= 0;
1465 struts
.bottom_end_x
= !struts
.bottom
? 0 : screen_area
.width
;
1469 ewmh_update_client_strut(c
);
1471 hook_property(client
, c
, "struts");
1475 return luaA_pushstruts(L
, c
->strut
);
1478 /** Client newindex.
1479 * \param L The Lua VM state.
1480 * \return The number of elements pushed on stack.
1483 luaA_client_newindex(lua_State
*L
)
1486 client_t
*c
= luaA_client_checkudata(L
, 1);
1487 const char *buf
= luaL_checklstring(L
, 2, &len
);
1492 switch(a_tokenize(buf
, len
))
1495 if(globalconf
.xinerama_is_active
)
1497 i
= luaL_checknumber(L
, 3) - 1;
1498 luaA_checkscreen(i
);
1499 screen_client_moveto(c
, &globalconf
.screens
.tab
[i
], true, true);
1503 b
= luaA_checkboolean(L
, 3);
1504 if(b
!= c
->ishidden
)
1506 client_need_reban(c
);
1508 client_need_reban(c
);
1509 hook_property(client
, c
, "hide");
1512 case A_TK_MINIMIZED
:
1513 client_setminimized(c
, luaA_checkboolean(L
, 3));
1515 case A_TK_FULLSCREEN
:
1516 client_setfullscreen(c
, luaA_checkboolean(L
, 3));
1518 case A_TK_MAXIMIZED_HORIZONTAL
:
1519 client_setmaxhoriz(c
, luaA_checkboolean(L
, 3));
1521 case A_TK_MAXIMIZED_VERTICAL
:
1522 client_setmaxvert(c
, luaA_checkboolean(L
, 3));
1525 luaA_object_unref_item(L
, 1, c
->icon
);
1527 c
->icon
= luaA_object_ref_item(L
, 1, 3);
1529 hook_property(client
, c
, "icon");
1533 window_opacity_set(c
->win
, -1);
1536 d
= luaL_checknumber(L
, 3);
1537 if(d
>= 0 && d
<= 1)
1538 window_opacity_set(c
->win
, d
);
1542 client_setsticky(c
, luaA_checkboolean(L
, 3));
1544 case A_TK_SIZE_HINTS_HONOR
:
1545 c
->size_hints_honor
= luaA_checkboolean(L
, 3);
1546 hook_property(client
, c
, "size_hints_honor");
1548 case A_TK_BORDER_WIDTH
:
1549 client_setborder(c
, luaL_checknumber(L
, 3));
1552 client_setontop(c
, luaA_checkboolean(L
, 3));
1555 client_setabove(c
, luaA_checkboolean(L
, 3));
1558 client_setbelow(c
, luaA_checkboolean(L
, 3));
1561 client_seturgent(c
, luaA_checkboolean(L
, 3));
1563 case A_TK_BORDER_COLOR
:
1564 if((buf
= luaL_checklstring(L
, 3, &len
))
1565 && xcolor_init_reply(xcolor_init_unchecked(&c
->border_color
, buf
, len
)))
1566 xcb_change_window_attributes(globalconf
.connection
, c
->win
,
1567 XCB_CW_BORDER_PIXEL
, &c
->border_color
.pixel
);
1571 titlebar_client_detach(c
);
1573 titlebar_client_attach(c
);
1575 case A_TK_SKIP_TASKBAR
:
1576 c
->skiptb
= luaA_checkboolean(L
, 3);
1577 hook_property(client
, c
, "skip_taskbar");
1580 luaA_object_unref_item(L
, 1, c
->keys
);
1581 c
->keys
= luaA_object_ref_item(L
, 1, 3);
1584 luaA_object_unref_item(L
, 1, c
->buttons
);
1585 c
->buttons
= luaA_object_ref_item(L
, 1, 3);
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
)
1638 client_t
*c
= luaA_client_checkudata(L
, 1);
1639 const char *buf
= luaL_checklstring(L
, 2, &len
);
1642 xcb_get_property_cookie_t prop_c
;
1643 xcb_get_property_reply_t
*prop_r
= NULL
;
1646 if(luaA_usemetatable(L
, 1, 2))
1649 switch(a_tokenize(buf
, len
))
1652 lua_pushstring(L
, c
->name
);
1654 case A_TK_TRANSIENT_FOR
:
1655 return client_push(globalconf
.L
, c
->transient_for
);
1656 case A_TK_SKIP_TASKBAR
:
1657 lua_pushboolean(L
, c
->skiptb
);
1660 return client_getcontent(c
);
1664 case WINDOW_TYPE_DESKTOP
:
1665 lua_pushliteral(L
, "desktop");
1667 case WINDOW_TYPE_DOCK
:
1668 lua_pushliteral(L
, "dock");
1670 case WINDOW_TYPE_SPLASH
:
1671 lua_pushliteral(L
, "splash");
1673 case WINDOW_TYPE_DIALOG
:
1674 lua_pushliteral(L
, "dialog");
1676 case WINDOW_TYPE_MENU
:
1677 lua_pushliteral(L
, "menu");
1679 case WINDOW_TYPE_TOOLBAR
:
1680 lua_pushliteral(L
, "toolbar");
1682 case WINDOW_TYPE_UTILITY
:
1683 lua_pushliteral(L
, "utility");
1685 case WINDOW_TYPE_DROPDOWN_MENU
:
1686 lua_pushliteral(L
, "dropdown_menu");
1688 case WINDOW_TYPE_POPUP_MENU
:
1689 lua_pushliteral(L
, "popup_menu");
1691 case WINDOW_TYPE_TOOLTIP
:
1692 lua_pushliteral(L
, "tooltip");
1694 case WINDOW_TYPE_NOTIFICATION
:
1695 lua_pushliteral(L
, "notification");
1697 case WINDOW_TYPE_COMBO
:
1698 lua_pushliteral(L
, "combo");
1700 case WINDOW_TYPE_DND
:
1701 lua_pushliteral(L
, "dnd");
1703 case WINDOW_TYPE_NORMAL
:
1704 lua_pushliteral(L
, "normal");
1709 lua_pushstring(L
, c
->class);
1712 lua_pushstring(L
, c
->instance
);
1715 if(!xutil_text_prop_get(globalconf
.connection
, c
->win
,
1716 WM_WINDOW_ROLE
, &value
, &slen
))
1718 lua_pushlstring(L
, value
, slen
);
1722 prop_c
= xcb_get_property_unchecked(globalconf
.connection
, false, c
->win
, _NET_WM_PID
, CARDINAL
, 0L, 1L);
1723 prop_r
= xcb_get_property_reply(globalconf
.connection
, prop_c
, NULL
);
1725 if(prop_r
&& prop_r
->value_len
&& (data
= xcb_get_property_value(prop_r
)))
1726 lua_pushnumber(L
, *(uint32_t *)data
);
1734 lua_pushnumber(L
, c
->win
);
1736 case A_TK_LEADER_ID
:
1737 lua_pushnumber(L
, c
->leader_win
);
1740 if(!xutil_text_prop_get(globalconf
.connection
, c
->win
,
1741 WM_CLIENT_MACHINE
, &value
, &slen
))
1743 lua_pushlstring(L
, value
, slen
);
1746 case A_TK_ICON_NAME
:
1747 lua_pushstring(L
, c
->icon_name
);
1750 lua_pushnumber(L
, 1 + screen_array_indexof(&globalconf
.screens
, c
->screen
));
1753 lua_pushboolean(L
, c
->ishidden
);
1755 case A_TK_MINIMIZED
:
1756 lua_pushboolean(L
, c
->isminimized
);
1758 case A_TK_FULLSCREEN
:
1759 lua_pushboolean(L
, c
->isfullscreen
);
1763 lua_pushnumber(L
, c
->group_win
);
1767 case A_TK_MAXIMIZED_HORIZONTAL
:
1768 lua_pushboolean(L
, c
->ismaxhoriz
);
1770 case A_TK_MAXIMIZED_VERTICAL
:
1771 lua_pushboolean(L
, c
->ismaxvert
);
1774 luaA_object_push_item(L
, 1, c
->icon
);
1777 if((d
= window_opacity_get(c
->win
)) >= 0)
1778 lua_pushnumber(L
, d
);
1783 lua_pushboolean(L
, c
->isontop
);
1786 lua_pushboolean(L
, c
->isabove
);
1789 lua_pushboolean(L
, c
->isbelow
);
1792 lua_pushboolean(L
, c
->issticky
);
1794 case A_TK_SIZE_HINTS_HONOR
:
1795 lua_pushboolean(L
, c
->size_hints_honor
);
1797 case A_TK_BORDER_WIDTH
:
1798 lua_pushnumber(L
, c
->border
);
1800 case A_TK_BORDER_COLOR
:
1801 luaA_pushxcolor(L
, &c
->border_color
);
1804 return wibox_push(L
, c
->titlebar
);
1806 lua_pushboolean(L
, c
->isurgent
);
1808 case A_TK_SIZE_HINTS
:
1810 const char *u_or_p
= NULL
;
1812 lua_createtable(L
, 0, 1);
1814 if(c
->size_hints
.flags
& XCB_SIZE_HINT_US_POSITION
)
1815 u_or_p
= "user_position";
1816 else if(c
->size_hints
.flags
& XCB_SIZE_HINT_P_POSITION
)
1817 u_or_p
= "program_position";
1821 lua_createtable(L
, 0, 2);
1822 lua_pushnumber(L
, c
->size_hints
.x
);
1823 lua_setfield(L
, -2, "x");
1824 lua_pushnumber(L
, c
->size_hints
.y
);
1825 lua_setfield(L
, -2, "y");
1826 lua_setfield(L
, -2, u_or_p
);
1830 if(c
->size_hints
.flags
& XCB_SIZE_HINT_US_SIZE
)
1831 u_or_p
= "user_size";
1832 else if(c
->size_hints
.flags
& XCB_SIZE_HINT_P_SIZE
)
1833 u_or_p
= "program_size";
1837 lua_createtable(L
, 0, 2);
1838 lua_pushnumber(L
, c
->size_hints
.width
);
1839 lua_setfield(L
, -2, "width");
1840 lua_pushnumber(L
, c
->size_hints
.height
);
1841 lua_setfield(L
, -2, "height");
1842 lua_setfield(L
, -2, u_or_p
);
1845 if(c
->size_hints
.flags
& XCB_SIZE_HINT_P_MIN_SIZE
)
1847 lua_pushnumber(L
, c
->size_hints
.min_width
);
1848 lua_setfield(L
, -2, "min_width");
1849 lua_pushnumber(L
, c
->size_hints
.min_height
);
1850 lua_setfield(L
, -2, "min_height");
1853 if(c
->size_hints
.flags
& XCB_SIZE_HINT_P_MAX_SIZE
)
1855 lua_pushnumber(L
, c
->size_hints
.max_width
);
1856 lua_setfield(L
, -2, "max_width");
1857 lua_pushnumber(L
, c
->size_hints
.max_height
);
1858 lua_setfield(L
, -2, "max_height");
1861 if(c
->size_hints
.flags
& XCB_SIZE_HINT_P_RESIZE_INC
)
1863 lua_pushnumber(L
, c
->size_hints
.width_inc
);
1864 lua_setfield(L
, -2, "width_inc");
1865 lua_pushnumber(L
, c
->size_hints
.height_inc
);
1866 lua_setfield(L
, -2, "height_inc");
1869 if(c
->size_hints
.flags
& XCB_SIZE_HINT_P_ASPECT
)
1871 lua_pushnumber(L
, c
->size_hints
.min_aspect_num
);
1872 lua_setfield(L
, -2, "min_aspect_num");
1873 lua_pushnumber(L
, c
->size_hints
.min_aspect_den
);
1874 lua_setfield(L
, -2, "min_aspect_den");
1875 lua_pushnumber(L
, c
->size_hints
.max_aspect_num
);
1876 lua_setfield(L
, -2, "max_aspect_num");
1877 lua_pushnumber(L
, c
->size_hints
.max_aspect_den
);
1878 lua_setfield(L
, -2, "max_aspect_den");
1881 if(c
->size_hints
.flags
& XCB_SIZE_HINT_BASE_SIZE
)
1883 lua_pushnumber(L
, c
->size_hints
.base_width
);
1884 lua_setfield(L
, -2, "base_width");
1885 lua_pushnumber(L
, c
->size_hints
.base_height
);
1886 lua_setfield(L
, -2, "base_height");
1889 if(c
->size_hints
.flags
& XCB_SIZE_HINT_P_WIN_GRAVITY
)
1891 switch(c
->size_hints
.win_gravity
)
1894 lua_pushliteral(L
, "north_west");
1896 case XCB_GRAVITY_NORTH
:
1897 lua_pushliteral(L
, "north");
1899 case XCB_GRAVITY_NORTH_EAST
:
1900 lua_pushliteral(L
, "north_east");
1902 case XCB_GRAVITY_WEST
:
1903 lua_pushliteral(L
, "west");
1905 case XCB_GRAVITY_CENTER
:
1906 lua_pushliteral(L
, "center");
1908 case XCB_GRAVITY_EAST
:
1909 lua_pushliteral(L
, "east");
1911 case XCB_GRAVITY_SOUTH_WEST
:
1912 lua_pushliteral(L
, "south_west");
1914 case XCB_GRAVITY_SOUTH
:
1915 lua_pushliteral(L
, "south");
1917 case XCB_GRAVITY_SOUTH_EAST
:
1918 lua_pushliteral(L
, "south_east");
1920 case XCB_GRAVITY_STATIC
:
1921 lua_pushliteral(L
, "static");
1924 lua_setfield(L
, -2, "win_gravity");
1929 return luaA_object_push_item(L
, 1, c
->keys
);
1931 return luaA_object_push_item(L
, 1, c
->buttons
);
1940 * \param L The Lua VM state.
1941 * \return The number of pushed elements.
1944 luaA_client_module_index(lua_State
*L
)
1947 const char *buf
= luaL_checklstring(L
, 2, &len
);
1949 switch(a_tokenize(buf
, len
))
1952 return client_push(globalconf
.L
, globalconf
.screen_focus
->client_focus
);
1959 /* Client module new index.
1960 * \param L The Lua VM state.
1961 * \return The number of pushed elements.
1964 luaA_client_module_newindex(lua_State
*L
)
1967 const char *buf
= luaL_checklstring(L
, 2, &len
);
1970 switch(a_tokenize(buf
, len
))
1973 c
= luaA_client_checkudata(L
, 3);
1983 const struct luaL_reg awesome_client_methods
[] =
1985 LUA_CLASS_METHODS(client
)
1986 { "get", luaA_client_get
},
1987 { "__index", luaA_client_module_index
},
1988 { "__newindex", luaA_client_module_newindex
},
1991 const struct luaL_reg awesome_client_meta
[] =
1993 LUA_OBJECT_META(client
)
1994 { "isvisible", luaA_client_isvisible
},
1995 { "geometry", luaA_client_geometry
},
1996 { "struts", luaA_client_struts
},
1997 { "tags", luaA_client_tags
},
1998 { "kill", luaA_client_kill
},
1999 { "swap", luaA_client_swap
},
2000 { "raise", luaA_client_raise
},
2001 { "lower", luaA_client_lower
},
2002 { "redraw", luaA_client_redraw
},
2003 { "unmanage", luaA_client_unmanage
},
2004 { "__index", luaA_client_index
},
2005 { "__newindex", luaA_client_newindex
},
2006 { "__gc", luaA_client_gc
},
2010 // vim: filetype=c:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=80