enum for command type

This commit is contained in:
taiyu 2015-09-04 17:09:07 -07:00
parent c5d0b5d437
commit afa6747145
3 changed files with 32 additions and 28 deletions

View file

@ -9,7 +9,11 @@ struct cmd_handler {
// if <0 command is deffered until compositor is ready. // if <0 command is deffered until compositor is ready.
// if =0 command can be called anytime. // if =0 command can be called anytime.
// if >0 command can only be called via keybind, ignored in config // if >0 command can only be called via keybind, ignored in config
int config_type; enum {
CMD_COMPOSITOR_READY,
CMD_KEYBIND,
CMD_ANYTIME
} config_type;
}; };
struct cmd_handler *find_handler(char *line); struct cmd_handler *find_handler(char *line);

View file

@ -860,31 +860,31 @@ static bool cmd_ws_auto_back_and_forth(struct sway_config *config, int argc, cha
/* Keep alphabetized */ /* Keep alphabetized */
static struct cmd_handler handlers[] = { static struct cmd_handler handlers[] = {
{ "bindsym", cmd_bindsym, 0 }, { "bindsym", cmd_bindsym, CMD_ANYTIME },
{ "default_orientation", cmd_orientation, 0}, { "default_orientation", cmd_orientation, CMD_ANYTIME},
{ "exec", cmd_exec, -1 }, { "exec", cmd_exec, CMD_COMPOSITOR_READY },
{ "exec_always", cmd_exec_always, -1 }, { "exec_always", cmd_exec_always, CMD_COMPOSITOR_READY },
{ "exit", cmd_exit, 1 }, { "exit", cmd_exit, CMD_KEYBIND },
{ "floating", cmd_floating, 1 }, { "floating", cmd_floating, CMD_KEYBIND },
{ "floating_modifier", cmd_floating_mod, 0 }, { "floating_modifier", cmd_floating_mod, CMD_ANYTIME },
{ "focus", cmd_focus, 1 }, { "focus", cmd_focus, CMD_KEYBIND },
{ "focus_follows_mouse", cmd_focus_follows_mouse, 0 }, { "focus_follows_mouse", cmd_focus_follows_mouse, CMD_ANYTIME },
{ "fullscreen", cmd_fullscreen, 1 }, { "fullscreen", cmd_fullscreen, CMD_KEYBIND },
{ "gaps", cmd_gaps, 0 }, { "gaps", cmd_gaps, CMD_ANYTIME },
{ "kill", cmd_kill, 1 }, { "kill", cmd_kill, CMD_KEYBIND },
{ "layout", cmd_layout, 1 }, { "layout", cmd_layout, CMD_KEYBIND },
{ "log_colors", cmd_log_colors, 0 }, { "log_colors", cmd_log_colors, CMD_ANYTIME },
{ "move", cmd_move, 1 }, { "move", cmd_move, CMD_KEYBIND },
{ "output", cmd_output, 0 }, { "output", cmd_output, CMD_ANYTIME },
{ "reload", cmd_reload, 1 }, { "reload", cmd_reload, CMD_KEYBIND },
{ "resize", cmd_resize, 1 }, { "resize", cmd_resize, CMD_KEYBIND },
{ "scratchpad", cmd_scratchpad, 1 }, { "scratchpad", cmd_scratchpad, CMD_KEYBIND },
{ "set", cmd_set, 0 }, { "set", cmd_set, CMD_ANYTIME },
{ "split", cmd_split, 1 }, { "split", cmd_split, CMD_KEYBIND },
{ "splith", cmd_splith, 1 }, { "splith", cmd_splith, CMD_KEYBIND },
{ "splitv", cmd_splitv, 1 }, { "splitv", cmd_splitv, CMD_KEYBIND },
{ "workspace", cmd_workspace, -1 }, { "workspace", cmd_workspace, CMD_COMPOSITOR_READY },
{ "workspace_auto_back_and_forth", cmd_ws_auto_back_and_forth, 0 } { "workspace_auto_back_and_forth", cmd_ws_auto_back_and_forth, CMD_ANYTIME },
}; };
static char **split_directive(char *line, int *argc) { static char **split_directive(char *line, int *argc) {

View file

@ -220,9 +220,9 @@ bool read_config(FILE *file, bool is_active) {
list_t *args = split_string(line, " "); list_t *args = split_string(line, " ");
struct cmd_handler *handler; struct cmd_handler *handler;
if ((handler = find_handler(args->items[0]))) { if ((handler = find_handler(args->items[0]))) {
if (handler->config_type > 0) { if (handler->config_type == CMD_KEYBIND) {
sway_log(L_ERROR, "Invalid command during config ``%s''", line); sway_log(L_ERROR, "Invalid command during config ``%s''", line);
} else if (handler->config_type < 0 && !is_active) { } else if (handler->config_type == CMD_COMPOSITOR_READY && !is_active) {
sway_log(L_DEBUG, "Deferring command ``%s''", line); sway_log(L_DEBUG, "Deferring command ``%s''", line);
char *cmd = malloc(strlen(line) + 1); char *cmd = malloc(strlen(line) + 1);
strcpy(cmd, line); strcpy(cmd, line);