From 66064b23cf826a4ea94eb76bf8f8a192df70dda7 Mon Sep 17 00:00:00 2001 From: "Pierre-Loup A. Griffais" Date: Sun, 12 Sep 2021 23:39:34 -0700 Subject: [PATCH] steamcompmgr: don't always warp cursor on mouse input focus change --- src/steamcompmgr.cpp | 5 ++--- src/wlserver.cpp | 15 ++++++++++++--- src/wlserver.hpp | 2 +- 3 files changed, 15 insertions(+), 7 deletions(-) diff --git a/src/steamcompmgr.cpp b/src/steamcompmgr.cpp index 9547964..1ea9ad3 100644 --- a/src/steamcompmgr.cpp +++ b/src/steamcompmgr.cpp @@ -1782,7 +1782,7 @@ found: wlserver_lock(); if ( inputFocus->surface.wlr != nullptr ) - wlserver_mousefocus( inputFocus->surface.wlr ); + wlserver_mousefocus( inputFocus->surface.wlr, cursor->x(), cursor->y() ); if ( keyboardFocusWin->surface.wlr != nullptr ) wlserver_keyboardfocus( keyboardFocusWin->surface.wlr ); @@ -1796,8 +1796,7 @@ found: currentInputFocusMode = inputFocus->inputFocusMode; currentKeyboardFocusWindow = keyboardFocusWin->id; - // at some point make wlserver_mousefocus smarter with preserving pointer position - // for now hide the jarring warp and possible image change in case cursor was still on screen + // cursor is likely not interactable anymore in its original context, hide cursor->hide(); } diff --git a/src/wlserver.cpp b/src/wlserver.cpp index 4502575..5bc6423 100644 --- a/src/wlserver.cpp +++ b/src/wlserver.cpp @@ -790,11 +790,20 @@ void wlserver_key( uint32_t key, bool press, uint32_t time ) wlr_seat_keyboard_notify_key( wlserver.wlr.seat, time, key, press ); } -void wlserver_mousefocus( struct wlr_surface *wlrsurface ) +void wlserver_mousefocus( struct wlr_surface *wlrsurface, int x /* = 0 */, int y /* = 0 */ ) { wlserver.mouse_focus_surface = wlrsurface; - wlserver.mouse_surface_cursorx = wlrsurface->current.width / 2.0; - wlserver.mouse_surface_cursory = wlrsurface->current.height / 2.0; + + if ( x < wlrsurface->current.width && y < wlrsurface->current.height ) + { + wlserver.mouse_surface_cursorx = x; + wlserver.mouse_surface_cursory = y; + } + else + { + wlserver.mouse_surface_cursorx = wlrsurface->current.width / 2.0; + wlserver.mouse_surface_cursory = wlrsurface->current.height / 2.0; + } wlr_seat_pointer_notify_enter( wlserver.wlr.seat, wlrsurface, wlserver.mouse_surface_cursorx, wlserver.mouse_surface_cursory ); } diff --git a/src/wlserver.hpp b/src/wlserver.hpp index 6475969..c8a362d 100644 --- a/src/wlserver.hpp +++ b/src/wlserver.hpp @@ -84,7 +84,7 @@ void wlserver_unlock(void); void wlserver_keyboardfocus( struct wlr_surface *surface ); void wlserver_key( uint32_t key, bool press, uint32_t time ); -void wlserver_mousefocus( struct wlr_surface *wlrsurface ); +void wlserver_mousefocus( struct wlr_surface *wlrsurface, int x = 0, int y = 0 ); void wlserver_mousemotion( int x, int y, uint32_t time ); void wlserver_mousebutton( int button, bool press, uint32_t time ); void wlserver_mousewheel( int x, int y, uint32_t time );