summaryrefslogtreecommitdiff
path: root/src/helpers
diff options
context:
space:
mode:
authorAlexander <51529891+Truenya@users.noreply.github.com>2025-01-11 19:05:53 +0300
committerGitHub <noreply@github.com>2025-01-11 16:05:53 +0000
commit15dc024a398d35957ccfb50ddade5f456a1646b5 (patch)
treedcc4644a49bcf8f3ae8d390526dffcf8b2dfd783 /src/helpers
parent3b85690aa6d9c14bb926692e25cc4480b85200ab (diff)
keybinds: fix previous_per_monitor logic (#9010)
Co-authored-by: Крылов Александр <aleksandr.krylov@hyperus.team>
Diffstat (limited to 'src/helpers')
-rw-r--r--src/helpers/MiscFunctions.cpp2
-rw-r--r--src/helpers/Monitor.cpp24
-rw-r--r--src/helpers/Monitor.hpp13
3 files changed, 35 insertions, 4 deletions
diff --git a/src/helpers/MiscFunctions.cpp b/src/helpers/MiscFunctions.cpp
index 08a1106a..0fa73e45 100644
--- a/src/helpers/MiscFunctions.cpp
+++ b/src/helpers/MiscFunctions.cpp
@@ -258,7 +258,7 @@ SWorkspaceIDName getWorkspaceIDNameFromString(const std::string& in) {
if (!valid(PWORKSPACE))
return {WORKSPACE_INVALID};
- const auto PLASTWORKSPACE = g_pCompositor->getWorkspaceByID(PWORKSPACE->m_sPrevWorkspace.id);
+ const auto PLASTWORKSPACE = g_pCompositor->getWorkspaceByID(PWORKSPACE->getPrevWorkspaceIDName().id);
if (!PLASTWORKSPACE)
return {WORKSPACE_INVALID};
diff --git a/src/helpers/Monitor.cpp b/src/helpers/Monitor.cpp
index e833e661..cf62bc54 100644
--- a/src/helpers/Monitor.cpp
+++ b/src/helpers/Monitor.cpp
@@ -1,5 +1,6 @@
#include "Monitor.hpp"
#include "MiscFunctions.hpp"
+#include "macros.hpp"
#include "math/Math.hpp"
#include "sync/SyncReleaser.hpp"
#include "../Compositor.hpp"
@@ -1169,6 +1170,29 @@ void CMonitor::moveTo(const Vector2D& pos) {
vecPosition = pos;
}
+SWorkspaceIDName CMonitor::getPrevWorkspaceIDName(const WORKSPACEID id) {
+ while (!prevWorkSpaces.empty()) {
+ const int PREVID = prevWorkSpaces.top();
+ prevWorkSpaces.pop();
+ if (PREVID == id) // skip same workspace
+ continue;
+
+ // recheck if previous workspace's was moved to another monitor
+ const auto ws = g_pCompositor->getWorkspaceByID(PREVID);
+ if (ws && ws->monitorID() == ID)
+ return {.id = PREVID, .name = ws->m_szName};
+ }
+
+ return {.id = WORKSPACE_INVALID};
+}
+
+void CMonitor::addPrevWorkspaceID(const WORKSPACEID id) {
+ if (!prevWorkSpaces.empty() && prevWorkSpaces.top() == id)
+ return;
+
+ prevWorkSpaces.emplace(id);
+}
+
Vector2D CMonitor::middle() {
return vecPosition + vecSize / 2.f;
}
diff --git a/src/helpers/Monitor.hpp b/src/helpers/Monitor.hpp
index b075df81..8085c460 100644
--- a/src/helpers/Monitor.hpp
+++ b/src/helpers/Monitor.hpp
@@ -1,7 +1,9 @@
#pragma once
#include "../defines.hpp"
+#include <stack>
#include <vector>
+#include "SharedDefs.hpp"
#include "WLClasses.hpp"
#include <vector>
#include <array>
@@ -196,11 +198,16 @@ class CMonitor {
return vecPosition == rhs.vecPosition && vecSize == rhs.vecSize && szName == rhs.szName;
}
+ // workspace previous per monitor functionality
+ SWorkspaceIDName getPrevWorkspaceIDName(const WORKSPACEID id);
+ void addPrevWorkspaceID(const WORKSPACEID id);
+
private:
- void setupDefaultWS(const SMonitorRule&);
- WORKSPACEID findAvailableDefaultWS();
+ void setupDefaultWS(const SMonitorRule&);
+ WORKSPACEID findAvailableDefaultWS();
- bool doneScheduled = false;
+ bool doneScheduled = false;
+ std::stack<WORKSPACEID> prevWorkSpaces;
struct {
CHyprSignalListener frame;