diff options
Diffstat (limited to 'src/helpers')
-rw-r--r-- | src/helpers/AnimatedVariable.cpp | 2 | ||||
-rw-r--r-- | src/helpers/AnimatedVariable.hpp | 13 | ||||
-rw-r--r-- | src/helpers/MiscFunctions.cpp | 20 | ||||
-rw-r--r-- | src/helpers/Monitor.cpp | 80 | ||||
-rw-r--r-- | src/helpers/Monitor.hpp | 18 | ||||
-rw-r--r-- | src/helpers/WLClasses.hpp | 14 |
6 files changed, 75 insertions, 72 deletions
diff --git a/src/helpers/AnimatedVariable.cpp b/src/helpers/AnimatedVariable.cpp index 74575c83..65206af0 100644 --- a/src/helpers/AnimatedVariable.cpp +++ b/src/helpers/AnimatedVariable.cpp @@ -22,7 +22,7 @@ void CBaseAnimatedVariable::create(SAnimationPropertyConfig* pAnimConfig, SLayer m_bDummy = false; } -void CBaseAnimatedVariable::create(SAnimationPropertyConfig* pAnimConfig, CWorkspace* pWorkspace, AVARDAMAGEPOLICY policy) { +void CBaseAnimatedVariable::create(SAnimationPropertyConfig* pAnimConfig, PHLWORKSPACE pWorkspace, AVARDAMAGEPOLICY policy) { m_eDamagePolicy = policy; m_pConfig = pAnimConfig; m_pWorkspace = pWorkspace; diff --git a/src/helpers/AnimatedVariable.hpp b/src/helpers/AnimatedVariable.hpp index 85ffb9ab..4c24f642 100644 --- a/src/helpers/AnimatedVariable.hpp +++ b/src/helpers/AnimatedVariable.hpp @@ -8,6 +8,7 @@ #include "Color.hpp" #include "../macros.hpp" #include "../debug/Log.hpp" +#include "../desktop/DesktopTypes.hpp" enum ANIMATEDVARTYPE { AVARTYPE_INVALID = -1, @@ -48,11 +49,11 @@ enum AVARDAMAGEPOLICY { }; class CAnimationManager; -class CWorkspace; struct SLayerSurface; struct SAnimationPropertyConfig; class CHyprRenderer; class CWindow; +class CWorkspace; // Utility to define a concept as a list of possible type template <class T, class... U> @@ -69,7 +70,7 @@ class CBaseAnimatedVariable { CBaseAnimatedVariable(ANIMATEDVARTYPE type); void create(SAnimationPropertyConfig* pAnimConfig, CWindow* pWindow, AVARDAMAGEPOLICY policy); void create(SAnimationPropertyConfig* pAnimConfig, SLayerSurface* pLayer, AVARDAMAGEPOLICY policy); - void create(SAnimationPropertyConfig* pAnimConfig, CWorkspace* pWorkspace, AVARDAMAGEPOLICY policy); + void create(SAnimationPropertyConfig* pAnimConfig, PHLWORKSPACE pWorkspace, AVARDAMAGEPOLICY policy); void create(SAnimationPropertyConfig* pAnimConfig, AVARDAMAGEPOLICY policy); CBaseAnimatedVariable(const CBaseAnimatedVariable&) = delete; @@ -144,9 +145,9 @@ class CBaseAnimatedVariable { } protected: - void* m_pWindow = nullptr; - void* m_pWorkspace = nullptr; - void* m_pLayer = nullptr; + void* m_pWindow = nullptr; + std::weak_ptr<CWorkspace> m_pWorkspace; + void* m_pLayer = nullptr; SAnimationPropertyConfig* m_pConfig = nullptr; @@ -217,7 +218,7 @@ class CAnimatedVariable : public CBaseAnimatedVariable { m_Value = value; m_Goal = value; } - void create(const VarType& value, SAnimationPropertyConfig* pAnimConfig, CWorkspace* pWorkspace, AVARDAMAGEPOLICY policy) { + void create(const VarType& value, SAnimationPropertyConfig* pAnimConfig, PHLWORKSPACE pWorkspace, AVARDAMAGEPOLICY policy) { create(pAnimConfig, pWorkspace, policy); m_Value = value; m_Goal = value; diff --git a/src/helpers/MiscFunctions.cpp b/src/helpers/MiscFunctions.cpp index 2b83832c..9e76ccc6 100644 --- a/src/helpers/MiscFunctions.cpp +++ b/src/helpers/MiscFunctions.cpp @@ -289,9 +289,9 @@ int getWorkspaceIDFromString(const std::string& in, std::string& outName) { if (!g_pCompositor->m_pLastMonitor) return WORKSPACE_INVALID; - const auto PWORKSPACE = g_pCompositor->getWorkspaceByID(g_pCompositor->m_pLastMonitor->activeWorkspace); + const auto PWORKSPACE = g_pCompositor->m_pLastMonitor->activeWorkspace; - if (!PWORKSPACE) + if (!valid(PWORKSPACE)) return WORKSPACE_INVALID; const auto PLASTWORKSPACE = g_pCompositor->getWorkspaceByID(PWORKSPACE->m_sPrevWorkspace.iID); @@ -347,7 +347,8 @@ int getWorkspaceIDFromString(const std::string& in, std::string& outName) { std::sort(namedWSes.begin(), namedWSes.end()); // Just take a blind guess at where we'll probably end up - int predictedWSID = g_pCompositor->m_pLastMonitor->activeWorkspace + remains; + int activeWSID = g_pCompositor->m_pLastMonitor->activeWorkspace ? g_pCompositor->m_pLastMonitor->activeWorkspace->m_iID : 1; + int predictedWSID = activeWSID + remains; int remainingWSes = 0; char walkDir = in[1]; @@ -355,20 +356,20 @@ int getWorkspaceIDFromString(const std::string& in, std::string& outName) { predictedWSID = std::max(predictedWSID, 0); // Count how many invalidWSes are in between (how bad the prediction was) - int beginID = in[1] == '+' ? g_pCompositor->m_pLastMonitor->activeWorkspace + 1 : predictedWSID; - int endID = in[1] == '+' ? predictedWSID : g_pCompositor->m_pLastMonitor->activeWorkspace; + int beginID = in[1] == '+' ? activeWSID + 1 : predictedWSID; + int endID = in[1] == '+' ? predictedWSID : activeWSID; auto begin = invalidWSes.upper_bound(beginID - 1); // upper_bound is >, we want >= for (auto it = begin; *it <= endID && it != invalidWSes.end(); it++) { remainingWSes++; } // Handle named workspaces. They are treated like always before other workspaces - if (g_pCompositor->m_pLastMonitor->activeWorkspace < 0) { + if (activeWSID < 0) { // Behaviour similar to 'm' // Find current int currentItem = -1; for (size_t i = 0; i < namedWSes.size(); i++) { - if (namedWSes[i] == g_pCompositor->m_pLastMonitor->activeWorkspace) { + if (namedWSes[i] == activeWSID) { currentItem = i; break; } @@ -473,9 +474,10 @@ int getWorkspaceIDFromString(const std::string& in, std::string& outName) { remains = remains < 0 ? -((-remains) % validWSes.size()) : remains % validWSes.size(); // get the current item + int activeWSID = g_pCompositor->m_pLastMonitor->activeWorkspace ? g_pCompositor->m_pLastMonitor->activeWorkspace->m_iID : 1; int currentItem = -1; for (size_t i = 0; i < validWSes.size(); i++) { - if (validWSes[i] == g_pCompositor->m_pLastMonitor->activeWorkspace) { + if (validWSes[i] == activeWSID) { currentItem = i; break; } @@ -496,7 +498,7 @@ int getWorkspaceIDFromString(const std::string& in, std::string& outName) { } else { if (in[0] == '+' || in[0] == '-') { if (g_pCompositor->m_pLastMonitor) { - const auto PLUSMINUSRESULT = getPlusMinusKeywordResult(in, g_pCompositor->m_pLastMonitor->activeWorkspace); + const auto PLUSMINUSRESULT = getPlusMinusKeywordResult(in, g_pCompositor->m_pLastMonitor->activeWorkspaceID()); if (!PLUSMINUSRESULT.has_value()) return WORKSPACE_INVALID; diff --git a/src/helpers/Monitor.cpp b/src/helpers/Monitor.cpp index 219257b9..8bae3477 100644 --- a/src/helpers/Monitor.cpp +++ b/src/helpers/Monitor.cpp @@ -170,7 +170,7 @@ void CMonitor::onConnect(bool noRule) { for (auto& ws : g_pCompositor->m_vWorkspaces) { if (ws->m_szLastMonitor == szName || g_pCompositor->m_vMonitors.size() == 1 /* avoid lost workspaces on recover */) { - g_pCompositor->moveWorkspaceToMonitor(ws.get(), this); + g_pCompositor->moveWorkspaceToMonitor(ws, this); ws->startAnim(true, true, true); ws->m_szLastMonitor = ""; } @@ -281,10 +281,10 @@ void CMonitor::onDisconnect(bool destroy) { BACKUPMON->vecPosition.y + BACKUPMON->vecTransformedSize.y / 2.f); // move workspaces - std::deque<CWorkspace*> wspToMove; + std::deque<PHLWORKSPACE> wspToMove; for (auto& w : g_pCompositor->m_vWorkspaces) { if (w->m_iMonitorID == ID || !g_pCompositor->getMonitorFromID(w->m_iMonitorID)) { - wspToMove.push_back(w.get()); + wspToMove.push_back(w); } } @@ -299,7 +299,7 @@ void CMonitor::onDisconnect(bool destroy) { g_pCompositor->m_pLastMonitor = nullptr; } - activeWorkspace = -1; + activeWorkspace.reset(); if (!destroy) wlr_output_layout_remove(g_pCompositor->m_sWLROutputLayout, output); @@ -403,17 +403,17 @@ void CMonitor::setupDefaultWS(const SMonitorRule& monitorRule) { if (PNEWWORKSPACE) { // workspace exists, move it to the newly connected monitor g_pCompositor->moveWorkspaceToMonitor(PNEWWORKSPACE, this); - activeWorkspace = PNEWWORKSPACE->m_iID; + activeWorkspace = PNEWWORKSPACE; g_pLayoutManager->getCurrentLayout()->recalculateMonitor(ID); PNEWWORKSPACE->startAnim(true, true, true); } else { if (newDefaultWorkspaceName == "") newDefaultWorkspaceName = std::to_string(WORKSPACEID); - PNEWWORKSPACE = g_pCompositor->m_vWorkspaces.emplace_back(std::make_unique<CWorkspace>(WORKSPACEID, ID, newDefaultWorkspaceName)).get(); + PNEWWORKSPACE = g_pCompositor->m_vWorkspaces.emplace_back(CWorkspace::create(WORKSPACEID, ID, newDefaultWorkspaceName)); } - activeWorkspace = PNEWWORKSPACE->m_iID; + activeWorkspace = PNEWWORKSPACE; PNEWWORKSPACE->setActive(true); PNEWWORKSPACE->m_szLastMonitor = ""; @@ -481,10 +481,10 @@ void CMonitor::setMirror(const std::string& mirrorOf) { } // move all the WS - std::deque<CWorkspace*> wspToMove; + std::deque<PHLWORKSPACE> wspToMove; for (auto& w : g_pCompositor->m_vWorkspaces) { if (w->m_iMonitorID == ID) { - wspToMove.push_back(w.get()); + wspToMove.push_back(w); } } @@ -493,7 +493,7 @@ void CMonitor::setMirror(const std::string& mirrorOf) { w->startAnim(true, true, true); } - activeWorkspace = -1; + activeWorkspace.reset(); wlr_output_layout_remove(g_pCompositor->m_sWLROutputLayout, output); @@ -532,24 +532,24 @@ float CMonitor::getDefaultScale() { return 1; } -void CMonitor::changeWorkspace(CWorkspace* const pWorkspace, bool internal, bool noMouseMove, bool noFocus) { +void CMonitor::changeWorkspace(const PHLWORKSPACE& pWorkspace, bool internal, bool noMouseMove, bool noFocus) { if (!pWorkspace) return; if (pWorkspace->m_bIsSpecialWorkspace) { - if (specialWorkspaceID != pWorkspace->m_iID) { + if (activeSpecialWorkspace != pWorkspace) { Debug::log(LOG, "changeworkspace on special, togglespecialworkspace to id {}", pWorkspace->m_iID); g_pKeybindManager->m_mDispatchers["togglespecialworkspace"](pWorkspace->m_szName == "special" ? "" : pWorkspace->m_szName); } return; } - if (pWorkspace->m_iID == activeWorkspace) + if (pWorkspace == activeWorkspace) return; - const auto POLDWORKSPACE = g_pCompositor->getWorkspaceByID(activeWorkspace); + const auto POLDWORKSPACE = activeWorkspace; - activeWorkspace = pWorkspace->m_iID; + activeWorkspace = pWorkspace; if (!internal) { const auto ANIMTOLEFT = pWorkspace->m_iID > POLDWORKSPACE->m_iID; @@ -558,12 +558,11 @@ void CMonitor::changeWorkspace(CWorkspace* const pWorkspace, bool internal, bool // move pinned windows for (auto& w : g_pCompositor->m_vWindows) { - if (w->m_iWorkspaceID == POLDWORKSPACE->m_iID && w->m_bPinned) { - w->m_iWorkspaceID = pWorkspace->m_iID; - } + if (w->m_pWorkspace == POLDWORKSPACE && w->m_bPinned) + w->moveToWorkspace(pWorkspace); } - if (!noFocus && !g_pCompositor->m_pLastMonitor->specialWorkspaceID) { + if (!noFocus && !g_pCompositor->m_pLastMonitor->activeSpecialWorkspace) { static auto PFOLLOWMOUSE = CConfigValue<Hyprlang::INT>("input:follow_mouse"); CWindow* pWindow = pWorkspace->getLastFocusedWindow(); @@ -599,37 +598,33 @@ void CMonitor::changeWorkspace(CWorkspace* const pWorkspace, bool internal, bool g_pCompositor->updateSuspendedStates(); - if (specialWorkspaceID) { - const auto PSPECIALWS = g_pCompositor->getWorkspaceByID(specialWorkspaceID); - if (PSPECIALWS->m_bHasFullscreenWindow) - g_pCompositor->updateFullscreenFadeOnWorkspace(PSPECIALWS); - } + if (activeSpecialWorkspace) + g_pCompositor->updateFullscreenFadeOnWorkspace(activeSpecialWorkspace); } void CMonitor::changeWorkspace(const int& id, bool internal, bool noMouseMove, bool noFocus) { changeWorkspace(g_pCompositor->getWorkspaceByID(id), internal, noMouseMove, noFocus); } -void CMonitor::setSpecialWorkspace(CWorkspace* const pWorkspace) { +void CMonitor::setSpecialWorkspace(const PHLWORKSPACE& pWorkspace) { g_pHyprRenderer->damageMonitor(this); if (!pWorkspace) { // remove special if exists - if (const auto EXISTINGSPECIAL = g_pCompositor->getWorkspaceByID(specialWorkspaceID); EXISTINGSPECIAL) { - EXISTINGSPECIAL->startAnim(false, false); + if (activeSpecialWorkspace) { + activeSpecialWorkspace->startAnim(false, false); g_pEventManager->postEvent(SHyprIPCEvent{"activespecial", "," + szName}); } - specialWorkspaceID = 0; + activeSpecialWorkspace.reset(); g_pLayoutManager->getCurrentLayout()->recalculateMonitor(ID); - const auto PWORKSPACE = g_pCompositor->getWorkspaceByID(activeWorkspace); - if (const auto PLAST = PWORKSPACE->getLastFocusedWindow(); PLAST) + if (const auto PLAST = activeWorkspace->getLastFocusedWindow(); PLAST) g_pCompositor->focusWindow(PLAST); else g_pInputManager->refocus(); - g_pCompositor->updateFullscreenFadeOnWorkspace(PWORKSPACE); + g_pCompositor->updateFullscreenFadeOnWorkspace(activeWorkspace); g_pConfigManager->ensureVRR(this); @@ -638,20 +633,18 @@ void CMonitor::setSpecialWorkspace(CWorkspace* const pWorkspace) { return; } - if (specialWorkspaceID) { - if (const auto EXISTINGSPECIAL = g_pCompositor->getWorkspaceByID(specialWorkspaceID); EXISTINGSPECIAL) - EXISTINGSPECIAL->startAnim(false, false); - } + if (activeSpecialWorkspace) + activeSpecialWorkspace->startAnim(false, false); bool animate = true; //close if open elsewhere const auto PMONITORWORKSPACEOWNER = g_pCompositor->getMonitorFromID(pWorkspace->m_iMonitorID); - if (PMONITORWORKSPACEOWNER->specialWorkspaceID == pWorkspace->m_iID) { - PMONITORWORKSPACEOWNER->specialWorkspaceID = 0; + if (PMONITORWORKSPACEOWNER->activeSpecialWorkspace == pWorkspace) { + PMONITORWORKSPACEOWNER->activeSpecialWorkspace.reset(); g_pLayoutManager->getCurrentLayout()->recalculateMonitor(PMONITORWORKSPACEOWNER->ID); g_pEventManager->postEvent(SHyprIPCEvent{"activespecial", "," + PMONITORWORKSPACEOWNER->szName}); - const auto PACTIVEWORKSPACE = g_pCompositor->getWorkspaceByID(PMONITORWORKSPACEOWNER->activeWorkspace); + const auto PACTIVEWORKSPACE = PMONITORWORKSPACEOWNER->activeWorkspace; g_pCompositor->updateFullscreenFadeOnWorkspace(PACTIVEWORKSPACE); animate = false; @@ -659,12 +652,12 @@ void CMonitor::setSpecialWorkspace(CWorkspace* const pWorkspace) { // open special pWorkspace->m_iMonitorID = ID; - specialWorkspaceID = pWorkspace->m_iID; + activeSpecialWorkspace = pWorkspace; if (animate) pWorkspace->startAnim(true, true); for (auto& w : g_pCompositor->m_vWindows) { - if (w->m_iWorkspaceID == pWorkspace->m_iID) { + if (w->m_pWorkspace == pWorkspace) { w->m_iMonitorID = ID; w->updateSurfaceScaleTransformDetails(); w->setAnimationsToMove(); @@ -729,6 +722,13 @@ void CMonitor::updateMatrix() { } } + int64_t CMonitor::activeWorkspaceID() { + return activeWorkspace ? activeWorkspace->m_iID : 0; + } + int64_t CMonitor::activeSpecialWorkspaceID() { + return activeSpecialWorkspace ? activeSpecialWorkspace->m_iID : 0; + } + CMonitorState::CMonitorState(CMonitor* owner) { m_pOwner = owner; wlr_output_state_init(&m_state); diff --git a/src/helpers/Monitor.hpp b/src/helpers/Monitor.hpp index 051c5305..69806055 100644 --- a/src/helpers/Monitor.hpp +++ b/src/helpers/Monitor.hpp @@ -57,10 +57,11 @@ class CMonitor { bool primary = false; - uint64_t ID = -1; - int activeWorkspace = -1; - float setScale = 1; // scale set by cfg - float scale = 1; // real scale + uint64_t ID = -1; + PHLWORKSPACE activeWorkspace = nullptr; + PHLWORKSPACE activeSpecialWorkspace = nullptr; + float setScale = 1; // scale set by cfg + float scale = 1; // real scale std::string szName = ""; std::string szDescription = ""; @@ -119,9 +120,6 @@ class CMonitor { bool frameScheduledWhileBusy = false; } tearingState; - // for the special workspace. 0 means not open. - int specialWorkspaceID = 0; - std::array<std::vector<std::unique_ptr<SLayerSurface>>, 4> m_aLayerSurfaceLayers; DYNLISTENER(monitorFrame); @@ -142,13 +140,15 @@ class CMonitor { bool isMirror(); bool matchesStaticSelector(const std::string& selector) const; float getDefaultScale(); - void changeWorkspace(CWorkspace* const pWorkspace, bool internal = false, bool noMouseMove = false, bool noFocus = false); + void changeWorkspace(const PHLWORKSPACE& pWorkspace, bool internal = false, bool noMouseMove = false, bool noFocus = false); void changeWorkspace(const int& id, bool internal = false, bool noMouseMove = false, bool noFocus = false); - void setSpecialWorkspace(CWorkspace* const pWorkspace); + void setSpecialWorkspace(const PHLWORKSPACE& pWorkspace); void setSpecialWorkspace(const int& id); void moveTo(const Vector2D& pos); Vector2D middle(); void updateMatrix(); + int64_t activeWorkspaceID(); + int64_t activeSpecialWorkspaceID(); bool m_bEnabled = false; bool m_bRenderingInitPassed = false; diff --git a/src/helpers/WLClasses.hpp b/src/helpers/WLClasses.hpp index f1311e42..bad290e6 100644 --- a/src/helpers/WLClasses.hpp +++ b/src/helpers/WLClasses.hpp @@ -280,16 +280,16 @@ struct SIdleInhibitor { }; struct SSwipeGesture { - CWorkspace* pWorkspaceBegin = nullptr; + PHLWORKSPACE pWorkspaceBegin = nullptr; - double delta = 0; + double delta = 0; - int initialDirection = 0; - float avgSpeed = 0; - int speedPoints = 0; - int touch_id = 0; + int initialDirection = 0; + float avgSpeed = 0; + int speedPoints = 0; + int touch_id = 0; - CMonitor* pMonitor = nullptr; + CMonitor* pMonitor = nullptr; }; struct SIMEKbGrab { |