diff options
Diffstat (limited to 'sway/commands/workspace.c')
-rw-r--r-- | sway/commands/workspace.c | 32 |
1 files changed, 15 insertions, 17 deletions
diff --git a/sway/commands/workspace.c b/sway/commands/workspace.c index 9ff1c97d..37a201b4 100644 --- a/sway/commands/workspace.c +++ b/sway/commands/workspace.c | |||
@@ -1,4 +1,3 @@ | |||
1 | #define _POSIX_C_SOURCE 200809L | ||
2 | #include <ctype.h> | 1 | #include <ctype.h> |
3 | #include <limits.h> | 2 | #include <limits.h> |
4 | #include <string.h> | 3 | #include <string.h> |
@@ -61,7 +60,7 @@ static struct cmd_results *cmd_workspace_gaps(int argc, char **argv, | |||
61 | const char expected[] = "Expected 'workspace <name> gaps " | 60 | const char expected[] = "Expected 'workspace <name> gaps " |
62 | "inner|outer|horizontal|vertical|top|right|bottom|left <px>'"; | 61 | "inner|outer|horizontal|vertical|top|right|bottom|left <px>'"; |
63 | if (gaps_location == 0) { | 62 | if (gaps_location == 0) { |
64 | return cmd_results_new(CMD_INVALID, expected); | 63 | return cmd_results_new(CMD_INVALID, "%s", expected); |
65 | } | 64 | } |
66 | struct cmd_results *error = NULL; | 65 | struct cmd_results *error = NULL; |
67 | if ((error = checkarg(argc, "workspace", EXPECTED_EQUAL_TO, | 66 | if ((error = checkarg(argc, "workspace", EXPECTED_EQUAL_TO, |
@@ -79,7 +78,7 @@ static struct cmd_results *cmd_workspace_gaps(int argc, char **argv, | |||
79 | char *end; | 78 | char *end; |
80 | int amount = strtol(argv[gaps_location + 2], &end, 10); | 79 | int amount = strtol(argv[gaps_location + 2], &end, 10); |
81 | if (strlen(end)) { | 80 | if (strlen(end)) { |
82 | return cmd_results_new(CMD_FAILURE, expected); | 81 | return cmd_results_new(CMD_FAILURE, "%s", expected); |
83 | } | 82 | } |
84 | 83 | ||
85 | bool valid = false; | 84 | bool valid = false; |
@@ -110,7 +109,7 @@ static struct cmd_results *cmd_workspace_gaps(int argc, char **argv, | |||
110 | } | 109 | } |
111 | } | 110 | } |
112 | if (!valid) { | 111 | if (!valid) { |
113 | return cmd_results_new(CMD_INVALID, expected); | 112 | return cmd_results_new(CMD_INVALID, "%s", expected); |
114 | } | 113 | } |
115 | 114 | ||
116 | // Prevent invalid gaps configurations. | 115 | // Prevent invalid gaps configurations. |
@@ -178,25 +177,20 @@ struct cmd_results *cmd_workspace(int argc, char **argv) { | |||
178 | } | 177 | } |
179 | 178 | ||
180 | if (root->fullscreen_global) { | 179 | if (root->fullscreen_global) { |
181 | return cmd_results_new(CMD_FAILURE, "workspace", | 180 | return cmd_results_new(CMD_FAILURE, |
182 | "Can't switch workspaces while fullscreen global"); | 181 | "Can't switch workspaces while fullscreen global"); |
183 | } | 182 | } |
184 | 183 | ||
185 | bool no_auto_back_and_forth = false; | 184 | bool auto_back_and_forth = true; |
186 | while (strcasecmp(argv[0], "--no-auto-back-and-forth") == 0) { | 185 | while (strcasecmp(argv[0], "--no-auto-back-and-forth") == 0) { |
187 | no_auto_back_and_forth = true; | 186 | auto_back_and_forth = false; |
188 | if ((error = checkarg(--argc, "workspace", EXPECTED_AT_LEAST, 1))) { | 187 | if ((error = checkarg(--argc, "workspace", EXPECTED_AT_LEAST, 1))) { |
189 | return error; | 188 | return error; |
190 | } | 189 | } |
191 | ++argv; | 190 | ++argv; |
192 | } | 191 | } |
193 | 192 | ||
194 | bool create = argc > 1 && strcasecmp(argv[1], "--create") == 0; | ||
195 | struct sway_seat *seat = config->handler_context.seat; | 193 | struct sway_seat *seat = config->handler_context.seat; |
196 | struct sway_workspace *current = seat_get_focused_workspace(seat); | ||
197 | if (!current) { | ||
198 | return cmd_results_new(CMD_FAILURE, "No workspace to switch from"); | ||
199 | } | ||
200 | 194 | ||
201 | struct sway_workspace *ws = NULL; | 195 | struct sway_workspace *ws = NULL; |
202 | if (strcasecmp(argv[0], "number") == 0) { | 196 | if (strcasecmp(argv[0], "number") == 0) { |
@@ -213,14 +207,15 @@ struct cmd_results *cmd_workspace(int argc, char **argv) { | |||
213 | ws = workspace_create(NULL, name); | 207 | ws = workspace_create(NULL, name); |
214 | free(name); | 208 | free(name); |
215 | } | 209 | } |
210 | if (ws && auto_back_and_forth) { | ||
211 | ws = workspace_auto_back_and_forth(ws); | ||
212 | } | ||
216 | } else if (strcasecmp(argv[0], "next") == 0 || | 213 | } else if (strcasecmp(argv[0], "next") == 0 || |
217 | strcasecmp(argv[0], "prev") == 0 || | 214 | strcasecmp(argv[0], "prev") == 0 || |
215 | strcasecmp(argv[0], "next_on_output") == 0 || | ||
216 | strcasecmp(argv[0], "prev_on_output") == 0 || | ||
218 | strcasecmp(argv[0], "current") == 0) { | 217 | strcasecmp(argv[0], "current") == 0) { |
219 | ws = workspace_by_name(argv[0]); | 218 | ws = workspace_by_name(argv[0]); |
220 | } else if (strcasecmp(argv[0], "next_on_output") == 0) { | ||
221 | ws = workspace_output_next(current, create); | ||
222 | } else if (strcasecmp(argv[0], "prev_on_output") == 0) { | ||
223 | ws = workspace_output_prev(current, create); | ||
224 | } else if (strcasecmp(argv[0], "back_and_forth") == 0) { | 219 | } else if (strcasecmp(argv[0], "back_and_forth") == 0) { |
225 | if (!seat->prev_workspace_name) { | 220 | if (!seat->prev_workspace_name) { |
226 | return cmd_results_new(CMD_INVALID, | 221 | return cmd_results_new(CMD_INVALID, |
@@ -235,11 +230,14 @@ struct cmd_results *cmd_workspace(int argc, char **argv) { | |||
235 | ws = workspace_create(NULL, name); | 230 | ws = workspace_create(NULL, name); |
236 | } | 231 | } |
237 | free(name); | 232 | free(name); |
233 | if (ws && auto_back_and_forth) { | ||
234 | ws = workspace_auto_back_and_forth(ws); | ||
235 | } | ||
238 | } | 236 | } |
239 | if (!ws) { | 237 | if (!ws) { |
240 | return cmd_results_new(CMD_FAILURE, "No workspace to switch to"); | 238 | return cmd_results_new(CMD_FAILURE, "No workspace to switch to"); |
241 | } | 239 | } |
242 | workspace_switch(ws, no_auto_back_and_forth); | 240 | workspace_switch(ws); |
243 | seat_consider_warp_to_focus(seat); | 241 | seat_consider_warp_to_focus(seat); |
244 | } | 242 | } |
245 | return cmd_results_new(CMD_SUCCESS, NULL); | 243 | return cmd_results_new(CMD_SUCCESS, NULL); |