diff --git a/src/config/ConfigManager.cpp b/src/config/ConfigManager.cpp index 89152acca442..21659cf2fccd 100644 --- a/src/config/ConfigManager.cpp +++ b/src/config/ConfigManager.cpp @@ -109,6 +109,7 @@ void CConfigManager::setDefaultVars() { configValues["master:new_is_master"].intValue = 1; configValues["master:new_on_top"].intValue = 0; configValues["master:no_gaps_when_only"].intValue = 0; + configValues["master:orientation"].strValue = "left"; configValues["animations:enabled"].intValue = 1; configValues["animations:speed"].floatValue = 7.f; diff --git a/src/helpers/Workspace.cpp b/src/helpers/Workspace.cpp index 5984ffbb8fed..8e87c113b27a 100644 --- a/src/helpers/Workspace.cpp +++ b/src/helpers/Workspace.cpp @@ -12,7 +12,6 @@ CWorkspace::CWorkspace(int monitorID, std::string name, bool special) { m_iMonitorID = monitorID; m_szName = name; m_bIsSpecialWorkspace = special; - m_orientation = ORIENTATION_LEFT; if (!special) { m_pWlrHandle = wlr_ext_workspace_handle_v1_create(PMONITOR->pWLRWorkspaceGroupHandle); diff --git a/src/helpers/Workspace.hpp b/src/helpers/Workspace.hpp index 8e11ea53d86a..ee70dcff8204 100644 --- a/src/helpers/Workspace.hpp +++ b/src/helpers/Workspace.hpp @@ -8,15 +8,6 @@ enum eFullscreenMode : uint8_t { FULLSCREEN_MAXIMIZED }; -//orientation is used by the Master layout -//and determines which side of the screen the master area resides -enum eOrientation: uint8_t { - ORIENTATION_LEFT =0, - ORIENTATION_TOP, - ORIENTATION_RIGHT, - ORIENTATION_BOTTOM -}; - class CWindow; class CWorkspace { @@ -34,7 +25,6 @@ class CWorkspace { int m_iPrevWorkspaceID = -1; bool m_bHasFullscreenWindow = false; eFullscreenMode m_efFullscreenMode = FULLSCREEN_FULL; - eOrientation m_orientation = ORIENTATION_LEFT; wlr_ext_workspace_handle_v1* m_pWlrHandle = nullptr; diff --git a/src/layout/MasterLayout.cpp b/src/layout/MasterLayout.cpp index fd6910022fa1..c5568efd874e 100644 --- a/src/layout/MasterLayout.cpp +++ b/src/layout/MasterLayout.cpp @@ -30,6 +30,28 @@ int CHyprMasterLayout::getMastersOnWorkspace(const int& ws) { return no; } +SMasterWorkspaceData* CHyprMasterLayout::getMasterWorkspaceData(const int& ws) { + for (auto& n : m_lMasterWorkspacesData) { + if (n.workspaceID == ws) + return &n; + } + + //create on the fly if it doesn't exist yet + const auto PWORKSPACEDATA = &m_lMasterWorkspacesData.emplace_back(); + PWORKSPACEDATA->workspaceID = ws; + const auto orientation = g_pConfigManager->getString("master:orientation"); + if (orientation == "top") { + PWORKSPACEDATA->orientation = ORIENTATION_TOP; + } else if (orientation == "right") { + PWORKSPACEDATA->orientation = ORIENTATION_RIGHT; + } else if (orientation == "bottom") { + PWORKSPACEDATA->orientation = ORIENTATION_BOTTOM; + } else { + PWORKSPACEDATA->orientation = ORIENTATION_LEFT; + } + return PWORKSPACEDATA; +} + std::string CHyprMasterLayout::getLayoutName() { return "Master"; } @@ -187,6 +209,8 @@ void CHyprMasterLayout::calculateWorkspace(const int& ws) { if (!PWORKSPACE) return; + const auto PWORKSPACEDATA = getMasterWorkspaceData(ws); + const auto PMONITOR = g_pCompositor->getMonitorFromID(PWORKSPACE->m_iMonitorID); const auto PMASTERNODE = getMasterNodeOnWorkspace(PWORKSPACE->m_iID); @@ -202,7 +226,7 @@ void CHyprMasterLayout::calculateWorkspace(const int& ws) { PMASTERNODE->size = Vector2D(PMONITOR->vecSize.x - PMONITOR->vecReservedTopLeft.x - PMONITOR->vecReservedBottomRight.x, PMONITOR->vecSize.y - PMONITOR->vecReservedBottomRight.y - PMONITOR->vecReservedTopLeft.y); applyNodeDataToWindow(PMASTERNODE); return; - } else if (PWORKSPACE->m_orientation == ORIENTATION_LEFT || PWORKSPACE->m_orientation == ORIENTATION_RIGHT) { + } else if (PWORKSPACEDATA->orientation == ORIENTATION_LEFT || PWORKSPACEDATA->orientation == ORIENTATION_RIGHT) { float heightLeft = PMONITOR->vecSize.y - PMONITOR->vecReservedBottomRight.y - PMONITOR->vecReservedTopLeft.y; int nodesLeft = MASTERS; float nextY = 0; @@ -210,7 +234,7 @@ void CHyprMasterLayout::calculateWorkspace(const int& ws) { for (auto& n : m_lMasterNodesData) { if (n.workspaceID == PWORKSPACE->m_iID && n.isMaster) { - if (PWORKSPACE->m_orientation == ORIENTATION_RIGHT) { + if (PWORKSPACEDATA->orientation == ORIENTATION_RIGHT) { n.position = PMONITOR->vecReservedTopLeft + PMONITOR->vecPosition + Vector2D(PMONITOR->vecSize.x - WIDTH, nextY); } else { n.position = PMONITOR->vecReservedTopLeft + PMONITOR->vecPosition + Vector2D(0, nextY); @@ -227,7 +251,7 @@ void CHyprMasterLayout::calculateWorkspace(const int& ws) { applyNodeDataToWindow(&n); } } - } else if (PWORKSPACE->m_orientation == ORIENTATION_TOP || PWORKSPACE->m_orientation == ORIENTATION_BOTTOM) { + } else if (PWORKSPACEDATA->orientation == ORIENTATION_TOP || PWORKSPACEDATA->orientation == ORIENTATION_BOTTOM) { float widthLeft = PMONITOR->vecSize.x - PMONITOR->vecReservedBottomRight.x - PMONITOR->vecReservedTopLeft.x; int nodesLeft = MASTERS; float nextX = 0; @@ -235,7 +259,7 @@ void CHyprMasterLayout::calculateWorkspace(const int& ws) { for (auto& n : m_lMasterNodesData) { if (n.workspaceID == PWORKSPACE->m_iID && n.isMaster) { - if (PWORKSPACE->m_orientation == ORIENTATION_BOTTOM) { + if (PWORKSPACEDATA->orientation == ORIENTATION_BOTTOM) { n.position = PMONITOR->vecReservedTopLeft + PMONITOR->vecPosition + Vector2D(nextX,PMONITOR->vecSize.y - HEIGHT - PMONITOR->vecReservedBottomRight.y); } else { n.position = PMONITOR->vecReservedTopLeft + PMONITOR->vecPosition + Vector2D(nextX, 0); @@ -257,7 +281,7 @@ void CHyprMasterLayout::calculateWorkspace(const int& ws) { //compute placement of slave window(s) int slavesLeft = getNodesOnWorkspace(PWORKSPACE->m_iID) - MASTERS; - if (PWORKSPACE->m_orientation == ORIENTATION_LEFT || PWORKSPACE->m_orientation == ORIENTATION_RIGHT) { + if (PWORKSPACEDATA->orientation == ORIENTATION_LEFT || PWORKSPACEDATA->orientation == ORIENTATION_RIGHT) { float heightLeft = PMONITOR->vecSize.y - PMONITOR->vecReservedBottomRight.y - PMONITOR->vecReservedTopLeft.y; float nextY = 0; const float WIDTH = PMONITOR->vecSize.x - PMONITOR->vecReservedBottomRight.x - PMONITOR->vecReservedTopLeft.x - PMASTERNODE->size.x; @@ -266,7 +290,7 @@ void CHyprMasterLayout::calculateWorkspace(const int& ws) { if (nd.workspaceID != PWORKSPACE->m_iID || nd.isMaster) continue; - if (PWORKSPACE->m_orientation == ORIENTATION_LEFT) { + if (PWORKSPACEDATA->orientation == ORIENTATION_LEFT) { nd.position = PMONITOR->vecReservedTopLeft + PMONITOR->vecPosition + Vector2D(PMASTERNODE->percMaster * (PMONITOR->vecSize.x - PMONITOR->vecReservedTopLeft.x - PMONITOR->vecReservedBottomRight.x), nextY); } else { nd.position = PMONITOR->vecReservedTopLeft + PMONITOR->vecPosition + Vector2D(0, nextY); @@ -282,7 +306,7 @@ void CHyprMasterLayout::calculateWorkspace(const int& ws) { applyNodeDataToWindow(&nd); } - } else if (PWORKSPACE->m_orientation == ORIENTATION_TOP || PWORKSPACE->m_orientation == ORIENTATION_BOTTOM) { + } else if (PWORKSPACEDATA->orientation == ORIENTATION_TOP || PWORKSPACEDATA->orientation == ORIENTATION_BOTTOM) { float widthLeft = PMONITOR->vecSize.x - PMONITOR->vecReservedBottomRight.x - PMONITOR->vecReservedTopLeft.x; float nextX = 0; const float HEIGHT = PMONITOR->vecSize.y - PMONITOR->vecReservedBottomRight.y - PMONITOR->vecReservedTopLeft.y - PMASTERNODE->size.y; @@ -290,7 +314,7 @@ void CHyprMasterLayout::calculateWorkspace(const int& ws) { for (auto& nd : m_lMasterNodesData) { if (nd.workspaceID != PWORKSPACE->m_iID || nd.isMaster) continue; - if (PWORKSPACE->m_orientation == ORIENTATION_TOP) { + if (PWORKSPACEDATA->orientation == ORIENTATION_TOP) { nd.position = PMONITOR->vecReservedTopLeft + PMONITOR->vecPosition + Vector2D(nextX, PMASTERNODE->percMaster * (PMONITOR->vecSize.y - PMONITOR->vecReservedBottomRight.y - PMONITOR->vecReservedTopLeft.y)); } else { nd.position = PMONITOR->vecReservedTopLeft + PMONITOR->vecPosition + Vector2D(nextX, 0); @@ -825,18 +849,16 @@ std::any CHyprMasterLayout::layoutMessage(SLayoutMessageHeader header, std::stri if (!PWINDOW) return 0; - const auto PWORKSPACE = g_pCompositor->getWorkspaceByID(PWINDOW->m_iWorkspaceID); - if (!PWORKSPACE) - return 0; + const auto PWORKSPACEDATA = getMasterWorkspaceData(PWINDOW->m_iWorkspaceID); if (message == "orientationleft") - PWORKSPACE->m_orientation = ORIENTATION_LEFT; + PWORKSPACEDATA->orientation = ORIENTATION_LEFT; else if (message == "orientationright") - PWORKSPACE->m_orientation = ORIENTATION_RIGHT; + PWORKSPACEDATA->orientation = ORIENTATION_RIGHT; else if (message == "orientationtop") - PWORKSPACE->m_orientation = ORIENTATION_TOP; + PWORKSPACEDATA->orientation = ORIENTATION_TOP; else if (message == "orientationbottom") - PWORKSPACE->m_orientation = ORIENTATION_BOTTOM; + PWORKSPACEDATA->orientation = ORIENTATION_BOTTOM; recalculateMonitor(header.pWindow->m_iMonitorID); @@ -846,14 +868,12 @@ std::any CHyprMasterLayout::layoutMessage(SLayoutMessageHeader header, std::stri if (!PWINDOW) return 0; - const auto PWORKSPACE = g_pCompositor->getWorkspaceByID(PWINDOW->m_iWorkspaceID); - if (!PWORKSPACE) - return 0; + const auto PWORKSPACEDATA = getMasterWorkspaceData(PWINDOW->m_iWorkspaceID); - if (PWORKSPACE->m_orientation == ORIENTATION_BOTTOM) { - PWORKSPACE->m_orientation = ORIENTATION_LEFT; + if (PWORKSPACEDATA->orientation == ORIENTATION_BOTTOM) { + PWORKSPACEDATA->orientation = ORIENTATION_LEFT; } else { - PWORKSPACE->m_orientation = (eOrientation) (PWORKSPACE->m_orientation + 1); + PWORKSPACEDATA->orientation = (eOrientation) (PWORKSPACEDATA->orientation + 1); } recalculateMonitor(header.pWindow->m_iMonitorID); @@ -863,14 +883,12 @@ std::any CHyprMasterLayout::layoutMessage(SLayoutMessageHeader header, std::stri if (!PWINDOW) return 0; - const auto PWORKSPACE = g_pCompositor->getWorkspaceByID(PWINDOW->m_iWorkspaceID); - if (!PWORKSPACE) - return 0; + const auto PWORKSPACEDATA = getMasterWorkspaceData(PWINDOW->m_iWorkspaceID); - if (PWORKSPACE->m_orientation == ORIENTATION_LEFT) { - PWORKSPACE->m_orientation = ORIENTATION_BOTTOM; + if (PWORKSPACEDATA->orientation == ORIENTATION_LEFT) { + PWORKSPACEDATA->orientation = ORIENTATION_BOTTOM; } else { - PWORKSPACE->m_orientation = (eOrientation) (PWORKSPACE->m_orientation - 1); + PWORKSPACEDATA->orientation = (eOrientation) (PWORKSPACEDATA->orientation - 1); } recalculateMonitor(header.pWindow->m_iMonitorID); diff --git a/src/layout/MasterLayout.hpp b/src/layout/MasterLayout.hpp index a70731386b22..9489bba78bae 100644 --- a/src/layout/MasterLayout.hpp +++ b/src/layout/MasterLayout.hpp @@ -1,11 +1,19 @@ #pragma once #include "IHyprLayout.hpp" +#include #include #include enum eFullscreenMode : uint8_t; -enum eOrientation : uint8_t; + +//orientation determines which side of the screen the master area resides +enum eOrientation : uint8_t { + ORIENTATION_LEFT =0, + ORIENTATION_TOP, + ORIENTATION_RIGHT, + ORIENTATION_BOTTOM +}; struct SMasterNodeData { bool isMaster = false; @@ -25,6 +33,15 @@ struct SMasterNodeData { } }; +struct SMasterWorkspaceData { + int workspaceID = -1; + eOrientation orientation = ORIENTATION_LEFT; + + bool operator==(const SMasterWorkspaceData& rhs) { + return workspaceID == rhs.workspaceID; + } +}; + class CHyprMasterLayout : public IHyprLayout { public: virtual void onWindowCreatedTiling(CWindow*); @@ -45,7 +62,8 @@ class CHyprMasterLayout : public IHyprLayout { private: - std::list m_lMasterNodesData; + std::list m_lMasterNodesData; + std::vector m_lMasterWorkspacesData; bool m_bForceWarps = false; @@ -53,9 +71,11 @@ class CHyprMasterLayout : public IHyprLayout { void applyNodeDataToWindow(SMasterNodeData*); SMasterNodeData* getNodeFromWindow(CWindow*); SMasterNodeData* getMasterNodeOnWorkspace(const int&); + SMasterWorkspaceData* getMasterWorkspaceData(const int&); void calculateWorkspace(const int&); CWindow* getNextWindow(CWindow*, bool); int getMastersOnWorkspace(const int&); friend struct SMasterNodeData; + friend struct SMasterWorkspaceData; };