Update the tasklist when a client's icon changes
[awesome.git] / wibox.c
blobe72690fd48634c9f4ef215cd7abd84426e462c64
1 /*
2 * wibox.c - wibox functions
4 * Copyright © 2008-2009 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/shape.h>
24 #include "screen.h"
25 #include "wibox.h"
26 #include "titlebar.h"
27 #include "client.h"
28 #include "screen.h"
29 #include "window.h"
30 #include "luaa.h"
31 #include "ewmh.h"
32 #include "common/xcursor.h"
33 #include "common/xutil.h"
35 LUA_OBJECT_FUNCS(wibox_class, wibox_t, wibox)
37 /** Take care of garbage collecting a wibox.
38 * \param L The Lua VM state.
39 * \return The number of elements pushed on stack, 0!
41 static int
42 luaA_wibox_gc(lua_State *L)
44 wibox_t *wibox = luaA_checkudata(L, 1, &wibox_class);
45 p_delete(&wibox->cursor);
46 wibox_wipe(wibox);
47 button_array_wipe(&wibox->buttons);
48 widget_node_array_wipe(&wibox->widgets);
49 return luaA_object_gc(L);
52 /** Wipe an array of widget_node. Release references to widgets.
53 * \param L The Lua VM state.
54 * \param idx The index of the wibox on the stack.
56 void
57 wibox_widget_node_array_wipe(lua_State *L, int idx)
59 wibox_t *wibox = luaA_checkudata(L, idx, &wibox_class);
60 foreach(widget_node, wibox->widgets)
61 luaA_object_unref_item(globalconf.L, idx, widget_node);
62 widget_node_array_wipe(&wibox->widgets);
66 void
67 wibox_unref_simplified(wibox_t **item)
69 luaA_object_unref(globalconf.L, *item);
72 static void
73 wibox_need_update(wibox_t *wibox)
75 wibox->need_update = true;
76 wibox_clear_mouse_over(wibox);
79 static int
80 have_shape(void)
82 const xcb_query_extension_reply_t *reply;
84 reply = xcb_get_extension_data(globalconf.connection, &xcb_shape_id);
85 if (!reply || !reply->present)
86 return 0;
88 /* We don't need a specific version of SHAPE, no version check required */
89 return 1;
92 static void
93 shape_update(xcb_window_t win, xcb_shape_kind_t kind, image_t *image, int offset)
95 xcb_pixmap_t shape;
97 if(image)
98 shape = image_to_1bit_pixmap(image, win);
99 else
100 /* Reset the shape */
101 shape = XCB_NONE;
103 xcb_shape_mask(globalconf.connection, XCB_SHAPE_SO_SET, kind,
104 win, offset, offset, shape);
106 if (shape != XCB_NONE)
107 xcb_free_pixmap(globalconf.connection, shape);
110 /** Update the window's shape.
111 * \param wibox The simple window whose shape should be updated.
113 static void
114 wibox_shape_update(wibox_t *wibox)
116 if(wibox->window == XCB_NONE)
117 return;
119 if(!have_shape())
121 static bool warned = false;
122 if(!warned)
123 warn("The X server doesn't have the SHAPE extension; "
124 "can't change window's shape");
125 warned = true;
126 return;
129 shape_update(wibox->window, XCB_SHAPE_SK_CLIP, wibox->shape.clip, 0);
130 shape_update(wibox->window, XCB_SHAPE_SK_BOUNDING, wibox->shape.bounding, - wibox->border_width);
132 wibox->need_shape_update = false;
135 static void
136 wibox_draw_context_update(wibox_t *w, xcb_screen_t *s)
138 xcolor_t fg = w->ctx.fg, bg = w->ctx.bg;
139 int phys_screen = w->ctx.phys_screen;
141 draw_context_wipe(&w->ctx);
143 /* update draw context */
144 switch(w->orientation)
146 case South:
147 case North:
148 /* we need a new pixmap this way [ ] to render */
149 w->ctx.pixmap = xcb_generate_id(globalconf.connection);
150 xcb_create_pixmap(globalconf.connection,
151 s->root_depth,
152 w->ctx.pixmap, s->root,
153 w->geometry.height,
154 w->geometry.width);
155 draw_context_init(&w->ctx, phys_screen,
156 w->geometry.height,
157 w->geometry.width,
158 w->ctx.pixmap, &fg, &bg);
159 break;
160 case East:
161 draw_context_init(&w->ctx, phys_screen,
162 w->geometry.width,
163 w->geometry.height,
164 w->pixmap, &fg, &bg);
165 break;
169 /** Initialize a wibox.
170 * \param w The wibox to initialize.
171 * \param phys_screen Physical screen number.
173 void
174 wibox_init(wibox_t *w, int phys_screen)
176 xcb_screen_t *s = xutil_screen_get(globalconf.connection, phys_screen);
178 w->window = xcb_generate_id(globalconf.connection);
179 xcb_create_window(globalconf.connection, s->root_depth, w->window, s->root,
180 w->geometry.x, w->geometry.y,
181 w->geometry.width, w->geometry.height,
182 w->border_width, XCB_COPY_FROM_PARENT, s->root_visual,
183 XCB_CW_BACK_PIXEL | XCB_CW_BORDER_PIXEL | XCB_CW_BIT_GRAVITY
184 | XCB_CW_OVERRIDE_REDIRECT | XCB_CW_EVENT_MASK,
185 (const uint32_t [])
187 w->ctx.bg.pixel,
188 w->border_color.pixel,
189 XCB_GRAVITY_NORTH_WEST,
191 XCB_EVENT_MASK_SUBSTRUCTURE_REDIRECT
192 | XCB_EVENT_MASK_SUBSTRUCTURE_NOTIFY | XCB_EVENT_MASK_ENTER_WINDOW
193 | XCB_EVENT_MASK_LEAVE_WINDOW | XCB_EVENT_MASK_STRUCTURE_NOTIFY
194 | XCB_EVENT_MASK_BUTTON_PRESS | XCB_EVENT_MASK_BUTTON_RELEASE
195 | XCB_EVENT_MASK_POINTER_MOTION | XCB_EVENT_MASK_EXPOSURE
196 | XCB_EVENT_MASK_PROPERTY_CHANGE
199 /* Create a pixmap. */
200 w->pixmap = xcb_generate_id(globalconf.connection);
201 xcb_create_pixmap(globalconf.connection, s->root_depth, w->pixmap, s->root,
202 w->geometry.width, w->geometry.height);
204 /* Update draw context physical screen, important for Zaphod. */
205 w->ctx.phys_screen = phys_screen;
206 wibox_draw_context_update(w, s);
208 /* The default GC is just a newly created associated to the root window */
209 w->gc = xcb_generate_id(globalconf.connection);
210 xcb_create_gc(globalconf.connection, w->gc, s->root, XCB_GC_FOREGROUND | XCB_GC_BACKGROUND,
211 (const uint32_t[]) { s->black_pixel, s->white_pixel });
213 wibox_shape_update(w);
216 /** Refresh the window content by copying its pixmap data to its window.
217 * \param w The wibox to refresh.
219 static inline void
220 wibox_refresh_pixmap(wibox_t *w)
222 wibox_refresh_pixmap_partial(w, 0, 0, w->geometry.width, w->geometry.height);
225 /** Move and/or resize a wibox
226 * \param L The Lua VM state.
227 * \param udx The index of the wibox.
228 * \param geometry The new geometry.
230 void
231 wibox_moveresize(lua_State *L, int udx, area_t geometry)
233 wibox_t *w = luaA_checkudata(L, udx, &wibox_class);
234 if(w->window)
236 int number_of_vals = 0;
237 uint32_t moveresize_win_vals[4], mask_vals = 0;
239 if(w->geometry.x != geometry.x)
241 w->geometry.x = moveresize_win_vals[number_of_vals++] = geometry.x;
242 mask_vals |= XCB_CONFIG_WINDOW_X;
245 if(w->geometry.y != geometry.y)
247 w->geometry.y = moveresize_win_vals[number_of_vals++] = geometry.y;
248 mask_vals |= XCB_CONFIG_WINDOW_Y;
251 if(geometry.width > 0 && w->geometry.width != geometry.width)
253 w->geometry.width = moveresize_win_vals[number_of_vals++] = geometry.width;
254 mask_vals |= XCB_CONFIG_WINDOW_WIDTH;
257 if(geometry.height > 0 && w->geometry.height != geometry.height)
259 w->geometry.height = moveresize_win_vals[number_of_vals++] = geometry.height;
260 mask_vals |= XCB_CONFIG_WINDOW_HEIGHT;
263 if(mask_vals & (XCB_CONFIG_WINDOW_WIDTH | XCB_CONFIG_WINDOW_HEIGHT))
265 xcb_free_pixmap(globalconf.connection, w->pixmap);
266 /* orientation != East */
267 if(w->pixmap != w->ctx.pixmap)
268 xcb_free_pixmap(globalconf.connection, w->ctx.pixmap);
269 w->pixmap = xcb_generate_id(globalconf.connection);
270 xcb_screen_t *s = xutil_screen_get(globalconf.connection, w->ctx.phys_screen);
271 xcb_create_pixmap(globalconf.connection, s->root_depth, w->pixmap, s->root,
272 w->geometry.width, w->geometry.height);
273 wibox_draw_context_update(w, s);
276 /* Activate BMA */
277 client_ignore_enterleave_events();
279 if(mask_vals)
280 xcb_configure_window(globalconf.connection, w->window, mask_vals, moveresize_win_vals);
282 /* Deactivate BMA */
283 client_restore_enterleave_events();
285 w->screen = screen_getbycoord(w->screen, w->geometry.x, w->geometry.y);
287 if(mask_vals & XCB_CONFIG_WINDOW_X)
288 luaA_object_emit_signal(L, udx, "property::x", 0);
289 if(mask_vals & XCB_CONFIG_WINDOW_Y)
290 luaA_object_emit_signal(L, udx, "property::y", 0);
291 if(mask_vals & XCB_CONFIG_WINDOW_WIDTH)
292 luaA_object_emit_signal(L, udx, "property::width", 0);
293 if(mask_vals & XCB_CONFIG_WINDOW_HEIGHT)
294 luaA_object_emit_signal(L, udx, "property::height", 0);
296 else
298 #define DO_WIBOX_GEOMETRY_CHECK_AND_EMIT(prop) \
299 if(w->geometry.prop != geometry.prop) \
301 w->geometry.prop = geometry.prop; \
302 luaA_object_emit_signal(L, udx, "property::" #prop, 0); \
304 DO_WIBOX_GEOMETRY_CHECK_AND_EMIT(x)
305 DO_WIBOX_GEOMETRY_CHECK_AND_EMIT(y)
306 DO_WIBOX_GEOMETRY_CHECK_AND_EMIT(width)
307 DO_WIBOX_GEOMETRY_CHECK_AND_EMIT(height)
308 #undef DO_WIBOX_GEOMETRY_CHECK_AND_EMIT
311 wibox_need_update(w);
314 /** Refresh the window content by copying its pixmap data to its window.
315 * \param wibox The wibox to refresh.
316 * \param x The copy starting point x component.
317 * \param y The copy starting point y component.
318 * \param w The copy width from the x component.
319 * \param h The copy height from the y component.
321 void
322 wibox_refresh_pixmap_partial(wibox_t *wibox,
323 int16_t x, int16_t y,
324 uint16_t w, uint16_t h)
326 xcb_copy_area(globalconf.connection, wibox->pixmap,
327 wibox->window, wibox->gc, x, y, x, y,
328 w, h);
331 void
332 wibox_set_opacity(lua_State *L, int udx, double opacity)
334 wibox_t *w = luaA_checkudata(L, udx, &wibox_class);
335 if(w->opacity != opacity)
337 w->opacity = opacity;
338 if(w->window)
339 window_opacity_set(w->window, opacity);
340 luaA_object_emit_signal(L, udx, "property::opacity", 0);
344 /** Set a wibox border color.
345 * \param L The Lua VM state.
346 * \param udx The wibox to change border width.
347 * \param color The border color.
349 static void
350 wibox_set_border_color(lua_State *L, int udx, const xcolor_t *color)
352 wibox_t *w = luaA_checkudata(L, udx, &wibox_class);
353 if (w->window != XCB_NONE)
354 xcb_change_window_attributes(globalconf.connection, w->window,
355 XCB_CW_BORDER_PIXEL, &color->pixel);
356 w->border_color = *color;
357 luaA_object_emit_signal(L, udx, "property::border_color", 0);
360 /** Set wibox orientation.
361 * \param L The Lua VM state.
362 * \param udx The wibox to change orientation.
363 * \param o The new orientation.
365 void
366 wibox_set_orientation(lua_State *L, int udx, orientation_t o)
368 wibox_t *w = luaA_checkudata(L, udx, &wibox_class);
369 if(o != w->orientation)
371 xcb_screen_t *s = xutil_screen_get(globalconf.connection, w->ctx.phys_screen);
372 w->orientation = o;
373 /* orientation != East */
374 if(w->pixmap != w->ctx.pixmap)
375 xcb_free_pixmap(globalconf.connection, w->ctx.pixmap);
376 wibox_draw_context_update(w, s);
377 luaA_object_emit_signal(L, udx, "property::orientation", 0);
381 static void
382 wibox_map(wibox_t *wibox)
384 /* Activate BMA */
385 client_ignore_enterleave_events();
386 /* Map the wibox */
387 xcb_map_window(globalconf.connection, wibox->window);
388 /* Deactivate BMA */
389 client_restore_enterleave_events();
390 /* We must make sure the wibox does not display garbage */
391 wibox_need_update(wibox);
392 /* Stack this wibox correctly */
393 client_stack();
396 /** Kick out systray windows.
397 * \param phys_screen Physical screen number.
399 static void
400 wibox_systray_kickout(int phys_screen)
402 xcb_screen_t *s = xutil_screen_get(globalconf.connection, phys_screen);
404 if(globalconf.screens.tab[phys_screen].systray.parent != s->root)
406 /* Who! Check that we're not deleting a wibox with a systray, because it
407 * may be its parent. If so, we reparent to root before, otherwise it will
408 * hurt very much. */
409 xcb_reparent_window(globalconf.connection,
410 globalconf.screens.tab[phys_screen].systray.window,
411 s->root, -512, -512);
413 globalconf.screens.tab[phys_screen].systray.parent = s->root;
417 static void
418 wibox_systray_refresh(wibox_t *wibox)
420 if(!wibox->screen)
421 return;
423 for(int i = 0; i < wibox->widgets.len; i++)
425 widget_node_t *systray = &wibox->widgets.tab[i];
426 if(systray->widget->type == widget_systray)
428 uint32_t config_back[] = { wibox->ctx.bg.pixel };
429 uint32_t config_win_vals[4];
430 uint32_t config_win_vals_off[2] = { -512, -512 };
431 xembed_window_t *em;
432 int phys_screen = wibox->ctx.phys_screen;
434 if(wibox->visible
435 && systray->widget->isvisible
436 && systray->geometry.width)
438 /* Set background of the systray window. */
439 xcb_change_window_attributes(globalconf.connection,
440 globalconf.screens.tab[phys_screen].systray.window,
441 XCB_CW_BACK_PIXEL, config_back);
442 /* Map it. */
443 xcb_map_window(globalconf.connection, globalconf.screens.tab[phys_screen].systray.window);
444 /* Move it. */
445 switch(wibox->orientation)
447 case North:
448 config_win_vals[0] = systray->geometry.y;
449 config_win_vals[1] = wibox->geometry.height - systray->geometry.x - systray->geometry.width;
450 config_win_vals[2] = systray->geometry.height;
451 config_win_vals[3] = systray->geometry.width;
452 break;
453 case South:
454 config_win_vals[0] = systray->geometry.y;
455 config_win_vals[1] = systray->geometry.x;
456 config_win_vals[2] = systray->geometry.height;
457 config_win_vals[3] = systray->geometry.width;
458 break;
459 case East:
460 config_win_vals[0] = systray->geometry.x;
461 config_win_vals[1] = systray->geometry.y;
462 config_win_vals[2] = systray->geometry.width;
463 config_win_vals[3] = systray->geometry.height;
464 break;
466 /* reparent */
467 if(globalconf.screens.tab[phys_screen].systray.parent != wibox->window)
469 xcb_reparent_window(globalconf.connection,
470 globalconf.screens.tab[phys_screen].systray.window,
471 wibox->window,
472 config_win_vals[0], config_win_vals[1]);
473 globalconf.screens.tab[phys_screen].systray.parent = wibox->window;
475 xcb_configure_window(globalconf.connection,
476 globalconf.screens.tab[phys_screen].systray.window,
477 XCB_CONFIG_WINDOW_X
478 | XCB_CONFIG_WINDOW_Y
479 | XCB_CONFIG_WINDOW_WIDTH
480 | XCB_CONFIG_WINDOW_HEIGHT,
481 config_win_vals);
482 /* width = height = systray height */
483 config_win_vals[2] = config_win_vals[3] = systray->geometry.height;
484 config_win_vals[0] = 0;
486 else
487 return wibox_systray_kickout(phys_screen);
489 switch(wibox->orientation)
491 case North:
492 config_win_vals[1] = systray->geometry.width - config_win_vals[3];
493 for(int j = 0; j < globalconf.embedded.len; j++)
495 em = &globalconf.embedded.tab[j];
496 if(em->phys_screen == phys_screen)
498 if(config_win_vals[1] - config_win_vals[2] >= (uint32_t) wibox->geometry.y)
500 xcb_map_window(globalconf.connection, em->win);
501 xcb_configure_window(globalconf.connection, em->win,
502 XCB_CONFIG_WINDOW_X
503 | XCB_CONFIG_WINDOW_Y
504 | XCB_CONFIG_WINDOW_WIDTH
505 | XCB_CONFIG_WINDOW_HEIGHT,
506 config_win_vals);
507 config_win_vals[1] -= config_win_vals[3];
509 else
510 xcb_configure_window(globalconf.connection, em->win,
511 XCB_CONFIG_WINDOW_X
512 | XCB_CONFIG_WINDOW_Y,
513 config_win_vals_off);
516 break;
517 case South:
518 config_win_vals[1] = 0;
519 for(int j = 0; j < globalconf.embedded.len; j++)
521 em = &globalconf.embedded.tab[j];
522 if(em->phys_screen == phys_screen)
524 /* if(y + width <= wibox.y + systray.right) */
525 if(config_win_vals[1] + config_win_vals[3] <= (uint32_t) wibox->geometry.y + AREA_RIGHT(systray->geometry))
527 xcb_map_window(globalconf.connection, em->win);
528 xcb_configure_window(globalconf.connection, em->win,
529 XCB_CONFIG_WINDOW_X
530 | XCB_CONFIG_WINDOW_Y
531 | XCB_CONFIG_WINDOW_WIDTH
532 | XCB_CONFIG_WINDOW_HEIGHT,
533 config_win_vals);
534 config_win_vals[1] += config_win_vals[3];
536 else
537 xcb_configure_window(globalconf.connection, em->win,
538 XCB_CONFIG_WINDOW_X
539 | XCB_CONFIG_WINDOW_Y,
540 config_win_vals_off);
543 break;
544 case East:
545 config_win_vals[1] = 0;
546 for(int j = 0; j < globalconf.embedded.len; j++)
548 em = &globalconf.embedded.tab[j];
549 if(em->phys_screen == phys_screen)
551 /* if(x + width < systray.x + systray.width) */
552 if(config_win_vals[0] + config_win_vals[2] <= (uint32_t) AREA_RIGHT(systray->geometry) + wibox->geometry.x)
554 xcb_map_window(globalconf.connection, em->win);
555 xcb_configure_window(globalconf.connection, em->win,
556 XCB_CONFIG_WINDOW_X
557 | XCB_CONFIG_WINDOW_Y
558 | XCB_CONFIG_WINDOW_WIDTH
559 | XCB_CONFIG_WINDOW_HEIGHT,
560 config_win_vals);
561 config_win_vals[0] += config_win_vals[2];
563 else
564 xcb_configure_window(globalconf.connection, em->win,
565 XCB_CONFIG_WINDOW_X
566 | XCB_CONFIG_WINDOW_Y,
567 config_win_vals_off);
570 break;
572 break;
577 /** Get a wibox by its window.
578 * \param win The window id.
579 * \return A wibox if found, NULL otherwise.
581 wibox_t *
582 wibox_getbywin(xcb_window_t win)
584 foreach(w, globalconf.wiboxes)
585 if((*w)->window == win)
586 return *w;
588 foreach(_c, globalconf.clients)
590 client_t *c = *_c;
591 if(c->titlebar && c->titlebar->window == win)
592 return c->titlebar;
595 return NULL;
598 /** Draw a wibox.
599 * \param wibox The wibox to draw.
601 static void
602 wibox_draw(wibox_t *wibox)
604 if(wibox->visible)
606 widget_render(wibox);
607 wibox_refresh_pixmap(wibox);
609 wibox->need_update = false;
612 wibox_systray_refresh(wibox);
615 /** Refresh all wiboxes.
617 void
618 wibox_refresh(void)
620 foreach(w, globalconf.wiboxes)
622 if((*w)->need_shape_update)
623 wibox_shape_update(*w);
624 if((*w)->need_update)
625 wibox_draw(*w);
628 foreach(_c, globalconf.clients)
630 client_t *c = *_c;
631 if(c->titlebar && c->titlebar->need_update)
632 wibox_draw(c->titlebar);
636 /** Clear the wibox' mouse_over pointer.
637 * \param wibox The wibox.
639 void
640 wibox_clear_mouse_over(wibox_t *wibox)
642 if (wibox->mouse_over)
644 luaA_object_unref(globalconf.L, wibox->mouse_over);
645 wibox->mouse_over = NULL;
649 /** Set a wibox visible or not.
650 * \param L The Lua VM state.
651 * \param udx The wibox.
652 * \param v The visible value.
654 static void
655 wibox_set_visible(lua_State *L, int udx, bool v)
657 wibox_t *wibox = luaA_checkudata(L, udx, &wibox_class);
658 if(v != wibox->visible)
660 wibox->visible = v;
661 wibox_clear_mouse_over(wibox);
663 if(wibox->screen)
665 if(wibox->visible)
666 wibox_map(wibox);
667 else
669 /* Active BMA */
670 client_ignore_enterleave_events();
671 /* Unmap window */
672 xcb_unmap_window(globalconf.connection, wibox->window);
673 /* Active BMA */
674 client_restore_enterleave_events();
677 /* kick out systray if needed */
678 wibox_systray_refresh(wibox);
681 luaA_object_emit_signal(L, udx, "property::visible", 0);
683 hook_property(wibox, "visible");
687 /** Destroy all X resources of a wibox.
688 * \param w The wibox to wipe.
690 void
691 wibox_wipe(wibox_t *w)
693 if(w->window)
695 /* Activate BMA */
696 client_ignore_enterleave_events();
697 xcb_destroy_window(globalconf.connection, w->window);
698 /* Deactivate BMA */
699 client_restore_enterleave_events();
700 w->window = XCB_NONE;
702 if(w->pixmap)
704 xcb_free_pixmap(globalconf.connection, w->pixmap);
705 w->pixmap = XCB_NONE;
707 if(w->gc)
709 xcb_free_gc(globalconf.connection, w->gc);
710 w->gc = XCB_NONE;
712 draw_context_wipe(&w->ctx);
715 /** Remove a wibox from a screen.
716 * \param L The Lua VM state.
717 * \param udx Wibox to detach from screen.
719 static void
720 wibox_detach(lua_State *L, int udx)
722 wibox_t *wibox = luaA_checkudata(L, udx, &wibox_class);
723 if(wibox->screen)
725 bool v;
727 /* save visible state */
728 v = wibox->visible;
729 wibox->visible = false;
730 wibox_systray_refresh(wibox);
731 /* restore visibility */
732 wibox->visible = v;
734 wibox_clear_mouse_over(wibox);
736 wibox_wipe(wibox);
738 foreach(item, globalconf.wiboxes)
739 if(*item == wibox)
741 wibox_array_remove(&globalconf.wiboxes, item);
742 break;
745 hook_property(wibox, "screen");
747 if(strut_has_value(&wibox->strut))
748 screen_emit_signal(L, wibox->screen, "property::workarea", 0);
750 wibox->screen = NULL;
751 luaA_object_emit_signal(L, udx, "property::screen", 0);
753 luaA_object_unref(globalconf.L, wibox);
757 /** Attach a wibox that is on top of the stack.
758 * \param L The Lua VM state.
759 * \param udx The wibox to attach.
760 * \param s The screen to attach the wibox to.
762 static void
763 wibox_attach(lua_State *L, int udx, screen_t *s)
765 int phys_screen = screen_virttophys(screen_array_indexof(&globalconf.screens, s));
767 /* duplicate wibox */
768 lua_pushvalue(L, udx);
769 /* ref it */
770 wibox_t *wibox = luaA_object_ref_class(globalconf.L, -1, &wibox_class);
772 wibox_detach(L, udx);
774 /* Set the wibox screen */
775 wibox->screen = s;
777 /* Check that the wibox coordinates matches the screen. */
778 screen_t *cscreen =
779 screen_getbycoord(wibox->screen, wibox->geometry.x, wibox->geometry.y);
781 /* If it does not match, move it to the screen coordinates */
782 if(cscreen != wibox->screen)
783 wibox_moveresize(L, udx, (area_t) { .x = s->geometry.x,
784 .y = s->geometry.y,
785 .width = wibox->geometry.width,
786 .height = wibox->geometry.height });
788 wibox_array_append(&globalconf.wiboxes, wibox);
790 wibox_init(wibox, phys_screen);
792 window_set_cursor(wibox->window,
793 xcursor_new(globalconf.connection, xcursor_font_fromstr(wibox->cursor)));
795 if(wibox->opacity != -1)
796 window_opacity_set(wibox->window, wibox->opacity);
798 ewmh_update_strut(wibox->window, &wibox->strut);
800 if(wibox->visible)
801 wibox_map(wibox);
802 else
803 wibox_need_update(wibox);
805 hook_property(wibox, "screen");
806 luaA_object_emit_signal(L, udx, "property::screen", 0);
808 if(strut_has_value(&wibox->strut))
809 screen_emit_signal(L, wibox->screen, "property::workarea", 0);
812 /** Create a new wibox.
813 * \param L The Lua VM state.
815 * \luastack
816 * \lparam A table with optionally defined values:
817 * fg, bg, border_width, border_color, ontop, width and height.
818 * \lreturn A brand new wibox.
820 static int
821 luaA_wibox_new(lua_State *L)
823 luaA_class_new(L, &wibox_class);
825 wibox_t *w = luaA_checkudata(L, -1, &wibox_class);
827 if(!w->ctx.fg.initialized)
828 w->ctx.fg = globalconf.colors.fg;
830 if(!w->ctx.bg.initialized)
831 w->ctx.bg = globalconf.colors.bg;
833 if(!w->border_color.initialized)
834 w->border_color = globalconf.colors.bg;
836 w->visible = true;
838 if(!w->opacity)
839 w->opacity = -1;
841 if(!w->cursor)
842 w->cursor = a_strdup("left_ptr");
844 if(!w->geometry.width)
845 w->geometry.width = 1;
847 if(!w->geometry.height)
848 w->geometry.height = 1;
850 return 1;
853 /** Check if a wibox widget table has an item.
854 * \param L The Lua VM state.
855 * \param wibox The wibox.
856 * \param item The item to look for.
858 static bool
859 luaA_wibox_hasitem(lua_State *L, wibox_t *wibox, const void *item)
861 if(wibox->widgets_table)
863 luaA_object_push(L, wibox);
864 luaA_object_push_item(L, -1, wibox->widgets_table);
865 lua_remove(L, -2);
866 if(lua_topointer(L, -1) == item || luaA_hasitem(L, item))
867 return true;
869 return false;
872 /** Invalidate a wibox by a Lua object (table, etc).
873 * \param L The Lua VM state.
874 * \param item The object identifier.
876 void
877 luaA_wibox_invalidate_byitem(lua_State *L, const void *item)
879 foreach(w, globalconf.wiboxes)
881 wibox_t *wibox = *w;
882 if(luaA_wibox_hasitem(L, wibox, item))
884 /* update wibox */
885 wibox_need_update(wibox);
886 lua_pop(L, 1); /* remove widgets table */
891 foreach(_c, globalconf.clients)
893 client_t *c = *_c;
894 if(c->titlebar && luaA_wibox_hasitem(L, c->titlebar, item))
896 /* update wibox */
897 wibox_need_update(c->titlebar);
898 lua_pop(L, 1); /* remove widgets table */
903 /* Set or get the wibox geometry.
904 * \param L The Lua VM state.
905 * \return The number of elements pushed on stack.
906 * \luastack
907 * \lparam An optional table with wibox geometry.
908 * \lreturn The wibox geometry.
910 static int
911 luaA_wibox_geometry(lua_State *L)
913 wibox_t *wibox = luaA_checkudata(L, 1, &wibox_class);
915 if(lua_gettop(L) == 2)
917 area_t wingeom;
919 luaA_checktable(L, 2);
920 wingeom.x = luaA_getopt_number(L, 2, "x", wibox->geometry.x);
921 wingeom.y = luaA_getopt_number(L, 2, "y", wibox->geometry.y);
922 wingeom.width = luaA_getopt_number(L, 2, "width", wibox->geometry.width);
923 wingeom.height = luaA_getopt_number(L, 2, "height", wibox->geometry.height);
925 if(wingeom.width > 0 && wingeom.height > 0)
926 switch(wibox->type)
928 case WIBOX_TYPE_TITLEBAR:
929 wibox_moveresize(L, 1, (area_t) { .x = wibox->geometry.x,
930 .y = wibox->geometry.y,
931 .width = wingeom.width,
932 .height = wingeom.height });
933 break;
934 case WIBOX_TYPE_NORMAL:
935 wibox_moveresize(L, 1, wingeom);
936 break;
940 return luaA_pusharea(L, wibox->geometry);
943 static int
944 luaA_wibox_struts(lua_State *L)
946 wibox_t *w = luaA_checkudata(L, 1, &wibox_class);
948 if(lua_gettop(L) == 2)
950 luaA_tostrut(L, 2, &w->strut);
951 if(w->window)
952 ewmh_update_strut(w->window, &w->strut);
953 luaA_object_emit_signal(L, 1, "property::struts", 0);
954 if(w->screen)
955 screen_emit_signal(L, w->screen, "property::workarea", 0);
958 return luaA_pushstrut(L, w->strut);
961 LUA_OBJECT_EXPORT_PROPERTY(wibox, wibox_t, ontop, lua_pushboolean)
962 LUA_OBJECT_EXPORT_PROPERTY(wibox, wibox_t, cursor, lua_pushstring)
963 LUA_OBJECT_EXPORT_PROPERTY(wibox, wibox_t, visible, lua_pushboolean)
964 LUA_OBJECT_EXPORT_PROPERTY(wibox, wibox_t, border_width, lua_pushnumber)
965 LUA_OBJECT_EXPORT_PROPERTY(wibox, wibox_t, border_color, luaA_pushxcolor)
967 static int
968 luaA_wibox_set_x(lua_State *L, wibox_t *wibox)
970 wibox_moveresize(L, -3, (area_t) { .x = luaL_checknumber(L, -1),
971 .y = wibox->geometry.y,
972 .width = wibox->geometry.width,
973 .height = wibox->geometry.height });
974 return 0;
977 static int
978 luaA_wibox_get_x(lua_State *L, wibox_t *wibox)
980 lua_pushnumber(L, wibox->geometry.x);
981 return 1;
984 static int
985 luaA_wibox_set_y(lua_State *L, wibox_t *wibox)
987 wibox_moveresize(L, -3, (area_t) { .x = wibox->geometry.x,
988 .y = luaL_checknumber(L, -1),
989 .width = wibox->geometry.width,
990 .height = wibox->geometry.height });
991 return 0;
994 static int
995 luaA_wibox_get_y(lua_State *L, wibox_t *wibox)
997 lua_pushnumber(L, wibox->geometry.y);
998 return 1;
1001 static int
1002 luaA_wibox_set_width(lua_State *L, wibox_t *wibox)
1004 int width = luaL_checknumber(L, -1);
1005 if(width <= 0)
1006 luaL_error(L, "invalid width");
1007 wibox_moveresize(L, -3, (area_t) { .x = wibox->geometry.x,
1008 .y = wibox->geometry.y,
1009 .width = width,
1010 .height = wibox->geometry.height });
1011 return 0;
1014 static int
1015 luaA_wibox_get_width(lua_State *L, wibox_t *wibox)
1017 lua_pushnumber(L, wibox->geometry.width);
1018 return 1;
1021 static int
1022 luaA_wibox_set_height(lua_State *L, wibox_t *wibox)
1024 int height = luaL_checknumber(L, -1);
1025 if(height <= 0)
1026 luaL_error(L, "invalid height");
1027 wibox_moveresize(L, -3, (area_t) { .x = wibox->geometry.x,
1028 .y = wibox->geometry.y,
1029 .width = wibox->geometry.width,
1030 .height = height });
1031 return 0;
1034 static int
1035 luaA_wibox_get_height(lua_State *L, wibox_t *wibox)
1037 lua_pushnumber(L, wibox->geometry.height);
1038 return 1;
1041 /** Set the wibox foreground color.
1042 * \param L The Lua VM state.
1043 * \param wibox The wibox object.
1044 * \return The number of elements pushed on stack.
1046 static int
1047 luaA_wibox_set_fg(lua_State *L, wibox_t *wibox)
1049 size_t len;
1050 const char *buf = luaL_checklstring(L, -1, &len);
1051 if(xcolor_init_reply(xcolor_init_unchecked(&wibox->ctx.fg, buf, len)))
1052 wibox->need_update = true;
1053 luaA_object_emit_signal(L, -3, "property::fg", 0);
1054 return 0;
1057 /** Get the wibox foreground color.
1058 * \param L The Lua VM state.
1059 * \param wibox The wibox object.
1060 * \return The number of elements pushed on stack.
1062 static int
1063 luaA_wibox_get_fg(lua_State *L, wibox_t *wibox)
1065 return luaA_pushxcolor(L, wibox->ctx.fg);
1068 /** Set the wibox background color.
1069 * \param L The Lua VM state.
1070 * \param wibox The wibox object.
1071 * \return The number of elements pushed on stack.
1073 static int
1074 luaA_wibox_set_bg(lua_State *L, wibox_t *wibox)
1076 size_t len;
1077 const char *buf = luaL_checklstring(L, -1, &len);
1078 if(xcolor_init_reply(xcolor_init_unchecked(&wibox->ctx.bg, buf, len)))
1080 uint32_t mask = XCB_CW_BACK_PIXEL;
1081 uint32_t values[] = { wibox->ctx.bg.pixel };
1083 wibox->need_update = true;
1085 if (wibox->window != XCB_NONE)
1086 xcb_change_window_attributes(globalconf.connection,
1087 wibox->window,
1088 mask,
1089 values);
1091 luaA_object_emit_signal(L, -3, "property::bg", 0);
1092 return 0;
1095 /** Get the wibox background color.
1096 * \param L The Lua VM state.
1097 * \param wibox The wibox object.
1098 * \return The number of elements pushed on stack.
1100 static int
1101 luaA_wibox_get_bg(lua_State *L, wibox_t *wibox)
1103 return luaA_pushxcolor(L, wibox->ctx.bg);
1106 /** Set the wibox background image.
1107 * \param L The Lua VM state.
1108 * \param wibox The wibox object.
1109 * \return The number of elements pushed on stack.
1111 static int
1112 luaA_wibox_set_bg_image(lua_State *L, wibox_t *wibox)
1114 luaA_checkudata(L, -1, &image_class);
1115 luaA_object_unref_item(L, -3, wibox->bg_image);
1116 wibox->bg_image = luaA_object_ref_item(L, -3, -1);
1117 wibox->need_update = true;
1118 luaA_object_emit_signal(L, -2, "property::bg_image", 0);
1119 return 0;
1122 /** Get the wibox background image.
1123 * \param L The Lua VM state.
1124 * \param wibox The wibox object.
1125 * \return The number of elements pushed on stack.
1127 static int
1128 luaA_wibox_get_bg_image(lua_State *L, wibox_t *wibox)
1130 return luaA_object_push_item(L, 1, wibox->bg_image);
1133 /** Set the wibox on top status.
1134 * \param L The Lua VM state.
1135 * \param wibox The wibox object.
1136 * \return The number of elements pushed on stack.
1138 static int
1139 luaA_wibox_set_ontop(lua_State *L, wibox_t *wibox)
1141 bool b = luaA_checkboolean(L, -1);
1142 if(b != wibox->ontop)
1144 wibox->ontop = b;
1145 client_stack();
1146 luaA_object_emit_signal(L, -3, "property::ontop", 0);
1148 return 0;
1151 /** Set the wibox opacity.
1152 * \param L The Lua VM state.
1153 * \param wibox The wibox object.
1154 * \return The number of elements pushed on stack.
1156 static int
1157 luaA_wibox_set_opacity(lua_State *L, wibox_t *wibox)
1159 if(lua_isnil(L, -1))
1160 wibox_set_opacity(L, -3, -1);
1161 else
1163 double d = luaL_checknumber(L, -1);
1164 if(d >= 0 && d <= 1)
1165 wibox_set_opacity(L, -3, d);
1167 return 0;
1170 /** Get the wibox opacity.
1171 * \param L The Lua VM state.
1172 * \param wibox The wibox object.
1173 * \return The number of elements pushed on stack.
1175 static int
1176 luaA_wibox_get_opacity(lua_State *L, wibox_t *wibox)
1178 if (wibox->opacity >= 0)
1180 lua_pushnumber(L, wibox->opacity);
1181 return 1;
1183 return 0;
1186 /** Set the wibox alignment.
1187 * \param L The Lua VM state.
1188 * \param wibox The wibox object.
1189 * \return The number of elements pushed on stack.
1191 static int
1192 luaA_wibox_set_align(lua_State *L, wibox_t *wibox)
1194 size_t len;
1195 const char *buf = luaL_checklstring(L, -1, &len);
1196 wibox->align = draw_align_fromstr(buf, len);
1197 luaA_object_emit_signal(L, -3, "property::align", 0);
1198 switch(wibox->type)
1200 case WIBOX_TYPE_NORMAL:
1201 luaA_deprecate(L, "awful.wibox.align");
1202 break;
1203 case WIBOX_TYPE_TITLEBAR:
1204 titlebar_update_geometry(client_getbytitlebar(wibox));
1205 break;
1207 return 0;
1210 /** Get the wibox alignment.
1211 * \param L The Lua VM state.
1212 * \param wibox The wibox object.
1213 * \return The number of elements pushed on stack.
1215 static int
1216 luaA_wibox_get_align(lua_State *L, wibox_t *wibox)
1218 if(wibox->type == WIBOX_TYPE_NORMAL)
1219 luaA_deprecate(L, "awful.wibox.align");
1220 lua_pushstring(L, draw_align_tostr(wibox->align));
1221 return 1;
1224 /** Set the wibox position.
1225 * \param L The Lua VM state.
1226 * \param wibox The wibox object.
1227 * \return The number of elements pushed on stack.
1229 static int
1230 luaA_wibox_set_position(lua_State *L, wibox_t *wibox)
1232 switch(wibox->type)
1234 case WIBOX_TYPE_NORMAL:
1236 size_t len;
1237 const char *buf;
1238 if((buf = luaL_checklstring(L, -1, &len)))
1240 luaA_deprecate(L, "awful.wibox.attach");
1241 wibox->position = position_fromstr(buf, len);
1244 break;
1245 case WIBOX_TYPE_TITLEBAR:
1246 return luaA_titlebar_set_position(L, -3);
1248 return 0;
1251 /** Get the wibox position.
1252 * \param L The Lua VM state.
1253 * \param wibox The wibox object.
1254 * \return The number of elements pushed on stack.
1256 static int
1257 luaA_wibox_get_position(lua_State *L, wibox_t *wibox)
1259 if(wibox->type == WIBOX_TYPE_NORMAL)
1260 luaA_deprecate(L, "awful.wibox.attach");
1261 lua_pushstring(L, position_tostr(wibox->position));
1262 return 1;
1265 /** Set the wibox (titlebar) client.
1266 * \param L The Lua VM state.
1267 * \param wibox The wibox object.
1268 * \return The number of elements pushed on stack.
1270 static int
1271 luaA_wibox_set_client(lua_State *L, wibox_t *wibox)
1273 /* first detach */
1274 if(lua_isnil(L, -1))
1275 titlebar_client_detach(client_getbytitlebar(wibox));
1276 else
1278 client_t *c = luaA_client_checkudata(L, -1);
1279 lua_pushvalue(L, -3);
1280 titlebar_client_attach(c);
1282 return 0;
1285 /** Get the wibox (titlebar) client.
1286 * \param L The Lua VM state.
1287 * \param wibox The wibox object.
1288 * \return The number of elements pushed on stack.
1290 static int
1291 luaA_wibox_get_client(lua_State *L, wibox_t *wibox)
1293 return luaA_object_push(L, client_getbytitlebar(wibox));
1296 /** Set the wibox cursor.
1297 * \param L The Lua VM state.
1298 * \param wibox The wibox object.
1299 * \return The number of elements pushed on stack.
1301 static int
1302 luaA_wibox_set_cursor(lua_State *L, wibox_t *wibox)
1304 const char *buf = luaL_checkstring(L, -1);
1305 if(buf)
1307 uint16_t cursor_font = xcursor_font_fromstr(buf);
1308 if(cursor_font)
1310 xcb_cursor_t cursor = xcursor_new(globalconf.connection, cursor_font);
1311 p_delete(&wibox->cursor);
1312 wibox->cursor = a_strdup(buf);
1313 window_set_cursor(wibox->window, cursor);
1314 luaA_object_emit_signal(L, -3, "property::cursor", 0);
1317 return 0;
1320 /** Set the wibox screen.
1321 * \param L The Lua VM state.
1322 * \param wibox The wibox object.
1323 * \return The number of elements pushed on stack.
1325 static int
1326 luaA_wibox_set_screen(lua_State *L, wibox_t *wibox)
1328 if(lua_isnil(L, -1))
1330 wibox_detach(L, -3);
1331 titlebar_client_detach(client_getbytitlebar(wibox));
1333 else
1335 int screen = luaL_checknumber(L, -1) - 1;
1336 luaA_checkscreen(screen);
1337 if(!wibox->screen || screen != screen_array_indexof(&globalconf.screens, wibox->screen))
1339 titlebar_client_detach(client_getbytitlebar(wibox));
1340 wibox_attach(L, -3, &globalconf.screens.tab[screen]);
1343 return 0;
1346 /** Get the wibox screen.
1347 * \param L The Lua VM state.
1348 * \param wibox The wibox object.
1349 * \return The number of elements pushed on stack.
1351 static int
1352 luaA_wibox_get_screen(lua_State *L, wibox_t *wibox)
1354 if(!wibox->screen)
1355 return 0;
1356 lua_pushnumber(L, screen_array_indexof(&globalconf.screens, wibox->screen) + 1);
1357 return 1;
1360 /** Set the wibox orientation.
1361 * \param L The Lua VM state.
1362 * \param wibox The wibox object.
1363 * \return The number of elements pushed on stack.
1365 static int
1366 luaA_wibox_set_orientation(lua_State *L, wibox_t *wibox)
1368 size_t len;
1369 const char *buf = luaL_checklstring(L, -1, &len);
1370 if(buf)
1372 wibox_set_orientation(L, -3, orientation_fromstr(buf, len));
1373 wibox_need_update(wibox);
1375 return 0;
1378 /** Get the wibox orientation.
1379 * \param L The Lua VM state.
1380 * \param wibox The wibox object.
1381 * \return The number of elements pushed on stack.
1383 static int
1384 luaA_wibox_get_orientation(lua_State *L, wibox_t *wibox)
1386 lua_pushstring(L, orientation_tostr(wibox->orientation));
1387 return 1;
1390 /** Set the wibox border color.
1391 * \param L The Lua VM state.
1392 * \param wibox The wibox object.
1393 * \return The number of elements pushed on stack.
1395 static int
1396 luaA_wibox_set_border_color(lua_State *L, wibox_t *wibox)
1398 size_t len;
1399 const char *buf = luaL_checklstring(L, -1, &len);
1400 if(buf)
1401 if(xcolor_init_reply(xcolor_init_unchecked(&wibox->border_color, buf, len)))
1402 if(wibox->window)
1403 wibox_set_border_color(L, -3, &wibox->border_color);
1404 return 0;
1407 /** Set the wibox visibility.
1408 * \param L The Lua VM state.
1409 * \param wibox The wibox object.
1410 * \return The number of elements pushed on stack.
1412 static int
1413 luaA_wibox_set_visible(lua_State *L, wibox_t *wibox)
1415 bool b = luaA_checkboolean(L, -1);
1416 if(b != wibox->visible)
1417 switch(wibox->type)
1419 case WIBOX_TYPE_NORMAL:
1420 wibox_set_visible(L, -3, b);
1421 break;
1422 case WIBOX_TYPE_TITLEBAR:
1423 titlebar_set_visible(wibox, b);
1424 break;
1426 return 0;
1429 /** Set the wibox widgets.
1430 * \param L The Lua VM state.
1431 * \param wibox The wibox object.
1432 * \return The number of elements pushed on stack.
1434 static int
1435 luaA_wibox_set_widgets(lua_State *L, wibox_t *wibox)
1437 if(luaA_isloop(L, -1))
1439 luaA_warn(L, "table is looping, cannot use this as widget table");
1440 return 0;
1442 /* duplicate table because next function will eat it */
1443 lua_pushvalue(L, -1);
1444 wibox->widgets_table = luaA_object_ref_item(L, -4, -1);
1445 luaA_object_emit_signal(L, -3, "property::widgets", 0);
1446 wibox_need_update(wibox);
1447 luaA_table2wtable(L);
1448 return 0;
1451 /** Get the wibox widgets.
1452 * \param L The Lua VM state.
1453 * \param wibox The wibox object.
1454 * \return The number of elements pushed on stack.
1456 static int
1457 luaA_wibox_get_widgets(lua_State *L, wibox_t *wibox)
1459 return luaA_object_push_item(L, 1, wibox->widgets_table);
1462 /** Get or set mouse buttons bindings to a wibox.
1463 * \param L The Lua VM state.
1464 * \luastack
1465 * \lvalue A wibox.
1466 * \lparam An array of mouse button bindings objects, or nothing.
1467 * \return The array of mouse button bindings objects of this wibox.
1469 static int
1470 luaA_wibox_buttons(lua_State *L)
1472 wibox_t *wibox = luaA_checkudata(L, 1, &wibox_class);
1474 if(lua_gettop(L) == 2)
1476 luaA_button_array_set(L, 1, 2, &wibox->buttons);
1477 luaA_object_emit_signal(L, 1, "property::buttons", 0);
1480 return luaA_button_array_get(L, 1, &wibox->buttons);
1483 /** Set the wibox border width.
1484 * \param L The Lua VM state.
1485 * \param wibox The wibox object.
1486 * \return The number of elements pushed on stack.
1488 static int
1489 luaA_wibox_set_border_width(lua_State *L, wibox_t *wibox)
1491 wibox_t *w = luaA_checkudata(L, -3, &wibox_class);
1492 int32_t border_width = luaL_checknumber(L, -1);
1493 if(border_width != w->border_width && border_width >= 0)
1495 if (w->window != XCB_NONE)
1496 xcb_configure_window(globalconf.connection, w->window, XCB_CONFIG_WINDOW_BORDER_WIDTH,
1497 (uint32_t[]) { border_width });
1498 w->border_width = border_width;
1499 /* Need update if transparent background */
1500 wibox_need_update(w);
1501 luaA_object_emit_signal(L, -3, "property::border_width", 0);
1503 return 0;
1506 static int
1507 luaA_wibox_set_shape_bounding(lua_State *L, wibox_t *wibox)
1509 luaA_checkudata(L, -1, &image_class);
1510 luaA_object_unref_item(L, -3, wibox->shape.bounding);
1511 wibox->shape.bounding = luaA_object_ref_item(L, -3, -1);
1512 wibox->need_shape_update = true;
1513 luaA_object_emit_signal(L, -2, "property::shape_bounding", 0);
1514 return 0;
1517 static int
1518 luaA_wibox_get_shape_bounding(lua_State *L, wibox_t *wibox)
1520 return luaA_object_push_item(L, 1, wibox->shape.bounding);
1523 static int
1524 luaA_wibox_set_shape_clip(lua_State *L, wibox_t *wibox)
1526 luaA_checkudata(L, -1, &image_class);
1527 luaA_object_unref_item(L, -3, wibox->shape.clip);
1528 wibox->shape.clip = luaA_object_ref_item(L, -3, -1);
1529 wibox->need_shape_update = true;
1530 luaA_object_emit_signal(L, -2, "property::shape_clip", 0);
1531 return 0;
1534 static int
1535 luaA_wibox_get_shape_clip(lua_State *L, wibox_t *wibox)
1537 return luaA_object_push_item(L, 1, wibox->shape.clip);
1540 void
1541 wibox_class_setup(lua_State *L)
1543 static const struct luaL_reg wibox_methods[] =
1545 LUA_CLASS_METHODS(wibox)
1546 { "__call", luaA_wibox_new },
1547 { NULL, NULL }
1550 static const struct luaL_reg wibox_meta[] =
1552 LUA_OBJECT_META(wibox)
1553 LUA_CLASS_META
1554 { "struts", luaA_wibox_struts },
1555 { "buttons", luaA_wibox_buttons },
1556 { "geometry", luaA_wibox_geometry },
1557 { "__gc", luaA_wibox_gc },
1558 { NULL, NULL },
1561 luaA_class_setup(L, &wibox_class, "wibox", (lua_class_allocator_t) wibox_new,
1562 luaA_class_index_miss_property, luaA_class_newindex_miss_property,
1563 wibox_methods, wibox_meta);
1564 luaA_class_add_property(&wibox_class, A_TK_WIDGETS,
1565 (lua_class_propfunc_t) luaA_wibox_set_widgets,
1566 (lua_class_propfunc_t) luaA_wibox_get_widgets,
1567 (lua_class_propfunc_t) luaA_wibox_set_widgets);
1568 luaA_class_add_property(&wibox_class, A_TK_OPACITY,
1569 (lua_class_propfunc_t) luaA_wibox_set_opacity,
1570 (lua_class_propfunc_t) luaA_wibox_get_opacity,
1571 (lua_class_propfunc_t) luaA_wibox_set_opacity);
1572 luaA_class_add_property(&wibox_class, A_TK_VISIBLE,
1573 (lua_class_propfunc_t) luaA_wibox_set_visible,
1574 (lua_class_propfunc_t) luaA_wibox_get_visible,
1575 (lua_class_propfunc_t) luaA_wibox_set_visible);
1576 luaA_class_add_property(&wibox_class, A_TK_BORDER_COLOR,
1577 (lua_class_propfunc_t) luaA_wibox_set_border_color,
1578 (lua_class_propfunc_t) luaA_wibox_get_border_color,
1579 (lua_class_propfunc_t) luaA_wibox_set_border_color);
1580 luaA_class_add_property(&wibox_class, A_TK_BORDER_WIDTH,
1581 (lua_class_propfunc_t) luaA_wibox_set_border_width,
1582 (lua_class_propfunc_t) luaA_wibox_get_border_width,
1583 (lua_class_propfunc_t) luaA_wibox_set_border_width);
1584 luaA_class_add_property(&wibox_class, A_TK_ORIENTATION,
1585 (lua_class_propfunc_t) luaA_wibox_set_orientation,
1586 (lua_class_propfunc_t) luaA_wibox_get_orientation,
1587 (lua_class_propfunc_t) luaA_wibox_set_orientation);
1588 luaA_class_add_property(&wibox_class, A_TK_ONTOP,
1589 (lua_class_propfunc_t) luaA_wibox_set_ontop,
1590 (lua_class_propfunc_t) luaA_wibox_get_ontop,
1591 (lua_class_propfunc_t) luaA_wibox_set_ontop);
1592 luaA_class_add_property(&wibox_class, A_TK_SCREEN,
1593 NULL,
1594 (lua_class_propfunc_t) luaA_wibox_get_screen,
1595 (lua_class_propfunc_t) luaA_wibox_set_screen);
1596 luaA_class_add_property(&wibox_class, A_TK_CURSOR,
1597 (lua_class_propfunc_t) luaA_wibox_set_cursor,
1598 (lua_class_propfunc_t) luaA_wibox_get_cursor,
1599 (lua_class_propfunc_t) luaA_wibox_set_cursor);
1600 luaA_class_add_property(&wibox_class, A_TK_CLIENT,
1601 (lua_class_propfunc_t) luaA_wibox_set_client,
1602 (lua_class_propfunc_t) luaA_wibox_get_client,
1603 (lua_class_propfunc_t) luaA_wibox_set_client);
1604 luaA_class_add_property(&wibox_class, A_TK_POSITION,
1605 (lua_class_propfunc_t) luaA_wibox_set_position,
1606 (lua_class_propfunc_t) luaA_wibox_get_position,
1607 (lua_class_propfunc_t) luaA_wibox_set_position);
1608 luaA_class_add_property(&wibox_class, A_TK_ALIGN,
1609 (lua_class_propfunc_t) luaA_wibox_set_align,
1610 (lua_class_propfunc_t) luaA_wibox_get_align,
1611 (lua_class_propfunc_t) luaA_wibox_set_align);
1612 luaA_class_add_property(&wibox_class, A_TK_FG,
1613 (lua_class_propfunc_t) luaA_wibox_set_fg,
1614 (lua_class_propfunc_t) luaA_wibox_get_fg,
1615 (lua_class_propfunc_t) luaA_wibox_set_fg);
1616 luaA_class_add_property(&wibox_class, A_TK_BG,
1617 (lua_class_propfunc_t) luaA_wibox_set_bg,
1618 (lua_class_propfunc_t) luaA_wibox_get_bg,
1619 (lua_class_propfunc_t) luaA_wibox_set_bg);
1620 luaA_class_add_property(&wibox_class, A_TK_BG_IMAGE,
1621 (lua_class_propfunc_t) luaA_wibox_set_bg_image,
1622 (lua_class_propfunc_t) luaA_wibox_get_bg_image,
1623 (lua_class_propfunc_t) luaA_wibox_set_bg_image);
1624 luaA_class_add_property(&wibox_class, A_TK_X,
1625 (lua_class_propfunc_t) luaA_wibox_set_x,
1626 (lua_class_propfunc_t) luaA_wibox_get_x,
1627 (lua_class_propfunc_t) luaA_wibox_set_x);
1628 luaA_class_add_property(&wibox_class, A_TK_Y,
1629 (lua_class_propfunc_t) luaA_wibox_set_y,
1630 (lua_class_propfunc_t) luaA_wibox_get_y,
1631 (lua_class_propfunc_t) luaA_wibox_set_y);
1632 luaA_class_add_property(&wibox_class, A_TK_WIDTH,
1633 (lua_class_propfunc_t) luaA_wibox_set_width,
1634 (lua_class_propfunc_t) luaA_wibox_get_width,
1635 (lua_class_propfunc_t) luaA_wibox_set_width);
1636 luaA_class_add_property(&wibox_class, A_TK_HEIGHT,
1637 (lua_class_propfunc_t) luaA_wibox_set_height,
1638 (lua_class_propfunc_t) luaA_wibox_get_height,
1639 (lua_class_propfunc_t) luaA_wibox_set_height);
1640 luaA_class_add_property(&wibox_class, A_TK_SHAPE_BOUNDING,
1641 (lua_class_propfunc_t) luaA_wibox_set_shape_bounding,
1642 (lua_class_propfunc_t) luaA_wibox_get_shape_bounding,
1643 (lua_class_propfunc_t) luaA_wibox_set_shape_bounding);
1644 luaA_class_add_property(&wibox_class, A_TK_SHAPE_CLIP,
1645 (lua_class_propfunc_t) luaA_wibox_set_shape_clip,
1646 (lua_class_propfunc_t) luaA_wibox_get_shape_clip,
1647 (lua_class_propfunc_t) luaA_wibox_set_shape_clip);
1650 // vim: filetype=c:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=80