From ab130fb56b5c450d3821cfdfc18fc7a37487c70a Mon Sep 17 00:00:00 2001 From: Luminarys Date: Thu, 13 Aug 2015 12:32:43 -0500 Subject: [PATCH] Added in command queue --- sway/commands.c | 4 +-- sway/config.c | 17 ++++++++++-- sway/config.h | 1 + sway/handlers.c | 13 ++++++++++ sway/workspace.c | 67 +++++++++++++++++++++++++----------------------- 5 files changed, 66 insertions(+), 36 deletions(-) diff --git a/sway/commands.c b/sway/commands.c index 0adda3e7..a370e83a 100644 --- a/sway/commands.c +++ b/sway/commands.c @@ -229,8 +229,8 @@ static bool cmd_set(struct sway_config *config, int argc, char **argv) { static bool _do_split(struct sway_config *config, int argc, char **argv, int layout) { char *name = layout == L_VERT ? "splitv": - layout == L_HORIZ ? "splith": - "split"; + layout == L_HORIZ ? "splith": + "split"; if (!checkarg(argc, name, EXPECTED_EQUAL_TO, 0)) { return false; } diff --git a/sway/config.c b/sway/config.c index 6fe681f6..e8ff42dc 100644 --- a/sway/config.c +++ b/sway/config.c @@ -33,6 +33,7 @@ bool load_config() { void config_defaults(struct sway_config *config) { config->symbols = create_list(); config->modes = create_list(); + config->cmd_queue = create_list(); config->current_mode = malloc(sizeof(struct sway_mode)); config->current_mode->name = NULL; config->current_mode->bindings = create_list(); @@ -68,9 +69,20 @@ struct sway_config *read_config(FILE *file, bool is_active) { goto _continue; } - if (!temp_depth && handle_command(config, line) != true) { + // Any command which would require wlc to be initialized + // should be queue for later execution + list_t *args = split_string(line, " "); + sway_log(L_DEBUG, "Checking command %s", line); + if (strcmp("workspace", args->items[0]) == 0) { + sway_log(L_DEBUG, "Deferring command %s", line); + char *cmd = malloc(strlen(line) + 1); + strcpy(cmd, line); + list_add(config->cmd_queue, cmd); + }else if (!temp_depth && !handle_command(config, line)) { + sway_log(L_DEBUG, "Config load failed for line %s", line); success = false; - } + } + list_free(args); _continue: if (line && line[strlen(line) - 1] == '{') { @@ -80,6 +92,7 @@ _continue: } if (success == false) { + sway_log(L_DEBUG, "Config load failed, exiting"); exit(1); } diff --git a/sway/config.h b/sway/config.h index 62b65723..f55453a3 100644 --- a/sway/config.h +++ b/sway/config.h @@ -24,6 +24,7 @@ struct sway_mode { struct sway_config { list_t *symbols; list_t *modes; + list_t *cmd_queue; struct sway_mode *current_mode; // Flags diff --git a/sway/handlers.c b/sway/handlers.c index fe7de75b..220aeb01 100644 --- a/sway/handlers.c +++ b/sway/handlers.c @@ -163,6 +163,16 @@ static bool handle_pointer_button(wlc_handle view, uint32_t time, const struct w return true; } +static void handle_wlc_ready(void) { + sway_log(L_DEBUG, "Compositor is ready, executing cmds in queue"); + int i; + for (i = 0; i < config->cmd_queue->length; ++i) { + sway_log(L_DEBUG, "Handling command %s", config->cmd_queue->items[i]); + handle_command(config, config->cmd_queue->items[i]); + } + list_free(config->cmd_queue); +} + struct wlc_interface interface = { .output = { @@ -185,6 +195,9 @@ struct wlc_interface interface = { .pointer = { .motion = handle_pointer_motion, .button = handle_pointer_button + }, + .compositor = { + .ready = handle_wlc_ready } }; diff --git a/sway/workspace.c b/sway/workspace.c index 9bc6838c..7b23b7d1 100644 --- a/sway/workspace.c +++ b/sway/workspace.c @@ -14,43 +14,46 @@ swayc_t *active_workspace = NULL; char *workspace_next_name(void) { sway_log(L_DEBUG, "Workspace: Generating new name"); int i; - int l = 1; - // Scan all workspace bindings to find the next available workspace name, - // if none are found/available then default to a number + int l = 1; + // Scan all workspace bindings to find the next available workspace name, + // if none are found/available then default to a number struct sway_mode *mode = config->current_mode; for (i = 0; i < mode->bindings->length; ++i) { struct sway_binding *binding = mode->bindings->items[i]; const char* command = binding->command; - list_t *args = split_string(command, " "); - sway_log(L_DEBUG, "Workspace: Checking name '%s'", command); - - if (strcmp("workspace", args->items[0]) == 0 && args->length > 1) { - sway_log(L_DEBUG, "Got valid workspace command for target: '%s'", args->items[1]); - const char* target = args->items[1]; - - while (*target == ' ' || *target == '\t') - target++; - - // Make sure that the command references an actual workspace - // not a command about workspaces - if (strcmp(target, "next") == 0 || - strcmp(target, "prev") == 0 || - strcmp(target, "next_on_output") == 0 || - strcmp(target, "prev_on_output") == 0 || - strcmp(target, "number") == 0 || - strcmp(target, "back_and_forth") == 0 || - strcmp(target, "current") == 0) - continue; - - //Make sure that the workspace doesn't already exist - if (workspace_find_by_name(args->items[1])) - continue; - - return args->items[1]; } - } - // As a fall back, get the current number of active workspaces - // and return that + 1 for the next workspace's name + list_t *args = split_string(command, " "); + + if (strcmp("workspace", args->items[0]) == 0 && args->length > 1) { + sway_log(L_DEBUG, "Got valid workspace command for target: '%s'", args->items[1]); + const char* target = args->items[1]; + + while (*target == ' ' || *target == '\t') + target++; + + // Make sure that the command references an actual workspace + // not a command about workspaces + if (strcmp(target, "next") == 0 || + strcmp(target, "prev") == 0 || + strcmp(target, "next_on_output") == 0 || + strcmp(target, "prev_on_output") == 0 || + strcmp(target, "number") == 0 || + strcmp(target, "back_and_forth") == 0 || + strcmp(target, "current") == 0) + continue; + + //Make sure that the workspace doesn't already exist + if (workspace_find_by_name(args->items[1])) + continue; + + list_free(args); + + sway_log(L_DEBUG, "Workspace: Found free name %s", args->items[1]); + return args->items[1]; + } + } + // As a fall back, get the current number of active workspaces + // and return that + 1 for the next workspace's name int ws_num = root_container.children->length; if (ws_num >= 10) { l = 2;