aboutsummaryrefslogtreecommitdiffstats
path: root/sway/commands/workspace.c
diff options
context:
space:
mode:
authorLibravatar Ian Fan <ianfan0@gmail.com>2018-08-05 00:05:48 +0100
committerLibravatar Ian Fan <ianfan0@gmail.com>2018-08-06 14:17:58 +0100
commit85ae121caad02265b95ecea66fa864607575eb31 (patch)
treeb4d8dab619005e0b2f34068fd908b9153164a74f /sway/commands/workspace.c
parentcommands: fix layout implementation (also better name for previous split layout) (diff)
downloadsway-85ae121caad02265b95ecea66fa864607575eb31.tar.gz
sway-85ae121caad02265b95ecea66fa864607575eb31.tar.zst
sway-85ae121caad02265b95ecea66fa864607575eb31.zip
commands: complete workspace implementation
Allow optional --no-auto-back-and-forth flag, as well as refactoring some logic
Diffstat (limited to 'sway/commands/workspace.c')
-rw-r--r--sway/commands/workspace.c54
1 files changed, 23 insertions, 31 deletions
diff --git a/sway/commands/workspace.c b/sway/commands/workspace.c
index e8b37182..f32ede1e 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,39 +46,42 @@ 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) {
68 ws = workspace_next(old_workspace);
69 } else if (strcasecmp(argv[0], "prev") == 0) {
70 ws = workspace_prev(old_workspace);
71 } else if (strcasecmp(argv[0], "next_on_output") == 0) {
72 ws = workspace_output_next(old_output);
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) {
76 // if auto_back_and_forth is enabled, workspace_switch will swap
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);
84 }
85 } else { 71 } else {
86 char *name = join_args(argv, argc); 72 char *name = join_args(argv, argc);
87 if (!(ws = workspace_by_name(name))) { 73 if (!(ws = workspace_by_name(name))) {
88 ws = workspace_create(NULL, name); 74 if (strcasecmp(argv[0], "back_and_forth") == 0) {
75 if (prev_workspace_name) {
76 ws = workspace_create(NULL, prev_workspace_name);
77 }
78 } else {
79 ws = workspace_create(NULL, name);
80 }
89 } 81 }
90 free(name); 82 free(name);
91 } 83 }
92 workspace_switch(ws); 84 workspace_switch(ws, no_auto_back_and_forth);
93 } 85 }
94 return cmd_results_new(CMD_SUCCESS, NULL, NULL); 86 return cmd_results_new(CMD_SUCCESS, NULL, NULL);
95} 87}