Increased Invaders difficulty
[awesome.git] / client.c
blobdd8a1988243f7cb88b9ef25aa9265f9e1eb958da
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 a protocole in WM_PROTOCOL.
118 * \param win The window.
119 * \return True if client has the atom in protocol, false otherwise.
121 static bool
122 window_hasproto(xcb_window_t win, xcb_atom_t atom)
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] == atom)
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_MODAL;
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, 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 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 bool fixed;
545 /* Values to configure a window is an array where values are
546 * stored according to 'value_mask' */
547 uint32_t values[5];
549 if(c->titlebar && !c->ismoving && !client_isfloating(c) && layout != layout_floating)
550 geometry = titlebar_geometry_remove(c->titlebar, c->border, geometry);
552 if(hints)
553 geometry = client_geometry_hints(c, geometry);
555 if(geometry.width <= 0 || geometry.height <= 0)
556 return;
558 /* offscreen appearance fixes */
559 area = display_area_get(c->phys_screen, NULL,
560 &globalconf.screens[c->screen].padding);
562 fixed = client_isfixed(c);
564 if(geometry.x > area.width)
565 geometry.x = area.width - geometry.width - 2 * c->border;
566 if(geometry.y > area.height)
567 geometry.y = area.height - geometry.height - 2 * c->border;
568 if(geometry.x + geometry.width + 2 * c->border < 0)
569 geometry.x = 0;
570 if(geometry.y + geometry.height + 2 * c->border < 0)
571 geometry.y = 0;
573 /* fixed windows can only change their x,y */
574 if((fixed && (c->geometry.x != geometry.x || c->geometry.y != geometry.y))
575 || (!fixed && (c->geometry.x != geometry.x
576 || c->geometry.y != geometry.y
577 || c->geometry.width != geometry.width
578 || c->geometry.height != geometry.height)))
580 new_screen = screen_getbycoord(c->screen, geometry.x, geometry.y);
582 c->geometry.x = values[0] = geometry.x;
583 c->geometry.width = values[2] = geometry.width;
584 c->geometry.y = values[1] = geometry.y;
585 c->geometry.height = values[3] = geometry.height;
586 values[4] = c->border;
588 /* save the floating geometry if the window is floating but not
589 * maximized */
590 if(c->ismoving || client_isfloating(c)
591 || layout_get_current(new_screen) == layout_floating)
592 if(!c->isfullscreen)
593 c->f_geometry = geometry;
595 titlebar_update_geometry_floating(c);
597 xcb_configure_window(globalconf.connection, c->win,
598 XCB_CONFIG_WINDOW_X | XCB_CONFIG_WINDOW_Y |
599 XCB_CONFIG_WINDOW_WIDTH | XCB_CONFIG_WINDOW_HEIGHT |
600 XCB_CONFIG_WINDOW_BORDER_WIDTH,
601 values);
602 window_configure(c->win, geometry, c->border);
604 if(c->screen != new_screen)
605 screen_client_moveto(c, new_screen, true, false);
607 /* execute hook */
608 hooks_property(c, "geometry");
612 /** Set a clinet floating.
613 * \param c The client.
614 * \param floating Set floating, or not.
615 * \param layer Layer to put the floating window onto.
617 void
618 client_setfloating(client_t *c, bool floating)
620 if(c->isfloating != floating
621 && (c->type == WINDOW_TYPE_NORMAL))
623 if((c->isfloating = floating))
624 if(!c->isfullscreen)
625 client_resize(c, c->f_geometry, false);
626 client_need_arrange(c);
627 widget_invalidate_cache(c->screen, WIDGET_CACHE_CLIENTS);
628 client_stack();
629 xcb_change_property(globalconf.connection,
630 XCB_PROP_MODE_REPLACE,
631 c->win, _AWESOME_FLOATING, CARDINAL, 8, 1,
632 &c->isfloating);
633 /* execute hook */
634 hooks_property(c, "floating");
638 /** Set a client minimized, or not.
639 * \param c The client.
640 * \param s Set or not the client minimized.
642 void
643 client_setminimized(client_t *c, bool s)
645 if(c->isminimized != s)
647 client_need_arrange(c);
648 c->isminimized = s;
649 client_need_arrange(c);
650 ewmh_client_update_hints(c);
651 /* execute hook */
652 hooks_property(c, "minimized");
656 /** Set a client sticky, or not.
657 * \param c The client.
658 * \param s Set or not the client sticky.
660 void
661 client_setsticky(client_t *c, bool s)
663 if(c->issticky != s)
665 client_need_arrange(c);
666 c->issticky = s;
667 client_need_arrange(c);
668 ewmh_client_update_hints(c);
669 hooks_property(c, "sticky");
673 /** Set a client fullscreen, or not.
674 * \param c The client.
675 * \param s Set or not the client fullscreen.
677 void
678 client_setfullscreen(client_t *c, bool s)
680 if(c->isfullscreen != s)
682 area_t geometry;
684 /* become fullscreen! */
685 if((c->isfullscreen = s))
687 geometry = screen_area_get(c->screen, NULL, &globalconf.screens[c->screen].padding, false);
688 c->m_geometry = c->geometry;
689 c->oldborder = c->border;
690 client_setborder(c, 0);
692 else
694 geometry = c->m_geometry;
695 client_setborder(c, c->oldborder);
696 client_resize(c, c->m_geometry, false);
698 client_resize(c, geometry, false);
699 client_need_arrange(c);
700 client_stack();
701 xcb_change_property(globalconf.connection,
702 XCB_PROP_MODE_REPLACE,
703 c->win, _AWESOME_FULLSCREEN, CARDINAL, 8, 1,
704 &c->isfullscreen);
705 ewmh_client_update_hints(c);
706 hooks_property(c, "fullscreen");
710 /** Set a client above, or not.
711 * \param c The client.
712 * \param s Set or not the client above.
714 void
715 client_setabove(client_t *c, bool s)
717 if(c->isabove != s)
719 c->isabove = s;
720 client_stack();
721 ewmh_client_update_hints(c);
722 /* execute hook */
723 hooks_property(c, "above");
727 /** Set a client below, or not.
728 * \param c The client.
729 * \param s Set or not the client below.
731 void
732 client_setbelow(client_t *c, bool s)
734 if(c->isbelow != s)
736 c->isbelow = s;
737 client_stack();
738 ewmh_client_update_hints(c);
739 /* execute hook */
740 hooks_property(c, "below");
744 /** Set a client modal, or not.
745 * \param c The client.
746 * \param s Set or not the client moda.
748 void
749 client_setmodal(client_t *c, bool s)
751 if(c->ismodal != s)
753 c->ismodal = s;
754 client_stack();
755 ewmh_client_update_hints(c);
756 /* execute hook */
757 hooks_property(c, "modal");
761 /** Set a client ontop, or not.
762 * \param c The client.
763 * \param s Set or not the client moda.
765 void
766 client_setontop(client_t *c, bool s)
768 if(c->isontop != s)
770 c->isontop = s;
771 client_stack();
772 /* execute hook */
773 hooks_property(c, "ontop");
777 /** Save client properties as an X property.
778 * \param c The client.
780 void
781 client_saveprops_tags(client_t *c)
783 tag_array_t *tags = &globalconf.screens[c->screen].tags;
784 unsigned char *prop = p_alloca(unsigned char, tags->len + 1);
785 int i;
787 for(i = 0; i < tags->len; i++)
788 prop[i] = is_client_tagged(c, tags->tab[i]) ? '1' : '0';
790 xcb_change_property(globalconf.connection, XCB_PROP_MODE_REPLACE, c->win, _AWESOME_TAGS, STRING, 8, i, prop);
793 /** Unban a client.
794 * \param c The client.
796 void
797 client_unban(client_t *c)
799 xcb_map_window(globalconf.connection, c->win);
800 window_state_set(c->win, XCB_WM_STATE_NORMAL);
801 if(c->titlebar)
803 if(c->isfullscreen || !c->titlebar->isvisible)
804 xcb_unmap_window(globalconf.connection, c->titlebar->sw.window);
805 else
806 xcb_map_window(globalconf.connection, c->titlebar->sw.window);
810 /** Unmanage a client.
811 * \param c The client.
813 void
814 client_unmanage(client_t *c)
816 tag_array_t *tags = &globalconf.screens[c->screen].tags;
818 if(globalconf.screens[c->phys_screen].client_focus == c)
819 client_unfocus(c);
821 /* remove client everywhere */
822 client_list_detach(&globalconf.clients, c);
823 stack_client_delete(c);
824 for(int i = 0; i < tags->len; i++)
825 untag_client(c, tags->tab[i]);
827 /* call hook */
828 luaA_client_userdata_new(globalconf.L, c);
829 luaA_dofunction(globalconf.L, globalconf.hooks.unmanage, 1, 0);
831 /* Call hook to notify list change */
832 luaA_dofunction(globalconf.L, globalconf.hooks.clients, 0, 0);
834 /* The server grab construct avoids race conditions. */
835 xcb_grab_server(globalconf.connection);
837 xcb_configure_window(globalconf.connection, c->win,
838 XCB_CONFIG_WINDOW_BORDER_WIDTH,
839 (uint32_t *) &c->oldborder);
841 xcb_ungrab_button(globalconf.connection, XCB_BUTTON_INDEX_ANY, c->win,
842 XCB_BUTTON_MASK_ANY);
843 window_state_set(c->win, XCB_WM_STATE_WITHDRAWN);
845 xcb_flush(globalconf.connection);
846 xcb_ungrab_server(globalconf.connection);
848 titlebar_client_detach(c);
850 ewmh_update_net_client_list(c->phys_screen);
852 /* delete properties */
853 xcb_delete_property(globalconf.connection, c->win, _AWESOME_TAGS);
854 xcb_delete_property(globalconf.connection, c->win, _AWESOME_FLOATING);
856 if(client_hasstrut(c))
857 /* All the wiboxes (may) need to be repositioned */
858 for(int screen = 0; screen < globalconf.nscreen; screen++)
859 for(int i = 0; i < globalconf.screens[screen].wiboxes.len; i++)
861 wibox_t *s = globalconf.screens[screen].wiboxes.tab[i];
862 wibox_position_update(s);
865 /* set client as invalid */
866 c->invalid = true;
868 client_unref(&c);
871 /** Kill a client via a WM_DELETE_WINDOW request or KillClient if not
872 * supported.
873 * \param c The client to kill.
875 void
876 client_kill(client_t *c)
878 if(window_hasproto(c->win, WM_DELETE_WINDOW))
880 xcb_client_message_event_t ev;
882 /* Initialize all of event's fields first */
883 p_clear(&ev, 1);
885 ev.response_type = XCB_CLIENT_MESSAGE;
886 ev.window = c->win;
887 ev.format = 32;
888 ev.data.data32[1] = XCB_CURRENT_TIME;
889 ev.type = WM_PROTOCOLS;
890 ev.data.data32[0] = WM_DELETE_WINDOW;
892 xcb_send_event(globalconf.connection, false, c->win,
893 XCB_EVENT_MASK_NO_EVENT, (char *) &ev);
895 else
896 xcb_kill_client(globalconf.connection, c->win);
899 /** Get all clients into a table.
900 * \param L The Lua VM state.
901 * \return The number of elements pushed on stack.
902 * \luastack
903 * \lparam An optional screen nunmber.
904 * \lreturn A table with all clients.
906 static int
907 luaA_client_get(lua_State *L)
909 int i = 1, screen;
910 client_t *c;
912 screen = luaL_optnumber(L, 1, 0) - 1;
914 lua_newtable(L);
916 if(screen == SCREEN_UNDEF)
917 for(c = globalconf.clients; c; c = c->next)
919 luaA_client_userdata_new(globalconf.L, c);
920 lua_rawseti(L, -2, i++);
922 else
924 luaA_checkscreen(screen);
925 for(c = globalconf.clients; c; c = c->next)
926 if(c->screen == screen)
928 luaA_client_userdata_new(globalconf.L, c);
929 lua_rawseti(L, -2, i++);
933 return 1;
936 /** Get only visible clients for a screen (DEPRECATED).
937 * \param L The Lua VM state.
938 * \return The number of elements pushed on stack.
939 * \luastack
940 * \lparam A screen number.
941 * \lreturn A table with all visible clients for this screen.
943 static int
944 luaA_client_visible_get(lua_State *L)
946 int i = 1;
947 client_t *c;
948 int screen = luaL_checknumber(L, 1) - 1;
950 luaA_checkscreen(screen);
952 deprecate();
954 lua_newtable(L);
956 for(c = globalconf.clients; c; c = c->next)
957 if(client_isvisible(c, screen))
959 luaA_client_userdata_new(L, c);
960 lua_rawseti(L, -2, i++);
963 return 1;
966 /** Check if a client is visible on its screen.
967 * \param L The Lua VM state.
968 * \return The number of elements pushed on stack.
969 * \luastack
970 * \lvalue A client.
971 * \lreturn A boolean value, true if the client is visible, false otherwise.
973 static int
974 luaA_client_isvisible(lua_State *L)
976 client_t **c = luaA_checkudata(L, 1, "client");
977 lua_pushboolean(L, client_isvisible(*c, (*c)->screen));
978 return 1;
981 /** Set client border width.
982 * \param c The client.
983 * \param width The border width.
985 void
986 client_setborder(client_t *c, int width)
988 uint32_t w = width;
990 if(width > 0 && (c->type == WINDOW_TYPE_DOCK
991 || c->type == WINDOW_TYPE_SPLASH
992 || c->type == WINDOW_TYPE_DESKTOP
993 || c->isfullscreen))
994 return;
996 if(width == c->border || width < 0)
997 return;
999 c->border = width;
1000 xcb_configure_window(globalconf.connection, c->win,
1001 XCB_CONFIG_WINDOW_BORDER_WIDTH, &w);
1003 if(client_isvisible(c, c->screen))
1005 if(client_isfloating(c) || layout_get_current(c->screen) == layout_floating)
1006 titlebar_update_geometry_floating(c);
1007 else
1008 globalconf.screens[c->screen].need_arrange = true;
1011 hooks_property(c, "border_width");
1014 /** Kill a client.
1015 * \param L The Lua VM state.
1017 * \luastack
1018 * \lvalue A client.
1020 static int
1021 luaA_client_kill(lua_State *L)
1023 client_t **c = luaA_checkudata(L, 1, "client");
1024 client_kill(*c);
1025 return 0;
1028 /** Swap a client with another one.
1029 * \param L The Lua VM state.
1030 * \luastack
1031 * \lvalue A client.
1032 * \lparam A client to swap with.
1034 static int
1035 luaA_client_swap(lua_State *L)
1037 client_t **c = luaA_checkudata(L, 1, "client");
1038 client_t **swap = luaA_checkudata(L, 2, "client");
1039 client_list_swap(&globalconf.clients, *swap, *c);
1040 client_need_arrange(*c);
1041 client_need_arrange(*swap);
1042 widget_invalidate_cache((*c)->screen, WIDGET_CACHE_CLIENTS);
1043 widget_invalidate_cache((*swap)->screen, WIDGET_CACHE_CLIENTS);
1045 /* Call hook to notify list change */
1046 luaA_dofunction(L, globalconf.hooks.clients, 0, 0);
1048 return 0;
1051 /** Access or set the client tags.
1052 * \param L The Lua VM state.
1053 * \return The number of elements pushed on stack.
1054 * \lparam A table with tags to set, or none to get the current tags table.
1055 * \return The clients tag.
1057 static int
1058 luaA_client_tags(lua_State *L)
1060 tag_array_t *tags;
1061 tag_t **tag;
1062 client_t **c = luaA_checkudata(L, 1, "client");
1063 int j = 0;
1065 if(lua_gettop(L) == 2)
1067 luaA_checktable(L, 2);
1068 tags = &globalconf.screens[(*c)->screen].tags;
1069 for(int i = 0; i < tags->len; i++)
1070 untag_client(*c, tags->tab[i]);
1071 lua_pushnil(L);
1072 while(lua_next(L, 2))
1074 tag = luaA_checkudata(L, -1, "tag");
1075 tag_client(*c, *tag);
1076 lua_pop(L, 1);
1078 lua_pop(L, 1);
1081 tags = &globalconf.screens[(*c)->screen].tags;
1082 luaA_otable_new(L);
1083 for(int i = 0; i < tags->len; i++)
1084 if(is_client_tagged(*c, tags->tab[i]))
1086 luaA_tag_userdata_new(L, tags->tab[i]);
1087 lua_rawseti(L, -2, ++j);
1090 return 1;
1093 /** Raise a client on top of others which are on the same layer.
1094 * \param L The Lua VM state.
1096 * \luastack
1097 * \lvalue A client.
1099 static int
1100 luaA_client_raise(lua_State *L)
1102 client_t **c = luaA_checkudata(L, 1, "client");
1103 client_raise(*c);
1104 return 0;
1107 /** Redraw a client by unmapping and mapping it quickly.
1108 * \param L The Lua VM state.
1110 * \luastack
1111 * \lvalue A client.
1113 static int
1114 luaA_client_redraw(lua_State *L)
1116 client_t **c = luaA_checkudata(L, 1, "client");
1118 xcb_unmap_window(globalconf.connection, (*c)->win);
1119 xcb_map_window(globalconf.connection, (*c)->win);
1121 /* Set the focus on the current window if the redraw has been
1122 performed on the window where the pointer is currently on
1123 because after the unmapping/mapping, the focus is lost */
1124 if(globalconf.screen_focus->client_focus == *c)
1125 xcb_set_input_focus(globalconf.connection, XCB_INPUT_FOCUS_POINTER_ROOT,
1126 (*c)->win, XCB_CURRENT_TIME);
1128 return 0;
1131 /** Return a formated string for a client.
1132 * \param L The Lua VM state.
1133 * \luastack
1134 * \lvalue A client.
1135 * \lreturn A string.
1137 static int
1138 luaA_client_tostring(lua_State *L)
1140 client_t **p = luaA_checkudata(L, 1, "client");
1141 lua_pushfstring(L, "[client udata(%p) name(%s)]", *p, (*p)->name);
1142 return 1;
1145 /** Stop managing a client.
1146 * \param L The Lua VM state.
1147 * \return The number of elements pushed on stack.
1148 * \luastack
1149 * \lvalue A client.
1151 static int
1152 luaA_client_unmanage(lua_State *L)
1154 client_t **c = luaA_checkudata(L, 1, "client");
1155 client_unmanage(*c);
1156 return 0;
1159 /** Return client coordinates.
1160 * \param L The Lua VM state.
1161 * \return The number of elements pushed on stack.
1162 * \luastack
1163 * \lparam A table with new coordinates, or none.
1164 * \lreturn A table with client coordinates.
1166 static int
1167 luaA_client_coords(lua_State *L)
1169 client_t **c = luaA_checkudata(L, 1, "client");
1171 if(lua_gettop(L) == 2)
1173 if((*c)->isfloating || layout_get_current((*c)->screen) == layout_floating)
1175 area_t geometry;
1177 luaA_checktable(L, 2);
1178 geometry.x = luaA_getopt_number(L, 2, "x", (*c)->geometry.x);
1179 geometry.y = luaA_getopt_number(L, 2, "y", (*c)->geometry.y);
1180 geometry.width = luaA_getopt_number(L, 2, "width", (*c)->geometry.width);
1181 geometry.height = luaA_getopt_number(L, 2, "height", (*c)->geometry.height);
1182 client_resize(*c, geometry, false);
1186 return luaA_pusharea(L, (*c)->geometry);
1189 /** Return client coordinates, using also titlebar and border width.
1190 * \param L The Lua VM state.
1191 * \return The number of elements pushed on stack.
1192 * \luastack
1193 * \lparam A table with new coordinates, or none.
1194 * \lreturn A table with client coordinates.
1196 static int
1197 luaA_client_fullcoords(lua_State *L)
1199 client_t **c = luaA_checkudata(L, 1, "client");
1200 area_t geometry;
1202 if(lua_gettop(L) == 2)
1204 if((*c)->isfloating || layout_get_current((*c)->screen) == layout_floating)
1206 luaA_checktable(L, 2);
1207 geometry.x = luaA_getopt_number(L, 2, "x", (*c)->geometry.x);
1208 geometry.y = luaA_getopt_number(L, 2, "y", (*c)->geometry.y);
1209 geometry.width = luaA_getopt_number(L, 2, "width", (*c)->geometry.width);
1210 geometry.height = luaA_getopt_number(L, 2, "height", (*c)->geometry.height);
1211 geometry = titlebar_geometry_remove((*c)->titlebar,
1212 (*c)->border,
1213 geometry);
1214 client_resize(*c, geometry, false);
1218 return luaA_pusharea(L, titlebar_geometry_add((*c)->titlebar,
1219 (*c)->border,
1220 (*c)->geometry));
1223 /** Client newindex.
1224 * \param L The Lua VM state.
1225 * \return The number of elements pushed on stack.
1228 luaA_client_newindex(lua_State *L)
1230 size_t len;
1231 client_t **c = luaA_checkudata(L, 1, "client");
1232 const char *buf = luaL_checklstring(L, 2, &len);
1233 bool b;
1234 double d;
1235 int i;
1236 wibox_t **t = NULL;
1237 image_t **image;
1239 if((*c)->invalid)
1240 luaL_error(L, "client is invalid\n");
1242 switch(a_tokenize(buf, len))
1244 case A_TK_SCREEN:
1245 if(globalconf.xinerama_is_active)
1247 i = luaL_checknumber(L, 3) - 1;
1248 luaA_checkscreen(i);
1249 if(i != (*c)->screen)
1250 screen_client_moveto(*c, i, true, true);
1252 break;
1253 case A_TK_HIDE:
1254 b = luaA_checkboolean(L, 3);
1255 if(b != (*c)->ishidden)
1257 client_need_arrange(*c);
1258 (*c)->ishidden = b;
1259 client_need_arrange(*c);
1261 break;
1262 case A_TK_MINIMIZE:
1263 client_setminimized(*c, luaA_checkboolean(L, 3));
1264 break;
1265 case A_TK_FULLSCREEN:
1266 client_setfullscreen(*c, luaA_checkboolean(L, 3));
1267 break;
1268 case A_TK_ICON:
1269 image = luaA_checkudata(L, 3, "image");
1270 image_unref(&(*c)->icon);
1271 image_ref(image);
1272 (*c)->icon = *image;
1273 widget_invalidate_cache((*c)->screen, WIDGET_CACHE_CLIENTS);
1274 break;
1275 case A_TK_OPACITY:
1276 if(lua_isnil(L, 3))
1277 window_opacity_set((*c)->win, -1);
1278 else
1280 d = luaL_checknumber(L, 3);
1281 if(d >= 0 && d <= 1)
1282 window_opacity_set((*c)->win, d);
1284 break;
1285 case A_TK_FLOATING:
1286 client_setfloating(*c, luaA_checkboolean(L, 3));
1287 break;
1288 case A_TK_STICKY:
1289 client_setsticky(*c, luaA_checkboolean(L, 3));
1290 break;
1291 case A_TK_HONORSIZEHINTS:
1292 (*c)->honorsizehints = luaA_checkboolean(L, 3);
1293 client_need_arrange(*c);
1294 break;
1295 case A_TK_BORDER_WIDTH:
1296 client_setborder(*c, luaL_checknumber(L, 3));
1297 break;
1298 case A_TK_ONTOP:
1299 client_setontop(*c, luaA_checkboolean(L, 3));
1300 break;
1301 case A_TK_BORDER_COLOR:
1302 if((buf = luaL_checklstring(L, 3, &len))
1303 && xcolor_init_reply(xcolor_init_unchecked(&(*c)->border_color, buf, len)))
1304 xcb_change_window_attributes(globalconf.connection, (*c)->win,
1305 XCB_CW_BORDER_PIXEL, &(*c)->border_color.pixel);
1306 break;
1307 case A_TK_TITLEBAR:
1308 if(lua_isnil(L, 3))
1309 titlebar_client_detach(*c);
1310 else
1312 t = luaA_checkudata(L, 3, "wibox");
1313 titlebar_client_attach(*c, *t);
1315 break;
1316 default:
1317 return 0;
1320 return 0;
1323 /** Client object.
1324 * \param L The Lua VM state.
1325 * \return The number of elements pushed on stack.
1326 * \luastack
1327 * \lfield name The client title.
1328 * \lfield skip_taskbar True if the client does not want to be in taskbar.
1329 * \lfield type The window type (desktop, normal, dock, …).
1330 * \lfield class The client class.
1331 * \lfield instance The client instance.
1332 * \lfield pid The client PID, if available.
1333 * \lfield role The window role, if available.
1334 * \lfield machine The machine client is running on.
1335 * \lfield icon_name The client name when iconified.
1336 * \lfield screen Client screen number.
1337 * \lfield hide Define if the client must be hidden, i.e. never mapped,
1338 * invisible in taskbar.
1339 * \lfield minimize Define it the client must be iconify, i.e. only visible in
1340 * taskbar.
1341 * \lfield icon_path Path to the icon used to identify.
1342 * \lfield floating True always floating.
1343 * \lfield honorsizehints Honor size hints, i.e. respect size ratio.
1344 * \lfield border_width The client border width.
1345 * \lfield border_color The client border color.
1346 * \lfield titlebar The client titlebar.
1347 * \lfield urgent The client urgent state.
1348 * \lfield focus The focused client.
1349 * \lfield opacity The client opacity between 0 and 1.
1350 * \lfield ontop The client is on top of every other windows.
1351 * \lfield fullscreen The client is fullscreen or not.
1353 static int
1354 luaA_client_index(lua_State *L)
1356 size_t len;
1357 ssize_t slen;
1358 client_t **c = luaA_checkudata(L, 1, "client");
1359 const char *buf = luaL_checklstring(L, 2, &len);
1360 char *value;
1361 void *data;
1362 xcb_get_wm_class_reply_t hint;
1363 xcb_get_property_cookie_t prop_c;
1364 xcb_get_property_reply_t *prop_r = NULL;
1365 double d;
1367 if((*c)->invalid)
1368 luaL_error(L, "client is invalid\n");
1370 if(luaA_usemetatable(L, 1, 2))
1371 return 1;
1373 switch(a_tokenize(buf, len))
1375 case A_TK_NAME:
1376 lua_pushstring(L, (*c)->name);
1377 break;
1378 case A_TK_SKIP_TASKBAR:
1379 lua_pushboolean(L, (*c)->skiptb);
1380 break;
1381 case A_TK_TYPE:
1382 switch((*c)->type)
1384 case WINDOW_TYPE_DESKTOP:
1385 lua_pushliteral(L, "desktop");
1386 break;
1387 case WINDOW_TYPE_DOCK:
1388 lua_pushliteral(L, "dock");
1389 break;
1390 case WINDOW_TYPE_SPLASH:
1391 lua_pushliteral(L, "splash");
1392 break;
1393 case WINDOW_TYPE_DIALOG:
1394 lua_pushliteral(L, "dialog");
1395 break;
1396 default:
1397 lua_pushliteral(L, "normal");
1398 break;
1400 break;
1401 case A_TK_CLASS:
1402 if(!xcb_get_wm_class_reply(globalconf.connection,
1403 xcb_get_wm_class_unchecked(globalconf.connection, (*c)->win),
1404 &hint, NULL))
1405 return 0;
1406 lua_pushstring(L, hint.class);
1407 xcb_get_wm_class_reply_wipe(&hint);
1408 break;
1409 case A_TK_INSTANCE:
1410 if(!xcb_get_wm_class_reply(globalconf.connection,
1411 xcb_get_wm_class_unchecked(globalconf.connection, (*c)->win),
1412 &hint, NULL))
1413 return 0;
1414 lua_pushstring(L, hint.name);
1415 xcb_get_wm_class_reply_wipe(&hint);
1416 break;
1417 case A_TK_ROLE:
1418 if(!xutil_text_prop_get(globalconf.connection, (*c)->win,
1419 WM_WINDOW_ROLE, &value, &slen))
1420 return 0;
1421 lua_pushlstring(L, value, slen);
1422 p_delete(&value);
1423 break;
1424 case A_TK_PID:
1425 prop_c = xcb_get_property_unchecked(globalconf.connection, false, (*c)->win, _NET_WM_PID, CARDINAL, 0L, 1L);
1426 prop_r = xcb_get_property_reply(globalconf.connection, prop_c, NULL);
1428 if(prop_r && prop_r->value_len && (data = xcb_get_property_value(prop_r)))
1429 lua_pushnumber(L, *(uint32_t *)data);
1430 else
1432 p_delete(&prop_r);
1433 return 0;
1435 break;
1436 case A_TK_MACHINE:
1437 if(!xutil_text_prop_get(globalconf.connection, (*c)->win,
1438 WM_CLIENT_MACHINE, &value, &slen))
1439 return 0;
1440 lua_pushlstring(L, value, slen);
1441 p_delete(&value);
1442 break;
1443 case A_TK_ICON_NAME:
1444 if(!xutil_text_prop_get(globalconf.connection, (*c)->win,
1445 _NET_WM_ICON_NAME, &value, &slen))
1446 if(!xutil_text_prop_get(globalconf.connection, (*c)->win,
1447 WM_ICON_NAME, &value, &slen))
1448 return 0;
1449 lua_pushlstring(L, value, slen);
1450 p_delete(&value);
1451 break;
1452 case A_TK_SCREEN:
1453 lua_pushnumber(L, 1 + (*c)->screen);
1454 break;
1455 case A_TK_HIDE:
1456 lua_pushboolean(L, (*c)->ishidden);
1457 break;
1458 case A_TK_MINIMIZE:
1459 lua_pushboolean(L, (*c)->isminimized);
1460 break;
1461 case A_TK_FULLSCREEN:
1462 lua_pushboolean(L, (*c)->isfullscreen);
1463 break;
1464 case A_TK_ICON:
1465 if((*c)->icon)
1466 luaA_image_userdata_new(L, (*c)->icon);
1467 else
1468 return 0;
1469 break;
1470 case A_TK_OPACITY:
1471 if((d = window_opacity_get((*c)->win)) >= 0)
1472 lua_pushnumber(L, d);
1473 else
1474 return 0;
1475 break;
1476 case A_TK_FLOATING:
1477 lua_pushboolean(L, (*c)->isfloating);
1478 break;
1479 case A_TK_ONTOP:
1480 lua_pushboolean(L, (*c)->isontop);
1481 break;
1482 case A_TK_STICKY:
1483 lua_pushboolean(L, (*c)->issticky);
1484 break;
1485 case A_TK_HONORSIZEHINTS:
1486 lua_pushboolean(L, (*c)->honorsizehints);
1487 break;
1488 case A_TK_BORDER_WIDTH:
1489 lua_pushnumber(L, (*c)->border);
1490 break;
1491 case A_TK_BORDER_COLOR:
1492 luaA_pushcolor(L, &(*c)->border_color);
1493 break;
1494 case A_TK_TITLEBAR:
1495 if((*c)->titlebar)
1496 return luaA_wibox_userdata_new(L, (*c)->titlebar);
1497 return 0;
1498 case A_TK_URGENT:
1499 lua_pushboolean(L, (*c)->isurgent);
1500 break;
1501 case A_TK_SIZEHINTS:
1502 lua_newtable(L);
1503 lua_pushboolean(L, (*c)->size_hints.flags & XCB_SIZE_HINT_US_POSITION);
1504 lua_setfield(L, -2, "user_position");
1505 lua_pushboolean(L, (*c)->size_hints.flags & XCB_SIZE_HINT_US_SIZE);
1506 lua_setfield(L, -2, "user_size");
1507 lua_pushboolean(L, (*c)->size_hints.flags & XCB_SIZE_HINT_P_POSITION);
1508 lua_setfield(L, -2, "program_position");
1509 lua_pushboolean(L, (*c)->size_hints.flags & XCB_SIZE_HINT_P_SIZE);
1510 lua_setfield(L, -2, "program_size");
1511 break;
1512 default:
1513 return 0;
1516 return 1;
1519 /** Get or set mouse buttons bindings for a client.
1520 * \param L The Lua VM state.
1521 * \return The number of element pushed on stack.
1522 * \luastack
1523 * \lvalue A client.
1524 * \lparam An array of mouse button bindings objects, or nothing.
1525 * \return The array of mouse button bindings objects of this client.
1527 static int
1528 luaA_client_buttons(lua_State *L)
1530 client_t **client = luaA_checkudata(L, 1, "client");
1531 button_array_t *buttons = &(*client)->buttons;
1533 if(lua_gettop(L) == 2)
1534 luaA_button_array_set(L, 2, buttons);
1536 return luaA_button_array_get(L, buttons);
1539 /* Client module.
1540 * \param L The Lua VM state.
1541 * \return The number of pushed elements.
1543 static int
1544 luaA_client_module_index(lua_State *L)
1546 size_t len;
1547 const char *buf = luaL_checklstring(L, 2, &len);
1549 switch(a_tokenize(buf, len))
1551 case A_TK_FOCUS:
1552 if(globalconf.screen_focus->client_focus)
1553 luaA_client_userdata_new(L, globalconf.screen_focus->client_focus);
1554 else
1555 return 0;
1556 break;
1557 default:
1558 return 0;
1561 return 1;
1564 /* Client module new index.
1565 * \param L The Lua VM state.
1566 * \return The number of pushed elements.
1568 static int
1569 luaA_client_module_newindex(lua_State *L)
1571 size_t len;
1572 const char *buf = luaL_checklstring(L, 2, &len);
1573 client_t **c;
1575 switch(a_tokenize(buf, len))
1577 case A_TK_FOCUS:
1578 c = luaA_checkudata(L, 3, "client");
1579 client_focus(*c);
1580 break;
1581 default:
1582 break;
1585 return 0;
1588 const struct luaL_reg awesome_client_methods[] =
1590 { "get", luaA_client_get },
1591 { "visible_get", luaA_client_visible_get },
1592 { "__index", luaA_client_module_index },
1593 { "__newindex", luaA_client_module_newindex },
1594 { NULL, NULL }
1596 const struct luaL_reg awesome_client_meta[] =
1598 { "isvisible", luaA_client_isvisible },
1599 { "coords", luaA_client_coords },
1600 { "fullcoords", luaA_client_fullcoords },
1601 { "buttons", luaA_client_buttons },
1602 { "tags", luaA_client_tags },
1603 { "kill", luaA_client_kill },
1604 { "swap", luaA_client_swap },
1605 { "raise", luaA_client_raise },
1606 { "redraw", luaA_client_redraw },
1607 { "mouse_resize", luaA_client_mouse_resize },
1608 { "mouse_move", luaA_client_mouse_move },
1609 { "unmanage", luaA_client_unmanage },
1610 { "__index", luaA_client_index },
1611 { "__newindex", luaA_client_newindex },
1612 { "__eq", luaA_client_eq },
1613 { "__gc", luaA_client_gc },
1614 { "__tostring", luaA_client_tostring },
1615 { NULL, NULL }
1618 // vim: filetype=c:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=80