aboutsummaryrefslogtreecommitdiff
path: root/sway/commands/mode.c
diff options
context:
space:
mode:
authorDrew DeVault <sir@cmpwn.com>2018-06-02 08:09:18 -0700
committerGitHub <noreply@github.com>2018-06-02 08:09:18 -0700
commitb0f2fd94791708a84aac2eccc57855a4ce8b6ec0 (patch)
tree919f22247b71c5562b3c1caff4f0bfa9dfcf0528 /sway/commands/mode.c
parent2d480e754e8287ba747faf1b21d8ecb927d565a1 (diff)
parent85a5c8dabd2561dfe616bea50faf2549e8cb345e (diff)
Merge pull request #2070 from RedSoxFan/generic-config-blocks
Make command block implementation generic
Diffstat (limited to 'sway/commands/mode.c')
-rw-r--r--sway/commands/mode.c28
1 files changed, 21 insertions, 7 deletions
diff --git a/sway/commands/mode.c b/sway/commands/mode.c
index c30a8bac..00331ccc 100644
--- a/sway/commands/mode.c
+++ b/sway/commands/mode.c
@@ -7,6 +7,13 @@
#include "sway/ipc-server.h"
#include "list.h"
#include "log.h"
+#include "stringop.h"
+
+// Must be in order for the bsearch
+static struct cmd_handler mode_handlers[] = {
+ { "bindcode", cmd_bindcode },
+ { "bindsym", cmd_bindsym }
+};
struct cmd_results *cmd_mode(int argc, char **argv) {
struct cmd_results *error = NULL;
@@ -14,12 +21,12 @@ struct cmd_results *cmd_mode(int argc, char **argv) {
return error;
}
- const char *mode_name = argv[0];
- bool new_mode = (argc == 2 && strcmp(argv[1], "{") == 0);
- if (new_mode && !config->reading) {
+ if (argc > 1 && !config->reading) {
return cmd_results_new(CMD_FAILURE,
"mode", "Can only be used in config file.");
}
+
+ const char *mode_name = argv[0];
struct sway_mode *mode = NULL;
// Find mode
for (int i = 0; i < config->modes->length; ++i) {
@@ -30,7 +37,7 @@ struct cmd_results *cmd_mode(int argc, char **argv) {
}
}
// Create mode if it doesn't exist
- if (!mode && new_mode) {
+ if (!mode && argc > 1) {
mode = calloc(1, sizeof(struct sway_mode));
if (!mode) {
return cmd_results_new(CMD_FAILURE,
@@ -46,14 +53,21 @@ struct cmd_results *cmd_mode(int argc, char **argv) {
"mode", "Unknown mode `%s'", mode_name);
return error;
}
- if ((config->reading && new_mode) || (!config->reading && !new_mode)) {
+ if ((config->reading && argc > 1) || (!config->reading && argc == 1)) {
wlr_log(L_DEBUG, "Switching to mode `%s'",mode->name);
}
// Set current mode
config->current_mode = mode;
- if (!new_mode) {
+ if (argc == 1) {
// trigger IPC mode event
ipc_event_mode(config->current_mode->name);
+ return cmd_results_new(CMD_SUCCESS, NULL, NULL);
}
- return cmd_results_new(new_mode ? CMD_BLOCK_MODE : CMD_SUCCESS, NULL, NULL);
+
+ // Create binding
+ struct cmd_results *result = config_subcommand(argv + 1, argc - 1,
+ mode_handlers, sizeof(mode_handlers));
+ config->current_mode = config->modes->items[0];
+
+ return result;
}