cnode: move struct to cnode header
[awesome.git] / client.c
blobb3284351eb46444e149e73c3fd096fdb98fc1fb9
1 /*
2 * client.c - client management
4 * Copyright © 2007-2008 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 <stdio.h>
24 #include <xcb/xcb.h>
25 #include <xcb/xcb_atom.h>
27 #include "cnode.h"
28 #include "image.h"
29 #include "client.h"
30 #include "tag.h"
31 #include "window.h"
32 #include "ewmh.h"
33 #include "widget.h"
34 #include "screen.h"
35 #include "titlebar.h"
36 #include "luaa.h"
37 #include "mouse.h"
38 #include "systray.h"
39 #include "wibox.h"
40 #include "property.h"
41 #include "layouts/floating.h"
42 #include "common/markup.h"
43 #include "common/atoms.h"
45 extern awesome_t globalconf;
47 /** Create a new client userdata.
48 * \param L The Lua VM state.
49 * \param p A client pointer.
50 * \param The number of elements pushed on the stack.
52 int
53 luaA_client_userdata_new(lua_State *L, client_t *p)
55 client_t **pp = lua_newuserdata(L, sizeof(client_t *));
56 *pp = p;
57 client_ref(pp);
58 return luaA_settype(L, "client");
61 DO_LUA_EQ(client_t, client, "client")
62 DO_LUA_GC(client_t, client, "client", client_unref)
64 /** Load windows properties, restoring client's tag
65 * and floating state before awesome was restarted if any.
66 * \param c A client pointer.
67 * \param screen A virtual screen.
68 * \return True if client had property, false otherwise.
70 static bool
71 client_loadprops(client_t * c, screen_t *screen)
73 ssize_t len;
74 tag_array_t *tags = &screen->tags;
75 char *prop = NULL;
76 xcb_get_property_cookie_t floating_q, fullscreen_q;
77 xcb_get_property_reply_t *reply;
78 void *data;
80 if(!xutil_text_prop_get(globalconf.connection, c->win, _AWESOME_TAGS,
81 &prop, &len))
82 return false;
84 /* Send the GetProperty requests which will be processed later */
85 floating_q = xcb_get_property_unchecked(globalconf.connection, false, c->win,
86 _AWESOME_FLOATING, CARDINAL, 0, 1);
88 fullscreen_q = xcb_get_property_unchecked(globalconf.connection, false, c->win,
89 _AWESOME_FULLSCREEN, CARDINAL, 0, 1);
91 /* ignore property if the tag count isn't matching */
92 if(len == tags->len)
93 for(int i = 0; i < tags->len; i++)
94 if(prop[i] == '1')
95 tag_client(c, tags->tab[i]);
96 else
97 untag_client(c, tags->tab[i]);
99 p_delete(&prop);
101 /* check for floating */
102 reply = xcb_get_property_reply(globalconf.connection, floating_q, NULL);
104 if(reply && reply->value_len && (data = xcb_get_property_value(reply)))
105 client_setfloating(c, *(bool *) data);
106 p_delete(&reply);
108 /* check for fullscreen */
109 reply = xcb_get_property_reply(globalconf.connection, fullscreen_q, NULL);
111 if(reply && reply->value_len && (data = xcb_get_property_value(reply)))
112 client_setfullscreen(c, *(bool *) data);
113 p_delete(&reply);
115 return true;
118 /** Check if client supports protocol a protocole in WM_PROTOCOL.
119 * \param win The window.
120 * \return True if client has the atom in protocol, false otherwise.
122 static bool
123 window_hasproto(xcb_window_t win, xcb_atom_t atom)
125 uint32_t i;
126 xcb_get_wm_protocols_reply_t protocols;
127 bool ret = false;
129 if(xcb_get_wm_protocols_reply(globalconf.connection,
130 xcb_get_wm_protocols_unchecked(globalconf.connection,
131 win, WM_PROTOCOLS),
132 &protocols, NULL))
134 for(i = 0; !ret && i < protocols.atoms_len; i++)
135 if(protocols.atoms[i] == atom)
136 ret = true;
137 xcb_get_wm_protocols_reply_wipe(&protocols);
139 return ret;
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 number.
146 * \return true if the client is visible, false otherwise.
148 bool
149 client_maybevisible(client_t *c, int screen)
151 if(c->screen == screen)
153 if(c->issticky || c->type == WINDOW_TYPE_DESKTOP)
154 return true;
156 tag_array_t *tags = &globalconf.screens[screen].tags;
158 for(int i = 0; i < tags->len; i++)
159 if(tags->tab[i]->selected && is_client_tagged(c, tags->tab[i]))
160 return true;
162 return false;
165 /** Get a client by its window.
166 * \param w The client window to find.
167 * \return A client pointer if found, NULL otherwise.
169 client_t *
170 client_getbywin(xcb_window_t w)
172 client_t *c;
173 for(c = globalconf.clients; c && c->win != w; c = c->next);
174 return c;
177 /** Unfocus a client.
178 * \param c The client.
180 static void
181 client_unfocus(client_t *c)
183 globalconf.screens[c->phys_screen].client_focus = NULL;
185 /* Call hook */
186 luaA_client_userdata_new(globalconf.L, c);
187 luaA_dofunction(globalconf.L, globalconf.hooks.unfocus, 1, 0);
189 ewmh_update_net_active_window(c->phys_screen);
192 /** Ban client and unmap it.
193 * \param c The client.
195 void
196 client_ban(client_t *c)
198 if(globalconf.screen_focus->client_focus == c)
199 client_unfocus(c);
200 xcb_unmap_window(globalconf.connection, c->win);
201 if(c->ishidden)
202 window_state_set(c->win, XCB_WM_STATE_ICONIC);
203 else
204 window_state_set(c->win, XCB_WM_STATE_WITHDRAWN);
205 if(c->titlebar)
206 xcb_unmap_window(globalconf.connection, c->titlebar->sw.window);
209 /** Give focus to client, or to first client if client is NULL.
210 * \param c The client or NULL.
211 * \return True if a window (even root) has received focus, false otherwise.
213 static void
214 client_focus(client_t *c)
216 if(!client_maybevisible(c, c->screen) || c->nofocus)
217 return;
219 /* unfocus current selected client */
220 if(globalconf.screen_focus->client_focus
221 && c != globalconf.screen_focus->client_focus)
222 client_unfocus(globalconf.screen_focus->client_focus);
224 /* stop hiding c */
225 c->ishidden = false;
226 client_setminimized(c, false);
228 /* unban the client before focusing or it will fail */
229 client_unban(c);
231 globalconf.screen_focus = &globalconf.screens[c->phys_screen];
232 globalconf.screen_focus->client_focus = c;
234 xcb_set_input_focus(globalconf.connection, XCB_INPUT_FOCUS_POINTER_ROOT,
235 c->win, XCB_CURRENT_TIME);
237 /* Some layouts use focused client differently, so call them back.
238 * And anyway, we have maybe unhidden */
239 client_need_arrange(c);
241 /* execute hook */
242 luaA_client_userdata_new(globalconf.L, globalconf.screen_focus->client_focus);
243 luaA_dofunction(globalconf.L, globalconf.hooks.focus, 1, 0);
245 ewmh_update_net_active_window(c->phys_screen);
248 /** Stack a window below.
249 * \param c The client.
250 * \param previous The previous window on the stack.
251 * \param return The next-previous!
253 static xcb_window_t
254 client_stack_below(client_t *c, xcb_window_t previous)
256 uint32_t config_win_vals[2];
258 config_win_vals[0] = previous;
259 config_win_vals[1] = XCB_STACK_MODE_BELOW;
261 if(c->titlebar)
263 xcb_configure_window(globalconf.connection,
264 c->titlebar->sw.window,
265 XCB_CONFIG_WINDOW_SIBLING | XCB_CONFIG_WINDOW_STACK_MODE,
266 config_win_vals);
267 config_win_vals[0] = c->titlebar->sw.window;
269 xcb_configure_window(globalconf.connection, c->win,
270 XCB_CONFIG_WINDOW_SIBLING | XCB_CONFIG_WINDOW_STACK_MODE,
271 config_win_vals);
272 config_win_vals[0] = c->win;
274 return c->win;
277 /** Stacking layout layers */
278 typedef enum
280 LAYER_DESKTOP = 1,
281 LAYER_BELOW,
282 LAYER_TILE,
283 LAYER_FLOAT,
284 LAYER_ABOVE,
285 LAYER_FULLSCREEN,
286 LAYER_MODAL,
287 LAYER_ONTOP,
288 LAYER_OUTOFSPACE
289 } layer_t;
291 /** Get the real layer of a client according to its attribute (fullscreen, …)
292 * \param c The client.
293 * \return The real layer.
295 static layer_t
296 client_layer_translator(client_t *c)
298 if(c->isontop)
299 return LAYER_ONTOP;
300 else if(c->ismodal)
301 return LAYER_MODAL;
302 else if(c->isfullscreen)
303 return LAYER_FULLSCREEN;
304 else if(c->isabove)
305 return LAYER_ABOVE;
306 else if(c->isfloating)
307 return LAYER_FLOAT;
309 switch(c->type)
311 case WINDOW_TYPE_DOCK:
312 return LAYER_ABOVE;
313 case WINDOW_TYPE_SPLASH:
314 case WINDOW_TYPE_DIALOG:
315 return LAYER_MODAL;
316 case WINDOW_TYPE_DESKTOP:
317 return LAYER_DESKTOP;
318 default:
319 return LAYER_TILE;
323 /** Restack clients.
324 * \todo It might be worth stopping to restack everyone and only stack `c'
325 * relatively to the first matching in the list.
327 void
328 client_stack()
330 uint32_t config_win_vals[2];
331 client_node_t *node;
332 layer_t layer;
333 int screen;
335 config_win_vals[0] = XCB_NONE;
336 config_win_vals[1] = XCB_STACK_MODE_BELOW;
338 /* first stack modal and fullscreen windows */
339 for(layer = LAYER_OUTOFSPACE - 1; layer >= LAYER_FULLSCREEN; layer--)
340 for(node = globalconf.stack; node; node = node->next)
341 if(client_layer_translator(node->client) == layer)
342 config_win_vals[0] = client_stack_below(node->client, config_win_vals[0]);
344 /* then stack ontop wibox window */
345 for(screen = 0; screen < globalconf.nscreen; screen++)
346 for(int i = 0; i < globalconf.screens[screen].wiboxes.len; i++)
348 wibox_t *sb = globalconf.screens[screen].wiboxes.tab[i];
349 if(sb->ontop)
351 xcb_configure_window(globalconf.connection,
352 sb->sw.window,
353 XCB_CONFIG_WINDOW_SIBLING | XCB_CONFIG_WINDOW_STACK_MODE,
354 config_win_vals);
355 config_win_vals[0] = sb->sw.window;
359 /* finally stack everything else */
360 for(layer = LAYER_FULLSCREEN - 1; layer >= LAYER_TILE; layer--)
361 for(node = globalconf.stack; node; node = node->next)
362 if(client_layer_translator(node->client) == layer)
363 config_win_vals[0] = client_stack_below(node->client, config_win_vals[0]);
365 /* then stack not ontop wibox window */
366 for(screen = 0; screen < globalconf.nscreen; screen++)
367 for(int i = 0; i < globalconf.screens[screen].wiboxes.len; i++)
369 wibox_t *sb = globalconf.screens[screen].wiboxes.tab[i];
370 if(!sb->ontop)
372 xcb_configure_window(globalconf.connection,
373 sb->sw.window,
374 XCB_CONFIG_WINDOW_SIBLING | XCB_CONFIG_WINDOW_STACK_MODE,
375 config_win_vals);
376 config_win_vals[0] = sb->sw.window;
380 /* finally stack everything else */
381 for(layer = LAYER_TILE - 1; layer >= LAYER_DESKTOP; layer--)
382 for(node = globalconf.stack; node; node = node->next)
383 if(client_layer_translator(node->client) == layer)
384 config_win_vals[0] = client_stack_below(node->client, config_win_vals[0]);
387 /** Manage a new client.
388 * \param w The window.
389 * \param wgeom Window geometry.
390 * \param phys_screen Physical screen number.
391 * \param screen Virtual screen number where to manage client.
393 void
394 client_manage(xcb_window_t w, xcb_get_geometry_reply_t *wgeom, int phys_screen, int screen)
396 xcb_get_property_cookie_t ewmh_icon_cookie;
397 client_t *c;
398 image_t *icon;
399 const uint32_t select_input_val[] =
401 XCB_EVENT_MASK_STRUCTURE_NOTIFY
402 | XCB_EVENT_MASK_PROPERTY_CHANGE
403 | XCB_EVENT_MASK_ENTER_WINDOW
406 /* Send request to get NET_WM_ICON property as soon as possible... */
407 ewmh_icon_cookie = ewmh_window_icon_get_unchecked(w);
408 xcb_change_window_attributes(globalconf.connection, w, XCB_CW_EVENT_MASK, select_input_val);
410 if(systray_iskdedockapp(w))
412 systray_request_handle(w, phys_screen, NULL);
413 return;
416 c = p_new(client_t, 1);
418 c->screen = screen_getbycoord(screen, wgeom->x, wgeom->y);
420 c->phys_screen = phys_screen;
422 /* Initial values */
423 c->win = w;
424 c->geometry.x = c->f_geometry.x = c->m_geometry.x = wgeom->x;
425 c->geometry.y = c->f_geometry.y = c->m_geometry.y = wgeom->y;
426 c->geometry.width = c->f_geometry.width = c->m_geometry.width = wgeom->width;
427 c->geometry.height = c->f_geometry.height = c->m_geometry.height = wgeom->height;
428 client_setborder(c, wgeom->border_width);
429 if((icon = ewmh_window_icon_get_reply(ewmh_icon_cookie)))
430 c->icon = image_ref(&icon);
432 /* we honor size hints by default */
433 c->honorsizehints = true;
435 /* update hints */
436 property_update_wm_normal_hints(c, NULL);
437 property_update_wm_hints(c, NULL);
438 property_update_wm_transient_for(c, NULL);
440 if(c->transient_for)
441 screen = c->transient_for->screen;
443 /* Try to load props if any */
444 client_loadprops(c, &globalconf.screens[screen]);
446 /* move client to screen, but do not tag it for now */
447 screen_client_moveto(c, screen, false, true);
449 /* Then check clients hints */
450 ewmh_client_check_hints(c);
452 /* Check if client has been tagged by loading props, or maybe with its
453 * hints.
454 * If not, we tag it with current selected ones.
455 * This could be done on Lua side, but it's a sane behaviour. */
456 if(!c->issticky)
458 int i;
459 tag_array_t *tags = &globalconf.screens[screen].tags;
460 for(i = 0; i < tags->len; i++)
461 if(is_client_tagged(c, tags->tab[i]))
462 break;
464 /* if no tag, set current selected */
465 if(i == tags->len)
466 for(i = 0; i < tags->len; i++)
467 if(tags->tab[i]->selected)
468 tag_client(c, tags->tab[i]);
471 /* Push client in client list */
472 client_list_push(&globalconf.clients, client_ref(&c));
474 /* Push client in stack */
475 client_raise(c);
477 /* update window title */
478 property_update_wm_name(c);
479 property_update_wm_icon_name(c);
481 /* update strut */
482 ewmh_client_strut_update(c, NULL);
484 ewmh_update_net_client_list(c->phys_screen);
486 /* Call hook to notify list change */
487 luaA_dofunction(globalconf.L, globalconf.hooks.clients, 0, 0);
489 /* call hook */
490 luaA_client_userdata_new(globalconf.L, c);
491 luaA_dofunction(globalconf.L, globalconf.hooks.manage, 1, 0);
494 /** Compute client geometry with respect to its geometry hints.
495 * \param c The client.
496 * \param geometry The geometry that the client might receive.
497 * \return The geometry the client must take respecting its hints.
499 area_t
500 client_geometry_hints(client_t *c, area_t geometry)
502 double dx, dy, max, min, ratio;
504 if(c->minay > 0 && c->maxay > 0 && (geometry.height - c->baseh) > 0
505 && (geometry.width - c->basew) > 0)
507 dx = (double) (geometry.width - c->basew);
508 dy = (double) (geometry.height - c->baseh);
509 min = (double) (c->minax) / (double) (c->minay);
510 max = (double) (c->maxax) / (double) (c->maxay);
511 ratio = dx / dy;
512 if(max > 0 && min > 0 && ratio > 0)
514 if(ratio < min)
516 dy = (dx * min + dy) / (min * min + 1);
517 dx = dy * min;
518 geometry.width = (int) dx + c->basew;
519 geometry.height = (int) dy + c->baseh;
521 else if(ratio > max)
523 dy = (dx * min + dy) / (max * max + 1);
524 dx = dy * min;
525 geometry.width = (int) dx + c->basew;
526 geometry.height = (int) dy + c->baseh;
530 if(c->minw && geometry.width < c->minw)
531 geometry.width = c->minw;
532 if(c->minh && geometry.height < c->minh)
533 geometry.height = c->minh;
534 if(c->maxw && geometry.width > c->maxw)
535 geometry.width = c->maxw;
536 if(c->maxh && geometry.height > c->maxh)
537 geometry.height = c->maxh;
538 if(c->incw)
539 geometry.width -= (geometry.width - c->basew) % c->incw;
540 if(c->inch)
541 geometry.height -= (geometry.height - c->baseh) % c->inch;
543 return geometry;
546 /** Resize client window.
547 * \param c Client to resize.
548 * \param geometry New window geometry.
549 * \param hints Use size hints.
551 void
552 client_resize(client_t *c, area_t geometry, bool hints)
554 int new_screen;
555 area_t area;
556 layout_t *layout = layout_get_current(c->screen);
557 bool fixed;
558 /* Values to configure a window is an array where values are
559 * stored according to 'value_mask' */
560 uint32_t values[5];
562 if(c->titlebar && !c->ismoving && !client_isfloating(c) && layout != layout_floating)
563 geometry = titlebar_geometry_remove(c->titlebar, c->border, geometry);
565 if(hints)
566 geometry = client_geometry_hints(c, geometry);
568 if(geometry.width <= 0 || geometry.height <= 0)
569 return;
571 /* offscreen appearance fixes */
572 area = display_area_get(c->phys_screen, NULL,
573 &globalconf.screens[c->screen].padding);
575 fixed = client_isfixed(c);
577 if(geometry.x > area.width)
578 geometry.x = area.width - geometry.width - 2 * c->border;
579 if(geometry.y > area.height)
580 geometry.y = area.height - geometry.height - 2 * c->border;
581 if(geometry.x + geometry.width + 2 * c->border < 0)
582 geometry.x = 0;
583 if(geometry.y + geometry.height + 2 * c->border < 0)
584 geometry.y = 0;
586 /* fixed windows can only change their x,y */
587 if((fixed && (c->geometry.x != geometry.x || c->geometry.y != geometry.y))
588 || (!fixed && (c->geometry.x != geometry.x
589 || c->geometry.y != geometry.y
590 || c->geometry.width != geometry.width
591 || c->geometry.height != geometry.height)))
593 new_screen = screen_getbycoord(c->screen, geometry.x, geometry.y);
595 c->geometry.x = values[0] = geometry.x;
596 c->geometry.width = values[2] = geometry.width;
597 c->geometry.y = values[1] = geometry.y;
598 c->geometry.height = values[3] = geometry.height;
599 values[4] = c->border;
601 /* save the floating geometry if the window is floating but not
602 * maximized */
603 if(c->ismoving || client_isfloating(c)
604 || layout_get_current(new_screen) == layout_floating)
605 if(!c->isfullscreen)
606 c->f_geometry = geometry;
608 titlebar_update_geometry_floating(c);
610 xcb_configure_window(globalconf.connection, c->win,
611 XCB_CONFIG_WINDOW_X | XCB_CONFIG_WINDOW_Y |
612 XCB_CONFIG_WINDOW_WIDTH | XCB_CONFIG_WINDOW_HEIGHT |
613 XCB_CONFIG_WINDOW_BORDER_WIDTH,
614 values);
615 window_configure(c->win, geometry, c->border);
617 if(c->screen != new_screen)
618 screen_client_moveto(c, new_screen, true, false);
620 /* execute hook */
621 hooks_property(c, "geometry");
625 /** Set a clinet floating.
626 * \param c The client.
627 * \param floating Set floating, or not.
628 * \param layer Layer to put the floating window onto.
630 void
631 client_setfloating(client_t *c, bool floating)
633 if(c->isfloating != floating
634 && (c->type == WINDOW_TYPE_NORMAL))
636 if((c->isfloating = floating))
637 if(!c->isfullscreen)
638 client_resize(c, c->f_geometry, false);
639 client_need_arrange(c);
640 client_stack();
641 xcb_change_property(globalconf.connection,
642 XCB_PROP_MODE_REPLACE,
643 c->win, _AWESOME_FLOATING, CARDINAL, 8, 1,
644 &c->isfloating);
645 /* execute hook */
646 hooks_property(c, "floating");
650 /** Set a client minimized, or not.
651 * \param c The client.
652 * \param s Set or not the client minimized.
654 void
655 client_setminimized(client_t *c, bool s)
657 if(c->isminimized != s)
659 client_need_arrange(c);
660 c->isminimized = s;
661 client_need_arrange(c);
662 ewmh_client_update_hints(c);
663 /* execute hook */
664 hooks_property(c, "minimized");
668 /** Set a client sticky, or not.
669 * \param c The client.
670 * \param s Set or not the client sticky.
672 void
673 client_setsticky(client_t *c, bool s)
675 if(c->issticky != s)
677 client_need_arrange(c);
678 c->issticky = s;
679 client_need_arrange(c);
680 ewmh_client_update_hints(c);
681 hooks_property(c, "sticky");
685 /** Set a client fullscreen, or not.
686 * \param c The client.
687 * \param s Set or not the client fullscreen.
689 void
690 client_setfullscreen(client_t *c, bool s)
692 if(c->isfullscreen != s)
694 area_t geometry;
696 /* become fullscreen! */
697 if((c->isfullscreen = s))
699 geometry = screen_area_get(c->screen, NULL, &globalconf.screens[c->screen].padding, false);
700 c->m_geometry = c->geometry;
701 c->oldborder = c->border;
702 client_setborder(c, 0);
704 else
706 geometry = c->m_geometry;
707 client_setborder(c, c->oldborder);
708 client_resize(c, c->m_geometry, false);
710 client_resize(c, geometry, false);
711 client_need_arrange(c);
712 client_stack();
713 xcb_change_property(globalconf.connection,
714 XCB_PROP_MODE_REPLACE,
715 c->win, _AWESOME_FULLSCREEN, CARDINAL, 8, 1,
716 &c->isfullscreen);
717 ewmh_client_update_hints(c);
718 hooks_property(c, "fullscreen");
722 /** Set a client above, or not.
723 * \param c The client.
724 * \param s Set or not the client above.
726 void
727 client_setabove(client_t *c, bool s)
729 if(c->isabove != s)
731 c->isabove = s;
732 client_stack();
733 ewmh_client_update_hints(c);
734 /* execute hook */
735 hooks_property(c, "above");
739 /** Set a client below, or not.
740 * \param c The client.
741 * \param s Set or not the client below.
743 void
744 client_setbelow(client_t *c, bool s)
746 if(c->isbelow != s)
748 c->isbelow = s;
749 client_stack();
750 ewmh_client_update_hints(c);
751 /* execute hook */
752 hooks_property(c, "below");
756 /** Set a client modal, or not.
757 * \param c The client.
758 * \param s Set or not the client moda.
760 void
761 client_setmodal(client_t *c, bool s)
763 if(c->ismodal != s)
765 c->ismodal = s;
766 client_stack();
767 ewmh_client_update_hints(c);
768 /* execute hook */
769 hooks_property(c, "modal");
773 /** Set a client ontop, or not.
774 * \param c The client.
775 * \param s Set or not the client moda.
777 void
778 client_setontop(client_t *c, bool s)
780 if(c->isontop != s)
782 c->isontop = s;
783 client_stack();
784 /* execute hook */
785 hooks_property(c, "ontop");
789 /** Save client properties as an X property.
790 * \param c The client.
792 void
793 client_saveprops_tags(client_t *c)
795 tag_array_t *tags = &globalconf.screens[c->screen].tags;
796 unsigned char *prop = p_alloca(unsigned char, tags->len + 1);
797 int i;
799 for(i = 0; i < tags->len; i++)
800 prop[i] = is_client_tagged(c, tags->tab[i]) ? '1' : '0';
802 xcb_change_property(globalconf.connection, XCB_PROP_MODE_REPLACE, c->win, _AWESOME_TAGS, STRING, 8, i, prop);
805 /** Unban a client.
806 * \param c The client.
808 void
809 client_unban(client_t *c)
811 xcb_map_window(globalconf.connection, c->win);
812 window_state_set(c->win, XCB_WM_STATE_NORMAL);
813 if(c->titlebar)
815 if(c->isfullscreen || !c->titlebar->isvisible)
816 xcb_unmap_window(globalconf.connection, c->titlebar->sw.window);
817 else
818 xcb_map_window(globalconf.connection, c->titlebar->sw.window);
822 /** Unmanage a client.
823 * \param c The client.
825 void
826 client_unmanage(client_t *c)
828 tag_array_t *tags = &globalconf.screens[c->screen].tags;
830 if(globalconf.screens[c->phys_screen].client_focus == c)
831 client_unfocus(c);
833 /* remove client everywhere */
834 client_list_detach(&globalconf.clients, c);
835 stack_client_delete(c);
836 for(int i = 0; i < tags->len; i++)
837 untag_client(c, tags->tab[i]);
839 /* call hook */
840 luaA_client_userdata_new(globalconf.L, c);
841 luaA_dofunction(globalconf.L, globalconf.hooks.unmanage, 1, 0);
843 /* Call hook to notify list change */
844 luaA_dofunction(globalconf.L, globalconf.hooks.clients, 0, 0);
846 /* The server grab construct avoids race conditions. */
847 xcb_grab_server(globalconf.connection);
849 xcb_configure_window(globalconf.connection, c->win,
850 XCB_CONFIG_WINDOW_BORDER_WIDTH,
851 (uint32_t *) &c->oldborder);
853 xcb_ungrab_button(globalconf.connection, XCB_BUTTON_INDEX_ANY, c->win,
854 XCB_BUTTON_MASK_ANY);
855 window_state_set(c->win, XCB_WM_STATE_WITHDRAWN);
857 xcb_flush(globalconf.connection);
858 xcb_ungrab_server(globalconf.connection);
860 titlebar_client_detach(c);
862 ewmh_update_net_client_list(c->phys_screen);
864 /* delete properties */
865 xcb_delete_property(globalconf.connection, c->win, _AWESOME_TAGS);
866 xcb_delete_property(globalconf.connection, c->win, _AWESOME_FLOATING);
868 if(client_hasstrut(c))
869 /* All the wiboxes (may) need to be repositioned */
870 for(int screen = 0; screen < globalconf.nscreen; screen++)
871 for(int i = 0; i < globalconf.screens[screen].wiboxes.len; i++)
873 wibox_t *s = globalconf.screens[screen].wiboxes.tab[i];
874 wibox_position_update(s);
877 /* set client as invalid */
878 c->invalid = true;
880 client_unref(&c);
883 /** Kill a client via a WM_DELETE_WINDOW request or KillClient if not
884 * supported.
885 * \param c The client to kill.
887 void
888 client_kill(client_t *c)
890 if(window_hasproto(c->win, WM_DELETE_WINDOW))
892 xcb_client_message_event_t ev;
894 /* Initialize all of event's fields first */
895 p_clear(&ev, 1);
897 ev.response_type = XCB_CLIENT_MESSAGE;
898 ev.window = c->win;
899 ev.format = 32;
900 ev.data.data32[1] = XCB_CURRENT_TIME;
901 ev.type = WM_PROTOCOLS;
902 ev.data.data32[0] = WM_DELETE_WINDOW;
904 xcb_send_event(globalconf.connection, false, c->win,
905 XCB_EVENT_MASK_NO_EVENT, (char *) &ev);
907 else
908 xcb_kill_client(globalconf.connection, c->win);
911 /** Get all clients into a table.
912 * \param L The Lua VM state.
913 * \return The number of elements pushed on stack.
914 * \luastack
915 * \lparam An optional screen nunmber.
916 * \lreturn A table with all clients.
918 static int
919 luaA_client_get(lua_State *L)
921 int i = 1, screen;
922 client_t *c;
924 screen = luaL_optnumber(L, 1, 0) - 1;
926 lua_newtable(L);
928 if(screen == SCREEN_UNDEF)
929 for(c = globalconf.clients; c; c = c->next)
931 luaA_client_userdata_new(globalconf.L, c);
932 lua_rawseti(L, -2, i++);
934 else
936 luaA_checkscreen(screen);
937 for(c = globalconf.clients; c; c = c->next)
938 if(c->screen == screen)
940 luaA_client_userdata_new(globalconf.L, c);
941 lua_rawseti(L, -2, i++);
945 return 1;
948 /** Get only visible clients for a screen (DEPRECATED).
949 * \param L The Lua VM state.
950 * \return The number of elements pushed on stack.
951 * \luastack
952 * \lparam A screen number.
953 * \lreturn A table with all visible clients for this screen.
955 static int
956 luaA_client_visible_get(lua_State *L)
958 int i = 1;
959 client_t *c;
960 int screen = luaL_checknumber(L, 1) - 1;
962 luaA_checkscreen(screen);
964 deprecate();
966 lua_newtable(L);
968 for(c = globalconf.clients; c; c = c->next)
969 if(client_isvisible(c, screen))
971 luaA_client_userdata_new(L, c);
972 lua_rawseti(L, -2, i++);
975 return 1;
978 /** Check if a client is visible on its screen.
979 * \param L The Lua VM state.
980 * \return The number of elements pushed on stack.
981 * \luastack
982 * \lvalue A client.
983 * \lreturn A boolean value, true if the client is visible, false otherwise.
985 static int
986 luaA_client_isvisible(lua_State *L)
988 client_t **c = luaA_checkudata(L, 1, "client");
989 lua_pushboolean(L, client_isvisible(*c, (*c)->screen));
990 return 1;
993 /** Set client border width.
994 * \param c The client.
995 * \param width The border width.
997 void
998 client_setborder(client_t *c, int width)
1000 uint32_t w = width;
1002 if(width > 0 && (c->type == WINDOW_TYPE_DOCK
1003 || c->type == WINDOW_TYPE_SPLASH
1004 || c->type == WINDOW_TYPE_DESKTOP
1005 || c->isfullscreen))
1006 return;
1008 if(width == c->border || width < 0)
1009 return;
1011 c->border = width;
1012 xcb_configure_window(globalconf.connection, c->win,
1013 XCB_CONFIG_WINDOW_BORDER_WIDTH, &w);
1015 if(client_isvisible(c, c->screen))
1017 if(client_isfloating(c) || layout_get_current(c->screen) == layout_floating)
1018 titlebar_update_geometry_floating(c);
1019 else
1020 globalconf.screens[c->screen].need_arrange = true;
1023 hooks_property(c, "border_width");
1026 /** Kill a client.
1027 * \param L The Lua VM state.
1029 * \luastack
1030 * \lvalue A client.
1032 static int
1033 luaA_client_kill(lua_State *L)
1035 client_t **c = luaA_checkudata(L, 1, "client");
1036 client_kill(*c);
1037 return 0;
1040 /** Swap a client with another one.
1041 * \param L The Lua VM state.
1042 * \luastack
1043 * \lvalue A client.
1044 * \lparam A client to swap with.
1046 static int
1047 luaA_client_swap(lua_State *L)
1049 client_t **c = luaA_checkudata(L, 1, "client");
1050 client_t **swap = luaA_checkudata(L, 2, "client");
1051 client_list_swap(&globalconf.clients, *swap, *c);
1052 client_need_arrange(*c);
1053 client_need_arrange(*swap);
1055 /* Call hook to notify list change */
1056 luaA_dofunction(L, globalconf.hooks.clients, 0, 0);
1058 return 0;
1061 /** Access or set the client tags.
1062 * \param L The Lua VM state.
1063 * \return The number of elements pushed on stack.
1064 * \lparam A table with tags to set, or none to get the current tags table.
1065 * \return The clients tag.
1067 static int
1068 luaA_client_tags(lua_State *L)
1070 tag_array_t *tags;
1071 tag_t **tag;
1072 client_t **c = luaA_checkudata(L, 1, "client");
1073 int j = 0;
1075 if(lua_gettop(L) == 2)
1077 luaA_checktable(L, 2);
1078 tags = &globalconf.screens[(*c)->screen].tags;
1079 for(int i = 0; i < tags->len; i++)
1080 untag_client(*c, tags->tab[i]);
1081 lua_pushnil(L);
1082 while(lua_next(L, 2))
1084 tag = luaA_checkudata(L, -1, "tag");
1085 tag_client(*c, *tag);
1086 lua_pop(L, 1);
1088 lua_pop(L, 1);
1091 tags = &globalconf.screens[(*c)->screen].tags;
1092 luaA_otable_new(L);
1093 for(int i = 0; i < tags->len; i++)
1094 if(is_client_tagged(*c, tags->tab[i]))
1096 luaA_tag_userdata_new(L, tags->tab[i]);
1097 lua_rawseti(L, -2, ++j);
1100 return 1;
1103 /** Raise a client on top of others which are on the same layer.
1104 * \param L The Lua VM state.
1106 * \luastack
1107 * \lvalue A client.
1109 static int
1110 luaA_client_raise(lua_State *L)
1112 client_t **c = luaA_checkudata(L, 1, "client");
1113 client_raise(*c);
1114 return 0;
1117 /** Redraw a client by unmapping and mapping it quickly.
1118 * \param L The Lua VM state.
1120 * \luastack
1121 * \lvalue A client.
1123 static int
1124 luaA_client_redraw(lua_State *L)
1126 client_t **c = luaA_checkudata(L, 1, "client");
1128 xcb_unmap_window(globalconf.connection, (*c)->win);
1129 xcb_map_window(globalconf.connection, (*c)->win);
1131 /* Set the focus on the current window if the redraw has been
1132 performed on the window where the pointer is currently on
1133 because after the unmapping/mapping, the focus is lost */
1134 if(globalconf.screen_focus->client_focus == *c)
1135 xcb_set_input_focus(globalconf.connection, XCB_INPUT_FOCUS_POINTER_ROOT,
1136 (*c)->win, XCB_CURRENT_TIME);
1138 return 0;
1141 /** Return a formated string for a client.
1142 * \param L The Lua VM state.
1143 * \luastack
1144 * \lvalue A client.
1145 * \lreturn A string.
1147 static int
1148 luaA_client_tostring(lua_State *L)
1150 client_t **p = luaA_checkudata(L, 1, "client");
1151 lua_pushfstring(L, "[client udata(%p) name(%s)]", *p, (*p)->name);
1152 return 1;
1155 /** Stop managing a client.
1156 * \param L The Lua VM state.
1157 * \return The number of elements pushed on stack.
1158 * \luastack
1159 * \lvalue A client.
1161 static int
1162 luaA_client_unmanage(lua_State *L)
1164 client_t **c = luaA_checkudata(L, 1, "client");
1165 client_unmanage(*c);
1166 return 0;
1169 /** Return client geometry.
1170 * \param L The Lua VM state.
1171 * \return The number of elements pushed on stack.
1172 * \luastack
1173 * \lparam A table with new coordinates, or none.
1174 * \lreturn A table with client coordinates.
1176 static int
1177 luaA_client_geometry(lua_State *L)
1179 client_t **c = luaA_checkudata(L, 1, "client");
1181 if(lua_gettop(L) == 2)
1183 if((*c)->isfloating || layout_get_current((*c)->screen) == layout_floating)
1185 area_t geometry;
1187 luaA_checktable(L, 2);
1188 geometry.x = luaA_getopt_number(L, 2, "x", (*c)->geometry.x);
1189 geometry.y = luaA_getopt_number(L, 2, "y", (*c)->geometry.y);
1190 geometry.width = luaA_getopt_number(L, 2, "width", (*c)->geometry.width);
1191 geometry.height = luaA_getopt_number(L, 2, "height", (*c)->geometry.height);
1192 client_resize(*c, geometry, false);
1196 return luaA_pusharea(L, (*c)->geometry);
1199 static int
1200 luaA_client_coords(lua_State *L)
1202 deprecate();
1203 return luaA_client_geometry(L);
1206 /** Return client geometry, using also titlebar and border width.
1207 * \param L The Lua VM state.
1208 * \return The number of elements pushed on stack.
1209 * \luastack
1210 * \lparam A table with new coordinates, or none.
1211 * \lreturn A table with client coordinates.
1213 static int
1214 luaA_client_fullgeometry(lua_State *L)
1216 client_t **c = luaA_checkudata(L, 1, "client");
1217 area_t geometry;
1219 if(lua_gettop(L) == 2)
1221 if((*c)->isfloating || layout_get_current((*c)->screen) == layout_floating)
1223 luaA_checktable(L, 2);
1224 geometry.x = luaA_getopt_number(L, 2, "x", (*c)->geometry.x);
1225 geometry.y = luaA_getopt_number(L, 2, "y", (*c)->geometry.y);
1226 geometry.width = luaA_getopt_number(L, 2, "width", (*c)->geometry.width);
1227 geometry.height = luaA_getopt_number(L, 2, "height", (*c)->geometry.height);
1228 geometry = titlebar_geometry_remove((*c)->titlebar,
1229 (*c)->border,
1230 geometry);
1231 client_resize(*c, geometry, false);
1235 return luaA_pusharea(L, titlebar_geometry_add((*c)->titlebar,
1236 (*c)->border,
1237 (*c)->geometry));
1240 static int
1241 luaA_client_fullcoords(lua_State *L)
1243 deprecate();
1244 return luaA_client_fullgeometry(L);
1247 /** Client newindex.
1248 * \param L The Lua VM state.
1249 * \return The number of elements pushed on stack.
1252 luaA_client_newindex(lua_State *L)
1254 size_t len;
1255 client_t **c = luaA_checkudata(L, 1, "client");
1256 const char *buf = luaL_checklstring(L, 2, &len);
1257 bool b;
1258 double d;
1259 int i;
1260 wibox_t **t = NULL;
1261 image_t **image;
1263 if((*c)->invalid)
1264 luaL_error(L, "client is invalid\n");
1266 switch(a_tokenize(buf, len))
1268 case A_TK_SCREEN:
1269 if(globalconf.xinerama_is_active)
1271 i = luaL_checknumber(L, 3) - 1;
1272 luaA_checkscreen(i);
1273 if(i != (*c)->screen)
1274 screen_client_moveto(*c, i, true, true);
1276 break;
1277 case A_TK_HIDE:
1278 b = luaA_checkboolean(L, 3);
1279 if(b != (*c)->ishidden)
1281 client_need_arrange(*c);
1282 (*c)->ishidden = b;
1283 client_need_arrange(*c);
1285 break;
1286 case A_TK_MINIMIZE:
1287 client_setminimized(*c, luaA_checkboolean(L, 3));
1288 break;
1289 case A_TK_FULLSCREEN:
1290 client_setfullscreen(*c, luaA_checkboolean(L, 3));
1291 break;
1292 case A_TK_ICON:
1293 image = luaA_checkudata(L, 3, "image");
1294 image_unref(&(*c)->icon);
1295 image_ref(image);
1296 (*c)->icon = *image;
1297 /* execute hook */
1298 hooks_property(*c, "icon");
1299 break;
1300 case A_TK_OPACITY:
1301 if(lua_isnil(L, 3))
1302 window_opacity_set((*c)->win, -1);
1303 else
1305 d = luaL_checknumber(L, 3);
1306 if(d >= 0 && d <= 1)
1307 window_opacity_set((*c)->win, d);
1309 break;
1310 case A_TK_FLOATING:
1311 client_setfloating(*c, luaA_checkboolean(L, 3));
1312 break;
1313 case A_TK_STICKY:
1314 client_setsticky(*c, luaA_checkboolean(L, 3));
1315 break;
1316 case A_TK_HONORSIZEHINTS:
1317 (*c)->honorsizehints = luaA_checkboolean(L, 3);
1318 client_need_arrange(*c);
1319 break;
1320 case A_TK_BORDER_WIDTH:
1321 client_setborder(*c, luaL_checknumber(L, 3));
1322 break;
1323 case A_TK_ONTOP:
1324 client_setontop(*c, luaA_checkboolean(L, 3));
1325 break;
1326 case A_TK_BORDER_COLOR:
1327 if((buf = luaL_checklstring(L, 3, &len))
1328 && xcolor_init_reply(xcolor_init_unchecked(&(*c)->border_color, buf, len)))
1329 xcb_change_window_attributes(globalconf.connection, (*c)->win,
1330 XCB_CW_BORDER_PIXEL, &(*c)->border_color.pixel);
1331 break;
1332 case A_TK_TITLEBAR:
1333 if(lua_isnil(L, 3))
1334 titlebar_client_detach(*c);
1335 else
1337 t = luaA_checkudata(L, 3, "wibox");
1338 titlebar_client_attach(*c, *t);
1340 break;
1341 default:
1342 return 0;
1345 return 0;
1348 /** Client object.
1349 * \param L The Lua VM state.
1350 * \return The number of elements pushed on stack.
1351 * \luastack
1352 * \lfield name The client title.
1353 * \lfield skip_taskbar True if the client does not want to be in taskbar.
1354 * \lfield type The window type (desktop, normal, dock, …).
1355 * \lfield class The client class.
1356 * \lfield instance The client instance.
1357 * \lfield pid The client PID, if available.
1358 * \lfield role The window role, if available.
1359 * \lfield machine The machine client is running on.
1360 * \lfield icon_name The client name when iconified.
1361 * \lfield screen Client screen number.
1362 * \lfield hide Define if the client must be hidden, i.e. never mapped,
1363 * invisible in taskbar.
1364 * \lfield minimize Define it the client must be iconify, i.e. only visible in
1365 * taskbar.
1366 * \lfield icon_path Path to the icon used to identify.
1367 * \lfield floating True always floating.
1368 * \lfield honorsizehints Honor size hints, i.e. respect size ratio.
1369 * \lfield border_width The client border width.
1370 * \lfield border_color The client border color.
1371 * \lfield titlebar The client titlebar.
1372 * \lfield urgent The client urgent state.
1373 * \lfield focus The focused client.
1374 * \lfield opacity The client opacity between 0 and 1.
1375 * \lfield ontop The client is on top of every other windows.
1376 * \lfield fullscreen The client is fullscreen or not.
1378 static int
1379 luaA_client_index(lua_State *L)
1381 size_t len;
1382 ssize_t slen;
1383 client_t **c = luaA_checkudata(L, 1, "client");
1384 const char *buf = luaL_checklstring(L, 2, &len);
1385 char *value;
1386 void *data;
1387 xcb_get_wm_class_reply_t hint;
1388 xcb_get_property_cookie_t prop_c;
1389 xcb_get_property_reply_t *prop_r = NULL;
1390 double d;
1392 if((*c)->invalid)
1393 luaL_error(L, "client is invalid\n");
1395 if(luaA_usemetatable(L, 1, 2))
1396 return 1;
1398 switch(a_tokenize(buf, len))
1400 case A_TK_NAME:
1401 lua_pushstring(L, (*c)->name);
1402 break;
1403 case A_TK_SKIP_TASKBAR:
1404 lua_pushboolean(L, (*c)->skiptb);
1405 break;
1406 case A_TK_TYPE:
1407 switch((*c)->type)
1409 case WINDOW_TYPE_DESKTOP:
1410 lua_pushliteral(L, "desktop");
1411 break;
1412 case WINDOW_TYPE_DOCK:
1413 lua_pushliteral(L, "dock");
1414 break;
1415 case WINDOW_TYPE_SPLASH:
1416 lua_pushliteral(L, "splash");
1417 break;
1418 case WINDOW_TYPE_DIALOG:
1419 lua_pushliteral(L, "dialog");
1420 break;
1421 default:
1422 lua_pushliteral(L, "normal");
1423 break;
1425 break;
1426 case A_TK_CLASS:
1427 if(!xcb_get_wm_class_reply(globalconf.connection,
1428 xcb_get_wm_class_unchecked(globalconf.connection, (*c)->win),
1429 &hint, NULL))
1430 return 0;
1431 lua_pushstring(L, hint.class);
1432 xcb_get_wm_class_reply_wipe(&hint);
1433 break;
1434 case A_TK_INSTANCE:
1435 if(!xcb_get_wm_class_reply(globalconf.connection,
1436 xcb_get_wm_class_unchecked(globalconf.connection, (*c)->win),
1437 &hint, NULL))
1438 return 0;
1439 lua_pushstring(L, hint.name);
1440 xcb_get_wm_class_reply_wipe(&hint);
1441 break;
1442 case A_TK_ROLE:
1443 if(!xutil_text_prop_get(globalconf.connection, (*c)->win,
1444 WM_WINDOW_ROLE, &value, &slen))
1445 return 0;
1446 lua_pushlstring(L, value, slen);
1447 p_delete(&value);
1448 break;
1449 case A_TK_PID:
1450 prop_c = xcb_get_property_unchecked(globalconf.connection, false, (*c)->win, _NET_WM_PID, CARDINAL, 0L, 1L);
1451 prop_r = xcb_get_property_reply(globalconf.connection, prop_c, NULL);
1453 if(prop_r && prop_r->value_len && (data = xcb_get_property_value(prop_r)))
1454 lua_pushnumber(L, *(uint32_t *)data);
1455 else
1457 p_delete(&prop_r);
1458 return 0;
1460 break;
1461 case A_TK_MACHINE:
1462 if(!xutil_text_prop_get(globalconf.connection, (*c)->win,
1463 WM_CLIENT_MACHINE, &value, &slen))
1464 return 0;
1465 lua_pushlstring(L, value, slen);
1466 p_delete(&value);
1467 break;
1468 case A_TK_ICON_NAME:
1469 lua_pushstring(L, (*c)->icon_name);
1470 break;
1471 case A_TK_SCREEN:
1472 lua_pushnumber(L, 1 + (*c)->screen);
1473 break;
1474 case A_TK_HIDE:
1475 lua_pushboolean(L, (*c)->ishidden);
1476 break;
1477 case A_TK_MINIMIZE:
1478 lua_pushboolean(L, (*c)->isminimized);
1479 break;
1480 case A_TK_FULLSCREEN:
1481 lua_pushboolean(L, (*c)->isfullscreen);
1482 break;
1483 case A_TK_ICON:
1484 if((*c)->icon)
1485 luaA_image_userdata_new(L, (*c)->icon);
1486 else
1487 return 0;
1488 break;
1489 case A_TK_OPACITY:
1490 if((d = window_opacity_get((*c)->win)) >= 0)
1491 lua_pushnumber(L, d);
1492 else
1493 return 0;
1494 break;
1495 case A_TK_FLOATING:
1496 lua_pushboolean(L, (*c)->isfloating);
1497 break;
1498 case A_TK_ONTOP:
1499 lua_pushboolean(L, (*c)->isontop);
1500 break;
1501 case A_TK_STICKY:
1502 lua_pushboolean(L, (*c)->issticky);
1503 break;
1504 case A_TK_HONORSIZEHINTS:
1505 lua_pushboolean(L, (*c)->honorsizehints);
1506 break;
1507 case A_TK_BORDER_WIDTH:
1508 lua_pushnumber(L, (*c)->border);
1509 break;
1510 case A_TK_BORDER_COLOR:
1511 luaA_pushcolor(L, &(*c)->border_color);
1512 break;
1513 case A_TK_TITLEBAR:
1514 if((*c)->titlebar)
1515 return luaA_wibox_userdata_new(L, (*c)->titlebar);
1516 return 0;
1517 case A_TK_URGENT:
1518 lua_pushboolean(L, (*c)->isurgent);
1519 break;
1520 case A_TK_SIZEHINTS:
1521 lua_newtable(L);
1522 lua_pushboolean(L, (*c)->size_hints.flags & XCB_SIZE_HINT_US_POSITION);
1523 lua_setfield(L, -2, "user_position");
1524 lua_pushboolean(L, (*c)->size_hints.flags & XCB_SIZE_HINT_US_SIZE);
1525 lua_setfield(L, -2, "user_size");
1526 lua_pushboolean(L, (*c)->size_hints.flags & XCB_SIZE_HINT_P_POSITION);
1527 lua_setfield(L, -2, "program_position");
1528 lua_pushboolean(L, (*c)->size_hints.flags & XCB_SIZE_HINT_P_SIZE);
1529 lua_setfield(L, -2, "program_size");
1530 break;
1531 default:
1532 return 0;
1535 return 1;
1538 /** Get or set mouse buttons bindings for a client.
1539 * \param L The Lua VM state.
1540 * \return The number of element pushed on stack.
1541 * \luastack
1542 * \lvalue A client.
1543 * \lparam An array of mouse button bindings objects, or nothing.
1544 * \return The array of mouse button bindings objects of this client.
1546 static int
1547 luaA_client_buttons(lua_State *L)
1549 client_t **client = luaA_checkudata(L, 1, "client");
1550 button_array_t *buttons = &(*client)->buttons;
1552 if(lua_gettop(L) == 2)
1553 luaA_button_array_set(L, 2, buttons);
1555 return luaA_button_array_get(L, buttons);
1558 /* Client module.
1559 * \param L The Lua VM state.
1560 * \return The number of pushed elements.
1562 static int
1563 luaA_client_module_index(lua_State *L)
1565 size_t len;
1566 const char *buf = luaL_checklstring(L, 2, &len);
1568 switch(a_tokenize(buf, len))
1570 case A_TK_FOCUS:
1571 if(globalconf.screen_focus->client_focus)
1572 luaA_client_userdata_new(L, globalconf.screen_focus->client_focus);
1573 else
1574 return 0;
1575 break;
1576 default:
1577 return 0;
1580 return 1;
1583 /* Client module new index.
1584 * \param L The Lua VM state.
1585 * \return The number of pushed elements.
1587 static int
1588 luaA_client_module_newindex(lua_State *L)
1590 size_t len;
1591 const char *buf = luaL_checklstring(L, 2, &len);
1592 client_t **c;
1594 switch(a_tokenize(buf, len))
1596 case A_TK_FOCUS:
1597 c = luaA_checkudata(L, 3, "client");
1598 client_focus(*c);
1599 break;
1600 default:
1601 break;
1604 return 0;
1607 const struct luaL_reg awesome_client_methods[] =
1609 { "get", luaA_client_get },
1610 { "visible_get", luaA_client_visible_get },
1611 { "__index", luaA_client_module_index },
1612 { "__newindex", luaA_client_module_newindex },
1613 { NULL, NULL }
1615 const struct luaL_reg awesome_client_meta[] =
1617 { "isvisible", luaA_client_isvisible },
1618 { "geometry", luaA_client_geometry },
1619 { "fullgeometry", luaA_client_fullgeometry },
1620 { "buttons", luaA_client_buttons },
1621 { "tags", luaA_client_tags },
1622 { "kill", luaA_client_kill },
1623 { "swap", luaA_client_swap },
1624 { "raise", luaA_client_raise },
1625 { "redraw", luaA_client_redraw },
1626 { "mouse_resize", luaA_client_mouse_resize },
1627 { "mouse_move", luaA_client_mouse_move },
1628 { "unmanage", luaA_client_unmanage },
1629 { "__index", luaA_client_index },
1630 { "__newindex", luaA_client_newindex },
1631 { "__eq", luaA_client_eq },
1632 { "__gc", luaA_client_gc },
1633 { "__tostring", luaA_client_tostring },
1634 /* deprecated */
1635 { "coords", luaA_client_coords },
1636 { "fullcoords", luaA_client_fullcoords },
1637 { NULL, NULL }
1640 // vim: filetype=c:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=80