diff --git a/src/desktop/Workspace.cpp b/src/desktop/Workspace.cpp index 7f8e7fc94..f2c221952 100644 --- a/src/desktop/Workspace.cpp +++ b/src/desktop/Workspace.cpp @@ -261,6 +261,7 @@ bool CWorkspace::matchesStaticSelector(const std::string& selector_) { // n - named: n[true] or n[s:string] or n[e:string] // m - monitor: m[monitor_selector] // w - windowCount: w[1-4] or w[1], optional flag t or f for tiled or floating and + // flag p to count only pinned windows, e.g. w[p1-2], w[pg4] // flag g to count groups instead of windows, e.g. w[t1-2], w[fg4] // flag v will count only visible windows // f - fullscreen state : f[-1], f[0], f[1], or f[2] for different fullscreen states @@ -370,6 +371,7 @@ bool CWorkspace::matchesStaticSelector(const std::string& selector_) { prop = prop.substr(2, prop.length() - 3); int wantsOnlyTiled = -1; + int wantsOnlyPinned = false; bool wantsCountGroup = false; bool wantsCountVisible = false; @@ -381,6 +383,9 @@ bool CWorkspace::matchesStaticSelector(const std::string& selector_) { } else if (flag == 'f' && wantsOnlyTiled == -1) { wantsOnlyTiled = 0; flagCount++; + } else if (flag == 'p' && !wantsOnlyPinned) { + wantsOnlyPinned = true; + flagCount++; } else if (flag == 'g' && !wantsCountGroup) { wantsCountGroup = true; flagCount++; @@ -411,9 +416,11 @@ bool CWorkspace::matchesStaticSelector(const std::string& selector_) { int count; if (wantsCountGroup) count = getGroups(wantsOnlyTiled == -1 ? std::nullopt : std::optional((bool)wantsOnlyTiled), + wantsOnlyPinned ? std::optional(wantsOnlyPinned) : std::nullopt, wantsCountVisible ? std::optional(wantsCountVisible) : std::nullopt); else count = getWindows(wantsOnlyTiled == -1 ? std::nullopt : std::optional((bool)wantsOnlyTiled), + wantsOnlyPinned ? std::optional(wantsOnlyPinned) : std::nullopt, wantsCountVisible ? std::optional(wantsCountVisible) : std::nullopt); if (count != from) @@ -444,10 +451,12 @@ bool CWorkspace::matchesStaticSelector(const std::string& selector_) { WORKSPACEID count; if (wantsCountGroup) - count = getGroups(wantsOnlyTiled == -1 ? std::nullopt : std::optional((bool)wantsOnlyTiled), - wantsCountVisible ? std::optional(wantsCountVisible) : std::nullopt); + count = + getGroups(wantsOnlyTiled == -1 ? std::nullopt : std::optional((bool)wantsOnlyTiled), + wantsOnlyPinned ? std::optional(wantsOnlyPinned) : std::nullopt, wantsCountVisible ? std::optional(wantsCountVisible) : std::nullopt); else count = getWindows(wantsOnlyTiled == -1 ? std::nullopt : std::optional((bool)wantsOnlyTiled), + wantsOnlyPinned ? std::optional(wantsOnlyPinned) : std::nullopt, wantsCountVisible ? std::optional(wantsCountVisible) : std::nullopt); if (std::clamp(count, from, to) != count) @@ -535,13 +544,15 @@ bool CWorkspace::isVisibleNotCovered() { return PMONITOR->activeWorkspace->m_iID == m_iID; } -int CWorkspace::getWindows(std::optional onlyTiled, std::optional onlyVisible) { +int CWorkspace::getWindows(std::optional onlyTiled, std::optional onlyPinned, std::optional onlyVisible) { int no = 0; for (auto const& w : g_pCompositor->m_vWindows) { if (w->workspaceID() != m_iID || !w->m_bIsMapped) continue; if (onlyTiled.has_value() && w->m_bIsFloating == onlyTiled.value()) continue; + if (onlyPinned.has_value() && w->m_bPinned != onlyPinned.value()) + continue; if (onlyVisible.has_value() && w->isHidden() == onlyVisible.value()) continue; no++; @@ -550,7 +561,7 @@ int CWorkspace::getWindows(std::optional onlyTiled, std::optional on return no; } -int CWorkspace::getGroups(std::optional onlyTiled, std::optional onlyVisible) { +int CWorkspace::getGroups(std::optional onlyTiled, std::optional onlyPinned, std::optional onlyVisible) { int no = 0; for (auto const& w : g_pCompositor->m_vWindows) { if (w->workspaceID() != m_iID || !w->m_bIsMapped) @@ -559,6 +570,8 @@ int CWorkspace::getGroups(std::optional onlyTiled, std::optional onl continue; if (onlyTiled.has_value() && w->m_bIsFloating == onlyTiled.value()) continue; + if (onlyPinned.has_value() && w->m_bPinned != onlyPinned.value()) + continue; if (onlyVisible.has_value() && w->isHidden() == onlyVisible.value()) continue; no++; diff --git a/src/desktop/Workspace.hpp b/src/desktop/Workspace.hpp index e9859d4fe..12dbe3283 100644 --- a/src/desktop/Workspace.hpp +++ b/src/desktop/Workspace.hpp @@ -72,8 +72,8 @@ class CWorkspace { SWorkspaceIDName getPrevWorkspaceIDName() const; void updateWindowDecos(); void updateWindowData(); - int getWindows(std::optional onlyTiled = {}, std::optional onlyVisible = {}); - int getGroups(std::optional onlyTiled = {}, std::optional onlyVisible = {}); + int getWindows(std::optional onlyTiled = {}, std::optional onlyPinned = {}, std::optional onlyVisible = {}); + int getGroups(std::optional onlyTiled = {}, std::optional onlyPinned = {}, std::optional onlyVisible = {}); bool hasUrgentWindow(); PHLWINDOW getFirstWindow(); PHLWINDOW getTopLeftWindow();