diff options
-rw-r--r-- | sway/commands/move.c | 60 | ||||
-rw-r--r-- | sway/commands/workspace.c | 18 | ||||
-rw-r--r-- | sway/tree/workspace.c | 39 |
3 files changed, 59 insertions, 58 deletions
diff --git a/sway/commands/move.c b/sway/commands/move.c index d49d6862..500151f7 100644 --- a/sway/commands/move.c +++ b/sway/commands/move.c | |||
@@ -99,40 +99,48 @@ static struct cmd_results *cmd_move_container(struct sway_container *current, | |||
99 | if (strcasecmp(argv[1], "workspace") == 0) { | 99 | if (strcasecmp(argv[1], "workspace") == 0) { |
100 | // move container to workspace x | 100 | // move container to workspace x |
101 | struct sway_container *ws; | 101 | struct sway_container *ws; |
102 | char *ws_name = NULL; | 102 | if (strcasecmp(argv[2], "next") == 0 || |
103 | if (strcasecmp(argv[2], "number") == 0) { | 103 | strcasecmp(argv[2], "prev") == 0 || |
104 | // move "container to workspace number x" | 104 | strcasecmp(argv[2], "next_on_output") == 0 || |
105 | if (argc < 4) { | 105 | strcasecmp(argv[2], "prev_on_output") == 0 || |
106 | return cmd_results_new(CMD_INVALID, "move", expected_syntax); | 106 | strcasecmp(argv[2], "back_and_forth") == 0 || |
107 | strcasecmp(argv[2], "current") == 0) { | ||
108 | ws = workspace_by_name(argv[2]); | ||
109 | } else if (strcasecmp(argv[2], "back_and_forth") == 0) { | ||
110 | if (!(ws = workspace_by_name(argv[0])) && prev_workspace_name) { | ||
111 | ws = workspace_create(NULL, prev_workspace_name); | ||
107 | } | 112 | } |
108 | ws_name = strdup(argv[3]); | ||
109 | ws = workspace_by_number(ws_name); | ||
110 | } else { | 113 | } else { |
111 | ws_name = join_args(argv + 2, argc - 2); | 114 | char *ws_name = NULL; |
112 | ws = workspace_by_name(ws_name); | 115 | if (strcasecmp(argv[2], "number") == 0) { |
113 | } | 116 | // move "container to workspace number x" |
114 | 117 | if (argc < 4) { | |
115 | if (!no_auto_back_and_forth && config->auto_back_and_forth && | 118 | return cmd_results_new(CMD_INVALID, "move", |
116 | prev_workspace_name) { | 119 | expected_syntax); |
117 | // auto back and forth move | 120 | } |
118 | if (old_ws->name && strcmp(old_ws->name, ws_name) == 0) { | 121 | ws_name = strdup(argv[3]); |
119 | // if target workspace is the current one | 122 | ws = workspace_by_number(ws_name); |
120 | free(ws_name); | 123 | } else { |
121 | ws_name = strdup(prev_workspace_name); | 124 | ws_name = join_args(argv + 2, argc - 2); |
122 | ws = workspace_by_name(ws_name); | 125 | ws = workspace_by_name(ws_name); |
123 | } | 126 | } |
124 | } | ||
125 | 127 | ||
126 | if (!ws) { | 128 | if (!no_auto_back_and_forth && config->auto_back_and_forth && |
127 | if (strcasecmp(argv[2], "back_and_forth") == 0) { | 129 | prev_workspace_name) { |
128 | if (prev_workspace_name) { | 130 | // auto back and forth move |
129 | ws = workspace_create(NULL, prev_workspace_name); | 131 | if (old_ws->name && strcmp(old_ws->name, ws_name) == 0) { |
132 | // if target workspace is the current one | ||
133 | free(ws_name); | ||
134 | ws_name = strdup(prev_workspace_name); | ||
135 | ws = workspace_by_name(ws_name); | ||
130 | } | 136 | } |
131 | } | 137 | } |
132 | ws = workspace_create(NULL, ws_name); | ||
133 | } | ||
134 | free(ws_name); | ||
135 | 138 | ||
139 | if (!ws) { | ||
140 | ws = workspace_create(NULL, ws_name); | ||
141 | } | ||
142 | free(ws_name); | ||
143 | } | ||
136 | destination = seat_get_focus_inactive(config->handler_context.seat, ws); | 144 | destination = seat_get_focus_inactive(config->handler_context.seat, ws); |
137 | } else if (strcasecmp(argv[1], "output") == 0) { | 145 | } else if (strcasecmp(argv[1], "output") == 0) { |
138 | struct sway_container *source = container_parent(current, C_OUTPUT); | 146 | struct sway_container *source = container_parent(current, C_OUTPUT); |
diff --git a/sway/commands/workspace.c b/sway/commands/workspace.c index f32ede1e..f5558bb4 100644 --- a/sway/commands/workspace.c +++ b/sway/commands/workspace.c | |||
@@ -68,16 +68,20 @@ struct cmd_results *cmd_workspace(int argc, char **argv) { | |||
68 | ws = workspace_create(NULL, name); | 68 | ws = workspace_create(NULL, name); |
69 | free(name); | 69 | free(name); |
70 | } | 70 | } |
71 | } else if (strcasecmp(argv[0], "next") == 0 || | ||
72 | strcasecmp(argv[0], "prev") == 0 || | ||
73 | strcasecmp(argv[0], "next_on_output") == 0 || | ||
74 | strcasecmp(argv[0], "prev_on_output") == 0 || | ||
75 | strcasecmp(argv[0], "current") == 0) { | ||
76 | ws = workspace_by_name(argv[0]); | ||
77 | } else if (strcasecmp(argv[0], "back_and_forth") == 0) { | ||
78 | if (!(ws = workspace_by_name(argv[0])) && prev_workspace_name) { | ||
79 | ws = workspace_create(NULL, prev_workspace_name); | ||
80 | } | ||
71 | } else { | 81 | } else { |
72 | char *name = join_args(argv, argc); | 82 | char *name = join_args(argv, argc); |
73 | if (!(ws = workspace_by_name(name))) { | 83 | if (!(ws = workspace_by_name(name))) { |
74 | if (strcasecmp(argv[0], "back_and_forth") == 0) { | 84 | ws = workspace_create(NULL, name); |
75 | if (prev_workspace_name) { | ||
76 | ws = workspace_create(NULL, prev_workspace_name); | ||
77 | } | ||
78 | } else { | ||
79 | ws = workspace_create(NULL, name); | ||
80 | } | ||
81 | } | 85 | } |
82 | free(name); | 86 | free(name); |
83 | } | 87 | } |
diff --git a/sway/tree/workspace.c b/sway/tree/workspace.c index 5e20429b..3fcad631 100644 --- a/sway/tree/workspace.c +++ b/sway/tree/workspace.c | |||
@@ -251,34 +251,23 @@ struct sway_container *workspace_by_name(const char *name) { | |||
251 | current_output = container_parent(focus, C_OUTPUT); | 251 | current_output = container_parent(focus, C_OUTPUT); |
252 | } | 252 | } |
253 | 253 | ||
254 | char *name_cpy = strdup(name); | 254 | if (strcmp(name, "prev") == 0) { |
255 | char *first_word = strtok(name_cpy, " "); | 255 | return workspace_prev(current_workspace); |
256 | if (first_word == NULL) { | 256 | } else if (strcmp(name, "prev_on_output") == 0) { |
257 | first_word = name_cpy; | 257 | return workspace_output_prev(current_output); |
258 | } | 258 | } else if (strcmp(name, "next") == 0) { |
259 | 259 | return workspace_next(current_workspace); | |
260 | struct sway_container *ws = NULL; | 260 | } else if (strcmp(name, "next_on_output") == 0) { |
261 | if (strcmp(first_word, "prev") == 0) { | 261 | return workspace_output_next(current_output); |
262 | ws = workspace_prev(current_workspace); | 262 | } else if (strcmp(name, "current") == 0) { |
263 | } else if (strcmp(first_word, "prev_on_output") == 0) { | 263 | return current_workspace; |
264 | ws = workspace_output_prev(current_output); | 264 | } else if (strcasecmp(name, "back_and_forth") == 0) { |
265 | } else if (strcmp(first_word, "next") == 0) { | 265 | return prev_workspace_name ? container_find(&root_container, |
266 | ws = workspace_next(current_workspace); | 266 | _workspace_by_name, (void *)prev_workspace_name) : NULL; |
267 | } else if (strcmp(first_word, "next_on_output") == 0) { | ||
268 | ws = workspace_output_next(current_output); | ||
269 | } else if (strcmp(first_word, "current") == 0) { | ||
270 | ws = current_workspace; | ||
271 | } else if (strcasecmp(first_word, "back_and_forth") == 0) { | ||
272 | if (prev_workspace_name) { | ||
273 | ws = container_find(&root_container, _workspace_by_name, | ||
274 | (void *)prev_workspace_name); | ||
275 | } | ||
276 | } else { | 267 | } else { |
277 | ws = container_find(&root_container, _workspace_by_name, | 268 | return container_find(&root_container, _workspace_by_name, |
278 | (void *)name); | 269 | (void *)name); |
279 | } | 270 | } |
280 | free(name_cpy); | ||
281 | return ws; | ||
282 | } | 271 | } |
283 | 272 | ||
284 | /** | 273 | /** |