fix(input): make a hardware mouse and keyboard work like a PC (#2053)

* feat(gamescope): a three way switch for relative mouse motion

Games that confine the cursor and warp it back to read movement never
reach the nested hints rule, so their aim stays bounded by the screen.
The convar defaults to 0 and leaves that rule alone; 1 forces relative
motion for the focused game, 2 keeps the pointer absolute even when the
rule would apply.

(cherry picked from commit db3d7555e0)

* feat(input): the session carries a relative mouse mode per game

Reads the mode from the game's gesture config, hands it to gamescope as
gamescope_relative_mouse, and pushes a change to the running session
through gamescopectl.

(cherry picked from commit e350d88464)

* feat(drawer): the relative mouse switch is a three way choice

Auto leaves it to the game, on forces relative motion, off keeps the
pointer absolute. Named in all 32 locales so none of the three falls
back to English.

(cherry picked from commit e96a187e02)

* fix(input): follow the focused game's relative mouse mode

Switching to a game whose saved mode differs left the session on the
previous game's mode, since only the drawer state was refreshed. The
requests also ran on a thread per selection, so two quick picks could
reach gamescope out of order.

(cherry picked from commit 7ff8c5d568)

* fix(input): retry the relative mouse mode gamescope did not take

The drawer state moved before the request ran, so a failed request left
the two out of step and the next focus change skipped the resend.

(cherry picked from commit cf0f82d8cd)

* fix(input): the relative mouse mode tracks the latest choice

The guest agent answers ok when it handled the exec, so a failing
gamescopectl was recorded as applied. Reconcile the newest desired mode
on the worker thread after each request, and only mark applied when the
command really exited zero.

(cherry picked from commit 5f5e3bd52e)

* gamescope: a hidden cursor under any pointer constraint is relative

Games that hide the cursor and confine the pointer had no lock hint, so the
nested pointer stayed absolute and the camera froze.

* Treat a hardware mouse as a real mouse in sessions

A mouse now moves the guest pointer by relative motion for the whole session
through pointer capture, so it no longer stops at screen edges or reaches
system gestures. Its cursor stays visible in every touch mode, follows the
game showing or hiding it, and clicks no longer press on-screen controls.

* gamescope: use the mouse test release

* Direct touch turns the camera while a game holds the pointer

A swipe in direct touch now sends relative motion when a game has the pointer
locked, including when the lock starts during the swipe, as when a game
hides the cursor while a button is held.

* Address review findings on mouse and touch input

Keep touchpad taps on on-screen controls, cancel a pending long press during a
locked swipe, let the three-finger gesture cancel a locked swipe, refresh
capture when the output changes, and use the menu's key for the relative
mouse setting.

* Keep locked touches inside the game picture and free the mouse in touch editors

* End touch editor ownership when the editor goes away

* Bring the mouse cursor back when a touch editor closes

* Release a pointer lock at the game's pointer

* gamescope: use the pointer position test release

* Fit the X screen to a fullscreen window larger than it

* gamescope: use the X screen fit test release

* Return the X screen when no game window has focus

* gamescope: use the X screen return test release

* ci: avoid redundant gamescope builds

* fix: hardware mouse in Desktop and pointer warping games

KWin nested on the host only reads relative motion while its own pointer lock is on, so a program that locked the pointer in Desktop (Blender orbit and pan) stopped receiving motion. A captured hardware mouse now turns that lock on, and a real Right Ctrl no longer toggles it.

Gamescope follows a game's pointer warps instead of overriding them, and absolute motion also sends raw motion. Also retries relative mouse requests, tidies the unplug path, passes side buttons and fits a second oversized window correctly.

* chore: use the gamescope build with patch 0131

* fix: Desktop mouse lock keeps retrying after early attempts fail

* fix: hold the key that turns on the Desktop mouse lock

KWin ignores a press and release delivered together.

* fix: gamescope enters warp following sooner and keeps steady motion

* chore: use gamescope p26

* Capture system keys in a focused session and keep the first Desktop mouse motion in place

* Use the p27 gamescope build

* Update the system keys row test

* Recognise a captured mouse so the Desktop grab can start

* Keep touch warps out of relative motion

* Send Esc from keyboards that report it as Back

* Use the p28 gamescope build

* Release captured keys on pause, forward motion during a grab and wait for a pending screen fit

* Use the p29 gamescope build

* fix(input): keep held system keys consumed until they are released

Copy each captured key event, since the service owns the original only for the callback, and consume the physical release of a key already released to the guest.

Use the published gamescope p20.

* fix(input): capture a system key only from its first press

---------

Co-authored-by: kingokksa <kingokksa@qq.com>
Co-authored-by: maxjivi05 <6025299+maxjivi05@users.noreply.github.com>
This commit is contained in:
authored and GitHub committed 2026-11-04 13:27:08 -05:00
1 parent eed9edaa1c
commit 5cf69732ef
56 files changed
+1210 -212

No files matched your search

+35
View File
@@ -225,3 +225,38 @@ PropertyNotify, and it listens for those from map on, so the style Wine sets bef
was never known; `map_win` now reads it with the other properties, which the layered-launcher and
Xalia rules rely on too. `tools/tests/test_gamescope_override_stacking.py` compiles the rule from
this patch.
## 0127 steamcompmgr: a three way relative mouse switch
`relative_mouse` is read where the decision is made: 0 leaves it to the rule below, 1 forces relative
motion for the focused game except Steam's own windows and composites the cursor, 2 never goes relative.
For games that confine a visible cursor and warp it, which the automatic rule cannot see.
## 0128 steamcompmgr: a hidden cursor under any pointer constraint is relative
The rule only counted a lock with a cursor position hint. A game that hides the cursor and confines the
pointer through a grab (Wine's ClipCursor) has a constraint with no hint, so the nested pointer stayed
absolute, the constraint held the X pointer still and no raw motion was produced: the camera froze.
## 0129 steamcompmgr, wayland: release a pointer lock at the game's pointer
A game can move the X pointer while it holds the lock (Wine's ClipCursor recentres it), and the nested host
never hears about it. On unlock the host's next absolute motion dropped the pointer back at its old position,
often near a corner. The unlock now sends the X pointer as a cursor position hint and commits it first. A cursor
forced On by `relative_mouse` also stays visible while idle, since the host cursor is hidden during the lock.
## 0130 steamcompmgr: fit the X screen to a larger fullscreen window
A game can open a fullscreen window larger than its X screen (Valheim at 1366x768 on 1280x720). The X server
keeps the pointer inside the screen, so the outer part of the window could not be reached and motion past the
edge had to be undone. The server's mode now follows such a window, and returns once the focused window fits,
focus moves to Steam or no window has focus.
## 0131 steamcompmgr, wlserver: follow a game's pointer warps
Under a nested host the seat's absolute position came from the host, so a game that warped a visible X pointer
to the screen centre read the distance back to the host's position on the next motion, and the view spun. When
the X pointer stays far from the seat position while input moves, gamescope takes the host's lock and applies
each frame's motion to the X pointer itself until the game stops warping. Absolute motion also sends relative
motion, as a real compositor does, so XInput2 raw motion reaches games that read only that. A touch moves the
pointer without relative motion, so tapping the screen does not turn the camera.
@@ -0,0 +1,30 @@
--- a/src/steamcompmgr.cpp
+++ b/src/steamcompmgr.cpp
@@ -3062,8 +3062,13 @@
#endif
gamescope::ConVar<int> cv_cursor_composite{ "cursor_composite", 1, "0 = Never composite a cursor. 1 = Composite cursor when not nested. 2 = Always composite a cursor manually" };
+static gamescope::ConVar<int> cv_relative_mouse( "relative_mouse", 0,
+"0 = Leave it to the game and the nested hints. 1 = Send host pointer motion as relative movement, for games that confine the cursor and warp it back to read movement. 2 = Never go relative." );
bool ShouldDrawCursor()
{
+ if ( cv_relative_mouse.Get() == 1 )
+ return true;
+
global_focus_t *pFocus = GetCurrentFocus();
gamescope::INestedHints *pNestedHints = pFocus ? pFocus->GetNestedHints() : nullptr;
return gamescope::CursorShouldBeComposited( cv_cursor_composite.Get(), g_bForceRelativeMouse,
@@ -10810,7 +10815,12 @@
const bool bExcludedAppId = uAppId && gamescope::Algorithm::Contains( s_uRelativeMouseFilteredAppids, uAppId );
- const bool bRelativeMouseMode = bImageEmpty && bHasPointerConstraint && !bExcludedAppId;
+ const int nRelativeMouse = cv_relative_mouse.Get();
+ const bool bForcedRelativeMouse = nRelativeMouse == 1 && !window_is_steam( pPaintFocus->inputFocusWindow );
+
+ const bool bRelativeMouseMode = nRelativeMouse == 2
+ ? false
+ : ( bForcedRelativeMouse || ( bImageEmpty && bHasPointerConstraint && !bExcludedAppId ) );
pPaintFocus->GetNestedHints()->SetRelativeMouseMode( bRelativeMouseMode );
}
@@ -0,0 +1,12 @@
--- a/src/steamcompmgr.cpp
+++ b/src/steamcompmgr.cpp
@@ -10804,7 +10804,8 @@
( pPaintFocus->cursor && pPaintFocus->cursor->imageEmpty() ) &&
( !window_is_steam( pPaintFocus->inputFocusWindow ) );
- const bool bHasPointerConstraint = pPaintFocus->cursor && pPaintFocus->cursor->IsConstrained();
+ const bool bHasPointerConstraint = pPaintFocus->cursor &&
+ ( pPaintFocus->cursor->IsConstrained() || wlserver.HasMouseConstraint() );
uint32_t uAppId = pPaintFocus->inputFocusWindow
? pPaintFocus->inputFocusWindow->appID
@@ -0,0 +1,145 @@
diff --git a/src/Backends/WaylandBackend.cpp b/src/Backends/WaylandBackend.cpp
index 953765a..572fb0e 100644
--- a/src/Backends/WaylandBackend.cpp
+++ b/src/Backends/WaylandBackend.cpp
@@ -464,6 +464,7 @@ namespace gamescope
virtual void SetCursorImage( std::shared_ptr<INestedHints::CursorInfo> info ) override;
virtual void SetRelativeMouseMode( bool bRelative ) override;
+ virtual void SetCursorPositionHint( double flX, double flY ) override;
virtual void SetVisible( bool bVisible ) override;
virtual void SetTitle( std::shared_ptr<std::string> szTitle ) override;
virtual void SetIcon( std::shared_ptr<std::vector<uint32_t>> uIconPixels ) override;
@@ -719,6 +720,7 @@ namespace gamescope
void SetCursorImage( std::shared_ptr<INestedHints::CursorInfo> info );
void SetRelativeMouseMode( wl_surface *pSurface, bool bRelative );
+ void SetCursorPositionHint( wl_fixed_t fSurfaceX, wl_fixed_t fSurfaceY );
void UpdateCursor();
friend CWaylandConnector;
@@ -1270,6 +1272,16 @@ namespace gamescope
// TODO: Do more tracking across multiple connectors, and activity here if we ever want to use this.
m_pBackend->SetRelativeMouseMode( m_Planes[0].GetSurface(), bRelative );
}
+ void CWaylandConnector::SetCursorPositionHint( double flX, double flY )
+ {
+ auto oState = m_Planes[0].GetCurrentState();
+ if ( !oState || !oState->uFractionalScale )
+ return;
+
+ const double flSurfaceX = ( flX * g_nOutputWidth - oState->nDestX ) * 120.0 / oState->uFractionalScale;
+ const double flSurfaceY = ( flY * g_nOutputHeight - oState->nDestY ) * 120.0 / oState->uFractionalScale;
+ m_pBackend->SetCursorPositionHint( wl_fixed_from_double( flSurfaceX ), wl_fixed_from_double( flSurfaceY ) );
+ }
void CWaylandConnector::SetVisible( bool bVisible )
{
if ( m_bVisible == bVisible )
@@ -2484,6 +2496,15 @@ namespace gamescope
UpdateCursor();
}
+ void CWaylandBackend::SetCursorPositionHint( wl_fixed_t fSurfaceX, wl_fixed_t fSurfaceY )
+ {
+ if ( !m_pLockedPointer )
+ return;
+
+ zwp_locked_pointer_v1_set_cursor_position_hint( m_pLockedPointer, fSurfaceX, fSurfaceY );
+ wl_surface_commit( m_pLockedSurface );
+ }
+
void CWaylandBackend::SetRelativeMouseMode( wl_surface *pSurface, bool bRelative )
{
if ( !m_pPointer )
diff --git a/src/backend.h b/src/backend.h
index d264917..37b936e 100644
--- a/src/backend.h
+++ b/src/backend.h
@@ -271,6 +271,7 @@ namespace gamescope
virtual void SetCursorImage( std::shared_ptr<CursorInfo> info ) = 0;
virtual void SetRelativeMouseMode( bool bRelative ) = 0;
+ virtual void SetCursorPositionHint( double flX, double flY ) {}
virtual void SetVisible( bool bVisible ) = 0;
virtual void SetTitle( std::shared_ptr<std::string> szTitle ) = 0;
virtual void SetIcon( std::shared_ptr<std::vector<uint32_t>> uIconPixels ) = 0;
diff --git a/src/steamcompmgr.cpp b/src/steamcompmgr.cpp
index f1346e5..2c92afe 100644
--- a/src/steamcompmgr.cpp
+++ b/src/steamcompmgr.cpp
@@ -2078,6 +2078,18 @@ void MouseCursor::UpdatePosition()
}
}
+void MouseCursor::QueryRootPosition( int *pX, int *pY )
+{
+ Window root_ret, child_ret;
+ int win_x = 0, win_y = 0;
+ unsigned int mask;
+ *pX = m_x;
+ *pY = m_y;
+ XQueryPointer( m_ctx->dpy, DefaultRootWindow( m_ctx->dpy ), &root_ret, &child_ret, pX, pY, &win_x, &win_y, &mask );
+}
+
+static bool relative_mouse_forced();
+
void MouseCursor::checkSuspension()
{
getTexture();
@@ -2085,7 +2097,12 @@ void MouseCursor::checkSuspension()
if ( ShouldDrawCursor() )
{
const bool suspended = int64_t( get_time_in_nanos() ) - int64_t( wlserver.ulLastMovedCursorTime ) > int64_t( cursorHideTime );
- if (!wlserver.bCursorHidden && suspended) {
+ if ( relative_mouse_forced() && wlserver.bCursorHidden )
+ {
+ wlserver.bCursorHidden = false;
+ hasRepaintNonBasePlane = true;
+ }
+ if (!wlserver.bCursorHidden && suspended && !relative_mouse_forced()) {
wlserver.bCursorHidden = true;
steamcompmgr_win_t *window = m_ctx->focus.inputFocusWindow;
@@ -3064,6 +3081,11 @@ static void paint_pipewire()
gamescope::ConVar<int> cv_cursor_composite{ "cursor_composite", 1, "0 = Never composite a cursor. 1 = Composite cursor when not nested. 2 = Always composite a cursor manually" };
static gamescope::ConVar<int> cv_relative_mouse( "relative_mouse", 0,
"0 = Leave it to the game and the nested hints. 1 = Send host pointer motion as relative movement, for games that confine the cursor and warp it back to read movement. 2 = Never go relative." );
+static bool relative_mouse_forced()
+{
+ return cv_relative_mouse.Get() == 1;
+}
+
bool ShouldDrawCursor()
{
if ( cv_relative_mouse.Get() == 1 )
@@ -10828,6 +10850,18 @@ steamcompmgr_main(int argc, char **argv)
? false
: ( bForcedRelativeMouse || ( bImageEmpty && bHasPointerConstraint && !bExcludedAppId ) );
+ static bool s_bRelativeMouseMode = false;
+ if ( s_bRelativeMouseMode && !bRelativeMouseMode && pPaintFocus->cursor &&
+ g_nOutputWidth && g_nOutputHeight && focusedWindowScaleX > 0.0f && focusedWindowScaleY > 0.0f )
+ {
+ int nRootX, nRootY;
+ pPaintFocus->cursor->QueryRootPosition( &nRootX, &nRootY );
+ pPaintFocus->GetNestedHints()->SetCursorPositionHint(
+ ( nRootX / focusedWindowScaleX - focusedWindowOffsetX ) / g_nOutputWidth,
+ ( nRootY / focusedWindowScaleY - focusedWindowOffsetY ) / g_nOutputHeight );
+ }
+ s_bRelativeMouseMode = bRelativeMouseMode;
+
pPaintFocus->GetNestedHints()->SetRelativeMouseMode( bRelativeMouseMode );
}
diff --git a/src/steamcompmgr.hpp b/src/steamcompmgr.hpp
index 7a7119f..ff54d8e 100644
--- a/src/steamcompmgr.hpp
+++ b/src/steamcompmgr.hpp
@@ -85,6 +85,7 @@ public:
}
void UpdatePosition();
+ void QueryRootPosition( int *pX, int *pY );
bool isHidden() { return wlserver.bCursorHidden || m_imageEmpty; }
bool imageEmpty() const { return m_imageEmpty; }
@@ -0,0 +1,94 @@
diff --git a/src/steamcompmgr.cpp b/src/steamcompmgr.cpp
index 2c92afe..17bae3a 100644
--- a/src/steamcompmgr.cpp
+++ b/src/steamcompmgr.cpp
@@ -4662,6 +4662,49 @@ static void set_wm_state( xwayland_ctx_t *ctx, Window win, uint32_t state )
sizeof(wmState) / sizeof(wmState[0]));
}
+static void
+fit_root_to_focus_window( xwayland_ctx_t *ctx )
+{
+ steamcompmgr_win_t *w = ctx->focus.focusWindow;
+ const bool bGame = w && !window_is_steam( w );
+ const int nWindowX = bGame ? w->xwayland().a.x : 0;
+ const int nWindowY = bGame ? w->xwayland().a.y : 0;
+ const int nWindowWidth = bGame ? w->xwayland().a.width : 0;
+ const int nWindowHeight = bGame ? w->xwayland().a.height : 0;
+ const int nBaseWidth = ctx->nFitRestoreWidth ? ctx->nFitRestoreWidth : ctx->root_width;
+ const int nBaseHeight = ctx->nFitRestoreWidth ? ctx->nFitRestoreHeight : ctx->root_height;
+ const bool bCoversBase = nWindowX == 0 && nWindowY == 0 && nWindowWidth >= nBaseWidth && nWindowHeight >= nBaseHeight;
+ const bool bPlausible = nWindowWidth <= 8192 && nWindowHeight <= 8192;
+
+ int nWidth = 0;
+ int nHeight = 0;
+ if ( bGame && bCoversBase && bPlausible && ( nWindowWidth > nBaseWidth || nWindowHeight > nBaseHeight ) )
+ {
+ if ( !ctx->nFitRestoreWidth )
+ {
+ ctx->nFitRestoreWidth = ctx->root_width;
+ ctx->nFitRestoreHeight = ctx->root_height;
+ }
+ nWidth = nWindowWidth;
+ nHeight = nWindowHeight;
+ }
+ else if ( ctx->nFitRestoreWidth && nWindowWidth <= ctx->nFitRestoreWidth && nWindowHeight <= ctx->nFitRestoreHeight )
+ {
+ nWidth = ctx->nFitRestoreWidth;
+ nHeight = ctx->nFitRestoreHeight;
+ ctx->nFitRestoreWidth = 0;
+ ctx->nFitRestoreHeight = 0;
+ }
+
+ if ( !nWidth || ( nWidth == ctx->root_width && nHeight == ctx->root_height ) )
+ return;
+
+ ctx->bFitPending = true;
+ wlserver_lock();
+ wlserver_set_xwayland_server_mode( ctx->xwayland_server->get_index(), nWidth, nHeight, g_nOutputRefresh );
+ wlserver_unlock();
+}
+
void xwayland_ctx_t::DetermineAndApplyFocus( const std::vector< steamcompmgr_win_t* > &vecPossibleFocusWindows )
{
xwayland_ctx_t *ctx = this;
@@ -4736,6 +4779,8 @@ void xwayland_ctx_t::DetermineAndApplyFocus( const std::vector< steamcompmgr_win
inputFocus = ctx->focus.focusWindow;
}
+ fit_root_to_focus_window( ctx );
+
if ( ctx->focus.focusWindow )
{
if ( prevFocusWindow != ctx->focus.focusWindow )
@@ -5001,7 +5046,7 @@ void xwayland_ctx_t::DetermineAndApplyFocus( const std::vector< steamcompmgr_win
fs_width = ctx->root_width * steam_height_scale;
}
- if ( w->GetGeometry().nWidth != fs_width || w->GetGeometry().nHeight != fs_height || globalScaleRatio != 1.0f )
+ if ( !ctx->bFitPending && ( w->GetGeometry().nWidth != fs_width || w->GetGeometry().nHeight != fs_height || globalScaleRatio != 1.0f ) )
XResizeWindow(ctx->dpy, ctx->focus.focusWindow->xwayland().id, fs_width, fs_height);
}
else
@@ -6232,6 +6277,7 @@ configure_win(xwayland_ctx_t *ctx, XConfigureEvent *ce)
{
if (ce->window == ctx->root)
{
+ ctx->bFitPending = false;
ctx->root_width = ce->width;
ctx->root_height = ce->height;
MakeFocusDirty();
diff --git a/src/xwayland_ctx.hpp b/src/xwayland_ctx.hpp
index 3a75650..15c2e6b 100644
--- a/src/xwayland_ctx.hpp
+++ b/src/xwayland_ctx.hpp
@@ -87,6 +87,9 @@ struct xwayland_ctx_t final : public gamescope::IWaitable
Window ourWindow;
focus_t focus;
+ int nFitRestoreWidth = 0;
+ int nFitRestoreHeight = 0;
+ bool bFitPending = false;
Window currentKeyboardFocusWindow;
Window focusControlWindow;
@@ -0,0 +1,216 @@
diff --git a/src/steamcompmgr.cpp b/src/steamcompmgr.cpp
index 17bae3a..c468fb3 100644
--- a/src/steamcompmgr.cpp
+++ b/src/steamcompmgr.cpp
@@ -32,6 +32,7 @@
#include "backend.h"
#include "gamescope_shared.h"
#include "xwayland_ctx.hpp"
+#include <cmath>
#include <X11/X.h>
#include <X11/Xlib.h>
#include <X11/Xcursor/Xcursor.h>
@@ -2088,6 +2089,7 @@ void MouseCursor::QueryRootPosition( int *pX, int *pY )
XQueryPointer( m_ctx->dpy, DefaultRootWindow( m_ctx->dpy ), &root_ret, &child_ret, pX, pY, &win_x, &win_y, &mask );
}
+static bool s_bFollowClientPointer = false;
static bool relative_mouse_forced();
void MouseCursor::checkSuspension()
@@ -3083,12 +3085,89 @@ static gamescope::ConVar<int> cv_relative_mouse( "relative_mouse", 0,
"0 = Leave it to the game and the nested hints. 1 = Send host pointer motion as relative movement, for games that confine the cursor and warp it back to read movement. 2 = Never go relative." );
static bool relative_mouse_forced()
{
- return cv_relative_mouse.Get() == 1;
+ return cv_relative_mouse.Get() == 1 || s_bFollowClientPointer;
+}
+
+static void update_client_pointer_follow( global_focus_t *pFocus, bool bAllowed )
+{
+ static int s_nAwayFrames = 0;
+ static int s_nQuietFrames = 0;
+ static uint64_t s_ulLastAway = 0;
+ static double s_flLastX = 0.0;
+ static double s_flLastY = 0.0;
+
+ int nRootX = 0;
+ int nRootY = 0;
+ if ( bAllowed && pFocus->cursor )
+ pFocus->cursor->QueryRootPosition( &nRootX, &nRootY );
+ else
+ bAllowed = false;
+
+ wlserver_lock();
+ const double flX = wlserver.mouse_surface_cursorx;
+ const double flY = wlserver.mouse_surface_cursory;
+ if ( !bAllowed )
+ {
+ s_nAwayFrames = 0;
+ s_bFollowClientPointer = false;
+ wlserver.bFollowClientPointer = false;
+ }
+ else if ( !s_bFollowClientPointer )
+ {
+ const bool bMoved = flX != s_flLastX || flY != s_flLastY;
+ if ( bMoved && ( std::abs( nRootX - flX ) > 48.0 || std::abs( nRootY - flY ) > 48.0 ) )
+ {
+ const uint64_t ulNow = get_time_in_nanos();
+ if ( ulNow - s_ulLastAway > 500'000'000ul )
+ s_nAwayFrames = 0;
+ s_ulLastAway = ulNow;
+ s_nAwayFrames++;
+ }
+
+ if ( s_nAwayFrames >= 3 )
+ {
+ s_nAwayFrames = 0;
+ s_nQuietFrames = 0;
+ s_bFollowClientPointer = true;
+ wlserver.bFollowClientPointer = true;
+ wlserver.flFollowDX = 0.0;
+ wlserver.flFollowDY = 0.0;
+ wlserver_mousewarp( nRootX, nRootY, 0, true );
+ }
+ }
+ else
+ {
+ const bool bWarped = std::abs( nRootX - flX ) > 2.0 || std::abs( nRootY - flY ) > 2.0;
+ const double flDX = std::trunc( wlserver.flFollowDX );
+ const double flDY = std::trunc( wlserver.flFollowDY );
+ if ( bWarped )
+ s_nQuietFrames = 0;
+ else if ( flDX != 0.0 || flDY != 0.0 )
+ s_nQuietFrames++;
+
+ if ( flDX != 0.0 || flDY != 0.0 || bWarped )
+ {
+ wlserver.flFollowDX -= flDX;
+ wlserver.flFollowDY -= flDY;
+ wlserver_mousewarp( nRootX, nRootY, 0, true );
+ if ( flDX != 0.0 || flDY != 0.0 )
+ wlserver_mousewarp( nRootX + flDX, nRootY + flDY, 0, true );
+ }
+
+ if ( s_nQuietFrames >= 60 )
+ {
+ s_bFollowClientPointer = false;
+ wlserver.bFollowClientPointer = false;
+ }
+ }
+ s_flLastX = wlserver.mouse_surface_cursorx;
+ s_flLastY = wlserver.mouse_surface_cursory;
+ wlserver_unlock();
}
bool ShouldDrawCursor()
{
- if ( cv_relative_mouse.Get() == 1 )
+ if ( relative_mouse_forced() )
return true;
global_focus_t *pFocus = GetCurrentFocus();
@@ -10892,9 +10971,15 @@ steamcompmgr_main(int argc, char **argv)
const int nRelativeMouse = cv_relative_mouse.Get();
const bool bForcedRelativeMouse = nRelativeMouse == 1 && !window_is_steam( pPaintFocus->inputFocusWindow );
+ if ( vblank )
+ {
+ update_client_pointer_follow( pPaintFocus,
+ nRelativeMouse != 2 && !bExcludedAppId && !bHasPointerConstraint && !window_is_steam( pPaintFocus->inputFocusWindow ) );
+ }
+
const bool bRelativeMouseMode = nRelativeMouse == 2
? false
- : ( bForcedRelativeMouse || ( bImageEmpty && bHasPointerConstraint && !bExcludedAppId ) );
+ : ( bForcedRelativeMouse || s_bFollowClientPointer || ( bImageEmpty && bHasPointerConstraint && !bExcludedAppId ) );
static bool s_bRelativeMouseMode = false;
if ( s_bRelativeMouseMode && !bRelativeMouseMode && pPaintFocus->cursor &&
diff --git a/src/wlserver.cpp b/src/wlserver.cpp
index 5733871..cc75f8a 100644
--- a/src/wlserver.cpp
+++ b/src/wlserver.cpp
@@ -1,3 +1,4 @@
+#include <cmath>
#include <xkbcommon/xkbcommon-keysyms.h>
#define _GNU_SOURCE 1
@@ -3086,6 +3087,16 @@ void wlserver_mousemotion( double dx, double dy, uint32_t time )
wlserver_perform_rel_pointer_motion( dx, dy );
+ if ( wlserver.bFollowClientPointer )
+ {
+ wlserver.flFollowDX += dx;
+ wlserver.flFollowDY += dy;
+ wlserver.ulLastMovedCursorTime = get_time_in_nanos();
+ wlserver.bCursorHidden = !wlserver.bCursorHasImage;
+ wlr_seat_pointer_notify_frame( wlserver.wlr.seat );
+ return;
+ }
+
if ( !wlserver_apply_constraint( &dx, &dy ) )
{
wlr_seat_pointer_notify_frame( wlserver.wlr.seat );
@@ -3110,10 +3121,18 @@ void wlserver_mousemotion( double dx, double dy, uint32_t time )
wlr_seat_pointer_notify_frame( wlserver.wlr.seat );
}
-void wlserver_mousewarp( double x, double y, uint32_t time, bool bSynthetic )
+void wlserver_mousewarp( double x, double y, uint32_t time, bool bSynthetic, bool bFromTouch )
{
assert( wlserver_is_lock_held() );
+ if ( !bSynthetic && wlserver.bFollowClientPointer )
+ return;
+
+ const double flStepX = x - wlserver.mouse_surface_cursorx;
+ const double flStepY = y - wlserver.mouse_surface_cursory;
+ if ( !bSynthetic && !bFromTouch && ( flStepX != 0.0 || flStepY != 0.0 ) && std::abs( flStepX ) < 256.0 && std::abs( flStepY ) < 256.0 )
+ wlserver_perform_rel_pointer_motion( flStepX, flStepY );
+
wlserver.mouse_surface_cursorx = x;
wlserver.mouse_surface_cursory = y;
@@ -3304,7 +3323,7 @@ void wlserver_touchmotion( double x, double y, int touch_id, uint32_t time, bool
{
g_bPendingTouchMovement = true;
- wlserver_mousewarp( tx, ty, time, false );
+ wlserver_mousewarp( tx, ty, time, false, !bAlwaysWarpCursor );
}
}
@@ -3352,7 +3371,7 @@ void wlserver_touchdown( double x, double y, int touch_id, uint32_t time, gamesc
if ( eMode != gamescope::TouchClickModes::Trackpad )
{
- wlserver_mousewarp( tx, ty, time, false );
+ wlserver_mousewarp( tx, ty, time, false, true );
}
uint32_t button = TouchClickModeToLinuxButton( eMode );
diff --git a/src/wlserver.hpp b/src/wlserver.hpp
index 79a0723..ca8d015 100644
--- a/src/wlserver.hpp
+++ b/src/wlserver.hpp
@@ -168,6 +168,9 @@ struct wlserver_t {
uint64_t ulLastMovedCursorTime = 0;
bool bCursorHidden = true;
bool bCursorHasImage = true;
+ bool bFollowClientPointer = false;
+ double flFollowDX = 0.0;
+ double flFollowDY = 0.0;
bool button_held[ WLSERVER_BUTTON_COUNT ];
std::set <uint32_t> touch_down_ids;
@@ -271,7 +274,7 @@ void wlserver_clear_dropdowns();
void wlserver_notify_dropdown( struct wlr_surface *wlrsurface, int nX, int nY );
void wlserver_mousemotion( double x, double y, uint32_t time );
void wlserver_mousehide();
-void wlserver_mousewarp( double x, double y, uint32_t time, bool bSynthetic );
+void wlserver_mousewarp( double x, double y, uint32_t time, bool bSynthetic, bool bFromTouch = false );
void wlserver_mousebutton( int button, bool press, uint32_t time );
void wlserver_mousewheel( double x, double y, uint32_t time );
bool wlserver_input_held();
+2 -2
View File
@@ -1,3 +1,3 @@
GAMESCOPE_REPO=Droid-Deck/DroidDeck-Components
GAMESCOPE_TAG=gamescope-3.16.29-p19
GAMESCOPE_SHA256=e7333c6a2b95708b199c2c5bd0973e3f0e711e2dc746950cc648c2515ea2926b
GAMESCOPE_TAG=gamescope-3.16.29-p20
GAMESCOPE_SHA256=30a94becf21f3de4d1d7239c47b5168aab973f4e95981402a550c228929ba827