From 79d41b29adf0c6ff1a06b805dccaa26a133a6159 Mon Sep 17 00:00:00 2001 From: xlulx <92148312+xlulx@users.noreply.github.com> Date: Wed, 25 Nov 2026 01:49:54 +0300 Subject: [PATCH] fix(gamescope): the nested mouse moves the pointer while touch is Disabled (#2961) The nested Wayland pointer reaches wlserver as touch 0, and in the Disabled touch click mode wlserver_touchmotion returned before moving anything. Buttons go through wlserver_mousebutton, so they still arrived, at an X pointer that stayed at (0,0). Steam picks Disabled for Don't Starve Together: DroidDeck's cursor followed the mouse while every click landed in the top-left corner. The nested pointer now warps the X pointer in Disabled as in the other modes; real fingers are still ignored. --- tools/gamescope/PATCHES.md | 9 +++ ...d-mouse-moves-when-touch-is-disabled.patch | 16 ++++ .../test_gamescope_disabled_touch_mouse.py | 76 +++++++++++++++++++ 3 files changed, 101 insertions(+) create mode 100644 tools/gamescope/patches/0141-nested-mouse-moves-when-touch-is-disabled.patch create mode 100644 tools/tests/test_gamescope_disabled_touch_mouse.py diff --git a/tools/gamescope/PATCHES.md b/tools/gamescope/PATCHES.md index cc719ce35b..bf14bf25b5 100644 --- a/tools/gamescope/PATCHES.md +++ b/tools/gamescope/PATCHES.md @@ -416,3 +416,12 @@ changed focus. In a nested session with no other window the SDL window stayed hi on screen. Focus is now chosen again whenever a window's opacity crosses zero in either direction; a change between two visible opacities leaves focus alone. `tools/tests/test_gamescope_focus_opacity.py` compiles the rule from this patch and checks the property handler applies it. + +## 0141 wlserver: the nested mouse moves the pointer while touch is Disabled + +The nested Wayland pointer reaches wlserver as touch 0 (`bAlwaysWarpCursor`, see 0111), and in the Disabled touch click +mode `wlserver_touchmotion` returned before anything moved. Buttons take `wlserver_mousebutton`, so they still arrived, +at a pointer that never left the top-left corner. Steam picks Disabled for some games (Don't Starve Together): the drawn +cursor followed the mouse while every click landed at (0,0). In Disabled the nested pointer now warps the X pointer as +in the other modes; real fingers are still ignored. `tools/tests/test_gamescope_disabled_touch_mouse.py` compiles the +branch from this patch. diff --git a/tools/gamescope/patches/0141-nested-mouse-moves-when-touch-is-disabled.patch b/tools/gamescope/patches/0141-nested-mouse-moves-when-touch-is-disabled.patch new file mode 100644 index 0000000000..c165ccc50b --- /dev/null +++ b/tools/gamescope/patches/0141-nested-mouse-moves-when-touch-is-disabled.patch @@ -0,0 +1,16 @@ +diff --git a/src/wlserver.cpp b/src/wlserver.cpp +index df352b0..9740875 100644 +--- a/src/wlserver.cpp ++++ b/src/wlserver.cpp +@@ -3326,7 +3326,10 @@ void wlserver_touchmotion( double x, double y, int touch_id, uint32_t time, bool + } + else if ( eMode == gamescope::TouchClickModes::Disabled ) + { +- return; ++ if ( !bAlwaysWarpCursor ) ++ return; ++ ++ wlserver_mousewarp( tx, ty, time, false ); + } + else if ( eMode == gamescope::TouchClickModes::Trackpad ) + { diff --git a/tools/tests/test_gamescope_disabled_touch_mouse.py b/tools/tests/test_gamescope_disabled_touch_mouse.py new file mode 100644 index 0000000000..8dc144c9c5 --- /dev/null +++ b/tools/tests/test_gamescope_disabled_touch_mouse.py @@ -0,0 +1,76 @@ +from pathlib import Path +import shutil +import subprocess +import tempfile +import unittest + + +ROOT = Path(__file__).resolve().parents[2] +PATCH = ROOT / "tools/gamescope/patches/0141-nested-mouse-moves-when-touch-is-disabled.patch" + + +def patched_source(): + return "\n".join(line[1:] for line in PATCH.read_text().splitlines() + if line[:1] in (" ", "+") and not line.startswith("+++")) + + +def branch(text, start): + begin = text.index(start) + depth = 0 + for i in range(text.index("{", begin), len(text)): + depth += {"{": 1, "}": -1}.get(text[i], 0) + if depth == 0: + return text[begin:i + 1] + raise ValueError(start) + + +PREAMBLE = r''' +#include +#include +namespace gamescope { enum class TouchClickModes { Hover, Left, Right, Middle, Passthrough, Disabled, Trackpad }; } +static int warps, bumps, warp_from_touch = -1; +static double warp_x, warp_y; +static void wlserver_mousewarp( double x, double y, uint32_t, bool, bool bFromTouch = false ) { warps++; warp_x = x; warp_y = y; warp_from_touch = bFromTouch; } +static void bump_input_counter() { bumps++; } + +static void touchmotion( double tx, double ty, uint32_t time, bool bAlwaysWarpCursor ) +{ + gamescope::TouchClickModes eMode = gamescope::TouchClickModes::Disabled; + if ( eMode == gamescope::TouchClickModes::Passthrough ) + { + } +''' + +MAIN = r''' + bump_input_counter(); +} + +int main() { + touchmotion( 0.0, 0.0, 1, false ); + assert( warps == 0 && bumps == 0 ); + + touchmotion( 640.5, 360.25, 2, true ); + assert( warps == 1 && warp_x == 640.5 && warp_y == 360.25 ); + assert( warp_from_touch == 0 ); + assert( bumps == 1 ); + return 0; +} +''' + + +class GamescopeDisabledTouchMouseTest(unittest.TestCase): + def test_the_nested_mouse_moves_the_pointer_while_fingers_stay_ignored(self): + compiler = shutil.which("c++") or shutil.which("g++") or shutil.which("clang++") + if not compiler: + self.skipTest("no C++ compiler") + disabled = branch(patched_source(), "else if ( eMode == gamescope::TouchClickModes::Disabled )") + with tempfile.TemporaryDirectory() as tmp: + src = Path(tmp) / "disabled_touch_mouse.cpp" + exe = Path(tmp) / "disabled_touch_mouse" + src.write_text(PREAMBLE + "\t" + disabled + "\n" + MAIN) + subprocess.run([compiler, "-std=c++17", "-Wall", "-Werror", "-UNDEBUG", str(src), "-o", str(exe)], check=True) + subprocess.run([str(exe)], check=True) + + +if __name__ == "__main__": + unittest.main()