From de45017b5d5323f7f5d543237e45dc318740c016 Mon Sep 17 00:00:00 2001 From: Julien Danjou Date: Mon, 8 Oct 2007 18:45:05 +0200 Subject: [PATCH] switch to libconfuse instead of libconfig --- README | 2 +- awesomerc | 677 +++++++++++++++++++++++++++++++++++++++---------- config.c | 402 ++++++++++++++--------------- config.h | 2 +- config.mk | 4 +- layouts/tile.c | 32 +-- layouts/tile.h | 2 +- statusbar.c | 2 +- 8 files changed, 760 insertions(+), 363 deletions(-) diff --git a/README b/README index 8cfb7c0a..80c57398 100644 --- a/README +++ b/README @@ -5,7 +5,7 @@ It's based on dwm. Requirements ------------ -In order to build awesome you need the Xlib header files and libconfig. +In order to build awesome you need the Xlib header files and libconfuse. Installation ------------ diff --git a/awesomerc b/awesomerc index 2392f71d..5a9ba9b8 100644 --- a/awesomerc +++ b/awesomerc @@ -1,140 +1,555 @@ # Configuration file for awesome -awesome: +general { - # Default bar position: top, bottom, off - barpos = "top"; - # Window border size - borderpx = 1; - # Window snap pixels - snap = 8; - # Master window width factor (used by tile layouts) - mwfact = 0.6; - # Font - font = "fixed-12"; - # Tags - tags = ( "1", "2", "3", "4", "5", "6", "7", "8", "9" ); - # Colors - normal_border_color = "#111111"; - normal_bg_color = "#111111"; - normal_fg_color = "#eeeeee"; - focus_border_color = "#6666ff"; - focus_bg_color = "#6666ff"; - focus_fg_color = "#ffffff"; - opacity_unfocused = 100; + border = 1 + snap = 8 + resize_hints = true + opacity_unfocused = 100 + focus_move_pointer = false + font = "fixed-12" +} - # Available layouts - layouts = ( - ("[]=", "tile"), - ("=[]", "tileleft"), - ("[ ]", "max"), - ("><>", "floating") - ); +colors +{ + normal_border = "#111111" + normal_bg = "#111111" + normal_fg = "#eeeeee" + focus_border = "#6666ff" + focus_bg = "#6666ff" + focus_fg = "#ffffff" +} - # Number of master windows (used by tile layouts) - nmaster = 2; - ncols = 1; +statusbar +{ + position = "top" +} - # Resize hints - resize_hints = true; +tags +{ + tag 1 + { + layout = "tile" + } + tag 2 + { + layout = "tile" + } + tag 3 + { + layout = "tile" + } + tag 4 + { + layout = "tile" + } + tag 5 + { + layout = "tile" + } + tag 6 + { + layout = "tile" + } + tag 7 + { + layout = "tile" + } + tag 8 + { + layout = "tile" + } + tag 9 + { + layout = "floating" + } +} - # Move pointer to the center of the focused window - focus_move_pointer = false; +layouts +{ + mwfact = 0.5 + nmaster = 1 + ncol = 1 + layout tile + { + symbol = "[]=" + } + layout tileleft + { + symbol = "=[]" + } + +} - # Set of rules to put some windows floating - # or to tag them on launch - rules = ({ name = "Gimp"; - tags = ""; - float = true; - }, - { name = "MPlayer"; - tags = ""; - float = true; - }, - { name = "Acroread"; - tags = ""; - float = true; - }, - { name = "VLC"; - tags = ""; - float = true; - }, - { name = "pinentry"; - tags = ""; - float = true; - }); +rules +{ + rule + { + name = "Gimp" + tags = "" + float = true + } + rule + { + name = "MPlayer" + float = true + } + rule + { + name = "Acroread" + float = true + } + rule + { + name = "pinentry" + float = true + } +} - # modkey for mouse actions - modkey = "Mod4"; - - # Keys binding - keys = ((("Mod4"), "Return", "spawn", "exec xterm"), - (("Mod4"), "space", "setlayout", "+1"), - (("Mod4", "Shift"), "space", "setlayout", "-1"), - (("Mod4"), "b", "togglebar"), - (("Mod4"), "j", "focusnext"), - (("Mod4"), "k", "focusprev"), - (("Mod4", "Shift"), "j", "swapnext"), - (("Mod4", "Shift"), "k", "swapprev"), - (("Mod4", "Control"), "j", "focusnextscreen"), - (("Mod4", "Control"), "k", "focusprevscreen"), - (("Mod4"), "h", "setmwfact", "-0.05"), - (("Mod4"), "l", "setmwfact", "+0.05"), - (("Mod4"), "p", "setborder", "+1"), - (("Mod4", "Shift"), "p", "setborder", "-1"), - (("Mod4", "Shift"), "h", "setnmaster", "+1"), - (("Mod4", "Shift"), "l", "setnmaster", "-1"), - (("Mod4", "Control"), "h", "setncols", "+1"), - (("Mod4", "Control"), "l", "setncols", "-1"), - (("Mod4"), "Escape", "view_tag_prev_selected"), - (("Mod4", "Control"), "Left", "view_tag_previous"), - (("Mod4", "Control"), "Right", "view_tag_next"), - (("Mod4"), "m", "togglemax"), - (("Mod4"), "t", "settrans", "-5"), - (("Mod4", "Shift"), "t", "settrans", "+5"), - (("Mod4", "Control"), "Return", "zoom"), - (("Mod4", "Control"), "space", "togglefloating"), - (("Mod4", "Shift"), "c", "killclient"), - (("Mod4", "Shift"), "q", "quit"), - (("Mod4"), "0", "view"), - (("Mod4"), "1", "view", "1"), - (("Mod4"), "2", "view", "2"), - (("Mod4"), "3", "view", "3"), - (("Mod4"), "4", "view", "4"), - (("Mod4"), "5", "view", "5"), - (("Mod4"), "6", "view", "6"), - (("Mod4"), "7", "view", "7"), - (("Mod4"), "8", "view", "8"), - (("Mod4"), "9", "view", "9"), - (("Mod4", "Control"), "0", "toggleview"), - (("Mod4", "Control"), "1", "toggleview", "1"), - (("Mod4", "Control"), "2", "toggleview", "2"), - (("Mod4", "Control"), "3", "toggleview", "3"), - (("Mod4", "Control"), "4", "toggleview", "4"), - (("Mod4", "Control"), "5", "toggleview", "5"), - (("Mod4", "Control"), "6", "toggleview", "6"), - (("Mod4", "Control"), "7", "toggleview", "7"), - (("Mod4", "Control"), "8", "toggleview", "8"), - (("Mod4", "Control"), "9", "toggleview", "9"), - (("Mod4", "Shift"), "0", "tag"), - (("Mod4", "Shift"), "1", "tag", "1"), - (("Mod4", "Shift"), "2", "tag", "2"), - (("Mod4", "Shift"), "3", "tag", "3"), - (("Mod4", "Shift"), "4", "tag", "4"), - (("Mod4", "Shift"), "5", "tag", "5"), - (("Mod4", "Shift"), "6", "tag", "6"), - (("Mod4", "Shift"), "7", "tag", "7"), - (("Mod4", "Shift"), "8", "tag", "8"), - (("Mod4", "Shift"), "9", "tag", "9"), - (("Mod4", "Shift", "Control"), "0", "toggletag"), - (("Mod4", "Shift", "Control"), "1", "toggletag", "1"), - (("Mod4", "Shift", "Control"), "2", "toggletag", "2"), - (("Mod4", "Shift", "Control"), "3", "toggletag", "3"), - (("Mod4", "Shift", "Control"), "4", "toggletag", "4"), - (("Mod4", "Shift", "Control"), "5", "toggletag", "5"), - (("Mod4", "Shift", "Control"), "6", "toggletag", "6"), - (("Mod4", "Shift", "Control"), "7", "toggletag", "7"), - (("Mod4", "Shift", "Control"), "8", "toggletag", "8"), - (("Mod4", "Shift", "Control"), "9", "toggletag", "9") - ); -}; +keys +{ + modkey = "Mod4" + key + { + modkey = {"Mod4"} + key = "Return" + command = "spawn" + arg = "exec xterm" + } + key + { + modkey = {"Mod4"} + key = "space" + command = "setlayout" + arg = "+1" + } + key + { + modkey = {"Mod4", "Shift"} + key = "space" + command = "setlayout" + arg = "-1" + } + key + { + modkey = {"Mod4"} + key = "b" + command = "togglebar" + } + key + { + modkey = {"Mod4"} + key = "j" + command = "focusnext" + } + key + { + modkey = {"Mod4"} + key = "k" + command = "focusprev" + } + key + { + modkey = {"Mod4", "Shift"} + key = "j" + command = "swapprev" + } + key + { + modkey = {"Mod4", "Shift"} + key = "k" + command = "swapnext" + } + key + { + modkey = {"Mod4", "Control"} + key = "j" + command = "focusnextscreen" + } + key + { + modkey = {"Mod4", "Control"} + key = "k" + command = "focusprevscreen" + } + key + { + modkey = {"Mod4"} + key = "h" + command = "setmwfact" + arg = "-0.05" + } + key + { + modkey = {"Mod4"} + key = "l" + command = "setmwfact" + arg = "+0.05" + } + key + { + modkey = {"Mod4", "Shift"} + key = "h" + command = "setnmaster" + arg = "+1" + } + key + { + modkey = {"Mod4", "Shift"} + key = "l" + command = "setnmaster" + arg = "-1" + } + key + { + modkey = {"Mod4", "Control"} + key = "h" + command = "setncol" + arg = "+1" + } + key + { + modkey = {"Mod4", "Control"} + key = "l" + command = "setncol" + arg = "-1" + } + key + { + modkey = {"Mod4"} + key = "escape" + command = "view_tag_prev_selected" + } + key + { + modkey = {"Mod4"} + key = "Left" + command = "view_tag_previous" + } + key + { + modkey = {"Mod4"} + key = "Right" + command = "view_tag_next" + } + key + { + modkey = {"Mod4"} + key = "m" + command = "togglemax" + } + key + { + modkey = {"Mod4", "Control"} + key = "Return" + command = "zoom" + } + key + { + modkey = {"Mod4", "Control"} + key = "Space" + command = "togglefloating" + } + key + { + modkey = {"Mod4", "Shift"} + key = "c" + command = "killclient" + } + key + { + modkey = {"Mod4", "Shift"} + key = "q" + command = "quit" + } + key + { + modkey = {"Mod4"} + key = "0" + command = "view" + } + key + { + modkey = {"Mod4"} + key = "1" + command = "view" + arg = "1" + } + key + { + modkey = {"Mod4"} + key = "2" + command = "view" + arg = "2" + } + key + { + modkey = {"Mod4"} + key = "3" + command = "view" + arg = "3" + } + key + { + modkey = {"Mod4"} + key = "4" + command = "view" + arg = "5" + } + key + { + modkey = {"Mod4"} + key = "5" + command = "view" + arg = "5" + } + key + { + modkey = {"Mod4"} + key = "6" + command = "view" + arg = "6" + } + key + { + modkey = {"Mod4"} + key = "7" + command = "view" + arg = "7" + } + key + { + modkey = {"Mod4"} + key = "8" + command = "view" + arg = "8" + } + key + { + modkey = {"Mod4"} + key = "9" + command = "view" + arg = "9" + } + key + { + modkey = {"Mod4"} + key = "9" + command = "view" + arg = "9" + } + key + { + modkey = {"Mod4", "Control"} + key = "0" + command = "toggleview" + } + key + { + modkey = {"Mod4", "Control"} + key = "1" + command = "toggleview" + arg = "1" + } + key + { + modkey = {"Mod4", "Control"} + key = "2" + command = "toggleview" + arg = "2" + } + key + { + modkey = {"Mod4", "Control"} + key = "3" + command = "toggleview" + arg = "3" + } + key + { + modkey = {"Mod4", "Control"} + key = "4" + command = "toggleview" + arg = "4" + } + key + { + modkey = {"Mod4", "Control"} + key = "5" + command = "toggleview" + arg = "5" + } + key + { + modkey = {"Mod4", "Control"} + key = "6" + command = "toggleview" + arg = "6" + } + key + { + modkey = {"Mod4", "Control"} + key = "7" + command = "toggleview" + arg = "7" + } + key + { + modkey = {"Mod4", "Control"} + key = "8" + command = "toggleview" + arg = "8" + } + key + { + modkey = {"Mod4", "Control"} + key = "9" + command = "toggleview" + arg = "9" + } + key + { + modkey = {"Mod4", "Shift"} + key = "0" + command = "tag" + } + key + { + modkey = {"Mod4", "Shift"} + key = "1" + command = "tag" + arg = "1" + } + key + { + modkey = {"Mod4", "Shift"} + key = "2" + command = "tag" + arg = "2" + } + key + { + modkey = {"Mod4", "Shift"} + key = "3" + command = "tag" + arg = "3" + } + key + { + modkey = {"Mod4", "Shift"} + key = "4" + command = "tag" + arg = "4" + } + key + { + modkey = {"Mod4", "Shift"} + key = "5" + command = "tag" + arg = "5" + } + key + { + modkey = {"Mod4", "Shift"} + key = "6" + command = "tag" + arg = "6" + } + key + { + modkey = {"Mod4", "Shift"} + key = "7" + command = "tag" + arg = "7" + } + key + { + modkey = {"Mod4", "Shift"} + key = "8" + command = "tag" + arg = "8" + } + key + { + modkey = {"Mod4", "Shift"} + key = "9" + command = "tag" + arg = "9" + } + key + { + modkey = {"Mod4", "Shift", "Control"} + key = "0" + command = "toggletag" + } + key + { + modkey = {"Mod4", "Shift", "Control"} + key = "1" + command = "toggletag" + arg = "1" + } + key + { + modkey = {"Mod4", "Shift", "Control"} + key = "2" + command = "toggletag" + arg = "2" + } + key + { + modkey = {"Mod4", "Shift", "Control"} + key = "3" + command = "toggletag" + arg = "3" + } + key + { + modkey = {"Mod4", "Shift", "Control"} + key = "3" + command = "toggletag" + arg = "3" + } + key + { + modkey = {"Mod4", "Shift", "Control"} + key = "4" + command = "toggletag" + arg = "4" + } + key + { + modkey = {"Mod4", "Shift", "Control"} + key = "5" + command = "toggletag" + arg = "5" + } + key + { + modkey = {"Mod4", "Shift", "Control"} + key = "6" + command = "toggletag" + arg = "6" + } + key + { + modkey = {"Mod4", "Shift", "Control"} + key = "7" + command = "toggletag" + arg = "7" + } + key + { + modkey = {"Mod4", "Shift", "Control"} + key = "8" + command = "toggletag" + arg = "8" + } + key + { + modkey = {"Mod4", "Shift", "Control"} + key = "9" + command = "toggletag" + arg = "9" + } +} diff --git a/config.c b/config.c index a89a3c7a..02e68008 100644 --- a/config.c +++ b/config.c @@ -24,7 +24,7 @@ * \defgroup ui_callback */ -#include +#include #include #include "awesome.h" @@ -111,7 +111,7 @@ static const NameFuncLink KeyfuncList[] = { /* layouts/tile.c */ {"setmwfact", uicb_setmwfact}, {"setnmaster", uicb_setnmaster}, - {"setncols", uicb_setncols}, + {"setncol", uicb_setncol}, /* screen.c */ {"focusnextscreen", uicb_focusnextscreen}, {"focusprevscreen", uicb_focusprevscreen}, @@ -167,14 +167,95 @@ name_func_lookup(const char *funcname, const NameFuncLink * list) void parse_config(Display * disp, int scr, DC * drawcontext, const char *confpatharg, awesome_config *awesomeconf) { - /* Main configuration object for parsing*/ - config_t awesomelibconf; - config_setting_t *conftags; - config_setting_t *conflayouts, *confsublayouts; - config_setting_t *confrules, *confsubrules; - config_setting_t *confkeys, *confsubkeys, *confkeysmasks, *confkeymaskelem; - int i = 0, j = 0; - double f = 0.0; + static cfg_opt_t general_opts[] = + { + CFG_INT((char *) "border", 1, CFGF_NONE), + CFG_INT((char *) "snap", 8, CFGF_NONE), + CFG_BOOL((char *) "resize_hints", cfg_false, CFGF_NONE), + CFG_INT((char *) "opacity_unfocused", 100, CFGF_NONE), + CFG_BOOL((char *) "focus_move_pointer", cfg_false, CFGF_NONE), + CFG_STR((char *) "font", (char *) "mono-12", CFGF_NONE), + CFG_END() + }; + static cfg_opt_t colors_opts[] = + { + CFG_STR((char *) "normal_border", (char *) "#111111", CFGF_NONE), + CFG_STR((char *) "normal_bg", (char *) "#111111", CFGF_NONE), + CFG_STR((char *) "normal_fg", (char *) "#eeeeee", CFGF_NONE), + CFG_STR((char *) "focus_border", (char *) "#6666ff", CFGF_NONE), + CFG_STR((char *) "focus_bg", (char *) "#6666ff", CFGF_NONE), + CFG_STR((char *) "focus_fg", (char *) "#ffffff", CFGF_NONE), + CFG_END() + }; + static cfg_opt_t statusbar_opts[] = + { + CFG_STR((char *) "position", (char *) "top", CFGF_NONE), + CFG_END() + }; + static cfg_opt_t tag_opts[] = + { + CFG_STR((char *) "layout", (char *) "tile", CFGF_NONE), + CFG_END() + }; + static cfg_opt_t tags_opts[] = + { + CFG_SEC((char *) "tag", tag_opts, CFGF_TITLE | CFGF_MULTI), + CFG_END() + }; + static cfg_opt_t layout_opts[] = + { + CFG_STR((char *) "symbol", (char *) "???", CFGF_NONE), + CFG_END() + }; + static cfg_opt_t layouts_opts[] = + { + CFG_SEC((char *) "layout", layout_opts, CFGF_TITLE | CFGF_MULTI), + CFG_FLOAT((char *) "mwfact", 0.5, CFGF_NONE), + CFG_INT((char *) "nmaster", 1, CFGF_NONE), + CFG_INT((char *) "ncol", 1, CFGF_NONE), + CFG_END() + }; + static cfg_opt_t rule_opts[] = + { + CFG_STR((char *) "name", (char *) "", CFGF_NONE), + CFG_STR((char *) "tags", (char *) "", CFGF_NONE), + CFG_BOOL((char *) "float", cfg_false, CFGF_NONE), + CFG_END() + }; + static cfg_opt_t rules_opts[] = + { + CFG_SEC((char *) "rule", rule_opts, CFGF_MULTI), + CFG_END() + }; + static cfg_opt_t key_opts[] = + { + CFG_STR_LIST((char *) "modkey", (char *) "{Mod4}", CFGF_NONE), + CFG_STR((char *) "key", (char *) "None", CFGF_NONE), + CFG_STR((char *) "command", (char *) "", CFGF_NONE), + CFG_STR((char *) "arg", NULL, CFGF_NONE), + CFG_END() + }; + static cfg_opt_t keys_opts[] = + { + CFG_STR((char *) "modkey", (char *) "Mod4", CFGF_NONE), + CFG_SEC((char *) "key", key_opts, CFGF_MULTI), + CFG_END() + }; + static cfg_opt_t opts[] = + { + CFG_SEC((char *) "general", general_opts, CFGF_NONE), + CFG_SEC((char *) "colors", colors_opts, CFGF_NONE), + CFG_SEC((char *) "statusbar", statusbar_opts, CFGF_NONE), + CFG_SEC((char *) "tags", tags_opts, CFGF_NONE), + CFG_SEC((char *) "layouts", layouts_opts, CFGF_NONE), + CFG_SEC((char *) "rules", rules_opts, CFGF_NONE), + CFG_SEC((char *) "keys", keys_opts, CFGF_NONE), + CFG_END() + }; + cfg_t *cfg, *cfg_general, *cfg_colors, *cfg_statusbar, + *cfg_tags, *cfg_layouts, *cfg_rules, *cfg_keys, *cfgsectmp; + int i = 0; + unsigned int j = 0; const char *tmp, *homedir; char *confpath; KeySym tmp_key; @@ -193,8 +274,6 @@ parse_config(Display * disp, int scr, DC * drawcontext, const char *confpatharg, a_strcat(confpath, confpath_len, AWESOME_CONFIG_FILE); } - config_init(&awesomelibconf); - a_strcpy(awesomeconf->statustext, sizeof(awesomeconf->statustext), "awesome-" VERSION); /* store display */ @@ -204,167 +283,49 @@ parse_config(Display * disp, int scr, DC * drawcontext, const char *confpatharg, awesomeconf->screen = scr; awesomeconf->phys_screen = get_phys_screen(disp, scr); - if(config_read_file(&awesomelibconf, confpath) == CONFIG_FALSE) - fprintf(stderr, "awesome: error parsing configuration file at line %d: %s\n", - config_error_line(&awesomelibconf), config_error_text(&awesomelibconf)); + cfg = cfg_init(opts, CFGF_NONE); + if(cfg_parse(cfg, confpath) == CFG_PARSE_ERROR) + fprintf(stderr, "awesome: error parsing configuration file\n"); - /* font */ - tmp = config_lookup_string(&awesomelibconf, "awesome.font"); - drawcontext->font = XftFontOpenName(disp, awesomeconf->phys_screen, tmp ? tmp : "sans-12"); + cfg_general = cfg_getsec(cfg, "general"); + cfg_colors = cfg_getsec(cfg, "colors"); + cfg_statusbar = cfg_getsec(cfg, "statusbar"); + cfg_tags = cfg_getsec(cfg, "tags"); + cfg_layouts = cfg_getsec(cfg, "layouts"); + cfg_rules = cfg_getsec(cfg, "rules"); + cfg_keys = cfg_getsec(cfg, "keys"); + /* General section */ + + awesomeconf->borderpx = cfg_getint(cfg_general, "border"); + awesomeconf->snap = cfg_getint(cfg_general, "snap"); + awesomeconf->resize_hints = cfg_getbool(cfg_general, "resize_hints"); + awesomeconf->opacity_unfocused = cfg_getint(cfg_general, "opacity_unfocused"); + awesomeconf->focus_move_pointer = cfg_getbool(cfg_general, "focus_move_pointer"); + drawcontext->font = XftFontOpenName(disp, awesomeconf->phys_screen, cfg_getstr(cfg_general, "font")); if(!drawcontext->font) eprint("awesome: cannot init font\n"); - /* layouts */ - conflayouts = config_lookup(&awesomelibconf, "awesome.layouts"); + /* Colors */ + drawcontext->norm[ColBorder] = initxcolor(disp, awesomeconf->phys_screen, + cfg_getstr(cfg_colors, "normal_border")).pixel; + drawcontext->norm[ColBG] = initxcolor(disp, awesomeconf->phys_screen, + cfg_getstr(cfg_colors, "normal_bg")).pixel; + drawcontext->sel[ColBorder] = initxcolor(disp, awesomeconf->phys_screen, + cfg_getstr(cfg_colors, "focus_border")).pixel; + drawcontext->sel[ColBG] = initxcolor(disp, awesomeconf->phys_screen, + cfg_getstr(cfg_colors, "focus_bg")).pixel; - if(!conflayouts) - { - fprintf(stderr, "awesome: layouts not found in configuration file, setting default\n"); - awesomeconf->nlayouts = 2; - awesomeconf->layouts = p_new(Layout, awesomeconf->nlayouts + 1); - awesomeconf->layouts[0].symbol = a_strdup("[]="); - awesomeconf->layouts[0].arrange = layout_tile; - awesomeconf->layouts[1].symbol = a_strdup("<><"); - awesomeconf->layouts[1].arrange = layout_floating; - awesomeconf->layouts[2].symbol = NULL; - awesomeconf->layouts[2].arrange = NULL; - } - else - { - awesomeconf->nlayouts = config_setting_length(conflayouts); - awesomeconf->layouts = p_new(Layout, awesomeconf->nlayouts + 1); - for(i = 0; (confsublayouts = config_setting_get_elem(conflayouts, i)); i++) - { - awesomeconf->layouts[i].arrange = - name_func_lookup(config_setting_get_string_elem(confsublayouts, 1), LayoutsList); - if(!awesomeconf->layouts[i].arrange) - { - fprintf(stderr, "awesome: unknown layout #%d in configuration file\n", i); - awesomeconf->layouts[i].symbol = NULL; - continue; - } - awesomeconf->layouts[i].symbol = a_strdup(config_setting_get_string_elem(confsublayouts, 0)); - } - awesomeconf->layouts[i].symbol = NULL; - awesomeconf->layouts[i].arrange = NULL; - } + colorbuf = initxcolor(disp, awesomeconf->phys_screen, cfg_getstr(cfg_colors, "normal_fg")); + drawcontext->norm[ColFG] = colorbuf.pixel; + drawcontext->text_normal = colorbuf; + colorbuf = initxcolor(disp, awesomeconf->phys_screen, cfg_getstr(cfg_colors, "focus_fg")); + drawcontext->sel[ColFG] = colorbuf.pixel; + drawcontext->text_selected = colorbuf; - awesomeconf->current_layout = awesomeconf->layouts; - - if(!awesomeconf->nlayouts || !awesomeconf->current_layout->arrange) - eprint("awesome: fatal: no default layout available\n"); - - for(i = 0; i < awesomeconf->nlayouts; i++) - { - j = drawcontext->font->height + - textwidth(disp, drawcontext->font, - awesomeconf->layouts[i].symbol, a_strlen(awesomeconf->layouts[i].symbol)); - if(j > awesomeconf->statusbar.width) - awesomeconf->statusbar.width = j; - } - - /* tags */ - conftags = config_lookup(&awesomelibconf, "awesome.tags"); - - if(!conftags) - { - fprintf(stderr, "awesome: tags not found in configuration file, setting default\n"); - awesomeconf->ntags = 3; - awesomeconf->tags = p_new(Tag, awesomeconf->ntags); - awesomeconf->tags[0].name = a_strdup("this"); - awesomeconf->tags[1].name = a_strdup("is"); - awesomeconf->tags[2].name = a_strdup("awesome"); - awesomeconf->tags[0].selected = True; - awesomeconf->tags[1].selected = False; - awesomeconf->tags[2].selected = False; - awesomeconf->tags[0].was_selected = False; - awesomeconf->tags[1].was_selected = False; - awesomeconf->tags[2].was_selected = False; - awesomeconf->tags[0].layout = awesomeconf->layouts; - awesomeconf->tags[1].layout = awesomeconf->layouts; - awesomeconf->tags[2].layout = awesomeconf->layouts; - } - else - { - awesomeconf->ntags = config_setting_length(conftags); - awesomeconf->tags = p_new(Tag, awesomeconf->ntags); - - for(i = 0; (tmp = config_setting_get_string_elem(conftags, i)); i++) - { - awesomeconf->tags[i].name = a_strdup(tmp); - awesomeconf->tags[i].selected = False; - awesomeconf->tags[i].was_selected = False; - /** \todo add support for default tag/layout in configuration file */ - awesomeconf->tags[i].layout = awesomeconf->layouts; - } - } - - if(!awesomeconf->ntags) - eprint("awesome: fatal: no tags found in configuration file\n"); - - /* select first tag by default */ - awesomeconf->tags[0].selected = True; - awesomeconf->tags[0].was_selected = True; - - /* rules */ - confrules = config_lookup(&awesomelibconf, "awesome.rules"); - - if(!confrules) - { - awesomeconf->nrules = 0; - fprintf(stderr, "awesome: no rules found in configuration file\n"); - } - else - { - awesomeconf->nrules = config_setting_length(confrules); - awesomeconf->rules = p_new(Rule, awesomeconf->nrules); - for(i = 0; (confsubrules = config_setting_get_elem(confrules, i)); i++) - { - awesomeconf->rules[i].prop = a_strdup(config_setting_get_string(config_setting_get_member(confsubrules, "name"))); - awesomeconf->rules[i].tags = a_strdup(config_setting_get_string(config_setting_get_member(confsubrules, "tags"))); - if(awesomeconf->rules[i].tags && !a_strlen(awesomeconf->rules[i].tags)) - awesomeconf->rules[i].tags = NULL; - awesomeconf->rules[i].isfloating = - config_setting_get_bool(config_setting_get_member(confsubrules, "float")); - } - } - - /* modkey */ - tmp_key = key_mask_lookup(config_lookup_string(&awesomelibconf, "awesome.modkey")); - awesomeconf->modkey = tmp_key ? tmp_key : Mod1Mask; - - /* find numlock mask */ - awesomeconf->numlockmask = get_numlockmask(disp); - - /* keys */ - confkeys = config_lookup(&awesomelibconf, "awesome.keys"); - - if(!confkeys) - { - awesomeconf->nkeys = 0; - fprintf(stderr, "awesome: no keys found in configuration file\n"); - } - else - { - awesomeconf->nkeys = config_setting_length(confkeys); - awesomeconf->keys = p_new(Key, awesomeconf->nkeys); - - for(i = 0; (confsubkeys = config_setting_get_elem(confkeys, i)); i++) - { - confkeysmasks = config_setting_get_elem(confsubkeys, 0); - for(j = 0; (confkeymaskelem = config_setting_get_elem(confkeysmasks, j)); j++) - awesomeconf->keys[i].mod |= key_mask_lookup(config_setting_get_string(confkeymaskelem)); - awesomeconf->keys[i].keysym = XStringToKeysym(config_setting_get_string_elem(confsubkeys, 1)); - awesomeconf->keys[i].func = - name_func_lookup(config_setting_get_string_elem(confsubkeys, 2), KeyfuncList); - awesomeconf->keys[i].arg = a_strdup(config_setting_get_string_elem(confsubkeys, 3)); - } - } - - /* barpos */ - tmp = config_lookup_string(&awesomelibconf, "awesome.barpos"); + /* Statusbar */ + tmp = cfg_getstr(cfg_statusbar, "position"); if(tmp && !a_strncmp(tmp, "off", 6)) awesomeconf->statusbar_default_position = BarOff; @@ -375,64 +336,85 @@ parse_config(Display * disp, int scr, DC * drawcontext, const char *confpatharg, awesomeconf->statusbar.position = awesomeconf->statusbar_default_position; - /* borderpx */ - awesomeconf->borderpx = config_lookup_int(&awesomelibconf, "awesome.borderpx"); + /* Layouts */ - /* opacity */ - awesomeconf->opacity_unfocused = config_lookup_int(&awesomelibconf, "awesome.opacity_unfocused"); - if(awesomeconf->opacity_unfocused >= 100 || awesomeconf->opacity_unfocused == 0) - awesomeconf->opacity_unfocused = -1; + awesomeconf->nlayouts = cfg_size(cfg_layouts, "layout"); + awesomeconf->layouts = p_new(Layout, awesomeconf->nlayouts); + for(i = 0; i < awesomeconf->nlayouts; i++) + { + cfgsectmp = cfg_getnsec(cfg_layouts, "layout", i); + awesomeconf->layouts[i].arrange = name_func_lookup(cfg_title(cfgsectmp), LayoutsList); + if(!awesomeconf->layouts[i].arrange) + { + fprintf(stderr, "awesome: unknown layout #%d in configuration file\n", i); + awesomeconf->layouts[i].symbol = NULL; + continue; + } + awesomeconf->layouts[i].symbol = a_strdup(cfg_getstr(cfgsectmp, "symbol")); + } - /* snap */ - i = config_lookup_int(&awesomelibconf, "awesome.snap"); - awesomeconf->snap = i ? i : 8; + awesomeconf->mwfact = cfg_getfloat(cfg_layouts, "mwfact"); + awesomeconf->nmaster = cfg_getint(cfg_layouts, "nmaster"); + awesomeconf->ncol = cfg_getint(cfg_layouts, "ncol"); - /* nmaster */ - i = config_lookup_int(&awesomelibconf, "awesome.nmaster"); - awesomeconf->nmaster = i ? i : 1; + awesomeconf->current_layout = awesomeconf->layouts; - /* ncols */ - i = config_lookup_int(&awesomelibconf, "awesome.ncols"); - awesomeconf->ncols = i ? i : 1; + if(!awesomeconf->nlayouts || !awesomeconf->current_layout->arrange) + eprint("awesome: fatal: no default layout available\n"); - /* mwfact */ - f = config_lookup_float(&awesomelibconf, "awesome.mwfact"); - awesomeconf->mwfact = f ? f : 0.6; + /* Rules */ - /* resize_hints */ - awesomeconf->resize_hints = config_lookup_bool(&awesomelibconf, "awesome.resize_hints"); + awesomeconf->nrules = cfg_size(cfg_rules, "rule"); + awesomeconf->rules = p_new(Rule, awesomeconf->nrules); + for(i = 0; i < awesomeconf->nrules; i++) + { + cfgsectmp = cfg_getnsec(cfg_rules, "rule", i); + awesomeconf->rules[i].prop = a_strdup(cfg_getstr(cfgsectmp, "name")); + awesomeconf->rules[i].tags = a_strdup(cfg_getstr(cfgsectmp, "tags")); + if(!a_strlen(awesomeconf->rules[i].tags)) + awesomeconf->rules[i].tags = NULL; + awesomeconf->rules[i].isfloating = cfg_getbool(cfgsectmp, "float"); + } - /* focus_move_pointer */ - awesomeconf->focus_move_pointer = config_lookup_bool(&awesomelibconf, "awesome.focus_move_pointer"); + /* Tags */ - /* colors */ - tmp = config_lookup_string(&awesomelibconf, "awesome.normal_border_color"); - colorbuf = initxcolor(disp, awesomeconf->phys_screen, tmp ? tmp : "#dddddd"); - drawcontext->norm[ColBorder] = colorbuf.pixel; + awesomeconf->ntags = cfg_size(cfg_tags, "tag"); + awesomeconf->tags = p_new(Tag, awesomeconf->ntags); + for(i = 0; i < awesomeconf->ntags; i++) + { + cfgsectmp = cfg_getnsec(cfg_tags, "tag", i); + awesomeconf->tags[i].name = a_strdup(cfg_title(cfgsectmp)); + awesomeconf->tags[i].selected = False; + awesomeconf->tags[i].was_selected = False; + awesomeconf->tags[i].layout = awesomeconf->layouts; + } - tmp = config_lookup_string(&awesomelibconf, "awesome.normal_bg_color"); - colorbuf = initxcolor(disp, awesomeconf->phys_screen, tmp ? tmp : "#000000"); - drawcontext->norm[ColBG] = colorbuf.pixel; + if(!awesomeconf->ntags) + eprint("awesome: fatal: no tags found in configuration file\n"); - tmp = config_lookup_string(&awesomelibconf, "awesome.normal_fg_color"); - colorbuf = initxcolor(disp, awesomeconf->phys_screen, tmp ? tmp : "#ffffff"); - drawcontext->norm[ColFG] = colorbuf.pixel; - drawcontext->text_normal = colorbuf; + /* select first tag by default */ + awesomeconf->tags[0].selected = True; + awesomeconf->tags[0].was_selected = True; - tmp = config_lookup_string(&awesomelibconf, "awesome.focus_border_color"); - colorbuf = initxcolor(disp, awesomeconf->phys_screen, tmp ? tmp : "#008b8b"); - drawcontext->sel[ColBorder] = colorbuf.pixel; + /* Keys */ + tmp_key = key_mask_lookup(cfg_getstr(cfg_keys, "modkey")); + awesomeconf->modkey = tmp_key ? tmp_key : Mod4Mask; + awesomeconf->numlockmask = get_numlockmask(disp); - tmp = config_lookup_string(&awesomelibconf, "awesome.focus_bg_color"); - colorbuf = initxcolor(disp, awesomeconf->phys_screen, tmp ? tmp : "#008b8b"); - drawcontext->sel[ColBG] = colorbuf.pixel; + awesomeconf->nkeys = cfg_size(cfg_keys, "key"); + awesomeconf->keys = p_new(Key, awesomeconf->nkeys); + for(i = 0; i < awesomeconf->nkeys; i++) + { + cfgsectmp = cfg_getnsec(cfg_keys, "key", i); + for(j = 0; j < cfg_size(cfgsectmp, "modkey"); j++) + awesomeconf->keys[i].mod |= key_mask_lookup(cfg_getnstr(cfgsectmp, "modkey", j)); + awesomeconf->keys[i].keysym = XStringToKeysym(cfg_getstr(cfgsectmp, "key")); + awesomeconf->keys[i].func = name_func_lookup(cfg_getstr(cfgsectmp, "command"), KeyfuncList); + awesomeconf->keys[i].arg = a_strdup(cfg_getstr(cfgsectmp, "arg")); + } - tmp = config_lookup_string(&awesomelibconf, "awesome.focus_fg_color"); - colorbuf = initxcolor(disp, awesomeconf->phys_screen, tmp ? tmp : "#ffffff"); - drawcontext->sel[ColFG] = colorbuf.pixel; - drawcontext->text_selected = colorbuf; - - config_destroy(&awesomelibconf); + /* Free! Like a river! */ + cfg_free(cfg); p_delete(&confpath); } diff --git a/config.h b/config.h index 6d799a7d..0bc98f06 100644 --- a/config.h +++ b/config.h @@ -142,7 +142,7 @@ struct awesome_config /** Number of master windows */ int nmaster; /** Number of columns in tile layout */ - int ncols; + int ncol; /** Transparency of unfocused clients */ int opacity_unfocused; /** Focus move pointer */ diff --git a/config.mk b/config.mk index 54d411ee..f1bd93ff 100644 --- a/config.mk +++ b/config.mk @@ -14,8 +14,8 @@ X11INC = /usr/include/X11 X11LIB = /usr/lib/X11 # includes and libs -INCS = -I. -I/usr/include -I${X11INC} `pkg-config --cflags libconfig xft` -LIBS = -L/usr/lib -lc -L${X11LIB} -lX11 `pkg-config --libs libconfig xft` -lXext -lXrandr -lXinerama +INCS = -I. -I/usr/include -I${X11INC} `pkg-config --cflags libconfuse xft` +LIBS = -L/usr/lib -lc -L${X11LIB} -lX11 `pkg-config --libs libconfuse xft` -lXext -lXrandr -lXinerama # flags CFLAGS = -fgnu89-inline -std=gnu99 -ggdb3 -pipe -Wall -Wextra -W -Wchar-subscripts -Wundef -Wshadow -Wcast-align -Wwrite-strings -Wsign-compare -Wunused -Wuninitialized -Winit-self -Wpointer-arith -Wredundant-decls -Wno-format-zero-length -Wmissing-prototypes -Wmissing-format-attribute -Wmissing-noreturn -O3 ${INCS} -DVERSION=\"${VERSION}\" diff --git a/layouts/tile.c b/layouts/tile.c index 986e2bc0..528df5b8 100644 --- a/layouts/tile.c +++ b/layouts/tile.c @@ -48,16 +48,16 @@ uicb_setnmaster(Display *disp, } void -uicb_setncols(Display *disp, - DC * drawcontext, - awesome_config *awesomeconf, - const char * arg) +uicb_setncol(Display *disp, + DC * drawcontext, + awesome_config *awesomeconf, + const char * arg) { if(!arg || (!IS_ARRANGE(layout_tile) && !IS_ARRANGE(layout_tileleft))) return; - if((awesomeconf->ncols = (int) compute_new_value_from_arg(arg, (double) awesomeconf->ncols)) < 1) - awesomeconf->ncols = 1; + if((awesomeconf->ncol = (int) compute_new_value_from_arg(arg, (double) awesomeconf->ncol)) < 1) + awesomeconf->ncol = 1; arrange(disp, drawcontext, awesomeconf); } @@ -101,7 +101,7 @@ _tile(Display *disp, awesome_config *awesomeconf, const Bool right) /* master size */ unsigned int mw = 0, mh = 0; int n, i, masterwin = 0, otherwin = 0; - int real_ncols = 1, win_by_col = 1, current_col = 0; + int real_ncol = 1, win_by_col = 1, current_col = 0; ScreenInfo *screens_info = NULL; Client *c; @@ -131,7 +131,7 @@ _tile(Display *disp, awesome_config *awesomeconf, const Bool right) else mh = mw = 0; - real_ncols = MIN(otherwin, awesomeconf->ncols); + real_ncol = MIN(otherwin, awesomeconf->ncol); for(i = 0, c = clients; c; c = c->next) { @@ -147,23 +147,23 @@ _tile(Display *disp, awesome_config *awesomeconf, const Bool right) } else { /* tile window */ - if(real_ncols) - win_by_col = otherwin / real_ncols; + if(real_ncol) + win_by_col = otherwin / real_ncol; - if((i - awesomeconf->nmaster) && (i - awesomeconf->nmaster) % win_by_col == 0 && current_col < real_ncols - 1) + if((i - awesomeconf->nmaster) && (i - awesomeconf->nmaster) % win_by_col == 0 && current_col < real_ncol - 1) current_col++; - if(current_col == real_ncols - 1) - win_by_col += otherwin % real_ncols; + if(current_col == real_ncol - 1) + win_by_col += otherwin % real_ncol; - if(otherwin <= real_ncols) + if(otherwin <= real_ncol) nh = wah - 2 * c->border; else nh = (wah / win_by_col) - 2 * c->border; - nw = (waw - mw) / real_ncols - 2 * c->border; + nw = (waw - mw) / real_ncol - 2 * c->border; - if(i == awesomeconf->nmaster || otherwin <= real_ncols || (i - awesomeconf->nmaster) % win_by_col == 0) + if(i == awesomeconf->nmaster || otherwin <= real_ncol || (i - awesomeconf->nmaster) % win_by_col == 0) ny = way; else ny = way + ((i - awesomeconf->nmaster) % win_by_col) * (nh + 2 * c->border); diff --git a/layouts/tile.h b/layouts/tile.h index cd4619b0..9e245abc 100644 --- a/layouts/tile.h +++ b/layouts/tile.h @@ -29,7 +29,7 @@ LAYOUT_PROTO(layout_tile); LAYOUT_PROTO(layout_tileleft); UICB_PROTO(uicb_setnmaster); -UICB_PROTO(uicb_setncols); +UICB_PROTO(uicb_setncol); UICB_PROTO(uicb_setmwfact); #endif diff --git a/statusbar.c b/statusbar.c index 60e5968f..e1ba231c 100644 --- a/statusbar.c +++ b/statusbar.c @@ -94,7 +94,7 @@ drawstatusbar(Display *disp, DC *drawcontext, awesome_config * awesomeconf) else if(IS_ARRANGE(layout_tile) || IS_ARRANGE(layout_tileleft)) { char buf[256]; - snprintf(buf, sizeof(buf), "nmaster: %d ncols: %d mwfact: %.2lf", awesomeconf->nmaster, awesomeconf->ncols, awesomeconf->mwfact); + snprintf(buf, sizeof(buf), "nmaster: %d ncol: %d mwfact: %.2lf", awesomeconf->nmaster, awesomeconf->ncol, awesomeconf->mwfact); drawtext(disp, awesomeconf->phys_screen, drawcontext, awesomeconf->statusbar.drawable, buf, drawcontext->norm, drawcontext->text_normal); } else