mirror of
https://github.com/Droid-Deck/DroidDeck.git
synced 2026-11-24 23:36:04 +00:00
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.
This commit is contained in:
1 parent
bb6523cd9c
commit
79d41b29ad
3 files changed
+101
No files matched your search
@@ -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 <cassert>
|
||||
#include <cstdint>
|
||||
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()
|
||||
Reference in new issue
Block a user