dwindle: Avoid rounding errors in window position (#3524)

* Avoid rounding errors in window position

* Fix naming scheme

* Fix unwanted window movement
This commit is contained in:
Michał Lewandowski 2023-10-09 13:28:58 +02:00 committed by GitHub
parent 499df49f7b
commit 7f8e0a1318
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -4,9 +4,6 @@
void SDwindleNodeData::recalcSizePosRecursive(bool force, bool horizontalOverride, bool verticalOverride) { void SDwindleNodeData::recalcSizePosRecursive(bool force, bool horizontalOverride, bool verticalOverride) {
if (children[0]) { if (children[0]) {
const auto REVERSESPLITRATIO = 2.f - splitRatio;
static auto* const PSMARTSPLIT = &g_pConfigManager->getConfigValuePtr("dwindle:smart_split")->intValue; static auto* const PSMARTSPLIT = &g_pConfigManager->getConfigValuePtr("dwindle:smart_split")->intValue;
static auto* const PPRESERVESPLIT = &g_pConfigManager->getConfigValuePtr("dwindle:preserve_split")->intValue; static auto* const PPRESERVESPLIT = &g_pConfigManager->getConfigValuePtr("dwindle:preserve_split")->intValue;
static auto* const PFLMULT = &g_pConfigManager->getConfigValuePtr("dwindle:split_width_multiplier")->floatValue; static auto* const PFLMULT = &g_pConfigManager->getConfigValuePtr("dwindle:split_width_multiplier")->floatValue;
@ -24,16 +21,18 @@ void SDwindleNodeData::recalcSizePosRecursive(bool force, bool horizontalOverrid
if (SPLITSIDE) { if (SPLITSIDE) {
// split left/right // split left/right
int const FIRSTSIZE = std::round(size.x / 2 * splitRatio);
children[0]->position = position; children[0]->position = position;
children[0]->size = Vector2D(size.x / 2.f * splitRatio, size.y); children[0]->size = Vector2D(FIRSTSIZE, size.y);
children[1]->position = Vector2D(position.x + size.x / 2.f * splitRatio, position.y); children[1]->position = Vector2D(position.x + FIRSTSIZE, position.y);
children[1]->size = Vector2D(size.x / 2.f * REVERSESPLITRATIO, size.y); children[1]->size = Vector2D(size.x - FIRSTSIZE, size.y);
} else { } else {
// split top/bottom // split top/bottom
int const FIRSTSIZE = std::round(size.y / 2 * splitRatio);
children[0]->position = position; children[0]->position = position;
children[0]->size = Vector2D(size.x, size.y / 2.f * splitRatio); children[0]->size = Vector2D(size.x, FIRSTSIZE);
children[1]->position = Vector2D(position.x, position.y + size.y / 2.f * splitRatio); children[1]->position = Vector2D(position.x, position.y + FIRSTSIZE);
children[1]->size = Vector2D(size.x, size.y / 2.f * REVERSESPLITRATIO); children[1]->size = Vector2D(size.x, size.y - FIRSTSIZE);
} }
children[0]->recalcSizePosRecursive(force); children[0]->recalcSizePosRecursive(force);