diff options
Diffstat (limited to 'sway/commands/workspace.c')
-rw-r--r-- | sway/commands/workspace.c | 48 |
1 files changed, 29 insertions, 19 deletions
diff --git a/sway/commands/workspace.c b/sway/commands/workspace.c index a7839746..958b3222 100644 --- a/sway/commands/workspace.c +++ b/sway/commands/workspace.c | |||
@@ -3,8 +3,8 @@ | |||
3 | #include <strings.h> | 3 | #include <strings.h> |
4 | #include "sway/commands.h" | 4 | #include "sway/commands.h" |
5 | #include "sway/config.h" | 5 | #include "sway/config.h" |
6 | #include "sway/input_state.h" | 6 | #include "sway/input/seat.h" |
7 | #include "sway/workspace.h" | 7 | #include "sway/tree/workspace.h" |
8 | #include "list.h" | 8 | #include "list.h" |
9 | #include "log.h" | 9 | #include "log.h" |
10 | #include "stringop.h" | 10 | #include "stringop.h" |
@@ -17,6 +17,17 @@ 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 | |||
20 | for (int i = 0; i < argc; ++i) { | 31 | for (int i = 0; i < argc; ++i) { |
21 | if (strcasecmp(argv[i], "output") == 0) { | 32 | if (strcasecmp(argv[i], "output") == 0) { |
22 | output_location = i; | 33 | output_location = i; |
@@ -40,52 +51,51 @@ struct cmd_results *cmd_workspace(int argc, char **argv) { | |||
40 | free(old); // workspaces can only be assigned to a single output | 51 | free(old); // workspaces can only be assigned to a single output |
41 | list_del(config->workspace_outputs, i); | 52 | list_del(config->workspace_outputs, i); |
42 | } | 53 | } |
43 | sway_log(L_DEBUG, "Assigning workspace %s to output %s", wso->workspace, wso->output); | 54 | wlr_log(L_DEBUG, "Assigning workspace %s to output %s", wso->workspace, wso->output); |
44 | list_add(config->workspace_outputs, wso); | 55 | list_add(config->workspace_outputs, wso); |
45 | } else { | 56 | } else { |
46 | if (config->reading || !config->active) { | 57 | if (config->reading || !config->active) { |
47 | return cmd_results_new(CMD_DEFER, "workspace", NULL); | 58 | return cmd_results_new(CMD_DEFER, "workspace", NULL); |
48 | } | 59 | } |
49 | swayc_t *ws = NULL; | 60 | struct sway_container *ws = NULL; |
50 | if (strcasecmp(argv[0], "number") == 0) { | 61 | if (strcasecmp(argv[0], "number") == 0) { |
51 | if (!(ws = workspace_by_number(argv[1]))) { | 62 | if (!(ws = workspace_by_number(argv[1]))) { |
52 | char *name = join_args(argv + 1, argc - 1); | 63 | char *name = join_args(argv + 1, argc - 1); |
53 | ws = workspace_create(name); | 64 | ws = workspace_create(NULL, name); |
54 | free(name); | 65 | free(name); |
55 | } | 66 | } |
56 | } else if (strcasecmp(argv[0], "next") == 0) { | 67 | } else if (strcasecmp(argv[0], "next") == 0) { |
57 | ws = workspace_next(); | 68 | ws = workspace_next(old_workspace); |
58 | } else if (strcasecmp(argv[0], "prev") == 0) { | 69 | } else if (strcasecmp(argv[0], "prev") == 0) { |
59 | ws = workspace_prev(); | 70 | ws = workspace_prev(old_workspace); |
60 | } else if (strcasecmp(argv[0], "next_on_output") == 0) { | 71 | } else if (strcasecmp(argv[0], "next_on_output") == 0) { |
61 | ws = workspace_output_next(); | 72 | ws = workspace_output_next(old_output); |
62 | } else if (strcasecmp(argv[0], "prev_on_output") == 0) { | 73 | } else if (strcasecmp(argv[0], "prev_on_output") == 0) { |
63 | ws = workspace_output_prev(); | 74 | ws = workspace_output_prev(old_output); |
64 | } else if (strcasecmp(argv[0], "back_and_forth") == 0) { | 75 | } else if (strcasecmp(argv[0], "back_and_forth") == 0) { |
65 | // if auto_back_and_forth is enabled, workspace_switch will swap | 76 | // if auto_back_and_forth is enabled, workspace_switch will swap |
66 | // the workspaces. If we created prev_workspace here, workspace_switch | 77 | // the workspaces. If we created prev_workspace here, workspace_switch |
67 | // would put us back on original workspace. | 78 | // would put us back on original workspace. |
68 | if (config->auto_back_and_forth) { | 79 | if (config->auto_back_and_forth) { |
69 | ws = swayc_active_workspace(); | 80 | ws = old_workspace; |
70 | } else if (prev_workspace_name && !(ws = workspace_by_name(prev_workspace_name))) { | 81 | } else if (prev_workspace_name |
71 | ws = workspace_create(prev_workspace_name); | 82 | && !(ws = workspace_by_name(prev_workspace_name))) { |
83 | ws = workspace_create(NULL, prev_workspace_name); | ||
72 | } | 84 | } |
73 | } else { | 85 | } else { |
74 | char *name = join_args(argv, argc); | 86 | char *name = join_args(argv, argc); |
75 | if (!(ws = workspace_by_name(name))) { | 87 | if (!(ws = workspace_by_name(name))) { |
76 | ws = workspace_create(name); | 88 | ws = workspace_create(NULL, name); |
77 | } | 89 | } |
78 | free(name); | 90 | free(name); |
79 | } | 91 | } |
80 | swayc_t *old_output = swayc_active_output(); | ||
81 | workspace_switch(ws); | 92 | workspace_switch(ws); |
82 | swayc_t *new_output = swayc_active_output(); | 93 | current_container = |
94 | seat_get_focus(config->handler_context.seat); | ||
95 | struct sway_container *new_output = container_parent(current_container, C_OUTPUT); | ||
83 | 96 | ||
84 | if (config->mouse_warping && old_output != new_output) { | 97 | if (config->mouse_warping && old_output != new_output) { |
85 | swayc_t *focused = get_focused_view(ws); | 98 | // TODO: Warp mouse |
86 | if (focused && focused->type == C_VIEW) { | ||
87 | center_pointer_on(focused); | ||
88 | } | ||
89 | } | 99 | } |
90 | } | 100 | } |
91 | return cmd_results_new(CMD_SUCCESS, NULL, NULL); | 101 | return cmd_results_new(CMD_SUCCESS, NULL, NULL); |