From 1681bea42dd2f11ba3fe6df05560d0b231de3c76 Mon Sep 17 00:00:00 2001 From: Vaxry <43317083+vaxerski@users.noreply.github.com> Date: Wed, 6 May 2026 13:56:12 +0100 Subject: config/lua: add simple layout API (#14258) Adds a simple layout lua api --- src/layout/algorithm/TiledAlgorithm.hpp | 11 ++++++++++- src/layout/supplementary/WorkspaceAlgoMatcher.cpp | 15 ++++++++++++++- src/layout/supplementary/WorkspaceAlgoMatcher.hpp | 3 ++- 3 files changed, 26 insertions(+), 3 deletions(-) (limited to 'src/layout') diff --git a/src/layout/algorithm/TiledAlgorithm.hpp b/src/layout/algorithm/TiledAlgorithm.hpp index 99d1bd99..6905ac74 100644 --- a/src/layout/algorithm/TiledAlgorithm.hpp +++ b/src/layout/algorithm/TiledAlgorithm.hpp @@ -5,6 +5,9 @@ #include "ModeAlgorithm.hpp" +#include +#include + namespace Layout { class ITarget; @@ -16,6 +19,12 @@ namespace Layout { virtual SP getNextCandidate(SP old) = 0; + // Optional runtime layout name. Useful for generic adapter classes where + // typeid alone cannot identify the selected layout instance. + virtual std::optional layoutName() const { + return std::nullopt; + } + protected: ITiledAlgorithm() = default; @@ -23,4 +32,4 @@ namespace Layout { friend class Layout::CAlgorithm; }; -} \ No newline at end of file +} diff --git a/src/layout/supplementary/WorkspaceAlgoMatcher.cpp b/src/layout/supplementary/WorkspaceAlgoMatcher.cpp index fe868038..08744e12 100644 --- a/src/layout/supplementary/WorkspaceAlgoMatcher.cpp +++ b/src/layout/supplementary/WorkspaceAlgoMatcher.cpp @@ -4,6 +4,7 @@ #include "../../config/shared/workspace/WorkspaceRuleManager.hpp" #include "../algorithm/Algorithm.hpp" +#include "../algorithm/TiledAlgorithm.hpp" #include "../space/Space.hpp" #include "../algorithm/floating/default/DefaultFloatingAlgorithm.hpp" @@ -124,7 +125,9 @@ void CWorkspaceAlgoMatcher::updateWorkspaceLayouts() { const auto LAYOUT_TO_USE = tiledAlgoForWorkspace(ws.lock()); - if (m_algoNames.contains(&typeid(*TILED_ALGO.get())) && m_algoNames.at(&typeid(*TILED_ALGO.get())) == LAYOUT_TO_USE) + const auto CURRENT_LAYOUT = getNameForTiledAlgo(TILED_ALGO.get()); + + if (CURRENT_LAYOUT == LAYOUT_TO_USE && m_tiledAlgos.contains(LAYOUT_TO_USE)) continue; // needs a switchup @@ -132,6 +135,16 @@ void CWorkspaceAlgoMatcher::updateWorkspaceLayouts() { } } +std::string CWorkspaceAlgoMatcher::getNameForTiledAlgo(const ITiledAlgorithm* algo) { + if (!algo) + return "unknown"; + + if (const auto name = algo->layoutName(); name.has_value()) + return *name; + + return getNameForTiledAlgo(&typeid(*algo)); +} + std::string CWorkspaceAlgoMatcher::getNameForTiledAlgo(const std::type_info* type) { if (m_algoNames.contains(type)) return m_algoNames.at(type); diff --git a/src/layout/supplementary/WorkspaceAlgoMatcher.hpp b/src/layout/supplementary/WorkspaceAlgoMatcher.hpp index d39e2998..bdc45be5 100644 --- a/src/layout/supplementary/WorkspaceAlgoMatcher.hpp +++ b/src/layout/supplementary/WorkspaceAlgoMatcher.hpp @@ -21,6 +21,7 @@ namespace Layout::Supplementary { SP createAlgorithmForWorkspace(PHLWORKSPACE w); void updateWorkspaceLayouts(); + std::string getNameForTiledAlgo(const Layout::ITiledAlgorithm* algo); std::string getNameForTiledAlgo(const std::type_info* type); // these fns can fail due to name collisions @@ -43,4 +44,4 @@ namespace Layout::Supplementary { }; const UP& algoMatcher(); -} \ No newline at end of file +} -- cgit v1.2.3