summaryrefslogtreecommitdiff
path: root/src/layout/DwindleLayout.cpp
diff options
context:
space:
mode:
authorViktor <vlofgren@gmail.com>2025-06-10 09:20:31 +0200
committerGitHub <noreply@github.com>2025-06-10 08:20:31 +0100
commit6bdb1f413e4c592f73d91bef33dfb202503ef7ab (patch)
tree2ab47ef05a2c084188d618119aa72dda5c1bb782 /src/layout/DwindleLayout.cpp
parent81468253eac574ed4410075eb991a338fff423df (diff)
dwindle: add the ability to specify an aspect ratio for a singular window (#10650)
Diffstat (limited to 'src/layout/DwindleLayout.cpp')
-rw-r--r--src/layout/DwindleLayout.cpp36
1 files changed, 30 insertions, 6 deletions
diff --git a/src/layout/DwindleLayout.cpp b/src/layout/DwindleLayout.cpp
index 305f1fee..2f51b162 100644
--- a/src/layout/DwindleLayout.cpp
+++ b/src/layout/DwindleLayout.cpp
@@ -152,15 +152,39 @@ void CHyprDwindleLayout::applyNodeDataToWindow(SDwindleNodeData* pNode, bool for
PWINDOW->updateWindowDecos();
- auto calcPos = PWINDOW->m_position;
- auto calcSize = PWINDOW->m_size;
+ auto calcPos = PWINDOW->m_position;
+ auto calcSize = PWINDOW->m_size;
- const auto OFFSETTOPLEFT = Vector2D((double)(DISPLAYLEFT ? gapsOut.m_left : gapsIn.m_left), (double)(DISPLAYTOP ? gapsOut.m_top : gapsIn.m_top));
+ const static auto REQUESTEDRATIO = *CConfigValue<Hyprlang::VEC2>("dwindle:single_window_aspect_ratio");
+ const static auto REQUESTEDRATIOTOLERANCE = CConfigValue<Hyprlang::FLOAT>("dwindle:single_window_aspect_ratio_tolerance");
- const auto OFFSETBOTTOMRIGHT = Vector2D((double)(DISPLAYRIGHT ? gapsOut.m_right : gapsIn.m_right), (double)(DISPLAYBOTTOM ? gapsOut.m_bottom : gapsIn.m_bottom));
+ Vector2D ratioPadding;
- calcPos = calcPos + OFFSETTOPLEFT;
- calcSize = calcSize - OFFSETTOPLEFT - OFFSETBOTTOMRIGHT;
+ if (REQUESTEDRATIO.y != 0 && !pNode->pParent) {
+ const Vector2D originalSize = PMONITOR->m_size - PMONITOR->m_reservedTopLeft - PMONITOR->m_reservedBottomRight;
+
+ const double requestedRatio = REQUESTEDRATIO.x / REQUESTEDRATIO.y;
+ const double originalRatio = originalSize.x / originalSize.y;
+
+ if (requestedRatio > originalRatio) {
+ double padding = originalSize.y - (originalSize.x / requestedRatio);
+
+ if (padding / 2 > (*REQUESTEDRATIOTOLERANCE) * originalSize.y)
+ ratioPadding = Vector2D{0., padding};
+ } else if (requestedRatio < originalRatio) {
+ double padding = originalSize.x - (originalSize.y * requestedRatio);
+
+ if (padding / 2 > (*REQUESTEDRATIOTOLERANCE) * originalSize.x)
+ ratioPadding = Vector2D{padding, 0.};
+ }
+ }
+
+ const auto GAPOFFSETTOPLEFT = Vector2D((double)(DISPLAYLEFT ? gapsOut.m_left : gapsIn.m_left), (double)(DISPLAYTOP ? gapsOut.m_top : gapsIn.m_top));
+
+ const auto GAPOFFSETBOTTOMRIGHT = Vector2D((double)(DISPLAYRIGHT ? gapsOut.m_right : gapsIn.m_right), (double)(DISPLAYBOTTOM ? gapsOut.m_bottom : gapsIn.m_bottom));
+
+ calcPos = calcPos + GAPOFFSETTOPLEFT + ratioPadding / 2;
+ calcSize = calcSize - GAPOFFSETTOPLEFT - GAPOFFSETBOTTOMRIGHT - ratioPadding;
if (PWINDOW->m_isPseudotiled) {
// Calculate pseudo