awsetbg: mkdir recursive
[awesome.git] / client.c
blob560c7a454ffaf791fd1ea819a7b2f5bc98e3f622
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 "image.h"
28 #include "client.h"
29 #include "tag.h"
30 #include "window.h"
31 #include "ewmh.h"
32 #include "widget.h"
33 #include "screen.h"
34 #include "titlebar.h"
35 #include "luaa.h"
36 #include "mouse.h"
37 #include "systray.h"
38 #include "wibox.h"
39 #include "property.h"
40 #include "layouts/floating.h"
41 #include "common/markup.h"
42 #include "common/atoms.h"
44 extern awesome_t globalconf;
46 /** Create a new client userdata.
47 * \param L The Lua VM state.
48 * \param p A client pointer.
49 * \param The number of elements pushed on the stack.
51 int
52 luaA_client_userdata_new(lua_State *L, client_t *p)
54 client_t **pp = lua_newuserdata(L, sizeof(client_t *));
55 *pp = p;
56 client_ref(pp);
57 return luaA_settype(L, "client");
60 DO_LUA_EQ(client_t, client, "client")
61 DO_LUA_GC(client_t, client, "client", client_unref)
63 /** Load windows properties, restoring client's tag
64 * and floating state before awesome was restarted if any.
65 * \param c A client pointer.
66 * \param screen A virtual screen.
67 * \return True if client had property, false otherwise.
69 static bool
70 client_loadprops(client_t * c, screen_t *screen)
72 ssize_t len;
73 tag_array_t *tags = &screen->tags;
74 char *prop = NULL;
75 xcb_get_property_cookie_t floating_q, fullscreen_q;
76 xcb_get_property_reply_t *reply;
77 void *data;
79 if(!xutil_text_prop_get(globalconf.connection, c->win, _AWESOME_TAGS,
80 &prop, &len))
81 return false;
83 /* Send the GetProperty requests which will be processed later */
84 floating_q = xcb_get_property_unchecked(globalconf.connection, false, c->win,
85 _AWESOME_FLOATING, CARDINAL, 0, 1);
87 fullscreen_q = xcb_get_property_unchecked(globalconf.connection, false, c->win,
88 _AWESOME_FULLSCREEN, CARDINAL, 0, 1);
90 /* ignore property if the tag count isn't matching */
91 if(len == tags->len)
92 for(int i = 0; i < tags->len; i++)
93 if(prop[i] == '1')
94 tag_client(c, tags->tab[i]);
95 else
96 untag_client(c, tags->tab[i]);
98 p_delete(&prop);
100 /* check for floating */
101 reply = xcb_get_property_reply(globalconf.connection, floating_q, NULL);
103 if(reply && reply->value_len && (data = xcb_get_property_value(reply)))
104 client_setfloating(c, *(bool *) data);
105 p_delete(&reply);
107 /* check for fullscreen */
108 reply = xcb_get_property_reply(globalconf.connection, fullscreen_q, NULL);
110 if(reply && reply->value_len && (data = xcb_get_property_value(reply)))
111 client_setfullscreen(c, *(bool *) data);
112 p_delete(&reply);
114 return true;
117 /** Check if client supports protocol WM_DELETE_WINDOW.
118 * \param win The window.
119 * \return True if client has WM_DELETE_WINDOW, false otherwise.
121 static bool
122 window_isprotodel(xcb_window_t win)
124 uint32_t i;
125 xcb_get_wm_protocols_reply_t protocols;
126 bool ret = false;
128 if(xcb_get_wm_protocols_reply(globalconf.connection,
129 xcb_get_wm_protocols_unchecked(globalconf.connection,
130 win, WM_PROTOCOLS),
131 &protocols, NULL))
133 for(i = 0; !ret && i < protocols.atoms_len; i++)
134 if(protocols.atoms[i] == WM_DELETE_WINDOW)
135 ret = true;
136 xcb_get_wm_protocols_reply_wipe(&protocols);
138 return ret;
141 /** Returns true if a client is tagged
142 * with one of the tags of the specified screen.
143 * \param c The client to check.
144 * \param screen Virtual screen number.
145 * \return true if the client is visible, false otherwise.
147 bool
148 client_maybevisible(client_t *c, int screen)
150 if(c->screen == screen)
152 if(c->issticky || c->type == WINDOW_TYPE_DESKTOP)
153 return true;
155 tag_array_t *tags = &globalconf.screens[screen].tags;
157 for(int i = 0; i < tags->len; i++)
158 if(tags->tab[i]->selected && is_client_tagged(c, tags->tab[i]))
159 return true;
161 return false;
164 /** Get a client by its window.
165 * \param w The client window to find.
166 * \return A client pointer if found, NULL otherwise.
168 client_t *
169 client_getbywin(xcb_window_t w)
171 client_t *c;
172 for(c = globalconf.clients; c && c->win != w; c = c->next);
173 return c;
176 /** Unfocus a client.
177 * \param c The client.
179 static void
180 client_unfocus(client_t *c)
182 globalconf.screens[c->phys_screen].client_focus = NULL;
184 /* Call hook */
185 luaA_client_userdata_new(globalconf.L, c);
186 luaA_dofunction(globalconf.L, globalconf.hooks.unfocus, 1, 0);
188 widget_invalidate_cache(c->screen, WIDGET_CACHE_CLIENTS);
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);
246 widget_invalidate_cache(c->screen, WIDGET_CACHE_CLIENTS);
249 /** Stack a window below.
250 * \param c The client.
251 * \param previous The previous window on the stack.
252 * \param return The next-previous!
254 static xcb_window_t
255 client_stack_below(client_t *c, xcb_window_t previous)
257 uint32_t config_win_vals[2];
259 config_win_vals[0] = previous;
260 config_win_vals[1] = XCB_STACK_MODE_BELOW;
262 if(c->titlebar)
264 xcb_configure_window(globalconf.connection,
265 c->titlebar->sw.window,
266 XCB_CONFIG_WINDOW_SIBLING | XCB_CONFIG_WINDOW_STACK_MODE,
267 config_win_vals);
268 config_win_vals[0] = c->titlebar->sw.window;
270 xcb_configure_window(globalconf.connection, c->win,
271 XCB_CONFIG_WINDOW_SIBLING | XCB_CONFIG_WINDOW_STACK_MODE,
272 config_win_vals);
273 config_win_vals[0] = c->win;
275 return c->win;
278 /** Get the real layer of a client according to its attribute (fullscreen, …)
279 * \param c The client.
280 * \return The real layer.
282 static layer_t
283 client_layer_translator(client_t *c)
285 if(c->isontop)
286 return LAYER_ONTOP;
287 else if(c->ismodal)
288 return LAYER_MODAL;
289 else if(c->isfullscreen)
290 return LAYER_FULLSCREEN;
291 else if(c->isabove)
292 return LAYER_ABOVE;
293 else if(c->isfloating)
294 return LAYER_FLOAT;
296 switch(c->type)
298 case WINDOW_TYPE_DOCK:
299 return LAYER_ABOVE;
300 case WINDOW_TYPE_SPLASH:
301 case WINDOW_TYPE_DIALOG:
302 return LAYER_ABOVE;
303 case WINDOW_TYPE_DESKTOP:
304 return LAYER_DESKTOP;
305 default:
306 return LAYER_TILE;
310 /** Restack clients.
311 * \todo It might be worth stopping to restack everyone and only stack `c'
312 * relatively to the first matching in the list.
314 void
315 client_stack()
317 uint32_t config_win_vals[2];
318 client_node_t *node;
319 layer_t layer;
320 int screen;
322 config_win_vals[0] = XCB_NONE;
323 config_win_vals[1] = XCB_STACK_MODE_BELOW;
325 /* first stack modal and fullscreen windows */
326 for(layer = LAYER_OUTOFSPACE - 1; layer >= LAYER_FULLSCREEN; layer--)
327 for(node = globalconf.stack; node; node = node->next)
328 if(client_layer_translator(node->client) == layer)
329 config_win_vals[0] = client_stack_below(node->client, config_win_vals[0]);
331 /* then stack ontop wibox window */
332 for(screen = 0; screen < globalconf.nscreen; screen++)
333 for(int i = 0; i < globalconf.screens[screen].wiboxes.len; i++)
335 wibox_t *sb = globalconf.screens[screen].wiboxes.tab[i];
336 if(sb->ontop)
338 xcb_configure_window(globalconf.connection,
339 sb->sw.window,
340 XCB_CONFIG_WINDOW_SIBLING | XCB_CONFIG_WINDOW_STACK_MODE,
341 config_win_vals);
342 config_win_vals[0] = sb->sw.window;
346 /* finally stack everything else */
347 for(layer = LAYER_FULLSCREEN - 1; layer >= LAYER_TILE; layer--)
348 for(node = globalconf.stack; node; node = node->next)
349 if(client_layer_translator(node->client) == layer)
350 config_win_vals[0] = client_stack_below(node->client, config_win_vals[0]);
352 /* then stack not ontop wibox window */
353 for(screen = 0; screen < globalconf.nscreen; screen++)
354 for(int i = 0; i < globalconf.screens[screen].wiboxes.len; i++)
356 wibox_t *sb = globalconf.screens[screen].wiboxes.tab[i];
357 if(!sb->ontop)
359 xcb_configure_window(globalconf.connection,
360 sb->sw.window,
361 XCB_CONFIG_WINDOW_SIBLING | XCB_CONFIG_WINDOW_STACK_MODE,
362 config_win_vals);
363 config_win_vals[0] = sb->sw.window;
367 /* finally stack everything else */
368 for(layer = LAYER_TILE - 1; layer >= LAYER_DESKTOP; layer--)
369 for(node = globalconf.stack; node; node = node->next)
370 if(client_layer_translator(node->client) == layer)
371 config_win_vals[0] = client_stack_below(node->client, config_win_vals[0]);
374 /** Manage a new client.
375 * \param w The window.
376 * \param wgeom Window geometry.
377 * \param phys_screen Physical screen number.
378 * \param screen Virtual screen number where to manage client.
380 void
381 client_manage(xcb_window_t w, xcb_get_geometry_reply_t *wgeom, int phys_screen, int screen)
383 xcb_get_property_cookie_t ewmh_icon_cookie;
384 client_t *c;
385 image_t *icon;
386 const uint32_t select_input_val[] =
388 XCB_EVENT_MASK_STRUCTURE_NOTIFY
389 | XCB_EVENT_MASK_PROPERTY_CHANGE
390 | XCB_EVENT_MASK_ENTER_WINDOW
393 /* Send request to get NET_WM_ICON property as soon as possible... */
394 ewmh_icon_cookie = ewmh_window_icon_get_unchecked(w);
395 xcb_change_window_attributes(globalconf.connection, w, XCB_CW_EVENT_MASK, select_input_val);
397 if(systray_iskdedockapp(w))
399 systray_request_handle(w, phys_screen, NULL);
400 return;
403 c = p_new(client_t, 1);
405 c->screen = screen_getbycoord(screen, wgeom->x, wgeom->y);
407 c->phys_screen = phys_screen;
409 /* Initial values */
410 c->win = w;
411 c->geometry.x = c->f_geometry.x = c->m_geometry.x = wgeom->x;
412 c->geometry.y = c->f_geometry.y = c->m_geometry.y = wgeom->y;
413 c->geometry.width = c->f_geometry.width = c->m_geometry.width = wgeom->width;
414 c->geometry.height = c->f_geometry.height = c->m_geometry.height = wgeom->height;
415 client_setborder(c, wgeom->border_width);
416 if((icon = ewmh_window_icon_get_reply(ewmh_icon_cookie)))
417 c->icon = image_ref(&icon);
419 /* we honor size hints by default */
420 c->honorsizehints = true;
422 /* update hints */
423 property_update_wm_normal_hints(c, NULL);
424 property_update_wm_hints(c, NULL);
425 property_update_wm_transient_for(c, NULL);
427 if(c->transient_for)
428 screen = c->transient_for->screen;
430 /* Try to load props if any */
431 client_loadprops(c, &globalconf.screens[screen]);
433 /* move client to screen, but do not tag it for now */
434 screen_client_moveto(c, screen, false, true);
436 /* Then check clients hints */
437 ewmh_client_check_hints(c);
439 /* Check if client has been tagged by loading props, or maybe with its
440 * hints.
441 * If not, we tag it with current selected ones.
442 * This could be done on Lua side, but it's a sane behaviour. */
443 if(!c->issticky)
445 int i;
446 tag_array_t *tags = &globalconf.screens[screen].tags;
447 for(i = 0; i < tags->len; i++)
448 if(is_client_tagged(c, tags->tab[i]))
449 break;
451 /* if no tag, set current selected */
452 if(i == tags->len)
453 for(i = 0; i < tags->len; i++)
454 if(tags->tab[i]->selected)
455 tag_client(c, tags->tab[i]);
458 /* Push client in client list */
459 client_list_push(&globalconf.clients, c);
460 client_ref(&c);
461 /* Push client in stack */
462 client_raise(c);
464 /* update window title */
465 property_update_wm_name(c);
467 /* update strut */
468 ewmh_client_strut_update(c, NULL);
470 ewmh_update_net_client_list(c->phys_screen);
471 widget_invalidate_cache(c->screen, WIDGET_CACHE_CLIENTS);
473 /* call hook */
474 luaA_client_userdata_new(globalconf.L, c);
475 luaA_dofunction(globalconf.L, globalconf.hooks.manage, 1, 0);
478 /** Compute client geometry with respect to its geometry hints.
479 * \param c The client.
480 * \param geometry The geometry that the client might receive.
481 * \return The geometry the client must take respecting its hints.
483 area_t
484 client_geometry_hints(client_t *c, area_t geometry)
486 double dx, dy, max, min, ratio;
488 if(c->minay > 0 && c->maxay > 0 && (geometry.height - c->baseh) > 0
489 && (geometry.width - c->basew) > 0)
491 dx = (double) (geometry.width - c->basew);
492 dy = (double) (geometry.height - c->baseh);
493 min = (double) (c->minax) / (double) (c->minay);
494 max = (double) (c->maxax) / (double) (c->maxay);
495 ratio = dx / dy;
496 if(max > 0 && min > 0 && ratio > 0)
498 if(ratio < min)
500 dy = (dx * min + dy) / (min * min + 1);
501 dx = dy * min;
502 geometry.width = (int) dx + c->basew;
503 geometry.height = (int) dy + c->baseh;
505 else if(ratio > max)
507 dy = (dx * min + dy) / (max * max + 1);
508 dx = dy * min;
509 geometry.width = (int) dx + c->basew;
510 geometry.height = (int) dy + c->baseh;
514 if(c->minw && geometry.width < c->minw)
515 geometry.width = c->minw;
516 if(c->minh && geometry.height < c->minh)
517 geometry.height = c->minh;
518 if(c->maxw && geometry.width > c->maxw)
519 geometry.width = c->maxw;
520 if(c->maxh && geometry.height > c->maxh)
521 geometry.height = c->maxh;
522 if(c->incw)
523 geometry.width -= (geometry.width - c->basew) % c->incw;
524 if(c->inch)
525 geometry.height -= (geometry.height - c->baseh) % c->inch;
527 return geometry;
530 /** Resize client window.
531 * \param c Client to resize.
532 * \param geometry New window geometry.
533 * \param hints Use size hints.
535 void
536 client_resize(client_t *c, area_t geometry, bool hints)
538 int new_screen;
539 area_t area;
540 layout_t *layout = layout_get_current(c->screen);
541 bool fixed;
542 /* Values to configure a window is an array where values are
543 * stored according to 'value_mask' */
544 uint32_t values[5];
546 if(c->titlebar && !c->ismoving && !client_isfloating(c) && layout != layout_floating)
547 geometry = titlebar_geometry_remove(c->titlebar, c->border, geometry);
549 if(hints)
550 geometry = client_geometry_hints(c, geometry);
552 if(geometry.width <= 0 || geometry.height <= 0)
553 return;
555 /* offscreen appearance fixes */
556 area = display_area_get(c->phys_screen, NULL,
557 &globalconf.screens[c->screen].padding);
559 fixed = client_isfixed(c);
561 if(geometry.x > area.width)
562 geometry.x = area.width - geometry.width - 2 * c->border;
563 if(geometry.y > area.height)
564 geometry.y = area.height - geometry.height - 2 * c->border;
565 if(geometry.x + geometry.width + 2 * c->border < 0)
566 geometry.x = 0;
567 if(geometry.y + geometry.height + 2 * c->border < 0)
568 geometry.y = 0;
570 /* fixed windows can only change their x,y */
571 if((fixed && (c->geometry.x != geometry.x || c->geometry.y != geometry.y))
572 || (!fixed && (c->geometry.x != geometry.x
573 || c->geometry.y != geometry.y
574 || c->geometry.width != geometry.width
575 || c->geometry.height != geometry.height)))
577 new_screen = screen_getbycoord(c->screen, geometry.x, geometry.y);
579 c->geometry.x = values[0] = geometry.x;
580 c->geometry.width = values[2] = geometry.width;
581 c->geometry.y = values[1] = geometry.y;
582 c->geometry.height = values[3] = geometry.height;
583 values[4] = c->border;
585 /* save the floating geometry if the window is floating but not
586 * maximized */
587 if(c->ismoving || client_isfloating(c)
588 || layout_get_current(new_screen) == layout_floating)
589 if(!c->isfullscreen)
590 c->f_geometry = geometry;
592 titlebar_update_geometry_floating(c);
594 xcb_configure_window(globalconf.connection, c->win,
595 XCB_CONFIG_WINDOW_X | XCB_CONFIG_WINDOW_Y |
596 XCB_CONFIG_WINDOW_WIDTH | XCB_CONFIG_WINDOW_HEIGHT |
597 XCB_CONFIG_WINDOW_BORDER_WIDTH,
598 values);
599 window_configure(c->win, geometry, c->border);
601 if(c->screen != new_screen)
602 screen_client_moveto(c, new_screen, true, false);
604 /* execute hook */
605 hooks_property(c, "geometry");
609 /** Set a clinet floating.
610 * \param c The client.
611 * \param floating Set floating, or not.
612 * \param layer Layer to put the floating window onto.
614 void
615 client_setfloating(client_t *c, bool floating)
617 if(c->isfloating != floating
618 && (c->type == WINDOW_TYPE_NORMAL))
620 if((c->isfloating = floating))
621 if(!c->isfullscreen)
622 client_resize(c, c->f_geometry, false);
623 client_need_arrange(c);
624 widget_invalidate_cache(c->screen, WIDGET_CACHE_CLIENTS);
625 client_stack();
626 xcb_change_property(globalconf.connection,
627 XCB_PROP_MODE_REPLACE,
628 c->win, _AWESOME_FLOATING, CARDINAL, 8, 1,
629 &c->isfloating);
630 /* execute hook */
631 hooks_property(c, "floating");
635 /** Set a client minimized, or not.
636 * \param c The client.
637 * \param s Set or not the client minimized.
639 void
640 client_setminimized(client_t *c, bool s)
642 if(c->isminimized != s)
644 client_need_arrange(c);
645 c->isminimized = s;
646 client_need_arrange(c);
647 ewmh_client_update_hints(c);
648 /* execute hook */
649 hooks_property(c, "minimized");
653 /** Set a client sticky, or not.
654 * \param c The client.
655 * \param s Set or not the client sticky.
657 void
658 client_setsticky(client_t *c, bool s)
660 if(c->issticky != s)
662 client_need_arrange(c);
663 c->issticky = s;
664 client_need_arrange(c);
665 ewmh_client_update_hints(c);
666 hooks_property(c, "sticky");
670 /** Set a client fullscreen, or not.
671 * \param c The client.
672 * \param s Set or not the client fullscreen.
674 void
675 client_setfullscreen(client_t *c, bool s)
677 if(c->isfullscreen != s)
679 area_t geometry;
681 /* become fullscreen! */
682 if((c->isfullscreen = s))
684 geometry = screen_area_get(c->screen, NULL, &globalconf.screens[c->screen].padding, false);
685 c->m_geometry = c->geometry;
686 c->oldborder = c->border;
687 client_setborder(c, 0);
689 else
691 geometry = c->m_geometry;
692 client_setborder(c, c->oldborder);
693 client_resize(c, c->m_geometry, false);
695 client_resize(c, geometry, false);
696 client_need_arrange(c);
697 client_stack();
698 xcb_change_property(globalconf.connection,
699 XCB_PROP_MODE_REPLACE,
700 c->win, _AWESOME_FULLSCREEN, CARDINAL, 8, 1,
701 &c->isfullscreen);
702 ewmh_client_update_hints(c);
703 hooks_property(c, "fullscreen");
707 /** Set a client above, or not.
708 * \param c The client.
709 * \param s Set or not the client above.
711 void
712 client_setabove(client_t *c, bool s)
714 if(c->isabove != s)
716 c->isabove = s;
717 client_stack();
718 ewmh_client_update_hints(c);
719 /* execute hook */
720 hooks_property(c, "above");
724 /** Set a client below, or not.
725 * \param c The client.
726 * \param s Set or not the client below.
728 void
729 client_setbelow(client_t *c, bool s)
731 if(c->isbelow != s)
733 c->isbelow = s;
734 client_stack();
735 ewmh_client_update_hints(c);
736 /* execute hook */
737 hooks_property(c, "below");
741 /** Set a client modal, or not.
742 * \param c The client.
743 * \param s Set or not the client moda.
745 void
746 client_setmodal(client_t *c, bool s)
748 if(c->ismodal != s)
750 c->ismodal = s;
751 client_stack();
752 ewmh_client_update_hints(c);
753 /* execute hook */
754 hooks_property(c, "modal");
758 /** Set a client ontop, or not.
759 * \param c The client.
760 * \param s Set or not the client moda.
762 void
763 client_setontop(client_t *c, bool s)
765 if(c->isontop != s)
767 c->isontop = s;
768 client_stack();
769 /* execute hook */
770 hooks_property(c, "ontop");
774 /** Save client properties as an X property.
775 * \param c The client.
777 void
778 client_saveprops_tags(client_t *c)
780 tag_array_t *tags = &globalconf.screens[c->screen].tags;
781 unsigned char *prop = p_alloca(unsigned char, tags->len + 1);
782 int i;
784 for(i = 0; i < tags->len; i++)
785 prop[i] = is_client_tagged(c, tags->tab[i]) ? '1' : '0';
787 xcb_change_property(globalconf.connection, XCB_PROP_MODE_REPLACE, c->win, _AWESOME_TAGS, STRING, 8, i, prop);
790 /** Unban a client.
791 * \param c The client.
793 void
794 client_unban(client_t *c)
796 xcb_map_window(globalconf.connection, c->win);
797 window_state_set(c->win, XCB_WM_STATE_NORMAL);
798 if(c->titlebar)
800 if(c->isfullscreen || !c->titlebar->isvisible)
801 xcb_unmap_window(globalconf.connection, c->titlebar->sw.window);
802 else
803 xcb_map_window(globalconf.connection, c->titlebar->sw.window);
807 /** Unmanage a client.
808 * \param c The client.
810 void
811 client_unmanage(client_t *c)
813 tag_array_t *tags = &globalconf.screens[c->screen].tags;
815 if(globalconf.screens[c->phys_screen].client_focus == c)
816 client_unfocus(c);
818 /* call hook */
819 luaA_client_userdata_new(globalconf.L, c);
820 luaA_dofunction(globalconf.L, globalconf.hooks.unmanage, 1, 0);
822 /* The server grab construct avoids race conditions. */
823 xcb_grab_server(globalconf.connection);
825 xcb_configure_window(globalconf.connection, c->win,
826 XCB_CONFIG_WINDOW_BORDER_WIDTH,
827 (uint32_t *) &c->oldborder);
829 xcb_ungrab_button(globalconf.connection, XCB_BUTTON_INDEX_ANY, c->win,
830 XCB_BUTTON_MASK_ANY);
831 window_state_set(c->win, XCB_WM_STATE_WITHDRAWN);
833 xcb_flush(globalconf.connection);
834 xcb_ungrab_server(globalconf.connection);
836 /* remove client everywhere */
837 client_list_detach(&globalconf.clients, c);
838 stack_client_delete(c);
839 for(int i = 0; i < tags->len; i++)
840 untag_client(c, tags->tab[i]);
842 titlebar_client_detach(c);
844 ewmh_update_net_client_list(c->phys_screen);
846 /* delete properties */
847 xcb_delete_property(globalconf.connection, c->win, _AWESOME_TAGS);
848 xcb_delete_property(globalconf.connection, c->win, _AWESOME_FLOATING);
850 if(client_hasstrut(c))
851 /* All the wiboxes (may) need to be repositioned */
852 for(int screen = 0; screen < globalconf.nscreen; screen++)
853 for(int i = 0; i < globalconf.screens[screen].wiboxes.len; i++)
855 wibox_t *s = globalconf.screens[screen].wiboxes.tab[i];
856 wibox_position_update(s);
859 /* set client as invalid */
860 c->invalid = true;
862 client_unref(&c);
865 /** Kill a client via a WM_DELETE_WINDOW request or XKillClient if not
866 * supported.
867 * \param c The client to kill.
869 void
870 client_kill(client_t *c)
872 xcb_client_message_event_t ev;
874 if(window_isprotodel(c->win))
876 /* Initialize all of event's fields first */
877 p_clear(&ev, 1);
879 ev.response_type = XCB_CLIENT_MESSAGE;
880 ev.window = c->win;
881 ev.format = 32;
882 ev.data.data32[1] = XCB_CURRENT_TIME;
883 ev.type = WM_PROTOCOLS;
884 ev.data.data32[0] = WM_DELETE_WINDOW;
886 xcb_send_event(globalconf.connection, false, c->win,
887 XCB_EVENT_MASK_NO_EVENT, (char *) &ev);
889 else
890 xcb_kill_client(globalconf.connection, c->win);
893 /** Get all clients into a table.
894 * \param L The Lua VM state.
895 * \return The number of elements pushed on stack.
896 * \luastack
897 * \lparam An optional screen nunmber.
898 * \lreturn A table with all clients.
900 static int
901 luaA_client_get(lua_State *L)
903 int i = 1, screen;
904 client_t *c;
906 screen = luaL_optnumber(L, 1, 0) - 1;
908 lua_newtable(L);
910 if(screen == SCREEN_UNDEF)
911 for(c = globalconf.clients; c; c = c->next)
913 luaA_client_userdata_new(globalconf.L, c);
914 lua_rawseti(L, -2, i++);
916 else
918 luaA_checkscreen(screen);
919 for(c = globalconf.clients; c; c = c->next)
920 if(c->screen == screen)
922 luaA_client_userdata_new(globalconf.L, c);
923 lua_rawseti(L, -2, i++);
927 return 1;
930 /** Get only visible clients for a screen (DEPRECATED).
931 * \param L The Lua VM state.
932 * \return The number of elements pushed on stack.
933 * \luastack
934 * \lparam A screen number.
935 * \lreturn A table with all visible clients for this screen.
937 static int
938 luaA_client_visible_get(lua_State *L)
940 int i = 1;
941 client_t *c;
942 int screen = luaL_checknumber(L, 1) - 1;
944 luaA_checkscreen(screen);
946 deprecate();
948 lua_newtable(L);
950 for(c = globalconf.clients; c; c = c->next)
951 if(client_isvisible(c, screen))
953 luaA_client_userdata_new(L, c);
954 lua_rawseti(L, -2, i++);
957 return 1;
960 /** Check if a client is visible on its screen.
961 * \param L The Lua VM state.
962 * \return The number of elements pushed on stack.
963 * \luastack
964 * \lvalue A client.
965 * \lreturn A boolean value, true if the client is visible, false otherwise.
967 static int
968 luaA_client_isvisible(lua_State *L)
970 client_t **c = luaA_checkudata(L, 1, "client");
971 lua_pushboolean(L, client_isvisible(*c, (*c)->screen));
972 return 1;
975 /** Set client border width.
976 * \param c The client.
977 * \param width The border width.
979 void
980 client_setborder(client_t *c, int width)
982 uint32_t w = width;
984 if(width > 0 && (c->type == WINDOW_TYPE_DOCK
985 || c->type == WINDOW_TYPE_SPLASH
986 || c->type == WINDOW_TYPE_DESKTOP
987 || c->isfullscreen))
988 return;
990 if(width == c->border || width < 0)
991 return;
993 c->border = width;
994 xcb_configure_window(globalconf.connection, c->win,
995 XCB_CONFIG_WINDOW_BORDER_WIDTH, &w);
997 if(client_isvisible(c, c->screen))
999 if(client_isfloating(c) || layout_get_current(c->screen) == layout_floating)
1000 titlebar_update_geometry_floating(c);
1001 else
1002 globalconf.screens[c->screen].need_arrange = true;
1005 hooks_property(c, "border_width");
1008 /** Kill a client.
1009 * \param L The Lua VM state.
1011 * \luastack
1012 * \lvalue A client.
1014 static int
1015 luaA_client_kill(lua_State *L)
1017 client_t **c = luaA_checkudata(L, 1, "client");
1018 client_kill(*c);
1019 return 0;
1022 /** Swap a client with another one.
1023 * \param L The Lua VM state.
1024 * \luastack
1025 * \lvalue A client.
1026 * \lparam A client to swap with.
1028 static int
1029 luaA_client_swap(lua_State *L)
1031 client_t **c = luaA_checkudata(L, 1, "client");
1032 client_t **swap = luaA_checkudata(L, 2, "client");
1033 client_list_swap(&globalconf.clients, *swap, *c);
1034 client_need_arrange(*c);
1035 client_need_arrange(*swap);
1036 widget_invalidate_cache((*c)->screen, WIDGET_CACHE_CLIENTS);
1037 widget_invalidate_cache((*swap)->screen, WIDGET_CACHE_CLIENTS);
1038 return 0;
1041 /** Access or set the client tags.
1042 * \param L The Lua VM state.
1043 * \return The number of elements pushed on stack.
1044 * \lparam A table with tags to set, or none to get the current tags table.
1045 * \return The clients tag.
1047 static int
1048 luaA_client_tags(lua_State *L)
1050 tag_array_t *tags;
1051 tag_t **tag;
1052 client_t **c = luaA_checkudata(L, 1, "client");
1053 int j = 0;
1055 if(lua_gettop(L) == 2)
1057 luaA_checktable(L, 2);
1058 tags = &globalconf.screens[(*c)->screen].tags;
1059 for(int i = 0; i < tags->len; i++)
1060 untag_client(*c, tags->tab[i]);
1061 lua_pushnil(L);
1062 while(lua_next(L, 2))
1064 tag = luaA_checkudata(L, -1, "tag");
1065 tag_client(*c, *tag);
1066 lua_pop(L, 1);
1068 lua_pop(L, 1);
1071 tags = &globalconf.screens[(*c)->screen].tags;
1072 luaA_otable_new(L);
1073 for(int i = 0; i < tags->len; i++)
1074 if(is_client_tagged(*c, tags->tab[i]))
1076 luaA_tag_userdata_new(L, tags->tab[i]);
1077 lua_rawseti(L, -2, ++j);
1080 return 1;
1083 /** Raise a client on top of others which are on the same layer.
1084 * \param L The Lua VM state.
1086 * \luastack
1087 * \lvalue A client.
1089 static int
1090 luaA_client_raise(lua_State *L)
1092 client_t **c = luaA_checkudata(L, 1, "client");
1093 client_raise(*c);
1094 return 0;
1097 /** Redraw a client by unmapping and mapping it quickly.
1098 * \param L The Lua VM state.
1100 * \luastack
1101 * \lvalue A client.
1103 static int
1104 luaA_client_redraw(lua_State *L)
1106 client_t **c = luaA_checkudata(L, 1, "client");
1108 xcb_unmap_window(globalconf.connection, (*c)->win);
1109 xcb_map_window(globalconf.connection, (*c)->win);
1111 /* Set the focus on the current window if the redraw has been
1112 performed on the window where the pointer is currently on
1113 because after the unmapping/mapping, the focus is lost */
1114 if(globalconf.screen_focus->client_focus == *c)
1115 xcb_set_input_focus(globalconf.connection, XCB_INPUT_FOCUS_POINTER_ROOT,
1116 (*c)->win, XCB_CURRENT_TIME);
1118 return 0;
1121 /** Return a formated string for a client.
1122 * \param L The Lua VM state.
1123 * \luastack
1124 * \lvalue A client.
1125 * \lreturn A string.
1127 static int
1128 luaA_client_tostring(lua_State *L)
1130 client_t **p = luaA_checkudata(L, 1, "client");
1131 lua_pushfstring(L, "[client udata(%p) name(%s)]", *p, (*p)->name);
1132 return 1;
1135 /** Stop managing a client.
1136 * \param L The Lua VM state.
1137 * \return The number of elements pushed on stack.
1138 * \luastack
1139 * \lvalue A client.
1141 static int
1142 luaA_client_unmanage(lua_State *L)
1144 client_t **c = luaA_checkudata(L, 1, "client");
1145 client_unmanage(*c);
1146 return 0;
1149 /** Return client coordinates.
1150 * \param L The Lua VM state.
1151 * \return The number of elements pushed on stack.
1152 * \luastack
1153 * \lparam A table with new coordinates, or none.
1154 * \lreturn A table with client coordinates.
1156 static int
1157 luaA_client_coords(lua_State *L)
1159 client_t **c = luaA_checkudata(L, 1, "client");
1161 if(lua_gettop(L) == 2)
1163 if((*c)->isfloating || layout_get_current((*c)->screen) == layout_floating)
1165 area_t geometry;
1167 luaA_checktable(L, 2);
1168 geometry.x = luaA_getopt_number(L, 2, "x", (*c)->geometry.x);
1169 geometry.y = luaA_getopt_number(L, 2, "y", (*c)->geometry.y);
1170 geometry.width = luaA_getopt_number(L, 2, "width", (*c)->geometry.width);
1171 geometry.height = luaA_getopt_number(L, 2, "height", (*c)->geometry.height);
1172 client_resize(*c, geometry, false);
1176 return luaA_pusharea(L, (*c)->geometry);
1179 /** Return client coordinates, using also titlebar and border width.
1180 * \param L The Lua VM state.
1181 * \return The number of elements pushed on stack.
1182 * \luastack
1183 * \lparam A table with new coordinates, or none.
1184 * \lreturn A table with client coordinates.
1186 static int
1187 luaA_client_fullcoords(lua_State *L)
1189 client_t **c = luaA_checkudata(L, 1, "client");
1190 area_t geometry;
1192 if(lua_gettop(L) == 2)
1194 if((*c)->isfloating || layout_get_current((*c)->screen) == layout_floating)
1196 luaA_checktable(L, 2);
1197 geometry.x = luaA_getopt_number(L, 2, "x", (*c)->geometry.x);
1198 geometry.y = luaA_getopt_number(L, 2, "y", (*c)->geometry.y);
1199 geometry.width = luaA_getopt_number(L, 2, "width", (*c)->geometry.width);
1200 geometry.height = luaA_getopt_number(L, 2, "height", (*c)->geometry.height);
1201 geometry = titlebar_geometry_remove((*c)->titlebar,
1202 (*c)->border,
1203 geometry);
1204 client_resize(*c, geometry, false);
1208 return luaA_pusharea(L, titlebar_geometry_add((*c)->titlebar,
1209 (*c)->border,
1210 (*c)->geometry));
1213 /** Client newindex.
1214 * \param L The Lua VM state.
1215 * \return The number of elements pushed on stack.
1218 luaA_client_newindex(lua_State *L)
1220 size_t len;
1221 client_t **c = luaA_checkudata(L, 1, "client");
1222 const char *buf = luaL_checklstring(L, 2, &len);
1223 bool b;
1224 double d;
1225 int i;
1226 wibox_t **t = NULL;
1227 image_t **image;
1229 if((*c)->invalid)
1230 luaL_error(L, "client is invalid\n");
1232 switch(a_tokenize(buf, len))
1234 case A_TK_NAME:
1235 buf = luaL_checklstring(L, 3, &len);
1236 p_delete(&(*c)->name);
1237 a_iso2utf8(&(*c)->name, buf, len);
1238 widget_invalidate_cache((*c)->screen, WIDGET_CACHE_CLIENTS);
1239 break;
1240 case A_TK_SCREEN:
1241 if(globalconf.xinerama_is_active)
1243 i = luaL_checknumber(L, 3) - 1;
1244 luaA_checkscreen(i);
1245 if(i != (*c)->screen)
1246 screen_client_moveto(*c, i, true, true);
1248 break;
1249 case A_TK_HIDE:
1250 b = luaA_checkboolean(L, 3);
1251 if(b != (*c)->ishidden)
1253 client_need_arrange(*c);
1254 (*c)->ishidden = b;
1255 client_need_arrange(*c);
1257 break;
1258 case A_TK_MINIMIZE:
1259 client_setminimized(*c, luaA_checkboolean(L, 3));
1260 break;
1261 case A_TK_FULLSCREEN:
1262 client_setfullscreen(*c, luaA_checkboolean(L, 3));
1263 break;
1264 case A_TK_ICON:
1265 image = luaA_checkudata(L, 3, "image");
1266 image_unref(&(*c)->icon);
1267 image_ref(image);
1268 (*c)->icon = *image;
1269 widget_invalidate_cache((*c)->screen, WIDGET_CACHE_CLIENTS);
1270 break;
1271 case A_TK_OPACITY:
1272 if(lua_isnil(L, 3))
1273 window_opacity_set((*c)->win, -1);
1274 else
1276 d = luaL_checknumber(L, 3);
1277 if(d >= 0 && d <= 1)
1278 window_opacity_set((*c)->win, d);
1280 break;
1281 case A_TK_FLOATING:
1282 client_setfloating(*c, luaA_checkboolean(L, 3));
1283 break;
1284 case A_TK_STICKY:
1285 client_setsticky(*c, luaA_checkboolean(L, 3));
1286 break;
1287 case A_TK_HONORSIZEHINTS:
1288 (*c)->honorsizehints = luaA_checkboolean(L, 3);
1289 client_need_arrange(*c);
1290 break;
1291 case A_TK_BORDER_WIDTH:
1292 client_setborder(*c, luaL_checknumber(L, 3));
1293 break;
1294 case A_TK_ONTOP:
1295 client_setontop(*c, luaA_checkboolean(L, 3));
1296 break;
1297 case A_TK_BORDER_COLOR:
1298 if((buf = luaL_checklstring(L, 3, &len))
1299 && xcolor_init_reply(xcolor_init_unchecked(&(*c)->border_color, buf, len)))
1300 xcb_change_window_attributes(globalconf.connection, (*c)->win,
1301 XCB_CW_BORDER_PIXEL, &(*c)->border_color.pixel);
1302 break;
1303 case A_TK_TITLEBAR:
1304 if(lua_isnil(L, 3))
1305 titlebar_client_detach(*c);
1306 else
1308 t = luaA_checkudata(L, 3, "wibox");
1309 titlebar_client_attach(*c, *t);
1311 break;
1312 default:
1313 return 0;
1316 return 0;
1319 /** Client object.
1320 * \param L The Lua VM state.
1321 * \return The number of elements pushed on stack.
1322 * \luastack
1323 * \lfield name The client title.
1324 * \lfield type The window type (desktop, normal, dock, …).
1325 * \lfield class The client class.
1326 * \lfield instance The client instance.
1327 * \lfield pid The client PID, if available.
1328 * \lfield role The window role, if available.
1329 * \lfield machine The machine client is running on.
1330 * \lfield icon_name The client name when iconified.
1331 * \lfield screen Client screen number.
1332 * \lfield hide Define if the client must be hidden, i.e. never mapped, not
1333 * visible in taskbar.
1334 * invisible in taskbar.
1335 * \lfield minimize Define it the client must be iconify, i.e. only visible in
1336 * taskbar.
1337 * \lfield icon_path Path to the icon used to identify.
1338 * \lfield floating True always floating.
1339 * \lfield honorsizehints Honor size hints, i.e. respect size ratio.
1340 * \lfield border_width The client border width.
1341 * \lfield border_color The client border color.
1342 * \lfield titlebar The client titlebar.
1343 * \lfield urgent The client urgent state.
1344 * \lfield focus The focused client.
1345 * \lfield opacity The client opacity between 0 and 1.
1346 * \lfield ontop The client is on top of every other windows.
1347 * \lfield fullscreen The client is fullscreen or not.
1349 static int
1350 luaA_client_index(lua_State *L)
1352 size_t len;
1353 ssize_t slen;
1354 client_t **c = luaA_checkudata(L, 1, "client");
1355 const char *buf = luaL_checklstring(L, 2, &len);
1356 char *value;
1357 void *data;
1358 xcb_get_wm_class_reply_t hint;
1359 xcb_get_property_cookie_t prop_c;
1360 xcb_get_property_reply_t *prop_r = NULL;
1361 double d;
1363 if((*c)->invalid)
1364 luaL_error(L, "client is invalid\n");
1366 if(luaA_usemetatable(L, 1, 2))
1367 return 1;
1369 switch(a_tokenize(buf, len))
1371 case A_TK_NAME:
1372 lua_pushstring(L, (*c)->name);
1373 break;
1374 case A_TK_TYPE:
1375 switch((*c)->type)
1377 case WINDOW_TYPE_DESKTOP:
1378 lua_pushliteral(L, "desktop");
1379 break;
1380 case WINDOW_TYPE_DOCK:
1381 lua_pushliteral(L, "dock");
1382 break;
1383 case WINDOW_TYPE_SPLASH:
1384 lua_pushliteral(L, "splash");
1385 break;
1386 case WINDOW_TYPE_DIALOG:
1387 lua_pushliteral(L, "dialog");
1388 break;
1389 default:
1390 lua_pushliteral(L, "normal");
1391 break;
1393 break;
1394 case A_TK_CLASS:
1395 if(!xcb_get_wm_class_reply(globalconf.connection,
1396 xcb_get_wm_class_unchecked(globalconf.connection, (*c)->win),
1397 &hint, NULL))
1398 return 0;
1399 lua_pushstring(L, hint.class);
1400 xcb_get_wm_class_reply_wipe(&hint);
1401 break;
1402 case A_TK_INSTANCE:
1403 if(!xcb_get_wm_class_reply(globalconf.connection,
1404 xcb_get_wm_class_unchecked(globalconf.connection, (*c)->win),
1405 &hint, NULL))
1406 return 0;
1407 lua_pushstring(L, hint.name);
1408 xcb_get_wm_class_reply_wipe(&hint);
1409 break;
1410 case A_TK_ROLE:
1411 if(!xutil_text_prop_get(globalconf.connection, (*c)->win,
1412 WM_WINDOW_ROLE, &value, &slen))
1413 return 0;
1414 lua_pushlstring(L, value, slen);
1415 p_delete(&value);
1416 break;
1417 case A_TK_PID:
1418 prop_c = xcb_get_property_unchecked(globalconf.connection, false, (*c)->win, _NET_WM_PID, CARDINAL, 0L, 1L);
1419 prop_r = xcb_get_property_reply(globalconf.connection, prop_c, NULL);
1421 if(prop_r && prop_r->value_len && (data = xcb_get_property_value(prop_r)))
1422 lua_pushnumber(L, *(uint32_t *)data);
1423 else
1425 p_delete(&prop_r);
1426 return 0;
1428 break;
1429 case A_TK_MACHINE:
1430 if(!xutil_text_prop_get(globalconf.connection, (*c)->win,
1431 WM_CLIENT_MACHINE, &value, &slen))
1432 return 0;
1433 lua_pushlstring(L, value, slen);
1434 p_delete(&value);
1435 break;
1436 case A_TK_ICON_NAME:
1437 if(!xutil_text_prop_get(globalconf.connection, (*c)->win,
1438 _NET_WM_ICON_NAME, &value, &slen))
1439 if(!xutil_text_prop_get(globalconf.connection, (*c)->win,
1440 WM_ICON_NAME, &value, &slen))
1441 return 0;
1442 lua_pushlstring(L, value, slen);
1443 p_delete(&value);
1444 break;
1445 case A_TK_SCREEN:
1446 lua_pushnumber(L, 1 + (*c)->screen);
1447 break;
1448 case A_TK_HIDE:
1449 lua_pushboolean(L, (*c)->ishidden);
1450 break;
1451 case A_TK_MINIMIZE:
1452 lua_pushboolean(L, (*c)->isminimized);
1453 break;
1454 case A_TK_FULLSCREEN:
1455 lua_pushboolean(L, (*c)->isfullscreen);
1456 break;
1457 case A_TK_ICON:
1458 if((*c)->icon)
1459 luaA_image_userdata_new(L, (*c)->icon);
1460 else
1461 return 0;
1462 break;
1463 case A_TK_OPACITY:
1464 if((d = window_opacity_get((*c)->win)) >= 0)
1465 lua_pushnumber(L, d);
1466 else
1467 return 0;
1468 break;
1469 case A_TK_FLOATING:
1470 lua_pushboolean(L, (*c)->isfloating);
1471 break;
1472 case A_TK_ONTOP:
1473 lua_pushboolean(L, (*c)->isontop);
1474 break;
1475 case A_TK_STICKY:
1476 lua_pushboolean(L, (*c)->issticky);
1477 break;
1478 case A_TK_HONORSIZEHINTS:
1479 lua_pushboolean(L, (*c)->honorsizehints);
1480 break;
1481 case A_TK_BORDER_WIDTH:
1482 lua_pushnumber(L, (*c)->border);
1483 break;
1484 case A_TK_BORDER_COLOR:
1485 luaA_pushcolor(L, &(*c)->border_color);
1486 break;
1487 case A_TK_TITLEBAR:
1488 if((*c)->titlebar)
1489 return luaA_wibox_userdata_new(L, (*c)->titlebar);
1490 return 0;
1491 case A_TK_URGENT:
1492 lua_pushboolean(L, (*c)->isurgent);
1493 break;
1494 case A_TK_SIZEHINTS:
1495 lua_newtable(L);
1496 lua_pushboolean(L, (*c)->size_hints.flags & XCB_SIZE_HINT_US_POSITION);
1497 lua_setfield(L, -2, "user_position");
1498 lua_pushboolean(L, (*c)->size_hints.flags & XCB_SIZE_HINT_US_SIZE);
1499 lua_setfield(L, -2, "user_size");
1500 lua_pushboolean(L, (*c)->size_hints.flags & XCB_SIZE_HINT_P_POSITION);
1501 lua_setfield(L, -2, "program_position");
1502 lua_pushboolean(L, (*c)->size_hints.flags & XCB_SIZE_HINT_P_SIZE);
1503 lua_setfield(L, -2, "program_size");
1504 break;
1505 default:
1506 return 0;
1509 return 1;
1512 /** Get or set mouse buttons bindings for a client.
1513 * \param L The Lua VM state.
1514 * \return The number of element pushed on stack.
1515 * \luastack
1516 * \lvalue A client.
1517 * \lparam An array of mouse button bindings objects, or nothing.
1518 * \return The array of mouse button bindings objects of this client.
1520 static int
1521 luaA_client_buttons(lua_State *L)
1523 client_t **client = luaA_checkudata(L, 1, "client");
1524 button_array_t *buttons = &(*client)->buttons;
1526 if(lua_gettop(L) == 2)
1527 luaA_button_array_set(L, 2, buttons);
1529 return luaA_button_array_get(L, buttons);
1532 /* Client module.
1533 * \param L The Lua VM state.
1534 * \return The number of pushed elements.
1536 static int
1537 luaA_client_module_index(lua_State *L)
1539 size_t len;
1540 const char *buf = luaL_checklstring(L, 2, &len);
1542 switch(a_tokenize(buf, len))
1544 case A_TK_FOCUS:
1545 if(globalconf.screen_focus->client_focus)
1546 luaA_client_userdata_new(L, globalconf.screen_focus->client_focus);
1547 else
1548 return 0;
1549 break;
1550 default:
1551 return 0;
1554 return 1;
1557 /* Client module new index.
1558 * \param L The Lua VM state.
1559 * \return The number of pushed elements.
1561 static int
1562 luaA_client_module_newindex(lua_State *L)
1564 size_t len;
1565 const char *buf = luaL_checklstring(L, 2, &len);
1566 client_t **c;
1568 switch(a_tokenize(buf, len))
1570 case A_TK_FOCUS:
1571 c = luaA_checkudata(L, 3, "client");
1572 client_focus(*c);
1573 break;
1574 default:
1575 break;
1578 return 0;
1581 const struct luaL_reg awesome_client_methods[] =
1583 { "get", luaA_client_get },
1584 { "visible_get", luaA_client_visible_get },
1585 { "__index", luaA_client_module_index },
1586 { "__newindex", luaA_client_module_newindex },
1587 { NULL, NULL }
1589 const struct luaL_reg awesome_client_meta[] =
1591 { "isvisible", luaA_client_isvisible },
1592 { "coords", luaA_client_coords },
1593 { "fullcoords", luaA_client_fullcoords },
1594 { "buttons", luaA_client_buttons },
1595 { "tags", luaA_client_tags },
1596 { "kill", luaA_client_kill },
1597 { "swap", luaA_client_swap },
1598 { "raise", luaA_client_raise },
1599 { "redraw", luaA_client_redraw },
1600 { "mouse_resize", luaA_client_mouse_resize },
1601 { "mouse_move", luaA_client_mouse_move },
1602 { "unmanage", luaA_client_unmanage },
1603 { "__index", luaA_client_index },
1604 { "__newindex", luaA_client_newindex },
1605 { "__eq", luaA_client_eq },
1606 { "__gc", luaA_client_gc },
1607 { "__tostring", luaA_client_tostring },
1608 { NULL, NULL }
1611 // vim: filetype=c:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=80