From 6931bc70e6ac1ae2899f74ea4aca1dcb2e33aebf Mon Sep 17 00:00:00 2001 From: Julien Danjou Date: Sat, 24 May 2008 11:08:34 +0200 Subject: [PATCH] [statusbar] Add align option Signed-off-by: Julien Danjou --- statusbar.c | 82 +++++++++++++++++++++++++++++++++++++++++++++++------ structs.h | 2 ++ 2 files changed, 76 insertions(+), 8 deletions(-) diff --git a/statusbar.c b/statusbar.c index b6e3b477..8949ccb8 100644 --- a/statusbar.c +++ b/statusbar.c @@ -204,20 +204,70 @@ statusbar_position_update(statusbar_t *statusbar, position_t position) switch(statusbar->position) { - case Top: - simplewindow_move(statusbar->sw, area.x, area.y); + default: + switch(statusbar->align) + { + default: + simplewindow_move(statusbar->sw, area.x, area.y); + 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: - 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; case Left: - simplewindow_move(statusbar->sw, area.x, - (area.y + area.height) - statusbar->sw->geometry.height); + switch(statusbar->align) + { + default: + simplewindow_move(statusbar->sw, area.x, + (area.y + area.height) - statusbar->sw->geometry.height); + 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: - simplewindow_move(statusbar->sw, area.x + area.width - statusbar->height, area.y); - break; - default: + switch(statusbar->align) + { + default: + simplewindow_move(statusbar->sw, area.x + area.width - statusbar->height, area.y); + break; + 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; } @@ -279,6 +329,19 @@ luaA_statusbar_position_set(lua_State *L) 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 luaA_statusbar_tostring(lua_State *L) { @@ -351,6 +414,8 @@ luaA_statusbar_new(lua_State *L) else (*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)->height = luaA_getopt_number(L, 1, "height", 0); if((*sb)->height <= 0) @@ -382,6 +447,7 @@ const struct luaL_reg awesome_statusbar_meta[] = { { "widget_add", luaA_statusbar_widget_add }, { "position_set", luaA_statusbar_position_set }, + { "align_set", luaA_statusbar_align_set }, { "add", luaA_statusbar_add }, { "__gc", luaA_statusbar_gc }, { "__eq", luaA_statusbar_eq }, diff --git a/structs.h b/structs.h index d2cabddb..8b57379c 100644 --- a/structs.h +++ b/structs.h @@ -200,6 +200,8 @@ struct statusbar_t int height; /** Bar position */ position_t position; + /** Alignment */ + alignment_t align; /** Screen */ int screen; /** Physical screen id */