From eee9698ec90daee9e6f8e3b4f4b242f38287ff81 Mon Sep 17 00:00:00 2001 From: vaxerski <43317083+vaxerski@users.noreply.github.com> Date: Mon, 30 May 2022 20:44:14 +0200 Subject: [PATCH] move workspaces and not windows on mon disconnect --- src/Compositor.cpp | 2 +- src/debug/HyprCtl.cpp | 8 ++++---- src/events/Monitors.cpp | 20 ++++++++++++++++---- src/layout/DwindleLayout.cpp | 2 +- 4 files changed, 22 insertions(+), 10 deletions(-) diff --git a/src/Compositor.cpp b/src/Compositor.cpp index 17d48b0f..9241a56a 100644 --- a/src/Compositor.cpp +++ b/src/Compositor.cpp @@ -592,7 +592,7 @@ CWorkspace* CCompositor::getWorkspaceByID(const int& id) { void CCompositor::sanityCheckWorkspaces() { for (auto it = m_lWorkspaces.begin(); it != m_lWorkspaces.end(); ++it) { - if (getWindowsOnWorkspace(it->m_iID) == 0 && !isWorkspaceVisible(it->m_iID)) { + if ((getWindowsOnWorkspace(it->m_iID) == 0 && !isWorkspaceVisible(it->m_iID))) { it = m_lWorkspaces.erase(it); } } diff --git a/src/debug/HyprCtl.cpp b/src/debug/HyprCtl.cpp index 2920045b..693a1ff6 100644 --- a/src/debug/HyprCtl.cpp +++ b/src/debug/HyprCtl.cpp @@ -26,8 +26,8 @@ std::string monitorsRequest() { std::string clientsRequest() { std::string result = ""; for (auto& w : g_pCompositor->m_lWindows) { - result += getFormat("Window %x -> %s:\n\tat: %i,%i\n\tsize: %i, %i\n\tworkspace: %i (%s)\n\tfloating: %i\n\n", - &w, w.m_szTitle.c_str(), (int)w.m_vRealPosition.vec().x, (int)w.m_vRealPosition.vec().y, (int)w.m_vRealSize.vec().x, (int)w.m_vRealSize.vec().y, w.m_iWorkspaceID, (w.m_iWorkspaceID == -1 ? "" : g_pCompositor->getWorkspaceByID(w.m_iWorkspaceID)->m_szName.c_str()), (int)w.m_bIsFloating); + result += getFormat("Window %x -> %s:\n\tat: %i,%i\n\tsize: %i, %i\n\tworkspace: %i (%s)\n\tfloating: %i\n\tmonitor: %i\n\n", + &w, w.m_szTitle.c_str(), (int)w.m_vRealPosition.vec().x, (int)w.m_vRealPosition.vec().y, (int)w.m_vRealSize.vec().x, (int)w.m_vRealSize.vec().y, w.m_iWorkspaceID, (w.m_iWorkspaceID == -1 ? "" : g_pCompositor->getWorkspaceByID(w.m_iWorkspaceID)->m_szName.c_str()), (int)w.m_bIsFloating, w.m_iMonitorID); } return result; } @@ -47,8 +47,8 @@ std::string activeWindowRequest() { if (!g_pCompositor->windowValidMapped(PWINDOW)) return "Invalid"; - return getFormat("Window %x -> %s:\n\tat: %i,%i\n\tsize: %i, %i\n\tworkspace: %i (%s)\n\tfloating: %i\n\n", - PWINDOW, PWINDOW->m_szTitle.c_str(), (int)PWINDOW->m_vRealPosition.vec().x, (int)PWINDOW->m_vRealPosition.vec().y, (int)PWINDOW->m_vRealSize.vec().x, (int)PWINDOW->m_vRealSize.vec().y, PWINDOW->m_iWorkspaceID, (PWINDOW->m_iWorkspaceID == -1 ? "" : g_pCompositor->getWorkspaceByID(PWINDOW->m_iWorkspaceID)->m_szName.c_str()), (int)PWINDOW->m_bIsFloating); + return getFormat("Window %x -> %s:\n\tat: %i,%i\n\tsize: %i, %i\n\tworkspace: %i (%s)\n\tfloating: %i\n\tmonitor: %i\n\n", + PWINDOW, PWINDOW->m_szTitle.c_str(), (int)PWINDOW->m_vRealPosition.vec().x, (int)PWINDOW->m_vRealPosition.vec().y, (int)PWINDOW->m_vRealSize.vec().x, (int)PWINDOW->m_vRealSize.vec().y, PWINDOW->m_iWorkspaceID, (PWINDOW->m_iWorkspaceID == -1 ? "" : g_pCompositor->getWorkspaceByID(PWINDOW->m_iWorkspaceID)->m_szName.c_str()), (int)PWINDOW->m_bIsFloating, (int)PWINDOW->m_iMonitorID); } std::string layersRequest() { diff --git a/src/events/Monitors.cpp b/src/events/Monitors.cpp index 13f99749..4487bf2f 100644 --- a/src/events/Monitors.cpp +++ b/src/events/Monitors.cpp @@ -309,14 +309,26 @@ void Events::listener_monitorDestroy(void* owner, void* data) { // snap cursor wlr_cursor_warp(g_pCompositor->m_sWLRCursor, g_pCompositor->m_sSeat.mouse->mouse, BACKUPMON->vecPosition.x + BACKUPMON->vecTransformedSize.x / 2.f, BACKUPMON->vecPosition.y + BACKUPMON->vecTransformedSize.y / 2.f); - // move windows - for (auto& w : g_pCompositor->m_lWindows) { + // move workspaces + std::deque wspToMove; + for (auto& w : g_pCompositor->m_lWorkspaces) { if (w.m_iMonitorID == pMonitor->ID) { - g_pCompositor->moveWindowToWorkspace(&w, BACKUPWORKSPACE); + wspToMove.push_back(&w); } } - g_pCompositor->sanityCheckWorkspaces(); + for (auto& w : wspToMove) { + g_pCompositor->moveWorkspaceToMonitor(w, BACKUPMON); + w->startAnim(true, true, true); + } + + pMonitor->activeWorkspace = -1; + + for (auto it = g_pCompositor->m_lWorkspaces.begin(); it != g_pCompositor->m_lWorkspaces.end(); ++it) { + if (it->m_iMonitorID == pMonitor->ID) { + it = g_pCompositor->m_lWorkspaces.erase(it); + } + } Debug::log(LOG, "Removed monitor %s!", pMonitor->szName.c_str()); diff --git a/src/layout/DwindleLayout.cpp b/src/layout/DwindleLayout.cpp index 79c08571..59429688 100644 --- a/src/layout/DwindleLayout.cpp +++ b/src/layout/DwindleLayout.cpp @@ -357,7 +357,7 @@ void CHyprDwindleLayout::recalculateMonitor(const int& monid) { const auto PWORKSPACE = g_pCompositor->getWorkspaceByID(PMONITOR->activeWorkspace); // Ignore any recalc events if we have a fullscreen window. - if (PWORKSPACE->m_bHasFullscreenWindow) + if (!PWORKSPACE || PWORKSPACE->m_bHasFullscreenWindow) return; const auto TOPNODE = getMasterNodeOnWorkspace(PMONITOR->activeWorkspace);