From 37e1450a4d028d974a7d38742a7bc5b093efa263 Mon Sep 17 00:00:00 2001 From: Darksome Date: Sat, 20 Aug 2022 13:25:56 +0300 Subject: [PATCH] Impl CCompositor::moveWindowToWorkspace --- src/Compositor.cpp | 14 ++++++++++++++ src/Compositor.hpp | 1 + src/events/Windows.cpp | 8 +++++--- src/layout/IHyprLayout.cpp | 12 ++---------- src/managers/KeybindManager.cpp | 4 +--- 5 files changed, 23 insertions(+), 16 deletions(-) diff --git a/src/Compositor.cpp b/src/Compositor.cpp index 5d6d65ec..f345e300 100644 --- a/src/Compositor.cpp +++ b/src/Compositor.cpp @@ -876,6 +876,20 @@ void CCompositor::moveWindowToTop(CWindow* pWindow) { } } +void CCompositor::moveWindowToWorkspace(CWindow* pWindow, int workspaceID) { + if (!windowValidMapped(pWindow)) + return; + + if (pWindow->m_iWorkspaceID != workspaceID) { + pWindow->m_iWorkspaceID = workspaceID; + + const auto PWORKSPACE = g_pCompositor->getWorkspaceByID(pWindow->m_iWorkspaceID); + if (PWORKSPACE) { + g_pEventManager->postEvent(SHyprIPCEvent{"movewindow", getFormat("%x,%s", pWindow, PWORKSPACE->m_szName.c_str())}); + } + } +} + void CCompositor::cleanupFadingOut(const int& monid) { for (auto& w : m_vWindowsFadingOut) { diff --git a/src/Compositor.hpp b/src/Compositor.hpp index 2e8c8dfe..8e380c94 100644 --- a/src/Compositor.hpp +++ b/src/Compositor.hpp @@ -132,6 +132,7 @@ public: bool doesSeatAcceptInput(wlr_surface*); bool isWindowActive(CWindow*); void moveWindowToTop(CWindow*); + void moveWindowToWorkspace(CWindow*, int); void cleanupFadingOut(const int& monid); CWindow* getWindowInDirection(CWindow*, char); void deactivateAllWLRWorkspaces(wlr_ext_workspace_handle_v1* exclude = nullptr); diff --git a/src/events/Windows.cpp b/src/events/Windows.cpp index ba2a5942..1eb35cc8 100644 --- a/src/events/Windows.cpp +++ b/src/events/Windows.cpp @@ -295,8 +295,6 @@ void Events::listener_mapWindow(void* owner, void* data) { const auto TIMER = wl_event_loop_add_timer(g_pCompositor->m_sWLEventLoop, setAnimToMove, PWINDOW); wl_event_source_timer_update(TIMER, PWINDOW->m_vRealPosition.getDurationLeftMs() + 5); - g_pEventManager->postEvent(SHyprIPCEvent{"mapwindow", getFormat("%x,%s,%s,%s", PWINDOW, PWORKSPACE->m_szName.c_str(), g_pXWaylandManager->getAppIDClass(PWINDOW).c_str(), PWINDOW->m_szTitle.c_str())}); - if (workspaceSilent) { // move the window if (g_pCompositor->m_pLastWindow == PWINDOW) { @@ -331,13 +329,17 @@ void Events::listener_mapWindow(void* owner, void* data) { PWINDOW->updateToplevel(); 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, PWINDOW->m_vRealSize.goalv().x, PWINDOW->m_vRealSize.goalv().y); + + auto workspaceID = requestedWorkspace != "" ? requestedWorkspace : PWORKSPACE->m_szName; + g_pEventManager->postEvent(SHyprIPCEvent{"openwindow", getFormat("%x,%s,%s,%s", PWINDOW, workspaceID.c_str(), g_pXWaylandManager->getAppIDClass(PWINDOW).c_str(), PWINDOW->m_szTitle.c_str())}); } void Events::listener_unmapWindow(void* owner, void* data) { CWindow* PWINDOW = (CWindow*)owner; Debug::log(LOG, "Window %x unmapped (class %s)", PWINDOW, g_pXWaylandManager->getAppIDClass(PWINDOW).c_str()); - g_pEventManager->postEvent(SHyprIPCEvent{"unmapwindow", getFormat("%x", PWINDOW)}); + + g_pEventManager->postEvent(SHyprIPCEvent{"closewindow", getFormat("%x", PWINDOW)}); if (!PWINDOW->m_bIsX11) { Debug::log(LOG, "Unregistered late callbacks XDG"); diff --git a/src/layout/IHyprLayout.cpp b/src/layout/IHyprLayout.cpp index 173668bc..f641ebc1 100644 --- a/src/layout/IHyprLayout.cpp +++ b/src/layout/IHyprLayout.cpp @@ -206,15 +206,7 @@ void IHyprLayout::onMouseMove(const Vector2D& mousePos) { if (PMONITOR) { DRAGGINGWINDOW->m_iMonitorID = PMONITOR->ID; - - if (DRAGGINGWINDOW->m_iWorkspaceID != PMONITOR->activeWorkspace) { - DRAGGINGWINDOW->m_iWorkspaceID = PMONITOR->activeWorkspace; - - auto PWORKSPACE = g_pCompositor->getWorkspaceByID(DRAGGINGWINDOW->m_iWorkspaceID); - if (PWORKSPACE) { - g_pEventManager->postEvent(SHyprIPCEvent{"movewindow", getFormat("%x,%s", DRAGGINGWINDOW, PWORKSPACE->m_szName.c_str())}); - } - } + g_pCompositor->moveWindowToWorkspace(DRAGGINGWINDOW, PMONITOR->activeWorkspace); DRAGGINGWINDOW->updateToplevel(); } @@ -239,7 +231,7 @@ void IHyprLayout::changeWindowFloatingMode(CWindow* pWindow) { if (!TILED) { const auto PNEWMON = g_pCompositor->getMonitorFromVector(pWindow->m_vRealPosition.vec() + pWindow->m_vRealSize.vec() / 2.f); pWindow->m_iMonitorID = PNEWMON->ID; - pWindow->m_iWorkspaceID = PNEWMON->activeWorkspace; + g_pCompositor->moveWindowToWorkspace(pWindow, PNEWMON->activeWorkspace); // save real pos cuz the func applies the default 5,5 mid const auto PSAVEDPOS = pWindow->m_vRealPosition.vec(); diff --git a/src/managers/KeybindManager.cpp b/src/managers/KeybindManager.cpp index c17886ff..7581f643 100644 --- a/src/managers/KeybindManager.cpp +++ b/src/managers/KeybindManager.cpp @@ -629,7 +629,7 @@ void CKeybindManager::moveActiveToWorkspace(std::string args) { OLDWORKSPACE->m_bHasFullscreenWindow = false; - PWINDOW->m_iWorkspaceID = PWORKSPACE->m_iID; + g_pCompositor->moveWindowToWorkspace(PWINDOW, PWORKSPACE->m_iID); PWINDOW->m_iMonitorID = PWORKSPACE->m_iMonitorID; PWINDOW->m_bIsFullscreen = false; @@ -670,8 +670,6 @@ void CKeybindManager::moveActiveToWorkspace(std::string args) { g_pInputManager->refocus(); PWINDOW->updateToplevel(); - - g_pEventManager->postEvent(SHyprIPCEvent{"movewindow", getFormat("%x,%s", PWINDOW, PWORKSPACE->m_szName.c_str())}); } void CKeybindManager::moveActiveToWorkspaceSilent(std::string args) {