mirror of
https://github.com/hyprwm/Hyprland
synced 2024-11-26 00:45:57 +01:00
workspace: Add 'v' flag for workspace selector that counts only visible windows (#5628)
* Add 'v' flag for workspace selector: counts only visible windows * extra commit because I'm dumb * guard
This commit is contained in:
parent
82222342f1
commit
4d0a635237
3 changed files with 35 additions and 15 deletions
|
@ -1273,23 +1273,34 @@ void CCompositor::sanityCheckWorkspaces() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int CCompositor::getWindowsOnWorkspace(const int& id, std::optional<bool> onlyTiled) {
|
int CCompositor::getWindowsOnWorkspace(const int& id, std::optional<bool> onlyTiled, std::optional<bool> onlyVisible) {
|
||||||
int no = 0;
|
int no = 0;
|
||||||
for (auto& w : m_vWindows) {
|
for (auto& w : m_vWindows) {
|
||||||
if (w->workspaceID() == id && w->m_bIsMapped && !(onlyTiled.has_value() && !w->m_bIsFloating != onlyTiled.value()))
|
if (w->workspaceID() != id || !w->m_bIsMapped)
|
||||||
no++;
|
continue;
|
||||||
|
if (onlyTiled.has_value() && w->m_bIsFloating == onlyTiled.value())
|
||||||
|
continue;
|
||||||
|
if (onlyVisible.has_value() && w->isHidden() == onlyVisible.value())
|
||||||
|
continue;
|
||||||
|
no++;
|
||||||
}
|
}
|
||||||
|
|
||||||
return no;
|
return no;
|
||||||
}
|
}
|
||||||
|
|
||||||
int CCompositor::getGroupsOnWorkspace(const int& id, std::optional<bool> onlyTiled) {
|
int CCompositor::getGroupsOnWorkspace(const int& id, std::optional<bool> onlyTiled, std::optional<bool> onlyVisible) {
|
||||||
int no = 0;
|
int no = 0;
|
||||||
for (auto& w : m_vWindows) {
|
for (auto& w : m_vWindows) {
|
||||||
if (w->workspaceID() == id && w->m_bIsMapped && !(onlyTiled.has_value() && !w->m_bIsFloating != onlyTiled.value()) && w->m_sGroupData.head)
|
if (w->workspaceID() != id || !w->m_bIsMapped)
|
||||||
no++;
|
continue;
|
||||||
|
if (!w->m_sGroupData.head)
|
||||||
|
continue;
|
||||||
|
if (onlyTiled.has_value() && w->m_bIsFloating == onlyTiled.value())
|
||||||
|
continue;
|
||||||
|
if (onlyVisible.has_value() && w->isHidden() == onlyVisible.value())
|
||||||
|
continue;
|
||||||
|
no++;
|
||||||
}
|
}
|
||||||
|
|
||||||
return no;
|
return no;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -151,8 +151,8 @@ class CCompositor {
|
||||||
void sanityCheckWorkspaces();
|
void sanityCheckWorkspaces();
|
||||||
void updateWorkspaceWindowDecos(const int&);
|
void updateWorkspaceWindowDecos(const int&);
|
||||||
void updateWorkspaceSpecialRenderData(const int&);
|
void updateWorkspaceSpecialRenderData(const int&);
|
||||||
int getWindowsOnWorkspace(const int& id, std::optional<bool> onlyTiled = {});
|
int getWindowsOnWorkspace(const int& id, std::optional<bool> onlyTiled = {}, std::optional<bool> onlyVisible = {});
|
||||||
int getGroupsOnWorkspace(const int& id, std::optional<bool> onlyTiled = {});
|
int getGroupsOnWorkspace(const int& id, std::optional<bool> onlyTiled = {}, std::optional<bool> onlyVisible = {});
|
||||||
CWindow* getUrgentWindow();
|
CWindow* getUrgentWindow();
|
||||||
bool hasUrgentWindowOnWorkspace(const int&);
|
bool hasUrgentWindowOnWorkspace(const int&);
|
||||||
CWindow* getFirstWindowOnWorkspace(const int&);
|
CWindow* getFirstWindowOnWorkspace(const int&);
|
||||||
|
|
|
@ -251,6 +251,7 @@ bool CWorkspace::matchesStaticSelector(const std::string& selector_) {
|
||||||
// m - monitor: m[monitor_selector]
|
// m - monitor: m[monitor_selector]
|
||||||
// w - windowCount: w[1-4] or w[1], optional flag t or f for tiled or floating and
|
// 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]
|
// flag g to count groups instead of windows, e.g. w[t1-2], w[fg4]
|
||||||
|
// flag v will count only visible windows
|
||||||
|
|
||||||
const auto NEXTSPACE = selector.find_first_of(' ', i);
|
const auto NEXTSPACE = selector.find_first_of(' ', i);
|
||||||
std::string prop = selector.substr(i, NEXTSPACE == std::string::npos ? std::string::npos : NEXTSPACE - i);
|
std::string prop = selector.substr(i, NEXTSPACE == std::string::npos ? std::string::npos : NEXTSPACE - i);
|
||||||
|
@ -355,8 +356,9 @@ bool CWorkspace::matchesStaticSelector(const std::string& selector_) {
|
||||||
|
|
||||||
prop = prop.substr(2, prop.length() - 3);
|
prop = prop.substr(2, prop.length() - 3);
|
||||||
|
|
||||||
int wantsOnlyTiled = -1;
|
int wantsOnlyTiled = -1;
|
||||||
bool wantsCountGroup = false;
|
bool wantsCountGroup = false;
|
||||||
|
bool wantsCountVisible = false;
|
||||||
|
|
||||||
int flagCount = 0;
|
int flagCount = 0;
|
||||||
for (auto& flag : prop) {
|
for (auto& flag : prop) {
|
||||||
|
@ -369,6 +371,9 @@ bool CWorkspace::matchesStaticSelector(const std::string& selector_) {
|
||||||
} else if (flag == 'g' && !wantsCountGroup) {
|
} else if (flag == 'g' && !wantsCountGroup) {
|
||||||
wantsCountGroup = true;
|
wantsCountGroup = true;
|
||||||
flagCount++;
|
flagCount++;
|
||||||
|
} else if (flag == 'v' && !wantsCountVisible) {
|
||||||
|
wantsCountVisible = true;
|
||||||
|
flagCount++;
|
||||||
} else {
|
} else {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -392,9 +397,11 @@ bool CWorkspace::matchesStaticSelector(const std::string& selector_) {
|
||||||
|
|
||||||
int count;
|
int count;
|
||||||
if (wantsCountGroup)
|
if (wantsCountGroup)
|
||||||
count = g_pCompositor->getGroupsOnWorkspace(m_iID, wantsOnlyTiled == -1 ? std::nullopt : std::optional<bool>((bool)wantsOnlyTiled));
|
count = g_pCompositor->getGroupsOnWorkspace(m_iID, wantsOnlyTiled == -1 ? std::nullopt : std::optional<bool>((bool)wantsOnlyTiled),
|
||||||
|
wantsCountVisible ? std::optional<bool>(wantsCountVisible) : std::nullopt);
|
||||||
else
|
else
|
||||||
count = g_pCompositor->getWindowsOnWorkspace(m_iID, wantsOnlyTiled == -1 ? std::nullopt : std::optional<bool>((bool)wantsOnlyTiled));
|
count = g_pCompositor->getWindowsOnWorkspace(m_iID, wantsOnlyTiled == -1 ? std::nullopt : std::optional<bool>((bool)wantsOnlyTiled),
|
||||||
|
wantsCountVisible ? std::optional<bool>(wantsCountVisible) : std::nullopt);
|
||||||
|
|
||||||
if (count != from)
|
if (count != from)
|
||||||
return false;
|
return false;
|
||||||
|
@ -424,9 +431,11 @@ bool CWorkspace::matchesStaticSelector(const std::string& selector_) {
|
||||||
|
|
||||||
int count;
|
int count;
|
||||||
if (wantsCountGroup)
|
if (wantsCountGroup)
|
||||||
count = g_pCompositor->getGroupsOnWorkspace(m_iID, wantsOnlyTiled == -1 ? std::nullopt : std::optional<bool>((bool)wantsOnlyTiled));
|
count = g_pCompositor->getGroupsOnWorkspace(m_iID, wantsOnlyTiled == -1 ? std::nullopt : std::optional<bool>((bool)wantsOnlyTiled),
|
||||||
|
wantsCountVisible ? std::optional<bool>(wantsCountVisible) : std::nullopt);
|
||||||
else
|
else
|
||||||
count = g_pCompositor->getWindowsOnWorkspace(m_iID, wantsOnlyTiled == -1 ? std::nullopt : std::optional<bool>((bool)wantsOnlyTiled));
|
count = g_pCompositor->getWindowsOnWorkspace(m_iID, wantsOnlyTiled == -1 ? std::nullopt : std::optional<bool>((bool)wantsOnlyTiled),
|
||||||
|
wantsCountVisible ? std::optional<bool>(wantsCountVisible) : std::nullopt);
|
||||||
|
|
||||||
if (std::clamp(count, from, to) != count)
|
if (std::clamp(count, from, to) != count)
|
||||||
return false;
|
return false;
|
||||||
|
|
Loading…
Reference in a new issue