config check: be more precise about what we check
[awesome.git] / client.c
blobfb99f125c6a9ca03aabe5ec8bfac537fa234494b
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 if(c->titlebar)
241 xcb_configure_window(globalconf.connection,
242 c->titlebar->sw.window,
243 XCB_CONFIG_WINDOW_SIBLING | XCB_CONFIG_WINDOW_STACK_MODE,
244 config_win_vals);
245 config_win_vals[0] = c->titlebar->sw.window;
248 xcb_configure_window(globalconf.connection, c->win,
249 XCB_CONFIG_WINDOW_SIBLING | XCB_CONFIG_WINDOW_STACK_MODE,
250 config_win_vals);
252 previous = c->win;
254 /* stack transient window on top of their parents */
255 for(client_node_t *node = *client_node_list_last(&globalconf.stack);
256 node; node = node->prev)
257 if(node->client->transient_for == c)
259 client_stack_above(node->client,
260 previous);
261 previous = node->client->win;
264 return previous;
267 /** Stacking layout layers */
268 typedef enum
270 /** This one is a special layer */
271 LAYER_IGNORE,
272 LAYER_DESKTOP,
273 LAYER_BELOW,
274 LAYER_TILE,
275 LAYER_FLOAT,
276 LAYER_ABOVE,
277 LAYER_FULLSCREEN,
278 LAYER_ONTOP,
279 LAYER_OUTOFSPACE
280 } layer_t;
282 /** Get the real layer of a client according to its attribute (fullscreen, …)
283 * \param c The client.
284 * \return The real layer.
286 static layer_t
287 client_layer_translator(client_t *c)
289 /* first deal with user set attributes */
290 if(c->isontop)
291 return LAYER_ONTOP;
292 else if(c->isfullscreen)
293 return LAYER_FULLSCREEN;
294 else if(c->isabove)
295 return LAYER_ABOVE;
296 else if(c->isbelow)
297 return LAYER_BELOW;
298 else if(c->isfloating)
299 return LAYER_FLOAT;
301 /* check for transient attr */
302 if(c->transient_for)
303 return LAYER_IGNORE;
305 /* then deal with windows type */
306 switch(c->type)
308 case WINDOW_TYPE_DOCK:
309 return LAYER_ABOVE;
310 case WINDOW_TYPE_DESKTOP:
311 return LAYER_DESKTOP;
312 case WINDOW_TYPE_DIALOG:
313 return LAYER_FLOAT;
314 default:
315 break;
318 if(client_isfixed(c))
319 return LAYER_FLOAT;
321 return LAYER_TILE;
324 /** Restack clients.
325 * \todo It might be worth stopping to restack everyone and only stack `c'
326 * relatively to the first matching in the list.
328 void
329 client_stack()
331 uint32_t config_win_vals[2];
332 client_node_t *node, *last = *client_node_list_last(&globalconf.stack);
333 layer_t layer;
334 int screen;
336 config_win_vals[0] = XCB_NONE;
337 config_win_vals[1] = XCB_STACK_MODE_ABOVE;
339 /* stack desktop windows */
340 for(layer = LAYER_DESKTOP; layer < LAYER_BELOW; layer++)
341 for(node = last; node; node = node->prev)
342 if(client_layer_translator(node->client) == layer)
343 config_win_vals[0] = client_stack_above(node->client,
344 config_win_vals[0]);
346 /* first stack not ontop wibox window */
347 for(screen = 0; screen < globalconf.nscreen; screen++)
348 for(int i = 0; i < globalconf.screens[screen].wiboxes.len; i++)
350 wibox_t *sb = globalconf.screens[screen].wiboxes.tab[i];
351 if(!sb->ontop)
353 xcb_configure_window(globalconf.connection,
354 sb->sw.window,
355 XCB_CONFIG_WINDOW_SIBLING | XCB_CONFIG_WINDOW_STACK_MODE,
356 config_win_vals);
357 config_win_vals[0] = sb->sw.window;
361 /* stack bottom layers */
362 for(layer = LAYER_BELOW; layer < LAYER_FULLSCREEN; layer++)
363 for(node = last; node; node = node->prev)
364 if(client_layer_translator(node->client) == layer)
365 config_win_vals[0] = client_stack_above(node->client,
366 config_win_vals[0]);
368 /* then stack ontop wibox window */
369 for(screen = 0; screen < globalconf.nscreen; screen++)
370 for(int i = 0; i < globalconf.screens[screen].wiboxes.len; i++)
372 wibox_t *sb = globalconf.screens[screen].wiboxes.tab[i];
373 if(sb->ontop)
375 xcb_configure_window(globalconf.connection,
376 sb->sw.window,
377 XCB_CONFIG_WINDOW_SIBLING | XCB_CONFIG_WINDOW_STACK_MODE,
378 config_win_vals);
379 config_win_vals[0] = sb->sw.window;
383 /* finally stack ontop and fullscreen windows */
384 for(layer = LAYER_FULLSCREEN; layer < LAYER_OUTOFSPACE; layer++)
385 for(node = last; node; node = node->prev)
386 if(client_layer_translator(node->client) == layer)
387 config_win_vals[0] = client_stack_above(node->client,
388 config_win_vals[0]);
391 /** Manage a new client.
392 * \param w The window.
393 * \param wgeom Window geometry.
394 * \param phys_screen Physical screen number.
395 * \param screen Virtual screen number where to manage client.
397 void
398 client_manage(xcb_window_t w, xcb_get_geometry_reply_t *wgeom, int phys_screen, int screen)
400 xcb_get_property_cookie_t ewmh_icon_cookie;
401 client_t *c;
402 image_t *icon;
403 const uint32_t select_input_val[] =
405 XCB_EVENT_MASK_STRUCTURE_NOTIFY
406 | XCB_EVENT_MASK_PROPERTY_CHANGE
407 | XCB_EVENT_MASK_ENTER_WINDOW
410 /* Send request to get NET_WM_ICON property as soon as possible... */
411 ewmh_icon_cookie = ewmh_window_icon_get_unchecked(w);
412 xcb_change_window_attributes(globalconf.connection, w, XCB_CW_EVENT_MASK, select_input_val);
414 if(systray_iskdedockapp(w))
416 systray_request_handle(w, phys_screen, NULL);
417 return;
420 c = p_new(client_t, 1);
422 c->screen = screen_getbycoord(screen, wgeom->x, wgeom->y);
424 c->phys_screen = phys_screen;
426 /* Initial values */
427 c->win = w;
428 c->geometry.x = c->f_geometry.x = c->m_geometry.x = wgeom->x;
429 c->geometry.y = c->f_geometry.y = c->m_geometry.y = wgeom->y;
430 c->geometry.width = c->f_geometry.width = c->m_geometry.width = wgeom->width;
431 c->geometry.height = c->f_geometry.height = c->m_geometry.height = wgeom->height;
432 client_setborder(c, wgeom->border_width);
433 if((icon = ewmh_window_icon_get_reply(ewmh_icon_cookie)))
434 c->icon = image_ref(&icon);
436 /* we honor size hints by default */
437 c->honorsizehints = true;
439 /* update hints */
440 property_update_wm_normal_hints(c, NULL);
441 property_update_wm_hints(c, NULL);
442 property_update_wm_transient_for(c, NULL);
444 if(c->transient_for)
445 screen = c->transient_for->screen;
447 /* Try to load props if any */
448 client_loadprops(c, &globalconf.screens[screen]);
451 /* Then check clients hints */
452 ewmh_client_check_hints(c);
454 /* move client to screen, but do not tag it for now */
455 screen_client_moveto(c, screen, false, true);
457 /* Check if client has been tagged by loading props, or maybe with its
458 * hints.
459 * If not, we tag it with current selected ones.
460 * This could be done on Lua side, but it's a sane behaviour. */
461 if(!c->issticky)
463 int i;
464 tag_array_t *tags = &globalconf.screens[screen].tags;
465 for(i = 0; i < tags->len; i++)
466 if(is_client_tagged(c, tags->tab[i]))
467 break;
469 /* if no tag, set current selected */
470 if(i == tags->len)
471 for(i = 0; i < tags->len; i++)
472 if(tags->tab[i]->selected)
473 tag_client(c, tags->tab[i]);
476 /* Push client in client list */
477 client_list_push(&globalconf.clients, client_ref(&c));
479 /* Push client in stack */
480 client_raise(c);
482 /* update window title */
483 property_update_wm_name(c);
484 property_update_wm_icon_name(c);
486 /* update strut */
487 ewmh_client_strut_update(c, NULL);
489 ewmh_update_net_client_list(c->phys_screen);
491 /* Call hook to notify list change */
492 luaA_dofunction(globalconf.L, globalconf.hooks.clients, 0, 0);
494 /* call hook */
495 luaA_client_userdata_new(globalconf.L, c);
496 luaA_dofunction(globalconf.L, globalconf.hooks.manage, 1, 0);
499 /** Compute client geometry with respect to its geometry hints.
500 * \param c The client.
501 * \param geometry The geometry that the client might receive.
502 * \return The geometry the client must take respecting its hints.
504 area_t
505 client_geometry_hints(client_t *c, area_t geometry)
507 double dx, dy, max, min, ratio;
509 if(c->minay > 0 && c->maxay > 0 && (geometry.height - c->baseh) > 0
510 && (geometry.width - c->basew) > 0)
512 dx = (double) (geometry.width - c->basew);
513 dy = (double) (geometry.height - c->baseh);
514 min = (double) (c->minax) / (double) (c->minay);
515 max = (double) (c->maxax) / (double) (c->maxay);
516 ratio = dx / dy;
517 if(max > 0 && min > 0 && ratio > 0)
519 if(ratio < min)
521 dy = (dx * min + dy) / (min * min + 1);
522 dx = dy * min;
523 geometry.width = (int) dx + c->basew;
524 geometry.height = (int) dy + c->baseh;
526 else if(ratio > max)
528 dy = (dx * min + dy) / (max * max + 1);
529 dx = dy * min;
530 geometry.width = (int) dx + c->basew;
531 geometry.height = (int) dy + c->baseh;
535 if(c->minw && geometry.width < c->minw)
536 geometry.width = c->minw;
537 if(c->minh && geometry.height < c->minh)
538 geometry.height = c->minh;
539 if(c->maxw && geometry.width > c->maxw)
540 geometry.width = c->maxw;
541 if(c->maxh && geometry.height > c->maxh)
542 geometry.height = c->maxh;
543 if(c->incw)
544 geometry.width -= (geometry.width - c->basew) % c->incw;
545 if(c->inch)
546 geometry.height -= (geometry.height - c->baseh) % c->inch;
548 return geometry;
551 /** Resize client window.
552 * \param c Client to resize.
553 * \param geometry New window geometry.
554 * \param hints Use size hints.
556 void
557 client_resize(client_t *c, area_t geometry, bool hints)
559 int new_screen;
560 area_t area;
561 layout_t *layout = layout_get_current(c->screen);
563 if(c->titlebar && !c->ismoving && c->titlebar->isvisible && !client_isfloating(c) && layout != layout_floating)
564 geometry = titlebar_geometry_remove(c->titlebar, c->border, geometry);
566 if(hints)
567 geometry = client_geometry_hints(c, geometry);
569 if(geometry.width <= 0 || geometry.height <= 0)
570 return;
572 /* offscreen appearance fixes */
573 area = display_area_get(c->phys_screen, NULL,
574 &globalconf.screens[c->screen].padding);
576 if(geometry.x > area.width)
577 geometry.x = area.width - geometry.width - 2 * c->border;
578 if(geometry.y > area.height)
579 geometry.y = area.height - geometry.height - 2 * c->border;
580 if(geometry.x + geometry.width + 2 * c->border < 0)
581 geometry.x = 0;
582 if(geometry.y + geometry.height + 2 * c->border < 0)
583 geometry.y = 0;
585 if(c->geometry.x != geometry.x
586 || c->geometry.y != geometry.y
587 || c->geometry.width != geometry.width
588 || c->geometry.height != geometry.height)
590 new_screen = screen_getbycoord(c->screen, geometry.x, geometry.y);
592 /* Values to configure a window is an array where values are
593 * stored according to 'value_mask' */
594 uint32_t values[4];
596 c->geometry.x = values[0] = geometry.x;
597 c->geometry.y = values[1] = geometry.y;
598 c->geometry.width = values[2] = geometry.width;
599 c->geometry.height = values[3] = geometry.height;
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 || layout_get_current(c->screen) == layout_floating)
606 if(!c->isfullscreen)
607 c->f_geometry = geometry;
609 titlebar_update_geometry_floating(c);
611 xcb_configure_window(globalconf.connection, c->win,
612 XCB_CONFIG_WINDOW_X | XCB_CONFIG_WINDOW_Y
613 | XCB_CONFIG_WINDOW_WIDTH | XCB_CONFIG_WINDOW_HEIGHT,
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 client 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, NULL, 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);
709 client_resize(c, geometry, false);
710 client_need_arrange(c);
711 client_stack();
712 xcb_change_property(globalconf.connection,
713 XCB_PROP_MODE_REPLACE,
714 c->win, _AWESOME_FULLSCREEN, CARDINAL, 8, 1,
715 &c->isfullscreen);
716 ewmh_client_update_hints(c);
717 hooks_property(c, "fullscreen");
721 /** Set a client above, or not.
722 * \param c The client.
723 * \param s Set or not the client above.
725 void
726 client_setabove(client_t *c, bool s)
728 if(c->isabove != s)
730 c->isabove = s;
731 client_stack();
732 ewmh_client_update_hints(c);
733 /* execute hook */
734 hooks_property(c, "above");
738 /** Set a client below, or not.
739 * \param c The client.
740 * \param s Set or not the client below.
742 void
743 client_setbelow(client_t *c, bool s)
745 if(c->isbelow != s)
747 c->isbelow = s;
748 client_stack();
749 ewmh_client_update_hints(c);
750 /* execute hook */
751 hooks_property(c, "below");
755 /** Set a client modal, or not.
756 * \param c The client.
757 * \param s Set or not the client moda.
759 void
760 client_setmodal(client_t *c, bool s)
762 if(c->ismodal != s)
764 c->ismodal = s;
765 client_stack();
766 ewmh_client_update_hints(c);
767 /* execute hook */
768 hooks_property(c, "modal");
772 /** Set a client ontop, or not.
773 * \param c The client.
774 * \param s Set or not the client moda.
776 void
777 client_setontop(client_t *c, bool s)
779 if(c->isontop != s)
781 c->isontop = s;
782 client_stack();
783 /* execute hook */
784 hooks_property(c, "ontop");
788 /** Save client properties as an X property.
789 * \param c The client.
791 void
792 client_saveprops_tags(client_t *c)
794 tag_array_t *tags = &globalconf.screens[c->screen].tags;
795 unsigned char *prop = p_alloca(unsigned char, tags->len + 1);
796 int i;
798 for(i = 0; i < tags->len; i++)
799 prop[i] = is_client_tagged(c, tags->tab[i]) ? '1' : '0';
801 xcb_change_property(globalconf.connection, XCB_PROP_MODE_REPLACE, c->win, _AWESOME_TAGS, STRING, 8, i, prop);
804 /** Unban a client.
805 * \param c The client.
807 void
808 client_unban(client_t *c)
810 xcb_map_window(globalconf.connection, c->win);
811 window_state_set(c->win, XCB_WM_STATE_NORMAL);
812 if(c->titlebar)
814 if(c->isfullscreen || !c->titlebar->isvisible)
815 xcb_unmap_window(globalconf.connection, c->titlebar->sw.window);
816 else
817 xcb_map_window(globalconf.connection, c->titlebar->sw.window);
821 /** Unmanage a client.
822 * \param c The client.
824 void
825 client_unmanage(client_t *c)
827 tag_array_t *tags = &globalconf.screens[c->screen].tags;
829 if(globalconf.screens[c->phys_screen].client_focus == c)
830 client_unfocus(c);
832 /* remove client everywhere */
833 client_list_detach(&globalconf.clients, c);
834 stack_client_delete(c);
835 for(int i = 0; i < tags->len; i++)
836 untag_client(c, tags->tab[i]);
838 /* call hook */
839 luaA_client_userdata_new(globalconf.L, c);
840 luaA_dofunction(globalconf.L, globalconf.hooks.unmanage, 1, 0);
842 /* Call hook to notify list change */
843 luaA_dofunction(globalconf.L, globalconf.hooks.clients, 0, 0);
845 /* The server grab construct avoids race conditions. */
846 xcb_grab_server(globalconf.connection);
848 xcb_configure_window(globalconf.connection, c->win,
849 XCB_CONFIG_WINDOW_BORDER_WIDTH,
850 (uint32_t *) &c->oldborder);
852 xcb_ungrab_button(globalconf.connection, XCB_BUTTON_INDEX_ANY, c->win,
853 XCB_BUTTON_MASK_ANY);
854 window_state_set(c->win, XCB_WM_STATE_WITHDRAWN);
856 xcb_flush(globalconf.connection);
857 xcb_ungrab_server(globalconf.connection);
859 titlebar_client_detach(c);
861 ewmh_update_net_client_list(c->phys_screen);
863 /* delete properties */
864 xcb_delete_property(globalconf.connection, c->win, _AWESOME_TAGS);
865 xcb_delete_property(globalconf.connection, c->win, _AWESOME_FLOATING);
867 if(client_hasstrut(c))
868 /* All the wiboxes (may) need to be repositioned */
869 for(int screen = 0; screen < globalconf.nscreen; screen++)
870 for(int i = 0; i < globalconf.screens[screen].wiboxes.len; i++)
872 wibox_t *s = globalconf.screens[screen].wiboxes.tab[i];
873 wibox_position_update(s);
876 /* set client as invalid */
877 c->invalid = true;
879 client_unref(&c);
882 /** Kill a client via a WM_DELETE_WINDOW request or KillClient if not
883 * supported.
884 * \param c The client to kill.
886 void
887 client_kill(client_t *c)
889 if(window_hasproto(c->win, WM_DELETE_WINDOW))
891 xcb_client_message_event_t ev;
893 /* Initialize all of event's fields first */
894 p_clear(&ev, 1);
896 ev.response_type = XCB_CLIENT_MESSAGE;
897 ev.window = c->win;
898 ev.format = 32;
899 ev.data.data32[1] = XCB_CURRENT_TIME;
900 ev.type = WM_PROTOCOLS;
901 ev.data.data32[0] = WM_DELETE_WINDOW;
903 xcb_send_event(globalconf.connection, false, c->win,
904 XCB_EVENT_MASK_NO_EVENT, (char *) &ev);
906 else
907 xcb_kill_client(globalconf.connection, c->win);
910 /** Get all clients into a table.
911 * \param L The Lua VM state.
912 * \return The number of elements pushed on stack.
913 * \luastack
914 * \lparam An optional screen nunmber.
915 * \lreturn A table with all clients.
917 static int
918 luaA_client_get(lua_State *L)
920 int i = 1, screen;
921 client_t *c;
923 screen = luaL_optnumber(L, 1, 0) - 1;
925 lua_newtable(L);
927 if(screen == SCREEN_UNDEF)
928 for(c = globalconf.clients; c; c = c->next)
930 luaA_client_userdata_new(globalconf.L, c);
931 lua_rawseti(L, -2, i++);
933 else
935 luaA_checkscreen(screen);
936 for(c = globalconf.clients; c; c = c->next)
937 if(c->screen == screen)
939 luaA_client_userdata_new(globalconf.L, c);
940 lua_rawseti(L, -2, i++);
944 return 1;
947 /** Get only visible clients for a screen (DEPRECATED).
948 * \param L The Lua VM state.
949 * \return The number of elements pushed on stack.
950 * \luastack
951 * \lparam A screen number.
952 * \lreturn A table with all visible clients for this screen.
954 static int
955 luaA_client_visible_get(lua_State *L)
957 int i = 1;
958 client_t *c;
959 int screen = luaL_checknumber(L, 1) - 1;
961 luaA_checkscreen(screen);
963 deprecate(L, "awful.client.visible()");
965 lua_newtable(L);
967 for(c = globalconf.clients; c; c = c->next)
968 if(client_isvisible(c, screen))
970 luaA_client_userdata_new(L, c);
971 lua_rawseti(L, -2, i++);
974 return 1;
977 /** Check if a client is visible on its screen.
978 * \param L The Lua VM state.
979 * \return The number of elements pushed on stack.
980 * \luastack
981 * \lvalue A client.
982 * \lreturn A boolean value, true if the client is visible, false otherwise.
984 static int
985 luaA_client_isvisible(lua_State *L)
987 client_t **c = luaA_checkudata(L, 1, "client");
988 lua_pushboolean(L, client_isvisible(*c, (*c)->screen));
989 return 1;
992 /** Set client border width.
993 * \param c The client.
994 * \param width The border width.
996 void
997 client_setborder(client_t *c, int width)
999 uint32_t w = width;
1001 if(width > 0 && (c->type == WINDOW_TYPE_DOCK
1002 || c->type == WINDOW_TYPE_SPLASH
1003 || c->type == WINDOW_TYPE_DESKTOP
1004 || c->isfullscreen))
1005 return;
1007 if(width == c->border || width < 0)
1008 return;
1010 c->border = width;
1011 xcb_configure_window(globalconf.connection, c->win,
1012 XCB_CONFIG_WINDOW_BORDER_WIDTH, &w);
1014 if(client_isvisible(c, c->screen))
1016 if(client_isfloating(c) || layout_get_current(c->screen) == layout_floating)
1017 titlebar_update_geometry_floating(c);
1018 else
1019 globalconf.screens[c->screen].need_arrange = true;
1022 hooks_property(c, "border_width");
1025 /** Kill a client.
1026 * \param L The Lua VM state.
1028 * \luastack
1029 * \lvalue A client.
1031 static int
1032 luaA_client_kill(lua_State *L)
1034 client_t **c = luaA_checkudata(L, 1, "client");
1035 client_kill(*c);
1036 return 0;
1039 /** Swap a client with another one.
1040 * \param L The Lua VM state.
1041 * \luastack
1042 * \lvalue A client.
1043 * \lparam A client to swap with.
1045 static int
1046 luaA_client_swap(lua_State *L)
1048 client_t **c = luaA_checkudata(L, 1, "client");
1049 client_t **swap = luaA_checkudata(L, 2, "client");
1050 client_list_swap(&globalconf.clients, *swap, *c);
1051 client_need_arrange(*c);
1052 client_need_arrange(*swap);
1054 /* Call hook to notify list change */
1055 luaA_dofunction(L, globalconf.hooks.clients, 0, 0);
1057 return 0;
1060 /** Access or set the client tags.
1061 * \param L The Lua VM state.
1062 * \return The number of elements pushed on stack.
1063 * \lparam A table with tags to set, or none to get the current tags table.
1064 * \return The clients tag.
1066 static int
1067 luaA_client_tags(lua_State *L)
1069 tag_array_t *tags;
1070 tag_t **tag;
1071 client_t **c = luaA_checkudata(L, 1, "client");
1072 int j = 0;
1074 if(lua_gettop(L) == 2)
1076 luaA_checktable(L, 2);
1077 tags = &globalconf.screens[(*c)->screen].tags;
1078 for(int i = 0; i < tags->len; i++)
1079 untag_client(*c, tags->tab[i]);
1080 lua_pushnil(L);
1081 while(lua_next(L, 2))
1083 tag = luaA_checkudata(L, -1, "tag");
1084 tag_client(*c, *tag);
1085 lua_pop(L, 1);
1087 lua_pop(L, 1);
1090 tags = &globalconf.screens[(*c)->screen].tags;
1091 luaA_otable_new(L);
1092 for(int i = 0; i < tags->len; i++)
1093 if(is_client_tagged(*c, tags->tab[i]))
1095 luaA_tag_userdata_new(L, tags->tab[i]);
1096 lua_rawseti(L, -2, ++j);
1099 return 1;
1102 /** Raise a client on top of others which are on the same layer.
1103 * \param L The Lua VM state.
1104 * \luastack
1105 * \lvalue A client.
1107 static int
1108 luaA_client_raise(lua_State *L)
1110 client_t **c = luaA_checkudata(L, 1, "client");
1111 client_raise(*c);
1112 return 0;
1115 /** Lower a client on bottom of others which are on the same layer.
1116 * \param L The Lua VM state.
1117 * \luastack
1118 * \lvalue A client.
1120 static int
1121 luaA_client_lower(lua_State *L)
1123 client_t **c = luaA_checkudata(L, 1, "client");
1124 client_lower(*c);
1125 return 0;
1128 /** Redraw a client by unmapping and mapping it quickly.
1129 * \param L The Lua VM state.
1131 * \luastack
1132 * \lvalue A client.
1134 static int
1135 luaA_client_redraw(lua_State *L)
1137 client_t **c = luaA_checkudata(L, 1, "client");
1139 xcb_unmap_window(globalconf.connection, (*c)->win);
1140 xcb_map_window(globalconf.connection, (*c)->win);
1142 /* Set the focus on the current window if the redraw has been
1143 performed on the window where the pointer is currently on
1144 because after the unmapping/mapping, the focus is lost */
1145 if(globalconf.screen_focus->client_focus == *c)
1146 xcb_set_input_focus(globalconf.connection, XCB_INPUT_FOCUS_POINTER_ROOT,
1147 (*c)->win, XCB_CURRENT_TIME);
1149 return 0;
1152 /** Stop managing a client.
1153 * \param L The Lua VM state.
1154 * \return The number of elements pushed on stack.
1155 * \luastack
1156 * \lvalue A client.
1158 static int
1159 luaA_client_unmanage(lua_State *L)
1161 client_t **c = luaA_checkudata(L, 1, "client");
1162 client_unmanage(*c);
1163 return 0;
1166 /** Return client geometry.
1167 * \param L The Lua VM state.
1168 * \param full Use titlebar also.
1169 * \return The number of elements pushed on stack.
1171 static int
1172 luaA_client_handlegeom(lua_State *L, bool full)
1174 client_t **c = luaA_checkudata(L, 1, "client");
1176 if(lua_gettop(L) == 2)
1177 if(client_isfloating(*c)
1178 || layout_get_current((*c)->screen) == layout_floating)
1180 area_t geometry;
1182 luaA_checktable(L, 2);
1183 geometry.x = luaA_getopt_number(L, 2, "x", (*c)->geometry.x);
1184 geometry.y = luaA_getopt_number(L, 2, "y", (*c)->geometry.y);
1185 if(client_isfixed(*c))
1187 geometry.width = (*c)->geometry.width;
1188 geometry.height = (*c)->geometry.height;
1190 else
1192 geometry.width = luaA_getopt_number(L, 2, "width", (*c)->geometry.width);
1193 geometry.height = luaA_getopt_number(L, 2, "height", (*c)->geometry.height);
1195 if(full)
1196 geometry = titlebar_geometry_remove((*c)->titlebar,
1197 (*c)->border,
1198 geometry);
1199 client_resize(*c, geometry, (*c)->honorsizehints);
1202 if(full)
1203 return luaA_pusharea(L, titlebar_geometry_add((*c)->titlebar,
1204 (*c)->border,
1205 (*c)->geometry));
1207 return luaA_pusharea(L, (*c)->geometry);
1210 /** Return client geometry.
1211 * \param L The Lua VM state.
1212 * \return The number of elements pushed on stack.
1213 * \luastack
1214 * \lparam A table with new coordinates, or none.
1215 * \lreturn A table with client coordinates.
1217 static int
1218 luaA_client_geometry(lua_State *L)
1220 return luaA_client_handlegeom(L, false);
1223 static int
1224 luaA_client_coords(lua_State *L)
1226 deprecate(L, "client:geometry()");
1227 return luaA_client_geometry(L);
1230 /** Return client geometry, using also titlebar and border width.
1231 * \param L The Lua VM state.
1232 * \return The number of elements pushed on stack.
1233 * \luastack
1234 * \lparam A table with new coordinates, or none.
1235 * \lreturn A table with client coordinates.
1237 static int
1238 luaA_client_fullgeometry(lua_State *L)
1240 return luaA_client_handlegeom(L, true);
1243 static int
1244 luaA_client_fullcoords(lua_State *L)
1246 deprecate(L, "client:fullgeometry()");
1247 return luaA_client_fullgeometry(L);
1250 /** Client newindex.
1251 * \param L The Lua VM state.
1252 * \return The number of elements pushed on stack.
1255 luaA_client_newindex(lua_State *L)
1257 size_t len;
1258 client_t **c = luaA_checkudata(L, 1, "client");
1259 const char *buf = luaL_checklstring(L, 2, &len);
1260 bool b;
1261 double d;
1262 int i;
1263 wibox_t **t = NULL;
1264 image_t **image;
1266 if((*c)->invalid)
1267 luaL_error(L, "client is invalid\n");
1269 switch(a_tokenize(buf, len))
1271 case A_TK_SCREEN:
1272 if(globalconf.xinerama_is_active)
1274 i = luaL_checknumber(L, 3) - 1;
1275 luaA_checkscreen(i);
1276 if(i != (*c)->screen)
1277 screen_client_moveto(*c, i, true, true);
1279 break;
1280 case A_TK_HIDE:
1281 b = luaA_checkboolean(L, 3);
1282 if(b != (*c)->ishidden)
1284 client_need_arrange(*c);
1285 (*c)->ishidden = b;
1286 client_need_arrange(*c);
1288 break;
1289 case A_TK_MINIMIZE:
1290 client_setminimized(*c, luaA_checkboolean(L, 3));
1291 break;
1292 case A_TK_FULLSCREEN:
1293 client_setfullscreen(*c, luaA_checkboolean(L, 3));
1294 break;
1295 case A_TK_ICON:
1296 image = luaA_checkudata(L, 3, "image");
1297 image_unref(&(*c)->icon);
1298 image_ref(image);
1299 (*c)->icon = *image;
1300 /* execute hook */
1301 hooks_property(*c, "icon");
1302 break;
1303 case A_TK_OPACITY:
1304 if(lua_isnil(L, 3))
1305 window_opacity_set((*c)->win, -1);
1306 else
1308 d = luaL_checknumber(L, 3);
1309 if(d >= 0 && d <= 1)
1310 window_opacity_set((*c)->win, d);
1312 break;
1313 case A_TK_FLOATING:
1314 client_setfloating(*c, luaA_checkboolean(L, 3));
1315 break;
1316 case A_TK_STICKY:
1317 client_setsticky(*c, luaA_checkboolean(L, 3));
1318 break;
1319 case A_TK_HONORSIZEHINTS:
1320 (*c)->honorsizehints = luaA_checkboolean(L, 3);
1321 client_need_arrange(*c);
1322 break;
1323 case A_TK_BORDER_WIDTH:
1324 client_setborder(*c, luaL_checknumber(L, 3));
1325 break;
1326 case A_TK_ONTOP:
1327 client_setontop(*c, luaA_checkboolean(L, 3));
1328 break;
1329 case A_TK_BORDER_COLOR:
1330 if((buf = luaL_checklstring(L, 3, &len))
1331 && xcolor_init_reply(xcolor_init_unchecked(&(*c)->border_color, buf, len)))
1332 xcb_change_window_attributes(globalconf.connection, (*c)->win,
1333 XCB_CW_BORDER_PIXEL, &(*c)->border_color.pixel);
1334 break;
1335 case A_TK_TITLEBAR:
1336 if(lua_isnil(L, 3))
1337 titlebar_client_detach(*c);
1338 else
1340 t = luaA_checkudata(L, 3, "wibox");
1341 titlebar_client_attach(*c, *t);
1343 break;
1344 default:
1345 return 0;
1348 return 0;
1351 /** Client object.
1352 * \param L The Lua VM state.
1353 * \return The number of elements pushed on stack.
1354 * \luastack
1355 * \lfield name The client title.
1356 * \lfield skip_taskbar True if the client does not want to be in taskbar.
1357 * \lfield type The window type (desktop, normal, dock, …).
1358 * \lfield class The client class.
1359 * \lfield instance The client instance.
1360 * \lfield pid The client PID, if available.
1361 * \lfield role The window role, if available.
1362 * \lfield machine The machine client is running on.
1363 * \lfield icon_name The client name when iconified.
1364 * \lfield screen Client screen number.
1365 * \lfield hide Define if the client must be hidden, i.e. never mapped,
1366 * invisible in taskbar.
1367 * \lfield minimize Define it the client must be iconify, i.e. only visible in
1368 * taskbar.
1369 * \lfield icon_path Path to the icon used to identify.
1370 * \lfield floating True always floating.
1371 * \lfield honorsizehints Honor size hints, i.e. respect size ratio.
1372 * \lfield border_width The client border width.
1373 * \lfield border_color The client border color.
1374 * \lfield titlebar The client titlebar.
1375 * \lfield urgent The client urgent state.
1376 * \lfield focus The focused client.
1377 * \lfield opacity The client opacity between 0 and 1.
1378 * \lfield ontop The client is on top of every other windows.
1379 * \lfield fullscreen The client is fullscreen or not.
1380 * \lfield transient_for Return the client the window is transient for.
1381 * \lfield size_hints A table with size hints of the client: user_position,
1382 * user_size, program_position and program_size.
1384 static int
1385 luaA_client_index(lua_State *L)
1387 size_t len;
1388 ssize_t slen;
1389 client_t **c = luaA_checkudata(L, 1, "client");
1390 const char *buf = luaL_checklstring(L, 2, &len);
1391 char *value;
1392 void *data;
1393 xcb_get_wm_class_reply_t hint;
1394 xcb_get_property_cookie_t prop_c;
1395 xcb_get_property_reply_t *prop_r = NULL;
1396 double d;
1398 if((*c)->invalid)
1399 luaL_error(L, "client is invalid\n");
1401 if(luaA_usemetatable(L, 1, 2))
1402 return 1;
1404 switch(a_tokenize(buf, len))
1406 case A_TK_NAME:
1407 lua_pushstring(L, (*c)->name);
1408 break;
1409 case A_TK_TRANSIENT_FOR:
1410 if((*c)->transient_for)
1411 return luaA_client_userdata_new(L, (*c)->transient_for);
1412 case A_TK_SKIP_TASKBAR:
1413 lua_pushboolean(L, (*c)->skiptb);
1414 break;
1415 case A_TK_TYPE:
1416 switch((*c)->type)
1418 case WINDOW_TYPE_DESKTOP:
1419 lua_pushliteral(L, "desktop");
1420 break;
1421 case WINDOW_TYPE_DOCK:
1422 lua_pushliteral(L, "dock");
1423 break;
1424 case WINDOW_TYPE_SPLASH:
1425 lua_pushliteral(L, "splash");
1426 break;
1427 case WINDOW_TYPE_DIALOG:
1428 lua_pushliteral(L, "dialog");
1429 break;
1430 default:
1431 lua_pushliteral(L, "normal");
1432 break;
1434 break;
1435 case A_TK_CLASS:
1436 if(!xcb_get_wm_class_reply(globalconf.connection,
1437 xcb_get_wm_class_unchecked(globalconf.connection, (*c)->win),
1438 &hint, NULL))
1439 return 0;
1440 lua_pushstring(L, hint.class);
1441 xcb_get_wm_class_reply_wipe(&hint);
1442 break;
1443 case A_TK_INSTANCE:
1444 if(!xcb_get_wm_class_reply(globalconf.connection,
1445 xcb_get_wm_class_unchecked(globalconf.connection, (*c)->win),
1446 &hint, NULL))
1447 return 0;
1448 lua_pushstring(L, hint.name);
1449 xcb_get_wm_class_reply_wipe(&hint);
1450 break;
1451 case A_TK_ROLE:
1452 if(!xutil_text_prop_get(globalconf.connection, (*c)->win,
1453 WM_WINDOW_ROLE, &value, &slen))
1454 return 0;
1455 lua_pushlstring(L, value, slen);
1456 p_delete(&value);
1457 break;
1458 case A_TK_PID:
1459 prop_c = xcb_get_property_unchecked(globalconf.connection, false, (*c)->win, _NET_WM_PID, CARDINAL, 0L, 1L);
1460 prop_r = xcb_get_property_reply(globalconf.connection, prop_c, NULL);
1462 if(prop_r && prop_r->value_len && (data = xcb_get_property_value(prop_r)))
1463 lua_pushnumber(L, *(uint32_t *)data);
1464 else
1466 p_delete(&prop_r);
1467 return 0;
1469 break;
1470 case A_TK_MACHINE:
1471 if(!xutil_text_prop_get(globalconf.connection, (*c)->win,
1472 WM_CLIENT_MACHINE, &value, &slen))
1473 return 0;
1474 lua_pushlstring(L, value, slen);
1475 p_delete(&value);
1476 break;
1477 case A_TK_ICON_NAME:
1478 lua_pushstring(L, (*c)->icon_name);
1479 break;
1480 case A_TK_SCREEN:
1481 lua_pushnumber(L, 1 + (*c)->screen);
1482 break;
1483 case A_TK_HIDE:
1484 lua_pushboolean(L, (*c)->ishidden);
1485 break;
1486 case A_TK_MINIMIZE:
1487 lua_pushboolean(L, (*c)->isminimized);
1488 break;
1489 case A_TK_FULLSCREEN:
1490 lua_pushboolean(L, (*c)->isfullscreen);
1491 break;
1492 case A_TK_ICON:
1493 if((*c)->icon)
1494 luaA_image_userdata_new(L, (*c)->icon);
1495 else
1496 return 0;
1497 break;
1498 case A_TK_OPACITY:
1499 if((d = window_opacity_get((*c)->win)) >= 0)
1500 lua_pushnumber(L, d);
1501 else
1502 return 0;
1503 break;
1504 case A_TK_FLOATING:
1505 lua_pushboolean(L, client_isfloating(*c));
1506 break;
1507 case A_TK_ONTOP:
1508 lua_pushboolean(L, (*c)->isontop);
1509 break;
1510 case A_TK_STICKY:
1511 lua_pushboolean(L, (*c)->issticky);
1512 break;
1513 case A_TK_HONORSIZEHINTS:
1514 lua_pushboolean(L, (*c)->honorsizehints);
1515 break;
1516 case A_TK_BORDER_WIDTH:
1517 lua_pushnumber(L, (*c)->border);
1518 break;
1519 case A_TK_BORDER_COLOR:
1520 luaA_pushcolor(L, &(*c)->border_color);
1521 break;
1522 case A_TK_TITLEBAR:
1523 if((*c)->titlebar)
1524 return luaA_wibox_userdata_new(L, (*c)->titlebar);
1525 return 0;
1526 case A_TK_URGENT:
1527 lua_pushboolean(L, (*c)->isurgent);
1528 break;
1529 case A_TK_SIZE_HINTS:
1530 lua_newtable(L);
1531 lua_pushboolean(L, (*c)->size_hints.flags & XCB_SIZE_HINT_US_POSITION);
1532 lua_setfield(L, -2, "user_position");
1533 lua_pushboolean(L, (*c)->size_hints.flags & XCB_SIZE_HINT_US_SIZE);
1534 lua_setfield(L, -2, "user_size");
1535 lua_pushboolean(L, (*c)->size_hints.flags & XCB_SIZE_HINT_P_POSITION);
1536 lua_setfield(L, -2, "program_position");
1537 lua_pushboolean(L, (*c)->size_hints.flags & XCB_SIZE_HINT_P_SIZE);
1538 lua_setfield(L, -2, "program_size");
1539 break;
1540 default:
1541 return 0;
1544 return 1;
1547 /** Get or set mouse buttons bindings for a client.
1548 * \param L The Lua VM state.
1549 * \return The number of element pushed on stack.
1550 * \luastack
1551 * \lvalue A client.
1552 * \lparam An array of mouse button bindings objects, or nothing.
1553 * \return The array of mouse button bindings objects of this client.
1555 static int
1556 luaA_client_buttons(lua_State *L)
1558 client_t **client = luaA_checkudata(L, 1, "client");
1559 button_array_t *buttons = &(*client)->buttons;
1561 if(lua_gettop(L) == 2)
1562 luaA_button_array_set(L, 2, buttons);
1564 return luaA_button_array_get(L, buttons);
1567 /* Client module.
1568 * \param L The Lua VM state.
1569 * \return The number of pushed elements.
1571 static int
1572 luaA_client_module_index(lua_State *L)
1574 size_t len;
1575 const char *buf = luaL_checklstring(L, 2, &len);
1577 switch(a_tokenize(buf, len))
1579 case A_TK_FOCUS:
1580 if(globalconf.screen_focus->client_focus)
1581 luaA_client_userdata_new(L, globalconf.screen_focus->client_focus);
1582 else
1583 return 0;
1584 break;
1585 default:
1586 return 0;
1589 return 1;
1592 /* Client module new index.
1593 * \param L The Lua VM state.
1594 * \return The number of pushed elements.
1596 static int
1597 luaA_client_module_newindex(lua_State *L)
1599 size_t len;
1600 const char *buf = luaL_checklstring(L, 2, &len);
1601 client_t **c;
1603 switch(a_tokenize(buf, len))
1605 case A_TK_FOCUS:
1606 c = luaA_checkudata(L, 3, "client");
1607 client_focus(*c);
1608 break;
1609 default:
1610 break;
1613 return 0;
1616 const struct luaL_reg awesome_client_methods[] =
1618 { "get", luaA_client_get },
1619 { "visible_get", luaA_client_visible_get },
1620 { "__index", luaA_client_module_index },
1621 { "__newindex", luaA_client_module_newindex },
1622 { NULL, NULL }
1624 const struct luaL_reg awesome_client_meta[] =
1626 { "isvisible", luaA_client_isvisible },
1627 { "geometry", luaA_client_geometry },
1628 { "fullgeometry", luaA_client_fullgeometry },
1629 { "buttons", luaA_client_buttons },
1630 { "tags", luaA_client_tags },
1631 { "kill", luaA_client_kill },
1632 { "swap", luaA_client_swap },
1633 { "raise", luaA_client_raise },
1634 { "lower", luaA_client_lower },
1635 { "redraw", luaA_client_redraw },
1636 { "mouse_resize", luaA_client_mouse_resize },
1637 { "mouse_move", luaA_client_mouse_move },
1638 { "unmanage", luaA_client_unmanage },
1639 { "__index", luaA_client_index },
1640 { "__newindex", luaA_client_newindex },
1641 { "__eq", luaA_client_eq },
1642 { "__gc", luaA_client_gc },
1643 { "__tostring", luaA_client_tostring },
1644 /* deprecated */
1645 { "coords", luaA_client_coords },
1646 { "fullcoords", luaA_client_fullcoords },
1647 { NULL, NULL }
1650 // vim: filetype=c:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=80