diff options
| author | Visal Vijay <150381094+B2krobbery@users.noreply.github.com> | 2026-04-02 03:50:56 +0530 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2026-04-01 23:20:56 +0100 |
| commit | 529f72249c2cf4cefc824a612aeddf2d5f858f54 (patch) | |
| tree | 481ed69b5a014b004f3d71dd2f6c7000fcdee0f3 /src/layout/supplementary | |
| parent | 7fbf8f98477dfbb2e6b193ef85e0c2d119d3fe80 (diff) | |
layout: replace string comparison with ID-based matching in WorkspaceAlgoMatcher (#13943)
* perf(layout): replace string comparison with ID-based matching in WorkspaceAlgoMatcher
* perf(layout): replace string comparison with ID-based matching in WorkspaceAlgoMatcher
Diffstat (limited to 'src/layout/supplementary')
| -rw-r--r-- | src/layout/supplementary/WorkspaceAlgoMatcher.cpp | 20 |
1 files changed, 16 insertions, 4 deletions
diff --git a/src/layout/supplementary/WorkspaceAlgoMatcher.cpp b/src/layout/supplementary/WorkspaceAlgoMatcher.cpp index 98cdb773..0bf394a4 100644 --- a/src/layout/supplementary/WorkspaceAlgoMatcher.cpp +++ b/src/layout/supplementary/WorkspaceAlgoMatcher.cpp @@ -1,5 +1,6 @@ #include "WorkspaceAlgoMatcher.hpp" - +#include <unordered_map> +#include <string> #include "../../config/ConfigValue.hpp" #include "../../config/shared/workspace/WorkspaceRuleManager.hpp" @@ -14,6 +15,8 @@ #include "../../Compositor.hpp" +static const std::unordered_map<std::string, int> layoutIDs = {{"dwindle", 1}, {"master", 2}, {"scrolling", 3}, {"monocle", 4}, {"default", 5}, {"floating", 6}}; + using namespace Layout; using namespace Layout::Supplementary; @@ -112,7 +115,7 @@ SP<CAlgorithm> CWorkspaceAlgoMatcher::createAlgorithmForWorkspace(PHLWORKSPACE w } void CWorkspaceAlgoMatcher::updateWorkspaceLayouts() { - // TODO: make this ID-based, string comparison is slow + // TODO: fully migrate layout selection to ID-based system (comparison optimized) for (const auto& ws : g_pCompositor->getWorkspaces()) { if (!ws) continue; @@ -123,9 +126,18 @@ void CWorkspaceAlgoMatcher::updateWorkspaceLayouts() { continue; const auto LAYOUT_TO_USE = tiledAlgoForWorkspace(ws.lock()); + auto itLayout = layoutIDs.find(LAYOUT_TO_USE); + const int layoutID = (itLayout != layoutIDs.end()) ? itLayout->second : -1; - if (m_algoNames.contains(&typeid(*TILED_ALGO.get())) && m_algoNames.at(&typeid(*TILED_ALGO.get())) == LAYOUT_TO_USE) - continue; + if (m_algoNames.contains(&typeid(*TILED_ALGO.get()))) { + const auto& currentName = m_algoNames.at(&typeid(*TILED_ALGO.get())); + + auto itCurrent = layoutIDs.find(currentName); + const int currentID = (itCurrent != layoutIDs.end()) ? itCurrent->second : -1; + + if (currentID == layoutID) + continue; + } // needs a switchup ws->m_space->algorithm()->updateTiledAlgo(algoForNameTiled(LAYOUT_TO_USE)); |
