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.
28 extern awesome_t globalconf
;
30 DO_LUA_NEW(extern, wibox_t
, wibox
, "wibox", wibox_ref
)
31 DO_LUA_GC(wibox_t
, wibox
, "wibox", wibox_unref
)
32 DO_LUA_EQ(wibox_t
, wibox
, "wibox")
35 wibox_move(wibox_t
*wibox
, int16_t x
, int16_t y
)
38 simplewindow_move(&wibox
->sw
, x
, y
);
41 wibox
->sw
.geometry
.x
= x
;
42 wibox
->sw
.geometry
.y
= y
;
47 wibox_resize(wibox_t
*wibox
, uint16_t width
, uint16_t height
)
50 simplewindow_resize(&wibox
->sw
, width
, height
);
53 wibox
->sw
.geometry
.width
= width
;
54 wibox
->sw
.geometry
.height
= height
;
56 wibox
->need_update
= true;
60 wibox_setposition(wibox_t
*wibox
, position_t p
)
62 if(p
!= wibox
->position
)
64 switch((wibox
->position
= p
))
69 simplewindow_orientation_set(&wibox
->sw
, East
);
72 simplewindow_orientation_set(&wibox
->sw
, North
);
75 simplewindow_orientation_set(&wibox
->sw
, South
);
78 /* reset width/height to 0 */
79 if(wibox
->position
!= Floating
)
80 wibox
->sw
.geometry
.width
= wibox
->sw
.geometry
.height
= 0;
82 /* recompute position */
83 wibox_position_update(wibox
);
85 /* reset all wibox position */
86 wibox_array_t
*w
= &globalconf
.screens
[wibox
->screen
].wiboxes
;
87 for(int i
= 0; i
< w
->len
; i
++)
88 wibox_position_update(w
->tab
[i
]);
90 ewmh_update_workarea(screen_virttophys(wibox
->screen
));
92 wibox
->need_update
= true;
96 /** Kick out systray windows.
97 * \param phys_screen Physical screen number.
100 wibox_systray_kickout(int phys_screen
)
102 xcb_screen_t
*s
= xutil_screen_get(globalconf
.connection
, phys_screen
);
104 /* Who! Check that we're not deleting a wibox with a systray, because it
105 * may be its parent. If so, we reparent to root before, otherwise it will
107 xcb_reparent_window(globalconf
.connection
,
108 globalconf
.screens
[phys_screen
].systray
.window
,
109 s
->root
, -512, -512);
111 globalconf
.screens
[phys_screen
].systray
.parent
= s
->root
;
115 wibox_systray_refresh(wibox_t
*wibox
)
117 if(wibox
->screen
== SCREEN_UNDEF
)
120 for(int i
= 0; i
< wibox
->widgets
.len
; i
++)
122 widget_node_t
*systray
= &wibox
->widgets
.tab
[i
];
123 if(systray
->widget
->type
== systray_new
)
125 uint32_t config_back
[] = { wibox
->sw
.ctx
.bg
.pixel
};
126 uint32_t config_win_vals
[4];
127 uint32_t config_win_vals_off
[2] = { -512, -512 };
130 int phys_screen
= wibox
->sw
.ctx
.phys_screen
;
133 && systray
->widget
->isvisible
134 && systray
->area
.width
)
136 pos
= wibox
->position
;
138 /* Set background of the systray window. */
139 xcb_change_window_attributes(globalconf
.connection
,
140 globalconf
.screens
[phys_screen
].systray
.window
,
141 XCB_CW_BACK_PIXEL
, config_back
);
143 xcb_map_window(globalconf
.connection
, globalconf
.screens
[phys_screen
].systray
.window
);
145 switch(wibox
->position
)
148 config_win_vals
[0] = systray
->area
.y
;
149 config_win_vals
[1] = wibox
->sw
.geometry
.height
- systray
->area
.x
- systray
->area
.width
;
150 config_win_vals
[2] = systray
->area
.height
;
151 config_win_vals
[3] = systray
->area
.width
;
154 config_win_vals
[0] = systray
->area
.y
;
155 config_win_vals
[1] = systray
->area
.x
;
156 config_win_vals
[2] = systray
->area
.height
;
157 config_win_vals
[3] = systray
->area
.width
;
160 config_win_vals
[0] = systray
->area
.x
;
161 config_win_vals
[1] = systray
->area
.y
;
162 config_win_vals
[2] = systray
->area
.width
;
163 config_win_vals
[3] = systray
->area
.height
;
167 if(globalconf
.screens
[phys_screen
].systray
.parent
!= wibox
->sw
.window
)
169 xcb_reparent_window(globalconf
.connection
,
170 globalconf
.screens
[phys_screen
].systray
.window
,
172 config_win_vals
[0], config_win_vals
[1]);
173 globalconf
.screens
[phys_screen
].systray
.parent
= wibox
->sw
.window
;
175 xcb_configure_window(globalconf
.connection
,
176 globalconf
.screens
[phys_screen
].systray
.window
,
178 | XCB_CONFIG_WINDOW_Y
179 | XCB_CONFIG_WINDOW_WIDTH
180 | XCB_CONFIG_WINDOW_HEIGHT
,
182 /* width = height = systray height */
183 config_win_vals
[2] = config_win_vals
[3] = systray
->area
.height
;
184 config_win_vals
[0] = 0;
187 return wibox_systray_kickout(phys_screen
);
192 config_win_vals
[1] = systray
->area
.width
- config_win_vals
[3];
193 for(em
= globalconf
.embedded
; em
; em
= em
->next
)
194 if(em
->phys_screen
== phys_screen
)
196 if(config_win_vals
[1] - config_win_vals
[2] >= (uint32_t) wibox
->sw
.geometry
.y
)
198 xcb_map_window(globalconf
.connection
, em
->win
);
199 xcb_configure_window(globalconf
.connection
, em
->win
,
201 | XCB_CONFIG_WINDOW_Y
202 | XCB_CONFIG_WINDOW_WIDTH
203 | XCB_CONFIG_WINDOW_HEIGHT
,
205 config_win_vals
[1] -= config_win_vals
[3];
208 xcb_configure_window(globalconf
.connection
, em
->win
,
210 | XCB_CONFIG_WINDOW_Y
,
211 config_win_vals_off
);
215 config_win_vals
[1] = 0;
216 for(em
= globalconf
.embedded
; em
; em
= em
->next
)
217 if(em
->phys_screen
== phys_screen
)
219 if(config_win_vals
[1] + config_win_vals
[3] <= (uint32_t) wibox
->sw
.geometry
.y
+ wibox
->sw
.geometry
.width
)
221 xcb_map_window(globalconf
.connection
, em
->win
);
222 xcb_configure_window(globalconf
.connection
, em
->win
,
224 | XCB_CONFIG_WINDOW_Y
225 | XCB_CONFIG_WINDOW_WIDTH
226 | XCB_CONFIG_WINDOW_HEIGHT
,
228 config_win_vals
[1] += config_win_vals
[3];
231 xcb_configure_window(globalconf
.connection
, em
->win
,
233 | XCB_CONFIG_WINDOW_Y
,
234 config_win_vals_off
);
240 config_win_vals
[1] = 0;
241 for(em
= globalconf
.embedded
; em
; em
= em
->next
)
242 if(em
->phys_screen
== phys_screen
)
244 /* if(x + width < systray.x + systray.width) */
245 if(config_win_vals
[0] + config_win_vals
[2] <= (uint32_t) AREA_RIGHT(systray
->area
) + wibox
->sw
.geometry
.x
)
247 xcb_map_window(globalconf
.connection
, em
->win
);
248 xcb_configure_window(globalconf
.connection
, em
->win
,
250 | XCB_CONFIG_WINDOW_Y
251 | XCB_CONFIG_WINDOW_WIDTH
252 | XCB_CONFIG_WINDOW_HEIGHT
,
254 config_win_vals
[0] += config_win_vals
[2];
257 xcb_configure_window(globalconf
.connection
, em
->win
,
259 | XCB_CONFIG_WINDOW_Y
,
260 config_win_vals_off
);
269 /** Update the wibox position. It deletes every wibox resources and
271 * \param wibox The wibox.
274 wibox_position_update(wibox_t
*wibox
)
276 area_t area
, wingeom
= wibox
->sw
.geometry
;
279 globalconf
.screens
[wibox
->screen
].need_arrange
= true;
281 area
= screen_area_get(wibox
->screen
, NULL
,
282 &globalconf
.screens
[wibox
->screen
].padding
, true);
284 /* Top and Bottom wibox_t have prio */
285 for(int i
= 0; i
< globalconf
.screens
[wibox
->screen
].wiboxes
.len
; i
++)
287 wibox_t
*w
= globalconf
.screens
[wibox
->screen
].wiboxes
.tab
[i
];
288 /* Ignore every wibox after me that is in the same position */
294 else if((ignore
&& wibox
->position
== w
->position
) || !w
->isvisible
)
301 switch(wibox
->position
)
304 area
.x
+= wibox
->sw
.geometry
.height
;
311 switch(wibox
->position
)
314 area
.x
-= wibox
->sw
.geometry
.height
;
321 switch(wibox
->position
)
324 area
.y
+= w
->sw
.geometry
.height
;
328 area
.height
-= w
->sw
.geometry
.height
;
329 area
.y
+= w
->sw
.geometry
.height
;
336 switch(wibox
->position
)
339 area
.y
-= w
->sw
.geometry
.height
;
343 area
.height
-= w
->sw
.geometry
.height
;
352 switch(wibox
->position
)
355 wingeom
.height
= wibox
->sw
.geometry
.height
> 0 ? wibox
->sw
.geometry
.height
: area
.height
;
356 wingeom
.width
= wibox
->sw
.geometry
.width
> 0 ? wibox
->sw
.geometry
.width
: 1.5 * globalconf
.font
->height
;
360 wingeom
.x
= area
.x
+ area
.width
- wingeom
.width
;
364 wingeom
.x
= area
.x
+ area
.width
- wingeom
.width
;
365 wingeom
.y
= area
.y
+ area
.height
- wingeom
.height
;
368 wingeom
.x
= area
.x
+ area
.width
- wingeom
.width
;
369 wingeom
.y
= (area
.y
+ area
.height
- wingeom
.height
) / 2;
374 wingeom
.height
= wibox
->sw
.geometry
.height
> 0 ? wibox
->sw
.geometry
.height
: area
.height
;
375 wingeom
.width
= wibox
->sw
.geometry
.width
> 0 ? wibox
->sw
.geometry
.width
: 1.5 * globalconf
.font
->height
;
380 wingeom
.y
= (area
.y
+ area
.height
) - wingeom
.height
;
388 wingeom
.y
= (area
.y
+ area
.height
- wingeom
.height
) / 2;
392 wingeom
.height
= wibox
->sw
.geometry
.height
> 0 ? wibox
->sw
.geometry
.height
: 1.5 * globalconf
.font
->height
;
393 wingeom
.width
= wibox
->sw
.geometry
.width
> 0 ? wibox
->sw
.geometry
.width
: area
.width
;
398 wingeom
.y
= (area
.y
+ area
.height
) - wingeom
.height
;
401 wingeom
.x
= area
.x
+ area
.width
- wingeom
.width
;
402 wingeom
.y
= (area
.y
+ area
.height
) - wingeom
.height
;
405 wingeom
.x
= area
.x
+ (area
.width
- wingeom
.width
) / 2;
406 wingeom
.y
= (area
.y
+ area
.height
) - wingeom
.height
;
411 wingeom
.height
= wibox
->sw
.geometry
.height
> 0 ? wibox
->sw
.geometry
.height
: 1.5 * globalconf
.font
->height
;
412 wingeom
.width
= wibox
->sw
.geometry
.width
> 0 ? wibox
->sw
.geometry
.width
: area
.width
;
420 wingeom
.x
= area
.x
+ area
.width
- wingeom
.width
;
424 wingeom
.x
= area
.x
+ (area
.width
- wingeom
.width
) / 2;
433 /* same window size and position ? */
434 if(wingeom
.width
!= wibox
->sw
.geometry
.width
435 || wingeom
.height
!= wibox
->sw
.geometry
.height
)
436 wibox_resize(wibox
, wingeom
.width
, wingeom
.height
);
438 if(wingeom
.x
!= wibox
->sw
.geometry
.x
439 || wingeom
.y
!= wibox
->sw
.geometry
.y
)
440 wibox_move(wibox
, wingeom
.x
, wingeom
.y
);
444 * \param wibox wibox to delete.
447 wibox_delete(wibox_t
**wibox
)
449 simplewindow_wipe(&(*wibox
)->sw
);
450 luaL_unref(globalconf
.L
, LUA_REGISTRYINDEX
, (*wibox
)->widgets_table
);
451 widget_node_array_wipe(&(*wibox
)->widgets
);
455 /** Get a wibox by its window.
456 * \param w The window id.
457 * \return A wibox if found, NULL otherwise.
460 wibox_getbywin(xcb_window_t w
)
462 for(int screen
= 0; screen
< globalconf
.nscreen
; screen
++)
463 for(int i
= 0; i
< globalconf
.screens
[screen
].wiboxes
.len
; i
++)
465 wibox_t
*s
= globalconf
.screens
[screen
].wiboxes
.tab
[i
];
466 if(s
->sw
.window
== w
)
470 for(client_t
*c
= globalconf
.clients
; c
; c
= c
->next
)
471 if(c
->titlebar
&& c
->titlebar
->sw
.window
== w
)
478 * \param wibox The wibox to draw.
481 wibox_draw(wibox_t
*wibox
)
485 widget_render(&wibox
->widgets
, &wibox
->sw
.ctx
, wibox
->sw
.gc
,
487 wibox
->screen
, wibox
->sw
.orientation
,
488 wibox
->sw
.geometry
.x
, wibox
->sw
.geometry
.y
,
490 simplewindow_refresh_pixmap(&wibox
->sw
);
492 wibox
->need_update
= false;
495 wibox_systray_refresh(wibox
);
498 /** Refresh all wiboxes.
503 for(int screen
= 0; screen
< globalconf
.nscreen
; screen
++)
504 for(int i
= 0; i
< globalconf
.screens
[screen
].wiboxes
.len
; i
++)
506 wibox_t
*s
= globalconf
.screens
[screen
].wiboxes
.tab
[i
];
511 for(client_t
*c
= globalconf
.clients
; c
; c
= c
->next
)
512 if(c
->titlebar
&& c
->titlebar
->need_update
)
513 wibox_draw(c
->titlebar
);
516 /** Set a wibox visible or not.
517 * \param wibox The wibox.
518 * \param v The visible value.
521 wibox_setvisible(wibox_t
*wibox
, bool v
)
523 if(v
!= wibox
->isvisible
)
525 if((wibox
->isvisible
= v
))
526 xcb_map_window(globalconf
.connection
, wibox
->sw
.window
);
528 xcb_unmap_window(globalconf
.connection
, wibox
->sw
.window
);
529 /* kick out systray if needed */
530 wibox_systray_refresh(wibox
);
532 /* All the other wibox and ourselves need to be repositioned */
533 wibox_array_t
*w
= &globalconf
.screens
[wibox
->screen
].wiboxes
;
534 for(int i
= 0; i
< w
->len
; i
++)
535 wibox_position_update(w
->tab
[i
]);
539 /** Remove a wibox from a screen.
540 * \param wibox Wibox to detach from screen.
543 wibox_detach(wibox_t
*wibox
)
545 if(wibox
->screen
!= SCREEN_UNDEF
)
549 /* save visible state */
550 v
= wibox
->isvisible
;
551 wibox
->isvisible
= false;
552 wibox_position_update(wibox
);
553 /* restore position */
554 wibox
->isvisible
= v
;
556 simplewindow_wipe(&wibox
->sw
);
558 for(int i
= 0; i
< globalconf
.screens
[wibox
->screen
].wiboxes
.len
; i
++)
559 if(globalconf
.screens
[wibox
->screen
].wiboxes
.tab
[i
] == wibox
)
561 wibox_array_take(&globalconf
.screens
[wibox
->screen
].wiboxes
, i
);
564 globalconf
.screens
[wibox
->screen
].need_arrange
= true;
565 wibox
->screen
= SCREEN_UNDEF
;
571 * \param wibox The wibox to attach.
572 * \param s The screen to attach the wibox to.
575 wibox_attach(wibox_t
*wibox
, screen_t
*s
)
577 int phys_screen
= screen_virttophys(s
->index
);
581 wibox
->screen
= s
->index
;
583 wibox_array_append(&s
->wiboxes
, wibox_ref(&wibox
));
585 /* compute x/y/width/height if not set */
586 wibox_position_update(wibox
);
588 simplewindow_init(&wibox
->sw
, phys_screen
,
590 wibox
->sw
.border
.width
,
591 wibox
->sw
.orientation
,
592 &wibox
->sw
.ctx
.fg
, &wibox
->sw
.ctx
.bg
);
594 simplewindow_border_color_set(&wibox
->sw
, &wibox
->sw
.border
.color
);
596 wibox
->need_update
= true;
599 xcb_map_window(globalconf
.connection
, wibox
->sw
.window
);
601 /* All the other wibox and ourselves need to be repositioned */
602 for(int i
= 0; i
< s
->wiboxes
.len
; i
++)
603 wibox_position_update(s
->wiboxes
.tab
[i
]);
605 ewmh_update_workarea(screen_virttophys(s
->index
));
609 /** Convert a wibox to a printable string.
610 * \param L The Lua VM state.
616 luaA_wibox_tostring(lua_State
*L
)
618 wibox_t
**p
= luaA_checkudata(L
, 1, "wibox");
619 lua_pushfstring(L
, "[wibox udata(%p)]", *p
);
623 /** Create a new wibox.
624 * \param L The Lua VM state.
627 * \lparam A table with optionaly defined values:
628 * position, align, fg, bg, border_width, border_color, width and height.
629 * \lreturn A brand new wibox.
632 luaA_wibox_new(lua_State
*L
)
637 xcolor_init_request_t reqs
[3];
638 int8_t i
, reqs_nbr
= -1;
640 luaA_checktable(L
, 2);
642 w
= p_new(wibox_t
, 1);
643 w
->widgets_table
= LUA_REFNIL
;
645 w
->sw
.ctx
.fg
= globalconf
.colors
.fg
;
646 if((buf
= luaA_getopt_lstring(L
, 2, "fg", NULL
, &len
)))
647 reqs
[++reqs_nbr
] = xcolor_init_unchecked(&w
->sw
.ctx
.fg
, buf
, len
);
649 w
->sw
.ctx
.bg
= globalconf
.colors
.bg
;
650 if((buf
= luaA_getopt_lstring(L
, 2, "bg", NULL
, &len
)))
651 reqs
[++reqs_nbr
] = xcolor_init_unchecked(&w
->sw
.ctx
.bg
, buf
, len
);
653 w
->sw
.border
.color
= globalconf
.colors
.bg
;
654 if((buf
= luaA_getopt_lstring(L
, 2, "border_color", NULL
, &len
)))
655 reqs
[++reqs_nbr
] = xcolor_init_unchecked(&w
->sw
.border
.color
, buf
, len
);
657 buf
= luaA_getopt_lstring(L
, 2, "align", "left", &len
);
658 w
->align
= draw_align_fromstr(buf
, len
);
660 w
->sw
.border
.width
= luaA_getopt_number(L
, 2, "border_width", 0);
662 buf
= luaA_getopt_lstring(L
, 2, "position", "top", &len
);
664 switch((w
->position
= position_fromstr(buf
, len
)))
669 simplewindow_orientation_set(&w
->sw
, East
);
672 simplewindow_orientation_set(&w
->sw
, North
);
675 simplewindow_orientation_set(&w
->sw
, South
);
679 /* recompute position */
680 wibox_position_update(w
);
682 w
->sw
.geometry
.width
= luaA_getopt_number(L
, 2, "width", 0);
683 w
->sw
.geometry
.height
= luaA_getopt_number(L
, 2, "height", 0);
685 w
->screen
= SCREEN_UNDEF
;
688 for(i
= 0; i
<= reqs_nbr
; i
++)
689 xcolor_init_reply(reqs
[i
]);
691 return luaA_wibox_userdata_new(L
, w
);
694 /** Rebuild wibox widgets list.
695 * \param L The Lua VM state.
696 * \param wibox The wibox.
699 wibox_widgets_table_build(lua_State
*L
, wibox_t
*wibox
)
701 widget_node_array_wipe(&wibox
->widgets
);
702 widget_node_array_init(&wibox
->widgets
);
703 luaA_table2widgets(L
, &wibox
->widgets
);
704 wibox
->mouse_over
= NULL
;
705 wibox
->need_update
= true;
708 /** Check if a wibox widget table has an item.
709 * \param L The Lua VM state.
710 * \param wibox The wibox.
711 * \param item The item to look for.
714 luaA_wibox_hasitem(lua_State
*L
, wibox_t
*wibox
, const void *item
)
717 if(wibox
->widgets_table
!= LUA_REFNIL
)
719 lua_rawgeti(globalconf
.L
, LUA_REGISTRYINDEX
, wibox
->widgets_table
);
720 if(lua_topointer(L
, -1) == item
|| luaA_hasitem(L
, item
))
726 /** Invalidate a wibox by a Lua object (table, etc).
727 * \param L The Lua VM state.
728 * \param item The object identifier.
731 luaA_wibox_invalidate_byitem(lua_State
*L
, const void *item
)
733 for(int screen
= 0; screen
< globalconf
.nscreen
; screen
++)
734 for(int i
= 0; i
< globalconf
.screens
[screen
].wiboxes
.len
; i
++)
736 wibox_t
*wibox
= globalconf
.screens
[screen
].wiboxes
.tab
[i
];
737 if(luaA_wibox_hasitem(L
, wibox
, item
))
739 /* recompute widget node list */
740 wibox_widgets_table_build(L
, wibox
);
741 lua_pop(L
, 1); /* remove widgets table */
746 for(client_t
*c
= globalconf
.clients
; c
; c
= c
->next
)
747 if(c
->titlebar
&& luaA_wibox_hasitem(L
, c
->titlebar
, item
))
749 /* recompute widget node list */
750 wibox_widgets_table_build(L
, c
->titlebar
);
751 lua_pop(L
, 1); /* remove widgets table */
757 * \param L The Lua VM state.
758 * \return The number of elements pushed on stack.
760 * \lfield screen Screen number.
761 * \lfield client The client attached to this titlebar.
762 * \lfield border_width Border width.
763 * \lfield border_color Border color.
764 * \lfield align The alignment.
765 * \lfield fg Foreground color.
766 * \lfield bg Background color.
767 * \lfield position The position.
768 * \lfield ontop On top of other windows.
771 luaA_wibox_index(lua_State
*L
)
774 wibox_t
**wibox
= luaA_checkudata(L
, 1, "wibox");
775 const char *attr
= luaL_checklstring(L
, 2, &len
);
777 if(luaA_usemetatable(L
, 1, 2))
780 switch(a_tokenize(attr
, len
))
785 lua_pushboolean(L
, (*wibox
)->isvisible
);
788 if((c
= client_getbytitlebar(*wibox
)))
789 return luaA_client_userdata_new(L
, c
);
793 if((*wibox
)->screen
== SCREEN_UNDEF
)
795 lua_pushnumber(L
, (*wibox
)->screen
+ 1);
797 case A_TK_BORDER_WIDTH
:
798 lua_pushnumber(L
, (*wibox
)->sw
.border
.width
);
800 case A_TK_BORDER_COLOR
:
801 luaA_pushcolor(L
, &(*wibox
)->sw
.border
.color
);
804 lua_pushstring(L
, draw_align_tostr((*wibox
)->align
));
807 luaA_pushcolor(L
, &(*wibox
)->sw
.ctx
.fg
);
810 luaA_pushcolor(L
, &(*wibox
)->sw
.ctx
.bg
);
813 lua_pushstring(L
, position_tostr((*wibox
)->position
));
816 lua_pushboolean(L
, (*wibox
)->ontop
);
818 case A_TK_ORIENTATION
:
819 lua_pushstring(L
, orientation_tostr((*wibox
)->sw
.orientation
));
822 if((*wibox
)->widgets_table
!= LUA_REFNIL
)
823 lua_rawgeti(L
, LUA_REGISTRYINDEX
, (*wibox
)->widgets_table
);
834 /* Set or get the wibox geometry.
835 * \param L The Lua VM state.
836 * \return The number of elements pushed on stack.
838 * \lparam An optional table with wibox geometry.
839 * \lreturn The wibox geometry.
842 luaA_wibox_geometry(lua_State
*L
)
844 wibox_t
**wibox
= luaA_checkudata(L
, 1, "wibox");
846 if(lua_gettop(L
) == 2)
850 luaA_checktable(L
, 2);
851 wingeom
.x
= luaA_getopt_number(L
, 2, "x", (*wibox
)->sw
.geometry
.x
);
852 wingeom
.y
= luaA_getopt_number(L
, 2, "y", (*wibox
)->sw
.geometry
.y
);
853 wingeom
.width
= luaA_getopt_number(L
, 2, "width", (*wibox
)->sw
.geometry
.width
);
854 wingeom
.height
= luaA_getopt_number(L
, 2, "height", (*wibox
)->sw
.geometry
.height
);
856 switch((*wibox
)->type
)
858 case WIBOX_TYPE_TITLEBAR
:
859 wibox_resize(*wibox
, wingeom
.width
, wingeom
.height
);
861 case WIBOX_TYPE_NORMAL
:
862 if((*wibox
)->position
== Floating
)
863 wibox_moveresize(*wibox
, wingeom
);
864 else if(wingeom
.width
!= (*wibox
)->sw
.geometry
.width
865 || wingeom
.height
!= (*wibox
)->sw
.geometry
.height
)
867 wibox_resize(*wibox
, wingeom
.width
, wingeom
.height
);
868 globalconf
.screens
[(*wibox
)->screen
].need_arrange
= true;
874 return luaA_pusharea(L
, (*wibox
)->sw
.geometry
);
878 * \param L The Lua VM state.
879 * \return The number of elements pushed on stack.
882 luaA_wibox_newindex(lua_State
*L
)
885 wibox_t
**wibox
= luaA_checkudata(L
, 1, "wibox");
886 const char *buf
, *attr
= luaL_checklstring(L
, 2, &len
);
889 switch((tok
= a_tokenize(attr
, len
)))
894 if((buf
= luaL_checklstring(L
, 3, &len
)))
895 if(xcolor_init_reply(xcolor_init_unchecked(&(*wibox
)->sw
.ctx
.fg
, buf
, len
)))
896 (*wibox
)->need_update
= true;
899 if((buf
= luaL_checklstring(L
, 3, &len
)))
900 if(xcolor_init_reply(xcolor_init_unchecked(&(*wibox
)->sw
.ctx
.bg
, buf
, len
)))
901 (*wibox
)->need_update
= true;
904 buf
= luaL_checklstring(L
, 3, &len
);
905 (*wibox
)->align
= draw_align_fromstr(buf
, len
);
906 switch((*wibox
)->type
)
908 case WIBOX_TYPE_NORMAL
:
909 wibox_position_update(*wibox
);
911 case WIBOX_TYPE_TITLEBAR
:
912 titlebar_update_geometry_floating(client_getbytitlebar(*wibox
));
917 switch((*wibox
)->type
)
919 case WIBOX_TYPE_TITLEBAR
:
920 return luaA_titlebar_newindex(L
, *wibox
, tok
);
921 case WIBOX_TYPE_NORMAL
:
922 if((buf
= luaL_checklstring(L
, 3, &len
)))
923 wibox_setposition(*wibox
, position_fromstr(buf
, len
));
930 titlebar_client_detach(client_getbytitlebar(*wibox
));
933 client_t
**c
= luaA_checkudata(L
, 3, "client");
934 titlebar_client_attach(*c
, *wibox
);
940 wibox_detach(*wibox
);
941 titlebar_client_detach(client_getbytitlebar(*wibox
));
945 int screen
= luaL_checknumber(L
, 3) - 1;
946 luaA_checkscreen(screen
);
947 if(screen
!= (*wibox
)->screen
)
949 titlebar_client_detach(client_getbytitlebar(*wibox
));
950 wibox_attach(*wibox
, &globalconf
.screens
[screen
]);
955 b
= luaA_checkboolean(L
, 3);
956 if(b
!= (*wibox
)->ontop
)
962 case A_TK_ORIENTATION
:
963 if((buf
= luaL_checklstring(L
, 3, &len
)))
965 simplewindow_orientation_set(&(*wibox
)->sw
, orientation_fromstr(buf
, len
));
966 (*wibox
)->need_update
= true;
969 case A_TK_BORDER_COLOR
:
970 if((buf
= luaL_checklstring(L
, 3, &len
)))
971 if(xcolor_init_reply(xcolor_init_unchecked(&(*wibox
)->sw
.border
.color
, buf
, len
)))
972 if((*wibox
)->sw
.window
)
973 simplewindow_border_color_set(&(*wibox
)->sw
, &(*wibox
)->sw
.border
.color
);
976 b
= luaA_checkboolean(L
, 3);
977 if(b
!= (*wibox
)->isvisible
)
978 switch((*wibox
)->type
)
980 case WIBOX_TYPE_NORMAL
:
981 wibox_setvisible(*wibox
, b
);
983 case WIBOX_TYPE_TITLEBAR
:
984 (*wibox
)->isvisible
= b
;
985 globalconf
.screens
[(*wibox
)->screen
].need_arrange
= true;
990 luaA_register(L
, 3, &(*wibox
)->widgets_table
);
991 /* recompute widget node list */
992 wibox_widgets_table_build(L
, *wibox
);
993 luaA_table2wtable(L
);
996 switch((*wibox
)->type
)
998 case WIBOX_TYPE_TITLEBAR
:
999 return luaA_titlebar_newindex(L
, *wibox
, tok
);
1000 case WIBOX_TYPE_NORMAL
:
1008 const struct luaL_reg awesome_wibox_methods
[] =
1010 { "__call", luaA_wibox_new
},
1013 const struct luaL_reg awesome_wibox_meta
[] =
1015 { "geometry", luaA_wibox_geometry
},
1016 { "__index", luaA_wibox_index
},
1017 { "__newindex", luaA_wibox_newindex
},
1018 { "__gc", luaA_wibox_gc
},
1019 { "__eq", luaA_wibox_eq
},
1020 { "__tostring", luaA_wibox_tostring
},
1024 // vim: filetype=c:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=80