diff options
author | Drew DeVault <sir@cmpwn.com> | 2015-08-31 07:11:02 -0400 |
---|---|---|
committer | Drew DeVault <sir@cmpwn.com> | 2015-08-31 07:11:02 -0400 |
commit | 4d9b05e649ff902c3b53b7e56c0feaa6087f13dc (patch) | |
tree | 60c4c9e7e61126f695c6fb049e2fde7337fc731c | |
parent | 0ab71f5f0a47fd87bb71d7361ea90a8fa88c8361 (diff) | |
parent | 12e96f0f9e77658e4f490a1ae94c66a4df40b66f (diff) | |
download | sway-4d9b05e649ff902c3b53b7e56c0feaa6087f13dc.tar.xz |
Merge pull request #156 from Luminarys/master
Added in workspace_auto_back_and_forth
-rw-r--r-- | include/config.h | 1 | ||||
-rw-r--r-- | sway/commands.c | 13 | ||||
-rw-r--r-- | sway/config.c | 1 | ||||
-rw-r--r-- | sway/workspace.c | 8 |
4 files changed, 20 insertions, 3 deletions
diff --git a/include/config.h b/include/config.h index d1a6d0ac..653e790f 100644 --- 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 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); } |