luaa: add XDG_CONFIG_DIR as include path
[awesome.git] / client.c
blob4e0f5403b8191fd80a6a5dc482e5b3f4994b5b27
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 mode The mode.
229 * \param previous The previous window on the stack.
230 * \param return The next-previous!
232 static xcb_window_t
233 client_stack_position(client_t *c, xcb_stack_mode_t mode, xcb_window_t previous)
235 uint32_t config_win_vals[2];
237 config_win_vals[0] = previous;
238 config_win_vals[1] = mode;
240 if(c->titlebar)
242 xcb_configure_window(globalconf.connection,
243 c->titlebar->sw.window,
244 XCB_CONFIG_WINDOW_SIBLING | XCB_CONFIG_WINDOW_STACK_MODE,
245 config_win_vals);
246 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);
251 return c->win;
254 /** Stacking layout layers */
255 typedef enum
257 /** This one is a special layer */
258 LAYER_TRANSIENT_FOR,
259 LAYER_DESKTOP,
260 LAYER_BELOW,
261 LAYER_TILE,
262 LAYER_FLOAT,
263 LAYER_ABOVE,
264 LAYER_FULLSCREEN,
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->isfullscreen)
279 return LAYER_FULLSCREEN;
280 else if(c->isabove)
281 return LAYER_ABOVE;
282 else if(c->isfloating || client_isfixed(c))
283 return LAYER_FLOAT;
284 else if(c->transient_for)
285 return LAYER_TRANSIENT_FOR;
287 switch(c->type)
289 case WINDOW_TYPE_DOCK:
290 return LAYER_ABOVE;
291 case WINDOW_TYPE_DESKTOP:
292 return LAYER_DESKTOP;
293 case WINDOW_TYPE_DIALOG:
294 return LAYER_FLOAT;
295 default:
296 return LAYER_TILE;
300 /** Restack clients.
301 * \todo It might be worth stopping to restack everyone and only stack `c'
302 * relatively to the first matching in the list.
304 void
305 client_stack()
307 uint32_t config_win_vals[2];
308 client_node_t *node, *last = *client_node_list_last(&globalconf.stack);
309 layer_t layer;
310 int screen;
312 config_win_vals[0] = XCB_NONE;
313 config_win_vals[1] = XCB_STACK_MODE_ABOVE;
315 /* first stack not ontop wibox window */
316 for(screen = 0; screen < globalconf.nscreen; screen++)
317 for(int i = 0; i < globalconf.screens[screen].wiboxes.len; i++)
319 wibox_t *sb = globalconf.screens[screen].wiboxes.tab[i];
320 if(!sb->ontop)
322 xcb_configure_window(globalconf.connection,
323 sb->sw.window,
324 XCB_CONFIG_WINDOW_SIBLING | XCB_CONFIG_WINDOW_STACK_MODE,
325 config_win_vals);
326 config_win_vals[0] = sb->sw.window;
330 /* stack bottom layers */
331 for(layer = LAYER_DESKTOP; layer < LAYER_FULLSCREEN; layer++)
332 for(node = last; node; node = node->prev)
333 if(client_layer_translator(node->client) == layer)
334 config_win_vals[0] = client_stack_position(node->client,
335 XCB_STACK_MODE_ABOVE,
336 config_win_vals[0]);
338 /* then stack ontop wibox window */
339 for(screen = 0; screen < globalconf.nscreen; screen++)
340 for(int i = 0; i < globalconf.screens[screen].wiboxes.len; i++)
342 wibox_t *sb = globalconf.screens[screen].wiboxes.tab[i];
343 if(sb->ontop)
345 xcb_configure_window(globalconf.connection,
346 sb->sw.window,
347 XCB_CONFIG_WINDOW_SIBLING | XCB_CONFIG_WINDOW_STACK_MODE,
348 config_win_vals);
349 config_win_vals[0] = sb->sw.window;
353 /* finally stack ontop and fullscreen windows */
354 for(layer = LAYER_FULLSCREEN; layer < LAYER_OUTOFSPACE; layer++)
355 for(node = last; node; node = node->prev)
356 if(client_layer_translator(node->client) == layer)
357 config_win_vals[0] = client_stack_position(node->client,
358 XCB_STACK_MODE_ABOVE,
359 config_win_vals[0]);
361 /* stack transient window on top of their parents */
362 for(node = last; node; node = node->prev)
363 if(client_layer_translator(node->client) == LAYER_TRANSIENT_FOR)
364 client_stack_position(node->client,
365 XCB_STACK_MODE_ABOVE,
366 node->client->transient_for->win);
369 /** Manage a new client.
370 * \param w The window.
371 * \param wgeom Window geometry.
372 * \param phys_screen Physical screen number.
373 * \param screen Virtual screen number where to manage client.
375 void
376 client_manage(xcb_window_t w, xcb_get_geometry_reply_t *wgeom, int phys_screen, int screen)
378 xcb_get_property_cookie_t ewmh_icon_cookie;
379 client_t *c;
380 image_t *icon;
381 const uint32_t select_input_val[] =
383 XCB_EVENT_MASK_STRUCTURE_NOTIFY
384 | XCB_EVENT_MASK_PROPERTY_CHANGE
385 | XCB_EVENT_MASK_ENTER_WINDOW
388 /* Send request to get NET_WM_ICON property as soon as possible... */
389 ewmh_icon_cookie = ewmh_window_icon_get_unchecked(w);
390 xcb_change_window_attributes(globalconf.connection, w, XCB_CW_EVENT_MASK, select_input_val);
392 if(systray_iskdedockapp(w))
394 systray_request_handle(w, phys_screen, NULL);
395 return;
398 c = p_new(client_t, 1);
400 c->screen = screen_getbycoord(screen, wgeom->x, wgeom->y);
402 c->phys_screen = phys_screen;
404 /* Initial values */
405 c->win = w;
406 c->geometry.x = c->f_geometry.x = c->m_geometry.x = wgeom->x;
407 c->geometry.y = c->f_geometry.y = c->m_geometry.y = wgeom->y;
408 c->geometry.width = c->f_geometry.width = c->m_geometry.width = wgeom->width;
409 c->geometry.height = c->f_geometry.height = c->m_geometry.height = wgeom->height;
410 client_setborder(c, wgeom->border_width);
411 if((icon = ewmh_window_icon_get_reply(ewmh_icon_cookie)))
412 c->icon = image_ref(&icon);
414 /* we honor size hints by default */
415 c->honorsizehints = true;
417 /* update hints */
418 property_update_wm_normal_hints(c, NULL);
419 property_update_wm_hints(c, NULL);
420 property_update_wm_transient_for(c, NULL);
422 if(c->transient_for)
423 screen = c->transient_for->screen;
425 /* Try to load props if any */
426 client_loadprops(c, &globalconf.screens[screen]);
429 /* Then check clients hints */
430 ewmh_client_check_hints(c);
432 /* move client to screen, but do not tag it for now */
433 screen_client_moveto(c, screen, false, true);
435 /* Check if client has been tagged by loading props, or maybe with its
436 * hints.
437 * If not, we tag it with current selected ones.
438 * This could be done on Lua side, but it's a sane behaviour. */
439 if(!c->issticky)
441 int i;
442 tag_array_t *tags = &globalconf.screens[screen].tags;
443 for(i = 0; i < tags->len; i++)
444 if(is_client_tagged(c, tags->tab[i]))
445 break;
447 /* if no tag, set current selected */
448 if(i == tags->len)
449 for(i = 0; i < tags->len; i++)
450 if(tags->tab[i]->selected)
451 tag_client(c, tags->tab[i]);
454 /* Push client in client list */
455 client_list_push(&globalconf.clients, client_ref(&c));
457 /* Push client in stack */
458 client_raise(c);
460 /* update window title */
461 property_update_wm_name(c);
462 property_update_wm_icon_name(c);
464 /* update strut */
465 ewmh_client_strut_update(c, NULL);
467 ewmh_update_net_client_list(c->phys_screen);
469 /* Call hook to notify list change */
470 luaA_dofunction(globalconf.L, globalconf.hooks.clients, 0, 0);
472 /* call hook */
473 luaA_client_userdata_new(globalconf.L, c);
474 luaA_dofunction(globalconf.L, globalconf.hooks.manage, 1, 0);
477 /** Compute client geometry with respect to its geometry hints.
478 * \param c The client.
479 * \param geometry The geometry that the client might receive.
480 * \return The geometry the client must take respecting its hints.
482 area_t
483 client_geometry_hints(client_t *c, area_t geometry)
485 double dx, dy, max, min, ratio;
487 if(c->minay > 0 && c->maxay > 0 && (geometry.height - c->baseh) > 0
488 && (geometry.width - c->basew) > 0)
490 dx = (double) (geometry.width - c->basew);
491 dy = (double) (geometry.height - c->baseh);
492 min = (double) (c->minax) / (double) (c->minay);
493 max = (double) (c->maxax) / (double) (c->maxay);
494 ratio = dx / dy;
495 if(max > 0 && min > 0 && ratio > 0)
497 if(ratio < min)
499 dy = (dx * min + dy) / (min * min + 1);
500 dx = dy * min;
501 geometry.width = (int) dx + c->basew;
502 geometry.height = (int) dy + c->baseh;
504 else if(ratio > max)
506 dy = (dx * min + dy) / (max * max + 1);
507 dx = dy * min;
508 geometry.width = (int) dx + c->basew;
509 geometry.height = (int) dy + c->baseh;
513 if(c->minw && geometry.width < c->minw)
514 geometry.width = c->minw;
515 if(c->minh && geometry.height < c->minh)
516 geometry.height = c->minh;
517 if(c->maxw && geometry.width > c->maxw)
518 geometry.width = c->maxw;
519 if(c->maxh && geometry.height > c->maxh)
520 geometry.height = c->maxh;
521 if(c->incw)
522 geometry.width -= (geometry.width - c->basew) % c->incw;
523 if(c->inch)
524 geometry.height -= (geometry.height - c->baseh) % c->inch;
526 return geometry;
529 /** Resize client window.
530 * \param c Client to resize.
531 * \param geometry New window geometry.
532 * \param hints Use size hints.
534 void
535 client_resize(client_t *c, area_t geometry, bool hints)
537 int new_screen;
538 area_t area;
539 layout_t *layout = layout_get_current(c->screen);
540 bool fixed;
541 /* Values to configure a window is an array where values are
542 * stored according to 'value_mask' */
543 uint32_t values[5];
545 if(c->titlebar && !c->ismoving && !client_isfloating(c) && layout != layout_floating)
546 geometry = titlebar_geometry_remove(c->titlebar, c->border, geometry);
548 if(hints)
549 geometry = client_geometry_hints(c, geometry);
551 if(geometry.width <= 0 || geometry.height <= 0)
552 return;
554 /* offscreen appearance fixes */
555 area = display_area_get(c->phys_screen, NULL,
556 &globalconf.screens[c->screen].padding);
558 fixed = client_isfixed(c);
560 if(geometry.x > area.width)
561 geometry.x = area.width - geometry.width - 2 * c->border;
562 if(geometry.y > area.height)
563 geometry.y = area.height - geometry.height - 2 * c->border;
564 if(geometry.x + geometry.width + 2 * c->border < 0)
565 geometry.x = 0;
566 if(geometry.y + geometry.height + 2 * c->border < 0)
567 geometry.y = 0;
569 /* fixed windows can only change their x,y */
570 if((fixed && (c->geometry.x != geometry.x || c->geometry.y != geometry.y))
571 || (!fixed && (c->geometry.x != geometry.x
572 || c->geometry.y != geometry.y
573 || c->geometry.width != geometry.width
574 || c->geometry.height != geometry.height)))
576 new_screen = screen_getbycoord(c->screen, geometry.x, geometry.y);
578 c->geometry.x = values[0] = geometry.x;
579 c->geometry.width = values[2] = geometry.width;
580 c->geometry.y = values[1] = geometry.y;
581 c->geometry.height = values[3] = geometry.height;
582 values[4] = c->border;
584 /* save the floating geometry if the window is floating but not
585 * maximized */
586 if(c->ismoving || client_isfloating(c)
587 || layout_get_current(new_screen) == layout_floating)
588 if(!c->isfullscreen)
589 c->f_geometry = geometry;
591 titlebar_update_geometry_floating(c);
593 xcb_configure_window(globalconf.connection, c->win,
594 XCB_CONFIG_WINDOW_X | XCB_CONFIG_WINDOW_Y |
595 XCB_CONFIG_WINDOW_WIDTH | XCB_CONFIG_WINDOW_HEIGHT |
596 XCB_CONFIG_WINDOW_BORDER_WIDTH,
597 values);
598 window_configure(c->win, geometry, c->border);
600 if(c->screen != new_screen)
601 screen_client_moveto(c, new_screen, true, false);
603 /* execute hook */
604 hooks_property(c, "geometry");
608 /** Set a clinet floating.
609 * \param c The client.
610 * \param floating Set floating, or not.
611 * \param layer Layer to put the floating window onto.
613 void
614 client_setfloating(client_t *c, bool floating)
616 if(c->isfloating != floating
617 && (c->type == WINDOW_TYPE_NORMAL))
619 if((c->isfloating = floating))
620 if(!c->isfullscreen)
621 client_resize(c, c->f_geometry, false);
622 client_need_arrange(c);
623 client_stack();
624 xcb_change_property(globalconf.connection,
625 XCB_PROP_MODE_REPLACE,
626 c->win, _AWESOME_FLOATING, CARDINAL, 8, 1,
627 &c->isfloating);
628 /* execute hook */
629 hooks_property(c, "floating");
633 /** Set a client minimized, or not.
634 * \param c The client.
635 * \param s Set or not the client minimized.
637 void
638 client_setminimized(client_t *c, bool s)
640 if(c->isminimized != s)
642 client_need_arrange(c);
643 c->isminimized = s;
644 client_need_arrange(c);
645 ewmh_client_update_hints(c);
646 /* execute hook */
647 hooks_property(c, "minimized");
651 /** Set a client sticky, or not.
652 * \param c The client.
653 * \param s Set or not the client sticky.
655 void
656 client_setsticky(client_t *c, bool s)
658 if(c->issticky != s)
660 client_need_arrange(c);
661 c->issticky = s;
662 client_need_arrange(c);
663 ewmh_client_update_hints(c);
664 hooks_property(c, "sticky");
668 /** Set a client fullscreen, or not.
669 * \param c The client.
670 * \param s Set or not the client fullscreen.
672 void
673 client_setfullscreen(client_t *c, bool s)
675 if(c->isfullscreen != s)
677 area_t geometry;
679 /* become fullscreen! */
680 if((c->isfullscreen = s))
682 geometry = screen_area_get(c->screen, NULL, NULL, false);
683 c->m_geometry = c->geometry;
684 c->oldborder = c->border;
685 client_setborder(c, 0);
687 else
689 geometry = c->m_geometry;
690 client_setborder(c, c->oldborder);
691 client_resize(c, c->m_geometry, false);
693 client_resize(c, geometry, false);
694 client_need_arrange(c);
695 client_stack();
696 xcb_change_property(globalconf.connection,
697 XCB_PROP_MODE_REPLACE,
698 c->win, _AWESOME_FULLSCREEN, CARDINAL, 8, 1,
699 &c->isfullscreen);
700 ewmh_client_update_hints(c);
701 hooks_property(c, "fullscreen");
705 /** Set a client above, or not.
706 * \param c The client.
707 * \param s Set or not the client above.
709 void
710 client_setabove(client_t *c, bool s)
712 if(c->isabove != s)
714 c->isabove = s;
715 client_stack();
716 ewmh_client_update_hints(c);
717 /* execute hook */
718 hooks_property(c, "above");
722 /** Set a client below, or not.
723 * \param c The client.
724 * \param s Set or not the client below.
726 void
727 client_setbelow(client_t *c, bool s)
729 if(c->isbelow != s)
731 c->isbelow = s;
732 client_stack();
733 ewmh_client_update_hints(c);
734 /* execute hook */
735 hooks_property(c, "below");
739 /** Set a client modal, or not.
740 * \param c The client.
741 * \param s Set or not the client moda.
743 void
744 client_setmodal(client_t *c, bool s)
746 if(c->ismodal != s)
748 c->ismodal = s;
749 client_stack();
750 ewmh_client_update_hints(c);
751 /* execute hook */
752 hooks_property(c, "modal");
756 /** Set a client ontop, or not.
757 * \param c The client.
758 * \param s Set or not the client moda.
760 void
761 client_setontop(client_t *c, bool s)
763 if(c->isontop != s)
765 c->isontop = s;
766 client_stack();
767 /* execute hook */
768 hooks_property(c, "ontop");
772 /** Save client properties as an X property.
773 * \param c The client.
775 void
776 client_saveprops_tags(client_t *c)
778 tag_array_t *tags = &globalconf.screens[c->screen].tags;
779 unsigned char *prop = p_alloca(unsigned char, tags->len + 1);
780 int i;
782 for(i = 0; i < tags->len; i++)
783 prop[i] = is_client_tagged(c, tags->tab[i]) ? '1' : '0';
785 xcb_change_property(globalconf.connection, XCB_PROP_MODE_REPLACE, c->win, _AWESOME_TAGS, STRING, 8, i, prop);
788 /** Unban a client.
789 * \param c The client.
791 void
792 client_unban(client_t *c)
794 xcb_map_window(globalconf.connection, c->win);
795 window_state_set(c->win, XCB_WM_STATE_NORMAL);
796 if(c->titlebar)
798 if(c->isfullscreen || !c->titlebar->isvisible)
799 xcb_unmap_window(globalconf.connection, c->titlebar->sw.window);
800 else
801 xcb_map_window(globalconf.connection, c->titlebar->sw.window);
805 /** Unmanage a client.
806 * \param c The client.
808 void
809 client_unmanage(client_t *c)
811 tag_array_t *tags = &globalconf.screens[c->screen].tags;
813 if(globalconf.screens[c->phys_screen].client_focus == c)
814 client_unfocus(c);
816 /* remove client everywhere */
817 client_list_detach(&globalconf.clients, c);
818 stack_client_delete(c);
819 for(int i = 0; i < tags->len; i++)
820 untag_client(c, tags->tab[i]);
822 /* call hook */
823 luaA_client_userdata_new(globalconf.L, c);
824 luaA_dofunction(globalconf.L, globalconf.hooks.unmanage, 1, 0);
826 /* Call hook to notify list change */
827 luaA_dofunction(globalconf.L, globalconf.hooks.clients, 0, 0);
829 /* The server grab construct avoids race conditions. */
830 xcb_grab_server(globalconf.connection);
832 xcb_configure_window(globalconf.connection, c->win,
833 XCB_CONFIG_WINDOW_BORDER_WIDTH,
834 (uint32_t *) &c->oldborder);
836 xcb_ungrab_button(globalconf.connection, XCB_BUTTON_INDEX_ANY, c->win,
837 XCB_BUTTON_MASK_ANY);
838 window_state_set(c->win, XCB_WM_STATE_WITHDRAWN);
840 xcb_flush(globalconf.connection);
841 xcb_ungrab_server(globalconf.connection);
843 titlebar_client_detach(c);
845 ewmh_update_net_client_list(c->phys_screen);
847 /* delete properties */
848 xcb_delete_property(globalconf.connection, c->win, _AWESOME_TAGS);
849 xcb_delete_property(globalconf.connection, c->win, _AWESOME_FLOATING);
851 if(client_hasstrut(c))
852 /* All the wiboxes (may) need to be repositioned */
853 for(int screen = 0; screen < globalconf.nscreen; screen++)
854 for(int i = 0; i < globalconf.screens[screen].wiboxes.len; i++)
856 wibox_t *s = globalconf.screens[screen].wiboxes.tab[i];
857 wibox_position_update(s);
860 /* set client as invalid */
861 c->invalid = true;
863 client_unref(&c);
866 /** Kill a client via a WM_DELETE_WINDOW request or KillClient if not
867 * supported.
868 * \param c The client to kill.
870 void
871 client_kill(client_t *c)
873 if(window_hasproto(c->win, WM_DELETE_WINDOW))
875 xcb_client_message_event_t ev;
877 /* Initialize all of event's fields first */
878 p_clear(&ev, 1);
880 ev.response_type = XCB_CLIENT_MESSAGE;
881 ev.window = c->win;
882 ev.format = 32;
883 ev.data.data32[1] = XCB_CURRENT_TIME;
884 ev.type = WM_PROTOCOLS;
885 ev.data.data32[0] = WM_DELETE_WINDOW;
887 xcb_send_event(globalconf.connection, false, c->win,
888 XCB_EVENT_MASK_NO_EVENT, (char *) &ev);
890 else
891 xcb_kill_client(globalconf.connection, c->win);
894 /** Get all clients into a table.
895 * \param L The Lua VM state.
896 * \return The number of elements pushed on stack.
897 * \luastack
898 * \lparam An optional screen nunmber.
899 * \lreturn A table with all clients.
901 static int
902 luaA_client_get(lua_State *L)
904 int i = 1, screen;
905 client_t *c;
907 screen = luaL_optnumber(L, 1, 0) - 1;
909 lua_newtable(L);
911 if(screen == SCREEN_UNDEF)
912 for(c = globalconf.clients; c; c = c->next)
914 luaA_client_userdata_new(globalconf.L, c);
915 lua_rawseti(L, -2, i++);
917 else
919 luaA_checkscreen(screen);
920 for(c = globalconf.clients; c; c = c->next)
921 if(c->screen == screen)
923 luaA_client_userdata_new(globalconf.L, c);
924 lua_rawseti(L, -2, i++);
928 return 1;
931 /** Get only visible clients for a screen (DEPRECATED).
932 * \param L The Lua VM state.
933 * \return The number of elements pushed on stack.
934 * \luastack
935 * \lparam A screen number.
936 * \lreturn A table with all visible clients for this screen.
938 static int
939 luaA_client_visible_get(lua_State *L)
941 int i = 1;
942 client_t *c;
943 int screen = luaL_checknumber(L, 1) - 1;
945 luaA_checkscreen(screen);
947 deprecate(L);
949 lua_newtable(L);
951 for(c = globalconf.clients; c; c = c->next)
952 if(client_isvisible(c, screen))
954 luaA_client_userdata_new(L, c);
955 lua_rawseti(L, -2, i++);
958 return 1;
961 /** Check if a client is visible on its screen.
962 * \param L The Lua VM state.
963 * \return The number of elements pushed on stack.
964 * \luastack
965 * \lvalue A client.
966 * \lreturn A boolean value, true if the client is visible, false otherwise.
968 static int
969 luaA_client_isvisible(lua_State *L)
971 client_t **c = luaA_checkudata(L, 1, "client");
972 lua_pushboolean(L, client_isvisible(*c, (*c)->screen));
973 return 1;
976 /** Set client border width.
977 * \param c The client.
978 * \param width The border width.
980 void
981 client_setborder(client_t *c, int width)
983 uint32_t w = width;
985 if(width > 0 && (c->type == WINDOW_TYPE_DOCK
986 || c->type == WINDOW_TYPE_SPLASH
987 || c->type == WINDOW_TYPE_DESKTOP
988 || c->isfullscreen))
989 return;
991 if(width == c->border || width < 0)
992 return;
994 c->border = width;
995 xcb_configure_window(globalconf.connection, c->win,
996 XCB_CONFIG_WINDOW_BORDER_WIDTH, &w);
998 if(client_isvisible(c, c->screen))
1000 if(client_isfloating(c) || layout_get_current(c->screen) == layout_floating)
1001 titlebar_update_geometry_floating(c);
1002 else
1003 globalconf.screens[c->screen].need_arrange = true;
1006 hooks_property(c, "border_width");
1009 /** Kill a client.
1010 * \param L The Lua VM state.
1012 * \luastack
1013 * \lvalue A client.
1015 static int
1016 luaA_client_kill(lua_State *L)
1018 client_t **c = luaA_checkudata(L, 1, "client");
1019 client_kill(*c);
1020 return 0;
1023 /** Swap a client with another one.
1024 * \param L The Lua VM state.
1025 * \luastack
1026 * \lvalue A client.
1027 * \lparam A client to swap with.
1029 static int
1030 luaA_client_swap(lua_State *L)
1032 client_t **c = luaA_checkudata(L, 1, "client");
1033 client_t **swap = luaA_checkudata(L, 2, "client");
1034 client_list_swap(&globalconf.clients, *swap, *c);
1035 client_need_arrange(*c);
1036 client_need_arrange(*swap);
1038 /* Call hook to notify list change */
1039 luaA_dofunction(L, globalconf.hooks.clients, 0, 0);
1041 return 0;
1044 /** Access or set the client tags.
1045 * \param L The Lua VM state.
1046 * \return The number of elements pushed on stack.
1047 * \lparam A table with tags to set, or none to get the current tags table.
1048 * \return The clients tag.
1050 static int
1051 luaA_client_tags(lua_State *L)
1053 tag_array_t *tags;
1054 tag_t **tag;
1055 client_t **c = luaA_checkudata(L, 1, "client");
1056 int j = 0;
1058 if(lua_gettop(L) == 2)
1060 luaA_checktable(L, 2);
1061 tags = &globalconf.screens[(*c)->screen].tags;
1062 for(int i = 0; i < tags->len; i++)
1063 untag_client(*c, tags->tab[i]);
1064 lua_pushnil(L);
1065 while(lua_next(L, 2))
1067 tag = luaA_checkudata(L, -1, "tag");
1068 tag_client(*c, *tag);
1069 lua_pop(L, 1);
1071 lua_pop(L, 1);
1074 tags = &globalconf.screens[(*c)->screen].tags;
1075 luaA_otable_new(L);
1076 for(int i = 0; i < tags->len; i++)
1077 if(is_client_tagged(*c, tags->tab[i]))
1079 luaA_tag_userdata_new(L, tags->tab[i]);
1080 lua_rawseti(L, -2, ++j);
1083 return 1;
1086 /** Raise a client on top of others which are on the same layer.
1087 * \param L The Lua VM state.
1089 * \luastack
1090 * \lvalue A client.
1092 static int
1093 luaA_client_raise(lua_State *L)
1095 client_t **c = luaA_checkudata(L, 1, "client");
1096 client_raise(*c);
1097 return 0;
1100 /** Redraw a client by unmapping and mapping it quickly.
1101 * \param L The Lua VM state.
1103 * \luastack
1104 * \lvalue A client.
1106 static int
1107 luaA_client_redraw(lua_State *L)
1109 client_t **c = luaA_checkudata(L, 1, "client");
1111 xcb_unmap_window(globalconf.connection, (*c)->win);
1112 xcb_map_window(globalconf.connection, (*c)->win);
1114 /* Set the focus on the current window if the redraw has been
1115 performed on the window where the pointer is currently on
1116 because after the unmapping/mapping, the focus is lost */
1117 if(globalconf.screen_focus->client_focus == *c)
1118 xcb_set_input_focus(globalconf.connection, XCB_INPUT_FOCUS_POINTER_ROOT,
1119 (*c)->win, XCB_CURRENT_TIME);
1121 return 0;
1124 /** Stop managing a client.
1125 * \param L The Lua VM state.
1126 * \return The number of elements pushed on stack.
1127 * \luastack
1128 * \lvalue A client.
1130 static int
1131 luaA_client_unmanage(lua_State *L)
1133 client_t **c = luaA_checkudata(L, 1, "client");
1134 client_unmanage(*c);
1135 return 0;
1138 /** Return client geometry.
1139 * \param L The Lua VM state.
1140 * \return The number of elements pushed on stack.
1141 * \luastack
1142 * \lparam A table with new coordinates, or none.
1143 * \lreturn A table with client coordinates.
1145 static int
1146 luaA_client_geometry(lua_State *L)
1148 client_t **c = luaA_checkudata(L, 1, "client");
1150 if(lua_gettop(L) == 2)
1152 if((*c)->isfloating || layout_get_current((*c)->screen) == layout_floating)
1154 area_t geometry;
1156 luaA_checktable(L, 2);
1157 geometry.x = luaA_getopt_number(L, 2, "x", (*c)->geometry.x);
1158 geometry.y = luaA_getopt_number(L, 2, "y", (*c)->geometry.y);
1159 geometry.width = luaA_getopt_number(L, 2, "width", (*c)->geometry.width);
1160 geometry.height = luaA_getopt_number(L, 2, "height", (*c)->geometry.height);
1161 client_resize(*c, geometry, false);
1165 return luaA_pusharea(L, (*c)->geometry);
1168 static int
1169 luaA_client_coords(lua_State *L)
1171 deprecate(L);
1172 return luaA_client_geometry(L);
1175 /** Return client geometry, using also titlebar and border width.
1176 * \param L The Lua VM state.
1177 * \return The number of elements pushed on stack.
1178 * \luastack
1179 * \lparam A table with new coordinates, or none.
1180 * \lreturn A table with client coordinates.
1182 static int
1183 luaA_client_fullgeometry(lua_State *L)
1185 client_t **c = luaA_checkudata(L, 1, "client");
1186 area_t geometry;
1188 if(lua_gettop(L) == 2)
1190 if((*c)->isfloating || layout_get_current((*c)->screen) == layout_floating)
1192 luaA_checktable(L, 2);
1193 geometry.x = luaA_getopt_number(L, 2, "x", (*c)->geometry.x);
1194 geometry.y = luaA_getopt_number(L, 2, "y", (*c)->geometry.y);
1195 geometry.width = luaA_getopt_number(L, 2, "width", (*c)->geometry.width);
1196 geometry.height = luaA_getopt_number(L, 2, "height", (*c)->geometry.height);
1197 geometry = titlebar_geometry_remove((*c)->titlebar,
1198 (*c)->border,
1199 geometry);
1200 client_resize(*c, geometry, false);
1204 return luaA_pusharea(L, titlebar_geometry_add((*c)->titlebar,
1205 (*c)->border,
1206 (*c)->geometry));
1209 static int
1210 luaA_client_fullcoords(lua_State *L)
1212 deprecate(L);
1213 return luaA_client_fullgeometry(L);
1216 /** Client newindex.
1217 * \param L The Lua VM state.
1218 * \return The number of elements pushed on stack.
1221 luaA_client_newindex(lua_State *L)
1223 size_t len;
1224 client_t **c = luaA_checkudata(L, 1, "client");
1225 const char *buf = luaL_checklstring(L, 2, &len);
1226 bool b;
1227 double d;
1228 int i;
1229 wibox_t **t = NULL;
1230 image_t **image;
1232 if((*c)->invalid)
1233 luaL_error(L, "client is invalid\n");
1235 switch(a_tokenize(buf, len))
1237 case A_TK_SCREEN:
1238 if(globalconf.xinerama_is_active)
1240 i = luaL_checknumber(L, 3) - 1;
1241 luaA_checkscreen(i);
1242 if(i != (*c)->screen)
1243 screen_client_moveto(*c, i, true, true);
1245 break;
1246 case A_TK_HIDE:
1247 b = luaA_checkboolean(L, 3);
1248 if(b != (*c)->ishidden)
1250 client_need_arrange(*c);
1251 (*c)->ishidden = b;
1252 client_need_arrange(*c);
1254 break;
1255 case A_TK_MINIMIZE:
1256 client_setminimized(*c, luaA_checkboolean(L, 3));
1257 break;
1258 case A_TK_FULLSCREEN:
1259 client_setfullscreen(*c, luaA_checkboolean(L, 3));
1260 break;
1261 case A_TK_ICON:
1262 image = luaA_checkudata(L, 3, "image");
1263 image_unref(&(*c)->icon);
1264 image_ref(image);
1265 (*c)->icon = *image;
1266 /* execute hook */
1267 hooks_property(*c, "icon");
1268 break;
1269 case A_TK_OPACITY:
1270 if(lua_isnil(L, 3))
1271 window_opacity_set((*c)->win, -1);
1272 else
1274 d = luaL_checknumber(L, 3);
1275 if(d >= 0 && d <= 1)
1276 window_opacity_set((*c)->win, d);
1278 break;
1279 case A_TK_FLOATING:
1280 client_setfloating(*c, luaA_checkboolean(L, 3));
1281 break;
1282 case A_TK_STICKY:
1283 client_setsticky(*c, luaA_checkboolean(L, 3));
1284 break;
1285 case A_TK_HONORSIZEHINTS:
1286 (*c)->honorsizehints = luaA_checkboolean(L, 3);
1287 client_need_arrange(*c);
1288 break;
1289 case A_TK_BORDER_WIDTH:
1290 client_setborder(*c, luaL_checknumber(L, 3));
1291 break;
1292 case A_TK_ONTOP:
1293 client_setontop(*c, luaA_checkboolean(L, 3));
1294 break;
1295 case A_TK_BORDER_COLOR:
1296 if((buf = luaL_checklstring(L, 3, &len))
1297 && xcolor_init_reply(xcolor_init_unchecked(&(*c)->border_color, buf, len)))
1298 xcb_change_window_attributes(globalconf.connection, (*c)->win,
1299 XCB_CW_BORDER_PIXEL, &(*c)->border_color.pixel);
1300 break;
1301 case A_TK_TITLEBAR:
1302 if(lua_isnil(L, 3))
1303 titlebar_client_detach(*c);
1304 else
1306 t = luaA_checkudata(L, 3, "wibox");
1307 titlebar_client_attach(*c, *t);
1309 break;
1310 default:
1311 return 0;
1314 return 0;
1317 /** Client object.
1318 * \param L The Lua VM state.
1319 * \return The number of elements pushed on stack.
1320 * \luastack
1321 * \lfield name The client title.
1322 * \lfield skip_taskbar True if the client does not want to be in taskbar.
1323 * \lfield type The window type (desktop, normal, dock, …).
1324 * \lfield class The client class.
1325 * \lfield instance The client instance.
1326 * \lfield pid The client PID, if available.
1327 * \lfield role The window role, if available.
1328 * \lfield machine The machine client is running on.
1329 * \lfield icon_name The client name when iconified.
1330 * \lfield screen Client screen number.
1331 * \lfield hide Define if the client must be hidden, i.e. never mapped,
1332 * invisible in taskbar.
1333 * \lfield minimize Define it the client must be iconify, i.e. only visible in
1334 * taskbar.
1335 * \lfield icon_path Path to the icon used to identify.
1336 * \lfield floating True always floating.
1337 * \lfield honorsizehints Honor size hints, i.e. respect size ratio.
1338 * \lfield border_width The client border width.
1339 * \lfield border_color The client border color.
1340 * \lfield titlebar The client titlebar.
1341 * \lfield urgent The client urgent state.
1342 * \lfield focus The focused client.
1343 * \lfield opacity The client opacity between 0 and 1.
1344 * \lfield ontop The client is on top of every other windows.
1345 * \lfield fullscreen The client is fullscreen or not.
1347 static int
1348 luaA_client_index(lua_State *L)
1350 size_t len;
1351 ssize_t slen;
1352 client_t **c = luaA_checkudata(L, 1, "client");
1353 const char *buf = luaL_checklstring(L, 2, &len);
1354 char *value;
1355 void *data;
1356 xcb_get_wm_class_reply_t hint;
1357 xcb_get_property_cookie_t prop_c;
1358 xcb_get_property_reply_t *prop_r = NULL;
1359 double d;
1361 if((*c)->invalid)
1362 luaL_error(L, "client is invalid\n");
1364 if(luaA_usemetatable(L, 1, 2))
1365 return 1;
1367 switch(a_tokenize(buf, len))
1369 case A_TK_NAME:
1370 lua_pushstring(L, (*c)->name);
1371 break;
1372 case A_TK_SKIP_TASKBAR:
1373 lua_pushboolean(L, (*c)->skiptb);
1374 break;
1375 case A_TK_TYPE:
1376 switch((*c)->type)
1378 case WINDOW_TYPE_DESKTOP:
1379 lua_pushliteral(L, "desktop");
1380 break;
1381 case WINDOW_TYPE_DOCK:
1382 lua_pushliteral(L, "dock");
1383 break;
1384 case WINDOW_TYPE_SPLASH:
1385 lua_pushliteral(L, "splash");
1386 break;
1387 case WINDOW_TYPE_DIALOG:
1388 lua_pushliteral(L, "dialog");
1389 break;
1390 default:
1391 lua_pushliteral(L, "normal");
1392 break;
1394 break;
1395 case A_TK_CLASS:
1396 if(!xcb_get_wm_class_reply(globalconf.connection,
1397 xcb_get_wm_class_unchecked(globalconf.connection, (*c)->win),
1398 &hint, NULL))
1399 return 0;
1400 lua_pushstring(L, hint.class);
1401 xcb_get_wm_class_reply_wipe(&hint);
1402 break;
1403 case A_TK_INSTANCE:
1404 if(!xcb_get_wm_class_reply(globalconf.connection,
1405 xcb_get_wm_class_unchecked(globalconf.connection, (*c)->win),
1406 &hint, NULL))
1407 return 0;
1408 lua_pushstring(L, hint.name);
1409 xcb_get_wm_class_reply_wipe(&hint);
1410 break;
1411 case A_TK_ROLE:
1412 if(!xutil_text_prop_get(globalconf.connection, (*c)->win,
1413 WM_WINDOW_ROLE, &value, &slen))
1414 return 0;
1415 lua_pushlstring(L, value, slen);
1416 p_delete(&value);
1417 break;
1418 case A_TK_PID:
1419 prop_c = xcb_get_property_unchecked(globalconf.connection, false, (*c)->win, _NET_WM_PID, CARDINAL, 0L, 1L);
1420 prop_r = xcb_get_property_reply(globalconf.connection, prop_c, NULL);
1422 if(prop_r && prop_r->value_len && (data = xcb_get_property_value(prop_r)))
1423 lua_pushnumber(L, *(uint32_t *)data);
1424 else
1426 p_delete(&prop_r);
1427 return 0;
1429 break;
1430 case A_TK_MACHINE:
1431 if(!xutil_text_prop_get(globalconf.connection, (*c)->win,
1432 WM_CLIENT_MACHINE, &value, &slen))
1433 return 0;
1434 lua_pushlstring(L, value, slen);
1435 p_delete(&value);
1436 break;
1437 case A_TK_ICON_NAME:
1438 lua_pushstring(L, (*c)->icon_name);
1439 break;
1440 case A_TK_SCREEN:
1441 lua_pushnumber(L, 1 + (*c)->screen);
1442 break;
1443 case A_TK_HIDE:
1444 lua_pushboolean(L, (*c)->ishidden);
1445 break;
1446 case A_TK_MINIMIZE:
1447 lua_pushboolean(L, (*c)->isminimized);
1448 break;
1449 case A_TK_FULLSCREEN:
1450 lua_pushboolean(L, (*c)->isfullscreen);
1451 break;
1452 case A_TK_ICON:
1453 if((*c)->icon)
1454 luaA_image_userdata_new(L, (*c)->icon);
1455 else
1456 return 0;
1457 break;
1458 case A_TK_OPACITY:
1459 if((d = window_opacity_get((*c)->win)) >= 0)
1460 lua_pushnumber(L, d);
1461 else
1462 return 0;
1463 break;
1464 case A_TK_FLOATING:
1465 lua_pushboolean(L, (*c)->isfloating);
1466 break;
1467 case A_TK_ONTOP:
1468 lua_pushboolean(L, (*c)->isontop);
1469 break;
1470 case A_TK_STICKY:
1471 lua_pushboolean(L, (*c)->issticky);
1472 break;
1473 case A_TK_HONORSIZEHINTS:
1474 lua_pushboolean(L, (*c)->honorsizehints);
1475 break;
1476 case A_TK_BORDER_WIDTH:
1477 lua_pushnumber(L, (*c)->border);
1478 break;
1479 case A_TK_BORDER_COLOR:
1480 luaA_pushcolor(L, &(*c)->border_color);
1481 break;
1482 case A_TK_TITLEBAR:
1483 if((*c)->titlebar)
1484 return luaA_wibox_userdata_new(L, (*c)->titlebar);
1485 return 0;
1486 case A_TK_URGENT:
1487 lua_pushboolean(L, (*c)->isurgent);
1488 break;
1489 case A_TK_SIZEHINTS:
1490 lua_newtable(L);
1491 lua_pushboolean(L, (*c)->size_hints.flags & XCB_SIZE_HINT_US_POSITION);
1492 lua_setfield(L, -2, "user_position");
1493 lua_pushboolean(L, (*c)->size_hints.flags & XCB_SIZE_HINT_US_SIZE);
1494 lua_setfield(L, -2, "user_size");
1495 lua_pushboolean(L, (*c)->size_hints.flags & XCB_SIZE_HINT_P_POSITION);
1496 lua_setfield(L, -2, "program_position");
1497 lua_pushboolean(L, (*c)->size_hints.flags & XCB_SIZE_HINT_P_SIZE);
1498 lua_setfield(L, -2, "program_size");
1499 break;
1500 default:
1501 return 0;
1504 return 1;
1507 /** Get or set mouse buttons bindings for a client.
1508 * \param L The Lua VM state.
1509 * \return The number of element pushed on stack.
1510 * \luastack
1511 * \lvalue A client.
1512 * \lparam An array of mouse button bindings objects, or nothing.
1513 * \return The array of mouse button bindings objects of this client.
1515 static int
1516 luaA_client_buttons(lua_State *L)
1518 client_t **client = luaA_checkudata(L, 1, "client");
1519 button_array_t *buttons = &(*client)->buttons;
1521 if(lua_gettop(L) == 2)
1522 luaA_button_array_set(L, 2, buttons);
1524 return luaA_button_array_get(L, buttons);
1527 /* Client module.
1528 * \param L The Lua VM state.
1529 * \return The number of pushed elements.
1531 static int
1532 luaA_client_module_index(lua_State *L)
1534 size_t len;
1535 const char *buf = luaL_checklstring(L, 2, &len);
1537 switch(a_tokenize(buf, len))
1539 case A_TK_FOCUS:
1540 if(globalconf.screen_focus->client_focus)
1541 luaA_client_userdata_new(L, globalconf.screen_focus->client_focus);
1542 else
1543 return 0;
1544 break;
1545 default:
1546 return 0;
1549 return 1;
1552 /* Client module new index.
1553 * \param L The Lua VM state.
1554 * \return The number of pushed elements.
1556 static int
1557 luaA_client_module_newindex(lua_State *L)
1559 size_t len;
1560 const char *buf = luaL_checklstring(L, 2, &len);
1561 client_t **c;
1563 switch(a_tokenize(buf, len))
1565 case A_TK_FOCUS:
1566 c = luaA_checkudata(L, 3, "client");
1567 client_focus(*c);
1568 break;
1569 default:
1570 break;
1573 return 0;
1576 const struct luaL_reg awesome_client_methods[] =
1578 { "get", luaA_client_get },
1579 { "visible_get", luaA_client_visible_get },
1580 { "__index", luaA_client_module_index },
1581 { "__newindex", luaA_client_module_newindex },
1582 { NULL, NULL }
1584 const struct luaL_reg awesome_client_meta[] =
1586 { "isvisible", luaA_client_isvisible },
1587 { "geometry", luaA_client_geometry },
1588 { "fullgeometry", luaA_client_fullgeometry },
1589 { "buttons", luaA_client_buttons },
1590 { "tags", luaA_client_tags },
1591 { "kill", luaA_client_kill },
1592 { "swap", luaA_client_swap },
1593 { "raise", luaA_client_raise },
1594 { "redraw", luaA_client_redraw },
1595 { "mouse_resize", luaA_client_mouse_resize },
1596 { "mouse_move", luaA_client_mouse_move },
1597 { "unmanage", luaA_client_unmanage },
1598 { "__index", luaA_client_index },
1599 { "__newindex", luaA_client_newindex },
1600 { "__eq", luaA_client_eq },
1601 { "__gc", luaA_client_gc },
1602 { "__tostring", luaA_client_tostring },
1603 /* deprecated */
1604 { "coords", luaA_client_coords },
1605 { "fullcoords", luaA_client_fullcoords },
1606 { NULL, NULL }
1609 // vim: filetype=c:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=80