2 * wibox.c - wibox functions
4 * Copyright © 2008 Julien Danjou <julien@danjou.info>
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License along
17 * with this program; if not, write to the Free Software Foundation, Inc.,
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
29 #include "common/xcursor.h"
30 #include "common/xutil.h"
32 DO_LUA_TOSTRING(wibox_t
, wibox
, "wibox")
34 /** Take care of garbage collecting a wibox.
35 * \param L The Lua VM state.
36 * \return The number of elements pushed on stack, 0!
39 luaA_wibox_gc(lua_State
*L
)
41 wibox_t
*wibox
= luaL_checkudata(L
, 1, "wibox");
42 p_delete(&wibox
->cursor
);
43 simplewindow_wipe(&wibox
->sw
);
44 button_array_wipe(&wibox
->buttons
);
45 image_unref(L
, wibox
->bg_image
);
46 luaL_unref(L
, LUA_REGISTRYINDEX
, wibox
->widgets_table
);
47 luaL_unref(L
, LUA_REGISTRYINDEX
, wibox
->mouse_enter
);
48 luaL_unref(L
, LUA_REGISTRYINDEX
, wibox
->mouse_leave
);
49 widget_node_array_wipe(&wibox
->widgets
);
54 wibox_unref_simplified(wibox_t
**item
)
56 wibox_unref(globalconf
.L
, *item
);
60 wibox_need_update(wibox_t
*wibox
)
62 wibox
->need_update
= true;
63 wibox
->mouse_over
= NULL
;
67 wibox_map(wibox_t
*wibox
)
69 xcb_map_window(globalconf
.connection
, wibox
->sw
.window
);
70 /* We must make sure the wibox does not display garbage */
71 wibox_need_update(wibox
);
72 /* Stack this wibox correctly */
77 wibox_move(wibox_t
*wibox
, int16_t x
, int16_t y
)
81 simplewindow_move(&wibox
->sw
, x
, y
);
82 wibox
->screen
= screen_getbycoord(wibox
->screen
, x
, y
);
86 wibox
->sw
.geometry
.x
= x
;
87 wibox
->sw
.geometry
.y
= y
;
92 wibox_resize(wibox_t
*wibox
, uint16_t width
, uint16_t height
)
95 simplewindow_resize(&wibox
->sw
, width
, height
);
98 wibox
->sw
.geometry
.width
= width
;
99 wibox
->sw
.geometry
.height
= height
;
101 wibox_need_update(wibox
);
105 wibox_setposition(wibox_t
*wibox
, position_t p
)
107 if(p
!= wibox
->position
)
109 switch((wibox
->position
= p
))
114 simplewindow_orientation_set(&wibox
->sw
, East
);
117 simplewindow_orientation_set(&wibox
->sw
, North
);
120 simplewindow_orientation_set(&wibox
->sw
, South
);
123 /* reset width/height to 0 */
124 if(wibox
->position
!= Floating
)
125 wibox
->sw
.geometry
.width
= wibox
->sw
.geometry
.height
= 0;
127 /* recompute position */
128 wibox_position_update(wibox
);
130 /* reset all wibox position */
131 foreach(w
, wibox
->screen
->wiboxes
)
132 wibox_position_update(*w
);
134 ewmh_update_workarea(screen_virttophys(screen_array_indexof(&globalconf
.screens
, wibox
->screen
)));
136 wibox_need_update(wibox
);
140 /** Kick out systray windows.
141 * \param phys_screen Physical screen number.
144 wibox_systray_kickout(int phys_screen
)
146 xcb_screen_t
*s
= xutil_screen_get(globalconf
.connection
, phys_screen
);
148 if(globalconf
.screens
.tab
[phys_screen
].systray
.parent
!= s
->root
)
150 /* Who! Check that we're not deleting a wibox with a systray, because it
151 * may be its parent. If so, we reparent to root before, otherwise it will
153 xcb_reparent_window(globalconf
.connection
,
154 globalconf
.screens
.tab
[phys_screen
].systray
.window
,
155 s
->root
, -512, -512);
157 globalconf
.screens
.tab
[phys_screen
].systray
.parent
= s
->root
;
162 wibox_systray_refresh(wibox_t
*wibox
)
167 for(int i
= 0; i
< wibox
->widgets
.len
; i
++)
169 widget_node_t
*systray
= &wibox
->widgets
.tab
[i
];
170 if(systray
->widget
->type
== widget_systray
)
172 uint32_t config_back
[] = { wibox
->sw
.ctx
.bg
.pixel
};
173 uint32_t config_win_vals
[4];
174 uint32_t config_win_vals_off
[2] = { -512, -512 };
176 int phys_screen
= wibox
->sw
.ctx
.phys_screen
;
179 && systray
->widget
->isvisible
180 && systray
->geometry
.width
)
182 /* Set background of the systray window. */
183 xcb_change_window_attributes(globalconf
.connection
,
184 globalconf
.screens
.tab
[phys_screen
].systray
.window
,
185 XCB_CW_BACK_PIXEL
, config_back
);
187 xcb_map_window(globalconf
.connection
, globalconf
.screens
.tab
[phys_screen
].systray
.window
);
189 switch(wibox
->sw
.orientation
)
192 config_win_vals
[0] = systray
->geometry
.y
;
193 config_win_vals
[1] = wibox
->sw
.geometry
.height
- systray
->geometry
.x
- systray
->geometry
.width
;
194 config_win_vals
[2] = systray
->geometry
.height
;
195 config_win_vals
[3] = systray
->geometry
.width
;
198 config_win_vals
[0] = systray
->geometry
.y
;
199 config_win_vals
[1] = systray
->geometry
.x
;
200 config_win_vals
[2] = systray
->geometry
.height
;
201 config_win_vals
[3] = systray
->geometry
.width
;
204 config_win_vals
[0] = systray
->geometry
.x
;
205 config_win_vals
[1] = systray
->geometry
.y
;
206 config_win_vals
[2] = systray
->geometry
.width
;
207 config_win_vals
[3] = systray
->geometry
.height
;
211 if(globalconf
.screens
.tab
[phys_screen
].systray
.parent
!= wibox
->sw
.window
)
213 xcb_reparent_window(globalconf
.connection
,
214 globalconf
.screens
.tab
[phys_screen
].systray
.window
,
216 config_win_vals
[0], config_win_vals
[1]);
217 globalconf
.screens
.tab
[phys_screen
].systray
.parent
= wibox
->sw
.window
;
219 xcb_configure_window(globalconf
.connection
,
220 globalconf
.screens
.tab
[phys_screen
].systray
.window
,
222 | XCB_CONFIG_WINDOW_Y
223 | XCB_CONFIG_WINDOW_WIDTH
224 | XCB_CONFIG_WINDOW_HEIGHT
,
226 /* width = height = systray height */
227 config_win_vals
[2] = config_win_vals
[3] = systray
->geometry
.height
;
228 config_win_vals
[0] = 0;
231 return wibox_systray_kickout(phys_screen
);
233 switch(wibox
->sw
.orientation
)
236 config_win_vals
[1] = systray
->geometry
.width
- config_win_vals
[3];
237 for(int j
= 0; j
< globalconf
.embedded
.len
; j
++)
239 em
= &globalconf
.embedded
.tab
[j
];
240 if(em
->phys_screen
== phys_screen
)
242 if(config_win_vals
[1] - config_win_vals
[2] >= (uint32_t) wibox
->sw
.geometry
.y
)
244 xcb_map_window(globalconf
.connection
, em
->win
);
245 xcb_configure_window(globalconf
.connection
, em
->win
,
247 | XCB_CONFIG_WINDOW_Y
248 | XCB_CONFIG_WINDOW_WIDTH
249 | XCB_CONFIG_WINDOW_HEIGHT
,
251 config_win_vals
[1] -= config_win_vals
[3];
254 xcb_configure_window(globalconf
.connection
, em
->win
,
256 | XCB_CONFIG_WINDOW_Y
,
257 config_win_vals_off
);
262 config_win_vals
[1] = 0;
263 for(int j
= 0; j
< globalconf
.embedded
.len
; j
++)
265 em
= &globalconf
.embedded
.tab
[j
];
266 if(em
->phys_screen
== phys_screen
)
268 /* if(y + width <= wibox.y + systray.right) */
269 if(config_win_vals
[1] + config_win_vals
[3] <= (uint32_t) wibox
->sw
.geometry
.y
+ AREA_RIGHT(systray
->geometry
))
271 xcb_map_window(globalconf
.connection
, em
->win
);
272 xcb_configure_window(globalconf
.connection
, em
->win
,
274 | XCB_CONFIG_WINDOW_Y
275 | XCB_CONFIG_WINDOW_WIDTH
276 | XCB_CONFIG_WINDOW_HEIGHT
,
278 config_win_vals
[1] += config_win_vals
[3];
281 xcb_configure_window(globalconf
.connection
, em
->win
,
283 | XCB_CONFIG_WINDOW_Y
,
284 config_win_vals_off
);
289 config_win_vals
[1] = 0;
290 for(int j
= 0; j
< globalconf
.embedded
.len
; j
++)
292 em
= &globalconf
.embedded
.tab
[j
];
293 if(em
->phys_screen
== phys_screen
)
295 /* if(x + width < systray.x + systray.width) */
296 if(config_win_vals
[0] + config_win_vals
[2] <= (uint32_t) AREA_RIGHT(systray
->geometry
) + wibox
->sw
.geometry
.x
)
298 xcb_map_window(globalconf
.connection
, em
->win
);
299 xcb_configure_window(globalconf
.connection
, em
->win
,
301 | XCB_CONFIG_WINDOW_Y
302 | XCB_CONFIG_WINDOW_WIDTH
303 | XCB_CONFIG_WINDOW_HEIGHT
,
305 config_win_vals
[0] += config_win_vals
[2];
308 xcb_configure_window(globalconf
.connection
, em
->win
,
310 | XCB_CONFIG_WINDOW_Y
,
311 config_win_vals_off
);
321 /* Only called by wibox_position_update() */
323 wibox_position_update_floating(wibox_t
*wibox
)
325 area_t wingeom
= wibox
->sw
.geometry
;
327 /* We only make sure the wibox is at least 1x1 pixel big. */
328 wingeom
.width
= MAX(1, wibox
->sw
.geometry
.width
);
329 wingeom
.height
= MAX(1, wibox
->sw
.geometry
.height
);
331 if(wingeom
.width
!= wibox
->sw
.geometry
.width
332 || wingeom
.height
!= wibox
->sw
.geometry
.height
)
333 wibox_resize(wibox
, wingeom
.width
, wingeom
.height
);
336 /* Only called by wibox_position_update() */
338 wibox_position_update_non_floating(wibox_t
*wibox
)
340 area_t area
, wingeom
= wibox
->sw
.geometry
;
343 /* Everything we do below needs the wibox' screen.
344 * No screen, nothing to do.
349 /* This wibox limits the space available to clients and thus clients
350 * need to be repositioned.
352 wibox
->screen
->need_arrange
= true;
354 /* Place wibox'es at the edge of the screen, struts come later. */
355 area
= screen_area_get(wibox
->screen
, NULL
,
356 &wibox
->screen
->padding
, false);
358 /* Top and Bottom wibox_t have prio */
359 foreach(_w
, wibox
->screen
->wiboxes
)
362 /* Ignore every wibox after me that is in the same position */
368 else if((ignore
&& wibox
->position
== w
->position
) || !w
->isvisible
)
375 if(wibox
->position
== Left
)
376 area
.x
+= wibox
->sw
.geometry
.height
;
379 if(wibox
->position
== Right
)
380 area
.x
-= wibox
->sw
.geometry
.height
;
383 switch(wibox
->position
)
386 area
.y
+= w
->sw
.geometry
.height
;
390 area
.height
-= w
->sw
.geometry
.height
;
391 area
.y
+= w
->sw
.geometry
.height
;
398 switch(wibox
->position
)
401 area
.y
-= w
->sw
.geometry
.height
;
405 area
.height
-= w
->sw
.geometry
.height
;
414 /* The "length" of a wibox is always chosen to be the optimal size (non-floating).
415 * The "width" of a wibox is kept if it exists.
417 switch(wibox
->position
)
420 wingeom
.height
= area
.height
- 2 * wibox
->sw
.border
.width
;
421 wingeom
.width
= wibox
->sw
.geometry
.width
> 0 ? wibox
->sw
.geometry
.width
: 1.5 * globalconf
.font
->height
;
422 wingeom
.x
= area
.x
+ area
.width
- wingeom
.width
;
429 wingeom
.y
= area
.y
+ area
.height
- wingeom
.height
;
432 wingeom
.y
= (area
.y
+ area
.height
- wingeom
.height
) / 2;
437 wingeom
.height
= area
.height
- 2 * wibox
->sw
.border
.width
;
438 wingeom
.width
= wibox
->sw
.geometry
.width
> 0 ? wibox
->sw
.geometry
.width
: 1.5 * globalconf
.font
->height
;
443 wingeom
.y
= (area
.y
+ area
.height
) - wingeom
.height
;
449 wingeom
.y
= (area
.y
+ area
.height
- wingeom
.height
) / 2;
453 wingeom
.height
= wibox
->sw
.geometry
.height
> 0 ? wibox
->sw
.geometry
.height
: 1.5 * globalconf
.font
->height
;
454 wingeom
.width
= area
.width
- 2 * wibox
->sw
.border
.width
;
455 wingeom
.y
= (area
.y
+ area
.height
) - wingeom
.height
;
462 wingeom
.x
+= area
.width
- wingeom
.width
;
465 wingeom
.x
+= (area
.width
- wingeom
.width
) / 2;
470 wingeom
.height
= wibox
->sw
.geometry
.height
> 0 ? wibox
->sw
.geometry
.height
: 1.5 * globalconf
.font
->height
;
471 wingeom
.width
= area
.width
- 2 * wibox
->sw
.border
.width
;
479 wingeom
.x
+= area
.width
- wingeom
.width
;
482 wingeom
.x
+= (area
.width
- wingeom
.width
) / 2;
487 /* Floating wiboxes are not handled here, but in
488 * wibox_position_update_floating(), but the compiler insists...
493 /* same window size and position ? */
494 if(wingeom
.width
!= wibox
->sw
.geometry
.width
495 || wingeom
.height
!= wibox
->sw
.geometry
.height
)
496 wibox_resize(wibox
, wingeom
.width
, wingeom
.height
);
498 if(wingeom
.x
!= wibox
->sw
.geometry
.x
499 || wingeom
.y
!= wibox
->sw
.geometry
.y
)
500 wibox_move(wibox
, wingeom
.x
, wingeom
.y
);
503 /** Update the wibox position. It deletes every wibox resources and
505 * \param wibox The wibox.
508 wibox_position_update(wibox_t
*wibox
)
510 if(wibox
->position
== Floating
)
511 wibox_position_update_floating(wibox
);
513 wibox_position_update_non_floating(wibox
);
516 /** Get a wibox by its window.
517 * \param w The window id.
518 * \return A wibox if found, NULL otherwise.
521 wibox_getbywin(xcb_window_t win
)
523 foreach(screen
, globalconf
.screens
)
524 foreach(w
, screen
->wiboxes
)
525 if((*w
)->sw
.window
== win
)
528 foreach(_c
, globalconf
.clients
)
531 if(c
->titlebar
&& c
->titlebar
->sw
.window
== win
)
539 * \param wibox The wibox to draw.
542 wibox_draw(wibox_t
*wibox
)
546 widget_render(wibox
);
547 simplewindow_refresh_pixmap(&wibox
->sw
);
549 wibox
->need_update
= false;
552 wibox_systray_refresh(wibox
);
555 /** Refresh all wiboxes.
560 foreach(screen
, globalconf
.screens
)
561 foreach(w
, screen
->wiboxes
)
562 if((*w
)->need_update
)
565 foreach(_c
, globalconf
.clients
)
568 if(c
->titlebar
&& c
->titlebar
->need_update
)
569 wibox_draw(c
->titlebar
);
573 /** Reposition all wiboxes.
576 wibox_update_positions(void)
578 foreach(screen
, globalconf
.screens
)
579 foreach(w
, screen
->wiboxes
)
580 wibox_position_update(*w
);
583 /** Set a wibox visible or not.
584 * \param wibox The wibox.
585 * \param v The visible value.
588 wibox_setvisible(wibox_t
*wibox
, bool v
)
590 if(v
!= wibox
->isvisible
)
592 wibox
->isvisible
= v
;
593 wibox
->mouse_over
= NULL
;
595 if(wibox
->screen
!= NULL
)
600 xcb_unmap_window(globalconf
.connection
, wibox
->sw
.window
);
602 /* kick out systray if needed */
603 wibox_systray_refresh(wibox
);
605 /* All the other wibox and ourselves need to be repositioned */
606 foreach(w
, wibox
->screen
->wiboxes
)
607 wibox_position_update(*w
);
612 /** Remove a wibox from a screen.
613 * \param wibox Wibox to detach from screen.
616 wibox_detach(wibox_t
*wibox
)
618 if(wibox
->screen
!= NULL
)
622 /* save visible state */
623 v
= wibox
->isvisible
;
624 wibox
->isvisible
= false;
625 wibox_systray_refresh(wibox
);
626 wibox_position_update(wibox
);
627 /* restore position */
628 wibox
->isvisible
= v
;
630 wibox
->mouse_over
= NULL
;
632 simplewindow_wipe(&wibox
->sw
);
634 wibox
->screen
->need_arrange
= true;
636 foreach(item
, wibox
->screen
->wiboxes
)
639 wibox_array_remove(&wibox
->screen
->wiboxes
, item
);
643 wibox
->screen
= NULL
;
644 wibox_unref(globalconf
.L
, wibox
);
648 /** Attach a wibox that is on top of the stack.
649 * \param s The screen to attach the wibox to.
652 wibox_attach(screen_t
*s
)
654 int phys_screen
= screen_virttophys(screen_array_indexof(&globalconf
.screens
, s
));
656 wibox_t
*wibox
= wibox_ref(globalconf
.L
);
660 /* Set the wibox screen */
663 /* Check that the wibox coordinates matches the screen. */
665 screen_getbycoord(wibox
->screen
, wibox
->sw
.geometry
.x
, wibox
->sw
.geometry
.y
);
667 /* If it does not match, move it to the screen coordinates */
668 if(cscreen
!= wibox
->screen
)
669 wibox_move(wibox
, s
->geometry
.x
, s
->geometry
.y
);
671 wibox_array_append(&s
->wiboxes
, wibox
);
673 /* compute x/y/width/height if not set */
674 wibox_position_update(wibox
);
676 simplewindow_init(&wibox
->sw
, phys_screen
,
678 wibox
->sw
.border
.width
,
679 wibox
->sw
.orientation
,
680 &wibox
->sw
.ctx
.fg
, &wibox
->sw
.ctx
.bg
);
682 simplewindow_border_color_set(&wibox
->sw
, &wibox
->sw
.border
.color
);
684 simplewindow_cursor_set(&wibox
->sw
,
685 xcursor_new(globalconf
.connection
, xcursor_font_fromstr(wibox
->cursor
)));
687 /* All the other wibox and ourselves need to be repositioned */
688 foreach(w
, s
->wiboxes
)
689 wibox_position_update(*w
);
691 ewmh_update_workarea(phys_screen
);
696 wibox_need_update(wibox
);
699 /** Create a new wibox.
700 * \param L The Lua VM state.
703 * \lparam A table with optionaly defined values:
704 * position, align, fg, bg, border_width, border_color, ontop, width and height.
705 * \lreturn A brand new wibox.
708 luaA_wibox_new(lua_State
*L
)
713 xcolor_init_request_t reqs
[3];
714 int i
, reqs_nbr
= -1;
716 luaA_checktable(L
, 2);
719 w
->widgets_table
= LUA_REFNIL
;
721 w
->sw
.ctx
.fg
= globalconf
.colors
.fg
;
722 if((buf
= luaA_getopt_lstring(L
, 2, "fg", NULL
, &len
)))
723 reqs
[++reqs_nbr
] = xcolor_init_unchecked(&w
->sw
.ctx
.fg
, buf
, len
);
725 w
->sw
.ctx
.bg
= globalconf
.colors
.bg
;
726 if((buf
= luaA_getopt_lstring(L
, 2, "bg", NULL
, &len
)))
727 reqs
[++reqs_nbr
] = xcolor_init_unchecked(&w
->sw
.ctx
.bg
, buf
, len
);
729 w
->sw
.border
.color
= globalconf
.colors
.bg
;
730 if((buf
= luaA_getopt_lstring(L
, 2, "border_color", NULL
, &len
)))
731 reqs
[++reqs_nbr
] = xcolor_init_unchecked(&w
->sw
.border
.color
, buf
, len
);
733 w
->ontop
= luaA_getopt_boolean(L
, 2, "ontop", false);
735 buf
= luaA_getopt_lstring(L
, 2, "align", "left", &len
);
736 w
->align
= draw_align_fromstr(buf
, len
);
738 w
->sw
.border
.width
= luaA_getopt_number(L
, 2, "border_width", 0);
740 buf
= luaA_getopt_lstring(L
, 2, "position", "top", &len
);
742 switch((w
->position
= position_fromstr(buf
, len
)))
747 w
->sw
.orientation
= East
;
750 w
->sw
.orientation
= North
;
753 w
->sw
.orientation
= South
;
757 w
->sw
.geometry
.x
= luaA_getopt_number(L
, 2, "x", 0);
758 w
->sw
.geometry
.y
= luaA_getopt_number(L
, 2, "y", 0);
759 w
->sw
.geometry
.width
= luaA_getopt_number(L
, 2, "width", 0);
760 w
->sw
.geometry
.height
= luaA_getopt_number(L
, 2, "height", 0);
763 w
->cursor
= a_strdup("left_ptr");
765 w
->mouse_enter
= w
->mouse_leave
= LUA_REFNIL
;
767 for(i
= 0; i
<= reqs_nbr
; i
++)
768 xcolor_init_reply(reqs
[i
]);
773 /** Rebuild wibox widgets list.
774 * \param L The Lua VM state.
775 * \param wibox The wibox.
778 wibox_widgets_table_build(lua_State
*L
, wibox_t
*wibox
)
780 widget_node_array_wipe(&wibox
->widgets
);
781 widget_node_array_init(&wibox
->widgets
);
782 luaA_table2widgets(L
, &wibox
->widgets
);
783 wibox_need_update(wibox
);
786 /** Check if a wibox widget table has an item.
787 * \param L The Lua VM state.
788 * \param wibox The wibox.
789 * \param item The item to look for.
792 luaA_wibox_hasitem(lua_State
*L
, wibox_t
*wibox
, const void *item
)
794 if(wibox
->widgets_table
!= LUA_REFNIL
)
796 lua_rawgeti(globalconf
.L
, LUA_REGISTRYINDEX
, wibox
->widgets_table
);
797 if(lua_topointer(L
, -1) == item
|| luaA_hasitem(L
, item
))
803 /** Invalidate a wibox by a Lua object (table, etc).
804 * \param L The Lua VM state.
805 * \param item The object identifier.
808 luaA_wibox_invalidate_byitem(lua_State
*L
, const void *item
)
810 foreach(screen
, globalconf
.screens
)
811 foreach(w
, screen
->wiboxes
)
814 if(luaA_wibox_hasitem(L
, wibox
, item
))
816 /* recompute widget node list */
817 wibox_widgets_table_build(L
, wibox
);
818 lua_pop(L
, 1); /* remove widgets table */
823 foreach(_c
, globalconf
.clients
)
826 if(c
->titlebar
&& luaA_wibox_hasitem(L
, c
->titlebar
, item
))
828 /* recompute widget node list */
829 wibox_widgets_table_build(L
, c
->titlebar
);
830 lua_pop(L
, 1); /* remove widgets table */
836 * \param L The Lua VM state.
837 * \return The number of elements pushed on stack.
839 * \lfield screen Screen number.
840 * \lfield client The client attached to this titlebar.
841 * \lfield border_width Border width.
842 * \lfield border_color Border color.
843 * \lfield align The alignment.
844 * \lfield fg Foreground color.
845 * \lfield bg Background color.
846 * \lfield position The position.
847 * \lfield ontop On top of other windows.
848 * \lfield cursor The mouse cursor.
849 * \lfield mouse_enter A function to execute when the mouse enter the widget.
850 * \lfield mouse_leave A function to execute when the mouse leave the widget.
853 luaA_wibox_index(lua_State
*L
)
856 wibox_t
*wibox
= luaL_checkudata(L
, 1, "wibox");
857 const char *attr
= luaL_checklstring(L
, 2, &len
);
859 if(luaA_usemetatable(L
, 1, 2))
862 switch(a_tokenize(attr
, len
))
865 lua_pushboolean(L
, wibox
->isvisible
);
868 return client_push(L
, client_getbytitlebar(wibox
));
872 lua_pushnumber(L
, screen_array_indexof(&globalconf
.screens
, wibox
->screen
) + 1);
874 case A_TK_BORDER_WIDTH
:
875 lua_pushnumber(L
, wibox
->sw
.border
.width
);
877 case A_TK_BORDER_COLOR
:
878 luaA_pushxcolor(L
, &wibox
->sw
.border
.color
);
881 lua_pushstring(L
, draw_align_tostr(wibox
->align
));
884 luaA_pushxcolor(L
, &wibox
->sw
.ctx
.fg
);
887 luaA_pushxcolor(L
, &wibox
->sw
.ctx
.bg
);
890 image_push(L
, wibox
->bg_image
);
893 lua_pushstring(L
, position_tostr(wibox
->position
));
896 lua_pushboolean(L
, wibox
->ontop
);
898 case A_TK_ORIENTATION
:
899 lua_pushstring(L
, orientation_tostr(wibox
->sw
.orientation
));
902 if(wibox
->widgets_table
!= LUA_REFNIL
)
903 lua_rawgeti(L
, LUA_REGISTRYINDEX
, wibox
->widgets_table
);
908 lua_pushstring(L
, wibox
->cursor
);
913 if ((d
= window_opacity_get(wibox
->sw
.window
)) >= 0)
914 lua_pushnumber(L
, d
);
919 case A_TK_MOUSE_ENTER
:
920 if(wibox
->mouse_enter
!= LUA_REFNIL
)
921 lua_rawgeti(L
, LUA_REGISTRYINDEX
, wibox
->mouse_enter
);
925 case A_TK_MOUSE_LEAVE
:
926 if(wibox
->mouse_leave
!= LUA_REFNIL
)
927 lua_rawgeti(L
, LUA_REGISTRYINDEX
, wibox
->mouse_leave
);
938 /* Set or get the wibox geometry.
939 * \param L The Lua VM state.
940 * \return The number of elements pushed on stack.
942 * \lparam An optional table with wibox geometry.
943 * \lreturn The wibox geometry.
946 luaA_wibox_geometry(lua_State
*L
)
948 wibox_t
*wibox
= luaL_checkudata(L
, 1, "wibox");
950 if(lua_gettop(L
) == 2)
954 luaA_checktable(L
, 2);
955 wingeom
.x
= luaA_getopt_number(L
, 2, "x", wibox
->sw
.geometry
.x
);
956 wingeom
.y
= luaA_getopt_number(L
, 2, "y", wibox
->sw
.geometry
.y
);
957 wingeom
.width
= luaA_getopt_number(L
, 2, "width", wibox
->sw
.geometry
.width
);
958 wingeom
.height
= luaA_getopt_number(L
, 2, "height", wibox
->sw
.geometry
.height
);
962 case WIBOX_TYPE_TITLEBAR
:
963 wibox_resize(wibox
, wingeom
.width
, wingeom
.height
);
965 case WIBOX_TYPE_NORMAL
:
966 if(wibox
->position
== Floating
)
967 wibox_moveresize(wibox
, wingeom
);
968 else if(wingeom
.width
!= wibox
->sw
.geometry
.width
969 || wingeom
.height
!= wibox
->sw
.geometry
.height
)
971 wibox_resize(wibox
, wingeom
.width
, wingeom
.height
);
972 wibox
->screen
->need_arrange
= true;
978 return luaA_pusharea(L
, wibox
->sw
.geometry
);
982 * \param L The Lua VM state.
983 * \return The number of elements pushed on stack.
986 luaA_wibox_newindex(lua_State
*L
)
989 wibox_t
*wibox
= luaL_checkudata(L
, 1, "wibox");
990 const char *buf
, *attr
= luaL_checklstring(L
, 2, &len
);
993 switch((tok
= a_tokenize(attr
, len
)))
998 if((buf
= luaL_checklstring(L
, 3, &len
)))
999 if(xcolor_init_reply(xcolor_init_unchecked(&wibox
->sw
.ctx
.fg
, buf
, len
)))
1000 wibox
->need_update
= true;
1003 if((buf
= luaL_checklstring(L
, 3, &len
)))
1004 if(xcolor_init_reply(xcolor_init_unchecked(&wibox
->sw
.ctx
.bg
, buf
, len
)))
1005 wibox
->need_update
= true;
1008 image_unref(L
, wibox
->bg_image
);
1009 wibox
->bg_image
= image_ref(L
);
1010 wibox
->need_update
= true;
1013 buf
= luaL_checklstring(L
, 3, &len
);
1014 wibox
->align
= draw_align_fromstr(buf
, len
);
1017 case WIBOX_TYPE_NORMAL
:
1018 wibox_position_update(wibox
);
1020 case WIBOX_TYPE_TITLEBAR
:
1021 titlebar_update_geometry(client_getbytitlebar(wibox
));
1028 case WIBOX_TYPE_TITLEBAR
:
1029 return luaA_titlebar_newindex(L
, wibox
, tok
);
1030 case WIBOX_TYPE_NORMAL
:
1031 if((buf
= luaL_checklstring(L
, 3, &len
)))
1032 wibox_setposition(wibox
, position_fromstr(buf
, len
));
1039 titlebar_client_detach(client_getbytitlebar(wibox
));
1042 client_t
*c
= luaA_client_checkudata(L
, -1);
1043 lua_pushvalue(L
, 1);
1044 titlebar_client_attach(c
);
1048 if((buf
= luaL_checkstring(L
, 3)))
1050 uint16_t cursor_font
= xcursor_font_fromstr(buf
);
1053 xcb_cursor_t cursor
= xcursor_new(globalconf
.connection
, cursor_font
);
1054 p_delete(&wibox
->cursor
);
1055 wibox
->cursor
= a_strdup(buf
);
1056 simplewindow_cursor_set(&wibox
->sw
, cursor
);
1063 wibox_detach(wibox
);
1064 titlebar_client_detach(client_getbytitlebar(wibox
));
1068 int screen
= luaL_checknumber(L
, 3) - 1;
1069 luaA_checkscreen(screen
);
1070 if(!wibox
->screen
|| screen
!= screen_array_indexof(&globalconf
.screens
, wibox
->screen
))
1072 titlebar_client_detach(client_getbytitlebar(wibox
));
1073 lua_pushvalue(L
, 1);
1074 wibox_attach(&globalconf
.screens
.tab
[screen
]);
1079 b
= luaA_checkboolean(L
, 3);
1080 if(b
!= wibox
->ontop
)
1086 case A_TK_ORIENTATION
:
1087 if((buf
= luaL_checklstring(L
, 3, &len
)))
1089 simplewindow_orientation_set(&wibox
->sw
, orientation_fromstr(buf
, len
));
1090 wibox_need_update(wibox
);
1093 case A_TK_BORDER_COLOR
:
1094 if((buf
= luaL_checklstring(L
, 3, &len
)))
1095 if(xcolor_init_reply(xcolor_init_unchecked(&wibox
->sw
.border
.color
, buf
, len
)))
1096 if(wibox
->sw
.window
)
1097 simplewindow_border_color_set(&wibox
->sw
, &wibox
->sw
.border
.color
);
1100 b
= luaA_checkboolean(L
, 3);
1101 if(b
!= wibox
->isvisible
)
1104 case WIBOX_TYPE_NORMAL
:
1105 wibox_setvisible(wibox
, b
);
1107 case WIBOX_TYPE_TITLEBAR
:
1108 titlebar_set_visible(wibox
, b
);
1113 if(luaA_isloop(L
, 3))
1115 luaA_warn(L
, "table is looping, cannot use this as widget table");
1118 /* register object */
1119 luaA_register(L
, 3, &wibox
->widgets_table
);
1120 /* duplicate table because next function will eat it */
1121 lua_pushvalue(L
, -1);
1122 /* recompute widget node list */
1123 wibox_widgets_table_build(L
, wibox
);
1124 luaA_table2wtable(L
);
1128 window_opacity_set(wibox
->sw
.window
, -1);
1131 double d
= luaL_checknumber(L
, 3);
1132 if(d
>= 0 && d
<= 1)
1133 window_opacity_set(wibox
->sw
.window
, d
);
1136 case A_TK_MOUSE_ENTER
:
1137 luaA_registerfct(L
, 3, &wibox
->mouse_enter
);
1139 case A_TK_MOUSE_LEAVE
:
1140 luaA_registerfct(L
, 3, &wibox
->mouse_leave
);
1145 case WIBOX_TYPE_TITLEBAR
:
1146 return luaA_titlebar_newindex(L
, wibox
, tok
);
1147 case WIBOX_TYPE_NORMAL
:
1155 /** Get or set mouse buttons bindings to a wibox.
1156 * \param L The Lua VM state.
1159 * \lparam An array of mouse button bindings objects, or nothing.
1160 * \return The array of mouse button bindings objects of this wibox.
1163 luaA_wibox_buttons(lua_State
*L
)
1165 wibox_t
*wibox
= luaL_checkudata(L
, 1, "wibox");
1166 button_array_t
*buttons
= &wibox
->buttons
;
1168 if(lua_gettop(L
) == 2)
1170 luaA_button_array_set(L
, 2, buttons
);
1174 return luaA_button_array_get(L
, buttons
);
1177 const struct luaL_reg awesome_wibox_methods
[] =
1179 { "__call", luaA_wibox_new
},
1182 const struct luaL_reg awesome_wibox_meta
[] =
1184 { "buttons", luaA_wibox_buttons
},
1185 { "geometry", luaA_wibox_geometry
},
1186 { "__index", luaA_wibox_index
},
1187 { "__newindex", luaA_wibox_newindex
},
1188 { "__gc", luaA_wibox_gc
},
1189 { "__tostring", luaA_wibox_tostring
},
1193 // vim: filetype=c:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=80