Revert "client: add a limit to the loop (FS#573)"
[awesome.git] / objects / client.c
blobbdbcaaeb6941e612fa0f417a43e7ac9633cb2c79
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/shape.h>
24 #include <cairo-xcb.h>
26 #include "objects/tag.h"
27 #include "ewmh.h"
28 #include "screen.h"
29 #include "systray.h"
30 #include "property.h"
31 #include "spawn.h"
32 #include "luaa.h"
33 #include "xwindow.h"
34 #include "common/atoms.h"
35 #include "common/xutil.h"
37 static area_t titlebar_get_area(client_t *c, client_titlebar_t bar);
38 static drawable_t *titlebar_get_drawable(lua_State *L, client_t *c, int cl_idx, client_titlebar_t bar);
40 /** Collect a client.
41 * \param L The Lua VM state.
42 * \return The number of element pushed on stack.
44 static void
45 client_wipe(client_t *c)
47 key_array_wipe(&c->keys);
48 xcb_icccm_get_wm_protocols_reply_wipe(&c->protocols);
49 p_delete(&c->machine);
50 p_delete(&c->class);
51 p_delete(&c->instance);
52 p_delete(&c->icon_name);
53 p_delete(&c->alt_icon_name);
54 p_delete(&c->name);
55 p_delete(&c->alt_name);
56 if(c->icon)
57 cairo_surface_destroy(c->icon);
60 /** Change the clients urgency flag.
61 * \param L The Lua VM state.
62 * \param cidx The client index on the stack.
63 * \param urgent The new flag state.
65 void
66 client_set_urgent(lua_State *L, int cidx, bool urgent)
68 client_t *c = luaA_checkudata(L, cidx, &client_class);
70 if(c->urgent != urgent)
72 xcb_get_property_cookie_t hints =
73 xcb_icccm_get_wm_hints_unchecked(globalconf.connection, c->window);
75 c->urgent = urgent;
77 /* update ICCCM hints */
78 xcb_icccm_wm_hints_t wmh;
79 xcb_icccm_get_wm_hints_reply(globalconf.connection, hints, &wmh, NULL);
81 if(urgent)
82 wmh.flags |= XCB_ICCCM_WM_HINT_X_URGENCY;
83 else
84 wmh.flags &= ~XCB_ICCCM_WM_HINT_X_URGENCY;
86 xcb_icccm_set_wm_hints(globalconf.connection, c->window, &wmh);
88 luaA_object_emit_signal(L, cidx, "property::urgent", 0);
92 #define DO_CLIENT_SET_PROPERTY(prop) \
93 void \
94 client_set_##prop(lua_State *L, int cidx, fieldtypeof(client_t, prop) value) \
95 { \
96 client_t *c = luaA_checkudata(L, cidx, &client_class); \
97 if(c->prop != value) \
98 { \
99 c->prop = value; \
100 luaA_object_emit_signal(L, cidx, "property::" #prop, 0); \
103 DO_CLIENT_SET_PROPERTY(group_window)
104 DO_CLIENT_SET_PROPERTY(type)
105 DO_CLIENT_SET_PROPERTY(transient_for)
106 DO_CLIENT_SET_PROPERTY(pid)
107 DO_CLIENT_SET_PROPERTY(skip_taskbar)
108 #undef DO_CLIENT_SET_PROPERTY
110 #define DO_CLIENT_SET_STRING_PROPERTY2(prop, signal) \
111 void \
112 client_set_##prop(lua_State *L, int cidx, char *value) \
114 client_t *c = luaA_checkudata(L, cidx, &client_class); \
115 if (A_STREQ(c->prop, value)) \
117 p_delete(&value); \
118 return; \
120 p_delete(&c->prop); \
121 c->prop = value; \
122 luaA_object_emit_signal(L, cidx, "property::" #signal, 0); \
124 #define DO_CLIENT_SET_STRING_PROPERTY(prop) \
125 DO_CLIENT_SET_STRING_PROPERTY2(prop, prop)
126 DO_CLIENT_SET_STRING_PROPERTY(name)
127 DO_CLIENT_SET_STRING_PROPERTY2(alt_name, name)
128 DO_CLIENT_SET_STRING_PROPERTY(icon_name)
129 DO_CLIENT_SET_STRING_PROPERTY2(alt_icon_name, icon_name)
130 DO_CLIENT_SET_STRING_PROPERTY(role)
131 DO_CLIENT_SET_STRING_PROPERTY(machine)
132 #undef DO_CLIENT_SET_STRING_PROPERTY
134 void
135 client_set_class_instance(lua_State *L, int cidx, const char *class, const char *instance)
137 client_t *c = luaA_checkudata(L, cidx, &client_class);
138 p_delete(&c->class);
139 p_delete(&c->instance);
140 c->class = a_strdup(class);
141 luaA_object_emit_signal(L, cidx, "property::class", 0);
142 c->instance = a_strdup(instance);
143 luaA_object_emit_signal(L, cidx, "property::instance", 0);
146 /** Returns true if a client is tagged
147 * with one of the tags of the specified screen.
148 * \param c The client to check.
149 * \param screen Virtual screen.
150 * \return true if the client is visible, false otherwise.
152 bool
153 client_maybevisible(client_t *c)
155 if(c->sticky)
156 return true;
158 foreach(tag, globalconf.tags)
159 if(tag_get_selected(*tag) && is_client_tagged(c, *tag))
160 return true;
162 return false;
165 /** Get a client by its window.
166 * \param w The client window to find.
167 * \return A client pointer if found, NULL otherwise.
169 client_t *
170 client_getbywin(xcb_window_t w)
172 foreach(c, globalconf.clients)
173 if((*c)->window == w)
174 return *c;
176 return NULL;
179 /** Get a client by its frame window.
180 * \param w The client window to find.
181 * \return A client pointer if found, NULL otherwise.
183 client_t *
184 client_getbyframewin(xcb_window_t w)
186 foreach(c, globalconf.clients)
187 if((*c)->frame_window == w)
188 return *c;
190 return NULL;
193 /** Unfocus a client (internal).
194 * \param c The client.
196 static void
197 client_unfocus_internal(client_t *c)
199 globalconf.focus.client = NULL;
201 luaA_object_push(globalconf.L, c);
202 luaA_object_emit_signal(globalconf.L, -1, "unfocus", 0);
203 lua_pop(globalconf.L, 1);
206 /** Unfocus a client.
207 * \param c The client.
209 static void
210 client_unfocus(client_t *c)
212 client_unfocus_internal(c);
213 globalconf.focus.need_update = true;
216 /** Check if client supports atom a protocol in WM_PROTOCOL.
217 * \param c The client.
218 * \param atom The protocol atom to check for.
219 * \return True if client has the atom in protocol, false otherwise.
221 bool
222 client_hasproto(client_t *c, xcb_atom_t atom)
224 for(uint32_t i = 0; i < c->protocols.atoms_len; i++)
225 if(c->protocols.atoms[i] == atom)
226 return true;
227 return false;
230 /** Prepare banning a client by running all needed lua events.
231 * \param c The client.
233 void client_ban_unfocus(client_t *c)
235 /* Wait until the last moment to take away the focus from the window. */
236 if(globalconf.focus.client == c)
237 client_unfocus(c);
240 /** Ban client and move it out of the viewport.
241 * \param c The client.
243 void
244 client_ban(client_t *c)
246 if(!c->isbanned)
248 xcb_unmap_window(globalconf.connection, c->frame_window);
250 c->isbanned = true;
252 client_ban_unfocus(c);
256 /** This is part of The Bob Marley Algorithm: we ignore enter and leave window
257 * in certain cases, like map/unmap or move, so we don't get spurious events.
259 void
260 client_ignore_enterleave_events(void)
262 foreach(c, globalconf.clients)
264 xcb_change_window_attributes(globalconf.connection,
265 (*c)->window,
266 XCB_CW_EVENT_MASK,
267 (const uint32_t []) { CLIENT_SELECT_INPUT_EVENT_MASK & ~(XCB_EVENT_MASK_ENTER_WINDOW | XCB_EVENT_MASK_LEAVE_WINDOW) });
268 xcb_change_window_attributes(globalconf.connection,
269 (*c)->frame_window,
270 XCB_CW_EVENT_MASK,
271 (const uint32_t []) { FRAME_SELECT_INPUT_EVENT_MASK & ~(XCB_EVENT_MASK_ENTER_WINDOW | XCB_EVENT_MASK_LEAVE_WINDOW) });
275 void
276 client_restore_enterleave_events(void)
278 foreach(c, globalconf.clients)
280 xcb_change_window_attributes(globalconf.connection,
281 (*c)->window,
282 XCB_CW_EVENT_MASK,
283 (const uint32_t []) { CLIENT_SELECT_INPUT_EVENT_MASK });
284 xcb_change_window_attributes(globalconf.connection,
285 (*c)->frame_window,
286 XCB_CW_EVENT_MASK,
287 (const uint32_t []) { FRAME_SELECT_INPUT_EVENT_MASK });
291 /** Record that a client got focus.
292 * \param c The client.
294 void
295 client_focus_update(client_t *c)
297 if(!client_maybevisible(c))
298 return;
300 if(globalconf.focus.client)
302 if (globalconf.focus.client == c)
303 /* Already focused */
304 return;
306 /* When we are called due to a FocusIn event (=old focused client
307 * already unfocused), we don't want to cause a SetInputFocus,
308 * because the client which has focus now could be using globally
309 * active input model (or 'no input').
311 client_unfocus_internal(globalconf.focus.client);
314 globalconf.focus.client = c;
316 /* according to EWMH, we have to remove the urgent state from a client */
317 luaA_object_push(globalconf.L, c);
318 client_set_urgent(globalconf.L, -1, false);
320 luaA_object_emit_signal(globalconf.L, -1, "focus", 0);
321 lua_pop(globalconf.L, 1);
324 /** Give focus to client, or to first client if client is NULL.
325 * \param c The client.
327 void
328 client_focus(client_t *c)
330 /* We have to set focus on first client */
331 if(!c && globalconf.clients.len && !(c = globalconf.clients.tab[0]))
332 return;
334 if(!client_maybevisible(c) || c == globalconf.focus.client)
335 return;
337 client_focus_update(c);
338 globalconf.focus.need_update = true;
341 void
342 client_focus_refresh(void)
344 client_t *c = globalconf.focus.client;
345 xcb_window_t win = globalconf.screen->root;
347 if(!globalconf.focus.need_update)
348 return;
349 globalconf.focus.need_update = false;
351 if(c)
353 /* Make sure this window is unbanned and e.g. not minimized */
354 client_unban(c);
355 /* Sets focus on window - using xcb_set_input_focus or WM_TAKE_FOCUS */
356 if(!c->nofocus)
357 win = c->window;
358 else
359 /* Focus the root window to make sure the previously focused client
360 * doesn't get any input in case WM_TAKE_FOCUS gets ignored.
362 win = globalconf.screen->root;
364 if(client_hasproto(c, WM_TAKE_FOCUS))
365 xwindow_takefocus(c->window);
368 /* If nothing has the focused or the currently focused client doesn't want
369 * us to focus it, this sets the focus to the root window. This makes sure
370 * the previously focused client actually gets unfocused. Alternatively, the
371 * new client gets the input focus.
373 xcb_set_input_focus(globalconf.connection, XCB_INPUT_FOCUS_PARENT,
374 win, globalconf.timestamp);
377 static void
378 client_update_properties(client_t *c)
380 /* get all hints */
381 xcb_get_property_cookie_t wm_normal_hints = property_get_wm_normal_hints(c);
382 xcb_get_property_cookie_t wm_hints = property_get_wm_hints(c);
383 xcb_get_property_cookie_t wm_transient_for = property_get_wm_transient_for(c);
384 xcb_get_property_cookie_t wm_client_leader = property_get_wm_client_leader(c);
385 xcb_get_property_cookie_t wm_client_machine = property_get_wm_client_machine(c);
386 xcb_get_property_cookie_t wm_window_role = property_get_wm_window_role(c);
387 xcb_get_property_cookie_t net_wm_pid = property_get_net_wm_pid(c);
388 xcb_get_property_cookie_t net_wm_icon = property_get_net_wm_icon(c);
389 xcb_get_property_cookie_t wm_name = property_get_wm_name(c);
390 xcb_get_property_cookie_t net_wm_name = property_get_net_wm_name(c);
391 xcb_get_property_cookie_t wm_icon_name = property_get_wm_icon_name(c);
392 xcb_get_property_cookie_t net_wm_icon_name = property_get_net_wm_icon_name(c);
393 xcb_get_property_cookie_t wm_class = property_get_wm_class(c);
394 xcb_get_property_cookie_t wm_protocols = property_get_wm_protocols(c);
395 xcb_get_property_cookie_t opacity = xwindow_get_opacity_unchecked(c->window);
397 /* update strut */
398 ewmh_process_client_strut(c);
400 /* Now process all replies */
401 property_update_wm_normal_hints(c, wm_normal_hints);
402 property_update_wm_hints(c, wm_hints);
403 property_update_wm_transient_for(c, wm_transient_for);
404 property_update_wm_client_leader(c, wm_client_leader);
405 property_update_wm_client_machine(c, wm_client_machine);
406 property_update_wm_window_role(c, wm_window_role);
407 property_update_net_wm_pid(c, net_wm_pid);
408 property_update_net_wm_icon(c, net_wm_icon);
409 property_update_wm_name(c, wm_name);
410 property_update_net_wm_name(c, net_wm_name);
411 property_update_wm_icon_name(c, wm_icon_name);
412 property_update_net_wm_icon_name(c, net_wm_icon_name);
413 property_update_wm_class(c, wm_class);
414 property_update_wm_protocols(c, wm_protocols);
415 window_set_opacity(globalconf.L, -1, xwindow_get_opacity_from_cookie(opacity));
418 /** Manage a new client.
419 * \param w The window.
420 * \param wgeom Window geometry.
421 * \param startup True if we are managing at startup time.
423 void
424 client_manage(xcb_window_t w, xcb_get_geometry_reply_t *wgeom, bool startup)
426 const uint32_t select_input_val[] = { CLIENT_SELECT_INPUT_EVENT_MASK };
428 if(systray_iskdedockapp(w))
430 systray_request_handle(w, NULL);
431 return;
434 /* If this is a new client that just has been launched, then request its
435 * startup id. */
436 xcb_get_property_cookie_t startup_id_q = { 0 };
437 if(!startup)
438 startup_id_q = xcb_get_property(globalconf.connection, false, w,
439 _NET_STARTUP_ID, XCB_GET_PROPERTY_TYPE_ANY, 0, UINT_MAX);
441 /* Make sure the window is automatically mapped if awesome exits or dies. */
442 xcb_change_save_set(globalconf.connection, XCB_SET_MODE_INSERT, w);
444 client_t *c = client_new(globalconf.L);
445 xcb_screen_t *s = globalconf.screen;
447 /* consider the window banned */
448 c->isbanned = true;
449 /* Store window */
450 c->window = w;
451 c->frame_window = xcb_generate_id(globalconf.connection);
452 xcb_create_window(globalconf.connection, globalconf.default_depth, c->frame_window, s->root,
453 wgeom->x, wgeom->y, wgeom->width, wgeom->height,
454 wgeom->border_width, XCB_COPY_FROM_PARENT, globalconf.visual->visual_id,
455 XCB_CW_BACK_PIXEL | XCB_CW_BORDER_PIXEL | XCB_CW_BIT_GRAVITY
456 | XCB_CW_WIN_GRAVITY | XCB_CW_OVERRIDE_REDIRECT | XCB_CW_EVENT_MASK
457 | XCB_CW_COLORMAP,
458 (const uint32_t [])
460 globalconf.screen->black_pixel,
461 globalconf.screen->black_pixel,
462 XCB_GRAVITY_NORTH_WEST,
463 XCB_GRAVITY_NORTH_WEST,
465 FRAME_SELECT_INPUT_EVENT_MASK,
466 globalconf.default_cmap
469 if (startup)
471 /* The client is already mapped, thus we must be sure that we don't send
472 * ourselves an UnmapNotify due to the xcb_reparent_window().
474 * Grab the server to make sure we don't lose any events.
476 uint32_t no_event[] = { 0 };
477 xcb_grab_server(globalconf.connection);
479 xcb_change_window_attributes(globalconf.connection,
480 globalconf.screen->root,
481 XCB_CW_EVENT_MASK,
482 no_event);
485 xcb_reparent_window(globalconf.connection, w, c->frame_window, 0, 0);
486 xcb_map_window(globalconf.connection, w);
488 if (startup)
490 xcb_change_window_attributes(globalconf.connection,
491 globalconf.screen->root,
492 XCB_CW_EVENT_MASK,
493 ROOT_WINDOW_EVENT_MASK);
494 xcb_ungrab_server(globalconf.connection);
497 /* Do this now so that we don't get any events for the above
498 * (Else, reparent could cause an UnmapNotify) */
499 xcb_change_window_attributes(globalconf.connection, w, XCB_CW_EVENT_MASK, select_input_val);
501 luaA_object_emit_signal(globalconf.L, -1, "property::window", 0);
503 /* The frame window gets the border, not the real client window */
504 xcb_configure_window(globalconf.connection, w,
505 XCB_CONFIG_WINDOW_BORDER_WIDTH,
506 (uint32_t[]) { 0 });
508 /* Move this window to the bottom of the stack. Without this we would force
509 * other windows which will be above this one to redraw themselves because
510 * this window occludes them for a tiny moment. The next stack_refresh()
511 * will fix this up and move the window to its correct place. */
512 xcb_configure_window(globalconf.connection, c->frame_window,
513 XCB_CONFIG_WINDOW_STACK_MODE,
514 (uint32_t[]) { XCB_STACK_MODE_BELOW});
516 /* Duplicate client and push it in client list */
517 lua_pushvalue(globalconf.L, -1);
518 client_array_push(&globalconf.clients, luaA_object_ref(globalconf.L, -1));
520 /* Set the right screen */
521 screen_client_moveto(c, screen_getbycoord(wgeom->x, wgeom->y), false);
523 /* Store initial geometry and emits signals so we inform that geometry have
524 * been set. */
525 #define HANDLE_GEOM(attr) \
526 c->geometry.attr = wgeom->attr; \
527 luaA_object_emit_signal(globalconf.L, -1, "property::" #attr, 0);
528 HANDLE_GEOM(x)
529 HANDLE_GEOM(y)
530 HANDLE_GEOM(width)
531 HANDLE_GEOM(height)
532 #undef HANDLE_GEOM
534 luaA_object_emit_signal(globalconf.L, -1, "property::geometry", 0);
536 /* Set border width */
537 window_set_border_width(globalconf.L, -1, wgeom->border_width);
539 /* we honor size hints by default */
540 c->size_hints_honor = true;
541 luaA_object_emit_signal(globalconf.L, -1, "property::size_hints_honor", 0);
543 /* update all properties */
544 client_update_properties(c);
546 /* Then check clients hints */
547 ewmh_client_check_hints(c);
549 /* Push client in stack */
550 client_raise(c);
552 /* Always stay in NORMAL_STATE. Even though iconified seems more
553 * appropriate sometimes. The only possible loss is that clients not using
554 * visibility events may continue to process data (when banned).
555 * Without any exposes or other events the cost should be fairly limited though.
557 * Some clients may expect the window to be unmapped when STATE_ICONIFIED.
558 * Two conflicting parts of the ICCCM v2.0 (section 4.1.4):
560 * "Normal -> Iconic - The client should send a ClientMessage event as described later in this section."
561 * (note no explicit mention of unmapping, while Normal->Widthdrawn does mention that)
563 * "Once a client's window has left the Withdrawn state, the window will be mapped
564 * if it is in the Normal state and the window will be unmapped if it is in the Iconic state."
566 * At this stage it's just safer to keep it in normal state and avoid confusion.
568 xwindow_set_state(c->window, XCB_ICCCM_WM_STATE_NORMAL);
570 if(!startup)
572 /* Request our response */
573 xcb_get_property_reply_t *reply =
574 xcb_get_property_reply(globalconf.connection, startup_id_q, NULL);
575 /* Say spawn that a client has been started, with startup id as argument */
576 char *startup_id = xutil_get_text_property_from_reply(reply);
577 p_delete(&reply);
578 spawn_start_notify(c, startup_id);
579 p_delete(&startup_id);
582 luaA_class_emit_signal(globalconf.L, &client_class, "list", 0);
584 /* client is still on top of the stack; push startup value,
585 * and emit signals with one arg */
586 lua_pushboolean(globalconf.L, startup);
587 luaA_object_emit_signal(globalconf.L, -2, "manage", 1);
588 /* pop client */
589 lua_pop(globalconf.L, 1);
592 static void
593 client_remove_titlebar_geometry(client_t *c, area_t *geometry)
595 geometry->x += c->titlebar[CLIENT_TITLEBAR_LEFT].size;
596 geometry->y += c->titlebar[CLIENT_TITLEBAR_TOP].size;
597 geometry->width -= c->titlebar[CLIENT_TITLEBAR_LEFT].size;
598 geometry->width -= c->titlebar[CLIENT_TITLEBAR_RIGHT].size;
599 geometry->height -= c->titlebar[CLIENT_TITLEBAR_TOP].size;
600 geometry->height -= c->titlebar[CLIENT_TITLEBAR_BOTTOM].size;
603 static void
604 client_add_titlebar_geometry(client_t *c, area_t *geometry)
606 geometry->x -= c->titlebar[CLIENT_TITLEBAR_LEFT].size;
607 geometry->y -= c->titlebar[CLIENT_TITLEBAR_TOP].size;
608 geometry->width += c->titlebar[CLIENT_TITLEBAR_LEFT].size;
609 geometry->width += c->titlebar[CLIENT_TITLEBAR_RIGHT].size;
610 geometry->height += c->titlebar[CLIENT_TITLEBAR_TOP].size;
611 geometry->height += c->titlebar[CLIENT_TITLEBAR_BOTTOM].size;
614 /** Send a synthetic configure event to a window.
616 void
617 client_send_configure(client_t *c)
619 area_t geometry = c->geometry;
621 if (!c->fullscreen)
622 client_remove_titlebar_geometry(c, &geometry);
623 xwindow_configure(c->window, geometry, c->border_width);
626 /** Apply size hints to the client's new geometry.
628 static area_t
629 client_apply_size_hints(client_t *c, area_t geometry)
631 int32_t minw = 0, minh = 0;
632 int32_t basew = 0, baseh = 0, real_basew = 0, real_baseh = 0;
634 if (c->fullscreen)
635 return geometry;
637 /* Size hints are applied to the window without any decoration */
638 client_remove_titlebar_geometry(c, &geometry);
640 if(c->size_hints.flags & XCB_ICCCM_SIZE_HINT_P_SIZE)
642 basew = c->size_hints.base_width;
643 baseh = c->size_hints.base_height;
644 real_basew = basew;
645 real_baseh = baseh;
647 else if(c->size_hints.flags & XCB_ICCCM_SIZE_HINT_P_MIN_SIZE)
649 /* base size is substituted with min size if not specified */
650 basew = c->size_hints.min_width;
651 baseh = c->size_hints.min_height;
654 if(c->size_hints.flags & XCB_ICCCM_SIZE_HINT_P_MIN_SIZE)
656 minw = c->size_hints.min_width;
657 minh = c->size_hints.min_height;
659 else if(c->size_hints.flags & XCB_ICCCM_SIZE_HINT_P_SIZE)
661 /* min size is substituted with base size if not specified */
662 minw = c->size_hints.base_width;
663 minh = c->size_hints.base_height;
666 /* Handle the size aspect ratio */
667 if(c->size_hints.flags & XCB_ICCCM_SIZE_HINT_P_ASPECT
668 && c->size_hints.min_aspect_den > 0
669 && c->size_hints.max_aspect_den > 0
670 && geometry.height > real_baseh
671 && geometry.width > real_basew)
673 /* ICCCM mandates:
674 * If a base size is provided along with the aspect ratio fields, the base size should be subtracted from the
675 * window size prior to checking that the aspect ratio falls in range. If a base size is not provided, nothing
676 * should be subtracted from the window size. (The minimum size is not to be used in place of the base size for
677 * this purpose.)
679 double dx = geometry.width - real_basew;
680 double dy = geometry.height - real_baseh;
681 double ratio = dx / dy;
682 double min = c->size_hints.min_aspect_num / (double) c->size_hints.min_aspect_den;
683 double max = c->size_hints.max_aspect_num / (double) c->size_hints.max_aspect_den;
685 if(max > 0 && min > 0 && ratio > 0)
687 if(ratio < min)
689 /* dx is lower than allowed, make dy lower to compensate this (+ 0.5 to force proper rounding). */
690 dy = dx / min + 0.5;
691 geometry.width = dx + real_basew;
692 geometry.height = dy + real_baseh;
693 } else if(ratio > max)
695 /* dx is too high, lower it (+0.5 for proper rounding) */
696 dx = dy * max + 0.5;
697 geometry.width = dx + real_basew;
698 geometry.height = dy + real_baseh;
703 /* Handle the minimum size */
704 geometry.width = MAX(geometry.width, minw);
705 geometry.height = MAX(geometry.height, minh);
707 /* Handle the maximum size */
708 if(c->size_hints.flags & XCB_ICCCM_SIZE_HINT_P_MAX_SIZE)
710 if(c->size_hints.max_width)
711 geometry.width = MIN(geometry.width, c->size_hints.max_width);
712 if(c->size_hints.max_height)
713 geometry.height = MIN(geometry.height, c->size_hints.max_height);
716 /* Handle the size increment */
717 if(c->size_hints.flags & (XCB_ICCCM_SIZE_HINT_P_RESIZE_INC | XCB_ICCCM_SIZE_HINT_BASE_SIZE)
718 && c->size_hints.width_inc && c->size_hints.height_inc)
720 uint16_t t1 = geometry.width, t2 = geometry.height;
721 unsigned_subtract(t1, basew);
722 unsigned_subtract(t2, baseh);
723 geometry.width -= t1 % c->size_hints.width_inc;
724 geometry.height -= t2 % c->size_hints.height_inc;
727 client_add_titlebar_geometry(c, &geometry);
728 return geometry;
731 static void
732 client_resize_do(client_t *c, area_t geometry, bool force_notice, bool honor_hints)
734 bool send_notice = force_notice;
735 bool hide_titlebars = c->fullscreen;
736 screen_t *new_screen = screen_getbycoord(geometry.x, geometry.y);
738 if (honor_hints)
739 geometry = client_apply_size_hints(c, geometry);
741 if(c->geometry.width == geometry.width
742 && c->geometry.height == geometry.height)
743 send_notice = true;
745 /* Also store geometry including border */
746 area_t old_geometry = c->geometry;
747 c->geometry = geometry;
749 /* Ignore all spurious enter/leave notify events */
750 client_ignore_enterleave_events();
752 /* Configure the client for its new size */
753 area_t real_geometry = geometry;
754 if (!hide_titlebars)
756 real_geometry.x = c->titlebar[CLIENT_TITLEBAR_LEFT].size;
757 real_geometry.y = c->titlebar[CLIENT_TITLEBAR_TOP].size;
758 real_geometry.width -= c->titlebar[CLIENT_TITLEBAR_LEFT].size;
759 real_geometry.width -= c->titlebar[CLIENT_TITLEBAR_RIGHT].size;
760 real_geometry.height -= c->titlebar[CLIENT_TITLEBAR_TOP].size;
761 real_geometry.height -= c->titlebar[CLIENT_TITLEBAR_BOTTOM].size;
762 } else {
763 real_geometry.x = 0;
764 real_geometry.y = 0;
767 xcb_configure_window(globalconf.connection, c->frame_window,
768 XCB_CONFIG_WINDOW_X | XCB_CONFIG_WINDOW_Y | XCB_CONFIG_WINDOW_WIDTH | XCB_CONFIG_WINDOW_HEIGHT,
769 (uint32_t[]) { geometry.x, geometry.y, geometry.width, geometry.height });
770 xcb_configure_window(globalconf.connection, c->window,
771 XCB_CONFIG_WINDOW_X | XCB_CONFIG_WINDOW_Y | XCB_CONFIG_WINDOW_WIDTH | XCB_CONFIG_WINDOW_HEIGHT,
772 (uint32_t[]) { real_geometry.x, real_geometry.y, real_geometry.width, real_geometry.height });
774 if(send_notice)
775 /* We are moving without changing the size, see ICCCM 4.2.3 */
776 client_send_configure(c);
778 client_restore_enterleave_events();
780 screen_client_moveto(c, new_screen, false);
782 luaA_object_push(globalconf.L, c);
783 luaA_object_emit_signal(globalconf.L, -1, "property::geometry", 0);
784 if (old_geometry.x != geometry.x)
785 luaA_object_emit_signal(globalconf.L, -1, "property::x", 0);
786 if (old_geometry.y != geometry.y)
787 luaA_object_emit_signal(globalconf.L, -1, "property::y", 0);
788 if (old_geometry.width != geometry.width)
789 luaA_object_emit_signal(globalconf.L, -1, "property::width", 0);
790 if (old_geometry.height != geometry.height)
791 luaA_object_emit_signal(globalconf.L, -1, "property::height", 0);
792 lua_pop(globalconf.L, 1);
794 /* Update all titlebars */
795 for (client_titlebar_t bar = CLIENT_TITLEBAR_TOP; bar < CLIENT_TITLEBAR_COUNT; bar++) {
796 if (c->titlebar[bar].drawable == NULL && c->titlebar[bar].size == 0)
797 continue;
799 luaA_object_push(globalconf.L, c);
800 drawable_t *drawable = titlebar_get_drawable(globalconf.L, c, -1, bar);
801 luaA_object_push_item(globalconf.L, -1, drawable);
803 area_t area = titlebar_get_area(c, bar);
805 /* Convert to global coordinates */
806 area.x += geometry.x;
807 area.y += geometry.y;
808 if (hide_titlebars)
809 area.width = area.height = 0;
811 if (old_geometry.width != geometry.width || old_geometry.height != geometry.height ||
812 drawable->geometry.width == 0 || drawable->geometry.height == 0) {
813 /* Get rid of the old state */
814 drawable_unset_surface(drawable);
815 if (c->titlebar[bar].pixmap != XCB_NONE)
816 xcb_free_pixmap(globalconf.connection, c->titlebar[bar].pixmap);
817 c->titlebar[bar].pixmap = XCB_NONE;
819 /* And get us some new state */
820 if (c->titlebar[bar].size != 0 && !hide_titlebars)
822 c->titlebar[bar].pixmap = xcb_generate_id(globalconf.connection);
823 xcb_create_pixmap(globalconf.connection, globalconf.default_depth, c->titlebar[bar].pixmap,
824 globalconf.screen->root, area.width, area.height);
825 cairo_surface_t *surface = cairo_xcb_surface_create(globalconf.connection,
826 c->titlebar[bar].pixmap, globalconf.visual,
827 area.width, area.height);
828 drawable_set_surface(drawable, -1, surface, area);
829 } else
830 drawable_set_geometry(drawable, -1, area);
831 } else
832 drawable_set_geometry(drawable, -1, area);
834 /* Pop the client and the drawable */
835 lua_pop(globalconf.L, 2);
839 /** Resize client window.
840 * The sizes given as parameters are with borders!
841 * \param c Client to resize.
842 * \param geometry New window geometry.
843 * \param honor_hints Use size hints.
844 * \return true if an actual resize occurred.
846 bool
847 client_resize(client_t *c, area_t geometry, bool honor_hints)
849 area_t area;
851 /* offscreen appearance fixes */
852 area = display_area_get();
854 if(geometry.x > area.width)
855 geometry.x = area.width - geometry.width;
856 if(geometry.y > area.height)
857 geometry.y = area.height - geometry.height;
858 if(geometry.x + geometry.width < 0)
859 geometry.x = 0;
860 if(geometry.y + geometry.height < 0)
861 geometry.y = 0;
863 if(geometry.width < c->titlebar[CLIENT_TITLEBAR_LEFT].size + c->titlebar[CLIENT_TITLEBAR_RIGHT].size)
864 return false;
865 if(geometry.height < c->titlebar[CLIENT_TITLEBAR_TOP].size + c->titlebar[CLIENT_TITLEBAR_BOTTOM].size)
866 return false;
868 if(geometry.width == 0 || geometry.height == 0)
869 return false;
871 if(c->geometry.x != geometry.x
872 || c->geometry.y != geometry.y
873 || c->geometry.width != geometry.width
874 || c->geometry.height != geometry.height)
876 client_resize_do(c, geometry, false, honor_hints);
878 return true;
881 return false;
884 /** Set a client minimized, or not.
885 * \param L The Lua VM state.
886 * \param cidx The client index.
887 * \param s Set or not the client minimized.
889 void
890 client_set_minimized(lua_State *L, int cidx, bool s)
892 client_t *c = luaA_checkudata(L, cidx, &client_class);
894 if(c->minimized != s)
896 c->minimized = s;
897 banning_need_update();
898 if(s)
899 xwindow_set_state(c->window, XCB_ICCCM_WM_STATE_ICONIC);
900 else
901 xwindow_set_state(c->window, XCB_ICCCM_WM_STATE_NORMAL);
902 if(strut_has_value(&c->strut))
903 screen_emit_signal(globalconf.L, c->screen, "property::workarea", 0);
904 luaA_object_emit_signal(L, cidx, "property::minimized", 0);
908 /** Set a client hidden, or not.
909 * \param L The Lua VM state.
910 * \param cidx The client index.
911 * \param s Set or not the client hidden.
913 static void
914 client_set_hidden(lua_State *L, int cidx, bool s)
916 client_t *c = luaA_checkudata(L, cidx, &client_class);
918 if(c->hidden != s)
920 c->hidden = s;
921 banning_need_update();
922 if(strut_has_value(&c->strut))
923 screen_emit_signal(globalconf.L, c->screen, "property::workarea", 0);
924 luaA_object_emit_signal(L, cidx, "property::hidden", 0);
928 /** Set a client sticky, or not.
929 * \param L The Lua VM state.
930 * \param cidx The client index.
931 * \param s Set or not the client sticky.
933 void
934 client_set_sticky(lua_State *L, int cidx, bool s)
936 client_t *c = luaA_checkudata(L, cidx, &client_class);
938 if(c->sticky != s)
940 c->sticky = s;
941 banning_need_update();
942 luaA_object_emit_signal(L, cidx, "property::sticky", 0);
946 /** Set a client fullscreen, or not.
947 * \param L The Lua VM state.
948 * \param cidx The client index.
949 * \param s Set or not the client fullscreen.
951 void
952 client_set_fullscreen(lua_State *L, int cidx, bool s)
954 client_t *c = luaA_checkudata(L, cidx, &client_class);
956 if(c->fullscreen != s)
958 /* become fullscreen! */
959 if(s)
961 /* remove any max state */
962 client_set_maximized_horizontal(L, cidx, false);
963 client_set_maximized_vertical(L, cidx, false);
964 /* You can only be part of one of the special layers. */
965 client_set_below(L, cidx, false);
966 client_set_above(L, cidx, false);
967 client_set_ontop(L, cidx, false);
969 int abs_cidx = luaA_absindex(L, cidx); \
970 lua_pushboolean(L, s);
971 c->fullscreen = s;
972 luaA_object_emit_signal(L, abs_cidx, "request::fullscreen", 1);
973 luaA_object_emit_signal(L, abs_cidx, "property::fullscreen", 0);
974 /* Force a client resize, so that titlebars get shown/hidden */
975 client_resize_do(c, c->geometry, true, false);
976 stack_windows();
980 /** Set a client horizontally|vertically maximized.
981 * \param L The Lua VM state.
982 * \param cidx The client index.
983 * \param s The maximized status.
985 #define DO_FUNCTION_CLIENT_MAXIMIZED(type) \
986 void \
987 client_set_maximized_##type(lua_State *L, int cidx, bool s) \
989 client_t *c = luaA_checkudata(L, cidx, &client_class); \
990 if(c->maximized_##type != s) \
992 int abs_cidx = luaA_absindex(L, cidx); \
993 if(s) \
994 client_set_fullscreen(L, abs_cidx, false); \
995 lua_pushboolean(L, s); \
996 c->maximized_##type = s; \
997 luaA_object_emit_signal(L, abs_cidx, "request::maximized_" #type, 1); \
998 luaA_object_emit_signal(L, abs_cidx, "property::maximized_" #type, 0); \
999 stack_windows(); \
1002 DO_FUNCTION_CLIENT_MAXIMIZED(vertical)
1003 DO_FUNCTION_CLIENT_MAXIMIZED(horizontal)
1004 #undef DO_FUNCTION_CLIENT_MAXIMIZED
1006 /** Set a client above, or not.
1007 * \param L The Lua VM state.
1008 * \param cidx The client index.
1009 * \param s Set or not the client above.
1011 void
1012 client_set_above(lua_State *L, int cidx, bool s)
1014 client_t *c = luaA_checkudata(L, cidx, &client_class);
1016 if(c->above != s)
1018 /* You can only be part of one of the special layers. */
1019 if(s)
1021 client_set_below(L, cidx, false);
1022 client_set_ontop(L, cidx, false);
1023 client_set_fullscreen(L, cidx, false);
1025 c->above = s;
1026 stack_windows();
1027 luaA_object_emit_signal(L, cidx, "property::above", 0);
1031 /** Set a client below, or not.
1032 * \param L The Lua VM state.
1033 * \param cidx The client index.
1034 * \param s Set or not the client below.
1036 void
1037 client_set_below(lua_State *L, int cidx, bool s)
1039 client_t *c = luaA_checkudata(L, cidx, &client_class);
1041 if(c->below != s)
1043 /* You can only be part of one of the special layers. */
1044 if(s)
1046 client_set_above(L, cidx, false);
1047 client_set_ontop(L, cidx, false);
1048 client_set_fullscreen(L, cidx, false);
1050 c->below = s;
1051 stack_windows();
1052 luaA_object_emit_signal(L, cidx, "property::below", 0);
1056 /** Set a client modal, or not.
1057 * \param L The Lua VM state.
1058 * \param cidx The client index.
1059 * \param s Set or not the client modal attribute.
1061 void
1062 client_set_modal(lua_State *L, int cidx, bool s)
1064 client_t *c = luaA_checkudata(L, cidx, &client_class);
1066 if(c->modal != s)
1068 c->modal = s;
1069 stack_windows();
1070 luaA_object_emit_signal(L, cidx, "property::modal", 0);
1074 /** Set a client ontop, or not.
1075 * \param L The Lua VM state.
1076 * \param cidx The client index.
1077 * \param s Set or not the client ontop attribute.
1079 void
1080 client_set_ontop(lua_State *L, int cidx, bool s)
1082 client_t *c = luaA_checkudata(L, cidx, &client_class);
1084 if(c->ontop != s)
1086 /* You can only be part of one of the special layers. */
1087 if(s)
1089 client_set_above(L, cidx, false);
1090 client_set_below(L, cidx, false);
1091 client_set_fullscreen(L, cidx, false);
1093 c->ontop = s;
1094 stack_windows();
1095 luaA_object_emit_signal(L, cidx, "property::ontop", 0);
1099 /** Unban a client and move it back into the viewport.
1100 * \param c The client.
1102 void
1103 client_unban(client_t *c)
1105 if(c->isbanned)
1107 xcb_map_window(globalconf.connection, c->frame_window);
1109 c->isbanned = false;
1111 /* An unbanned client shouldn't be minimized or hidden */
1112 luaA_object_push(globalconf.L, c);
1113 client_set_minimized(globalconf.L, -1, false);
1114 client_set_hidden(globalconf.L, -1, false);
1115 lua_pop(globalconf.L, 1);
1119 /** Unmanage a client.
1120 * \param c The client.
1121 * \param window_valid Is the client's window still valid?
1123 void
1124 client_unmanage(client_t *c, bool window_valid)
1126 /* Reset transient_for attributes of widows that maybe referring to us */
1127 foreach(_tc, globalconf.clients)
1129 client_t *tc = *_tc;
1130 if(tc->transient_for == c)
1131 tc->transient_for = NULL;
1134 if(globalconf.focus.client == c)
1135 client_unfocus(c);
1137 /* remove client from global list and everywhere else */
1138 foreach(elem, globalconf.clients)
1139 if(*elem == c)
1141 client_array_remove(&globalconf.clients, elem);
1142 break;
1144 stack_client_remove(c);
1145 for(int i = 0; i < globalconf.tags.len; i++)
1146 untag_client(c, globalconf.tags.tab[i]);
1148 luaA_object_push(globalconf.L, c);
1149 luaA_object_emit_signal(globalconf.L, -1, "unmanage", 0);
1150 lua_pop(globalconf.L, 1);
1152 luaA_class_emit_signal(globalconf.L, &client_class, "list", 0);
1154 if(strut_has_value(&c->strut))
1155 screen_emit_signal(globalconf.L, c->screen, "property::workarea", 0);
1157 /* Get rid of all titlebars */
1158 for (client_titlebar_t bar = CLIENT_TITLEBAR_TOP; bar < CLIENT_TITLEBAR_COUNT; bar++) {
1159 if (c->titlebar[bar].drawable == NULL)
1160 continue;
1162 luaA_object_push(globalconf.L, c);
1163 luaA_object_push_item(globalconf.L, -1, c->titlebar[bar].drawable);
1165 /* Make the drawable unusable */
1166 drawable_unset_surface(c->titlebar[bar].drawable);
1167 if (c->titlebar[bar].pixmap != XCB_NONE)
1168 xcb_free_pixmap(globalconf.connection, c->titlebar[bar].pixmap);
1170 /* And forget about it */
1171 luaA_object_unref_item(globalconf.L, -2, c->titlebar[bar].drawable);
1172 c->titlebar[bar].drawable = NULL;
1173 lua_pop(globalconf.L, 2);
1176 /* Clear our event mask so that we don't receive any events from now on,
1177 * especially not for the following requests. */
1178 if(window_valid)
1179 xcb_change_window_attributes(globalconf.connection,
1180 c->window,
1181 XCB_CW_EVENT_MASK,
1182 (const uint32_t []) { 0 });
1183 xcb_change_window_attributes(globalconf.connection,
1184 c->frame_window,
1185 XCB_CW_EVENT_MASK,
1186 (const uint32_t []) { 0 });
1188 if(window_valid)
1190 xcb_unmap_window(globalconf.connection, c->window);
1191 xcb_reparent_window(globalconf.connection, c->window, globalconf.screen->root,
1192 c->geometry.x, c->geometry.y);
1194 xcb_destroy_window(globalconf.connection, c->frame_window);
1196 if(window_valid)
1198 /* Remove this window from the save set since this shouldn't be made visible
1199 * after a restart anymore. */
1200 xcb_change_save_set(globalconf.connection, XCB_SET_MODE_DELETE, c->window);
1202 /* Do this last to avoid races with clients. According to ICCCM, clients
1203 * arent allowed to re-use the window until after this. */
1204 xwindow_set_state(c->window, XCB_ICCCM_WM_STATE_WITHDRAWN);
1207 /* set client as invalid */
1208 c->window = XCB_NONE;
1210 luaA_object_unref(globalconf.L, c);
1213 /** Kill a client via a WM_DELETE_WINDOW request or KillClient if not
1214 * supported.
1215 * \param c The client to kill.
1217 void
1218 client_kill(client_t *c)
1220 if(client_hasproto(c, WM_DELETE_WINDOW))
1222 xcb_client_message_event_t ev;
1224 /* Initialize all of event's fields first */
1225 p_clear(&ev, 1);
1227 ev.response_type = XCB_CLIENT_MESSAGE;
1228 ev.window = c->window;
1229 ev.format = 32;
1230 ev.data.data32[1] = globalconf.timestamp;
1231 ev.type = WM_PROTOCOLS;
1232 ev.data.data32[0] = WM_DELETE_WINDOW;
1234 xcb_send_event(globalconf.connection, false, c->window,
1235 XCB_EVENT_MASK_NO_EVENT, (char *) &ev);
1237 else
1238 xcb_kill_client(globalconf.connection, c->window);
1241 /** Get all clients into a table.
1242 * \param L The Lua VM state.
1243 * \return The number of elements pushed on stack.
1244 * \luastack
1245 * \lparam An optional screen number.
1246 * \lreturn A table with all clients.
1248 static int
1249 luaA_client_get(lua_State *L)
1251 int i = 1, screen;
1253 screen = luaL_optnumber(L, 1, 0) - 1;
1255 lua_newtable(L);
1257 if(screen == -1)
1258 foreach(c, globalconf.clients)
1260 luaA_object_push(L, *c);
1261 lua_rawseti(L, -2, i++);
1263 else
1265 luaA_checkscreen(screen);
1266 foreach(c, globalconf.clients)
1267 if((*c)->screen == &globalconf.screens.tab[screen])
1269 luaA_object_push(L, *c);
1270 lua_rawseti(L, -2, i++);
1274 return 1;
1277 /** Check if a client is visible on its screen.
1278 * \param L The Lua VM state.
1279 * \return The number of elements pushed on stack.
1280 * \luastack
1281 * \lvalue A client.
1282 * \lreturn A boolean value, true if the client is visible, false otherwise.
1284 static int
1285 luaA_client_isvisible(lua_State *L)
1287 client_t *c = luaA_checkudata(L, 1, &client_class);
1288 lua_pushboolean(L, client_isvisible(c));
1289 return 1;
1292 /** Set a client icon.
1293 * \param L The Lua VM state.
1294 * \param cidx The client index on the stack.
1295 * \param iidx The image index on the stack.
1297 void
1298 client_set_icon(client_t *c, cairo_surface_t *s)
1300 if (s)
1301 s = draw_dup_image_surface(s);
1302 if(c->icon)
1303 cairo_surface_destroy(c->icon);
1304 c->icon = s;
1306 luaA_object_push(globalconf.L, c);
1307 luaA_object_emit_signal(globalconf.L, -1, "property::icon", 0);
1308 lua_pop(globalconf.L, 1);
1311 /** Kill a client.
1312 * \param L The Lua VM state.
1314 * \luastack
1315 * \lvalue A client.
1317 static int
1318 luaA_client_kill(lua_State *L)
1320 client_t *c = luaA_checkudata(L, 1, &client_class);
1321 client_kill(c);
1322 return 0;
1325 /** Swap a client with another one.
1326 * \param L The Lua VM state.
1327 * \luastack
1328 * \lvalue A client.
1329 * \lparam A client to swap with.
1331 static int
1332 luaA_client_swap(lua_State *L)
1334 client_t *c = luaA_checkudata(L, 1, &client_class);
1335 client_t *swap = luaA_checkudata(L, 2, &client_class);
1337 if(c != swap)
1339 client_t **ref_c = NULL, **ref_swap = NULL;
1340 foreach(item, globalconf.clients)
1342 if(*item == c)
1343 ref_c = item;
1344 else if(*item == swap)
1345 ref_swap = item;
1346 if(ref_c && ref_swap)
1347 break;
1349 /* swap ! */
1350 *ref_c = swap;
1351 *ref_swap = c;
1353 luaA_class_emit_signal(globalconf.L, &client_class, "list", 0);
1356 return 0;
1359 /** Access or set the client tags.
1360 * \param L The Lua VM state.
1361 * \return The number of elements pushed on stack.
1362 * \lparam A table with tags to set, or none to get the current tags table.
1363 * \return The clients tag.
1365 static int
1366 luaA_client_tags(lua_State *L)
1368 client_t *c = luaA_checkudata(L, 1, &client_class);
1369 int j = 0;
1371 if(lua_gettop(L) == 2)
1373 luaA_checktable(L, 2);
1374 for(int i = 0; i < globalconf.tags.len; i++)
1376 /* Only untag if we aren't going to add this tag again */
1377 bool found = false;
1378 lua_pushnil(L);
1379 while(lua_next(L, 2))
1381 tag_t *t = lua_touserdata(L, -1);
1382 /* Pop the value from lua_next */
1383 lua_pop(L, 1);
1384 if (t != globalconf.tags.tab[i])
1385 continue;
1387 /* Pop the key from lua_next */
1388 lua_pop(L, 1);
1389 found = true;
1390 break;
1392 if(!found)
1393 untag_client(c, globalconf.tags.tab[i]);
1395 lua_pushnil(L);
1396 while(lua_next(L, 2))
1397 tag_client(c);
1398 lua_pop(L, 1);
1401 lua_newtable(L);
1402 foreach(tag, globalconf.tags)
1403 if(is_client_tagged(c, *tag))
1405 luaA_object_push(L, *tag);
1406 lua_rawseti(L, -2, ++j);
1409 return 1;
1412 /** Raise a client on top of others which are on the same layer.
1413 * \param L The Lua VM state.
1414 * \luastack
1415 * \lvalue A client.
1417 static int
1418 luaA_client_raise(lua_State *L)
1420 client_t *c = luaA_checkudata(L, 1, &client_class);
1421 client_raise(c);
1422 return 0;
1425 /** Lower a client on bottom of others which are on the same layer.
1426 * \param L The Lua VM state.
1427 * \luastack
1428 * \lvalue A client.
1430 static int
1431 luaA_client_lower(lua_State *L)
1433 client_t *c = luaA_checkudata(L, 1, &client_class);
1435 stack_client_push(c);
1437 /* Traverse all transient layers. */
1438 for(client_t *tc = c->transient_for; tc; tc = tc->transient_for)
1439 stack_client_push(tc);
1441 return 0;
1444 /** Stop managing a client.
1445 * \param L The Lua VM state.
1446 * \return The number of elements pushed on stack.
1447 * \luastack
1448 * \lvalue A client.
1450 static int
1451 luaA_client_unmanage(lua_State *L)
1453 client_t *c = luaA_checkudata(L, 1, &client_class);
1454 client_unmanage(c, true);
1455 return 0;
1458 static area_t
1459 titlebar_get_area(client_t *c, client_titlebar_t bar)
1461 area_t result = c->geometry;
1462 result.x = result.y = 0;
1464 // Let's try some ascii art:
1465 // ---------------------------
1466 // | Top |
1467 // |-------------------------|
1468 // |L| |R|
1469 // |e| |i|
1470 // |f| |g|
1471 // |t| |h|
1472 // | | |t|
1473 // |-------------------------|
1474 // | Bottom |
1475 // ---------------------------
1477 switch (bar) {
1478 case CLIENT_TITLEBAR_BOTTOM:
1479 result.y = c->geometry.height - c->titlebar[bar].size;
1480 /* Fall through */
1481 case CLIENT_TITLEBAR_TOP:
1482 result.height = c->titlebar[bar].size;
1483 break;
1484 case CLIENT_TITLEBAR_RIGHT:
1485 result.x = c->geometry.width - c->titlebar[bar].size;
1486 /* Fall through */
1487 case CLIENT_TITLEBAR_LEFT:
1488 result.y = c->titlebar[CLIENT_TITLEBAR_TOP].size;
1489 result.width = c->titlebar[bar].size;
1490 result.height -= c->titlebar[CLIENT_TITLEBAR_TOP].size;
1491 result.height -= c->titlebar[CLIENT_TITLEBAR_BOTTOM].size;
1492 break;
1493 default:
1494 fatal("Unknown titlebar kind %d\n", (int) bar);
1497 return result;
1500 drawable_t *
1501 client_get_drawable_offset(client_t *c, int *x, int *y)
1503 for (client_titlebar_t bar = CLIENT_TITLEBAR_TOP; bar < CLIENT_TITLEBAR_COUNT; bar++) {
1504 area_t area = titlebar_get_area(c, bar);
1505 if (AREA_LEFT(area) > *x || AREA_RIGHT(area) <= *x)
1506 continue;
1507 if (AREA_TOP(area) > *y || AREA_BOTTOM(area) <= *y)
1508 continue;
1510 *x -= area.x;
1511 *y -= area.y;
1512 return c->titlebar[bar].drawable;
1515 return NULL;
1518 drawable_t *
1519 client_get_drawable(client_t *c, int x, int y)
1521 return client_get_drawable_offset(c, &x, &y);
1524 void
1525 client_refresh(client_t *c)
1527 for (client_titlebar_t bar = CLIENT_TITLEBAR_TOP; bar < CLIENT_TITLEBAR_COUNT; bar++) {
1528 if (c->titlebar[bar].drawable == NULL || c->titlebar[bar].drawable->surface == NULL)
1529 continue;
1531 area_t area = titlebar_get_area(c, bar);
1532 cairo_surface_flush(c->titlebar[bar].drawable->surface);
1533 xcb_copy_area(globalconf.connection, c->titlebar[bar].pixmap, c->frame_window,
1534 globalconf.gc, 0, 0, area.x, area.y, area.width, area.height);
1538 static drawable_t *
1539 titlebar_get_drawable(lua_State *L, client_t *c, int cl_idx, client_titlebar_t bar)
1541 if (c->titlebar[bar].drawable == NULL)
1543 cl_idx = luaA_absindex(L, cl_idx);
1544 drawable_allocator(L, (drawable_refresh_callback *) client_refresh, c);
1545 c->titlebar[bar].drawable = luaA_object_ref_item(L, cl_idx, -1);
1548 return c->titlebar[bar].drawable;
1551 static void
1552 titlebar_resize(client_t *c, client_titlebar_t bar, int size)
1554 if (size < 0)
1555 return;
1557 if (size == c->titlebar[bar].size)
1558 return;
1560 /* Now resize the client (and titlebars!) suitably (the client without
1561 * titlebars should keep its current size!) */
1562 area_t geometry = c->geometry;
1563 int change = size - c->titlebar[bar].size;
1564 switch (bar) {
1565 case CLIENT_TITLEBAR_TOP:
1566 case CLIENT_TITLEBAR_BOTTOM:
1567 geometry.height += change;
1568 break;
1569 case CLIENT_TITLEBAR_RIGHT:
1570 case CLIENT_TITLEBAR_LEFT:
1571 geometry.width += change;
1572 break;
1573 default:
1574 fatal("Unknown titlebar kind %d\n", (int) bar);
1577 c->titlebar[bar].size = size;
1578 client_resize_do(c, geometry, true, false);
1581 #define HANDLE_TITLEBAR(name, index) \
1582 static int \
1583 luaA_client_titlebar_ ## name(lua_State *L) \
1585 client_t *c = luaA_checkudata(L, 1, &client_class); \
1587 if (lua_gettop(L) == 2) \
1589 if (lua_isnil(L, 2)) \
1590 titlebar_resize(c, index, 0); \
1591 else \
1592 titlebar_resize(c, index, luaL_checknumber(L, 2)); \
1595 luaA_object_push_item(L, 1, titlebar_get_drawable(L, c, 1, index)); \
1596 lua_pushnumber(L, c->titlebar[index].size); \
1597 return 2; \
1599 HANDLE_TITLEBAR(top, CLIENT_TITLEBAR_TOP)
1600 HANDLE_TITLEBAR(right, CLIENT_TITLEBAR_RIGHT)
1601 HANDLE_TITLEBAR(bottom, CLIENT_TITLEBAR_BOTTOM)
1602 HANDLE_TITLEBAR(left, CLIENT_TITLEBAR_LEFT)
1604 /** Return client geometry.
1605 * \param L The Lua VM state.
1606 * \return The number of elements pushed on stack.
1607 * \luastack
1608 * \lparam A table with new coordinates, or none.
1609 * \lreturn A table with client coordinates.
1611 static int
1612 luaA_client_geometry(lua_State *L)
1614 client_t *c = luaA_checkudata(L, 1, &client_class);
1616 if(lua_gettop(L) == 2 && !lua_isnil(L, 2))
1618 area_t geometry;
1620 luaA_checktable(L, 2);
1621 geometry.x = luaA_getopt_number(L, 2, "x", c->geometry.x);
1622 geometry.y = luaA_getopt_number(L, 2, "y", c->geometry.y);
1623 if(client_isfixed(c))
1625 geometry.width = c->geometry.width;
1626 geometry.height = c->geometry.height;
1628 else
1630 geometry.width = luaA_getopt_number(L, 2, "width", c->geometry.width);
1631 geometry.height = luaA_getopt_number(L, 2, "height", c->geometry.height);
1634 client_resize(c, geometry, c->size_hints_honor);
1637 return luaA_pusharea(L, c->geometry);
1640 static int
1641 luaA_client_set_screen(lua_State *L, client_t *c)
1643 int screen = luaL_checknumber(L, -1) - 1;
1644 luaA_checkscreen(screen);
1645 screen_client_moveto(c, &globalconf.screens.tab[screen], true);
1647 return 0;
1650 static int
1651 luaA_client_set_hidden(lua_State *L, client_t *c)
1653 client_set_hidden(L, -3, luaA_checkboolean(L, -1));
1654 return 0;
1657 static int
1658 luaA_client_set_minimized(lua_State *L, client_t *c)
1660 client_set_minimized(L, -3, luaA_checkboolean(L, -1));
1661 return 0;
1664 static int
1665 luaA_client_set_fullscreen(lua_State *L, client_t *c)
1667 client_set_fullscreen(L, -3, luaA_checkboolean(L, -1));
1668 return 0;
1671 static int
1672 luaA_client_set_modal(lua_State *L, client_t *c)
1674 client_set_modal(L, -3, luaA_checkboolean(L, -1));
1675 return 0;
1678 static int
1679 luaA_client_set_maximized_horizontal(lua_State *L, client_t *c)
1681 client_set_maximized_horizontal(L, -3, luaA_checkboolean(L, -1));
1682 return 0;
1685 static int
1686 luaA_client_set_maximized_vertical(lua_State *L, client_t *c)
1688 client_set_maximized_vertical(L, -3, luaA_checkboolean(L, -1));
1689 return 0;
1692 static int
1693 luaA_client_set_icon(lua_State *L, client_t *c)
1695 cairo_surface_t *surf = NULL;
1696 if(!lua_isnil(L, -1))
1697 surf = (cairo_surface_t *)lua_touserdata(L, -1);
1698 client_set_icon(c, surf);
1699 return 0;
1702 static int
1703 luaA_client_set_sticky(lua_State *L, client_t *c)
1705 client_set_sticky(L, -3, luaA_checkboolean(L, -1));
1706 return 0;
1709 static int
1710 luaA_client_set_size_hints_honor(lua_State *L, client_t *c)
1712 c->size_hints_honor = luaA_checkboolean(L, -1);
1713 luaA_object_emit_signal(L, -3, "property::size_hints_honor", 0);
1714 return 0;
1717 static int
1718 luaA_client_set_ontop(lua_State *L, client_t *c)
1720 client_set_ontop(L, -3, luaA_checkboolean(L, -1));
1721 return 0;
1724 static int
1725 luaA_client_set_below(lua_State *L, client_t *c)
1727 client_set_below(L, -3, luaA_checkboolean(L, -1));
1728 return 0;
1731 static int
1732 luaA_client_set_above(lua_State *L, client_t *c)
1734 client_set_above(L, -3, luaA_checkboolean(L, -1));
1735 return 0;
1738 static int
1739 luaA_client_set_urgent(lua_State *L, client_t *c)
1741 client_set_urgent(L, -3, luaA_checkboolean(L, -1));
1742 return 0;
1745 static int
1746 luaA_client_set_skip_taskbar(lua_State *L, client_t *c)
1748 client_set_skip_taskbar(L, -3, luaA_checkboolean(L, -1));
1749 return 0;
1752 static int
1753 luaA_client_get_name(lua_State *L, client_t *c)
1755 lua_pushstring(L, c->name ? c->name : c->alt_name);
1756 return 1;
1759 static int
1760 luaA_client_get_icon_name(lua_State *L, client_t *c)
1762 lua_pushstring(L, c->icon_name ? c->icon_name : c->alt_icon_name);
1763 return 1;
1766 LUA_OBJECT_EXPORT_PROPERTY(client, client_t, class, lua_pushstring)
1767 LUA_OBJECT_EXPORT_PROPERTY(client, client_t, instance, lua_pushstring)
1768 LUA_OBJECT_EXPORT_PROPERTY(client, client_t, machine, lua_pushstring)
1769 LUA_OBJECT_EXPORT_PROPERTY(client, client_t, role, lua_pushstring)
1770 LUA_OBJECT_EXPORT_PROPERTY(client, client_t, transient_for, luaA_object_push)
1771 LUA_OBJECT_EXPORT_PROPERTY(client, client_t, skip_taskbar, lua_pushboolean)
1772 LUA_OBJECT_EXPORT_PROPERTY(client, client_t, leader_window, lua_pushnumber)
1773 LUA_OBJECT_EXPORT_PROPERTY(client, client_t, group_window, lua_pushnumber)
1774 LUA_OBJECT_EXPORT_PROPERTY(client, client_t, pid, lua_pushnumber)
1775 LUA_OBJECT_EXPORT_PROPERTY(client, client_t, hidden, lua_pushboolean)
1776 LUA_OBJECT_EXPORT_PROPERTY(client, client_t, minimized, lua_pushboolean)
1777 LUA_OBJECT_EXPORT_PROPERTY(client, client_t, fullscreen, lua_pushboolean)
1778 LUA_OBJECT_EXPORT_PROPERTY(client, client_t, modal, lua_pushboolean)
1779 LUA_OBJECT_EXPORT_PROPERTY(client, client_t, ontop, lua_pushboolean)
1780 LUA_OBJECT_EXPORT_PROPERTY(client, client_t, urgent, lua_pushboolean)
1781 LUA_OBJECT_EXPORT_PROPERTY(client, client_t, above, lua_pushboolean)
1782 LUA_OBJECT_EXPORT_PROPERTY(client, client_t, below, lua_pushboolean)
1783 LUA_OBJECT_EXPORT_PROPERTY(client, client_t, sticky, lua_pushboolean)
1784 LUA_OBJECT_EXPORT_PROPERTY(client, client_t, size_hints_honor, lua_pushboolean)
1785 LUA_OBJECT_EXPORT_PROPERTY(client, client_t, maximized_horizontal, lua_pushboolean)
1786 LUA_OBJECT_EXPORT_PROPERTY(client, client_t, maximized_vertical, lua_pushboolean)
1788 static int
1789 luaA_client_get_content(lua_State *L, client_t *c)
1791 xcb_get_window_attributes_cookie_t cookie;
1792 xcb_get_window_attributes_reply_t *attr;
1793 cairo_surface_t *surface;
1794 int width = c->geometry.width;
1795 int height = c->geometry.height;
1797 /* Just the client size without decorations */
1798 width -= c->titlebar[CLIENT_TITLEBAR_LEFT].size + c->titlebar[CLIENT_TITLEBAR_RIGHT].size;
1799 height -= c->titlebar[CLIENT_TITLEBAR_TOP].size + c->titlebar[CLIENT_TITLEBAR_BOTTOM].size;
1801 cookie = xcb_get_window_attributes(globalconf.connection, c->window);
1802 attr = xcb_get_window_attributes_reply(globalconf.connection, cookie, NULL);
1804 if (!attr)
1805 return 0;
1807 surface = cairo_xcb_surface_create(globalconf.connection, c->window,
1808 draw_find_visual(globalconf.screen, attr->visual),
1809 width, height);
1811 /* lua has to make sure to free the ref or we have a leak */
1812 lua_pushlightuserdata(L, surface);
1813 free(attr);
1814 return 1;
1817 static int
1818 luaA_client_get_screen(lua_State *L, client_t *c)
1820 if(!c->screen)
1821 return 0;
1822 lua_pushnumber(L, 1 + screen_array_indexof(&globalconf.screens, c->screen));
1823 return 1;
1826 static int
1827 luaA_client_get_icon(lua_State *L, client_t *c)
1829 if(!c->icon)
1830 return 0;
1831 /* lua gets its own reference which it will have to destroy */
1832 lua_pushlightuserdata(L, cairo_surface_reference(c->icon));
1833 return 1;
1836 static int
1837 luaA_client_get_focusable(lua_State *L, client_t *c)
1839 bool ret;
1841 /* A client can be focused if it doesnt have the "nofocus" hint...*/
1842 if (!c->nofocus)
1843 ret = true;
1844 else
1845 /* ...or if it knows the WM_TAKE_FOCUS protocol */
1846 ret = client_hasproto(c, WM_TAKE_FOCUS);
1848 lua_pushboolean(L, ret);
1849 return 1;
1852 static int
1853 luaA_client_get_size_hints(lua_State *L, client_t *c)
1855 const char *u_or_p = NULL;
1857 lua_createtable(L, 0, 1);
1859 if(c->size_hints.flags & XCB_ICCCM_SIZE_HINT_US_POSITION)
1860 u_or_p = "user_position";
1861 else if(c->size_hints.flags & XCB_ICCCM_SIZE_HINT_P_POSITION)
1862 u_or_p = "program_position";
1864 if(u_or_p)
1866 lua_createtable(L, 0, 2);
1867 lua_pushnumber(L, c->size_hints.x);
1868 lua_setfield(L, -2, "x");
1869 lua_pushnumber(L, c->size_hints.y);
1870 lua_setfield(L, -2, "y");
1871 lua_setfield(L, -2, u_or_p);
1872 u_or_p = NULL;
1875 if(c->size_hints.flags & XCB_ICCCM_SIZE_HINT_US_SIZE)
1876 u_or_p = "user_size";
1877 else if(c->size_hints.flags & XCB_ICCCM_SIZE_HINT_P_SIZE)
1878 u_or_p = "program_size";
1880 if(u_or_p)
1882 lua_createtable(L, 0, 2);
1883 lua_pushnumber(L, c->size_hints.width);
1884 lua_setfield(L, -2, "width");
1885 lua_pushnumber(L, c->size_hints.height);
1886 lua_setfield(L, -2, "height");
1887 lua_setfield(L, -2, u_or_p);
1890 if(c->size_hints.flags & XCB_ICCCM_SIZE_HINT_P_MIN_SIZE)
1892 lua_pushnumber(L, c->size_hints.min_width);
1893 lua_setfield(L, -2, "min_width");
1894 lua_pushnumber(L, c->size_hints.min_height);
1895 lua_setfield(L, -2, "min_height");
1898 if(c->size_hints.flags & XCB_ICCCM_SIZE_HINT_P_MAX_SIZE)
1900 lua_pushnumber(L, c->size_hints.max_width);
1901 lua_setfield(L, -2, "max_width");
1902 lua_pushnumber(L, c->size_hints.max_height);
1903 lua_setfield(L, -2, "max_height");
1906 if(c->size_hints.flags & XCB_ICCCM_SIZE_HINT_P_RESIZE_INC)
1908 lua_pushnumber(L, c->size_hints.width_inc);
1909 lua_setfield(L, -2, "width_inc");
1910 lua_pushnumber(L, c->size_hints.height_inc);
1911 lua_setfield(L, -2, "height_inc");
1914 if(c->size_hints.flags & XCB_ICCCM_SIZE_HINT_P_ASPECT)
1916 lua_pushnumber(L, c->size_hints.min_aspect_num);
1917 lua_setfield(L, -2, "min_aspect_num");
1918 lua_pushnumber(L, c->size_hints.min_aspect_den);
1919 lua_setfield(L, -2, "min_aspect_den");
1920 lua_pushnumber(L, c->size_hints.max_aspect_num);
1921 lua_setfield(L, -2, "max_aspect_num");
1922 lua_pushnumber(L, c->size_hints.max_aspect_den);
1923 lua_setfield(L, -2, "max_aspect_den");
1926 if(c->size_hints.flags & XCB_ICCCM_SIZE_HINT_BASE_SIZE)
1928 lua_pushnumber(L, c->size_hints.base_width);
1929 lua_setfield(L, -2, "base_width");
1930 lua_pushnumber(L, c->size_hints.base_height);
1931 lua_setfield(L, -2, "base_height");
1934 if(c->size_hints.flags & XCB_ICCCM_SIZE_HINT_P_WIN_GRAVITY)
1936 switch(c->size_hints.win_gravity)
1938 default:
1939 lua_pushliteral(L, "north_west");
1940 break;
1941 case XCB_GRAVITY_NORTH:
1942 lua_pushliteral(L, "north");
1943 break;
1944 case XCB_GRAVITY_NORTH_EAST:
1945 lua_pushliteral(L, "north_east");
1946 break;
1947 case XCB_GRAVITY_WEST:
1948 lua_pushliteral(L, "west");
1949 break;
1950 case XCB_GRAVITY_CENTER:
1951 lua_pushliteral(L, "center");
1952 break;
1953 case XCB_GRAVITY_EAST:
1954 lua_pushliteral(L, "east");
1955 break;
1956 case XCB_GRAVITY_SOUTH_WEST:
1957 lua_pushliteral(L, "south_west");
1958 break;
1959 case XCB_GRAVITY_SOUTH:
1960 lua_pushliteral(L, "south");
1961 break;
1962 case XCB_GRAVITY_SOUTH_EAST:
1963 lua_pushliteral(L, "south_east");
1964 break;
1965 case XCB_GRAVITY_STATIC:
1966 lua_pushliteral(L, "static");
1967 break;
1969 lua_setfield(L, -2, "win_gravity");
1972 return 1;
1975 /** Set the client's bounding shape.
1976 * \param L The Lua VM state.
1977 * \param client The client object.
1978 * \return The number of elements pushed on stack.
1980 static int
1981 luaA_client_set_shape_bounding(lua_State *L, client_t *c)
1983 cairo_surface_t *surf = NULL;
1984 if(!lua_isnil(L, -1))
1985 surf = (cairo_surface_t *)lua_touserdata(L, -1);
1986 xwindow_set_shape(c->frame_window,
1987 c->geometry.width + (c->border_width * 2),
1988 c->geometry.height + (c->border_width * 2),
1989 XCB_SHAPE_SK_BOUNDING, surf, -c->border_width);
1990 return 0;
1993 /** Set the client's clip shape.
1994 * \param L The Lua VM state.
1995 * \param client The client object.
1996 * \return The number of elements pushed on stack.
1998 static int
1999 luaA_client_set_shape_clip(lua_State *L, client_t *c)
2001 cairo_surface_t *surf = NULL;
2002 if(!lua_isnil(L, -1))
2003 surf = (cairo_surface_t *)lua_touserdata(L, -1);
2004 xwindow_set_shape(c->frame_window, c->geometry.width, c->geometry.height,
2005 XCB_SHAPE_SK_CLIP, surf, 0);
2006 return 0;
2009 /** Get or set keys bindings for a client.
2010 * \param L The Lua VM state.
2011 * \return The number of element pushed on stack.
2012 * \luastack
2013 * \lvalue A client.
2014 * \lparam An array of key bindings objects, or nothing.
2015 * \return The array of key bindings objects of this client.
2017 static int
2018 luaA_client_keys(lua_State *L)
2020 client_t *c = luaA_checkudata(L, 1, &client_class);
2021 key_array_t *keys = &c->keys;
2023 if(lua_gettop(L) == 2)
2025 luaA_key_array_set(L, 1, 2, keys);
2026 luaA_object_emit_signal(L, 1, "property::keys", 0);
2027 xcb_ungrab_key(globalconf.connection, XCB_GRAB_ANY, c->frame_window, XCB_BUTTON_MASK_ANY);
2028 xwindow_grabkeys(c->frame_window, keys);
2031 return luaA_key_array_get(L, 1, keys);
2034 /* Client module.
2035 * \param L The Lua VM state.
2036 * \return The number of pushed elements.
2038 static int
2039 luaA_client_module_index(lua_State *L)
2041 const char *buf = luaL_checkstring(L, 2);
2043 if (A_STREQ(buf, "focus"))
2044 return luaA_object_push(globalconf.L, globalconf.focus.client);
2045 return 0;
2048 /* Client module new index.
2049 * \param L The Lua VM state.
2050 * \return The number of pushed elements.
2052 static int
2053 luaA_client_module_newindex(lua_State *L)
2055 const char *buf = luaL_checkstring(L, 2);
2056 client_t *c;
2058 if (A_STREQ(buf, "focus"))
2060 c = luaA_checkudata(L, 3, &client_class);
2061 client_focus(c);
2064 return 0;
2067 static bool
2068 client_checker(client_t *c)
2070 return c->window != XCB_NONE;
2073 void
2074 client_class_setup(lua_State *L)
2076 static const struct luaL_Reg client_methods[] =
2078 LUA_CLASS_METHODS(client)
2079 { "get", luaA_client_get },
2080 { "__index", luaA_client_module_index },
2081 { "__newindex", luaA_client_module_newindex },
2082 { NULL, NULL }
2085 static const struct luaL_Reg client_meta[] =
2087 LUA_OBJECT_META(client)
2088 LUA_CLASS_META
2089 { "keys", luaA_client_keys },
2090 { "isvisible", luaA_client_isvisible },
2091 { "geometry", luaA_client_geometry },
2092 { "tags", luaA_client_tags },
2093 { "kill", luaA_client_kill },
2094 { "swap", luaA_client_swap },
2095 { "raise", luaA_client_raise },
2096 { "lower", luaA_client_lower },
2097 { "unmanage", luaA_client_unmanage },
2098 { "titlebar_top", luaA_client_titlebar_top },
2099 { "titlebar_right", luaA_client_titlebar_right },
2100 { "titlebar_bottom", luaA_client_titlebar_bottom },
2101 { "titlebar_left", luaA_client_titlebar_left },
2102 { NULL, NULL }
2105 luaA_class_setup(L, &client_class, "client", &window_class,
2106 (lua_class_allocator_t) client_new,
2107 (lua_class_collector_t) client_wipe,
2108 (lua_class_checker_t) client_checker,
2109 luaA_class_index_miss_property, luaA_class_newindex_miss_property,
2110 client_methods, client_meta);
2111 luaA_class_add_property(&client_class, "name",
2112 NULL,
2113 (lua_class_propfunc_t) luaA_client_get_name,
2114 NULL);
2115 luaA_class_add_property(&client_class, "transient_for",
2116 NULL,
2117 (lua_class_propfunc_t) luaA_client_get_transient_for,
2118 NULL);
2119 luaA_class_add_property(&client_class, "skip_taskbar",
2120 (lua_class_propfunc_t) luaA_client_set_skip_taskbar,
2121 (lua_class_propfunc_t) luaA_client_get_skip_taskbar,
2122 (lua_class_propfunc_t) luaA_client_set_skip_taskbar);
2123 luaA_class_add_property(&client_class, "content",
2124 NULL,
2125 (lua_class_propfunc_t) luaA_client_get_content,
2126 NULL);
2127 luaA_class_add_property(&client_class, "type",
2128 NULL,
2129 (lua_class_propfunc_t) luaA_window_get_type,
2130 NULL);
2131 luaA_class_add_property(&client_class, "class",
2132 NULL,
2133 (lua_class_propfunc_t) luaA_client_get_class,
2134 NULL);
2135 luaA_class_add_property(&client_class, "instance",
2136 NULL,
2137 (lua_class_propfunc_t) luaA_client_get_instance,
2138 NULL);
2139 luaA_class_add_property(&client_class, "role",
2140 NULL,
2141 (lua_class_propfunc_t) luaA_client_get_role,
2142 NULL);
2143 luaA_class_add_property(&client_class, "pid",
2144 NULL,
2145 (lua_class_propfunc_t) luaA_client_get_pid,
2146 NULL);
2147 luaA_class_add_property(&client_class, "leader_window",
2148 NULL,
2149 (lua_class_propfunc_t) luaA_client_get_leader_window,
2150 NULL);
2151 luaA_class_add_property(&client_class, "machine",
2152 NULL,
2153 (lua_class_propfunc_t) luaA_client_get_machine,
2154 NULL);
2155 luaA_class_add_property(&client_class, "icon_name",
2156 NULL,
2157 (lua_class_propfunc_t) luaA_client_get_icon_name,
2158 NULL);
2159 luaA_class_add_property(&client_class, "screen",
2160 NULL,
2161 (lua_class_propfunc_t) luaA_client_get_screen,
2162 (lua_class_propfunc_t) luaA_client_set_screen);
2163 luaA_class_add_property(&client_class, "hidden",
2164 (lua_class_propfunc_t) luaA_client_set_hidden,
2165 (lua_class_propfunc_t) luaA_client_get_hidden,
2166 (lua_class_propfunc_t) luaA_client_set_hidden);
2167 luaA_class_add_property(&client_class, "minimized",
2168 (lua_class_propfunc_t) luaA_client_set_minimized,
2169 (lua_class_propfunc_t) luaA_client_get_minimized,
2170 (lua_class_propfunc_t) luaA_client_set_minimized);
2171 luaA_class_add_property(&client_class, "fullscreen",
2172 (lua_class_propfunc_t) luaA_client_set_fullscreen,
2173 (lua_class_propfunc_t) luaA_client_get_fullscreen,
2174 (lua_class_propfunc_t) luaA_client_set_fullscreen);
2175 luaA_class_add_property(&client_class, "modal",
2176 (lua_class_propfunc_t) luaA_client_set_modal,
2177 (lua_class_propfunc_t) luaA_client_get_modal,
2178 (lua_class_propfunc_t) luaA_client_set_modal);
2179 luaA_class_add_property(&client_class, "group_window",
2180 NULL,
2181 (lua_class_propfunc_t) luaA_client_get_group_window,
2182 NULL);
2183 luaA_class_add_property(&client_class, "maximized_horizontal",
2184 (lua_class_propfunc_t) luaA_client_set_maximized_horizontal,
2185 (lua_class_propfunc_t) luaA_client_get_maximized_horizontal,
2186 (lua_class_propfunc_t) luaA_client_set_maximized_horizontal);
2187 luaA_class_add_property(&client_class, "maximized_vertical",
2188 (lua_class_propfunc_t) luaA_client_set_maximized_vertical,
2189 (lua_class_propfunc_t) luaA_client_get_maximized_vertical,
2190 (lua_class_propfunc_t) luaA_client_set_maximized_vertical);
2191 luaA_class_add_property(&client_class, "icon",
2192 (lua_class_propfunc_t) luaA_client_set_icon,
2193 (lua_class_propfunc_t) luaA_client_get_icon,
2194 (lua_class_propfunc_t) luaA_client_set_icon);
2195 luaA_class_add_property(&client_class, "ontop",
2196 (lua_class_propfunc_t) luaA_client_set_ontop,
2197 (lua_class_propfunc_t) luaA_client_get_ontop,
2198 (lua_class_propfunc_t) luaA_client_set_ontop);
2199 luaA_class_add_property(&client_class, "above",
2200 (lua_class_propfunc_t) luaA_client_set_above,
2201 (lua_class_propfunc_t) luaA_client_get_above,
2202 (lua_class_propfunc_t) luaA_client_set_above);
2203 luaA_class_add_property(&client_class, "below",
2204 (lua_class_propfunc_t) luaA_client_set_below,
2205 (lua_class_propfunc_t) luaA_client_get_below,
2206 (lua_class_propfunc_t) luaA_client_set_below);
2207 luaA_class_add_property(&client_class, "sticky",
2208 (lua_class_propfunc_t) luaA_client_set_sticky,
2209 (lua_class_propfunc_t) luaA_client_get_sticky,
2210 (lua_class_propfunc_t) luaA_client_set_sticky);
2211 luaA_class_add_property(&client_class, "size_hints_honor",
2212 (lua_class_propfunc_t) luaA_client_set_size_hints_honor,
2213 (lua_class_propfunc_t) luaA_client_get_size_hints_honor,
2214 (lua_class_propfunc_t) luaA_client_set_size_hints_honor);
2215 luaA_class_add_property(&client_class, "urgent",
2216 (lua_class_propfunc_t) luaA_client_set_urgent,
2217 (lua_class_propfunc_t) luaA_client_get_urgent,
2218 (lua_class_propfunc_t) luaA_client_set_urgent);
2219 luaA_class_add_property(&client_class, "size_hints",
2220 NULL,
2221 (lua_class_propfunc_t) luaA_client_get_size_hints,
2222 NULL);
2223 luaA_class_add_property(&client_class, "focusable",
2224 NULL,
2225 (lua_class_propfunc_t) luaA_client_get_focusable,
2226 NULL);
2227 luaA_class_add_property(&client_class, "shape_bounding",
2228 (lua_class_propfunc_t) luaA_client_set_shape_bounding,
2229 NULL,
2230 (lua_class_propfunc_t) luaA_client_set_shape_bounding);
2231 luaA_class_add_property(&client_class, "shape_clip",
2232 (lua_class_propfunc_t) luaA_client_set_shape_clip,
2233 NULL,
2234 (lua_class_propfunc_t) luaA_client_set_shape_clip);
2236 signal_add(&client_class.signals, "focus");
2237 signal_add(&client_class.signals, "list");
2238 signal_add(&client_class.signals, "manage");
2239 signal_add(&client_class.signals, "button::press");
2240 signal_add(&client_class.signals, "button::release");
2241 signal_add(&client_class.signals, "mouse::enter");
2242 signal_add(&client_class.signals, "mouse::leave");
2243 signal_add(&client_class.signals, "mouse::move");
2244 signal_add(&client_class.signals, "property::above");
2245 signal_add(&client_class.signals, "property::below");
2246 signal_add(&client_class.signals, "property::class");
2247 signal_add(&client_class.signals, "property::fullscreen");
2248 signal_add(&client_class.signals, "property::geometry");
2249 signal_add(&client_class.signals, "property::group_window");
2250 signal_add(&client_class.signals, "property::height");
2251 signal_add(&client_class.signals, "property::hidden");
2252 signal_add(&client_class.signals, "property::icon");
2253 signal_add(&client_class.signals, "property::icon_name");
2254 signal_add(&client_class.signals, "property::instance");
2255 signal_add(&client_class.signals, "property::keys");
2256 signal_add(&client_class.signals, "property::machine");
2257 signal_add(&client_class.signals, "property::maximized_horizontal");
2258 signal_add(&client_class.signals, "property::maximized_vertical");
2259 signal_add(&client_class.signals, "property::minimized");
2260 signal_add(&client_class.signals, "property::modal");
2261 signal_add(&client_class.signals, "property::name");
2262 signal_add(&client_class.signals, "property::ontop");
2263 signal_add(&client_class.signals, "property::pid");
2264 signal_add(&client_class.signals, "property::role");
2265 signal_add(&client_class.signals, "property::screen");
2266 signal_add(&client_class.signals, "property::size_hints_honor");
2267 signal_add(&client_class.signals, "property::skip_taskbar");
2268 signal_add(&client_class.signals, "property::sticky");
2269 signal_add(&client_class.signals, "property::struts");
2270 signal_add(&client_class.signals, "property::transient_for");
2271 signal_add(&client_class.signals, "property::type");
2272 signal_add(&client_class.signals, "property::urgent");
2273 signal_add(&client_class.signals, "property::width");
2274 signal_add(&client_class.signals, "property::window");
2275 signal_add(&client_class.signals, "property::x");
2276 signal_add(&client_class.signals, "property::y");
2277 signal_add(&client_class.signals, "request::fullscreen");
2278 signal_add(&client_class.signals, "request::maximized_horizontal");
2279 signal_add(&client_class.signals, "request::maximized_vertical");
2280 signal_add(&client_class.signals, "tagged");
2281 signal_add(&client_class.signals, "unfocus");
2282 signal_add(&client_class.signals, "unmanage");
2283 signal_add(&client_class.signals, "untagged");
2286 // vim: filetype=c:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:textwidth=80