+/*
+ * Checks whether we switched to a new workspace and returns false in that case,
+ * signaling that further workspace switching should be done by the calling function
+ * If not, calls workspace_back_and_forth() if workspace_auto_back_and_forth is set
+ * and return true, signaling that no further workspace switching should occur in the calling function.
+ *
+ */
+static bool maybe_back_and_forth(struct CommandResult *cmd_output, char *name) {
+ Con *ws = con_get_workspace(focused);
+
+ /* If we switched to a different workspace, do nothing */
+ if (strcmp(ws->name, name) != 0)
+ return false;
+
+ DLOG("This workspace is already focused.\n");
+ if (config.workspace_auto_back_and_forth) {
+ workspace_back_and_forth();
+ cmd_output->needs_tree_render = true;
+ }
+ return true;
+}
+
+/*
+ * Return the passed workspace unless it is the current one and auto back and
+ * forth is enabled, in which case the back_and_forth workspace is returned.
+ */
+static Con *maybe_auto_back_and_forth_workspace(Con *workspace) {
+ Con *current, *baf;
+
+ if (!config.workspace_auto_back_and_forth)
+ return workspace;
+
+ current = con_get_workspace(focused);
+
+ if (current == workspace) {
+ baf = workspace_back_and_forth_get();
+ if (baf != NULL) {
+ DLOG("Substituting workspace with back_and_forth, as it is focused.\n");
+ return baf;
+ }
+ }
+
+ return workspace;
+}
+