rules: allow defining exceptions to a rule - except, and except_any
[awesome.git] / client.c
blob049e3d55e6c36fd2c0ec9df6473c5cff832f37d0
1 /*
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>
25 #include "tag.h"
26 #include "ewmh.h"
27 #include "screen.h"
28 #include "titlebar.h"
29 #include "systray.h"
30 #include "property.h"
31 #include "spawn.h"
32 #include "luaa.h"
33 #include "common/atoms.h"
34 #include "common/xutil.h"
36 client_t *
37 luaA_client_checkudata(lua_State *L, int ud)
39 client_t *c = luaA_checkudata(L, ud, &client_class);
40 if(c->invalid)
41 luaL_error(L, "client is invalid\n");
42 return c;
45 /** Collect a client.
46 * \param L The Lua VM state.
47 * \return The number of element pushed on stack.
49 static int
50 luaA_client_gc(lua_State *L)
52 client_t *c = luaA_checkudata(L, 1, &client_class);
53 button_array_wipe(&c->buttons);
54 key_array_wipe(&c->keys);
55 xcb_get_wm_protocols_reply_wipe(&c->protocols);
56 p_delete(&c->machine);
57 p_delete(&c->class);
58 p_delete(&c->instance);
59 p_delete(&c->icon_name);
60 p_delete(&c->alt_icon_name);
61 p_delete(&c->name);
62 p_delete(&c->alt_name);
63 return luaA_object_gc(L);
66 /** Change the client opacity.
67 * \param L The Lua VM state.
68 * \param cidx The client index.
69 * \param opacity The opacity.
71 void
72 client_set_opacity(lua_State *L, int cidx, double opacity)
74 client_t *c = luaA_client_checkudata(L, cidx);
76 if(c->opacity != opacity)
78 c->opacity = opacity;
79 window_opacity_set(c->window, opacity);
80 luaA_object_emit_signal(L, cidx, "property::opacity", 0);
84 /** Change the clients urgency flag.
85 * \param L The Lua VM state.
86 * \param cidx The client index on the stack.
87 * \param urgent The new flag state.
89 void
90 client_set_urgent(lua_State *L, int cidx, bool urgent)
92 client_t *c = luaA_client_checkudata(L, cidx);
94 if(c->urgent != urgent)
96 xcb_get_property_cookie_t hints =
97 xcb_get_wm_hints_unchecked(globalconf.connection, c->window);
99 c->urgent = urgent;
100 ewmh_client_update_hints(c);
102 /* update ICCCM hints */
103 xcb_wm_hints_t wmh;
104 xcb_get_wm_hints_reply(globalconf.connection, hints, &wmh, NULL);
106 if(urgent)
107 wmh.flags |= XCB_WM_HINT_X_URGENCY;
108 else
109 wmh.flags &= ~XCB_WM_HINT_X_URGENCY;
111 xcb_set_wm_hints(globalconf.connection, c->window, &wmh);
113 hook_property(c, "urgent");
114 luaA_object_emit_signal(L, cidx, "property::urgent", 0);
118 void
119 client_set_group_window(lua_State *L, int cidx, xcb_window_t window)
121 client_t *c = luaA_client_checkudata(L, cidx);
123 if(c->group_window != window)
125 c->group_window = window;
126 luaA_object_emit_signal(L, cidx, "property::group_window", 0);
130 void
131 client_set_type(lua_State *L, int cidx, window_type_t type)
133 client_t *c = luaA_client_checkudata(L, cidx);
135 if(c->type != type)
137 c->type = type;
138 luaA_object_emit_signal(L, cidx, "property::type", 0);
142 void
143 client_set_pid(lua_State *L, int cidx, uint32_t pid)
145 client_t *c = luaA_client_checkudata(L, cidx);
147 if(c->pid != pid)
149 c->pid = pid;
150 luaA_object_emit_signal(L, cidx, "property::pid", 0);
154 void
155 client_set_icon_name(lua_State *L, int cidx, char *icon_name)
157 client_t *c = luaA_client_checkudata(L, cidx);
158 p_delete(&c->icon_name);
159 c->icon_name = icon_name;
160 luaA_object_emit_signal(L, cidx, "property::icon_name", 0);
161 hook_property(c, "icon_name");
164 void
165 client_set_alt_icon_name(lua_State *L, int cidx, char *icon_name)
167 client_t *c = luaA_client_checkudata(L, cidx);
168 p_delete(&c->alt_icon_name);
169 c->alt_icon_name = icon_name;
170 luaA_object_emit_signal(L, cidx, "property::icon_name", 0);
171 hook_property(c, "icon_name");
174 void
175 client_set_role(lua_State *L, int cidx, char *role)
177 client_t *c = luaA_client_checkudata(L, cidx);
178 p_delete(&c->role);
179 c->role = role;
180 luaA_object_emit_signal(L, cidx, "property::role", 0);
183 void
184 client_set_machine(lua_State *L, int cidx, char *machine)
186 client_t *c = luaA_client_checkudata(L, cidx);
187 p_delete(&c->machine);
188 c->machine = machine;
189 luaA_object_emit_signal(L, cidx, "property::machine", 0);
192 void
193 client_set_class_instance(lua_State *L, int cidx, const char *class, const char *instance)
195 client_t *c = luaA_client_checkudata(L, cidx);
196 p_delete(&c->class);
197 p_delete(&c->instance);
198 c->class = a_strdup(class);
199 c->instance = a_strdup(instance);
200 luaA_object_emit_signal(L, cidx, "property::class", 0);
201 luaA_object_emit_signal(L, cidx, "property::instance", 0);
204 void
205 client_set_transient_for(lua_State *L, int cidx, client_t *transient_for)
207 client_t *c = luaA_client_checkudata(L, cidx);
209 if(c->transient_for != transient_for)
211 c->transient_for = transient_for;
212 luaA_object_emit_signal(L, cidx, "property::transient_for", 0);
216 void
217 client_set_name(lua_State *L, int cidx, char *name)
219 client_t *c = luaA_client_checkudata(L, cidx);
220 p_delete(&c->name);
221 c->name = name;
222 hook_property(c, "name");
223 luaA_object_emit_signal(L, cidx, "property::name", 0);
226 void
227 client_set_alt_name(lua_State *L, int cidx, char *name)
229 client_t *c = luaA_client_checkudata(L, cidx);
230 p_delete(&c->alt_name);
231 c->alt_name = name;
232 hook_property(c, "name");
233 luaA_object_emit_signal(L, cidx, "property::name", 0);
236 /** Returns true if a client is tagged
237 * with one of the tags of the specified screen.
238 * \param c The client to check.
239 * \param screen Virtual screen.
240 * \return true if the client is visible, false otherwise.
242 bool
243 client_maybevisible(client_t *c, screen_t *screen)
245 if(screen && c->screen == screen)
247 if(c->sticky || c->type == WINDOW_TYPE_DESKTOP)
248 return true;
250 foreach(tag, screen->tags)
251 if(tag_get_selected(*tag) && is_client_tagged(c, *tag))
252 return true;
254 return false;
257 /** Get a client by its window.
258 * \param w The client window to find.
259 * \return A client pointer if found, NULL otherwise.
261 client_t *
262 client_getbywin(xcb_window_t w)
264 foreach(c, globalconf.clients)
265 if((*c)->window == w)
266 return *c;
268 return NULL;
271 /** Record that a client lost focus.
272 * \param c Client being unfocused
274 void
275 client_unfocus_update(client_t *c)
277 globalconf.screens.tab[c->phys_screen].client_focus = NULL;
278 ewmh_update_net_active_window(c->phys_screen);
280 /* Call hook */
281 if(globalconf.hooks.unfocus != LUA_REFNIL)
283 luaA_object_push(globalconf.L, c);
284 luaA_dofunction_from_registry(globalconf.L, globalconf.hooks.unfocus, 1, 0);
287 luaA_object_push(globalconf.L, c);
288 luaA_class_emit_signal(globalconf.L, &client_class, "unfocus", 1);
291 /** Unfocus a client.
292 * \param c The client.
294 void
295 client_unfocus(client_t *c)
298 xcb_window_t root_win = xutil_screen_get(globalconf.connection, c->phys_screen)->root;
299 /* Set focus on root window, so no events leak to the current window.
300 * This kind of inlines client_set_focus(), but a root window will never have
301 * the WM_TAKE_FOCUS protocol.
303 xcb_set_input_focus(globalconf.connection, XCB_INPUT_FOCUS_PARENT,
304 root_win, globalconf.timestamp);
306 client_unfocus_update(c);
309 /** Check if client supports atom a protocol in WM_PROTOCOL.
310 * \param c The client.
311 * \param atom The protocol atom to check for.
312 * \return True if client has the atom in protocol, false otherwise.
314 bool
315 client_hasproto(client_t *c, xcb_atom_t atom)
317 for(uint32_t i = 0; i < c->protocols.atoms_len; i++)
318 if(c->protocols.atoms[i] == atom)
319 return true;
320 return false;
323 /** Sets focus on window - using xcb_set_input_focus or WM_TAKE_FOCUS
324 * \param c Client that should get focus
325 * \param set_input_focus Should we call xcb_set_input_focus
327 void
328 client_set_focus(client_t *c, bool set_input_focus)
330 bool takefocus = client_hasproto(c, WM_TAKE_FOCUS);
331 if(set_input_focus)
332 xcb_set_input_focus(globalconf.connection, XCB_INPUT_FOCUS_PARENT,
333 c->window, globalconf.timestamp);
334 if(takefocus)
335 window_takefocus(c->window);
338 /** Prepare banning a client by running all needed lua events.
339 * \param c The client.
341 void client_ban_unfocus(client_t *c)
343 if(globalconf.screens.tab[c->phys_screen].prev_client_focus == c)
344 globalconf.screens.tab[c->phys_screen].prev_client_focus = NULL;
346 /* Wait until the last moment to take away the focus from the window. */
347 if(globalconf.screens.tab[c->phys_screen].client_focus == c)
348 client_unfocus(c);
351 /** Ban client and move it out of the viewport.
352 * \param c The client.
354 void
355 client_ban(client_t *c)
357 if(!c->isbanned)
359 xcb_unmap_window(globalconf.connection, c->window);
361 c->isbanned = true;
363 client_ban_unfocus(c);
367 /** This is part of The Bob Marley Algorithm: we ignore enter and leave window
368 * in certain cases, like map/unmap or move, so we don't get spurious events.
370 void
371 client_ignore_enterleave_events(void)
373 foreach(c, globalconf.clients)
374 xcb_change_window_attributes(globalconf.connection,
375 (*c)->window,
376 XCB_CW_EVENT_MASK,
377 (const uint32_t []) { CLIENT_SELECT_INPUT_EVENT_MASK & ~(XCB_EVENT_MASK_ENTER_WINDOW | XCB_EVENT_MASK_LEAVE_WINDOW) });
380 void
381 client_restore_enterleave_events(void)
383 foreach(c, globalconf.clients)
384 xcb_change_window_attributes(globalconf.connection,
385 (*c)->window,
386 XCB_CW_EVENT_MASK,
387 (const uint32_t []) { CLIENT_SELECT_INPUT_EVENT_MASK });
390 /** Record that a client got focus.
391 * \param c The client.
393 void
394 client_focus_update(client_t *c)
396 if(!client_maybevisible(c, c->screen))
398 /* Focus previously focused client */
399 client_focus(globalconf.screen_focus->prev_client_focus);
400 return;
403 if(globalconf.screen_focus
404 && globalconf.screen_focus->client_focus)
406 if (globalconf.screen_focus->client_focus != c)
407 client_unfocus_update(globalconf.screen_focus->client_focus);
408 else
409 /* Already focused */
410 return;
413 globalconf.screen_focus = &globalconf.screens.tab[c->phys_screen];
414 globalconf.screen_focus->prev_client_focus = c;
415 globalconf.screen_focus->client_focus = c;
417 /* according to EWMH, we have to remove the urgent state from a client */
418 luaA_object_push(globalconf.L, c);
419 client_set_urgent(globalconf.L, -1, false);
421 ewmh_update_net_active_window(c->phys_screen);
423 /* execute hook */
424 if(globalconf.hooks.focus != LUA_REFNIL)
426 luaA_object_push(globalconf.L, c);
427 luaA_dofunction_from_registry(globalconf.L, globalconf.hooks.focus, 1, 0);
430 luaA_class_emit_signal(globalconf.L, &client_class, "focus", 1);
433 /** Give focus to client, or to first client if client is NULL.
434 * \param c The client.
436 void
437 client_focus(client_t *c)
439 /* We have to set focus on first client */
440 if(!c && globalconf.clients.len && !(c = globalconf.clients.tab[0]))
441 return;
443 if(!client_maybevisible(c, c->screen))
444 return;
446 /* X11 doesn't let you focus a window that isn't viewable */
447 client_unban(c);
449 if (!c->nofocus)
450 client_focus_update(c);
452 client_set_focus(c, !c->nofocus);
455 /** Stack a window below.
456 * \param c The client.
457 * \param previous The previous window on the stack.
458 * \return The next-previous!
460 static xcb_window_t
461 client_stack_above(client_t *c, xcb_window_t previous)
463 uint32_t config_win_vals[2];
465 config_win_vals[0] = previous;
466 config_win_vals[1] = XCB_STACK_MODE_ABOVE;
468 xcb_configure_window(globalconf.connection, c->window,
469 XCB_CONFIG_WINDOW_SIBLING | XCB_CONFIG_WINDOW_STACK_MODE,
470 config_win_vals);
472 config_win_vals[0] = c->window;
474 if(c->titlebar)
476 xcb_configure_window(globalconf.connection,
477 c->titlebar->window,
478 XCB_CONFIG_WINDOW_SIBLING | XCB_CONFIG_WINDOW_STACK_MODE,
479 config_win_vals);
480 previous = c->titlebar->window;
482 else
483 previous = c->window;
485 /* stack transient window on top of their parents */
486 foreach(node, globalconf.stack)
487 if((*node)->transient_for == c)
488 previous = client_stack_above(*node, previous);
490 return previous;
493 /** Stacking layout layers */
494 typedef enum
496 /** This one is a special layer */
497 LAYER_IGNORE,
498 LAYER_DESKTOP,
499 LAYER_BELOW,
500 LAYER_NORMAL,
501 LAYER_ABOVE,
502 LAYER_FULLSCREEN,
503 LAYER_ONTOP,
504 /** This one only used for counting and is not a real layer */
505 LAYER_COUNT
506 } layer_t;
508 /** Get the real layer of a client according to its attribute (fullscreen, …)
509 * \param c The client.
510 * \return The real layer.
512 static layer_t
513 client_layer_translator(client_t *c)
515 /* first deal with user set attributes */
516 if(c->ontop)
517 return LAYER_ONTOP;
518 else if(c->fullscreen && globalconf.screen_focus->client_focus == c)
519 return LAYER_FULLSCREEN;
520 else if(c->above)
521 return LAYER_ABOVE;
522 else if(c->below)
523 return LAYER_BELOW;
525 /* check for transient attr */
526 if(c->transient_for)
527 return LAYER_IGNORE;
529 /* then deal with windows type */
530 switch(c->type)
532 case WINDOW_TYPE_DESKTOP:
533 return LAYER_DESKTOP;
534 default:
535 break;
538 return LAYER_NORMAL;
541 /** Restack clients.
542 * \todo It might be worth stopping to restack everyone and only stack `c'
543 * relatively to the first matching in the list.
545 void
546 client_stack_refresh()
548 uint32_t config_win_vals[2];
549 layer_t layer;
551 if (!globalconf.client_need_stack_refresh)
552 return;
553 globalconf.client_need_stack_refresh = false;
555 config_win_vals[0] = XCB_NONE;
556 config_win_vals[1] = XCB_STACK_MODE_ABOVE;
558 /* stack desktop windows */
559 for(layer = LAYER_DESKTOP; layer < LAYER_BELOW; layer++)
560 foreach(node, globalconf.stack)
561 if(client_layer_translator(*node) == layer)
562 config_win_vals[0] = client_stack_above(*node,
563 config_win_vals[0]);
565 /* first stack not ontop wibox window */
566 foreach(_sb, globalconf.wiboxes)
568 wibox_t *sb = *_sb;
569 if(!sb->ontop)
571 xcb_configure_window(globalconf.connection,
572 sb->window,
573 XCB_CONFIG_WINDOW_SIBLING | XCB_CONFIG_WINDOW_STACK_MODE,
574 config_win_vals);
575 config_win_vals[0] = sb->window;
579 /* then stack clients */
580 for(layer = LAYER_BELOW; layer < LAYER_COUNT; layer++)
581 foreach(node, globalconf.stack)
582 if(client_layer_translator(*node) == layer)
583 config_win_vals[0] = client_stack_above(*node,
584 config_win_vals[0]);
586 /* then stack ontop wibox window */
587 foreach(_sb, globalconf.wiboxes)
589 wibox_t *sb = *_sb;
590 if(sb->ontop)
592 xcb_configure_window(globalconf.connection,
593 sb->window,
594 XCB_CONFIG_WINDOW_SIBLING | XCB_CONFIG_WINDOW_STACK_MODE,
595 config_win_vals);
596 config_win_vals[0] = sb->window;
601 /** Manage a new client.
602 * \param w The window.
603 * \param wgeom Window geometry.
604 * \param phys_screen Physical screen number.
605 * \param startup True if we are managing at startup time.
607 void
608 client_manage(xcb_window_t w, xcb_get_geometry_reply_t *wgeom, int phys_screen, bool startup)
610 const uint32_t select_input_val[] = { CLIENT_SELECT_INPUT_EVENT_MASK };
612 if(systray_iskdedockapp(w))
614 systray_request_handle(w, phys_screen, NULL);
615 return;
618 /* If this is a new client that just has been launched, then request its
619 * startup id. */
620 xcb_get_property_cookie_t startup_id_q = { 0 };
621 if(!startup)
622 startup_id_q = xcb_get_property(globalconf.connection, false, w,
623 _NET_STARTUP_ID, XCB_GET_PROPERTY_TYPE_ANY, 0, UINT_MAX);
625 xcb_change_window_attributes(globalconf.connection, w, XCB_CW_EVENT_MASK, select_input_val);
627 /* Make sure the window is automatically mapped if awesome exits or dies. */
628 xcb_change_save_set(globalconf.connection, XCB_SET_MODE_INSERT, w);
630 /* Move this window to the bottom of the stack. Without this we would force
631 * other windows which will be above this one to redraw themselves because
632 * this window occludes them for a tiny moment. The next stack_refresh()
633 * will fix this up and move the window to its correct place. */
634 xcb_configure_window(globalconf.connection, w,
635 XCB_CONFIG_WINDOW_STACK_MODE,
636 (uint32_t[]) { XCB_STACK_MODE_BELOW});
638 client_t *c = client_new(globalconf.L);
640 /* This cannot change, ever. */
641 c->phys_screen = phys_screen;
642 /* consider the window banned */
643 c->isbanned = true;
644 /* Store window */
645 c->window = w;
646 luaA_object_emit_signal(globalconf.L, -1, "property::window", 0);
648 /* Duplicate client and push it in client list */
649 lua_pushvalue(globalconf.L, -1);
650 client_array_push(&globalconf.clients, luaA_object_ref(globalconf.L, -1));
652 /* Set the right screen */
653 screen_client_moveto(c, screen_getbycoord(&globalconf.screens.tab[phys_screen], wgeom->x, wgeom->y), false);
655 /* Store initial geometry and emits signals so we inform that geometry have
656 * been set. */
657 #define HANDLE_GEOM(attr) \
658 c->geometry.attr = wgeom->attr; \
659 c->geometries.internal.attr = wgeom->attr; \
660 luaA_object_emit_signal(globalconf.L, -1, "property::" #attr, 0);
661 HANDLE_GEOM(x)
662 HANDLE_GEOM(y)
663 HANDLE_GEOM(width)
664 HANDLE_GEOM(height)
665 #undef HANDLE_GEOM
667 luaA_object_emit_signal(globalconf.L, -1, "property::geometry", 0);
669 /* Push client */
670 client_set_border_width(globalconf.L, -1, wgeom->border_width);
672 /* we honor size hints by default */
673 c->size_hints_honor = true;
674 luaA_object_emit_signal(globalconf.L, -1, "property::size_hints_honor", 0);
676 /* update hints */
677 property_update_wm_normal_hints(c, NULL);
678 property_update_wm_hints(c, NULL);
679 property_update_wm_transient_for(c, NULL);
680 property_update_wm_client_leader(c, NULL);
681 property_update_wm_client_machine(c, NULL);
682 property_update_wm_window_role(c, NULL);
683 property_update_net_wm_pid(c, NULL);
684 property_update_net_wm_icon(c, NULL);
686 /* get opacity */
687 client_set_opacity(globalconf.L, -1, window_opacity_get(c->window));
689 /* Then check clients hints */
690 ewmh_client_check_hints(c);
692 /* Push client in stack */
693 client_raise(c);
695 /* update window title */
696 property_update_wm_name(c, NULL);
697 property_update_net_wm_name(c, NULL);
698 property_update_wm_icon_name(c, NULL);
699 property_update_net_wm_icon_name(c, NULL);
700 property_update_wm_class(c, NULL);
701 property_update_wm_protocols(c, NULL);
703 /* update strut */
704 ewmh_process_client_strut(c, NULL);
706 ewmh_update_net_client_list(c->phys_screen);
708 /* Always stay in NORMAL_STATE. Even though iconified seems more
709 * appropriate sometimes. The only possible loss is that clients not using
710 * visibility events may continue to process data (when banned).
711 * Without any exposes or other events the cost should be fairly limited though.
713 * Some clients may expect the window to be unmapped when STATE_ICONIFIED.
714 * Two conflicting parts of the ICCCM v2.0 (section 4.1.4):
716 * "Normal -> Iconic - The client should send a ClientMessage event as described later in this section."
717 * (note no explicit mention of unmapping, while Normal->Widthdrawn does mention that)
719 * "Once a client's window has left the Withdrawn state, the window will be mapped
720 * if it is in the Normal state and the window will be unmapped if it is in the Iconic state."
722 * At this stage it's just safer to keep it in normal state and avoid confusion.
724 window_state_set(c->window, XCB_WM_STATE_NORMAL);
726 if(!startup)
728 /* Request our response */
729 xcb_get_property_reply_t *reply =
730 xcb_get_property_reply(globalconf.connection, startup_id_q, NULL);
731 /* Say spawn that a client has been started, with startup id as argument */
732 char *startup_id = xutil_get_text_property_from_reply(reply);
733 p_delete(&reply);
734 spawn_start_notify(c, startup_id);
735 p_delete(&startup_id);
738 /* Call hook to notify list change */
739 if(globalconf.hooks.clients != LUA_REFNIL)
740 luaA_dofunction_from_registry(globalconf.L, globalconf.hooks.clients, 0, 0);
742 luaA_class_emit_signal(globalconf.L, &client_class, "list", 0);
744 /* call hook */
745 if(globalconf.hooks.manage != LUA_REFNIL)
747 luaA_object_push(globalconf.L, c);
748 lua_pushboolean(globalconf.L, startup);
749 luaA_dofunction_from_registry(globalconf.L, globalconf.hooks.manage, 2, 0);
752 /* client is still on top of the stack; push startup value,
753 * and emit signals with 2 args */
754 lua_pushboolean(globalconf.L, startup);
755 luaA_class_emit_signal(globalconf.L, &client_class, "manage", 2);
758 /** Compute client geometry with respect to its geometry hints.
759 * \param c The client.
760 * \param geometry The geometry that the client might receive.
761 * \return The geometry the client must take respecting its hints.
763 area_t
764 client_geometry_hints(client_t *c, area_t geometry)
766 int32_t basew, baseh, minw, minh;
767 int32_t real_basew = 0, real_baseh = 0;
769 /* base size is substituted with min size if not specified */
770 if(c->size_hints.flags & XCB_SIZE_HINT_P_SIZE)
772 basew = c->size_hints.base_width;
773 baseh = c->size_hints.base_height;
774 real_basew = basew;
775 real_baseh = baseh;
777 else if(c->size_hints.flags & XCB_SIZE_HINT_P_MIN_SIZE)
779 basew = c->size_hints.min_width;
780 baseh = c->size_hints.min_height;
782 else
783 basew = baseh = 0;
785 /* min size is substituted with base size if not specified */
786 if(c->size_hints.flags & XCB_SIZE_HINT_P_MIN_SIZE)
788 minw = c->size_hints.min_width;
789 minh = c->size_hints.min_height;
791 else if(c->size_hints.flags & XCB_SIZE_HINT_P_SIZE)
793 minw = c->size_hints.base_width;
794 minh = c->size_hints.base_height;
796 else
797 minw = minh = 0;
799 if(c->size_hints.flags & XCB_SIZE_HINT_P_ASPECT
800 && c->size_hints.min_aspect_den > 0
801 && c->size_hints.max_aspect_den > 0
802 && geometry.height - real_baseh > 0
803 && geometry.width - real_basew > 0)
805 /* ICCCM mandates:
806 * If a base size is provided along with the aspect ratio fields, the
807 * base size should be subtracted from the window size prior to checking
808 * that the aspect ratio falls in range. If a base size is not provided,
809 * nothing should be subtracted from the window size. (The minimum size
810 * is not to be used in place of the base size for this purpose.) */
811 double dx = (double) (geometry.width - real_basew);
812 double dy = (double) (geometry.height - real_baseh);
813 double min = (double) c->size_hints.min_aspect_num / (double) c->size_hints.min_aspect_den;
814 double max = (double) c->size_hints.max_aspect_num / (double) c->size_hints.max_aspect_den;
815 double ratio = dx / dy;
816 if(max > 0 && min > 0 && ratio > 0)
818 if(ratio < min)
820 /* dx is lower than allowed, make dy lower to compensate this
821 * (+ 0.5 to force proper rounding). */
822 dy = dx / min + 0.5;
823 geometry.width = (int) dx + real_basew;
824 geometry.height = (int) dy + real_baseh;
826 else if(ratio > max)
828 /* dx is too high, lower it (+0.5 for proper rounding) */
829 dx = dy * max + 0.5;
830 geometry.width = (int) dx + real_basew;
831 geometry.height = (int) dy + real_baseh;
836 if(minw)
837 geometry.width = MAX(geometry.width, minw);
838 if(minh)
839 geometry.height = MAX(geometry.height, minh);
841 if(c->size_hints.flags & XCB_SIZE_HINT_P_MAX_SIZE)
843 if(c->size_hints.max_width)
844 geometry.width = MIN(geometry.width, c->size_hints.max_width);
845 if(c->size_hints.max_height)
846 geometry.height = MIN(geometry.height, c->size_hints.max_height);
849 if(c->size_hints.flags & (XCB_SIZE_HINT_P_RESIZE_INC | XCB_SIZE_HINT_BASE_SIZE)
850 && c->size_hints.width_inc && c->size_hints.height_inc)
852 uint16_t t1 = geometry.width, t2 = geometry.height;
853 unsigned_subtract(t1, basew);
854 unsigned_subtract(t2, baseh);
855 geometry.width -= t1 % c->size_hints.width_inc;
856 geometry.height -= t2 % c->size_hints.height_inc;
859 return geometry;
862 /** Resize client window.
863 * The sizes given as parameters are with titlebar and borders!
864 * \param c Client to resize.
865 * \param geometry New window geometry.
866 * \param hints Use size hints.
867 * \return true if an actual resize occurred.
869 bool
870 client_resize(client_t *c, area_t geometry, bool hints)
872 area_t geometry_internal;
873 area_t area;
875 /* offscreen appearance fixes */
876 area = display_area_get(c->phys_screen);
878 if(geometry.x > area.width)
879 geometry.x = area.width - geometry.width;
880 if(geometry.y > area.height)
881 geometry.y = area.height - geometry.height;
882 if(geometry.x + geometry.width < 0)
883 geometry.x = 0;
884 if(geometry.y + geometry.height < 0)
885 geometry.y = 0;
887 /* Real client geometry, please keep it contained to C code at the very least. */
888 if (!c->fullscreen)
889 geometry_internal = titlebar_geometry_remove(c->titlebar, c->border_width, geometry);
890 else
891 geometry_internal = geometry;
893 if(hints && !c->fullscreen)
894 geometry_internal = client_geometry_hints(c, geometry_internal);
896 if(geometry_internal.width == 0 || geometry_internal.height == 0)
897 return false;
899 /* Also let client hints propagate to the "official" geometry. */
900 if (!c->fullscreen)
901 geometry = titlebar_geometry_add(c->titlebar, c->border_width, geometry_internal);
902 else
903 geometry = geometry_internal;
905 if(c->geometries.internal.x != geometry_internal.x
906 || c->geometries.internal.y != geometry_internal.y
907 || c->geometries.internal.width != geometry_internal.width
908 || c->geometries.internal.height != geometry_internal.height)
910 screen_t *new_screen = screen_getbycoord(c->screen,
911 geometry_internal.x, geometry_internal.y);
913 /* Values to configure a window is an array where values are
914 * stored according to 'value_mask' */
915 uint32_t values[4];
917 c->geometries.internal.x = values[0] = geometry_internal.x;
918 c->geometries.internal.y = values[1] = geometry_internal.y;
919 c->geometries.internal.width = values[2] = geometry_internal.width;
920 c->geometries.internal.height = values[3] = geometry_internal.height;
922 /* Also store geometry including border and titlebar. */
923 c->geometry = geometry;
925 titlebar_update_geometry(c);
927 /* Ignore all spurious enter/leave notify events */
928 client_ignore_enterleave_events();
930 xcb_configure_window(globalconf.connection, c->window,
931 XCB_CONFIG_WINDOW_X | XCB_CONFIG_WINDOW_Y
932 | XCB_CONFIG_WINDOW_WIDTH | XCB_CONFIG_WINDOW_HEIGHT,
933 values);
935 client_restore_enterleave_events();
937 screen_client_moveto(c, new_screen, false);
939 /* execute hook */
940 hook_property(c, "geometry");
942 luaA_object_push(globalconf.L, c);
943 luaA_object_emit_signal(globalconf.L, -1, "property::geometry", 0);
944 /** \todo This need to be VERIFIED before it is emitted! */
945 luaA_object_emit_signal(globalconf.L, -1, "property::x", 0);
946 luaA_object_emit_signal(globalconf.L, -1, "property::y", 0);
947 luaA_object_emit_signal(globalconf.L, -1, "property::width", 0);
948 luaA_object_emit_signal(globalconf.L, -1, "property::height", 0);
949 lua_pop(globalconf.L, 1);
951 return true;
954 return false;
957 /** Set a client minimized, or not.
958 * \param L The Lua VM state.
959 * \param cidx The client index.
960 * \param s Set or not the client minimized.
962 void
963 client_set_minimized(lua_State *L, int cidx, bool s)
965 client_t *c = luaA_client_checkudata(L, cidx);
967 if(c->minimized != s)
969 c->minimized = s;
970 banning_need_update((c)->screen);
971 if(s)
972 window_state_set(c->window, XCB_WM_STATE_ICONIC);
973 else
974 window_state_set(c->window, XCB_WM_STATE_NORMAL);
975 ewmh_client_update_hints(c);
976 if(strut_has_value(&c->strut))
977 screen_emit_signal(globalconf.L, c->screen, "property::workarea", 0);
978 /* execute hook */
979 hook_property(c, "minimized");
980 luaA_object_emit_signal(L, cidx, "property::minimized", 0);
984 /** Set a client sticky, or not.
985 * \param L The Lua VM state.
986 * \param cidx The client index.
987 * \param s Set or not the client sticky.
989 void
990 client_set_sticky(lua_State *L, int cidx, bool s)
992 client_t *c = luaA_client_checkudata(L, cidx);
994 if(c->sticky != s)
996 c->sticky = s;
997 banning_need_update((c)->screen);
998 ewmh_client_update_hints(c);
999 hook_property(c, "sticky");
1000 luaA_object_emit_signal(L, cidx, "property::sticky", 0);
1004 /** Set a client fullscreen, or not.
1005 * \param L The Lua VM state.
1006 * \param cidx The client index.
1007 * \param s Set or not the client fullscreen.
1009 void
1010 client_set_fullscreen(lua_State *L, int cidx, bool s)
1012 client_t *c = luaA_client_checkudata(L, cidx);
1014 if(c->fullscreen != s)
1016 area_t geometry;
1018 /* become fullscreen! */
1019 if(s)
1021 /* Make sure the current geometry is stored without titlebar. */
1022 titlebar_ban(c->titlebar);
1023 /* remove any max state */
1024 client_set_maximized_horizontal(L, cidx, false);
1025 client_set_maximized_vertical(L, cidx, false);
1026 /* You can only be part of one of the special layers. */
1027 client_set_below(L, cidx, false);
1028 client_set_above(L, cidx, false);
1029 client_set_ontop(L, cidx, false);
1031 geometry = screen_area_get(c->screen, false);
1032 c->geometries.fullscreen = c->geometry;
1033 c->border_width_fs = c->border_width;
1034 client_set_border_width(L, cidx, 0);
1035 c->fullscreen = true;
1037 else
1039 /* The titlebar was banned, unban! */
1040 titlebar_unban(c->titlebar);
1041 geometry = titlebar_geometry_add(c->titlebar, 0, c->geometries.fullscreen);
1042 c->fullscreen = false;
1043 client_set_border_width(L, cidx, c->border_width_fs);
1045 client_resize(c, geometry, false);
1046 client_stack();
1047 ewmh_client_update_hints(c);
1048 hook_property(c, "fullscreen");
1049 luaA_object_emit_signal(L, cidx, "property::fullscreen", 0);
1053 /** Set a client horizontally maximized.
1054 * \param L The Lua VM state.
1055 * \param cidx The client index.
1056 * \param s The maximized status.
1058 void
1059 client_set_maximized_horizontal(lua_State *L, int cidx, bool s)
1061 client_t *c = luaA_client_checkudata(L, cidx);
1063 if(c->maximized_horizontal != s)
1065 area_t geometry;
1067 if((c->maximized_horizontal = s))
1069 /* remove fullscreen mode */
1070 client_set_fullscreen(L, cidx, false);
1072 geometry = screen_area_get(c->screen, true);
1073 geometry.y = c->geometry.y;
1074 geometry.height = c->geometry.height;
1075 c->geometries.max.x = c->geometry.x;
1076 c->geometries.max.width = c->geometry.width;
1078 else
1080 geometry = c->geometry;
1081 geometry.x = c->geometries.max.x;
1082 geometry.width = c->geometries.max.width;
1085 client_resize(c, geometry, c->size_hints_honor);
1086 client_stack();
1087 ewmh_client_update_hints(c);
1088 hook_property(c, "maximized_horizontal");
1089 luaA_object_emit_signal(L, cidx, "property::maximized_horizontal", 0);
1093 /** Set a client vertically maximized.
1094 * \param L The Lua VM state.
1095 * \param cidx The client index.
1096 * \param s The maximized status.
1098 void
1099 client_set_maximized_vertical(lua_State *L, int cidx, bool s)
1101 client_t *c = luaA_client_checkudata(L, cidx);
1103 if(c->maximized_vertical != s)
1105 area_t geometry;
1107 if((c->maximized_vertical = s))
1109 /* remove fullscreen mode */
1110 client_set_fullscreen(L, cidx, false);
1112 geometry = screen_area_get(c->screen, true);
1113 geometry.x = c->geometry.x;
1114 geometry.width = c->geometry.width;
1115 c->geometries.max.y = c->geometry.y;
1116 c->geometries.max.height = c->geometry.height;
1118 else
1120 geometry = c->geometry;
1121 geometry.y = c->geometries.max.y;
1122 geometry.height = c->geometries.max.height;
1125 client_resize(c, geometry, c->size_hints_honor);
1126 client_stack();
1127 ewmh_client_update_hints(c);
1128 hook_property(c, "maximized_vertical");
1129 luaA_object_emit_signal(L, cidx, "property::maximized_vertical", 0);
1133 /** Set a client above, or not.
1134 * \param L The Lua VM state.
1135 * \param cidx The client index.
1136 * \param s Set or not the client above.
1138 void
1139 client_set_above(lua_State *L, int cidx, bool s)
1141 client_t *c = luaA_client_checkudata(L, cidx);
1143 if(c->above != s)
1145 /* You can only be part of one of the special layers. */
1146 if(s)
1148 client_set_below(L, cidx, false);
1149 client_set_ontop(L, cidx, false);
1150 client_set_fullscreen(L, cidx, false);
1152 c->above = s;
1153 client_stack();
1154 ewmh_client_update_hints(c);
1155 /* execute hook */
1156 hook_property(c, "above");
1157 luaA_object_emit_signal(L, cidx, "property::above", 0);
1161 /** Set a client below, or not.
1162 * \param L The Lua VM state.
1163 * \param cidx The client index.
1164 * \param s Set or not the client below.
1166 void
1167 client_set_below(lua_State *L, int cidx, bool s)
1169 client_t *c = luaA_client_checkudata(L, cidx);
1171 if(c->below != s)
1173 /* You can only be part of one of the special layers. */
1174 if(s)
1176 client_set_above(L, cidx, false);
1177 client_set_ontop(L, cidx, false);
1178 client_set_fullscreen(L, cidx, false);
1180 c->below = s;
1181 client_stack();
1182 ewmh_client_update_hints(c);
1183 /* execute hook */
1184 hook_property(c, "below");
1185 luaA_object_emit_signal(L, cidx, "property::below", 0);
1189 /** Set a client modal, or not.
1190 * \param L The Lua VM state.
1191 * \param cidx The client index.
1192 * \param s Set or not the client modal attribute.
1194 void
1195 client_set_modal(lua_State *L, int cidx, bool s)
1197 client_t *c = luaA_client_checkudata(L, cidx);
1199 if(c->modal != s)
1201 c->modal = s;
1202 client_stack();
1203 ewmh_client_update_hints(c);
1204 /* execute hook */
1205 hook_property(c, "modal");
1206 luaA_object_emit_signal(L, cidx, "property::modal", 0);
1210 /** Set a client ontop, or not.
1211 * \param L The Lua VM state.
1212 * \param cidx The client index.
1213 * \param s Set or not the client ontop attribute.
1215 void
1216 client_set_ontop(lua_State *L, int cidx, bool s)
1218 client_t *c = luaA_client_checkudata(L, cidx);
1220 if(c->ontop != s)
1222 /* You can only be part of one of the special layers. */
1223 if(s)
1225 client_set_above(L, cidx, false);
1226 client_set_below(L, cidx, false);
1227 client_set_fullscreen(L, cidx, false);
1229 c->ontop = s;
1230 client_stack();
1231 /* execute hook */
1232 hook_property(c, "ontop");
1233 luaA_object_emit_signal(L, cidx, "property::ontop", 0);
1237 /** Set a client skip taskbar attribute.
1238 * \param L Tha Lua VM state.
1239 * \param cidx The client index.
1240 * \param s Set or not the client skip taskbar attribute.
1242 void
1243 client_set_skip_taskbar(lua_State *L, int cidx, bool s)
1245 client_t *c = luaA_client_checkudata(L, cidx);
1247 if(c->skip_taskbar != s)
1249 c->skip_taskbar = s;
1250 ewmh_client_update_hints(c);
1251 luaA_object_emit_signal(L, cidx, "property::skip_taskbar", 0);
1255 /** Unban a client and move it back into the viewport.
1256 * \param c The client.
1258 void
1259 client_unban(client_t *c)
1261 if(c->isbanned)
1263 xcb_map_window(globalconf.connection, c->window);
1265 c->isbanned = false;
1267 /* An unbanned clients shouldn't be minimized */
1268 luaA_object_push(globalconf.L, c);
1269 client_set_minimized(globalconf.L, -1, false);
1270 lua_pop(globalconf.L, 1);
1274 /** Unmanage a client.
1275 * \param c The client.
1277 void
1278 client_unmanage(client_t *c)
1280 tag_array_t *tags = &c->screen->tags;
1282 /* Reset transient_for attributes of widows that maybe referring to us */
1283 foreach(_tc, globalconf.clients)
1285 client_t *tc = *_tc;
1286 if(tc->transient_for == c)
1287 tc->transient_for = NULL;
1290 if(globalconf.screens.tab[c->phys_screen].prev_client_focus == c)
1291 globalconf.screens.tab[c->phys_screen].prev_client_focus = NULL;
1293 if(globalconf.screens.tab[c->phys_screen].client_focus == c)
1294 client_unfocus(c);
1296 /* remove client from global list and everywhere else */
1297 foreach(elem, globalconf.clients)
1298 if(*elem == c)
1300 client_array_remove(&globalconf.clients, elem);
1301 break;
1303 stack_client_remove(c);
1304 for(int i = 0; i < tags->len; i++)
1305 untag_client(c, tags->tab[i]);
1307 /* call hook */
1308 if(globalconf.hooks.unmanage != LUA_REFNIL)
1310 luaA_object_push(globalconf.L, c);
1311 luaA_dofunction_from_registry(globalconf.L, globalconf.hooks.unmanage, 1, 0);
1314 luaA_object_push(globalconf.L, c);
1315 luaA_class_emit_signal(globalconf.L, &client_class, "unmanage", 1);
1317 /* Call hook to notify list change */
1318 if(globalconf.hooks.clients != LUA_REFNIL)
1319 luaA_dofunction_from_registry(globalconf.L, globalconf.hooks.clients, 0, 0);
1321 luaA_class_emit_signal(globalconf.L, &client_class, "list", 0);
1323 if(strut_has_value(&c->strut))
1324 screen_emit_signal(globalconf.L, c->screen, "property::workarea", 0);
1326 titlebar_client_detach(c);
1328 ewmh_update_net_client_list(c->phys_screen);
1330 /* Remove this window from the save set since this shouldn't be made visible
1331 * after a restart anymore. */
1332 xcb_change_save_set(globalconf.connection, XCB_SET_MODE_DELETE, c->window);
1334 /* Do this last to avoid races with clients. According to ICCCM, clients
1335 * arent allowed to re-use the window until after this. */
1336 window_state_set(c->window, XCB_WM_STATE_WITHDRAWN);
1338 /* set client as invalid */
1339 c->invalid = true;
1341 luaA_object_unref(globalconf.L, c);
1344 /** Kill a client via a WM_DELETE_WINDOW request or KillClient if not
1345 * supported.
1346 * \param c The client to kill.
1348 void
1349 client_kill(client_t *c)
1351 if(client_hasproto(c, WM_DELETE_WINDOW))
1353 xcb_client_message_event_t ev;
1355 /* Initialize all of event's fields first */
1356 p_clear(&ev, 1);
1358 ev.response_type = XCB_CLIENT_MESSAGE;
1359 ev.window = c->window;
1360 ev.format = 32;
1361 ev.data.data32[1] = globalconf.timestamp;
1362 ev.type = WM_PROTOCOLS;
1363 ev.data.data32[0] = WM_DELETE_WINDOW;
1365 xcb_send_event(globalconf.connection, false, c->window,
1366 XCB_EVENT_MASK_NO_EVENT, (char *) &ev);
1368 else
1369 xcb_kill_client(globalconf.connection, c->window);
1372 /** Get all clients into a table.
1373 * \param L The Lua VM state.
1374 * \return The number of elements pushed on stack.
1375 * \luastack
1376 * \lparam An optional screen number.
1377 * \lreturn A table with all clients.
1379 static int
1380 luaA_client_get(lua_State *L)
1382 int i = 1, screen;
1384 screen = luaL_optnumber(L, 1, 0) - 1;
1386 lua_newtable(L);
1388 if(screen == -1)
1389 foreach(c, globalconf.clients)
1391 luaA_object_push(L, *c);
1392 lua_rawseti(L, -2, i++);
1394 else
1396 luaA_checkscreen(screen);
1397 foreach(c, globalconf.clients)
1398 if((*c)->screen == &globalconf.screens.tab[screen])
1400 luaA_object_push(L, *c);
1401 lua_rawseti(L, -2, i++);
1405 return 1;
1408 /** Check if a client is visible on its screen.
1409 * \param L The Lua VM state.
1410 * \return The number of elements pushed on stack.
1411 * \luastack
1412 * \lvalue A client.
1413 * \lreturn A boolean value, true if the client is visible, false otherwise.
1415 static int
1416 luaA_client_isvisible(lua_State *L)
1418 client_t *c = luaA_client_checkudata(L, 1);
1419 lua_pushboolean(L, client_isvisible(c, c->screen));
1420 return 1;
1423 /** Set client border width.
1424 * \param L The Lua VM state.
1425 * \param cidx The client index.
1426 * \param width The border width.
1428 void
1429 client_set_border_width(lua_State *L, int cidx, int width)
1431 client_t *c = luaA_client_checkudata(L, cidx);
1432 uint32_t w = width;
1434 if(width > 0 && (c->type == WINDOW_TYPE_DOCK
1435 || c->type == WINDOW_TYPE_SPLASH
1436 || c->type == WINDOW_TYPE_DESKTOP
1437 || c->fullscreen))
1438 return;
1440 if(width == c->border_width || width < 0)
1441 return;
1443 /* disallow change of border width if the client is fullscreen */
1444 if(c->fullscreen)
1445 return;
1447 /* Update geometry with the new border. */
1448 c->geometry.width -= 2 * c->border_width;
1449 c->geometry.height -= 2 * c->border_width;
1451 c->border_width = width;
1452 xcb_configure_window(globalconf.connection, c->window,
1453 XCB_CONFIG_WINDOW_BORDER_WIDTH, &w);
1455 c->geometry.width += 2 * c->border_width;
1456 c->geometry.height += 2 * c->border_width;
1458 /* Changing border size also affects the size of the titlebar. */
1459 titlebar_update_geometry(c);
1461 hook_property(c, "border_width");
1462 luaA_object_emit_signal(L, cidx, "property::border_width", 0);
1465 /** Set a client icon.
1466 * \param L The Lua VM state.
1467 * \param cidx The client index on the stack.
1468 * \param iidx The image index on the stack.
1470 void
1471 client_set_icon(lua_State *L, int cidx, int iidx)
1473 client_t *c = luaA_client_checkudata(L, cidx);
1474 /* convert index to absolute */
1475 cidx = luaA_absindex(L, cidx);
1476 iidx = luaA_absindex(L, iidx);
1477 luaA_checkudata(L, iidx, &image_class);
1478 luaA_object_unref_item(L, cidx, c->icon);
1479 c->icon = luaA_object_ref_item(L, cidx, iidx);
1480 luaA_object_emit_signal(L, cidx < iidx ? cidx : cidx - 1, "property::icon", 0);
1481 /* execute hook */
1482 hook_property(c, "icon");
1485 /** Kill a client.
1486 * \param L The Lua VM state.
1488 * \luastack
1489 * \lvalue A client.
1491 static int
1492 luaA_client_kill(lua_State *L)
1494 client_t *c = luaA_client_checkudata(L, 1);
1495 client_kill(c);
1496 return 0;
1499 /** Swap a client with another one.
1500 * \param L The Lua VM state.
1501 * \luastack
1502 * \lvalue A client.
1503 * \lparam A client to swap with.
1505 static int
1506 luaA_client_swap(lua_State *L)
1508 client_t *c = luaA_client_checkudata(L, 1);
1509 client_t *swap = luaA_client_checkudata(L, 2);
1511 if(c != swap)
1513 client_t **ref_c = NULL, **ref_swap = NULL;
1514 foreach(item, globalconf.clients)
1516 if(*item == c)
1517 ref_c = item;
1518 else if(*item == swap)
1519 ref_swap = item;
1520 if(ref_c && ref_swap)
1521 break;
1523 /* swap ! */
1524 *ref_c = swap;
1525 *ref_swap = c;
1527 /* Call hook to notify list change */
1528 if(globalconf.hooks.clients != LUA_REFNIL)
1529 luaA_dofunction_from_registry(L, globalconf.hooks.clients, 0, 0);
1531 luaA_class_emit_signal(globalconf.L, &client_class, "list", 0);
1534 return 0;
1537 /** Access or set the client tags.
1538 * \param L The Lua VM state.
1539 * \return The number of elements pushed on stack.
1540 * \lparam A table with tags to set, or none to get the current tags table.
1541 * \return The clients tag.
1543 static int
1544 luaA_client_tags(lua_State *L)
1546 client_t *c = luaA_client_checkudata(L, 1);
1547 tag_array_t *tags = &c->screen->tags;
1548 int j = 0;
1550 if(lua_gettop(L) == 2)
1552 luaA_checktable(L, 2);
1553 for(int i = 0; i < tags->len; i++)
1555 /* Only untag if we aren't going to add this tag again */
1556 bool found = false;
1557 lua_pushnil(L);
1558 while(lua_next(L, 2))
1560 tag_t *t = lua_touserdata(L, -1);
1561 /* Pop the value from lua_next */
1562 lua_pop(L, 1);
1563 if (t != tags->tab[i])
1564 continue;
1566 /* Pop the key from lua_next */
1567 lua_pop(L, 1);
1568 found = true;
1569 break;
1571 if(!found)
1572 untag_client(c, tags->tab[i]);
1574 lua_pushnil(L);
1575 while(lua_next(L, 2))
1576 tag_client(c);
1577 lua_pop(L, 1);
1580 lua_newtable(L);
1581 foreach(tag, *tags)
1582 if(is_client_tagged(c, *tag))
1584 luaA_object_push(L, *tag);
1585 lua_rawseti(L, -2, ++j);
1588 return 1;
1591 /** Raise a client on top of others which are on the same layer.
1592 * \param L The Lua VM state.
1593 * \luastack
1594 * \lvalue A client.
1596 static int
1597 luaA_client_raise(lua_State *L)
1599 client_t *c = luaA_client_checkudata(L, 1);
1600 client_raise(c);
1601 return 0;
1604 /** Lower a client on bottom of others which are on the same layer.
1605 * \param L The Lua VM state.
1606 * \luastack
1607 * \lvalue A client.
1609 static int
1610 luaA_client_lower(lua_State *L)
1612 client_t *c = luaA_client_checkudata(L, 1);
1614 stack_client_push(c);
1616 /* Traverse all transient layers. */
1617 for(client_t *tc = c->transient_for; tc; tc = tc->transient_for)
1618 stack_client_push(tc);
1620 client_stack();
1622 return 0;
1625 /** Redraw a client by unmapping and mapping it quickly.
1626 * \param L The Lua VM state.
1628 * \luastack
1629 * \lvalue A client.
1631 static int
1632 luaA_client_redraw(lua_State *L)
1634 client_t *c = luaA_client_checkudata(L, 1);
1636 xcb_unmap_window(globalconf.connection, c->window);
1637 xcb_map_window(globalconf.connection, c->window);
1639 /* Set the focus on the current window if the redraw has been
1640 performed on the window where the pointer is currently on
1641 because after the unmapping/mapping, the focus is lost */
1642 if(globalconf.screen_focus->client_focus == c)
1644 client_unfocus(c);
1645 client_focus(c);
1648 return 0;
1651 /** Stop managing a client.
1652 * \param L The Lua VM state.
1653 * \return The number of elements pushed on stack.
1654 * \luastack
1655 * \lvalue A client.
1657 static int
1658 luaA_client_unmanage(lua_State *L)
1660 client_t *c = luaA_client_checkudata(L, 1);
1661 client_unmanage(c);
1662 return 0;
1665 /** Return client geometry.
1666 * \param L The Lua VM state.
1667 * \return The number of elements pushed on stack.
1668 * \luastack
1669 * \lparam A table with new coordinates, or none.
1670 * \lreturn A table with client coordinates.
1672 static int
1673 luaA_client_geometry(lua_State *L)
1675 client_t *c = luaA_client_checkudata(L, 1);
1677 if(lua_gettop(L) == 2 && !lua_isnil(L, 2))
1679 area_t geometry;
1681 luaA_checktable(L, 2);
1682 geometry.x = luaA_getopt_number(L, 2, "x", c->geometry.x);
1683 geometry.y = luaA_getopt_number(L, 2, "y", c->geometry.y);
1684 if(client_isfixed(c))
1686 geometry.width = c->geometry.width;
1687 geometry.height = c->geometry.height;
1689 else
1691 geometry.width = luaA_getopt_number(L, 2, "width", c->geometry.width);
1692 geometry.height = luaA_getopt_number(L, 2, "height", c->geometry.height);
1695 client_resize(c, geometry, c->size_hints_honor);
1698 return luaA_pusharea(L, c->geometry);
1701 /** Return client struts (reserved space at the edge of the screen).
1702 * \param L The Lua VM state.
1703 * \return The number of elements pushed on stack.
1704 * \luastack
1705 * \lparam A table with new strut values, or none.
1706 * \lreturn A table with strut values.
1708 static int
1709 luaA_client_struts(lua_State *L)
1711 client_t *c = luaA_client_checkudata(L, 1);
1713 if(lua_gettop(L) == 2)
1715 luaA_tostrut(L, 2, &c->strut);
1716 ewmh_update_strut(c->window, &c->strut);
1717 hook_property(c, "struts");
1718 luaA_object_emit_signal(L, 1, "property::struts", 0);
1719 screen_emit_signal(L, c->screen, "property::workarea", 0);
1722 return luaA_pushstrut(L, c->strut);
1725 static int
1726 luaA_client_set_screen(lua_State *L, client_t *c)
1728 if(globalconf.xinerama_is_active)
1730 int screen = luaL_checknumber(L, -1) - 1;
1731 luaA_checkscreen(screen);
1732 screen_client_moveto(c, &globalconf.screens.tab[screen], true);
1734 return 0;
1737 static int
1738 luaA_client_set_hidden(lua_State *L, client_t *c)
1740 bool b = luaA_checkboolean(L, -1);
1741 if(b != c->hidden)
1743 c->hidden = b;
1744 banning_need_update((c)->screen);
1745 hook_property(c, "hidden");
1746 if(strut_has_value(&c->strut))
1747 screen_emit_signal(globalconf.L, c->screen, "property::workarea", 0);
1748 luaA_object_emit_signal(L, -3, "property::hidden", 0);
1750 return 0;
1753 static int
1754 luaA_client_set_minimized(lua_State *L, client_t *c)
1756 client_set_minimized(L, -3, luaA_checkboolean(L, -1));
1757 return 0;
1760 static int
1761 luaA_client_set_fullscreen(lua_State *L, client_t *c)
1763 client_set_fullscreen(L, -3, luaA_checkboolean(L, -1));
1764 return 0;
1767 static int
1768 luaA_client_set_modal(lua_State *L, client_t *c)
1770 client_set_modal(L, -3, luaA_checkboolean(L, -1));
1771 return 0;
1774 static int
1775 luaA_client_set_maximized_horizontal(lua_State *L, client_t *c)
1777 client_set_maximized_horizontal(L, -3, luaA_checkboolean(L, -1));
1778 return 0;
1781 static int
1782 luaA_client_set_maximized_vertical(lua_State *L, client_t *c)
1784 client_set_maximized_vertical(L, -3, luaA_checkboolean(L, -1));
1785 return 0;
1788 static int
1789 luaA_client_set_icon(lua_State *L, client_t *c)
1791 client_set_icon(L, -3, -1);
1792 return 0;
1795 static int
1796 luaA_client_set_opacity(lua_State *L, client_t *c)
1798 if(lua_isnil(L, -1))
1799 client_set_opacity(L, -3, -1);
1800 else
1801 client_set_opacity(L, -3, luaL_checknumber(L, -1));
1802 return 0;
1805 static int
1806 luaA_client_set_sticky(lua_State *L, client_t *c)
1808 client_set_sticky(L, -3, luaA_checkboolean(L, -1));
1809 return 0;
1812 static int
1813 luaA_client_set_size_hints_honor(lua_State *L, client_t *c)
1815 c->size_hints_honor = luaA_checkboolean(L, -1);
1816 hook_property(c, "size_hints_honor");
1817 luaA_object_emit_signal(L, -3, "property::size_hints_honor", 0);
1818 return 0;
1821 static int
1822 luaA_client_set_border_width(lua_State *L, client_t *c)
1824 client_set_border_width(L, -3, luaL_checknumber(L, -1));
1825 return 0;
1828 static int
1829 luaA_client_set_ontop(lua_State *L, client_t *c)
1831 client_set_ontop(L, -3, luaA_checkboolean(L, -1));
1832 return 0;
1835 static int
1836 luaA_client_set_below(lua_State *L, client_t *c)
1838 client_set_below(L, -3, luaA_checkboolean(L, -1));
1839 return 0;
1842 static int
1843 luaA_client_set_above(lua_State *L, client_t *c)
1845 client_set_above(L, -3, luaA_checkboolean(L, -1));
1846 return 0;
1849 static int
1850 luaA_client_set_urgent(lua_State *L, client_t *c)
1852 client_set_urgent(L, -3, luaA_checkboolean(L, -1));
1853 return 0;
1856 static int
1857 luaA_client_set_border_color(lua_State *L, client_t *c)
1859 size_t len;
1860 const char *buf;
1861 if((buf = luaL_checklstring(L, -1, &len))
1862 && xcolor_init_reply(xcolor_init_unchecked(&c->border_color, buf, len)))
1864 xcb_change_window_attributes(globalconf.connection, c->window,
1865 XCB_CW_BORDER_PIXEL, &c->border_color.pixel);
1866 luaA_object_emit_signal(L, -3, "property::border_color", 0);
1868 return 0;
1871 static int
1872 luaA_client_set_titlebar(lua_State *L, client_t *c)
1874 if(lua_isnil(L, -1))
1875 titlebar_client_detach(c);
1876 else
1877 titlebar_client_attach(c);
1878 return 0;
1881 static int
1882 luaA_client_set_skip_taskbar(lua_State *L, client_t *c)
1884 client_set_skip_taskbar(L, -3, luaA_checkboolean(L, -1));
1885 return 0;
1888 static int
1889 luaA_client_get_name(lua_State *L, client_t *c)
1891 lua_pushstring(L, c->name ? c->name : c->alt_name);
1892 return 1;
1895 static int
1896 luaA_client_get_icon_name(lua_State *L, client_t *c)
1898 lua_pushstring(L, c->icon_name ? c->icon_name : c->alt_icon_name);
1899 return 1;
1902 LUA_OBJECT_EXPORT_PROPERTY(client, client_t, class, lua_pushstring)
1903 LUA_OBJECT_EXPORT_PROPERTY(client, client_t, instance, lua_pushstring)
1904 LUA_OBJECT_EXPORT_PROPERTY(client, client_t, machine, lua_pushstring)
1905 LUA_OBJECT_EXPORT_PROPERTY(client, client_t, role, lua_pushstring)
1906 LUA_OBJECT_EXPORT_PROPERTY(client, client_t, transient_for, luaA_object_push)
1907 LUA_OBJECT_EXPORT_PROPERTY(client, client_t, skip_taskbar, lua_pushboolean)
1908 LUA_OBJECT_EXPORT_PROPERTY(client, client_t, window, lua_pushnumber)
1909 LUA_OBJECT_EXPORT_PROPERTY(client, client_t, leader_window, lua_pushnumber)
1910 LUA_OBJECT_EXPORT_PROPERTY(client, client_t, group_window, lua_pushnumber)
1911 LUA_OBJECT_EXPORT_PROPERTY(client, client_t, pid, lua_pushnumber)
1912 LUA_OBJECT_EXPORT_PROPERTY(client, client_t, hidden, lua_pushboolean)
1913 LUA_OBJECT_EXPORT_PROPERTY(client, client_t, minimized, lua_pushboolean)
1914 LUA_OBJECT_EXPORT_PROPERTY(client, client_t, fullscreen, lua_pushboolean)
1915 LUA_OBJECT_EXPORT_PROPERTY(client, client_t, modal, lua_pushboolean)
1916 LUA_OBJECT_EXPORT_PROPERTY(client, client_t, ontop, lua_pushboolean)
1917 LUA_OBJECT_EXPORT_PROPERTY(client, client_t, urgent, lua_pushboolean)
1918 LUA_OBJECT_EXPORT_PROPERTY(client, client_t, above, lua_pushboolean)
1919 LUA_OBJECT_EXPORT_PROPERTY(client, client_t, below, lua_pushboolean)
1920 LUA_OBJECT_EXPORT_PROPERTY(client, client_t, sticky, lua_pushboolean)
1921 LUA_OBJECT_EXPORT_PROPERTY(client, client_t, size_hints_honor, lua_pushboolean)
1922 LUA_OBJECT_EXPORT_PROPERTY(client, client_t, maximized_horizontal, lua_pushboolean)
1923 LUA_OBJECT_EXPORT_PROPERTY(client, client_t, maximized_vertical, lua_pushboolean)
1924 LUA_OBJECT_EXPORT_PROPERTY(client, client_t, opacity, lua_pushnumber)
1925 LUA_OBJECT_EXPORT_PROPERTY(client, client_t, border_width, lua_pushnumber)
1926 LUA_OBJECT_EXPORT_PROPERTY(client, client_t, border_color, luaA_pushxcolor)
1928 static int
1929 luaA_client_get_content(lua_State *L, client_t *c)
1931 xcb_image_t *ximage = xcb_image_get(globalconf.connection,
1932 c->window,
1933 0, 0,
1934 c->geometries.internal.width,
1935 c->geometries.internal.height,
1936 ~0, XCB_IMAGE_FORMAT_Z_PIXMAP);
1937 int retval = 0;
1939 if(ximage)
1941 if(ximage->bpp >= 24)
1943 uint32_t *data = p_alloca(uint32_t, ximage->width * ximage->height);
1945 for(int y = 0; y < ximage->height; y++)
1946 for(int x = 0; x < ximage->width; x++)
1948 data[y * ximage->width + x] = xcb_image_get_pixel(ximage, x, y);
1949 data[y * ximage->width + x] |= 0xff000000; /* set alpha to 0xff */
1952 retval = image_new_from_argb32(ximage->width, ximage->height, data);
1954 xcb_image_destroy(ximage);
1957 return retval;
1960 static int
1961 luaA_client_get_type(lua_State *L, client_t *c)
1963 switch(c->type)
1965 case WINDOW_TYPE_DESKTOP:
1966 lua_pushliteral(L, "desktop");
1967 break;
1968 case WINDOW_TYPE_DOCK:
1969 lua_pushliteral(L, "dock");
1970 break;
1971 case WINDOW_TYPE_SPLASH:
1972 lua_pushliteral(L, "splash");
1973 break;
1974 case WINDOW_TYPE_DIALOG:
1975 lua_pushliteral(L, "dialog");
1976 break;
1977 case WINDOW_TYPE_MENU:
1978 lua_pushliteral(L, "menu");
1979 break;
1980 case WINDOW_TYPE_TOOLBAR:
1981 lua_pushliteral(L, "toolbar");
1982 break;
1983 case WINDOW_TYPE_UTILITY:
1984 lua_pushliteral(L, "utility");
1985 break;
1986 case WINDOW_TYPE_DROPDOWN_MENU:
1987 lua_pushliteral(L, "dropdown_menu");
1988 break;
1989 case WINDOW_TYPE_POPUP_MENU:
1990 lua_pushliteral(L, "popup_menu");
1991 break;
1992 case WINDOW_TYPE_TOOLTIP:
1993 lua_pushliteral(L, "tooltip");
1994 break;
1995 case WINDOW_TYPE_NOTIFICATION:
1996 lua_pushliteral(L, "notification");
1997 break;
1998 case WINDOW_TYPE_COMBO:
1999 lua_pushliteral(L, "combo");
2000 break;
2001 case WINDOW_TYPE_DND:
2002 lua_pushliteral(L, "dnd");
2003 break;
2004 case WINDOW_TYPE_NORMAL:
2005 lua_pushliteral(L, "normal");
2006 break;
2008 return 1;
2011 static int
2012 luaA_client_get_screen(lua_State *L, client_t *c)
2014 if(!c->screen)
2015 return 0;
2016 lua_pushnumber(L, 1 + screen_array_indexof(&globalconf.screens, c->screen));
2017 return 1;
2020 static int
2021 luaA_client_get_icon(lua_State *L, client_t *c)
2023 return luaA_object_push_item(L, -2, c->icon);
2026 static int
2027 luaA_client_get_titlebar(lua_State *L, client_t *c)
2029 return luaA_object_push(L, c->titlebar);
2032 static int
2033 luaA_client_get_focusable(lua_State *L, client_t *c)
2035 bool ret;
2037 /* A client can be focused if it doesnt have the "nofocus" hint...*/
2038 if (!c->nofocus)
2039 ret = true;
2040 else
2041 /* ...or if it knows the WM_TAKE_FOCUS protocol */
2042 ret = client_hasproto(c, WM_TAKE_FOCUS);
2044 lua_pushboolean(L, ret);
2045 return 1;
2048 static int
2049 luaA_client_get_size_hints(lua_State *L, client_t *c)
2051 const char *u_or_p = NULL;
2053 lua_createtable(L, 0, 1);
2055 if(c->size_hints.flags & XCB_SIZE_HINT_US_POSITION)
2056 u_or_p = "user_position";
2057 else if(c->size_hints.flags & XCB_SIZE_HINT_P_POSITION)
2058 u_or_p = "program_position";
2060 if(u_or_p)
2062 lua_createtable(L, 0, 2);
2063 lua_pushnumber(L, c->size_hints.x);
2064 lua_setfield(L, -2, "x");
2065 lua_pushnumber(L, c->size_hints.y);
2066 lua_setfield(L, -2, "y");
2067 lua_setfield(L, -2, u_or_p);
2068 u_or_p = NULL;
2071 if(c->size_hints.flags & XCB_SIZE_HINT_US_SIZE)
2072 u_or_p = "user_size";
2073 else if(c->size_hints.flags & XCB_SIZE_HINT_P_SIZE)
2074 u_or_p = "program_size";
2076 if(u_or_p)
2078 lua_createtable(L, 0, 2);
2079 lua_pushnumber(L, c->size_hints.width);
2080 lua_setfield(L, -2, "width");
2081 lua_pushnumber(L, c->size_hints.height);
2082 lua_setfield(L, -2, "height");
2083 lua_setfield(L, -2, u_or_p);
2086 if(c->size_hints.flags & XCB_SIZE_HINT_P_MIN_SIZE)
2088 lua_pushnumber(L, c->size_hints.min_width);
2089 lua_setfield(L, -2, "min_width");
2090 lua_pushnumber(L, c->size_hints.min_height);
2091 lua_setfield(L, -2, "min_height");
2094 if(c->size_hints.flags & XCB_SIZE_HINT_P_MAX_SIZE)
2096 lua_pushnumber(L, c->size_hints.max_width);
2097 lua_setfield(L, -2, "max_width");
2098 lua_pushnumber(L, c->size_hints.max_height);
2099 lua_setfield(L, -2, "max_height");
2102 if(c->size_hints.flags & XCB_SIZE_HINT_P_RESIZE_INC)
2104 lua_pushnumber(L, c->size_hints.width_inc);
2105 lua_setfield(L, -2, "width_inc");
2106 lua_pushnumber(L, c->size_hints.height_inc);
2107 lua_setfield(L, -2, "height_inc");
2110 if(c->size_hints.flags & XCB_SIZE_HINT_P_ASPECT)
2112 lua_pushnumber(L, c->size_hints.min_aspect_num);
2113 lua_setfield(L, -2, "min_aspect_num");
2114 lua_pushnumber(L, c->size_hints.min_aspect_den);
2115 lua_setfield(L, -2, "min_aspect_den");
2116 lua_pushnumber(L, c->size_hints.max_aspect_num);
2117 lua_setfield(L, -2, "max_aspect_num");
2118 lua_pushnumber(L, c->size_hints.max_aspect_den);
2119 lua_setfield(L, -2, "max_aspect_den");
2122 if(c->size_hints.flags & XCB_SIZE_HINT_BASE_SIZE)
2124 lua_pushnumber(L, c->size_hints.base_width);
2125 lua_setfield(L, -2, "base_width");
2126 lua_pushnumber(L, c->size_hints.base_height);
2127 lua_setfield(L, -2, "base_height");
2130 if(c->size_hints.flags & XCB_SIZE_HINT_P_WIN_GRAVITY)
2132 switch(c->size_hints.win_gravity)
2134 default:
2135 lua_pushliteral(L, "north_west");
2136 break;
2137 case XCB_GRAVITY_NORTH:
2138 lua_pushliteral(L, "north");
2139 break;
2140 case XCB_GRAVITY_NORTH_EAST:
2141 lua_pushliteral(L, "north_east");
2142 break;
2143 case XCB_GRAVITY_WEST:
2144 lua_pushliteral(L, "west");
2145 break;
2146 case XCB_GRAVITY_CENTER:
2147 lua_pushliteral(L, "center");
2148 break;
2149 case XCB_GRAVITY_EAST:
2150 lua_pushliteral(L, "east");
2151 break;
2152 case XCB_GRAVITY_SOUTH_WEST:
2153 lua_pushliteral(L, "south_west");
2154 break;
2155 case XCB_GRAVITY_SOUTH:
2156 lua_pushliteral(L, "south");
2157 break;
2158 case XCB_GRAVITY_SOUTH_EAST:
2159 lua_pushliteral(L, "south_east");
2160 break;
2161 case XCB_GRAVITY_STATIC:
2162 lua_pushliteral(L, "static");
2163 break;
2165 lua_setfield(L, -2, "win_gravity");
2168 return 1;
2171 /** Get or set mouse buttons bindings for a client.
2172 * \param L The Lua VM state.
2173 * \return The number of element pushed on stack.
2174 * \luastack
2175 * \lvalue A client.
2176 * \lparam An array of mouse button bindings objects, or nothing.
2177 * \return The array of mouse button bindings objects of this client.
2179 static int
2180 luaA_client_buttons(lua_State *L)
2182 client_t *client = luaA_client_checkudata(L, 1);
2183 button_array_t *buttons = &client->buttons;
2185 if(lua_gettop(L) == 2)
2187 luaA_button_array_set(L, 1, 2, buttons);
2188 luaA_object_emit_signal(L, 1, "property::buttons", 0);
2189 window_buttons_grab(client->window, &client->buttons);
2192 return luaA_button_array_get(L, 1, buttons);
2195 /** Get or set keys bindings for a client.
2196 * \param L The Lua VM state.
2197 * \return The number of element pushed on stack.
2198 * \luastack
2199 * \lvalue A client.
2200 * \lparam An array of key bindings objects, or nothing.
2201 * \return The array of key bindings objects of this client.
2203 static int
2204 luaA_client_keys(lua_State *L)
2206 client_t *c = luaA_client_checkudata(L, 1);
2207 key_array_t *keys = &c->keys;
2209 if(lua_gettop(L) == 2)
2211 luaA_key_array_set(L, 1, 2, keys);
2212 luaA_object_emit_signal(L, 1, "property::keys", 0);
2213 xcb_ungrab_key(globalconf.connection, XCB_GRAB_ANY, c->window, XCB_BUTTON_MASK_ANY);
2214 window_grabkeys(c->window, keys);
2217 return luaA_key_array_get(L, 1, keys);
2220 /* Client module.
2221 * \param L The Lua VM state.
2222 * \return The number of pushed elements.
2224 static int
2225 luaA_client_module_index(lua_State *L)
2227 size_t len;
2228 const char *buf = luaL_checklstring(L, 2, &len);
2230 switch(a_tokenize(buf, len))
2232 case A_TK_FOCUS:
2233 return luaA_object_push(globalconf.L, globalconf.screen_focus->client_focus);
2234 break;
2235 default:
2236 return 0;
2240 /* Client module new index.
2241 * \param L The Lua VM state.
2242 * \return The number of pushed elements.
2244 static int
2245 luaA_client_module_newindex(lua_State *L)
2247 size_t len;
2248 const char *buf = luaL_checklstring(L, 2, &len);
2249 client_t *c;
2251 switch(a_tokenize(buf, len))
2253 case A_TK_FOCUS:
2254 c = luaA_client_checkudata(L, 3);
2255 client_focus(c);
2256 break;
2257 default:
2258 break;
2261 return 0;
2264 void
2265 client_class_setup(lua_State *L)
2267 static const struct luaL_reg client_methods[] =
2269 LUA_CLASS_METHODS(client)
2270 { "get", luaA_client_get },
2271 { "__index", luaA_client_module_index },
2272 { "__newindex", luaA_client_module_newindex },
2273 { NULL, NULL }
2276 static const struct luaL_reg client_meta[] =
2278 LUA_OBJECT_META(client)
2279 LUA_CLASS_META
2280 { "buttons", luaA_client_buttons },
2281 { "keys", luaA_client_keys },
2282 { "isvisible", luaA_client_isvisible },
2283 { "geometry", luaA_client_geometry },
2284 { "struts", luaA_client_struts },
2285 { "tags", luaA_client_tags },
2286 { "kill", luaA_client_kill },
2287 { "swap", luaA_client_swap },
2288 { "raise", luaA_client_raise },
2289 { "lower", luaA_client_lower },
2290 { "redraw", luaA_client_redraw },
2291 { "unmanage", luaA_client_unmanage },
2292 { "__gc", luaA_client_gc },
2293 { NULL, NULL }
2296 luaA_class_setup(L, &client_class, "client", (lua_class_allocator_t) client_new,
2297 luaA_class_index_miss_property, luaA_class_newindex_miss_property,
2298 client_methods, client_meta);
2299 luaA_class_add_property(&client_class, A_TK_NAME,
2300 NULL,
2301 (lua_class_propfunc_t) luaA_client_get_name,
2302 NULL);
2303 luaA_class_add_property(&client_class, A_TK_TRANSIENT_FOR,
2304 NULL,
2305 (lua_class_propfunc_t) luaA_client_get_transient_for,
2306 NULL);
2307 luaA_class_add_property(&client_class, A_TK_SKIP_TASKBAR,
2308 (lua_class_propfunc_t) luaA_client_set_skip_taskbar,
2309 (lua_class_propfunc_t) luaA_client_get_skip_taskbar,
2310 (lua_class_propfunc_t) luaA_client_set_skip_taskbar);
2311 luaA_class_add_property(&client_class, A_TK_CONTENT,
2312 NULL,
2313 (lua_class_propfunc_t) luaA_client_get_content,
2314 NULL);
2315 luaA_class_add_property(&client_class, A_TK_TYPE,
2316 NULL,
2317 (lua_class_propfunc_t) luaA_client_get_type,
2318 NULL);
2319 luaA_class_add_property(&client_class, A_TK_CLASS,
2320 NULL,
2321 (lua_class_propfunc_t) luaA_client_get_class,
2322 NULL);
2323 luaA_class_add_property(&client_class, A_TK_INSTANCE,
2324 NULL,
2325 (lua_class_propfunc_t) luaA_client_get_instance,
2326 NULL);
2327 luaA_class_add_property(&client_class, A_TK_ROLE,
2328 NULL,
2329 (lua_class_propfunc_t) luaA_client_get_role,
2330 NULL);
2331 luaA_class_add_property(&client_class, A_TK_PID,
2332 NULL,
2333 (lua_class_propfunc_t) luaA_client_get_pid,
2334 NULL);
2335 luaA_class_add_property(&client_class, A_TK_WINDOW,
2336 NULL,
2337 (lua_class_propfunc_t) luaA_client_get_window,
2338 NULL);
2339 luaA_class_add_property(&client_class, A_TK_LEADER_WINDOW,
2340 NULL,
2341 (lua_class_propfunc_t) luaA_client_get_leader_window,
2342 NULL);
2343 luaA_class_add_property(&client_class, A_TK_MACHINE,
2344 NULL,
2345 (lua_class_propfunc_t) luaA_client_get_machine,
2346 NULL);
2347 luaA_class_add_property(&client_class, A_TK_ICON_NAME,
2348 NULL,
2349 (lua_class_propfunc_t) luaA_client_get_icon_name,
2350 NULL);
2351 luaA_class_add_property(&client_class, A_TK_SCREEN,
2352 NULL,
2353 (lua_class_propfunc_t) luaA_client_get_screen,
2354 (lua_class_propfunc_t) luaA_client_set_screen);
2355 luaA_class_add_property(&client_class, A_TK_HIDDEN,
2356 (lua_class_propfunc_t) luaA_client_set_hidden,
2357 (lua_class_propfunc_t) luaA_client_get_hidden,
2358 (lua_class_propfunc_t) luaA_client_set_hidden);
2359 luaA_class_add_property(&client_class, A_TK_MINIMIZED,
2360 (lua_class_propfunc_t) luaA_client_set_minimized,
2361 (lua_class_propfunc_t) luaA_client_get_minimized,
2362 (lua_class_propfunc_t) luaA_client_set_minimized);
2363 luaA_class_add_property(&client_class, A_TK_FULLSCREEN,
2364 (lua_class_propfunc_t) luaA_client_set_fullscreen,
2365 (lua_class_propfunc_t) luaA_client_get_fullscreen,
2366 (lua_class_propfunc_t) luaA_client_set_fullscreen);
2367 luaA_class_add_property(&client_class, A_TK_MODAL,
2368 (lua_class_propfunc_t) luaA_client_set_modal,
2369 (lua_class_propfunc_t) luaA_client_get_modal,
2370 (lua_class_propfunc_t) luaA_client_set_modal);
2371 luaA_class_add_property(&client_class, A_TK_GROUP_WINDOW,
2372 NULL,
2373 (lua_class_propfunc_t) luaA_client_get_group_window,
2374 NULL);
2375 luaA_class_add_property(&client_class, A_TK_MAXIMIZED_HORIZONTAL,
2376 (lua_class_propfunc_t) luaA_client_set_maximized_horizontal,
2377 (lua_class_propfunc_t) luaA_client_get_maximized_horizontal,
2378 (lua_class_propfunc_t) luaA_client_set_maximized_horizontal);
2379 luaA_class_add_property(&client_class, A_TK_MAXIMIZED_VERTICAL,
2380 (lua_class_propfunc_t) luaA_client_set_maximized_vertical,
2381 (lua_class_propfunc_t) luaA_client_get_maximized_vertical,
2382 (lua_class_propfunc_t) luaA_client_set_maximized_vertical);
2383 luaA_class_add_property(&client_class, A_TK_ICON,
2384 (lua_class_propfunc_t) luaA_client_set_icon,
2385 (lua_class_propfunc_t) luaA_client_get_icon,
2386 (lua_class_propfunc_t) luaA_client_set_icon);
2387 luaA_class_add_property(&client_class, A_TK_OPACITY,
2388 (lua_class_propfunc_t) luaA_client_set_opacity,
2389 (lua_class_propfunc_t) luaA_client_get_opacity,
2390 (lua_class_propfunc_t) luaA_client_set_opacity);
2391 luaA_class_add_property(&client_class, A_TK_ONTOP,
2392 (lua_class_propfunc_t) luaA_client_set_ontop,
2393 (lua_class_propfunc_t) luaA_client_get_ontop,
2394 (lua_class_propfunc_t) luaA_client_set_ontop);
2395 luaA_class_add_property(&client_class, A_TK_ABOVE,
2396 (lua_class_propfunc_t) luaA_client_set_above,
2397 (lua_class_propfunc_t) luaA_client_get_above,
2398 (lua_class_propfunc_t) luaA_client_set_above);
2399 luaA_class_add_property(&client_class, A_TK_BELOW,
2400 (lua_class_propfunc_t) luaA_client_set_below,
2401 (lua_class_propfunc_t) luaA_client_get_below,
2402 (lua_class_propfunc_t) luaA_client_set_below);
2403 luaA_class_add_property(&client_class, A_TK_STICKY,
2404 (lua_class_propfunc_t) luaA_client_set_sticky,
2405 (lua_class_propfunc_t) luaA_client_get_sticky,
2406 (lua_class_propfunc_t) luaA_client_set_sticky);
2407 luaA_class_add_property(&client_class, A_TK_SIZE_HINTS_HONOR,
2408 (lua_class_propfunc_t) luaA_client_set_size_hints_honor,
2409 (lua_class_propfunc_t) luaA_client_get_size_hints_honor,
2410 (lua_class_propfunc_t) luaA_client_set_size_hints_honor);
2411 luaA_class_add_property(&client_class, A_TK_BORDER_WIDTH,
2412 (lua_class_propfunc_t) luaA_client_set_border_width,
2413 (lua_class_propfunc_t) luaA_client_get_border_width,
2414 (lua_class_propfunc_t) luaA_client_set_border_width);
2415 luaA_class_add_property(&client_class, A_TK_BORDER_COLOR,
2416 (lua_class_propfunc_t) luaA_client_set_border_color,
2417 (lua_class_propfunc_t) luaA_client_get_border_color,
2418 (lua_class_propfunc_t) luaA_client_set_border_color);
2419 luaA_class_add_property(&client_class, A_TK_TITLEBAR,
2420 (lua_class_propfunc_t) luaA_client_set_titlebar,
2421 (lua_class_propfunc_t) luaA_client_get_titlebar,
2422 (lua_class_propfunc_t) luaA_client_set_titlebar);
2423 luaA_class_add_property(&client_class, A_TK_URGENT,
2424 (lua_class_propfunc_t) luaA_client_set_urgent,
2425 (lua_class_propfunc_t) luaA_client_get_urgent,
2426 (lua_class_propfunc_t) luaA_client_set_urgent);
2427 luaA_class_add_property(&client_class, A_TK_SIZE_HINTS,
2428 NULL,
2429 (lua_class_propfunc_t) luaA_client_get_size_hints,
2430 NULL);
2431 luaA_class_add_property(&client_class, A_TK_FOCUSABLE,
2432 NULL,
2433 (lua_class_propfunc_t) luaA_client_get_focusable,
2434 NULL);
2437 // vim: filetype=c:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=80