Fix wibox.layout.rotate
[awesome.git] / objects / client.c
blob4f912d893ea223ba44e293a747c1b85f5c3cd008
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>
24 #include <xcb/shape.h>
25 #include <cairo-xcb.h>
27 #include "objects/tag.h"
28 #include "ewmh.h"
29 #include "screen.h"
30 #include "systray.h"
31 #include "property.h"
32 #include "spawn.h"
33 #include "luaa.h"
34 #include "xwindow.h"
35 #include "common/atoms.h"
36 #include "common/xutil.h"
38 static area_t titlebar_get_area(client_t *c, client_titlebar_t bar);
39 static drawable_t *titlebar_get_drawable(lua_State *L, client_t *c, int cl_idx, client_titlebar_t bar);
41 /** Collect a client.
42 * \param L The Lua VM state.
43 * \return The number of element pushed on stack.
45 static void
46 client_wipe(client_t *c)
48 key_array_wipe(&c->keys);
49 xcb_icccm_get_wm_protocols_reply_wipe(&c->protocols);
50 p_delete(&c->machine);
51 p_delete(&c->class);
52 p_delete(&c->instance);
53 p_delete(&c->icon_name);
54 p_delete(&c->alt_icon_name);
55 p_delete(&c->name);
56 p_delete(&c->alt_name);
57 if(c->icon)
58 cairo_surface_destroy(c->icon);
61 /** Change the clients urgency flag.
62 * \param L The Lua VM state.
63 * \param cidx The client index on the stack.
64 * \param urgent The new flag state.
66 void
67 client_set_urgent(lua_State *L, int cidx, bool urgent)
69 client_t *c = luaA_checkudata(L, cidx, &client_class);
71 if(c->urgent != urgent)
73 xcb_get_property_cookie_t hints =
74 xcb_icccm_get_wm_hints_unchecked(globalconf.connection, c->window);
76 c->urgent = urgent;
78 /* update ICCCM hints */
79 xcb_icccm_wm_hints_t wmh;
80 xcb_icccm_get_wm_hints_reply(globalconf.connection, hints, &wmh, NULL);
82 if(urgent)
83 wmh.flags |= XCB_ICCCM_WM_HINT_X_URGENCY;
84 else
85 wmh.flags &= ~XCB_ICCCM_WM_HINT_X_URGENCY;
87 xcb_icccm_set_wm_hints(globalconf.connection, c->window, &wmh);
89 luaA_object_emit_signal(L, cidx, "property::urgent", 0);
93 #define DO_CLIENT_SET_PROPERTY(prop) \
94 void \
95 client_set_##prop(lua_State *L, int cidx, fieldtypeof(client_t, prop) value) \
96 { \
97 client_t *c = luaA_checkudata(L, cidx, &client_class); \
98 if(c->prop != value) \
99 { \
100 c->prop = value; \
101 luaA_object_emit_signal(L, cidx, "property::" #prop, 0); \
104 DO_CLIENT_SET_PROPERTY(group_window)
105 DO_CLIENT_SET_PROPERTY(type)
106 DO_CLIENT_SET_PROPERTY(transient_for)
107 DO_CLIENT_SET_PROPERTY(pid)
108 DO_CLIENT_SET_PROPERTY(skip_taskbar)
109 #undef DO_CLIENT_SET_PROPERTY
111 #define DO_CLIENT_SET_STRING_PROPERTY2(prop, signal) \
112 void \
113 client_set_##prop(lua_State *L, int cidx, char *value) \
115 client_t *c = luaA_checkudata(L, cidx, &client_class); \
116 p_delete(&c->prop); \
117 c->prop = value; \
118 luaA_object_emit_signal(L, cidx, "property::" #signal, 0); \
120 #define DO_CLIENT_SET_STRING_PROPERTY(prop) \
121 DO_CLIENT_SET_STRING_PROPERTY2(prop, prop)
122 DO_CLIENT_SET_STRING_PROPERTY(name)
123 DO_CLIENT_SET_STRING_PROPERTY2(alt_name, name)
124 DO_CLIENT_SET_STRING_PROPERTY(icon_name)
125 DO_CLIENT_SET_STRING_PROPERTY2(alt_icon_name, icon_name)
126 DO_CLIENT_SET_STRING_PROPERTY(role)
127 DO_CLIENT_SET_STRING_PROPERTY(machine)
128 #undef DO_CLIENT_SET_STRING_PROPERTY
130 void
131 client_set_class_instance(lua_State *L, int cidx, const char *class, const char *instance)
133 client_t *c = luaA_checkudata(L, cidx, &client_class);
134 p_delete(&c->class);
135 p_delete(&c->instance);
136 c->class = a_strdup(class);
137 luaA_object_emit_signal(L, cidx, "property::class", 0);
138 c->instance = a_strdup(instance);
139 luaA_object_emit_signal(L, cidx, "property::instance", 0);
142 /** Returns true if a client is tagged
143 * with one of the tags of the specified screen.
144 * \param c The client to check.
145 * \param screen Virtual screen.
146 * \return true if the client is visible, false otherwise.
148 bool
149 client_maybevisible(client_t *c)
151 if(c->sticky)
152 return true;
154 foreach(tag, globalconf.tags)
155 if(tag_get_selected(*tag) && is_client_tagged(c, *tag))
156 return true;
158 return false;
161 /** Get a client by its window.
162 * \param w The client window to find.
163 * \return A client pointer if found, NULL otherwise.
165 client_t *
166 client_getbywin(xcb_window_t w)
168 foreach(c, globalconf.clients)
169 if((*c)->window == w)
170 return *c;
172 return NULL;
175 /** Get a client by its frame window.
176 * \param w The client window to find.
177 * \return A client pointer if found, NULL otherwise.
179 client_t *
180 client_getbyframewin(xcb_window_t w)
182 foreach(c, globalconf.clients)
183 if((*c)->frame_window == w)
184 return *c;
186 return NULL;
189 /** Unfocus a client (internal).
190 * \param c The client.
192 static void
193 client_unfocus_internal(client_t *c)
195 globalconf.focus.client = NULL;
197 luaA_object_push(globalconf.L, c);
198 luaA_object_emit_signal(globalconf.L, -1, "unfocus", 0);
199 lua_pop(globalconf.L, 1);
202 /** Unfocus a client.
203 * \param c The client.
205 static void
206 client_unfocus(client_t *c)
208 client_unfocus_internal(c);
209 globalconf.focus.need_update = true;
212 /** Check if client supports atom a protocol in WM_PROTOCOL.
213 * \param c The client.
214 * \param atom The protocol atom to check for.
215 * \return True if client has the atom in protocol, false otherwise.
217 bool
218 client_hasproto(client_t *c, xcb_atom_t atom)
220 for(uint32_t i = 0; i < c->protocols.atoms_len; i++)
221 if(c->protocols.atoms[i] == atom)
222 return true;
223 return false;
226 /** Prepare banning a client by running all needed lua events.
227 * \param c The client.
229 void client_ban_unfocus(client_t *c)
231 /* Wait until the last moment to take away the focus from the window. */
232 if(globalconf.focus.client == c)
233 client_unfocus(c);
236 /** Ban client and move it out of the viewport.
237 * \param c The client.
239 void
240 client_ban(client_t *c)
242 if(!c->isbanned)
244 xcb_unmap_window(globalconf.connection, c->frame_window);
246 c->isbanned = true;
248 client_ban_unfocus(c);
252 /** This is part of The Bob Marley Algorithm: we ignore enter and leave window
253 * in certain cases, like map/unmap or move, so we don't get spurious events.
255 void
256 client_ignore_enterleave_events(void)
258 foreach(c, globalconf.clients)
260 xcb_change_window_attributes(globalconf.connection,
261 (*c)->window,
262 XCB_CW_EVENT_MASK,
263 (const uint32_t []) { CLIENT_SELECT_INPUT_EVENT_MASK & ~(XCB_EVENT_MASK_ENTER_WINDOW | XCB_EVENT_MASK_LEAVE_WINDOW) });
264 xcb_change_window_attributes(globalconf.connection,
265 (*c)->frame_window,
266 XCB_CW_EVENT_MASK,
267 (const uint32_t []) { FRAME_SELECT_INPUT_EVENT_MASK & ~(XCB_EVENT_MASK_ENTER_WINDOW | XCB_EVENT_MASK_LEAVE_WINDOW) });
271 void
272 client_restore_enterleave_events(void)
274 foreach(c, globalconf.clients)
276 xcb_change_window_attributes(globalconf.connection,
277 (*c)->window,
278 XCB_CW_EVENT_MASK,
279 (const uint32_t []) { CLIENT_SELECT_INPUT_EVENT_MASK });
280 xcb_change_window_attributes(globalconf.connection,
281 (*c)->frame_window,
282 XCB_CW_EVENT_MASK,
283 (const uint32_t []) { FRAME_SELECT_INPUT_EVENT_MASK });
287 /** Record that a client got focus.
288 * \param c The client.
290 void
291 client_focus_update(client_t *c)
293 if(!client_maybevisible(c))
294 return;
296 if(globalconf.focus.client)
298 if (globalconf.focus.client == c)
299 /* Already focused */
300 return;
302 /* When we are called due to a FocusIn event (=old focused client
303 * already unfocused), we don't want to cause a SetInputFocus,
304 * because the client which has focus now could be using globally
305 * active input model (or 'no input').
307 client_unfocus_internal(globalconf.focus.client);
310 globalconf.focus.client = c;
312 /* according to EWMH, we have to remove the urgent state from a client */
313 luaA_object_push(globalconf.L, c);
314 client_set_urgent(globalconf.L, -1, false);
316 luaA_object_emit_signal(globalconf.L, -1, "focus", 0);
317 lua_pop(globalconf.L, 1);
320 /** Give focus to client, or to first client if client is NULL.
321 * \param c The client.
323 void
324 client_focus(client_t *c)
326 /* We have to set focus on first client */
327 if(!c && globalconf.clients.len && !(c = globalconf.clients.tab[0]))
328 return;
330 if(!client_maybevisible(c) || c == globalconf.focus.client)
331 return;
333 client_focus_update(c);
334 globalconf.focus.need_update = true;
337 void
338 client_focus_refresh(void)
340 client_t *c = globalconf.focus.client;
341 xcb_window_t win = globalconf.screen->root;
343 if(!globalconf.focus.need_update)
344 return;
345 globalconf.focus.need_update = false;
347 if(c)
349 /* Make sure this window is unbanned and e.g. not minimized */
350 client_unban(c);
351 /* Sets focus on window - using xcb_set_input_focus or WM_TAKE_FOCUS */
352 if(!c->nofocus)
353 win = c->window;
354 else
355 /* Focus the root window to make sure the previously focused client
356 * doesn't get any input in case WM_TAKE_FOCUS gets ignored.
358 win = globalconf.screen->root;
360 if(client_hasproto(c, WM_TAKE_FOCUS))
361 xwindow_takefocus(c->window);
364 /* If nothing has the focused or the currently focused client doesn't want
365 * us to focus it, this sets the focus to the root window. This makes sure
366 * the previously focused client actually gets unfocused. Alternatively, the
367 * new client gets the input focus.
369 xcb_set_input_focus(globalconf.connection, XCB_INPUT_FOCUS_PARENT,
370 win, globalconf.timestamp);
373 static void
374 client_update_properties(client_t *c)
376 /* get all hints */
377 xcb_get_property_cookie_t wm_normal_hints = property_get_wm_normal_hints(c);
378 xcb_get_property_cookie_t wm_hints = property_get_wm_hints(c);
379 xcb_get_property_cookie_t wm_transient_for = property_get_wm_transient_for(c);
380 xcb_get_property_cookie_t wm_client_leader = property_get_wm_client_leader(c);
381 xcb_get_property_cookie_t wm_client_machine = property_get_wm_client_machine(c);
382 xcb_get_property_cookie_t wm_window_role = property_get_wm_window_role(c);
383 xcb_get_property_cookie_t net_wm_pid = property_get_net_wm_pid(c);
384 xcb_get_property_cookie_t net_wm_icon = property_get_net_wm_icon(c);
385 xcb_get_property_cookie_t wm_name = property_get_wm_name(c);
386 xcb_get_property_cookie_t net_wm_name = property_get_net_wm_name(c);
387 xcb_get_property_cookie_t wm_icon_name = property_get_wm_icon_name(c);
388 xcb_get_property_cookie_t net_wm_icon_name = property_get_net_wm_icon_name(c);
389 xcb_get_property_cookie_t wm_class = property_get_wm_class(c);
390 xcb_get_property_cookie_t wm_protocols = property_get_wm_protocols(c);
391 xcb_get_property_cookie_t opacity = xwindow_get_opacity_unchecked(c->window);
393 /* update strut */
394 ewmh_process_client_strut(c);
396 /* Now process all replies */
397 property_update_wm_normal_hints(c, wm_normal_hints);
398 property_update_wm_hints(c, wm_hints);
399 property_update_wm_transient_for(c, wm_transient_for);
400 property_update_wm_client_leader(c, wm_client_leader);
401 property_update_wm_client_machine(c, wm_client_machine);
402 property_update_wm_window_role(c, wm_window_role);
403 property_update_net_wm_pid(c, net_wm_pid);
404 property_update_net_wm_icon(c, net_wm_icon);
405 property_update_wm_name(c, wm_name);
406 property_update_net_wm_name(c, net_wm_name);
407 property_update_wm_icon_name(c, wm_icon_name);
408 property_update_net_wm_icon_name(c, net_wm_icon_name);
409 property_update_wm_class(c, wm_class);
410 property_update_wm_protocols(c, wm_protocols);
411 window_set_opacity(globalconf.L, -1, xwindow_get_opacity_from_cookie(opacity));
414 /** Manage a new client.
415 * \param w The window.
416 * \param wgeom Window geometry.
417 * \param startup True if we are managing at startup time.
419 void
420 client_manage(xcb_window_t w, xcb_get_geometry_reply_t *wgeom, bool startup)
422 const uint32_t select_input_val[] = { CLIENT_SELECT_INPUT_EVENT_MASK };
424 if(systray_iskdedockapp(w))
426 systray_request_handle(w, NULL);
427 return;
430 /* If this is a new client that just has been launched, then request its
431 * startup id. */
432 xcb_get_property_cookie_t startup_id_q = { 0 };
433 if(!startup)
434 startup_id_q = xcb_get_property(globalconf.connection, false, w,
435 _NET_STARTUP_ID, XCB_GET_PROPERTY_TYPE_ANY, 0, UINT_MAX);
437 /* Make sure the window is automatically mapped if awesome exits or dies. */
438 xcb_change_save_set(globalconf.connection, XCB_SET_MODE_INSERT, w);
440 client_t *c = client_new(globalconf.L);
441 xcb_screen_t *s = globalconf.screen;
443 /* consider the window banned */
444 c->isbanned = true;
445 /* Store window */
446 c->window = w;
447 c->frame_window = xcb_generate_id(globalconf.connection);
448 xcb_create_window(globalconf.connection, globalconf.default_depth, c->frame_window, s->root,
449 wgeom->x, wgeom->y, wgeom->width, wgeom->height,
450 wgeom->border_width, XCB_COPY_FROM_PARENT, globalconf.visual->visual_id,
451 XCB_CW_BACK_PIXEL | XCB_CW_BORDER_PIXEL | XCB_CW_BIT_GRAVITY
452 | XCB_CW_WIN_GRAVITY | XCB_CW_OVERRIDE_REDIRECT | XCB_CW_EVENT_MASK
453 | XCB_CW_COLORMAP,
454 (const uint32_t [])
456 globalconf.screen->black_pixel,
457 globalconf.screen->black_pixel,
458 XCB_GRAVITY_NORTH_WEST,
459 XCB_GRAVITY_NORTH_WEST,
461 FRAME_SELECT_INPUT_EVENT_MASK,
462 globalconf.default_cmap
465 if (startup)
467 /* The client is already mapped, thus we must be sure that we don't send
468 * ourselves an UnmapNotify due to the xcb_reparent_window().
470 * Grab the server to make sure we don't lose any events.
472 uint32_t no_event[] = { 0 };
473 xcb_grab_server(globalconf.connection);
475 xcb_change_window_attributes(globalconf.connection,
476 globalconf.screen->root,
477 XCB_CW_EVENT_MASK,
478 no_event);
481 xcb_reparent_window(globalconf.connection, w, c->frame_window, 0, 0);
482 xcb_map_window(globalconf.connection, w);
484 if (startup)
486 xcb_change_window_attributes(globalconf.connection,
487 globalconf.screen->root,
488 XCB_CW_EVENT_MASK,
489 ROOT_WINDOW_EVENT_MASK);
490 xcb_ungrab_server(globalconf.connection);
493 /* Do this now so that we don't get any events for the above
494 * (Else, reparent could cause an UnmapNotify) */
495 xcb_change_window_attributes(globalconf.connection, w, XCB_CW_EVENT_MASK, select_input_val);
497 luaA_object_emit_signal(globalconf.L, -1, "property::window", 0);
499 /* The frame window gets the border, not the real client window */
500 xcb_configure_window(globalconf.connection, w,
501 XCB_CONFIG_WINDOW_BORDER_WIDTH,
502 (uint32_t[]) { 0 });
504 /* Move this window to the bottom of the stack. Without this we would force
505 * other windows which will be above this one to redraw themselves because
506 * this window occludes them for a tiny moment. The next stack_refresh()
507 * will fix this up and move the window to its correct place. */
508 xcb_configure_window(globalconf.connection, c->frame_window,
509 XCB_CONFIG_WINDOW_STACK_MODE,
510 (uint32_t[]) { XCB_STACK_MODE_BELOW});
512 /* Duplicate client and push it in client list */
513 lua_pushvalue(globalconf.L, -1);
514 client_array_push(&globalconf.clients, luaA_object_ref(globalconf.L, -1));
516 /* Set the right screen */
517 screen_client_moveto(c, screen_getbycoord(wgeom->x, wgeom->y), false);
519 /* Store initial geometry and emits signals so we inform that geometry have
520 * been set. */
521 #define HANDLE_GEOM(attr) \
522 c->geometry.attr = wgeom->attr; \
523 luaA_object_emit_signal(globalconf.L, -1, "property::" #attr, 0);
524 HANDLE_GEOM(x)
525 HANDLE_GEOM(y)
526 HANDLE_GEOM(width)
527 HANDLE_GEOM(height)
528 #undef HANDLE_GEOM
530 luaA_object_emit_signal(globalconf.L, -1, "property::geometry", 0);
532 /* Set border width */
533 window_set_border_width(globalconf.L, -1, wgeom->border_width);
535 /* we honor size hints by default */
536 c->size_hints_honor = true;
537 luaA_object_emit_signal(globalconf.L, -1, "property::size_hints_honor", 0);
539 /* update all properties */
540 client_update_properties(c);
542 /* Then check clients hints */
543 ewmh_client_check_hints(c);
545 /* Push client in stack */
546 client_raise(c);
548 /* Always stay in NORMAL_STATE. Even though iconified seems more
549 * appropriate sometimes. The only possible loss is that clients not using
550 * visibility events may continue to process data (when banned).
551 * Without any exposes or other events the cost should be fairly limited though.
553 * Some clients may expect the window to be unmapped when STATE_ICONIFIED.
554 * Two conflicting parts of the ICCCM v2.0 (section 4.1.4):
556 * "Normal -> Iconic - The client should send a ClientMessage event as described later in this section."
557 * (note no explicit mention of unmapping, while Normal->Widthdrawn does mention that)
559 * "Once a client's window has left the Withdrawn state, the window will be mapped
560 * if it is in the Normal state and the window will be unmapped if it is in the Iconic state."
562 * At this stage it's just safer to keep it in normal state and avoid confusion.
564 xwindow_set_state(c->window, XCB_ICCCM_WM_STATE_NORMAL);
566 if(!startup)
568 /* Request our response */
569 xcb_get_property_reply_t *reply =
570 xcb_get_property_reply(globalconf.connection, startup_id_q, NULL);
571 /* Say spawn that a client has been started, with startup id as argument */
572 char *startup_id = xutil_get_text_property_from_reply(reply);
573 p_delete(&reply);
574 spawn_start_notify(c, startup_id);
575 p_delete(&startup_id);
578 luaA_class_emit_signal(globalconf.L, &client_class, "list", 0);
580 /* client is still on top of the stack; push startup value,
581 * and emit signals with one arg */
582 lua_pushboolean(globalconf.L, startup);
583 luaA_object_emit_signal(globalconf.L, -2, "manage", 1);
584 /* pop client */
585 lua_pop(globalconf.L, 1);
588 /** Send a synthetic configure event to a window.
590 void
591 client_send_configure(client_t *c)
593 area_t geometry = c->geometry;
594 geometry.x += c->titlebar[CLIENT_TITLEBAR_LEFT].size;
595 geometry.y += c->titlebar[CLIENT_TITLEBAR_TOP].size;
596 geometry.width -= c->titlebar[CLIENT_TITLEBAR_LEFT].size;
597 geometry.width -= c->titlebar[CLIENT_TITLEBAR_RIGHT].size;
598 geometry.height -= c->titlebar[CLIENT_TITLEBAR_TOP].size;
599 geometry.height -= c->titlebar[CLIENT_TITLEBAR_BOTTOM].size;
601 xwindow_configure(c->window, geometry, c->border_width);
604 static void
605 client_resize_do(client_t *c, area_t geometry, bool force_notice)
607 bool send_notice = force_notice;
608 bool hide_titlebars = c->fullscreen;
609 screen_t *new_screen = screen_getbycoord(geometry.x, geometry.y);
611 if(c->geometry.width == geometry.width
612 && c->geometry.height == geometry.height)
613 send_notice = true;
615 /* Also store geometry including border */
616 area_t old_geometry = c->geometry;
617 c->geometry = geometry;
619 /* Ignore all spurious enter/leave notify events */
620 client_ignore_enterleave_events();
622 /* Configure the client for its new size */
623 area_t real_geometry = geometry;
624 if (!hide_titlebars)
626 real_geometry.x = c->titlebar[CLIENT_TITLEBAR_LEFT].size;
627 real_geometry.y = c->titlebar[CLIENT_TITLEBAR_TOP].size;
628 real_geometry.width -= c->titlebar[CLIENT_TITLEBAR_LEFT].size;
629 real_geometry.width -= c->titlebar[CLIENT_TITLEBAR_RIGHT].size;
630 real_geometry.height -= c->titlebar[CLIENT_TITLEBAR_TOP].size;
631 real_geometry.height -= c->titlebar[CLIENT_TITLEBAR_BOTTOM].size;
632 } else {
633 real_geometry.x = 0;
634 real_geometry.y = 0;
637 xcb_configure_window(globalconf.connection, c->frame_window,
638 XCB_CONFIG_WINDOW_X | XCB_CONFIG_WINDOW_Y | XCB_CONFIG_WINDOW_WIDTH | XCB_CONFIG_WINDOW_HEIGHT,
639 (uint32_t[]) { geometry.x, geometry.y, geometry.width, geometry.height });
640 xcb_configure_window(globalconf.connection, c->window,
641 XCB_CONFIG_WINDOW_X | XCB_CONFIG_WINDOW_Y | XCB_CONFIG_WINDOW_WIDTH | XCB_CONFIG_WINDOW_HEIGHT,
642 (uint32_t[]) { real_geometry.x, real_geometry.y, real_geometry.width, real_geometry.height });
644 if(send_notice)
645 /* We are moving without changing the size, see ICCCM 4.2.3 */
646 client_send_configure(c);
648 client_restore_enterleave_events();
650 screen_client_moveto(c, new_screen, false);
652 luaA_object_push(globalconf.L, c);
653 luaA_object_emit_signal(globalconf.L, -1, "property::geometry", 0);
654 if (old_geometry.x != geometry.x)
655 luaA_object_emit_signal(globalconf.L, -1, "property::x", 0);
656 if (old_geometry.y != geometry.y)
657 luaA_object_emit_signal(globalconf.L, -1, "property::y", 0);
658 if (old_geometry.width != geometry.width)
659 luaA_object_emit_signal(globalconf.L, -1, "property::width", 0);
660 if (old_geometry.height != geometry.height)
661 luaA_object_emit_signal(globalconf.L, -1, "property::height", 0);
662 lua_pop(globalconf.L, 1);
664 /* Update all titlebars */
665 for (client_titlebar_t bar = CLIENT_TITLEBAR_TOP; bar < CLIENT_TITLEBAR_COUNT; bar++) {
666 if (c->titlebar[bar].drawable == NULL && c->titlebar[bar].size == 0)
667 continue;
669 luaA_object_push(globalconf.L, c);
670 drawable_t *drawable = titlebar_get_drawable(globalconf.L, c, -1, bar);
672 /* Get rid of the old state */
673 luaA_object_push_item(globalconf.L, -1, drawable);
674 drawable_set_surface(drawable, -1, NULL);
675 if (c->titlebar[bar].pixmap != XCB_NONE)
676 xcb_free_pixmap(globalconf.connection, c->titlebar[bar].pixmap);
677 c->titlebar[bar].pixmap = XCB_NONE;
679 /* And get us some new state */
680 area_t area = titlebar_get_area(c, bar);
681 if (c->titlebar[bar].size != 0 && !hide_titlebars)
683 c->titlebar[bar].pixmap = xcb_generate_id(globalconf.connection);
684 xcb_create_pixmap(globalconf.connection, globalconf.default_depth, c->titlebar[bar].pixmap,
685 globalconf.screen->root, area.width, area.height);
686 cairo_surface_t *surface = cairo_xcb_surface_create(globalconf.connection,
687 c->titlebar[bar].pixmap, globalconf.visual,
688 area.width, area.height);
689 drawable_set_surface(drawable, -1, surface);
692 /* Convert to global coordinates */
693 area.x += geometry.x;
694 area.y += geometry.y;
695 if (hide_titlebars)
696 area.width = area.height = 0;
697 drawable_set_geometry(drawable, -1, area);
699 /* Pop the client and the drawable */
700 lua_pop(globalconf.L, 2);
704 /** Resize client window.
705 * The sizes given as parameters are with borders!
706 * \param c Client to resize.
707 * \param geometry New window geometry.
708 * \param hints Use size hints.
709 * \return true if an actual resize occurred.
711 bool
712 client_resize(client_t *c, area_t geometry)
714 area_t area;
716 /* offscreen appearance fixes */
717 area = display_area_get();
719 if(geometry.x > area.width)
720 geometry.x = area.width - geometry.width;
721 if(geometry.y > area.height)
722 geometry.y = area.height - geometry.height;
723 if(geometry.x + geometry.width < 0)
724 geometry.x = 0;
725 if(geometry.y + geometry.height < 0)
726 geometry.y = 0;
728 if(geometry.width < c->titlebar[CLIENT_TITLEBAR_LEFT].size + c->titlebar[CLIENT_TITLEBAR_RIGHT].size)
729 return false;
730 if(geometry.height < c->titlebar[CLIENT_TITLEBAR_TOP].size + c->titlebar[CLIENT_TITLEBAR_BOTTOM].size)
731 return false;
733 if(geometry.width == 0 || geometry.height == 0)
734 return false;
736 if(c->geometry.x != geometry.x
737 || c->geometry.y != geometry.y
738 || c->geometry.width != geometry.width
739 || c->geometry.height != geometry.height)
741 client_resize_do(c, geometry, false);
743 return true;
746 return false;
749 /** Set a client minimized, or not.
750 * \param L The Lua VM state.
751 * \param cidx The client index.
752 * \param s Set or not the client minimized.
754 void
755 client_set_minimized(lua_State *L, int cidx, bool s)
757 client_t *c = luaA_checkudata(L, cidx, &client_class);
759 if(c->minimized != s)
761 c->minimized = s;
762 banning_need_update();
763 if(s)
764 xwindow_set_state(c->window, XCB_ICCCM_WM_STATE_ICONIC);
765 else
766 xwindow_set_state(c->window, XCB_ICCCM_WM_STATE_NORMAL);
767 if(strut_has_value(&c->strut))
768 screen_emit_signal(globalconf.L, c->screen, "property::workarea", 0);
769 luaA_object_emit_signal(L, cidx, "property::minimized", 0);
773 /** Set a client hidden, or not.
774 * \param L The Lua VM state.
775 * \param cidx The client index.
776 * \param s Set or not the client hidden.
778 static void
779 client_set_hidden(lua_State *L, int cidx, bool s)
781 client_t *c = luaA_checkudata(L, cidx, &client_class);
783 if(c->hidden != s)
785 c->hidden = s;
786 banning_need_update();
787 if(strut_has_value(&c->strut))
788 screen_emit_signal(globalconf.L, c->screen, "property::workarea", 0);
789 luaA_object_emit_signal(L, cidx, "property::hidden", 0);
793 /** Set a client sticky, or not.
794 * \param L The Lua VM state.
795 * \param cidx The client index.
796 * \param s Set or not the client sticky.
798 void
799 client_set_sticky(lua_State *L, int cidx, bool s)
801 client_t *c = luaA_checkudata(L, cidx, &client_class);
803 if(c->sticky != s)
805 c->sticky = s;
806 banning_need_update();
807 luaA_object_emit_signal(L, cidx, "property::sticky", 0);
811 /** Set a client fullscreen, or not.
812 * \param L The Lua VM state.
813 * \param cidx The client index.
814 * \param s Set or not the client fullscreen.
816 void
817 client_set_fullscreen(lua_State *L, int cidx, bool s)
819 client_t *c = luaA_checkudata(L, cidx, &client_class);
821 if(c->fullscreen != s)
823 /* become fullscreen! */
824 if(s)
826 /* remove any max state */
827 client_set_maximized_horizontal(L, cidx, false);
828 client_set_maximized_vertical(L, cidx, false);
829 /* You can only be part of one of the special layers. */
830 client_set_below(L, cidx, false);
831 client_set_above(L, cidx, false);
832 client_set_ontop(L, cidx, false);
834 int abs_cidx = luaA_absindex(L, cidx); \
835 lua_pushboolean(L, s);
836 c->fullscreen = s;
837 luaA_object_emit_signal(L, abs_cidx, "request::fullscreen", 1);
838 luaA_object_emit_signal(L, abs_cidx, "property::fullscreen", 0);
839 /* Force a client resize, so that titlebars get shown/hidden */
840 client_resize_do(c, c->geometry, true);
841 stack_windows();
845 /** Set a client horizontally|vertically maximized.
846 * \param L The Lua VM state.
847 * \param cidx The client index.
848 * \param s The maximized status.
850 #define DO_FUNCTION_CLIENT_MAXIMIZED(type) \
851 void \
852 client_set_maximized_##type(lua_State *L, int cidx, bool s) \
854 client_t *c = luaA_checkudata(L, cidx, &client_class); \
855 if(c->maximized_##type != s) \
857 int abs_cidx = luaA_absindex(L, cidx); \
858 if(s) \
859 client_set_fullscreen(L, abs_cidx, false); \
860 lua_pushboolean(L, s); \
861 c->maximized_##type = s; \
862 luaA_object_emit_signal(L, abs_cidx, "request::maximized_" #type, 1); \
863 luaA_object_emit_signal(L, abs_cidx, "property::maximized_" #type, 0); \
864 stack_windows(); \
867 DO_FUNCTION_CLIENT_MAXIMIZED(vertical)
868 DO_FUNCTION_CLIENT_MAXIMIZED(horizontal)
869 #undef DO_FUNCTION_CLIENT_MAXIMIZED
871 /** Set a client above, or not.
872 * \param L The Lua VM state.
873 * \param cidx The client index.
874 * \param s Set or not the client above.
876 void
877 client_set_above(lua_State *L, int cidx, bool s)
879 client_t *c = luaA_checkudata(L, cidx, &client_class);
881 if(c->above != s)
883 /* You can only be part of one of the special layers. */
884 if(s)
886 client_set_below(L, cidx, false);
887 client_set_ontop(L, cidx, false);
888 client_set_fullscreen(L, cidx, false);
890 c->above = s;
891 stack_windows();
892 luaA_object_emit_signal(L, cidx, "property::above", 0);
896 /** Set a client below, or not.
897 * \param L The Lua VM state.
898 * \param cidx The client index.
899 * \param s Set or not the client below.
901 void
902 client_set_below(lua_State *L, int cidx, bool s)
904 client_t *c = luaA_checkudata(L, cidx, &client_class);
906 if(c->below != s)
908 /* You can only be part of one of the special layers. */
909 if(s)
911 client_set_above(L, cidx, false);
912 client_set_ontop(L, cidx, false);
913 client_set_fullscreen(L, cidx, false);
915 c->below = s;
916 stack_windows();
917 luaA_object_emit_signal(L, cidx, "property::below", 0);
921 /** Set a client modal, or not.
922 * \param L The Lua VM state.
923 * \param cidx The client index.
924 * \param s Set or not the client modal attribute.
926 void
927 client_set_modal(lua_State *L, int cidx, bool s)
929 client_t *c = luaA_checkudata(L, cidx, &client_class);
931 if(c->modal != s)
933 c->modal = s;
934 stack_windows();
935 luaA_object_emit_signal(L, cidx, "property::modal", 0);
939 /** Set a client ontop, or not.
940 * \param L The Lua VM state.
941 * \param cidx The client index.
942 * \param s Set or not the client ontop attribute.
944 void
945 client_set_ontop(lua_State *L, int cidx, bool s)
947 client_t *c = luaA_checkudata(L, cidx, &client_class);
949 if(c->ontop != s)
951 /* You can only be part of one of the special layers. */
952 if(s)
954 client_set_above(L, cidx, false);
955 client_set_below(L, cidx, false);
956 client_set_fullscreen(L, cidx, false);
958 c->ontop = s;
959 stack_windows();
960 luaA_object_emit_signal(L, cidx, "property::ontop", 0);
964 /** Unban a client and move it back into the viewport.
965 * \param c The client.
967 void
968 client_unban(client_t *c)
970 if(c->isbanned)
972 xcb_map_window(globalconf.connection, c->frame_window);
974 c->isbanned = false;
976 /* An unbanned client shouldn't be minimized or hidden */
977 luaA_object_push(globalconf.L, c);
978 client_set_minimized(globalconf.L, -1, false);
979 client_set_hidden(globalconf.L, -1, false);
980 lua_pop(globalconf.L, 1);
984 /** Unmanage a client.
985 * \param c The client.
986 * \param window_valid Is the client's window still valid?
988 void
989 client_unmanage(client_t *c, bool window_valid)
991 /* Reset transient_for attributes of widows that maybe referring to us */
992 foreach(_tc, globalconf.clients)
994 client_t *tc = *_tc;
995 if(tc->transient_for == c)
996 tc->transient_for = NULL;
999 if(globalconf.focus.client == c)
1000 client_unfocus(c);
1002 /* remove client from global list and everywhere else */
1003 foreach(elem, globalconf.clients)
1004 if(*elem == c)
1006 client_array_remove(&globalconf.clients, elem);
1007 break;
1009 stack_client_remove(c);
1010 for(int i = 0; i < globalconf.tags.len; i++)
1011 untag_client(c, globalconf.tags.tab[i]);
1013 luaA_object_push(globalconf.L, c);
1014 luaA_object_emit_signal(globalconf.L, -1, "unmanage", 0);
1015 lua_pop(globalconf.L, 1);
1017 luaA_class_emit_signal(globalconf.L, &client_class, "list", 0);
1019 if(strut_has_value(&c->strut))
1020 screen_emit_signal(globalconf.L, c->screen, "property::workarea", 0);
1022 /* Get rid of all titlebars */
1023 for (client_titlebar_t bar = CLIENT_TITLEBAR_TOP; bar < CLIENT_TITLEBAR_COUNT; bar++) {
1024 if (c->titlebar[bar].drawable == NULL)
1025 continue;
1027 luaA_object_push(globalconf.L, c);
1028 luaA_object_push_item(globalconf.L, -1, c->titlebar[bar].drawable);
1030 /* Make the drawable unusable */
1031 drawable_set_surface(c->titlebar[bar].drawable, -1, NULL);
1032 if (c->titlebar[bar].pixmap != XCB_NONE)
1033 xcb_free_pixmap(globalconf.connection, c->titlebar[bar].pixmap);
1035 /* And forget about it */
1036 luaA_object_unref_item(globalconf.L, -2, c->titlebar[bar].drawable);
1037 c->titlebar[bar].drawable = NULL;
1038 lua_pop(globalconf.L, 2);
1041 /* Clear our event mask so that we don't receive any events from now on,
1042 * especially not for the following requests. */
1043 if(window_valid)
1044 xcb_change_window_attributes(globalconf.connection,
1045 c->window,
1046 XCB_CW_EVENT_MASK,
1047 (const uint32_t []) { 0 });
1048 xcb_change_window_attributes(globalconf.connection,
1049 c->frame_window,
1050 XCB_CW_EVENT_MASK,
1051 (const uint32_t []) { 0 });
1053 if(window_valid)
1055 xcb_unmap_window(globalconf.connection, c->window);
1056 xcb_reparent_window(globalconf.connection, c->window, globalconf.screen->root,
1057 c->geometry.x, c->geometry.y);
1059 xcb_destroy_window(globalconf.connection, c->frame_window);
1061 if(window_valid)
1063 /* Remove this window from the save set since this shouldn't be made visible
1064 * after a restart anymore. */
1065 xcb_change_save_set(globalconf.connection, XCB_SET_MODE_DELETE, c->window);
1067 /* Do this last to avoid races with clients. According to ICCCM, clients
1068 * arent allowed to re-use the window until after this. */
1069 xwindow_set_state(c->window, XCB_ICCCM_WM_STATE_WITHDRAWN);
1072 /* set client as invalid */
1073 c->window = XCB_NONE;
1075 luaA_object_unref(globalconf.L, c);
1078 /** Kill a client via a WM_DELETE_WINDOW request or KillClient if not
1079 * supported.
1080 * \param c The client to kill.
1082 void
1083 client_kill(client_t *c)
1085 if(client_hasproto(c, WM_DELETE_WINDOW))
1087 xcb_client_message_event_t ev;
1089 /* Initialize all of event's fields first */
1090 p_clear(&ev, 1);
1092 ev.response_type = XCB_CLIENT_MESSAGE;
1093 ev.window = c->window;
1094 ev.format = 32;
1095 ev.data.data32[1] = globalconf.timestamp;
1096 ev.type = WM_PROTOCOLS;
1097 ev.data.data32[0] = WM_DELETE_WINDOW;
1099 xcb_send_event(globalconf.connection, false, c->window,
1100 XCB_EVENT_MASK_NO_EVENT, (char *) &ev);
1102 else
1103 xcb_kill_client(globalconf.connection, c->window);
1106 /** Get all clients into a table.
1107 * \param L The Lua VM state.
1108 * \return The number of elements pushed on stack.
1109 * \luastack
1110 * \lparam An optional screen number.
1111 * \lreturn A table with all clients.
1113 static int
1114 luaA_client_get(lua_State *L)
1116 int i = 1, screen;
1118 screen = luaL_optnumber(L, 1, 0) - 1;
1120 lua_newtable(L);
1122 if(screen == -1)
1123 foreach(c, globalconf.clients)
1125 luaA_object_push(L, *c);
1126 lua_rawseti(L, -2, i++);
1128 else
1130 luaA_checkscreen(screen);
1131 foreach(c, globalconf.clients)
1132 if((*c)->screen == &globalconf.screens.tab[screen])
1134 luaA_object_push(L, *c);
1135 lua_rawseti(L, -2, i++);
1139 return 1;
1142 /** Check if a client is visible on its screen.
1143 * \param L The Lua VM state.
1144 * \return The number of elements pushed on stack.
1145 * \luastack
1146 * \lvalue A client.
1147 * \lreturn A boolean value, true if the client is visible, false otherwise.
1149 static int
1150 luaA_client_isvisible(lua_State *L)
1152 client_t *c = luaA_checkudata(L, 1, &client_class);
1153 lua_pushboolean(L, client_isvisible(c));
1154 return 1;
1157 /** Set a client icon.
1158 * \param L The Lua VM state.
1159 * \param cidx The client index on the stack.
1160 * \param iidx The image index on the stack.
1162 void
1163 client_set_icon(client_t *c, cairo_surface_t *s)
1165 if (s)
1166 s = draw_dup_image_surface(s);
1167 if(c->icon)
1168 cairo_surface_destroy(c->icon);
1169 c->icon = s;
1171 luaA_object_push(globalconf.L, c);
1172 luaA_object_emit_signal(globalconf.L, -1, "property::icon", 0);
1173 lua_pop(globalconf.L, 1);
1176 /** Kill a client.
1177 * \param L The Lua VM state.
1179 * \luastack
1180 * \lvalue A client.
1182 static int
1183 luaA_client_kill(lua_State *L)
1185 client_t *c = luaA_checkudata(L, 1, &client_class);
1186 client_kill(c);
1187 return 0;
1190 /** Swap a client with another one.
1191 * \param L The Lua VM state.
1192 * \luastack
1193 * \lvalue A client.
1194 * \lparam A client to swap with.
1196 static int
1197 luaA_client_swap(lua_State *L)
1199 client_t *c = luaA_checkudata(L, 1, &client_class);
1200 client_t *swap = luaA_checkudata(L, 2, &client_class);
1202 if(c != swap)
1204 client_t **ref_c = NULL, **ref_swap = NULL;
1205 foreach(item, globalconf.clients)
1207 if(*item == c)
1208 ref_c = item;
1209 else if(*item == swap)
1210 ref_swap = item;
1211 if(ref_c && ref_swap)
1212 break;
1214 /* swap ! */
1215 *ref_c = swap;
1216 *ref_swap = c;
1218 luaA_class_emit_signal(globalconf.L, &client_class, "list", 0);
1221 return 0;
1224 /** Access or set the client tags.
1225 * \param L The Lua VM state.
1226 * \return The number of elements pushed on stack.
1227 * \lparam A table with tags to set, or none to get the current tags table.
1228 * \return The clients tag.
1230 static int
1231 luaA_client_tags(lua_State *L)
1233 client_t *c = luaA_checkudata(L, 1, &client_class);
1234 int j = 0;
1236 if(lua_gettop(L) == 2)
1238 luaA_checktable(L, 2);
1239 for(int i = 0; i < globalconf.tags.len; i++)
1241 /* Only untag if we aren't going to add this tag again */
1242 bool found = false;
1243 lua_pushnil(L);
1244 while(lua_next(L, 2))
1246 tag_t *t = lua_touserdata(L, -1);
1247 /* Pop the value from lua_next */
1248 lua_pop(L, 1);
1249 if (t != globalconf.tags.tab[i])
1250 continue;
1252 /* Pop the key from lua_next */
1253 lua_pop(L, 1);
1254 found = true;
1255 break;
1257 if(!found)
1258 untag_client(c, globalconf.tags.tab[i]);
1260 lua_pushnil(L);
1261 while(lua_next(L, 2))
1262 tag_client(c);
1263 lua_pop(L, 1);
1266 lua_newtable(L);
1267 foreach(tag, globalconf.tags)
1268 if(is_client_tagged(c, *tag))
1270 luaA_object_push(L, *tag);
1271 lua_rawseti(L, -2, ++j);
1274 return 1;
1277 /** Raise a client on top of others which are on the same layer.
1278 * \param L The Lua VM state.
1279 * \luastack
1280 * \lvalue A client.
1282 static int
1283 luaA_client_raise(lua_State *L)
1285 client_t *c = luaA_checkudata(L, 1, &client_class);
1286 client_raise(c);
1287 return 0;
1290 /** Lower a client on bottom of others which are on the same layer.
1291 * \param L The Lua VM state.
1292 * \luastack
1293 * \lvalue A client.
1295 static int
1296 luaA_client_lower(lua_State *L)
1298 client_t *c = luaA_checkudata(L, 1, &client_class);
1300 stack_client_push(c);
1302 /* Traverse all transient layers. */
1303 for(client_t *tc = c->transient_for; tc; tc = tc->transient_for)
1304 stack_client_push(tc);
1306 return 0;
1309 /** Stop managing a client.
1310 * \param L The Lua VM state.
1311 * \return The number of elements pushed on stack.
1312 * \luastack
1313 * \lvalue A client.
1315 static int
1316 luaA_client_unmanage(lua_State *L)
1318 client_t *c = luaA_checkudata(L, 1, &client_class);
1319 client_unmanage(c, true);
1320 return 0;
1323 static area_t
1324 titlebar_get_area(client_t *c, client_titlebar_t bar)
1326 area_t result = c->geometry;
1327 result.x = result.y = 0;
1329 // Let's try some ascii art:
1330 // ---------------------------
1331 // | Top |
1332 // |-------------------------|
1333 // |L| |R|
1334 // |e| |i|
1335 // |f| |g|
1336 // |t| |h|
1337 // | | |t|
1338 // |-------------------------|
1339 // | Bottom |
1340 // ---------------------------
1342 switch (bar) {
1343 case CLIENT_TITLEBAR_BOTTOM:
1344 result.y = c->geometry.height - c->titlebar[bar].size;
1345 /* Fall through */
1346 case CLIENT_TITLEBAR_TOP:
1347 result.height = c->titlebar[bar].size;
1348 break;
1349 case CLIENT_TITLEBAR_RIGHT:
1350 result.x = c->geometry.width - c->titlebar[bar].size;
1351 /* Fall through */
1352 case CLIENT_TITLEBAR_LEFT:
1353 result.y = c->titlebar[CLIENT_TITLEBAR_TOP].size;
1354 result.width = c->titlebar[bar].size;
1355 result.height -= c->titlebar[CLIENT_TITLEBAR_TOP].size;
1356 result.height -= c->titlebar[CLIENT_TITLEBAR_BOTTOM].size;
1357 break;
1358 default:
1359 fatal("Unknown titlebar kind %d\n", (int) bar);
1362 return result;
1365 drawable_t *
1366 client_get_drawable_offset(client_t *c, int *x, int *y)
1368 for (client_titlebar_t bar = CLIENT_TITLEBAR_TOP; bar < CLIENT_TITLEBAR_COUNT; bar++) {
1369 area_t area = titlebar_get_area(c, bar);
1370 if (AREA_LEFT(area) > *x || AREA_RIGHT(area) <= *x)
1371 continue;
1372 if (AREA_TOP(area) > *y || AREA_BOTTOM(area) <= *y)
1373 continue;
1375 *x -= area.x;
1376 *y -= area.y;
1377 return c->titlebar[bar].drawable;
1380 return NULL;
1383 drawable_t *
1384 client_get_drawable(client_t *c, int x, int y)
1386 return client_get_drawable_offset(c, &x, &y);
1389 void
1390 client_refresh(client_t *c)
1392 for (client_titlebar_t bar = CLIENT_TITLEBAR_TOP; bar < CLIENT_TITLEBAR_COUNT; bar++) {
1393 if (c->titlebar[bar].drawable == NULL || c->titlebar[bar].drawable->surface == NULL)
1394 continue;
1396 area_t area = titlebar_get_area(c, bar);
1397 cairo_surface_flush(c->titlebar[bar].drawable->surface);
1398 xcb_copy_area(globalconf.connection, c->titlebar[bar].pixmap, c->frame_window,
1399 globalconf.gc, 0, 0, area.x, area.y, area.width, area.height);
1403 static drawable_t *
1404 titlebar_get_drawable(lua_State *L, client_t *c, int cl_idx, client_titlebar_t bar)
1406 if (c->titlebar[bar].drawable == NULL)
1408 cl_idx = luaA_absindex(L, cl_idx);
1409 drawable_allocator(L, (drawable_refresh_callback *) client_refresh, c);
1410 c->titlebar[bar].drawable = luaA_object_ref_item(L, cl_idx, -1);
1413 return c->titlebar[bar].drawable;
1416 static void
1417 titlebar_resize(client_t *c, client_titlebar_t bar, int size)
1419 if (size < 0)
1420 return;
1422 if (size == c->titlebar[bar].size)
1423 return;
1425 /* Now resize the client (and titlebars!) suitably (the client without
1426 * titlebars should keep its current size!) */
1427 area_t geometry = c->geometry;
1428 int change = size - c->titlebar[bar].size;
1429 switch (bar) {
1430 case CLIENT_TITLEBAR_TOP:
1431 case CLIENT_TITLEBAR_BOTTOM:
1432 geometry.height += change;
1433 break;
1434 case CLIENT_TITLEBAR_RIGHT:
1435 case CLIENT_TITLEBAR_LEFT:
1436 geometry.width += change;
1437 break;
1438 default:
1439 fatal("Unknown titlebar kind %d\n", (int) bar);
1442 c->titlebar[bar].size = size;
1443 client_resize_do(c, geometry, true);
1446 #define HANDLE_TITLEBAR(name, index) \
1447 static int \
1448 luaA_client_titlebar_ ## name(lua_State *L) \
1450 client_t *c = luaA_checkudata(L, 1, &client_class); \
1452 if (lua_gettop(L) == 2) \
1454 if (lua_isnil(L, 2)) \
1455 titlebar_resize(c, index, 0); \
1456 else \
1457 titlebar_resize(c, index, luaL_checknumber(L, 2)); \
1460 luaA_object_push_item(L, 1, titlebar_get_drawable(L, c, 1, index)); \
1461 lua_pushnumber(L, c->titlebar[index].size); \
1462 return 2; \
1464 HANDLE_TITLEBAR(top, CLIENT_TITLEBAR_TOP)
1465 HANDLE_TITLEBAR(right, CLIENT_TITLEBAR_RIGHT)
1466 HANDLE_TITLEBAR(bottom, CLIENT_TITLEBAR_BOTTOM)
1467 HANDLE_TITLEBAR(left, CLIENT_TITLEBAR_LEFT)
1469 /** Return client geometry.
1470 * \param L The Lua VM state.
1471 * \return The number of elements pushed on stack.
1472 * \luastack
1473 * \lparam A table with new coordinates, or none.
1474 * \lreturn A table with client coordinates.
1476 static int
1477 luaA_client_geometry(lua_State *L)
1479 client_t *c = luaA_checkudata(L, 1, &client_class);
1481 if(lua_gettop(L) == 2 && !lua_isnil(L, 2))
1483 area_t geometry;
1485 luaA_checktable(L, 2);
1486 geometry.x = luaA_getopt_number(L, 2, "x", c->geometry.x);
1487 geometry.y = luaA_getopt_number(L, 2, "y", c->geometry.y);
1488 if(client_isfixed(c))
1490 geometry.width = c->geometry.width;
1491 geometry.height = c->geometry.height;
1493 else
1495 geometry.width = luaA_getopt_number(L, 2, "width", c->geometry.width);
1496 geometry.height = luaA_getopt_number(L, 2, "height", c->geometry.height);
1499 client_resize(c, geometry);
1502 return luaA_pusharea(L, c->geometry);
1505 static int
1506 luaA_client_set_screen(lua_State *L, client_t *c)
1508 int screen = luaL_checknumber(L, -1) - 1;
1509 luaA_checkscreen(screen);
1510 screen_client_moveto(c, &globalconf.screens.tab[screen], true);
1512 return 0;
1515 static int
1516 luaA_client_set_hidden(lua_State *L, client_t *c)
1518 client_set_hidden(L, -3, luaA_checkboolean(L, -1));
1519 return 0;
1522 static int
1523 luaA_client_set_minimized(lua_State *L, client_t *c)
1525 client_set_minimized(L, -3, luaA_checkboolean(L, -1));
1526 return 0;
1529 static int
1530 luaA_client_set_fullscreen(lua_State *L, client_t *c)
1532 client_set_fullscreen(L, -3, luaA_checkboolean(L, -1));
1533 return 0;
1536 static int
1537 luaA_client_set_modal(lua_State *L, client_t *c)
1539 client_set_modal(L, -3, luaA_checkboolean(L, -1));
1540 return 0;
1543 static int
1544 luaA_client_set_maximized_horizontal(lua_State *L, client_t *c)
1546 client_set_maximized_horizontal(L, -3, luaA_checkboolean(L, -1));
1547 return 0;
1550 static int
1551 luaA_client_set_maximized_vertical(lua_State *L, client_t *c)
1553 client_set_maximized_vertical(L, -3, luaA_checkboolean(L, -1));
1554 return 0;
1557 static int
1558 luaA_client_set_icon(lua_State *L, client_t *c)
1560 cairo_surface_t *surf = NULL;
1561 if(!lua_isnil(L, -1))
1562 surf = (cairo_surface_t *)lua_touserdata(L, -1);
1563 client_set_icon(c, surf);
1564 return 0;
1567 static int
1568 luaA_client_set_sticky(lua_State *L, client_t *c)
1570 client_set_sticky(L, -3, luaA_checkboolean(L, -1));
1571 return 0;
1574 static int
1575 luaA_client_set_size_hints_honor(lua_State *L, client_t *c)
1577 c->size_hints_honor = luaA_checkboolean(L, -1);
1578 luaA_object_emit_signal(L, -3, "property::size_hints_honor", 0);
1579 return 0;
1582 static int
1583 luaA_client_set_ontop(lua_State *L, client_t *c)
1585 client_set_ontop(L, -3, luaA_checkboolean(L, -1));
1586 return 0;
1589 static int
1590 luaA_client_set_below(lua_State *L, client_t *c)
1592 client_set_below(L, -3, luaA_checkboolean(L, -1));
1593 return 0;
1596 static int
1597 luaA_client_set_above(lua_State *L, client_t *c)
1599 client_set_above(L, -3, luaA_checkboolean(L, -1));
1600 return 0;
1603 static int
1604 luaA_client_set_urgent(lua_State *L, client_t *c)
1606 client_set_urgent(L, -3, luaA_checkboolean(L, -1));
1607 return 0;
1610 static int
1611 luaA_client_set_skip_taskbar(lua_State *L, client_t *c)
1613 client_set_skip_taskbar(L, -3, luaA_checkboolean(L, -1));
1614 return 0;
1617 static int
1618 luaA_client_get_name(lua_State *L, client_t *c)
1620 lua_pushstring(L, c->name ? c->name : c->alt_name);
1621 return 1;
1624 static int
1625 luaA_client_get_icon_name(lua_State *L, client_t *c)
1627 lua_pushstring(L, c->icon_name ? c->icon_name : c->alt_icon_name);
1628 return 1;
1631 LUA_OBJECT_EXPORT_PROPERTY(client, client_t, class, lua_pushstring)
1632 LUA_OBJECT_EXPORT_PROPERTY(client, client_t, instance, lua_pushstring)
1633 LUA_OBJECT_EXPORT_PROPERTY(client, client_t, machine, lua_pushstring)
1634 LUA_OBJECT_EXPORT_PROPERTY(client, client_t, role, lua_pushstring)
1635 LUA_OBJECT_EXPORT_PROPERTY(client, client_t, transient_for, luaA_object_push)
1636 LUA_OBJECT_EXPORT_PROPERTY(client, client_t, skip_taskbar, lua_pushboolean)
1637 LUA_OBJECT_EXPORT_PROPERTY(client, client_t, leader_window, lua_pushnumber)
1638 LUA_OBJECT_EXPORT_PROPERTY(client, client_t, group_window, lua_pushnumber)
1639 LUA_OBJECT_EXPORT_PROPERTY(client, client_t, pid, lua_pushnumber)
1640 LUA_OBJECT_EXPORT_PROPERTY(client, client_t, hidden, lua_pushboolean)
1641 LUA_OBJECT_EXPORT_PROPERTY(client, client_t, minimized, lua_pushboolean)
1642 LUA_OBJECT_EXPORT_PROPERTY(client, client_t, fullscreen, lua_pushboolean)
1643 LUA_OBJECT_EXPORT_PROPERTY(client, client_t, modal, lua_pushboolean)
1644 LUA_OBJECT_EXPORT_PROPERTY(client, client_t, ontop, lua_pushboolean)
1645 LUA_OBJECT_EXPORT_PROPERTY(client, client_t, urgent, lua_pushboolean)
1646 LUA_OBJECT_EXPORT_PROPERTY(client, client_t, above, lua_pushboolean)
1647 LUA_OBJECT_EXPORT_PROPERTY(client, client_t, below, lua_pushboolean)
1648 LUA_OBJECT_EXPORT_PROPERTY(client, client_t, sticky, lua_pushboolean)
1649 LUA_OBJECT_EXPORT_PROPERTY(client, client_t, size_hints_honor, lua_pushboolean)
1650 LUA_OBJECT_EXPORT_PROPERTY(client, client_t, maximized_horizontal, lua_pushboolean)
1651 LUA_OBJECT_EXPORT_PROPERTY(client, client_t, maximized_vertical, lua_pushboolean)
1653 static int
1654 luaA_client_get_content(lua_State *L, client_t *c)
1656 xcb_image_t *ximage = xcb_image_get(globalconf.connection,
1657 c->window,
1658 0, 0,
1659 c->geometry.width,
1660 c->geometry.height,
1661 ~0, XCB_IMAGE_FORMAT_Z_PIXMAP);
1662 cairo_surface_t *surface = NULL;
1664 if(ximage)
1666 if(ximage->bpp >= 24)
1668 uint32_t *data = p_new(uint32_t, ximage->width * ximage->height);
1670 for(int y = 0; y < ximage->height; y++)
1671 for(int x = 0; x < ximage->width; x++)
1673 data[y * ximage->width + x] = xcb_image_get_pixel(ximage, x, y);
1674 data[y * ximage->width + x] |= 0xff000000; /* set alpha to 0xff */
1677 surface = draw_surface_from_data(ximage->width, ximage->height, data);
1678 p_delete(&data);
1680 xcb_image_destroy(ximage);
1683 if (!surface)
1684 return 0;
1686 /* lua has to make sure to free the ref or we have a leak */
1687 lua_pushlightuserdata(L, surface);
1688 return 1;
1691 static int
1692 luaA_client_get_screen(lua_State *L, client_t *c)
1694 if(!c->screen)
1695 return 0;
1696 lua_pushnumber(L, 1 + screen_array_indexof(&globalconf.screens, c->screen));
1697 return 1;
1700 static int
1701 luaA_client_get_icon(lua_State *L, client_t *c)
1703 if(!c->icon)
1704 return 0;
1705 /* lua gets its own reference which it will have to destroy */
1706 lua_pushlightuserdata(L, cairo_surface_reference(c->icon));
1707 return 1;
1710 static int
1711 luaA_client_get_focusable(lua_State *L, client_t *c)
1713 bool ret;
1715 /* A client can be focused if it doesnt have the "nofocus" hint...*/
1716 if (!c->nofocus)
1717 ret = true;
1718 else
1719 /* ...or if it knows the WM_TAKE_FOCUS protocol */
1720 ret = client_hasproto(c, WM_TAKE_FOCUS);
1722 lua_pushboolean(L, ret);
1723 return 1;
1726 static int
1727 luaA_client_get_size_hints(lua_State *L, client_t *c)
1729 const char *u_or_p = NULL;
1731 lua_createtable(L, 0, 1);
1733 if(c->size_hints.flags & XCB_ICCCM_SIZE_HINT_US_POSITION)
1734 u_or_p = "user_position";
1735 else if(c->size_hints.flags & XCB_ICCCM_SIZE_HINT_P_POSITION)
1736 u_or_p = "program_position";
1738 if(u_or_p)
1740 lua_createtable(L, 0, 2);
1741 lua_pushnumber(L, c->size_hints.x);
1742 lua_setfield(L, -2, "x");
1743 lua_pushnumber(L, c->size_hints.y);
1744 lua_setfield(L, -2, "y");
1745 lua_setfield(L, -2, u_or_p);
1746 u_or_p = NULL;
1749 if(c->size_hints.flags & XCB_ICCCM_SIZE_HINT_US_SIZE)
1750 u_or_p = "user_size";
1751 else if(c->size_hints.flags & XCB_ICCCM_SIZE_HINT_P_SIZE)
1752 u_or_p = "program_size";
1754 if(u_or_p)
1756 lua_createtable(L, 0, 2);
1757 lua_pushnumber(L, c->size_hints.width);
1758 lua_setfield(L, -2, "width");
1759 lua_pushnumber(L, c->size_hints.height);
1760 lua_setfield(L, -2, "height");
1761 lua_setfield(L, -2, u_or_p);
1764 if(c->size_hints.flags & XCB_ICCCM_SIZE_HINT_P_MIN_SIZE)
1766 lua_pushnumber(L, c->size_hints.min_width);
1767 lua_setfield(L, -2, "min_width");
1768 lua_pushnumber(L, c->size_hints.min_height);
1769 lua_setfield(L, -2, "min_height");
1772 if(c->size_hints.flags & XCB_ICCCM_SIZE_HINT_P_MAX_SIZE)
1774 lua_pushnumber(L, c->size_hints.max_width);
1775 lua_setfield(L, -2, "max_width");
1776 lua_pushnumber(L, c->size_hints.max_height);
1777 lua_setfield(L, -2, "max_height");
1780 if(c->size_hints.flags & XCB_ICCCM_SIZE_HINT_P_RESIZE_INC)
1782 lua_pushnumber(L, c->size_hints.width_inc);
1783 lua_setfield(L, -2, "width_inc");
1784 lua_pushnumber(L, c->size_hints.height_inc);
1785 lua_setfield(L, -2, "height_inc");
1788 if(c->size_hints.flags & XCB_ICCCM_SIZE_HINT_P_ASPECT)
1790 lua_pushnumber(L, c->size_hints.min_aspect_num);
1791 lua_setfield(L, -2, "min_aspect_num");
1792 lua_pushnumber(L, c->size_hints.min_aspect_den);
1793 lua_setfield(L, -2, "min_aspect_den");
1794 lua_pushnumber(L, c->size_hints.max_aspect_num);
1795 lua_setfield(L, -2, "max_aspect_num");
1796 lua_pushnumber(L, c->size_hints.max_aspect_den);
1797 lua_setfield(L, -2, "max_aspect_den");
1800 if(c->size_hints.flags & XCB_ICCCM_SIZE_HINT_BASE_SIZE)
1802 lua_pushnumber(L, c->size_hints.base_width);
1803 lua_setfield(L, -2, "base_width");
1804 lua_pushnumber(L, c->size_hints.base_height);
1805 lua_setfield(L, -2, "base_height");
1808 if(c->size_hints.flags & XCB_ICCCM_SIZE_HINT_P_WIN_GRAVITY)
1810 switch(c->size_hints.win_gravity)
1812 default:
1813 lua_pushliteral(L, "north_west");
1814 break;
1815 case XCB_GRAVITY_NORTH:
1816 lua_pushliteral(L, "north");
1817 break;
1818 case XCB_GRAVITY_NORTH_EAST:
1819 lua_pushliteral(L, "north_east");
1820 break;
1821 case XCB_GRAVITY_WEST:
1822 lua_pushliteral(L, "west");
1823 break;
1824 case XCB_GRAVITY_CENTER:
1825 lua_pushliteral(L, "center");
1826 break;
1827 case XCB_GRAVITY_EAST:
1828 lua_pushliteral(L, "east");
1829 break;
1830 case XCB_GRAVITY_SOUTH_WEST:
1831 lua_pushliteral(L, "south_west");
1832 break;
1833 case XCB_GRAVITY_SOUTH:
1834 lua_pushliteral(L, "south");
1835 break;
1836 case XCB_GRAVITY_SOUTH_EAST:
1837 lua_pushliteral(L, "south_east");
1838 break;
1839 case XCB_GRAVITY_STATIC:
1840 lua_pushliteral(L, "static");
1841 break;
1843 lua_setfield(L, -2, "win_gravity");
1846 return 1;
1849 /** Set the client's bounding shape.
1850 * \param L The Lua VM state.
1851 * \param client The client object.
1852 * \return The number of elements pushed on stack.
1854 static int
1855 luaA_client_set_shape_bounding(lua_State *L, client_t *c)
1857 cairo_surface_t *surf = NULL;
1858 if(!lua_isnil(L, -1))
1859 surf = (cairo_surface_t *)lua_touserdata(L, -1);
1860 xwindow_set_shape(c->frame_window,
1861 c->geometry.width + (c->border_width * 2),
1862 c->geometry.height + (c->border_width * 2),
1863 XCB_SHAPE_SK_BOUNDING, surf, -c->border_width);
1864 return 0;
1867 /** Set the client's clip shape.
1868 * \param L The Lua VM state.
1869 * \param client The client object.
1870 * \return The number of elements pushed on stack.
1872 static int
1873 luaA_client_set_shape_clip(lua_State *L, client_t *c)
1875 cairo_surface_t *surf = NULL;
1876 if(!lua_isnil(L, -1))
1877 surf = (cairo_surface_t *)lua_touserdata(L, -1);
1878 xwindow_set_shape(c->frame_window, c->geometry.width, c->geometry.height,
1879 XCB_SHAPE_SK_CLIP, surf, 0);
1880 return 0;
1883 /** Get or set keys bindings for a client.
1884 * \param L The Lua VM state.
1885 * \return The number of element pushed on stack.
1886 * \luastack
1887 * \lvalue A client.
1888 * \lparam An array of key bindings objects, or nothing.
1889 * \return The array of key bindings objects of this client.
1891 static int
1892 luaA_client_keys(lua_State *L)
1894 client_t *c = luaA_checkudata(L, 1, &client_class);
1895 key_array_t *keys = &c->keys;
1897 if(lua_gettop(L) == 2)
1899 luaA_key_array_set(L, 1, 2, keys);
1900 luaA_object_emit_signal(L, 1, "property::keys", 0);
1901 xcb_ungrab_key(globalconf.connection, XCB_GRAB_ANY, c->frame_window, XCB_BUTTON_MASK_ANY);
1902 xwindow_grabkeys(c->frame_window, keys);
1905 return luaA_key_array_get(L, 1, keys);
1908 /* Client module.
1909 * \param L The Lua VM state.
1910 * \return The number of pushed elements.
1912 static int
1913 luaA_client_module_index(lua_State *L)
1915 const char *buf = luaL_checkstring(L, 2);
1917 if (A_STREQ(buf, "focus"))
1918 return luaA_object_push(globalconf.L, globalconf.focus.client);
1919 return 0;
1922 /* Client module new index.
1923 * \param L The Lua VM state.
1924 * \return The number of pushed elements.
1926 static int
1927 luaA_client_module_newindex(lua_State *L)
1929 const char *buf = luaL_checkstring(L, 2);
1930 client_t *c;
1932 if (A_STREQ(buf, "focus"))
1934 c = luaA_checkudata(L, 3, &client_class);
1935 client_focus(c);
1938 return 0;
1941 static bool
1942 client_checker(client_t *c)
1944 return c->window != XCB_NONE;
1947 void
1948 client_class_setup(lua_State *L)
1950 static const struct luaL_Reg client_methods[] =
1952 LUA_CLASS_METHODS(client)
1953 { "get", luaA_client_get },
1954 { "__index", luaA_client_module_index },
1955 { "__newindex", luaA_client_module_newindex },
1956 { NULL, NULL }
1959 static const struct luaL_Reg client_meta[] =
1961 LUA_OBJECT_META(client)
1962 LUA_CLASS_META
1963 { "keys", luaA_client_keys },
1964 { "isvisible", luaA_client_isvisible },
1965 { "geometry", luaA_client_geometry },
1966 { "tags", luaA_client_tags },
1967 { "kill", luaA_client_kill },
1968 { "swap", luaA_client_swap },
1969 { "raise", luaA_client_raise },
1970 { "lower", luaA_client_lower },
1971 { "unmanage", luaA_client_unmanage },
1972 { "titlebar_top", luaA_client_titlebar_top },
1973 { "titlebar_right", luaA_client_titlebar_right },
1974 { "titlebar_bottom", luaA_client_titlebar_bottom },
1975 { "titlebar_left", luaA_client_titlebar_left },
1976 { NULL, NULL }
1979 luaA_class_setup(L, &client_class, "client", &window_class,
1980 (lua_class_allocator_t) client_new,
1981 (lua_class_collector_t) client_wipe,
1982 (lua_class_checker_t) client_checker,
1983 luaA_class_index_miss_property, luaA_class_newindex_miss_property,
1984 client_methods, client_meta);
1985 luaA_class_add_property(&client_class, "name",
1986 NULL,
1987 (lua_class_propfunc_t) luaA_client_get_name,
1988 NULL);
1989 luaA_class_add_property(&client_class, "transient_for",
1990 NULL,
1991 (lua_class_propfunc_t) luaA_client_get_transient_for,
1992 NULL);
1993 luaA_class_add_property(&client_class, "skip_taskbar",
1994 (lua_class_propfunc_t) luaA_client_set_skip_taskbar,
1995 (lua_class_propfunc_t) luaA_client_get_skip_taskbar,
1996 (lua_class_propfunc_t) luaA_client_set_skip_taskbar);
1997 luaA_class_add_property(&client_class, "content",
1998 NULL,
1999 (lua_class_propfunc_t) luaA_client_get_content,
2000 NULL);
2001 luaA_class_add_property(&client_class, "type",
2002 NULL,
2003 (lua_class_propfunc_t) luaA_window_get_type,
2004 NULL);
2005 luaA_class_add_property(&client_class, "class",
2006 NULL,
2007 (lua_class_propfunc_t) luaA_client_get_class,
2008 NULL);
2009 luaA_class_add_property(&client_class, "instance",
2010 NULL,
2011 (lua_class_propfunc_t) luaA_client_get_instance,
2012 NULL);
2013 luaA_class_add_property(&client_class, "role",
2014 NULL,
2015 (lua_class_propfunc_t) luaA_client_get_role,
2016 NULL);
2017 luaA_class_add_property(&client_class, "pid",
2018 NULL,
2019 (lua_class_propfunc_t) luaA_client_get_pid,
2020 NULL);
2021 luaA_class_add_property(&client_class, "leader_window",
2022 NULL,
2023 (lua_class_propfunc_t) luaA_client_get_leader_window,
2024 NULL);
2025 luaA_class_add_property(&client_class, "machine",
2026 NULL,
2027 (lua_class_propfunc_t) luaA_client_get_machine,
2028 NULL);
2029 luaA_class_add_property(&client_class, "icon_name",
2030 NULL,
2031 (lua_class_propfunc_t) luaA_client_get_icon_name,
2032 NULL);
2033 luaA_class_add_property(&client_class, "screen",
2034 NULL,
2035 (lua_class_propfunc_t) luaA_client_get_screen,
2036 (lua_class_propfunc_t) luaA_client_set_screen);
2037 luaA_class_add_property(&client_class, "hidden",
2038 (lua_class_propfunc_t) luaA_client_set_hidden,
2039 (lua_class_propfunc_t) luaA_client_get_hidden,
2040 (lua_class_propfunc_t) luaA_client_set_hidden);
2041 luaA_class_add_property(&client_class, "minimized",
2042 (lua_class_propfunc_t) luaA_client_set_minimized,
2043 (lua_class_propfunc_t) luaA_client_get_minimized,
2044 (lua_class_propfunc_t) luaA_client_set_minimized);
2045 luaA_class_add_property(&client_class, "fullscreen",
2046 (lua_class_propfunc_t) luaA_client_set_fullscreen,
2047 (lua_class_propfunc_t) luaA_client_get_fullscreen,
2048 (lua_class_propfunc_t) luaA_client_set_fullscreen);
2049 luaA_class_add_property(&client_class, "modal",
2050 (lua_class_propfunc_t) luaA_client_set_modal,
2051 (lua_class_propfunc_t) luaA_client_get_modal,
2052 (lua_class_propfunc_t) luaA_client_set_modal);
2053 luaA_class_add_property(&client_class, "group_window",
2054 NULL,
2055 (lua_class_propfunc_t) luaA_client_get_group_window,
2056 NULL);
2057 luaA_class_add_property(&client_class, "maximized_horizontal",
2058 (lua_class_propfunc_t) luaA_client_set_maximized_horizontal,
2059 (lua_class_propfunc_t) luaA_client_get_maximized_horizontal,
2060 (lua_class_propfunc_t) luaA_client_set_maximized_horizontal);
2061 luaA_class_add_property(&client_class, "maximized_vertical",
2062 (lua_class_propfunc_t) luaA_client_set_maximized_vertical,
2063 (lua_class_propfunc_t) luaA_client_get_maximized_vertical,
2064 (lua_class_propfunc_t) luaA_client_set_maximized_vertical);
2065 luaA_class_add_property(&client_class, "icon",
2066 (lua_class_propfunc_t) luaA_client_set_icon,
2067 (lua_class_propfunc_t) luaA_client_get_icon,
2068 (lua_class_propfunc_t) luaA_client_set_icon);
2069 luaA_class_add_property(&client_class, "ontop",
2070 (lua_class_propfunc_t) luaA_client_set_ontop,
2071 (lua_class_propfunc_t) luaA_client_get_ontop,
2072 (lua_class_propfunc_t) luaA_client_set_ontop);
2073 luaA_class_add_property(&client_class, "above",
2074 (lua_class_propfunc_t) luaA_client_set_above,
2075 (lua_class_propfunc_t) luaA_client_get_above,
2076 (lua_class_propfunc_t) luaA_client_set_above);
2077 luaA_class_add_property(&client_class, "below",
2078 (lua_class_propfunc_t) luaA_client_set_below,
2079 (lua_class_propfunc_t) luaA_client_get_below,
2080 (lua_class_propfunc_t) luaA_client_set_below);
2081 luaA_class_add_property(&client_class, "sticky",
2082 (lua_class_propfunc_t) luaA_client_set_sticky,
2083 (lua_class_propfunc_t) luaA_client_get_sticky,
2084 (lua_class_propfunc_t) luaA_client_set_sticky);
2085 luaA_class_add_property(&client_class, "size_hints_honor",
2086 (lua_class_propfunc_t) luaA_client_set_size_hints_honor,
2087 (lua_class_propfunc_t) luaA_client_get_size_hints_honor,
2088 (lua_class_propfunc_t) luaA_client_set_size_hints_honor);
2089 luaA_class_add_property(&client_class, "urgent",
2090 (lua_class_propfunc_t) luaA_client_set_urgent,
2091 (lua_class_propfunc_t) luaA_client_get_urgent,
2092 (lua_class_propfunc_t) luaA_client_set_urgent);
2093 luaA_class_add_property(&client_class, "size_hints",
2094 NULL,
2095 (lua_class_propfunc_t) luaA_client_get_size_hints,
2096 NULL);
2097 luaA_class_add_property(&client_class, "focusable",
2098 NULL,
2099 (lua_class_propfunc_t) luaA_client_get_focusable,
2100 NULL);
2101 luaA_class_add_property(&client_class, "shape_bounding",
2102 (lua_class_propfunc_t) luaA_client_set_shape_bounding,
2103 NULL,
2104 (lua_class_propfunc_t) luaA_client_set_shape_bounding);
2105 luaA_class_add_property(&client_class, "shape_clip",
2106 (lua_class_propfunc_t) luaA_client_set_shape_clip,
2107 NULL,
2108 (lua_class_propfunc_t) luaA_client_set_shape_clip);
2110 signal_add(&client_class.signals, "focus");
2111 signal_add(&client_class.signals, "list");
2112 signal_add(&client_class.signals, "manage");
2113 signal_add(&client_class.signals, "button::press");
2114 signal_add(&client_class.signals, "button::release");
2115 signal_add(&client_class.signals, "mouse::enter");
2116 signal_add(&client_class.signals, "mouse::leave");
2117 signal_add(&client_class.signals, "mouse::move");
2118 signal_add(&client_class.signals, "property::above");
2119 signal_add(&client_class.signals, "property::below");
2120 signal_add(&client_class.signals, "property::class");
2121 signal_add(&client_class.signals, "property::fullscreen");
2122 signal_add(&client_class.signals, "property::geometry");
2123 signal_add(&client_class.signals, "property::group_window");
2124 signal_add(&client_class.signals, "property::height");
2125 signal_add(&client_class.signals, "property::hidden");
2126 signal_add(&client_class.signals, "property::icon");
2127 signal_add(&client_class.signals, "property::icon_name");
2128 signal_add(&client_class.signals, "property::instance");
2129 signal_add(&client_class.signals, "property::keys");
2130 signal_add(&client_class.signals, "property::machine");
2131 signal_add(&client_class.signals, "property::maximized_horizontal");
2132 signal_add(&client_class.signals, "property::maximized_vertical");
2133 signal_add(&client_class.signals, "property::minimized");
2134 signal_add(&client_class.signals, "property::modal");
2135 signal_add(&client_class.signals, "property::name");
2136 signal_add(&client_class.signals, "property::ontop");
2137 signal_add(&client_class.signals, "property::pid");
2138 signal_add(&client_class.signals, "property::role");
2139 signal_add(&client_class.signals, "property::screen");
2140 signal_add(&client_class.signals, "property::size_hints_honor");
2141 signal_add(&client_class.signals, "property::skip_taskbar");
2142 signal_add(&client_class.signals, "property::sticky");
2143 signal_add(&client_class.signals, "property::struts");
2144 signal_add(&client_class.signals, "property::transient_for");
2145 signal_add(&client_class.signals, "property::type");
2146 signal_add(&client_class.signals, "property::urgent");
2147 signal_add(&client_class.signals, "property::width");
2148 signal_add(&client_class.signals, "property::window");
2149 signal_add(&client_class.signals, "property::x");
2150 signal_add(&client_class.signals, "property::y");
2151 signal_add(&client_class.signals, "request::fullscreen");
2152 signal_add(&client_class.signals, "request::maximized_horizontal");
2153 signal_add(&client_class.signals, "request::maximized_vertical");
2154 signal_add(&client_class.signals, "tagged");
2155 signal_add(&client_class.signals, "unfocus");
2156 signal_add(&client_class.signals, "unmanage");
2157 signal_add(&client_class.signals, "untagged");
2160 // vim: filetype=c:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:textwidth=80