From c3e063d55eee83bfd951395d5e4a787cac48c885 Mon Sep 17 00:00:00 2001 From: Julien Danjou Date: Sun, 4 May 2008 12:47:16 +0200 Subject: [PATCH] [config] Use a string array as args for uicb Signed-off-by: Julien Danjou --- awesomerc.in | 489 +++++++++----------------------------------- common/configopts.c | 21 +- config.c | 76 ++----- 3 files changed, 120 insertions(+), 466 deletions(-) diff --git a/awesomerc.in b/awesomerc.in index 53697f03d..5e00b8f10 100644 --- a/awesomerc.in +++ b/awesomerc.in @@ -50,104 +50,31 @@ screen 0 taglist mytaglist { - mouse - { - button = "1" - command = "tag_view" - } - mouse - { - button = "1" - modkey = {"Mod4"} - command = "client_tag" - } - mouse - { - button = "3" - command = "tag_toggleview" - } - mouse - { - button = "3" - modkey = {"Mod4"} - command = "client_toggletag" - } - mouse - { - button = "4" - command = "tag_viewnext" - } - mouse - { - button = "5" - command = "tag_viewprev" - } + mouse { button = "1" command = "tag_view" } + mouse { button = "1" modkey = {"Mod4"} command = "client_tag" } + mouse { button = "3" command = "tag_toggleview" } + mouse { button = "3" modkey = {"Mod4"} command = "client_toggletag" } + mouse { button = "4" command = "tag_viewnext" } + mouse { button = "5" command = "tag_viewprev" } } layoutinfo mylayoutinfo { - mouse - { - button = "1" - command = "tag_setlayout" - arg = "+1" - } - mouse - { - button = "4" - command = "tag_setlayout" - arg = "+1" - } - mouse - { - button = "3" - command = "tag_setlayout" - arg = "-1" - } - mouse - { - button = "5" - command = "tag_setlayout" - arg = "-1" - } + mouse { button = "1" command = "tag_setlayout" args = {"+1"} } + mouse { button = "4" command = "tag_setlayout" args = {"+1"} } + mouse { button = "3" command = "tag_setlayout" args = {"-1"} } + mouse { button = "5" command = "tag_setlayout" args = {"-1"} } } tasklist mytasklist { - mouse - { - button = "4" - command = "client_focus" - arg = "+1" - } - mouse - { - button = "5" - command = "client_focus" - arg = "-1" - } - mouse - { - modkey = {"Mod4"} - button = "4" - command = "client_swap" - arg = "+1" - } - mouse - { - modkey = {"Mod4"} - button = "5" - command = "client_swap" - arg = "-1" - } + mouse { button = "4" command = "client_focus" args = {"+1"} } + mouse { button = "5" command = "client_focus" args = {"-1"} } + mouse { modkey = {"Mod4"} button = "4" command = "client_swap" args = {"+1"} } + mouse { modkey = {"Mod4"} button = "5" command = "client_swap" args = {"-1"} } } iconbox logo { image = "@iconsdir@/awesome16.png" - mouse - { - button = "1" - command = "spawn" - arg = "exec xterm -e man awesome" - } + mouse { button = "1" command = "spawn" args = {"exec xterm -e man awesome"} } } } } @@ -162,314 +89,94 @@ rules mouse { - root - { - button = "3" - command = "spawn" - arg = "exec xterm" - } - root - { - button = "4" - command = "tag_viewnext" - } - root - { - button = "5" - command = "tag_viewprev" - } - client - { - modkey = {"Mod4"} - button = "1" - command = "client_movemouse" - } - client - { - modkey = {"Mod4"} - button = "2" - command = "client_swap" - arg = "0" - } - client - { - modkey = {"Mod4"} - button = "3" - command = "client_resizemouse" - } - titlebar - { - button = "1" - command = "client_movemouse" - } - titlebar - { - button = "3" - command = "client_resizemouse" - } + root { button = "3" command = "spawn" args = {"exec xterm"} } + root { button = "4" command = "tag_viewnext" } + root { button = "5" command = "tag_viewprev" } + client { modkey = {"Mod4"} button = "1" command = "client_movemouse" } + client { modkey = {"Mod4"} button = "2" command = "client_swap" args = {"0"} } + client { modkey = {"Mod4"} button = "3" command = "client_resizemouse" } + titlebar { button = "1" command = "client_movemouse" } + titlebar { button = "3" command = "client_resizemouse" } } keys { - key - { - modkey = {"Mod4"} - key = "F1" - command = "spawn" - arg = "for i in /usr/share/man/man?;do ls $i; done | cut -d. -f1 | awesome-menu -e 'xterm -e man ' 'See manual page for:'" - } - key - { - modkey = {"Mod4"} - key = "F2" - command = "spawn" - arg = "find /usr/bin -type f -executable ! -empty | awesome-menu -e 'exec ' Execute:" - } - key - { - modkey = {"Mod4"} - key = "F3" - command = "spawn" - arg = "cut -d' ' -f1 ~/.ssh/known_hosts | cut -d, -f1 | awesome-menu -e 'xterm -e ssh ' 'ssh to:'" - } - key - { - modkey = {"Mod4"} - key = "Return" - command = "spawn" - arg = "exec xterm" - } - key - { - modkey = {"Mod4"} - key = "space" - command = "tag_setlayout" - arg = "+1" - } - key - { - modkey = {"Mod4", "Shift"} - key = "space" - command = "tag_setlayout" - arg = "-1" - } - key - { - modkey = {"Mod4"} - key = "b" - command = "statusbar_toggle" - } - key - { - modkey = {"Mod4"} - key = "j" - command = "client_focus" - arg = "+1" - } - key - { - modkey = {"Mod4"} - key = "k" - command = "client_focus" - arg = "-1" - } - key - { - modkey = {"Mod4"} - key = "Tab" - command = "focus_history" - arg = "-1" - } - key - { - modkey = {"Mod4", "Shift"} - key = "j" - command = "client_swap" - arg = "+1" - } - key - { - modkey = {"Mod4", "Shift"} - key = "k" - command = "client_swap" - arg = "-1" - } - key - { - modkey = {"Mod4", "Control"} - key = "j" - command = "screen_focus" - arg = "+1" - } - key - { - modkey = {"Mod4", "Control"} - key = "k" - command = "screen_focus" - arg = "-1" - } - key - { - modkey = {"Mod4"} - key = "h" - command = "tag_setmwfact" - arg = "-0.05" - } - key - { - modkey = {"Mod4"} - key = "l" - command = "tag_setmwfact" - arg = "+0.05" - } - key - { - modkey = {"Mod4", "Shift"} - key = "h" - command = "tag_setnmaster" - arg = "+1" - } - key - { - modkey = {"Mod4", "Shift"} - key = "l" - command = "tag_setnmaster" - arg = "-1" - } - key - { - modkey = {"Mod4", "Control"} - key = "h" - command = "tag_setncol" - arg = "+1" - } - key - { - modkey = {"Mod4", "Control"} - key = "l" - command = "tag_setncol" - arg = "-1" - } - key - { - modkey = {"Mod4"} - key = "Escape" - command = "tag_prev_selected" - } - key - { - modkey = {"Mod4"} - key = "Left" - command = "tag_viewprev" - } - key - { - modkey = {"Mod4"} - key = "Right" - command = "tag_viewnext" - } - key - { - modkey = {"Mod4"} - key = "m" - command = "client_togglemax" - } - key - { - modkey = {"Mod4", "Control"} - key = "Return" - command = "client_swap" - arg = "0" - } - key - { - modkey = {"Mod4", "Control"} - key = "space" - command = "client_setfloating" - } - key - { - modkey = {"Mod4"} - key = "s" - command = "client_togglescratch" - } - key - { - modkey = {"Mod4", "Control"} - key = "s" - command = "client_setscratch" - } - key - { - modkey = {"Mod4", "Shift"} - key = "c" - command = "client_kill" - } - key - { - modkey = {"Mod4", "Shift"} - key = "q" - command = "quit" - } - key - { - modkey = {"Mod4", "Control"} - key = "r" - command = "restart" - } - key - { - modkey = {"Mod4"} - key = "0" - command = "tag_view" - } - keylist - { - modkey = {"Mod4"} - command = "tag_view" - keylist = { 1, 2, 3, 4, 5, 6, 7, 8, 9 } - arglist = { 1, 2, 3, 4, 5, 6, 7, 8, 9 } - } - key - { - modkey = {"Mod4", "Control"} - key = "0" - command = "tag_toggleview" - } - keylist - { - modkey = {"Mod4", "Control"} - command = "tag_toggleview" - keylist = { 1, 2, 3, 4, 5, 6, 7, 8, 9 } - arglist = { 1, 2, 3, 4, 5, 6, 7, 8, 9 } - } + key { modkey = {"Mod4"} key = "F1" command = "spawn" args = {"for i in /usr/share/man/man?;do ls $i; done | cut -d. -f1 | awesome-menu -e 'xterm -e man ' 'See manual page for:'"} } + key { modkey = {"Mod4"} key = "F2" command = "spawn" args = {"find /usr/bin -type f -executable ! -empty | awesome-menu -e 'exec ' Execute:"} } + key { modkey = {"Mod4"} key = "F3" command = "spawn" args = {"cut -d' ' -f1 ~/.ssh/known_hosts | cut -d, -f1 | awesome-menu -e 'xterm -e ssh ' 'ssh to:'"} } + key { modkey = {"Mod4"} key = "Return" command = "spawn" args = {"exec xterm"} } + key { modkey = {"Mod4"} key = "space" command = "tag_setlayout" args = {"+1"} } + key { modkey = {"Mod4", "Shift"} key = "space" command = "tag_setlayout" args = {"-1"} } + key { modkey = {"Mod4"} key = "b" command = "statusbar_toggle" } + key { modkey = {"Mod4"} key = "j" command = "client_focus" args = {"+1"} } + key { modkey = {"Mod4"} key = "k" command = "client_focus" args = {"-1"} } + key { modkey = {"Mod4"} key = "Tab" command = "focus_history" args = {"-1"} } + key { modkey = {"Mod4", "Shift"} key = "j" command = "client_swap" args = {"+1"} } + key { modkey = {"Mod4", "Shift"} key = "k" command = "client_swap" args = {"-1"} } + key { modkey = {"Mod4", "Control"} key = "j" command = "screen_focus" args = {"+1"} } + key { modkey = {"Mod4", "Control"} key = "k" command = "screen_focus" args = {"-1"} } + key { modkey = {"Mod4"} key = "h" command = "tag_setmwfact" args = {"-0.05"} } + key { modkey = {"Mod4"} key = "l" command = "tag_setmwfact" args = {"+0.05"} } + key { modkey = {"Mod4", "Shift"} key = "h" command = "tag_setnmaster" args = {"+1"} } + key { modkey = {"Mod4", "Shift"} key = "l" command = "tag_setnmaster" args = {"-1"} } + key { modkey = {"Mod4", "Control"} key = "h" command = "tag_setncol" args = {"+1"} } + key { modkey = {"Mod4", "Control"} key = "l" command = "tag_setncol" args = {"-1"} } + key { modkey = {"Mod4"} key = "Escape" command = "tag_prev_selected" } + key { modkey = {"Mod4"} key = "Left" command = "tag_viewprev" } + key { modkey = {"Mod4"} key = "Right" command = "tag_viewnext" } + key { modkey = {"Mod4"} key = "m" command = "client_togglemax" } + key { modkey = {"Mod4", "Control"} key = "Return" command = "client_swap" args = {"0"} } + key { modkey = {"Mod4", "Control"} key = "space" command = "client_setfloating" } + key { modkey = {"Mod4"} key = "s" command = "client_togglescratch" } + key { modkey = {"Mod4", "Control"} key = "s" command = "client_setscratch" } + key { modkey = {"Mod4", "Shift"} key = "c" command = "client_kill" } + key { modkey = {"Mod4", "Shift"} key = "q" command = "quit" } + key { modkey = {"Mod4", "Control"} key = "r" command = "restart" } - key - { - modkey = {"Mod4", "Shift"} - key = "0" - command = "client_tag" - } - keylist - { - modkey = {"Mod4", "Shift"} - command = "client_tag" - keylist = { 1, 2, 3, 4, 5, 6, 7, 8, 9 } - arglist = { 1, 2, 3, 4, 5, 6, 7, 8, 9 } - } + key { modkey = {"Mod4"} key = "0" command = "tag_view" } + key { modkey = {"Mod4"} key = "0" command = "tag_view" } + key { modkey = {"Mod4"} key = "1" command = "tag_view" args = {"1"} } + key { modkey = {"Mod4"} key = "2" command = "tag_view" args = {"2"} } + key { modkey = {"Mod4"} key = "3" command = "tag_view" args = {"3"} } + key { modkey = {"Mod4"} key = "4" command = "tag_view" args = {"4"} } + key { modkey = {"Mod4"} key = "5" command = "tag_view" args = {"5"} } + key { modkey = {"Mod4"} key = "6" command = "tag_view" args = {"6"} } + key { modkey = {"Mod4"} key = "7" command = "tag_view" args = {"7"} } + key { modkey = {"Mod4"} key = "8" command = "tag_view" args = {"8"} } + key { modkey = {"Mod4"} key = "9" command = "tag_view" args = {"9"} } - key - { - modkey = {"Mod4", "Shift", "Control"} - key = "0" - command = "client_toggletag" - } - keylist - { - modkey = {"Mod4", "Shift", "Control"} - command = "client_toggletag" - keylist = { 1, 2, 3, 4, 5, 6, 7, 8, 9 } - arglist = { 1, 2, 3, 4, 5, 6, 7, 8, 9 } - } + key { modkey = {"Mod4"} key = "0" command = "tag_toggleview" } + key { modkey = {"Mod4", "Control"} key = "0" command = "tag_toggleview" } + key { modkey = {"Mod4", "Control"} key = "1" command = "tag_toggleview" args = {"1"} } + key { modkey = {"Mod4", "Control"} key = "2" command = "tag_toggleview" args = {"2"} } + key { modkey = {"Mod4", "Control"} key = "3" command = "tag_toggleview" args = {"3"} } + key { modkey = {"Mod4", "Control"} key = "4" command = "tag_toggleview" args = {"4"} } + key { modkey = {"Mod4", "Control"} key = "5" command = "tag_toggleview" args = {"5"} } + key { modkey = {"Mod4", "Control"} key = "6" command = "tag_toggleview" args = {"6"} } + key { modkey = {"Mod4", "Control"} key = "7" command = "tag_toggleview" args = {"7"} } + key { modkey = {"Mod4", "Control"} key = "8" command = "tag_toggleview" args = {"8"} } + key { modkey = {"Mod4", "Control"} key = "9" command = "tag_toggleview" args = {"9"} } + + key { modkey = {"Mod4", "Shift"} key = "0" command = "client_tag" } + key { modkey = {"Mod4", "Shift"} key = "1" command = "client_tag" args = {"1"} } + key { modkey = {"Mod4", "Shift"} key = "2" command = "client_tag" args = {"2"} } + key { modkey = {"Mod4", "Shift"} key = "3" command = "client_tag" args = {"3"} } + key { modkey = {"Mod4", "Shift"} key = "4" command = "client_tag" args = {"4"} } + key { modkey = {"Mod4", "Shift"} key = "5" command = "client_tag" args = {"5"} } + key { modkey = {"Mod4", "Shift"} key = "6" command = "client_tag" args = {"6"} } + key { modkey = {"Mod4", "Shift"} key = "7" command = "client_tag" args = {"7"} } + key { modkey = {"Mod4", "Shift"} key = "8" command = "client_tag" args = {"8"} } + key { modkey = {"Mod4", "Shift"} key = "9" command = "client_tag" args = {"9"} } + + key { modkey = {"Mod4", "Shift", "Control"} key = "0" command = "client_toggletag" } + key { modkey = {"Mod4", "Shift", "Control"} key = "1" command = "client_toggletag" args = {"1"} } + key { modkey = {"Mod4", "Shift", "Control"} key = "2" command = "client_toggletag" args = {"2"} } + key { modkey = {"Mod4", "Shift", "Control"} key = "3" command = "client_toggletag" args = {"3"} } + key { modkey = {"Mod4", "Shift", "Control"} key = "4" command = "client_toggletag" args = {"4"} } + key { modkey = {"Mod4", "Shift", "Control"} key = "5" command = "client_toggletag" args = {"5"} } + key { modkey = {"Mod4", "Shift", "Control"} key = "6" command = "client_toggletag" args = {"6"} } + key { modkey = {"Mod4", "Shift", "Control"} key = "7" command = "client_toggletag" args = {"7"} } + key { modkey = {"Mod4", "Shift", "Control"} key = "8" command = "client_toggletag" args = {"8"} } + key { modkey = {"Mod4", "Shift", "Control"} key = "9" command = "client_toggletag" args = {"9"} } } # vim: filetype=conf diff --git a/common/configopts.c b/common/configopts.c index 4adb57138..11062c3b0 100644 --- a/common/configopts.c +++ b/common/configopts.c @@ -248,8 +248,8 @@ cfg_opt_t mouse_generic_opts[] = CFG_STR((char *) "button", (char *) "XCB_NONE", CFGF_NONE), /** Uicb command to run. */ CFG_STR((char *) "command", NULL, CFGF_NONE), - /** Argument to use for command. */ - CFG_STR((char *) "arg", NULL, CFGF_NONE), + /** Arguments to use for command. */ + CFG_STR_LIST((char *) "args", NULL, CFGF_NONE), CFG_AWESOME_END() }; /** This section defines common widgets options. */ @@ -568,20 +568,7 @@ cfg_opt_t key_opts[] = /** Uicb command to run. */ CFG_STR((char *) "command", (char *) "", CFGF_NONE), /** Argument to use for command. */ - CFG_STR((char *) "arg", NULL, CFGF_NONE), - CFG_AWESOME_END() -}; -/** This section defines keylist options. */ -cfg_opt_t keylist_opts[] = -{ - /** Modifier keys. */ - CFG_STR_LIST((char *) "modkey", (char *) "", CFGF_NONE), - /** List of keys, order matters. */ - CFG_STR_LIST((char *) "keylist", (char *) NULL, CFGF_NONE), - /** Uicb command to run. */ - CFG_STR((char *) "command", (char *) "", CFGF_NONE), - /** List of arguments for command, order matters. */ - CFG_STR_LIST((char *) "arglist", NULL, CFGF_NONE), + CFG_STR_LIST((char *) "args", NULL, CFGF_NONE), CFG_AWESOME_END() }; /** This section defines keys options. */ @@ -589,8 +576,6 @@ cfg_opt_t keys_opts[] = { /** A key binding. */ CFG_SEC((char *) "key", key_opts, CFGF_MULTI), - /** A list of key bindings. */ - CFG_SEC((char *) "keylist", keylist_opts, CFGF_MULTI), CFG_AWESOME_END() }; /** This section defines mouse options. */ diff --git a/config.c b/config.c index 69647ea3b..0fb1bf212 100644 --- a/config.c +++ b/config.c @@ -144,7 +144,7 @@ parse_mouse_bindings(cfg_t * cfg, const char *secname, bool handle_arg) if(!b->func) warn("unknown command %s\n", cfg_getstr(cfgsectmp, "command")); if(handle_arg) - b->arg = a_strdup(cfg_getstr(cfgsectmp, "arg")); + b->arg = a_strdup(cfg_getnstr(cfgsectmp, "args", 0)); else b->arg = NULL; @@ -154,19 +154,6 @@ parse_mouse_bindings(cfg_t * cfg, const char *secname, bool handle_arg) return head; } - -static void -set_key_info(keybinding_t *key, cfg_t *cfg) -{ - unsigned int j; - - for(j = 0; j < cfg_size(cfg, "modkey"); j++) - key->mod |= key_mask_lookup(cfg_getnstr(cfg, "modkey", j)); - key->func = name_func_lookup(cfg_getstr(cfg, "command"), UicbList); - if(!key->func) - warn("unknown command %s\n", cfg_getstr(cfg, "command")); -} - static void config_key_store(keybinding_t *key, char *str) { @@ -185,47 +172,6 @@ config_key_store(keybinding_t *key, char *str) } } -static keybinding_t * -section_keys(cfg_t *cfg_keys) -{ - keybinding_t *key = NULL, *head = NULL; - int i, j, numkeys; - cfg_t *cfgkeytmp; - - for(i = cfg_size(cfg_keys, "key") - 1; i >= 0; i--) - { - key = p_new(keybinding_t, 1); - cfgkeytmp = cfg_getnsec(cfg_keys, "key", i); - set_key_info(key, cfgkeytmp); - config_key_store(key, cfg_getstr(cfgkeytmp, "key")); - key->arg = a_strdup(cfg_getstr(cfgkeytmp, "arg")); - keybinding_list_push(&head, key); - } - - for(i = cfg_size(cfg_keys, "keylist") - 1; i >= 0; i--) - { - cfgkeytmp = cfg_getnsec(cfg_keys, "keylist", i); - numkeys = cfg_size(cfgkeytmp, "keylist"); - if(numkeys != (int) cfg_size(cfgkeytmp, "arglist")) - { - warn("number of keys != number of args in keylist"); - continue; - } - - for(j = 0; j < numkeys; j++) - { - key = p_new(keybinding_t, 1); - set_key_info(key, cfgkeytmp); - config_key_store(key, cfg_getnstr(cfgkeytmp, "keylist", j)); - key->arg = a_strdup(cfg_getnstr(cfgkeytmp, "arglist", j)); - keybinding_list_push(&head, key); - } - } - - return head; -} - - static int cmp_widget_cfg(const void *a, const void *b) { @@ -471,8 +417,10 @@ config_parse(const char *confpatharg) { cfg_t *cfg, *cfg_rules, *cfg_keys, *cfg_mouse, *cfgsectmp; int ret, screen, i; + unsigned int j; char *confpath; rule_t *rule = NULL; + keybinding_t *key; FILE *defconfig = NULL; if(confpatharg) @@ -537,6 +485,22 @@ config_parse(const char *confpatharg) rule_list_push(&globalconf.rules, rule); } + /* Key bindings */ + keybinding_list_init(&globalconf.keys); + for(i = cfg_size(cfg_keys, "key") - 1; i >= 0; i--) + { + key = p_new(keybinding_t, 1); + cfgsectmp = cfg_getnsec(cfg_keys, "key", i); + config_key_store(key, cfg_getstr(cfgsectmp, "key")); + for(j = 0; j < cfg_size(cfgsectmp, "modkey"); j++) + key->mod |= key_mask_lookup(cfg_getnstr(cfgsectmp, "modkey", j)); + if(!(key->func = name_func_lookup(cfg_getstr(cfgsectmp, "command"), UicbList))) + warn("unknown command %s\n", cfg_getstr(cfgsectmp, "command")); + key->arg = a_strdup(cfg_getnstr(cfgsectmp, "args", 0)); + printf("key %s %s %d\n", cfg_getstr(cfgsectmp, "command"), key->arg, key->keysym); + keybinding_list_push(&globalconf.keys, key); + } + /* Mouse: root window click bindings */ globalconf.buttons.root = parse_mouse_bindings(cfg_mouse, "root", true); @@ -546,8 +510,6 @@ config_parse(const char *confpatharg) /* Mouse: titlebar windows click bindings */ globalconf.buttons.titlebar = parse_mouse_bindings(cfg_mouse, "titlebar", true); - globalconf.keys = section_keys(cfg_keys); - if(defconfig) { fwrite(AWESOME_DEFAULT_CONFIG, a_strlen(AWESOME_DEFAULT_CONFIG), 1, defconfig);