diff options
Diffstat (limited to 'sway/commands/workspace.c')
-rw-r--r-- | sway/commands/workspace.c | 35 |
1 files changed, 19 insertions, 16 deletions
diff --git a/sway/commands/workspace.c b/sway/commands/workspace.c index 2858a284..8536929e 100644 --- a/sway/commands/workspace.c +++ b/sway/commands/workspace.c | |||
@@ -61,7 +61,7 @@ static struct cmd_results *cmd_workspace_gaps(int argc, char **argv, | |||
61 | const char expected[] = "Expected 'workspace <name> gaps " | 61 | const char expected[] = "Expected 'workspace <name> gaps " |
62 | "inner|outer|horizontal|vertical|top|right|bottom|left <px>'"; | 62 | "inner|outer|horizontal|vertical|top|right|bottom|left <px>'"; |
63 | if (gaps_location == 0) { | 63 | if (gaps_location == 0) { |
64 | return cmd_results_new(CMD_INVALID, expected); | 64 | return cmd_results_new(CMD_INVALID, "%s", expected); |
65 | } | 65 | } |
66 | struct cmd_results *error = NULL; | 66 | struct cmd_results *error = NULL; |
67 | if ((error = checkarg(argc, "workspace", EXPECTED_EQUAL_TO, | 67 | if ((error = checkarg(argc, "workspace", EXPECTED_EQUAL_TO, |
@@ -79,7 +79,7 @@ static struct cmd_results *cmd_workspace_gaps(int argc, char **argv, | |||
79 | char *end; | 79 | char *end; |
80 | int amount = strtol(argv[gaps_location + 2], &end, 10); | 80 | int amount = strtol(argv[gaps_location + 2], &end, 10); |
81 | if (strlen(end)) { | 81 | if (strlen(end)) { |
82 | return cmd_results_new(CMD_FAILURE, expected); | 82 | return cmd_results_new(CMD_FAILURE, "%s", expected); |
83 | } | 83 | } |
84 | 84 | ||
85 | bool valid = false; | 85 | bool valid = false; |
@@ -110,7 +110,7 @@ static struct cmd_results *cmd_workspace_gaps(int argc, char **argv, | |||
110 | } | 110 | } |
111 | } | 111 | } |
112 | if (!valid) { | 112 | if (!valid) { |
113 | return cmd_results_new(CMD_INVALID, expected); | 113 | return cmd_results_new(CMD_INVALID, "%s", expected); |
114 | } | 114 | } |
115 | 115 | ||
116 | // Prevent invalid gaps configurations. | 116 | // Prevent invalid gaps configurations. |
@@ -158,6 +158,10 @@ struct cmd_results *cmd_workspace(int argc, char **argv) { | |||
158 | return cmd_results_new(CMD_FAILURE, | 158 | return cmd_results_new(CMD_FAILURE, |
159 | "Unable to allocate workspace output"); | 159 | "Unable to allocate workspace output"); |
160 | } | 160 | } |
161 | if (output_location + 1 < argc) { | ||
162 | list_free_items_and_destroy(wsc->outputs); | ||
163 | wsc->outputs = create_list(); | ||
164 | } | ||
161 | for (int i = output_location + 1; i < argc; ++i) { | 165 | for (int i = output_location + 1; i < argc; ++i) { |
162 | list_add(wsc->outputs, strdup(argv[i])); | 166 | list_add(wsc->outputs, strdup(argv[i])); |
163 | } | 167 | } |
@@ -174,25 +178,20 @@ struct cmd_results *cmd_workspace(int argc, char **argv) { | |||
174 | } | 178 | } |
175 | 179 | ||
176 | if (root->fullscreen_global) { | 180 | if (root->fullscreen_global) { |
177 | return cmd_results_new(CMD_FAILURE, "workspace", | 181 | return cmd_results_new(CMD_FAILURE, |
178 | "Can't switch workspaces while fullscreen global"); | 182 | "Can't switch workspaces while fullscreen global"); |
179 | } | 183 | } |
180 | 184 | ||
181 | bool no_auto_back_and_forth = false; | 185 | bool auto_back_and_forth = true; |
182 | while (strcasecmp(argv[0], "--no-auto-back-and-forth") == 0) { | 186 | while (strcasecmp(argv[0], "--no-auto-back-and-forth") == 0) { |
183 | no_auto_back_and_forth = true; | 187 | auto_back_and_forth = false; |
184 | if ((error = checkarg(--argc, "workspace", EXPECTED_AT_LEAST, 1))) { | 188 | if ((error = checkarg(--argc, "workspace", EXPECTED_AT_LEAST, 1))) { |
185 | return error; | 189 | return error; |
186 | } | 190 | } |
187 | ++argv; | 191 | ++argv; |
188 | } | 192 | } |
189 | 193 | ||
190 | bool create = argc > 1 && strcasecmp(argv[1], "--create") == 0; | ||
191 | struct sway_seat *seat = config->handler_context.seat; | 194 | struct sway_seat *seat = config->handler_context.seat; |
192 | struct sway_workspace *current = seat_get_focused_workspace(seat); | ||
193 | if (!current) { | ||
194 | return cmd_results_new(CMD_FAILURE, "No workspace to switch from"); | ||
195 | } | ||
196 | 195 | ||
197 | struct sway_workspace *ws = NULL; | 196 | struct sway_workspace *ws = NULL; |
198 | if (strcasecmp(argv[0], "number") == 0) { | 197 | if (strcasecmp(argv[0], "number") == 0) { |
@@ -209,14 +208,15 @@ struct cmd_results *cmd_workspace(int argc, char **argv) { | |||
209 | ws = workspace_create(NULL, name); | 208 | ws = workspace_create(NULL, name); |
210 | free(name); | 209 | free(name); |
211 | } | 210 | } |
211 | if (ws && auto_back_and_forth) { | ||
212 | ws = workspace_auto_back_and_forth(ws); | ||
213 | } | ||
212 | } else if (strcasecmp(argv[0], "next") == 0 || | 214 | } else if (strcasecmp(argv[0], "next") == 0 || |
213 | strcasecmp(argv[0], "prev") == 0 || | 215 | strcasecmp(argv[0], "prev") == 0 || |
216 | strcasecmp(argv[0], "next_on_output") == 0 || | ||
217 | strcasecmp(argv[0], "prev_on_output") == 0 || | ||
214 | strcasecmp(argv[0], "current") == 0) { | 218 | strcasecmp(argv[0], "current") == 0) { |
215 | ws = workspace_by_name(argv[0]); | 219 | ws = workspace_by_name(argv[0]); |
216 | } else if (strcasecmp(argv[0], "next_on_output") == 0) { | ||
217 | ws = workspace_output_next(current, create); | ||
218 | } else if (strcasecmp(argv[0], "prev_on_output") == 0) { | ||
219 | ws = workspace_output_prev(current, create); | ||
220 | } else if (strcasecmp(argv[0], "back_and_forth") == 0) { | 220 | } else if (strcasecmp(argv[0], "back_and_forth") == 0) { |
221 | if (!seat->prev_workspace_name) { | 221 | if (!seat->prev_workspace_name) { |
222 | return cmd_results_new(CMD_INVALID, | 222 | return cmd_results_new(CMD_INVALID, |
@@ -231,11 +231,14 @@ struct cmd_results *cmd_workspace(int argc, char **argv) { | |||
231 | ws = workspace_create(NULL, name); | 231 | ws = workspace_create(NULL, name); |
232 | } | 232 | } |
233 | free(name); | 233 | free(name); |
234 | if (ws && auto_back_and_forth) { | ||
235 | ws = workspace_auto_back_and_forth(ws); | ||
236 | } | ||
234 | } | 237 | } |
235 | if (!ws) { | 238 | if (!ws) { |
236 | return cmd_results_new(CMD_FAILURE, "No workspace to switch to"); | 239 | return cmd_results_new(CMD_FAILURE, "No workspace to switch to"); |
237 | } | 240 | } |
238 | workspace_switch(ws, no_auto_back_and_forth); | 241 | workspace_switch(ws); |
239 | seat_consider_warp_to_focus(seat); | 242 | seat_consider_warp_to_focus(seat); |
240 | } | 243 | } |
241 | return cmd_results_new(CMD_SUCCESS, NULL); | 244 | return cmd_results_new(CMD_SUCCESS, NULL); |