aboutsummaryrefslogtreecommitdiff
path: root/sway
diff options
context:
space:
mode:
Diffstat (limited to 'sway')
-rw-r--r--sway/commands.c13
-rw-r--r--sway/config.c1
-rw-r--r--sway/workspace.c8
3 files changed, 19 insertions, 3 deletions
diff --git a/sway/commands.c b/sway/commands.c
index 1825be4f..177c54ab 100644
--- a/sway/commands.c
+++ b/sway/commands.c
@@ -852,6 +852,16 @@ static bool cmd_workspace(struct sway_config *config, int argc, char **argv) {
return true;
}
+static bool cmd_ws_auto_back_and_forth(struct sway_config *config, int argc, char **argv) {
+ if (!checkarg(argc, "workspace_auto_back_and_forth", EXPECTED_EQUAL_TO, 1)) {
+ return false;
+ }
+ if (strcasecmp(argv[0], "yes") == 0) {
+ config->auto_back_and_forth = true;
+ }
+ return true;
+}
+
/* Keep alphabetized */
static struct cmd_handler handlers[] = {
{ "bindsym", cmd_bindsym },
@@ -877,7 +887,8 @@ static struct cmd_handler handlers[] = {
{ "split", cmd_split },
{ "splith", cmd_splith },
{ "splitv", cmd_splitv },
- { "workspace", cmd_workspace }
+ { "workspace", cmd_workspace },
+ { "workspace_auto_back_and_forth", cmd_ws_auto_back_and_forth }
};
static char **split_directive(char *line, int *argc) {
diff --git a/sway/config.c b/sway/config.c
index f10c73b2..2d7e241d 100644
--- a/sway/config.c
+++ b/sway/config.c
@@ -36,6 +36,7 @@ void config_defaults(struct sway_config *config) {
config->reloading = false;
config->active = false;
config->failed = false;
+ config->auto_back_and_forth = false;
config->gaps_inner = 0;
config->gaps_outer = 0;
diff --git a/sway/workspace.c b/sway/workspace.c
index 0f36e35a..866276d8 100644
--- a/sway/workspace.c
+++ b/sway/workspace.c
@@ -13,7 +13,7 @@
#include "focus.h"
#include "util.h"
-char *prev_workspace_name;
+char *prev_workspace_name = "";
char *workspace_next_name(void) {
sway_log(L_DEBUG, "Workspace: Generating new name");
@@ -182,7 +182,11 @@ void workspace_switch(swayc_t *workspace) {
if (!workspace) {
return;
}
- if (!prev_workspace_name || strcmp(prev_workspace_name, swayc_active_workspace()->name) != 0) {
+ if (strcmp(prev_workspace_name, swayc_active_workspace()->name) != 0 && swayc_active_workspace() != workspace) {
+ prev_workspace_name = malloc(strlen(swayc_active_workspace()->name) + 1);
+ strcpy(prev_workspace_name, swayc_active_workspace()->name);
+ } else if (config->auto_back_and_forth && swayc_active_workspace() == workspace && strlen(prev_workspace_name) != 0) {
+ workspace = workspace_by_name(prev_workspace_name) ? workspace_by_name(prev_workspace_name) : workspace_create(prev_workspace_name);
prev_workspace_name = malloc(strlen(swayc_active_workspace()->name) + 1);
strcpy(prev_workspace_name, swayc_active_workspace()->name);
}