From 7b1ce042de638f0674937da724c9335fe1c91c0b Mon Sep 17 00:00:00 2001 From: Julien Danjou Date: Wed, 19 Mar 2008 11:58:43 +0100 Subject: [PATCH] Add cfg_getposition() and cie to ease libconfuse compatibility Signed-off-by: Julien Danjou --- common/configopts.c | 18 ++++++++++++++++++ common/configopts.h | 4 ++++ config.c | 4 ++-- widgets/graph.c | 5 +++-- 4 files changed, 27 insertions(+), 4 deletions(-) diff --git a/common/configopts.c b/common/configopts.c index 25e93b4a9..c4145fdaf 100644 --- a/common/configopts.c +++ b/common/configopts.c @@ -119,6 +119,24 @@ cfg_value_free(void *value) p_delete(&value); } +Position +cfg_opt_getnposition(cfg_opt_t *opt, unsigned int oindex) +{ + return * (Position *) cfg_opt_getnptr(opt, oindex); +} + +Position +cfg_getnposition(cfg_t *cfg, const char *name, unsigned int oindex) +{ + return cfg_opt_getnposition(cfg_getopt(cfg, name), oindex); +} + +Position +cfg_getposition(cfg_t *cfg, const char *name) +{ + return cfg_getnposition(cfg, name, 0); +} + cfg_opt_t titlebar_opts[] = { CFG_POSITION((char *) "position", (char *) "auto", CFGF_NONE), diff --git a/common/configopts.h b/common/configopts.h index 84b4d35de..93be15494 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 *); +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 *); + #endif // vim: filetype=c:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=80 diff --git a/config.c b/config.c index e606abd6f..5048c4fcc 100644 --- a/config.c +++ b/config.c @@ -275,7 +275,7 @@ create_widgets(cfg_t* cfg_statusbar, Statusbar *statusbar) static void config_section_titlebar_init(cfg_t *cfg_titlebar, Titlebar *tb) { - tb->position = tb->dposition = *(Position *) cfg_getptr(cfg_titlebar, "position"); + tb->position = tb->dposition = cfg_getposition(cfg_titlebar, "position"); tb->text_align = * (Alignment *) cfg_getptr(cfg_titlebar, "text_align"); } @@ -373,7 +373,7 @@ config_parse_screen(cfg_t *cfg, int screen) statusbar = p_new(Statusbar, 1); cfgsectmp = cfg_getnsec(cfg_screen, "statusbar", i); statusbar->position = statusbar->dposition = - * (Position *) cfg_getptr(cfgsectmp, "position"); + cfg_getposition(cfgsectmp, "position"); statusbar->height = cfg_getint(cfgsectmp, "height"); statusbar->width = cfg_getint(cfgsectmp, "width"); statusbar->name = a_strdup(cfg_title(cfgsectmp)); diff --git a/widgets/graph.c b/widgets/graph.c index a0ec3b9f8..a403eb4dc 100644 --- a/widgets/graph.c +++ b/widgets/graph.c @@ -20,10 +20,11 @@ * */ -#include "common/draw.h" #include "widget.h" #include "screen.h" #include "common/util.h" +#include "common/draw.h" +#include "common/configopts.h" extern AwesomeConf globalconf; @@ -403,7 +404,7 @@ graph_new(Statusbar *statusbar, cfg_t *config) return w; } - d->grow = *(Position *) cfg_getptr(config, "grow"); + d->grow = cfg_getposition(config, "grow"); if(d->grow != Left && d->grow != Right) { warn("graph widget: 'grow' argument must be 'left' or 'right'\n");