[statusbar] Add align option
Signed-off-by: Julien Danjou <julien@danjou.info>
This commit is contained in:
parent
ca68059b19
commit
6931bc70e6
72
statusbar.c
72
statusbar.c
|
@ -204,20 +204,70 @@ statusbar_position_update(statusbar_t *statusbar, position_t position)
|
||||||
|
|
||||||
switch(statusbar->position)
|
switch(statusbar->position)
|
||||||
{
|
{
|
||||||
case Top:
|
default:
|
||||||
|
switch(statusbar->align)
|
||||||
|
{
|
||||||
|
default:
|
||||||
simplewindow_move(statusbar->sw, area.x, area.y);
|
simplewindow_move(statusbar->sw, area.x, area.y);
|
||||||
break;
|
break;
|
||||||
|
case AlignRight:
|
||||||
|
simplewindow_move(statusbar->sw,
|
||||||
|
area.x + area.width - statusbar->width, area.y);
|
||||||
|
break;
|
||||||
|
case AlignCenter:
|
||||||
|
simplewindow_move(statusbar->sw,
|
||||||
|
area.x + (area.width - statusbar->width) / 2, area.y);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
break;
|
||||||
case Bottom:
|
case Bottom:
|
||||||
simplewindow_move(statusbar->sw, area.x, (area.y + area.height) - statusbar->height);
|
switch(statusbar->align)
|
||||||
|
{
|
||||||
|
default:
|
||||||
|
simplewindow_move(statusbar->sw,
|
||||||
|
area.x, (area.y + area.height) - statusbar->height);
|
||||||
|
break;
|
||||||
|
case AlignRight:
|
||||||
|
simplewindow_move(statusbar->sw,
|
||||||
|
area.x + area.width - statusbar->width,
|
||||||
|
(area.y + area.height) - statusbar->height);
|
||||||
|
break;
|
||||||
|
case AlignCenter:
|
||||||
|
simplewindow_move(statusbar->sw,
|
||||||
|
area.x + (area.width - statusbar->width) / 2,
|
||||||
|
(area.y + area.height) - statusbar->height);
|
||||||
|
break;
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
case Left:
|
case Left:
|
||||||
|
switch(statusbar->align)
|
||||||
|
{
|
||||||
|
default:
|
||||||
simplewindow_move(statusbar->sw, area.x,
|
simplewindow_move(statusbar->sw, area.x,
|
||||||
(area.y + area.height) - statusbar->sw->geometry.height);
|
(area.y + area.height) - statusbar->sw->geometry.height);
|
||||||
break;
|
break;
|
||||||
|
case AlignRight:
|
||||||
|
simplewindow_move(statusbar->sw, area.x, area.y);
|
||||||
|
break;
|
||||||
|
case AlignCenter:
|
||||||
|
simplewindow_move(statusbar->sw, area.x, (area.y + area.height - statusbar->width) / 2);
|
||||||
|
}
|
||||||
|
break;
|
||||||
case Right:
|
case Right:
|
||||||
|
switch(statusbar->align)
|
||||||
|
{
|
||||||
|
default:
|
||||||
simplewindow_move(statusbar->sw, area.x + area.width - statusbar->height, area.y);
|
simplewindow_move(statusbar->sw, area.x + area.width - statusbar->height, area.y);
|
||||||
break;
|
break;
|
||||||
default:
|
case AlignRight:
|
||||||
|
simplewindow_move(statusbar->sw, area.x + area.width - statusbar->height,
|
||||||
|
area.y + area.height - statusbar->width);
|
||||||
|
break;
|
||||||
|
case AlignCenter:
|
||||||
|
simplewindow_move(statusbar->sw, area.x + area.width - statusbar->height,
|
||||||
|
(area.y + area.height - statusbar->width) / 2);
|
||||||
|
break;
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -279,6 +329,19 @@ luaA_statusbar_position_set(lua_State *L)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int
|
||||||
|
luaA_statusbar_align_set(lua_State *L)
|
||||||
|
{
|
||||||
|
statusbar_t **sb = luaL_checkudata(L, 1, "statusbar");
|
||||||
|
const char *al = luaL_checkstring(L, 2);
|
||||||
|
alignment_t align = draw_align_get_from_str(al);
|
||||||
|
|
||||||
|
(*sb)->align = align;
|
||||||
|
statusbar_position_update(*sb, (*sb)->position);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
luaA_statusbar_tostring(lua_State *L)
|
luaA_statusbar_tostring(lua_State *L)
|
||||||
{
|
{
|
||||||
|
@ -351,6 +414,8 @@ luaA_statusbar_new(lua_State *L)
|
||||||
else
|
else
|
||||||
(*sb)->colors.bg = globalconf.colors.bg;
|
(*sb)->colors.bg = globalconf.colors.bg;
|
||||||
|
|
||||||
|
(*sb)->align = draw_align_get_from_str(luaA_getopt_string(L, 1, "align", "left"));
|
||||||
|
|
||||||
(*sb)->width = luaA_getopt_number(L, 1, "width", 0);
|
(*sb)->width = luaA_getopt_number(L, 1, "width", 0);
|
||||||
(*sb)->height = luaA_getopt_number(L, 1, "height", 0);
|
(*sb)->height = luaA_getopt_number(L, 1, "height", 0);
|
||||||
if((*sb)->height <= 0)
|
if((*sb)->height <= 0)
|
||||||
|
@ -382,6 +447,7 @@ const struct luaL_reg awesome_statusbar_meta[] =
|
||||||
{
|
{
|
||||||
{ "widget_add", luaA_statusbar_widget_add },
|
{ "widget_add", luaA_statusbar_widget_add },
|
||||||
{ "position_set", luaA_statusbar_position_set },
|
{ "position_set", luaA_statusbar_position_set },
|
||||||
|
{ "align_set", luaA_statusbar_align_set },
|
||||||
{ "add", luaA_statusbar_add },
|
{ "add", luaA_statusbar_add },
|
||||||
{ "__gc", luaA_statusbar_gc },
|
{ "__gc", luaA_statusbar_gc },
|
||||||
{ "__eq", luaA_statusbar_eq },
|
{ "__eq", luaA_statusbar_eq },
|
||||||
|
|
|
@ -200,6 +200,8 @@ struct statusbar_t
|
||||||
int height;
|
int height;
|
||||||
/** Bar position */
|
/** Bar position */
|
||||||
position_t position;
|
position_t position;
|
||||||
|
/** Alignment */
|
||||||
|
alignment_t align;
|
||||||
/** Screen */
|
/** Screen */
|
||||||
int screen;
|
int screen;
|
||||||
/** Physical screen id */
|
/** Physical screen id */
|
||||||
|
|
Loading…
Reference in New Issue