Fix image cropping/enlarging
[awesome.git] / wibox.c
blobbb1a6f36eb34f55212f44b0d8851093d59bb9e9c
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->widget);
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 wibox->has_systray = false;
422 if(!wibox->screen)
423 return;
425 for(int i = 0; i < wibox->widgets.len; i++)
427 widget_node_t *systray = &wibox->widgets.tab[i];
428 if(systray->widget->type == widget_systray)
430 uint32_t config_back[] = { wibox->ctx.bg.pixel };
431 uint32_t config_win_vals[4];
432 uint32_t config_win_vals_off[2] = { -512, -512 };
433 xembed_window_t *em;
434 int phys_screen = wibox->ctx.phys_screen;
436 wibox->has_systray = true;
438 if(wibox->visible
439 && systray->widget->isvisible
440 && systray->geometry.width)
442 /* Set background of the systray window. */
443 xcb_change_window_attributes(globalconf.connection,
444 globalconf.screens.tab[phys_screen].systray.window,
445 XCB_CW_BACK_PIXEL, config_back);
446 /* Map it. */
447 xcb_map_window(globalconf.connection, globalconf.screens.tab[phys_screen].systray.window);
448 /* Move it. */
449 switch(wibox->orientation)
451 case North:
452 config_win_vals[0] = systray->geometry.y;
453 config_win_vals[1] = wibox->geometry.height - systray->geometry.x - systray->geometry.width;
454 config_win_vals[2] = systray->geometry.height;
455 config_win_vals[3] = systray->geometry.width;
456 break;
457 case South:
458 config_win_vals[0] = systray->geometry.y;
459 config_win_vals[1] = systray->geometry.x;
460 config_win_vals[2] = systray->geometry.height;
461 config_win_vals[3] = systray->geometry.width;
462 break;
463 case East:
464 config_win_vals[0] = systray->geometry.x;
465 config_win_vals[1] = systray->geometry.y;
466 config_win_vals[2] = systray->geometry.width;
467 config_win_vals[3] = systray->geometry.height;
468 break;
470 /* reparent */
471 if(globalconf.screens.tab[phys_screen].systray.parent != wibox->window)
473 xcb_reparent_window(globalconf.connection,
474 globalconf.screens.tab[phys_screen].systray.window,
475 wibox->window,
476 config_win_vals[0], config_win_vals[1]);
477 globalconf.screens.tab[phys_screen].systray.parent = wibox->window;
479 xcb_configure_window(globalconf.connection,
480 globalconf.screens.tab[phys_screen].systray.window,
481 XCB_CONFIG_WINDOW_X
482 | XCB_CONFIG_WINDOW_Y
483 | XCB_CONFIG_WINDOW_WIDTH
484 | XCB_CONFIG_WINDOW_HEIGHT,
485 config_win_vals);
486 /* width = height = systray height */
487 config_win_vals[2] = config_win_vals[3] = systray->geometry.height;
488 config_win_vals[0] = 0;
490 else
491 return wibox_systray_kickout(phys_screen);
493 switch(wibox->orientation)
495 case North:
496 config_win_vals[1] = systray->geometry.width - config_win_vals[3];
497 for(int j = 0; j < globalconf.embedded.len; j++)
499 em = &globalconf.embedded.tab[j];
500 if(em->phys_screen == phys_screen)
502 if(config_win_vals[1] - config_win_vals[2] >= (uint32_t) wibox->geometry.y)
504 xcb_map_window(globalconf.connection, em->win);
505 xcb_configure_window(globalconf.connection, em->win,
506 XCB_CONFIG_WINDOW_X
507 | XCB_CONFIG_WINDOW_Y
508 | XCB_CONFIG_WINDOW_WIDTH
509 | XCB_CONFIG_WINDOW_HEIGHT,
510 config_win_vals);
511 config_win_vals[1] -= config_win_vals[3];
513 else
514 xcb_configure_window(globalconf.connection, em->win,
515 XCB_CONFIG_WINDOW_X
516 | XCB_CONFIG_WINDOW_Y,
517 config_win_vals_off);
520 break;
521 case South:
522 config_win_vals[1] = 0;
523 for(int j = 0; j < globalconf.embedded.len; j++)
525 em = &globalconf.embedded.tab[j];
526 if(em->phys_screen == phys_screen)
528 /* if(y + width <= wibox.y + systray.right) */
529 if(config_win_vals[1] + config_win_vals[3] <= (uint32_t) wibox->geometry.y + AREA_RIGHT(systray->geometry))
531 xcb_map_window(globalconf.connection, em->win);
532 xcb_configure_window(globalconf.connection, em->win,
533 XCB_CONFIG_WINDOW_X
534 | XCB_CONFIG_WINDOW_Y
535 | XCB_CONFIG_WINDOW_WIDTH
536 | XCB_CONFIG_WINDOW_HEIGHT,
537 config_win_vals);
538 config_win_vals[1] += config_win_vals[3];
540 else
541 xcb_configure_window(globalconf.connection, em->win,
542 XCB_CONFIG_WINDOW_X
543 | XCB_CONFIG_WINDOW_Y,
544 config_win_vals_off);
547 break;
548 case East:
549 config_win_vals[1] = 0;
550 for(int j = 0; j < globalconf.embedded.len; j++)
552 em = &globalconf.embedded.tab[j];
553 if(em->phys_screen == phys_screen)
555 /* if(x + width < systray.x + systray.width) */
556 if(config_win_vals[0] + config_win_vals[2] <= (uint32_t) AREA_RIGHT(systray->geometry) + wibox->geometry.x)
558 xcb_map_window(globalconf.connection, em->win);
559 xcb_configure_window(globalconf.connection, em->win,
560 XCB_CONFIG_WINDOW_X
561 | XCB_CONFIG_WINDOW_Y
562 | XCB_CONFIG_WINDOW_WIDTH
563 | XCB_CONFIG_WINDOW_HEIGHT,
564 config_win_vals);
565 config_win_vals[0] += config_win_vals[2];
567 else
568 xcb_configure_window(globalconf.connection, em->win,
569 XCB_CONFIG_WINDOW_X
570 | XCB_CONFIG_WINDOW_Y,
571 config_win_vals_off);
574 break;
576 break;
581 /** Get a wibox by its window.
582 * \param win The window id.
583 * \return A wibox if found, NULL otherwise.
585 wibox_t *
586 wibox_getbywin(xcb_window_t win)
588 foreach(w, globalconf.wiboxes)
589 if((*w)->window == win)
590 return *w;
592 foreach(_c, globalconf.clients)
594 client_t *c = *_c;
595 if(c->titlebar && c->titlebar->window == win)
596 return c->titlebar;
599 return NULL;
602 /** Draw a wibox.
603 * \param wibox The wibox to draw.
605 static void
606 wibox_draw(wibox_t *wibox)
608 if(wibox->visible)
610 widget_render(wibox);
611 wibox_refresh_pixmap(wibox);
613 wibox->need_update = false;
616 wibox_systray_refresh(wibox);
619 /** Refresh all wiboxes.
621 void
622 wibox_refresh(void)
624 foreach(w, globalconf.wiboxes)
626 if((*w)->need_shape_update)
627 wibox_shape_update(*w);
628 if((*w)->need_update)
629 wibox_draw(*w);
632 foreach(_c, globalconf.clients)
634 client_t *c = *_c;
635 if(c->titlebar && c->titlebar->need_update)
636 wibox_draw(c->titlebar);
640 /** Clear the wibox' mouse_over pointer.
641 * \param wibox The wibox.
643 void
644 wibox_clear_mouse_over(wibox_t *wibox)
646 if (wibox->mouse_over)
648 luaA_object_unref(globalconf.L, wibox->mouse_over);
649 wibox->mouse_over = NULL;
653 /** Set a wibox visible or not.
654 * \param L The Lua VM state.
655 * \param udx The wibox.
656 * \param v The visible value.
658 static void
659 wibox_set_visible(lua_State *L, int udx, bool v)
661 wibox_t *wibox = luaA_checkudata(L, udx, &wibox_class);
662 if(v != wibox->visible)
664 wibox->visible = v;
665 wibox_clear_mouse_over(wibox);
667 if(wibox->screen)
669 if(wibox->visible)
670 wibox_map(wibox);
671 else
673 /* Active BMA */
674 client_ignore_enterleave_events();
675 /* Unmap window */
676 xcb_unmap_window(globalconf.connection, wibox->window);
677 /* Active BMA */
678 client_restore_enterleave_events();
681 /* kick out systray if needed */
682 wibox_systray_refresh(wibox);
685 luaA_object_emit_signal(L, udx, "property::visible", 0);
687 hook_property(wibox, "visible");
691 /** Destroy all X resources of a wibox.
692 * \param w The wibox to wipe.
694 void
695 wibox_wipe(wibox_t *w)
697 if(w->window)
699 int phys_screen = w->ctx.phys_screen;
701 /* Activate BMA */
702 client_ignore_enterleave_events();
703 /* Make sure we don't accidentally kill the systray window */
704 if(globalconf.screens.tab[phys_screen].systray.parent == w->window)
705 wibox_systray_kickout(phys_screen);
706 xcb_destroy_window(globalconf.connection, w->window);
707 /* Deactivate BMA */
708 client_restore_enterleave_events();
709 w->window = XCB_NONE;
711 if(w->pixmap)
713 xcb_free_pixmap(globalconf.connection, w->pixmap);
714 w->pixmap = XCB_NONE;
716 if(w->gc)
718 xcb_free_gc(globalconf.connection, w->gc);
719 w->gc = XCB_NONE;
721 draw_context_wipe(&w->ctx);
724 /** Remove a wibox from a screen.
725 * \param L The Lua VM state.
726 * \param udx Wibox to detach from screen.
728 static void
729 wibox_detach(lua_State *L, int udx)
731 wibox_t *wibox = luaA_checkudata(L, udx, &wibox_class);
732 if(wibox->screen)
734 bool v;
736 /* save visible state */
737 v = wibox->visible;
738 wibox->visible = false;
739 wibox_systray_refresh(wibox);
740 /* restore visibility */
741 wibox->visible = v;
743 wibox_clear_mouse_over(wibox);
745 wibox_wipe(wibox);
747 foreach(item, globalconf.wiboxes)
748 if(*item == wibox)
750 wibox_array_remove(&globalconf.wiboxes, item);
751 break;
754 hook_property(wibox, "screen");
756 if(strut_has_value(&wibox->strut))
757 screen_emit_signal(L, wibox->screen, "property::workarea", 0);
759 wibox->screen = NULL;
760 luaA_object_emit_signal(L, udx, "property::screen", 0);
762 luaA_object_unref(globalconf.L, wibox);
766 /** Attach a wibox that is on top of the stack.
767 * \param L The Lua VM state.
768 * \param udx The wibox to attach.
769 * \param s The screen to attach the wibox to.
771 static void
772 wibox_attach(lua_State *L, int udx, screen_t *s)
774 int phys_screen = screen_virttophys(screen_array_indexof(&globalconf.screens, s));
776 /* duplicate wibox */
777 lua_pushvalue(L, udx);
778 /* ref it */
779 wibox_t *wibox = luaA_object_ref_class(globalconf.L, -1, &wibox_class);
781 wibox_detach(L, udx);
783 /* Set the wibox screen */
784 wibox->screen = s;
786 /* Check that the wibox coordinates matches the screen. */
787 screen_t *cscreen =
788 screen_getbycoord(wibox->screen, wibox->geometry.x, wibox->geometry.y);
790 /* If it does not match, move it to the screen coordinates */
791 if(cscreen != wibox->screen)
792 wibox_moveresize(L, udx, (area_t) { .x = s->geometry.x,
793 .y = s->geometry.y,
794 .width = wibox->geometry.width,
795 .height = wibox->geometry.height });
797 wibox_array_append(&globalconf.wiboxes, wibox);
799 wibox_init(wibox, phys_screen);
801 window_set_cursor(wibox->window,
802 xcursor_new(globalconf.connection, xcursor_font_fromstr(wibox->cursor)));
804 if(wibox->opacity != -1)
805 window_opacity_set(wibox->window, wibox->opacity);
807 ewmh_update_strut(wibox->window, &wibox->strut);
809 if(wibox->visible)
810 wibox_map(wibox);
811 else
812 wibox_need_update(wibox);
814 hook_property(wibox, "screen");
815 luaA_object_emit_signal(L, udx, "property::screen", 0);
817 if(strut_has_value(&wibox->strut))
818 screen_emit_signal(L, wibox->screen, "property::workarea", 0);
821 /** Create a new wibox.
822 * \param L The Lua VM state.
824 * \luastack
825 * \lparam A table with optionally defined values:
826 * fg, bg, border_width, border_color, ontop, width and height.
827 * \lreturn A brand new wibox.
829 static int
830 luaA_wibox_new(lua_State *L)
832 luaA_class_new(L, &wibox_class);
834 wibox_t *w = luaA_checkudata(L, -1, &wibox_class);
836 if(!w->ctx.fg.initialized)
837 w->ctx.fg = globalconf.colors.fg;
839 if(!w->ctx.bg.initialized)
840 w->ctx.bg = globalconf.colors.bg;
842 if(!w->border_color.initialized)
843 w->border_color = globalconf.colors.bg;
845 w->visible = true;
847 if(!w->opacity)
848 w->opacity = -1;
850 if(!w->cursor)
851 w->cursor = a_strdup("left_ptr");
853 if(!w->geometry.width)
854 w->geometry.width = 1;
856 if(!w->geometry.height)
857 w->geometry.height = 1;
859 return 1;
862 /** Check if a wibox widget table has an item.
863 * \param L The Lua VM state.
864 * \param wibox The wibox.
865 * \param item The item to look for.
867 static bool
868 luaA_wibox_hasitem(lua_State *L, wibox_t *wibox, const void *item)
870 if(wibox->widgets_table)
872 luaA_object_push(L, wibox);
873 luaA_object_push_item(L, -1, wibox->widgets_table);
874 lua_remove(L, -2);
875 if(lua_topointer(L, -1) == item || luaA_hasitem(L, item))
876 return true;
878 return false;
881 /** Invalidate a wibox by a Lua object (table, etc).
882 * \param L The Lua VM state.
883 * \param item The object identifier.
885 void
886 luaA_wibox_invalidate_byitem(lua_State *L, const void *item)
888 foreach(w, globalconf.wiboxes)
890 wibox_t *wibox = *w;
891 if(luaA_wibox_hasitem(L, wibox, item))
893 /* update wibox */
894 wibox_need_update(wibox);
895 lua_pop(L, 1); /* remove widgets table */
900 foreach(_c, globalconf.clients)
902 client_t *c = *_c;
903 if(c->titlebar && luaA_wibox_hasitem(L, c->titlebar, item))
905 /* update wibox */
906 wibox_need_update(c->titlebar);
907 lua_pop(L, 1); /* remove widgets table */
912 /* Set or get the wibox geometry.
913 * \param L The Lua VM state.
914 * \return The number of elements pushed on stack.
915 * \luastack
916 * \lparam An optional table with wibox geometry.
917 * \lreturn The wibox geometry.
919 static int
920 luaA_wibox_geometry(lua_State *L)
922 wibox_t *wibox = luaA_checkudata(L, 1, &wibox_class);
924 if(lua_gettop(L) == 2)
926 area_t wingeom;
928 luaA_checktable(L, 2);
929 wingeom.x = luaA_getopt_number(L, 2, "x", wibox->geometry.x);
930 wingeom.y = luaA_getopt_number(L, 2, "y", wibox->geometry.y);
931 wingeom.width = luaA_getopt_number(L, 2, "width", wibox->geometry.width);
932 wingeom.height = luaA_getopt_number(L, 2, "height", wibox->geometry.height);
934 if(wingeom.width > 0 && wingeom.height > 0)
935 switch(wibox->type)
937 case WIBOX_TYPE_TITLEBAR:
938 wibox_moveresize(L, 1, (area_t) { .x = wibox->geometry.x,
939 .y = wibox->geometry.y,
940 .width = wingeom.width,
941 .height = wingeom.height });
942 break;
943 case WIBOX_TYPE_NORMAL:
944 wibox_moveresize(L, 1, wingeom);
945 break;
949 return luaA_pusharea(L, wibox->geometry);
952 static int
953 luaA_wibox_struts(lua_State *L)
955 wibox_t *w = luaA_checkudata(L, 1, &wibox_class);
957 if(lua_gettop(L) == 2)
959 luaA_tostrut(L, 2, &w->strut);
960 if(w->window)
961 ewmh_update_strut(w->window, &w->strut);
962 luaA_object_emit_signal(L, 1, "property::struts", 0);
963 if(w->screen)
964 screen_emit_signal(L, w->screen, "property::workarea", 0);
967 return luaA_pushstrut(L, w->strut);
970 LUA_OBJECT_EXPORT_PROPERTY(wibox, wibox_t, ontop, lua_pushboolean)
971 LUA_OBJECT_EXPORT_PROPERTY(wibox, wibox_t, cursor, lua_pushstring)
972 LUA_OBJECT_EXPORT_PROPERTY(wibox, wibox_t, visible, lua_pushboolean)
973 LUA_OBJECT_EXPORT_PROPERTY(wibox, wibox_t, border_width, lua_pushnumber)
974 LUA_OBJECT_EXPORT_PROPERTY(wibox, wibox_t, border_color, luaA_pushxcolor)
976 static int
977 luaA_wibox_set_x(lua_State *L, wibox_t *wibox)
979 wibox_moveresize(L, -3, (area_t) { .x = luaL_checknumber(L, -1),
980 .y = wibox->geometry.y,
981 .width = wibox->geometry.width,
982 .height = wibox->geometry.height });
983 return 0;
986 static int
987 luaA_wibox_get_x(lua_State *L, wibox_t *wibox)
989 lua_pushnumber(L, wibox->geometry.x);
990 return 1;
993 static int
994 luaA_wibox_set_y(lua_State *L, wibox_t *wibox)
996 wibox_moveresize(L, -3, (area_t) { .x = wibox->geometry.x,
997 .y = luaL_checknumber(L, -1),
998 .width = wibox->geometry.width,
999 .height = wibox->geometry.height });
1000 return 0;
1003 static int
1004 luaA_wibox_get_y(lua_State *L, wibox_t *wibox)
1006 lua_pushnumber(L, wibox->geometry.y);
1007 return 1;
1010 static int
1011 luaA_wibox_set_width(lua_State *L, wibox_t *wibox)
1013 int width = luaL_checknumber(L, -1);
1014 if(width <= 0)
1015 luaL_error(L, "invalid width");
1016 wibox_moveresize(L, -3, (area_t) { .x = wibox->geometry.x,
1017 .y = wibox->geometry.y,
1018 .width = width,
1019 .height = wibox->geometry.height });
1020 return 0;
1023 static int
1024 luaA_wibox_get_width(lua_State *L, wibox_t *wibox)
1026 lua_pushnumber(L, wibox->geometry.width);
1027 return 1;
1030 static int
1031 luaA_wibox_set_height(lua_State *L, wibox_t *wibox)
1033 int height = luaL_checknumber(L, -1);
1034 if(height <= 0)
1035 luaL_error(L, "invalid height");
1036 wibox_moveresize(L, -3, (area_t) { .x = wibox->geometry.x,
1037 .y = wibox->geometry.y,
1038 .width = wibox->geometry.width,
1039 .height = height });
1040 return 0;
1043 static int
1044 luaA_wibox_get_height(lua_State *L, wibox_t *wibox)
1046 lua_pushnumber(L, wibox->geometry.height);
1047 return 1;
1050 /** Set the wibox foreground color.
1051 * \param L The Lua VM state.
1052 * \param wibox The wibox object.
1053 * \return The number of elements pushed on stack.
1055 static int
1056 luaA_wibox_set_fg(lua_State *L, wibox_t *wibox)
1058 size_t len;
1059 const char *buf = luaL_checklstring(L, -1, &len);
1060 if(xcolor_init_reply(xcolor_init_unchecked(&wibox->ctx.fg, buf, len)))
1061 wibox->need_update = true;
1062 luaA_object_emit_signal(L, -3, "property::fg", 0);
1063 return 0;
1066 /** Get the wibox foreground color.
1067 * \param L The Lua VM state.
1068 * \param wibox The wibox object.
1069 * \return The number of elements pushed on stack.
1071 static int
1072 luaA_wibox_get_fg(lua_State *L, wibox_t *wibox)
1074 return luaA_pushxcolor(L, wibox->ctx.fg);
1077 /** Set the wibox background color.
1078 * \param L The Lua VM state.
1079 * \param wibox The wibox object.
1080 * \return The number of elements pushed on stack.
1082 static int
1083 luaA_wibox_set_bg(lua_State *L, wibox_t *wibox)
1085 size_t len;
1086 const char *buf = luaL_checklstring(L, -1, &len);
1087 if(xcolor_init_reply(xcolor_init_unchecked(&wibox->ctx.bg, buf, len)))
1089 uint32_t mask = XCB_CW_BACK_PIXEL;
1090 uint32_t values[] = { wibox->ctx.bg.pixel };
1092 wibox->need_update = true;
1094 if (wibox->window != XCB_NONE)
1095 xcb_change_window_attributes(globalconf.connection,
1096 wibox->window,
1097 mask,
1098 values);
1100 luaA_object_emit_signal(L, -3, "property::bg", 0);
1101 return 0;
1104 /** Get the wibox background color.
1105 * \param L The Lua VM state.
1106 * \param wibox The wibox object.
1107 * \return The number of elements pushed on stack.
1109 static int
1110 luaA_wibox_get_bg(lua_State *L, wibox_t *wibox)
1112 return luaA_pushxcolor(L, wibox->ctx.bg);
1115 /** Set the wibox background image.
1116 * \param L The Lua VM state.
1117 * \param wibox The wibox object.
1118 * \return The number of elements pushed on stack.
1120 static int
1121 luaA_wibox_set_bg_image(lua_State *L, wibox_t *wibox)
1123 luaA_checkudata(L, -1, &image_class);
1124 luaA_object_unref_item(L, -3, wibox->bg_image);
1125 wibox->bg_image = luaA_object_ref_item(L, -3, -1);
1126 wibox->need_update = true;
1127 luaA_object_emit_signal(L, -2, "property::bg_image", 0);
1128 return 0;
1131 /** Get the wibox background image.
1132 * \param L The Lua VM state.
1133 * \param wibox The wibox object.
1134 * \return The number of elements pushed on stack.
1136 static int
1137 luaA_wibox_get_bg_image(lua_State *L, wibox_t *wibox)
1139 return luaA_object_push_item(L, 1, wibox->bg_image);
1142 /** Set the wibox on top status.
1143 * \param L The Lua VM state.
1144 * \param wibox The wibox object.
1145 * \return The number of elements pushed on stack.
1147 static int
1148 luaA_wibox_set_ontop(lua_State *L, wibox_t *wibox)
1150 bool b = luaA_checkboolean(L, -1);
1151 if(b != wibox->ontop)
1153 wibox->ontop = b;
1154 client_stack();
1155 luaA_object_emit_signal(L, -3, "property::ontop", 0);
1157 return 0;
1160 /** Set the wibox opacity.
1161 * \param L The Lua VM state.
1162 * \param wibox The wibox object.
1163 * \return The number of elements pushed on stack.
1165 static int
1166 luaA_wibox_set_opacity(lua_State *L, wibox_t *wibox)
1168 if(lua_isnil(L, -1))
1169 wibox_set_opacity(L, -3, -1);
1170 else
1172 double d = luaL_checknumber(L, -1);
1173 if(d >= 0 && d <= 1)
1174 wibox_set_opacity(L, -3, d);
1176 return 0;
1179 /** Get the wibox opacity.
1180 * \param L The Lua VM state.
1181 * \param wibox The wibox object.
1182 * \return The number of elements pushed on stack.
1184 static int
1185 luaA_wibox_get_opacity(lua_State *L, wibox_t *wibox)
1187 if (wibox->opacity >= 0)
1189 lua_pushnumber(L, wibox->opacity);
1190 return 1;
1192 return 0;
1195 /** Set the wibox alignment.
1196 * \param L The Lua VM state.
1197 * \param wibox The wibox object.
1198 * \return The number of elements pushed on stack.
1200 static int
1201 luaA_wibox_set_align(lua_State *L, wibox_t *wibox)
1203 size_t len;
1204 const char *buf = luaL_checklstring(L, -1, &len);
1205 wibox->align = draw_align_fromstr(buf, len);
1206 luaA_object_emit_signal(L, -3, "property::align", 0);
1207 switch(wibox->type)
1209 case WIBOX_TYPE_NORMAL:
1210 luaA_deprecate(L, "awful.wibox.align");
1211 break;
1212 case WIBOX_TYPE_TITLEBAR:
1213 titlebar_update_geometry(client_getbytitlebar(wibox));
1214 break;
1216 return 0;
1219 /** Get the wibox alignment.
1220 * \param L The Lua VM state.
1221 * \param wibox The wibox object.
1222 * \return The number of elements pushed on stack.
1224 static int
1225 luaA_wibox_get_align(lua_State *L, wibox_t *wibox)
1227 if(wibox->type == WIBOX_TYPE_NORMAL)
1228 luaA_deprecate(L, "awful.wibox.align");
1229 lua_pushstring(L, draw_align_tostr(wibox->align));
1230 return 1;
1233 /** Set the wibox position.
1234 * \param L The Lua VM state.
1235 * \param wibox The wibox object.
1236 * \return The number of elements pushed on stack.
1238 static int
1239 luaA_wibox_set_position(lua_State *L, wibox_t *wibox)
1241 switch(wibox->type)
1243 case WIBOX_TYPE_NORMAL:
1245 size_t len;
1246 const char *buf;
1247 if((buf = luaL_checklstring(L, -1, &len)))
1249 luaA_deprecate(L, "awful.wibox.attach");
1250 wibox->position = position_fromstr(buf, len);
1253 break;
1254 case WIBOX_TYPE_TITLEBAR:
1255 return luaA_titlebar_set_position(L, -3);
1257 return 0;
1260 /** Get the wibox position.
1261 * \param L The Lua VM state.
1262 * \param wibox The wibox object.
1263 * \return The number of elements pushed on stack.
1265 static int
1266 luaA_wibox_get_position(lua_State *L, wibox_t *wibox)
1268 if(wibox->type == WIBOX_TYPE_NORMAL)
1269 luaA_deprecate(L, "awful.wibox.attach");
1270 lua_pushstring(L, position_tostr(wibox->position));
1271 return 1;
1274 /** Set the wibox (titlebar) client.
1275 * \param L The Lua VM state.
1276 * \param wibox The wibox object.
1277 * \return The number of elements pushed on stack.
1279 static int
1280 luaA_wibox_set_client(lua_State *L, wibox_t *wibox)
1282 /* first detach */
1283 if(lua_isnil(L, -1))
1284 titlebar_client_detach(client_getbytitlebar(wibox));
1285 else
1287 client_t *c = luaA_client_checkudata(L, -1);
1288 lua_pushvalue(L, -3);
1289 titlebar_client_attach(c);
1291 return 0;
1294 /** Get the wibox (titlebar) client.
1295 * \param L The Lua VM state.
1296 * \param wibox The wibox object.
1297 * \return The number of elements pushed on stack.
1299 static int
1300 luaA_wibox_get_client(lua_State *L, wibox_t *wibox)
1302 return luaA_object_push(L, client_getbytitlebar(wibox));
1305 /** Set the wibox cursor.
1306 * \param L The Lua VM state.
1307 * \param wibox The wibox object.
1308 * \return The number of elements pushed on stack.
1310 static int
1311 luaA_wibox_set_cursor(lua_State *L, wibox_t *wibox)
1313 const char *buf = luaL_checkstring(L, -1);
1314 if(buf)
1316 uint16_t cursor_font = xcursor_font_fromstr(buf);
1317 if(cursor_font)
1319 xcb_cursor_t cursor = xcursor_new(globalconf.connection, cursor_font);
1320 p_delete(&wibox->cursor);
1321 wibox->cursor = a_strdup(buf);
1322 window_set_cursor(wibox->window, cursor);
1323 luaA_object_emit_signal(L, -3, "property::cursor", 0);
1326 return 0;
1329 /** Set the wibox screen.
1330 * \param L The Lua VM state.
1331 * \param wibox The wibox object.
1332 * \return The number of elements pushed on stack.
1334 static int
1335 luaA_wibox_set_screen(lua_State *L, wibox_t *wibox)
1337 if(lua_isnil(L, -1))
1339 wibox_detach(L, -3);
1340 titlebar_client_detach(client_getbytitlebar(wibox));
1342 else
1344 int screen = luaL_checknumber(L, -1) - 1;
1345 luaA_checkscreen(screen);
1346 if(!wibox->screen || screen != screen_array_indexof(&globalconf.screens, wibox->screen))
1348 titlebar_client_detach(client_getbytitlebar(wibox));
1349 wibox_attach(L, -3, &globalconf.screens.tab[screen]);
1352 return 0;
1355 /** Get the wibox screen.
1356 * \param L The Lua VM state.
1357 * \param wibox The wibox object.
1358 * \return The number of elements pushed on stack.
1360 static int
1361 luaA_wibox_get_screen(lua_State *L, wibox_t *wibox)
1363 if(!wibox->screen)
1364 return 0;
1365 lua_pushnumber(L, screen_array_indexof(&globalconf.screens, wibox->screen) + 1);
1366 return 1;
1369 /** Set the wibox orientation.
1370 * \param L The Lua VM state.
1371 * \param wibox The wibox object.
1372 * \return The number of elements pushed on stack.
1374 static int
1375 luaA_wibox_set_orientation(lua_State *L, wibox_t *wibox)
1377 size_t len;
1378 const char *buf = luaL_checklstring(L, -1, &len);
1379 if(buf)
1381 wibox_set_orientation(L, -3, orientation_fromstr(buf, len));
1382 wibox_need_update(wibox);
1384 return 0;
1387 /** Get the wibox orientation.
1388 * \param L The Lua VM state.
1389 * \param wibox The wibox object.
1390 * \return The number of elements pushed on stack.
1392 static int
1393 luaA_wibox_get_orientation(lua_State *L, wibox_t *wibox)
1395 lua_pushstring(L, orientation_tostr(wibox->orientation));
1396 return 1;
1399 /** Set the wibox border color.
1400 * \param L The Lua VM state.
1401 * \param wibox The wibox object.
1402 * \return The number of elements pushed on stack.
1404 static int
1405 luaA_wibox_set_border_color(lua_State *L, wibox_t *wibox)
1407 size_t len;
1408 const char *buf = luaL_checklstring(L, -1, &len);
1409 if(buf)
1410 if(xcolor_init_reply(xcolor_init_unchecked(&wibox->border_color, buf, len)))
1411 if(wibox->window)
1412 wibox_set_border_color(L, -3, &wibox->border_color);
1413 return 0;
1416 /** Set the wibox visibility.
1417 * \param L The Lua VM state.
1418 * \param wibox The wibox object.
1419 * \return The number of elements pushed on stack.
1421 static int
1422 luaA_wibox_set_visible(lua_State *L, wibox_t *wibox)
1424 bool b = luaA_checkboolean(L, -1);
1425 if(b != wibox->visible)
1426 switch(wibox->type)
1428 case WIBOX_TYPE_NORMAL:
1429 wibox_set_visible(L, -3, b);
1430 break;
1431 case WIBOX_TYPE_TITLEBAR:
1432 titlebar_set_visible(wibox, b);
1433 break;
1435 return 0;
1438 /** Set the wibox widgets.
1439 * \param L The Lua VM state.
1440 * \param wibox The wibox object.
1441 * \return The number of elements pushed on stack.
1443 static int
1444 luaA_wibox_set_widgets(lua_State *L, wibox_t *wibox)
1446 if(luaA_isloop(L, -1))
1448 luaA_warn(L, "table is looping, cannot use this as widget table");
1449 return 0;
1451 /* duplicate table because next function will eat it */
1452 lua_pushvalue(L, -1);
1453 luaA_object_unref_item(L, -4, wibox->widgets_table);
1454 wibox->widgets_table = luaA_object_ref_item(L, -4, -1);
1455 luaA_object_emit_signal(L, -3, "property::widgets", 0);
1456 wibox_need_update(wibox);
1457 luaA_table2wtable(L);
1458 return 0;
1461 /** Get the wibox widgets.
1462 * \param L The Lua VM state.
1463 * \param wibox The wibox object.
1464 * \return The number of elements pushed on stack.
1466 static int
1467 luaA_wibox_get_widgets(lua_State *L, wibox_t *wibox)
1469 return luaA_object_push_item(L, 1, wibox->widgets_table);
1472 /** Get or set mouse buttons bindings to a wibox.
1473 * \param L The Lua VM state.
1474 * \luastack
1475 * \lvalue A wibox.
1476 * \lparam An array of mouse button bindings objects, or nothing.
1477 * \return The array of mouse button bindings objects of this wibox.
1479 static int
1480 luaA_wibox_buttons(lua_State *L)
1482 wibox_t *wibox = luaA_checkudata(L, 1, &wibox_class);
1484 if(lua_gettop(L) == 2)
1486 luaA_button_array_set(L, 1, 2, &wibox->buttons);
1487 luaA_object_emit_signal(L, 1, "property::buttons", 0);
1490 return luaA_button_array_get(L, 1, &wibox->buttons);
1493 /** Set the wibox border width.
1494 * \param L The Lua VM state.
1495 * \param wibox The wibox object.
1496 * \return The number of elements pushed on stack.
1498 static int
1499 luaA_wibox_set_border_width(lua_State *L, wibox_t *wibox)
1501 wibox_t *w = luaA_checkudata(L, -3, &wibox_class);
1502 int32_t border_width = luaL_checknumber(L, -1);
1503 if(border_width != w->border_width && border_width >= 0)
1505 if (w->window != XCB_NONE)
1506 xcb_configure_window(globalconf.connection, w->window, XCB_CONFIG_WINDOW_BORDER_WIDTH,
1507 (uint32_t[]) { border_width });
1508 w->border_width = border_width;
1509 /* Need update if transparent background */
1510 wibox_need_update(w);
1511 luaA_object_emit_signal(L, -3, "property::border_width", 0);
1513 return 0;
1516 static int
1517 luaA_wibox_set_shape_bounding(lua_State *L, wibox_t *wibox)
1519 luaA_checkudata(L, -1, &image_class);
1520 luaA_object_unref_item(L, -3, wibox->shape.bounding);
1521 wibox->shape.bounding = luaA_object_ref_item(L, -3, -1);
1522 wibox->need_shape_update = true;
1523 luaA_object_emit_signal(L, -2, "property::shape_bounding", 0);
1524 return 0;
1527 static int
1528 luaA_wibox_get_shape_bounding(lua_State *L, wibox_t *wibox)
1530 return luaA_object_push_item(L, 1, wibox->shape.bounding);
1533 static int
1534 luaA_wibox_set_shape_clip(lua_State *L, wibox_t *wibox)
1536 luaA_checkudata(L, -1, &image_class);
1537 luaA_object_unref_item(L, -3, wibox->shape.clip);
1538 wibox->shape.clip = luaA_object_ref_item(L, -3, -1);
1539 wibox->need_shape_update = true;
1540 luaA_object_emit_signal(L, -2, "property::shape_clip", 0);
1541 return 0;
1544 static int
1545 luaA_wibox_get_shape_clip(lua_State *L, wibox_t *wibox)
1547 return luaA_object_push_item(L, 1, wibox->shape.clip);
1550 void
1551 wibox_class_setup(lua_State *L)
1553 static const struct luaL_reg wibox_methods[] =
1555 LUA_CLASS_METHODS(wibox)
1556 { "__call", luaA_wibox_new },
1557 { NULL, NULL }
1560 static const struct luaL_reg wibox_meta[] =
1562 LUA_OBJECT_META(wibox)
1563 LUA_CLASS_META
1564 { "struts", luaA_wibox_struts },
1565 { "buttons", luaA_wibox_buttons },
1566 { "geometry", luaA_wibox_geometry },
1567 { "__gc", luaA_wibox_gc },
1568 { NULL, NULL },
1571 luaA_class_setup(L, &wibox_class, "wibox", (lua_class_allocator_t) wibox_new,
1572 luaA_class_index_miss_property, luaA_class_newindex_miss_property,
1573 wibox_methods, wibox_meta);
1574 luaA_class_add_property(&wibox_class, A_TK_WIDGETS,
1575 (lua_class_propfunc_t) luaA_wibox_set_widgets,
1576 (lua_class_propfunc_t) luaA_wibox_get_widgets,
1577 (lua_class_propfunc_t) luaA_wibox_set_widgets);
1578 luaA_class_add_property(&wibox_class, A_TK_OPACITY,
1579 (lua_class_propfunc_t) luaA_wibox_set_opacity,
1580 (lua_class_propfunc_t) luaA_wibox_get_opacity,
1581 (lua_class_propfunc_t) luaA_wibox_set_opacity);
1582 luaA_class_add_property(&wibox_class, A_TK_VISIBLE,
1583 (lua_class_propfunc_t) luaA_wibox_set_visible,
1584 (lua_class_propfunc_t) luaA_wibox_get_visible,
1585 (lua_class_propfunc_t) luaA_wibox_set_visible);
1586 luaA_class_add_property(&wibox_class, A_TK_BORDER_COLOR,
1587 (lua_class_propfunc_t) luaA_wibox_set_border_color,
1588 (lua_class_propfunc_t) luaA_wibox_get_border_color,
1589 (lua_class_propfunc_t) luaA_wibox_set_border_color);
1590 luaA_class_add_property(&wibox_class, A_TK_BORDER_WIDTH,
1591 (lua_class_propfunc_t) luaA_wibox_set_border_width,
1592 (lua_class_propfunc_t) luaA_wibox_get_border_width,
1593 (lua_class_propfunc_t) luaA_wibox_set_border_width);
1594 luaA_class_add_property(&wibox_class, A_TK_ORIENTATION,
1595 (lua_class_propfunc_t) luaA_wibox_set_orientation,
1596 (lua_class_propfunc_t) luaA_wibox_get_orientation,
1597 (lua_class_propfunc_t) luaA_wibox_set_orientation);
1598 luaA_class_add_property(&wibox_class, A_TK_ONTOP,
1599 (lua_class_propfunc_t) luaA_wibox_set_ontop,
1600 (lua_class_propfunc_t) luaA_wibox_get_ontop,
1601 (lua_class_propfunc_t) luaA_wibox_set_ontop);
1602 luaA_class_add_property(&wibox_class, A_TK_SCREEN,
1603 NULL,
1604 (lua_class_propfunc_t) luaA_wibox_get_screen,
1605 (lua_class_propfunc_t) luaA_wibox_set_screen);
1606 luaA_class_add_property(&wibox_class, A_TK_CURSOR,
1607 (lua_class_propfunc_t) luaA_wibox_set_cursor,
1608 (lua_class_propfunc_t) luaA_wibox_get_cursor,
1609 (lua_class_propfunc_t) luaA_wibox_set_cursor);
1610 luaA_class_add_property(&wibox_class, A_TK_CLIENT,
1611 (lua_class_propfunc_t) luaA_wibox_set_client,
1612 (lua_class_propfunc_t) luaA_wibox_get_client,
1613 (lua_class_propfunc_t) luaA_wibox_set_client);
1614 luaA_class_add_property(&wibox_class, A_TK_POSITION,
1615 (lua_class_propfunc_t) luaA_wibox_set_position,
1616 (lua_class_propfunc_t) luaA_wibox_get_position,
1617 (lua_class_propfunc_t) luaA_wibox_set_position);
1618 luaA_class_add_property(&wibox_class, A_TK_ALIGN,
1619 (lua_class_propfunc_t) luaA_wibox_set_align,
1620 (lua_class_propfunc_t) luaA_wibox_get_align,
1621 (lua_class_propfunc_t) luaA_wibox_set_align);
1622 luaA_class_add_property(&wibox_class, A_TK_FG,
1623 (lua_class_propfunc_t) luaA_wibox_set_fg,
1624 (lua_class_propfunc_t) luaA_wibox_get_fg,
1625 (lua_class_propfunc_t) luaA_wibox_set_fg);
1626 luaA_class_add_property(&wibox_class, A_TK_BG,
1627 (lua_class_propfunc_t) luaA_wibox_set_bg,
1628 (lua_class_propfunc_t) luaA_wibox_get_bg,
1629 (lua_class_propfunc_t) luaA_wibox_set_bg);
1630 luaA_class_add_property(&wibox_class, A_TK_BG_IMAGE,
1631 (lua_class_propfunc_t) luaA_wibox_set_bg_image,
1632 (lua_class_propfunc_t) luaA_wibox_get_bg_image,
1633 (lua_class_propfunc_t) luaA_wibox_set_bg_image);
1634 luaA_class_add_property(&wibox_class, A_TK_X,
1635 (lua_class_propfunc_t) luaA_wibox_set_x,
1636 (lua_class_propfunc_t) luaA_wibox_get_x,
1637 (lua_class_propfunc_t) luaA_wibox_set_x);
1638 luaA_class_add_property(&wibox_class, A_TK_Y,
1639 (lua_class_propfunc_t) luaA_wibox_set_y,
1640 (lua_class_propfunc_t) luaA_wibox_get_y,
1641 (lua_class_propfunc_t) luaA_wibox_set_y);
1642 luaA_class_add_property(&wibox_class, A_TK_WIDTH,
1643 (lua_class_propfunc_t) luaA_wibox_set_width,
1644 (lua_class_propfunc_t) luaA_wibox_get_width,
1645 (lua_class_propfunc_t) luaA_wibox_set_width);
1646 luaA_class_add_property(&wibox_class, A_TK_HEIGHT,
1647 (lua_class_propfunc_t) luaA_wibox_set_height,
1648 (lua_class_propfunc_t) luaA_wibox_get_height,
1649 (lua_class_propfunc_t) luaA_wibox_set_height);
1650 luaA_class_add_property(&wibox_class, A_TK_SHAPE_BOUNDING,
1651 (lua_class_propfunc_t) luaA_wibox_set_shape_bounding,
1652 (lua_class_propfunc_t) luaA_wibox_get_shape_bounding,
1653 (lua_class_propfunc_t) luaA_wibox_set_shape_bounding);
1654 luaA_class_add_property(&wibox_class, A_TK_SHAPE_CLIP,
1655 (lua_class_propfunc_t) luaA_wibox_set_shape_clip,
1656 (lua_class_propfunc_t) luaA_wibox_get_shape_clip,
1657 (lua_class_propfunc_t) luaA_wibox_set_shape_clip);
1660 // vim: filetype=c:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=80