aboutsummaryrefslogtreecommitdiffstats
path: root/sway/commands/workspace.c
diff options
context:
space:
mode:
Diffstat (limited to 'sway/commands/workspace.c')
-rw-r--r--sway/commands/workspace.c50
1 files changed, 23 insertions, 27 deletions
diff --git a/sway/commands/workspace.c b/sway/commands/workspace.c
index e8b37182..f5558bb4 100644
--- a/sway/commands/workspace.c
+++ b/sway/commands/workspace.c
@@ -17,17 +17,6 @@ struct cmd_results *cmd_workspace(int argc, char **argv) {
17 17
18 int output_location = -1; 18 int output_location = -1;
19 19
20 struct sway_container *current_container = config->handler_context.current_container;
21 struct sway_container *old_workspace = NULL, *old_output = NULL;
22 if (current_container) {
23 if (current_container->type == C_WORKSPACE) {
24 old_workspace = current_container;
25 } else {
26 old_workspace = container_parent(current_container, C_WORKSPACE);
27 }
28 old_output = container_parent(current_container, C_OUTPUT);
29 }
30
31 for (int i = 0; i < argc; ++i) { 20 for (int i = 0; i < argc; ++i) {
32 if (strcasecmp(argv[i], "output") == 0) { 21 if (strcasecmp(argv[i], "output") == 0) {
33 output_location = i; 22 output_location = i;
@@ -57,29 +46,36 @@ struct cmd_results *cmd_workspace(int argc, char **argv) {
57 if (config->reading || !config->active) { 46 if (config->reading || !config->active) {
58 return cmd_results_new(CMD_DEFER, "workspace", NULL); 47 return cmd_results_new(CMD_DEFER, "workspace", NULL);
59 } 48 }
49
50 bool no_auto_back_and_forth = false;
51 while (strcasecmp(argv[0], "--no-auto-back-and-forth") == 0) {
52 no_auto_back_and_forth = true;
53 if ((error = checkarg(--argc, "workspace", EXPECTED_AT_LEAST, 1))) {
54 return error;
55 }
56 ++argv;
57 }
58
59
60 struct sway_container *ws = NULL; 60 struct sway_container *ws = NULL;
61 if (strcasecmp(argv[0], "number") == 0) { 61 if (strcasecmp(argv[0], "number") == 0) {
62 if (argc < 2) {
63 cmd_results_new(CMD_INVALID, "workspace",
64 "Expected workspace number");
65 }
62 if (!(ws = workspace_by_number(argv[1]))) { 66 if (!(ws = workspace_by_number(argv[1]))) {
63 char *name = join_args(argv + 1, argc - 1); 67 char *name = join_args(argv + 1, argc - 1);
64 ws = workspace_create(NULL, name); 68 ws = workspace_create(NULL, name);
65 free(name); 69 free(name);
66 } 70 }
67 } else if (strcasecmp(argv[0], "next") == 0) { 71 } else if (strcasecmp(argv[0], "next") == 0 ||
68 ws = workspace_next(old_workspace); 72 strcasecmp(argv[0], "prev") == 0 ||
69 } else if (strcasecmp(argv[0], "prev") == 0) { 73 strcasecmp(argv[0], "next_on_output") == 0 ||
70 ws = workspace_prev(old_workspace); 74 strcasecmp(argv[0], "prev_on_output") == 0 ||
71 } else if (strcasecmp(argv[0], "next_on_output") == 0) { 75 strcasecmp(argv[0], "current") == 0) {
72 ws = workspace_output_next(old_output); 76 ws = workspace_by_name(argv[0]);
73 } else if (strcasecmp(argv[0], "prev_on_output") == 0) {
74 ws = workspace_output_prev(old_output);
75 } else if (strcasecmp(argv[0], "back_and_forth") == 0) { 77 } else if (strcasecmp(argv[0], "back_and_forth") == 0) {
76 // if auto_back_and_forth is enabled, workspace_switch will swap 78 if (!(ws = workspace_by_name(argv[0])) && prev_workspace_name) {
77 // the workspaces. If we created prev_workspace here, workspace_switch
78 // would put us back on original workspace.
79 if (config->auto_back_and_forth) {
80 ws = old_workspace;
81 } else if (prev_workspace_name
82 && !(ws = workspace_by_name(prev_workspace_name))) {
83 ws = workspace_create(NULL, prev_workspace_name); 79 ws = workspace_create(NULL, prev_workspace_name);
84 } 80 }
85 } else { 81 } else {
@@ -89,7 +85,7 @@ struct cmd_results *cmd_workspace(int argc, char **argv) {
89 } 85 }
90 free(name); 86 free(name);
91 } 87 }
92 workspace_switch(ws); 88 workspace_switch(ws, no_auto_back_and_forth);
93 } 89 }
94 return cmd_results_new(CMD_SUCCESS, NULL, NULL); 90 return cmd_results_new(CMD_SUCCESS, NULL, NULL);
95} 91}