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
->geometry
.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
->geometry
.y
;
149 config_win_vals
[1] = wibox
->sw
.geometry
.height
- systray
->geometry
.x
- systray
->geometry
.width
;
150 config_win_vals
[2] = systray
->geometry
.height
;
151 config_win_vals
[3] = systray
->geometry
.width
;
154 config_win_vals
[0] = systray
->geometry
.y
;
155 config_win_vals
[1] = systray
->geometry
.x
;
156 config_win_vals
[2] = systray
->geometry
.height
;
157 config_win_vals
[3] = systray
->geometry
.width
;
160 config_win_vals
[0] = systray
->geometry
.x
;
161 config_win_vals
[1] = systray
->geometry
.y
;
162 config_win_vals
[2] = systray
->geometry
.width
;
163 config_win_vals
[3] = systray
->geometry
.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
->geometry
.height
;
184 config_win_vals
[0] = 0;
187 return wibox_systray_kickout(phys_screen
);
192 config_win_vals
[1] = systray
->geometry
.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
->geometry
) + 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 if(wibox
->position
!= Floating
)
286 for(int i
= 0; i
< globalconf
.screens
[wibox
->screen
].wiboxes
.len
; i
++)
288 wibox_t
*w
= globalconf
.screens
[wibox
->screen
].wiboxes
.tab
[i
];
289 /* Ignore every wibox after me that is in the same position */
295 else if((ignore
&& wibox
->position
== w
->position
) || !w
->isvisible
)
302 switch(wibox
->position
)
305 area
.x
+= wibox
->sw
.geometry
.height
;
312 switch(wibox
->position
)
315 area
.x
-= wibox
->sw
.geometry
.height
;
322 switch(wibox
->position
)
325 area
.y
+= w
->sw
.geometry
.height
;
329 area
.height
-= w
->sw
.geometry
.height
;
330 area
.y
+= w
->sw
.geometry
.height
;
337 switch(wibox
->position
)
340 area
.y
-= w
->sw
.geometry
.height
;
344 area
.height
-= w
->sw
.geometry
.height
;
353 switch(wibox
->position
)
356 wingeom
.height
= wibox
->sw
.geometry
.height
> 0 ?
357 wibox
->sw
.geometry
.height
: area
.height
- 2 * wibox
->sw
.border
.width
;
358 wingeom
.width
= wibox
->sw
.geometry
.width
> 0 ? wibox
->sw
.geometry
.width
: 1.5 * globalconf
.font
->height
;
359 wingeom
.x
= area
.x
+ area
.width
- wingeom
.width
- 2 * wibox
->sw
.border
.width
;
366 wingeom
.y
= area
.y
+ area
.height
- wingeom
.height
;
369 wingeom
.y
= (area
.y
+ area
.height
- wingeom
.height
) / 2;
374 wingeom
.height
= wibox
->sw
.geometry
.height
> 0 ?
375 wibox
->sw
.geometry
.height
: area
.height
- 2 * wibox
->sw
.border
.width
;
376 wingeom
.width
= wibox
->sw
.geometry
.width
> 0 ? wibox
->sw
.geometry
.width
: 1.5 * globalconf
.font
->height
;
381 wingeom
.y
= (area
.y
+ area
.height
) - wingeom
.height
- 2 * wibox
->sw
.border
.width
;
387 wingeom
.y
= (area
.y
+ area
.height
- wingeom
.height
) / 2;
391 wingeom
.height
= wibox
->sw
.geometry
.height
> 0 ? wibox
->sw
.geometry
.height
: 1.5 * globalconf
.font
->height
;
392 wingeom
.width
= wibox
->sw
.geometry
.width
> 0 ?
393 wibox
->sw
.geometry
.width
: area
.width
- 2 * wibox
->sw
.border
.width
;
394 wingeom
.y
= (area
.y
+ area
.height
) - wingeom
.height
- 2 * wibox
->sw
.border
.width
;
401 wingeom
.x
+= area
.width
- wingeom
.width
;
404 wingeom
.x
+= (area
.width
- wingeom
.width
) / 2;
409 wingeom
.height
= wibox
->sw
.geometry
.height
> 0 ? wibox
->sw
.geometry
.height
: 1.5 * globalconf
.font
->height
;
410 wingeom
.width
= wibox
->sw
.geometry
.width
> 0 ?
411 wibox
->sw
.geometry
.width
: area
.width
- 2 * wibox
->sw
.border
.width
;
419 wingeom
.x
+= area
.width
- wingeom
.width
;
422 wingeom
.x
+= (area
.width
- wingeom
.width
) / 2;
427 wingeom
.width
= MAX(1, wibox
->sw
.geometry
.width
);
428 wingeom
.height
= MAX(1, wibox
->sw
.geometry
.height
);
432 /* same window size and position ? */
433 if(wingeom
.width
!= wibox
->sw
.geometry
.width
434 || wingeom
.height
!= wibox
->sw
.geometry
.height
)
435 wibox_resize(wibox
, wingeom
.width
, wingeom
.height
);
437 if(wingeom
.x
!= wibox
->sw
.geometry
.x
438 || wingeom
.y
!= wibox
->sw
.geometry
.y
)
439 wibox_move(wibox
, wingeom
.x
, wingeom
.y
);
443 * \param wibox wibox to delete.
446 wibox_delete(wibox_t
**wibox
)
448 simplewindow_wipe(&(*wibox
)->sw
);
449 luaL_unref(globalconf
.L
, LUA_REGISTRYINDEX
, (*wibox
)->widgets_table
);
450 widget_node_array_wipe(&(*wibox
)->widgets
);
454 /** Get a wibox by its window.
455 * \param w The window id.
456 * \return A wibox if found, NULL otherwise.
459 wibox_getbywin(xcb_window_t w
)
461 for(int screen
= 0; screen
< globalconf
.nscreen
; screen
++)
462 for(int i
= 0; i
< globalconf
.screens
[screen
].wiboxes
.len
; i
++)
464 wibox_t
*s
= globalconf
.screens
[screen
].wiboxes
.tab
[i
];
465 if(s
->sw
.window
== w
)
469 for(client_t
*c
= globalconf
.clients
; c
; c
= c
->next
)
470 if(c
->titlebar
&& c
->titlebar
->sw
.window
== w
)
477 * \param wibox The wibox to draw.
480 wibox_draw(wibox_t
*wibox
)
484 widget_render(&wibox
->widgets
, &wibox
->sw
.ctx
, wibox
->sw
.gc
,
486 wibox
->screen
, wibox
->sw
.orientation
,
487 wibox
->sw
.geometry
.x
, wibox
->sw
.geometry
.y
,
489 simplewindow_refresh_pixmap(&wibox
->sw
);
491 wibox
->need_update
= false;
494 wibox_systray_refresh(wibox
);
497 /** Refresh all wiboxes.
502 for(int screen
= 0; screen
< globalconf
.nscreen
; screen
++)
503 for(int i
= 0; i
< globalconf
.screens
[screen
].wiboxes
.len
; i
++)
505 wibox_t
*s
= globalconf
.screens
[screen
].wiboxes
.tab
[i
];
510 for(client_t
*c
= globalconf
.clients
; c
; c
= c
->next
)
511 if(c
->titlebar
&& c
->titlebar
->need_update
)
512 wibox_draw(c
->titlebar
);
515 /** Set a wibox visible or not.
516 * \param wibox The wibox.
517 * \param v The visible value.
520 wibox_setvisible(wibox_t
*wibox
, bool v
)
522 if(v
!= wibox
->isvisible
)
524 if((wibox
->isvisible
= v
))
526 xcb_map_window(globalconf
.connection
, wibox
->sw
.window
);
527 simplewindow_refresh_pixmap(&wibox
->sw
);
528 /* stack correctly the wibox */
532 xcb_unmap_window(globalconf
.connection
, wibox
->sw
.window
);
534 /* kick out systray if needed */
535 wibox_systray_refresh(wibox
);
537 /* All the other wibox and ourselves need to be repositioned */
538 wibox_array_t
*w
= &globalconf
.screens
[wibox
->screen
].wiboxes
;
539 for(int i
= 0; i
< w
->len
; i
++)
540 wibox_position_update(w
->tab
[i
]);
544 /** Remove a wibox from a screen.
545 * \param wibox Wibox to detach from screen.
548 wibox_detach(wibox_t
*wibox
)
550 if(wibox
->screen
!= SCREEN_UNDEF
)
554 /* save visible state */
555 v
= wibox
->isvisible
;
556 wibox
->isvisible
= false;
557 wibox_position_update(wibox
);
558 /* restore position */
559 wibox
->isvisible
= v
;
561 simplewindow_wipe(&wibox
->sw
);
563 for(int i
= 0; i
< globalconf
.screens
[wibox
->screen
].wiboxes
.len
; i
++)
564 if(globalconf
.screens
[wibox
->screen
].wiboxes
.tab
[i
] == wibox
)
566 wibox_array_take(&globalconf
.screens
[wibox
->screen
].wiboxes
, i
);
569 globalconf
.screens
[wibox
->screen
].need_arrange
= true;
570 wibox
->screen
= SCREEN_UNDEF
;
576 * \param wibox The wibox to attach.
577 * \param s The screen to attach the wibox to.
580 wibox_attach(wibox_t
*wibox
, screen_t
*s
)
582 int phys_screen
= screen_virttophys(s
->index
);
586 wibox
->screen
= s
->index
;
588 wibox_array_append(&s
->wiboxes
, wibox_ref(&wibox
));
590 /* compute x/y/width/height if not set */
591 wibox_position_update(wibox
);
593 simplewindow_init(&wibox
->sw
, phys_screen
,
595 wibox
->sw
.border
.width
,
596 wibox
->sw
.orientation
,
597 &wibox
->sw
.ctx
.fg
, &wibox
->sw
.ctx
.bg
);
599 simplewindow_border_color_set(&wibox
->sw
, &wibox
->sw
.border
.color
);
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 /* draw it right now once to avoid garbage shown */
611 xcb_map_window(globalconf
.connection
, wibox
->sw
.window
);
612 simplewindow_refresh_pixmap(&wibox
->sw
);
613 /* stack correctly the wibox */
617 wibox
->need_update
= true;
620 /** Create a new wibox.
621 * \param L The Lua VM state.
624 * \lparam A table with optionaly defined values:
625 * position, align, fg, bg, border_width, border_color, width and height.
626 * \lreturn A brand new wibox.
629 luaA_wibox_new(lua_State
*L
)
634 xcolor_init_request_t reqs
[3];
635 int8_t i
, reqs_nbr
= -1;
637 luaA_checktable(L
, 2);
639 w
= p_new(wibox_t
, 1);
640 w
->widgets_table
= LUA_REFNIL
;
642 w
->sw
.ctx
.fg
= globalconf
.colors
.fg
;
643 if((buf
= luaA_getopt_lstring(L
, 2, "fg", NULL
, &len
)))
644 reqs
[++reqs_nbr
] = xcolor_init_unchecked(&w
->sw
.ctx
.fg
, buf
, len
);
646 w
->sw
.ctx
.bg
= globalconf
.colors
.bg
;
647 if((buf
= luaA_getopt_lstring(L
, 2, "bg", NULL
, &len
)))
648 reqs
[++reqs_nbr
] = xcolor_init_unchecked(&w
->sw
.ctx
.bg
, buf
, len
);
650 w
->sw
.border
.color
= globalconf
.colors
.bg
;
651 if((buf
= luaA_getopt_lstring(L
, 2, "border_color", NULL
, &len
)))
652 reqs
[++reqs_nbr
] = xcolor_init_unchecked(&w
->sw
.border
.color
, buf
, len
);
654 buf
= luaA_getopt_lstring(L
, 2, "align", "left", &len
);
655 w
->align
= draw_align_fromstr(buf
, len
);
657 w
->sw
.border
.width
= luaA_getopt_number(L
, 2, "border_width", 0);
659 buf
= luaA_getopt_lstring(L
, 2, "position", "top", &len
);
661 switch((w
->position
= position_fromstr(buf
, len
)))
666 simplewindow_orientation_set(&w
->sw
, East
);
669 simplewindow_orientation_set(&w
->sw
, North
);
672 simplewindow_orientation_set(&w
->sw
, South
);
676 /* recompute position */
677 wibox_position_update(w
);
679 w
->sw
.geometry
.width
= luaA_getopt_number(L
, 2, "width", 0);
680 w
->sw
.geometry
.height
= luaA_getopt_number(L
, 2, "height", 0);
682 w
->screen
= SCREEN_UNDEF
;
685 for(i
= 0; i
<= reqs_nbr
; i
++)
686 xcolor_init_reply(reqs
[i
]);
688 return luaA_wibox_userdata_new(L
, w
);
691 /** Rebuild wibox widgets list.
692 * \param L The Lua VM state.
693 * \param wibox The wibox.
696 wibox_widgets_table_build(lua_State
*L
, wibox_t
*wibox
)
698 widget_node_array_wipe(&wibox
->widgets
);
699 widget_node_array_init(&wibox
->widgets
);
700 luaA_table2widgets(L
, &wibox
->widgets
);
701 wibox
->mouse_over
= NULL
;
702 wibox
->need_update
= true;
705 /** Check if a wibox widget table has an item.
706 * \param L The Lua VM state.
707 * \param wibox The wibox.
708 * \param item The item to look for.
711 luaA_wibox_hasitem(lua_State
*L
, wibox_t
*wibox
, const void *item
)
714 if(wibox
->widgets_table
!= LUA_REFNIL
)
716 lua_rawgeti(globalconf
.L
, LUA_REGISTRYINDEX
, wibox
->widgets_table
);
717 if(lua_topointer(L
, -1) == item
|| luaA_hasitem(L
, item
))
723 /** Invalidate a wibox by a Lua object (table, etc).
724 * \param L The Lua VM state.
725 * \param item The object identifier.
728 luaA_wibox_invalidate_byitem(lua_State
*L
, const void *item
)
730 for(int screen
= 0; screen
< globalconf
.nscreen
; screen
++)
731 for(int i
= 0; i
< globalconf
.screens
[screen
].wiboxes
.len
; i
++)
733 wibox_t
*wibox
= globalconf
.screens
[screen
].wiboxes
.tab
[i
];
734 if(luaA_wibox_hasitem(L
, wibox
, item
))
736 /* recompute widget node list */
737 wibox_widgets_table_build(L
, wibox
);
738 lua_pop(L
, 1); /* remove widgets table */
743 for(client_t
*c
= globalconf
.clients
; c
; c
= c
->next
)
744 if(c
->titlebar
&& luaA_wibox_hasitem(L
, c
->titlebar
, item
))
746 /* recompute widget node list */
747 wibox_widgets_table_build(L
, c
->titlebar
);
748 lua_pop(L
, 1); /* remove widgets table */
754 * \param L The Lua VM state.
755 * \return The number of elements pushed on stack.
757 * \lfield screen Screen number.
758 * \lfield client The client attached to this titlebar.
759 * \lfield border_width Border width.
760 * \lfield border_color Border color.
761 * \lfield align The alignment.
762 * \lfield fg Foreground color.
763 * \lfield bg Background color.
764 * \lfield position The position.
765 * \lfield ontop On top of other windows.
768 luaA_wibox_index(lua_State
*L
)
771 wibox_t
**wibox
= luaA_checkudata(L
, 1, "wibox");
772 const char *attr
= luaL_checklstring(L
, 2, &len
);
774 if(luaA_usemetatable(L
, 1, 2))
777 switch(a_tokenize(attr
, len
))
782 lua_pushboolean(L
, (*wibox
)->isvisible
);
785 if((c
= client_getbytitlebar(*wibox
)))
786 return luaA_client_userdata_new(L
, c
);
790 if((*wibox
)->screen
== SCREEN_UNDEF
)
792 lua_pushnumber(L
, (*wibox
)->screen
+ 1);
794 case A_TK_BORDER_WIDTH
:
795 lua_pushnumber(L
, (*wibox
)->sw
.border
.width
);
797 case A_TK_BORDER_COLOR
:
798 luaA_pushcolor(L
, &(*wibox
)->sw
.border
.color
);
801 lua_pushstring(L
, draw_align_tostr((*wibox
)->align
));
804 luaA_pushcolor(L
, &(*wibox
)->sw
.ctx
.fg
);
807 luaA_pushcolor(L
, &(*wibox
)->sw
.ctx
.bg
);
810 lua_pushstring(L
, position_tostr((*wibox
)->position
));
813 lua_pushboolean(L
, (*wibox
)->ontop
);
815 case A_TK_ORIENTATION
:
816 lua_pushstring(L
, orientation_tostr((*wibox
)->sw
.orientation
));
819 if((*wibox
)->widgets_table
!= LUA_REFNIL
)
820 lua_rawgeti(L
, LUA_REGISTRYINDEX
, (*wibox
)->widgets_table
);
831 /* Set or get the wibox geometry.
832 * \param L The Lua VM state.
833 * \return The number of elements pushed on stack.
835 * \lparam An optional table with wibox geometry.
836 * \lreturn The wibox geometry.
839 luaA_wibox_geometry(lua_State
*L
)
841 wibox_t
**wibox
= luaA_checkudata(L
, 1, "wibox");
843 if(lua_gettop(L
) == 2)
847 luaA_checktable(L
, 2);
848 wingeom
.x
= luaA_getopt_number(L
, 2, "x", (*wibox
)->sw
.geometry
.x
);
849 wingeom
.y
= luaA_getopt_number(L
, 2, "y", (*wibox
)->sw
.geometry
.y
);
850 wingeom
.width
= luaA_getopt_number(L
, 2, "width", (*wibox
)->sw
.geometry
.width
);
851 wingeom
.height
= luaA_getopt_number(L
, 2, "height", (*wibox
)->sw
.geometry
.height
);
853 switch((*wibox
)->type
)
855 case WIBOX_TYPE_TITLEBAR
:
856 wibox_resize(*wibox
, wingeom
.width
, wingeom
.height
);
858 case WIBOX_TYPE_NORMAL
:
859 if((*wibox
)->position
== Floating
)
860 wibox_moveresize(*wibox
, wingeom
);
861 else if(wingeom
.width
!= (*wibox
)->sw
.geometry
.width
862 || wingeom
.height
!= (*wibox
)->sw
.geometry
.height
)
864 wibox_resize(*wibox
, wingeom
.width
, wingeom
.height
);
865 globalconf
.screens
[(*wibox
)->screen
].need_arrange
= true;
871 return luaA_pusharea(L
, (*wibox
)->sw
.geometry
);
875 * \param L The Lua VM state.
876 * \return The number of elements pushed on stack.
879 luaA_wibox_newindex(lua_State
*L
)
882 wibox_t
**wibox
= luaA_checkudata(L
, 1, "wibox");
883 const char *buf
, *attr
= luaL_checklstring(L
, 2, &len
);
886 switch((tok
= a_tokenize(attr
, len
)))
891 if((buf
= luaL_checklstring(L
, 3, &len
)))
892 if(xcolor_init_reply(xcolor_init_unchecked(&(*wibox
)->sw
.ctx
.fg
, buf
, len
)))
893 (*wibox
)->need_update
= true;
896 if((buf
= luaL_checklstring(L
, 3, &len
)))
897 if(xcolor_init_reply(xcolor_init_unchecked(&(*wibox
)->sw
.ctx
.bg
, buf
, len
)))
898 (*wibox
)->need_update
= true;
901 buf
= luaL_checklstring(L
, 3, &len
);
902 (*wibox
)->align
= draw_align_fromstr(buf
, len
);
903 switch((*wibox
)->type
)
905 case WIBOX_TYPE_NORMAL
:
906 wibox_position_update(*wibox
);
908 case WIBOX_TYPE_TITLEBAR
:
909 titlebar_update_geometry_floating(client_getbytitlebar(*wibox
));
914 switch((*wibox
)->type
)
916 case WIBOX_TYPE_TITLEBAR
:
917 return luaA_titlebar_newindex(L
, *wibox
, tok
);
918 case WIBOX_TYPE_NORMAL
:
919 if((buf
= luaL_checklstring(L
, 3, &len
)))
920 wibox_setposition(*wibox
, position_fromstr(buf
, len
));
927 titlebar_client_detach(client_getbytitlebar(*wibox
));
930 client_t
**c
= luaA_checkudata(L
, 3, "client");
931 titlebar_client_attach(*c
, *wibox
);
937 wibox_detach(*wibox
);
938 titlebar_client_detach(client_getbytitlebar(*wibox
));
942 int screen
= luaL_checknumber(L
, 3) - 1;
943 luaA_checkscreen(screen
);
944 if(screen
!= (*wibox
)->screen
)
946 titlebar_client_detach(client_getbytitlebar(*wibox
));
947 wibox_attach(*wibox
, &globalconf
.screens
[screen
]);
952 b
= luaA_checkboolean(L
, 3);
953 if(b
!= (*wibox
)->ontop
)
959 case A_TK_ORIENTATION
:
960 if((buf
= luaL_checklstring(L
, 3, &len
)))
962 simplewindow_orientation_set(&(*wibox
)->sw
, orientation_fromstr(buf
, len
));
963 (*wibox
)->need_update
= true;
966 case A_TK_BORDER_COLOR
:
967 if((buf
= luaL_checklstring(L
, 3, &len
)))
968 if(xcolor_init_reply(xcolor_init_unchecked(&(*wibox
)->sw
.border
.color
, buf
, len
)))
969 if((*wibox
)->sw
.window
)
970 simplewindow_border_color_set(&(*wibox
)->sw
, &(*wibox
)->sw
.border
.color
);
973 b
= luaA_checkboolean(L
, 3);
974 if(b
!= (*wibox
)->isvisible
)
975 switch((*wibox
)->type
)
977 case WIBOX_TYPE_NORMAL
:
978 wibox_setvisible(*wibox
, b
);
980 case WIBOX_TYPE_TITLEBAR
:
981 (*wibox
)->isvisible
= b
;
982 globalconf
.screens
[(*wibox
)->screen
].need_arrange
= true;
987 if(luaA_isloop(L
, 3))
989 luaA_warn(L
, "table is looping, cannot use this as widget table");
992 luaA_register(L
, 3, &(*wibox
)->widgets_table
);
993 /* recompute widget node list */
994 wibox_widgets_table_build(L
, *wibox
);
995 luaA_table2wtable(L
);
998 switch((*wibox
)->type
)
1000 case WIBOX_TYPE_TITLEBAR
:
1001 return luaA_titlebar_newindex(L
, *wibox
, tok
);
1002 case WIBOX_TYPE_NORMAL
:
1010 const struct luaL_reg awesome_wibox_methods
[] =
1012 { "__call", luaA_wibox_new
},
1015 const struct luaL_reg awesome_wibox_meta
[] =
1017 { "geometry", luaA_wibox_geometry
},
1018 { "__index", luaA_wibox_index
},
1019 { "__newindex", luaA_wibox_newindex
},
1020 { "__gc", luaA_wibox_gc
},
1021 { "__eq", luaA_wibox_eq
},
1022 { "__tostring", luaA_wibox_tostring
},
1026 // vim: filetype=c:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=80