config: Make functions for all config section
This commit is contained in:
parent
fd31ec4e4b
commit
f873a83b44
246
src/config.c
246
src/config.c
@ -34,16 +34,7 @@
|
||||
|
||||
#define FILE_NAME ".config/wmfs/wmfsrc"
|
||||
|
||||
cfg_t *cfg;
|
||||
cfg_t *cfg_misc;
|
||||
cfg_t *cfg_bar;
|
||||
cfg_t *cfg_alias;
|
||||
cfg_t *cfg_root;
|
||||
cfg_t *cfg_client;
|
||||
cfg_t *cfg_layouts;
|
||||
cfg_t *cfg_tags;
|
||||
cfg_t *cfg_keys;
|
||||
cfg_t *cfgtmp;
|
||||
cfg_t *cfg, *cfgtmp;
|
||||
|
||||
static cfg_opt_t misc_opts[] =
|
||||
{
|
||||
@ -242,6 +233,9 @@ name_to_uint_t mouse_button_list[] =
|
||||
{"5", Button5 },
|
||||
};
|
||||
|
||||
/* The following function are for configuration
|
||||
section util. {{{
|
||||
*/
|
||||
void*
|
||||
name_to_func(char *name, func_name_list_t l[])
|
||||
{
|
||||
@ -334,95 +328,95 @@ mouse_section(MouseBinding mb[], cfg_t *cfg, int ns)
|
||||
return;
|
||||
}
|
||||
|
||||
/** Configuration initialization
|
||||
* \todo Make functions for all section (tag, client, layout...)
|
||||
/* }}} */
|
||||
|
||||
|
||||
/* The following function are the
|
||||
different configuration section. {{{
|
||||
*/
|
||||
void
|
||||
init_conf(void)
|
||||
conf_alias_section(cfg_t *cfg_a)
|
||||
{
|
||||
char final_path[128];
|
||||
int ret, i, j, l, k;
|
||||
int i;
|
||||
|
||||
sprintf(final_path, "%s/%s",
|
||||
strdup(getenv("HOME")),
|
||||
strdup(FILE_NAME));
|
||||
|
||||
cfg = cfg_init(opts, CFGF_NONE);
|
||||
ret = cfg_parse(cfg, final_path);
|
||||
|
||||
if(ret == CFG_FILE_ERROR
|
||||
|| ret == CFG_PARSE_ERROR)
|
||||
{
|
||||
fprintf(stderr, "WMFS: parsing configuration file (%s) failed\n", final_path);
|
||||
sprintf(final_path, "%s/wmfs/wmfsrc", XDG_CONFIG_DIR);
|
||||
fprintf(stderr, "Use the default configuration (%s).\n", final_path);
|
||||
cfg = cfg_init(opts, CFGF_NONE);
|
||||
ret = cfg_parse(cfg, final_path);
|
||||
}
|
||||
|
||||
cfg_misc = cfg_getsec(cfg, "misc");
|
||||
cfg_alias = cfg_getsec(cfg, "alias");
|
||||
cfg_root = cfg_getsec(cfg, "root");
|
||||
cfg_client = cfg_getsec(cfg, "client");
|
||||
cfg_bar = cfg_getsec(cfg, "bar");
|
||||
cfg_layouts = cfg_getsec(cfg, "layouts");
|
||||
cfg_tags = cfg_getsec(cfg, "tags");
|
||||
cfg_keys = cfg_getsec(cfg, "keys");
|
||||
|
||||
/* alias */
|
||||
if(cfg_size(cfg_alias, "alias") < 256)
|
||||
{
|
||||
for(i = 0; i < cfg_size(cfg_alias, "alias"); ++i)
|
||||
if(cfg_size(cfg_a, "alias") < 256)
|
||||
for(i = 0; i < cfg_size(cfg_a, "alias"); ++i)
|
||||
{
|
||||
cfgtmp = cfg_getnsec(cfg_alias, "alias", i);
|
||||
cfgtmp = cfg_getnsec(cfg_a, "alias", i);
|
||||
conf.alias[i].name = strdup(cfg_title(cfgtmp));
|
||||
conf.alias[i].content = strdup(cfg_getstr(cfgtmp, "content"));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
fprintf(stderr,"WMFS Configuration: Too many alias (%d) !\n", cfg_size(cfg_alias, "alias"));
|
||||
fprintf(stderr,"WMFS Configuration: Too many alias (%d) !\n", cfg_size(cfg_a, "alias"));
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
/* misc */
|
||||
conf.font = alias_to_str(strdup(cfg_getstr(cfg_misc, "font")));
|
||||
conf.raisefocus = cfg_getbool(cfg_misc, "raisefocus");
|
||||
conf.raiseswitch = cfg_getbool(cfg_misc, "raiseswitch");
|
||||
return;
|
||||
}
|
||||
|
||||
/* bar */
|
||||
conf.colors.bar = getcolor(alias_to_str(cfg_getstr(cfg_bar, "bg")));
|
||||
conf.colors.text = strdup(alias_to_str(cfg_getstr(cfg_bar, "fg")));
|
||||
conf.bartop = (strcmp(strdup(cfg_getstr(cfg_bar, "position")), "top") == 0) ? True : False;
|
||||
void
|
||||
conf_misc_section(cfg_t *cfg_m)
|
||||
{
|
||||
conf.font = alias_to_str(strdup(cfg_getstr(cfg_m, "font")));
|
||||
conf.raisefocus = cfg_getbool(cfg_m, "raisefocus");
|
||||
conf.raiseswitch = cfg_getbool(cfg_m, "raiseswitch");
|
||||
|
||||
/* root */
|
||||
conf.root.background_command = strdup(alias_to_str(cfg_getstr(cfg_root, "background_command")));
|
||||
conf.root.nmouse = cfg_size(cfg_root, "mouse");
|
||||
return;
|
||||
}
|
||||
|
||||
void
|
||||
conf_bar_section(cfg_t *cfg_b)
|
||||
{
|
||||
conf.colors.bar = getcolor(alias_to_str(cfg_getstr(cfg_b, "bg")));
|
||||
conf.colors.text = strdup(alias_to_str(cfg_getstr(cfg_b, "fg")));
|
||||
conf.bartop = (strcmp(strdup(cfg_getstr(cfg_b, "position")), "top") == 0) ? True : False;
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
void
|
||||
conf_root_section(cfg_t *cfg_r)
|
||||
{
|
||||
conf.root.background_command = strdup(alias_to_str(cfg_getstr(cfg_r, "background_command")));
|
||||
conf.root.nmouse = cfg_size(cfg_r, "mouse");
|
||||
conf.root.mouse = emalloc(conf.root.nmouse, sizeof(MouseBinding));
|
||||
mouse_section(conf.root.mouse, cfg_root, conf.root.nmouse);
|
||||
mouse_section(conf.root.mouse, cfg_r, conf.root.nmouse);
|
||||
|
||||
/* client */
|
||||
conf.client.borderheight = (cfg_getint(cfg_client, "border_height"))
|
||||
? cfg_getint(cfg_client, "border_height") : 1;
|
||||
conf.client.place_at_mouse = cfg_getbool(cfg_client, "place_at_mouse");
|
||||
conf.client.bordernormal = getcolor(alias_to_str(cfg_getstr(cfg_client, "border_normal")));
|
||||
conf.client.borderfocus = getcolor(alias_to_str(cfg_getstr(cfg_client, "border_focus")));
|
||||
conf.client.resizecorner_normal = getcolor(alias_to_str(cfg_getstr(cfg_client, "resize_corner_normal")));
|
||||
conf.client.resizecorner_focus = getcolor(alias_to_str(cfg_getstr(cfg_client, "resize_corner_focus")));
|
||||
conf.client.mod |= char_to_modkey(cfg_getstr(cfg_client, "modifier"));
|
||||
conf.client.nmouse = cfg_size(cfg_client, "mouse");
|
||||
return;
|
||||
}
|
||||
|
||||
void
|
||||
conf_client_section(cfg_t *cfg_c)
|
||||
{
|
||||
/* Client misc */
|
||||
conf.client.borderheight = (cfg_getint(cfg_c, "border_height")) ? cfg_getint(cfg_c, "border_height") : 1;
|
||||
conf.client.place_at_mouse = cfg_getbool(cfg_c, "place_at_mouse");
|
||||
conf.client.bordernormal = getcolor(alias_to_str(cfg_getstr(cfg_c, "border_normal")));
|
||||
conf.client.borderfocus = getcolor(alias_to_str(cfg_getstr(cfg_c, "border_focus")));
|
||||
conf.client.resizecorner_normal = getcolor(alias_to_str(cfg_getstr(cfg_c, "resize_corner_normal")));
|
||||
conf.client.resizecorner_focus = getcolor(alias_to_str(cfg_getstr(cfg_c, "resize_corner_focus")));
|
||||
conf.client.mod |= char_to_modkey(cfg_getstr(cfg_c, "modifier"));
|
||||
conf.client.nmouse = cfg_size(cfg_c, "mouse");
|
||||
conf.client.mouse = emalloc(conf.client.nmouse, sizeof(MouseBinding));
|
||||
mouse_section(conf.client.mouse, cfg_client, conf.client.nmouse);
|
||||
mouse_section(conf.client.mouse, cfg_c, conf.client.nmouse);
|
||||
|
||||
/* titlebar (into the client section) */
|
||||
cfgtmp = cfg_getsec(cfg_client, "titlebar");
|
||||
/* Titlebar part */
|
||||
cfgtmp = cfg_getsec(cfg_c, "titlebar");
|
||||
conf.titlebar.height = cfg_getint(cfgtmp, "height");
|
||||
conf.titlebar.fg = alias_to_str(cfg_getstr(cfgtmp, "fg"));
|
||||
conf.titlebar.nmouse = cfg_size(cfgtmp, "mouse");
|
||||
conf.titlebar.mouse = emalloc(conf.titlebar.nmouse, sizeof(MouseBinding));
|
||||
mouse_section(conf.titlebar.mouse, cfgtmp, conf.titlebar.nmouse);
|
||||
|
||||
/* layout */
|
||||
return;
|
||||
}
|
||||
|
||||
void
|
||||
conf_layout_section(cfg_t *cfg_l)
|
||||
{
|
||||
int i;
|
||||
|
||||
/* Set conf.layout NULL for conf reload */
|
||||
for(i = 0; i < NUM_OF_LAYOUT; ++i)
|
||||
{
|
||||
@ -430,11 +424,11 @@ init_conf(void)
|
||||
conf.layout[i].func = NULL;
|
||||
}
|
||||
|
||||
conf.colors.layout_fg = strdup(alias_to_str(cfg_getstr(cfg_layouts, "fg")));
|
||||
conf.colors.layout_bg = getcolor(alias_to_str(cfg_getstr(cfg_layouts, "bg")));
|
||||
conf.colors.layout_fg = strdup(alias_to_str(cfg_getstr(cfg_l, "fg")));
|
||||
conf.colors.layout_bg = getcolor(alias_to_str(cfg_getstr(cfg_l, "bg")));
|
||||
|
||||
if((conf.nlayout = cfg_size(cfg_layouts, "layout")) > NUM_OF_LAYOUT
|
||||
|| !(conf.nlayout = cfg_size(cfg_layouts, "layout")))
|
||||
if((conf.nlayout = cfg_size(cfg_l, "layout")) > NUM_OF_LAYOUT
|
||||
|| !(conf.nlayout = cfg_size(cfg_l, "layout")))
|
||||
{
|
||||
fprintf(stderr, "WMFS Configuration: Too many or no layouts (%d)\n", conf.nlayout);
|
||||
conf.nlayout = 1;
|
||||
@ -447,7 +441,7 @@ init_conf(void)
|
||||
{
|
||||
for(i = 0; i < conf.nlayout; ++i)
|
||||
{
|
||||
cfgtmp = cfg_getnsec(cfg_layouts, "layout", i);
|
||||
cfgtmp = cfg_getnsec(cfg_l, "layout", i);
|
||||
if(!name_to_func(strdup(cfg_getstr(cfgtmp, "type")), layout_list))
|
||||
{
|
||||
fprintf(stderr, "WMFS Configuration: Unknow Layout type: \"%s\"\n",
|
||||
@ -462,25 +456,32 @@ init_conf(void)
|
||||
}
|
||||
}
|
||||
|
||||
/* Tag
|
||||
* If there is no tag in the conf or more than
|
||||
return;
|
||||
}
|
||||
|
||||
void
|
||||
conf_tag_section(cfg_t *cfg_t)
|
||||
{
|
||||
int i, j, k;
|
||||
|
||||
/* If there is no tag in the conf or more than
|
||||
* MAXTAG (32) print an error and create only one.
|
||||
*/
|
||||
conf.tag_round = cfg_getbool(cfg_tags, "tag_round");
|
||||
conf.colors.tagselfg = strdup(alias_to_str(cfg_getstr(cfg_tags, "sel_fg")));
|
||||
conf.colors.tagselbg = getcolor(alias_to_str(cfg_getstr(cfg_tags, "sel_bg")));
|
||||
conf.colors.tag_occupied_bg = getcolor(alias_to_str(cfg_getstr(cfg_tags, "occupied_bg")));
|
||||
conf.colors.tagbord = getcolor(alias_to_str(cfg_getstr(cfg_tags, "border")));
|
||||
conf.tag_round = cfg_getbool(cfg_t, "tag_round");
|
||||
conf.colors.tagselfg = strdup(alias_to_str(cfg_getstr(cfg_t, "sel_fg")));
|
||||
conf.colors.tagselbg = getcolor(alias_to_str(cfg_getstr(cfg_t, "sel_bg")));
|
||||
conf.colors.tag_occupied_bg = getcolor(alias_to_str(cfg_getstr(cfg_t, "occupied_bg")));
|
||||
conf.colors.tagbord = getcolor(alias_to_str(cfg_getstr(cfg_t, "border")));
|
||||
|
||||
/* Alloc all */
|
||||
conf.ntag = emalloc(screen_count(), sizeof(int));
|
||||
tags = emalloc(screen_count(), sizeof(Tag*));
|
||||
for(i = 0; i < screen_count(); ++i)
|
||||
tags[i] = emalloc(cfg_size(cfg_tags, "tag") + 1, sizeof(Tag));
|
||||
tags[i] = emalloc(cfg_size(cfg_t, "tag") + 1, sizeof(Tag));
|
||||
|
||||
for(i = 0; i < cfg_size(cfg_tags, "tag"); ++i)
|
||||
for(i = 0; i < cfg_size(cfg_t, "tag"); ++i)
|
||||
{
|
||||
cfgtmp = cfg_getnsec(cfg_tags, "tag", i);
|
||||
cfgtmp = cfg_getnsec(cfg_t, "tag", i);
|
||||
j = cfg_getint(cfgtmp, "screen");
|
||||
if(j < 0 || j > screen_count() - 1)
|
||||
j = -1;
|
||||
@ -510,6 +511,7 @@ init_conf(void)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
for(i = 0; i < screen_count(); ++i)
|
||||
if(!conf.ntag[i] || conf.ntag[i] > MAXTAG)
|
||||
{
|
||||
@ -528,28 +530,74 @@ init_conf(void)
|
||||
for(j = 0; j < screen_count(); ++j)
|
||||
seltag[j] = 1;
|
||||
|
||||
/* keybind */
|
||||
conf.nkeybind = cfg_size(cfg_keys, "key");
|
||||
return;
|
||||
}
|
||||
|
||||
void
|
||||
conf_keybind_section(cfg_t *cfg_k)
|
||||
{
|
||||
int i, j;
|
||||
|
||||
conf.nkeybind = cfg_size(cfg_k, "key");
|
||||
keys = emalloc(conf.nkeybind, sizeof(Key));
|
||||
|
||||
for(j = 0; j < conf.nkeybind; ++j)
|
||||
for(i = 0; i < conf.nkeybind; ++i)
|
||||
{
|
||||
cfgtmp = cfg_getnsec(cfg_keys, "key", j);
|
||||
cfgtmp = cfg_getnsec(cfg_k, "key", i);
|
||||
|
||||
for(l = 0; l < cfg_size(cfgtmp, "mod"); ++l)
|
||||
keys[j].mod |= char_to_modkey(cfg_getnstr(cfgtmp, "mod", l));
|
||||
for(j = 0; j < cfg_size(cfgtmp, "mod"); ++j)
|
||||
keys[j].mod |= char_to_modkey(cfg_getnstr(cfgtmp, "mod", j));
|
||||
|
||||
keys[j].keysym = XStringToKeysym(cfg_getstr(cfgtmp, "key"));
|
||||
keys[j].func = name_to_func(cfg_getstr(cfgtmp, "func"), func_list);
|
||||
if(keys[j].func == NULL)
|
||||
keys[i].keysym = XStringToKeysym(cfg_getstr(cfgtmp, "key"));
|
||||
keys[i].func = name_to_func(cfg_getstr(cfgtmp, "func"), func_list);
|
||||
if(keys[i].func == NULL)
|
||||
{
|
||||
fprintf(stderr, "WMFS Configuration error: Unknow Function \"%s\"\n",
|
||||
cfg_getstr(cfgtmp, "func"));
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
keys[j].cmd = (!strdup(alias_to_str((cfg_getstr(cfgtmp, "cmd"))))
|
||||
keys[i].cmd = (!strdup(alias_to_str((cfg_getstr(cfgtmp, "cmd"))))
|
||||
? NULL : strdup(alias_to_str(cfg_getstr(cfgtmp, "cmd"))));
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
/* }}} */
|
||||
|
||||
/** Configuration initialization
|
||||
*/
|
||||
void
|
||||
init_conf(void)
|
||||
{
|
||||
char final_path[128];
|
||||
int ret;
|
||||
|
||||
sprintf(final_path, "%s/%s",
|
||||
strdup(getenv("HOME")),
|
||||
strdup(FILE_NAME));
|
||||
|
||||
cfg = cfg_init(opts, CFGF_NONE);
|
||||
ret = cfg_parse(cfg, final_path);
|
||||
|
||||
if(ret == CFG_FILE_ERROR || ret == CFG_PARSE_ERROR)
|
||||
{
|
||||
fprintf(stderr, "WMFS: parsing configuration file (%s) failed\n", final_path);
|
||||
sprintf(final_path, "%s/wmfs/wmfsrc", XDG_CONFIG_DIR);
|
||||
fprintf(stderr, "Use the default configuration (%s).\n", final_path);
|
||||
cfg = cfg_init(opts, CFGF_NONE);
|
||||
ret = cfg_parse(cfg, final_path);
|
||||
}
|
||||
|
||||
conf_alias_section(cfg_getsec(cfg, "alias"));
|
||||
conf_misc_section(cfg_getsec(cfg, "misc"));
|
||||
conf_bar_section(cfg_getsec(cfg, "bar"));
|
||||
conf_root_section(cfg_getsec(cfg, "root"));
|
||||
conf_client_section(cfg_getsec(cfg, "client"));
|
||||
conf_layout_section(cfg_getsec(cfg, "layouts"));
|
||||
conf_tag_section(cfg_getsec(cfg, "tags"));
|
||||
conf_keybind_section(cfg_getsec(cfg, "keys"));
|
||||
|
||||
cfg_free(cfg);
|
||||
|
||||
return;
|
||||
|
||||
@ -142,6 +142,14 @@ void frame_moveresize(Client *c, XRectangle geo);
|
||||
void frame_update(Client *c);
|
||||
|
||||
/* config.c */
|
||||
void conf_alias_section(cfg_t *cfg_a);
|
||||
void conf_misc_section(cfg_t *cfg_m);
|
||||
void conf_bar_section(cfg_t *cfg_b);
|
||||
void conf_root_section(cfg_t *cfg_r);
|
||||
void conf_client_section(cfg_t *cfg_c);
|
||||
void conf_layout_section(cfg_t *cfg_l);
|
||||
void conf_tag_section(cfg_t *cfg_t);
|
||||
void conf_keybind_section(cfg_t *cfg_k);
|
||||
void init_conf(void);
|
||||
|
||||
/* event.c */
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user