summaryrefslogtreecommitdiff
path: root/src/desktop/Workspace.cpp
diff options
context:
space:
mode:
authorVaxry <vaxry@vaxry.net>2024-11-22 16:01:02 +0000
committerVaxry <vaxry@vaxry.net>2024-11-22 16:01:02 +0000
commit745a82ce8ab19d958e344f5925bb1dc8ea7d6a53 (patch)
tree6ef992f0b52c5ca2492e248d5433f8edbc7cb1ba /src/desktop/Workspace.cpp
parenta847bc67b1efcf3a0fa9c8a3a1da1a79743940c1 (diff)
core: workspace-related function cleanup / refactor
CCompositor is massive, and has a lot of functions that could be better optimized if in CWorkspace
Diffstat (limited to 'src/desktop/Workspace.cpp')
-rw-r--r--src/desktop/Workspace.cpp149
1 files changed, 141 insertions, 8 deletions
diff --git a/src/desktop/Workspace.cpp b/src/desktop/Workspace.cpp
index 8cddbb6b..7c3d47d7 100644
--- a/src/desktop/Workspace.cpp
+++ b/src/desktop/Workspace.cpp
@@ -422,11 +422,11 @@ bool CWorkspace::matchesStaticSelector(const std::string& selector_) {
int count;
if (wantsCountGroup)
- count = g_pCompositor->getGroupsOnWorkspace(m_iID, wantsOnlyTiled == -1 ? std::nullopt : std::optional<bool>((bool)wantsOnlyTiled),
- wantsCountVisible ? std::optional<bool>(wantsCountVisible) : std::nullopt);
+ count = getGroups(wantsOnlyTiled == -1 ? std::nullopt : std::optional<bool>((bool)wantsOnlyTiled),
+ wantsCountVisible ? std::optional<bool>(wantsCountVisible) : std::nullopt);
else
- count = g_pCompositor->getWindowsOnWorkspace(m_iID, wantsOnlyTiled == -1 ? std::nullopt : std::optional<bool>((bool)wantsOnlyTiled),
- wantsCountVisible ? std::optional<bool>(wantsCountVisible) : std::nullopt);
+ count = getWindows(wantsOnlyTiled == -1 ? std::nullopt : std::optional<bool>((bool)wantsOnlyTiled),
+ wantsCountVisible ? std::optional<bool>(wantsCountVisible) : std::nullopt);
if (count != from)
return false;
@@ -456,11 +456,11 @@ bool CWorkspace::matchesStaticSelector(const std::string& selector_) {
WORKSPACEID count;
if (wantsCountGroup)
- count = g_pCompositor->getGroupsOnWorkspace(m_iID, wantsOnlyTiled == -1 ? std::nullopt : std::optional<bool>((bool)wantsOnlyTiled),
- wantsCountVisible ? std::optional<bool>(wantsCountVisible) : std::nullopt);
+ count = getGroups(wantsOnlyTiled == -1 ? std::nullopt : std::optional<bool>((bool)wantsOnlyTiled),
+ wantsCountVisible ? std::optional<bool>(wantsCountVisible) : std::nullopt);
else
- count = g_pCompositor->getWindowsOnWorkspace(m_iID, wantsOnlyTiled == -1 ? std::nullopt : std::optional<bool>((bool)wantsOnlyTiled),
- wantsCountVisible ? std::optional<bool>(wantsCountVisible) : std::nullopt);
+ count = getWindows(wantsOnlyTiled == -1 ? std::nullopt : std::optional<bool>((bool)wantsOnlyTiled),
+ wantsCountVisible ? std::optional<bool>(wantsCountVisible) : std::nullopt);
if (std::clamp(count, from, to) != count)
return false;
@@ -525,3 +525,136 @@ bool CWorkspace::inert() {
MONITORID CWorkspace::monitorID() {
return m_pMonitor ? m_pMonitor->ID : MONITOR_INVALID;
}
+
+PHLWINDOW CWorkspace::getFullscreenWindow() {
+ for (auto const& w : g_pCompositor->m_vWindows) {
+ if (w->m_pWorkspace == m_pSelf && w->isFullscreen())
+ return w;
+ }
+
+ return nullptr;
+}
+
+bool CWorkspace::isVisible() {
+ return m_bVisible;
+}
+
+bool CWorkspace::isVisibleNotCovered() {
+ const auto PMONITOR = m_pMonitor.lock();
+ if (PMONITOR->activeSpecialWorkspace)
+ return PMONITOR->activeSpecialWorkspace->m_iID == m_iID;
+
+ return PMONITOR->activeWorkspace->m_iID == m_iID;
+}
+
+int CWorkspace::getWindows(std::optional<bool> onlyTiled, std::optional<bool> 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 (onlyVisible.has_value() && w->isHidden() == onlyVisible.value())
+ continue;
+ no++;
+ }
+
+ return no;
+}
+
+int CWorkspace::getGroups(std::optional<bool> onlyTiled, std::optional<bool> onlyVisible) {
+ int no = 0;
+ for (auto const& w : g_pCompositor->m_vWindows) {
+ if (w->workspaceID() != m_iID || !w->m_bIsMapped)
+ 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;
+}
+
+PHLWINDOW CWorkspace::getFirstWindow() {
+ for (auto const& w : g_pCompositor->m_vWindows) {
+ if (w->m_pWorkspace == m_pSelf && w->m_bIsMapped && !w->isHidden())
+ return w;
+ }
+
+ return nullptr;
+}
+
+PHLWINDOW CWorkspace::getTopLeftWindow() {
+ const auto PMONITOR = m_pMonitor.lock();
+
+ for (auto const& w : g_pCompositor->m_vWindows) {
+ if (w->m_pWorkspace != m_pSelf || !w->m_bIsMapped || w->isHidden())
+ continue;
+
+ const auto WINDOWIDEALBB = w->getWindowIdealBoundingBoxIgnoreReserved();
+
+ if (WINDOWIDEALBB.x <= PMONITOR->vecPosition.x + 1 && WINDOWIDEALBB.y <= PMONITOR->vecPosition.y + 1)
+ return w;
+ }
+ return nullptr;
+}
+
+bool CWorkspace::hasUrgentWindow() {
+ for (auto const& w : g_pCompositor->m_vWindows) {
+ if (w->m_pWorkspace == m_pSelf && w->m_bIsMapped && w->m_bIsUrgent)
+ return true;
+ }
+
+ return false;
+}
+
+void CWorkspace::updateWindowDecos() {
+ for (auto const& w : g_pCompositor->m_vWindows) {
+ if (w->m_pWorkspace != m_pSelf)
+ continue;
+
+ w->updateWindowDecos();
+ }
+}
+
+void CWorkspace::updateWindowData() {
+ const auto WORKSPACERULE = g_pConfigManager->getWorkspaceRuleFor(m_pSelf.lock());
+
+ for (auto const& w : g_pCompositor->m_vWindows) {
+ if (w->m_pWorkspace != m_pSelf)
+ continue;
+
+ w->updateWindowData(WORKSPACERULE);
+ }
+}
+
+void CWorkspace::forceReportSizesToWindows() {
+ for (auto const& w : g_pCompositor->m_vWindows) {
+ if (w->m_pWorkspace != m_pSelf || !w->m_bIsMapped || w->isHidden())
+ continue;
+
+ g_pXWaylandManager->setWindowSize(w, w->m_vRealSize.value(), true);
+ }
+}
+
+void CWorkspace::rename(const std::string& name) {
+ if (g_pCompositor->isWorkspaceSpecial(m_iID))
+ return;
+
+ Debug::log(LOG, "CWorkspace::rename: Renaming workspace {} to '{}'", m_iID, name);
+ m_szName = name;
+
+ g_pEventManager->postEvent({"renameworkspace", std::to_string(m_iID) + "," + m_szName});
+}
+
+void CWorkspace::updateWindows() {
+ for (auto const& w : g_pCompositor->m_vWindows) {
+ if (!w->m_bIsMapped || w->m_pWorkspace != m_pSelf)
+ continue;
+
+ w->updateDynamicRules();
+ }
+}