aboutsummaryrefslogtreecommitdiffstats
path: root/sway/tree/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/tree/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/tree/workspace.c')
-rw-r--r--sway/tree/workspace.c42
1 files changed, 29 insertions, 13 deletions
diff --git a/sway/tree/workspace.c b/sway/tree/workspace.c
index 250d5ba7..5e20429b 100644
--- a/sway/tree/workspace.c
+++ b/sway/tree/workspace.c
@@ -250,20 +250,35 @@ struct sway_container *workspace_by_name(const char *name) {
250 current_workspace = container_parent(focus, C_WORKSPACE); 250 current_workspace = container_parent(focus, C_WORKSPACE);
251 current_output = container_parent(focus, C_OUTPUT); 251 current_output = container_parent(focus, C_OUTPUT);
252 } 252 }
253 if (strcmp(name, "prev") == 0) { 253
254 return workspace_prev(current_workspace); 254 char *name_cpy = strdup(name);
255 } else if (strcmp(name, "prev_on_output") == 0) { 255 char *first_word = strtok(name_cpy, " ");
256 return workspace_output_prev(current_output); 256 if (first_word == NULL) {
257 } else if (strcmp(name, "next") == 0) { 257 first_word = name_cpy;
258 return workspace_next(current_workspace); 258 }
259 } else if (strcmp(name, "next_on_output") == 0) { 259
260 return workspace_output_next(current_output); 260 struct sway_container *ws = NULL;
261 } else if (strcmp(name, "current") == 0) { 261 if (strcmp(first_word, "prev") == 0) {
262 return current_workspace; 262 ws = workspace_prev(current_workspace);
263 } else if (strcmp(first_word, "prev_on_output") == 0) {
264 ws = workspace_output_prev(current_output);
265 } else if (strcmp(first_word, "next") == 0) {
266 ws = workspace_next(current_workspace);
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 }
263 } else { 276 } else {
264 return container_find(&root_container, _workspace_by_name, 277 ws = container_find(&root_container, _workspace_by_name,
265 (void *)name); 278 (void *)name);
266 } 279 }
280 free(name_cpy);
281 return ws;
267} 282}
268 283
269/** 284/**
@@ -364,7 +379,8 @@ struct sway_container *workspace_prev(struct sway_container *current) {
364 return workspace_prev_next_impl(current, false); 379 return workspace_prev_next_impl(current, false);
365} 380}
366 381
367bool workspace_switch(struct sway_container *workspace) { 382bool workspace_switch(struct sway_container *workspace,
383 bool no_auto_back_and_forth) {
368 if (!workspace) { 384 if (!workspace) {
369 return false; 385 return false;
370 } 386 }
@@ -379,7 +395,7 @@ bool workspace_switch(struct sway_container *workspace) {
379 active_ws = container_parent(focus, C_WORKSPACE); 395 active_ws = container_parent(focus, C_WORKSPACE);
380 } 396 }
381 397
382 if (config->auto_back_and_forth 398 if (!no_auto_back_and_forth && config->auto_back_and_forth
383 && active_ws == workspace 399 && active_ws == workspace
384 && prev_workspace_name) { 400 && prev_workspace_name) {
385 struct sway_container *new_ws = workspace_by_name(prev_workspace_name); 401 struct sway_container *new_ws = workspace_by_name(prev_workspace_name);