diff options
Diffstat (limited to 'sway/tree/workspace.c')
-rw-r--r-- | sway/tree/workspace.c | 49 |
1 files changed, 23 insertions, 26 deletions
diff --git a/sway/tree/workspace.c b/sway/tree/workspace.c index 16031e87..d65a3e4c 100644 --- a/sway/tree/workspace.c +++ b/sway/tree/workspace.c | |||
@@ -20,17 +20,23 @@ | |||
20 | #include "log.h" | 20 | #include "log.h" |
21 | #include "util.h" | 21 | #include "util.h" |
22 | 22 | ||
23 | struct workspace_config *workspace_find_config(const char *ws_name) { | ||
24 | for (int i = 0; i < config->workspace_configs->length; ++i) { | ||
25 | struct workspace_config *wsc = config->workspace_configs->items[i]; | ||
26 | if (strcmp(wsc->workspace, ws_name) == 0) { | ||
27 | return wsc; | ||
28 | } | ||
29 | } | ||
30 | return NULL; | ||
31 | } | ||
32 | |||
23 | struct sway_output *workspace_get_initial_output(const char *name) { | 33 | struct sway_output *workspace_get_initial_output(const char *name) { |
24 | // Search for workspace<->output pair | 34 | // Check workspace configs for a workspace<->output pair |
25 | for (int i = 0; i < config->workspace_outputs->length; ++i) { | 35 | struct workspace_config *wsc = workspace_find_config(name); |
26 | struct workspace_output *wso = config->workspace_outputs->items[i]; | 36 | if (wsc && wsc->output) { |
27 | if (strcasecmp(wso->workspace, name) == 0) { | 37 | struct sway_output *output = output_by_name(wsc->output); |
28 | // Find output to use if it exists | 38 | if (output) { |
29 | struct sway_output *output = output_by_name(wso->output); | 39 | return output; |
30 | if (output) { | ||
31 | return output; | ||
32 | } | ||
33 | break; | ||
34 | } | 40 | } |
35 | } | 41 | } |
36 | // Otherwise put it on the focused output | 42 | // Otherwise put it on the focused output |
@@ -121,17 +127,8 @@ void next_name_map(struct sway_container *ws, void *data) { | |||
121 | 127 | ||
122 | static bool workspace_valid_on_output(const char *output_name, | 128 | static bool workspace_valid_on_output(const char *output_name, |
123 | const char *ws_name) { | 129 | const char *ws_name) { |
124 | int i; | 130 | struct workspace_config *wsc = workspace_find_config(ws_name); |
125 | for (i = 0; i < config->workspace_outputs->length; ++i) { | 131 | return !wsc || !wsc->output || strcmp(wsc->output, output_name) == 0; |
126 | struct workspace_output *wso = config->workspace_outputs->items[i]; | ||
127 | if (strcasecmp(wso->workspace, ws_name) == 0) { | ||
128 | if (strcasecmp(wso->output, output_name) != 0) { | ||
129 | return false; | ||
130 | } | ||
131 | } | ||
132 | } | ||
133 | |||
134 | return true; | ||
135 | } | 132 | } |
136 | 133 | ||
137 | static void workspace_name_from_binding(const struct sway_binding * binding, | 134 | static void workspace_name_from_binding(const struct sway_binding * binding, |
@@ -231,13 +228,13 @@ char *workspace_next_name(const char *output_name) { | |||
231 | workspace_name_from_binding(mode->keycode_bindings->items[i], | 228 | workspace_name_from_binding(mode->keycode_bindings->items[i], |
232 | output_name, &order, &target); | 229 | output_name, &order, &target); |
233 | } | 230 | } |
234 | for (int i = 0; i < config->workspace_outputs->length; ++i) { | 231 | for (int i = 0; i < config->workspace_configs->length; ++i) { |
235 | // Unlike with bindings, this does not guarantee order | 232 | // Unlike with bindings, this does not guarantee order |
236 | const struct workspace_output *wso = config->workspace_outputs->items[i]; | 233 | const struct workspace_config *wsc = config->workspace_configs->items[i]; |
237 | if (strcmp(wso->output, output_name) == 0 | 234 | if (wsc->output && strcmp(wsc->output, output_name) == 0 |
238 | && workspace_by_name(wso->workspace) == NULL) { | 235 | && workspace_by_name(wsc->workspace) == NULL) { |
239 | free(target); | 236 | free(target); |
240 | target = strdup(wso->workspace); | 237 | target = strdup(wsc->workspace); |
241 | break; | 238 | break; |
242 | } | 239 | } |
243 | } | 240 | } |