From 7fce5f1063d0bc6d091f56c45809a88e13dde814 Mon Sep 17 00:00:00 2001 From: LordGrimmauld Date: Mon, 1 Apr 2024 11:53:37 +0200 Subject: [PATCH] create workspace now respects selected output again --- Keys/CreateWorkspaceKeyListener.h | 2 +- Keys/MainWindowAwareKeyListener.h | 11 ++++++----- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/Keys/CreateWorkspaceKeyListener.h b/Keys/CreateWorkspaceKeyListener.h index f881c75..69935c0 100644 --- a/Keys/CreateWorkspaceKeyListener.h +++ b/Keys/CreateWorkspaceKeyListener.h @@ -23,7 +23,7 @@ public: if (selectedOutput != nullptr) cmd << "focus output " << selectedOutput->node.name << " , "; - cmd << "workspace " << createNewWorkspaceId({}); + cmd << "workspace " << createNewWorkspaceId({}, selectedOutput); auto resp = SwayTreeModel::sway.sendIPC(swaymsg(0, cmd.str())); std::cout << resp.msg << "\n"; QApplication::quit(); diff --git a/Keys/MainWindowAwareKeyListener.h b/Keys/MainWindowAwareKeyListener.h index d201824..46bbcd8 100644 --- a/Keys/MainWindowAwareKeyListener.h +++ b/Keys/MainWindowAwareKeyListener.h @@ -32,7 +32,7 @@ protected: return containerIds; } - [[nodiscard]] std::string createNewWorkspaceId(const std::set &allowedContainers) const { + [[nodiscard]] std::string createNewWorkspaceId(const std::set &allowedContainers, const SwayTreeNode* preferredOutput = nullptr) const { std::set candidates; for (auto *con: allowedContainers) { @@ -40,14 +40,14 @@ protected: if (workspace == nullptr) continue; - if (allowedContainers.contains(workspace)) { + if (allowedContainers.contains(workspace) && (preferredOutput == nullptr || preferredOutput == workspace->findOutput())) { candidates.insert(workspace->node.name); continue; } auto containers = workspace->accumulateContainers(); - if (std::all_of(containers.begin(), containers.end(), [allowedContainers](const SwayTreeNode *container) { - return allowedContainers.contains(container); + if (std::all_of(containers.begin(), containers.end(), [allowedContainers, preferredOutput](const SwayTreeNode *container) { + return allowedContainers.contains(container) && (preferredOutput == nullptr || preferredOutput == container->findOutput()); })) { candidates.insert(workspace->node.name); } @@ -63,7 +63,8 @@ protected: do { newWorkspace++; workspaceNode = getModel()->getRoot()->findWorkspaceByName(std::to_string(newWorkspace)); - } while (workspaceNode != nullptr && workspaceNode->childCount() != 0); + } while (workspaceNode != nullptr && workspaceNode->childCount() != 0 + && (preferredOutput != nullptr && preferredOutput == workspaceNode->findOutput())); return std::to_string(newWorkspace); }