diff options
author | Brian Ashworth <bosrsf04@gmail.com> | 2019-06-20 00:33:29 -0400 |
---|---|---|
committer | Drew DeVault <sir@cmpwn.com> | 2019-06-20 10:14:19 -0400 |
commit | d0d01810f3590f8132c3b81bd9775f337cfd0507 (patch) | |
tree | a0785c6be51445708d65ee137b0a29671feab5d9 /sway/commands | |
parent | fc3253cc35b123ae5d21db3379ad0acf43ad0c20 (diff) | |
download | sway-d0d01810f3590f8132c3b81bd9775f337cfd0507.tar.xz |
cmd_mode: allow runtime creation and modification
This allows for modes to be created, bindings to be added to modes, and
bindings to be removed from modes at runtime. Additionally, this also
allows for `mode <mode>` to be deferred in the config to set an initial
mode.
Diffstat (limited to 'sway/commands')
-rw-r--r-- | sway/commands/mode.c | 17 |
1 files changed, 9 insertions, 8 deletions
diff --git a/sway/commands/mode.c b/sway/commands/mode.c index ef2c5d79..e5ddec4a 100644 --- a/sway/commands/mode.c +++ b/sway/commands/mode.c @@ -15,6 +15,9 @@ static struct cmd_handler mode_handlers[] = { { "bindswitch", cmd_bindswitch }, { "bindsym", cmd_bindsym }, { "set", cmd_set }, + { "unbindcode", cmd_unbindcode }, + { "unbindswitch", cmd_unbindswitch }, + { "unbindsym", cmd_unbindsym }, }; struct cmd_results *cmd_mode(int argc, char **argv) { @@ -23,10 +26,6 @@ struct cmd_results *cmd_mode(int argc, char **argv) { return error; } - if (argc > 1 && !config->reading) { - return cmd_results_new(CMD_FAILURE, "Can only be used in config file"); - } - bool pango = strcmp(*argv, "--pango_markup") == 0; if (pango) { argc--; argv++; @@ -35,6 +34,10 @@ struct cmd_results *cmd_mode(int argc, char **argv) { } } + if (config->reading && argc == 1) { + return cmd_results_new(CMD_DEFER, NULL); + } + char *mode_name = *argv; strip_quotes(mode_name); struct sway_mode *mode = NULL; @@ -64,14 +67,12 @@ struct cmd_results *cmd_mode(int argc, char **argv) { error = cmd_results_new(CMD_INVALID, "Unknown mode `%s'", mode_name); return error; } - if ((config->reading && argc > 1) || (!config->reading && argc == 1)) { - sway_log(SWAY_DEBUG, "Switching to mode `%s' (pango=%d)", - mode->name, mode->pango); - } // Set current mode config->current_mode = mode; if (argc == 1) { // trigger IPC mode event + sway_log(SWAY_DEBUG, "Switching to mode `%s' (pango=%d)", + mode->name, mode->pango); ipc_event_mode(config->current_mode->name, config->current_mode->pango); return cmd_results_new(CMD_SUCCESS, NULL); |