imagebox: allow to not resize images
[awesome.git] / client.c
blob9096f9bc23285a4763229ad5c87b52a9f75360c5
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)
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 default:
294 return LAYER_TILE;
298 /** Restack clients.
299 * \todo It might be worth stopping to restack everyone and only stack `c'
300 * relatively to the first matching in the list.
302 void
303 client_stack()
305 uint32_t config_win_vals[2];
306 client_node_t *node, *last = *client_node_list_last(&globalconf.stack);
307 layer_t layer;
308 int screen;
310 config_win_vals[0] = XCB_NONE;
311 config_win_vals[1] = XCB_STACK_MODE_ABOVE;
313 /* first stack not ontop wibox window */
314 for(screen = 0; screen < globalconf.nscreen; screen++)
315 for(int i = 0; i < globalconf.screens[screen].wiboxes.len; i++)
317 wibox_t *sb = globalconf.screens[screen].wiboxes.tab[i];
318 if(!sb->ontop)
320 xcb_configure_window(globalconf.connection,
321 sb->sw.window,
322 XCB_CONFIG_WINDOW_SIBLING | XCB_CONFIG_WINDOW_STACK_MODE,
323 config_win_vals);
324 config_win_vals[0] = sb->sw.window;
328 /* stack bottom layers */
329 for(layer = LAYER_DESKTOP; layer < LAYER_FULLSCREEN; layer++)
330 for(node = last; node; node = node->prev)
331 if(client_layer_translator(node->client) == layer)
332 config_win_vals[0] = client_stack_position(node->client,
333 XCB_STACK_MODE_ABOVE,
334 config_win_vals[0]);
336 /* then stack ontop wibox window */
337 for(screen = 0; screen < globalconf.nscreen; screen++)
338 for(int i = 0; i < globalconf.screens[screen].wiboxes.len; i++)
340 wibox_t *sb = globalconf.screens[screen].wiboxes.tab[i];
341 if(sb->ontop)
343 xcb_configure_window(globalconf.connection,
344 sb->sw.window,
345 XCB_CONFIG_WINDOW_SIBLING | XCB_CONFIG_WINDOW_STACK_MODE,
346 config_win_vals);
347 config_win_vals[0] = sb->sw.window;
351 /* finally stack ontop and fullscreen windows */
352 for(layer = LAYER_FULLSCREEN; layer < LAYER_OUTOFSPACE; layer++)
353 for(node = last; node; node = node->prev)
354 if(client_layer_translator(node->client) == layer)
355 config_win_vals[0] = client_stack_position(node->client,
356 XCB_STACK_MODE_ABOVE,
357 config_win_vals[0]);
359 /* stack transient window on top of their parents */
360 for(node = last; node; node = node->prev)
361 if(client_layer_translator(node->client) == LAYER_TRANSIENT_FOR)
362 client_stack_position(node->client,
363 XCB_STACK_MODE_ABOVE,
364 node->client->transient_for->win);
368 /** Manage a new client.
369 * \param w The window.
370 * \param wgeom Window geometry.
371 * \param phys_screen Physical screen number.
372 * \param screen Virtual screen number where to manage client.
374 void
375 client_manage(xcb_window_t w, xcb_get_geometry_reply_t *wgeom, int phys_screen, int screen)
377 xcb_get_property_cookie_t ewmh_icon_cookie;
378 client_t *c;
379 image_t *icon;
380 const uint32_t select_input_val[] =
382 XCB_EVENT_MASK_STRUCTURE_NOTIFY
383 | XCB_EVENT_MASK_PROPERTY_CHANGE
384 | XCB_EVENT_MASK_ENTER_WINDOW
387 /* Send request to get NET_WM_ICON property as soon as possible... */
388 ewmh_icon_cookie = ewmh_window_icon_get_unchecked(w);
389 xcb_change_window_attributes(globalconf.connection, w, XCB_CW_EVENT_MASK, select_input_val);
391 if(systray_iskdedockapp(w))
393 systray_request_handle(w, phys_screen, NULL);
394 return;
397 c = p_new(client_t, 1);
399 c->screen = screen_getbycoord(screen, wgeom->x, wgeom->y);
401 c->phys_screen = phys_screen;
403 /* Initial values */
404 c->win = w;
405 c->geometry.x = c->f_geometry.x = c->m_geometry.x = wgeom->x;
406 c->geometry.y = c->f_geometry.y = c->m_geometry.y = wgeom->y;
407 c->geometry.width = c->f_geometry.width = c->m_geometry.width = wgeom->width;
408 c->geometry.height = c->f_geometry.height = c->m_geometry.height = wgeom->height;
409 client_setborder(c, wgeom->border_width);
410 if((icon = ewmh_window_icon_get_reply(ewmh_icon_cookie)))
411 c->icon = image_ref(&icon);
413 /* we honor size hints by default */
414 c->honorsizehints = true;
416 /* update hints */
417 property_update_wm_normal_hints(c, NULL);
418 property_update_wm_hints(c, NULL);
419 property_update_wm_transient_for(c, NULL);
421 if(c->transient_for)
422 screen = c->transient_for->screen;
424 /* Try to load props if any */
425 client_loadprops(c, &globalconf.screens[screen]);
427 /* move client to screen, but do not tag it for now */
428 screen_client_moveto(c, screen, false, true);
430 /* Then check clients hints */
431 ewmh_client_check_hints(c);
433 /* Check if client has been tagged by loading props, or maybe with its
434 * hints.
435 * If not, we tag it with current selected ones.
436 * This could be done on Lua side, but it's a sane behaviour. */
437 if(!c->issticky)
439 int i;
440 tag_array_t *tags = &globalconf.screens[screen].tags;
441 for(i = 0; i < tags->len; i++)
442 if(is_client_tagged(c, tags->tab[i]))
443 break;
445 /* if no tag, set current selected */
446 if(i == tags->len)
447 for(i = 0; i < tags->len; i++)
448 if(tags->tab[i]->selected)
449 tag_client(c, tags->tab[i]);
452 /* Push client in client list */
453 client_list_push(&globalconf.clients, client_ref(&c));
455 /* Push client in stack */
456 client_raise(c);
458 /* update window title */
459 property_update_wm_name(c);
460 property_update_wm_icon_name(c);
462 /* update strut */
463 ewmh_client_strut_update(c, NULL);
465 ewmh_update_net_client_list(c->phys_screen);
467 /* Call hook to notify list change */
468 luaA_dofunction(globalconf.L, globalconf.hooks.clients, 0, 0);
470 /* call hook */
471 luaA_client_userdata_new(globalconf.L, c);
472 luaA_dofunction(globalconf.L, globalconf.hooks.manage, 1, 0);
475 /** Compute client geometry with respect to its geometry hints.
476 * \param c The client.
477 * \param geometry The geometry that the client might receive.
478 * \return The geometry the client must take respecting its hints.
480 area_t
481 client_geometry_hints(client_t *c, area_t geometry)
483 double dx, dy, max, min, ratio;
485 if(c->minay > 0 && c->maxay > 0 && (geometry.height - c->baseh) > 0
486 && (geometry.width - c->basew) > 0)
488 dx = (double) (geometry.width - c->basew);
489 dy = (double) (geometry.height - c->baseh);
490 min = (double) (c->minax) / (double) (c->minay);
491 max = (double) (c->maxax) / (double) (c->maxay);
492 ratio = dx / dy;
493 if(max > 0 && min > 0 && ratio > 0)
495 if(ratio < min)
497 dy = (dx * min + dy) / (min * min + 1);
498 dx = dy * min;
499 geometry.width = (int) dx + c->basew;
500 geometry.height = (int) dy + c->baseh;
502 else if(ratio > max)
504 dy = (dx * min + dy) / (max * max + 1);
505 dx = dy * min;
506 geometry.width = (int) dx + c->basew;
507 geometry.height = (int) dy + c->baseh;
511 if(c->minw && geometry.width < c->minw)
512 geometry.width = c->minw;
513 if(c->minh && geometry.height < c->minh)
514 geometry.height = c->minh;
515 if(c->maxw && geometry.width > c->maxw)
516 geometry.width = c->maxw;
517 if(c->maxh && geometry.height > c->maxh)
518 geometry.height = c->maxh;
519 if(c->incw)
520 geometry.width -= (geometry.width - c->basew) % c->incw;
521 if(c->inch)
522 geometry.height -= (geometry.height - c->baseh) % c->inch;
524 return geometry;
527 /** Resize client window.
528 * \param c Client to resize.
529 * \param geometry New window geometry.
530 * \param hints Use size hints.
532 void
533 client_resize(client_t *c, area_t geometry, bool hints)
535 int new_screen;
536 area_t area;
537 layout_t *layout = layout_get_current(c->screen);
538 bool fixed;
539 /* Values to configure a window is an array where values are
540 * stored according to 'value_mask' */
541 uint32_t values[5];
543 if(c->titlebar && !c->ismoving && !client_isfloating(c) && layout != layout_floating)
544 geometry = titlebar_geometry_remove(c->titlebar, c->border, geometry);
546 if(hints)
547 geometry = client_geometry_hints(c, geometry);
549 if(geometry.width <= 0 || geometry.height <= 0)
550 return;
552 /* offscreen appearance fixes */
553 area = display_area_get(c->phys_screen, NULL,
554 &globalconf.screens[c->screen].padding);
556 fixed = client_isfixed(c);
558 if(geometry.x > area.width)
559 geometry.x = area.width - geometry.width - 2 * c->border;
560 if(geometry.y > area.height)
561 geometry.y = area.height - geometry.height - 2 * c->border;
562 if(geometry.x + geometry.width + 2 * c->border < 0)
563 geometry.x = 0;
564 if(geometry.y + geometry.height + 2 * c->border < 0)
565 geometry.y = 0;
567 /* fixed windows can only change their x,y */
568 if((fixed && (c->geometry.x != geometry.x || c->geometry.y != geometry.y))
569 || (!fixed && (c->geometry.x != geometry.x
570 || c->geometry.y != geometry.y
571 || c->geometry.width != geometry.width
572 || c->geometry.height != geometry.height)))
574 new_screen = screen_getbycoord(c->screen, geometry.x, geometry.y);
576 c->geometry.x = values[0] = geometry.x;
577 c->geometry.width = values[2] = geometry.width;
578 c->geometry.y = values[1] = geometry.y;
579 c->geometry.height = values[3] = geometry.height;
580 values[4] = c->border;
582 /* save the floating geometry if the window is floating but not
583 * maximized */
584 if(c->ismoving || client_isfloating(c)
585 || layout_get_current(new_screen) == layout_floating)
586 if(!c->isfullscreen)
587 c->f_geometry = geometry;
589 titlebar_update_geometry_floating(c);
591 xcb_configure_window(globalconf.connection, c->win,
592 XCB_CONFIG_WINDOW_X | XCB_CONFIG_WINDOW_Y |
593 XCB_CONFIG_WINDOW_WIDTH | XCB_CONFIG_WINDOW_HEIGHT |
594 XCB_CONFIG_WINDOW_BORDER_WIDTH,
595 values);
596 window_configure(c->win, geometry, c->border);
598 if(c->screen != new_screen)
599 screen_client_moveto(c, new_screen, true, false);
601 /* execute hook */
602 hooks_property(c, "geometry");
606 /** Set a clinet floating.
607 * \param c The client.
608 * \param floating Set floating, or not.
609 * \param layer Layer to put the floating window onto.
611 void
612 client_setfloating(client_t *c, bool floating)
614 if(c->isfloating != floating
615 && (c->type == WINDOW_TYPE_NORMAL))
617 if((c->isfloating = floating))
618 if(!c->isfullscreen)
619 client_resize(c, c->f_geometry, false);
620 client_need_arrange(c);
621 client_stack();
622 xcb_change_property(globalconf.connection,
623 XCB_PROP_MODE_REPLACE,
624 c->win, _AWESOME_FLOATING, CARDINAL, 8, 1,
625 &c->isfloating);
626 /* execute hook */
627 hooks_property(c, "floating");
631 /** Set a client minimized, or not.
632 * \param c The client.
633 * \param s Set or not the client minimized.
635 void
636 client_setminimized(client_t *c, bool s)
638 if(c->isminimized != s)
640 client_need_arrange(c);
641 c->isminimized = s;
642 client_need_arrange(c);
643 ewmh_client_update_hints(c);
644 /* execute hook */
645 hooks_property(c, "minimized");
649 /** Set a client sticky, or not.
650 * \param c The client.
651 * \param s Set or not the client sticky.
653 void
654 client_setsticky(client_t *c, bool s)
656 if(c->issticky != s)
658 client_need_arrange(c);
659 c->issticky = s;
660 client_need_arrange(c);
661 ewmh_client_update_hints(c);
662 hooks_property(c, "sticky");
666 /** Set a client fullscreen, or not.
667 * \param c The client.
668 * \param s Set or not the client fullscreen.
670 void
671 client_setfullscreen(client_t *c, bool s)
673 if(c->isfullscreen != s)
675 area_t geometry;
677 /* become fullscreen! */
678 if((c->isfullscreen = s))
680 geometry = screen_area_get(c->screen, NULL, NULL, false);
681 c->m_geometry = c->geometry;
682 c->oldborder = c->border;
683 client_setborder(c, 0);
685 else
687 geometry = c->m_geometry;
688 client_setborder(c, c->oldborder);
689 client_resize(c, c->m_geometry, false);
691 client_resize(c, geometry, false);
692 client_need_arrange(c);
693 client_stack();
694 xcb_change_property(globalconf.connection,
695 XCB_PROP_MODE_REPLACE,
696 c->win, _AWESOME_FULLSCREEN, CARDINAL, 8, 1,
697 &c->isfullscreen);
698 ewmh_client_update_hints(c);
699 hooks_property(c, "fullscreen");
703 /** Set a client above, or not.
704 * \param c The client.
705 * \param s Set or not the client above.
707 void
708 client_setabove(client_t *c, bool s)
710 if(c->isabove != s)
712 c->isabove = s;
713 client_stack();
714 ewmh_client_update_hints(c);
715 /* execute hook */
716 hooks_property(c, "above");
720 /** Set a client below, or not.
721 * \param c The client.
722 * \param s Set or not the client below.
724 void
725 client_setbelow(client_t *c, bool s)
727 if(c->isbelow != s)
729 c->isbelow = s;
730 client_stack();
731 ewmh_client_update_hints(c);
732 /* execute hook */
733 hooks_property(c, "below");
737 /** Set a client modal, or not.
738 * \param c The client.
739 * \param s Set or not the client moda.
741 void
742 client_setmodal(client_t *c, bool s)
744 if(c->ismodal != s)
746 c->ismodal = s;
747 client_stack();
748 ewmh_client_update_hints(c);
749 /* execute hook */
750 hooks_property(c, "modal");
754 /** Set a client ontop, or not.
755 * \param c The client.
756 * \param s Set or not the client moda.
758 void
759 client_setontop(client_t *c, bool s)
761 if(c->isontop != s)
763 c->isontop = s;
764 client_stack();
765 /* execute hook */
766 hooks_property(c, "ontop");
770 /** Save client properties as an X property.
771 * \param c The client.
773 void
774 client_saveprops_tags(client_t *c)
776 tag_array_t *tags = &globalconf.screens[c->screen].tags;
777 unsigned char *prop = p_alloca(unsigned char, tags->len + 1);
778 int i;
780 for(i = 0; i < tags->len; i++)
781 prop[i] = is_client_tagged(c, tags->tab[i]) ? '1' : '0';
783 xcb_change_property(globalconf.connection, XCB_PROP_MODE_REPLACE, c->win, _AWESOME_TAGS, STRING, 8, i, prop);
786 /** Unban a client.
787 * \param c The client.
789 void
790 client_unban(client_t *c)
792 xcb_map_window(globalconf.connection, c->win);
793 window_state_set(c->win, XCB_WM_STATE_NORMAL);
794 if(c->titlebar)
796 if(c->isfullscreen || !c->titlebar->isvisible)
797 xcb_unmap_window(globalconf.connection, c->titlebar->sw.window);
798 else
799 xcb_map_window(globalconf.connection, c->titlebar->sw.window);
803 /** Unmanage a client.
804 * \param c The client.
806 void
807 client_unmanage(client_t *c)
809 tag_array_t *tags = &globalconf.screens[c->screen].tags;
811 if(globalconf.screens[c->phys_screen].client_focus == c)
812 client_unfocus(c);
814 /* remove client everywhere */
815 client_list_detach(&globalconf.clients, c);
816 stack_client_delete(c);
817 for(int i = 0; i < tags->len; i++)
818 untag_client(c, tags->tab[i]);
820 /* call hook */
821 luaA_client_userdata_new(globalconf.L, c);
822 luaA_dofunction(globalconf.L, globalconf.hooks.unmanage, 1, 0);
824 /* Call hook to notify list change */
825 luaA_dofunction(globalconf.L, globalconf.hooks.clients, 0, 0);
827 /* The server grab construct avoids race conditions. */
828 xcb_grab_server(globalconf.connection);
830 xcb_configure_window(globalconf.connection, c->win,
831 XCB_CONFIG_WINDOW_BORDER_WIDTH,
832 (uint32_t *) &c->oldborder);
834 xcb_ungrab_button(globalconf.connection, XCB_BUTTON_INDEX_ANY, c->win,
835 XCB_BUTTON_MASK_ANY);
836 window_state_set(c->win, XCB_WM_STATE_WITHDRAWN);
838 xcb_flush(globalconf.connection);
839 xcb_ungrab_server(globalconf.connection);
841 titlebar_client_detach(c);
843 ewmh_update_net_client_list(c->phys_screen);
845 /* delete properties */
846 xcb_delete_property(globalconf.connection, c->win, _AWESOME_TAGS);
847 xcb_delete_property(globalconf.connection, c->win, _AWESOME_FLOATING);
849 if(client_hasstrut(c))
850 /* All the wiboxes (may) need to be repositioned */
851 for(int screen = 0; screen < globalconf.nscreen; screen++)
852 for(int i = 0; i < globalconf.screens[screen].wiboxes.len; i++)
854 wibox_t *s = globalconf.screens[screen].wiboxes.tab[i];
855 wibox_position_update(s);
858 /* set client as invalid */
859 c->invalid = true;
861 client_unref(&c);
864 /** Kill a client via a WM_DELETE_WINDOW request or KillClient if not
865 * supported.
866 * \param c The client to kill.
868 void
869 client_kill(client_t *c)
871 if(window_hasproto(c->win, WM_DELETE_WINDOW))
873 xcb_client_message_event_t ev;
875 /* Initialize all of event's fields first */
876 p_clear(&ev, 1);
878 ev.response_type = XCB_CLIENT_MESSAGE;
879 ev.window = c->win;
880 ev.format = 32;
881 ev.data.data32[1] = XCB_CURRENT_TIME;
882 ev.type = WM_PROTOCOLS;
883 ev.data.data32[0] = WM_DELETE_WINDOW;
885 xcb_send_event(globalconf.connection, false, c->win,
886 XCB_EVENT_MASK_NO_EVENT, (char *) &ev);
888 else
889 xcb_kill_client(globalconf.connection, c->win);
892 /** Get all clients into a table.
893 * \param L The Lua VM state.
894 * \return The number of elements pushed on stack.
895 * \luastack
896 * \lparam An optional screen nunmber.
897 * \lreturn A table with all clients.
899 static int
900 luaA_client_get(lua_State *L)
902 int i = 1, screen;
903 client_t *c;
905 screen = luaL_optnumber(L, 1, 0) - 1;
907 lua_newtable(L);
909 if(screen == SCREEN_UNDEF)
910 for(c = globalconf.clients; c; c = c->next)
912 luaA_client_userdata_new(globalconf.L, c);
913 lua_rawseti(L, -2, i++);
915 else
917 luaA_checkscreen(screen);
918 for(c = globalconf.clients; c; c = c->next)
919 if(c->screen == screen)
921 luaA_client_userdata_new(globalconf.L, c);
922 lua_rawseti(L, -2, i++);
926 return 1;
929 /** Get only visible clients for a screen (DEPRECATED).
930 * \param L The Lua VM state.
931 * \return The number of elements pushed on stack.
932 * \luastack
933 * \lparam A screen number.
934 * \lreturn A table with all visible clients for this screen.
936 static int
937 luaA_client_visible_get(lua_State *L)
939 int i = 1;
940 client_t *c;
941 int screen = luaL_checknumber(L, 1) - 1;
943 luaA_checkscreen(screen);
945 deprecate();
947 lua_newtable(L);
949 for(c = globalconf.clients; c; c = c->next)
950 if(client_isvisible(c, screen))
952 luaA_client_userdata_new(L, c);
953 lua_rawseti(L, -2, i++);
956 return 1;
959 /** Check if a client is visible on its screen.
960 * \param L The Lua VM state.
961 * \return The number of elements pushed on stack.
962 * \luastack
963 * \lvalue A client.
964 * \lreturn A boolean value, true if the client is visible, false otherwise.
966 static int
967 luaA_client_isvisible(lua_State *L)
969 client_t **c = luaA_checkudata(L, 1, "client");
970 lua_pushboolean(L, client_isvisible(*c, (*c)->screen));
971 return 1;
974 /** Set client border width.
975 * \param c The client.
976 * \param width The border width.
978 void
979 client_setborder(client_t *c, int width)
981 uint32_t w = width;
983 if(width > 0 && (c->type == WINDOW_TYPE_DOCK
984 || c->type == WINDOW_TYPE_SPLASH
985 || c->type == WINDOW_TYPE_DESKTOP
986 || c->isfullscreen))
987 return;
989 if(width == c->border || width < 0)
990 return;
992 c->border = width;
993 xcb_configure_window(globalconf.connection, c->win,
994 XCB_CONFIG_WINDOW_BORDER_WIDTH, &w);
996 if(client_isvisible(c, c->screen))
998 if(client_isfloating(c) || layout_get_current(c->screen) == layout_floating)
999 titlebar_update_geometry_floating(c);
1000 else
1001 globalconf.screens[c->screen].need_arrange = true;
1004 hooks_property(c, "border_width");
1007 /** Kill a client.
1008 * \param L The Lua VM state.
1010 * \luastack
1011 * \lvalue A client.
1013 static int
1014 luaA_client_kill(lua_State *L)
1016 client_t **c = luaA_checkudata(L, 1, "client");
1017 client_kill(*c);
1018 return 0;
1021 /** Swap a client with another one.
1022 * \param L The Lua VM state.
1023 * \luastack
1024 * \lvalue A client.
1025 * \lparam A client to swap with.
1027 static int
1028 luaA_client_swap(lua_State *L)
1030 client_t **c = luaA_checkudata(L, 1, "client");
1031 client_t **swap = luaA_checkudata(L, 2, "client");
1032 client_list_swap(&globalconf.clients, *swap, *c);
1033 client_need_arrange(*c);
1034 client_need_arrange(*swap);
1036 /* Call hook to notify list change */
1037 luaA_dofunction(L, globalconf.hooks.clients, 0, 0);
1039 return 0;
1042 /** Access or set the client tags.
1043 * \param L The Lua VM state.
1044 * \return The number of elements pushed on stack.
1045 * \lparam A table with tags to set, or none to get the current tags table.
1046 * \return The clients tag.
1048 static int
1049 luaA_client_tags(lua_State *L)
1051 tag_array_t *tags;
1052 tag_t **tag;
1053 client_t **c = luaA_checkudata(L, 1, "client");
1054 int j = 0;
1056 if(lua_gettop(L) == 2)
1058 luaA_checktable(L, 2);
1059 tags = &globalconf.screens[(*c)->screen].tags;
1060 for(int i = 0; i < tags->len; i++)
1061 untag_client(*c, tags->tab[i]);
1062 lua_pushnil(L);
1063 while(lua_next(L, 2))
1065 tag = luaA_checkudata(L, -1, "tag");
1066 tag_client(*c, *tag);
1067 lua_pop(L, 1);
1069 lua_pop(L, 1);
1072 tags = &globalconf.screens[(*c)->screen].tags;
1073 luaA_otable_new(L);
1074 for(int i = 0; i < tags->len; i++)
1075 if(is_client_tagged(*c, tags->tab[i]))
1077 luaA_tag_userdata_new(L, tags->tab[i]);
1078 lua_rawseti(L, -2, ++j);
1081 return 1;
1084 /** Raise a client on top of others which are on the same layer.
1085 * \param L The Lua VM state.
1087 * \luastack
1088 * \lvalue A client.
1090 static int
1091 luaA_client_raise(lua_State *L)
1093 client_t **c = luaA_checkudata(L, 1, "client");
1094 client_raise(*c);
1095 return 0;
1098 /** Redraw a client by unmapping and mapping it quickly.
1099 * \param L The Lua VM state.
1101 * \luastack
1102 * \lvalue A client.
1104 static int
1105 luaA_client_redraw(lua_State *L)
1107 client_t **c = luaA_checkudata(L, 1, "client");
1109 xcb_unmap_window(globalconf.connection, (*c)->win);
1110 xcb_map_window(globalconf.connection, (*c)->win);
1112 /* Set the focus on the current window if the redraw has been
1113 performed on the window where the pointer is currently on
1114 because after the unmapping/mapping, the focus is lost */
1115 if(globalconf.screen_focus->client_focus == *c)
1116 xcb_set_input_focus(globalconf.connection, XCB_INPUT_FOCUS_POINTER_ROOT,
1117 (*c)->win, XCB_CURRENT_TIME);
1119 return 0;
1122 /** Stop managing a client.
1123 * \param L The Lua VM state.
1124 * \return The number of elements pushed on stack.
1125 * \luastack
1126 * \lvalue A client.
1128 static int
1129 luaA_client_unmanage(lua_State *L)
1131 client_t **c = luaA_checkudata(L, 1, "client");
1132 client_unmanage(*c);
1133 return 0;
1136 /** Return client geometry.
1137 * \param L The Lua VM state.
1138 * \return The number of elements pushed on stack.
1139 * \luastack
1140 * \lparam A table with new coordinates, or none.
1141 * \lreturn A table with client coordinates.
1143 static int
1144 luaA_client_geometry(lua_State *L)
1146 client_t **c = luaA_checkudata(L, 1, "client");
1148 if(lua_gettop(L) == 2)
1150 if((*c)->isfloating || layout_get_current((*c)->screen) == layout_floating)
1152 area_t geometry;
1154 luaA_checktable(L, 2);
1155 geometry.x = luaA_getopt_number(L, 2, "x", (*c)->geometry.x);
1156 geometry.y = luaA_getopt_number(L, 2, "y", (*c)->geometry.y);
1157 geometry.width = luaA_getopt_number(L, 2, "width", (*c)->geometry.width);
1158 geometry.height = luaA_getopt_number(L, 2, "height", (*c)->geometry.height);
1159 client_resize(*c, geometry, false);
1163 return luaA_pusharea(L, (*c)->geometry);
1166 static int
1167 luaA_client_coords(lua_State *L)
1169 deprecate();
1170 return luaA_client_geometry(L);
1173 /** Return client geometry, using also titlebar and border width.
1174 * \param L The Lua VM state.
1175 * \return The number of elements pushed on stack.
1176 * \luastack
1177 * \lparam A table with new coordinates, or none.
1178 * \lreturn A table with client coordinates.
1180 static int
1181 luaA_client_fullgeometry(lua_State *L)
1183 client_t **c = luaA_checkudata(L, 1, "client");
1184 area_t geometry;
1186 if(lua_gettop(L) == 2)
1188 if((*c)->isfloating || layout_get_current((*c)->screen) == layout_floating)
1190 luaA_checktable(L, 2);
1191 geometry.x = luaA_getopt_number(L, 2, "x", (*c)->geometry.x);
1192 geometry.y = luaA_getopt_number(L, 2, "y", (*c)->geometry.y);
1193 geometry.width = luaA_getopt_number(L, 2, "width", (*c)->geometry.width);
1194 geometry.height = luaA_getopt_number(L, 2, "height", (*c)->geometry.height);
1195 geometry = titlebar_geometry_remove((*c)->titlebar,
1196 (*c)->border,
1197 geometry);
1198 client_resize(*c, geometry, false);
1202 return luaA_pusharea(L, titlebar_geometry_add((*c)->titlebar,
1203 (*c)->border,
1204 (*c)->geometry));
1207 static int
1208 luaA_client_fullcoords(lua_State *L)
1210 deprecate();
1211 return luaA_client_fullgeometry(L);
1214 /** Client newindex.
1215 * \param L The Lua VM state.
1216 * \return The number of elements pushed on stack.
1219 luaA_client_newindex(lua_State *L)
1221 size_t len;
1222 client_t **c = luaA_checkudata(L, 1, "client");
1223 const char *buf = luaL_checklstring(L, 2, &len);
1224 bool b;
1225 double d;
1226 int i;
1227 wibox_t **t = NULL;
1228 image_t **image;
1230 if((*c)->invalid)
1231 luaL_error(L, "client is invalid\n");
1233 switch(a_tokenize(buf, len))
1235 case A_TK_SCREEN:
1236 if(globalconf.xinerama_is_active)
1238 i = luaL_checknumber(L, 3) - 1;
1239 luaA_checkscreen(i);
1240 if(i != (*c)->screen)
1241 screen_client_moveto(*c, i, true, true);
1243 break;
1244 case A_TK_HIDE:
1245 b = luaA_checkboolean(L, 3);
1246 if(b != (*c)->ishidden)
1248 client_need_arrange(*c);
1249 (*c)->ishidden = b;
1250 client_need_arrange(*c);
1252 break;
1253 case A_TK_MINIMIZE:
1254 client_setminimized(*c, luaA_checkboolean(L, 3));
1255 break;
1256 case A_TK_FULLSCREEN:
1257 client_setfullscreen(*c, luaA_checkboolean(L, 3));
1258 break;
1259 case A_TK_ICON:
1260 image = luaA_checkudata(L, 3, "image");
1261 image_unref(&(*c)->icon);
1262 image_ref(image);
1263 (*c)->icon = *image;
1264 /* execute hook */
1265 hooks_property(*c, "icon");
1266 break;
1267 case A_TK_OPACITY:
1268 if(lua_isnil(L, 3))
1269 window_opacity_set((*c)->win, -1);
1270 else
1272 d = luaL_checknumber(L, 3);
1273 if(d >= 0 && d <= 1)
1274 window_opacity_set((*c)->win, d);
1276 break;
1277 case A_TK_FLOATING:
1278 client_setfloating(*c, luaA_checkboolean(L, 3));
1279 break;
1280 case A_TK_STICKY:
1281 client_setsticky(*c, luaA_checkboolean(L, 3));
1282 break;
1283 case A_TK_HONORSIZEHINTS:
1284 (*c)->honorsizehints = luaA_checkboolean(L, 3);
1285 client_need_arrange(*c);
1286 break;
1287 case A_TK_BORDER_WIDTH:
1288 client_setborder(*c, luaL_checknumber(L, 3));
1289 break;
1290 case A_TK_ONTOP:
1291 client_setontop(*c, luaA_checkboolean(L, 3));
1292 break;
1293 case A_TK_BORDER_COLOR:
1294 if((buf = luaL_checklstring(L, 3, &len))
1295 && xcolor_init_reply(xcolor_init_unchecked(&(*c)->border_color, buf, len)))
1296 xcb_change_window_attributes(globalconf.connection, (*c)->win,
1297 XCB_CW_BORDER_PIXEL, &(*c)->border_color.pixel);
1298 break;
1299 case A_TK_TITLEBAR:
1300 if(lua_isnil(L, 3))
1301 titlebar_client_detach(*c);
1302 else
1304 t = luaA_checkudata(L, 3, "wibox");
1305 titlebar_client_attach(*c, *t);
1307 break;
1308 default:
1309 return 0;
1312 return 0;
1315 /** Client object.
1316 * \param L The Lua VM state.
1317 * \return The number of elements pushed on stack.
1318 * \luastack
1319 * \lfield name The client title.
1320 * \lfield skip_taskbar True if the client does not want to be in taskbar.
1321 * \lfield type The window type (desktop, normal, dock, …).
1322 * \lfield class The client class.
1323 * \lfield instance The client instance.
1324 * \lfield pid The client PID, if available.
1325 * \lfield role The window role, if available.
1326 * \lfield machine The machine client is running on.
1327 * \lfield icon_name The client name when iconified.
1328 * \lfield screen Client screen number.
1329 * \lfield hide Define if the client must be hidden, i.e. never mapped,
1330 * invisible in taskbar.
1331 * \lfield minimize Define it the client must be iconify, i.e. only visible in
1332 * taskbar.
1333 * \lfield icon_path Path to the icon used to identify.
1334 * \lfield floating True always floating.
1335 * \lfield honorsizehints Honor size hints, i.e. respect size ratio.
1336 * \lfield border_width The client border width.
1337 * \lfield border_color The client border color.
1338 * \lfield titlebar The client titlebar.
1339 * \lfield urgent The client urgent state.
1340 * \lfield focus The focused client.
1341 * \lfield opacity The client opacity between 0 and 1.
1342 * \lfield ontop The client is on top of every other windows.
1343 * \lfield fullscreen The client is fullscreen or not.
1345 static int
1346 luaA_client_index(lua_State *L)
1348 size_t len;
1349 ssize_t slen;
1350 client_t **c = luaA_checkudata(L, 1, "client");
1351 const char *buf = luaL_checklstring(L, 2, &len);
1352 char *value;
1353 void *data;
1354 xcb_get_wm_class_reply_t hint;
1355 xcb_get_property_cookie_t prop_c;
1356 xcb_get_property_reply_t *prop_r = NULL;
1357 double d;
1359 if((*c)->invalid)
1360 luaL_error(L, "client is invalid\n");
1362 if(luaA_usemetatable(L, 1, 2))
1363 return 1;
1365 switch(a_tokenize(buf, len))
1367 case A_TK_NAME:
1368 lua_pushstring(L, (*c)->name);
1369 break;
1370 case A_TK_SKIP_TASKBAR:
1371 lua_pushboolean(L, (*c)->skiptb);
1372 break;
1373 case A_TK_TYPE:
1374 switch((*c)->type)
1376 case WINDOW_TYPE_DESKTOP:
1377 lua_pushliteral(L, "desktop");
1378 break;
1379 case WINDOW_TYPE_DOCK:
1380 lua_pushliteral(L, "dock");
1381 break;
1382 case WINDOW_TYPE_SPLASH:
1383 lua_pushliteral(L, "splash");
1384 break;
1385 case WINDOW_TYPE_DIALOG:
1386 lua_pushliteral(L, "dialog");
1387 break;
1388 default:
1389 lua_pushliteral(L, "normal");
1390 break;
1392 break;
1393 case A_TK_CLASS:
1394 if(!xcb_get_wm_class_reply(globalconf.connection,
1395 xcb_get_wm_class_unchecked(globalconf.connection, (*c)->win),
1396 &hint, NULL))
1397 return 0;
1398 lua_pushstring(L, hint.class);
1399 xcb_get_wm_class_reply_wipe(&hint);
1400 break;
1401 case A_TK_INSTANCE:
1402 if(!xcb_get_wm_class_reply(globalconf.connection,
1403 xcb_get_wm_class_unchecked(globalconf.connection, (*c)->win),
1404 &hint, NULL))
1405 return 0;
1406 lua_pushstring(L, hint.name);
1407 xcb_get_wm_class_reply_wipe(&hint);
1408 break;
1409 case A_TK_ROLE:
1410 if(!xutil_text_prop_get(globalconf.connection, (*c)->win,
1411 WM_WINDOW_ROLE, &value, &slen))
1412 return 0;
1413 lua_pushlstring(L, value, slen);
1414 p_delete(&value);
1415 break;
1416 case A_TK_PID:
1417 prop_c = xcb_get_property_unchecked(globalconf.connection, false, (*c)->win, _NET_WM_PID, CARDINAL, 0L, 1L);
1418 prop_r = xcb_get_property_reply(globalconf.connection, prop_c, NULL);
1420 if(prop_r && prop_r->value_len && (data = xcb_get_property_value(prop_r)))
1421 lua_pushnumber(L, *(uint32_t *)data);
1422 else
1424 p_delete(&prop_r);
1425 return 0;
1427 break;
1428 case A_TK_MACHINE:
1429 if(!xutil_text_prop_get(globalconf.connection, (*c)->win,
1430 WM_CLIENT_MACHINE, &value, &slen))
1431 return 0;
1432 lua_pushlstring(L, value, slen);
1433 p_delete(&value);
1434 break;
1435 case A_TK_ICON_NAME:
1436 lua_pushstring(L, (*c)->icon_name);
1437 break;
1438 case A_TK_SCREEN:
1439 lua_pushnumber(L, 1 + (*c)->screen);
1440 break;
1441 case A_TK_HIDE:
1442 lua_pushboolean(L, (*c)->ishidden);
1443 break;
1444 case A_TK_MINIMIZE:
1445 lua_pushboolean(L, (*c)->isminimized);
1446 break;
1447 case A_TK_FULLSCREEN:
1448 lua_pushboolean(L, (*c)->isfullscreen);
1449 break;
1450 case A_TK_ICON:
1451 if((*c)->icon)
1452 luaA_image_userdata_new(L, (*c)->icon);
1453 else
1454 return 0;
1455 break;
1456 case A_TK_OPACITY:
1457 if((d = window_opacity_get((*c)->win)) >= 0)
1458 lua_pushnumber(L, d);
1459 else
1460 return 0;
1461 break;
1462 case A_TK_FLOATING:
1463 lua_pushboolean(L, (*c)->isfloating);
1464 break;
1465 case A_TK_ONTOP:
1466 lua_pushboolean(L, (*c)->isontop);
1467 break;
1468 case A_TK_STICKY:
1469 lua_pushboolean(L, (*c)->issticky);
1470 break;
1471 case A_TK_HONORSIZEHINTS:
1472 lua_pushboolean(L, (*c)->honorsizehints);
1473 break;
1474 case A_TK_BORDER_WIDTH:
1475 lua_pushnumber(L, (*c)->border);
1476 break;
1477 case A_TK_BORDER_COLOR:
1478 luaA_pushcolor(L, &(*c)->border_color);
1479 break;
1480 case A_TK_TITLEBAR:
1481 if((*c)->titlebar)
1482 return luaA_wibox_userdata_new(L, (*c)->titlebar);
1483 return 0;
1484 case A_TK_URGENT:
1485 lua_pushboolean(L, (*c)->isurgent);
1486 break;
1487 case A_TK_SIZEHINTS:
1488 lua_newtable(L);
1489 lua_pushboolean(L, (*c)->size_hints.flags & XCB_SIZE_HINT_US_POSITION);
1490 lua_setfield(L, -2, "user_position");
1491 lua_pushboolean(L, (*c)->size_hints.flags & XCB_SIZE_HINT_US_SIZE);
1492 lua_setfield(L, -2, "user_size");
1493 lua_pushboolean(L, (*c)->size_hints.flags & XCB_SIZE_HINT_P_POSITION);
1494 lua_setfield(L, -2, "program_position");
1495 lua_pushboolean(L, (*c)->size_hints.flags & XCB_SIZE_HINT_P_SIZE);
1496 lua_setfield(L, -2, "program_size");
1497 break;
1498 default:
1499 return 0;
1502 return 1;
1505 /** Get or set mouse buttons bindings for a client.
1506 * \param L The Lua VM state.
1507 * \return The number of element pushed on stack.
1508 * \luastack
1509 * \lvalue A client.
1510 * \lparam An array of mouse button bindings objects, or nothing.
1511 * \return The array of mouse button bindings objects of this client.
1513 static int
1514 luaA_client_buttons(lua_State *L)
1516 client_t **client = luaA_checkudata(L, 1, "client");
1517 button_array_t *buttons = &(*client)->buttons;
1519 if(lua_gettop(L) == 2)
1520 luaA_button_array_set(L, 2, buttons);
1522 return luaA_button_array_get(L, buttons);
1525 /* Client module.
1526 * \param L The Lua VM state.
1527 * \return The number of pushed elements.
1529 static int
1530 luaA_client_module_index(lua_State *L)
1532 size_t len;
1533 const char *buf = luaL_checklstring(L, 2, &len);
1535 switch(a_tokenize(buf, len))
1537 case A_TK_FOCUS:
1538 if(globalconf.screen_focus->client_focus)
1539 luaA_client_userdata_new(L, globalconf.screen_focus->client_focus);
1540 else
1541 return 0;
1542 break;
1543 default:
1544 return 0;
1547 return 1;
1550 /* Client module new index.
1551 * \param L The Lua VM state.
1552 * \return The number of pushed elements.
1554 static int
1555 luaA_client_module_newindex(lua_State *L)
1557 size_t len;
1558 const char *buf = luaL_checklstring(L, 2, &len);
1559 client_t **c;
1561 switch(a_tokenize(buf, len))
1563 case A_TK_FOCUS:
1564 c = luaA_checkudata(L, 3, "client");
1565 client_focus(*c);
1566 break;
1567 default:
1568 break;
1571 return 0;
1574 const struct luaL_reg awesome_client_methods[] =
1576 { "get", luaA_client_get },
1577 { "visible_get", luaA_client_visible_get },
1578 { "__index", luaA_client_module_index },
1579 { "__newindex", luaA_client_module_newindex },
1580 { NULL, NULL }
1582 const struct luaL_reg awesome_client_meta[] =
1584 { "isvisible", luaA_client_isvisible },
1585 { "geometry", luaA_client_geometry },
1586 { "fullgeometry", luaA_client_fullgeometry },
1587 { "buttons", luaA_client_buttons },
1588 { "tags", luaA_client_tags },
1589 { "kill", luaA_client_kill },
1590 { "swap", luaA_client_swap },
1591 { "raise", luaA_client_raise },
1592 { "redraw", luaA_client_redraw },
1593 { "mouse_resize", luaA_client_mouse_resize },
1594 { "mouse_move", luaA_client_mouse_move },
1595 { "unmanage", luaA_client_unmanage },
1596 { "__index", luaA_client_index },
1597 { "__newindex", luaA_client_newindex },
1598 { "__eq", luaA_client_eq },
1599 { "__gc", luaA_client_gc },
1600 { "__tostring", luaA_client_tostring },
1601 /* deprecated */
1602 { "coords", luaA_client_coords },
1603 { "fullcoords", luaA_client_fullcoords },
1604 { NULL, NULL }
1607 // vim: filetype=c:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=80