From 2a47aa7f0bdb2885c407756b4660b17e1511c00a Mon Sep 17 00:00:00 2001 From: Julien Danjou Date: Wed, 19 Mar 2008 12:05:36 +0100 Subject: [PATCH] Add cfg_getalignment() functions Signed-off-by: Julien Danjou --- common/configopts.c | 18 ++++++++++++++++++ common/configopts.h | 4 ++++ config.c | 2 +- widgets/focusicon.c | 3 ++- widgets/graph.c | 2 +- widgets/iconbox.c | 3 ++- widgets/layoutinfo.c | 3 ++- widgets/progressbar.c | 4 +++- widgets/taglist.c | 3 ++- widgets/tasklist.c | 3 ++- widgets/textbox.c | 5 +++-- 11 files changed, 40 insertions(+), 10 deletions(-) diff --git a/common/configopts.c b/common/configopts.c index c4145fdaf..f94d67319 100644 --- a/common/configopts.c +++ b/common/configopts.c @@ -119,6 +119,24 @@ cfg_value_free(void *value) p_delete(&value); } +Alignment +cfg_opt_getnalignment(cfg_opt_t *opt, unsigned int oindex) +{ + return * (Alignment *) cfg_opt_getnptr(opt, oindex); +} + +Alignment +cfg_getnalignment(cfg_t *cfg, const char *name, unsigned int oindex) +{ + return cfg_opt_getnalignment(cfg_getopt(cfg, name), oindex); +} + +Alignment +cfg_getalignment(cfg_t *cfg, const char *name) +{ + return cfg_getnalignment(cfg, name, 0); +} + Position cfg_opt_getnposition(cfg_opt_t *opt, unsigned int oindex) { diff --git a/common/configopts.h b/common/configopts.h index 93be15494..49c64b954 100644 --- a/common/configopts.h +++ b/common/configopts.h @@ -28,6 +28,10 @@ cfg_t * cfg_new(void); char * config_file(void); int config_check(const char *); +Alignment cfg_opt_getnalignment(cfg_opt_t *, unsigned int); +Alignment cfg_getnalignment(cfg_t *, const char *, unsigned int); +Alignment cfg_getalignment(cfg_t *, const char *); + Position cfg_opt_getnposition(cfg_opt_t *, unsigned int); Position cfg_getnposition(cfg_t *, const char *, unsigned int); Position cfg_getposition(cfg_t *, const char *); diff --git a/config.c b/config.c index 5048c4fcc..61f51f18b 100644 --- a/config.c +++ b/config.c @@ -276,7 +276,7 @@ static void config_section_titlebar_init(cfg_t *cfg_titlebar, Titlebar *tb) { tb->position = tb->dposition = cfg_getposition(cfg_titlebar, "position"); - tb->text_align = * (Alignment *) cfg_getptr(cfg_titlebar, "text_align"); + tb->text_align = cfg_getalignment(cfg_titlebar, "text_align"); } static void diff --git a/widgets/focusicon.c b/widgets/focusicon.c index e3c967ae6..71860cc77 100644 --- a/widgets/focusicon.c +++ b/widgets/focusicon.c @@ -25,6 +25,7 @@ #include "widget.h" #include "rules.h" #include "ewmh.h" +#include "common/configopts.h" extern AwesomeConf globalconf; @@ -100,7 +101,7 @@ focusicon_new(Statusbar *statusbar, cfg_t *config) w = p_new(Widget, 1); widget_common_new(w, statusbar, config); w->draw = focusicon_draw; - w->alignment = * (Alignment *) cfg_getptr(config, "align"); + w->alignment = cfg_getalignment(config, "align"); /* Set cache property */ w->cache.flags = WIDGET_CACHE_CLIENTS; diff --git a/widgets/graph.c b/widgets/graph.c index a403eb4dc..c9d61b526 100644 --- a/widgets/graph.c +++ b/widgets/graph.c @@ -384,7 +384,7 @@ graph_new(Statusbar *statusbar, cfg_t *config) w->draw = graph_draw; w->tell = graph_tell; - w->alignment = * (Alignment *) cfg_getptr(config, "align"); + w->alignment = cfg_getalignment(config, "align"); d = w->data = p_new(Data, 1); d->width = cfg_getint(config, "width"); diff --git a/widgets/iconbox.c b/widgets/iconbox.c index 317cab72a..3a3410f9f 100644 --- a/widgets/iconbox.c +++ b/widgets/iconbox.c @@ -21,6 +21,7 @@ #include "widget.h" #include "common/util.h" +#include "common/configopts.h" extern AwesomeConf globalconf; @@ -99,7 +100,7 @@ iconbox_new(Statusbar *statusbar, cfg_t *config) w = p_new(Widget, 1); widget_common_new(w, statusbar, config); - w->alignment = * (Alignment *) cfg_getptr(config, "align"); + w->alignment = cfg_getalignment(config, "align"); w->draw = iconbox_draw; w->tell = iconbox_tell; w->data = d = p_new(Data, 1); diff --git a/widgets/layoutinfo.c b/widgets/layoutinfo.c index 15c72dd98..5f1c7cfd7 100644 --- a/widgets/layoutinfo.c +++ b/widgets/layoutinfo.c @@ -24,6 +24,7 @@ #include "widget.h" #include "tag.h" #include "common/util.h" +#include "common/configopts.h" extern AwesomeConf globalconf; @@ -64,7 +65,7 @@ layoutinfo_new(Statusbar *statusbar, cfg_t* config) w = p_new(Widget, 1); widget_common_new(w, statusbar, config); w->draw = layoutinfo_draw; - w->alignment = * (Alignment *) cfg_getptr(config, "align"); + w->alignment = cfg_getalignment(config, "align"); /* Set cache property */ w->cache.flags = WIDGET_CACHE_LAYOUTS; diff --git a/widgets/progressbar.c b/widgets/progressbar.c index a65e49386..0a9bb3797 100644 --- a/widgets/progressbar.c +++ b/widgets/progressbar.c @@ -21,8 +21,10 @@ #include #include "widget.h" + #include "screen.h" #include "common/util.h" +#include "common/configopts.h" extern AwesomeConf globalconf; @@ -430,7 +432,7 @@ progressbar_new(Statusbar *statusbar, cfg_t *config) if(!(d->vertical = cfg_getbool(config, "vertical"))) d->vertical = False; - w->alignment = * (Alignment *) cfg_getptr(config, "align"); + w->alignment = cfg_getalignment(config, "align"); if(!(d->data_items = cfg_size(config, "data"))) { diff --git a/widgets/taglist.c b/widgets/taglist.c index 22d1c9bc3..571352dba 100644 --- a/widgets/taglist.c +++ b/widgets/taglist.c @@ -25,6 +25,7 @@ #include "tag.h" #include "event.h" #include "common/util.h" +#include "common/configopts.h" extern AwesomeConf globalconf; @@ -205,7 +206,7 @@ taglist_new(Statusbar *statusbar, cfg_t *config) widget_common_new(w, statusbar, config); w->draw = taglist_draw; w->button_press = taglist_button_press; - w->alignment = * (Alignment *) cfg_getptr(config, "align"); + w->alignment = cfg_getalignment(config, "align"); /* Set cache property */ w->cache.flags = WIDGET_CACHE_TAGS | WIDGET_CACHE_CLIENTS; diff --git a/widgets/tasklist.c b/widgets/tasklist.c index e3640a581..218000808 100644 --- a/widgets/tasklist.c +++ b/widgets/tasklist.c @@ -28,6 +28,7 @@ #include "rules.h" #include "tag.h" #include "common/util.h" +#include "common/configopts.h" extern AwesomeConf globalconf; @@ -297,7 +298,7 @@ tasklist_new(Statusbar *statusbar, cfg_t *config) &d->styles.urgent, &globalconf.screens[statusbar->screen].styles.urgent); - d->align = * (Alignment *) cfg_getptr(config, "text_align"); + d->align = cfg_getalignment(config, "text_align"); d->show_icons = cfg_getbool(config, "show_icons"); buf = cfg_getstr(config, "show"); diff --git a/widgets/textbox.c b/widgets/textbox.c index a5d74006d..2fbd0699f 100644 --- a/widgets/textbox.c +++ b/widgets/textbox.c @@ -22,6 +22,7 @@ #include "widget.h" #include "screen.h" #include "common/util.h" +#include "common/configopts.h" extern AwesomeConf globalconf; @@ -118,7 +119,7 @@ textbox_new(Statusbar *statusbar, cfg_t *config) widget_common_new(w, statusbar, config); w->draw = textbox_draw; w->tell = textbox_tell; - w->alignment = * (Alignment *) cfg_getptr(config, "align"); + w->alignment = cfg_getalignment(config, "align"); w->data = d = p_new(Data, 1); @@ -128,7 +129,7 @@ textbox_new(Statusbar *statusbar, cfg_t *config) &globalconf.screens[statusbar->screen].styles.normal); d->width = cfg_getint(config, "width"); - d->align = * (Alignment *) cfg_getptr(config, "text_align"); + d->align = cfg_getalignment(config, "text_align"); d->text = a_strdup(cfg_getstr(config, "text"));