aboutsummaryrefslogtreecommitdiff
path: root/sway/commands.c
diff options
context:
space:
mode:
authorTony Crisci <tony@dubstepdish.com>2018-02-24 13:20:34 -0500
committerTony Crisci <tony@dubstepdish.com>2018-02-24 13:20:34 -0500
commit5b219a15982b9626f85535c082ee2adb460ad11d (patch)
treee7cf000493871657311c1492ba314e82443b3551 /sway/commands.c
parentac8269d536bf636bd0fbf8047cf6516912634864 (diff)
separate config directives and commands
Diffstat (limited to 'sway/commands.c')
-rw-r--r--sway/commands.c46
1 files changed, 35 insertions, 11 deletions
diff --git a/sway/commands.c b/sway/commands.c
index 66614058..ed8da3dc 100644
--- a/sway/commands.c
+++ b/sway/commands.c
@@ -125,25 +125,35 @@ struct cmd_results *add_color(const char *name, char *buffer, const char *color)
return NULL;
}
-/* Keep alphabetized */
+/**
+ * handlers that can run in either config or command context
+ * Keep alphabetized
+ */
static struct cmd_handler handlers[] = {
{ "bindcode", cmd_bindcode },
{ "bindsym", cmd_bindsym },
{ "exec", cmd_exec },
{ "exec_always", cmd_exec_always },
- { "exit", cmd_exit },
- { "focus", cmd_focus },
{ "include", cmd_include },
{ "input", cmd_input },
- { "kill", cmd_kill },
- { "layout", cmd_layout },
{ "output", cmd_output },
- { "reload", cmd_reload },
{ "seat", cmd_seat },
{ "set", cmd_set },
{ "workspace", cmd_workspace },
};
+/**
+ * Commands that can *not* run in the config loading context
+ * Keep alphabetized
+ */
+static struct cmd_handler command_handlers[] = {
+ { "exit", cmd_exit },
+ { "focus", cmd_focus },
+ { "kill", cmd_kill },
+ { "layout", cmd_layout },
+ { "reload", cmd_reload },
+};
+
static int handler_compare(const void *_a, const void *_b) {
const struct cmd_handler *a = _a;
const struct cmd_handler *b = _b;
@@ -181,20 +191,34 @@ static struct cmd_handler *find_handler(char *line, enum cmd_status block) {
struct cmd_handler *res = NULL;
wlr_log(L_DEBUG, "find_handler(%s) %d", line, block == CMD_BLOCK_SEAT);
+ bool config_loading = config->reading || !config->active;
+
if (block == CMD_BLOCK_INPUT) {
- res = bsearch(&d, input_handlers,
+ // input commands can run in either context
+ return bsearch(&d, input_handlers,
sizeof(input_handlers) / sizeof(struct cmd_handler),
sizeof(struct cmd_handler), handler_compare);
} else if (block == CMD_BLOCK_SEAT) {
- res = bsearch(&d, seat_handlers,
+ // seat commands can run in either context
+ return bsearch(&d, seat_handlers,
sizeof(seat_handlers) / sizeof(struct cmd_handler),
sizeof(struct cmd_handler), handler_compare);
- } else {
- res = bsearch(&d, handlers,
- sizeof(handlers) / sizeof(struct cmd_handler),
+ }
+
+ if (!config_loading) {
+ res = bsearch(&d, command_handlers,
+ sizeof(command_handlers) / sizeof(struct cmd_handler),
sizeof(struct cmd_handler), handler_compare);
+
+ if (res) {
+ return res;
+ }
}
+ res = bsearch(&d, handlers,
+ sizeof(handlers) / sizeof(struct cmd_handler),
+ sizeof(struct cmd_handler), handler_compare);
+
return res;
}