From dacaf72e02b8d1819135f6aef3911e8211e98630 Mon Sep 17 00:00:00 2001 From: vaxerski <43317083+vaxerski@users.noreply.github.com> Date: Wed, 31 Aug 2022 17:02:44 +0200 Subject: [PATCH] remember last window on workspace --- src/helpers/Workspace.hpp | 5 +++++ src/managers/KeybindManager.cpp | 23 ++++++++++++++++++++--- src/managers/XWaylandManager.cpp | 2 ++ 3 files changed, 27 insertions(+), 3 deletions(-) diff --git a/src/helpers/Workspace.hpp b/src/helpers/Workspace.hpp index 3faebdd8..88e72a25 100644 --- a/src/helpers/Workspace.hpp +++ b/src/helpers/Workspace.hpp @@ -8,6 +8,8 @@ enum eFullscreenMode : uint8_t { FULLSCREEN_MAXIMIZED }; +class CWindow; + class CWorkspace { public: CWorkspace(int monitorID, std::string name, bool special = false); @@ -36,6 +38,9 @@ public: // "scratchpad" bool m_bIsSpecialWorkspace = false; + // last window + CWindow* m_pLastFocusedWindow = nullptr; + // user-set bool m_bDefaultFloating = false; bool m_bDefaultPseudo = false; diff --git a/src/managers/KeybindManager.cpp b/src/managers/KeybindManager.cpp index 5d791004..bf926c6e 100644 --- a/src/managers/KeybindManager.cpp +++ b/src/managers/KeybindManager.cpp @@ -651,7 +651,12 @@ void CKeybindManager::changeworkspace(std::string args) { Debug::log(LOG, "Changed to workspace %i", workspaceToChangeTo); // focus - g_pInputManager->refocus(); + if (const auto PWINDOW = PWORKSPACETOCHANGETO->m_pLastFocusedWindow; g_pCompositor->windowValidMapped(PWINDOW)) { + // warp and focus + g_pCompositor->warpCursorTo(PWINDOW->m_vRealPosition.vec() + PWINDOW->m_vRealSize.vec() / 2.f); + g_pCompositor->focusWindow(PWINDOW, g_pXWaylandManager->getWindowSurface(PWINDOW)); + } else + g_pInputManager->refocus(); // mark the monitor dirty g_pHyprRenderer->damageMonitor(PMONITOR); @@ -1222,14 +1227,23 @@ void CKeybindManager::toggleSpecialWorkspace(std::string args) { Debug::log(LOG, "Toggling special workspace to open"); if (open) { + uint64_t monID = -1; + for (auto& m : g_pCompositor->m_vMonitors) { if (m->specialWorkspaceOpen != !open) { m->specialWorkspaceOpen = !open; g_pLayoutManager->getCurrentLayout()->recalculateMonitor(m->ID); g_pCompositor->getWorkspaceByID(SPECIAL_WORKSPACE_ID)->startAnim(false, false); + + monID = m->ID; } } + + if (const auto PWINDOW = g_pCompositor->getWorkspaceByID(g_pCompositor->m_pLastMonitor->activeWorkspace)->m_pLastFocusedWindow; g_pCompositor->windowValidMapped(PWINDOW) && PWINDOW->m_iMonitorID == monID) + g_pCompositor->focusWindow(PWINDOW); + else + g_pInputManager->refocus(); } else { auto PSPECIALWORKSPACE = g_pCompositor->getWorkspaceByID(SPECIAL_WORKSPACE_ID); @@ -1243,9 +1257,12 @@ void CKeybindManager::toggleSpecialWorkspace(std::string args) { PSPECIALWORKSPACE->startAnim(true, true); PSPECIALWORKSPACE->m_iMonitorID = g_pCompositor->m_pLastMonitor->ID; - } - g_pInputManager->refocus(); + if (const auto PWINDOW = PSPECIALWORKSPACE->m_pLastFocusedWindow; g_pCompositor->windowValidMapped(PWINDOW)) + g_pCompositor->focusWindow(PWINDOW); + else + g_pInputManager->refocus(); + } } void CKeybindManager::forceRendererReload(std::string args) { diff --git a/src/managers/XWaylandManager.cpp b/src/managers/XWaylandManager.cpp index 40d841ab..26a6fae4 100644 --- a/src/managers/XWaylandManager.cpp +++ b/src/managers/XWaylandManager.cpp @@ -62,6 +62,8 @@ void CHyprXWaylandManager::activateWindow(CWindow* pWindow, bool activate) { g_pCompositor->m_pLastFocus = getWindowSurface(pWindow); g_pCompositor->m_pLastWindow = pWindow; + + g_pCompositor->getWorkspaceByID(pWindow->m_iWorkspaceID)->m_pLastFocusedWindow = pWindow; } void CHyprXWaylandManager::getGeometryForWindow(CWindow* pWindow, wlr_box* pbox) {