dwindle: add the ability to specify an aspect ratio for a singular window (#10650)

This commit is contained in:
Viktor 2025-06-10 09:20:31 +02:00 committed by GitHub
parent 81468253ea
commit 6bdb1f413e
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 44 additions and 6 deletions

View file

@ -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