diff --git a/src/Compositor.cpp b/src/Compositor.cpp index e6a39c7b..f698f05a 100644 --- a/src/Compositor.cpp +++ b/src/Compositor.cpp @@ -1874,7 +1874,7 @@ void CCompositor::warpCursorTo(const Vector2D& pos) { const auto PMONITORNEW = getMonitorFromVector(pos); if (PMONITORNEW != m_pLastMonitor) - m_pLastMonitor = PMONITORNEW; + setActiveMonitor(PMONITORNEW); } SLayerSurface* CCompositor::getLayerSurfaceFromWlr(wlr_layer_surface_v1* pLS) { @@ -1987,3 +1987,13 @@ CWorkspace* CCompositor::createNewWorkspace(const int& id, const int& monid, con return PWORKSPACE; } + +void CCompositor::setActiveMonitor(CMonitor* pMonitor) { + if (m_pLastMonitor == pMonitor) + return; + + const auto PWORKSPACE = getWorkspaceByID(pMonitor->activeWorkspace); + + g_pEventManager->postEvent(SHyprIPCEvent{"focusedmon", pMonitor->szName + "," + PWORKSPACE->m_szName}); + m_pLastMonitor = pMonitor; +} diff --git a/src/Compositor.hpp b/src/Compositor.hpp index c5cc5127..9cf73acc 100644 --- a/src/Compositor.hpp +++ b/src/Compositor.hpp @@ -169,6 +169,7 @@ public: void forceReportSizesToWindowsOnWorkspace(const int&); bool cursorOnReservedArea(); CWorkspace* createNewWorkspace(const int&, const int&, const std::string& name = ""); // will be deleted next frame if left empty and unfocused! + void setActiveMonitor(CMonitor*); std::string explicitConfigPath; diff --git a/src/helpers/Monitor.cpp b/src/helpers/Monitor.cpp index 76150f9b..cae53904 100644 --- a/src/helpers/Monitor.cpp +++ b/src/helpers/Monitor.cpp @@ -130,16 +130,16 @@ void CMonitor::onConnect(bool noRule) { forceFullFrames = 3; // force 3 full frames to make sure there is no blinking due to double-buffering. // + g_pEventManager->postEvent(SHyprIPCEvent{"monitoradded", szName}); + if (!g_pCompositor->m_pLastMonitor) // set the last monitor if it isnt set yet - g_pCompositor->m_pLastMonitor = this; + g_pCompositor->setActiveMonitor(this); wlr_xcursor_manager_load(g_pCompositor->m_sWLRXCursorMgr, scale); g_pHyprRenderer->arrangeLayersForMonitor(ID); g_pLayoutManager->getCurrentLayout()->recalculateMonitor(ID); - g_pEventManager->postEvent(SHyprIPCEvent{"monitoradded", szName}); - // ensure VRR (will enable if necessary) g_pConfigManager->ensureVRR(this); } @@ -161,7 +161,7 @@ void CMonitor::onDisconnect() { } if (g_pCompositor->m_pLastMonitor == this) - g_pCompositor->m_pLastMonitor = BACKUPMON; + g_pCompositor->setActiveMonitor(BACKUPMON); // remove mirror if (pMirrorOf) { @@ -365,6 +365,6 @@ void CMonitor::setMirror(const std::string& mirrorOf) { g_pCompositor->m_vMonitors.erase(std::remove_if(g_pCompositor->m_vMonitors.begin(), g_pCompositor->m_vMonitors.end(), [&](const auto& other) { return other.get() == this; })); } - g_pCompositor->m_pLastMonitor = g_pCompositor->m_vMonitors.front().get(); + g_pCompositor->setActiveMonitor(g_pCompositor->m_vMonitors.front().get()); } } diff --git a/src/managers/KeybindManager.cpp b/src/managers/KeybindManager.cpp index 1b8a010f..a129ac59 100644 --- a/src/managers/KeybindManager.cpp +++ b/src/managers/KeybindManager.cpp @@ -756,14 +756,8 @@ void CKeybindManager::changeworkspace(std::string args) { // If the monitor is not the one our cursor's at, warp to it. const bool anotherMonitor = PMONITOR != g_pCompositor->m_pLastMonitor; - if (anotherMonitor) { - Vector2D middle = PMONITOR->vecPosition + PMONITOR->vecSize / 2.f; - g_pCompositor->warpCursorTo(middle); - - // event for focusedmon, as we changed. - g_pEventManager->postEvent(SHyprIPCEvent{"focusedmon", PMONITOR->szName + "," + PWORKSPACETOCHANGETO->m_szName}); - g_pCompositor->m_pLastMonitor = PMONITOR; - } + if (anotherMonitor) + g_pCompositor->warpCursorTo(PMONITOR->vecPosition + PMONITOR->vecSize / 2.f); // set active and deactivate all other in wlr g_pCompositor->deactivateAllWLRWorkspaces(PWORKSPACETOCHANGETO->m_pWlrHandle); @@ -788,7 +782,7 @@ void CKeybindManager::changeworkspace(std::string args) { g_pInputManager->refocus(); // set the new monitor as the last (no warps would bug otherwise) - g_pCompositor->m_pLastMonitor = g_pCompositor->getMonitorFromID(PWORKSPACETOCHANGETO->m_iMonitorID); + g_pCompositor->setActiveMonitor(g_pCompositor->getMonitorFromID(PWORKSPACETOCHANGETO->m_iMonitorID)); // mark the monitor dirty g_pHyprRenderer->damageMonitor(PMONITOR); @@ -812,7 +806,7 @@ void CKeybindManager::changeworkspace(std::string args) { const auto PWORKSPACE = g_pCompositor->createNewWorkspace(workspaceToChangeTo, PMONITOR->ID, workspaceName); - const bool ANOTHERMONITOR = PMONITOR == g_pCompositor->m_pLastMonitor; + const bool ANOTHERMONITOR = PMONITOR != g_pCompositor->m_pLastMonitor; if (!isSwitchingToPrevious) // Remember previous workspace. @@ -846,21 +840,16 @@ void CKeybindManager::changeworkspace(std::string args) { if (g_pCompositor->m_pLastMonitor != PMONITOR) g_pCompositor->warpCursorTo(PMONITOR->vecPosition + PMONITOR->vecSize / 2.f); - g_pCompositor->m_pLastMonitor = PMONITOR; + g_pEventManager->postEvent(SHyprIPCEvent{"workspace", PWORKSPACE->m_szName}); + + g_pCompositor->setActiveMonitor(PMONITOR); // focus (clears the last) g_pInputManager->refocus(); // Events - g_pEventManager->postEvent(SHyprIPCEvent{"workspace", PWORKSPACE->m_szName}); - if (ANOTHERMONITOR) { - Vector2D middle = PMONITOR->vecPosition + PMONITOR->vecSize / 2.f; - g_pCompositor->warpCursorTo(middle); - - // event for focusedmon, as we changed. - g_pEventManager->postEvent(SHyprIPCEvent{"focusedmon", PMONITOR->szName + "," + PWORKSPACE->m_szName}); - g_pCompositor->m_pLastMonitor = PMONITOR; - } + if (ANOTHERMONITOR) + g_pCompositor->warpCursorTo(PMONITOR->vecPosition + PMONITOR->vecSize / 2.f); Debug::log(LOG, "Changed to workspace %i", workspaceToChangeTo); } @@ -1074,10 +1063,8 @@ void CKeybindManager::moveFocusTo(std::string args) { if (PLASTWINDOW->m_iMonitorID != PWINDOWTOCHANGETO->m_iMonitorID) { // event const auto PNEWMON = g_pCompositor->getMonitorFromID(PWINDOWTOCHANGETO->m_iMonitorID); - const auto PNEWWS = g_pCompositor->getWorkspaceByID(PNEWMON->activeWorkspace); - g_pEventManager->postEvent(SHyprIPCEvent{"focusedmon", PNEWMON->szName + "," + PNEWWS->m_szName}); - g_pCompositor->m_pLastMonitor = PNEWMON; + g_pCompositor->setActiveMonitor(PNEWMON); } } }; diff --git a/src/managers/input/InputManager.cpp b/src/managers/input/InputManager.cpp index c95fd910..ed96cb64 100644 --- a/src/managers/input/InputManager.cpp +++ b/src/managers/input/InputManager.cpp @@ -123,15 +123,12 @@ void CInputManager::mouseMoveUnified(uint32_t time, bool refocus) { g_pLayoutManager->getCurrentLayout()->onMouseMove(getMouseCoordsInternal()); if (PMONITOR && PMONITOR != g_pCompositor->m_pLastMonitor) { - g_pCompositor->m_pLastMonitor = PMONITOR; + g_pCompositor->setActiveMonitor(PMONITOR); // set active workspace and deactivate all other in wlr const auto ACTIVEWORKSPACE = g_pCompositor->getWorkspaceByID(PMONITOR->activeWorkspace); g_pCompositor->deactivateAllWLRWorkspaces(ACTIVEWORKSPACE->m_pWlrHandle); ACTIVEWORKSPACE->setActive(true); - - // event - g_pEventManager->postEvent(SHyprIPCEvent{"focusedmon", PMONITOR->szName + "," + ACTIVEWORKSPACE->m_szName}); } // overlay is above fullscreen