icons: crush
[awesome.git] / client.c
blobc982e816ab200140be62dc0bb53abc50e2850c4d
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_below(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_BELOW;
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;
247 xcb_configure_window(globalconf.connection, c->win,
248 XCB_CONFIG_WINDOW_SIBLING | XCB_CONFIG_WINDOW_STACK_MODE,
249 config_win_vals);
250 config_win_vals[0] = c->win;
252 return c->win;
255 /** Stacking layout layers */
256 typedef enum
258 LAYER_DESKTOP = 1,
259 LAYER_BELOW,
260 LAYER_TILE,
261 LAYER_FLOAT,
262 LAYER_ABOVE,
263 LAYER_FULLSCREEN,
264 LAYER_MODAL,
265 LAYER_ONTOP,
266 LAYER_OUTOFSPACE
267 } layer_t;
269 /** Get the real layer of a client according to its attribute (fullscreen, …)
270 * \param c The client.
271 * \return The real layer.
273 static layer_t
274 client_layer_translator(client_t *c)
276 if(c->isontop)
277 return LAYER_ONTOP;
278 else if(c->ismodal)
279 return LAYER_MODAL;
280 else if(c->isfullscreen)
281 return LAYER_FULLSCREEN;
282 else if(c->isabove)
283 return LAYER_ABOVE;
284 else if(c->isfloating)
285 return LAYER_FLOAT;
287 switch(c->type)
289 case WINDOW_TYPE_DOCK:
290 return LAYER_ABOVE;
291 case WINDOW_TYPE_SPLASH:
292 case WINDOW_TYPE_DIALOG:
293 return LAYER_MODAL;
294 case WINDOW_TYPE_DESKTOP:
295 return LAYER_DESKTOP;
296 default:
297 return LAYER_TILE;
301 /** Restack clients.
302 * \todo It might be worth stopping to restack everyone and only stack `c'
303 * relatively to the first matching in the list.
305 void
306 client_stack()
308 uint32_t config_win_vals[2];
309 client_node_t *node;
310 layer_t layer;
311 int screen;
313 config_win_vals[0] = XCB_NONE;
314 config_win_vals[1] = XCB_STACK_MODE_BELOW;
316 /* first stack modal and fullscreen windows */
317 for(layer = LAYER_OUTOFSPACE - 1; layer >= LAYER_FULLSCREEN; layer--)
318 for(node = globalconf.stack; node; node = node->next)
319 if(client_layer_translator(node->client) == layer)
320 config_win_vals[0] = client_stack_below(node->client, config_win_vals[0]);
322 /* then stack ontop wibox window */
323 for(screen = 0; screen < globalconf.nscreen; screen++)
324 for(int i = 0; i < globalconf.screens[screen].wiboxes.len; i++)
326 wibox_t *sb = globalconf.screens[screen].wiboxes.tab[i];
327 if(sb->ontop)
329 xcb_configure_window(globalconf.connection,
330 sb->sw.window,
331 XCB_CONFIG_WINDOW_SIBLING | XCB_CONFIG_WINDOW_STACK_MODE,
332 config_win_vals);
333 config_win_vals[0] = sb->sw.window;
337 /* finally stack everything else */
338 for(layer = LAYER_FULLSCREEN - 1; layer >= LAYER_TILE; layer--)
339 for(node = globalconf.stack; node; node = node->next)
340 if(client_layer_translator(node->client) == layer)
341 config_win_vals[0] = client_stack_below(node->client, config_win_vals[0]);
343 /* then stack not ontop wibox window */
344 for(screen = 0; screen < globalconf.nscreen; screen++)
345 for(int i = 0; i < globalconf.screens[screen].wiboxes.len; i++)
347 wibox_t *sb = globalconf.screens[screen].wiboxes.tab[i];
348 if(!sb->ontop)
350 xcb_configure_window(globalconf.connection,
351 sb->sw.window,
352 XCB_CONFIG_WINDOW_SIBLING | XCB_CONFIG_WINDOW_STACK_MODE,
353 config_win_vals);
354 config_win_vals[0] = sb->sw.window;
358 /* finally stack everything else */
359 for(layer = LAYER_TILE - 1; layer >= LAYER_DESKTOP; layer--)
360 for(node = globalconf.stack; node; node = node->next)
361 if(client_layer_translator(node->client) == layer)
362 config_win_vals[0] = client_stack_below(node->client, config_win_vals[0]);
365 /** Manage a new client.
366 * \param w The window.
367 * \param wgeom Window geometry.
368 * \param phys_screen Physical screen number.
369 * \param screen Virtual screen number where to manage client.
371 void
372 client_manage(xcb_window_t w, xcb_get_geometry_reply_t *wgeom, int phys_screen, int screen)
374 xcb_get_property_cookie_t ewmh_icon_cookie;
375 client_t *c;
376 image_t *icon;
377 const uint32_t select_input_val[] =
379 XCB_EVENT_MASK_STRUCTURE_NOTIFY
380 | XCB_EVENT_MASK_PROPERTY_CHANGE
381 | XCB_EVENT_MASK_ENTER_WINDOW
384 /* Send request to get NET_WM_ICON property as soon as possible... */
385 ewmh_icon_cookie = ewmh_window_icon_get_unchecked(w);
386 xcb_change_window_attributes(globalconf.connection, w, XCB_CW_EVENT_MASK, select_input_val);
388 if(systray_iskdedockapp(w))
390 systray_request_handle(w, phys_screen, NULL);
391 return;
394 c = p_new(client_t, 1);
396 c->screen = screen_getbycoord(screen, wgeom->x, wgeom->y);
398 c->phys_screen = phys_screen;
400 /* Initial values */
401 c->win = w;
402 c->geometry.x = c->f_geometry.x = c->m_geometry.x = wgeom->x;
403 c->geometry.y = c->f_geometry.y = c->m_geometry.y = wgeom->y;
404 c->geometry.width = c->f_geometry.width = c->m_geometry.width = wgeom->width;
405 c->geometry.height = c->f_geometry.height = c->m_geometry.height = wgeom->height;
406 client_setborder(c, wgeom->border_width);
407 if((icon = ewmh_window_icon_get_reply(ewmh_icon_cookie)))
408 c->icon = image_ref(&icon);
410 /* we honor size hints by default */
411 c->honorsizehints = true;
413 /* update hints */
414 property_update_wm_normal_hints(c, NULL);
415 property_update_wm_hints(c, NULL);
416 property_update_wm_transient_for(c, NULL);
418 if(c->transient_for)
419 screen = c->transient_for->screen;
421 /* Try to load props if any */
422 client_loadprops(c, &globalconf.screens[screen]);
424 /* move client to screen, but do not tag it for now */
425 screen_client_moveto(c, screen, false, true);
427 /* Then check clients hints */
428 ewmh_client_check_hints(c);
430 /* Check if client has been tagged by loading props, or maybe with its
431 * hints.
432 * If not, we tag it with current selected ones.
433 * This could be done on Lua side, but it's a sane behaviour. */
434 if(!c->issticky)
436 int i;
437 tag_array_t *tags = &globalconf.screens[screen].tags;
438 for(i = 0; i < tags->len; i++)
439 if(is_client_tagged(c, tags->tab[i]))
440 break;
442 /* if no tag, set current selected */
443 if(i == tags->len)
444 for(i = 0; i < tags->len; i++)
445 if(tags->tab[i]->selected)
446 tag_client(c, tags->tab[i]);
449 /* Push client in client list */
450 client_list_push(&globalconf.clients, client_ref(&c));
452 /* Push client in stack */
453 client_raise(c);
455 /* update window title */
456 property_update_wm_name(c);
457 property_update_wm_icon_name(c);
459 /* update strut */
460 ewmh_client_strut_update(c, NULL);
462 ewmh_update_net_client_list(c->phys_screen);
464 /* Call hook to notify list change */
465 luaA_dofunction(globalconf.L, globalconf.hooks.clients, 0, 0);
467 /* call hook */
468 luaA_client_userdata_new(globalconf.L, c);
469 luaA_dofunction(globalconf.L, globalconf.hooks.manage, 1, 0);
472 /** Compute client geometry with respect to its geometry hints.
473 * \param c The client.
474 * \param geometry The geometry that the client might receive.
475 * \return The geometry the client must take respecting its hints.
477 area_t
478 client_geometry_hints(client_t *c, area_t geometry)
480 double dx, dy, max, min, ratio;
482 if(c->minay > 0 && c->maxay > 0 && (geometry.height - c->baseh) > 0
483 && (geometry.width - c->basew) > 0)
485 dx = (double) (geometry.width - c->basew);
486 dy = (double) (geometry.height - c->baseh);
487 min = (double) (c->minax) / (double) (c->minay);
488 max = (double) (c->maxax) / (double) (c->maxay);
489 ratio = dx / dy;
490 if(max > 0 && min > 0 && ratio > 0)
492 if(ratio < min)
494 dy = (dx * min + dy) / (min * min + 1);
495 dx = dy * min;
496 geometry.width = (int) dx + c->basew;
497 geometry.height = (int) dy + c->baseh;
499 else if(ratio > max)
501 dy = (dx * min + dy) / (max * max + 1);
502 dx = dy * min;
503 geometry.width = (int) dx + c->basew;
504 geometry.height = (int) dy + c->baseh;
508 if(c->minw && geometry.width < c->minw)
509 geometry.width = c->minw;
510 if(c->minh && geometry.height < c->minh)
511 geometry.height = c->minh;
512 if(c->maxw && geometry.width > c->maxw)
513 geometry.width = c->maxw;
514 if(c->maxh && geometry.height > c->maxh)
515 geometry.height = c->maxh;
516 if(c->incw)
517 geometry.width -= (geometry.width - c->basew) % c->incw;
518 if(c->inch)
519 geometry.height -= (geometry.height - c->baseh) % c->inch;
521 return geometry;
524 /** Resize client window.
525 * \param c Client to resize.
526 * \param geometry New window geometry.
527 * \param hints Use size hints.
529 void
530 client_resize(client_t *c, area_t geometry, bool hints)
532 int new_screen;
533 area_t area;
534 layout_t *layout = layout_get_current(c->screen);
535 bool fixed;
536 /* Values to configure a window is an array where values are
537 * stored according to 'value_mask' */
538 uint32_t values[5];
540 if(c->titlebar && !c->ismoving && !client_isfloating(c) && layout != layout_floating)
541 geometry = titlebar_geometry_remove(c->titlebar, c->border, geometry);
543 if(hints)
544 geometry = client_geometry_hints(c, geometry);
546 if(geometry.width <= 0 || geometry.height <= 0)
547 return;
549 /* offscreen appearance fixes */
550 area = display_area_get(c->phys_screen, NULL,
551 &globalconf.screens[c->screen].padding);
553 fixed = client_isfixed(c);
555 if(geometry.x > area.width)
556 geometry.x = area.width - geometry.width - 2 * c->border;
557 if(geometry.y > area.height)
558 geometry.y = area.height - geometry.height - 2 * c->border;
559 if(geometry.x + geometry.width + 2 * c->border < 0)
560 geometry.x = 0;
561 if(geometry.y + geometry.height + 2 * c->border < 0)
562 geometry.y = 0;
564 /* fixed windows can only change their x,y */
565 if((fixed && (c->geometry.x != geometry.x || c->geometry.y != geometry.y))
566 || (!fixed && (c->geometry.x != geometry.x
567 || c->geometry.y != geometry.y
568 || c->geometry.width != geometry.width
569 || c->geometry.height != geometry.height)))
571 new_screen = screen_getbycoord(c->screen, geometry.x, geometry.y);
573 c->geometry.x = values[0] = geometry.x;
574 c->geometry.width = values[2] = geometry.width;
575 c->geometry.y = values[1] = geometry.y;
576 c->geometry.height = values[3] = geometry.height;
577 values[4] = c->border;
579 /* save the floating geometry if the window is floating but not
580 * maximized */
581 if(c->ismoving || client_isfloating(c)
582 || layout_get_current(new_screen) == layout_floating)
583 if(!c->isfullscreen)
584 c->f_geometry = geometry;
586 titlebar_update_geometry_floating(c);
588 xcb_configure_window(globalconf.connection, c->win,
589 XCB_CONFIG_WINDOW_X | XCB_CONFIG_WINDOW_Y |
590 XCB_CONFIG_WINDOW_WIDTH | XCB_CONFIG_WINDOW_HEIGHT |
591 XCB_CONFIG_WINDOW_BORDER_WIDTH,
592 values);
593 window_configure(c->win, geometry, c->border);
595 if(c->screen != new_screen)
596 screen_client_moveto(c, new_screen, true, false);
598 /* execute hook */
599 hooks_property(c, "geometry");
603 /** Set a clinet floating.
604 * \param c The client.
605 * \param floating Set floating, or not.
606 * \param layer Layer to put the floating window onto.
608 void
609 client_setfloating(client_t *c, bool floating)
611 if(c->isfloating != floating
612 && (c->type == WINDOW_TYPE_NORMAL))
614 if((c->isfloating = floating))
615 if(!c->isfullscreen)
616 client_resize(c, c->f_geometry, false);
617 client_need_arrange(c);
618 client_stack();
619 xcb_change_property(globalconf.connection,
620 XCB_PROP_MODE_REPLACE,
621 c->win, _AWESOME_FLOATING, CARDINAL, 8, 1,
622 &c->isfloating);
623 /* execute hook */
624 hooks_property(c, "floating");
628 /** Set a client minimized, or not.
629 * \param c The client.
630 * \param s Set or not the client minimized.
632 void
633 client_setminimized(client_t *c, bool s)
635 if(c->isminimized != s)
637 client_need_arrange(c);
638 c->isminimized = s;
639 client_need_arrange(c);
640 ewmh_client_update_hints(c);
641 /* execute hook */
642 hooks_property(c, "minimized");
646 /** Set a client sticky, or not.
647 * \param c The client.
648 * \param s Set or not the client sticky.
650 void
651 client_setsticky(client_t *c, bool s)
653 if(c->issticky != s)
655 client_need_arrange(c);
656 c->issticky = s;
657 client_need_arrange(c);
658 ewmh_client_update_hints(c);
659 hooks_property(c, "sticky");
663 /** Set a client fullscreen, or not.
664 * \param c The client.
665 * \param s Set or not the client fullscreen.
667 void
668 client_setfullscreen(client_t *c, bool s)
670 if(c->isfullscreen != s)
672 area_t geometry;
674 /* become fullscreen! */
675 if((c->isfullscreen = s))
677 geometry = screen_area_get(c->screen, NULL, &globalconf.screens[c->screen].padding, false);
678 c->m_geometry = c->geometry;
679 c->oldborder = c->border;
680 client_setborder(c, 0);
682 else
684 geometry = c->m_geometry;
685 client_setborder(c, c->oldborder);
686 client_resize(c, c->m_geometry, false);
688 client_resize(c, geometry, false);
689 client_need_arrange(c);
690 client_stack();
691 xcb_change_property(globalconf.connection,
692 XCB_PROP_MODE_REPLACE,
693 c->win, _AWESOME_FULLSCREEN, CARDINAL, 8, 1,
694 &c->isfullscreen);
695 ewmh_client_update_hints(c);
696 hooks_property(c, "fullscreen");
700 /** Set a client above, or not.
701 * \param c The client.
702 * \param s Set or not the client above.
704 void
705 client_setabove(client_t *c, bool s)
707 if(c->isabove != s)
709 c->isabove = s;
710 client_stack();
711 ewmh_client_update_hints(c);
712 /* execute hook */
713 hooks_property(c, "above");
717 /** Set a client below, or not.
718 * \param c The client.
719 * \param s Set or not the client below.
721 void
722 client_setbelow(client_t *c, bool s)
724 if(c->isbelow != s)
726 c->isbelow = s;
727 client_stack();
728 ewmh_client_update_hints(c);
729 /* execute hook */
730 hooks_property(c, "below");
734 /** Set a client modal, or not.
735 * \param c The client.
736 * \param s Set or not the client moda.
738 void
739 client_setmodal(client_t *c, bool s)
741 if(c->ismodal != s)
743 c->ismodal = s;
744 client_stack();
745 ewmh_client_update_hints(c);
746 /* execute hook */
747 hooks_property(c, "modal");
751 /** Set a client ontop, or not.
752 * \param c The client.
753 * \param s Set or not the client moda.
755 void
756 client_setontop(client_t *c, bool s)
758 if(c->isontop != s)
760 c->isontop = s;
761 client_stack();
762 /* execute hook */
763 hooks_property(c, "ontop");
767 /** Save client properties as an X property.
768 * \param c The client.
770 void
771 client_saveprops_tags(client_t *c)
773 tag_array_t *tags = &globalconf.screens[c->screen].tags;
774 unsigned char *prop = p_alloca(unsigned char, tags->len + 1);
775 int i;
777 for(i = 0; i < tags->len; i++)
778 prop[i] = is_client_tagged(c, tags->tab[i]) ? '1' : '0';
780 xcb_change_property(globalconf.connection, XCB_PROP_MODE_REPLACE, c->win, _AWESOME_TAGS, STRING, 8, i, prop);
783 /** Unban a client.
784 * \param c The client.
786 void
787 client_unban(client_t *c)
789 xcb_map_window(globalconf.connection, c->win);
790 window_state_set(c->win, XCB_WM_STATE_NORMAL);
791 if(c->titlebar)
793 if(c->isfullscreen || !c->titlebar->isvisible)
794 xcb_unmap_window(globalconf.connection, c->titlebar->sw.window);
795 else
796 xcb_map_window(globalconf.connection, c->titlebar->sw.window);
800 /** Unmanage a client.
801 * \param c The client.
803 void
804 client_unmanage(client_t *c)
806 tag_array_t *tags = &globalconf.screens[c->screen].tags;
808 if(globalconf.screens[c->phys_screen].client_focus == c)
809 client_unfocus(c);
811 /* remove client everywhere */
812 client_list_detach(&globalconf.clients, c);
813 stack_client_delete(c);
814 for(int i = 0; i < tags->len; i++)
815 untag_client(c, tags->tab[i]);
817 /* call hook */
818 luaA_client_userdata_new(globalconf.L, c);
819 luaA_dofunction(globalconf.L, globalconf.hooks.unmanage, 1, 0);
821 /* Call hook to notify list change */
822 luaA_dofunction(globalconf.L, globalconf.hooks.clients, 0, 0);
824 /* The server grab construct avoids race conditions. */
825 xcb_grab_server(globalconf.connection);
827 xcb_configure_window(globalconf.connection, c->win,
828 XCB_CONFIG_WINDOW_BORDER_WIDTH,
829 (uint32_t *) &c->oldborder);
831 xcb_ungrab_button(globalconf.connection, XCB_BUTTON_INDEX_ANY, c->win,
832 XCB_BUTTON_MASK_ANY);
833 window_state_set(c->win, XCB_WM_STATE_WITHDRAWN);
835 xcb_flush(globalconf.connection);
836 xcb_ungrab_server(globalconf.connection);
838 titlebar_client_detach(c);
840 ewmh_update_net_client_list(c->phys_screen);
842 /* delete properties */
843 xcb_delete_property(globalconf.connection, c->win, _AWESOME_TAGS);
844 xcb_delete_property(globalconf.connection, c->win, _AWESOME_FLOATING);
846 if(client_hasstrut(c))
847 /* All the wiboxes (may) need to be repositioned */
848 for(int screen = 0; screen < globalconf.nscreen; screen++)
849 for(int i = 0; i < globalconf.screens[screen].wiboxes.len; i++)
851 wibox_t *s = globalconf.screens[screen].wiboxes.tab[i];
852 wibox_position_update(s);
855 /* set client as invalid */
856 c->invalid = true;
858 client_unref(&c);
861 /** Kill a client via a WM_DELETE_WINDOW request or KillClient if not
862 * supported.
863 * \param c The client to kill.
865 void
866 client_kill(client_t *c)
868 if(window_hasproto(c->win, WM_DELETE_WINDOW))
870 xcb_client_message_event_t ev;
872 /* Initialize all of event's fields first */
873 p_clear(&ev, 1);
875 ev.response_type = XCB_CLIENT_MESSAGE;
876 ev.window = c->win;
877 ev.format = 32;
878 ev.data.data32[1] = XCB_CURRENT_TIME;
879 ev.type = WM_PROTOCOLS;
880 ev.data.data32[0] = WM_DELETE_WINDOW;
882 xcb_send_event(globalconf.connection, false, c->win,
883 XCB_EVENT_MASK_NO_EVENT, (char *) &ev);
885 else
886 xcb_kill_client(globalconf.connection, c->win);
889 /** Get all clients into a table.
890 * \param L The Lua VM state.
891 * \return The number of elements pushed on stack.
892 * \luastack
893 * \lparam An optional screen nunmber.
894 * \lreturn A table with all clients.
896 static int
897 luaA_client_get(lua_State *L)
899 int i = 1, screen;
900 client_t *c;
902 screen = luaL_optnumber(L, 1, 0) - 1;
904 lua_newtable(L);
906 if(screen == SCREEN_UNDEF)
907 for(c = globalconf.clients; c; c = c->next)
909 luaA_client_userdata_new(globalconf.L, c);
910 lua_rawseti(L, -2, i++);
912 else
914 luaA_checkscreen(screen);
915 for(c = globalconf.clients; c; c = c->next)
916 if(c->screen == screen)
918 luaA_client_userdata_new(globalconf.L, c);
919 lua_rawseti(L, -2, i++);
923 return 1;
926 /** Get only visible clients for a screen (DEPRECATED).
927 * \param L The Lua VM state.
928 * \return The number of elements pushed on stack.
929 * \luastack
930 * \lparam A screen number.
931 * \lreturn A table with all visible clients for this screen.
933 static int
934 luaA_client_visible_get(lua_State *L)
936 int i = 1;
937 client_t *c;
938 int screen = luaL_checknumber(L, 1) - 1;
940 luaA_checkscreen(screen);
942 deprecate();
944 lua_newtable(L);
946 for(c = globalconf.clients; c; c = c->next)
947 if(client_isvisible(c, screen))
949 luaA_client_userdata_new(L, c);
950 lua_rawseti(L, -2, i++);
953 return 1;
956 /** Check if a client is visible on its screen.
957 * \param L The Lua VM state.
958 * \return The number of elements pushed on stack.
959 * \luastack
960 * \lvalue A client.
961 * \lreturn A boolean value, true if the client is visible, false otherwise.
963 static int
964 luaA_client_isvisible(lua_State *L)
966 client_t **c = luaA_checkudata(L, 1, "client");
967 lua_pushboolean(L, client_isvisible(*c, (*c)->screen));
968 return 1;
971 /** Set client border width.
972 * \param c The client.
973 * \param width The border width.
975 void
976 client_setborder(client_t *c, int width)
978 uint32_t w = width;
980 if(width > 0 && (c->type == WINDOW_TYPE_DOCK
981 || c->type == WINDOW_TYPE_SPLASH
982 || c->type == WINDOW_TYPE_DESKTOP
983 || c->isfullscreen))
984 return;
986 if(width == c->border || width < 0)
987 return;
989 c->border = width;
990 xcb_configure_window(globalconf.connection, c->win,
991 XCB_CONFIG_WINDOW_BORDER_WIDTH, &w);
993 if(client_isvisible(c, c->screen))
995 if(client_isfloating(c) || layout_get_current(c->screen) == layout_floating)
996 titlebar_update_geometry_floating(c);
997 else
998 globalconf.screens[c->screen].need_arrange = true;
1001 hooks_property(c, "border_width");
1004 /** Kill a client.
1005 * \param L The Lua VM state.
1007 * \luastack
1008 * \lvalue A client.
1010 static int
1011 luaA_client_kill(lua_State *L)
1013 client_t **c = luaA_checkudata(L, 1, "client");
1014 client_kill(*c);
1015 return 0;
1018 /** Swap a client with another one.
1019 * \param L The Lua VM state.
1020 * \luastack
1021 * \lvalue A client.
1022 * \lparam A client to swap with.
1024 static int
1025 luaA_client_swap(lua_State *L)
1027 client_t **c = luaA_checkudata(L, 1, "client");
1028 client_t **swap = luaA_checkudata(L, 2, "client");
1029 client_list_swap(&globalconf.clients, *swap, *c);
1030 client_need_arrange(*c);
1031 client_need_arrange(*swap);
1033 /* Call hook to notify list change */
1034 luaA_dofunction(L, globalconf.hooks.clients, 0, 0);
1036 return 0;
1039 /** Access or set the client tags.
1040 * \param L The Lua VM state.
1041 * \return The number of elements pushed on stack.
1042 * \lparam A table with tags to set, or none to get the current tags table.
1043 * \return The clients tag.
1045 static int
1046 luaA_client_tags(lua_State *L)
1048 tag_array_t *tags;
1049 tag_t **tag;
1050 client_t **c = luaA_checkudata(L, 1, "client");
1051 int j = 0;
1053 if(lua_gettop(L) == 2)
1055 luaA_checktable(L, 2);
1056 tags = &globalconf.screens[(*c)->screen].tags;
1057 for(int i = 0; i < tags->len; i++)
1058 untag_client(*c, tags->tab[i]);
1059 lua_pushnil(L);
1060 while(lua_next(L, 2))
1062 tag = luaA_checkudata(L, -1, "tag");
1063 tag_client(*c, *tag);
1064 lua_pop(L, 1);
1066 lua_pop(L, 1);
1069 tags = &globalconf.screens[(*c)->screen].tags;
1070 luaA_otable_new(L);
1071 for(int i = 0; i < tags->len; i++)
1072 if(is_client_tagged(*c, tags->tab[i]))
1074 luaA_tag_userdata_new(L, tags->tab[i]);
1075 lua_rawseti(L, -2, ++j);
1078 return 1;
1081 /** Raise a client on top of others which are on the same layer.
1082 * \param L The Lua VM state.
1084 * \luastack
1085 * \lvalue A client.
1087 static int
1088 luaA_client_raise(lua_State *L)
1090 client_t **c = luaA_checkudata(L, 1, "client");
1091 client_raise(*c);
1092 return 0;
1095 /** Redraw a client by unmapping and mapping it quickly.
1096 * \param L The Lua VM state.
1098 * \luastack
1099 * \lvalue A client.
1101 static int
1102 luaA_client_redraw(lua_State *L)
1104 client_t **c = luaA_checkudata(L, 1, "client");
1106 xcb_unmap_window(globalconf.connection, (*c)->win);
1107 xcb_map_window(globalconf.connection, (*c)->win);
1109 /* Set the focus on the current window if the redraw has been
1110 performed on the window where the pointer is currently on
1111 because after the unmapping/mapping, the focus is lost */
1112 if(globalconf.screen_focus->client_focus == *c)
1113 xcb_set_input_focus(globalconf.connection, XCB_INPUT_FOCUS_POINTER_ROOT,
1114 (*c)->win, XCB_CURRENT_TIME);
1116 return 0;
1119 /** Stop managing a client.
1120 * \param L The Lua VM state.
1121 * \return The number of elements pushed on stack.
1122 * \luastack
1123 * \lvalue A client.
1125 static int
1126 luaA_client_unmanage(lua_State *L)
1128 client_t **c = luaA_checkudata(L, 1, "client");
1129 client_unmanage(*c);
1130 return 0;
1133 /** Return client geometry.
1134 * \param L The Lua VM state.
1135 * \return The number of elements pushed on stack.
1136 * \luastack
1137 * \lparam A table with new coordinates, or none.
1138 * \lreturn A table with client coordinates.
1140 static int
1141 luaA_client_geometry(lua_State *L)
1143 client_t **c = luaA_checkudata(L, 1, "client");
1145 if(lua_gettop(L) == 2)
1147 if((*c)->isfloating || layout_get_current((*c)->screen) == layout_floating)
1149 area_t geometry;
1151 luaA_checktable(L, 2);
1152 geometry.x = luaA_getopt_number(L, 2, "x", (*c)->geometry.x);
1153 geometry.y = luaA_getopt_number(L, 2, "y", (*c)->geometry.y);
1154 geometry.width = luaA_getopt_number(L, 2, "width", (*c)->geometry.width);
1155 geometry.height = luaA_getopt_number(L, 2, "height", (*c)->geometry.height);
1156 client_resize(*c, geometry, false);
1160 return luaA_pusharea(L, (*c)->geometry);
1163 static int
1164 luaA_client_coords(lua_State *L)
1166 deprecate();
1167 return luaA_client_geometry(L);
1170 /** Return client geometry, using also titlebar and border width.
1171 * \param L The Lua VM state.
1172 * \return The number of elements pushed on stack.
1173 * \luastack
1174 * \lparam A table with new coordinates, or none.
1175 * \lreturn A table with client coordinates.
1177 static int
1178 luaA_client_fullgeometry(lua_State *L)
1180 client_t **c = luaA_checkudata(L, 1, "client");
1181 area_t geometry;
1183 if(lua_gettop(L) == 2)
1185 if((*c)->isfloating || layout_get_current((*c)->screen) == layout_floating)
1187 luaA_checktable(L, 2);
1188 geometry.x = luaA_getopt_number(L, 2, "x", (*c)->geometry.x);
1189 geometry.y = luaA_getopt_number(L, 2, "y", (*c)->geometry.y);
1190 geometry.width = luaA_getopt_number(L, 2, "width", (*c)->geometry.width);
1191 geometry.height = luaA_getopt_number(L, 2, "height", (*c)->geometry.height);
1192 geometry = titlebar_geometry_remove((*c)->titlebar,
1193 (*c)->border,
1194 geometry);
1195 client_resize(*c, geometry, false);
1199 return luaA_pusharea(L, titlebar_geometry_add((*c)->titlebar,
1200 (*c)->border,
1201 (*c)->geometry));
1204 static int
1205 luaA_client_fullcoords(lua_State *L)
1207 deprecate();
1208 return luaA_client_fullgeometry(L);
1211 /** Client newindex.
1212 * \param L The Lua VM state.
1213 * \return The number of elements pushed on stack.
1216 luaA_client_newindex(lua_State *L)
1218 size_t len;
1219 client_t **c = luaA_checkudata(L, 1, "client");
1220 const char *buf = luaL_checklstring(L, 2, &len);
1221 bool b;
1222 double d;
1223 int i;
1224 wibox_t **t = NULL;
1225 image_t **image;
1227 if((*c)->invalid)
1228 luaL_error(L, "client is invalid\n");
1230 switch(a_tokenize(buf, len))
1232 case A_TK_SCREEN:
1233 if(globalconf.xinerama_is_active)
1235 i = luaL_checknumber(L, 3) - 1;
1236 luaA_checkscreen(i);
1237 if(i != (*c)->screen)
1238 screen_client_moveto(*c, i, true, true);
1240 break;
1241 case A_TK_HIDE:
1242 b = luaA_checkboolean(L, 3);
1243 if(b != (*c)->ishidden)
1245 client_need_arrange(*c);
1246 (*c)->ishidden = b;
1247 client_need_arrange(*c);
1249 break;
1250 case A_TK_MINIMIZE:
1251 client_setminimized(*c, luaA_checkboolean(L, 3));
1252 break;
1253 case A_TK_FULLSCREEN:
1254 client_setfullscreen(*c, luaA_checkboolean(L, 3));
1255 break;
1256 case A_TK_ICON:
1257 image = luaA_checkudata(L, 3, "image");
1258 image_unref(&(*c)->icon);
1259 image_ref(image);
1260 (*c)->icon = *image;
1261 /* execute hook */
1262 hooks_property(*c, "icon");
1263 break;
1264 case A_TK_OPACITY:
1265 if(lua_isnil(L, 3))
1266 window_opacity_set((*c)->win, -1);
1267 else
1269 d = luaL_checknumber(L, 3);
1270 if(d >= 0 && d <= 1)
1271 window_opacity_set((*c)->win, d);
1273 break;
1274 case A_TK_FLOATING:
1275 client_setfloating(*c, luaA_checkboolean(L, 3));
1276 break;
1277 case A_TK_STICKY:
1278 client_setsticky(*c, luaA_checkboolean(L, 3));
1279 break;
1280 case A_TK_HONORSIZEHINTS:
1281 (*c)->honorsizehints = luaA_checkboolean(L, 3);
1282 client_need_arrange(*c);
1283 break;
1284 case A_TK_BORDER_WIDTH:
1285 client_setborder(*c, luaL_checknumber(L, 3));
1286 break;
1287 case A_TK_ONTOP:
1288 client_setontop(*c, luaA_checkboolean(L, 3));
1289 break;
1290 case A_TK_BORDER_COLOR:
1291 if((buf = luaL_checklstring(L, 3, &len))
1292 && xcolor_init_reply(xcolor_init_unchecked(&(*c)->border_color, buf, len)))
1293 xcb_change_window_attributes(globalconf.connection, (*c)->win,
1294 XCB_CW_BORDER_PIXEL, &(*c)->border_color.pixel);
1295 break;
1296 case A_TK_TITLEBAR:
1297 if(lua_isnil(L, 3))
1298 titlebar_client_detach(*c);
1299 else
1301 t = luaA_checkudata(L, 3, "wibox");
1302 titlebar_client_attach(*c, *t);
1304 break;
1305 default:
1306 return 0;
1309 return 0;
1312 /** Client object.
1313 * \param L The Lua VM state.
1314 * \return The number of elements pushed on stack.
1315 * \luastack
1316 * \lfield name The client title.
1317 * \lfield skip_taskbar True if the client does not want to be in taskbar.
1318 * \lfield type The window type (desktop, normal, dock, …).
1319 * \lfield class The client class.
1320 * \lfield instance The client instance.
1321 * \lfield pid The client PID, if available.
1322 * \lfield role The window role, if available.
1323 * \lfield machine The machine client is running on.
1324 * \lfield icon_name The client name when iconified.
1325 * \lfield screen Client screen number.
1326 * \lfield hide Define if the client must be hidden, i.e. never mapped,
1327 * invisible in taskbar.
1328 * \lfield minimize Define it the client must be iconify, i.e. only visible in
1329 * taskbar.
1330 * \lfield icon_path Path to the icon used to identify.
1331 * \lfield floating True always floating.
1332 * \lfield honorsizehints Honor size hints, i.e. respect size ratio.
1333 * \lfield border_width The client border width.
1334 * \lfield border_color The client border color.
1335 * \lfield titlebar The client titlebar.
1336 * \lfield urgent The client urgent state.
1337 * \lfield focus The focused client.
1338 * \lfield opacity The client opacity between 0 and 1.
1339 * \lfield ontop The client is on top of every other windows.
1340 * \lfield fullscreen The client is fullscreen or not.
1342 static int
1343 luaA_client_index(lua_State *L)
1345 size_t len;
1346 ssize_t slen;
1347 client_t **c = luaA_checkudata(L, 1, "client");
1348 const char *buf = luaL_checklstring(L, 2, &len);
1349 char *value;
1350 void *data;
1351 xcb_get_wm_class_reply_t hint;
1352 xcb_get_property_cookie_t prop_c;
1353 xcb_get_property_reply_t *prop_r = NULL;
1354 double d;
1356 if((*c)->invalid)
1357 luaL_error(L, "client is invalid\n");
1359 if(luaA_usemetatable(L, 1, 2))
1360 return 1;
1362 switch(a_tokenize(buf, len))
1364 case A_TK_NAME:
1365 lua_pushstring(L, (*c)->name);
1366 break;
1367 case A_TK_SKIP_TASKBAR:
1368 lua_pushboolean(L, (*c)->skiptb);
1369 break;
1370 case A_TK_TYPE:
1371 switch((*c)->type)
1373 case WINDOW_TYPE_DESKTOP:
1374 lua_pushliteral(L, "desktop");
1375 break;
1376 case WINDOW_TYPE_DOCK:
1377 lua_pushliteral(L, "dock");
1378 break;
1379 case WINDOW_TYPE_SPLASH:
1380 lua_pushliteral(L, "splash");
1381 break;
1382 case WINDOW_TYPE_DIALOG:
1383 lua_pushliteral(L, "dialog");
1384 break;
1385 default:
1386 lua_pushliteral(L, "normal");
1387 break;
1389 break;
1390 case A_TK_CLASS:
1391 if(!xcb_get_wm_class_reply(globalconf.connection,
1392 xcb_get_wm_class_unchecked(globalconf.connection, (*c)->win),
1393 &hint, NULL))
1394 return 0;
1395 lua_pushstring(L, hint.class);
1396 xcb_get_wm_class_reply_wipe(&hint);
1397 break;
1398 case A_TK_INSTANCE:
1399 if(!xcb_get_wm_class_reply(globalconf.connection,
1400 xcb_get_wm_class_unchecked(globalconf.connection, (*c)->win),
1401 &hint, NULL))
1402 return 0;
1403 lua_pushstring(L, hint.name);
1404 xcb_get_wm_class_reply_wipe(&hint);
1405 break;
1406 case A_TK_ROLE:
1407 if(!xutil_text_prop_get(globalconf.connection, (*c)->win,
1408 WM_WINDOW_ROLE, &value, &slen))
1409 return 0;
1410 lua_pushlstring(L, value, slen);
1411 p_delete(&value);
1412 break;
1413 case A_TK_PID:
1414 prop_c = xcb_get_property_unchecked(globalconf.connection, false, (*c)->win, _NET_WM_PID, CARDINAL, 0L, 1L);
1415 prop_r = xcb_get_property_reply(globalconf.connection, prop_c, NULL);
1417 if(prop_r && prop_r->value_len && (data = xcb_get_property_value(prop_r)))
1418 lua_pushnumber(L, *(uint32_t *)data);
1419 else
1421 p_delete(&prop_r);
1422 return 0;
1424 break;
1425 case A_TK_MACHINE:
1426 if(!xutil_text_prop_get(globalconf.connection, (*c)->win,
1427 WM_CLIENT_MACHINE, &value, &slen))
1428 return 0;
1429 lua_pushlstring(L, value, slen);
1430 p_delete(&value);
1431 break;
1432 case A_TK_ICON_NAME:
1433 lua_pushstring(L, (*c)->icon_name);
1434 break;
1435 case A_TK_SCREEN:
1436 lua_pushnumber(L, 1 + (*c)->screen);
1437 break;
1438 case A_TK_HIDE:
1439 lua_pushboolean(L, (*c)->ishidden);
1440 break;
1441 case A_TK_MINIMIZE:
1442 lua_pushboolean(L, (*c)->isminimized);
1443 break;
1444 case A_TK_FULLSCREEN:
1445 lua_pushboolean(L, (*c)->isfullscreen);
1446 break;
1447 case A_TK_ICON:
1448 if((*c)->icon)
1449 luaA_image_userdata_new(L, (*c)->icon);
1450 else
1451 return 0;
1452 break;
1453 case A_TK_OPACITY:
1454 if((d = window_opacity_get((*c)->win)) >= 0)
1455 lua_pushnumber(L, d);
1456 else
1457 return 0;
1458 break;
1459 case A_TK_FLOATING:
1460 lua_pushboolean(L, (*c)->isfloating);
1461 break;
1462 case A_TK_ONTOP:
1463 lua_pushboolean(L, (*c)->isontop);
1464 break;
1465 case A_TK_STICKY:
1466 lua_pushboolean(L, (*c)->issticky);
1467 break;
1468 case A_TK_HONORSIZEHINTS:
1469 lua_pushboolean(L, (*c)->honorsizehints);
1470 break;
1471 case A_TK_BORDER_WIDTH:
1472 lua_pushnumber(L, (*c)->border);
1473 break;
1474 case A_TK_BORDER_COLOR:
1475 luaA_pushcolor(L, &(*c)->border_color);
1476 break;
1477 case A_TK_TITLEBAR:
1478 if((*c)->titlebar)
1479 return luaA_wibox_userdata_new(L, (*c)->titlebar);
1480 return 0;
1481 case A_TK_URGENT:
1482 lua_pushboolean(L, (*c)->isurgent);
1483 break;
1484 case A_TK_SIZEHINTS:
1485 lua_newtable(L);
1486 lua_pushboolean(L, (*c)->size_hints.flags & XCB_SIZE_HINT_US_POSITION);
1487 lua_setfield(L, -2, "user_position");
1488 lua_pushboolean(L, (*c)->size_hints.flags & XCB_SIZE_HINT_US_SIZE);
1489 lua_setfield(L, -2, "user_size");
1490 lua_pushboolean(L, (*c)->size_hints.flags & XCB_SIZE_HINT_P_POSITION);
1491 lua_setfield(L, -2, "program_position");
1492 lua_pushboolean(L, (*c)->size_hints.flags & XCB_SIZE_HINT_P_SIZE);
1493 lua_setfield(L, -2, "program_size");
1494 break;
1495 default:
1496 return 0;
1499 return 1;
1502 /** Get or set mouse buttons bindings for a client.
1503 * \param L The Lua VM state.
1504 * \return The number of element pushed on stack.
1505 * \luastack
1506 * \lvalue A client.
1507 * \lparam An array of mouse button bindings objects, or nothing.
1508 * \return The array of mouse button bindings objects of this client.
1510 static int
1511 luaA_client_buttons(lua_State *L)
1513 client_t **client = luaA_checkudata(L, 1, "client");
1514 button_array_t *buttons = &(*client)->buttons;
1516 if(lua_gettop(L) == 2)
1517 luaA_button_array_set(L, 2, buttons);
1519 return luaA_button_array_get(L, buttons);
1522 /* Client module.
1523 * \param L The Lua VM state.
1524 * \return The number of pushed elements.
1526 static int
1527 luaA_client_module_index(lua_State *L)
1529 size_t len;
1530 const char *buf = luaL_checklstring(L, 2, &len);
1532 switch(a_tokenize(buf, len))
1534 case A_TK_FOCUS:
1535 if(globalconf.screen_focus->client_focus)
1536 luaA_client_userdata_new(L, globalconf.screen_focus->client_focus);
1537 else
1538 return 0;
1539 break;
1540 default:
1541 return 0;
1544 return 1;
1547 /* Client module new index.
1548 * \param L The Lua VM state.
1549 * \return The number of pushed elements.
1551 static int
1552 luaA_client_module_newindex(lua_State *L)
1554 size_t len;
1555 const char *buf = luaL_checklstring(L, 2, &len);
1556 client_t **c;
1558 switch(a_tokenize(buf, len))
1560 case A_TK_FOCUS:
1561 c = luaA_checkudata(L, 3, "client");
1562 client_focus(*c);
1563 break;
1564 default:
1565 break;
1568 return 0;
1571 const struct luaL_reg awesome_client_methods[] =
1573 { "get", luaA_client_get },
1574 { "visible_get", luaA_client_visible_get },
1575 { "__index", luaA_client_module_index },
1576 { "__newindex", luaA_client_module_newindex },
1577 { NULL, NULL }
1579 const struct luaL_reg awesome_client_meta[] =
1581 { "isvisible", luaA_client_isvisible },
1582 { "geometry", luaA_client_geometry },
1583 { "fullgeometry", luaA_client_fullgeometry },
1584 { "buttons", luaA_client_buttons },
1585 { "tags", luaA_client_tags },
1586 { "kill", luaA_client_kill },
1587 { "swap", luaA_client_swap },
1588 { "raise", luaA_client_raise },
1589 { "redraw", luaA_client_redraw },
1590 { "mouse_resize", luaA_client_mouse_resize },
1591 { "mouse_move", luaA_client_mouse_move },
1592 { "unmanage", luaA_client_unmanage },
1593 { "__index", luaA_client_index },
1594 { "__newindex", luaA_client_newindex },
1595 { "__eq", luaA_client_eq },
1596 { "__gc", luaA_client_gc },
1597 { "__tostring", luaA_client_tostring },
1598 /* deprecated */
1599 { "coords", luaA_client_coords },
1600 { "fullcoords", luaA_client_fullcoords },
1601 { NULL, NULL }
1604 // vim: filetype=c:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=80