From 86df0042706e877ad8558fc8fe249ffc3d9f5de1 Mon Sep 17 00:00:00 2001 From: MightyPlaza <123664421+MightyPlaza@users.noreply.github.com> Date: Mon, 4 Sep 2023 16:10:42 +0100 Subject: [PATCH 1/2] add "maxsize" workspace rule modified: src/Window.cpp modified: src/config/ConfigManager.cpp modified: src/config/ConfigManager.hpp modified: src/events/Windows.cpp --- src/Window.cpp | 8 -------- src/config/ConfigManager.cpp | 3 ++- src/config/ConfigManager.hpp | 1 + src/events/Windows.cpp | 24 ++++++++++++++++++++++++ 4 files changed, 27 insertions(+), 9 deletions(-) diff --git a/src/Window.cpp b/src/Window.cpp index 9c93cf94..cd599c82 100644 --- a/src/Window.cpp +++ b/src/Window.cpp @@ -417,8 +417,6 @@ void CWindow::onUnmap() { void CWindow::onMap() { - static auto* const PISOLATESPECIAL = &g_pConfigManager->getConfigValuePtr("misc:isolate_special")->intValue; - m_pWLSurface.assign(g_pXWaylandManager->getWindowSurface(this)); // JIC, reset the callbacks. If any are set, we'll make sure they are cleared so we don't accidentally unset them. (In case a window got remapped) @@ -449,12 +447,6 @@ void CWindow::onMap() { hyprListener_unmapWindow.initCallback(m_bIsX11 ? &m_uSurface.xwayland->surface->events.unmap : &m_uSurface.xdg->surface->events.unmap, &Events::listener_unmapWindow, this, "CWindow"); - - if (*PISOLATESPECIAL && g_pCompositor->getWindowsOnWorkspace(m_iWorkspaceID) > *PISOLATESPECIAL && g_pCompositor->isWorkspaceSpecial(m_iWorkspaceID)) { - const auto PMONITOR = g_pCompositor->getMonitorFromID(m_iMonitorID); - this->moveToWorkspace(PMONITOR->activeWorkspace); - } - } void CWindow::onBorderAngleAnimEnd(void* ptr) { diff --git a/src/config/ConfigManager.cpp b/src/config/ConfigManager.cpp index 6d1eaa5b..5f7c5191 100644 --- a/src/config/ConfigManager.cpp +++ b/src/config/ConfigManager.cpp @@ -114,7 +114,6 @@ void CConfigManager::setDefaultVars() { configValues["misc:groupbar_titles_font_size"].intValue = 8; configValues["misc:groupbar_gradients"].intValue = 1; configValues["misc:close_special_on_empty"].intValue = 1; - configValues["misc:isolate_special"].intValue = 0; configValues["misc:groupbar_text_color"].intValue = 0xffffffff; configValues["misc:background_color"].intValue = 0xff111111; @@ -1159,6 +1158,8 @@ void CConfigManager::handleWorkspaceRules(const std::string& command, const std: wsRule.monitor = rule.substr(delim + 8); else if ((delim = rule.find("default:")) != std::string::npos) wsRule.isDefault = configStringToInt(rule.substr(delim + 8)); + else if ((delim = rule.find("maxsize:")) != std::string::npos) + wsRule.maxSize = configStringToInt(rule.substr(delim + 8)); }; size_t pos = 0; diff --git a/src/config/ConfigManager.hpp b/src/config/ConfigManager.hpp index a14f5470..26b18dca 100644 --- a/src/config/ConfigManager.hpp +++ b/src/config/ConfigManager.hpp @@ -42,6 +42,7 @@ struct SWorkspaceRule { std::string workspaceName = ""; int workspaceId = -1; bool isDefault = false; + int maxSize = 0; std::optional gapsIn; std::optional gapsOut; std::optional borderSize; diff --git a/src/events/Windows.cpp b/src/events/Windows.cpp index 888f0447..ca617a4a 100644 --- a/src/events/Windows.cpp +++ b/src/events/Windows.cpp @@ -260,6 +260,30 @@ void Events::listener_mapWindow(void* owner, void* data) { PMONITOR = g_pCompositor->m_pLastMonitor; } } + } else { + auto pWorkspace = g_pCompositor->getWorkspaceByID(PWINDOW->m_iWorkspaceID); + auto workspaceRule = pWorkspace ? g_pConfigManager->getWorkspaceRuleFor(pWorkspace) : SWorkspaceRule{}; + const auto PMONITOR = g_pCompositor->getMonitorFromID(PWINDOW->m_iMonitorID); + + int maxSize = workspaceRule.maxSize; + if (maxSize != 0 && maxSize < g_pCompositor->getWindowsOnWorkspace(pWorkspace->m_iID)) { + if (pWorkspace->m_bIsSpecialWorkspace) { + PWINDOW->m_iWorkspaceID = PMONITOR->activeWorkspace; + PMONITOR->setSpecialWorkspace(nullptr); + } + + pWorkspace = g_pCompositor->getWorkspaceByID(PMONITOR->activeWorkspace); + workspaceRule = pWorkspace ? g_pConfigManager->getWorkspaceRuleFor(pWorkspace) : SWorkspaceRule{}; + maxSize = workspaceRule.maxSize; + if (maxSize != 0 && maxSize < g_pCompositor->getWindowsOnWorkspace(pWorkspace->m_iID)) { + std::string requestedWorkspaceName; + const int REQUESTEDWORKSPACEID = getWorkspaceIDFromString("empty", requestedWorkspaceName); + // doesn't exist since it's empty + pWorkspace = g_pCompositor->createNewWorkspace(REQUESTEDWORKSPACEID, PWINDOW->m_iMonitorID, requestedWorkspaceName); + PWINDOW->m_iWorkspaceID = pWorkspace->m_iID; + g_pKeybindManager->m_mDispatchers["workspace"](requestedWorkspaceName); + } + } } if (PWINDOW->m_bIsFloating) { From 3f7d9b304811bf54918cc42729f2d05740700573 Mon Sep 17 00:00:00 2001 From: MightyPlaza <123664421+MightyPlaza@users.noreply.github.com> Date: Mon, 4 Sep 2023 19:54:14 +0100 Subject: [PATCH 2/2] fix groups and swallowing modified: src/Compositor.cpp modified: src/Compositor.hpp modified: src/events/Windows.cpp --- src/Compositor.cpp | 10 ++++++++ src/Compositor.hpp | 1 + src/events/Windows.cpp | 56 ++++++++++++++++++++++-------------------- 3 files changed, 41 insertions(+), 26 deletions(-) diff --git a/src/Compositor.cpp b/src/Compositor.cpp index 73ed8439..58c50bcc 100644 --- a/src/Compositor.cpp +++ b/src/Compositor.cpp @@ -1164,6 +1164,16 @@ int CCompositor::getWindowsOnWorkspace(const int& id) { return no; } +int CCompositor::getVisibleWindowsOnWorkspace(const int& id) { + int no = 0; + for (auto& w : m_vWindows) { + if (w->m_iWorkspaceID == id && w->m_bIsMapped && !w->isHidden()) + no++; + } + + return no; +} + CWindow* CCompositor::getUrgentWindow() { for (auto& w : m_vWindows) { if (w->m_bIsMapped && w->m_bIsUrgent) diff --git a/src/Compositor.hpp b/src/Compositor.hpp index 2661af27..8482ed33 100644 --- a/src/Compositor.hpp +++ b/src/Compositor.hpp @@ -153,6 +153,7 @@ class CCompositor { void sanityCheckWorkspaces(); void updateWorkspaceWindowDecos(const int&); int getWindowsOnWorkspace(const int&); + int getVisibleWindowsOnWorkspace(const int&); CWindow* getUrgentWindow(); bool hasUrgentWindowOnWorkspace(const int&); CWindow* getFirstWindowOnWorkspace(const int&); diff --git a/src/events/Windows.cpp b/src/events/Windows.cpp index ca617a4a..b8cc8769 100644 --- a/src/events/Windows.cpp +++ b/src/events/Windows.cpp @@ -229,13 +229,15 @@ void Events::listener_mapWindow(void* owner, void* data) { if (PWINDOW->m_bPinned && !PWINDOW->m_bIsFloating) PWINDOW->m_bPinned = false; - const CVarList WORKSPACEARGS = CVarList(requestedWorkspace, 2, ' '); + bool isWorkspaceSet = false; + const CVarList WORKSPACEARGS = CVarList(requestedWorkspace, 2, ' '); if (!WORKSPACEARGS[0].empty()) { std::string requestedWorkspaceName; const int REQUESTEDWORKSPACEID = getWorkspaceIDFromString(WORKSPACEARGS[0], requestedWorkspaceName); if (REQUESTEDWORKSPACEID != INT_MAX) { + isWorkspaceSet = true; if (WORKSPACEARGS[1].find("silent") == 0) workspaceSilent = true; @@ -255,35 +257,11 @@ void Events::listener_mapWindow(void* owner, void* data) { if (pWorkspace->m_bIsSpecialWorkspace) g_pCompositor->getMonitorFromID(pWorkspace->m_iMonitorID)->setSpecialWorkspace(pWorkspace); else - g_pKeybindManager->m_mDispatchers["workspace"](requestedWorkspaceName); + g_pKeybindManager->m_mDispatchers["workspace"](pWorkspace->m_szName); PMONITOR = g_pCompositor->m_pLastMonitor; } } - } else { - auto pWorkspace = g_pCompositor->getWorkspaceByID(PWINDOW->m_iWorkspaceID); - auto workspaceRule = pWorkspace ? g_pConfigManager->getWorkspaceRuleFor(pWorkspace) : SWorkspaceRule{}; - const auto PMONITOR = g_pCompositor->getMonitorFromID(PWINDOW->m_iMonitorID); - - int maxSize = workspaceRule.maxSize; - if (maxSize != 0 && maxSize < g_pCompositor->getWindowsOnWorkspace(pWorkspace->m_iID)) { - if (pWorkspace->m_bIsSpecialWorkspace) { - PWINDOW->m_iWorkspaceID = PMONITOR->activeWorkspace; - PMONITOR->setSpecialWorkspace(nullptr); - } - - pWorkspace = g_pCompositor->getWorkspaceByID(PMONITOR->activeWorkspace); - workspaceRule = pWorkspace ? g_pConfigManager->getWorkspaceRuleFor(pWorkspace) : SWorkspaceRule{}; - maxSize = workspaceRule.maxSize; - if (maxSize != 0 && maxSize < g_pCompositor->getWindowsOnWorkspace(pWorkspace->m_iID)) { - std::string requestedWorkspaceName; - const int REQUESTEDWORKSPACEID = getWorkspaceIDFromString("empty", requestedWorkspaceName); - // doesn't exist since it's empty - pWorkspace = g_pCompositor->createNewWorkspace(REQUESTEDWORKSPACEID, PWINDOW->m_iMonitorID, requestedWorkspaceName); - PWINDOW->m_iWorkspaceID = pWorkspace->m_iID; - g_pKeybindManager->m_mDispatchers["workspace"](requestedWorkspaceName); - } - } } if (PWINDOW->m_bIsFloating) { @@ -594,6 +572,32 @@ void Events::listener_mapWindow(void* owner, void* data) { } } + if (!isWorkspaceSet) { + auto pWorkspace = g_pCompositor->getWorkspaceByID(PWINDOW->m_iWorkspaceID); + auto workspaceRule = pWorkspace ? g_pConfigManager->getWorkspaceRuleFor(pWorkspace) : SWorkspaceRule{}; + const auto PMONITOR = g_pCompositor->getMonitorFromID(PWINDOW->m_iMonitorID); + + int maxSize = workspaceRule.maxSize; + if (maxSize != 0 && maxSize < g_pCompositor->getVisibleWindowsOnWorkspace(pWorkspace->m_iID)) { + if (pWorkspace->m_bIsSpecialWorkspace) { + g_pCompositor->moveWindowToWorkspaceSafe(PWINDOW, g_pCompositor->getWorkspaceByID(PMONITOR->activeWorkspace)); + PMONITOR->setSpecialWorkspace(nullptr); + } + + pWorkspace = g_pCompositor->getWorkspaceByID(PMONITOR->activeWorkspace); + workspaceRule = pWorkspace ? g_pConfigManager->getWorkspaceRuleFor(pWorkspace) : SWorkspaceRule{}; + maxSize = workspaceRule.maxSize; + if (maxSize != 0 && maxSize < g_pCompositor->getVisibleWindowsOnWorkspace(pWorkspace->m_iID)) { + std::string requestedWorkspaceName; + const int REQUESTEDWORKSPACEID = getWorkspaceIDFromString("empty", requestedWorkspaceName); + // doesn't exist since it's empty + pWorkspace = g_pCompositor->createNewWorkspace(REQUESTEDWORKSPACEID, PWINDOW->m_iMonitorID, requestedWorkspaceName); + g_pCompositor->moveWindowToWorkspaceSafe(PWINDOW, pWorkspace); + g_pKeybindManager->m_mDispatchers["workspace"](pWorkspace->m_szName); + } + } + } + PWINDOW->m_bFirstMap = false; Debug::log(LOG, "Map request dispatched, monitor %s, xywh: %f %f %f %f", PMONITOR->szName.c_str(), PWINDOW->m_vRealPosition.goalv().x, PWINDOW->m_vRealPosition.goalv().y,