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 "objects/client.h"
23 #include "common/atoms.h"
24 #include "common/xutil.h"
27 #include "objects/drawable.h"
28 #include "objects/screen.h"
29 #include "objects/tag.h"
35 #include <xcb/xcb_atom.h>
36 #include <xcb/shape.h>
37 #include <cairo-xcb.h>
39 static area_t
titlebar_get_area(client_t
*c
, client_titlebar_t bar
);
40 static drawable_t
*titlebar_get_drawable(lua_State
*L
, client_t
*c
, int cl_idx
, client_titlebar_t bar
);
43 * \param L The Lua VM state.
44 * \return The number of element pushed on stack.
47 client_wipe(client_t
*c
)
49 key_array_wipe(&c
->keys
);
50 xcb_icccm_get_wm_protocols_reply_wipe(&c
->protocols
);
51 p_delete(&c
->machine
);
53 p_delete(&c
->instance
);
54 p_delete(&c
->icon_name
);
55 p_delete(&c
->alt_icon_name
);
57 p_delete(&c
->alt_name
);
58 p_delete(&c
->startup_id
);
60 cairo_surface_destroy(c
->icon
);
63 /** Change the clients urgency flag.
64 * \param L The Lua VM state.
65 * \param cidx The client index on the stack.
66 * \param urgent The new flag state.
69 client_set_urgent(lua_State
*L
, int cidx
, bool urgent
)
71 client_t
*c
= luaA_checkudata(L
, cidx
, &client_class
);
73 if(c
->urgent
!= urgent
)
75 xcb_get_property_cookie_t hints
=
76 xcb_icccm_get_wm_hints_unchecked(globalconf
.connection
, c
->window
);
80 /* update ICCCM hints */
81 xcb_icccm_wm_hints_t wmh
;
82 xcb_icccm_get_wm_hints_reply(globalconf
.connection
, hints
, &wmh
, NULL
);
85 wmh
.flags
|= XCB_ICCCM_WM_HINT_X_URGENCY
;
87 wmh
.flags
&= ~XCB_ICCCM_WM_HINT_X_URGENCY
;
89 xcb_icccm_set_wm_hints(globalconf
.connection
, c
->window
, &wmh
);
91 luaA_object_emit_signal(L
, cidx
, "property::urgent", 0);
95 #define DO_CLIENT_SET_PROPERTY(prop) \
97 client_set_##prop(lua_State *L, int cidx, fieldtypeof(client_t, prop) value) \
99 client_t *c = luaA_checkudata(L, cidx, &client_class); \
100 if(c->prop != value) \
103 luaA_object_emit_signal(L, cidx, "property::" #prop, 0); \
106 DO_CLIENT_SET_PROPERTY(group_window
)
107 DO_CLIENT_SET_PROPERTY(type
)
108 DO_CLIENT_SET_PROPERTY(transient_for
)
109 DO_CLIENT_SET_PROPERTY(pid
)
110 DO_CLIENT_SET_PROPERTY(skip_taskbar
)
111 #undef DO_CLIENT_SET_PROPERTY
113 #define DO_CLIENT_SET_STRING_PROPERTY2(prop, signal) \
115 client_set_##prop(lua_State *L, int cidx, char *value) \
117 client_t *c = luaA_checkudata(L, cidx, &client_class); \
118 if (A_STREQ(c->prop, value)) \
123 p_delete(&c->prop); \
125 luaA_object_emit_signal(L, cidx, "property::" #signal, 0); \
127 #define DO_CLIENT_SET_STRING_PROPERTY(prop) \
128 DO_CLIENT_SET_STRING_PROPERTY2(prop, prop)
129 DO_CLIENT_SET_STRING_PROPERTY(name
)
130 DO_CLIENT_SET_STRING_PROPERTY2(alt_name
, name
)
131 DO_CLIENT_SET_STRING_PROPERTY(icon_name
)
132 DO_CLIENT_SET_STRING_PROPERTY2(alt_icon_name
, icon_name
)
133 DO_CLIENT_SET_STRING_PROPERTY(role
)
134 DO_CLIENT_SET_STRING_PROPERTY(machine
)
135 #undef DO_CLIENT_SET_STRING_PROPERTY
138 client_set_class_instance(lua_State
*L
, int cidx
, const char *class, const char *instance
)
140 client_t
*c
= luaA_checkudata(L
, cidx
, &client_class
);
142 p_delete(&c
->instance
);
143 c
->class = a_strdup(class);
144 luaA_object_emit_signal(L
, cidx
, "property::class", 0);
145 c
->instance
= a_strdup(instance
);
146 luaA_object_emit_signal(L
, cidx
, "property::instance", 0);
149 /** Returns true if a client is tagged
150 * with one of the tags of the specified screen.
151 * \param c The client to check.
152 * \param screen Virtual screen.
153 * \return true if the client is visible, false otherwise.
156 client_maybevisible(client_t
*c
)
161 foreach(tag
, globalconf
.tags
)
162 if(tag_get_selected(*tag
) && is_client_tagged(c
, *tag
))
168 /** Get a client by its window.
169 * \param w The client window to find.
170 * \return A client pointer if found, NULL otherwise.
173 client_getbywin(xcb_window_t w
)
175 foreach(c
, globalconf
.clients
)
176 if((*c
)->window
== w
)
182 /** Get a client by its frame window.
183 * \param w The client window to find.
184 * \return A client pointer if found, NULL otherwise.
187 client_getbyframewin(xcb_window_t w
)
189 foreach(c
, globalconf
.clients
)
190 if((*c
)->frame_window
== w
)
196 /** Unfocus a client (internal).
197 * \param c The client.
200 client_unfocus_internal(client_t
*c
)
202 globalconf
.focus
.client
= NULL
;
204 luaA_object_push(globalconf
.L
, c
);
205 luaA_object_emit_signal(globalconf
.L
, -1, "unfocus", 0);
206 lua_pop(globalconf
.L
, 1);
209 /** Unfocus a client.
210 * \param c The client.
213 client_unfocus(client_t
*c
)
215 client_unfocus_internal(c
);
216 globalconf
.focus
.need_update
= true;
219 /** Check if client supports atom a protocol in WM_PROTOCOL.
220 * \param c The client.
221 * \param atom The protocol atom to check for.
222 * \return True if client has the atom in protocol, false otherwise.
225 client_hasproto(client_t
*c
, xcb_atom_t atom
)
227 for(uint32_t i
= 0; i
< c
->protocols
.atoms_len
; i
++)
228 if(c
->protocols
.atoms
[i
] == atom
)
233 /** Prepare banning a client by running all needed lua events.
234 * \param c The client.
236 void client_ban_unfocus(client_t
*c
)
238 /* Wait until the last moment to take away the focus from the window. */
239 if(globalconf
.focus
.client
== c
)
243 /** Ban client and move it out of the viewport.
244 * \param c The client.
247 client_ban(client_t
*c
)
251 xcb_unmap_window(globalconf
.connection
, c
->frame_window
);
255 client_ban_unfocus(c
);
259 /** This is part of The Bob Marley Algorithm: we ignore enter and leave window
260 * in certain cases, like map/unmap or move, so we don't get spurious events.
263 client_ignore_enterleave_events(void)
265 foreach(c
, globalconf
.clients
)
267 xcb_change_window_attributes(globalconf
.connection
,
270 (const uint32_t []) { CLIENT_SELECT_INPUT_EVENT_MASK
& ~(XCB_EVENT_MASK_ENTER_WINDOW
| XCB_EVENT_MASK_LEAVE_WINDOW
) });
271 xcb_change_window_attributes(globalconf
.connection
,
274 (const uint32_t []) { FRAME_SELECT_INPUT_EVENT_MASK
& ~(XCB_EVENT_MASK_ENTER_WINDOW
| XCB_EVENT_MASK_LEAVE_WINDOW
) });
279 client_restore_enterleave_events(void)
281 foreach(c
, globalconf
.clients
)
283 xcb_change_window_attributes(globalconf
.connection
,
286 (const uint32_t []) { CLIENT_SELECT_INPUT_EVENT_MASK
});
287 xcb_change_window_attributes(globalconf
.connection
,
290 (const uint32_t []) { FRAME_SELECT_INPUT_EVENT_MASK
});
294 /** Record that a client got focus.
295 * \param c The client.
298 client_focus_update(client_t
*c
)
300 if(!client_maybevisible(c
))
303 if(globalconf
.focus
.client
)
305 if (globalconf
.focus
.client
== c
)
306 /* Already focused */
309 /* When we are called due to a FocusIn event (=old focused client
310 * already unfocused), we don't want to cause a SetInputFocus,
311 * because the client which has focus now could be using globally
312 * active input model (or 'no input').
314 client_unfocus_internal(globalconf
.focus
.client
);
317 globalconf
.focus
.client
= c
;
319 /* according to EWMH, we have to remove the urgent state from a client */
320 luaA_object_push(globalconf
.L
, c
);
321 client_set_urgent(globalconf
.L
, -1, false);
323 luaA_object_emit_signal(globalconf
.L
, -1, "focus", 0);
324 lua_pop(globalconf
.L
, 1);
327 /** Give focus to client, or to first client if client is NULL.
328 * \param c The client.
331 client_focus(client_t
*c
)
333 /* We have to set focus on first client */
334 if(!c
&& globalconf
.clients
.len
&& !(c
= globalconf
.clients
.tab
[0]))
337 if(!client_maybevisible(c
) || c
== globalconf
.focus
.client
)
340 client_focus_update(c
);
341 globalconf
.focus
.need_update
= true;
345 client_focus_refresh(void)
347 client_t
*c
= globalconf
.focus
.client
;
348 xcb_window_t win
= globalconf
.screen
->root
;
350 if(!globalconf
.focus
.need_update
)
352 globalconf
.focus
.need_update
= false;
356 /* Make sure this window is unbanned and e.g. not minimized */
358 /* Sets focus on window - using xcb_set_input_focus or WM_TAKE_FOCUS */
362 /* Focus the root window to make sure the previously focused client
363 * doesn't get any input in case WM_TAKE_FOCUS gets ignored.
365 win
= globalconf
.screen
->root
;
367 if(client_hasproto(c
, WM_TAKE_FOCUS
))
368 xwindow_takefocus(c
->window
);
371 /* If nothing has the focused or the currently focused client doesn't want
372 * us to focus it, this sets the focus to the root window. This makes sure
373 * the previously focused client actually gets unfocused. Alternatively, the
374 * new client gets the input focus.
376 xcb_set_input_focus(globalconf
.connection
, XCB_INPUT_FOCUS_PARENT
,
377 win
, globalconf
.timestamp
);
381 client_update_properties(client_t
*c
)
384 xcb_get_property_cookie_t wm_normal_hints
= property_get_wm_normal_hints(c
);
385 xcb_get_property_cookie_t wm_hints
= property_get_wm_hints(c
);
386 xcb_get_property_cookie_t wm_transient_for
= property_get_wm_transient_for(c
);
387 xcb_get_property_cookie_t wm_client_leader
= property_get_wm_client_leader(c
);
388 xcb_get_property_cookie_t wm_client_machine
= property_get_wm_client_machine(c
);
389 xcb_get_property_cookie_t wm_window_role
= property_get_wm_window_role(c
);
390 xcb_get_property_cookie_t net_wm_pid
= property_get_net_wm_pid(c
);
391 xcb_get_property_cookie_t net_wm_icon
= property_get_net_wm_icon(c
);
392 xcb_get_property_cookie_t wm_name
= property_get_wm_name(c
);
393 xcb_get_property_cookie_t net_wm_name
= property_get_net_wm_name(c
);
394 xcb_get_property_cookie_t wm_icon_name
= property_get_wm_icon_name(c
);
395 xcb_get_property_cookie_t net_wm_icon_name
= property_get_net_wm_icon_name(c
);
396 xcb_get_property_cookie_t wm_class
= property_get_wm_class(c
);
397 xcb_get_property_cookie_t wm_protocols
= property_get_wm_protocols(c
);
398 xcb_get_property_cookie_t opacity
= xwindow_get_opacity_unchecked(c
->window
);
401 ewmh_process_client_strut(c
);
403 /* Now process all replies */
404 property_update_wm_normal_hints(c
, wm_normal_hints
);
405 property_update_wm_hints(c
, wm_hints
);
406 property_update_wm_transient_for(c
, wm_transient_for
);
407 property_update_wm_client_leader(c
, wm_client_leader
);
408 property_update_wm_client_machine(c
, wm_client_machine
);
409 property_update_wm_window_role(c
, wm_window_role
);
410 property_update_net_wm_pid(c
, net_wm_pid
);
411 property_update_net_wm_icon(c
, net_wm_icon
);
412 property_update_wm_name(c
, wm_name
);
413 property_update_net_wm_name(c
, net_wm_name
);
414 property_update_wm_icon_name(c
, wm_icon_name
);
415 property_update_net_wm_icon_name(c
, net_wm_icon_name
);
416 property_update_wm_class(c
, wm_class
);
417 property_update_wm_protocols(c
, wm_protocols
);
418 window_set_opacity(globalconf
.L
, -1, xwindow_get_opacity_from_cookie(opacity
));
421 /** Manage a new client.
422 * \param w The window.
423 * \param wgeom Window geometry.
424 * \param startup True if we are managing at startup time.
427 client_manage(xcb_window_t w
, xcb_get_geometry_reply_t
*wgeom
, xcb_get_window_attributes_reply_t
*wattr
)
429 const uint32_t select_input_val
[] = { CLIENT_SELECT_INPUT_EVENT_MASK
};
431 if(systray_iskdedockapp(w
))
433 systray_request_handle(w
, NULL
);
437 /* If this is a new client that just has been launched, then request its
439 xcb_get_property_cookie_t startup_id_q
= xcb_get_property(globalconf
.connection
, false,
441 XCB_GET_PROPERTY_TYPE_ANY
, 0, UINT_MAX
);
443 /* Make sure the window is automatically mapped if awesome exits or dies. */
444 xcb_change_save_set(globalconf
.connection
, XCB_SET_MODE_INSERT
, w
);
445 if (globalconf
.have_shape
)
446 xcb_shape_select_input(globalconf
.connection
, w
, 1);
448 client_t
*c
= client_new(globalconf
.L
);
449 xcb_screen_t
*s
= globalconf
.screen
;
451 /* consider the window banned */
453 /* Store window and visual */
455 c
->visualtype
= draw_find_visual(globalconf
.screen
, wattr
->visual
);
456 c
->frame_window
= xcb_generate_id(globalconf
.connection
);
457 xcb_create_window(globalconf
.connection
, globalconf
.default_depth
, c
->frame_window
, s
->root
,
458 wgeom
->x
, wgeom
->y
, wgeom
->width
, wgeom
->height
,
459 wgeom
->border_width
, XCB_COPY_FROM_PARENT
, globalconf
.visual
->visual_id
,
460 XCB_CW_BORDER_PIXEL
| XCB_CW_BIT_GRAVITY
| XCB_CW_WIN_GRAVITY
461 | XCB_CW_OVERRIDE_REDIRECT
| XCB_CW_EVENT_MASK
| XCB_CW_COLORMAP
,
464 globalconf
.screen
->black_pixel
,
465 XCB_GRAVITY_NORTH_WEST
,
466 XCB_GRAVITY_NORTH_WEST
,
468 FRAME_SELECT_INPUT_EVENT_MASK
,
469 globalconf
.default_cmap
472 /* The client may already be mapped, thus we must be sure that we don't send
473 * ourselves an UnmapNotify due to the xcb_reparent_window().
475 * Grab the server to make sure we don't lose any events.
477 uint32_t no_event
[] = { 0 };
478 xcb_grab_server(globalconf
.connection
);
480 xcb_change_window_attributes(globalconf
.connection
,
481 globalconf
.screen
->root
,
484 xcb_reparent_window(globalconf
.connection
, w
, c
->frame_window
, 0, 0);
485 xcb_map_window(globalconf
.connection
, w
);
486 xcb_change_window_attributes(globalconf
.connection
,
487 globalconf
.screen
->root
,
489 ROOT_WINDOW_EVENT_MASK
);
490 xcb_ungrab_server(globalconf
.connection
);
492 /* Do this now so that we don't get any events for the above
493 * (Else, reparent could cause an UnmapNotify) */
494 xcb_change_window_attributes(globalconf
.connection
, w
, XCB_CW_EVENT_MASK
, select_input_val
);
496 luaA_object_emit_signal(globalconf
.L
, -1, "property::window", 0);
498 /* The frame window gets the border, not the real client window */
499 xcb_configure_window(globalconf
.connection
, w
,
500 XCB_CONFIG_WINDOW_BORDER_WIDTH
,
503 /* Move this window to the bottom of the stack. Without this we would force
504 * other windows which will be above this one to redraw themselves because
505 * this window occludes them for a tiny moment. The next stack_refresh()
506 * will fix this up and move the window to its correct place. */
507 xcb_configure_window(globalconf
.connection
, c
->frame_window
,
508 XCB_CONFIG_WINDOW_STACK_MODE
,
509 (uint32_t[]) { XCB_STACK_MODE_BELOW
});
511 /* Duplicate client and push it in client list */
512 lua_pushvalue(globalconf
.L
, -1);
513 client_array_push(&globalconf
.clients
, luaA_object_ref(globalconf
.L
, -1));
515 /* Set the right screen */
516 screen_client_moveto(c
, screen_getbycoord(wgeom
->x
, wgeom
->y
), false);
518 /* Store initial geometry and emits signals so we inform that geometry have
520 #define HANDLE_GEOM(attr) \
521 c->geometry.attr = wgeom->attr; \
522 luaA_object_emit_signal(globalconf.L, -1, "property::" #attr, 0);
529 luaA_object_emit_signal(globalconf
.L
, -1, "property::geometry", 0);
531 /* Set border width */
532 window_set_border_width(globalconf
.L
, -1, wgeom
->border_width
);
534 /* we honor size hints by default */
535 c
->size_hints_honor
= true;
536 luaA_object_emit_signal(globalconf
.L
, -1, "property::size_hints_honor", 0);
538 /* update all properties */
539 client_update_properties(c
);
541 /* Then check clients hints */
542 ewmh_client_check_hints(c
);
544 /* Push client in stack */
545 stack_client_push(c
);
547 /* Always stay in NORMAL_STATE. Even though iconified seems more
548 * appropriate sometimes. The only possible loss is that clients not using
549 * visibility events may continue to process data (when banned).
550 * Without any exposes or other events the cost should be fairly limited though.
552 * Some clients may expect the window to be unmapped when STATE_ICONIFIED.
553 * Two conflicting parts of the ICCCM v2.0 (section 4.1.4):
555 * "Normal -> Iconic - The client should send a ClientMessage event as described later in this section."
556 * (note no explicit mention of unmapping, while Normal->Widthdrawn does mention that)
558 * "Once a client's window has left the Withdrawn state, the window will be mapped
559 * if it is in the Normal state and the window will be unmapped if it is in the Iconic state."
561 * At this stage it's just safer to keep it in normal state and avoid confusion.
563 xwindow_set_state(c
->window
, XCB_ICCCM_WM_STATE_NORMAL
);
565 /* Request our response */
566 xcb_get_property_reply_t
*reply
=
567 xcb_get_property_reply(globalconf
.connection
, startup_id_q
, NULL
);
568 /* Say spawn that a client has been started, with startup id as argument */
569 char *startup_id
= xutil_get_text_property_from_reply(reply
);
570 c
->startup_id
= startup_id
;
572 spawn_start_notify(c
, startup_id
);
574 luaA_class_emit_signal(globalconf
.L
, &client_class
, "list", 0);
576 /* client is still on top of the stack; emit signal */
577 luaA_object_emit_signal(globalconf
.L
, -1, "manage", 0);
579 lua_pop(globalconf
.L
, 1);
583 client_remove_titlebar_geometry(client_t
*c
, area_t
*geometry
)
585 geometry
->x
+= c
->titlebar
[CLIENT_TITLEBAR_LEFT
].size
;
586 geometry
->y
+= c
->titlebar
[CLIENT_TITLEBAR_TOP
].size
;
587 geometry
->width
-= c
->titlebar
[CLIENT_TITLEBAR_LEFT
].size
;
588 geometry
->width
-= c
->titlebar
[CLIENT_TITLEBAR_RIGHT
].size
;
589 geometry
->height
-= c
->titlebar
[CLIENT_TITLEBAR_TOP
].size
;
590 geometry
->height
-= c
->titlebar
[CLIENT_TITLEBAR_BOTTOM
].size
;
594 client_add_titlebar_geometry(client_t
*c
, area_t
*geometry
)
596 geometry
->x
-= c
->titlebar
[CLIENT_TITLEBAR_LEFT
].size
;
597 geometry
->y
-= c
->titlebar
[CLIENT_TITLEBAR_TOP
].size
;
598 geometry
->width
+= c
->titlebar
[CLIENT_TITLEBAR_LEFT
].size
;
599 geometry
->width
+= c
->titlebar
[CLIENT_TITLEBAR_RIGHT
].size
;
600 geometry
->height
+= c
->titlebar
[CLIENT_TITLEBAR_TOP
].size
;
601 geometry
->height
+= c
->titlebar
[CLIENT_TITLEBAR_BOTTOM
].size
;
604 /** Send a synthetic configure event to a window.
607 client_send_configure(client_t
*c
)
609 area_t geometry
= c
->geometry
;
612 client_remove_titlebar_geometry(c
, &geometry
);
613 xwindow_configure(c
->window
, geometry
, c
->border_width
);
616 /** Apply size hints to the client's new geometry.
619 client_apply_size_hints(client_t
*c
, area_t geometry
)
621 int32_t minw
= 0, minh
= 0;
622 int32_t basew
= 0, baseh
= 0, real_basew
= 0, real_baseh
= 0;
627 /* Size hints are applied to the window without any decoration */
628 client_remove_titlebar_geometry(c
, &geometry
);
630 if(c
->size_hints
.flags
& XCB_ICCCM_SIZE_HINT_P_SIZE
)
632 basew
= c
->size_hints
.base_width
;
633 baseh
= c
->size_hints
.base_height
;
637 else if(c
->size_hints
.flags
& XCB_ICCCM_SIZE_HINT_P_MIN_SIZE
)
639 /* base size is substituted with min size if not specified */
640 basew
= c
->size_hints
.min_width
;
641 baseh
= c
->size_hints
.min_height
;
644 if(c
->size_hints
.flags
& XCB_ICCCM_SIZE_HINT_P_MIN_SIZE
)
646 minw
= c
->size_hints
.min_width
;
647 minh
= c
->size_hints
.min_height
;
649 else if(c
->size_hints
.flags
& XCB_ICCCM_SIZE_HINT_P_SIZE
)
651 /* min size is substituted with base size if not specified */
652 minw
= c
->size_hints
.base_width
;
653 minh
= c
->size_hints
.base_height
;
656 /* Handle the size aspect ratio */
657 if(c
->size_hints
.flags
& XCB_ICCCM_SIZE_HINT_P_ASPECT
658 && c
->size_hints
.min_aspect_den
> 0
659 && c
->size_hints
.max_aspect_den
> 0
660 && geometry
.height
> real_baseh
661 && geometry
.width
> real_basew
)
664 * If a base size is provided along with the aspect ratio fields, the base size should be subtracted from the
665 * window size prior to checking that the aspect ratio falls in range. If a base size is not provided, nothing
666 * should be subtracted from the window size. (The minimum size is not to be used in place of the base size for
669 double dx
= geometry
.width
- real_basew
;
670 double dy
= geometry
.height
- real_baseh
;
671 double ratio
= dx
/ dy
;
672 double min
= c
->size_hints
.min_aspect_num
/ (double) c
->size_hints
.min_aspect_den
;
673 double max
= c
->size_hints
.max_aspect_num
/ (double) c
->size_hints
.max_aspect_den
;
675 if(max
> 0 && min
> 0 && ratio
> 0)
679 /* dx is lower than allowed, make dy lower to compensate this (+ 0.5 to force proper rounding). */
681 geometry
.width
= dx
+ real_basew
;
682 geometry
.height
= dy
+ real_baseh
;
683 } else if(ratio
> max
)
685 /* dx is too high, lower it (+0.5 for proper rounding) */
687 geometry
.width
= dx
+ real_basew
;
688 geometry
.height
= dy
+ real_baseh
;
693 /* Handle the minimum size */
694 geometry
.width
= MAX(geometry
.width
, minw
);
695 geometry
.height
= MAX(geometry
.height
, minh
);
697 /* Handle the maximum size */
698 if(c
->size_hints
.flags
& XCB_ICCCM_SIZE_HINT_P_MAX_SIZE
)
700 if(c
->size_hints
.max_width
)
701 geometry
.width
= MIN(geometry
.width
, c
->size_hints
.max_width
);
702 if(c
->size_hints
.max_height
)
703 geometry
.height
= MIN(geometry
.height
, c
->size_hints
.max_height
);
706 /* Handle the size increment */
707 if(c
->size_hints
.flags
& (XCB_ICCCM_SIZE_HINT_P_RESIZE_INC
| XCB_ICCCM_SIZE_HINT_BASE_SIZE
)
708 && c
->size_hints
.width_inc
&& c
->size_hints
.height_inc
)
710 uint16_t t1
= geometry
.width
, t2
= geometry
.height
;
711 unsigned_subtract(t1
, basew
);
712 unsigned_subtract(t2
, baseh
);
713 geometry
.width
-= t1
% c
->size_hints
.width_inc
;
714 geometry
.height
-= t2
% c
->size_hints
.height_inc
;
717 client_add_titlebar_geometry(c
, &geometry
);
722 client_resize_do(client_t
*c
, area_t geometry
, bool force_notice
, bool honor_hints
)
724 bool send_notice
= force_notice
;
725 bool hide_titlebars
= c
->fullscreen
;
726 screen_t
*new_screen
= screen_getbycoord(geometry
.x
, geometry
.y
);
729 geometry
= client_apply_size_hints(c
, geometry
);
731 if(c
->geometry
.width
== geometry
.width
732 && c
->geometry
.height
== geometry
.height
)
735 /* Also store geometry including border */
736 area_t old_geometry
= c
->geometry
;
737 c
->geometry
= geometry
;
739 /* Ignore all spurious enter/leave notify events */
740 client_ignore_enterleave_events();
742 /* Configure the client for its new size */
743 area_t real_geometry
= geometry
;
746 real_geometry
.x
= c
->titlebar
[CLIENT_TITLEBAR_LEFT
].size
;
747 real_geometry
.y
= c
->titlebar
[CLIENT_TITLEBAR_TOP
].size
;
748 real_geometry
.width
-= c
->titlebar
[CLIENT_TITLEBAR_LEFT
].size
;
749 real_geometry
.width
-= c
->titlebar
[CLIENT_TITLEBAR_RIGHT
].size
;
750 real_geometry
.height
-= c
->titlebar
[CLIENT_TITLEBAR_TOP
].size
;
751 real_geometry
.height
-= c
->titlebar
[CLIENT_TITLEBAR_BOTTOM
].size
;
757 xcb_configure_window(globalconf
.connection
, c
->frame_window
,
758 XCB_CONFIG_WINDOW_X
| XCB_CONFIG_WINDOW_Y
| XCB_CONFIG_WINDOW_WIDTH
| XCB_CONFIG_WINDOW_HEIGHT
,
759 (uint32_t[]) { geometry
.x
, geometry
.y
, geometry
.width
, geometry
.height
});
760 xcb_configure_window(globalconf
.connection
, c
->window
,
761 XCB_CONFIG_WINDOW_X
| XCB_CONFIG_WINDOW_Y
| XCB_CONFIG_WINDOW_WIDTH
| XCB_CONFIG_WINDOW_HEIGHT
,
762 (uint32_t[]) { real_geometry
.x
, real_geometry
.y
, real_geometry
.width
, real_geometry
.height
});
765 /* We are moving without changing the size, see ICCCM 4.2.3 */
766 client_send_configure(c
);
768 client_restore_enterleave_events();
770 luaA_object_push(globalconf
.L
, c
);
771 luaA_object_emit_signal(globalconf
.L
, -1, "property::geometry", 0);
772 if (old_geometry
.x
!= geometry
.x
)
773 luaA_object_emit_signal(globalconf
.L
, -1, "property::x", 0);
774 if (old_geometry
.y
!= geometry
.y
)
775 luaA_object_emit_signal(globalconf
.L
, -1, "property::y", 0);
776 if (old_geometry
.width
!= geometry
.width
)
777 luaA_object_emit_signal(globalconf
.L
, -1, "property::width", 0);
778 if (old_geometry
.height
!= geometry
.height
)
779 luaA_object_emit_signal(globalconf
.L
, -1, "property::height", 0);
780 lua_pop(globalconf
.L
, 1);
782 screen_client_moveto(c
, new_screen
, false);
784 /* Update all titlebars */
785 for (client_titlebar_t bar
= CLIENT_TITLEBAR_TOP
; bar
< CLIENT_TITLEBAR_COUNT
; bar
++) {
786 if (c
->titlebar
[bar
].drawable
== NULL
&& c
->titlebar
[bar
].size
== 0)
789 luaA_object_push(globalconf
.L
, c
);
790 drawable_t
*drawable
= titlebar_get_drawable(globalconf
.L
, c
, -1, bar
);
791 luaA_object_push_item(globalconf
.L
, -1, drawable
);
793 area_t area
= titlebar_get_area(c
, bar
);
795 /* Convert to global coordinates */
796 area
.x
+= geometry
.x
;
797 area
.y
+= geometry
.y
;
799 area
.width
= area
.height
= 0;
800 drawable_set_geometry(drawable
, -1, area
);
802 /* Pop the client and the drawable */
803 lua_pop(globalconf
.L
, 2);
807 /** Resize client window.
808 * The sizes given as parameters are with borders!
809 * \param c Client to resize.
810 * \param geometry New window geometry.
811 * \param honor_hints Use size hints.
812 * \return true if an actual resize occurred.
815 client_resize(client_t
*c
, area_t geometry
, bool honor_hints
)
819 /* offscreen appearance fixes */
820 area
= display_area_get();
822 if(geometry
.x
> area
.width
)
823 geometry
.x
= area
.width
- geometry
.width
;
824 if(geometry
.y
> area
.height
)
825 geometry
.y
= area
.height
- geometry
.height
;
826 if(geometry
.x
+ geometry
.width
< 0)
828 if(geometry
.y
+ geometry
.height
< 0)
831 if(geometry
.width
< c
->titlebar
[CLIENT_TITLEBAR_LEFT
].size
+ c
->titlebar
[CLIENT_TITLEBAR_RIGHT
].size
)
833 if(geometry
.height
< c
->titlebar
[CLIENT_TITLEBAR_TOP
].size
+ c
->titlebar
[CLIENT_TITLEBAR_BOTTOM
].size
)
836 if(geometry
.width
== 0 || geometry
.height
== 0)
839 if(c
->geometry
.x
!= geometry
.x
840 || c
->geometry
.y
!= geometry
.y
841 || c
->geometry
.width
!= geometry
.width
842 || c
->geometry
.height
!= geometry
.height
)
844 client_resize_do(c
, geometry
, false, honor_hints
);
853 client_emit_property_workarea_on_screen(lua_State
*L
, client_t
*c
)
855 luaA_object_push(L
, c
->screen
);
856 luaA_object_emit_signal(L
, -1, "property::workarea", 0);
860 /** Set a client minimized, or not.
861 * \param L The Lua VM state.
862 * \param cidx The client index.
863 * \param s Set or not the client minimized.
866 client_set_minimized(lua_State
*L
, int cidx
, bool s
)
868 client_t
*c
= luaA_checkudata(L
, cidx
, &client_class
);
870 if(c
->minimized
!= s
)
873 banning_need_update();
875 xwindow_set_state(c
->window
, XCB_ICCCM_WM_STATE_ICONIC
);
877 xwindow_set_state(c
->window
, XCB_ICCCM_WM_STATE_NORMAL
);
878 if(strut_has_value(&c
->strut
))
879 client_emit_property_workarea_on_screen(L
, c
);
880 luaA_object_emit_signal(L
, cidx
, "property::minimized", 0);
884 /** Set a client hidden, or not.
885 * \param L The Lua VM state.
886 * \param cidx The client index.
887 * \param s Set or not the client hidden.
890 client_set_hidden(lua_State
*L
, int cidx
, bool s
)
892 client_t
*c
= luaA_checkudata(L
, cidx
, &client_class
);
897 banning_need_update();
898 if(strut_has_value(&c
->strut
))
899 client_emit_property_workarea_on_screen(L
, c
);
900 luaA_object_emit_signal(L
, cidx
, "property::hidden", 0);
904 /** Set a client sticky, or not.
905 * \param L The Lua VM state.
906 * \param cidx The client index.
907 * \param s Set or not the client sticky.
910 client_set_sticky(lua_State
*L
, int cidx
, bool s
)
912 client_t
*c
= luaA_checkudata(L
, cidx
, &client_class
);
917 banning_need_update();
918 luaA_object_emit_signal(L
, cidx
, "property::sticky", 0);
922 /** Set a client fullscreen, or not.
923 * \param L The Lua VM state.
924 * \param cidx The client index.
925 * \param s Set or not the client fullscreen.
928 client_set_fullscreen(lua_State
*L
, int cidx
, bool s
)
930 client_t
*c
= luaA_checkudata(L
, cidx
, &client_class
);
932 if(c
->fullscreen
!= s
)
934 /* become fullscreen! */
937 /* remove any max state */
938 client_set_maximized(L
, cidx
, false);
939 /* You can only be part of one of the special layers. */
940 client_set_below(L
, cidx
, false);
941 client_set_above(L
, cidx
, false);
942 client_set_ontop(L
, cidx
, false);
944 int abs_cidx
= luaA_absindex(L
, cidx
); \
945 lua_pushboolean(L
, s
);
947 luaA_object_emit_signal(L
, abs_cidx
, "request::fullscreen", 1);
948 luaA_object_emit_signal(L
, abs_cidx
, "property::fullscreen", 0);
949 /* Force a client resize, so that titlebars get shown/hidden */
950 client_resize_do(c
, c
->geometry
, true, false);
955 /** Get a clients maximized state (horizontally and vertically).
956 * \param c The client.
957 * \return The maximized state.
960 client_get_maximized(client_t
*c
)
962 return c
->maximized_horizontal
&& c
->maximized_vertical
;
965 /** Set a client horizontally|vertically maximized.
966 * \param L The Lua VM state.
967 * \param cidx The client index.
968 * \param s The maximized status.
970 #define DO_FUNCTION_CLIENT_MAXIMIZED(type) \
972 client_set_maximized_##type(lua_State *L, int cidx, bool s) \
974 client_t *c = luaA_checkudata(L, cidx, &client_class); \
975 if(c->maximized_##type != s) \
977 int abs_cidx = luaA_absindex(L, cidx); \
979 client_set_fullscreen(L, abs_cidx, false); \
980 lua_pushboolean(L, s); \
981 int max_before = client_get_maximized(c); \
982 c->maximized_##type = s; \
983 luaA_object_emit_signal(L, abs_cidx, "request::maximized_" #type, 1); \
984 luaA_object_emit_signal(L, abs_cidx, "property::maximized_" #type, 0); \
985 if(max_before != client_get_maximized(c)) \
986 luaA_object_emit_signal(L, abs_cidx, "property::maximized", 0); \
990 DO_FUNCTION_CLIENT_MAXIMIZED(vertical
)
991 DO_FUNCTION_CLIENT_MAXIMIZED(horizontal
)
992 #undef DO_FUNCTION_CLIENT_MAXIMIZED
994 /** Set a client maximized (horizontally and vertically).
995 * \param L The Lua VM state.
996 * \param cidx The client index.
997 * \param s Set or not the client maximized attribute.
1000 client_set_maximized(lua_State
*L
, int cidx
, bool s
)
1002 client_set_maximized_horizontal(L
, cidx
, s
);
1003 client_set_maximized_vertical(L
, cidx
, s
);
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.
1012 client_set_above(lua_State
*L
, int cidx
, bool s
)
1014 client_t
*c
= luaA_checkudata(L
, cidx
, &client_class
);
1018 /* You can only be part of one of the special layers. */
1021 client_set_below(L
, cidx
, false);
1022 client_set_ontop(L
, cidx
, false);
1023 client_set_fullscreen(L
, cidx
, false);
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.
1037 client_set_below(lua_State
*L
, int cidx
, bool s
)
1039 client_t
*c
= luaA_checkudata(L
, cidx
, &client_class
);
1043 /* You can only be part of one of the special layers. */
1046 client_set_above(L
, cidx
, false);
1047 client_set_ontop(L
, cidx
, false);
1048 client_set_fullscreen(L
, cidx
, false);
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.
1062 client_set_modal(lua_State
*L
, int cidx
, bool s
)
1064 client_t
*c
= luaA_checkudata(L
, cidx
, &client_class
);
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.
1080 client_set_ontop(lua_State
*L
, int cidx
, bool s
)
1082 client_t
*c
= luaA_checkudata(L
, cidx
, &client_class
);
1086 /* You can only be part of one of the special layers. */
1089 client_set_above(L
, cidx
, false);
1090 client_set_below(L
, cidx
, false);
1091 client_set_fullscreen(L
, cidx
, false);
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.
1103 client_unban(client_t
*c
)
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?
1124 client_unmanage(client_t
*c
, bool window_valid
)
1126 /* Reset transient_for attributes of windows that might be 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
)
1137 /* remove client from global list and everywhere else */
1138 foreach(elem
, globalconf
.clients
)
1141 client_array_remove(&globalconf
.clients
, elem
);
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 client_emit_property_workarea_on_screen(globalconf
.L
, c
);
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
)
1162 /* Forget about the drawable */
1163 luaA_object_push(globalconf
.L
, c
);
1164 luaA_object_unref_item(globalconf
.L
, -1, c
->titlebar
[bar
].drawable
);
1165 c
->titlebar
[bar
].drawable
= NULL
;
1166 lua_pop(globalconf
.L
, 1);
1169 /* Clear our event mask so that we don't receive any events from now on,
1170 * especially not for the following requests. */
1172 xcb_change_window_attributes(globalconf
.connection
,
1175 (const uint32_t []) { 0 });
1176 xcb_change_window_attributes(globalconf
.connection
,
1179 (const uint32_t []) { 0 });
1183 xcb_unmap_window(globalconf
.connection
, c
->window
);
1184 xcb_reparent_window(globalconf
.connection
, c
->window
, globalconf
.screen
->root
,
1185 c
->geometry
.x
, c
->geometry
.y
);
1188 /* Ignore all spurious enter/leave notify events */
1189 client_ignore_enterleave_events();
1190 xcb_destroy_window(globalconf
.connection
, c
->frame_window
);
1191 client_restore_enterleave_events();
1195 /* Remove this window from the save set since this shouldn't be made visible
1196 * after a restart anymore. */
1197 xcb_change_save_set(globalconf
.connection
, XCB_SET_MODE_DELETE
, c
->window
);
1198 if (globalconf
.have_shape
)
1199 xcb_shape_select_input(globalconf
.connection
, c
->window
, 0);
1201 /* Do this last to avoid races with clients. According to ICCCM, clients
1202 * arent allowed to re-use the window until after this. */
1203 xwindow_set_state(c
->window
, XCB_ICCCM_WM_STATE_WITHDRAWN
);
1206 /* set client as invalid */
1207 c
->window
= XCB_NONE
;
1209 luaA_object_unref(globalconf
.L
, c
);
1212 /** Kill a client via a WM_DELETE_WINDOW request or KillClient if not
1214 * \param c The client to kill.
1217 client_kill(client_t
*c
)
1219 if(client_hasproto(c
, WM_DELETE_WINDOW
))
1221 xcb_client_message_event_t ev
;
1223 /* Initialize all of event's fields first */
1226 ev
.response_type
= XCB_CLIENT_MESSAGE
;
1227 ev
.window
= c
->window
;
1229 ev
.data
.data32
[1] = globalconf
.timestamp
;
1230 ev
.type
= WM_PROTOCOLS
;
1231 ev
.data
.data32
[0] = WM_DELETE_WINDOW
;
1233 xcb_send_event(globalconf
.connection
, false, c
->window
,
1234 XCB_EVENT_MASK_NO_EVENT
, (char *) &ev
);
1237 xcb_kill_client(globalconf
.connection
, c
->window
);
1240 /** Get all clients into a table.
1241 * \param L The Lua VM state.
1242 * \return The number of elements pushed on stack.
1244 * \lparam An optional screen number.
1245 * \lreturn A table with all clients.
1248 luaA_client_get(lua_State
*L
)
1251 screen_t
*screen
= NULL
;
1253 if(!lua_isnoneornil(L
, 1))
1254 screen
= luaA_checkscreen(L
, 1);
1257 foreach(c
, globalconf
.clients
)
1258 if(screen
== NULL
|| (*c
)->screen
== screen
)
1260 luaA_object_push(L
, *c
);
1261 lua_rawseti(L
, -2, i
++);
1267 /** Check if a client is visible on its screen.
1268 * \param L The Lua VM state.
1269 * \return The number of elements pushed on stack.
1272 * \lreturn A boolean value, true if the client is visible, false otherwise.
1275 luaA_client_isvisible(lua_State
*L
)
1277 client_t
*c
= luaA_checkudata(L
, 1, &client_class
);
1278 lua_pushboolean(L
, client_isvisible(c
));
1282 /** Set a client icon.
1283 * \param L The Lua VM state.
1284 * \param cidx The client index on the stack.
1285 * \param iidx The image index on the stack.
1288 client_set_icon(client_t
*c
, cairo_surface_t
*s
)
1291 s
= draw_dup_image_surface(s
);
1293 cairo_surface_destroy(c
->icon
);
1296 luaA_object_push(globalconf
.L
, c
);
1297 luaA_object_emit_signal(globalconf
.L
, -1, "property::icon", 0);
1298 lua_pop(globalconf
.L
, 1);
1302 * \param L The Lua VM state.
1308 luaA_client_kill(lua_State
*L
)
1310 client_t
*c
= luaA_checkudata(L
, 1, &client_class
);
1315 /** Swap a client with another one.
1316 * \param L The Lua VM state.
1319 * \lparam A client to swap with.
1322 luaA_client_swap(lua_State
*L
)
1324 client_t
*c
= luaA_checkudata(L
, 1, &client_class
);
1325 client_t
*swap
= luaA_checkudata(L
, 2, &client_class
);
1329 client_t
**ref_c
= NULL
, **ref_swap
= NULL
;
1330 foreach(item
, globalconf
.clients
)
1334 else if(*item
== swap
)
1336 if(ref_c
&& ref_swap
)
1343 luaA_class_emit_signal(globalconf
.L
, &client_class
, "list", 0);
1349 /** Access or set the client tags.
1350 * \param L The Lua VM state.
1351 * \return The number of elements pushed on stack.
1352 * \lparam A table with tags to set, or none to get the current tags table.
1353 * \return The clients tag.
1356 luaA_client_tags(lua_State
*L
)
1358 client_t
*c
= luaA_checkudata(L
, 1, &client_class
);
1361 if(lua_gettop(L
) == 2)
1363 luaA_checktable(L
, 2);
1364 for(int i
= 0; i
< globalconf
.tags
.len
; i
++)
1366 /* Only untag if we aren't going to add this tag again */
1369 while(lua_next(L
, 2))
1371 tag_t
*t
= lua_touserdata(L
, -1);
1372 /* Pop the value from lua_next */
1374 if (t
!= globalconf
.tags
.tab
[i
])
1377 /* Pop the key from lua_next */
1383 untag_client(c
, globalconf
.tags
.tab
[i
]);
1386 while(lua_next(L
, 2))
1392 foreach(tag
, globalconf
.tags
)
1393 if(is_client_tagged(c
, *tag
))
1395 luaA_object_push(L
, *tag
);
1396 lua_rawseti(L
, -2, ++j
);
1402 /** Raise a client on top of others which are on the same layer.
1403 * \param L The Lua VM state.
1408 luaA_client_raise(lua_State
*L
)
1410 client_t
*c
= luaA_checkudata(L
, 1, &client_class
);
1415 /** Lower a client on bottom of others which are on the same layer.
1416 * \param L The Lua VM state.
1421 luaA_client_lower(lua_State
*L
)
1423 client_t
*c
= luaA_checkudata(L
, 1, &client_class
);
1425 stack_client_push(c
);
1427 /* Traverse all transient layers. */
1428 for(client_t
*tc
= c
->transient_for
; tc
; tc
= tc
->transient_for
)
1429 stack_client_push(tc
);
1434 /** Stop managing a client.
1435 * \param L The Lua VM state.
1436 * \return The number of elements pushed on stack.
1441 luaA_client_unmanage(lua_State
*L
)
1443 client_t
*c
= luaA_checkudata(L
, 1, &client_class
);
1444 client_unmanage(c
, true);
1449 titlebar_get_area(client_t
*c
, client_titlebar_t bar
)
1451 area_t result
= c
->geometry
;
1452 result
.x
= result
.y
= 0;
1454 // Let's try some ascii art:
1455 // ---------------------------
1457 // |-------------------------|
1463 // |-------------------------|
1465 // ---------------------------
1468 case CLIENT_TITLEBAR_BOTTOM
:
1469 result
.y
= c
->geometry
.height
- c
->titlebar
[bar
].size
;
1471 case CLIENT_TITLEBAR_TOP
:
1472 result
.height
= c
->titlebar
[bar
].size
;
1474 case CLIENT_TITLEBAR_RIGHT
:
1475 result
.x
= c
->geometry
.width
- c
->titlebar
[bar
].size
;
1477 case CLIENT_TITLEBAR_LEFT
:
1478 result
.y
= c
->titlebar
[CLIENT_TITLEBAR_TOP
].size
;
1479 result
.width
= c
->titlebar
[bar
].size
;
1480 result
.height
-= c
->titlebar
[CLIENT_TITLEBAR_TOP
].size
;
1481 result
.height
-= c
->titlebar
[CLIENT_TITLEBAR_BOTTOM
].size
;
1484 fatal("Unknown titlebar kind %d\n", (int) bar
);
1491 client_get_drawable_offset(client_t
*c
, int *x
, int *y
)
1493 for (client_titlebar_t bar
= CLIENT_TITLEBAR_TOP
; bar
< CLIENT_TITLEBAR_COUNT
; bar
++) {
1494 area_t area
= titlebar_get_area(c
, bar
);
1495 if (AREA_LEFT(area
) > *x
|| AREA_RIGHT(area
) <= *x
)
1497 if (AREA_TOP(area
) > *y
|| AREA_BOTTOM(area
) <= *y
)
1502 return c
->titlebar
[bar
].drawable
;
1509 client_get_drawable(client_t
*c
, int x
, int y
)
1511 return client_get_drawable_offset(c
, &x
, &y
);
1515 client_refresh_titlebar_partial(client_t
*c
, client_titlebar_t bar
, int16_t x
, int16_t y
, uint16_t width
, uint16_t height
)
1517 if(c
->titlebar
[bar
].drawable
== NULL
1518 || c
->titlebar
[bar
].drawable
->pixmap
== XCB_NONE
1519 || !c
->titlebar
[bar
].drawable
->refreshed
)
1522 /* Is the titlebar part of the area that should get redrawn? */
1523 area_t area
= titlebar_get_area(c
, bar
);
1524 if (AREA_LEFT(area
) >= x
+ width
|| AREA_RIGHT(area
) <= x
)
1526 if (AREA_TOP(area
) >= y
+ height
|| AREA_BOTTOM(area
) <= y
)
1529 /* Redraw the affected parts */
1530 cairo_surface_flush(c
->titlebar
[bar
].drawable
->surface
);
1531 xcb_copy_area(globalconf
.connection
, c
->titlebar
[bar
].drawable
->pixmap
, c
->frame_window
,
1532 globalconf
.gc
, x
- area
.x
, y
- area
.y
, x
, y
, width
, height
);
1535 #define HANDLE_TITLEBAR_REFRESH(name, index) \
1537 client_refresh_titlebar_ ## name(client_t *c) \
1539 area_t area = titlebar_get_area(c, index); \
1540 client_refresh_titlebar_partial(c, index, area.x, area.y, area.width, area.height); \
1542 HANDLE_TITLEBAR_REFRESH(top
, CLIENT_TITLEBAR_TOP
)
1543 HANDLE_TITLEBAR_REFRESH(right
, CLIENT_TITLEBAR_RIGHT
)
1544 HANDLE_TITLEBAR_REFRESH(bottom
, CLIENT_TITLEBAR_BOTTOM
)
1545 HANDLE_TITLEBAR_REFRESH(left
, CLIENT_TITLEBAR_LEFT
)
1548 * Refresh all titlebars that are in the specified rectangle
1551 client_refresh_partial(client_t
*c
, int16_t x
, int16_t y
, uint16_t width
, uint16_t height
)
1553 for (client_titlebar_t bar
= CLIENT_TITLEBAR_TOP
; bar
< CLIENT_TITLEBAR_COUNT
; bar
++) {
1554 client_refresh_titlebar_partial(c
, bar
, x
, y
, width
, height
);
1559 titlebar_get_drawable(lua_State
*L
, client_t
*c
, int cl_idx
, client_titlebar_t bar
)
1561 if (c
->titlebar
[bar
].drawable
== NULL
)
1563 cl_idx
= luaA_absindex(L
, cl_idx
);
1565 case CLIENT_TITLEBAR_TOP
:
1566 drawable_allocator(L
, (drawable_refresh_callback
*) client_refresh_titlebar_top
, c
);
1568 case CLIENT_TITLEBAR_BOTTOM
:
1569 drawable_allocator(L
, (drawable_refresh_callback
*) client_refresh_titlebar_bottom
, c
);
1571 case CLIENT_TITLEBAR_RIGHT
:
1572 drawable_allocator(L
, (drawable_refresh_callback
*) client_refresh_titlebar_right
, c
);
1574 case CLIENT_TITLEBAR_LEFT
:
1575 drawable_allocator(L
, (drawable_refresh_callback
*) client_refresh_titlebar_left
, c
);
1578 fatal("Unknown titlebar kind %d\n", (int) bar
);
1580 c
->titlebar
[bar
].drawable
= luaA_object_ref_item(L
, cl_idx
, -1);
1583 return c
->titlebar
[bar
].drawable
;
1587 titlebar_resize(lua_State
*L
, int cidx
, client_t
*c
, client_titlebar_t bar
, int size
)
1589 const char *property_name
;
1594 if (size
== c
->titlebar
[bar
].size
)
1597 /* Now resize the client (and titlebars!) suitably (the client without
1598 * titlebars should keep its current size!) */
1599 area_t geometry
= c
->geometry
;
1600 int change
= size
- c
->titlebar
[bar
].size
;
1602 case CLIENT_TITLEBAR_TOP
:
1603 geometry
.height
+= change
;
1604 property_name
= "property::titlebar_top";
1606 case CLIENT_TITLEBAR_BOTTOM
:
1607 geometry
.height
+= change
;
1608 property_name
= "property::titlebar_bottom";
1610 case CLIENT_TITLEBAR_RIGHT
:
1611 geometry
.width
+= change
;
1612 property_name
= "property::titlebar_right";
1614 case CLIENT_TITLEBAR_LEFT
:
1615 geometry
.width
+= change
;
1616 property_name
= "property::titlebar_left";
1619 fatal("Unknown titlebar kind %d\n", (int) bar
);
1622 c
->titlebar
[bar
].size
= size
;
1623 client_resize_do(c
, geometry
, true, false);
1625 luaA_object_emit_signal(L
, cidx
, property_name
, 0);
1628 #define HANDLE_TITLEBAR(name, index) \
1630 luaA_client_titlebar_ ## name(lua_State *L) \
1632 client_t *c = luaA_checkudata(L, 1, &client_class); \
1634 if (lua_gettop(L) == 2) \
1636 if (lua_isnil(L, 2)) \
1637 titlebar_resize(L, 1, c, index, 0); \
1639 titlebar_resize(L, 1, c, index, luaL_checknumber(L, 2)); \
1642 luaA_object_push_item(L, 1, titlebar_get_drawable(L, c, 1, index)); \
1643 lua_pushnumber(L, c->titlebar[index].size); \
1646 HANDLE_TITLEBAR(top
, CLIENT_TITLEBAR_TOP
)
1647 HANDLE_TITLEBAR(right
, CLIENT_TITLEBAR_RIGHT
)
1648 HANDLE_TITLEBAR(bottom
, CLIENT_TITLEBAR_BOTTOM
)
1649 HANDLE_TITLEBAR(left
, CLIENT_TITLEBAR_LEFT
)
1651 /** Return or set client geometry.
1652 * \param L The Lua VM state.
1653 * \return The number of elements pushed on stack.
1655 * \lparam A table with new coordinates, or none.
1656 * \lreturn A table with client coordinates.
1659 luaA_client_geometry(lua_State
*L
)
1661 client_t
*c
= luaA_checkudata(L
, 1, &client_class
);
1663 if(lua_gettop(L
) == 2 && !lua_isnil(L
, 2))
1667 luaA_checktable(L
, 2);
1668 geometry
.x
= luaA_getopt_number(L
, 2, "x", c
->geometry
.x
);
1669 geometry
.y
= luaA_getopt_number(L
, 2, "y", c
->geometry
.y
);
1670 if(client_isfixed(c
))
1672 geometry
.width
= c
->geometry
.width
;
1673 geometry
.height
= c
->geometry
.height
;
1677 geometry
.width
= luaA_getopt_number(L
, 2, "width", c
->geometry
.width
);
1678 geometry
.height
= luaA_getopt_number(L
, 2, "height", c
->geometry
.height
);
1681 client_resize(c
, geometry
, c
->size_hints_honor
);
1684 return luaA_pusharea(L
, c
->geometry
);
1688 luaA_client_set_screen(lua_State
*L
, client_t
*c
)
1690 screen_client_moveto(c
, luaA_checkscreen(L
, -1), true);
1695 luaA_client_set_hidden(lua_State
*L
, client_t
*c
)
1697 client_set_hidden(L
, -3, luaA_checkboolean(L
, -1));
1702 luaA_client_set_minimized(lua_State
*L
, client_t
*c
)
1704 client_set_minimized(L
, -3, luaA_checkboolean(L
, -1));
1709 luaA_client_set_fullscreen(lua_State
*L
, client_t
*c
)
1711 client_set_fullscreen(L
, -3, luaA_checkboolean(L
, -1));
1716 luaA_client_set_modal(lua_State
*L
, client_t
*c
)
1718 client_set_modal(L
, -3, luaA_checkboolean(L
, -1));
1723 luaA_client_set_maximized(lua_State
*L
, client_t
*c
)
1725 client_set_maximized(L
, -3, luaA_checkboolean(L
, -1));
1730 luaA_client_set_maximized_horizontal(lua_State
*L
, client_t
*c
)
1732 client_set_maximized_horizontal(L
, -3, luaA_checkboolean(L
, -1));
1737 luaA_client_set_maximized_vertical(lua_State
*L
, client_t
*c
)
1739 client_set_maximized_vertical(L
, -3, luaA_checkboolean(L
, -1));
1744 luaA_client_set_icon(lua_State
*L
, client_t
*c
)
1746 cairo_surface_t
*surf
= NULL
;
1747 if(!lua_isnil(L
, -1))
1748 surf
= (cairo_surface_t
*)lua_touserdata(L
, -1);
1749 client_set_icon(c
, surf
);
1754 luaA_client_set_sticky(lua_State
*L
, client_t
*c
)
1756 client_set_sticky(L
, -3, luaA_checkboolean(L
, -1));
1761 luaA_client_set_size_hints_honor(lua_State
*L
, client_t
*c
)
1763 c
->size_hints_honor
= luaA_checkboolean(L
, -1);
1764 luaA_object_emit_signal(L
, -3, "property::size_hints_honor", 0);
1769 luaA_client_set_ontop(lua_State
*L
, client_t
*c
)
1771 client_set_ontop(L
, -3, luaA_checkboolean(L
, -1));
1776 luaA_client_set_below(lua_State
*L
, client_t
*c
)
1778 client_set_below(L
, -3, luaA_checkboolean(L
, -1));
1783 luaA_client_set_above(lua_State
*L
, client_t
*c
)
1785 client_set_above(L
, -3, luaA_checkboolean(L
, -1));
1790 luaA_client_set_urgent(lua_State
*L
, client_t
*c
)
1792 client_set_urgent(L
, -3, luaA_checkboolean(L
, -1));
1797 luaA_client_set_skip_taskbar(lua_State
*L
, client_t
*c
)
1799 client_set_skip_taskbar(L
, -3, luaA_checkboolean(L
, -1));
1804 luaA_client_get_name(lua_State
*L
, client_t
*c
)
1806 lua_pushstring(L
, c
->name
? c
->name
: c
->alt_name
);
1811 luaA_client_get_icon_name(lua_State
*L
, client_t
*c
)
1813 lua_pushstring(L
, c
->icon_name
? c
->icon_name
: c
->alt_icon_name
);
1817 LUA_OBJECT_EXPORT_PROPERTY(client
, client_t
, class, lua_pushstring
)
1818 LUA_OBJECT_EXPORT_PROPERTY(client
, client_t
, instance
, lua_pushstring
)
1819 LUA_OBJECT_EXPORT_PROPERTY(client
, client_t
, machine
, lua_pushstring
)
1820 LUA_OBJECT_EXPORT_PROPERTY(client
, client_t
, role
, lua_pushstring
)
1821 LUA_OBJECT_EXPORT_PROPERTY(client
, client_t
, transient_for
, luaA_object_push
)
1822 LUA_OBJECT_EXPORT_PROPERTY(client
, client_t
, skip_taskbar
, lua_pushboolean
)
1823 LUA_OBJECT_EXPORT_PROPERTY(client
, client_t
, leader_window
, lua_pushnumber
)
1824 LUA_OBJECT_EXPORT_PROPERTY(client
, client_t
, group_window
, lua_pushnumber
)
1825 LUA_OBJECT_EXPORT_PROPERTY(client
, client_t
, pid
, lua_pushnumber
)
1826 LUA_OBJECT_EXPORT_PROPERTY(client
, client_t
, hidden
, lua_pushboolean
)
1827 LUA_OBJECT_EXPORT_PROPERTY(client
, client_t
, minimized
, lua_pushboolean
)
1828 LUA_OBJECT_EXPORT_PROPERTY(client
, client_t
, fullscreen
, lua_pushboolean
)
1829 LUA_OBJECT_EXPORT_PROPERTY(client
, client_t
, modal
, lua_pushboolean
)
1830 LUA_OBJECT_EXPORT_PROPERTY(client
, client_t
, ontop
, lua_pushboolean
)
1831 LUA_OBJECT_EXPORT_PROPERTY(client
, client_t
, urgent
, lua_pushboolean
)
1832 LUA_OBJECT_EXPORT_PROPERTY(client
, client_t
, above
, lua_pushboolean
)
1833 LUA_OBJECT_EXPORT_PROPERTY(client
, client_t
, below
, lua_pushboolean
)
1834 LUA_OBJECT_EXPORT_PROPERTY(client
, client_t
, sticky
, lua_pushboolean
)
1835 LUA_OBJECT_EXPORT_PROPERTY(client
, client_t
, size_hints_honor
, lua_pushboolean
)
1836 LUA_OBJECT_EXPORT_PROPERTY(client
, client_t
, maximized_horizontal
, lua_pushboolean
)
1837 LUA_OBJECT_EXPORT_PROPERTY(client
, client_t
, maximized_vertical
, lua_pushboolean
)
1838 LUA_OBJECT_EXPORT_PROPERTY(client
, client_t
, startup_id
, lua_pushstring
)
1841 luaA_client_get_maximized(lua_State
*L
, client_t
*c
)
1843 lua_pushboolean(L
, client_get_maximized(c
));
1848 luaA_client_get_content(lua_State
*L
, client_t
*c
)
1850 cairo_surface_t
*surface
;
1851 int width
= c
->geometry
.width
;
1852 int height
= c
->geometry
.height
;
1854 /* Just the client size without decorations */
1855 width
-= c
->titlebar
[CLIENT_TITLEBAR_LEFT
].size
+ c
->titlebar
[CLIENT_TITLEBAR_RIGHT
].size
;
1856 height
-= c
->titlebar
[CLIENT_TITLEBAR_TOP
].size
+ c
->titlebar
[CLIENT_TITLEBAR_BOTTOM
].size
;
1858 surface
= cairo_xcb_surface_create(globalconf
.connection
, c
->window
,
1859 c
->visualtype
, width
, height
);
1861 /* lua has to make sure to free the ref or we have a leak */
1862 lua_pushlightuserdata(L
, surface
);
1867 luaA_client_get_screen(lua_State
*L
, client_t
*c
)
1871 lua_pushnumber(L
, screen_get_index(c
->screen
));
1876 luaA_client_get_icon(lua_State
*L
, client_t
*c
)
1880 /* lua gets its own reference which it will have to destroy */
1881 lua_pushlightuserdata(L
, cairo_surface_reference(c
->icon
));
1886 luaA_client_get_focusable(lua_State
*L
, client_t
*c
)
1890 /* A client can be focused if it doesnt have the "nofocus" hint...*/
1894 /* ...or if it knows the WM_TAKE_FOCUS protocol */
1895 ret
= client_hasproto(c
, WM_TAKE_FOCUS
);
1897 lua_pushboolean(L
, ret
);
1902 luaA_client_get_size_hints(lua_State
*L
, client_t
*c
)
1904 const char *u_or_p
= NULL
;
1906 lua_createtable(L
, 0, 1);
1908 if(c
->size_hints
.flags
& XCB_ICCCM_SIZE_HINT_US_POSITION
)
1909 u_or_p
= "user_position";
1910 else if(c
->size_hints
.flags
& XCB_ICCCM_SIZE_HINT_P_POSITION
)
1911 u_or_p
= "program_position";
1915 lua_createtable(L
, 0, 2);
1916 lua_pushnumber(L
, c
->size_hints
.x
);
1917 lua_setfield(L
, -2, "x");
1918 lua_pushnumber(L
, c
->size_hints
.y
);
1919 lua_setfield(L
, -2, "y");
1920 lua_setfield(L
, -2, u_or_p
);
1924 if(c
->size_hints
.flags
& XCB_ICCCM_SIZE_HINT_US_SIZE
)
1925 u_or_p
= "user_size";
1926 else if(c
->size_hints
.flags
& XCB_ICCCM_SIZE_HINT_P_SIZE
)
1927 u_or_p
= "program_size";
1931 lua_createtable(L
, 0, 2);
1932 lua_pushnumber(L
, c
->size_hints
.width
);
1933 lua_setfield(L
, -2, "width");
1934 lua_pushnumber(L
, c
->size_hints
.height
);
1935 lua_setfield(L
, -2, "height");
1936 lua_setfield(L
, -2, u_or_p
);
1939 if(c
->size_hints
.flags
& XCB_ICCCM_SIZE_HINT_P_MIN_SIZE
)
1941 lua_pushnumber(L
, c
->size_hints
.min_width
);
1942 lua_setfield(L
, -2, "min_width");
1943 lua_pushnumber(L
, c
->size_hints
.min_height
);
1944 lua_setfield(L
, -2, "min_height");
1947 if(c
->size_hints
.flags
& XCB_ICCCM_SIZE_HINT_P_MAX_SIZE
)
1949 lua_pushnumber(L
, c
->size_hints
.max_width
);
1950 lua_setfield(L
, -2, "max_width");
1951 lua_pushnumber(L
, c
->size_hints
.max_height
);
1952 lua_setfield(L
, -2, "max_height");
1955 if(c
->size_hints
.flags
& XCB_ICCCM_SIZE_HINT_P_RESIZE_INC
)
1957 lua_pushnumber(L
, c
->size_hints
.width_inc
);
1958 lua_setfield(L
, -2, "width_inc");
1959 lua_pushnumber(L
, c
->size_hints
.height_inc
);
1960 lua_setfield(L
, -2, "height_inc");
1963 if(c
->size_hints
.flags
& XCB_ICCCM_SIZE_HINT_P_ASPECT
)
1965 lua_pushnumber(L
, c
->size_hints
.min_aspect_num
);
1966 lua_setfield(L
, -2, "min_aspect_num");
1967 lua_pushnumber(L
, c
->size_hints
.min_aspect_den
);
1968 lua_setfield(L
, -2, "min_aspect_den");
1969 lua_pushnumber(L
, c
->size_hints
.max_aspect_num
);
1970 lua_setfield(L
, -2, "max_aspect_num");
1971 lua_pushnumber(L
, c
->size_hints
.max_aspect_den
);
1972 lua_setfield(L
, -2, "max_aspect_den");
1975 if(c
->size_hints
.flags
& XCB_ICCCM_SIZE_HINT_BASE_SIZE
)
1977 lua_pushnumber(L
, c
->size_hints
.base_width
);
1978 lua_setfield(L
, -2, "base_width");
1979 lua_pushnumber(L
, c
->size_hints
.base_height
);
1980 lua_setfield(L
, -2, "base_height");
1983 if(c
->size_hints
.flags
& XCB_ICCCM_SIZE_HINT_P_WIN_GRAVITY
)
1985 switch(c
->size_hints
.win_gravity
)
1988 lua_pushliteral(L
, "north_west");
1990 case XCB_GRAVITY_NORTH
:
1991 lua_pushliteral(L
, "north");
1993 case XCB_GRAVITY_NORTH_EAST
:
1994 lua_pushliteral(L
, "north_east");
1996 case XCB_GRAVITY_WEST
:
1997 lua_pushliteral(L
, "west");
1999 case XCB_GRAVITY_CENTER
:
2000 lua_pushliteral(L
, "center");
2002 case XCB_GRAVITY_EAST
:
2003 lua_pushliteral(L
, "east");
2005 case XCB_GRAVITY_SOUTH_WEST
:
2006 lua_pushliteral(L
, "south_west");
2008 case XCB_GRAVITY_SOUTH
:
2009 lua_pushliteral(L
, "south");
2011 case XCB_GRAVITY_SOUTH_EAST
:
2012 lua_pushliteral(L
, "south_east");
2014 case XCB_GRAVITY_STATIC
:
2015 lua_pushliteral(L
, "static");
2018 lua_setfield(L
, -2, "win_gravity");
2024 /** Get the client's child window bounding shape.
2025 * \param L The Lua VM state.
2026 * \param client The client object.
2027 * \return The number of elements pushed on stack.
2030 luaA_client_get_client_shape_bounding(lua_State
*L
, client_t
*c
)
2032 cairo_surface_t
*surf
= xwindow_get_shape(c
->window
, XCB_SHAPE_SK_BOUNDING
);
2035 /* lua has to make sure to free the ref or we have a leak */
2036 lua_pushlightuserdata(L
, surf
);
2040 /** Get the client's frame window bounding shape.
2041 * \param L The Lua VM state.
2042 * \param client The client object.
2043 * \return The number of elements pushed on stack.
2046 luaA_client_get_shape_bounding(lua_State
*L
, client_t
*c
)
2048 cairo_surface_t
*surf
= xwindow_get_shape(c
->frame_window
, XCB_SHAPE_SK_BOUNDING
);
2051 /* lua has to make sure to free the ref or we have a leak */
2052 lua_pushlightuserdata(L
, surf
);
2056 /** Set the client's frame window bounding shape.
2057 * \param L The Lua VM state.
2058 * \param client The client object.
2059 * \return The number of elements pushed on stack.
2062 luaA_client_set_shape_bounding(lua_State
*L
, client_t
*c
)
2064 cairo_surface_t
*surf
= NULL
;
2065 if(!lua_isnil(L
, -1))
2066 surf
= (cairo_surface_t
*)lua_touserdata(L
, -1);
2067 xwindow_set_shape(c
->frame_window
,
2068 c
->geometry
.width
+ (c
->border_width
* 2),
2069 c
->geometry
.height
+ (c
->border_width
* 2),
2070 XCB_SHAPE_SK_BOUNDING
, surf
, -c
->border_width
);
2071 luaA_object_emit_signal(L
, -3, "property::shape_bounding", 0);
2075 /** Get the client's child window clip shape.
2076 * \param L The Lua VM state.
2077 * \param client The client object.
2078 * \return The number of elements pushed on stack.
2081 luaA_client_get_client_shape_clip(lua_State
*L
, client_t
*c
)
2083 cairo_surface_t
*surf
= xwindow_get_shape(c
->window
, XCB_SHAPE_SK_CLIP
);
2086 /* lua has to make sure to free the ref or we have a leak */
2087 lua_pushlightuserdata(L
, surf
);
2091 /** Get the client's frame window clip shape.
2092 * \param L The Lua VM state.
2093 * \param client The client object.
2094 * \return The number of elements pushed on stack.
2097 luaA_client_get_shape_clip(lua_State
*L
, client_t
*c
)
2099 cairo_surface_t
*surf
= xwindow_get_shape(c
->frame_window
, XCB_SHAPE_SK_CLIP
);
2102 /* lua has to make sure to free the ref or we have a leak */
2103 lua_pushlightuserdata(L
, surf
);
2107 /** Set the client's frame window clip shape.
2108 * \param L The Lua VM state.
2109 * \param client The client object.
2110 * \return The number of elements pushed on stack.
2113 luaA_client_set_shape_clip(lua_State
*L
, client_t
*c
)
2115 cairo_surface_t
*surf
= NULL
;
2116 if(!lua_isnil(L
, -1))
2117 surf
= (cairo_surface_t
*)lua_touserdata(L
, -1);
2118 xwindow_set_shape(c
->frame_window
, c
->geometry
.width
, c
->geometry
.height
,
2119 XCB_SHAPE_SK_CLIP
, surf
, 0);
2120 luaA_object_emit_signal(L
, -3, "property::shape_clip", 0);
2124 /** Get or set keys bindings for a client.
2125 * \param L The Lua VM state.
2126 * \return The number of element pushed on stack.
2129 * \lparam An array of key bindings objects, or nothing.
2130 * \return The array of key bindings objects of this client.
2133 luaA_client_keys(lua_State
*L
)
2135 client_t
*c
= luaA_checkudata(L
, 1, &client_class
);
2136 key_array_t
*keys
= &c
->keys
;
2138 if(lua_gettop(L
) == 2)
2140 luaA_key_array_set(L
, 1, 2, keys
);
2141 luaA_object_emit_signal(L
, 1, "property::keys", 0);
2142 xcb_ungrab_key(globalconf
.connection
, XCB_GRAB_ANY
, c
->frame_window
, XCB_BUTTON_MASK_ANY
);
2143 xwindow_grabkeys(c
->frame_window
, keys
);
2146 return luaA_key_array_get(L
, 1, keys
);
2150 * \param L The Lua VM state.
2151 * \return The number of pushed elements.
2154 luaA_client_module_index(lua_State
*L
)
2156 const char *buf
= luaL_checkstring(L
, 2);
2158 if (A_STREQ(buf
, "focus"))
2159 return luaA_object_push(globalconf
.L
, globalconf
.focus
.client
);
2163 /* Client module new index.
2164 * \param L The Lua VM state.
2165 * \return The number of pushed elements.
2168 luaA_client_module_newindex(lua_State
*L
)
2170 const char *buf
= luaL_checkstring(L
, 2);
2173 if (A_STREQ(buf
, "focus"))
2175 c
= luaA_checkudata(L
, 3, &client_class
);
2183 client_checker(client_t
*c
)
2185 return c
->window
!= XCB_NONE
;
2189 client_class_setup(lua_State
*L
)
2191 static const struct luaL_Reg client_methods
[] =
2193 LUA_CLASS_METHODS(client
)
2194 { "get", luaA_client_get
},
2195 { "__index", luaA_client_module_index
},
2196 { "__newindex", luaA_client_module_newindex
},
2200 static const struct luaL_Reg client_meta
[] =
2202 LUA_OBJECT_META(client
)
2204 { "keys", luaA_client_keys
},
2205 { "isvisible", luaA_client_isvisible
},
2206 { "geometry", luaA_client_geometry
},
2207 { "tags", luaA_client_tags
},
2208 { "kill", luaA_client_kill
},
2209 { "swap", luaA_client_swap
},
2210 { "raise", luaA_client_raise
},
2211 { "lower", luaA_client_lower
},
2212 { "unmanage", luaA_client_unmanage
},
2213 { "titlebar_top", luaA_client_titlebar_top
},
2214 { "titlebar_right", luaA_client_titlebar_right
},
2215 { "titlebar_bottom", luaA_client_titlebar_bottom
},
2216 { "titlebar_left", luaA_client_titlebar_left
},
2220 luaA_class_setup(L
, &client_class
, "client", &window_class
,
2221 (lua_class_allocator_t
) client_new
,
2222 (lua_class_collector_t
) client_wipe
,
2223 (lua_class_checker_t
) client_checker
,
2224 luaA_class_index_miss_property
, luaA_class_newindex_miss_property
,
2225 client_methods
, client_meta
);
2226 luaA_class_add_property(&client_class
, "name",
2228 (lua_class_propfunc_t
) luaA_client_get_name
,
2230 luaA_class_add_property(&client_class
, "transient_for",
2232 (lua_class_propfunc_t
) luaA_client_get_transient_for
,
2234 luaA_class_add_property(&client_class
, "skip_taskbar",
2235 (lua_class_propfunc_t
) luaA_client_set_skip_taskbar
,
2236 (lua_class_propfunc_t
) luaA_client_get_skip_taskbar
,
2237 (lua_class_propfunc_t
) luaA_client_set_skip_taskbar
);
2238 luaA_class_add_property(&client_class
, "content",
2240 (lua_class_propfunc_t
) luaA_client_get_content
,
2242 luaA_class_add_property(&client_class
, "type",
2244 (lua_class_propfunc_t
) luaA_window_get_type
,
2246 luaA_class_add_property(&client_class
, "class",
2248 (lua_class_propfunc_t
) luaA_client_get_class
,
2250 luaA_class_add_property(&client_class
, "instance",
2252 (lua_class_propfunc_t
) luaA_client_get_instance
,
2254 luaA_class_add_property(&client_class
, "role",
2256 (lua_class_propfunc_t
) luaA_client_get_role
,
2258 luaA_class_add_property(&client_class
, "pid",
2260 (lua_class_propfunc_t
) luaA_client_get_pid
,
2262 luaA_class_add_property(&client_class
, "leader_window",
2264 (lua_class_propfunc_t
) luaA_client_get_leader_window
,
2266 luaA_class_add_property(&client_class
, "machine",
2268 (lua_class_propfunc_t
) luaA_client_get_machine
,
2270 luaA_class_add_property(&client_class
, "icon_name",
2272 (lua_class_propfunc_t
) luaA_client_get_icon_name
,
2274 luaA_class_add_property(&client_class
, "screen",
2276 (lua_class_propfunc_t
) luaA_client_get_screen
,
2277 (lua_class_propfunc_t
) luaA_client_set_screen
);
2278 luaA_class_add_property(&client_class
, "hidden",
2279 (lua_class_propfunc_t
) luaA_client_set_hidden
,
2280 (lua_class_propfunc_t
) luaA_client_get_hidden
,
2281 (lua_class_propfunc_t
) luaA_client_set_hidden
);
2282 luaA_class_add_property(&client_class
, "minimized",
2283 (lua_class_propfunc_t
) luaA_client_set_minimized
,
2284 (lua_class_propfunc_t
) luaA_client_get_minimized
,
2285 (lua_class_propfunc_t
) luaA_client_set_minimized
);
2286 luaA_class_add_property(&client_class
, "fullscreen",
2287 (lua_class_propfunc_t
) luaA_client_set_fullscreen
,
2288 (lua_class_propfunc_t
) luaA_client_get_fullscreen
,
2289 (lua_class_propfunc_t
) luaA_client_set_fullscreen
);
2290 luaA_class_add_property(&client_class
, "modal",
2291 (lua_class_propfunc_t
) luaA_client_set_modal
,
2292 (lua_class_propfunc_t
) luaA_client_get_modal
,
2293 (lua_class_propfunc_t
) luaA_client_set_modal
);
2294 luaA_class_add_property(&client_class
, "group_window",
2296 (lua_class_propfunc_t
) luaA_client_get_group_window
,
2298 luaA_class_add_property(&client_class
, "maximized",
2299 (lua_class_propfunc_t
) luaA_client_set_maximized
,
2300 (lua_class_propfunc_t
) luaA_client_get_maximized
,
2301 (lua_class_propfunc_t
) luaA_client_set_maximized
);
2302 luaA_class_add_property(&client_class
, "maximized_horizontal",
2303 (lua_class_propfunc_t
) luaA_client_set_maximized_horizontal
,
2304 (lua_class_propfunc_t
) luaA_client_get_maximized_horizontal
,
2305 (lua_class_propfunc_t
) luaA_client_set_maximized_horizontal
);
2306 luaA_class_add_property(&client_class
, "maximized_vertical",
2307 (lua_class_propfunc_t
) luaA_client_set_maximized_vertical
,
2308 (lua_class_propfunc_t
) luaA_client_get_maximized_vertical
,
2309 (lua_class_propfunc_t
) luaA_client_set_maximized_vertical
);
2310 luaA_class_add_property(&client_class
, "icon",
2311 (lua_class_propfunc_t
) luaA_client_set_icon
,
2312 (lua_class_propfunc_t
) luaA_client_get_icon
,
2313 (lua_class_propfunc_t
) luaA_client_set_icon
);
2314 luaA_class_add_property(&client_class
, "ontop",
2315 (lua_class_propfunc_t
) luaA_client_set_ontop
,
2316 (lua_class_propfunc_t
) luaA_client_get_ontop
,
2317 (lua_class_propfunc_t
) luaA_client_set_ontop
);
2318 luaA_class_add_property(&client_class
, "above",
2319 (lua_class_propfunc_t
) luaA_client_set_above
,
2320 (lua_class_propfunc_t
) luaA_client_get_above
,
2321 (lua_class_propfunc_t
) luaA_client_set_above
);
2322 luaA_class_add_property(&client_class
, "below",
2323 (lua_class_propfunc_t
) luaA_client_set_below
,
2324 (lua_class_propfunc_t
) luaA_client_get_below
,
2325 (lua_class_propfunc_t
) luaA_client_set_below
);
2326 luaA_class_add_property(&client_class
, "sticky",
2327 (lua_class_propfunc_t
) luaA_client_set_sticky
,
2328 (lua_class_propfunc_t
) luaA_client_get_sticky
,
2329 (lua_class_propfunc_t
) luaA_client_set_sticky
);
2330 luaA_class_add_property(&client_class
, "size_hints_honor",
2331 (lua_class_propfunc_t
) luaA_client_set_size_hints_honor
,
2332 (lua_class_propfunc_t
) luaA_client_get_size_hints_honor
,
2333 (lua_class_propfunc_t
) luaA_client_set_size_hints_honor
);
2334 luaA_class_add_property(&client_class
, "urgent",
2335 (lua_class_propfunc_t
) luaA_client_set_urgent
,
2336 (lua_class_propfunc_t
) luaA_client_get_urgent
,
2337 (lua_class_propfunc_t
) luaA_client_set_urgent
);
2338 luaA_class_add_property(&client_class
, "size_hints",
2340 (lua_class_propfunc_t
) luaA_client_get_size_hints
,
2342 luaA_class_add_property(&client_class
, "focusable",
2344 (lua_class_propfunc_t
) luaA_client_get_focusable
,
2346 luaA_class_add_property(&client_class
, "shape_bounding",
2347 (lua_class_propfunc_t
) luaA_client_set_shape_bounding
,
2348 (lua_class_propfunc_t
) luaA_client_get_shape_bounding
,
2349 (lua_class_propfunc_t
) luaA_client_set_shape_bounding
);
2350 luaA_class_add_property(&client_class
, "shape_clip",
2351 (lua_class_propfunc_t
) luaA_client_set_shape_clip
,
2352 (lua_class_propfunc_t
) luaA_client_get_shape_clip
,
2353 (lua_class_propfunc_t
) luaA_client_set_shape_clip
);
2354 luaA_class_add_property(&client_class
, "startup_id",
2356 (lua_class_propfunc_t
) luaA_client_get_startup_id
,
2358 luaA_class_add_property(&client_class
, "client_shape_bounding",
2360 (lua_class_propfunc_t
) luaA_client_get_client_shape_bounding
,
2362 luaA_class_add_property(&client_class
, "client_shape_clip",
2364 (lua_class_propfunc_t
) luaA_client_get_client_shape_clip
,
2367 signal_add(&client_class
.signals
, "focus");
2368 signal_add(&client_class
.signals
, "list");
2369 signal_add(&client_class
.signals
, "manage");
2370 signal_add(&client_class
.signals
, "button::press");
2371 signal_add(&client_class
.signals
, "button::release");
2372 signal_add(&client_class
.signals
, "mouse::enter");
2373 signal_add(&client_class
.signals
, "mouse::leave");
2374 signal_add(&client_class
.signals
, "mouse::move");
2375 signal_add(&client_class
.signals
, "property::above");
2376 signal_add(&client_class
.signals
, "property::below");
2377 signal_add(&client_class
.signals
, "property::class");
2378 signal_add(&client_class
.signals
, "property::fullscreen");
2379 signal_add(&client_class
.signals
, "property::geometry");
2380 signal_add(&client_class
.signals
, "property::group_window");
2381 signal_add(&client_class
.signals
, "property::height");
2382 signal_add(&client_class
.signals
, "property::hidden");
2383 signal_add(&client_class
.signals
, "property::icon");
2384 signal_add(&client_class
.signals
, "property::icon_name");
2385 signal_add(&client_class
.signals
, "property::instance");
2386 signal_add(&client_class
.signals
, "property::keys");
2387 signal_add(&client_class
.signals
, "property::machine");
2388 signal_add(&client_class
.signals
, "property::maximized");
2389 signal_add(&client_class
.signals
, "property::maximized_horizontal");
2390 signal_add(&client_class
.signals
, "property::maximized_vertical");
2391 signal_add(&client_class
.signals
, "property::minimized");
2392 signal_add(&client_class
.signals
, "property::modal");
2393 signal_add(&client_class
.signals
, "property::name");
2394 signal_add(&client_class
.signals
, "property::ontop");
2395 signal_add(&client_class
.signals
, "property::pid");
2396 signal_add(&client_class
.signals
, "property::role");
2397 signal_add(&client_class
.signals
, "property::screen");
2398 signal_add(&client_class
.signals
, "property::shape_bounding");
2399 signal_add(&client_class
.signals
, "property::shape_client_bounding");
2400 signal_add(&client_class
.signals
, "property::shape_client_clip");
2401 signal_add(&client_class
.signals
, "property::shape_clip");
2402 signal_add(&client_class
.signals
, "property::size_hints_honor");
2403 signal_add(&client_class
.signals
, "property::skip_taskbar");
2404 signal_add(&client_class
.signals
, "property::sticky");
2405 signal_add(&client_class
.signals
, "property::struts");
2406 signal_add(&client_class
.signals
, "property::titlebar_bottom");
2407 signal_add(&client_class
.signals
, "property::titlebar_left");
2408 signal_add(&client_class
.signals
, "property::titlebar_right");
2409 signal_add(&client_class
.signals
, "property::titlebar_top");
2410 signal_add(&client_class
.signals
, "property::transient_for");
2411 signal_add(&client_class
.signals
, "property::type");
2412 signal_add(&client_class
.signals
, "property::urgent");
2413 signal_add(&client_class
.signals
, "property::width");
2414 signal_add(&client_class
.signals
, "property::window");
2415 signal_add(&client_class
.signals
, "property::x");
2416 signal_add(&client_class
.signals
, "property::y");
2417 signal_add(&client_class
.signals
, "request::activate");
2418 signal_add(&client_class
.signals
, "request::fullscreen");
2419 signal_add(&client_class
.signals
, "request::maximized_horizontal");
2420 signal_add(&client_class
.signals
, "request::maximized_vertical");
2421 signal_add(&client_class
.signals
, "request::tag");
2422 signal_add(&client_class
.signals
, "tagged");
2423 signal_add(&client_class
.signals
, "unfocus");
2424 signal_add(&client_class
.signals
, "unmanage");
2425 signal_add(&client_class
.signals
, "untagged");
2428 // vim: filetype=c:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:textwidth=80