client: fix translator for fixed window, add BELOW (FS#377)
[awesome.git] / client.c
blobc04485c3be5f7c1a4ae65fb70f401dfb45cf351b
1 /*
2 * client.c - client management
4 * Copyright © 2007-2008 Julien Danjou <julien@danjou.info>
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License along
17 * with this program; if not, write to the Free Software Foundation, Inc.,
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
22 #include <xcb/xcb_atom.h>
24 #include "cnode.h"
25 #include "tag.h"
26 #include "window.h"
27 #include "ewmh.h"
28 #include "screen.h"
29 #include "titlebar.h"
30 #include "systray.h"
31 #include "property.h"
32 #include "layouts/floating.h"
33 #include "common/markup.h"
34 #include "common/atoms.h"
36 extern awesome_t globalconf;
38 DO_LUA_NEW(extern, client_t, client, "client", client_ref)
39 DO_LUA_EQ(client_t, client, "client")
40 DO_LUA_GC(client_t, client, "client", client_unref)
42 /** Load windows properties, restoring client's tag
43 * and floating state before awesome was restarted if any.
44 * \param c A client pointer.
45 * \param screen A virtual screen.
46 * \return True if client had property, false otherwise.
48 static bool
49 client_loadprops(client_t * c, screen_t *screen)
51 ssize_t len;
52 tag_array_t *tags = &screen->tags;
53 char *prop = NULL;
54 xcb_get_property_cookie_t floating_q, fullscreen_q;
55 xcb_get_property_reply_t *reply;
56 void *data;
58 if(!xutil_text_prop_get(globalconf.connection, c->win, _AWESOME_TAGS,
59 &prop, &len))
60 return false;
62 /* Send the GetProperty requests which will be processed later */
63 floating_q = xcb_get_property_unchecked(globalconf.connection, false, c->win,
64 _AWESOME_FLOATING, CARDINAL, 0, 1);
66 fullscreen_q = xcb_get_property_unchecked(globalconf.connection, false, c->win,
67 _AWESOME_FULLSCREEN, CARDINAL, 0, 1);
69 /* ignore property if the tag count isn't matching */
70 if(len == tags->len)
71 for(int i = 0; i < tags->len; i++)
72 if(prop[i] == '1')
73 tag_client(c, tags->tab[i]);
74 else
75 untag_client(c, tags->tab[i]);
77 p_delete(&prop);
79 /* check for floating */
80 reply = xcb_get_property_reply(globalconf.connection, floating_q, NULL);
82 if(reply && reply->value_len && (data = xcb_get_property_value(reply)))
83 client_setfloating(c, *(bool *) data);
84 p_delete(&reply);
86 /* check for fullscreen */
87 reply = xcb_get_property_reply(globalconf.connection, fullscreen_q, NULL);
89 if(reply && reply->value_len && (data = xcb_get_property_value(reply)))
90 client_setfullscreen(c, *(bool *) data);
91 p_delete(&reply);
93 return true;
96 /** Check if client supports protocol a protocole in WM_PROTOCOL.
97 * \param win The window.
98 * \return True if client has the atom in protocol, false otherwise.
100 static bool
101 window_hasproto(xcb_window_t win, xcb_atom_t atom)
103 uint32_t i;
104 xcb_get_wm_protocols_reply_t protocols;
105 bool ret = false;
107 if(xcb_get_wm_protocols_reply(globalconf.connection,
108 xcb_get_wm_protocols_unchecked(globalconf.connection,
109 win, WM_PROTOCOLS),
110 &protocols, NULL))
112 for(i = 0; !ret && i < protocols.atoms_len; i++)
113 if(protocols.atoms[i] == atom)
114 ret = true;
115 xcb_get_wm_protocols_reply_wipe(&protocols);
117 return ret;
120 /** Returns true if a client is tagged
121 * with one of the tags of the specified screen.
122 * \param c The client to check.
123 * \param screen Virtual screen number.
124 * \return true if the client is visible, false otherwise.
126 bool
127 client_maybevisible(client_t *c, int screen)
129 if(c->screen == screen)
131 if(c->issticky || c->type == WINDOW_TYPE_DESKTOP)
132 return true;
134 tag_array_t *tags = &globalconf.screens[screen].tags;
136 for(int i = 0; i < tags->len; i++)
137 if(tags->tab[i]->selected && is_client_tagged(c, tags->tab[i]))
138 return true;
140 return false;
143 /** Get a client by its window.
144 * \param w The client window to find.
145 * \return A client pointer if found, NULL otherwise.
147 client_t *
148 client_getbywin(xcb_window_t w)
150 client_t *c;
151 for(c = globalconf.clients; c && c->win != w; c = c->next);
152 return c;
155 /** Unfocus a client.
156 * \param c The client.
158 static void
159 client_unfocus(client_t *c)
161 globalconf.screens[c->phys_screen].client_focus = NULL;
163 /* Call hook */
164 luaA_client_userdata_new(globalconf.L, c);
165 luaA_dofunction(globalconf.L, globalconf.hooks.unfocus, 1, 0);
167 ewmh_update_net_active_window(c->phys_screen);
170 /** Ban client and unmap it.
171 * \param c The client.
173 void
174 client_ban(client_t *c)
176 if(globalconf.screen_focus->client_focus == c)
177 client_unfocus(c);
178 xcb_unmap_window(globalconf.connection, c->win);
179 if(c->ishidden)
180 window_state_set(c->win, XCB_WM_STATE_ICONIC);
181 else
182 window_state_set(c->win, XCB_WM_STATE_WITHDRAWN);
183 if(c->titlebar)
184 xcb_unmap_window(globalconf.connection, c->titlebar->sw.window);
187 /** Give focus to client, or to first client if client is NULL.
188 * \param c The client or NULL.
189 * \return True if a window (even root) has received focus, false otherwise.
191 static void
192 client_focus(client_t *c)
194 if(!client_maybevisible(c, c->screen) || c->nofocus)
195 return;
197 /* unfocus current selected client */
198 if(globalconf.screen_focus->client_focus
199 && c != globalconf.screen_focus->client_focus)
200 client_unfocus(globalconf.screen_focus->client_focus);
202 /* stop hiding c */
203 c->ishidden = false;
204 client_setminimized(c, false);
206 /* unban the client before focusing or it will fail */
207 client_unban(c);
209 globalconf.screen_focus = &globalconf.screens[c->phys_screen];
210 globalconf.screen_focus->client_focus = c;
212 xcb_set_input_focus(globalconf.connection, XCB_INPUT_FOCUS_POINTER_ROOT,
213 c->win, XCB_CURRENT_TIME);
215 /* Some layouts use focused client differently, so call them back.
216 * And anyway, we have maybe unhidden */
217 client_need_arrange(c);
219 /* execute hook */
220 luaA_client_userdata_new(globalconf.L, globalconf.screen_focus->client_focus);
221 luaA_dofunction(globalconf.L, globalconf.hooks.focus, 1, 0);
223 ewmh_update_net_active_window(c->phys_screen);
226 /** Stack a window below.
227 * \param c The client.
228 * \param previous The previous window on the stack.
229 * \param return The next-previous!
231 static xcb_window_t
232 client_stack_above(client_t *c, xcb_window_t previous)
234 uint32_t config_win_vals[2];
236 config_win_vals[0] = previous;
237 config_win_vals[1] = XCB_STACK_MODE_ABOVE;
239 if(c->titlebar)
241 xcb_configure_window(globalconf.connection,
242 c->titlebar->sw.window,
243 XCB_CONFIG_WINDOW_SIBLING | XCB_CONFIG_WINDOW_STACK_MODE,
244 config_win_vals);
245 config_win_vals[0] = c->titlebar->sw.window;
248 xcb_configure_window(globalconf.connection, c->win,
249 XCB_CONFIG_WINDOW_SIBLING | XCB_CONFIG_WINDOW_STACK_MODE,
250 config_win_vals);
252 previous = c->win;
254 /* stack transient window on top of their parents */
255 for(client_node_t *node = *client_node_list_last(&globalconf.stack);
256 node; node = node->prev)
257 if(node->client->transient_for == c)
259 client_stack_above(node->client,
260 previous);
261 previous = node->client->win;
264 return previous;
267 /** Stacking layout layers */
268 typedef enum
270 /** This one is a special layer */
271 LAYER_IGNORE,
272 LAYER_DESKTOP,
273 LAYER_BELOW,
274 LAYER_TILE,
275 LAYER_FLOAT,
276 LAYER_ABOVE,
277 LAYER_FULLSCREEN,
278 LAYER_ONTOP,
279 LAYER_OUTOFSPACE
280 } layer_t;
282 /** Get the real layer of a client according to its attribute (fullscreen, …)
283 * \param c The client.
284 * \return The real layer.
286 static layer_t
287 client_layer_translator(client_t *c)
289 /* first deal with user set attributes */
290 if(c->isontop)
291 return LAYER_ONTOP;
292 else if(c->isfullscreen)
293 return LAYER_FULLSCREEN;
294 else if(c->isabove)
295 return LAYER_ABOVE;
296 else if(c->isbelow)
297 return LAYER_BELOW;
298 else if(c->isfloating)
299 return LAYER_FLOAT;
301 /* check for transient attr */
302 if(c->transient_for)
303 return LAYER_IGNORE;
305 /* then deal with windows type */
306 switch(c->type)
308 case WINDOW_TYPE_DOCK:
309 return LAYER_ABOVE;
310 case WINDOW_TYPE_DESKTOP:
311 return LAYER_DESKTOP;
312 case WINDOW_TYPE_DIALOG:
313 return LAYER_FLOAT;
314 default:
315 break;
318 if(client_isfixed(c))
319 return LAYER_FLOAT;
321 return LAYER_TILE;
324 /** Restack clients.
325 * \todo It might be worth stopping to restack everyone and only stack `c'
326 * relatively to the first matching in the list.
328 void
329 client_stack()
331 uint32_t config_win_vals[2];
332 client_node_t *node, *last = *client_node_list_last(&globalconf.stack);
333 layer_t layer;
334 int screen;
336 config_win_vals[0] = XCB_NONE;
337 config_win_vals[1] = XCB_STACK_MODE_ABOVE;
339 /* first stack not ontop wibox window */
340 for(screen = 0; screen < globalconf.nscreen; screen++)
341 for(int i = 0; i < globalconf.screens[screen].wiboxes.len; i++)
343 wibox_t *sb = globalconf.screens[screen].wiboxes.tab[i];
344 if(!sb->ontop)
346 xcb_configure_window(globalconf.connection,
347 sb->sw.window,
348 XCB_CONFIG_WINDOW_SIBLING | XCB_CONFIG_WINDOW_STACK_MODE,
349 config_win_vals);
350 config_win_vals[0] = sb->sw.window;
354 /* stack bottom layers */
355 for(layer = LAYER_DESKTOP; layer < LAYER_FULLSCREEN; layer++)
356 for(node = last; node; node = node->prev)
357 if(client_layer_translator(node->client) == layer)
358 config_win_vals[0] = client_stack_above(node->client,
359 config_win_vals[0]);
361 /* then stack ontop wibox window */
362 for(screen = 0; screen < globalconf.nscreen; screen++)
363 for(int i = 0; i < globalconf.screens[screen].wiboxes.len; i++)
365 wibox_t *sb = globalconf.screens[screen].wiboxes.tab[i];
366 if(sb->ontop)
368 xcb_configure_window(globalconf.connection,
369 sb->sw.window,
370 XCB_CONFIG_WINDOW_SIBLING | XCB_CONFIG_WINDOW_STACK_MODE,
371 config_win_vals);
372 config_win_vals[0] = sb->sw.window;
376 /* finally stack ontop and fullscreen windows */
377 for(layer = LAYER_FULLSCREEN; layer < LAYER_OUTOFSPACE; layer++)
378 for(node = last; node; node = node->prev)
379 if(client_layer_translator(node->client) == layer)
380 config_win_vals[0] = client_stack_above(node->client,
381 config_win_vals[0]);
384 /** Manage a new client.
385 * \param w The window.
386 * \param wgeom Window geometry.
387 * \param phys_screen Physical screen number.
388 * \param screen Virtual screen number where to manage client.
390 void
391 client_manage(xcb_window_t w, xcb_get_geometry_reply_t *wgeom, int phys_screen, int screen)
393 xcb_get_property_cookie_t ewmh_icon_cookie;
394 client_t *c;
395 image_t *icon;
396 const uint32_t select_input_val[] =
398 XCB_EVENT_MASK_STRUCTURE_NOTIFY
399 | XCB_EVENT_MASK_PROPERTY_CHANGE
400 | XCB_EVENT_MASK_ENTER_WINDOW
403 /* Send request to get NET_WM_ICON property as soon as possible... */
404 ewmh_icon_cookie = ewmh_window_icon_get_unchecked(w);
405 xcb_change_window_attributes(globalconf.connection, w, XCB_CW_EVENT_MASK, select_input_val);
407 if(systray_iskdedockapp(w))
409 systray_request_handle(w, phys_screen, NULL);
410 return;
413 c = p_new(client_t, 1);
415 c->screen = screen_getbycoord(screen, wgeom->x, wgeom->y);
417 c->phys_screen = phys_screen;
419 /* Initial values */
420 c->win = w;
421 c->geometry.x = c->f_geometry.x = c->m_geometry.x = wgeom->x;
422 c->geometry.y = c->f_geometry.y = c->m_geometry.y = wgeom->y;
423 c->geometry.width = c->f_geometry.width = c->m_geometry.width = wgeom->width;
424 c->geometry.height = c->f_geometry.height = c->m_geometry.height = wgeom->height;
425 client_setborder(c, wgeom->border_width);
426 if((icon = ewmh_window_icon_get_reply(ewmh_icon_cookie)))
427 c->icon = image_ref(&icon);
429 /* we honor size hints by default */
430 c->honorsizehints = true;
432 /* update hints */
433 property_update_wm_normal_hints(c, NULL);
434 property_update_wm_hints(c, NULL);
435 property_update_wm_transient_for(c, NULL);
437 if(c->transient_for)
438 screen = c->transient_for->screen;
440 /* Try to load props if any */
441 client_loadprops(c, &globalconf.screens[screen]);
444 /* Then check clients hints */
445 ewmh_client_check_hints(c);
447 /* move client to screen, but do not tag it for now */
448 screen_client_moveto(c, screen, false, true);
450 /* Check if client has been tagged by loading props, or maybe with its
451 * hints.
452 * If not, we tag it with current selected ones.
453 * This could be done on Lua side, but it's a sane behaviour. */
454 if(!c->issticky)
456 int i;
457 tag_array_t *tags = &globalconf.screens[screen].tags;
458 for(i = 0; i < tags->len; i++)
459 if(is_client_tagged(c, tags->tab[i]))
460 break;
462 /* if no tag, set current selected */
463 if(i == tags->len)
464 for(i = 0; i < tags->len; i++)
465 if(tags->tab[i]->selected)
466 tag_client(c, tags->tab[i]);
469 /* Push client in client list */
470 client_list_push(&globalconf.clients, client_ref(&c));
472 /* Push client in stack */
473 client_raise(c);
475 /* update window title */
476 property_update_wm_name(c);
477 property_update_wm_icon_name(c);
479 /* update strut */
480 ewmh_client_strut_update(c, NULL);
482 ewmh_update_net_client_list(c->phys_screen);
484 /* Call hook to notify list change */
485 luaA_dofunction(globalconf.L, globalconf.hooks.clients, 0, 0);
487 /* call hook */
488 luaA_client_userdata_new(globalconf.L, c);
489 luaA_dofunction(globalconf.L, globalconf.hooks.manage, 1, 0);
492 /** Compute client geometry with respect to its geometry hints.
493 * \param c The client.
494 * \param geometry The geometry that the client might receive.
495 * \return The geometry the client must take respecting its hints.
497 area_t
498 client_geometry_hints(client_t *c, area_t geometry)
500 double dx, dy, max, min, ratio;
502 if(c->minay > 0 && c->maxay > 0 && (geometry.height - c->baseh) > 0
503 && (geometry.width - c->basew) > 0)
505 dx = (double) (geometry.width - c->basew);
506 dy = (double) (geometry.height - c->baseh);
507 min = (double) (c->minax) / (double) (c->minay);
508 max = (double) (c->maxax) / (double) (c->maxay);
509 ratio = dx / dy;
510 if(max > 0 && min > 0 && ratio > 0)
512 if(ratio < min)
514 dy = (dx * min + dy) / (min * min + 1);
515 dx = dy * min;
516 geometry.width = (int) dx + c->basew;
517 geometry.height = (int) dy + c->baseh;
519 else if(ratio > max)
521 dy = (dx * min + dy) / (max * max + 1);
522 dx = dy * min;
523 geometry.width = (int) dx + c->basew;
524 geometry.height = (int) dy + c->baseh;
528 if(c->minw && geometry.width < c->minw)
529 geometry.width = c->minw;
530 if(c->minh && geometry.height < c->minh)
531 geometry.height = c->minh;
532 if(c->maxw && geometry.width > c->maxw)
533 geometry.width = c->maxw;
534 if(c->maxh && geometry.height > c->maxh)
535 geometry.height = c->maxh;
536 if(c->incw)
537 geometry.width -= (geometry.width - c->basew) % c->incw;
538 if(c->inch)
539 geometry.height -= (geometry.height - c->baseh) % c->inch;
541 return geometry;
544 /** Resize client window.
545 * \param c Client to resize.
546 * \param geometry New window geometry.
547 * \param hints Use size hints.
549 void
550 client_resize(client_t *c, area_t geometry, bool hints)
552 int new_screen;
553 area_t area;
554 layout_t *layout = layout_get_current(c->screen);
556 if(c->titlebar && !c->ismoving && !client_isfloating(c) && layout != layout_floating)
557 geometry = titlebar_geometry_remove(c->titlebar, c->border, geometry);
559 if(hints)
560 geometry = client_geometry_hints(c, geometry);
562 if(geometry.width <= 0 || geometry.height <= 0)
563 return;
565 /* offscreen appearance fixes */
566 area = display_area_get(c->phys_screen, NULL,
567 &globalconf.screens[c->screen].padding);
569 if(geometry.x > area.width)
570 geometry.x = area.width - geometry.width - 2 * c->border;
571 if(geometry.y > area.height)
572 geometry.y = area.height - geometry.height - 2 * c->border;
573 if(geometry.x + geometry.width + 2 * c->border < 0)
574 geometry.x = 0;
575 if(geometry.y + geometry.height + 2 * c->border < 0)
576 geometry.y = 0;
578 if(c->geometry.x != geometry.x
579 || c->geometry.y != geometry.y
580 || c->geometry.width != geometry.width
581 || c->geometry.height != geometry.height)
583 new_screen = screen_getbycoord(c->screen, geometry.x, geometry.y);
585 /* Values to configure a window is an array where values are
586 * stored according to 'value_mask' */
587 uint32_t values[4];
589 c->geometry.x = values[0] = geometry.x;
590 c->geometry.y = values[1] = geometry.y;
591 c->geometry.width = values[2] = geometry.width;
592 c->geometry.height = values[3] = geometry.height;
594 /* save the floating geometry if the window is floating but not
595 * maximized */
596 if(c->ismoving || client_isfloating(c)
597 || layout_get_current(new_screen) == layout_floating
598 || layout_get_current(c->screen) == layout_floating)
599 if(!c->isfullscreen)
600 c->f_geometry = geometry;
602 titlebar_update_geometry_floating(c);
604 xcb_configure_window(globalconf.connection, c->win,
605 XCB_CONFIG_WINDOW_X | XCB_CONFIG_WINDOW_Y
606 | XCB_CONFIG_WINDOW_WIDTH | XCB_CONFIG_WINDOW_HEIGHT,
607 values);
608 window_configure(c->win, geometry, c->border);
610 if(c->screen != new_screen)
611 screen_client_moveto(c, new_screen, true, false);
613 /* execute hook */
614 hooks_property(c, "geometry");
618 /** Set a clinet floating.
619 * \param c The client.
620 * \param floating Set floating, or not.
621 * \param layer Layer to put the floating window onto.
623 void
624 client_setfloating(client_t *c, bool floating)
626 if(c->isfloating != floating
627 && (c->type == WINDOW_TYPE_NORMAL))
629 if((c->isfloating = floating))
630 if(!c->isfullscreen)
631 client_resize(c, c->f_geometry, false);
632 client_need_arrange(c);
633 client_stack();
634 xcb_change_property(globalconf.connection,
635 XCB_PROP_MODE_REPLACE,
636 c->win, _AWESOME_FLOATING, CARDINAL, 8, 1,
637 &c->isfloating);
638 /* execute hook */
639 hooks_property(c, "floating");
643 /** Set a client minimized, or not.
644 * \param c The client.
645 * \param s Set or not the client minimized.
647 void
648 client_setminimized(client_t *c, bool s)
650 if(c->isminimized != s)
652 client_need_arrange(c);
653 c->isminimized = s;
654 client_need_arrange(c);
655 ewmh_client_update_hints(c);
656 /* execute hook */
657 hooks_property(c, "minimized");
661 /** Set a client sticky, or not.
662 * \param c The client.
663 * \param s Set or not the client sticky.
665 void
666 client_setsticky(client_t *c, bool s)
668 if(c->issticky != s)
670 client_need_arrange(c);
671 c->issticky = s;
672 client_need_arrange(c);
673 ewmh_client_update_hints(c);
674 hooks_property(c, "sticky");
678 /** Set a client fullscreen, or not.
679 * \param c The client.
680 * \param s Set or not the client fullscreen.
682 void
683 client_setfullscreen(client_t *c, bool s)
685 if(c->isfullscreen != s)
687 area_t geometry;
689 /* become fullscreen! */
690 if((c->isfullscreen = s))
692 geometry = screen_area_get(c->screen, NULL, NULL, false);
693 c->m_geometry = c->geometry;
694 c->oldborder = c->border;
695 client_setborder(c, 0);
697 else
699 geometry = c->m_geometry;
700 client_setborder(c, c->oldborder);
701 client_resize(c, c->m_geometry, false);
703 client_resize(c, geometry, false);
704 client_need_arrange(c);
705 client_stack();
706 xcb_change_property(globalconf.connection,
707 XCB_PROP_MODE_REPLACE,
708 c->win, _AWESOME_FULLSCREEN, CARDINAL, 8, 1,
709 &c->isfullscreen);
710 ewmh_client_update_hints(c);
711 hooks_property(c, "fullscreen");
715 /** Set a client above, or not.
716 * \param c The client.
717 * \param s Set or not the client above.
719 void
720 client_setabove(client_t *c, bool s)
722 if(c->isabove != s)
724 c->isabove = s;
725 client_stack();
726 ewmh_client_update_hints(c);
727 /* execute hook */
728 hooks_property(c, "above");
732 /** Set a client below, or not.
733 * \param c The client.
734 * \param s Set or not the client below.
736 void
737 client_setbelow(client_t *c, bool s)
739 if(c->isbelow != s)
741 c->isbelow = s;
742 client_stack();
743 ewmh_client_update_hints(c);
744 /* execute hook */
745 hooks_property(c, "below");
749 /** Set a client modal, or not.
750 * \param c The client.
751 * \param s Set or not the client moda.
753 void
754 client_setmodal(client_t *c, bool s)
756 if(c->ismodal != s)
758 c->ismodal = s;
759 client_stack();
760 ewmh_client_update_hints(c);
761 /* execute hook */
762 hooks_property(c, "modal");
766 /** Set a client ontop, or not.
767 * \param c The client.
768 * \param s Set or not the client moda.
770 void
771 client_setontop(client_t *c, bool s)
773 if(c->isontop != s)
775 c->isontop = s;
776 client_stack();
777 /* execute hook */
778 hooks_property(c, "ontop");
782 /** Save client properties as an X property.
783 * \param c The client.
785 void
786 client_saveprops_tags(client_t *c)
788 tag_array_t *tags = &globalconf.screens[c->screen].tags;
789 unsigned char *prop = p_alloca(unsigned char, tags->len + 1);
790 int i;
792 for(i = 0; i < tags->len; i++)
793 prop[i] = is_client_tagged(c, tags->tab[i]) ? '1' : '0';
795 xcb_change_property(globalconf.connection, XCB_PROP_MODE_REPLACE, c->win, _AWESOME_TAGS, STRING, 8, i, prop);
798 /** Unban a client.
799 * \param c The client.
801 void
802 client_unban(client_t *c)
804 xcb_map_window(globalconf.connection, c->win);
805 window_state_set(c->win, XCB_WM_STATE_NORMAL);
806 if(c->titlebar)
808 if(c->isfullscreen || !c->titlebar->isvisible)
809 xcb_unmap_window(globalconf.connection, c->titlebar->sw.window);
810 else
811 xcb_map_window(globalconf.connection, c->titlebar->sw.window);
815 /** Unmanage a client.
816 * \param c The client.
818 void
819 client_unmanage(client_t *c)
821 tag_array_t *tags = &globalconf.screens[c->screen].tags;
823 if(globalconf.screens[c->phys_screen].client_focus == c)
824 client_unfocus(c);
826 /* remove client everywhere */
827 client_list_detach(&globalconf.clients, c);
828 stack_client_delete(c);
829 for(int i = 0; i < tags->len; i++)
830 untag_client(c, tags->tab[i]);
832 /* call hook */
833 luaA_client_userdata_new(globalconf.L, c);
834 luaA_dofunction(globalconf.L, globalconf.hooks.unmanage, 1, 0);
836 /* Call hook to notify list change */
837 luaA_dofunction(globalconf.L, globalconf.hooks.clients, 0, 0);
839 /* The server grab construct avoids race conditions. */
840 xcb_grab_server(globalconf.connection);
842 xcb_configure_window(globalconf.connection, c->win,
843 XCB_CONFIG_WINDOW_BORDER_WIDTH,
844 (uint32_t *) &c->oldborder);
846 xcb_ungrab_button(globalconf.connection, XCB_BUTTON_INDEX_ANY, c->win,
847 XCB_BUTTON_MASK_ANY);
848 window_state_set(c->win, XCB_WM_STATE_WITHDRAWN);
850 xcb_flush(globalconf.connection);
851 xcb_ungrab_server(globalconf.connection);
853 titlebar_client_detach(c);
855 ewmh_update_net_client_list(c->phys_screen);
857 /* delete properties */
858 xcb_delete_property(globalconf.connection, c->win, _AWESOME_TAGS);
859 xcb_delete_property(globalconf.connection, c->win, _AWESOME_FLOATING);
861 if(client_hasstrut(c))
862 /* All the wiboxes (may) need to be repositioned */
863 for(int screen = 0; screen < globalconf.nscreen; screen++)
864 for(int i = 0; i < globalconf.screens[screen].wiboxes.len; i++)
866 wibox_t *s = globalconf.screens[screen].wiboxes.tab[i];
867 wibox_position_update(s);
870 /* set client as invalid */
871 c->invalid = true;
873 client_unref(&c);
876 /** Kill a client via a WM_DELETE_WINDOW request or KillClient if not
877 * supported.
878 * \param c The client to kill.
880 void
881 client_kill(client_t *c)
883 if(window_hasproto(c->win, WM_DELETE_WINDOW))
885 xcb_client_message_event_t ev;
887 /* Initialize all of event's fields first */
888 p_clear(&ev, 1);
890 ev.response_type = XCB_CLIENT_MESSAGE;
891 ev.window = c->win;
892 ev.format = 32;
893 ev.data.data32[1] = XCB_CURRENT_TIME;
894 ev.type = WM_PROTOCOLS;
895 ev.data.data32[0] = WM_DELETE_WINDOW;
897 xcb_send_event(globalconf.connection, false, c->win,
898 XCB_EVENT_MASK_NO_EVENT, (char *) &ev);
900 else
901 xcb_kill_client(globalconf.connection, c->win);
904 /** Get all clients into a table.
905 * \param L The Lua VM state.
906 * \return The number of elements pushed on stack.
907 * \luastack
908 * \lparam An optional screen nunmber.
909 * \lreturn A table with all clients.
911 static int
912 luaA_client_get(lua_State *L)
914 int i = 1, screen;
915 client_t *c;
917 screen = luaL_optnumber(L, 1, 0) - 1;
919 lua_newtable(L);
921 if(screen == SCREEN_UNDEF)
922 for(c = globalconf.clients; c; c = c->next)
924 luaA_client_userdata_new(globalconf.L, c);
925 lua_rawseti(L, -2, i++);
927 else
929 luaA_checkscreen(screen);
930 for(c = globalconf.clients; c; c = c->next)
931 if(c->screen == screen)
933 luaA_client_userdata_new(globalconf.L, c);
934 lua_rawseti(L, -2, i++);
938 return 1;
941 /** Get only visible clients for a screen (DEPRECATED).
942 * \param L The Lua VM state.
943 * \return The number of elements pushed on stack.
944 * \luastack
945 * \lparam A screen number.
946 * \lreturn A table with all visible clients for this screen.
948 static int
949 luaA_client_visible_get(lua_State *L)
951 int i = 1;
952 client_t *c;
953 int screen = luaL_checknumber(L, 1) - 1;
955 luaA_checkscreen(screen);
957 deprecate(L, "awful.client.visible()");
959 lua_newtable(L);
961 for(c = globalconf.clients; c; c = c->next)
962 if(client_isvisible(c, screen))
964 luaA_client_userdata_new(L, c);
965 lua_rawseti(L, -2, i++);
968 return 1;
971 /** Check if a client is visible on its screen.
972 * \param L The Lua VM state.
973 * \return The number of elements pushed on stack.
974 * \luastack
975 * \lvalue A client.
976 * \lreturn A boolean value, true if the client is visible, false otherwise.
978 static int
979 luaA_client_isvisible(lua_State *L)
981 client_t **c = luaA_checkudata(L, 1, "client");
982 lua_pushboolean(L, client_isvisible(*c, (*c)->screen));
983 return 1;
986 /** Set client border width.
987 * \param c The client.
988 * \param width The border width.
990 void
991 client_setborder(client_t *c, int width)
993 uint32_t w = width;
995 if(width > 0 && (c->type == WINDOW_TYPE_DOCK
996 || c->type == WINDOW_TYPE_SPLASH
997 || c->type == WINDOW_TYPE_DESKTOP
998 || c->isfullscreen))
999 return;
1001 if(width == c->border || width < 0)
1002 return;
1004 c->border = width;
1005 xcb_configure_window(globalconf.connection, c->win,
1006 XCB_CONFIG_WINDOW_BORDER_WIDTH, &w);
1008 if(client_isvisible(c, c->screen))
1010 if(client_isfloating(c) || layout_get_current(c->screen) == layout_floating)
1011 titlebar_update_geometry_floating(c);
1012 else
1013 globalconf.screens[c->screen].need_arrange = true;
1016 hooks_property(c, "border_width");
1019 /** Kill a client.
1020 * \param L The Lua VM state.
1022 * \luastack
1023 * \lvalue A client.
1025 static int
1026 luaA_client_kill(lua_State *L)
1028 client_t **c = luaA_checkudata(L, 1, "client");
1029 client_kill(*c);
1030 return 0;
1033 /** Swap a client with another one.
1034 * \param L The Lua VM state.
1035 * \luastack
1036 * \lvalue A client.
1037 * \lparam A client to swap with.
1039 static int
1040 luaA_client_swap(lua_State *L)
1042 client_t **c = luaA_checkudata(L, 1, "client");
1043 client_t **swap = luaA_checkudata(L, 2, "client");
1044 client_list_swap(&globalconf.clients, *swap, *c);
1045 client_need_arrange(*c);
1046 client_need_arrange(*swap);
1048 /* Call hook to notify list change */
1049 luaA_dofunction(L, globalconf.hooks.clients, 0, 0);
1051 return 0;
1054 /** Access or set the client tags.
1055 * \param L The Lua VM state.
1056 * \return The number of elements pushed on stack.
1057 * \lparam A table with tags to set, or none to get the current tags table.
1058 * \return The clients tag.
1060 static int
1061 luaA_client_tags(lua_State *L)
1063 tag_array_t *tags;
1064 tag_t **tag;
1065 client_t **c = luaA_checkudata(L, 1, "client");
1066 int j = 0;
1068 if(lua_gettop(L) == 2)
1070 luaA_checktable(L, 2);
1071 tags = &globalconf.screens[(*c)->screen].tags;
1072 for(int i = 0; i < tags->len; i++)
1073 untag_client(*c, tags->tab[i]);
1074 lua_pushnil(L);
1075 while(lua_next(L, 2))
1077 tag = luaA_checkudata(L, -1, "tag");
1078 tag_client(*c, *tag);
1079 lua_pop(L, 1);
1081 lua_pop(L, 1);
1084 tags = &globalconf.screens[(*c)->screen].tags;
1085 luaA_otable_new(L);
1086 for(int i = 0; i < tags->len; i++)
1087 if(is_client_tagged(*c, tags->tab[i]))
1089 luaA_tag_userdata_new(L, tags->tab[i]);
1090 lua_rawseti(L, -2, ++j);
1093 return 1;
1096 /** Raise a client on top of others which are on the same layer.
1097 * \param L The Lua VM state.
1098 * \luastack
1099 * \lvalue A client.
1101 static int
1102 luaA_client_raise(lua_State *L)
1104 client_t **c = luaA_checkudata(L, 1, "client");
1105 client_raise(*c);
1106 return 0;
1109 /** Lower a client on bottom of others which are on the same layer.
1110 * \param L The Lua VM state.
1111 * \luastack
1112 * \lvalue A client.
1114 static int
1115 luaA_client_lower(lua_State *L)
1117 client_t **c = luaA_checkudata(L, 1, "client");
1118 client_lower(*c);
1119 return 0;
1122 /** Redraw a client by unmapping and mapping it quickly.
1123 * \param L The Lua VM state.
1125 * \luastack
1126 * \lvalue A client.
1128 static int
1129 luaA_client_redraw(lua_State *L)
1131 client_t **c = luaA_checkudata(L, 1, "client");
1133 xcb_unmap_window(globalconf.connection, (*c)->win);
1134 xcb_map_window(globalconf.connection, (*c)->win);
1136 /* Set the focus on the current window if the redraw has been
1137 performed on the window where the pointer is currently on
1138 because after the unmapping/mapping, the focus is lost */
1139 if(globalconf.screen_focus->client_focus == *c)
1140 xcb_set_input_focus(globalconf.connection, XCB_INPUT_FOCUS_POINTER_ROOT,
1141 (*c)->win, XCB_CURRENT_TIME);
1143 return 0;
1146 /** Stop managing a client.
1147 * \param L The Lua VM state.
1148 * \return The number of elements pushed on stack.
1149 * \luastack
1150 * \lvalue A client.
1152 static int
1153 luaA_client_unmanage(lua_State *L)
1155 client_t **c = luaA_checkudata(L, 1, "client");
1156 client_unmanage(*c);
1157 return 0;
1160 /** Return client geometry.
1161 * \param L The Lua VM state.
1162 * \param full Use titlebar also.
1163 * \return The number of elements pushed on stack.
1165 static int
1166 luaA_client_handlegeom(lua_State *L, bool full)
1168 client_t **c = luaA_checkudata(L, 1, "client");
1170 if(lua_gettop(L) == 2)
1171 if(client_isfloating(*c)
1172 || layout_get_current((*c)->screen) == layout_floating)
1174 area_t geometry;
1176 luaA_checktable(L, 2);
1177 geometry.x = luaA_getopt_number(L, 2, "x", (*c)->geometry.x);
1178 geometry.y = luaA_getopt_number(L, 2, "y", (*c)->geometry.y);
1179 if(client_isfixed(*c))
1181 geometry.width = (*c)->geometry.width;
1182 geometry.height = (*c)->geometry.height;
1184 else
1186 geometry.width = luaA_getopt_number(L, 2, "width", (*c)->geometry.width);
1187 geometry.height = luaA_getopt_number(L, 2, "height", (*c)->geometry.height);
1189 if(full)
1190 geometry = titlebar_geometry_remove((*c)->titlebar,
1191 (*c)->border,
1192 geometry);
1193 client_resize(*c, geometry, false);
1196 if(full)
1197 return luaA_pusharea(L, titlebar_geometry_add((*c)->titlebar,
1198 (*c)->border,
1199 (*c)->geometry));
1201 return luaA_pusharea(L, (*c)->geometry);
1204 /** Return client geometry.
1205 * \param L The Lua VM state.
1206 * \return The number of elements pushed on stack.
1207 * \luastack
1208 * \lparam A table with new coordinates, or none.
1209 * \lreturn A table with client coordinates.
1211 static int
1212 luaA_client_geometry(lua_State *L)
1214 return luaA_client_handlegeom(L, false);
1217 static int
1218 luaA_client_coords(lua_State *L)
1220 deprecate(L, "client:geometry()");
1221 return luaA_client_geometry(L);
1224 /** Return client geometry, using also titlebar and border width.
1225 * \param L The Lua VM state.
1226 * \return The number of elements pushed on stack.
1227 * \luastack
1228 * \lparam A table with new coordinates, or none.
1229 * \lreturn A table with client coordinates.
1231 static int
1232 luaA_client_fullgeometry(lua_State *L)
1234 return luaA_client_handlegeom(L, true);
1237 static int
1238 luaA_client_fullcoords(lua_State *L)
1240 deprecate(L, "client:fullgeometry()");
1241 return luaA_client_fullgeometry(L);
1244 /** Client newindex.
1245 * \param L The Lua VM state.
1246 * \return The number of elements pushed on stack.
1249 luaA_client_newindex(lua_State *L)
1251 size_t len;
1252 client_t **c = luaA_checkudata(L, 1, "client");
1253 const char *buf = luaL_checklstring(L, 2, &len);
1254 bool b;
1255 double d;
1256 int i;
1257 wibox_t **t = NULL;
1258 image_t **image;
1260 if((*c)->invalid)
1261 luaL_error(L, "client is invalid\n");
1263 switch(a_tokenize(buf, len))
1265 case A_TK_SCREEN:
1266 if(globalconf.xinerama_is_active)
1268 i = luaL_checknumber(L, 3) - 1;
1269 luaA_checkscreen(i);
1270 if(i != (*c)->screen)
1271 screen_client_moveto(*c, i, true, true);
1273 break;
1274 case A_TK_HIDE:
1275 b = luaA_checkboolean(L, 3);
1276 if(b != (*c)->ishidden)
1278 client_need_arrange(*c);
1279 (*c)->ishidden = b;
1280 client_need_arrange(*c);
1282 break;
1283 case A_TK_MINIMIZE:
1284 client_setminimized(*c, luaA_checkboolean(L, 3));
1285 break;
1286 case A_TK_FULLSCREEN:
1287 client_setfullscreen(*c, luaA_checkboolean(L, 3));
1288 break;
1289 case A_TK_ICON:
1290 image = luaA_checkudata(L, 3, "image");
1291 image_unref(&(*c)->icon);
1292 image_ref(image);
1293 (*c)->icon = *image;
1294 /* execute hook */
1295 hooks_property(*c, "icon");
1296 break;
1297 case A_TK_OPACITY:
1298 if(lua_isnil(L, 3))
1299 window_opacity_set((*c)->win, -1);
1300 else
1302 d = luaL_checknumber(L, 3);
1303 if(d >= 0 && d <= 1)
1304 window_opacity_set((*c)->win, d);
1306 break;
1307 case A_TK_FLOATING:
1308 client_setfloating(*c, luaA_checkboolean(L, 3));
1309 break;
1310 case A_TK_STICKY:
1311 client_setsticky(*c, luaA_checkboolean(L, 3));
1312 break;
1313 case A_TK_HONORSIZEHINTS:
1314 (*c)->honorsizehints = luaA_checkboolean(L, 3);
1315 client_need_arrange(*c);
1316 break;
1317 case A_TK_BORDER_WIDTH:
1318 client_setborder(*c, luaL_checknumber(L, 3));
1319 break;
1320 case A_TK_ONTOP:
1321 client_setontop(*c, luaA_checkboolean(L, 3));
1322 break;
1323 case A_TK_BORDER_COLOR:
1324 if((buf = luaL_checklstring(L, 3, &len))
1325 && xcolor_init_reply(xcolor_init_unchecked(&(*c)->border_color, buf, len)))
1326 xcb_change_window_attributes(globalconf.connection, (*c)->win,
1327 XCB_CW_BORDER_PIXEL, &(*c)->border_color.pixel);
1328 break;
1329 case A_TK_TITLEBAR:
1330 if(lua_isnil(L, 3))
1331 titlebar_client_detach(*c);
1332 else
1334 t = luaA_checkudata(L, 3, "wibox");
1335 titlebar_client_attach(*c, *t);
1337 break;
1338 default:
1339 return 0;
1342 return 0;
1345 /** Client object.
1346 * \param L The Lua VM state.
1347 * \return The number of elements pushed on stack.
1348 * \luastack
1349 * \lfield name The client title.
1350 * \lfield skip_taskbar True if the client does not want to be in taskbar.
1351 * \lfield type The window type (desktop, normal, dock, …).
1352 * \lfield class The client class.
1353 * \lfield instance The client instance.
1354 * \lfield pid The client PID, if available.
1355 * \lfield role The window role, if available.
1356 * \lfield machine The machine client is running on.
1357 * \lfield icon_name The client name when iconified.
1358 * \lfield screen Client screen number.
1359 * \lfield hide Define if the client must be hidden, i.e. never mapped,
1360 * invisible in taskbar.
1361 * \lfield minimize Define it the client must be iconify, i.e. only visible in
1362 * taskbar.
1363 * \lfield icon_path Path to the icon used to identify.
1364 * \lfield floating True always floating.
1365 * \lfield honorsizehints Honor size hints, i.e. respect size ratio.
1366 * \lfield border_width The client border width.
1367 * \lfield border_color The client border color.
1368 * \lfield titlebar The client titlebar.
1369 * \lfield urgent The client urgent state.
1370 * \lfield focus The focused client.
1371 * \lfield opacity The client opacity between 0 and 1.
1372 * \lfield ontop The client is on top of every other windows.
1373 * \lfield fullscreen The client is fullscreen or not.
1374 * \lfield transient_for Return the client the window is transient for.
1375 * \lfield size_hints A table with size hints of the client: user_position,
1376 * user_size, program_position and program_size.
1378 static int
1379 luaA_client_index(lua_State *L)
1381 size_t len;
1382 ssize_t slen;
1383 client_t **c = luaA_checkudata(L, 1, "client");
1384 const char *buf = luaL_checklstring(L, 2, &len);
1385 char *value;
1386 void *data;
1387 xcb_get_wm_class_reply_t hint;
1388 xcb_get_property_cookie_t prop_c;
1389 xcb_get_property_reply_t *prop_r = NULL;
1390 double d;
1392 if((*c)->invalid)
1393 luaL_error(L, "client is invalid\n");
1395 if(luaA_usemetatable(L, 1, 2))
1396 return 1;
1398 switch(a_tokenize(buf, len))
1400 case A_TK_NAME:
1401 lua_pushstring(L, (*c)->name);
1402 break;
1403 case A_TK_TRANSIENT_FOR:
1404 if((*c)->transient_for)
1405 return luaA_client_userdata_new(L, (*c)->transient_for);
1406 case A_TK_SKIP_TASKBAR:
1407 lua_pushboolean(L, (*c)->skiptb);
1408 break;
1409 case A_TK_TYPE:
1410 switch((*c)->type)
1412 case WINDOW_TYPE_DESKTOP:
1413 lua_pushliteral(L, "desktop");
1414 break;
1415 case WINDOW_TYPE_DOCK:
1416 lua_pushliteral(L, "dock");
1417 break;
1418 case WINDOW_TYPE_SPLASH:
1419 lua_pushliteral(L, "splash");
1420 break;
1421 case WINDOW_TYPE_DIALOG:
1422 lua_pushliteral(L, "dialog");
1423 break;
1424 default:
1425 lua_pushliteral(L, "normal");
1426 break;
1428 break;
1429 case A_TK_CLASS:
1430 if(!xcb_get_wm_class_reply(globalconf.connection,
1431 xcb_get_wm_class_unchecked(globalconf.connection, (*c)->win),
1432 &hint, NULL))
1433 return 0;
1434 lua_pushstring(L, hint.class);
1435 xcb_get_wm_class_reply_wipe(&hint);
1436 break;
1437 case A_TK_INSTANCE:
1438 if(!xcb_get_wm_class_reply(globalconf.connection,
1439 xcb_get_wm_class_unchecked(globalconf.connection, (*c)->win),
1440 &hint, NULL))
1441 return 0;
1442 lua_pushstring(L, hint.name);
1443 xcb_get_wm_class_reply_wipe(&hint);
1444 break;
1445 case A_TK_ROLE:
1446 if(!xutil_text_prop_get(globalconf.connection, (*c)->win,
1447 WM_WINDOW_ROLE, &value, &slen))
1448 return 0;
1449 lua_pushlstring(L, value, slen);
1450 p_delete(&value);
1451 break;
1452 case A_TK_PID:
1453 prop_c = xcb_get_property_unchecked(globalconf.connection, false, (*c)->win, _NET_WM_PID, CARDINAL, 0L, 1L);
1454 prop_r = xcb_get_property_reply(globalconf.connection, prop_c, NULL);
1456 if(prop_r && prop_r->value_len && (data = xcb_get_property_value(prop_r)))
1457 lua_pushnumber(L, *(uint32_t *)data);
1458 else
1460 p_delete(&prop_r);
1461 return 0;
1463 break;
1464 case A_TK_MACHINE:
1465 if(!xutil_text_prop_get(globalconf.connection, (*c)->win,
1466 WM_CLIENT_MACHINE, &value, &slen))
1467 return 0;
1468 lua_pushlstring(L, value, slen);
1469 p_delete(&value);
1470 break;
1471 case A_TK_ICON_NAME:
1472 lua_pushstring(L, (*c)->icon_name);
1473 break;
1474 case A_TK_SCREEN:
1475 lua_pushnumber(L, 1 + (*c)->screen);
1476 break;
1477 case A_TK_HIDE:
1478 lua_pushboolean(L, (*c)->ishidden);
1479 break;
1480 case A_TK_MINIMIZE:
1481 lua_pushboolean(L, (*c)->isminimized);
1482 break;
1483 case A_TK_FULLSCREEN:
1484 lua_pushboolean(L, (*c)->isfullscreen);
1485 break;
1486 case A_TK_ICON:
1487 if((*c)->icon)
1488 luaA_image_userdata_new(L, (*c)->icon);
1489 else
1490 return 0;
1491 break;
1492 case A_TK_OPACITY:
1493 if((d = window_opacity_get((*c)->win)) >= 0)
1494 lua_pushnumber(L, d);
1495 else
1496 return 0;
1497 break;
1498 case A_TK_FLOATING:
1499 lua_pushboolean(L, client_isfloating(*c));
1500 break;
1501 case A_TK_ONTOP:
1502 lua_pushboolean(L, (*c)->isontop);
1503 break;
1504 case A_TK_STICKY:
1505 lua_pushboolean(L, (*c)->issticky);
1506 break;
1507 case A_TK_HONORSIZEHINTS:
1508 lua_pushboolean(L, (*c)->honorsizehints);
1509 break;
1510 case A_TK_BORDER_WIDTH:
1511 lua_pushnumber(L, (*c)->border);
1512 break;
1513 case A_TK_BORDER_COLOR:
1514 luaA_pushcolor(L, &(*c)->border_color);
1515 break;
1516 case A_TK_TITLEBAR:
1517 if((*c)->titlebar)
1518 return luaA_wibox_userdata_new(L, (*c)->titlebar);
1519 return 0;
1520 case A_TK_URGENT:
1521 lua_pushboolean(L, (*c)->isurgent);
1522 break;
1523 case A_TK_SIZE_HINTS:
1524 lua_newtable(L);
1525 lua_pushboolean(L, (*c)->size_hints.flags & XCB_SIZE_HINT_US_POSITION);
1526 lua_setfield(L, -2, "user_position");
1527 lua_pushboolean(L, (*c)->size_hints.flags & XCB_SIZE_HINT_US_SIZE);
1528 lua_setfield(L, -2, "user_size");
1529 lua_pushboolean(L, (*c)->size_hints.flags & XCB_SIZE_HINT_P_POSITION);
1530 lua_setfield(L, -2, "program_position");
1531 lua_pushboolean(L, (*c)->size_hints.flags & XCB_SIZE_HINT_P_SIZE);
1532 lua_setfield(L, -2, "program_size");
1533 break;
1534 default:
1535 return 0;
1538 return 1;
1541 /** Get or set mouse buttons bindings for a client.
1542 * \param L The Lua VM state.
1543 * \return The number of element pushed on stack.
1544 * \luastack
1545 * \lvalue A client.
1546 * \lparam An array of mouse button bindings objects, or nothing.
1547 * \return The array of mouse button bindings objects of this client.
1549 static int
1550 luaA_client_buttons(lua_State *L)
1552 client_t **client = luaA_checkudata(L, 1, "client");
1553 button_array_t *buttons = &(*client)->buttons;
1555 if(lua_gettop(L) == 2)
1556 luaA_button_array_set(L, 2, buttons);
1558 return luaA_button_array_get(L, buttons);
1561 /* Client module.
1562 * \param L The Lua VM state.
1563 * \return The number of pushed elements.
1565 static int
1566 luaA_client_module_index(lua_State *L)
1568 size_t len;
1569 const char *buf = luaL_checklstring(L, 2, &len);
1571 switch(a_tokenize(buf, len))
1573 case A_TK_FOCUS:
1574 if(globalconf.screen_focus->client_focus)
1575 luaA_client_userdata_new(L, globalconf.screen_focus->client_focus);
1576 else
1577 return 0;
1578 break;
1579 default:
1580 return 0;
1583 return 1;
1586 /* Client module new index.
1587 * \param L The Lua VM state.
1588 * \return The number of pushed elements.
1590 static int
1591 luaA_client_module_newindex(lua_State *L)
1593 size_t len;
1594 const char *buf = luaL_checklstring(L, 2, &len);
1595 client_t **c;
1597 switch(a_tokenize(buf, len))
1599 case A_TK_FOCUS:
1600 c = luaA_checkudata(L, 3, "client");
1601 client_focus(*c);
1602 break;
1603 default:
1604 break;
1607 return 0;
1610 const struct luaL_reg awesome_client_methods[] =
1612 { "get", luaA_client_get },
1613 { "visible_get", luaA_client_visible_get },
1614 { "__index", luaA_client_module_index },
1615 { "__newindex", luaA_client_module_newindex },
1616 { NULL, NULL }
1618 const struct luaL_reg awesome_client_meta[] =
1620 { "isvisible", luaA_client_isvisible },
1621 { "geometry", luaA_client_geometry },
1622 { "fullgeometry", luaA_client_fullgeometry },
1623 { "buttons", luaA_client_buttons },
1624 { "tags", luaA_client_tags },
1625 { "kill", luaA_client_kill },
1626 { "swap", luaA_client_swap },
1627 { "raise", luaA_client_raise },
1628 { "lower", luaA_client_lower },
1629 { "redraw", luaA_client_redraw },
1630 { "mouse_resize", luaA_client_mouse_resize },
1631 { "mouse_move", luaA_client_mouse_move },
1632 { "unmanage", luaA_client_unmanage },
1633 { "__index", luaA_client_index },
1634 { "__newindex", luaA_client_newindex },
1635 { "__eq", luaA_client_eq },
1636 { "__gc", luaA_client_gc },
1637 { "__tostring", luaA_client_tostring },
1638 /* deprecated */
1639 { "coords", luaA_client_coords },
1640 { "fullcoords", luaA_client_fullcoords },
1641 { NULL, NULL }
1644 // vim: filetype=c:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=80