Add a CFG_ALIGNMENT type and use it
Signed-off-by: Julien Danjou <julien@danjou.info>
This commit is contained in:
parent
fe8bd0bb5b
commit
19656fc36d
|
@ -40,6 +40,10 @@
|
||||||
CFG_PTR_CB(name, value, flags, \
|
CFG_PTR_CB(name, value, flags, \
|
||||||
cfg_position_parse, cfg_value_free)
|
cfg_position_parse, cfg_value_free)
|
||||||
|
|
||||||
|
#define CFG_ALIGNMENT(name, value, flags) \
|
||||||
|
CFG_PTR_CB(name, value, flags, \
|
||||||
|
cfg_alignment_parse, cfg_value_free)
|
||||||
|
|
||||||
/** This is a better writing of cfg_include coming from libconfuse.
|
/** This is a better writing of cfg_include coming from libconfuse.
|
||||||
* With this one, we do not treat errors as fatal.
|
* With this one, we do not treat errors as fatal.
|
||||||
*/
|
*/
|
||||||
|
@ -90,6 +94,25 @@ cfg_position_parse(cfg_t *cfg, cfg_opt_t *opt,
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int
|
||||||
|
cfg_alignment_parse(cfg_t *cfg, cfg_opt_t *opt,
|
||||||
|
const char *value, void *result)
|
||||||
|
{
|
||||||
|
Alignment *p = p_new(Alignment, 1);
|
||||||
|
|
||||||
|
if((*p = draw_align_get_from_str(value)) == Auto
|
||||||
|
&& a_strcmp(value, "auto"))
|
||||||
|
{
|
||||||
|
cfg_error(cfg,
|
||||||
|
"alignment option '%s' must be left, center, right, flex or auto in section '%s'",
|
||||||
|
opt->name, cfg->name);
|
||||||
|
p_delete(&p);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
*(void **) result = p;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
cfg_value_free(void *value)
|
cfg_value_free(void *value)
|
||||||
{
|
{
|
||||||
|
@ -99,7 +122,7 @@ cfg_value_free(void *value)
|
||||||
cfg_opt_t titlebar_opts[] =
|
cfg_opt_t titlebar_opts[] =
|
||||||
{
|
{
|
||||||
CFG_POSITION((char *) "position", (char *) "auto", CFGF_NONE),
|
CFG_POSITION((char *) "position", (char *) "auto", CFGF_NONE),
|
||||||
CFG_STR((char *) "text_align", (char *) "center", CFGF_NONE),
|
CFG_ALIGNMENT((char *) "text_align", (char *) "center", CFGF_NONE),
|
||||||
CFG_STR((char *) "icon", (char *) "left", CFGF_NONE),
|
CFG_STR((char *) "icon", (char *) "left", CFGF_NONE),
|
||||||
CFG_AWESOME_END()
|
CFG_AWESOME_END()
|
||||||
};
|
};
|
||||||
|
@ -154,7 +177,7 @@ cfg_opt_t widget_opts[] =
|
||||||
{
|
{
|
||||||
CFG_INT((char *) "x", 0xffffffff, CFGF_NONE),
|
CFG_INT((char *) "x", 0xffffffff, CFGF_NONE),
|
||||||
CFG_INT((char *) "y", 0xffffffff, CFGF_NONE),
|
CFG_INT((char *) "y", 0xffffffff, CFGF_NONE),
|
||||||
CFG_STR((char *) "align", (char *) "auto", CFGF_NONE),
|
CFG_ALIGNMENT((char *) "align", (char *) "auto", CFGF_NONE),
|
||||||
CFG_SEC((char *) "mouse", mouse_generic_opts, CFGF_MULTI),
|
CFG_SEC((char *) "mouse", mouse_generic_opts, CFGF_MULTI),
|
||||||
CFG_AWESOME_END()
|
CFG_AWESOME_END()
|
||||||
};
|
};
|
||||||
|
@ -162,7 +185,7 @@ cfg_opt_t widget_taglist_opts[] =
|
||||||
{
|
{
|
||||||
CFG_INT((char *) "x", 0xffffffff, CFGF_NONE),
|
CFG_INT((char *) "x", 0xffffffff, CFGF_NONE),
|
||||||
CFG_INT((char *) "y", 0xffffffff, CFGF_NONE),
|
CFG_INT((char *) "y", 0xffffffff, CFGF_NONE),
|
||||||
CFG_STR((char *) "align", (char *) "auto", CFGF_NONE),
|
CFG_ALIGNMENT((char *) "align", (char *) "auto", CFGF_NONE),
|
||||||
CFG_SEC((char *) "mouse", mouse_taglist_opts, CFGF_MULTI),
|
CFG_SEC((char *) "mouse", mouse_taglist_opts, CFGF_MULTI),
|
||||||
CFG_AWESOME_END()
|
CFG_AWESOME_END()
|
||||||
};
|
};
|
||||||
|
@ -170,7 +193,7 @@ cfg_opt_t widget_iconbox_opts[] =
|
||||||
{
|
{
|
||||||
CFG_INT((char *) "x", 0xffffffff, CFGF_NONE),
|
CFG_INT((char *) "x", 0xffffffff, CFGF_NONE),
|
||||||
CFG_INT((char *) "y", 0xffffffff, CFGF_NONE),
|
CFG_INT((char *) "y", 0xffffffff, CFGF_NONE),
|
||||||
CFG_STR((char *) "align", (char *) "auto", CFGF_NONE),
|
CFG_ALIGNMENT((char *) "align", (char *) "auto", CFGF_NONE),
|
||||||
CFG_SEC((char *) "mouse", mouse_generic_opts, CFGF_MULTI),
|
CFG_SEC((char *) "mouse", mouse_generic_opts, CFGF_MULTI),
|
||||||
CFG_STR((char *) "image", (char *) NULL, CFGF_NONE),
|
CFG_STR((char *) "image", (char *) NULL, CFGF_NONE),
|
||||||
CFG_BOOL((char *) "resize", cfg_true, CFGF_NONE),
|
CFG_BOOL((char *) "resize", cfg_true, CFGF_NONE),
|
||||||
|
@ -180,11 +203,11 @@ cfg_opt_t widget_textbox_opts[] =
|
||||||
{
|
{
|
||||||
CFG_INT((char *) "x", 0xffffffff, CFGF_NONE),
|
CFG_INT((char *) "x", 0xffffffff, CFGF_NONE),
|
||||||
CFG_INT((char *) "y", 0xffffffff, CFGF_NONE),
|
CFG_INT((char *) "y", 0xffffffff, CFGF_NONE),
|
||||||
CFG_STR((char *) "align", (char *) "auto", CFGF_NONE),
|
CFG_ALIGNMENT((char *) "align", (char *) "auto", CFGF_NONE),
|
||||||
CFG_SEC((char *) "mouse", mouse_generic_opts, CFGF_MULTI),
|
CFG_SEC((char *) "mouse", mouse_generic_opts, CFGF_MULTI),
|
||||||
CFG_INT((char *) "width", 0, CFGF_NONE),
|
CFG_INT((char *) "width", 0, CFGF_NONE),
|
||||||
CFG_STR((char *) "text", (char *) NULL, CFGF_NONE),
|
CFG_STR((char *) "text", (char *) NULL, CFGF_NONE),
|
||||||
CFG_STR((char *) "text_align", (char *) "center", CFGF_NONE),
|
CFG_ALIGNMENT((char *) "text_align", (char *) "center", CFGF_NONE),
|
||||||
CFG_SEC((char *) "style", style_opts, CFGF_NONE),
|
CFG_SEC((char *) "style", style_opts, CFGF_NONE),
|
||||||
CFG_AWESOME_END()
|
CFG_AWESOME_END()
|
||||||
};
|
};
|
||||||
|
@ -194,7 +217,7 @@ cfg_opt_t widget_tasklist_opts[] =
|
||||||
CFG_INT((char *) "y", 0xffffffff, CFGF_NONE),
|
CFG_INT((char *) "y", 0xffffffff, CFGF_NONE),
|
||||||
CFG_SEC((char *) "mouse", mouse_generic_opts, CFGF_MULTI),
|
CFG_SEC((char *) "mouse", mouse_generic_opts, CFGF_MULTI),
|
||||||
CFG_SEC((char *) "styles", styles_opts, CFGF_NONE),
|
CFG_SEC((char *) "styles", styles_opts, CFGF_NONE),
|
||||||
CFG_STR((char *) "text_align", (char *) "left", CFGF_NONE),
|
CFG_ALIGNMENT((char *) "text_align", (char *) "left", CFGF_NONE),
|
||||||
CFG_STR((char *) "show", (char *) "tags", CFGF_NONE),
|
CFG_STR((char *) "show", (char *) "tags", CFGF_NONE),
|
||||||
CFG_BOOL((char *) "show_icons", cfg_true, CFGF_NONE),
|
CFG_BOOL((char *) "show_icons", cfg_true, CFGF_NONE),
|
||||||
CFG_AWESOME_END()
|
CFG_AWESOME_END()
|
||||||
|
@ -214,7 +237,7 @@ cfg_opt_t widget_graph_opts[] =
|
||||||
{
|
{
|
||||||
CFG_INT((char *) "x", 0xffffffff, CFGF_NONE),
|
CFG_INT((char *) "x", 0xffffffff, CFGF_NONE),
|
||||||
CFG_INT((char *) "y", 0xffffffff, CFGF_NONE),
|
CFG_INT((char *) "y", 0xffffffff, CFGF_NONE),
|
||||||
CFG_STR((char *) "align", (char *) "auto", CFGF_NONE),
|
CFG_ALIGNMENT((char *) "align", (char *) "auto", CFGF_NONE),
|
||||||
CFG_SEC((char *) "mouse", mouse_generic_opts, CFGF_MULTI),
|
CFG_SEC((char *) "mouse", mouse_generic_opts, CFGF_MULTI),
|
||||||
CFG_SEC((char *) "data", widget_graph_data_opts, CFGF_TITLE | CFGF_MULTI | CFGF_NO_TITLE_DUPES),
|
CFG_SEC((char *) "data", widget_graph_data_opts, CFGF_TITLE | CFGF_MULTI | CFGF_NO_TITLE_DUPES),
|
||||||
CFG_INT((char *) "width", 100, CFGF_NONE),
|
CFG_INT((char *) "width", 100, CFGF_NONE),
|
||||||
|
@ -239,7 +262,7 @@ cfg_opt_t widget_progressbar_opts[] =
|
||||||
{
|
{
|
||||||
CFG_INT((char *) "x", 0xffffffff, CFGF_NONE),
|
CFG_INT((char *) "x", 0xffffffff, CFGF_NONE),
|
||||||
CFG_INT((char *) "y", 0xffffffff, CFGF_NONE),
|
CFG_INT((char *) "y", 0xffffffff, CFGF_NONE),
|
||||||
CFG_STR((char *) "align", (char *) "auto", CFGF_NONE),
|
CFG_ALIGNMENT((char *) "align", (char *) "auto", CFGF_NONE),
|
||||||
CFG_SEC((char *) "mouse", mouse_generic_opts, CFGF_MULTI),
|
CFG_SEC((char *) "mouse", mouse_generic_opts, CFGF_MULTI),
|
||||||
CFG_SEC((char *) "data", widget_progressbar_data_opts, CFGF_TITLE | CFGF_MULTI | CFGF_NO_TITLE_DUPES),
|
CFG_SEC((char *) "data", widget_progressbar_data_opts, CFGF_TITLE | CFGF_MULTI | CFGF_NO_TITLE_DUPES),
|
||||||
CFG_INT((char *) "width", 100, CFGF_NONE),
|
CFG_INT((char *) "width", 100, CFGF_NONE),
|
||||||
|
@ -434,22 +457,6 @@ config_validate_zero_one_float(cfg_t *cfg, cfg_opt_t *opt)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
|
||||||
config_validate_alignment(cfg_t *cfg, cfg_opt_t *opt)
|
|
||||||
{
|
|
||||||
char *value = cfg_opt_getnstr(opt, cfg_opt_size(opt) - 1);
|
|
||||||
|
|
||||||
if(draw_get_align(value) == Auto
|
|
||||||
&& a_strcmp(value, "auto"))
|
|
||||||
{
|
|
||||||
cfg_error(cfg,
|
|
||||||
"alignment option '%s' must be left, center, right, flex or auto in section '%s'",
|
|
||||||
opt->name, cfg->name);
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
cfg_t *
|
cfg_t *
|
||||||
cfg_new(void)
|
cfg_new(void)
|
||||||
{
|
{
|
||||||
|
@ -472,10 +479,6 @@ cfg_new(void)
|
||||||
cfg_set_validate_func(cfg, "screen|general|mwfact_upper_limit", config_validate_zero_one_float);
|
cfg_set_validate_func(cfg, "screen|general|mwfact_upper_limit", config_validate_zero_one_float);
|
||||||
cfg_set_validate_func(cfg, "screen|tags|tag|mwfact", config_validate_zero_one_float);
|
cfg_set_validate_func(cfg, "screen|tags|tag|mwfact", config_validate_zero_one_float);
|
||||||
|
|
||||||
/* Check alignment values */
|
|
||||||
cfg_set_validate_func(cfg, "screen|titlebar|text_align", config_validate_alignment);
|
|
||||||
cfg_set_validate_func(cfg, "rules|rule|titlebar|text_align", config_validate_alignment);
|
|
||||||
|
|
||||||
return cfg;
|
return cfg;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -723,7 +723,7 @@ draw_textwidth(Display *disp, font_t *font, char *text)
|
||||||
* \return Alignment type
|
* \return Alignment type
|
||||||
*/
|
*/
|
||||||
Alignment
|
Alignment
|
||||||
draw_get_align(const char *align)
|
draw_align_get_from_str(const char *align)
|
||||||
{
|
{
|
||||||
if(!a_strncmp(align, "left", 4))
|
if(!a_strncmp(align, "left", 4))
|
||||||
return AlignLeft;
|
return AlignLeft;
|
||||||
|
|
|
@ -135,7 +135,7 @@ void draw_image_from_argb_data(DrawCtx *, int, int, int, int, int, unsigned char
|
||||||
area_t draw_get_image_size(const char *filename);
|
area_t draw_get_image_size(const char *filename);
|
||||||
Drawable draw_rotate(DrawCtx *, int, double, int, int);
|
Drawable draw_rotate(DrawCtx *, int, double, int, int);
|
||||||
unsigned short draw_textwidth(Display *, font_t *, char *);
|
unsigned short draw_textwidth(Display *, font_t *, char *);
|
||||||
Alignment draw_get_align(const char *);
|
Alignment draw_align_get_from_str(const char *);
|
||||||
Bool draw_color_new(Display *, int, const char *, XColor *);
|
Bool draw_color_new(Display *, int, const char *, XColor *);
|
||||||
void draw_style_init(Display *, int, cfg_t *, style_t *, style_t *);
|
void draw_style_init(Display *, int, cfg_t *, style_t *, style_t *);
|
||||||
|
|
||||||
|
|
2
config.c
2
config.c
|
@ -276,7 +276,7 @@ static void
|
||||||
config_section_titlebar_init(cfg_t *cfg_titlebar, Titlebar *tb)
|
config_section_titlebar_init(cfg_t *cfg_titlebar, Titlebar *tb)
|
||||||
{
|
{
|
||||||
tb->position = tb->dposition = *(Position *) cfg_getptr(cfg_titlebar, "position");
|
tb->position = tb->dposition = *(Position *) cfg_getptr(cfg_titlebar, "position");
|
||||||
tb->text_align = draw_get_align(cfg_getstr(cfg_titlebar, "text_align"));
|
tb->text_align = * (Alignment *) cfg_getptr(cfg_titlebar, "text_align");
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
|
|
@ -100,7 +100,7 @@ focusicon_new(Statusbar *statusbar, cfg_t *config)
|
||||||
w = p_new(Widget, 1);
|
w = p_new(Widget, 1);
|
||||||
widget_common_new(w, statusbar, config);
|
widget_common_new(w, statusbar, config);
|
||||||
w->draw = focusicon_draw;
|
w->draw = focusicon_draw;
|
||||||
w->alignment = draw_get_align(cfg_getstr(config, "align"));
|
w->alignment = * (Alignment *) cfg_getptr(config, "align");
|
||||||
|
|
||||||
/* Set cache property */
|
/* Set cache property */
|
||||||
w->cache.flags = WIDGET_CACHE_CLIENTS;
|
w->cache.flags = WIDGET_CACHE_CLIENTS;
|
||||||
|
|
|
@ -383,7 +383,7 @@ graph_new(Statusbar *statusbar, cfg_t *config)
|
||||||
|
|
||||||
w->draw = graph_draw;
|
w->draw = graph_draw;
|
||||||
w->tell = graph_tell;
|
w->tell = graph_tell;
|
||||||
w->alignment = draw_get_align(cfg_getstr(config, "align"));
|
w->alignment = * (Alignment *) cfg_getptr(config, "align");
|
||||||
d = w->data = p_new(Data, 1);
|
d = w->data = p_new(Data, 1);
|
||||||
|
|
||||||
d->width = cfg_getint(config, "width");
|
d->width = cfg_getint(config, "width");
|
||||||
|
|
|
@ -99,7 +99,7 @@ iconbox_new(Statusbar *statusbar, cfg_t *config)
|
||||||
|
|
||||||
w = p_new(Widget, 1);
|
w = p_new(Widget, 1);
|
||||||
widget_common_new(w, statusbar, config);
|
widget_common_new(w, statusbar, config);
|
||||||
w->alignment = draw_get_align(cfg_getstr(config, "align"));
|
w->alignment = * (Alignment *) cfg_getptr(config, "align");
|
||||||
w->draw = iconbox_draw;
|
w->draw = iconbox_draw;
|
||||||
w->tell = iconbox_tell;
|
w->tell = iconbox_tell;
|
||||||
w->data = d = p_new(Data, 1);
|
w->data = d = p_new(Data, 1);
|
||||||
|
|
|
@ -64,7 +64,7 @@ layoutinfo_new(Statusbar *statusbar, cfg_t* config)
|
||||||
w = p_new(Widget, 1);
|
w = p_new(Widget, 1);
|
||||||
widget_common_new(w, statusbar, config);
|
widget_common_new(w, statusbar, config);
|
||||||
w->draw = layoutinfo_draw;
|
w->draw = layoutinfo_draw;
|
||||||
w->alignment = draw_get_align(cfg_getstr(config, "align"));
|
w->alignment = * (Alignment *) cfg_getptr(config, "align");
|
||||||
|
|
||||||
/* Set cache property */
|
/* Set cache property */
|
||||||
w->cache.flags = WIDGET_CACHE_LAYOUTS;
|
w->cache.flags = WIDGET_CACHE_LAYOUTS;
|
||||||
|
|
|
@ -430,7 +430,7 @@ progressbar_new(Statusbar *statusbar, cfg_t *config)
|
||||||
if(!(d->vertical = cfg_getbool(config, "vertical")))
|
if(!(d->vertical = cfg_getbool(config, "vertical")))
|
||||||
d->vertical = False;
|
d->vertical = False;
|
||||||
|
|
||||||
w->alignment = draw_get_align(cfg_getstr(config, "align"));
|
w->alignment = * (Alignment *) cfg_getptr(config, "align");
|
||||||
|
|
||||||
if(!(d->data_items = cfg_size(config, "data")))
|
if(!(d->data_items = cfg_size(config, "data")))
|
||||||
{
|
{
|
||||||
|
|
|
@ -205,7 +205,7 @@ taglist_new(Statusbar *statusbar, cfg_t *config)
|
||||||
widget_common_new(w, statusbar, config);
|
widget_common_new(w, statusbar, config);
|
||||||
w->draw = taglist_draw;
|
w->draw = taglist_draw;
|
||||||
w->button_press = taglist_button_press;
|
w->button_press = taglist_button_press;
|
||||||
w->alignment = draw_get_align(cfg_getstr(config, "align"));
|
w->alignment = * (Alignment *) cfg_getptr(config, "align");
|
||||||
|
|
||||||
/* Set cache property */
|
/* Set cache property */
|
||||||
w->cache.flags = WIDGET_CACHE_TAGS | WIDGET_CACHE_CLIENTS;
|
w->cache.flags = WIDGET_CACHE_TAGS | WIDGET_CACHE_CLIENTS;
|
||||||
|
|
|
@ -297,7 +297,7 @@ tasklist_new(Statusbar *statusbar, cfg_t *config)
|
||||||
&d->styles.urgent,
|
&d->styles.urgent,
|
||||||
&globalconf.screens[statusbar->screen].styles.urgent);
|
&globalconf.screens[statusbar->screen].styles.urgent);
|
||||||
|
|
||||||
d->align = draw_get_align(cfg_getstr(config, "text_align"));
|
d->align = * (Alignment *) cfg_getptr(config, "text_align");
|
||||||
d->show_icons = cfg_getbool(config, "show_icons");
|
d->show_icons = cfg_getbool(config, "show_icons");
|
||||||
|
|
||||||
buf = cfg_getstr(config, "show");
|
buf = cfg_getstr(config, "show");
|
||||||
|
|
|
@ -100,7 +100,7 @@ textbox_tell(Widget *widget, char *property, char *command)
|
||||||
else if(!a_strcmp(property, "width"))
|
else if(!a_strcmp(property, "width"))
|
||||||
d->width = atoi(command);
|
d->width = atoi(command);
|
||||||
else if(!a_strcmp(property, "text_align"))
|
else if(!a_strcmp(property, "text_align"))
|
||||||
d->align = draw_get_align(command);
|
d->align = draw_align_get_from_str(command);
|
||||||
else
|
else
|
||||||
return WIDGET_ERROR;
|
return WIDGET_ERROR;
|
||||||
|
|
||||||
|
@ -118,7 +118,7 @@ textbox_new(Statusbar *statusbar, cfg_t *config)
|
||||||
widget_common_new(w, statusbar, config);
|
widget_common_new(w, statusbar, config);
|
||||||
w->draw = textbox_draw;
|
w->draw = textbox_draw;
|
||||||
w->tell = textbox_tell;
|
w->tell = textbox_tell;
|
||||||
w->alignment = draw_get_align(cfg_getstr(config, "align"));
|
w->alignment = * (Alignment *) cfg_getptr(config, "align");
|
||||||
|
|
||||||
w->data = d = p_new(Data, 1);
|
w->data = d = p_new(Data, 1);
|
||||||
|
|
||||||
|
@ -128,7 +128,7 @@ textbox_new(Statusbar *statusbar, cfg_t *config)
|
||||||
&globalconf.screens[statusbar->screen].styles.normal);
|
&globalconf.screens[statusbar->screen].styles.normal);
|
||||||
|
|
||||||
d->width = cfg_getint(config, "width");
|
d->width = cfg_getint(config, "width");
|
||||||
d->align = draw_get_align(cfg_getstr(config, "text_align"));
|
d->align = * (Alignment *) cfg_getptr(config, "text_align");
|
||||||
|
|
||||||
d->text = a_strdup(cfg_getstr(config, "text"));
|
d->text = a_strdup(cfg_getstr(config, "text"));
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue