diff options
| author | Vaxry <43317083+vaxerski@users.noreply.github.com> | 2024-04-02 20:32:39 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-04-02 20:32:39 +0100 |
| commit | ef23ef60c5641c5903f9cf40571ead7ad6aba1b9 (patch) | |
| tree | 2eece29849bf25d7710edd9cee5d12186a9253fc /src/layout | |
| parent | fc0a7af7ba5c52f7a70309020f5cb27c19d068e6 (diff) | |
Workspace/core: Refactor workspace storage (#5380)
* refactor workspaces to use ptrs
* clang-format
Diffstat (limited to 'src/layout')
| -rw-r--r-- | src/layout/DwindleLayout.cpp | 53 | ||||
| -rw-r--r-- | src/layout/DwindleLayout.hpp | 2 | ||||
| -rw-r--r-- | src/layout/IHyprLayout.cpp | 22 | ||||
| -rw-r--r-- | src/layout/MasterLayout.cpp | 116 | ||||
| -rw-r--r-- | src/layout/MasterLayout.hpp | 2 |
5 files changed, 92 insertions, 103 deletions
diff --git a/src/layout/DwindleLayout.cpp b/src/layout/DwindleLayout.cpp index 93f60e3f..67390010 100644 --- a/src/layout/DwindleLayout.cpp +++ b/src/layout/DwindleLayout.cpp @@ -105,7 +105,7 @@ void CHyprDwindleLayout::applyNodeDataToWindow(SDwindleNodeData* pNode, bool for if (g_pCompositor->isWorkspaceSpecial(pNode->workspaceID)) { for (auto& m : g_pCompositor->m_vMonitors) { - if (m->specialWorkspaceID == pNode->workspaceID) { + if (m->activeSpecialWorkspaceID() == pNode->workspaceID) { PMONITOR = m.get(); break; } @@ -162,10 +162,10 @@ void CHyprDwindleLayout::applyNodeDataToWindow(SDwindleNodeData* pNode, bool for PWINDOW->m_vSize = nodeBox.size(); PWINDOW->m_vPosition = nodeBox.pos(); - const auto NODESONWORKSPACE = getNodesOnWorkspace(PWINDOW->m_iWorkspaceID); + const auto NODESONWORKSPACE = getNodesOnWorkspace(PWINDOW->workspaceID()); - if (*PNOGAPSWHENONLY && !g_pCompositor->isWorkspaceSpecial(PWINDOW->m_iWorkspaceID) && - (NODESONWORKSPACE == 1 || (PWINDOW->m_bIsFullscreen && g_pCompositor->getWorkspaceByID(PWINDOW->m_iWorkspaceID)->m_efFullscreenMode == FULLSCREEN_MAXIMIZED))) { + if (*PNOGAPSWHENONLY && !PWINDOW->onSpecialWorkspace() && + (NODESONWORKSPACE == 1 || (PWINDOW->m_bIsFullscreen && PWINDOW->m_pWorkspace->m_efFullscreenMode == FULLSCREEN_MAXIMIZED))) { PWINDOW->m_sSpecialRenderData.rounding = false; PWINDOW->m_sSpecialRenderData.shadow = false; @@ -229,7 +229,7 @@ void CHyprDwindleLayout::applyNodeDataToWindow(SDwindleNodeData* pNode, bool for calcPos = calcPos + RESERVED.topLeft; calcSize = calcSize - (RESERVED.topLeft + RESERVED.bottomRight); - if (g_pCompositor->isWorkspaceSpecial(PWINDOW->m_iWorkspaceID) && !PWINDOW->m_bIsFullscreen) { + if (PWINDOW->onSpecialWorkspace() && !PWINDOW->m_bIsFullscreen) { // if special, we adjust the coords a bit static auto PSCALEFACTOR = CConfigValue<Hyprlang::FLOAT>("dwindle:special_scale_factor"); @@ -278,7 +278,7 @@ void CHyprDwindleLayout::onWindowCreatedTiling(CWindow* pWindow, eDirection dire overrideDirection = direction; // Populate the node with our window's data - PNODE->workspaceID = pWindow->m_iWorkspaceID; + PNODE->workspaceID = pWindow->workspaceID(); PNODE->pWindow = pWindow; PNODE->isNode = false; PNODE->layout = this; @@ -289,7 +289,7 @@ void CHyprDwindleLayout::onWindowCreatedTiling(CWindow* pWindow, eDirection dire const auto MONFROMCURSOR = g_pCompositor->getMonitorFromVector(MOUSECOORDS); if (PMONITOR->ID == MONFROMCURSOR->ID && - (PNODE->workspaceID == PMONITOR->activeWorkspace || (g_pCompositor->isWorkspaceSpecial(PNODE->workspaceID) && PMONITOR->specialWorkspaceID)) && !*PUSEACTIVE) { + (PNODE->workspaceID == PMONITOR->activeWorkspaceID() || (g_pCompositor->isWorkspaceSpecial(PNODE->workspaceID) && PMONITOR->activeSpecialWorkspace)) && !*PUSEACTIVE) { OPENINGON = getNodeFromWindow(g_pCompositor->vectorToWindowUnified(MOUSECOORDS, RESERVED_EXTENTS | INPUT_EXTENTS)); if (!OPENINGON && g_pCompositor->isPointOnReservedArea(MOUSECOORDS, PMONITOR)) @@ -297,7 +297,7 @@ void CHyprDwindleLayout::onWindowCreatedTiling(CWindow* pWindow, eDirection dire } else if (*PUSEACTIVE) { if (g_pCompositor->m_pLastWindow && !g_pCompositor->m_pLastWindow->m_bIsFloating && g_pCompositor->m_pLastWindow != pWindow && - g_pCompositor->m_pLastWindow->m_iWorkspaceID == pWindow->m_iWorkspaceID && g_pCompositor->m_pLastWindow->m_bIsMapped) { + g_pCompositor->m_pLastWindow->m_pWorkspace == pWindow->m_pWorkspace && g_pCompositor->m_pLastWindow->m_bIsMapped) { OPENINGON = getNodeFromWindow(g_pCompositor->m_pLastWindow); } else { OPENINGON = getNodeFromWindow(g_pCompositor->vectorToWindowUnified(MOUSECOORDS, RESERVED_EXTENTS | INPUT_EXTENTS)); @@ -307,7 +307,7 @@ void CHyprDwindleLayout::onWindowCreatedTiling(CWindow* pWindow, eDirection dire OPENINGON = getClosestNodeOnWorkspace(PNODE->workspaceID, MOUSECOORDS); } else - OPENINGON = getFirstNodeOnWorkspace(pWindow->m_iWorkspaceID); + OPENINGON = getFirstNodeOnWorkspace(pWindow->workspaceID()); Debug::log(LOG, "OPENINGON: {}, Monitor: {}", OPENINGON, PMONITOR->ID); @@ -551,40 +551,35 @@ void CHyprDwindleLayout::onWindowRemovedTiling(CWindow* pWindow) { void CHyprDwindleLayout::recalculateMonitor(const int& monid) { const auto PMONITOR = g_pCompositor->getMonitorFromID(monid); - if (!PMONITOR) + if (!PMONITOR || !PMONITOR->activeWorkspace) return; // ??? g_pHyprRenderer->damageMonitor(PMONITOR); - if (PMONITOR->specialWorkspaceID) - calculateWorkspace(PMONITOR->specialWorkspaceID); + if (PMONITOR->activeSpecialWorkspace) + calculateWorkspace(PMONITOR->activeSpecialWorkspace); calculateWorkspace(PMONITOR->activeWorkspace); } -void CHyprDwindleLayout::calculateWorkspace(const int& ws) { - const auto PWORKSPACE = g_pCompositor->getWorkspaceByID(ws); - - if (!PWORKSPACE) - return; - - const auto PMONITOR = g_pCompositor->getMonitorFromID(PWORKSPACE->m_iMonitorID); +void CHyprDwindleLayout::calculateWorkspace(const PHLWORKSPACE& pWorkspace) { + const auto PMONITOR = g_pCompositor->getMonitorFromID(pWorkspace->m_iMonitorID); if (!PMONITOR) return; - if (PWORKSPACE->m_bHasFullscreenWindow) { + if (pWorkspace->m_bHasFullscreenWindow) { // massive hack from the fullscreen func - const auto PFULLWINDOW = g_pCompositor->getFullscreenWindowOnWorkspace(PWORKSPACE->m_iID); + const auto PFULLWINDOW = g_pCompositor->getFullscreenWindowOnWorkspace(pWorkspace->m_iID); - if (PWORKSPACE->m_efFullscreenMode == FULLSCREEN_FULL) { + if (pWorkspace->m_efFullscreenMode == FULLSCREEN_FULL) { PFULLWINDOW->m_vRealPosition = PMONITOR->vecPosition; PFULLWINDOW->m_vRealSize = PMONITOR->vecSize; - } else if (PWORKSPACE->m_efFullscreenMode == FULLSCREEN_MAXIMIZED) { + } else if (pWorkspace->m_efFullscreenMode == FULLSCREEN_MAXIMIZED) { SDwindleNodeData fakeNode; fakeNode.pWindow = PFULLWINDOW; fakeNode.box = {PMONITOR->vecPosition + PMONITOR->vecReservedTopLeft, PMONITOR->vecSize - PMONITOR->vecReservedTopLeft - PMONITOR->vecReservedBottomRight}; - fakeNode.workspaceID = PWORKSPACE->m_iID; + fakeNode.workspaceID = pWorkspace->m_iID; PFULLWINDOW->m_vPosition = fakeNode.box.pos(); PFULLWINDOW->m_vSize = fakeNode.box.size(); fakeNode.ignoreFullscreenChecks = true; @@ -596,7 +591,7 @@ void CHyprDwindleLayout::calculateWorkspace(const int& ws) { return; } - const auto TOPNODE = getMasterNodeOnWorkspace(ws); + const auto TOPNODE = getMasterNodeOnWorkspace(pWorkspace->m_iID); if (TOPNODE) { TOPNODE->box = {PMONITOR->vecPosition + PMONITOR->vecReservedTopLeft, PMONITOR->vecSize - PMONITOR->vecReservedTopLeft - PMONITOR->vecReservedBottomRight}; @@ -813,7 +808,7 @@ void CHyprDwindleLayout::fullscreenRequestForWindow(CWindow* pWindow, eFullscree return; // ignore const auto PMONITOR = g_pCompositor->getMonitorFromID(pWindow->m_iMonitorID); - const auto PWORKSPACE = g_pCompositor->getWorkspaceByID(pWindow->m_iWorkspaceID); + const auto PWORKSPACE = pWindow->m_pWorkspace; if (PWORKSPACE->m_bHasFullscreenWindow && on) { // if the window wants to be fullscreen but there already is one, @@ -868,7 +863,7 @@ void CHyprDwindleLayout::fullscreenRequestForWindow(CWindow* pWindow, eFullscree SDwindleNodeData fakeNode; fakeNode.pWindow = pWindow; fakeNode.box = {PMONITOR->vecPosition + PMONITOR->vecReservedTopLeft, PMONITOR->vecSize - PMONITOR->vecReservedTopLeft - PMONITOR->vecReservedBottomRight}; - fakeNode.workspaceID = pWindow->m_iWorkspaceID; + fakeNode.workspaceID = pWindow->workspaceID(); pWindow->m_vPosition = fakeNode.box.pos(); pWindow->m_vSize = fakeNode.box.size(); fakeNode.ignoreFullscreenChecks = true; @@ -981,7 +976,7 @@ void CHyprDwindleLayout::switchWindows(CWindow* pWindow, CWindow* pWindow2) { if (PNODE->workspaceID != PNODE2->workspaceID) { std::swap(pWindow2->m_iMonitorID, pWindow->m_iMonitorID); - std::swap(pWindow2->m_iWorkspaceID, pWindow->m_iWorkspaceID); + std::swap(pWindow2->m_pWorkspace, pWindow->m_pWorkspace); } pWindow->setAnimationsToMove(); @@ -1137,7 +1132,7 @@ Vector2D CHyprDwindleLayout::predictSizeForNewWindowTiled() { CWindow* candidate = g_pCompositor->m_pLastWindow; if (!candidate) - candidate = g_pCompositor->getFirstWindowOnWorkspace(g_pCompositor->m_pLastMonitor->activeWorkspace); + candidate = g_pCompositor->getFirstWindowOnWorkspace(g_pCompositor->m_pLastMonitor->activeWorkspace->m_iID); // create a fake node SDwindleNodeData node; diff --git a/src/layout/DwindleLayout.hpp b/src/layout/DwindleLayout.hpp index b8c752f4..30c6e74a 100644 --- a/src/layout/DwindleLayout.hpp +++ b/src/layout/DwindleLayout.hpp @@ -78,7 +78,7 @@ class CHyprDwindleLayout : public IHyprLayout { int getNodesOnWorkspace(const int&); void applyNodeDataToWindow(SDwindleNodeData*, bool force = false); - void calculateWorkspace(const int& ws); + void calculateWorkspace(const PHLWORKSPACE& pWorkspace); SDwindleNodeData* getNodeFromWindow(CWindow*); SDwindleNodeData* getFirstNodeOnWorkspace(const int&); SDwindleNodeData* getClosestNodeOnWorkspace(const int&, const Vector2D&); diff --git a/src/layout/IHyprLayout.cpp b/src/layout/IHyprLayout.cpp index 1570fd73..3648faee 100644 --- a/src/layout/IHyprLayout.cpp +++ b/src/layout/IHyprLayout.cpp @@ -189,7 +189,7 @@ void IHyprLayout::onBeginDragWindow() { g_pCompositor->setWindowFullscreen(DRAGGINGWINDOW, false, FULLSCREEN_FULL); } - const auto PWORKSPACE = g_pCompositor->getWorkspaceByID(DRAGGINGWINDOW->m_iWorkspaceID); + const auto PWORKSPACE = DRAGGINGWINDOW->m_pWorkspace; if (PWORKSPACE->m_bHasFullscreenWindow && (!DRAGGINGWINDOW->m_bCreatedOverFullscreen || !DRAGGINGWINDOW->m_bIsFloating)) { Debug::log(LOG, "Rejecting drag on a fullscreen workspace. (window under fullscreen)"); @@ -329,7 +329,7 @@ void IHyprLayout::onMouseMove(const Vector2D& mousePos) { static auto TIMER = std::chrono::high_resolution_clock::now(), MSTIMER = TIMER; - const auto SPECIAL = g_pCompositor->isWorkspaceSpecial(DRAGGINGWINDOW->m_iWorkspaceID); + const auto SPECIAL = DRAGGINGWINDOW->onSpecialWorkspace(); const auto DELTA = Vector2D(mousePos.x - m_vBeginDragXY.x, mousePos.y - m_vBeginDragXY.y); const auto TICKDELTA = Vector2D(mousePos.x - m_vLastDragXY.x, mousePos.y - m_vLastDragXY.y); @@ -479,10 +479,10 @@ void IHyprLayout::changeWindowFloatingMode(CWindow* pWindow) { if (!TILED) { const auto PNEWMON = g_pCompositor->getMonitorFromVector(pWindow->m_vRealPosition.value() + pWindow->m_vRealSize.value() / 2.f); pWindow->m_iMonitorID = PNEWMON->ID; - pWindow->moveToWorkspace(PNEWMON->specialWorkspaceID != 0 ? PNEWMON->specialWorkspaceID : PNEWMON->activeWorkspace); + pWindow->moveToWorkspace(PNEWMON->activeSpecialWorkspace ? PNEWMON->activeSpecialWorkspace : PNEWMON->activeWorkspace); pWindow->updateGroupOutputs(); - const auto PWORKSPACE = g_pCompositor->getWorkspaceByID(PNEWMON->specialWorkspaceID != 0 ? PNEWMON->specialWorkspaceID : PNEWMON->activeWorkspace); + const auto PWORKSPACE = PNEWMON->activeSpecialWorkspace ? PNEWMON->activeSpecialWorkspace : PNEWMON->activeWorkspace; if (PWORKSPACE->m_bHasFullscreenWindow) g_pCompositor->setWindowFullscreen(g_pCompositor->getFullscreenWindowOnWorkspace(PWORKSPACE->m_iID), false); @@ -569,17 +569,17 @@ CWindow* IHyprLayout::getNextWindowCandidate(CWindow* pWindow) { if (!pWindow) return nullptr; - const auto PWORKSPACE = g_pCompositor->getWorkspaceByID(pWindow->m_iWorkspaceID); + const auto PWORKSPACE = pWindow->m_pWorkspace; // first of all, if this is a fullscreen workspace, if (PWORKSPACE->m_bHasFullscreenWindow) - return g_pCompositor->getFullscreenWindowOnWorkspace(pWindow->m_iWorkspaceID); + return g_pCompositor->getFullscreenWindowOnWorkspace(pWindow->workspaceID()); if (pWindow->m_bIsFloating) { // find whether there is a floating window below this one for (auto& w : g_pCompositor->m_vWindows) { - if (w->m_bIsMapped && !w->isHidden() && w->m_bIsFloating && w->m_iX11Type != 2 && w->m_iWorkspaceID == pWindow->m_iWorkspaceID && !w->m_bX11ShouldntFocus && + if (w->m_bIsMapped && !w->isHidden() && w->m_bIsFloating && w->m_iX11Type != 2 && w->m_pWorkspace == pWindow->m_pWorkspace && !w->m_bX11ShouldntFocus && !w->m_sAdditionalConfigData.noFocus && w.get() != pWindow) { if (VECINRECT((pWindow->m_vSize / 2.f + pWindow->m_vPosition), w->m_vPosition.x, w->m_vPosition.y, w->m_vPosition.x + w->m_vSize.x, w->m_vPosition.y + w->m_vSize.y)) { @@ -589,7 +589,7 @@ CWindow* IHyprLayout::getNextWindowCandidate(CWindow* pWindow) { } // let's try the last tiled window. - if (m_pLastTiledWindow && m_pLastTiledWindow->m_iWorkspaceID == pWindow->m_iWorkspaceID) + if (m_pLastTiledWindow && m_pLastTiledWindow->m_pWorkspace == pWindow->m_pWorkspace) return m_pLastTiledWindow; // if we don't, let's try to find any window that is in the middle @@ -599,7 +599,7 @@ CWindow* IHyprLayout::getNextWindowCandidate(CWindow* pWindow) { // if not, floating window for (auto& w : g_pCompositor->m_vWindows) { - if (w->m_bIsMapped && !w->isHidden() && w->m_bIsFloating && w->m_iX11Type != 2 && w->m_iWorkspaceID == pWindow->m_iWorkspaceID && !w->m_bX11ShouldntFocus && + if (w->m_bIsMapped && !w->isHidden() && w->m_bIsFloating && w->m_iX11Type != 2 && w->m_pWorkspace == pWindow->m_pWorkspace && !w->m_bX11ShouldntFocus && !w->m_sAdditionalConfigData.noFocus && w.get() != pWindow) return w.get(); } @@ -612,10 +612,10 @@ CWindow* IHyprLayout::getNextWindowCandidate(CWindow* pWindow) { auto pWindowCandidate = g_pCompositor->vectorToWindowUnified(pWindow->middle(), RESERVED_EXTENTS | INPUT_EXTENTS | ALLOW_FLOATING); if (!pWindowCandidate) - pWindowCandidate = g_pCompositor->getTopLeftWindowOnWorkspace(pWindow->m_iWorkspaceID); + pWindowCandidate = g_pCompositor->getTopLeftWindowOnWorkspace(pWindow->workspaceID()); if (!pWindowCandidate) - pWindowCandidate = g_pCompositor->getFirstWindowOnWorkspace(pWindow->m_iWorkspaceID); + pWindowCandidate = g_pCompositor->getFirstWindowOnWorkspace(pWindow->workspaceID()); if (!pWindowCandidate || pWindow == pWindowCandidate || !pWindowCandidate->m_bIsMapped || pWindowCandidate->isHidden() || pWindowCandidate->m_bX11ShouldntFocus || pWindowCandidate->m_iX11Type == 2 || pWindowCandidate->m_iMonitorID != g_pCompositor->m_pLastMonitor->ID) diff --git a/src/layout/MasterLayout.cpp b/src/layout/MasterLayout.cpp index 375840fb..2066ca76 100644 --- a/src/layout/MasterLayout.cpp +++ b/src/layout/MasterLayout.cpp @@ -90,7 +90,7 @@ void CHyprMasterLayout::onWindowCreatedTiling(CWindow* pWindow, eDirection direc const auto PNODE = *PNEWTOP ? &m_lMasterNodesData.emplace_front() : &m_lMasterNodesData.emplace_back(); - PNODE->workspaceID = pWindow->m_iWorkspaceID; + PNODE->workspaceID = pWindow->workspaceID(); PNODE->pWindow = pWindow; static auto PNEWISMASTER = CConfigValue<Hyprlang::INT>("master:new_is_master"); @@ -99,9 +99,9 @@ void CHyprMasterLayout::onWindowCreatedTiling(CWindow* pWindow, eDirection direc static auto PMFACT = CConfigValue<Hyprlang::FLOAT>("master:mfact"); float lastSplitPercent = *PMFACT; - auto OPENINGON = isWindowTiled(g_pCompositor->m_pLastWindow) && g_pCompositor->m_pLastWindow->m_iWorkspaceID == pWindow->m_iWorkspaceID ? + auto OPENINGON = isWindowTiled(g_pCompositor->m_pLastWindow) && g_pCompositor->m_pLastWindow->m_pWorkspace == pWindow->m_pWorkspace ? getNodeFromWindow(g_pCompositor->m_pLastWindow) : - getMasterNodeOnWorkspace(pWindow->m_iWorkspaceID); + getMasterNodeOnWorkspace(pWindow->workspaceID()); const auto MOUSECOORDS = g_pInputManager->getMouseCoordsInternal(); @@ -133,7 +133,7 @@ void CHyprMasterLayout::onWindowCreatedTiling(CWindow* pWindow, eDirection direc pWindow->applyGroupRules(); static auto PDROPATCURSOR = CConfigValue<Hyprlang::INT>("master:drop_at_cursor"); - const auto PWORKSPACEDATA = getMasterWorkspaceData(pWindow->m_iWorkspaceID); + const auto PWORKSPACEDATA = getMasterWorkspaceData(pWindow->workspaceID()); eOrientation orientation = PWORKSPACEDATA->orientation; const auto NODEIT = std::find(m_lMasterNodesData.begin(), m_lMasterNodesData.end(), *PNODE); @@ -142,7 +142,7 @@ void CHyprMasterLayout::onWindowCreatedTiling(CWindow* pWindow, eDirection direc if (*PDROPATCURSOR && g_pInputManager->dragMode == MBIND_MOVE) { if (WINDOWSONWORKSPACE > 2) { for (auto it = m_lMasterNodesData.begin(); it != m_lMasterNodesData.end(); ++it) { - if (it->workspaceID != pWindow->m_iWorkspaceID) + if (it->workspaceID != pWindow->workspaceID()) continue; const CBox box = it->pWindow->getWindowIdealBoundingBoxIgnoreReserved(); if (box.containsPoint(MOUSECOORDS)) { @@ -286,41 +286,36 @@ void CHyprMasterLayout::onWindowRemovedTiling(CWindow* pWindow) { void CHyprMasterLayout::recalculateMonitor(const int& monid) { const auto PMONITOR = g_pCompositor->getMonitorFromID(monid); - if (!PMONITOR) + if (!PMONITOR || !PMONITOR->activeWorkspace) return; g_pHyprRenderer->damageMonitor(PMONITOR); - if (PMONITOR->specialWorkspaceID) - calculateWorkspace(PMONITOR->specialWorkspaceID); + if (PMONITOR->activeSpecialWorkspace) + calculateWorkspace(PMONITOR->activeSpecialWorkspace); calculateWorkspace(PMONITOR->activeWorkspace); } -void CHyprMasterLayout::calculateWorkspace(const int& ws) { - const auto PWORKSPACE = g_pCompositor->getWorkspaceByID(ws); - - if (!PWORKSPACE) - return; - - const auto PMONITOR = g_pCompositor->getMonitorFromID(PWORKSPACE->m_iMonitorID); +void CHyprMasterLayout::calculateWorkspace(PHLWORKSPACE pWorkspace) { + const auto PMONITOR = g_pCompositor->getMonitorFromID(pWorkspace->m_iMonitorID); if (!PMONITOR) return; - if (PWORKSPACE->m_bHasFullscreenWindow) { + if (pWorkspace->m_bHasFullscreenWindow) { // massive hack from the fullscreen func - const auto PFULLWINDOW = g_pCompositor->getFullscreenWindowOnWorkspace(PWORKSPACE->m_iID); + const auto PFULLWINDOW = g_pCompositor->getFullscreenWindowOnWorkspace(pWorkspace->m_iID); - if (PWORKSPACE->m_efFullscreenMode == FULLSCREEN_FULL) { + if (pWorkspace->m_efFullscreenMode == FULLSCREEN_FULL) { PFULLWINDOW->m_vRealPosition = PMONITOR->vecPosition; PFULLWINDOW->m_vRealSize = PMONITOR->vecSize; - } else if (PWORKSPACE->m_efFullscreenMode == FULLSCREEN_MAXIMIZED) { + } else if (pWorkspace->m_efFullscreenMode == FULLSCREEN_MAXIMIZED) { SMasterNodeData fakeNode; fakeNode.pWindow = PFULLWINDOW; fakeNode.position = PMONITOR->vecPosition + PMONITOR->vecReservedTopLeft; fakeNode.size = PMONITOR->vecSize - PMONITOR->vecReservedTopLeft - PMONITOR->vecReservedBottomRight; - fakeNode.workspaceID = PWORKSPACE->m_iID; + fakeNode.workspaceID = pWorkspace->m_iID; PFULLWINDOW->m_vPosition = fakeNode.position; PFULLWINDOW->m_vSize = fakeNode.size; fakeNode.ignoreFullscreenChecks = true; @@ -332,14 +327,14 @@ void CHyprMasterLayout::calculateWorkspace(const int& ws) { return; } - const auto PWORKSPACEDATA = getMasterWorkspaceData(ws); - const auto PMASTERNODE = getMasterNodeOnWorkspace(PWORKSPACE->m_iID); + const auto PWORKSPACEDATA = getMasterWorkspaceData(pWorkspace->m_iID); + const auto PMASTERNODE = getMasterNodeOnWorkspace(pWorkspace->m_iID); if (!PMASTERNODE) return; // dynamic workspace rules - const auto WORKSPACERULES = g_pConfigManager->getWorkspaceRulesFor(g_pCompositor->getWorkspaceByID(ws)); + const auto WORKSPACERULES = g_pConfigManager->getWorkspaceRulesFor(pWorkspace); std::string orientationForWs; for (auto& wsRule : WORKSPACERULES) { @@ -363,8 +358,8 @@ void CHyprMasterLayout::calculateWorkspace(const int& ws) { static auto ALWAYSCENTER = CConfigValue<Hyprlang::INT>("master:always_center_master"); static auto PSMARTRESIZING = CConfigValue<Hyprlang::INT>("master:smart_resizing"); - const auto MASTERS = getMastersOnWorkspace(PWORKSPACE->m_iID); - const auto WINDOWS = getNodesOnWorkspace(PWORKSPACE->m_iID); + const auto MASTERS = getMastersOnWorkspace(pWorkspace->m_iID); + const auto WINDOWS = getNodesOnWorkspace(pWorkspace->m_iID); const auto STACKWINDOWS = WINDOWS - MASTERS; const auto WSSIZE = PMONITOR->vecSize - PMONITOR->vecReservedTopLeft - PMONITOR->vecReservedBottomRight; const auto WSPOS = PMONITOR->vecPosition + PMONITOR->vecReservedTopLeft; @@ -387,7 +382,7 @@ void CHyprMasterLayout::calculateWorkspace(const int& ws) { // check the total width and height so that later // if larger/smaller than screen size them down/up for (auto& nd : m_lMasterNodesData) { - if (nd.workspaceID == PWORKSPACE->m_iID) { + if (nd.workspaceID == pWorkspace->m_iID) { if (nd.isMaster) masterAccumulatedSize += totalSize / MASTERS * nd.percSize; else @@ -414,7 +409,7 @@ void CHyprMasterLayout::calculateWorkspace(const int& ws) { nextY = WSSIZE.y - HEIGHT; for (auto& nd : m_lMasterNodesData) { - if (nd.workspaceID != PWORKSPACE->m_iID || !nd.isMaster) + if (nd.workspaceID != pWorkspace->m_iID || !nd.isMaster) continue; float WIDTH = mastersLeft > 1 ? widthLeft / mastersLeft * nd.percSize : widthLeft; @@ -451,7 +446,7 @@ void CHyprMasterLayout::calculateWorkspace(const int& ws) { } for (auto& nd : m_lMasterNodesData) { - if (nd.workspaceID != PWORKSPACE->m_iID || !nd.isMaster) + if (nd.workspaceID != pWorkspace->m_iID || !nd.isMaster) continue; float HEIGHT = mastersLeft > 1 ? heightLeft / mastersLeft * nd.percSize : heightLeft; @@ -488,7 +483,7 @@ void CHyprMasterLayout::calculateWorkspace(const int& ws) { nextY = PMASTERNODE->size.y; for (auto& nd : m_lMasterNodesData) { - if (nd.workspaceID != PWORKSPACE->m_iID || nd.isMaster) + if (nd.workspaceID != pWorkspace->m_iID || nd.isMaster) continue; float WIDTH = slavesLeft > 1 ? widthLeft / slavesLeft * nd.percSize : widthLeft; @@ -518,7 +513,7 @@ void CHyprMasterLayout::calculateWorkspace(const int& ws) { nextX = PMASTERNODE->size.x; for (auto& nd : m_lMasterNodesData) { - if (nd.workspaceID != PWORKSPACE->m_iID || nd.isMaster) + if (nd.workspaceID != pWorkspace->m_iID || nd.isMaster) continue; float HEIGHT = slavesLeft > 1 ? heightLeft / slavesLeft * nd.percSize : heightLeft; @@ -558,7 +553,7 @@ void CHyprMasterLayout::calculateWorkspace(const int& ws) { float slaveAccumulatedHeightR = 0; if (*PSMARTRESIZING) { for (auto& nd : m_lMasterNodesData) { - if (nd.workspaceID != PWORKSPACE->m_iID || nd.isMaster) + if (nd.workspaceID != pWorkspace->m_iID || nd.isMaster) continue; if (onRight) { @@ -572,7 +567,7 @@ void CHyprMasterLayout::calculateWorkspace(const int& ws) { } for (auto& nd : m_lMasterNodesData) { - if (nd.workspaceID != PWORKSPACE->m_iID || nd.isMaster) + if (nd.workspaceID != pWorkspace->m_iID || nd.isMaster) continue; if (onRight) { @@ -625,7 +620,7 @@ void CHyprMasterLayout::applyNodeDataToWindow(SMasterNodeData* pNode) { if (g_pCompositor->isWorkspaceSpecial(pNode->workspaceID)) { for (auto& m : g_pCompositor->m_vMonitors) { - if (m->specialWorkspaceID == pNode->workspaceID) { + if (m->activeSpecialWorkspaceID() == pNode->workspaceID) { PMONITOR = m.get(); break; } @@ -648,7 +643,7 @@ void CHyprMasterLayout::applyNodeDataToWindow(SMasterNodeData* pNode) { const auto PWINDOW = pNode->pWindow; // get specific gaps and rules for this workspace, // if user specified them in config - const auto WORKSPACERULES = g_pConfigManager->getWorkspaceRulesFor(g_pCompositor->getWorkspaceByID(PWINDOW->m_iWorkspaceID)); + const auto WORKSPACERULES = g_pConfigManager->getWorkspaceRulesFor(PWINDOW->m_pWorkspace); if (PWINDOW->m_bIsFullscreen && !pNode->ignoreFullscreenChecks) return; @@ -679,9 +674,8 @@ void CHyprMasterLayout::applyNodeDataToWindow(SMasterNodeData* pNode) { PWINDOW->m_vSize = pNode->size; PWINDOW->m_vPosition = pNode->position; - if (*PNOGAPSWHENONLY && !g_pCompositor->isWorkspaceSpecial(PWINDOW->m_iWorkspaceID) && - (getNodesOnWorkspace(PWINDOW->m_iWorkspaceID) == 1 || - (PWINDOW->m_bIsFullscreen && g_pCompositor->getWorkspaceByID(PWINDOW->m_iWorkspaceID)->m_efFullscreenMode == FULLSCREEN_MAXIMIZED))) { + if (*PNOGAPSWHENONLY && !PWINDOW->onSpecialWorkspace() && + (getNodesOnWorkspace(PWINDOW->workspaceID()) == 1 || (PWINDOW->m_bIsFullscreen && PWINDOW->m_pWorkspace->m_efFullscreenMode == FULLSCREEN_MAXIMIZED))) { PWINDOW->m_sSpecialRenderData.rounding = false; PWINDOW->m_sSpecialRenderData.shadow = false; @@ -721,7 +715,7 @@ void CHyprMasterLayout::applyNodeDataToWindow(SMasterNodeData* pNode) { calcPos = calcPos + RESERVED.topLeft; calcSize = calcSize - (RESERVED.topLeft + RESERVED.bottomRight); - if (g_pCompositor->isWorkspaceSpecial(PWINDOW->m_iWorkspaceID) && !PWINDOW->m_bIsFullscreen) { + if (PWINDOW->onSpecialWorkspace() && !PWINDOW->m_bIsFullscreen) { static auto PSCALEFACTOR = CConfigValue<Hyprlang::FLOAT>("master:special_scale_factor"); CBox wb = {calcPos + (calcSize - calcSize * *PSCALEFACTOR) / 2.f, calcSize * *PSCALEFACTOR}; @@ -772,7 +766,7 @@ void CHyprMasterLayout::resizeActiveWindow(const Vector2D& pixResize, eRectCorne } const auto PMONITOR = g_pCompositor->getMonitorFromID(PWINDOW->m_iMonitorID); - const auto PWORKSPACEDATA = getMasterWorkspaceData(PWINDOW->m_iWorkspaceID); + const auto PWORKSPACEDATA = getMasterWorkspaceData(PWINDOW->workspaceID()); static auto ALWAYSCENTER = CConfigValue<Hyprlang::INT>("master:always_center_master"); static auto PSMARTRESIZING = CConfigValue<Hyprlang::INT>("master:smart_resizing"); @@ -793,7 +787,7 @@ void CHyprMasterLayout::resizeActiveWindow(const Vector2D& pixResize, eRectCorne const auto WINDOWS = getNodesOnWorkspace(PNODE->workspaceID); const auto STACKWINDOWS = WINDOWS - MASTERS; - if (getNodesOnWorkspace(PWINDOW->m_iWorkspaceID) == 1 && !centered) + if (getNodesOnWorkspace(PWINDOW->workspaceID()) == 1 && !centered) return; m_bForceWarps = true; @@ -815,7 +809,7 @@ void CHyprMasterLayout::resizeActiveWindow(const Vector2D& pixResize, eRectCorne default: UNREACHABLE(); } - const auto workspaceIdForResizing = PMONITOR->specialWorkspaceID == 0 ? PMONITOR->activeWorkspace : PMONITOR->specialWorkspaceID; + const auto workspaceIdForResizing = PMONITOR->activeSpecialWorkspace ? PMONITOR->activeWorkspaceID() : PMONITOR->activeSpecialWorkspaceID(); for (auto& n : m_lMasterNodesData) { if (n.isMaster && n.workspaceID == workspaceIdForResizing) n.percMaster = std::clamp(n.percMaster + delta, 0.05, 0.95); @@ -908,7 +902,7 @@ void CHyprMasterLayout::fullscreenRequestForWindow(CWindow* pWindow, eFullscreen return; // ignore const auto PMONITOR = g_pCompositor->getMonitorFromID(pWindow->m_iMonitorID); - const auto PWORKSPACE = g_pCompositor->getWorkspaceByID(pWindow->m_iWorkspaceID); + const auto PWORKSPACE = pWindow->m_pWorkspace; if (PWORKSPACE->m_bHasFullscreenWindow && on) { // if the window wants to be fullscreen but there already is one, @@ -964,7 +958,7 @@ void CHyprMasterLayout::fullscreenRequestForWindow(CWindow* pWindow, eFullscreen fakeNode.pWindow = pWindow; fakeNode.position = PMONITOR->vecPosition + PMONITOR->vecReservedTopLeft; fakeNode.size = PMONITOR->vecSize - PMONITOR->vecReservedTopLeft - PMONITOR->vecReservedBottomRight; - fakeNode.workspaceID = pWindow->m_iWorkspaceID; + fakeNode.workspaceID = pWindow->workspaceID(); pWindow->m_vPosition = fakeNode.position; pWindow->m_vSize = fakeNode.size; fakeNode.ignoreFullscreenChecks = true; @@ -1010,10 +1004,10 @@ void CHyprMasterLayout::moveWindowTo(CWindow* pWindow, const std::string& dir) { pWindow->setAnimationsToMove(); - if (pWindow->m_iWorkspaceID != PWINDOW2->m_iWorkspaceID) { + if (pWindow->m_pWorkspace != PWINDOW2->m_pWorkspace) { // if different monitors, send to monitor onWindowRemovedTiling(pWindow); - pWindow->moveToWorkspace(PWINDOW2->m_iWorkspaceID); + pWindow->moveToWorkspace(PWINDOW2->m_pWorkspace); pWindow->m_iMonitorID = PWINDOW2->m_iMonitorID; const auto pMonitor = g_pCompositor->getMonitorFromID(pWindow->m_iMonitorID); g_pCompositor->setActiveMonitor(pMonitor); @@ -1035,7 +1029,7 @@ void CHyprMasterLayout::switchWindows(CWindow* pWindow, CWindow* pWindow2) { if (PNODE->workspaceID != PNODE2->workspaceID) { std::swap(pWindow2->m_iMonitorID, pWindow->m_iMonitorID); - std::swap(pWindow2->m_iWorkspaceID, pWindow->m_iWorkspaceID); + std::swap(pWindow2->m_pWorkspace, pWindow->m_pWorkspace); } // massive hack: just swap window pointers, lol @@ -1061,7 +1055,7 @@ void CHyprMasterLayout::alterSplitRatio(CWindow* pWindow, float ratio, bool exac if (!PNODE) return; - const auto PMASTER = getMasterNodeOnWorkspace(pWindow->m_iWorkspaceID); + const auto PMASTER = getMasterNodeOnWorkspace(pWindow->workspaceID()); float newRatio = exact ? ratio : PMASTER->percMaster + ratio; PMASTER->percMaster = std::clamp(newRatio, 0.05f, 0.95f); @@ -1097,7 +1091,7 @@ std::any CHyprMasterLayout::layoutMessage(SLayoutMessageHeader header, std::stri return; if (header.pWindow->m_bIsFullscreen) { - const auto PWORKSPACE = g_pCompositor->getWorkspaceByID(header.pWindow->m_iWorkspaceID); + const auto PWORKSPACE = header.pWindow->m_pWorkspace; const auto FSMODE = PWORKSPACE->m_efFullscreenMode; static auto INHERITFULLSCREEN = CConfigValue<Hyprlang::INT>("master:inherit_fullscreen"); g_pCompositor->setWindowFullscreen(header.pWindow, false, FULLSCREEN_FULL); @@ -1137,7 +1131,7 @@ std::any CHyprMasterLayout::layoutMessage(SLayoutMessageHeader header, std::stri if (!isWindowTiled(PWINDOW)) return 0; - const auto PMASTER = getMasterNodeOnWorkspace(PWINDOW->m_iWorkspaceID); + const auto PMASTER = getMasterNodeOnWorkspace(PWINDOW->workspaceID()); if (!PMASTER) return 0; @@ -1175,7 +1169,7 @@ std::any CHyprMasterLayout::layoutMessage(SLayoutMessageHeader header, std::stri if (!PWINDOW) return 0; - const auto PMASTER = getMasterNodeOnWorkspace(PWINDOW->m_iWorkspaceID); + const auto PMASTER = getMasterNodeOnWorkspace(PWINDOW->workspaceID()); if (!PMASTER) return 0; @@ -1252,8 +1246,8 @@ std::any CHyprMasterLayout::layoutMessage(SLayoutMessageHeader header, std::stri const auto PNODE = getNodeFromWindow(header.pWindow); - const auto WINDOWS = getNodesOnWorkspace(header.pWindow->m_iWorkspaceID); - const auto MASTERS = getMastersOnWorkspace(header.pWindow->m_iWorkspaceID); + const auto WINDOWS = getNodesOnWorkspace(header.pWindow->workspaceID()); + const auto MASTERS = getMastersOnWorkspace(header.pWindow->workspaceID()); static auto SMALLSPLIT = CConfigValue<Hyprlang::INT>("master:allow_small_split"); if (MASTERS + 2 > WINDOWS && *SMALLSPLIT == 0) @@ -1263,7 +1257,7 @@ std::any CHyprMasterLayout::layoutMessage(SLayoutMessageHeader header, std::stri if (!PNODE || PNODE->isMaster) { // first non-master node for (auto& n : m_lMasterNodesData) { - if (n.workspaceID == header.pWindow->m_iWorkspaceID && !n.isMaster) { + if (n.workspaceID == header.pWindow->workspaceID() && !n.isMaster) { n.isMaster = true; break; } @@ -1284,8 +1278,8 @@ std::any CHyprMasterLayout::layoutMessage(SLayoutMessageHeader header, std::stri const auto PNODE = getNodeFromWindow(header.pWindow); - const auto WINDOWS = getNodesOnWorkspace(header.pWindow->m_iWorkspaceID); - const auto MASTERS = getMastersOnWorkspace(header.pWindow->m_iWorkspaceID); + const auto WINDOWS = getNodesOnWorkspace(header.pWindow->workspaceID()); + const auto MASTERS = getMastersOnWorkspace(header.pWindow->workspaceID()); if (WINDOWS < 2 || MASTERS < 2) return 0; @@ -1295,7 +1289,7 @@ std::any CHyprMasterLayout::layoutMessage(SLayoutMessageHeader header, std::stri if (!PNODE || !PNODE->isMaster) { // first non-master node for (auto& nd : m_lMasterNodesData | std::views::reverse) { - if (nd.workspaceID == header.pWindow->m_iWorkspaceID && nd.isMaster) { + if (nd.workspaceID == header.pWindow->workspaceID() && nd.isMaster) { nd.isMaster = false; break; } @@ -1313,7 +1307,7 @@ std::any CHyprMasterLayout::layoutMessage(SLayoutMessageHeader header, std::stri g_pCompositor->setWindowFullscreen(PWINDOW, false, FULLSCREEN_FULL); - const auto PWORKSPACEDATA = getMasterWorkspaceData(PWINDOW->m_iWorkspaceID); + const auto PWORKSPACEDATA = getMasterWorkspaceData(PWINDOW->workspaceID()); if (command == "orientationleft") PWORKSPACEDATA->orientation = ORIENTATION_LEFT; @@ -1421,7 +1415,7 @@ void CHyprMasterLayout::runOrientationCycle(SLayoutMessageHeader& header, CVarLi g_pCompositor->setWindowFullscreen(PWINDOW, false, FULLSCREEN_FULL); - const auto PWORKSPACEDATA = getMasterWorkspaceData(PWINDOW->m_iWorkspaceID); + const auto PWORKSPACEDATA = getMasterWorkspaceData(PWINDOW->workspaceID()); int nextOrPrev = 0; for (size_t i = 0; i < cycle.size(); ++i) { @@ -1479,19 +1473,19 @@ Vector2D CHyprMasterLayout::predictSizeForNewWindowTiled() { if (!g_pCompositor->m_pLastMonitor) return {}; - const int NODES = getNodesOnWorkspace(g_pCompositor->m_pLastMonitor->activeWorkspace); + const int NODES = getNodesOnWorkspace(g_pCompositor->m_pLastMonitor->activeWorkspace->m_iID); if (NODES <= 0) return g_pCompositor->m_pLastMonitor->vecSize; - const auto MASTER = getMasterNodeOnWorkspace(g_pCompositor->m_pLastMonitor->activeWorkspace); + const auto MASTER = getMasterNodeOnWorkspace(g_pCompositor->m_pLastMonitor->activeWorkspace->m_iID); if (!MASTER) // wtf return {}; if (*PNEWISMASTER) { return MASTER->size; } else { - const auto SLAVES = NODES - getMastersOnWorkspace(g_pCompositor->m_pLastMonitor->activeWorkspace); + const auto SLAVES = NODES - getMastersOnWorkspace(g_pCompositor->m_pLastMonitor->activeWorkspace->m_iID); // TODO: make this better return {g_pCompositor->m_pLastMonitor->vecSize.x - MASTER->size.x, g_pCompositor->m_pLastMonitor->vecSize.y / (SLAVES + 1)}; diff --git a/src/layout/MasterLayout.hpp b/src/layout/MasterLayout.hpp index 1e48b5dd..922d7bb6 100644 --- a/src/layout/MasterLayout.hpp +++ b/src/layout/MasterLayout.hpp @@ -84,7 +84,7 @@ class CHyprMasterLayout : public IHyprLayout { SMasterNodeData* getNodeFromWindow(CWindow*); SMasterNodeData* getMasterNodeOnWorkspace(const int&); SMasterWorkspaceData* getMasterWorkspaceData(const int&); - void calculateWorkspace(const int&); + void calculateWorkspace(PHLWORKSPACE); CWindow* getNextWindow(CWindow*, bool); int getMastersOnWorkspace(const int&); |
