awful.prompt: stop grabbing keyboard before calling callback
[awesome.git] / client.c
blob2aec5051c40912624ea76f4263562f7ffae9a840
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 if(c->isontop)
290 return LAYER_ONTOP;
291 else if(c->isfullscreen)
292 return LAYER_FULLSCREEN;
293 else if(c->isabove)
294 return LAYER_ABOVE;
295 else if(c->isfloating || client_isfixed(c))
296 return LAYER_FLOAT;
297 else if(c->transient_for)
298 return LAYER_IGNORE;
300 switch(c->type)
302 case WINDOW_TYPE_DOCK:
303 return LAYER_ABOVE;
304 case WINDOW_TYPE_DESKTOP:
305 return LAYER_DESKTOP;
306 case WINDOW_TYPE_DIALOG:
307 return LAYER_FLOAT;
308 default:
309 return LAYER_TILE;
313 /** Restack clients.
314 * \todo It might be worth stopping to restack everyone and only stack `c'
315 * relatively to the first matching in the list.
317 void
318 client_stack()
320 uint32_t config_win_vals[2];
321 client_node_t *node, *last = *client_node_list_last(&globalconf.stack);
322 layer_t layer;
323 int screen;
325 config_win_vals[0] = XCB_NONE;
326 config_win_vals[1] = XCB_STACK_MODE_ABOVE;
328 /* first stack not ontop wibox window */
329 for(screen = 0; screen < globalconf.nscreen; screen++)
330 for(int i = 0; i < globalconf.screens[screen].wiboxes.len; i++)
332 wibox_t *sb = globalconf.screens[screen].wiboxes.tab[i];
333 if(!sb->ontop)
335 xcb_configure_window(globalconf.connection,
336 sb->sw.window,
337 XCB_CONFIG_WINDOW_SIBLING | XCB_CONFIG_WINDOW_STACK_MODE,
338 config_win_vals);
339 config_win_vals[0] = sb->sw.window;
343 /* stack bottom layers */
344 for(layer = LAYER_DESKTOP; layer < LAYER_FULLSCREEN; layer++)
345 for(node = last; node; node = node->prev)
346 if(client_layer_translator(node->client) == layer)
347 config_win_vals[0] = client_stack_above(node->client,
348 config_win_vals[0]);
350 /* then stack ontop wibox window */
351 for(screen = 0; screen < globalconf.nscreen; screen++)
352 for(int i = 0; i < globalconf.screens[screen].wiboxes.len; i++)
354 wibox_t *sb = globalconf.screens[screen].wiboxes.tab[i];
355 if(sb->ontop)
357 xcb_configure_window(globalconf.connection,
358 sb->sw.window,
359 XCB_CONFIG_WINDOW_SIBLING | XCB_CONFIG_WINDOW_STACK_MODE,
360 config_win_vals);
361 config_win_vals[0] = sb->sw.window;
365 /* finally stack ontop and fullscreen windows */
366 for(layer = LAYER_FULLSCREEN; layer < LAYER_OUTOFSPACE; layer++)
367 for(node = last; node; node = node->prev)
368 if(client_layer_translator(node->client) == layer)
369 config_win_vals[0] = client_stack_above(node->client,
370 config_win_vals[0]);
373 /** Manage a new client.
374 * \param w The window.
375 * \param wgeom Window geometry.
376 * \param phys_screen Physical screen number.
377 * \param screen Virtual screen number where to manage client.
379 void
380 client_manage(xcb_window_t w, xcb_get_geometry_reply_t *wgeom, int phys_screen, int screen)
382 xcb_get_property_cookie_t ewmh_icon_cookie;
383 client_t *c;
384 image_t *icon;
385 const uint32_t select_input_val[] =
387 XCB_EVENT_MASK_STRUCTURE_NOTIFY
388 | XCB_EVENT_MASK_PROPERTY_CHANGE
389 | XCB_EVENT_MASK_ENTER_WINDOW
392 /* Send request to get NET_WM_ICON property as soon as possible... */
393 ewmh_icon_cookie = ewmh_window_icon_get_unchecked(w);
394 xcb_change_window_attributes(globalconf.connection, w, XCB_CW_EVENT_MASK, select_input_val);
396 if(systray_iskdedockapp(w))
398 systray_request_handle(w, phys_screen, NULL);
399 return;
402 c = p_new(client_t, 1);
404 c->screen = screen_getbycoord(screen, wgeom->x, wgeom->y);
406 c->phys_screen = phys_screen;
408 /* Initial values */
409 c->win = w;
410 c->geometry.x = c->f_geometry.x = c->m_geometry.x = wgeom->x;
411 c->geometry.y = c->f_geometry.y = c->m_geometry.y = wgeom->y;
412 c->geometry.width = c->f_geometry.width = c->m_geometry.width = wgeom->width;
413 c->geometry.height = c->f_geometry.height = c->m_geometry.height = wgeom->height;
414 client_setborder(c, wgeom->border_width);
415 if((icon = ewmh_window_icon_get_reply(ewmh_icon_cookie)))
416 c->icon = image_ref(&icon);
418 /* we honor size hints by default */
419 c->honorsizehints = true;
421 /* update hints */
422 property_update_wm_normal_hints(c, NULL);
423 property_update_wm_hints(c, NULL);
424 property_update_wm_transient_for(c, NULL);
426 if(c->transient_for)
427 screen = c->transient_for->screen;
429 /* Try to load props if any */
430 client_loadprops(c, &globalconf.screens[screen]);
433 /* Then check clients hints */
434 ewmh_client_check_hints(c);
436 /* move client to screen, but do not tag it for now */
437 screen_client_moveto(c, screen, false, true);
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, client_ref(&c));
461 /* Push client in stack */
462 client_raise(c);
464 /* update window title */
465 property_update_wm_name(c);
466 property_update_wm_icon_name(c);
468 /* update strut */
469 ewmh_client_strut_update(c, NULL);
471 ewmh_update_net_client_list(c->phys_screen);
473 /* Call hook to notify list change */
474 luaA_dofunction(globalconf.L, globalconf.hooks.clients, 0, 0);
476 /* call hook */
477 luaA_client_userdata_new(globalconf.L, c);
478 luaA_dofunction(globalconf.L, globalconf.hooks.manage, 1, 0);
481 /** Compute client geometry with respect to its geometry hints.
482 * \param c The client.
483 * \param geometry The geometry that the client might receive.
484 * \return The geometry the client must take respecting its hints.
486 area_t
487 client_geometry_hints(client_t *c, area_t geometry)
489 double dx, dy, max, min, ratio;
491 if(c->minay > 0 && c->maxay > 0 && (geometry.height - c->baseh) > 0
492 && (geometry.width - c->basew) > 0)
494 dx = (double) (geometry.width - c->basew);
495 dy = (double) (geometry.height - c->baseh);
496 min = (double) (c->minax) / (double) (c->minay);
497 max = (double) (c->maxax) / (double) (c->maxay);
498 ratio = dx / dy;
499 if(max > 0 && min > 0 && ratio > 0)
501 if(ratio < min)
503 dy = (dx * min + dy) / (min * min + 1);
504 dx = dy * min;
505 geometry.width = (int) dx + c->basew;
506 geometry.height = (int) dy + c->baseh;
508 else if(ratio > max)
510 dy = (dx * min + dy) / (max * max + 1);
511 dx = dy * min;
512 geometry.width = (int) dx + c->basew;
513 geometry.height = (int) dy + c->baseh;
517 if(c->minw && geometry.width < c->minw)
518 geometry.width = c->minw;
519 if(c->minh && geometry.height < c->minh)
520 geometry.height = c->minh;
521 if(c->maxw && geometry.width > c->maxw)
522 geometry.width = c->maxw;
523 if(c->maxh && geometry.height > c->maxh)
524 geometry.height = c->maxh;
525 if(c->incw)
526 geometry.width -= (geometry.width - c->basew) % c->incw;
527 if(c->inch)
528 geometry.height -= (geometry.height - c->baseh) % c->inch;
530 return geometry;
533 /** Resize client window.
534 * \param c Client to resize.
535 * \param geometry New window geometry.
536 * \param hints Use size hints.
538 void
539 client_resize(client_t *c, area_t geometry, bool hints)
541 int new_screen;
542 area_t area;
543 layout_t *layout = layout_get_current(c->screen);
544 /* Values to configure a window is an array where values are
545 * stored according to 'value_mask' */
546 uint32_t values[5];
548 if(c->titlebar && !c->ismoving && !client_isfloating(c) && layout != layout_floating)
549 geometry = titlebar_geometry_remove(c->titlebar, c->border, geometry);
551 if(hints)
552 geometry = client_geometry_hints(c, geometry);
554 if(geometry.width <= 0 || geometry.height <= 0)
555 return;
557 /* offscreen appearance fixes */
558 area = display_area_get(c->phys_screen, NULL,
559 &globalconf.screens[c->screen].padding);
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 if(c->geometry.x != geometry.x
571 || c->geometry.y != geometry.y
572 || c->geometry.width != geometry.width
573 || c->geometry.height != geometry.height)
575 new_screen = screen_getbycoord(c->screen, geometry.x, geometry.y);
577 c->geometry.x = values[0] = geometry.x;
578 c->geometry.width = values[2] = geometry.width;
579 c->geometry.y = values[1] = geometry.y;
580 c->geometry.height = values[3] = geometry.height;
581 values[4] = c->border;
583 /* save the floating geometry if the window is floating but not
584 * maximized */
585 if(c->ismoving || client_isfloating(c)
586 || layout_get_current(new_screen) == layout_floating)
587 if(!c->isfullscreen)
588 c->f_geometry = geometry;
590 titlebar_update_geometry_floating(c);
592 xcb_configure_window(globalconf.connection, c->win,
593 XCB_CONFIG_WINDOW_X | XCB_CONFIG_WINDOW_Y |
594 XCB_CONFIG_WINDOW_WIDTH | XCB_CONFIG_WINDOW_HEIGHT |
595 XCB_CONFIG_WINDOW_BORDER_WIDTH,
596 values);
597 window_configure(c->win, geometry, c->border);
599 if(c->screen != new_screen)
600 screen_client_moveto(c, new_screen, true, false);
602 /* execute hook */
603 hooks_property(c, "geometry");
607 /** Set a clinet floating.
608 * \param c The client.
609 * \param floating Set floating, or not.
610 * \param layer Layer to put the floating window onto.
612 void
613 client_setfloating(client_t *c, bool floating)
615 if(c->isfloating != floating
616 && (c->type == WINDOW_TYPE_NORMAL))
618 if((c->isfloating = floating))
619 if(!c->isfullscreen)
620 client_resize(c, c->f_geometry, false);
621 client_need_arrange(c);
622 client_stack();
623 xcb_change_property(globalconf.connection,
624 XCB_PROP_MODE_REPLACE,
625 c->win, _AWESOME_FLOATING, CARDINAL, 8, 1,
626 &c->isfloating);
627 /* execute hook */
628 hooks_property(c, "floating");
632 /** Set a client minimized, or not.
633 * \param c The client.
634 * \param s Set or not the client minimized.
636 void
637 client_setminimized(client_t *c, bool s)
639 if(c->isminimized != s)
641 client_need_arrange(c);
642 c->isminimized = s;
643 client_need_arrange(c);
644 ewmh_client_update_hints(c);
645 /* execute hook */
646 hooks_property(c, "minimized");
650 /** Set a client sticky, or not.
651 * \param c The client.
652 * \param s Set or not the client sticky.
654 void
655 client_setsticky(client_t *c, bool s)
657 if(c->issticky != s)
659 client_need_arrange(c);
660 c->issticky = s;
661 client_need_arrange(c);
662 ewmh_client_update_hints(c);
663 hooks_property(c, "sticky");
667 /** Set a client fullscreen, or not.
668 * \param c The client.
669 * \param s Set or not the client fullscreen.
671 void
672 client_setfullscreen(client_t *c, bool s)
674 if(c->isfullscreen != s)
676 area_t geometry;
678 /* become fullscreen! */
679 if((c->isfullscreen = s))
681 geometry = screen_area_get(c->screen, NULL, NULL, false);
682 c->m_geometry = c->geometry;
683 c->oldborder = c->border;
684 client_setborder(c, 0);
686 else
688 geometry = c->m_geometry;
689 client_setborder(c, c->oldborder);
690 client_resize(c, c->m_geometry, false);
692 client_resize(c, geometry, false);
693 client_need_arrange(c);
694 client_stack();
695 xcb_change_property(globalconf.connection,
696 XCB_PROP_MODE_REPLACE,
697 c->win, _AWESOME_FULLSCREEN, CARDINAL, 8, 1,
698 &c->isfullscreen);
699 ewmh_client_update_hints(c);
700 hooks_property(c, "fullscreen");
704 /** Set a client above, or not.
705 * \param c The client.
706 * \param s Set or not the client above.
708 void
709 client_setabove(client_t *c, bool s)
711 if(c->isabove != s)
713 c->isabove = s;
714 client_stack();
715 ewmh_client_update_hints(c);
716 /* execute hook */
717 hooks_property(c, "above");
721 /** Set a client below, or not.
722 * \param c The client.
723 * \param s Set or not the client below.
725 void
726 client_setbelow(client_t *c, bool s)
728 if(c->isbelow != s)
730 c->isbelow = s;
731 client_stack();
732 ewmh_client_update_hints(c);
733 /* execute hook */
734 hooks_property(c, "below");
738 /** Set a client modal, or not.
739 * \param c The client.
740 * \param s Set or not the client moda.
742 void
743 client_setmodal(client_t *c, bool s)
745 if(c->ismodal != s)
747 c->ismodal = s;
748 client_stack();
749 ewmh_client_update_hints(c);
750 /* execute hook */
751 hooks_property(c, "modal");
755 /** Set a client ontop, or not.
756 * \param c The client.
757 * \param s Set or not the client moda.
759 void
760 client_setontop(client_t *c, bool s)
762 if(c->isontop != s)
764 c->isontop = s;
765 client_stack();
766 /* execute hook */
767 hooks_property(c, "ontop");
771 /** Save client properties as an X property.
772 * \param c The client.
774 void
775 client_saveprops_tags(client_t *c)
777 tag_array_t *tags = &globalconf.screens[c->screen].tags;
778 unsigned char *prop = p_alloca(unsigned char, tags->len + 1);
779 int i;
781 for(i = 0; i < tags->len; i++)
782 prop[i] = is_client_tagged(c, tags->tab[i]) ? '1' : '0';
784 xcb_change_property(globalconf.connection, XCB_PROP_MODE_REPLACE, c->win, _AWESOME_TAGS, STRING, 8, i, prop);
787 /** Unban a client.
788 * \param c The client.
790 void
791 client_unban(client_t *c)
793 xcb_map_window(globalconf.connection, c->win);
794 window_state_set(c->win, XCB_WM_STATE_NORMAL);
795 if(c->titlebar)
797 if(c->isfullscreen || !c->titlebar->isvisible)
798 xcb_unmap_window(globalconf.connection, c->titlebar->sw.window);
799 else
800 xcb_map_window(globalconf.connection, c->titlebar->sw.window);
804 /** Unmanage a client.
805 * \param c The client.
807 void
808 client_unmanage(client_t *c)
810 tag_array_t *tags = &globalconf.screens[c->screen].tags;
812 if(globalconf.screens[c->phys_screen].client_focus == c)
813 client_unfocus(c);
815 /* remove client everywhere */
816 client_list_detach(&globalconf.clients, c);
817 stack_client_delete(c);
818 for(int i = 0; i < tags->len; i++)
819 untag_client(c, tags->tab[i]);
821 /* call hook */
822 luaA_client_userdata_new(globalconf.L, c);
823 luaA_dofunction(globalconf.L, globalconf.hooks.unmanage, 1, 0);
825 /* Call hook to notify list change */
826 luaA_dofunction(globalconf.L, globalconf.hooks.clients, 0, 0);
828 /* The server grab construct avoids race conditions. */
829 xcb_grab_server(globalconf.connection);
831 xcb_configure_window(globalconf.connection, c->win,
832 XCB_CONFIG_WINDOW_BORDER_WIDTH,
833 (uint32_t *) &c->oldborder);
835 xcb_ungrab_button(globalconf.connection, XCB_BUTTON_INDEX_ANY, c->win,
836 XCB_BUTTON_MASK_ANY);
837 window_state_set(c->win, XCB_WM_STATE_WITHDRAWN);
839 xcb_flush(globalconf.connection);
840 xcb_ungrab_server(globalconf.connection);
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 KillClient if not
866 * supported.
867 * \param c The client to kill.
869 void
870 client_kill(client_t *c)
872 if(window_hasproto(c->win, WM_DELETE_WINDOW))
874 xcb_client_message_event_t ev;
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(L);
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);
1037 /* Call hook to notify list change */
1038 luaA_dofunction(L, globalconf.hooks.clients, 0, 0);
1040 return 0;
1043 /** Access or set the client tags.
1044 * \param L The Lua VM state.
1045 * \return The number of elements pushed on stack.
1046 * \lparam A table with tags to set, or none to get the current tags table.
1047 * \return The clients tag.
1049 static int
1050 luaA_client_tags(lua_State *L)
1052 tag_array_t *tags;
1053 tag_t **tag;
1054 client_t **c = luaA_checkudata(L, 1, "client");
1055 int j = 0;
1057 if(lua_gettop(L) == 2)
1059 luaA_checktable(L, 2);
1060 tags = &globalconf.screens[(*c)->screen].tags;
1061 for(int i = 0; i < tags->len; i++)
1062 untag_client(*c, tags->tab[i]);
1063 lua_pushnil(L);
1064 while(lua_next(L, 2))
1066 tag = luaA_checkudata(L, -1, "tag");
1067 tag_client(*c, *tag);
1068 lua_pop(L, 1);
1070 lua_pop(L, 1);
1073 tags = &globalconf.screens[(*c)->screen].tags;
1074 luaA_otable_new(L);
1075 for(int i = 0; i < tags->len; i++)
1076 if(is_client_tagged(*c, tags->tab[i]))
1078 luaA_tag_userdata_new(L, tags->tab[i]);
1079 lua_rawseti(L, -2, ++j);
1082 return 1;
1085 /** Raise a client on top of others which are on the same layer.
1086 * \param L The Lua VM state.
1087 * \luastack
1088 * \lvalue A client.
1090 static int
1091 luaA_client_raise(lua_State *L)
1093 client_t **c = luaA_checkudata(L, 1, "client");
1094 client_raise(*c);
1095 return 0;
1098 /** Lower a client on bottom of others which are on the same layer.
1099 * \param L The Lua VM state.
1100 * \luastack
1101 * \lvalue A client.
1103 static int
1104 luaA_client_lower(lua_State *L)
1106 client_t **c = luaA_checkudata(L, 1, "client");
1107 client_lower(*c);
1108 return 0;
1111 /** Redraw a client by unmapping and mapping it quickly.
1112 * \param L The Lua VM state.
1114 * \luastack
1115 * \lvalue A client.
1117 static int
1118 luaA_client_redraw(lua_State *L)
1120 client_t **c = luaA_checkudata(L, 1, "client");
1122 xcb_unmap_window(globalconf.connection, (*c)->win);
1123 xcb_map_window(globalconf.connection, (*c)->win);
1125 /* Set the focus on the current window if the redraw has been
1126 performed on the window where the pointer is currently on
1127 because after the unmapping/mapping, the focus is lost */
1128 if(globalconf.screen_focus->client_focus == *c)
1129 xcb_set_input_focus(globalconf.connection, XCB_INPUT_FOCUS_POINTER_ROOT,
1130 (*c)->win, XCB_CURRENT_TIME);
1132 return 0;
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 geometry.
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_geometry(lua_State *L)
1159 client_t **c = luaA_checkudata(L, 1, "client");
1161 if(lua_gettop(L) == 2)
1162 if(client_isfloating(*c)
1163 || 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 if(client_isfixed(*c))
1172 geometry.width = (*c)->geometry.width;
1173 geometry.height = (*c)->geometry.height;
1175 else
1177 geometry.width = luaA_getopt_number(L, 2, "width", (*c)->geometry.width);
1178 geometry.height = luaA_getopt_number(L, 2, "height", (*c)->geometry.height);
1180 client_resize(*c, geometry, false);
1183 return luaA_pusharea(L, (*c)->geometry);
1186 static int
1187 luaA_client_coords(lua_State *L)
1189 deprecate(L);
1190 return luaA_client_geometry(L);
1193 /** Return client geometry, using also titlebar and border width.
1194 * \param L The Lua VM state.
1195 * \return The number of elements pushed on stack.
1196 * \luastack
1197 * \lparam A table with new coordinates, or none.
1198 * \lreturn A table with client coordinates.
1200 static int
1201 luaA_client_fullgeometry(lua_State *L)
1203 client_t **c = luaA_checkudata(L, 1, "client");
1204 area_t geometry;
1206 if(lua_gettop(L) == 2)
1208 if((*c)->isfloating || layout_get_current((*c)->screen) == layout_floating)
1210 luaA_checktable(L, 2);
1211 geometry.x = luaA_getopt_number(L, 2, "x", (*c)->geometry.x);
1212 geometry.y = luaA_getopt_number(L, 2, "y", (*c)->geometry.y);
1213 geometry.width = luaA_getopt_number(L, 2, "width", (*c)->geometry.width);
1214 geometry.height = luaA_getopt_number(L, 2, "height", (*c)->geometry.height);
1215 geometry = titlebar_geometry_remove((*c)->titlebar,
1216 (*c)->border,
1217 geometry);
1218 client_resize(*c, geometry, false);
1222 return luaA_pusharea(L, titlebar_geometry_add((*c)->titlebar,
1223 (*c)->border,
1224 (*c)->geometry));
1227 static int
1228 luaA_client_fullcoords(lua_State *L)
1230 deprecate(L);
1231 return luaA_client_fullgeometry(L);
1234 /** Client newindex.
1235 * \param L The Lua VM state.
1236 * \return The number of elements pushed on stack.
1239 luaA_client_newindex(lua_State *L)
1241 size_t len;
1242 client_t **c = luaA_checkudata(L, 1, "client");
1243 const char *buf = luaL_checklstring(L, 2, &len);
1244 bool b;
1245 double d;
1246 int i;
1247 wibox_t **t = NULL;
1248 image_t **image;
1250 if((*c)->invalid)
1251 luaL_error(L, "client is invalid\n");
1253 switch(a_tokenize(buf, len))
1255 case A_TK_SCREEN:
1256 if(globalconf.xinerama_is_active)
1258 i = luaL_checknumber(L, 3) - 1;
1259 luaA_checkscreen(i);
1260 if(i != (*c)->screen)
1261 screen_client_moveto(*c, i, true, true);
1263 break;
1264 case A_TK_HIDE:
1265 b = luaA_checkboolean(L, 3);
1266 if(b != (*c)->ishidden)
1268 client_need_arrange(*c);
1269 (*c)->ishidden = b;
1270 client_need_arrange(*c);
1272 break;
1273 case A_TK_MINIMIZE:
1274 client_setminimized(*c, luaA_checkboolean(L, 3));
1275 break;
1276 case A_TK_FULLSCREEN:
1277 client_setfullscreen(*c, luaA_checkboolean(L, 3));
1278 break;
1279 case A_TK_ICON:
1280 image = luaA_checkudata(L, 3, "image");
1281 image_unref(&(*c)->icon);
1282 image_ref(image);
1283 (*c)->icon = *image;
1284 /* execute hook */
1285 hooks_property(*c, "icon");
1286 break;
1287 case A_TK_OPACITY:
1288 if(lua_isnil(L, 3))
1289 window_opacity_set((*c)->win, -1);
1290 else
1292 d = luaL_checknumber(L, 3);
1293 if(d >= 0 && d <= 1)
1294 window_opacity_set((*c)->win, d);
1296 break;
1297 case A_TK_FLOATING:
1298 client_setfloating(*c, luaA_checkboolean(L, 3));
1299 break;
1300 case A_TK_STICKY:
1301 client_setsticky(*c, luaA_checkboolean(L, 3));
1302 break;
1303 case A_TK_HONORSIZEHINTS:
1304 (*c)->honorsizehints = luaA_checkboolean(L, 3);
1305 client_need_arrange(*c);
1306 break;
1307 case A_TK_BORDER_WIDTH:
1308 client_setborder(*c, luaL_checknumber(L, 3));
1309 break;
1310 case A_TK_ONTOP:
1311 client_setontop(*c, luaA_checkboolean(L, 3));
1312 break;
1313 case A_TK_BORDER_COLOR:
1314 if((buf = luaL_checklstring(L, 3, &len))
1315 && xcolor_init_reply(xcolor_init_unchecked(&(*c)->border_color, buf, len)))
1316 xcb_change_window_attributes(globalconf.connection, (*c)->win,
1317 XCB_CW_BORDER_PIXEL, &(*c)->border_color.pixel);
1318 break;
1319 case A_TK_TITLEBAR:
1320 if(lua_isnil(L, 3))
1321 titlebar_client_detach(*c);
1322 else
1324 t = luaA_checkudata(L, 3, "wibox");
1325 titlebar_client_attach(*c, *t);
1327 break;
1328 default:
1329 return 0;
1332 return 0;
1335 /** Client object.
1336 * \param L The Lua VM state.
1337 * \return The number of elements pushed on stack.
1338 * \luastack
1339 * \lfield name The client title.
1340 * \lfield skip_taskbar True if the client does not want to be in taskbar.
1341 * \lfield type The window type (desktop, normal, dock, …).
1342 * \lfield class The client class.
1343 * \lfield instance The client instance.
1344 * \lfield pid The client PID, if available.
1345 * \lfield role The window role, if available.
1346 * \lfield machine The machine client is running on.
1347 * \lfield icon_name The client name when iconified.
1348 * \lfield screen Client screen number.
1349 * \lfield hide Define if the client must be hidden, i.e. never mapped,
1350 * invisible in taskbar.
1351 * \lfield minimize Define it the client must be iconify, i.e. only visible in
1352 * taskbar.
1353 * \lfield icon_path Path to the icon used to identify.
1354 * \lfield floating True always floating.
1355 * \lfield honorsizehints Honor size hints, i.e. respect size ratio.
1356 * \lfield border_width The client border width.
1357 * \lfield border_color The client border color.
1358 * \lfield titlebar The client titlebar.
1359 * \lfield urgent The client urgent state.
1360 * \lfield focus The focused client.
1361 * \lfield opacity The client opacity between 0 and 1.
1362 * \lfield ontop The client is on top of every other windows.
1363 * \lfield fullscreen The client is fullscreen or not.
1364 * \lfield transient_for Return the client the window is transient for.
1365 * \lfield size_hints A table with size hints of the client: user_position,
1366 * user_size, program_position and program_size.
1368 static int
1369 luaA_client_index(lua_State *L)
1371 size_t len;
1372 ssize_t slen;
1373 client_t **c = luaA_checkudata(L, 1, "client");
1374 const char *buf = luaL_checklstring(L, 2, &len);
1375 char *value;
1376 void *data;
1377 xcb_get_wm_class_reply_t hint;
1378 xcb_get_property_cookie_t prop_c;
1379 xcb_get_property_reply_t *prop_r = NULL;
1380 double d;
1382 if((*c)->invalid)
1383 luaL_error(L, "client is invalid\n");
1385 if(luaA_usemetatable(L, 1, 2))
1386 return 1;
1388 switch(a_tokenize(buf, len))
1390 case A_TK_NAME:
1391 lua_pushstring(L, (*c)->name);
1392 break;
1393 case A_TK_TRANSIENT_FOR:
1394 if((*c)->transient_for)
1395 return luaA_client_userdata_new(L, (*c)->transient_for);
1396 case A_TK_SKIP_TASKBAR:
1397 lua_pushboolean(L, (*c)->skiptb);
1398 break;
1399 case A_TK_TYPE:
1400 switch((*c)->type)
1402 case WINDOW_TYPE_DESKTOP:
1403 lua_pushliteral(L, "desktop");
1404 break;
1405 case WINDOW_TYPE_DOCK:
1406 lua_pushliteral(L, "dock");
1407 break;
1408 case WINDOW_TYPE_SPLASH:
1409 lua_pushliteral(L, "splash");
1410 break;
1411 case WINDOW_TYPE_DIALOG:
1412 lua_pushliteral(L, "dialog");
1413 break;
1414 default:
1415 lua_pushliteral(L, "normal");
1416 break;
1418 break;
1419 case A_TK_CLASS:
1420 if(!xcb_get_wm_class_reply(globalconf.connection,
1421 xcb_get_wm_class_unchecked(globalconf.connection, (*c)->win),
1422 &hint, NULL))
1423 return 0;
1424 lua_pushstring(L, hint.class);
1425 xcb_get_wm_class_reply_wipe(&hint);
1426 break;
1427 case A_TK_INSTANCE:
1428 if(!xcb_get_wm_class_reply(globalconf.connection,
1429 xcb_get_wm_class_unchecked(globalconf.connection, (*c)->win),
1430 &hint, NULL))
1431 return 0;
1432 lua_pushstring(L, hint.name);
1433 xcb_get_wm_class_reply_wipe(&hint);
1434 break;
1435 case A_TK_ROLE:
1436 if(!xutil_text_prop_get(globalconf.connection, (*c)->win,
1437 WM_WINDOW_ROLE, &value, &slen))
1438 return 0;
1439 lua_pushlstring(L, value, slen);
1440 p_delete(&value);
1441 break;
1442 case A_TK_PID:
1443 prop_c = xcb_get_property_unchecked(globalconf.connection, false, (*c)->win, _NET_WM_PID, CARDINAL, 0L, 1L);
1444 prop_r = xcb_get_property_reply(globalconf.connection, prop_c, NULL);
1446 if(prop_r && prop_r->value_len && (data = xcb_get_property_value(prop_r)))
1447 lua_pushnumber(L, *(uint32_t *)data);
1448 else
1450 p_delete(&prop_r);
1451 return 0;
1453 break;
1454 case A_TK_MACHINE:
1455 if(!xutil_text_prop_get(globalconf.connection, (*c)->win,
1456 WM_CLIENT_MACHINE, &value, &slen))
1457 return 0;
1458 lua_pushlstring(L, value, slen);
1459 p_delete(&value);
1460 break;
1461 case A_TK_ICON_NAME:
1462 lua_pushstring(L, (*c)->icon_name);
1463 break;
1464 case A_TK_SCREEN:
1465 lua_pushnumber(L, 1 + (*c)->screen);
1466 break;
1467 case A_TK_HIDE:
1468 lua_pushboolean(L, (*c)->ishidden);
1469 break;
1470 case A_TK_MINIMIZE:
1471 lua_pushboolean(L, (*c)->isminimized);
1472 break;
1473 case A_TK_FULLSCREEN:
1474 lua_pushboolean(L, (*c)->isfullscreen);
1475 break;
1476 case A_TK_ICON:
1477 if((*c)->icon)
1478 luaA_image_userdata_new(L, (*c)->icon);
1479 else
1480 return 0;
1481 break;
1482 case A_TK_OPACITY:
1483 if((d = window_opacity_get((*c)->win)) >= 0)
1484 lua_pushnumber(L, d);
1485 else
1486 return 0;
1487 break;
1488 case A_TK_FLOATING:
1489 lua_pushboolean(L, (*c)->isfloating);
1490 break;
1491 case A_TK_ONTOP:
1492 lua_pushboolean(L, (*c)->isontop);
1493 break;
1494 case A_TK_STICKY:
1495 lua_pushboolean(L, (*c)->issticky);
1496 break;
1497 case A_TK_HONORSIZEHINTS:
1498 lua_pushboolean(L, (*c)->honorsizehints);
1499 break;
1500 case A_TK_BORDER_WIDTH:
1501 lua_pushnumber(L, (*c)->border);
1502 break;
1503 case A_TK_BORDER_COLOR:
1504 luaA_pushcolor(L, &(*c)->border_color);
1505 break;
1506 case A_TK_TITLEBAR:
1507 if((*c)->titlebar)
1508 return luaA_wibox_userdata_new(L, (*c)->titlebar);
1509 return 0;
1510 case A_TK_URGENT:
1511 lua_pushboolean(L, (*c)->isurgent);
1512 break;
1513 case A_TK_SIZE_HINTS:
1514 lua_newtable(L);
1515 lua_pushboolean(L, (*c)->size_hints.flags & XCB_SIZE_HINT_US_POSITION);
1516 lua_setfield(L, -2, "user_position");
1517 lua_pushboolean(L, (*c)->size_hints.flags & XCB_SIZE_HINT_US_SIZE);
1518 lua_setfield(L, -2, "user_size");
1519 lua_pushboolean(L, (*c)->size_hints.flags & XCB_SIZE_HINT_P_POSITION);
1520 lua_setfield(L, -2, "program_position");
1521 lua_pushboolean(L, (*c)->size_hints.flags & XCB_SIZE_HINT_P_SIZE);
1522 lua_setfield(L, -2, "program_size");
1523 break;
1524 default:
1525 return 0;
1528 return 1;
1531 /** Get or set mouse buttons bindings for a client.
1532 * \param L The Lua VM state.
1533 * \return The number of element pushed on stack.
1534 * \luastack
1535 * \lvalue A client.
1536 * \lparam An array of mouse button bindings objects, or nothing.
1537 * \return The array of mouse button bindings objects of this client.
1539 static int
1540 luaA_client_buttons(lua_State *L)
1542 client_t **client = luaA_checkudata(L, 1, "client");
1543 button_array_t *buttons = &(*client)->buttons;
1545 if(lua_gettop(L) == 2)
1546 luaA_button_array_set(L, 2, buttons);
1548 return luaA_button_array_get(L, buttons);
1551 /* Client module.
1552 * \param L The Lua VM state.
1553 * \return The number of pushed elements.
1555 static int
1556 luaA_client_module_index(lua_State *L)
1558 size_t len;
1559 const char *buf = luaL_checklstring(L, 2, &len);
1561 switch(a_tokenize(buf, len))
1563 case A_TK_FOCUS:
1564 if(globalconf.screen_focus->client_focus)
1565 luaA_client_userdata_new(L, globalconf.screen_focus->client_focus);
1566 else
1567 return 0;
1568 break;
1569 default:
1570 return 0;
1573 return 1;
1576 /* Client module new index.
1577 * \param L The Lua VM state.
1578 * \return The number of pushed elements.
1580 static int
1581 luaA_client_module_newindex(lua_State *L)
1583 size_t len;
1584 const char *buf = luaL_checklstring(L, 2, &len);
1585 client_t **c;
1587 switch(a_tokenize(buf, len))
1589 case A_TK_FOCUS:
1590 c = luaA_checkudata(L, 3, "client");
1591 client_focus(*c);
1592 break;
1593 default:
1594 break;
1597 return 0;
1600 const struct luaL_reg awesome_client_methods[] =
1602 { "get", luaA_client_get },
1603 { "visible_get", luaA_client_visible_get },
1604 { "__index", luaA_client_module_index },
1605 { "__newindex", luaA_client_module_newindex },
1606 { NULL, NULL }
1608 const struct luaL_reg awesome_client_meta[] =
1610 { "isvisible", luaA_client_isvisible },
1611 { "geometry", luaA_client_geometry },
1612 { "fullgeometry", luaA_client_fullgeometry },
1613 { "buttons", luaA_client_buttons },
1614 { "tags", luaA_client_tags },
1615 { "kill", luaA_client_kill },
1616 { "swap", luaA_client_swap },
1617 { "raise", luaA_client_raise },
1618 { "lower", luaA_client_lower },
1619 { "redraw", luaA_client_redraw },
1620 { "mouse_resize", luaA_client_mouse_resize },
1621 { "mouse_move", luaA_client_mouse_move },
1622 { "unmanage", luaA_client_unmanage },
1623 { "__index", luaA_client_index },
1624 { "__newindex", luaA_client_newindex },
1625 { "__eq", luaA_client_eq },
1626 { "__gc", luaA_client_gc },
1627 { "__tostring", luaA_client_tostring },
1628 /* deprecated */
1629 { "coords", luaA_client_coords },
1630 { "fullcoords", luaA_client_fullcoords },
1631 { NULL, NULL }
1634 // vim: filetype=c:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=80