sway

i3-compatible Wayland compositor
git clone https://git.awy.one/sway
Log | Files | Refs | README | LICENSE

commit 12e96f0f9e77658e4f490a1ae94c66a4df40b66f
parent 0ab71f5f0a47fd87bb71d7361ea90a8fa88c8361
Author: Luminarys <kizunanohikari@gmail.com>
Date:   Sun, 30 Aug 2015 21:34:10 -0500

Added in workspace_auto_back_and_forth

Diffstat:
Minclude/config.h | 1+
Msway/commands.c | 13++++++++++++-
Msway/config.c | 1+
Msway/workspace.c | 8++++++--
4 files changed, 20 insertions(+), 3 deletions(-)

diff --git a/include/config.h b/include/config.h @@ -52,6 +52,7 @@ struct sway_config { bool active; bool failed; bool reloading; + bool auto_back_and_forth; int gaps_inner; int gaps_outer; diff --git 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 @@ -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 @@ -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); }