From b884544ee63b4c3b3b150ff69cf24c90058c2777 Mon Sep 17 00:00:00 2001 From: vaxerski Date: Wed, 13 Sep 2023 11:33:36 +0100 Subject: [PATCH] input: don't refocus on switched workspace on the same monitor --- src/managers/KeybindManager.cpp | 12 ++++-------- src/managers/input/InputManager.cpp | 19 ++++++++++++++++++- src/managers/input/InputManager.hpp | 1 + 3 files changed, 23 insertions(+), 9 deletions(-) diff --git a/src/managers/KeybindManager.cpp b/src/managers/KeybindManager.cpp index b86a2844..e8bb3e74 100644 --- a/src/managers/KeybindManager.cpp +++ b/src/managers/KeybindManager.cpp @@ -801,7 +801,6 @@ void CKeybindManager::changeworkspace(std::string args) { // the current workspace will instead switch to the previous. static auto* const PBACKANDFORTH = &g_pConfigManager->getConfigValuePtr("binds:workspace_back_and_forth")->intValue; static auto* const PALLOWWORKSPACECYCLES = &g_pConfigManager->getConfigValuePtr("binds:allow_workspace_cycles")->intValue; - static auto* const PFOLLOWMOUSE = &g_pConfigManager->getConfigValuePtr("input:follow_mouse")->intValue; const auto PMONITOR = g_pCompositor->m_pLastMonitor; const auto PCURRENTWORKSPACE = g_pCompositor->getWorkspaceByID(PMONITOR->activeWorkspace); @@ -871,10 +870,7 @@ void CKeybindManager::changeworkspace(std::string args) { } else pWorkspaceToChangeTo->rememberPrevWorkspace(PCURRENTWORKSPACE); - if (auto PLASTWINDOW = pWorkspaceToChangeTo->getLastFocusedWindow(); PLASTWINDOW && *PFOLLOWMOUSE == 1) - g_pCompositor->warpCursorTo(PLASTWINDOW->middle()); - - g_pInputManager->simulateMouseMovement(); + g_pInputManager->sendMotionEventsToFocused(); } void CKeybindManager::fullscreenActive(std::string args) { @@ -1964,9 +1960,9 @@ void CKeybindManager::moveWindowIntoGroup(CWindow* pWindow, CWindow* pWindowInDi } void CKeybindManager::moveWindowOutOfGroup(CWindow* pWindow, const std::string& dir) { - static auto* const BFOCUSREMOVEDWINDOW = &g_pConfigManager->getConfigValuePtr("misc:group_focus_removed_window")->intValue; - const auto PWINDOWPREV = pWindow->getGroupPrevious(); - eDirection direction; + static auto* const BFOCUSREMOVEDWINDOW = &g_pConfigManager->getConfigValuePtr("misc:group_focus_removed_window")->intValue; + const auto PWINDOWPREV = pWindow->getGroupPrevious(); + eDirection direction; switch (dir[0]) { case 't': diff --git a/src/managers/input/InputManager.cpp b/src/managers/input/InputManager.cpp index dbd40bef..6b0841f5 100644 --- a/src/managers/input/InputManager.cpp +++ b/src/managers/input/InputManager.cpp @@ -45,6 +45,23 @@ void CInputManager::simulateMouseMovement() { m_tmrLastCursorMovement.reset(); } +void CInputManager::sendMotionEventsToFocused() { + if (!g_pCompositor->m_pLastFocus) + return; + + // todo: this sucks ass + const auto PWINDOW = g_pCompositor->getWindowFromSurface(g_pCompositor->m_pLastFocus); + const auto PLS = g_pCompositor->getLayerSurfaceFromSurface(g_pCompositor->m_pLastFocus); + + timespec now; + clock_gettime(CLOCK_MONOTONIC, &now); + + const auto LOCAL = getMouseCoordsInternal() - (PWINDOW ? PWINDOW->m_vRealPosition.goalv() : (PLS ? Vector2D{PLS->geometry.x, PLS->geometry.y} : Vector2D{})); + + wlr_seat_pointer_notify_enter(g_pCompositor->m_sSeat.seat, g_pCompositor->m_pLastFocus, LOCAL.x, LOCAL.y); + wlr_seat_pointer_notify_motion(g_pCompositor->m_sSeat.seat, now.tv_sec * 1000 + now.tv_nsec / 10000000, LOCAL.x, LOCAL.y); +} + void CInputManager::mouseMoveUnified(uint32_t time, bool refocus) { static auto* const PFOLLOWMOUSE = &g_pConfigManager->getConfigValuePtr("input:follow_mouse")->intValue; static auto* const PMOUSEREFOCUS = &g_pConfigManager->getConfigValuePtr("input:mouse_refocus")->intValue; @@ -1569,7 +1586,7 @@ void CInputManager::setCursorIconOnBorder(CWindow* w) { wlr_box box = {w->m_vRealPosition.vec().x, w->m_vRealPosition.vec().y, w->m_vRealSize.vec().x, w->m_vRealSize.vec().y}; eBorderIconDirection direction = BORDERICON_NONE; wlr_box boxFullGrabInput = {box.x - *PEXTENDBORDERGRAB - BORDERSIZE, box.y - *PEXTENDBORDERGRAB - BORDERSIZE, box.width + 2 * (*PEXTENDBORDERGRAB + BORDERSIZE), - box.height + 2 * (*PEXTENDBORDERGRAB + BORDERSIZE)}; + box.height + 2 * (*PEXTENDBORDERGRAB + BORDERSIZE)}; if (!wlr_box_contains_point(&boxFullGrabInput, mouseCoords.x, mouseCoords.y) || (!m_lCurrentlyHeldButtons.empty() && !currentlyDraggedWindow)) { direction = BORDERICON_NONE; diff --git a/src/managers/input/InputManager.hpp b/src/managers/input/InputManager.hpp index a5f38947..323be307 100644 --- a/src/managers/input/InputManager.hpp +++ b/src/managers/input/InputManager.hpp @@ -88,6 +88,7 @@ class CInputManager { Vector2D getMouseCoordsInternal(); void refocus(); void simulateMouseMovement(); + void sendMotionEventsToFocused(); void setKeyboardLayout(); void setPointerConfigs();