awesomerc: add missing check for client.focus
[awesome.git] / client.c
blob2add23c040847bcbbfecf1fc9aad4fc48eaea34c
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 if(globalconf.hooks.unfocus != LUA_REFNIL)
166 luaA_client_userdata_new(globalconf.L, c);
167 luaA_dofunction(globalconf.L, globalconf.hooks.unfocus, 1, 0);
170 ewmh_update_net_active_window(c->phys_screen);
173 /** Ban client and unmap it.
174 * \param c The client.
176 void
177 client_ban(client_t *c)
179 if(globalconf.screen_focus->client_focus == c)
180 client_unfocus(c);
181 xcb_unmap_window(globalconf.connection, c->win);
182 if(c->ishidden)
183 window_state_set(c->win, XCB_WM_STATE_ICONIC);
184 else
185 window_state_set(c->win, XCB_WM_STATE_WITHDRAWN);
186 if(c->titlebar)
187 xcb_unmap_window(globalconf.connection, c->titlebar->sw.window);
190 /** Give focus to client, or to first client if client is NULL.
191 * \param c The client or NULL.
192 * \return True if a window (even root) has received focus, false otherwise.
194 static void
195 client_focus(client_t *c)
197 if(!client_maybevisible(c, c->screen) || c->nofocus)
198 return;
200 /* unfocus current selected client */
201 if(globalconf.screen_focus->client_focus
202 && c != globalconf.screen_focus->client_focus)
203 client_unfocus(globalconf.screen_focus->client_focus);
205 /* stop hiding c */
206 c->ishidden = false;
207 client_setminimized(c, false);
209 /* unban the client before focusing or it will fail */
210 client_unban(c);
212 globalconf.screen_focus = &globalconf.screens[c->phys_screen];
213 globalconf.screen_focus->client_focus = c;
215 xcb_set_input_focus(globalconf.connection, XCB_INPUT_FOCUS_POINTER_ROOT,
216 c->win, XCB_CURRENT_TIME);
218 /* Some layouts use focused client differently, so call them back.
219 * And anyway, we have maybe unhidden */
220 client_need_arrange(c);
222 /* execute hook */
223 if(globalconf.hooks.focus != LUA_REFNIL)
225 luaA_client_userdata_new(globalconf.L, globalconf.screen_focus->client_focus);
226 luaA_dofunction(globalconf.L, globalconf.hooks.focus, 1, 0);
229 ewmh_update_net_active_window(c->phys_screen);
232 /** Stack a window below.
233 * \param c The client.
234 * \param previous The previous window on the stack.
235 * \param return The next-previous!
237 static xcb_window_t
238 client_stack_above(client_t *c, xcb_window_t previous)
240 uint32_t config_win_vals[2];
242 config_win_vals[0] = previous;
243 config_win_vals[1] = XCB_STACK_MODE_ABOVE;
245 xcb_configure_window(globalconf.connection, c->win,
246 XCB_CONFIG_WINDOW_SIBLING | XCB_CONFIG_WINDOW_STACK_MODE,
247 config_win_vals);
249 config_win_vals[0] = c->win;
251 if(c->titlebar)
253 xcb_configure_window(globalconf.connection,
254 c->titlebar->sw.window,
255 XCB_CONFIG_WINDOW_SIBLING | XCB_CONFIG_WINDOW_STACK_MODE,
256 config_win_vals);
257 previous = c->titlebar->sw.window;
259 else
260 previous = c->win;
262 /* stack transient window on top of their parents */
263 for(client_node_t *node = *client_node_list_last(&globalconf.stack);
264 node; node = node->prev)
265 if(node->client->transient_for == c)
267 client_stack_above(node->client,
268 previous);
269 previous = node->client->win;
272 return previous;
275 /** Stacking layout layers */
276 typedef enum
278 /** This one is a special layer */
279 LAYER_IGNORE,
280 LAYER_DESKTOP,
281 LAYER_BELOW,
282 LAYER_TILE,
283 LAYER_FLOAT,
284 LAYER_ABOVE,
285 LAYER_FULLSCREEN,
286 LAYER_ONTOP,
287 LAYER_OUTOFSPACE
288 } layer_t;
290 /** Get the real layer of a client according to its attribute (fullscreen, …)
291 * \param c The client.
292 * \return The real layer.
294 static layer_t
295 client_layer_translator(client_t *c)
297 /* first deal with user set attributes */
298 if(c->isontop)
299 return LAYER_ONTOP;
300 else if(c->isfullscreen)
301 return LAYER_FULLSCREEN;
302 else if(c->isabove)
303 return LAYER_ABOVE;
304 else if(c->isbelow)
305 return LAYER_BELOW;
306 else if(c->isfloating)
307 return LAYER_FLOAT;
309 /* check for transient attr */
310 if(c->transient_for)
311 return LAYER_IGNORE;
313 /* then deal with windows type */
314 switch(c->type)
316 case WINDOW_TYPE_DOCK:
317 return LAYER_ABOVE;
318 case WINDOW_TYPE_DESKTOP:
319 return LAYER_DESKTOP;
320 case WINDOW_TYPE_DIALOG:
321 return LAYER_FLOAT;
322 default:
323 break;
326 if(client_isfixed(c))
327 return LAYER_FLOAT;
329 return LAYER_TILE;
332 /** Restack clients.
333 * \todo It might be worth stopping to restack everyone and only stack `c'
334 * relatively to the first matching in the list.
336 void
337 client_stack()
339 uint32_t config_win_vals[2];
340 client_node_t *node, *last = *client_node_list_last(&globalconf.stack);
341 layer_t layer;
342 int screen;
344 config_win_vals[0] = XCB_NONE;
345 config_win_vals[1] = XCB_STACK_MODE_ABOVE;
347 /* stack desktop windows */
348 for(layer = LAYER_DESKTOP; layer < LAYER_BELOW; layer++)
349 for(node = last; node; node = node->prev)
350 if(client_layer_translator(node->client) == layer)
351 config_win_vals[0] = client_stack_above(node->client,
352 config_win_vals[0]);
354 /* first stack not ontop wibox window */
355 for(screen = 0; screen < globalconf.nscreen; screen++)
356 for(int i = 0; i < globalconf.screens[screen].wiboxes.len; i++)
358 wibox_t *sb = globalconf.screens[screen].wiboxes.tab[i];
359 if(!sb->ontop)
361 xcb_configure_window(globalconf.connection,
362 sb->sw.window,
363 XCB_CONFIG_WINDOW_SIBLING | XCB_CONFIG_WINDOW_STACK_MODE,
364 config_win_vals);
365 config_win_vals[0] = sb->sw.window;
369 /* stack bottom layers */
370 for(layer = LAYER_BELOW; layer < LAYER_FULLSCREEN; layer++)
371 for(node = last; node; node = node->prev)
372 if(client_layer_translator(node->client) == layer)
373 config_win_vals[0] = client_stack_above(node->client,
374 config_win_vals[0]);
376 /* then stack ontop wibox window */
377 for(screen = 0; screen < globalconf.nscreen; screen++)
378 for(int i = 0; i < globalconf.screens[screen].wiboxes.len; i++)
380 wibox_t *sb = globalconf.screens[screen].wiboxes.tab[i];
381 if(sb->ontop)
383 xcb_configure_window(globalconf.connection,
384 sb->sw.window,
385 XCB_CONFIG_WINDOW_SIBLING | XCB_CONFIG_WINDOW_STACK_MODE,
386 config_win_vals);
387 config_win_vals[0] = sb->sw.window;
391 /* finally stack ontop and fullscreen windows */
392 for(layer = LAYER_FULLSCREEN; layer < LAYER_OUTOFSPACE; layer++)
393 for(node = last; node; node = node->prev)
394 if(client_layer_translator(node->client) == layer)
395 config_win_vals[0] = client_stack_above(node->client,
396 config_win_vals[0]);
399 /** Manage a new client.
400 * \param w The window.
401 * \param wgeom Window geometry.
402 * \param phys_screen Physical screen number.
403 * \param screen Virtual screen number where to manage client.
405 void
406 client_manage(xcb_window_t w, xcb_get_geometry_reply_t *wgeom, int phys_screen, int screen)
408 xcb_get_property_cookie_t ewmh_icon_cookie;
409 client_t *c;
410 image_t *icon;
411 const uint32_t select_input_val[] =
413 XCB_EVENT_MASK_STRUCTURE_NOTIFY
414 | XCB_EVENT_MASK_PROPERTY_CHANGE
415 | XCB_EVENT_MASK_ENTER_WINDOW
418 /* Send request to get NET_WM_ICON property as soon as possible... */
419 ewmh_icon_cookie = ewmh_window_icon_get_unchecked(w);
420 xcb_change_window_attributes(globalconf.connection, w, XCB_CW_EVENT_MASK, select_input_val);
422 if(systray_iskdedockapp(w))
424 systray_request_handle(w, phys_screen, NULL);
425 return;
428 c = p_new(client_t, 1);
430 c->screen = screen_getbycoord(screen, wgeom->x, wgeom->y);
432 c->phys_screen = phys_screen;
434 /* Initial values */
435 c->win = w;
436 c->geometry.x = c->f_geometry.x = c->m_geometry.x = wgeom->x;
437 c->geometry.y = c->f_geometry.y = c->m_geometry.y = wgeom->y;
438 c->geometry.width = c->f_geometry.width = c->m_geometry.width = wgeom->width;
439 c->geometry.height = c->f_geometry.height = c->m_geometry.height = wgeom->height;
440 client_setborder(c, wgeom->border_width);
441 if((icon = ewmh_window_icon_get_reply(ewmh_icon_cookie)))
442 c->icon = image_ref(&icon);
444 /* we honor size hints by default */
445 c->honorsizehints = true;
447 /* update hints */
448 property_update_wm_normal_hints(c, NULL);
449 property_update_wm_hints(c, NULL);
450 property_update_wm_transient_for(c, NULL);
452 if(c->transient_for)
453 screen = c->transient_for->screen;
455 /* Try to load props if any */
456 client_loadprops(c, &globalconf.screens[screen]);
459 /* Then check clients hints */
460 ewmh_client_check_hints(c);
462 /* move client to screen, but do not tag it for now */
463 screen_client_moveto(c, screen, false, true);
465 /* Check if client has been tagged by loading props, or maybe with its
466 * hints.
467 * If not, we tag it with current selected ones.
468 * This could be done on Lua side, but it's a sane behaviour. */
469 if(!c->issticky)
471 int i;
472 tag_array_t *tags = &globalconf.screens[screen].tags;
473 for(i = 0; i < tags->len; i++)
474 if(is_client_tagged(c, tags->tab[i]))
475 break;
477 /* if no tag, set current selected */
478 if(i == tags->len)
479 for(i = 0; i < tags->len; i++)
480 if(tags->tab[i]->selected)
481 tag_client(c, tags->tab[i]);
484 /* Push client in client list */
485 client_list_push(&globalconf.clients, client_ref(&c));
487 /* Push client in stack */
488 client_raise(c);
490 /* update window title */
491 property_update_wm_name(c);
492 property_update_wm_icon_name(c);
494 /* update strut */
495 ewmh_client_strut_update(c, NULL);
497 ewmh_update_net_client_list(c->phys_screen);
499 /* Call hook to notify list change */
500 if(globalconf.hooks.clients != LUA_REFNIL)
501 luaA_dofunction(globalconf.L, globalconf.hooks.clients, 0, 0);
503 /* call hook */
504 if(globalconf.hooks.manage != LUA_REFNIL)
506 luaA_client_userdata_new(globalconf.L, c);
507 luaA_dofunction(globalconf.L, globalconf.hooks.manage, 1, 0);
511 /** Compute client geometry with respect to its geometry hints.
512 * \param c The client.
513 * \param geometry The geometry that the client might receive.
514 * \return The geometry the client must take respecting its hints.
516 area_t
517 client_geometry_hints(client_t *c, area_t geometry)
519 double dx, dy, max, min, ratio;
521 if(c->minay > 0 && c->maxay > 0 && (geometry.height - c->baseh) > 0
522 && (geometry.width - c->basew) > 0)
524 dx = (double) (geometry.width - c->basew);
525 dy = (double) (geometry.height - c->baseh);
526 min = (double) (c->minax) / (double) (c->minay);
527 max = (double) (c->maxax) / (double) (c->maxay);
528 ratio = dx / dy;
529 if(max > 0 && min > 0 && ratio > 0)
531 if(ratio < min)
533 dy = (dx * min + dy) / (min * min + 1);
534 dx = dy * min;
535 geometry.width = (int) dx + c->basew;
536 geometry.height = (int) dy + c->baseh;
538 else if(ratio > max)
540 dy = (dx * min + dy) / (max * max + 1);
541 dx = dy * min;
542 geometry.width = (int) dx + c->basew;
543 geometry.height = (int) dy + c->baseh;
547 if(c->minw && geometry.width < c->minw)
548 geometry.width = c->minw;
549 if(c->minh && geometry.height < c->minh)
550 geometry.height = c->minh;
551 if(c->maxw && geometry.width > c->maxw)
552 geometry.width = c->maxw;
553 if(c->maxh && geometry.height > c->maxh)
554 geometry.height = c->maxh;
555 if(c->incw)
556 geometry.width -= (geometry.width - c->basew) % c->incw;
557 if(c->inch)
558 geometry.height -= (geometry.height - c->baseh) % c->inch;
560 return geometry;
563 /** Resize client window.
564 * \param c Client to resize.
565 * \param geometry New window geometry.
566 * \param hints Use size hints.
568 void
569 client_resize(client_t *c, area_t geometry, bool hints)
571 int new_screen;
572 area_t area;
573 layout_t *layout = layout_get_current(c->screen);
575 if(c->titlebar && !c->ismoving && c->titlebar->isvisible && !client_isfloating(c) && layout != layout_floating)
576 geometry = titlebar_geometry_remove(c->titlebar, c->border, geometry);
578 if(hints)
579 geometry = client_geometry_hints(c, geometry);
581 if(geometry.width <= 0 || geometry.height <= 0)
582 return;
584 /* offscreen appearance fixes */
585 area = display_area_get(c->phys_screen, NULL,
586 &globalconf.screens[c->screen].padding);
588 if(geometry.x > area.width)
589 geometry.x = area.width - geometry.width - 2 * c->border;
590 if(geometry.y > area.height)
591 geometry.y = area.height - geometry.height - 2 * c->border;
592 if(geometry.x + geometry.width + 2 * c->border < 0)
593 geometry.x = 0;
594 if(geometry.y + geometry.height + 2 * c->border < 0)
595 geometry.y = 0;
597 if(c->geometry.x != geometry.x
598 || c->geometry.y != geometry.y
599 || c->geometry.width != geometry.width
600 || c->geometry.height != geometry.height)
602 new_screen = screen_getbycoord(c->screen, geometry.x, geometry.y);
604 /* Values to configure a window is an array where values are
605 * stored according to 'value_mask' */
606 uint32_t values[4];
608 c->geometry.x = values[0] = geometry.x;
609 c->geometry.y = values[1] = geometry.y;
610 c->geometry.width = values[2] = geometry.width;
611 c->geometry.height = values[3] = geometry.height;
613 /* save the floating geometry if the window is floating but not
614 * maximized */
615 if(c->ismoving || client_isfloating(c)
616 || layout_get_current(new_screen) == layout_floating
617 || layout_get_current(c->screen) == layout_floating)
618 if(!c->isfullscreen)
619 c->f_geometry = geometry;
621 titlebar_update_geometry_floating(c);
623 xcb_configure_window(globalconf.connection, c->win,
624 XCB_CONFIG_WINDOW_X | XCB_CONFIG_WINDOW_Y
625 | XCB_CONFIG_WINDOW_WIDTH | XCB_CONFIG_WINDOW_HEIGHT,
626 values);
627 window_configure(c->win, geometry, c->border);
629 if(c->screen != new_screen)
630 screen_client_moveto(c, new_screen, true, false);
632 /* execute hook */
633 hooks_property(c, "geometry");
637 /** Set a client floating.
638 * \param c The client.
639 * \param floating Set floating, or not.
640 * \param layer Layer to put the floating window onto.
642 void
643 client_setfloating(client_t *c, bool floating)
645 if(c->isfloating != floating
646 && (c->type == WINDOW_TYPE_NORMAL))
648 if((c->isfloating = floating))
649 if(!c->isfullscreen)
650 client_resize(c, c->f_geometry, false);
651 client_need_arrange(c);
652 client_stack();
653 xcb_change_property(globalconf.connection,
654 XCB_PROP_MODE_REPLACE,
655 c->win, _AWESOME_FLOATING, CARDINAL, 8, 1,
656 &c->isfloating);
657 /* execute hook */
658 hooks_property(c, "floating");
662 /** Set a client minimized, or not.
663 * \param c The client.
664 * \param s Set or not the client minimized.
666 void
667 client_setminimized(client_t *c, bool s)
669 if(c->isminimized != s)
671 client_need_arrange(c);
672 c->isminimized = s;
673 client_need_arrange(c);
674 ewmh_client_update_hints(c);
675 /* execute hook */
676 hooks_property(c, "minimized");
680 /** Set a client sticky, or not.
681 * \param c The client.
682 * \param s Set or not the client sticky.
684 void
685 client_setsticky(client_t *c, bool s)
687 if(c->issticky != s)
689 client_need_arrange(c);
690 c->issticky = s;
691 client_need_arrange(c);
692 ewmh_client_update_hints(c);
693 hooks_property(c, "sticky");
697 /** Set a client fullscreen, or not.
698 * \param c The client.
699 * \param s Set or not the client fullscreen.
701 void
702 client_setfullscreen(client_t *c, bool s)
704 if(c->isfullscreen != s)
706 area_t geometry;
708 /* become fullscreen! */
709 if((c->isfullscreen = s))
711 geometry = screen_area_get(c->screen, NULL, NULL, false);
712 c->m_geometry = c->geometry;
713 c->oldborder = c->border;
714 client_setborder(c, 0);
716 else
718 geometry = c->m_geometry;
719 client_setborder(c, c->oldborder);
721 client_resize(c, geometry, false);
722 client_need_arrange(c);
723 client_stack();
724 xcb_change_property(globalconf.connection,
725 XCB_PROP_MODE_REPLACE,
726 c->win, _AWESOME_FULLSCREEN, CARDINAL, 8, 1,
727 &c->isfullscreen);
728 ewmh_client_update_hints(c);
729 hooks_property(c, "fullscreen");
733 /** Set a client above, or not.
734 * \param c The client.
735 * \param s Set or not the client above.
737 void
738 client_setabove(client_t *c, bool s)
740 if(c->isabove != s)
742 c->isabove = s;
743 client_stack();
744 ewmh_client_update_hints(c);
745 /* execute hook */
746 hooks_property(c, "above");
750 /** Set a client below, or not.
751 * \param c The client.
752 * \param s Set or not the client below.
754 void
755 client_setbelow(client_t *c, bool s)
757 if(c->isbelow != s)
759 c->isbelow = s;
760 client_stack();
761 ewmh_client_update_hints(c);
762 /* execute hook */
763 hooks_property(c, "below");
767 /** Set a client modal, or not.
768 * \param c The client.
769 * \param s Set or not the client moda.
771 void
772 client_setmodal(client_t *c, bool s)
774 if(c->ismodal != s)
776 c->ismodal = s;
777 client_stack();
778 ewmh_client_update_hints(c);
779 /* execute hook */
780 hooks_property(c, "modal");
784 /** Set a client ontop, or not.
785 * \param c The client.
786 * \param s Set or not the client moda.
788 void
789 client_setontop(client_t *c, bool s)
791 if(c->isontop != s)
793 c->isontop = s;
794 client_stack();
795 /* execute hook */
796 hooks_property(c, "ontop");
800 /** Save client properties as an X property.
801 * \param c The client.
803 void
804 client_saveprops_tags(client_t *c)
806 tag_array_t *tags = &globalconf.screens[c->screen].tags;
807 unsigned char *prop = p_alloca(unsigned char, tags->len + 1);
808 int i;
810 for(i = 0; i < tags->len; i++)
811 prop[i] = is_client_tagged(c, tags->tab[i]) ? '1' : '0';
813 xcb_change_property(globalconf.connection, XCB_PROP_MODE_REPLACE, c->win, _AWESOME_TAGS, STRING, 8, i, prop);
816 /** Unban a client.
817 * \param c The client.
819 void
820 client_unban(client_t *c)
822 xcb_map_window(globalconf.connection, c->win);
823 window_state_set(c->win, XCB_WM_STATE_NORMAL);
824 if(c->titlebar)
826 if(c->isfullscreen || !c->titlebar->isvisible)
827 xcb_unmap_window(globalconf.connection, c->titlebar->sw.window);
828 else
829 xcb_map_window(globalconf.connection, c->titlebar->sw.window);
833 /** Unmanage a client.
834 * \param c The client.
836 void
837 client_unmanage(client_t *c)
839 tag_array_t *tags = &globalconf.screens[c->screen].tags;
841 if(globalconf.screens[c->phys_screen].client_focus == c)
842 client_unfocus(c);
844 /* remove client everywhere */
845 client_list_detach(&globalconf.clients, c);
846 stack_client_delete(c);
847 for(int i = 0; i < tags->len; i++)
848 untag_client(c, tags->tab[i]);
850 /* call hook */
851 if(globalconf.hooks.unmanage != LUA_REFNIL)
853 luaA_client_userdata_new(globalconf.L, c);
854 luaA_dofunction(globalconf.L, globalconf.hooks.unmanage, 1, 0);
857 /* Call hook to notify list change */
858 if(globalconf.hooks.clients != LUA_REFNIL)
859 luaA_dofunction(globalconf.L, globalconf.hooks.clients, 0, 0);
861 /* The server grab construct avoids race conditions. */
862 xcb_grab_server(globalconf.connection);
864 xcb_configure_window(globalconf.connection, c->win,
865 XCB_CONFIG_WINDOW_BORDER_WIDTH,
866 (uint32_t *) &c->oldborder);
868 xcb_ungrab_button(globalconf.connection, XCB_BUTTON_INDEX_ANY, c->win,
869 XCB_BUTTON_MASK_ANY);
870 window_state_set(c->win, XCB_WM_STATE_WITHDRAWN);
872 xcb_flush(globalconf.connection);
873 xcb_ungrab_server(globalconf.connection);
875 titlebar_client_detach(c);
877 ewmh_update_net_client_list(c->phys_screen);
879 /* delete properties */
880 xcb_delete_property(globalconf.connection, c->win, _AWESOME_TAGS);
881 xcb_delete_property(globalconf.connection, c->win, _AWESOME_FLOATING);
883 if(client_hasstrut(c))
884 /* All the wiboxes (may) need to be repositioned */
885 for(int screen = 0; screen < globalconf.nscreen; screen++)
886 for(int i = 0; i < globalconf.screens[screen].wiboxes.len; i++)
888 wibox_t *s = globalconf.screens[screen].wiboxes.tab[i];
889 wibox_position_update(s);
892 /* set client as invalid */
893 c->invalid = true;
895 client_unref(&c);
898 /** Kill a client via a WM_DELETE_WINDOW request or KillClient if not
899 * supported.
900 * \param c The client to kill.
902 void
903 client_kill(client_t *c)
905 if(window_hasproto(c->win, WM_DELETE_WINDOW))
907 xcb_client_message_event_t ev;
909 /* Initialize all of event's fields first */
910 p_clear(&ev, 1);
912 ev.response_type = XCB_CLIENT_MESSAGE;
913 ev.window = c->win;
914 ev.format = 32;
915 ev.data.data32[1] = XCB_CURRENT_TIME;
916 ev.type = WM_PROTOCOLS;
917 ev.data.data32[0] = WM_DELETE_WINDOW;
919 xcb_send_event(globalconf.connection, false, c->win,
920 XCB_EVENT_MASK_NO_EVENT, (char *) &ev);
922 else
923 xcb_kill_client(globalconf.connection, c->win);
926 /** Get all clients into a table.
927 * \param L The Lua VM state.
928 * \return The number of elements pushed on stack.
929 * \luastack
930 * \lparam An optional screen nunmber.
931 * \lreturn A table with all clients.
933 static int
934 luaA_client_get(lua_State *L)
936 int i = 1, screen;
937 client_t *c;
939 screen = luaL_optnumber(L, 1, 0) - 1;
941 lua_newtable(L);
943 if(screen == SCREEN_UNDEF)
944 for(c = globalconf.clients; c; c = c->next)
946 luaA_client_userdata_new(globalconf.L, c);
947 lua_rawseti(L, -2, i++);
949 else
951 luaA_checkscreen(screen);
952 for(c = globalconf.clients; c; c = c->next)
953 if(c->screen == screen)
955 luaA_client_userdata_new(globalconf.L, c);
956 lua_rawseti(L, -2, i++);
960 return 1;
963 /** Get only visible clients for a screen (DEPRECATED).
964 * \param L The Lua VM state.
965 * \return The number of elements pushed on stack.
966 * \luastack
967 * \lparam A screen number.
968 * \lreturn A table with all visible clients for this screen.
970 static int
971 luaA_client_visible_get(lua_State *L)
973 int i = 1;
974 client_t *c;
975 int screen = luaL_checknumber(L, 1) - 1;
977 luaA_checkscreen(screen);
979 deprecate(L, "awful.client.visible()");
981 lua_newtable(L);
983 for(c = globalconf.clients; c; c = c->next)
984 if(client_isvisible(c, screen))
986 luaA_client_userdata_new(L, c);
987 lua_rawseti(L, -2, i++);
990 return 1;
993 /** Check if a client is visible on its screen.
994 * \param L The Lua VM state.
995 * \return The number of elements pushed on stack.
996 * \luastack
997 * \lvalue A client.
998 * \lreturn A boolean value, true if the client is visible, false otherwise.
1000 static int
1001 luaA_client_isvisible(lua_State *L)
1003 client_t **c = luaA_checkudata(L, 1, "client");
1004 lua_pushboolean(L, client_isvisible(*c, (*c)->screen));
1005 return 1;
1008 /** Set client border width.
1009 * \param c The client.
1010 * \param width The border width.
1012 void
1013 client_setborder(client_t *c, int width)
1015 uint32_t w = width;
1017 if(width > 0 && (c->type == WINDOW_TYPE_DOCK
1018 || c->type == WINDOW_TYPE_SPLASH
1019 || c->type == WINDOW_TYPE_DESKTOP
1020 || c->isfullscreen))
1021 return;
1023 if(width == c->border || width < 0)
1024 return;
1026 c->border = width;
1027 xcb_configure_window(globalconf.connection, c->win,
1028 XCB_CONFIG_WINDOW_BORDER_WIDTH, &w);
1030 if(client_isvisible(c, c->screen))
1032 if(client_isfloating(c) || layout_get_current(c->screen) == layout_floating)
1033 titlebar_update_geometry_floating(c);
1034 else
1035 globalconf.screens[c->screen].need_arrange = true;
1038 hooks_property(c, "border_width");
1041 /** Kill a client.
1042 * \param L The Lua VM state.
1044 * \luastack
1045 * \lvalue A client.
1047 static int
1048 luaA_client_kill(lua_State *L)
1050 client_t **c = luaA_checkudata(L, 1, "client");
1051 client_kill(*c);
1052 return 0;
1055 /** Swap a client with another one.
1056 * \param L The Lua VM state.
1057 * \luastack
1058 * \lvalue A client.
1059 * \lparam A client to swap with.
1061 static int
1062 luaA_client_swap(lua_State *L)
1064 client_t **c = luaA_checkudata(L, 1, "client");
1065 client_t **swap = luaA_checkudata(L, 2, "client");
1066 client_list_swap(&globalconf.clients, *swap, *c);
1067 client_need_arrange(*c);
1068 client_need_arrange(*swap);
1070 /* Call hook to notify list change */
1071 if(globalconf.hooks.clients != LUA_REFNIL)
1072 luaA_dofunction(L, globalconf.hooks.clients, 0, 0);
1074 return 0;
1077 /** Access or set the client tags.
1078 * \param L The Lua VM state.
1079 * \return The number of elements pushed on stack.
1080 * \lparam A table with tags to set, or none to get the current tags table.
1081 * \return The clients tag.
1083 static int
1084 luaA_client_tags(lua_State *L)
1086 tag_array_t *tags;
1087 tag_t **tag;
1088 client_t **c = luaA_checkudata(L, 1, "client");
1089 int j = 0;
1091 if(lua_gettop(L) == 2)
1093 luaA_checktable(L, 2);
1094 tags = &globalconf.screens[(*c)->screen].tags;
1095 for(int i = 0; i < tags->len; i++)
1096 untag_client(*c, tags->tab[i]);
1097 lua_pushnil(L);
1098 while(lua_next(L, 2))
1100 tag = luaA_checkudata(L, -1, "tag");
1101 tag_client(*c, *tag);
1102 lua_pop(L, 1);
1104 lua_pop(L, 1);
1107 tags = &globalconf.screens[(*c)->screen].tags;
1108 luaA_otable_new(L);
1109 for(int i = 0; i < tags->len; i++)
1110 if(is_client_tagged(*c, tags->tab[i]))
1112 luaA_tag_userdata_new(L, tags->tab[i]);
1113 lua_rawseti(L, -2, ++j);
1116 return 1;
1119 /** Raise a client on top of others which are on the same layer.
1120 * \param L The Lua VM state.
1121 * \luastack
1122 * \lvalue A client.
1124 static int
1125 luaA_client_raise(lua_State *L)
1127 client_t **c = luaA_checkudata(L, 1, "client");
1128 client_raise(*c);
1129 return 0;
1132 /** Lower a client on bottom of others which are on the same layer.
1133 * \param L The Lua VM state.
1134 * \luastack
1135 * \lvalue A client.
1137 static int
1138 luaA_client_lower(lua_State *L)
1140 client_t **c = luaA_checkudata(L, 1, "client");
1141 client_lower(*c);
1142 return 0;
1145 /** Redraw a client by unmapping and mapping it quickly.
1146 * \param L The Lua VM state.
1148 * \luastack
1149 * \lvalue A client.
1151 static int
1152 luaA_client_redraw(lua_State *L)
1154 client_t **c = luaA_checkudata(L, 1, "client");
1156 xcb_unmap_window(globalconf.connection, (*c)->win);
1157 xcb_map_window(globalconf.connection, (*c)->win);
1159 /* Set the focus on the current window if the redraw has been
1160 performed on the window where the pointer is currently on
1161 because after the unmapping/mapping, the focus is lost */
1162 if(globalconf.screen_focus->client_focus == *c)
1163 xcb_set_input_focus(globalconf.connection, XCB_INPUT_FOCUS_POINTER_ROOT,
1164 (*c)->win, XCB_CURRENT_TIME);
1166 return 0;
1169 /** Stop managing a client.
1170 * \param L The Lua VM state.
1171 * \return The number of elements pushed on stack.
1172 * \luastack
1173 * \lvalue A client.
1175 static int
1176 luaA_client_unmanage(lua_State *L)
1178 client_t **c = luaA_checkudata(L, 1, "client");
1179 client_unmanage(*c);
1180 return 0;
1183 /** Return client geometry.
1184 * \param L The Lua VM state.
1185 * \param full Use titlebar also.
1186 * \return The number of elements pushed on stack.
1188 static int
1189 luaA_client_handlegeom(lua_State *L, bool full)
1191 client_t **c = luaA_checkudata(L, 1, "client");
1193 if(lua_gettop(L) == 2)
1194 if(client_isfloating(*c)
1195 || layout_get_current((*c)->screen) == layout_floating)
1197 area_t geometry;
1199 luaA_checktable(L, 2);
1200 geometry.x = luaA_getopt_number(L, 2, "x", (*c)->geometry.x);
1201 geometry.y = luaA_getopt_number(L, 2, "y", (*c)->geometry.y);
1202 if(client_isfixed(*c))
1204 geometry.width = (*c)->geometry.width;
1205 geometry.height = (*c)->geometry.height;
1207 else
1209 geometry.width = luaA_getopt_number(L, 2, "width", (*c)->geometry.width);
1210 geometry.height = luaA_getopt_number(L, 2, "height", (*c)->geometry.height);
1212 if(full)
1213 geometry = titlebar_geometry_remove((*c)->titlebar,
1214 (*c)->border,
1215 geometry);
1216 client_resize(*c, geometry, (*c)->honorsizehints);
1219 if(full)
1220 return luaA_pusharea(L, titlebar_geometry_add((*c)->titlebar,
1221 (*c)->border,
1222 (*c)->geometry));
1224 return luaA_pusharea(L, (*c)->geometry);
1227 /** Return client geometry.
1228 * \param L The Lua VM state.
1229 * \return The number of elements pushed on stack.
1230 * \luastack
1231 * \lparam A table with new coordinates, or none.
1232 * \lreturn A table with client coordinates.
1234 static int
1235 luaA_client_geometry(lua_State *L)
1237 return luaA_client_handlegeom(L, false);
1240 static int
1241 luaA_client_coords(lua_State *L)
1243 deprecate(L, "client:geometry()");
1244 return luaA_client_geometry(L);
1247 /** Return client geometry, using also titlebar and border width.
1248 * \param L The Lua VM state.
1249 * \return The number of elements pushed on stack.
1250 * \luastack
1251 * \lparam A table with new coordinates, or none.
1252 * \lreturn A table with client coordinates.
1254 static int
1255 luaA_client_fullgeometry(lua_State *L)
1257 return luaA_client_handlegeom(L, true);
1260 static int
1261 luaA_client_fullcoords(lua_State *L)
1263 deprecate(L, "client:fullgeometry()");
1264 return luaA_client_fullgeometry(L);
1267 /** Client newindex.
1268 * \param L The Lua VM state.
1269 * \return The number of elements pushed on stack.
1272 luaA_client_newindex(lua_State *L)
1274 size_t len;
1275 client_t **c = luaA_checkudata(L, 1, "client");
1276 const char *buf = luaL_checklstring(L, 2, &len);
1277 bool b;
1278 double d;
1279 int i;
1280 wibox_t **t = NULL;
1281 image_t **image;
1283 if((*c)->invalid)
1284 luaL_error(L, "client is invalid\n");
1286 switch(a_tokenize(buf, len))
1288 case A_TK_SCREEN:
1289 if(globalconf.xinerama_is_active)
1291 i = luaL_checknumber(L, 3) - 1;
1292 luaA_checkscreen(i);
1293 if(i != (*c)->screen)
1294 screen_client_moveto(*c, i, true, true);
1296 break;
1297 case A_TK_HIDE:
1298 b = luaA_checkboolean(L, 3);
1299 if(b != (*c)->ishidden)
1301 client_need_arrange(*c);
1302 (*c)->ishidden = b;
1303 client_need_arrange(*c);
1305 break;
1306 case A_TK_MINIMIZE:
1307 client_setminimized(*c, luaA_checkboolean(L, 3));
1308 break;
1309 case A_TK_FULLSCREEN:
1310 client_setfullscreen(*c, luaA_checkboolean(L, 3));
1311 break;
1312 case A_TK_ICON:
1313 image = luaA_checkudata(L, 3, "image");
1314 image_unref(&(*c)->icon);
1315 image_ref(image);
1316 (*c)->icon = *image;
1317 /* execute hook */
1318 hooks_property(*c, "icon");
1319 break;
1320 case A_TK_OPACITY:
1321 if(lua_isnil(L, 3))
1322 window_opacity_set((*c)->win, -1);
1323 else
1325 d = luaL_checknumber(L, 3);
1326 if(d >= 0 && d <= 1)
1327 window_opacity_set((*c)->win, d);
1329 break;
1330 case A_TK_FLOATING:
1331 client_setfloating(*c, luaA_checkboolean(L, 3));
1332 break;
1333 case A_TK_STICKY:
1334 client_setsticky(*c, luaA_checkboolean(L, 3));
1335 break;
1336 case A_TK_HONORSIZEHINTS:
1337 (*c)->honorsizehints = luaA_checkboolean(L, 3);
1338 client_need_arrange(*c);
1339 break;
1340 case A_TK_BORDER_WIDTH:
1341 client_setborder(*c, luaL_checknumber(L, 3));
1342 break;
1343 case A_TK_ONTOP:
1344 client_setontop(*c, luaA_checkboolean(L, 3));
1345 break;
1346 case A_TK_BORDER_COLOR:
1347 if((buf = luaL_checklstring(L, 3, &len))
1348 && xcolor_init_reply(xcolor_init_unchecked(&(*c)->border_color, buf, len)))
1349 xcb_change_window_attributes(globalconf.connection, (*c)->win,
1350 XCB_CW_BORDER_PIXEL, &(*c)->border_color.pixel);
1351 break;
1352 case A_TK_TITLEBAR:
1353 if(lua_isnil(L, 3))
1354 titlebar_client_detach(*c);
1355 else
1357 t = luaA_checkudata(L, 3, "wibox");
1358 titlebar_client_attach(*c, *t);
1360 break;
1361 default:
1362 return 0;
1365 return 0;
1368 /** Client object.
1369 * \param L The Lua VM state.
1370 * \return The number of elements pushed on stack.
1371 * \luastack
1372 * \lfield name The client title.
1373 * \lfield skip_taskbar True if the client does not want to be in taskbar.
1374 * \lfield type The window type (desktop, normal, dock, …).
1375 * \lfield class The client class.
1376 * \lfield instance The client instance.
1377 * \lfield pid The client PID, if available.
1378 * \lfield role The window role, if available.
1379 * \lfield machine The machine client is running on.
1380 * \lfield icon_name The client name when iconified.
1381 * \lfield screen Client screen number.
1382 * \lfield hide Define if the client must be hidden, i.e. never mapped,
1383 * invisible in taskbar.
1384 * \lfield minimize Define it the client must be iconify, i.e. only visible in
1385 * taskbar.
1386 * \lfield icon_path Path to the icon used to identify.
1387 * \lfield floating True always floating.
1388 * \lfield honorsizehints Honor size hints, i.e. respect size ratio.
1389 * \lfield border_width The client border width.
1390 * \lfield border_color The client border color.
1391 * \lfield titlebar The client titlebar.
1392 * \lfield urgent The client urgent state.
1393 * \lfield focus The focused client.
1394 * \lfield opacity The client opacity between 0 and 1.
1395 * \lfield ontop The client is on top of every other windows.
1396 * \lfield fullscreen The client is fullscreen or not.
1397 * \lfield transient_for Return the client the window is transient for.
1398 * \lfield size_hints A table with size hints of the client: user_position,
1399 * user_size, program_position and program_size.
1401 static int
1402 luaA_client_index(lua_State *L)
1404 size_t len;
1405 ssize_t slen;
1406 client_t **c = luaA_checkudata(L, 1, "client");
1407 const char *buf = luaL_checklstring(L, 2, &len);
1408 char *value;
1409 void *data;
1410 xcb_get_wm_class_reply_t hint;
1411 xcb_get_property_cookie_t prop_c;
1412 xcb_get_property_reply_t *prop_r = NULL;
1413 double d;
1415 if((*c)->invalid)
1416 luaL_error(L, "client is invalid\n");
1418 if(luaA_usemetatable(L, 1, 2))
1419 return 1;
1421 switch(a_tokenize(buf, len))
1423 case A_TK_NAME:
1424 lua_pushstring(L, (*c)->name);
1425 break;
1426 case A_TK_TRANSIENT_FOR:
1427 if((*c)->transient_for)
1428 return luaA_client_userdata_new(L, (*c)->transient_for);
1429 case A_TK_SKIP_TASKBAR:
1430 lua_pushboolean(L, (*c)->skiptb);
1431 break;
1432 case A_TK_TYPE:
1433 switch((*c)->type)
1435 case WINDOW_TYPE_DESKTOP:
1436 lua_pushliteral(L, "desktop");
1437 break;
1438 case WINDOW_TYPE_DOCK:
1439 lua_pushliteral(L, "dock");
1440 break;
1441 case WINDOW_TYPE_SPLASH:
1442 lua_pushliteral(L, "splash");
1443 break;
1444 case WINDOW_TYPE_DIALOG:
1445 lua_pushliteral(L, "dialog");
1446 break;
1447 default:
1448 lua_pushliteral(L, "normal");
1449 break;
1451 break;
1452 case A_TK_CLASS:
1453 if(!xcb_get_wm_class_reply(globalconf.connection,
1454 xcb_get_wm_class_unchecked(globalconf.connection, (*c)->win),
1455 &hint, NULL))
1456 return 0;
1457 lua_pushstring(L, hint.class);
1458 xcb_get_wm_class_reply_wipe(&hint);
1459 break;
1460 case A_TK_INSTANCE:
1461 if(!xcb_get_wm_class_reply(globalconf.connection,
1462 xcb_get_wm_class_unchecked(globalconf.connection, (*c)->win),
1463 &hint, NULL))
1464 return 0;
1465 lua_pushstring(L, hint.name);
1466 xcb_get_wm_class_reply_wipe(&hint);
1467 break;
1468 case A_TK_ROLE:
1469 if(!xutil_text_prop_get(globalconf.connection, (*c)->win,
1470 WM_WINDOW_ROLE, &value, &slen))
1471 return 0;
1472 lua_pushlstring(L, value, slen);
1473 p_delete(&value);
1474 break;
1475 case A_TK_PID:
1476 prop_c = xcb_get_property_unchecked(globalconf.connection, false, (*c)->win, _NET_WM_PID, CARDINAL, 0L, 1L);
1477 prop_r = xcb_get_property_reply(globalconf.connection, prop_c, NULL);
1479 if(prop_r && prop_r->value_len && (data = xcb_get_property_value(prop_r)))
1480 lua_pushnumber(L, *(uint32_t *)data);
1481 else
1483 p_delete(&prop_r);
1484 return 0;
1486 break;
1487 case A_TK_MACHINE:
1488 if(!xutil_text_prop_get(globalconf.connection, (*c)->win,
1489 WM_CLIENT_MACHINE, &value, &slen))
1490 return 0;
1491 lua_pushlstring(L, value, slen);
1492 p_delete(&value);
1493 break;
1494 case A_TK_ICON_NAME:
1495 lua_pushstring(L, (*c)->icon_name);
1496 break;
1497 case A_TK_SCREEN:
1498 lua_pushnumber(L, 1 + (*c)->screen);
1499 break;
1500 case A_TK_HIDE:
1501 lua_pushboolean(L, (*c)->ishidden);
1502 break;
1503 case A_TK_MINIMIZE:
1504 lua_pushboolean(L, (*c)->isminimized);
1505 break;
1506 case A_TK_FULLSCREEN:
1507 lua_pushboolean(L, (*c)->isfullscreen);
1508 break;
1509 case A_TK_ICON:
1510 if((*c)->icon)
1511 luaA_image_userdata_new(L, (*c)->icon);
1512 else
1513 return 0;
1514 break;
1515 case A_TK_OPACITY:
1516 if((d = window_opacity_get((*c)->win)) >= 0)
1517 lua_pushnumber(L, d);
1518 else
1519 return 0;
1520 break;
1521 case A_TK_FLOATING:
1522 lua_pushboolean(L, client_isfloating(*c));
1523 break;
1524 case A_TK_ONTOP:
1525 lua_pushboolean(L, (*c)->isontop);
1526 break;
1527 case A_TK_STICKY:
1528 lua_pushboolean(L, (*c)->issticky);
1529 break;
1530 case A_TK_HONORSIZEHINTS:
1531 lua_pushboolean(L, (*c)->honorsizehints);
1532 break;
1533 case A_TK_BORDER_WIDTH:
1534 lua_pushnumber(L, (*c)->border);
1535 break;
1536 case A_TK_BORDER_COLOR:
1537 luaA_pushcolor(L, &(*c)->border_color);
1538 break;
1539 case A_TK_TITLEBAR:
1540 if((*c)->titlebar)
1541 return luaA_wibox_userdata_new(L, (*c)->titlebar);
1542 return 0;
1543 case A_TK_URGENT:
1544 lua_pushboolean(L, (*c)->isurgent);
1545 break;
1546 case A_TK_SIZE_HINTS:
1547 lua_newtable(L);
1548 lua_pushboolean(L, (*c)->size_hints.flags & XCB_SIZE_HINT_US_POSITION);
1549 lua_setfield(L, -2, "user_position");
1550 lua_pushboolean(L, (*c)->size_hints.flags & XCB_SIZE_HINT_US_SIZE);
1551 lua_setfield(L, -2, "user_size");
1552 lua_pushboolean(L, (*c)->size_hints.flags & XCB_SIZE_HINT_P_POSITION);
1553 lua_setfield(L, -2, "program_position");
1554 lua_pushboolean(L, (*c)->size_hints.flags & XCB_SIZE_HINT_P_SIZE);
1555 lua_setfield(L, -2, "program_size");
1556 break;
1557 default:
1558 return 0;
1561 return 1;
1564 /** Get or set mouse buttons bindings for a client.
1565 * \param L The Lua VM state.
1566 * \return The number of element pushed on stack.
1567 * \luastack
1568 * \lvalue A client.
1569 * \lparam An array of mouse button bindings objects, or nothing.
1570 * \return The array of mouse button bindings objects of this client.
1572 static int
1573 luaA_client_buttons(lua_State *L)
1575 client_t **client = luaA_checkudata(L, 1, "client");
1576 button_array_t *buttons = &(*client)->buttons;
1578 if(lua_gettop(L) == 2)
1579 luaA_button_array_set(L, 2, buttons);
1581 return luaA_button_array_get(L, buttons);
1584 /* Client module.
1585 * \param L The Lua VM state.
1586 * \return The number of pushed elements.
1588 static int
1589 luaA_client_module_index(lua_State *L)
1591 size_t len;
1592 const char *buf = luaL_checklstring(L, 2, &len);
1594 switch(a_tokenize(buf, len))
1596 case A_TK_FOCUS:
1597 if(globalconf.screen_focus->client_focus)
1598 luaA_client_userdata_new(L, globalconf.screen_focus->client_focus);
1599 else
1600 return 0;
1601 break;
1602 default:
1603 return 0;
1606 return 1;
1609 /* Client module new index.
1610 * \param L The Lua VM state.
1611 * \return The number of pushed elements.
1613 static int
1614 luaA_client_module_newindex(lua_State *L)
1616 size_t len;
1617 const char *buf = luaL_checklstring(L, 2, &len);
1618 client_t **c;
1620 switch(a_tokenize(buf, len))
1622 case A_TK_FOCUS:
1623 c = luaA_checkudata(L, 3, "client");
1624 client_focus(*c);
1625 break;
1626 default:
1627 break;
1630 return 0;
1633 const struct luaL_reg awesome_client_methods[] =
1635 { "get", luaA_client_get },
1636 { "visible_get", luaA_client_visible_get },
1637 { "__index", luaA_client_module_index },
1638 { "__newindex", luaA_client_module_newindex },
1639 { NULL, NULL }
1641 const struct luaL_reg awesome_client_meta[] =
1643 { "isvisible", luaA_client_isvisible },
1644 { "geometry", luaA_client_geometry },
1645 { "fullgeometry", luaA_client_fullgeometry },
1646 { "buttons", luaA_client_buttons },
1647 { "tags", luaA_client_tags },
1648 { "kill", luaA_client_kill },
1649 { "swap", luaA_client_swap },
1650 { "raise", luaA_client_raise },
1651 { "lower", luaA_client_lower },
1652 { "redraw", luaA_client_redraw },
1653 { "mouse_resize", luaA_client_mouse_resize },
1654 { "mouse_move", luaA_client_mouse_move },
1655 { "unmanage", luaA_client_unmanage },
1656 { "__index", luaA_client_index },
1657 { "__newindex", luaA_client_newindex },
1658 { "__eq", luaA_client_eq },
1659 { "__gc", luaA_client_gc },
1660 { "__tostring", luaA_client_tostring },
1661 /* deprecated */
1662 { "coords", luaA_client_coords },
1663 { "fullcoords", luaA_client_fullcoords },
1664 { NULL, NULL }
1667 // vim: filetype=c:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=80