summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLibravatar Drew DeVault <sir@cmpwn.com>2015-09-04 20:29:28 -0400
committerLibravatar Drew DeVault <sir@cmpwn.com>2015-09-04 20:29:28 -0400
commitc2cd56c939098d601c9602807f8f54deb9dee2cf (patch)
treeea60cef6ce17693128669c277d6e8b8ca9cb271b
parentMerge pull request #168 from taiyu-len/master (diff)
parentremove outdated comment (diff)
downloadsway-c2cd56c939098d601c9602807f8f54deb9dee2cf.tar.gz
sway-c2cd56c939098d601c9602807f8f54deb9dee2cf.tar.zst
sway-c2cd56c939098d601c9602807f8f54deb9dee2cf.zip
Merge pull request #169 from taiyu-len/master
handling of commands during config
-rw-r--r--include/commands.h6
-rw-r--r--sway/commands.c58
-rw-r--r--sway/config.c28
3 files changed, 52 insertions, 40 deletions
diff --git a/include/commands.h b/include/commands.h
index 714d2db0..808e64eb 100644
--- a/include/commands.h
+++ b/include/commands.h
@@ -6,8 +6,14 @@
6struct cmd_handler { 6struct cmd_handler {
7 char *command; 7 char *command;
8 bool (*handle)(struct sway_config *config, int argc, char **argv); 8 bool (*handle)(struct sway_config *config, int argc, char **argv);
9 enum {
10 CMD_COMPOSITOR_READY,
11 CMD_KEYBIND,
12 CMD_ANYTIME
13 } config_type;
9}; 14};
10 15
16struct cmd_handler *find_handler(char *line);
11bool handle_command(struct sway_config *config, char *command); 17bool handle_command(struct sway_config *config, char *command);
12 18
13void remove_view_from_scratchpad(); 19void remove_view_from_scratchpad();
diff --git a/sway/commands.c b/sway/commands.c
index cf3d5b3f..0fc98538 100644
--- a/sway/commands.c
+++ b/sway/commands.c
@@ -860,31 +860,31 @@ static bool cmd_ws_auto_back_and_forth(struct sway_config *config, int argc, cha
860 860
861/* Keep alphabetized */ 861/* Keep alphabetized */
862static struct cmd_handler handlers[] = { 862static struct cmd_handler handlers[] = {
863 { "bindsym", cmd_bindsym }, 863 { "bindsym", cmd_bindsym, CMD_ANYTIME },
864 { "default_orientation", cmd_orientation }, 864 { "default_orientation", cmd_orientation, CMD_ANYTIME},
865 { "exec", cmd_exec }, 865 { "exec", cmd_exec, CMD_COMPOSITOR_READY },
866 { "exec_always", cmd_exec_always }, 866 { "exec_always", cmd_exec_always, CMD_COMPOSITOR_READY },
867 { "exit", cmd_exit }, 867 { "exit", cmd_exit, CMD_KEYBIND },
868 { "floating", cmd_floating }, 868 { "floating", cmd_floating, CMD_KEYBIND },
869 { "floating_modifier", cmd_floating_mod }, 869 { "floating_modifier", cmd_floating_mod, CMD_ANYTIME },
870 { "focus", cmd_focus }, 870 { "focus", cmd_focus, CMD_KEYBIND },
871 { "focus_follows_mouse", cmd_focus_follows_mouse }, 871 { "focus_follows_mouse", cmd_focus_follows_mouse, CMD_ANYTIME },
872 { "fullscreen", cmd_fullscreen }, 872 { "fullscreen", cmd_fullscreen, CMD_KEYBIND },
873 { "gaps", cmd_gaps }, 873 { "gaps", cmd_gaps, CMD_ANYTIME },
874 { "kill", cmd_kill }, 874 { "kill", cmd_kill, CMD_KEYBIND },
875 { "layout", cmd_layout }, 875 { "layout", cmd_layout, CMD_KEYBIND },
876 { "log_colors", cmd_log_colors }, 876 { "log_colors", cmd_log_colors, CMD_ANYTIME },
877 { "move", cmd_move}, 877 { "move", cmd_move, CMD_KEYBIND },
878 { "output", cmd_output}, 878 { "output", cmd_output, CMD_ANYTIME },
879 { "reload", cmd_reload }, 879 { "reload", cmd_reload, CMD_KEYBIND },
880 { "resize", cmd_resize }, 880 { "resize", cmd_resize, CMD_KEYBIND },
881 { "scratchpad", cmd_scratchpad }, 881 { "scratchpad", cmd_scratchpad, CMD_KEYBIND },
882 { "set", cmd_set }, 882 { "set", cmd_set, CMD_ANYTIME },
883 { "split", cmd_split }, 883 { "split", cmd_split, CMD_KEYBIND },
884 { "splith", cmd_splith }, 884 { "splith", cmd_splith, CMD_KEYBIND },
885 { "splitv", cmd_splitv }, 885 { "splitv", cmd_splitv, CMD_KEYBIND },
886 { "workspace", cmd_workspace }, 886 { "workspace", cmd_workspace, CMD_COMPOSITOR_READY },
887 { "workspace_auto_back_and_forth", cmd_ws_auto_back_and_forth } 887 { "workspace_auto_back_and_forth", cmd_ws_auto_back_and_forth, CMD_ANYTIME },
888}; 888};
889 889
890static char **split_directive(char *line, int *argc) { 890static char **split_directive(char *line, int *argc) {
@@ -945,9 +945,11 @@ static int handler_compare(const void *_a, const void *_b) {
945 return strcasecmp(a->command, b->command); 945 return strcasecmp(a->command, b->command);
946} 946}
947 947
948static struct cmd_handler *find_handler(struct cmd_handler handlers[], int l, char *line) { 948struct cmd_handler *find_handler(char *line) {
949 struct cmd_handler d = { .command=line }; 949 struct cmd_handler d = { .command=line };
950 struct cmd_handler *res = bsearch(&d, handlers, l, sizeof(struct cmd_handler), handler_compare); 950 struct cmd_handler *res = bsearch(&d, handlers,
951 sizeof(handlers) / sizeof(struct cmd_handler),
952 sizeof(struct cmd_handler), handler_compare);
951 return res; 953 return res;
952} 954}
953 955
@@ -964,7 +966,7 @@ bool handle_command(struct sway_config *config, char *exec) {
964 strncpy(cmd, exec, index); 966 strncpy(cmd, exec, index);
965 cmd[index] = '\0'; 967 cmd[index] = '\0';
966 } 968 }
967 struct cmd_handler *handler = find_handler(handlers, sizeof(handlers) / sizeof(struct cmd_handler), cmd); 969 struct cmd_handler *handler = find_handler(cmd);
968 if (handler == NULL) { 970 if (handler == NULL) {
969 sway_log(L_ERROR, "Unknown command '%s'", cmd); 971 sway_log(L_ERROR, "Unknown command '%s'", cmd);
970 exec_success = false; // TODO: return error, probably 972 exec_success = false; // TODO: return error, probably
diff --git a/sway/config.c b/sway/config.c
index 2d7e241d..90f6529a 100644
--- a/sway/config.c
+++ b/sway/config.c
@@ -218,18 +218,22 @@ bool read_config(FILE *file, bool is_active) {
218 // Any command which would require wlc to be initialized 218 // Any command which would require wlc to be initialized
219 // should be queued for later execution 219 // should be queued for later execution
220 list_t *args = split_string(line, " "); 220 list_t *args = split_string(line, " ");
221 if (!is_active && ( 221 struct cmd_handler *handler;
222 strcmp("exec", args->items[0]) == 0 || 222 if ((handler = find_handler(args->items[0]))) {
223 strcmp("exec_always", args->items[0]) == 0 )) { 223 if (handler->config_type == CMD_KEYBIND) {
224 sway_log(L_DEBUG, "Deferring command %s", line); 224 sway_log(L_ERROR, "Invalid command during config ``%s''", line);
225 225 } else if (handler->config_type == CMD_COMPOSITOR_READY && !is_active) {
226 char *cmd = malloc(strlen(line) + 1); 226 sway_log(L_DEBUG, "Deferring command ``%s''", line);
227 strcpy(cmd, line); 227 char *cmd = malloc(strlen(line) + 1);
228 list_add(temp_config->cmd_queue, cmd); 228 strcpy(cmd, line);
229 } else if (!temp_depth && !handle_command(temp_config, line)) { 229 list_add(temp_config->cmd_queue, cmd);
230 sway_log(L_DEBUG, "Config load failed for line %s", line); 230 } else if (!temp_depth && !handle_command(temp_config, line)) {
231 success = false; 231 sway_log(L_DEBUG, "Config load failed for line ``%s''", line);
232 temp_config->failed = true; 232 success = false;
233 temp_config->failed = true;
234 }
235 } else {
236 sway_log(L_ERROR, "Invalid command ``%s''", line);
233 } 237 }
234 free_flat_list(args); 238 free_flat_list(args);
235 239