awsetbg: Add montage(1) support
[awesome.git] / client.c
blob68251dd2c5eb48db00a04d0df43aa79e35ea2fda
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 <xcb/xcb_atom.h>
24 #include "cnode.h"
25 #include "tag.h"
26 #include "window.h"
27 #include "ewmh.h"
28 #include "screen.h"
29 #include "titlebar.h"
30 #include "systray.h"
31 #include "property.h"
32 #include "layouts/floating.h"
33 #include "common/markup.h"
34 #include "common/atoms.h"
36 extern awesome_t globalconf;
38 DO_LUA_NEW(extern, client_t, client, "client", client_ref)
39 DO_LUA_EQ(client_t, client, "client")
40 DO_LUA_GC(client_t, client, "client", client_unref)
42 /** Load windows properties, restoring client's tag
43 * and floating state before awesome was restarted if any.
44 * \param c A client pointer.
45 * \param screen A virtual screen.
46 * \return True if client had property, false otherwise.
48 static bool
49 client_loadprops(client_t * c, screen_t *screen)
51 ssize_t len;
52 tag_array_t *tags = &screen->tags;
53 char *prop = NULL;
54 xcb_get_property_cookie_t floating_q, fullscreen_q;
55 xcb_get_property_reply_t *reply;
56 void *data;
58 if(!xutil_text_prop_get(globalconf.connection, c->win, _AWESOME_TAGS,
59 &prop, &len))
60 return false;
62 /* Send the GetProperty requests which will be processed later */
63 floating_q = xcb_get_property_unchecked(globalconf.connection, false, c->win,
64 _AWESOME_FLOATING, CARDINAL, 0, 1);
66 fullscreen_q = xcb_get_property_unchecked(globalconf.connection, false, c->win,
67 _AWESOME_FULLSCREEN, CARDINAL, 0, 1);
69 /* ignore property if the tag count isn't matching */
70 if(len == tags->len)
71 for(int i = 0; i < tags->len; i++)
72 if(prop[i] == '1')
73 tag_client(c, tags->tab[i]);
74 else
75 untag_client(c, tags->tab[i]);
77 p_delete(&prop);
79 /* check for floating */
80 reply = xcb_get_property_reply(globalconf.connection, floating_q, NULL);
82 if(reply && reply->value_len && (data = xcb_get_property_value(reply)))
83 client_setfloating(c, *(bool *) data);
84 p_delete(&reply);
86 /* check for fullscreen */
87 reply = xcb_get_property_reply(globalconf.connection, fullscreen_q, NULL);
89 if(reply && reply->value_len && (data = xcb_get_property_value(reply)))
90 client_setfullscreen(c, *(bool *) data);
91 p_delete(&reply);
93 return true;
96 /** Check if client supports protocol a protocole in WM_PROTOCOL.
97 * \param win The window.
98 * \return True if client has the atom in protocol, false otherwise.
100 static bool
101 window_hasproto(xcb_window_t win, xcb_atom_t atom)
103 uint32_t i;
104 xcb_get_wm_protocols_reply_t protocols;
105 bool ret = false;
107 if(xcb_get_wm_protocols_reply(globalconf.connection,
108 xcb_get_wm_protocols_unchecked(globalconf.connection,
109 win, WM_PROTOCOLS),
110 &protocols, NULL))
112 for(i = 0; !ret && i < protocols.atoms_len; i++)
113 if(protocols.atoms[i] == atom)
114 ret = true;
115 xcb_get_wm_protocols_reply_wipe(&protocols);
117 return ret;
120 /** Returns true if a client is tagged
121 * with one of the tags of the specified screen.
122 * \param c The client to check.
123 * \param screen Virtual screen number.
124 * \return true if the client is visible, false otherwise.
126 bool
127 client_maybevisible(client_t *c, int screen)
129 if(c->screen == screen)
131 if(c->issticky || c->type == WINDOW_TYPE_DESKTOP)
132 return true;
134 tag_array_t *tags = &globalconf.screens[screen].tags;
136 for(int i = 0; i < tags->len; i++)
137 if(tags->tab[i]->selected && is_client_tagged(c, tags->tab[i]))
138 return true;
140 return false;
143 /** Get a client by its window.
144 * \param w The client window to find.
145 * \return A client pointer if found, NULL otherwise.
147 client_t *
148 client_getbywin(xcb_window_t w)
150 client_t *c;
151 for(c = globalconf.clients; c && c->win != w; c = c->next);
152 return c;
155 /** Unfocus a client.
156 * \param c The client.
158 static void
159 client_unfocus(client_t *c)
161 globalconf.screens[c->phys_screen].client_focus = NULL;
163 /* Call hook */
164 luaA_client_userdata_new(globalconf.L, c);
165 luaA_dofunction(globalconf.L, globalconf.hooks.unfocus, 1, 0);
167 ewmh_update_net_active_window(c->phys_screen);
170 /** Ban client and unmap it.
171 * \param c The client.
173 void
174 client_ban(client_t *c)
176 if(globalconf.screen_focus->client_focus == c)
177 client_unfocus(c);
178 xcb_unmap_window(globalconf.connection, c->win);
179 if(c->ishidden)
180 window_state_set(c->win, XCB_WM_STATE_ICONIC);
181 else
182 window_state_set(c->win, XCB_WM_STATE_WITHDRAWN);
183 if(c->titlebar)
184 xcb_unmap_window(globalconf.connection, c->titlebar->sw.window);
187 /** Give focus to client, or to first client if client is NULL.
188 * \param c The client or NULL.
189 * \return True if a window (even root) has received focus, false otherwise.
191 static void
192 client_focus(client_t *c)
194 if(!client_maybevisible(c, c->screen) || c->nofocus)
195 return;
197 /* unfocus current selected client */
198 if(globalconf.screen_focus->client_focus
199 && c != globalconf.screen_focus->client_focus)
200 client_unfocus(globalconf.screen_focus->client_focus);
202 /* stop hiding c */
203 c->ishidden = false;
204 client_setminimized(c, false);
206 /* unban the client before focusing or it will fail */
207 client_unban(c);
209 globalconf.screen_focus = &globalconf.screens[c->phys_screen];
210 globalconf.screen_focus->client_focus = c;
212 xcb_set_input_focus(globalconf.connection, XCB_INPUT_FOCUS_POINTER_ROOT,
213 c->win, XCB_CURRENT_TIME);
215 /* Some layouts use focused client differently, so call them back.
216 * And anyway, we have maybe unhidden */
217 client_need_arrange(c);
219 /* execute hook */
220 luaA_client_userdata_new(globalconf.L, globalconf.screen_focus->client_focus);
221 luaA_dofunction(globalconf.L, globalconf.hooks.focus, 1, 0);
223 ewmh_update_net_active_window(c->phys_screen);
226 /** Stack a window below.
227 * \param c The client.
228 * \param previous The previous window on the stack.
229 * \param return The next-previous!
231 static xcb_window_t
232 client_stack_above(client_t *c, xcb_window_t previous)
234 uint32_t config_win_vals[2];
236 config_win_vals[0] = previous;
237 config_win_vals[1] = XCB_STACK_MODE_ABOVE;
239 xcb_configure_window(globalconf.connection, c->win,
240 XCB_CONFIG_WINDOW_SIBLING | XCB_CONFIG_WINDOW_STACK_MODE,
241 config_win_vals);
243 config_win_vals[0] = c->win;
245 if(c->titlebar)
247 xcb_configure_window(globalconf.connection,
248 c->titlebar->sw.window,
249 XCB_CONFIG_WINDOW_SIBLING | XCB_CONFIG_WINDOW_STACK_MODE,
250 config_win_vals);
251 previous = c->titlebar->sw.window;
253 else
254 previous = c->win;
256 /* stack transient window on top of their parents */
257 for(client_node_t *node = *client_node_list_last(&globalconf.stack);
258 node; node = node->prev)
259 if(node->client->transient_for == c)
261 client_stack_above(node->client,
262 previous);
263 previous = node->client->win;
266 return previous;
269 /** Stacking layout layers */
270 typedef enum
272 /** This one is a special layer */
273 LAYER_IGNORE,
274 LAYER_DESKTOP,
275 LAYER_BELOW,
276 LAYER_TILE,
277 LAYER_FLOAT,
278 LAYER_ABOVE,
279 LAYER_FULLSCREEN,
280 LAYER_ONTOP,
281 LAYER_OUTOFSPACE
282 } layer_t;
284 /** Get the real layer of a client according to its attribute (fullscreen, …)
285 * \param c The client.
286 * \return The real layer.
288 static layer_t
289 client_layer_translator(client_t *c)
291 /* first deal with user set attributes */
292 if(c->isontop)
293 return LAYER_ONTOP;
294 else if(c->isfullscreen)
295 return LAYER_FULLSCREEN;
296 else if(c->isabove)
297 return LAYER_ABOVE;
298 else if(c->isbelow)
299 return LAYER_BELOW;
300 else if(c->isfloating)
301 return LAYER_FLOAT;
303 /* check for transient attr */
304 if(c->transient_for)
305 return LAYER_IGNORE;
307 /* then deal with windows type */
308 switch(c->type)
310 case WINDOW_TYPE_DOCK:
311 return LAYER_ABOVE;
312 case WINDOW_TYPE_DESKTOP:
313 return LAYER_DESKTOP;
314 case WINDOW_TYPE_DIALOG:
315 return LAYER_FLOAT;
316 default:
317 break;
320 if(client_isfixed(c))
321 return LAYER_FLOAT;
323 return LAYER_TILE;
326 /** Restack clients.
327 * \todo It might be worth stopping to restack everyone and only stack `c'
328 * relatively to the first matching in the list.
330 void
331 client_stack()
333 uint32_t config_win_vals[2];
334 client_node_t *node, *last = *client_node_list_last(&globalconf.stack);
335 layer_t layer;
336 int screen;
338 config_win_vals[0] = XCB_NONE;
339 config_win_vals[1] = XCB_STACK_MODE_ABOVE;
341 /* stack desktop windows */
342 for(layer = LAYER_DESKTOP; layer < LAYER_BELOW; layer++)
343 for(node = last; node; node = node->prev)
344 if(client_layer_translator(node->client) == layer)
345 config_win_vals[0] = client_stack_above(node->client,
346 config_win_vals[0]);
348 /* first stack not ontop wibox window */
349 for(screen = 0; screen < globalconf.nscreen; screen++)
350 for(int i = 0; i < globalconf.screens[screen].wiboxes.len; i++)
352 wibox_t *sb = globalconf.screens[screen].wiboxes.tab[i];
353 if(!sb->ontop)
355 xcb_configure_window(globalconf.connection,
356 sb->sw.window,
357 XCB_CONFIG_WINDOW_SIBLING | XCB_CONFIG_WINDOW_STACK_MODE,
358 config_win_vals);
359 config_win_vals[0] = sb->sw.window;
363 /* stack bottom layers */
364 for(layer = LAYER_BELOW; layer < LAYER_FULLSCREEN; layer++)
365 for(node = last; node; node = node->prev)
366 if(client_layer_translator(node->client) == layer)
367 config_win_vals[0] = client_stack_above(node->client,
368 config_win_vals[0]);
370 /* then stack ontop wibox window */
371 for(screen = 0; screen < globalconf.nscreen; screen++)
372 for(int i = 0; i < globalconf.screens[screen].wiboxes.len; i++)
374 wibox_t *sb = globalconf.screens[screen].wiboxes.tab[i];
375 if(sb->ontop)
377 xcb_configure_window(globalconf.connection,
378 sb->sw.window,
379 XCB_CONFIG_WINDOW_SIBLING | XCB_CONFIG_WINDOW_STACK_MODE,
380 config_win_vals);
381 config_win_vals[0] = sb->sw.window;
385 /* finally stack ontop and fullscreen windows */
386 for(layer = LAYER_FULLSCREEN; layer < LAYER_OUTOFSPACE; layer++)
387 for(node = last; node; node = node->prev)
388 if(client_layer_translator(node->client) == layer)
389 config_win_vals[0] = client_stack_above(node->client,
390 config_win_vals[0]);
393 /** Manage a new client.
394 * \param w The window.
395 * \param wgeom Window geometry.
396 * \param phys_screen Physical screen number.
397 * \param screen Virtual screen number where to manage client.
399 void
400 client_manage(xcb_window_t w, xcb_get_geometry_reply_t *wgeom, int phys_screen, int screen)
402 xcb_get_property_cookie_t ewmh_icon_cookie;
403 client_t *c;
404 image_t *icon;
405 const uint32_t select_input_val[] =
407 XCB_EVENT_MASK_STRUCTURE_NOTIFY
408 | XCB_EVENT_MASK_PROPERTY_CHANGE
409 | XCB_EVENT_MASK_ENTER_WINDOW
412 /* Send request to get NET_WM_ICON property as soon as possible... */
413 ewmh_icon_cookie = ewmh_window_icon_get_unchecked(w);
414 xcb_change_window_attributes(globalconf.connection, w, XCB_CW_EVENT_MASK, select_input_val);
416 if(systray_iskdedockapp(w))
418 systray_request_handle(w, phys_screen, NULL);
419 return;
422 c = p_new(client_t, 1);
424 c->screen = screen_getbycoord(screen, wgeom->x, wgeom->y);
426 c->phys_screen = phys_screen;
428 /* Initial values */
429 c->win = w;
430 c->geometry.x = c->f_geometry.x = c->m_geometry.x = wgeom->x;
431 c->geometry.y = c->f_geometry.y = c->m_geometry.y = wgeom->y;
432 c->geometry.width = c->f_geometry.width = c->m_geometry.width = wgeom->width;
433 c->geometry.height = c->f_geometry.height = c->m_geometry.height = wgeom->height;
434 client_setborder(c, wgeom->border_width);
435 if((icon = ewmh_window_icon_get_reply(ewmh_icon_cookie)))
436 c->icon = image_ref(&icon);
438 /* we honor size hints by default */
439 c->honorsizehints = true;
441 /* update hints */
442 property_update_wm_normal_hints(c, NULL);
443 property_update_wm_hints(c, NULL);
444 property_update_wm_transient_for(c, NULL);
446 if(c->transient_for)
447 screen = c->transient_for->screen;
449 /* Try to load props if any */
450 client_loadprops(c, &globalconf.screens[screen]);
453 /* Then check clients hints */
454 ewmh_client_check_hints(c);
456 /* move client to screen, but do not tag it for now */
457 screen_client_moveto(c, screen, false, true);
459 /* Check if client has been tagged by loading props, or maybe with its
460 * hints.
461 * If not, we tag it with current selected ones.
462 * This could be done on Lua side, but it's a sane behaviour. */
463 if(!c->issticky)
465 int i;
466 tag_array_t *tags = &globalconf.screens[screen].tags;
467 for(i = 0; i < tags->len; i++)
468 if(is_client_tagged(c, tags->tab[i]))
469 break;
471 /* if no tag, set current selected */
472 if(i == tags->len)
473 for(i = 0; i < tags->len; i++)
474 if(tags->tab[i]->selected)
475 tag_client(c, tags->tab[i]);
478 /* Push client in client list */
479 client_list_push(&globalconf.clients, client_ref(&c));
481 /* Push client in stack */
482 client_raise(c);
484 /* update window title */
485 property_update_wm_name(c);
486 property_update_wm_icon_name(c);
488 /* update strut */
489 ewmh_client_strut_update(c, NULL);
491 ewmh_update_net_client_list(c->phys_screen);
493 /* Call hook to notify list change */
494 luaA_dofunction(globalconf.L, globalconf.hooks.clients, 0, 0);
496 /* call hook */
497 luaA_client_userdata_new(globalconf.L, c);
498 luaA_dofunction(globalconf.L, globalconf.hooks.manage, 1, 0);
501 /** Compute client geometry with respect to its geometry hints.
502 * \param c The client.
503 * \param geometry The geometry that the client might receive.
504 * \return The geometry the client must take respecting its hints.
506 area_t
507 client_geometry_hints(client_t *c, area_t geometry)
509 double dx, dy, max, min, ratio;
511 if(c->minay > 0 && c->maxay > 0 && (geometry.height - c->baseh) > 0
512 && (geometry.width - c->basew) > 0)
514 dx = (double) (geometry.width - c->basew);
515 dy = (double) (geometry.height - c->baseh);
516 min = (double) (c->minax) / (double) (c->minay);
517 max = (double) (c->maxax) / (double) (c->maxay);
518 ratio = dx / dy;
519 if(max > 0 && min > 0 && ratio > 0)
521 if(ratio < min)
523 dy = (dx * min + dy) / (min * min + 1);
524 dx = dy * min;
525 geometry.width = (int) dx + c->basew;
526 geometry.height = (int) dy + c->baseh;
528 else if(ratio > max)
530 dy = (dx * min + dy) / (max * max + 1);
531 dx = dy * min;
532 geometry.width = (int) dx + c->basew;
533 geometry.height = (int) dy + c->baseh;
537 if(c->minw && geometry.width < c->minw)
538 geometry.width = c->minw;
539 if(c->minh && geometry.height < c->minh)
540 geometry.height = c->minh;
541 if(c->maxw && geometry.width > c->maxw)
542 geometry.width = c->maxw;
543 if(c->maxh && geometry.height > c->maxh)
544 geometry.height = c->maxh;
545 if(c->incw)
546 geometry.width -= (geometry.width - c->basew) % c->incw;
547 if(c->inch)
548 geometry.height -= (geometry.height - c->baseh) % c->inch;
550 return geometry;
553 /** Resize client window.
554 * \param c Client to resize.
555 * \param geometry New window geometry.
556 * \param hints Use size hints.
558 void
559 client_resize(client_t *c, area_t geometry, bool hints)
561 int new_screen;
562 area_t area;
563 layout_t *layout = layout_get_current(c->screen);
565 if(c->titlebar && !c->ismoving && c->titlebar->isvisible && !client_isfloating(c) && layout != layout_floating)
566 geometry = titlebar_geometry_remove(c->titlebar, c->border, geometry);
568 if(hints)
569 geometry = client_geometry_hints(c, geometry);
571 if(geometry.width <= 0 || geometry.height <= 0)
572 return;
574 /* offscreen appearance fixes */
575 area = display_area_get(c->phys_screen, NULL,
576 &globalconf.screens[c->screen].padding);
578 if(geometry.x > area.width)
579 geometry.x = area.width - geometry.width - 2 * c->border;
580 if(geometry.y > area.height)
581 geometry.y = area.height - geometry.height - 2 * c->border;
582 if(geometry.x + geometry.width + 2 * c->border < 0)
583 geometry.x = 0;
584 if(geometry.y + geometry.height + 2 * c->border < 0)
585 geometry.y = 0;
587 if(c->geometry.x != geometry.x
588 || c->geometry.y != geometry.y
589 || c->geometry.width != geometry.width
590 || c->geometry.height != geometry.height)
592 new_screen = screen_getbycoord(c->screen, geometry.x, geometry.y);
594 /* Values to configure a window is an array where values are
595 * stored according to 'value_mask' */
596 uint32_t values[4];
598 c->geometry.x = values[0] = geometry.x;
599 c->geometry.y = values[1] = geometry.y;
600 c->geometry.width = values[2] = geometry.width;
601 c->geometry.height = values[3] = geometry.height;
603 /* save the floating geometry if the window is floating but not
604 * maximized */
605 if(c->ismoving || client_isfloating(c)
606 || layout_get_current(new_screen) == layout_floating
607 || layout_get_current(c->screen) == layout_floating)
608 if(!c->isfullscreen)
609 c->f_geometry = geometry;
611 titlebar_update_geometry_floating(c);
613 xcb_configure_window(globalconf.connection, c->win,
614 XCB_CONFIG_WINDOW_X | XCB_CONFIG_WINDOW_Y
615 | XCB_CONFIG_WINDOW_WIDTH | XCB_CONFIG_WINDOW_HEIGHT,
616 values);
617 window_configure(c->win, geometry, c->border);
619 if(c->screen != new_screen)
620 screen_client_moveto(c, new_screen, true, false);
622 /* execute hook */
623 hooks_property(c, "geometry");
627 /** Set a client floating.
628 * \param c The client.
629 * \param floating Set floating, or not.
630 * \param layer Layer to put the floating window onto.
632 void
633 client_setfloating(client_t *c, bool floating)
635 if(c->isfloating != floating
636 && (c->type == WINDOW_TYPE_NORMAL))
638 if((c->isfloating = floating))
639 if(!c->isfullscreen)
640 client_resize(c, c->f_geometry, false);
641 client_need_arrange(c);
642 client_stack();
643 xcb_change_property(globalconf.connection,
644 XCB_PROP_MODE_REPLACE,
645 c->win, _AWESOME_FLOATING, CARDINAL, 8, 1,
646 &c->isfloating);
647 /* execute hook */
648 hooks_property(c, "floating");
652 /** Set a client minimized, or not.
653 * \param c The client.
654 * \param s Set or not the client minimized.
656 void
657 client_setminimized(client_t *c, bool s)
659 if(c->isminimized != s)
661 client_need_arrange(c);
662 c->isminimized = s;
663 client_need_arrange(c);
664 ewmh_client_update_hints(c);
665 /* execute hook */
666 hooks_property(c, "minimized");
670 /** Set a client sticky, or not.
671 * \param c The client.
672 * \param s Set or not the client sticky.
674 void
675 client_setsticky(client_t *c, bool s)
677 if(c->issticky != s)
679 client_need_arrange(c);
680 c->issticky = s;
681 client_need_arrange(c);
682 ewmh_client_update_hints(c);
683 hooks_property(c, "sticky");
687 /** Set a client fullscreen, or not.
688 * \param c The client.
689 * \param s Set or not the client fullscreen.
691 void
692 client_setfullscreen(client_t *c, bool s)
694 if(c->isfullscreen != s)
696 area_t geometry;
698 /* become fullscreen! */
699 if((c->isfullscreen = s))
701 geometry = screen_area_get(c->screen, NULL, NULL, false);
702 c->m_geometry = c->geometry;
703 c->oldborder = c->border;
704 client_setborder(c, 0);
706 else
708 geometry = c->m_geometry;
709 client_setborder(c, c->oldborder);
711 client_resize(c, geometry, false);
712 client_need_arrange(c);
713 client_stack();
714 xcb_change_property(globalconf.connection,
715 XCB_PROP_MODE_REPLACE,
716 c->win, _AWESOME_FULLSCREEN, CARDINAL, 8, 1,
717 &c->isfullscreen);
718 ewmh_client_update_hints(c);
719 hooks_property(c, "fullscreen");
723 /** Set a client above, or not.
724 * \param c The client.
725 * \param s Set or not the client above.
727 void
728 client_setabove(client_t *c, bool s)
730 if(c->isabove != s)
732 c->isabove = s;
733 client_stack();
734 ewmh_client_update_hints(c);
735 /* execute hook */
736 hooks_property(c, "above");
740 /** Set a client below, or not.
741 * \param c The client.
742 * \param s Set or not the client below.
744 void
745 client_setbelow(client_t *c, bool s)
747 if(c->isbelow != s)
749 c->isbelow = s;
750 client_stack();
751 ewmh_client_update_hints(c);
752 /* execute hook */
753 hooks_property(c, "below");
757 /** Set a client modal, or not.
758 * \param c The client.
759 * \param s Set or not the client moda.
761 void
762 client_setmodal(client_t *c, bool s)
764 if(c->ismodal != s)
766 c->ismodal = s;
767 client_stack();
768 ewmh_client_update_hints(c);
769 /* execute hook */
770 hooks_property(c, "modal");
774 /** Set a client ontop, or not.
775 * \param c The client.
776 * \param s Set or not the client moda.
778 void
779 client_setontop(client_t *c, bool s)
781 if(c->isontop != s)
783 c->isontop = s;
784 client_stack();
785 /* execute hook */
786 hooks_property(c, "ontop");
790 /** Save client properties as an X property.
791 * \param c The client.
793 void
794 client_saveprops_tags(client_t *c)
796 tag_array_t *tags = &globalconf.screens[c->screen].tags;
797 unsigned char *prop = p_alloca(unsigned char, tags->len + 1);
798 int i;
800 for(i = 0; i < tags->len; i++)
801 prop[i] = is_client_tagged(c, tags->tab[i]) ? '1' : '0';
803 xcb_change_property(globalconf.connection, XCB_PROP_MODE_REPLACE, c->win, _AWESOME_TAGS, STRING, 8, i, prop);
806 /** Unban a client.
807 * \param c The client.
809 void
810 client_unban(client_t *c)
812 xcb_map_window(globalconf.connection, c->win);
813 window_state_set(c->win, XCB_WM_STATE_NORMAL);
814 if(c->titlebar)
816 if(c->isfullscreen || !c->titlebar->isvisible)
817 xcb_unmap_window(globalconf.connection, c->titlebar->sw.window);
818 else
819 xcb_map_window(globalconf.connection, c->titlebar->sw.window);
823 /** Unmanage a client.
824 * \param c The client.
826 void
827 client_unmanage(client_t *c)
829 tag_array_t *tags = &globalconf.screens[c->screen].tags;
831 if(globalconf.screens[c->phys_screen].client_focus == c)
832 client_unfocus(c);
834 /* remove client everywhere */
835 client_list_detach(&globalconf.clients, c);
836 stack_client_delete(c);
837 for(int i = 0; i < tags->len; i++)
838 untag_client(c, tags->tab[i]);
840 /* call hook */
841 luaA_client_userdata_new(globalconf.L, c);
842 luaA_dofunction(globalconf.L, globalconf.hooks.unmanage, 1, 0);
844 /* Call hook to notify list change */
845 luaA_dofunction(globalconf.L, globalconf.hooks.clients, 0, 0);
847 /* The server grab construct avoids race conditions. */
848 xcb_grab_server(globalconf.connection);
850 xcb_configure_window(globalconf.connection, c->win,
851 XCB_CONFIG_WINDOW_BORDER_WIDTH,
852 (uint32_t *) &c->oldborder);
854 xcb_ungrab_button(globalconf.connection, XCB_BUTTON_INDEX_ANY, c->win,
855 XCB_BUTTON_MASK_ANY);
856 window_state_set(c->win, XCB_WM_STATE_WITHDRAWN);
858 xcb_flush(globalconf.connection);
859 xcb_ungrab_server(globalconf.connection);
861 titlebar_client_detach(c);
863 ewmh_update_net_client_list(c->phys_screen);
865 /* delete properties */
866 xcb_delete_property(globalconf.connection, c->win, _AWESOME_TAGS);
867 xcb_delete_property(globalconf.connection, c->win, _AWESOME_FLOATING);
869 if(client_hasstrut(c))
870 /* All the wiboxes (may) need to be repositioned */
871 for(int screen = 0; screen < globalconf.nscreen; screen++)
872 for(int i = 0; i < globalconf.screens[screen].wiboxes.len; i++)
874 wibox_t *s = globalconf.screens[screen].wiboxes.tab[i];
875 wibox_position_update(s);
878 /* set client as invalid */
879 c->invalid = true;
881 client_unref(&c);
884 /** Kill a client via a WM_DELETE_WINDOW request or KillClient if not
885 * supported.
886 * \param c The client to kill.
888 void
889 client_kill(client_t *c)
891 if(window_hasproto(c->win, WM_DELETE_WINDOW))
893 xcb_client_message_event_t ev;
895 /* Initialize all of event's fields first */
896 p_clear(&ev, 1);
898 ev.response_type = XCB_CLIENT_MESSAGE;
899 ev.window = c->win;
900 ev.format = 32;
901 ev.data.data32[1] = XCB_CURRENT_TIME;
902 ev.type = WM_PROTOCOLS;
903 ev.data.data32[0] = WM_DELETE_WINDOW;
905 xcb_send_event(globalconf.connection, false, c->win,
906 XCB_EVENT_MASK_NO_EVENT, (char *) &ev);
908 else
909 xcb_kill_client(globalconf.connection, c->win);
912 /** Get all clients into a table.
913 * \param L The Lua VM state.
914 * \return The number of elements pushed on stack.
915 * \luastack
916 * \lparam An optional screen nunmber.
917 * \lreturn A table with all clients.
919 static int
920 luaA_client_get(lua_State *L)
922 int i = 1, screen;
923 client_t *c;
925 screen = luaL_optnumber(L, 1, 0) - 1;
927 lua_newtable(L);
929 if(screen == SCREEN_UNDEF)
930 for(c = globalconf.clients; c; c = c->next)
932 luaA_client_userdata_new(globalconf.L, c);
933 lua_rawseti(L, -2, i++);
935 else
937 luaA_checkscreen(screen);
938 for(c = globalconf.clients; c; c = c->next)
939 if(c->screen == screen)
941 luaA_client_userdata_new(globalconf.L, c);
942 lua_rawseti(L, -2, i++);
946 return 1;
949 /** Get only visible clients for a screen (DEPRECATED).
950 * \param L The Lua VM state.
951 * \return The number of elements pushed on stack.
952 * \luastack
953 * \lparam A screen number.
954 * \lreturn A table with all visible clients for this screen.
956 static int
957 luaA_client_visible_get(lua_State *L)
959 int i = 1;
960 client_t *c;
961 int screen = luaL_checknumber(L, 1) - 1;
963 luaA_checkscreen(screen);
965 deprecate(L, "awful.client.visible()");
967 lua_newtable(L);
969 for(c = globalconf.clients; c; c = c->next)
970 if(client_isvisible(c, screen))
972 luaA_client_userdata_new(L, c);
973 lua_rawseti(L, -2, i++);
976 return 1;
979 /** Check if a client is visible on its screen.
980 * \param L The Lua VM state.
981 * \return The number of elements pushed on stack.
982 * \luastack
983 * \lvalue A client.
984 * \lreturn A boolean value, true if the client is visible, false otherwise.
986 static int
987 luaA_client_isvisible(lua_State *L)
989 client_t **c = luaA_checkudata(L, 1, "client");
990 lua_pushboolean(L, client_isvisible(*c, (*c)->screen));
991 return 1;
994 /** Set client border width.
995 * \param c The client.
996 * \param width The border width.
998 void
999 client_setborder(client_t *c, int width)
1001 uint32_t w = width;
1003 if(width > 0 && (c->type == WINDOW_TYPE_DOCK
1004 || c->type == WINDOW_TYPE_SPLASH
1005 || c->type == WINDOW_TYPE_DESKTOP
1006 || c->isfullscreen))
1007 return;
1009 if(width == c->border || width < 0)
1010 return;
1012 c->border = width;
1013 xcb_configure_window(globalconf.connection, c->win,
1014 XCB_CONFIG_WINDOW_BORDER_WIDTH, &w);
1016 if(client_isvisible(c, c->screen))
1018 if(client_isfloating(c) || layout_get_current(c->screen) == layout_floating)
1019 titlebar_update_geometry_floating(c);
1020 else
1021 globalconf.screens[c->screen].need_arrange = true;
1024 hooks_property(c, "border_width");
1027 /** Kill a client.
1028 * \param L The Lua VM state.
1030 * \luastack
1031 * \lvalue A client.
1033 static int
1034 luaA_client_kill(lua_State *L)
1036 client_t **c = luaA_checkudata(L, 1, "client");
1037 client_kill(*c);
1038 return 0;
1041 /** Swap a client with another one.
1042 * \param L The Lua VM state.
1043 * \luastack
1044 * \lvalue A client.
1045 * \lparam A client to swap with.
1047 static int
1048 luaA_client_swap(lua_State *L)
1050 client_t **c = luaA_checkudata(L, 1, "client");
1051 client_t **swap = luaA_checkudata(L, 2, "client");
1052 client_list_swap(&globalconf.clients, *swap, *c);
1053 client_need_arrange(*c);
1054 client_need_arrange(*swap);
1056 /* Call hook to notify list change */
1057 luaA_dofunction(L, globalconf.hooks.clients, 0, 0);
1059 return 0;
1062 /** Access or set the client tags.
1063 * \param L The Lua VM state.
1064 * \return The number of elements pushed on stack.
1065 * \lparam A table with tags to set, or none to get the current tags table.
1066 * \return The clients tag.
1068 static int
1069 luaA_client_tags(lua_State *L)
1071 tag_array_t *tags;
1072 tag_t **tag;
1073 client_t **c = luaA_checkudata(L, 1, "client");
1074 int j = 0;
1076 if(lua_gettop(L) == 2)
1078 luaA_checktable(L, 2);
1079 tags = &globalconf.screens[(*c)->screen].tags;
1080 for(int i = 0; i < tags->len; i++)
1081 untag_client(*c, tags->tab[i]);
1082 lua_pushnil(L);
1083 while(lua_next(L, 2))
1085 tag = luaA_checkudata(L, -1, "tag");
1086 tag_client(*c, *tag);
1087 lua_pop(L, 1);
1089 lua_pop(L, 1);
1092 tags = &globalconf.screens[(*c)->screen].tags;
1093 luaA_otable_new(L);
1094 for(int i = 0; i < tags->len; i++)
1095 if(is_client_tagged(*c, tags->tab[i]))
1097 luaA_tag_userdata_new(L, tags->tab[i]);
1098 lua_rawseti(L, -2, ++j);
1101 return 1;
1104 /** Raise a client on top of others which are on the same layer.
1105 * \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 /** Lower a client on bottom of others which are on the same layer.
1118 * \param L The Lua VM state.
1119 * \luastack
1120 * \lvalue A client.
1122 static int
1123 luaA_client_lower(lua_State *L)
1125 client_t **c = luaA_checkudata(L, 1, "client");
1126 client_lower(*c);
1127 return 0;
1130 /** Redraw a client by unmapping and mapping it quickly.
1131 * \param L The Lua VM state.
1133 * \luastack
1134 * \lvalue A client.
1136 static int
1137 luaA_client_redraw(lua_State *L)
1139 client_t **c = luaA_checkudata(L, 1, "client");
1141 xcb_unmap_window(globalconf.connection, (*c)->win);
1142 xcb_map_window(globalconf.connection, (*c)->win);
1144 /* Set the focus on the current window if the redraw has been
1145 performed on the window where the pointer is currently on
1146 because after the unmapping/mapping, the focus is lost */
1147 if(globalconf.screen_focus->client_focus == *c)
1148 xcb_set_input_focus(globalconf.connection, XCB_INPUT_FOCUS_POINTER_ROOT,
1149 (*c)->win, XCB_CURRENT_TIME);
1151 return 0;
1154 /** Stop managing a client.
1155 * \param L The Lua VM state.
1156 * \return The number of elements pushed on stack.
1157 * \luastack
1158 * \lvalue A client.
1160 static int
1161 luaA_client_unmanage(lua_State *L)
1163 client_t **c = luaA_checkudata(L, 1, "client");
1164 client_unmanage(*c);
1165 return 0;
1168 /** Return client geometry.
1169 * \param L The Lua VM state.
1170 * \param full Use titlebar also.
1171 * \return The number of elements pushed on stack.
1173 static int
1174 luaA_client_handlegeom(lua_State *L, bool full)
1176 client_t **c = luaA_checkudata(L, 1, "client");
1178 if(lua_gettop(L) == 2)
1179 if(client_isfloating(*c)
1180 || layout_get_current((*c)->screen) == layout_floating)
1182 area_t geometry;
1184 luaA_checktable(L, 2);
1185 geometry.x = luaA_getopt_number(L, 2, "x", (*c)->geometry.x);
1186 geometry.y = luaA_getopt_number(L, 2, "y", (*c)->geometry.y);
1187 if(client_isfixed(*c))
1189 geometry.width = (*c)->geometry.width;
1190 geometry.height = (*c)->geometry.height;
1192 else
1194 geometry.width = luaA_getopt_number(L, 2, "width", (*c)->geometry.width);
1195 geometry.height = luaA_getopt_number(L, 2, "height", (*c)->geometry.height);
1197 if(full)
1198 geometry = titlebar_geometry_remove((*c)->titlebar,
1199 (*c)->border,
1200 geometry);
1201 client_resize(*c, geometry, (*c)->honorsizehints);
1204 if(full)
1205 return luaA_pusharea(L, titlebar_geometry_add((*c)->titlebar,
1206 (*c)->border,
1207 (*c)->geometry));
1209 return luaA_pusharea(L, (*c)->geometry);
1212 /** Return client geometry.
1213 * \param L The Lua VM state.
1214 * \return The number of elements pushed on stack.
1215 * \luastack
1216 * \lparam A table with new coordinates, or none.
1217 * \lreturn A table with client coordinates.
1219 static int
1220 luaA_client_geometry(lua_State *L)
1222 return luaA_client_handlegeom(L, false);
1225 static int
1226 luaA_client_coords(lua_State *L)
1228 deprecate(L, "client:geometry()");
1229 return luaA_client_geometry(L);
1232 /** Return client geometry, using also titlebar and border width.
1233 * \param L The Lua VM state.
1234 * \return The number of elements pushed on stack.
1235 * \luastack
1236 * \lparam A table with new coordinates, or none.
1237 * \lreturn A table with client coordinates.
1239 static int
1240 luaA_client_fullgeometry(lua_State *L)
1242 return luaA_client_handlegeom(L, true);
1245 static int
1246 luaA_client_fullcoords(lua_State *L)
1248 deprecate(L, "client:fullgeometry()");
1249 return luaA_client_fullgeometry(L);
1252 /** Client newindex.
1253 * \param L The Lua VM state.
1254 * \return The number of elements pushed on stack.
1257 luaA_client_newindex(lua_State *L)
1259 size_t len;
1260 client_t **c = luaA_checkudata(L, 1, "client");
1261 const char *buf = luaL_checklstring(L, 2, &len);
1262 bool b;
1263 double d;
1264 int i;
1265 wibox_t **t = NULL;
1266 image_t **image;
1268 if((*c)->invalid)
1269 luaL_error(L, "client is invalid\n");
1271 switch(a_tokenize(buf, len))
1273 case A_TK_SCREEN:
1274 if(globalconf.xinerama_is_active)
1276 i = luaL_checknumber(L, 3) - 1;
1277 luaA_checkscreen(i);
1278 if(i != (*c)->screen)
1279 screen_client_moveto(*c, i, true, true);
1281 break;
1282 case A_TK_HIDE:
1283 b = luaA_checkboolean(L, 3);
1284 if(b != (*c)->ishidden)
1286 client_need_arrange(*c);
1287 (*c)->ishidden = b;
1288 client_need_arrange(*c);
1290 break;
1291 case A_TK_MINIMIZE:
1292 client_setminimized(*c, luaA_checkboolean(L, 3));
1293 break;
1294 case A_TK_FULLSCREEN:
1295 client_setfullscreen(*c, luaA_checkboolean(L, 3));
1296 break;
1297 case A_TK_ICON:
1298 image = luaA_checkudata(L, 3, "image");
1299 image_unref(&(*c)->icon);
1300 image_ref(image);
1301 (*c)->icon = *image;
1302 /* execute hook */
1303 hooks_property(*c, "icon");
1304 break;
1305 case A_TK_OPACITY:
1306 if(lua_isnil(L, 3))
1307 window_opacity_set((*c)->win, -1);
1308 else
1310 d = luaL_checknumber(L, 3);
1311 if(d >= 0 && d <= 1)
1312 window_opacity_set((*c)->win, d);
1314 break;
1315 case A_TK_FLOATING:
1316 client_setfloating(*c, luaA_checkboolean(L, 3));
1317 break;
1318 case A_TK_STICKY:
1319 client_setsticky(*c, luaA_checkboolean(L, 3));
1320 break;
1321 case A_TK_HONORSIZEHINTS:
1322 (*c)->honorsizehints = luaA_checkboolean(L, 3);
1323 client_need_arrange(*c);
1324 break;
1325 case A_TK_BORDER_WIDTH:
1326 client_setborder(*c, luaL_checknumber(L, 3));
1327 break;
1328 case A_TK_ONTOP:
1329 client_setontop(*c, luaA_checkboolean(L, 3));
1330 break;
1331 case A_TK_BORDER_COLOR:
1332 if((buf = luaL_checklstring(L, 3, &len))
1333 && xcolor_init_reply(xcolor_init_unchecked(&(*c)->border_color, buf, len)))
1334 xcb_change_window_attributes(globalconf.connection, (*c)->win,
1335 XCB_CW_BORDER_PIXEL, &(*c)->border_color.pixel);
1336 break;
1337 case A_TK_TITLEBAR:
1338 if(lua_isnil(L, 3))
1339 titlebar_client_detach(*c);
1340 else
1342 t = luaA_checkudata(L, 3, "wibox");
1343 titlebar_client_attach(*c, *t);
1345 break;
1346 default:
1347 return 0;
1350 return 0;
1353 /** Client object.
1354 * \param L The Lua VM state.
1355 * \return The number of elements pushed on stack.
1356 * \luastack
1357 * \lfield name The client title.
1358 * \lfield skip_taskbar True if the client does not want to be in taskbar.
1359 * \lfield type The window type (desktop, normal, dock, …).
1360 * \lfield class The client class.
1361 * \lfield instance The client instance.
1362 * \lfield pid The client PID, if available.
1363 * \lfield role The window role, if available.
1364 * \lfield machine The machine client is running on.
1365 * \lfield icon_name The client name when iconified.
1366 * \lfield screen Client screen number.
1367 * \lfield hide Define if the client must be hidden, i.e. never mapped,
1368 * invisible in taskbar.
1369 * \lfield minimize Define it the client must be iconify, i.e. only visible in
1370 * taskbar.
1371 * \lfield icon_path Path to the icon used to identify.
1372 * \lfield floating True always floating.
1373 * \lfield honorsizehints Honor size hints, i.e. respect size ratio.
1374 * \lfield border_width The client border width.
1375 * \lfield border_color The client border color.
1376 * \lfield titlebar The client titlebar.
1377 * \lfield urgent The client urgent state.
1378 * \lfield focus The focused client.
1379 * \lfield opacity The client opacity between 0 and 1.
1380 * \lfield ontop The client is on top of every other windows.
1381 * \lfield fullscreen The client is fullscreen or not.
1382 * \lfield transient_for Return the client the window is transient for.
1383 * \lfield size_hints A table with size hints of the client: user_position,
1384 * user_size, program_position and program_size.
1386 static int
1387 luaA_client_index(lua_State *L)
1389 size_t len;
1390 ssize_t slen;
1391 client_t **c = luaA_checkudata(L, 1, "client");
1392 const char *buf = luaL_checklstring(L, 2, &len);
1393 char *value;
1394 void *data;
1395 xcb_get_wm_class_reply_t hint;
1396 xcb_get_property_cookie_t prop_c;
1397 xcb_get_property_reply_t *prop_r = NULL;
1398 double d;
1400 if((*c)->invalid)
1401 luaL_error(L, "client is invalid\n");
1403 if(luaA_usemetatable(L, 1, 2))
1404 return 1;
1406 switch(a_tokenize(buf, len))
1408 case A_TK_NAME:
1409 lua_pushstring(L, (*c)->name);
1410 break;
1411 case A_TK_TRANSIENT_FOR:
1412 if((*c)->transient_for)
1413 return luaA_client_userdata_new(L, (*c)->transient_for);
1414 case A_TK_SKIP_TASKBAR:
1415 lua_pushboolean(L, (*c)->skiptb);
1416 break;
1417 case A_TK_TYPE:
1418 switch((*c)->type)
1420 case WINDOW_TYPE_DESKTOP:
1421 lua_pushliteral(L, "desktop");
1422 break;
1423 case WINDOW_TYPE_DOCK:
1424 lua_pushliteral(L, "dock");
1425 break;
1426 case WINDOW_TYPE_SPLASH:
1427 lua_pushliteral(L, "splash");
1428 break;
1429 case WINDOW_TYPE_DIALOG:
1430 lua_pushliteral(L, "dialog");
1431 break;
1432 default:
1433 lua_pushliteral(L, "normal");
1434 break;
1436 break;
1437 case A_TK_CLASS:
1438 if(!xcb_get_wm_class_reply(globalconf.connection,
1439 xcb_get_wm_class_unchecked(globalconf.connection, (*c)->win),
1440 &hint, NULL))
1441 return 0;
1442 lua_pushstring(L, hint.class);
1443 xcb_get_wm_class_reply_wipe(&hint);
1444 break;
1445 case A_TK_INSTANCE:
1446 if(!xcb_get_wm_class_reply(globalconf.connection,
1447 xcb_get_wm_class_unchecked(globalconf.connection, (*c)->win),
1448 &hint, NULL))
1449 return 0;
1450 lua_pushstring(L, hint.name);
1451 xcb_get_wm_class_reply_wipe(&hint);
1452 break;
1453 case A_TK_ROLE:
1454 if(!xutil_text_prop_get(globalconf.connection, (*c)->win,
1455 WM_WINDOW_ROLE, &value, &slen))
1456 return 0;
1457 lua_pushlstring(L, value, slen);
1458 p_delete(&value);
1459 break;
1460 case A_TK_PID:
1461 prop_c = xcb_get_property_unchecked(globalconf.connection, false, (*c)->win, _NET_WM_PID, CARDINAL, 0L, 1L);
1462 prop_r = xcb_get_property_reply(globalconf.connection, prop_c, NULL);
1464 if(prop_r && prop_r->value_len && (data = xcb_get_property_value(prop_r)))
1465 lua_pushnumber(L, *(uint32_t *)data);
1466 else
1468 p_delete(&prop_r);
1469 return 0;
1471 break;
1472 case A_TK_MACHINE:
1473 if(!xutil_text_prop_get(globalconf.connection, (*c)->win,
1474 WM_CLIENT_MACHINE, &value, &slen))
1475 return 0;
1476 lua_pushlstring(L, value, slen);
1477 p_delete(&value);
1478 break;
1479 case A_TK_ICON_NAME:
1480 lua_pushstring(L, (*c)->icon_name);
1481 break;
1482 case A_TK_SCREEN:
1483 lua_pushnumber(L, 1 + (*c)->screen);
1484 break;
1485 case A_TK_HIDE:
1486 lua_pushboolean(L, (*c)->ishidden);
1487 break;
1488 case A_TK_MINIMIZE:
1489 lua_pushboolean(L, (*c)->isminimized);
1490 break;
1491 case A_TK_FULLSCREEN:
1492 lua_pushboolean(L, (*c)->isfullscreen);
1493 break;
1494 case A_TK_ICON:
1495 if((*c)->icon)
1496 luaA_image_userdata_new(L, (*c)->icon);
1497 else
1498 return 0;
1499 break;
1500 case A_TK_OPACITY:
1501 if((d = window_opacity_get((*c)->win)) >= 0)
1502 lua_pushnumber(L, d);
1503 else
1504 return 0;
1505 break;
1506 case A_TK_FLOATING:
1507 lua_pushboolean(L, client_isfloating(*c));
1508 break;
1509 case A_TK_ONTOP:
1510 lua_pushboolean(L, (*c)->isontop);
1511 break;
1512 case A_TK_STICKY:
1513 lua_pushboolean(L, (*c)->issticky);
1514 break;
1515 case A_TK_HONORSIZEHINTS:
1516 lua_pushboolean(L, (*c)->honorsizehints);
1517 break;
1518 case A_TK_BORDER_WIDTH:
1519 lua_pushnumber(L, (*c)->border);
1520 break;
1521 case A_TK_BORDER_COLOR:
1522 luaA_pushcolor(L, &(*c)->border_color);
1523 break;
1524 case A_TK_TITLEBAR:
1525 if((*c)->titlebar)
1526 return luaA_wibox_userdata_new(L, (*c)->titlebar);
1527 return 0;
1528 case A_TK_URGENT:
1529 lua_pushboolean(L, (*c)->isurgent);
1530 break;
1531 case A_TK_SIZE_HINTS:
1532 lua_newtable(L);
1533 lua_pushboolean(L, (*c)->size_hints.flags & XCB_SIZE_HINT_US_POSITION);
1534 lua_setfield(L, -2, "user_position");
1535 lua_pushboolean(L, (*c)->size_hints.flags & XCB_SIZE_HINT_US_SIZE);
1536 lua_setfield(L, -2, "user_size");
1537 lua_pushboolean(L, (*c)->size_hints.flags & XCB_SIZE_HINT_P_POSITION);
1538 lua_setfield(L, -2, "program_position");
1539 lua_pushboolean(L, (*c)->size_hints.flags & XCB_SIZE_HINT_P_SIZE);
1540 lua_setfield(L, -2, "program_size");
1541 break;
1542 default:
1543 return 0;
1546 return 1;
1549 /** Get or set mouse buttons bindings for a client.
1550 * \param L The Lua VM state.
1551 * \return The number of element pushed on stack.
1552 * \luastack
1553 * \lvalue A client.
1554 * \lparam An array of mouse button bindings objects, or nothing.
1555 * \return The array of mouse button bindings objects of this client.
1557 static int
1558 luaA_client_buttons(lua_State *L)
1560 client_t **client = luaA_checkudata(L, 1, "client");
1561 button_array_t *buttons = &(*client)->buttons;
1563 if(lua_gettop(L) == 2)
1564 luaA_button_array_set(L, 2, buttons);
1566 return luaA_button_array_get(L, buttons);
1569 /* Client module.
1570 * \param L The Lua VM state.
1571 * \return The number of pushed elements.
1573 static int
1574 luaA_client_module_index(lua_State *L)
1576 size_t len;
1577 const char *buf = luaL_checklstring(L, 2, &len);
1579 switch(a_tokenize(buf, len))
1581 case A_TK_FOCUS:
1582 if(globalconf.screen_focus->client_focus)
1583 luaA_client_userdata_new(L, globalconf.screen_focus->client_focus);
1584 else
1585 return 0;
1586 break;
1587 default:
1588 return 0;
1591 return 1;
1594 /* Client module new index.
1595 * \param L The Lua VM state.
1596 * \return The number of pushed elements.
1598 static int
1599 luaA_client_module_newindex(lua_State *L)
1601 size_t len;
1602 const char *buf = luaL_checklstring(L, 2, &len);
1603 client_t **c;
1605 switch(a_tokenize(buf, len))
1607 case A_TK_FOCUS:
1608 c = luaA_checkudata(L, 3, "client");
1609 client_focus(*c);
1610 break;
1611 default:
1612 break;
1615 return 0;
1618 const struct luaL_reg awesome_client_methods[] =
1620 { "get", luaA_client_get },
1621 { "visible_get", luaA_client_visible_get },
1622 { "__index", luaA_client_module_index },
1623 { "__newindex", luaA_client_module_newindex },
1624 { NULL, NULL }
1626 const struct luaL_reg awesome_client_meta[] =
1628 { "isvisible", luaA_client_isvisible },
1629 { "geometry", luaA_client_geometry },
1630 { "fullgeometry", luaA_client_fullgeometry },
1631 { "buttons", luaA_client_buttons },
1632 { "tags", luaA_client_tags },
1633 { "kill", luaA_client_kill },
1634 { "swap", luaA_client_swap },
1635 { "raise", luaA_client_raise },
1636 { "lower", luaA_client_lower },
1637 { "redraw", luaA_client_redraw },
1638 { "mouse_resize", luaA_client_mouse_resize },
1639 { "mouse_move", luaA_client_mouse_move },
1640 { "unmanage", luaA_client_unmanage },
1641 { "__index", luaA_client_index },
1642 { "__newindex", luaA_client_newindex },
1643 { "__eq", luaA_client_eq },
1644 { "__gc", luaA_client_gc },
1645 { "__tostring", luaA_client_tostring },
1646 /* deprecated */
1647 { "coords", luaA_client_coords },
1648 { "fullcoords", luaA_client_fullcoords },
1649 { NULL, NULL }
1652 // vim: filetype=c:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=80