diff options
-rw-r--r-- | sway/commands.c | 4 | ||||
-rw-r--r-- | sway/config.c | 17 | ||||
-rw-r--r-- | sway/config.h | 1 | ||||
-rw-r--r-- | sway/handlers.c | 13 | ||||
-rw-r--r-- | 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) { | |||
229 | 229 | ||
230 | static bool _do_split(struct sway_config *config, int argc, char **argv, int layout) { | 230 | static bool _do_split(struct sway_config *config, int argc, char **argv, int layout) { |
231 | char *name = layout == L_VERT ? "splitv": | 231 | char *name = layout == L_VERT ? "splitv": |
232 | layout == L_HORIZ ? "splith": | 232 | layout == L_HORIZ ? "splith": |
233 | "split"; | 233 | "split"; |
234 | if (!checkarg(argc, name, EXPECTED_EQUAL_TO, 0)) { | 234 | if (!checkarg(argc, name, EXPECTED_EQUAL_TO, 0)) { |
235 | return false; | 235 | return false; |
236 | } | 236 | } |
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() { | |||
33 | void config_defaults(struct sway_config *config) { | 33 | void config_defaults(struct sway_config *config) { |
34 | config->symbols = create_list(); | 34 | config->symbols = create_list(); |
35 | config->modes = create_list(); | 35 | config->modes = create_list(); |
36 | config->cmd_queue = create_list(); | ||
36 | config->current_mode = malloc(sizeof(struct sway_mode)); | 37 | config->current_mode = malloc(sizeof(struct sway_mode)); |
37 | config->current_mode->name = NULL; | 38 | config->current_mode->name = NULL; |
38 | config->current_mode->bindings = create_list(); | 39 | config->current_mode->bindings = create_list(); |
@@ -68,9 +69,20 @@ struct sway_config *read_config(FILE *file, bool is_active) { | |||
68 | goto _continue; | 69 | goto _continue; |
69 | } | 70 | } |
70 | 71 | ||
71 | if (!temp_depth && handle_command(config, line) != true) { | 72 | // Any command which would require wlc to be initialized |
73 | // should be queue for later execution | ||
74 | list_t *args = split_string(line, " "); | ||
75 | sway_log(L_DEBUG, "Checking command %s", line); | ||
76 | if (strcmp("workspace", args->items[0]) == 0) { | ||
77 | sway_log(L_DEBUG, "Deferring command %s", line); | ||
78 | char *cmd = malloc(strlen(line) + 1); | ||
79 | strcpy(cmd, line); | ||
80 | list_add(config->cmd_queue, cmd); | ||
81 | }else if (!temp_depth && !handle_command(config, line)) { | ||
82 | sway_log(L_DEBUG, "Config load failed for line %s", line); | ||
72 | success = false; | 83 | success = false; |
73 | } | 84 | } |
85 | list_free(args); | ||
74 | 86 | ||
75 | _continue: | 87 | _continue: |
76 | if (line && line[strlen(line) - 1] == '{') { | 88 | if (line && line[strlen(line) - 1] == '{') { |
@@ -80,6 +92,7 @@ _continue: | |||
80 | } | 92 | } |
81 | 93 | ||
82 | if (success == false) { | 94 | if (success == false) { |
95 | sway_log(L_DEBUG, "Config load failed, exiting"); | ||
83 | exit(1); | 96 | exit(1); |
84 | } | 97 | } |
85 | 98 | ||
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 { | |||
24 | struct sway_config { | 24 | struct sway_config { |
25 | list_t *symbols; | 25 | list_t *symbols; |
26 | list_t *modes; | 26 | list_t *modes; |
27 | list_t *cmd_queue; | ||
27 | struct sway_mode *current_mode; | 28 | struct sway_mode *current_mode; |
28 | 29 | ||
29 | // Flags | 30 | // 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 | |||
163 | return true; | 163 | return true; |
164 | } | 164 | } |
165 | 165 | ||
166 | static void handle_wlc_ready(void) { | ||
167 | sway_log(L_DEBUG, "Compositor is ready, executing cmds in queue"); | ||
168 | int i; | ||
169 | for (i = 0; i < config->cmd_queue->length; ++i) { | ||
170 | sway_log(L_DEBUG, "Handling command %s", config->cmd_queue->items[i]); | ||
171 | handle_command(config, config->cmd_queue->items[i]); | ||
172 | } | ||
173 | list_free(config->cmd_queue); | ||
174 | } | ||
175 | |||
166 | 176 | ||
167 | struct wlc_interface interface = { | 177 | struct wlc_interface interface = { |
168 | .output = { | 178 | .output = { |
@@ -185,6 +195,9 @@ struct wlc_interface interface = { | |||
185 | .pointer = { | 195 | .pointer = { |
186 | .motion = handle_pointer_motion, | 196 | .motion = handle_pointer_motion, |
187 | .button = handle_pointer_button | 197 | .button = handle_pointer_button |
198 | }, | ||
199 | .compositor = { | ||
200 | .ready = handle_wlc_ready | ||
188 | } | 201 | } |
189 | }; | 202 | }; |
190 | 203 | ||
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; | |||
14 | char *workspace_next_name(void) { | 14 | char *workspace_next_name(void) { |
15 | sway_log(L_DEBUG, "Workspace: Generating new name"); | 15 | sway_log(L_DEBUG, "Workspace: Generating new name"); |
16 | int i; | 16 | int i; |
17 | int l = 1; | 17 | int l = 1; |
18 | // Scan all workspace bindings to find the next available workspace name, | 18 | // Scan all workspace bindings to find the next available workspace name, |
19 | // if none are found/available then default to a number | 19 | // if none are found/available then default to a number |
20 | struct sway_mode *mode = config->current_mode; | 20 | struct sway_mode *mode = config->current_mode; |
21 | 21 | ||
22 | for (i = 0; i < mode->bindings->length; ++i) { | 22 | for (i = 0; i < mode->bindings->length; ++i) { |
23 | struct sway_binding *binding = mode->bindings->items[i]; | 23 | struct sway_binding *binding = mode->bindings->items[i]; |
24 | const char* command = binding->command; | 24 | const char* command = binding->command; |
25 | list_t *args = split_string(command, " "); | 25 | list_t *args = split_string(command, " "); |
26 | sway_log(L_DEBUG, "Workspace: Checking name '%s'", command); | 26 | |
27 | 27 | if (strcmp("workspace", args->items[0]) == 0 && args->length > 1) { | |
28 | if (strcmp("workspace", args->items[0]) == 0 && args->length > 1) { | 28 | sway_log(L_DEBUG, "Got valid workspace command for target: '%s'", args->items[1]); |
29 | sway_log(L_DEBUG, "Got valid workspace command for target: '%s'", args->items[1]); | 29 | const char* target = args->items[1]; |
30 | const char* target = args->items[1]; | 30 | |
31 | 31 | while (*target == ' ' || *target == '\t') | |
32 | while (*target == ' ' || *target == '\t') | 32 | target++; |
33 | target++; | 33 | |
34 | 34 | // Make sure that the command references an actual workspace | |
35 | // Make sure that the command references an actual workspace | 35 | // not a command about workspaces |
36 | // not a command about workspaces | 36 | if (strcmp(target, "next") == 0 || |
37 | if (strcmp(target, "next") == 0 || | 37 | strcmp(target, "prev") == 0 || |
38 | strcmp(target, "prev") == 0 || | 38 | strcmp(target, "next_on_output") == 0 || |
39 | strcmp(target, "next_on_output") == 0 || | 39 | strcmp(target, "prev_on_output") == 0 || |
40 | strcmp(target, "prev_on_output") == 0 || | 40 | strcmp(target, "number") == 0 || |
41 | strcmp(target, "number") == 0 || | 41 | strcmp(target, "back_and_forth") == 0 || |
42 | strcmp(target, "back_and_forth") == 0 || | 42 | strcmp(target, "current") == 0) |
43 | strcmp(target, "current") == 0) | 43 | continue; |
44 | continue; | 44 | |
45 | 45 | //Make sure that the workspace doesn't already exist | |
46 | //Make sure that the workspace doesn't already exist | 46 | if (workspace_find_by_name(args->items[1])) |
47 | if (workspace_find_by_name(args->items[1])) | 47 | continue; |
48 | continue; | 48 | |
49 | 49 | list_free(args); | |
50 | return args->items[1]; } | 50 | |
51 | } | 51 | sway_log(L_DEBUG, "Workspace: Found free name %s", args->items[1]); |
52 | // As a fall back, get the current number of active workspaces | 52 | return args->items[1]; |
53 | // and return that + 1 for the next workspace's name | 53 | } |
54 | } | ||
55 | // As a fall back, get the current number of active workspaces | ||
56 | // and return that + 1 for the next workspace's name | ||
54 | int ws_num = root_container.children->length; | 57 | int ws_num = root_container.children->length; |
55 | if (ws_num >= 10) { | 58 | if (ws_num >= 10) { |
56 | l = 2; | 59 | l = 2; |