Send correct size to fullscreen clients (FS#1093)
[awesome.git] / objects / client.c
blobcaefe80c05927374e4963eeae034163c7585ce3b
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 static void
589 client_remove_titlebar_geometry(client_t *c, area_t *geometry)
591 geometry->x += c->titlebar[CLIENT_TITLEBAR_LEFT].size;
592 geometry->y += c->titlebar[CLIENT_TITLEBAR_TOP].size;
593 geometry->width -= c->titlebar[CLIENT_TITLEBAR_LEFT].size;
594 geometry->width -= c->titlebar[CLIENT_TITLEBAR_RIGHT].size;
595 geometry->height -= c->titlebar[CLIENT_TITLEBAR_TOP].size;
596 geometry->height -= c->titlebar[CLIENT_TITLEBAR_BOTTOM].size;
599 static void
600 client_add_titlebar_geometry(client_t *c, area_t *geometry)
602 geometry->x -= c->titlebar[CLIENT_TITLEBAR_LEFT].size;
603 geometry->y -= c->titlebar[CLIENT_TITLEBAR_TOP].size;
604 geometry->width += c->titlebar[CLIENT_TITLEBAR_LEFT].size;
605 geometry->width += c->titlebar[CLIENT_TITLEBAR_RIGHT].size;
606 geometry->height += c->titlebar[CLIENT_TITLEBAR_TOP].size;
607 geometry->height += c->titlebar[CLIENT_TITLEBAR_BOTTOM].size;
610 /** Send a synthetic configure event to a window.
612 void
613 client_send_configure(client_t *c)
615 area_t geometry = c->geometry;
617 if (!c->fullscreen)
618 client_remove_titlebar_geometry(c, &geometry);
619 xwindow_configure(c->window, geometry, c->border_width);
622 /** Apply size hints to the client's new geometry.
624 static area_t
625 client_apply_size_hints(client_t *c, area_t geometry)
627 int32_t minw = 0, minh = 0;
628 int32_t basew = 0, baseh = 0, real_basew = 0, real_baseh = 0;
630 if (c->fullscreen)
631 return geometry;
633 /* Size hints are applied to the window without any decoration */
634 client_remove_titlebar_geometry(c, &geometry);
636 if(c->size_hints.flags & XCB_ICCCM_SIZE_HINT_P_SIZE)
638 basew = c->size_hints.base_width;
639 baseh = c->size_hints.base_height;
640 real_basew = basew;
641 real_baseh = baseh;
643 else if(c->size_hints.flags & XCB_ICCCM_SIZE_HINT_P_MIN_SIZE)
645 /* base size is substituted with min size if not specified */
646 basew = c->size_hints.min_width;
647 baseh = c->size_hints.min_height;
650 if(c->size_hints.flags & XCB_ICCCM_SIZE_HINT_P_MIN_SIZE)
652 minw = c->size_hints.min_width;
653 minh = c->size_hints.min_height;
655 else if(c->size_hints.flags & XCB_ICCCM_SIZE_HINT_P_SIZE)
657 /* min size is substituted with base size if not specified */
658 minw = c->size_hints.base_width;
659 minh = c->size_hints.base_height;
662 /* Handle the size aspect ratio */
663 if(c->size_hints.flags & XCB_ICCCM_SIZE_HINT_P_ASPECT
664 && c->size_hints.min_aspect_den > 0
665 && c->size_hints.max_aspect_den > 0
666 && geometry.height > real_baseh
667 && geometry.width > real_basew)
669 /* ICCCM mandates:
670 * If a base size is provided along with the aspect ratio fields, the base size should be subtracted from the
671 * window size prior to checking that the aspect ratio falls in range. If a base size is not provided, nothing
672 * should be subtracted from the window size. (The minimum size is not to be used in place of the base size for
673 * this purpose.)
675 double dx = geometry.width - real_basew;
676 double dy = geometry.height - real_baseh;
677 double ratio = dx / dy;
678 double min = c->size_hints.min_aspect_num / (double) c->size_hints.min_aspect_den;
679 double max = c->size_hints.max_aspect_num / (double) c->size_hints.max_aspect_den;
681 if(max > 0 && min > 0 && ratio > 0)
683 if(ratio < min)
685 /* dx is lower than allowed, make dy lower to compensate this (+ 0.5 to force proper rounding). */
686 dy = dx / min + 0.5;
687 geometry.width = dx + real_basew;
688 geometry.height = dy + real_baseh;
689 } else if(ratio > max)
691 /* dx is too high, lower it (+0.5 for proper rounding) */
692 dx = dy * max + 0.5;
693 geometry.width = dx + real_basew;
694 geometry.height = dy + real_baseh;
699 /* Handle the minimum size */
700 geometry.width = MAX(geometry.width, minw);
701 geometry.height = MAX(geometry.height, minh);
703 /* Handle the maximum size */
704 if(c->size_hints.flags & XCB_ICCCM_SIZE_HINT_P_MAX_SIZE)
706 if(c->size_hints.max_width)
707 geometry.width = MIN(geometry.width, c->size_hints.max_width);
708 if(c->size_hints.max_height)
709 geometry.height = MIN(geometry.height, c->size_hints.max_height);
712 /* Handle the size increment */
713 if(c->size_hints.flags & (XCB_ICCCM_SIZE_HINT_P_RESIZE_INC | XCB_ICCCM_SIZE_HINT_BASE_SIZE)
714 && c->size_hints.width_inc && c->size_hints.height_inc)
716 uint16_t t1 = geometry.width, t2 = geometry.height;
717 unsigned_subtract(t1, basew);
718 unsigned_subtract(t2, baseh);
719 geometry.width -= t1 % c->size_hints.width_inc;
720 geometry.height -= t2 % c->size_hints.height_inc;
723 client_add_titlebar_geometry(c, &geometry);
724 return geometry;
727 static void
728 client_resize_do(client_t *c, area_t geometry, bool force_notice, bool honor_hints)
730 bool send_notice = force_notice;
731 bool hide_titlebars = c->fullscreen;
732 screen_t *new_screen = screen_getbycoord(geometry.x, geometry.y);
734 if (honor_hints)
735 geometry = client_apply_size_hints(c, geometry);
737 if(c->geometry.width == geometry.width
738 && c->geometry.height == geometry.height)
739 send_notice = true;
741 /* Also store geometry including border */
742 area_t old_geometry = c->geometry;
743 c->geometry = geometry;
745 /* Ignore all spurious enter/leave notify events */
746 client_ignore_enterleave_events();
748 /* Configure the client for its new size */
749 area_t real_geometry = geometry;
750 if (!hide_titlebars)
752 real_geometry.x = c->titlebar[CLIENT_TITLEBAR_LEFT].size;
753 real_geometry.y = c->titlebar[CLIENT_TITLEBAR_TOP].size;
754 real_geometry.width -= c->titlebar[CLIENT_TITLEBAR_LEFT].size;
755 real_geometry.width -= c->titlebar[CLIENT_TITLEBAR_RIGHT].size;
756 real_geometry.height -= c->titlebar[CLIENT_TITLEBAR_TOP].size;
757 real_geometry.height -= c->titlebar[CLIENT_TITLEBAR_BOTTOM].size;
758 } else {
759 real_geometry.x = 0;
760 real_geometry.y = 0;
763 xcb_configure_window(globalconf.connection, c->frame_window,
764 XCB_CONFIG_WINDOW_X | XCB_CONFIG_WINDOW_Y | XCB_CONFIG_WINDOW_WIDTH | XCB_CONFIG_WINDOW_HEIGHT,
765 (uint32_t[]) { geometry.x, geometry.y, geometry.width, geometry.height });
766 xcb_configure_window(globalconf.connection, c->window,
767 XCB_CONFIG_WINDOW_X | XCB_CONFIG_WINDOW_Y | XCB_CONFIG_WINDOW_WIDTH | XCB_CONFIG_WINDOW_HEIGHT,
768 (uint32_t[]) { real_geometry.x, real_geometry.y, real_geometry.width, real_geometry.height });
770 if(send_notice)
771 /* We are moving without changing the size, see ICCCM 4.2.3 */
772 client_send_configure(c);
774 client_restore_enterleave_events();
776 screen_client_moveto(c, new_screen, false);
778 luaA_object_push(globalconf.L, c);
779 luaA_object_emit_signal(globalconf.L, -1, "property::geometry", 0);
780 if (old_geometry.x != geometry.x)
781 luaA_object_emit_signal(globalconf.L, -1, "property::x", 0);
782 if (old_geometry.y != geometry.y)
783 luaA_object_emit_signal(globalconf.L, -1, "property::y", 0);
784 if (old_geometry.width != geometry.width)
785 luaA_object_emit_signal(globalconf.L, -1, "property::width", 0);
786 if (old_geometry.height != geometry.height)
787 luaA_object_emit_signal(globalconf.L, -1, "property::height", 0);
788 lua_pop(globalconf.L, 1);
790 /* Update all titlebars */
791 for (client_titlebar_t bar = CLIENT_TITLEBAR_TOP; bar < CLIENT_TITLEBAR_COUNT; bar++) {
792 if (c->titlebar[bar].drawable == NULL && c->titlebar[bar].size == 0)
793 continue;
795 luaA_object_push(globalconf.L, c);
796 drawable_t *drawable = titlebar_get_drawable(globalconf.L, c, -1, bar);
797 luaA_object_push_item(globalconf.L, -1, drawable);
799 area_t area = titlebar_get_area(c, bar);
801 /* Convert to global coordinates */
802 area.x += geometry.x;
803 area.y += geometry.y;
804 if (hide_titlebars)
805 area.width = area.height = 0;
807 if (old_geometry.width != geometry.width || old_geometry.height != geometry.height ||
808 drawable->geometry.width == 0 || drawable->geometry.height == 0) {
809 /* Get rid of the old state */
810 drawable_unset_surface(drawable);
811 if (c->titlebar[bar].pixmap != XCB_NONE)
812 xcb_free_pixmap(globalconf.connection, c->titlebar[bar].pixmap);
813 c->titlebar[bar].pixmap = XCB_NONE;
815 /* And get us some new state */
816 if (c->titlebar[bar].size != 0 && !hide_titlebars)
818 c->titlebar[bar].pixmap = xcb_generate_id(globalconf.connection);
819 xcb_create_pixmap(globalconf.connection, globalconf.default_depth, c->titlebar[bar].pixmap,
820 globalconf.screen->root, area.width, area.height);
821 cairo_surface_t *surface = cairo_xcb_surface_create(globalconf.connection,
822 c->titlebar[bar].pixmap, globalconf.visual,
823 area.width, area.height);
824 drawable_set_surface(drawable, -1, surface, area);
825 } else
826 drawable_set_geometry(drawable, -1, area);
827 } else
828 drawable_set_geometry(drawable, -1, area);
830 /* Pop the client and the drawable */
831 lua_pop(globalconf.L, 2);
835 /** Resize client window.
836 * The sizes given as parameters are with borders!
837 * \param c Client to resize.
838 * \param geometry New window geometry.
839 * \param honor_hints Use size hints.
840 * \return true if an actual resize occurred.
842 bool
843 client_resize(client_t *c, area_t geometry, bool honor_hints)
845 area_t area;
847 /* offscreen appearance fixes */
848 area = display_area_get();
850 if(geometry.x > area.width)
851 geometry.x = area.width - geometry.width;
852 if(geometry.y > area.height)
853 geometry.y = area.height - geometry.height;
854 if(geometry.x + geometry.width < 0)
855 geometry.x = 0;
856 if(geometry.y + geometry.height < 0)
857 geometry.y = 0;
859 if(geometry.width < c->titlebar[CLIENT_TITLEBAR_LEFT].size + c->titlebar[CLIENT_TITLEBAR_RIGHT].size)
860 return false;
861 if(geometry.height < c->titlebar[CLIENT_TITLEBAR_TOP].size + c->titlebar[CLIENT_TITLEBAR_BOTTOM].size)
862 return false;
864 if(geometry.width == 0 || geometry.height == 0)
865 return false;
867 if(c->geometry.x != geometry.x
868 || c->geometry.y != geometry.y
869 || c->geometry.width != geometry.width
870 || c->geometry.height != geometry.height)
872 client_resize_do(c, geometry, false, honor_hints);
874 return true;
877 return false;
880 /** Set a client minimized, or not.
881 * \param L The Lua VM state.
882 * \param cidx The client index.
883 * \param s Set or not the client minimized.
885 void
886 client_set_minimized(lua_State *L, int cidx, bool s)
888 client_t *c = luaA_checkudata(L, cidx, &client_class);
890 if(c->minimized != s)
892 c->minimized = s;
893 banning_need_update();
894 if(s)
895 xwindow_set_state(c->window, XCB_ICCCM_WM_STATE_ICONIC);
896 else
897 xwindow_set_state(c->window, XCB_ICCCM_WM_STATE_NORMAL);
898 if(strut_has_value(&c->strut))
899 screen_emit_signal(globalconf.L, c->screen, "property::workarea", 0);
900 luaA_object_emit_signal(L, cidx, "property::minimized", 0);
904 /** Set a client hidden, or not.
905 * \param L The Lua VM state.
906 * \param cidx The client index.
907 * \param s Set or not the client hidden.
909 static void
910 client_set_hidden(lua_State *L, int cidx, bool s)
912 client_t *c = luaA_checkudata(L, cidx, &client_class);
914 if(c->hidden != s)
916 c->hidden = s;
917 banning_need_update();
918 if(strut_has_value(&c->strut))
919 screen_emit_signal(globalconf.L, c->screen, "property::workarea", 0);
920 luaA_object_emit_signal(L, cidx, "property::hidden", 0);
924 /** Set a client sticky, or not.
925 * \param L The Lua VM state.
926 * \param cidx The client index.
927 * \param s Set or not the client sticky.
929 void
930 client_set_sticky(lua_State *L, int cidx, bool s)
932 client_t *c = luaA_checkudata(L, cidx, &client_class);
934 if(c->sticky != s)
936 c->sticky = s;
937 banning_need_update();
938 luaA_object_emit_signal(L, cidx, "property::sticky", 0);
942 /** Set a client fullscreen, or not.
943 * \param L The Lua VM state.
944 * \param cidx The client index.
945 * \param s Set or not the client fullscreen.
947 void
948 client_set_fullscreen(lua_State *L, int cidx, bool s)
950 client_t *c = luaA_checkudata(L, cidx, &client_class);
952 if(c->fullscreen != s)
954 /* become fullscreen! */
955 if(s)
957 /* remove any max state */
958 client_set_maximized_horizontal(L, cidx, false);
959 client_set_maximized_vertical(L, cidx, false);
960 /* You can only be part of one of the special layers. */
961 client_set_below(L, cidx, false);
962 client_set_above(L, cidx, false);
963 client_set_ontop(L, cidx, false);
965 int abs_cidx = luaA_absindex(L, cidx); \
966 lua_pushboolean(L, s);
967 c->fullscreen = s;
968 luaA_object_emit_signal(L, abs_cidx, "request::fullscreen", 1);
969 luaA_object_emit_signal(L, abs_cidx, "property::fullscreen", 0);
970 /* Force a client resize, so that titlebars get shown/hidden */
971 client_resize_do(c, c->geometry, true, false);
972 stack_windows();
976 /** Set a client horizontally|vertically maximized.
977 * \param L The Lua VM state.
978 * \param cidx The client index.
979 * \param s The maximized status.
981 #define DO_FUNCTION_CLIENT_MAXIMIZED(type) \
982 void \
983 client_set_maximized_##type(lua_State *L, int cidx, bool s) \
985 client_t *c = luaA_checkudata(L, cidx, &client_class); \
986 if(c->maximized_##type != s) \
988 int abs_cidx = luaA_absindex(L, cidx); \
989 if(s) \
990 client_set_fullscreen(L, abs_cidx, false); \
991 lua_pushboolean(L, s); \
992 c->maximized_##type = s; \
993 luaA_object_emit_signal(L, abs_cidx, "request::maximized_" #type, 1); \
994 luaA_object_emit_signal(L, abs_cidx, "property::maximized_" #type, 0); \
995 stack_windows(); \
998 DO_FUNCTION_CLIENT_MAXIMIZED(vertical)
999 DO_FUNCTION_CLIENT_MAXIMIZED(horizontal)
1000 #undef DO_FUNCTION_CLIENT_MAXIMIZED
1002 /** Set a client above, or not.
1003 * \param L The Lua VM state.
1004 * \param cidx The client index.
1005 * \param s Set or not the client above.
1007 void
1008 client_set_above(lua_State *L, int cidx, bool s)
1010 client_t *c = luaA_checkudata(L, cidx, &client_class);
1012 if(c->above != s)
1014 /* You can only be part of one of the special layers. */
1015 if(s)
1017 client_set_below(L, cidx, false);
1018 client_set_ontop(L, cidx, false);
1019 client_set_fullscreen(L, cidx, false);
1021 c->above = s;
1022 stack_windows();
1023 luaA_object_emit_signal(L, cidx, "property::above", 0);
1027 /** Set a client below, or not.
1028 * \param L The Lua VM state.
1029 * \param cidx The client index.
1030 * \param s Set or not the client below.
1032 void
1033 client_set_below(lua_State *L, int cidx, bool s)
1035 client_t *c = luaA_checkudata(L, cidx, &client_class);
1037 if(c->below != s)
1039 /* You can only be part of one of the special layers. */
1040 if(s)
1042 client_set_above(L, cidx, false);
1043 client_set_ontop(L, cidx, false);
1044 client_set_fullscreen(L, cidx, false);
1046 c->below = s;
1047 stack_windows();
1048 luaA_object_emit_signal(L, cidx, "property::below", 0);
1052 /** Set a client modal, or not.
1053 * \param L The Lua VM state.
1054 * \param cidx The client index.
1055 * \param s Set or not the client modal attribute.
1057 void
1058 client_set_modal(lua_State *L, int cidx, bool s)
1060 client_t *c = luaA_checkudata(L, cidx, &client_class);
1062 if(c->modal != s)
1064 c->modal = s;
1065 stack_windows();
1066 luaA_object_emit_signal(L, cidx, "property::modal", 0);
1070 /** Set a client ontop, or not.
1071 * \param L The Lua VM state.
1072 * \param cidx The client index.
1073 * \param s Set or not the client ontop attribute.
1075 void
1076 client_set_ontop(lua_State *L, int cidx, bool s)
1078 client_t *c = luaA_checkudata(L, cidx, &client_class);
1080 if(c->ontop != s)
1082 /* You can only be part of one of the special layers. */
1083 if(s)
1085 client_set_above(L, cidx, false);
1086 client_set_below(L, cidx, false);
1087 client_set_fullscreen(L, cidx, false);
1089 c->ontop = s;
1090 stack_windows();
1091 luaA_object_emit_signal(L, cidx, "property::ontop", 0);
1095 /** Unban a client and move it back into the viewport.
1096 * \param c The client.
1098 void
1099 client_unban(client_t *c)
1101 if(c->isbanned)
1103 xcb_map_window(globalconf.connection, c->frame_window);
1105 c->isbanned = false;
1107 /* An unbanned client shouldn't be minimized or hidden */
1108 luaA_object_push(globalconf.L, c);
1109 client_set_minimized(globalconf.L, -1, false);
1110 client_set_hidden(globalconf.L, -1, false);
1111 lua_pop(globalconf.L, 1);
1115 /** Unmanage a client.
1116 * \param c The client.
1117 * \param window_valid Is the client's window still valid?
1119 void
1120 client_unmanage(client_t *c, bool window_valid)
1122 /* Reset transient_for attributes of widows that maybe referring to us */
1123 foreach(_tc, globalconf.clients)
1125 client_t *tc = *_tc;
1126 if(tc->transient_for == c)
1127 tc->transient_for = NULL;
1130 if(globalconf.focus.client == c)
1131 client_unfocus(c);
1133 /* remove client from global list and everywhere else */
1134 foreach(elem, globalconf.clients)
1135 if(*elem == c)
1137 client_array_remove(&globalconf.clients, elem);
1138 break;
1140 stack_client_remove(c);
1141 for(int i = 0; i < globalconf.tags.len; i++)
1142 untag_client(c, globalconf.tags.tab[i]);
1144 luaA_object_push(globalconf.L, c);
1145 luaA_object_emit_signal(globalconf.L, -1, "unmanage", 0);
1146 lua_pop(globalconf.L, 1);
1148 luaA_class_emit_signal(globalconf.L, &client_class, "list", 0);
1150 if(strut_has_value(&c->strut))
1151 screen_emit_signal(globalconf.L, c->screen, "property::workarea", 0);
1153 /* Get rid of all titlebars */
1154 for (client_titlebar_t bar = CLIENT_TITLEBAR_TOP; bar < CLIENT_TITLEBAR_COUNT; bar++) {
1155 if (c->titlebar[bar].drawable == NULL)
1156 continue;
1158 luaA_object_push(globalconf.L, c);
1159 luaA_object_push_item(globalconf.L, -1, c->titlebar[bar].drawable);
1161 /* Make the drawable unusable */
1162 drawable_unset_surface(c->titlebar[bar].drawable);
1163 if (c->titlebar[bar].pixmap != XCB_NONE)
1164 xcb_free_pixmap(globalconf.connection, c->titlebar[bar].pixmap);
1166 /* And forget about it */
1167 luaA_object_unref_item(globalconf.L, -2, c->titlebar[bar].drawable);
1168 c->titlebar[bar].drawable = NULL;
1169 lua_pop(globalconf.L, 2);
1172 /* Clear our event mask so that we don't receive any events from now on,
1173 * especially not for the following requests. */
1174 if(window_valid)
1175 xcb_change_window_attributes(globalconf.connection,
1176 c->window,
1177 XCB_CW_EVENT_MASK,
1178 (const uint32_t []) { 0 });
1179 xcb_change_window_attributes(globalconf.connection,
1180 c->frame_window,
1181 XCB_CW_EVENT_MASK,
1182 (const uint32_t []) { 0 });
1184 if(window_valid)
1186 xcb_unmap_window(globalconf.connection, c->window);
1187 xcb_reparent_window(globalconf.connection, c->window, globalconf.screen->root,
1188 c->geometry.x, c->geometry.y);
1190 xcb_destroy_window(globalconf.connection, c->frame_window);
1192 if(window_valid)
1194 /* Remove this window from the save set since this shouldn't be made visible
1195 * after a restart anymore. */
1196 xcb_change_save_set(globalconf.connection, XCB_SET_MODE_DELETE, c->window);
1198 /* Do this last to avoid races with clients. According to ICCCM, clients
1199 * arent allowed to re-use the window until after this. */
1200 xwindow_set_state(c->window, XCB_ICCCM_WM_STATE_WITHDRAWN);
1203 /* set client as invalid */
1204 c->window = XCB_NONE;
1206 luaA_object_unref(globalconf.L, c);
1209 /** Kill a client via a WM_DELETE_WINDOW request or KillClient if not
1210 * supported.
1211 * \param c The client to kill.
1213 void
1214 client_kill(client_t *c)
1216 if(client_hasproto(c, WM_DELETE_WINDOW))
1218 xcb_client_message_event_t ev;
1220 /* Initialize all of event's fields first */
1221 p_clear(&ev, 1);
1223 ev.response_type = XCB_CLIENT_MESSAGE;
1224 ev.window = c->window;
1225 ev.format = 32;
1226 ev.data.data32[1] = globalconf.timestamp;
1227 ev.type = WM_PROTOCOLS;
1228 ev.data.data32[0] = WM_DELETE_WINDOW;
1230 xcb_send_event(globalconf.connection, false, c->window,
1231 XCB_EVENT_MASK_NO_EVENT, (char *) &ev);
1233 else
1234 xcb_kill_client(globalconf.connection, c->window);
1237 /** Get all clients into a table.
1238 * \param L The Lua VM state.
1239 * \return The number of elements pushed on stack.
1240 * \luastack
1241 * \lparam An optional screen number.
1242 * \lreturn A table with all clients.
1244 static int
1245 luaA_client_get(lua_State *L)
1247 int i = 1, screen;
1249 screen = luaL_optnumber(L, 1, 0) - 1;
1251 lua_newtable(L);
1253 if(screen == -1)
1254 foreach(c, globalconf.clients)
1256 luaA_object_push(L, *c);
1257 lua_rawseti(L, -2, i++);
1259 else
1261 luaA_checkscreen(screen);
1262 foreach(c, globalconf.clients)
1263 if((*c)->screen == &globalconf.screens.tab[screen])
1265 luaA_object_push(L, *c);
1266 lua_rawseti(L, -2, i++);
1270 return 1;
1273 /** Check if a client is visible on its screen.
1274 * \param L The Lua VM state.
1275 * \return The number of elements pushed on stack.
1276 * \luastack
1277 * \lvalue A client.
1278 * \lreturn A boolean value, true if the client is visible, false otherwise.
1280 static int
1281 luaA_client_isvisible(lua_State *L)
1283 client_t *c = luaA_checkudata(L, 1, &client_class);
1284 lua_pushboolean(L, client_isvisible(c));
1285 return 1;
1288 /** Set a client icon.
1289 * \param L The Lua VM state.
1290 * \param cidx The client index on the stack.
1291 * \param iidx The image index on the stack.
1293 void
1294 client_set_icon(client_t *c, cairo_surface_t *s)
1296 if (s)
1297 s = draw_dup_image_surface(s);
1298 if(c->icon)
1299 cairo_surface_destroy(c->icon);
1300 c->icon = s;
1302 luaA_object_push(globalconf.L, c);
1303 luaA_object_emit_signal(globalconf.L, -1, "property::icon", 0);
1304 lua_pop(globalconf.L, 1);
1307 /** Kill a client.
1308 * \param L The Lua VM state.
1310 * \luastack
1311 * \lvalue A client.
1313 static int
1314 luaA_client_kill(lua_State *L)
1316 client_t *c = luaA_checkudata(L, 1, &client_class);
1317 client_kill(c);
1318 return 0;
1321 /** Swap a client with another one.
1322 * \param L The Lua VM state.
1323 * \luastack
1324 * \lvalue A client.
1325 * \lparam A client to swap with.
1327 static int
1328 luaA_client_swap(lua_State *L)
1330 client_t *c = luaA_checkudata(L, 1, &client_class);
1331 client_t *swap = luaA_checkudata(L, 2, &client_class);
1333 if(c != swap)
1335 client_t **ref_c = NULL, **ref_swap = NULL;
1336 foreach(item, globalconf.clients)
1338 if(*item == c)
1339 ref_c = item;
1340 else if(*item == swap)
1341 ref_swap = item;
1342 if(ref_c && ref_swap)
1343 break;
1345 /* swap ! */
1346 *ref_c = swap;
1347 *ref_swap = c;
1349 luaA_class_emit_signal(globalconf.L, &client_class, "list", 0);
1352 return 0;
1355 /** Access or set the client tags.
1356 * \param L The Lua VM state.
1357 * \return The number of elements pushed on stack.
1358 * \lparam A table with tags to set, or none to get the current tags table.
1359 * \return The clients tag.
1361 static int
1362 luaA_client_tags(lua_State *L)
1364 client_t *c = luaA_checkudata(L, 1, &client_class);
1365 int j = 0;
1367 if(lua_gettop(L) == 2)
1369 luaA_checktable(L, 2);
1370 for(int i = 0; i < globalconf.tags.len; i++)
1372 /* Only untag if we aren't going to add this tag again */
1373 bool found = false;
1374 lua_pushnil(L);
1375 while(lua_next(L, 2))
1377 tag_t *t = lua_touserdata(L, -1);
1378 /* Pop the value from lua_next */
1379 lua_pop(L, 1);
1380 if (t != globalconf.tags.tab[i])
1381 continue;
1383 /* Pop the key from lua_next */
1384 lua_pop(L, 1);
1385 found = true;
1386 break;
1388 if(!found)
1389 untag_client(c, globalconf.tags.tab[i]);
1391 lua_pushnil(L);
1392 while(lua_next(L, 2))
1393 tag_client(c);
1394 lua_pop(L, 1);
1397 lua_newtable(L);
1398 foreach(tag, globalconf.tags)
1399 if(is_client_tagged(c, *tag))
1401 luaA_object_push(L, *tag);
1402 lua_rawseti(L, -2, ++j);
1405 return 1;
1408 /** Raise a client on top of others which are on the same layer.
1409 * \param L The Lua VM state.
1410 * \luastack
1411 * \lvalue A client.
1413 static int
1414 luaA_client_raise(lua_State *L)
1416 client_t *c = luaA_checkudata(L, 1, &client_class);
1417 client_raise(c);
1418 return 0;
1421 /** Lower a client on bottom of others which are on the same layer.
1422 * \param L The Lua VM state.
1423 * \luastack
1424 * \lvalue A client.
1426 static int
1427 luaA_client_lower(lua_State *L)
1429 client_t *c = luaA_checkudata(L, 1, &client_class);
1431 stack_client_push(c);
1433 /* Traverse all transient layers. */
1434 for(client_t *tc = c->transient_for; tc; tc = tc->transient_for)
1435 stack_client_push(tc);
1437 return 0;
1440 /** Stop managing a client.
1441 * \param L The Lua VM state.
1442 * \return The number of elements pushed on stack.
1443 * \luastack
1444 * \lvalue A client.
1446 static int
1447 luaA_client_unmanage(lua_State *L)
1449 client_t *c = luaA_checkudata(L, 1, &client_class);
1450 client_unmanage(c, true);
1451 return 0;
1454 static area_t
1455 titlebar_get_area(client_t *c, client_titlebar_t bar)
1457 area_t result = c->geometry;
1458 result.x = result.y = 0;
1460 // Let's try some ascii art:
1461 // ---------------------------
1462 // | Top |
1463 // |-------------------------|
1464 // |L| |R|
1465 // |e| |i|
1466 // |f| |g|
1467 // |t| |h|
1468 // | | |t|
1469 // |-------------------------|
1470 // | Bottom |
1471 // ---------------------------
1473 switch (bar) {
1474 case CLIENT_TITLEBAR_BOTTOM:
1475 result.y = c->geometry.height - c->titlebar[bar].size;
1476 /* Fall through */
1477 case CLIENT_TITLEBAR_TOP:
1478 result.height = c->titlebar[bar].size;
1479 break;
1480 case CLIENT_TITLEBAR_RIGHT:
1481 result.x = c->geometry.width - c->titlebar[bar].size;
1482 /* Fall through */
1483 case CLIENT_TITLEBAR_LEFT:
1484 result.y = c->titlebar[CLIENT_TITLEBAR_TOP].size;
1485 result.width = c->titlebar[bar].size;
1486 result.height -= c->titlebar[CLIENT_TITLEBAR_TOP].size;
1487 result.height -= c->titlebar[CLIENT_TITLEBAR_BOTTOM].size;
1488 break;
1489 default:
1490 fatal("Unknown titlebar kind %d\n", (int) bar);
1493 return result;
1496 drawable_t *
1497 client_get_drawable_offset(client_t *c, int *x, int *y)
1499 for (client_titlebar_t bar = CLIENT_TITLEBAR_TOP; bar < CLIENT_TITLEBAR_COUNT; bar++) {
1500 area_t area = titlebar_get_area(c, bar);
1501 if (AREA_LEFT(area) > *x || AREA_RIGHT(area) <= *x)
1502 continue;
1503 if (AREA_TOP(area) > *y || AREA_BOTTOM(area) <= *y)
1504 continue;
1506 *x -= area.x;
1507 *y -= area.y;
1508 return c->titlebar[bar].drawable;
1511 return NULL;
1514 drawable_t *
1515 client_get_drawable(client_t *c, int x, int y)
1517 return client_get_drawable_offset(c, &x, &y);
1520 void
1521 client_refresh(client_t *c)
1523 for (client_titlebar_t bar = CLIENT_TITLEBAR_TOP; bar < CLIENT_TITLEBAR_COUNT; bar++) {
1524 if (c->titlebar[bar].drawable == NULL || c->titlebar[bar].drawable->surface == NULL)
1525 continue;
1527 area_t area = titlebar_get_area(c, bar);
1528 cairo_surface_flush(c->titlebar[bar].drawable->surface);
1529 xcb_copy_area(globalconf.connection, c->titlebar[bar].pixmap, c->frame_window,
1530 globalconf.gc, 0, 0, area.x, area.y, area.width, area.height);
1534 static drawable_t *
1535 titlebar_get_drawable(lua_State *L, client_t *c, int cl_idx, client_titlebar_t bar)
1537 if (c->titlebar[bar].drawable == NULL)
1539 cl_idx = luaA_absindex(L, cl_idx);
1540 drawable_allocator(L, (drawable_refresh_callback *) client_refresh, c);
1541 c->titlebar[bar].drawable = luaA_object_ref_item(L, cl_idx, -1);
1544 return c->titlebar[bar].drawable;
1547 static void
1548 titlebar_resize(client_t *c, client_titlebar_t bar, int size)
1550 if (size < 0)
1551 return;
1553 if (size == c->titlebar[bar].size)
1554 return;
1556 /* Now resize the client (and titlebars!) suitably (the client without
1557 * titlebars should keep its current size!) */
1558 area_t geometry = c->geometry;
1559 int change = size - c->titlebar[bar].size;
1560 switch (bar) {
1561 case CLIENT_TITLEBAR_TOP:
1562 case CLIENT_TITLEBAR_BOTTOM:
1563 geometry.height += change;
1564 break;
1565 case CLIENT_TITLEBAR_RIGHT:
1566 case CLIENT_TITLEBAR_LEFT:
1567 geometry.width += change;
1568 break;
1569 default:
1570 fatal("Unknown titlebar kind %d\n", (int) bar);
1573 c->titlebar[bar].size = size;
1574 client_resize_do(c, geometry, true, false);
1577 #define HANDLE_TITLEBAR(name, index) \
1578 static int \
1579 luaA_client_titlebar_ ## name(lua_State *L) \
1581 client_t *c = luaA_checkudata(L, 1, &client_class); \
1583 if (lua_gettop(L) == 2) \
1585 if (lua_isnil(L, 2)) \
1586 titlebar_resize(c, index, 0); \
1587 else \
1588 titlebar_resize(c, index, luaL_checknumber(L, 2)); \
1591 luaA_object_push_item(L, 1, titlebar_get_drawable(L, c, 1, index)); \
1592 lua_pushnumber(L, c->titlebar[index].size); \
1593 return 2; \
1595 HANDLE_TITLEBAR(top, CLIENT_TITLEBAR_TOP)
1596 HANDLE_TITLEBAR(right, CLIENT_TITLEBAR_RIGHT)
1597 HANDLE_TITLEBAR(bottom, CLIENT_TITLEBAR_BOTTOM)
1598 HANDLE_TITLEBAR(left, CLIENT_TITLEBAR_LEFT)
1600 /** Return client geometry.
1601 * \param L The Lua VM state.
1602 * \return The number of elements pushed on stack.
1603 * \luastack
1604 * \lparam A table with new coordinates, or none.
1605 * \lreturn A table with client coordinates.
1607 static int
1608 luaA_client_geometry(lua_State *L)
1610 client_t *c = luaA_checkudata(L, 1, &client_class);
1612 if(lua_gettop(L) == 2 && !lua_isnil(L, 2))
1614 area_t geometry;
1616 luaA_checktable(L, 2);
1617 geometry.x = luaA_getopt_number(L, 2, "x", c->geometry.x);
1618 geometry.y = luaA_getopt_number(L, 2, "y", c->geometry.y);
1619 if(client_isfixed(c))
1621 geometry.width = c->geometry.width;
1622 geometry.height = c->geometry.height;
1624 else
1626 geometry.width = luaA_getopt_number(L, 2, "width", c->geometry.width);
1627 geometry.height = luaA_getopt_number(L, 2, "height", c->geometry.height);
1630 client_resize(c, geometry, c->size_hints_honor);
1633 return luaA_pusharea(L, c->geometry);
1636 static int
1637 luaA_client_set_screen(lua_State *L, client_t *c)
1639 int screen = luaL_checknumber(L, -1) - 1;
1640 luaA_checkscreen(screen);
1641 screen_client_moveto(c, &globalconf.screens.tab[screen], true);
1643 return 0;
1646 static int
1647 luaA_client_set_hidden(lua_State *L, client_t *c)
1649 client_set_hidden(L, -3, luaA_checkboolean(L, -1));
1650 return 0;
1653 static int
1654 luaA_client_set_minimized(lua_State *L, client_t *c)
1656 client_set_minimized(L, -3, luaA_checkboolean(L, -1));
1657 return 0;
1660 static int
1661 luaA_client_set_fullscreen(lua_State *L, client_t *c)
1663 client_set_fullscreen(L, -3, luaA_checkboolean(L, -1));
1664 return 0;
1667 static int
1668 luaA_client_set_modal(lua_State *L, client_t *c)
1670 client_set_modal(L, -3, luaA_checkboolean(L, -1));
1671 return 0;
1674 static int
1675 luaA_client_set_maximized_horizontal(lua_State *L, client_t *c)
1677 client_set_maximized_horizontal(L, -3, luaA_checkboolean(L, -1));
1678 return 0;
1681 static int
1682 luaA_client_set_maximized_vertical(lua_State *L, client_t *c)
1684 client_set_maximized_vertical(L, -3, luaA_checkboolean(L, -1));
1685 return 0;
1688 static int
1689 luaA_client_set_icon(lua_State *L, client_t *c)
1691 cairo_surface_t *surf = NULL;
1692 if(!lua_isnil(L, -1))
1693 surf = (cairo_surface_t *)lua_touserdata(L, -1);
1694 client_set_icon(c, surf);
1695 return 0;
1698 static int
1699 luaA_client_set_sticky(lua_State *L, client_t *c)
1701 client_set_sticky(L, -3, luaA_checkboolean(L, -1));
1702 return 0;
1705 static int
1706 luaA_client_set_size_hints_honor(lua_State *L, client_t *c)
1708 c->size_hints_honor = luaA_checkboolean(L, -1);
1709 luaA_object_emit_signal(L, -3, "property::size_hints_honor", 0);
1710 return 0;
1713 static int
1714 luaA_client_set_ontop(lua_State *L, client_t *c)
1716 client_set_ontop(L, -3, luaA_checkboolean(L, -1));
1717 return 0;
1720 static int
1721 luaA_client_set_below(lua_State *L, client_t *c)
1723 client_set_below(L, -3, luaA_checkboolean(L, -1));
1724 return 0;
1727 static int
1728 luaA_client_set_above(lua_State *L, client_t *c)
1730 client_set_above(L, -3, luaA_checkboolean(L, -1));
1731 return 0;
1734 static int
1735 luaA_client_set_urgent(lua_State *L, client_t *c)
1737 client_set_urgent(L, -3, luaA_checkboolean(L, -1));
1738 return 0;
1741 static int
1742 luaA_client_set_skip_taskbar(lua_State *L, client_t *c)
1744 client_set_skip_taskbar(L, -3, luaA_checkboolean(L, -1));
1745 return 0;
1748 static int
1749 luaA_client_get_name(lua_State *L, client_t *c)
1751 lua_pushstring(L, c->name ? c->name : c->alt_name);
1752 return 1;
1755 static int
1756 luaA_client_get_icon_name(lua_State *L, client_t *c)
1758 lua_pushstring(L, c->icon_name ? c->icon_name : c->alt_icon_name);
1759 return 1;
1762 LUA_OBJECT_EXPORT_PROPERTY(client, client_t, class, lua_pushstring)
1763 LUA_OBJECT_EXPORT_PROPERTY(client, client_t, instance, lua_pushstring)
1764 LUA_OBJECT_EXPORT_PROPERTY(client, client_t, machine, lua_pushstring)
1765 LUA_OBJECT_EXPORT_PROPERTY(client, client_t, role, lua_pushstring)
1766 LUA_OBJECT_EXPORT_PROPERTY(client, client_t, transient_for, luaA_object_push)
1767 LUA_OBJECT_EXPORT_PROPERTY(client, client_t, skip_taskbar, lua_pushboolean)
1768 LUA_OBJECT_EXPORT_PROPERTY(client, client_t, leader_window, lua_pushnumber)
1769 LUA_OBJECT_EXPORT_PROPERTY(client, client_t, group_window, lua_pushnumber)
1770 LUA_OBJECT_EXPORT_PROPERTY(client, client_t, pid, lua_pushnumber)
1771 LUA_OBJECT_EXPORT_PROPERTY(client, client_t, hidden, lua_pushboolean)
1772 LUA_OBJECT_EXPORT_PROPERTY(client, client_t, minimized, lua_pushboolean)
1773 LUA_OBJECT_EXPORT_PROPERTY(client, client_t, fullscreen, lua_pushboolean)
1774 LUA_OBJECT_EXPORT_PROPERTY(client, client_t, modal, lua_pushboolean)
1775 LUA_OBJECT_EXPORT_PROPERTY(client, client_t, ontop, lua_pushboolean)
1776 LUA_OBJECT_EXPORT_PROPERTY(client, client_t, urgent, lua_pushboolean)
1777 LUA_OBJECT_EXPORT_PROPERTY(client, client_t, above, lua_pushboolean)
1778 LUA_OBJECT_EXPORT_PROPERTY(client, client_t, below, lua_pushboolean)
1779 LUA_OBJECT_EXPORT_PROPERTY(client, client_t, sticky, lua_pushboolean)
1780 LUA_OBJECT_EXPORT_PROPERTY(client, client_t, size_hints_honor, lua_pushboolean)
1781 LUA_OBJECT_EXPORT_PROPERTY(client, client_t, maximized_horizontal, lua_pushboolean)
1782 LUA_OBJECT_EXPORT_PROPERTY(client, client_t, maximized_vertical, lua_pushboolean)
1784 static int
1785 luaA_client_get_content(lua_State *L, client_t *c)
1787 xcb_image_t *ximage = xcb_image_get(globalconf.connection,
1788 c->window,
1789 0, 0,
1790 c->geometry.width,
1791 c->geometry.height,
1792 ~0, XCB_IMAGE_FORMAT_Z_PIXMAP);
1793 cairo_surface_t *surface = NULL;
1795 if(ximage)
1797 if(ximage->bpp >= 24)
1799 uint32_t *data = p_new(uint32_t, ximage->width * ximage->height);
1801 for(int y = 0; y < ximage->height; y++)
1802 for(int x = 0; x < ximage->width; x++)
1804 data[y * ximage->width + x] = xcb_image_get_pixel(ximage, x, y);
1805 data[y * ximage->width + x] |= 0xff000000; /* set alpha to 0xff */
1808 surface = draw_surface_from_data(ximage->width, ximage->height, data);
1809 p_delete(&data);
1811 xcb_image_destroy(ximage);
1814 if (!surface)
1815 return 0;
1817 /* lua has to make sure to free the ref or we have a leak */
1818 lua_pushlightuserdata(L, surface);
1819 return 1;
1822 static int
1823 luaA_client_get_screen(lua_State *L, client_t *c)
1825 if(!c->screen)
1826 return 0;
1827 lua_pushnumber(L, 1 + screen_array_indexof(&globalconf.screens, c->screen));
1828 return 1;
1831 static int
1832 luaA_client_get_icon(lua_State *L, client_t *c)
1834 if(!c->icon)
1835 return 0;
1836 /* lua gets its own reference which it will have to destroy */
1837 lua_pushlightuserdata(L, cairo_surface_reference(c->icon));
1838 return 1;
1841 static int
1842 luaA_client_get_focusable(lua_State *L, client_t *c)
1844 bool ret;
1846 /* A client can be focused if it doesnt have the "nofocus" hint...*/
1847 if (!c->nofocus)
1848 ret = true;
1849 else
1850 /* ...or if it knows the WM_TAKE_FOCUS protocol */
1851 ret = client_hasproto(c, WM_TAKE_FOCUS);
1853 lua_pushboolean(L, ret);
1854 return 1;
1857 static int
1858 luaA_client_get_size_hints(lua_State *L, client_t *c)
1860 const char *u_or_p = NULL;
1862 lua_createtable(L, 0, 1);
1864 if(c->size_hints.flags & XCB_ICCCM_SIZE_HINT_US_POSITION)
1865 u_or_p = "user_position";
1866 else if(c->size_hints.flags & XCB_ICCCM_SIZE_HINT_P_POSITION)
1867 u_or_p = "program_position";
1869 if(u_or_p)
1871 lua_createtable(L, 0, 2);
1872 lua_pushnumber(L, c->size_hints.x);
1873 lua_setfield(L, -2, "x");
1874 lua_pushnumber(L, c->size_hints.y);
1875 lua_setfield(L, -2, "y");
1876 lua_setfield(L, -2, u_or_p);
1877 u_or_p = NULL;
1880 if(c->size_hints.flags & XCB_ICCCM_SIZE_HINT_US_SIZE)
1881 u_or_p = "user_size";
1882 else if(c->size_hints.flags & XCB_ICCCM_SIZE_HINT_P_SIZE)
1883 u_or_p = "program_size";
1885 if(u_or_p)
1887 lua_createtable(L, 0, 2);
1888 lua_pushnumber(L, c->size_hints.width);
1889 lua_setfield(L, -2, "width");
1890 lua_pushnumber(L, c->size_hints.height);
1891 lua_setfield(L, -2, "height");
1892 lua_setfield(L, -2, u_or_p);
1895 if(c->size_hints.flags & XCB_ICCCM_SIZE_HINT_P_MIN_SIZE)
1897 lua_pushnumber(L, c->size_hints.min_width);
1898 lua_setfield(L, -2, "min_width");
1899 lua_pushnumber(L, c->size_hints.min_height);
1900 lua_setfield(L, -2, "min_height");
1903 if(c->size_hints.flags & XCB_ICCCM_SIZE_HINT_P_MAX_SIZE)
1905 lua_pushnumber(L, c->size_hints.max_width);
1906 lua_setfield(L, -2, "max_width");
1907 lua_pushnumber(L, c->size_hints.max_height);
1908 lua_setfield(L, -2, "max_height");
1911 if(c->size_hints.flags & XCB_ICCCM_SIZE_HINT_P_RESIZE_INC)
1913 lua_pushnumber(L, c->size_hints.width_inc);
1914 lua_setfield(L, -2, "width_inc");
1915 lua_pushnumber(L, c->size_hints.height_inc);
1916 lua_setfield(L, -2, "height_inc");
1919 if(c->size_hints.flags & XCB_ICCCM_SIZE_HINT_P_ASPECT)
1921 lua_pushnumber(L, c->size_hints.min_aspect_num);
1922 lua_setfield(L, -2, "min_aspect_num");
1923 lua_pushnumber(L, c->size_hints.min_aspect_den);
1924 lua_setfield(L, -2, "min_aspect_den");
1925 lua_pushnumber(L, c->size_hints.max_aspect_num);
1926 lua_setfield(L, -2, "max_aspect_num");
1927 lua_pushnumber(L, c->size_hints.max_aspect_den);
1928 lua_setfield(L, -2, "max_aspect_den");
1931 if(c->size_hints.flags & XCB_ICCCM_SIZE_HINT_BASE_SIZE)
1933 lua_pushnumber(L, c->size_hints.base_width);
1934 lua_setfield(L, -2, "base_width");
1935 lua_pushnumber(L, c->size_hints.base_height);
1936 lua_setfield(L, -2, "base_height");
1939 if(c->size_hints.flags & XCB_ICCCM_SIZE_HINT_P_WIN_GRAVITY)
1941 switch(c->size_hints.win_gravity)
1943 default:
1944 lua_pushliteral(L, "north_west");
1945 break;
1946 case XCB_GRAVITY_NORTH:
1947 lua_pushliteral(L, "north");
1948 break;
1949 case XCB_GRAVITY_NORTH_EAST:
1950 lua_pushliteral(L, "north_east");
1951 break;
1952 case XCB_GRAVITY_WEST:
1953 lua_pushliteral(L, "west");
1954 break;
1955 case XCB_GRAVITY_CENTER:
1956 lua_pushliteral(L, "center");
1957 break;
1958 case XCB_GRAVITY_EAST:
1959 lua_pushliteral(L, "east");
1960 break;
1961 case XCB_GRAVITY_SOUTH_WEST:
1962 lua_pushliteral(L, "south_west");
1963 break;
1964 case XCB_GRAVITY_SOUTH:
1965 lua_pushliteral(L, "south");
1966 break;
1967 case XCB_GRAVITY_SOUTH_EAST:
1968 lua_pushliteral(L, "south_east");
1969 break;
1970 case XCB_GRAVITY_STATIC:
1971 lua_pushliteral(L, "static");
1972 break;
1974 lua_setfield(L, -2, "win_gravity");
1977 return 1;
1980 /** Set the client's bounding shape.
1981 * \param L The Lua VM state.
1982 * \param client The client object.
1983 * \return The number of elements pushed on stack.
1985 static int
1986 luaA_client_set_shape_bounding(lua_State *L, client_t *c)
1988 cairo_surface_t *surf = NULL;
1989 if(!lua_isnil(L, -1))
1990 surf = (cairo_surface_t *)lua_touserdata(L, -1);
1991 xwindow_set_shape(c->frame_window,
1992 c->geometry.width + (c->border_width * 2),
1993 c->geometry.height + (c->border_width * 2),
1994 XCB_SHAPE_SK_BOUNDING, surf, -c->border_width);
1995 return 0;
1998 /** Set the client's clip shape.
1999 * \param L The Lua VM state.
2000 * \param client The client object.
2001 * \return The number of elements pushed on stack.
2003 static int
2004 luaA_client_set_shape_clip(lua_State *L, client_t *c)
2006 cairo_surface_t *surf = NULL;
2007 if(!lua_isnil(L, -1))
2008 surf = (cairo_surface_t *)lua_touserdata(L, -1);
2009 xwindow_set_shape(c->frame_window, c->geometry.width, c->geometry.height,
2010 XCB_SHAPE_SK_CLIP, surf, 0);
2011 return 0;
2014 /** Get or set keys bindings for a client.
2015 * \param L The Lua VM state.
2016 * \return The number of element pushed on stack.
2017 * \luastack
2018 * \lvalue A client.
2019 * \lparam An array of key bindings objects, or nothing.
2020 * \return The array of key bindings objects of this client.
2022 static int
2023 luaA_client_keys(lua_State *L)
2025 client_t *c = luaA_checkudata(L, 1, &client_class);
2026 key_array_t *keys = &c->keys;
2028 if(lua_gettop(L) == 2)
2030 luaA_key_array_set(L, 1, 2, keys);
2031 luaA_object_emit_signal(L, 1, "property::keys", 0);
2032 xcb_ungrab_key(globalconf.connection, XCB_GRAB_ANY, c->frame_window, XCB_BUTTON_MASK_ANY);
2033 xwindow_grabkeys(c->frame_window, keys);
2036 return luaA_key_array_get(L, 1, keys);
2039 /* Client module.
2040 * \param L The Lua VM state.
2041 * \return The number of pushed elements.
2043 static int
2044 luaA_client_module_index(lua_State *L)
2046 const char *buf = luaL_checkstring(L, 2);
2048 if (A_STREQ(buf, "focus"))
2049 return luaA_object_push(globalconf.L, globalconf.focus.client);
2050 return 0;
2053 /* Client module new index.
2054 * \param L The Lua VM state.
2055 * \return The number of pushed elements.
2057 static int
2058 luaA_client_module_newindex(lua_State *L)
2060 const char *buf = luaL_checkstring(L, 2);
2061 client_t *c;
2063 if (A_STREQ(buf, "focus"))
2065 c = luaA_checkudata(L, 3, &client_class);
2066 client_focus(c);
2069 return 0;
2072 static bool
2073 client_checker(client_t *c)
2075 return c->window != XCB_NONE;
2078 void
2079 client_class_setup(lua_State *L)
2081 static const struct luaL_Reg client_methods[] =
2083 LUA_CLASS_METHODS(client)
2084 { "get", luaA_client_get },
2085 { "__index", luaA_client_module_index },
2086 { "__newindex", luaA_client_module_newindex },
2087 { NULL, NULL }
2090 static const struct luaL_Reg client_meta[] =
2092 LUA_OBJECT_META(client)
2093 LUA_CLASS_META
2094 { "keys", luaA_client_keys },
2095 { "isvisible", luaA_client_isvisible },
2096 { "geometry", luaA_client_geometry },
2097 { "tags", luaA_client_tags },
2098 { "kill", luaA_client_kill },
2099 { "swap", luaA_client_swap },
2100 { "raise", luaA_client_raise },
2101 { "lower", luaA_client_lower },
2102 { "unmanage", luaA_client_unmanage },
2103 { "titlebar_top", luaA_client_titlebar_top },
2104 { "titlebar_right", luaA_client_titlebar_right },
2105 { "titlebar_bottom", luaA_client_titlebar_bottom },
2106 { "titlebar_left", luaA_client_titlebar_left },
2107 { NULL, NULL }
2110 luaA_class_setup(L, &client_class, "client", &window_class,
2111 (lua_class_allocator_t) client_new,
2112 (lua_class_collector_t) client_wipe,
2113 (lua_class_checker_t) client_checker,
2114 luaA_class_index_miss_property, luaA_class_newindex_miss_property,
2115 client_methods, client_meta);
2116 luaA_class_add_property(&client_class, "name",
2117 NULL,
2118 (lua_class_propfunc_t) luaA_client_get_name,
2119 NULL);
2120 luaA_class_add_property(&client_class, "transient_for",
2121 NULL,
2122 (lua_class_propfunc_t) luaA_client_get_transient_for,
2123 NULL);
2124 luaA_class_add_property(&client_class, "skip_taskbar",
2125 (lua_class_propfunc_t) luaA_client_set_skip_taskbar,
2126 (lua_class_propfunc_t) luaA_client_get_skip_taskbar,
2127 (lua_class_propfunc_t) luaA_client_set_skip_taskbar);
2128 luaA_class_add_property(&client_class, "content",
2129 NULL,
2130 (lua_class_propfunc_t) luaA_client_get_content,
2131 NULL);
2132 luaA_class_add_property(&client_class, "type",
2133 NULL,
2134 (lua_class_propfunc_t) luaA_window_get_type,
2135 NULL);
2136 luaA_class_add_property(&client_class, "class",
2137 NULL,
2138 (lua_class_propfunc_t) luaA_client_get_class,
2139 NULL);
2140 luaA_class_add_property(&client_class, "instance",
2141 NULL,
2142 (lua_class_propfunc_t) luaA_client_get_instance,
2143 NULL);
2144 luaA_class_add_property(&client_class, "role",
2145 NULL,
2146 (lua_class_propfunc_t) luaA_client_get_role,
2147 NULL);
2148 luaA_class_add_property(&client_class, "pid",
2149 NULL,
2150 (lua_class_propfunc_t) luaA_client_get_pid,
2151 NULL);
2152 luaA_class_add_property(&client_class, "leader_window",
2153 NULL,
2154 (lua_class_propfunc_t) luaA_client_get_leader_window,
2155 NULL);
2156 luaA_class_add_property(&client_class, "machine",
2157 NULL,
2158 (lua_class_propfunc_t) luaA_client_get_machine,
2159 NULL);
2160 luaA_class_add_property(&client_class, "icon_name",
2161 NULL,
2162 (lua_class_propfunc_t) luaA_client_get_icon_name,
2163 NULL);
2164 luaA_class_add_property(&client_class, "screen",
2165 NULL,
2166 (lua_class_propfunc_t) luaA_client_get_screen,
2167 (lua_class_propfunc_t) luaA_client_set_screen);
2168 luaA_class_add_property(&client_class, "hidden",
2169 (lua_class_propfunc_t) luaA_client_set_hidden,
2170 (lua_class_propfunc_t) luaA_client_get_hidden,
2171 (lua_class_propfunc_t) luaA_client_set_hidden);
2172 luaA_class_add_property(&client_class, "minimized",
2173 (lua_class_propfunc_t) luaA_client_set_minimized,
2174 (lua_class_propfunc_t) luaA_client_get_minimized,
2175 (lua_class_propfunc_t) luaA_client_set_minimized);
2176 luaA_class_add_property(&client_class, "fullscreen",
2177 (lua_class_propfunc_t) luaA_client_set_fullscreen,
2178 (lua_class_propfunc_t) luaA_client_get_fullscreen,
2179 (lua_class_propfunc_t) luaA_client_set_fullscreen);
2180 luaA_class_add_property(&client_class, "modal",
2181 (lua_class_propfunc_t) luaA_client_set_modal,
2182 (lua_class_propfunc_t) luaA_client_get_modal,
2183 (lua_class_propfunc_t) luaA_client_set_modal);
2184 luaA_class_add_property(&client_class, "group_window",
2185 NULL,
2186 (lua_class_propfunc_t) luaA_client_get_group_window,
2187 NULL);
2188 luaA_class_add_property(&client_class, "maximized_horizontal",
2189 (lua_class_propfunc_t) luaA_client_set_maximized_horizontal,
2190 (lua_class_propfunc_t) luaA_client_get_maximized_horizontal,
2191 (lua_class_propfunc_t) luaA_client_set_maximized_horizontal);
2192 luaA_class_add_property(&client_class, "maximized_vertical",
2193 (lua_class_propfunc_t) luaA_client_set_maximized_vertical,
2194 (lua_class_propfunc_t) luaA_client_get_maximized_vertical,
2195 (lua_class_propfunc_t) luaA_client_set_maximized_vertical);
2196 luaA_class_add_property(&client_class, "icon",
2197 (lua_class_propfunc_t) luaA_client_set_icon,
2198 (lua_class_propfunc_t) luaA_client_get_icon,
2199 (lua_class_propfunc_t) luaA_client_set_icon);
2200 luaA_class_add_property(&client_class, "ontop",
2201 (lua_class_propfunc_t) luaA_client_set_ontop,
2202 (lua_class_propfunc_t) luaA_client_get_ontop,
2203 (lua_class_propfunc_t) luaA_client_set_ontop);
2204 luaA_class_add_property(&client_class, "above",
2205 (lua_class_propfunc_t) luaA_client_set_above,
2206 (lua_class_propfunc_t) luaA_client_get_above,
2207 (lua_class_propfunc_t) luaA_client_set_above);
2208 luaA_class_add_property(&client_class, "below",
2209 (lua_class_propfunc_t) luaA_client_set_below,
2210 (lua_class_propfunc_t) luaA_client_get_below,
2211 (lua_class_propfunc_t) luaA_client_set_below);
2212 luaA_class_add_property(&client_class, "sticky",
2213 (lua_class_propfunc_t) luaA_client_set_sticky,
2214 (lua_class_propfunc_t) luaA_client_get_sticky,
2215 (lua_class_propfunc_t) luaA_client_set_sticky);
2216 luaA_class_add_property(&client_class, "size_hints_honor",
2217 (lua_class_propfunc_t) luaA_client_set_size_hints_honor,
2218 (lua_class_propfunc_t) luaA_client_get_size_hints_honor,
2219 (lua_class_propfunc_t) luaA_client_set_size_hints_honor);
2220 luaA_class_add_property(&client_class, "urgent",
2221 (lua_class_propfunc_t) luaA_client_set_urgent,
2222 (lua_class_propfunc_t) luaA_client_get_urgent,
2223 (lua_class_propfunc_t) luaA_client_set_urgent);
2224 luaA_class_add_property(&client_class, "size_hints",
2225 NULL,
2226 (lua_class_propfunc_t) luaA_client_get_size_hints,
2227 NULL);
2228 luaA_class_add_property(&client_class, "focusable",
2229 NULL,
2230 (lua_class_propfunc_t) luaA_client_get_focusable,
2231 NULL);
2232 luaA_class_add_property(&client_class, "shape_bounding",
2233 (lua_class_propfunc_t) luaA_client_set_shape_bounding,
2234 NULL,
2235 (lua_class_propfunc_t) luaA_client_set_shape_bounding);
2236 luaA_class_add_property(&client_class, "shape_clip",
2237 (lua_class_propfunc_t) luaA_client_set_shape_clip,
2238 NULL,
2239 (lua_class_propfunc_t) luaA_client_set_shape_clip);
2241 signal_add(&client_class.signals, "focus");
2242 signal_add(&client_class.signals, "list");
2243 signal_add(&client_class.signals, "manage");
2244 signal_add(&client_class.signals, "button::press");
2245 signal_add(&client_class.signals, "button::release");
2246 signal_add(&client_class.signals, "mouse::enter");
2247 signal_add(&client_class.signals, "mouse::leave");
2248 signal_add(&client_class.signals, "mouse::move");
2249 signal_add(&client_class.signals, "property::above");
2250 signal_add(&client_class.signals, "property::below");
2251 signal_add(&client_class.signals, "property::class");
2252 signal_add(&client_class.signals, "property::fullscreen");
2253 signal_add(&client_class.signals, "property::geometry");
2254 signal_add(&client_class.signals, "property::group_window");
2255 signal_add(&client_class.signals, "property::height");
2256 signal_add(&client_class.signals, "property::hidden");
2257 signal_add(&client_class.signals, "property::icon");
2258 signal_add(&client_class.signals, "property::icon_name");
2259 signal_add(&client_class.signals, "property::instance");
2260 signal_add(&client_class.signals, "property::keys");
2261 signal_add(&client_class.signals, "property::machine");
2262 signal_add(&client_class.signals, "property::maximized_horizontal");
2263 signal_add(&client_class.signals, "property::maximized_vertical");
2264 signal_add(&client_class.signals, "property::minimized");
2265 signal_add(&client_class.signals, "property::modal");
2266 signal_add(&client_class.signals, "property::name");
2267 signal_add(&client_class.signals, "property::ontop");
2268 signal_add(&client_class.signals, "property::pid");
2269 signal_add(&client_class.signals, "property::role");
2270 signal_add(&client_class.signals, "property::screen");
2271 signal_add(&client_class.signals, "property::size_hints_honor");
2272 signal_add(&client_class.signals, "property::skip_taskbar");
2273 signal_add(&client_class.signals, "property::sticky");
2274 signal_add(&client_class.signals, "property::struts");
2275 signal_add(&client_class.signals, "property::transient_for");
2276 signal_add(&client_class.signals, "property::type");
2277 signal_add(&client_class.signals, "property::urgent");
2278 signal_add(&client_class.signals, "property::width");
2279 signal_add(&client_class.signals, "property::window");
2280 signal_add(&client_class.signals, "property::x");
2281 signal_add(&client_class.signals, "property::y");
2282 signal_add(&client_class.signals, "request::fullscreen");
2283 signal_add(&client_class.signals, "request::maximized_horizontal");
2284 signal_add(&client_class.signals, "request::maximized_vertical");
2285 signal_add(&client_class.signals, "tagged");
2286 signal_add(&client_class.signals, "unfocus");
2287 signal_add(&client_class.signals, "unmanage");
2288 signal_add(&client_class.signals, "untagged");
2291 // vim: filetype=c:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:textwidth=80