summaryrefslogtreecommitdiff
path: root/src/layout
diff options
context:
space:
mode:
authorJulian Schuler <31921487+julianschuler@users.noreply.github.com>2022-12-17 23:37:44 +0100
committerGitHub <noreply@github.com>2022-12-17 22:37:44 +0000
commit2daabfa0e981d8d2e33c068c9cc84ecb3cf2daa0 (patch)
tree02b4cdf3dfae7874fdb6f5893d46531a9b8ad6f6 /src/layout
parent0f3214714f237afcccb5d6a1bd3cdb5b26ddbcfb (diff)
Add 'exact' option for 'splitratio' (#1245)
* Simplify getPlusMinusKeywordResult() * Add an 'exact' option for 'splitratio'
Diffstat (limited to 'src/layout')
-rw-r--r--src/layout/DwindleLayout.cpp5
-rw-r--r--src/layout/DwindleLayout.hpp4
-rw-r--r--src/layout/IHyprLayout.hpp4
-rw-r--r--src/layout/MasterLayout.cpp5
-rw-r--r--src/layout/MasterLayout.hpp2
5 files changed, 11 insertions, 9 deletions
diff --git a/src/layout/DwindleLayout.cpp b/src/layout/DwindleLayout.cpp
index 87f1fe33..c903a441 100644
--- a/src/layout/DwindleLayout.cpp
+++ b/src/layout/DwindleLayout.cpp
@@ -1166,7 +1166,7 @@ void CHyprDwindleLayout::switchWindows(CWindow* pWindow, CWindow* pWindow2) {
g_pHyprRenderer->damageWindow(pWindow2);
}
-void CHyprDwindleLayout::alterSplitRatioBy(CWindow* pWindow, float ratio) {
+void CHyprDwindleLayout::alterSplitRatio(CWindow* pWindow, float ratio, bool exact) {
// window should be valid, insallah
const auto PNODE = getNodeFromWindow(pWindow);
@@ -1174,7 +1174,8 @@ void CHyprDwindleLayout::alterSplitRatioBy(CWindow* pWindow, float ratio) {
if (!PNODE || !PNODE->pParent || (PNODE->isGroupMember() && PNODE->getGroupMemberCount() == g_pCompositor->getWindowsOnWorkspace(PNODE->workspaceID)))
return;
- PNODE->pParent->splitRatio = std::clamp(PNODE->pParent->splitRatio + ratio, 0.1f, 1.9f);
+ float newRatio = exact ? ratio : PNODE->pParent->splitRatio + ratio;
+ PNODE->pParent->splitRatio = std::clamp(newRatio, 0.1f, 1.9f);
PNODE->pParent->recalcSizePosRecursive();
}
diff --git a/src/layout/DwindleLayout.hpp b/src/layout/DwindleLayout.hpp
index 2c6f7229..e6a98915 100644
--- a/src/layout/DwindleLayout.hpp
+++ b/src/layout/DwindleLayout.hpp
@@ -60,7 +60,7 @@ class CHyprDwindleLayout : public IHyprLayout {
virtual std::any layoutMessage(SLayoutMessageHeader, std::string);
virtual SWindowRenderLayoutHints requestRenderHints(CWindow*);
virtual void switchWindows(CWindow*, CWindow*);
- virtual void alterSplitRatioBy(CWindow*, float);
+ virtual void alterSplitRatio(CWindow*, float, bool);
virtual std::string getLayoutName();
virtual void onEnable();
@@ -81,4 +81,4 @@ class CHyprDwindleLayout : public IHyprLayout {
std::deque<CWindow*> getGroupMembers(CWindow*);
friend struct SDwindleNodeData;
-}; \ No newline at end of file
+};
diff --git a/src/layout/IHyprLayout.hpp b/src/layout/IHyprLayout.hpp
index a58783e4..1be26d2b 100644
--- a/src/layout/IHyprLayout.hpp
+++ b/src/layout/IHyprLayout.hpp
@@ -115,10 +115,10 @@ interface IHyprLayout {
virtual void switchWindows(CWindow*, CWindow*) = 0;
/*
- Called when the user requests to change the splitratio by X
+ Called when the user requests to change the splitratio by or to X
on a window
*/
- virtual void alterSplitRatioBy(CWindow*, float) = 0;
+ virtual void alterSplitRatio(CWindow*, float, bool exact = false) = 0;
/*
Called when something wants the current layout's name
diff --git a/src/layout/MasterLayout.cpp b/src/layout/MasterLayout.cpp
index 5f38c871..0237bca9 100644
--- a/src/layout/MasterLayout.cpp
+++ b/src/layout/MasterLayout.cpp
@@ -604,7 +604,7 @@ void CHyprMasterLayout::switchWindows(CWindow* pWindow, CWindow* pWindow2) {
prepareNewFocus(pWindow2, inheritFullscreen);
}
-void CHyprMasterLayout::alterSplitRatioBy(CWindow* pWindow, float ratio) {
+void CHyprMasterLayout::alterSplitRatio(CWindow* pWindow, float ratio, bool exact) {
// window should be valid, insallah
const auto PNODE = getNodeFromWindow(pWindow);
@@ -614,7 +614,8 @@ void CHyprMasterLayout::alterSplitRatioBy(CWindow* pWindow, float ratio) {
const auto PMASTER = getMasterNodeOnWorkspace(pWindow->m_iWorkspaceID);
- PMASTER->percMaster = std::clamp(PMASTER->percMaster + ratio, 0.05f, 0.95f);
+ float newRatio = exact ? ratio : PMASTER->percMaster + ratio;
+ PMASTER->percMaster = std::clamp(newRatio, 0.05f, 0.95f);
recalculateMonitor(pWindow->m_iMonitorID);
}
diff --git a/src/layout/MasterLayout.hpp b/src/layout/MasterLayout.hpp
index 1b637fde..746c500e 100644
--- a/src/layout/MasterLayout.hpp
+++ b/src/layout/MasterLayout.hpp
@@ -56,7 +56,7 @@ class CHyprMasterLayout : public IHyprLayout {
virtual std::any layoutMessage(SLayoutMessageHeader, std::string);
virtual SWindowRenderLayoutHints requestRenderHints(CWindow*);
virtual void switchWindows(CWindow*, CWindow*);
- virtual void alterSplitRatioBy(CWindow*, float);
+ virtual void alterSplitRatio(CWindow*, float, bool);
virtual std::string getLayoutName();
virtual void onEnable();