input: don't refocus on switched workspace on the same monitor

This commit is contained in:
Vaxry 2023-09-13 11:33:36 +01:00
parent 6b1ac659e0
commit b884544ee6
3 changed files with 23 additions and 9 deletions

View file

@ -801,7 +801,6 @@ void CKeybindManager::changeworkspace(std::string args) {
// the current workspace will instead switch to the previous. // 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 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 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 PMONITOR = g_pCompositor->m_pLastMonitor;
const auto PCURRENTWORKSPACE = g_pCompositor->getWorkspaceByID(PMONITOR->activeWorkspace); const auto PCURRENTWORKSPACE = g_pCompositor->getWorkspaceByID(PMONITOR->activeWorkspace);
@ -871,10 +870,7 @@ void CKeybindManager::changeworkspace(std::string args) {
} else } else
pWorkspaceToChangeTo->rememberPrevWorkspace(PCURRENTWORKSPACE); pWorkspaceToChangeTo->rememberPrevWorkspace(PCURRENTWORKSPACE);
if (auto PLASTWINDOW = pWorkspaceToChangeTo->getLastFocusedWindow(); PLASTWINDOW && *PFOLLOWMOUSE == 1) g_pInputManager->sendMotionEventsToFocused();
g_pCompositor->warpCursorTo(PLASTWINDOW->middle());
g_pInputManager->simulateMouseMovement();
} }
void CKeybindManager::fullscreenActive(std::string args) { void CKeybindManager::fullscreenActive(std::string args) {

View file

@ -45,6 +45,23 @@ void CInputManager::simulateMouseMovement() {
m_tmrLastCursorMovement.reset(); 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) { void CInputManager::mouseMoveUnified(uint32_t time, bool refocus) {
static auto* const PFOLLOWMOUSE = &g_pConfigManager->getConfigValuePtr("input:follow_mouse")->intValue; static auto* const PFOLLOWMOUSE = &g_pConfigManager->getConfigValuePtr("input:follow_mouse")->intValue;
static auto* const PMOUSEREFOCUS = &g_pConfigManager->getConfigValuePtr("input:mouse_refocus")->intValue; static auto* const PMOUSEREFOCUS = &g_pConfigManager->getConfigValuePtr("input:mouse_refocus")->intValue;

View file

@ -88,6 +88,7 @@ class CInputManager {
Vector2D getMouseCoordsInternal(); Vector2D getMouseCoordsInternal();
void refocus(); void refocus();
void simulateMouseMovement(); void simulateMouseMovement();
void sendMotionEventsToFocused();
void setKeyboardLayout(); void setKeyboardLayout();
void setPointerConfigs(); void setPointerConfigs();