From 1fb61f54df720d323dcd8f9e6dc7acaba32177d3 Mon Sep 17 00:00:00 2001 From: Julien Danjou Date: Sun, 9 Mar 2008 16:00:14 +0100 Subject: [PATCH] [awesome-menu] Remove command line option and add support for menu {} in conffile --- awesome-menu.c | 87 ++++++++++++++++++++++++++++++--------------- common/configopts.c | 19 ++++++++++ 2 files changed, 77 insertions(+), 29 deletions(-) diff --git a/awesome-menu.c b/awesome-menu.c index 5db371407..5280542b4 100644 --- a/awesome-menu.c +++ b/awesome-menu.c @@ -111,17 +111,18 @@ static void __attribute__ ((noreturn)) exit_help(int exit_code) { FILE *outfile = (exit_code == EXIT_SUCCESS) ? stdout : stderr; - fprintf(outfile, "Usage: %s [-x xcoord] [-y ycoord] [-e command] \n", + fprintf(outfile, "Usage: %s [-e command] \n", PROGNAME); exit(exit_code); } static int -config_parse(const char *confpatharg) +config_parse(const char *confpatharg, const char *menu_title, Area *geometry) { - int ret; - char *confpath; - cfg_t *cfg, *cfg_screen, *cfg_general, *cfg_colors; + int ret, i; + char *confpath, *opt; + cfg_t *cfg, *cfg_menu = NULL, *cfg_screen, *cfg_general, + *cfg_colors, *cfg_menu_colors = NULL; if(!confpatharg) confpath = config_file(); @@ -143,35 +144,65 @@ config_parse(const char *confpatharg) if(ret) return ret; - /* get global screen section */ - cfg_screen = cfg_getsec(cfg, "screen"); + if(!(cfg_menu = cfg_gettsec(cfg, "menu", menu_title))) + warn("no definition for menu %s in configuration file: using default\n", menu_title); - if(!cfg_screen) + /* get global screen section */ + if(!(cfg_screen = cfg_getsec(cfg, "screen"))) eprint("parsing configuration file failed, no screen section found\n"); /* get colors and general section */ + if(cfg_menu) + cfg_menu_colors = cfg_getsec(cfg_menu, "colors"); cfg_general = cfg_getsec(cfg_screen, "general"); cfg_colors = cfg_getsec(cfg_screen, "colors"); /* colors */ + if(!cfg_menu_colors || !(opt = cfg_getstr(cfg_menu_colors, "normal_fg"))) + opt = cfg_getstr(cfg_colors, "normal_fg"); + draw_color_new(globalconf.display, DefaultScreen(globalconf.display), - cfg_getstr(cfg_colors, "normal_fg"), - &globalconf.fg); + opt, &globalconf.fg); + + if(!cfg_menu_colors || !(opt = cfg_getstr(cfg_menu_colors, "normal_bg"))) + opt = cfg_getstr(cfg_colors, "normal_bg"); + draw_color_new(globalconf.display, DefaultScreen(globalconf.display), - cfg_getstr(cfg_colors, "normal_bg"), - &globalconf.bg); + opt, &globalconf.bg); + + if(!cfg_menu_colors || !(opt = cfg_getstr(cfg_menu_colors, "focus_fg"))) + opt = cfg_getstr(cfg_colors, "focus_fg"); + draw_color_new(globalconf.display, DefaultScreen(globalconf.display), - cfg_getstr(cfg_colors, "focus_fg"), - &globalconf.fg_focus); + opt, &globalconf.fg_focus); + + if(!cfg_menu_colors || !(opt = cfg_getstr(cfg_menu_colors, "focus_bg"))) + opt = cfg_getstr(cfg_colors, "focus_bg"); + draw_color_new(globalconf.display, DefaultScreen(globalconf.display), - cfg_getstr(cfg_colors, "focus_bg"), - &globalconf.bg_focus); + opt, &globalconf.bg_focus); /* font */ + if(!cfg_menu || !(opt = cfg_getstr(cfg_menu, "font"))) + opt = cfg_getstr(cfg_general, "font"); + globalconf.font = XftFontOpenName(globalconf.display, DefaultScreen(globalconf.display), - cfg_getstr(cfg_general, "font")); + opt); + globalconf.shadow_offset = cfg_getint(cfg_general, "text_shadow_offset"); + if(cfg_menu) + { + if((i = cfg_getint(cfg_menu, "x")) != (int) 0xffffffff) + geometry->x = i; + if((i = cfg_getint(cfg_menu, "y")) != (int) 0xffffffff) + geometry->y = i; + if((i = cfg_getint(cfg_menu, "width")) > 0) + geometry->width = i; + if((i = cfg_getint(cfg_menu, "height")) > 0) + geometry->height = i; + } + p_delete(&confpath); return ret; @@ -552,12 +583,6 @@ main(int argc, char **argv) case 'v': eprint_version(PROGNAME); break; - case 'x': - geometry.x = atoi(optarg); - break; - case 'y': - geometry.y = atoi(optarg); - break; case 'h': exit_help(EXIT_SUCCESS); break; @@ -572,14 +597,15 @@ main(int argc, char **argv) if(argc - optind >= 1) globalconf.prompt = a_strdup(argv[optind]); - if((ret = config_parse(configfile))) + if((ret = config_parse(configfile, globalconf.prompt, &geometry))) return ret; /* Get the numlock mask */ globalconf.numlockmask = get_numlockmask(disp); /* Init the geometry */ - geometry.height = globalconf.font->height * 1.5; + if(!geometry.height) + geometry.height = globalconf.font->height * 1.5; /* XXX this must be replace with a common/ infra */ if(XineramaIsActive(disp)) @@ -600,13 +626,16 @@ main(int argc, char **argv) && (y < 0 || (y >= si[i].y_org && y < si[i].y_org + si[i].height))) break; - geometry.x = si[i].x_org; - geometry.y = si[i].y_org; - geometry.width = si[i].width; + if(!geometry.x) + geometry.x = si[i].x_org; + if(!geometry.y) + geometry.y = si[i].y_org; + if(!geometry.width) + geometry.width = si[i].width; XFree(si); } - else + else if(!geometry.width) geometry.width = DisplayWidth(disp, DefaultScreen(disp)); /* Create the window */ diff --git a/common/configopts.c b/common/configopts.c index 344fc5c43..8ff8ee4e5 100644 --- a/common/configopts.c +++ b/common/configopts.c @@ -316,12 +316,31 @@ cfg_opt_t mouse_opts[] = CFG_SEC((char *) "client", mouse_generic_opts, CFGF_MULTI), CFG_AWESOME_END() }; +cfg_opt_t menu_colors_opts[] = +{ + CFG_STR((char *) "normal_bg", NULL, CFGF_NONE), + CFG_STR((char *) "normal_fg", NULL, CFGF_NONE), + CFG_STR((char *) "focus_bg", NULL, CFGF_NONE), + CFG_STR((char *) "focus_fg", NULL, CFGF_NONE), + CFG_AWESOME_END() +}; +cfg_opt_t menu_opts[] = +{ + CFG_INT((char *) "width", 0, CFGF_NONE), + CFG_INT((char *) "height", 0, CFGF_NONE), + CFG_INT((char *) "y", 0xffffffff, CFGF_NONE), + CFG_INT((char *) "x", 0xffffffff, CFGF_NONE), + CFG_STR((char *) "font", NULL, CFGF_NONE), + CFG_SEC((char *) "colors", menu_colors_opts, CFGF_NONE), + CFG_AWESOME_END() +}; cfg_opt_t awesome_opts[] = { CFG_SEC((char *) "screen", screen_opts, CFGF_TITLE | CFGF_MULTI | CFGF_NO_TITLE_DUPES), CFG_SEC((char *) "rules", rules_opts, CFGF_NONE), CFG_SEC((char *) "keys", keys_opts, CFGF_NONE), CFG_SEC((char *) "mouse", mouse_opts, CFGF_NONE), + CFG_SEC((char *) "menu", menu_opts, CFGF_TITLE | CFGF_MULTI | CFGF_NO_TITLE_DUPES), CFG_AWESOME_END() };