Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
130 changes: 130 additions & 0 deletions android/patches/gamescope/0053-A60-absolute-pointer-motion.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
A60 — a pointer that reports positions moves the cursor to them

The host sends input through a virtual pointer (I1). That protocol has two
motion requests: a step (motion) and a position (motion_absolute). Only the step
was heard, so the host turned every touch position into a step from the cursor
position it kept for itself. gamescope keeps the cursor inside the focused
window's surface; a step that ran past an edge was cut short here and not there,
and from then on every touch landed that far off. The same happened whenever the
cursor moved without the host: a window that takes the focus, a game that warps
the pointer, a window smaller than the nested display.

The position is now heard too. It is a place on the output, 0..1 on each axis,
and it reaches the focused window as a touch does: through the window's offset
and scale on the output, then clamped to the surface. There is no second cursor
to disagree with.

The games that read steps still get them. The step sent with a position is the
one from the cursor to it, and a confinement bounds it as it bounds a mouse. A
locked pointer does not move, so there the step is the one from the last
position: a drag turns the view as a mouse drag does.
diff --git a/src/wlserver.cpp b/src/wlserver.cpp
index f7635d0..40fc8f5 100644
--- a/src/wlserver.cpp
+++ b/src/wlserver.cpp
@@ -368,6 +368,15 @@ static void wlserver_handle_pointer_motion(struct wl_listener *listener, void *d
wlserver_mousemotion(event->unaccel_dx, event->unaccel_dy, event->time_msec);
}

+static void wlserver_handle_pointer_motion_absolute(struct wl_listener *listener, void *data)
+{
+ struct wlr_pointer_motion_absolute_event *event = (struct wlr_pointer_motion_absolute_event *) data;
+
+ wlserver.physical_cursor_move = true;
+
+ wlserver_mouseabsolute(event->x, event->y, event->time_msec);
+}
+
void wlserver_open_steam_menu( bool qam )
{
gamescope_xwayland_server_t *server = wlserver_get_xwayland_server( 0 );
@@ -516,6 +525,7 @@ static void wlserver_handle_pointer_destroy(struct wl_listener *listener, void *
struct wlserver_pointer *pointer = wl_container_of( listener, pointer, destroy );

wl_list_remove( &pointer->motion.link );
+ wl_list_remove( &pointer->motion_absolute.link );
wl_list_remove( &pointer->button.link );
wl_list_remove( &pointer->axis.link );
wl_list_remove( &pointer->frame.link );
@@ -573,6 +583,8 @@ static void wlserver_new_input(struct wl_listener *listener, void *data)

pointer->motion.notify = wlserver_handle_pointer_motion;
wl_signal_add( &pointer->wlr->events.motion, &pointer->motion );
+ pointer->motion_absolute.notify = wlserver_handle_pointer_motion_absolute;
+ wl_signal_add( &pointer->wlr->events.motion_absolute, &pointer->motion_absolute );
pointer->button.notify = wlserver_handle_pointer_button;
wl_signal_add( &pointer->wlr->events.button, &pointer->button );
pointer->axis.notify = wlserver_handle_pointer_axis;
@@ -3352,6 +3364,52 @@ void wlserver_mousewarp( double x, double y, uint32_t time, bool bSynthetic )
wlr_seat_pointer_notify_frame( wlserver.wlr.seat );
}

+// A position on the output, 0..1 on each axis, from a pointer that reports
+// positions and not steps (the host's touchscreen, through the virtual
+// pointer). It reaches the focused window as a touch does, so the cursor lands
+// where the picture was touched whatever the window's size and place.
+void wlserver_mouseabsolute( double x, double y, uint32_t time )
+{
+ assert( wlserver_is_lock_held() );
+
+ if ( wlserver.mouse_focus_surface == NULL )
+ return;
+
+ double tx = ( x * g_nOutputWidth + focusedWindowOffsetX ) * focusedWindowScaleX;
+ double ty = ( y * g_nOutputHeight + focusedWindowOffsetY ) * focusedWindowScaleY;
+
+ auto [nWidth, nHeight] = wlserver_get_cursor_bounds();
+ tx = std::clamp( tx, 0.0, std::max( nWidth - 0.1, 0.0 ) );
+ ty = std::clamp( ty, 0.0, std::max( nHeight - 0.1, 0.0 ) );
+
+ // A game that locked the pointer reads steps and the cursor does not move:
+ // its step is the one from the last position, not the one from the cursor.
+ static double s_flLastX = 0.0, s_flLastY = 0.0;
+ static bool s_bHaveLast = false;
+
+ struct wlr_pointer_constraint_v1 *pConstraint = wlserver.GetCursorConstraint();
+ bool bLocked = pConstraint && pConstraint->type == WLR_POINTER_CONSTRAINT_V1_LOCKED;
+
+ double dx = tx - ( bLocked ? s_flLastX : wlserver.mouse_surface_cursorx );
+ double dy = ty - ( bLocked ? s_flLastY : wlserver.mouse_surface_cursory );
+ if ( bLocked && !s_bHaveLast )
+ dx = dy = 0.0;
+
+ s_flLastX = tx;
+ s_flLastY = ty;
+ s_bHaveLast = true;
+
+ wlserver_perform_rel_pointer_motion( dx, dy );
+
+ if ( !wlserver_apply_constraint( &dx, &dy ) )
+ {
+ wlr_seat_pointer_notify_frame( wlserver.wlr.seat );
+ return;
+ }
+
+ wlserver_mousewarp( wlserver.mouse_surface_cursorx + dx, wlserver.mouse_surface_cursory + dy, time, false );
+}
+
void wlserver_fake_mouse_pos( double x, double y )
{
// Fake a pos for eg. hiding true cursor state from Steam.
diff --git a/src/wlserver.hpp b/src/wlserver.hpp
index 54452c1..361657e 100644
--- a/src/wlserver.hpp
+++ b/src/wlserver.hpp
@@ -241,6 +241,7 @@ struct wlserver_pointer {
struct wlr_pointer *wlr;

struct wl_listener motion;
+ struct wl_listener motion_absolute;
struct wl_listener button;
struct wl_listener axis;
struct wl_listener frame;
@@ -282,6 +283,7 @@ 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_mouseabsolute( double x, double y, uint32_t time );
void wlserver_mousebutton( int button, bool press, uint32_t time );
void wlserver_mousewheel( double x, double y, uint32_t time );
bool wlserver_input_held();
Loading