diff options
| author | Vaxry <43317083+vaxerski@users.noreply.github.com> | 2026-04-26 15:16:36 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2026-04-26 15:16:36 +0100 |
| commit | 5ba33f846129f3e6c0505b19f94634b24505e828 (patch) | |
| tree | aaacabe678006040c342935481a86607c66607fd /src/layout/algorithm/tiled/dwindle/DwindleAlgorithm.cpp | |
| parent | 329b2b356dd92ac07f4e2aa69cbce82ee9ba9d19 (diff) | |
config/lua: init lua config manager, use lua if available (#13817)
Adds a new lua config manager, which will automatically be used if there is a lua config present.
Diffstat (limited to 'src/layout/algorithm/tiled/dwindle/DwindleAlgorithm.cpp')
| -rw-r--r-- | src/layout/algorithm/tiled/dwindle/DwindleAlgorithm.cpp | 108 |
1 files changed, 45 insertions, 63 deletions
diff --git a/src/layout/algorithm/tiled/dwindle/DwindleAlgorithm.cpp b/src/layout/algorithm/tiled/dwindle/DwindleAlgorithm.cpp index baf767be..32035de0 100644 --- a/src/layout/algorithm/tiled/dwindle/DwindleAlgorithm.cpp +++ b/src/layout/algorithm/tiled/dwindle/DwindleAlgorithm.cpp @@ -18,58 +18,40 @@ using namespace Layout::Tiled; using namespace Hyprutils::String; -struct Layout::Tiled::SDwindleNodeData { - WP<SDwindleNodeData> pParent; - bool isNode = false; - WP<ITarget> pTarget; - std::array<WP<SDwindleNodeData>, 2> children = {}; - WP<SDwindleNodeData> self; - bool splitTop = false; // for preserve_split - CBox box = {0}; - float splitRatio = 1.f; - bool valid = true; - bool ignoreFullscreenChecks = false; - - // For list lookup - bool operator==(const SDwindleNodeData& rhs) const { - return pTarget.lock() == rhs.pTarget.lock() && box == rhs.box && pParent == rhs.pParent && children[0] == rhs.children[0] && children[1] == rhs.children[1]; - } - - void recalcSizePosRecursive(bool force = false, bool horizontalOverride = false, bool verticalOverride = false) { - if (children[0]) { - static auto PSMARTSPLIT = CConfigValue<Hyprlang::INT>("dwindle:smart_split"); - static auto PPRESERVESPLIT = CConfigValue<Hyprlang::INT>("dwindle:preserve_split"); - static auto PFLMULT = CConfigValue<Hyprlang::FLOAT>("dwindle:split_width_multiplier"); - static auto PPRECISEMOUSEMOVE = CConfigValue<Hyprlang::INT>("dwindle:precise_mouse_move"); - - if (*PPRESERVESPLIT == 0 && *PSMARTSPLIT == 0 && *PPRECISEMOUSEMOVE == 0) - splitTop = box.h * *PFLMULT > box.w; - - if (verticalOverride) - splitTop = true; - else if (horizontalOverride) - splitTop = false; - - const auto SPLITSIDE = !splitTop; - - if (SPLITSIDE) { - // split left/right - const float FIRSTSIZE = box.w / 2.0 * splitRatio; - children[0]->box = CBox{box.x, box.y, FIRSTSIZE, box.h}.noNegativeSize(); - children[1]->box = CBox{box.x + FIRSTSIZE, box.y, box.w - FIRSTSIZE, box.h}.noNegativeSize(); - } else { - // split top/bottom - const float FIRSTSIZE = box.h / 2.0 * splitRatio; - children[0]->box = CBox{box.x, box.y, box.w, FIRSTSIZE}.noNegativeSize(); - children[1]->box = CBox{box.x, box.y + FIRSTSIZE, box.w, box.h - FIRSTSIZE}.noNegativeSize(); - } +void SDwindleNodeData::recalcSizePosRecursive(bool force, bool horizontalOverride, bool verticalOverride) { + if (children[0]) { + static auto PSMARTSPLIT = CConfigValue<Config::INTEGER>("dwindle:smart_split"); + static auto PPRESERVESPLIT = CConfigValue<Config::INTEGER>("dwindle:preserve_split"); + static auto PFLMULT = CConfigValue<Config::FLOAT>("dwindle:split_width_multiplier"); + static auto PPRECISEMOUSEMOVE = CConfigValue<Config::INTEGER>("dwindle:precise_mouse_move"); + + if (*PPRESERVESPLIT == 0 && *PSMARTSPLIT == 0 && *PPRECISEMOUSEMOVE == 0) + splitTop = box.h * *PFLMULT > box.w; + + if (verticalOverride) + splitTop = true; + else if (horizontalOverride) + splitTop = false; + + const auto SPLITSIDE = !splitTop; + + if (SPLITSIDE) { + // split left/right + const float FIRSTSIZE = box.w / 2.0 * splitRatio; + children[0]->box = CBox{box.x, box.y, FIRSTSIZE, box.h}.noNegativeSize(); + children[1]->box = CBox{box.x + FIRSTSIZE, box.y, box.w - FIRSTSIZE, box.h}.noNegativeSize(); + } else { + // split top/bottom + const float FIRSTSIZE = box.h / 2.0 * splitRatio; + children[0]->box = CBox{box.x, box.y, box.w, FIRSTSIZE}.noNegativeSize(); + children[1]->box = CBox{box.x, box.y + FIRSTSIZE, box.w, box.h - FIRSTSIZE}.noNegativeSize(); + } - children[0]->recalcSizePosRecursive(force); - children[1]->recalcSizePosRecursive(force); - } else - pTarget->setPositionGlobal(box); - } -}; + children[0]->recalcSizePosRecursive(force); + children[1]->recalcSizePosRecursive(force); + } else + pTarget->setPositionGlobal(box); +} void CDwindleAlgorithm::newTarget(SP<ITarget> target) { addTarget(target); @@ -84,8 +66,8 @@ void CDwindleAlgorithm::addTarget(SP<ITarget> target) { const auto PMONITOR = m_parent->space()->workspace()->m_monitor; const auto PWORKSPACE = m_parent->space()->workspace(); - static auto PUSEACTIVE = CConfigValue<Hyprlang::INT>("dwindle:use_active_for_splits"); - static auto PDEFAULTSPLIT = CConfigValue<Hyprlang::FLOAT>("dwindle:default_split_ratio"); + static auto PUSEACTIVE = CConfigValue<Config::INTEGER>("dwindle:use_active_for_splits"); + static auto PDEFAULTSPLIT = CConfigValue<Config::FLOAT>("dwindle:default_split_ratio"); // Populate the node with our window's data PNODE->pTarget = target; @@ -154,17 +136,17 @@ void CDwindleAlgorithm::addTarget(SP<ITarget> target) { NEWPARENT->isNode = true; // it is a node NEWPARENT->splitRatio = std::clamp(*PDEFAULTSPLIT, 0.1F, 1.9F); - static auto PWIDTHMULTIPLIER = CConfigValue<Hyprlang::FLOAT>("dwindle:split_width_multiplier"); + static auto PWIDTHMULTIPLIER = CConfigValue<Config::FLOAT>("dwindle:split_width_multiplier"); // if cursor over first child, make it first, etc const auto SIDEBYSIDE = NEWPARENT->box.w > NEWPARENT->box.h * *PWIDTHMULTIPLIER; NEWPARENT->splitTop = !SIDEBYSIDE; - static auto PFORCESPLIT = CConfigValue<Hyprlang::INT>("dwindle:force_split"); - static auto PERMANENTDIRECTIONOVERRIDE = CConfigValue<Hyprlang::INT>("dwindle:permanent_direction_override"); - static auto PSMARTSPLIT = CConfigValue<Hyprlang::INT>("dwindle:smart_split"); - static auto PSPLITBIAS = CConfigValue<Hyprlang::INT>("dwindle:split_bias"); - static auto PPRECISEMOUSEMOVE = CConfigValue<Hyprlang::INT>("dwindle:precise_mouse_move"); + static auto PFORCESPLIT = CConfigValue<Config::INTEGER>("dwindle:force_split"); + static auto PERMANENTDIRECTIONOVERRIDE = CConfigValue<Config::INTEGER>("dwindle:permanent_direction_override"); + static auto PSMARTSPLIT = CConfigValue<Config::INTEGER>("dwindle:smart_split"); + static auto PSPLITBIAS = CConfigValue<Config::INTEGER>("dwindle:split_bias"); + static auto PPRECISEMOUSEMOVE = CConfigValue<Config::INTEGER>("dwindle:precise_mouse_move"); bool horizontalOverride = false; bool verticalOverride = false; @@ -324,8 +306,8 @@ void CDwindleAlgorithm::resizeTarget(const Vector2D& Δ, SP<ITarget> target, eRe if (!PNODE) return; - static auto PANIMATE = CConfigValue<Hyprlang::INT>("misc:animate_manual_resizes"); - static auto PSMARTRESIZING = CConfigValue<Hyprlang::INT>("dwindle:smart_resizing"); + static auto PANIMATE = CConfigValue<Config::INTEGER>("misc:animate_manual_resizes"); + static auto PSMARTRESIZING = CConfigValue<Config::INTEGER>("dwindle:smart_resizing"); // get some data about our window const auto PMONITOR = m_parent->space()->workspace()->m_monitor; @@ -533,7 +515,7 @@ std::optional<Vector2D> CDwindleAlgorithm::predictSizeForNewTarget() { CBox box = PNODE->box; - static auto PFLMULT = CConfigValue<Hyprlang::FLOAT>("dwindle:split_width_multiplier"); + static auto PFLMULT = CConfigValue<Config::FLOAT>("dwindle:split_width_multiplier"); bool splitTop = box.h * *PFLMULT > box.w; @@ -553,7 +535,7 @@ std::optional<Vector2D> CDwindleAlgorithm::predictSizeForNewTarget() { } void CDwindleAlgorithm::moveTargetInDirection(SP<ITarget> t, Math::eDirection dir, bool silent) { - static auto PMONITORFALLBACK = CConfigValue<Hyprlang::INT>("binds:window_direction_monitor_fallback"); + static auto PMONITORFALLBACK = CConfigValue<Config::INTEGER>("binds:window_direction_monitor_fallback"); const auto PNODE = getNodeFromTarget(t); const Vector2D originalPos = t->position().middle(); |
