From fcac25bcc2496dc248e9ee912d95ec38b5397acd Mon Sep 17 00:00:00 2001 From: Sungyoon Cho Date: Tue, 9 Apr 2024 20:08:38 +0900 Subject: workspace: Add count group flag in windowCount workspace selector prop (#5499) * Add groupCount workspace selector prop * Intergrate groupCount with windowCount --- src/desktop/Workspace.cpp | 48 +++++++++++++++++++++++++++++++++++------------ 1 file changed, 36 insertions(+), 12 deletions(-) (limited to 'src/desktop/Workspace.cpp') diff --git a/src/desktop/Workspace.cpp b/src/desktop/Workspace.cpp index cbc4b16e..70a0f370 100644 --- a/src/desktop/Workspace.cpp +++ b/src/desktop/Workspace.cpp @@ -249,7 +249,8 @@ bool CWorkspace::matchesStaticSelector(const std::string& selector_) { // s - special: s[true] // n - named: n[true] or n[s:string] or n[e:string] // m - monitor: m[monitor_selector] - // w - windowCount: w[0-4] or w[1], optional flag t or f for tiled or floating, e.g. w[t0-1] + // w - windowCount: w[1-4] or w[1], optional flag t or f for tiled or floating and + // flag g to count groups instead of windows, e.g. w[t1-2], w[fg4] const auto NEXTSPACE = selector.find_first_of(' ', i); std::string prop = selector.substr(i, NEXTSPACE == std::string::npos ? std::string::npos : NEXTSPACE - i); @@ -354,15 +355,25 @@ bool CWorkspace::matchesStaticSelector(const std::string& selector_) { prop = prop.substr(2, prop.length() - 3); - int wantsOnlyTiled = -1; - - if (prop.starts_with("t")) { - wantsOnlyTiled = 1; - prop = prop.substr(1); - } else if (prop.starts_with("f")) { - wantsOnlyTiled = 0; - prop = prop.substr(1); + int wantsOnlyTiled = -1; + bool wantsCountGroup = false; + + int flagCount = 0; + for (auto& flag : prop) { + if (flag == 't' && wantsOnlyTiled == -1) { + wantsOnlyTiled = 1; + flagCount++; + } else if (flag == 'f' && wantsOnlyTiled == -1) { + wantsOnlyTiled = 0; + flagCount++; + } else if (flag == 'g' && !wantsCountGroup) { + wantsCountGroup = true; + flagCount++; + } else { + break; + } } + prop = prop.substr(flagCount); if (!prop.contains("-")) { // try single @@ -379,7 +390,15 @@ bool CWorkspace::matchesStaticSelector(const std::string& selector_) { return false; } - return g_pCompositor->getWindowsOnWorkspace(m_iID, wantsOnlyTiled == -1 ? std::nullopt : std::optional((bool)wantsOnlyTiled)) == from; + int count; + if (wantsCountGroup) + count = g_pCompositor->getGroupsOnWorkspace(m_iID, wantsOnlyTiled == -1 ? std::nullopt : std::optional((bool)wantsOnlyTiled)); + else + count = g_pCompositor->getWindowsOnWorkspace(m_iID, wantsOnlyTiled == -1 ? std::nullopt : std::optional((bool)wantsOnlyTiled)); + + if (count != from) + return false; + continue; } const auto DASHPOS = prop.find("-"); @@ -403,8 +422,13 @@ bool CWorkspace::matchesStaticSelector(const std::string& selector_) { return false; } - const auto WINDOWSONWORKSPACE = g_pCompositor->getWindowsOnWorkspace(m_iID, wantsOnlyTiled == -1 ? std::nullopt : std::optional((bool)wantsOnlyTiled)); - if (std::clamp(WINDOWSONWORKSPACE, from, to) != WINDOWSONWORKSPACE) + int count; + if (wantsCountGroup) + count = g_pCompositor->getGroupsOnWorkspace(m_iID, wantsOnlyTiled == -1 ? std::nullopt : std::optional((bool)wantsOnlyTiled)); + else + count = g_pCompositor->getWindowsOnWorkspace(m_iID, wantsOnlyTiled == -1 ? std::nullopt : std::optional((bool)wantsOnlyTiled)); + + if (std::clamp(count, from, to) != count) return false; continue; } -- cgit v1.2.3