From 5ba33f846129f3e6c0505b19f94634b24505e828 Mon Sep 17 00:00:00 2001 From: Vaxry <43317083+vaxerski@users.noreply.github.com> Date: Sun, 26 Apr 2026 15:16:36 +0100 Subject: 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. --- .../algorithm/tiled/master/MasterAlgorithm.cpp | 56 ++++++++-------------- 1 file changed, 19 insertions(+), 37 deletions(-) (limited to 'src/layout/algorithm/tiled/master/MasterAlgorithm.cpp') diff --git a/src/layout/algorithm/tiled/master/MasterAlgorithm.cpp b/src/layout/algorithm/tiled/master/MasterAlgorithm.cpp index 7017deb1..11a59a5f 100644 --- a/src/layout/algorithm/tiled/master/MasterAlgorithm.cpp +++ b/src/layout/algorithm/tiled/master/MasterAlgorithm.cpp @@ -5,6 +5,7 @@ #include "../../../target/WindowTarget.hpp" #include "../../../../config/ConfigValue.hpp" +#include "../../../../config/shared/actions/ConfigActions.hpp" #include "../../../../config/shared/workspace/WorkspaceRuleManager.hpp" #include "../../../../desktop/state/FocusState.hpp" #include "../../../../helpers/Monitor.hpp" @@ -18,25 +19,6 @@ using namespace Layout; using namespace Layout::Tiled; using namespace Hyprutils::String; -struct Layout::Tiled::SMasterNodeData { - bool isMaster = false; - float percMaster = 0.5f; - - WP pTarget; - - Vector2D position; - Vector2D size; - - float percSize = 1.f; // size multiplier for resizing children - - bool ignoreFullscreenChecks = false; - - // - bool operator==(const SMasterNodeData& rhs) const { - return pTarget.lock() == rhs.pTarget.lock(); - } -}; - void CMasterAlgorithm::newTarget(SP target) { addTarget(target, true); } @@ -47,7 +29,7 @@ void CMasterAlgorithm::movedTarget(SP target, std::optional f void CMasterAlgorithm::addTarget(SP target, bool firstMap) { static auto PNEWONACTIVE = CConfigValue("master:new_on_active"); - static auto PNEWONTOP = CConfigValue("master:new_on_top"); + static auto PNEWONTOP = CConfigValue("master:new_on_top"); static auto PNEWSTATUS = CConfigValue("master:new_status"); const auto PWORKSPACE = m_parent->space()->workspace(); @@ -79,7 +61,7 @@ void CMasterAlgorithm::addTarget(SP target, bool firstMap) { PNODE->pTarget = target; const auto WINDOWSONWORKSPACE = getNodesNo(); - static auto PMFACT = CConfigValue("master:mfact"); + static auto PMFACT = CConfigValue("master:mfact"); float lastSplitPercent = *PMFACT; auto OPENINGON = isWindowTiled(Desktop::focusState()->window()) && Desktop::focusState()->window()->m_workspace == PWORKSPACE ? @@ -87,7 +69,7 @@ void CMasterAlgorithm::addTarget(SP target, bool firstMap) { getMasterNode(); const auto MOUSECOORDS = g_pInputManager->getMouseCoordsInternal(); - static auto PDROPATCURSOR = CConfigValue("master:drop_at_cursor"); + static auto PDROPATCURSOR = CConfigValue("master:drop_at_cursor"); eOrientation orientation = getDynamicOrientation(); const auto NODEIT = std::ranges::find(m_masterNodesData, PNODE); @@ -97,7 +79,7 @@ void CMasterAlgorithm::addTarget(SP target, bool firstMap) { if (WINDOWSONWORKSPACE > 2) { auto& v = m_masterNodesData; - const std::size_t srcIndex = static_cast(std::distance(v.begin(), NODEIT)); + const std::size_t srcIndex = sc(std::distance(v.begin(), NODEIT)); for (std::size_t i = 0; i < v.size(); ++i) { const CBox box = v[i]->pTarget->position(); @@ -131,8 +113,8 @@ void CMasterAlgorithm::addTarget(SP target, bool firstMap) { break; auto node = std::move(v[srcIndex]); - v.erase(v.begin() + static_cast(srcIndex)); - v.insert(v.begin() + static_cast(insertIndex), std::move(node)); + v.erase(v.begin() + sc(srcIndex)); + v.insert(v.begin() + sc(insertIndex), std::move(node)); break; } @@ -222,7 +204,7 @@ void CMasterAlgorithm::addTarget(SP target, bool firstMap) { void CMasterAlgorithm::removeTarget(SP target) { const auto MASTERSLEFT = getMastersNo(); - static auto SMALLSPLIT = CConfigValue("master:allow_small_split"); + static auto SMALLSPLIT = CConfigValue("master:allow_small_split"); const auto PNODE = getNodeFromTarget(target); @@ -269,8 +251,8 @@ void CMasterAlgorithm::resizeTarget(const Vector2D& Δ, SP target, eRec return; const auto PMONITOR = m_parent->space()->workspace()->m_monitor; - static auto SLAVECOUNTFORCENTER = CConfigValue("master:slave_count_for_center_master"); - static auto PSMARTRESIZING = CConfigValue("master:smart_resizing"); + static auto SLAVECOUNTFORCENTER = CConfigValue("master:slave_count_for_center_master"); + static auto PSMARTRESIZING = CConfigValue("master:smart_resizing"); const auto WORKAREA = PMONITOR->logicalBoxMinusReserved(); const bool DISPLAYBOTTOM = STICKS(PNODE->position.y + PNODE->size.y, WORKAREA.y + WORKAREA.h); @@ -405,7 +387,7 @@ void CMasterAlgorithm::swapTargets(SP a, SP b) { } void CMasterAlgorithm::moveTargetInDirection(SP t, Math::eDirection dir, bool silent) { - static auto PMONITORFALLBACK = CConfigValue("binds:window_direction_monitor_fallback"); + static auto PMONITORFALLBACK = CConfigValue("binds:window_direction_monitor_fallback"); const auto PWINDOW2 = g_pCompositor->getWindowInDirection(t->window(), dir); @@ -576,7 +558,7 @@ std::expected CMasterAlgorithm::layoutMsg(const std::string_v return std::unexpected("no window"); if (PWINDOW->layoutTarget()->floating()) { - g_pKeybindManager->m_dispatchers["swapnext"](""); + Config::Actions::swapNext(true); return {}; } @@ -593,7 +575,7 @@ std::expected CMasterAlgorithm::layoutMsg(const std::string_v return std::unexpected("no window"); if (PWINDOW->layoutTarget()->floating()) { - g_pKeybindManager->m_dispatchers["swapnext"]("prev"); + Config::Actions::swapNext(false); return {}; } @@ -616,7 +598,7 @@ std::expected CMasterAlgorithm::layoutMsg(const std::string_v const auto WINDOWS = getNodesNo(); const auto MASTERS = getMastersNo(); - static auto SMALLSPLIT = CConfigValue("master:allow_small_split"); + static auto SMALLSPLIT = CConfigValue("master:allow_small_split"); if (MASTERS + 2 > WINDOWS && *SMALLSPLIT == 0) return std::unexpected("nothing to do"); @@ -916,7 +898,7 @@ SP CMasterAlgorithm::getNodeFromWindow(PHLWINDOW x) { return x ? getNodeFromTarget(x->layoutTarget()) : nullptr; } -SP CMasterAlgorithm::getNodeFromTarget(SP x) { +SP CMasterAlgorithm::getNodeFromTarget(SP x) const { for (const auto& n : m_masterNodesData) { if (n->pTarget == x) return n; @@ -953,10 +935,10 @@ void CMasterAlgorithm::calculateWorkspace() { eOrientation orientation = getDynamicOrientation(); bool centerMasterWindow = false; - static auto SLAVECOUNTFORCENTER = CConfigValue("master:slave_count_for_center_master"); + static auto SLAVECOUNTFORCENTER = CConfigValue("master:slave_count_for_center_master"); static auto CMFALLBACK = CConfigValue("master:center_master_fallback"); - static auto PIGNORERESERVED = CConfigValue("master:center_ignores_reserved"); - static auto PSMARTRESIZING = CConfigValue("master:smart_resizing"); + static auto PIGNORERESERVED = CConfigValue("master:center_ignores_reserved"); + static auto PSMARTRESIZING = CConfigValue("master:smart_resizing"); const auto MASTERS = getMastersNo(); const auto WINDOWS = getNodesNo(); @@ -1003,7 +985,7 @@ void CMasterAlgorithm::calculateWorkspace() { // compute placement of master window(s) if (WINDOWS == 1 && !centerMasterWindow) { - static auto PALWAYSKEEPPOSITION = CConfigValue("master:always_keep_position"); + static auto PALWAYSKEEPPOSITION = CConfigValue("master:always_keep_position"); if (*PALWAYSKEEPPOSITION) { const float WIDTH = WORKAREA.w * PMASTERNODE->percMaster; float nextX = 0; -- cgit v1.2.3