mirror of
https://github.com/Droid-Deck/DroidDeck.git
synced 2026-12-05 21:43:15 -05:00
* fix(gamescope): only the first finger drives the emulated mouse In the click touch modes every finger warped the X pointer and any finger lifting released the click, so a second finger made the pointer jump between both contacts and dropped whatever the first was dragging. The first finger of a gesture now owns the emulated mouse until it lifts, and later fingers are ignored until every finger is up. * fix(gamescope): motion into the screen edge does not decide the pointer hold A drawn-cursor game whose X pointer sat at the screen edge looked like it held the pointer whenever motion pushed outward, which kept the hold on and turned touch drags into relative motion. The sent motion is clamped to what the pointer can reach before the comparison. * fix(gamescope): touch warps do not decide the pointer hold * fix(gamescope): only touch-down warps are left out of the pointer hold Touch drags are real pointer motion, so they count toward releasing the hold again. Only the jump a touch-down makes is skipped.
122 lines
3.5 KiB
Python
122 lines
3.5 KiB
Python
from pathlib import Path
|
|
import shutil
|
|
import subprocess
|
|
import tempfile
|
|
import unittest
|
|
|
|
|
|
ROOT = Path(__file__).resolve().parents[2]
|
|
PATCH = ROOT / "tools/gamescope/patches/0143-touch-click-first-finger-drives.patch"
|
|
|
|
|
|
def added_source():
|
|
return "\n".join(line[1:] for line in PATCH.read_text().splitlines() if line.startswith("+") and not line.startswith("+++"))
|
|
|
|
|
|
def block(text, start):
|
|
begin = text.index(start)
|
|
return text[begin:text.index("\n}", begin) + 3]
|
|
|
|
|
|
PREAMBLE = r'''
|
|
#include <cassert>
|
|
#include <set>
|
|
'''
|
|
|
|
MAIN = r'''
|
|
struct Pointer {
|
|
TouchClickState state;
|
|
int warps = 0;
|
|
int presses = 0;
|
|
int releases = 0;
|
|
void down(int id) { if (touch_click_claim(state, id)) { warps++; presses++; } }
|
|
void move(int id, bool nested = false) { if (nested || touch_click_drives(state, id)) warps++; }
|
|
void up(int id) { if (touch_click_lift(state, id)) releases++; }
|
|
};
|
|
|
|
int main() {
|
|
Pointer tap;
|
|
tap.down(1);
|
|
tap.move(1);
|
|
tap.up(1);
|
|
assert(tap.presses == 1 && tap.releases == 1 && tap.warps == 2);
|
|
|
|
Pointer drag;
|
|
drag.down(1);
|
|
drag.move(1);
|
|
drag.down(2);
|
|
drag.move(2);
|
|
drag.move(1);
|
|
drag.up(2);
|
|
assert(drag.presses == 1 && drag.releases == 0 && drag.warps == 3);
|
|
drag.move(1);
|
|
drag.up(1);
|
|
assert(drag.releases == 1 && drag.warps == 4);
|
|
|
|
Pointer handover;
|
|
handover.down(1);
|
|
handover.down(2);
|
|
handover.up(1);
|
|
assert(handover.releases == 1);
|
|
handover.move(2);
|
|
handover.down(3);
|
|
handover.move(3);
|
|
assert(handover.warps == 1 && handover.presses == 1);
|
|
handover.up(3);
|
|
handover.up(2);
|
|
assert(handover.releases == 1);
|
|
handover.down(4);
|
|
handover.move(4);
|
|
handover.up(4);
|
|
assert(handover.presses == 2 && handover.releases == 2 && handover.warps == 3);
|
|
|
|
Pointer nested;
|
|
nested.move(0, true);
|
|
nested.down(1);
|
|
nested.move(0, true);
|
|
assert(nested.warps == 3);
|
|
|
|
Pointer stray;
|
|
stray.up(7);
|
|
assert(stray.releases == 1);
|
|
stray.down(1);
|
|
stray.up(7);
|
|
assert(stray.releases == 1);
|
|
stray.up(1);
|
|
assert(stray.releases == 2);
|
|
return 0;
|
|
}
|
|
'''
|
|
|
|
|
|
class GamescopeTouchClickOwnerTest(unittest.TestCase):
|
|
def test_only_the_first_finger_drives_the_emulated_mouse(self):
|
|
compiler = shutil.which("c++") or shutil.which("g++") or shutil.which("clang++")
|
|
if not compiler:
|
|
self.skipTest("no C++ compiler")
|
|
added = added_source()
|
|
helpers = "\n".join(block(added, start) for start in (
|
|
"struct TouchClickState",
|
|
"static bool touch_click_claim",
|
|
"static bool touch_click_drives",
|
|
"static bool touch_click_lift",
|
|
))
|
|
source = PREAMBLE + helpers + MAIN
|
|
with tempfile.TemporaryDirectory() as tmp:
|
|
src = Path(tmp) / "touch_click_owner.cpp"
|
|
exe = Path(tmp) / "touch_click_owner"
|
|
src.write_text(source)
|
|
subprocess.run([compiler, "-std=c++17", "-Wall", "-Werror", "-UNDEBUG", str(src), "-o", str(exe)], check=True)
|
|
subprocess.run([str(exe)], check=True)
|
|
|
|
def test_the_patch_gates_every_finger_path(self):
|
|
added = added_source()
|
|
self.assertIn("else if ( bAlwaysWarpCursor || touch_click_drives( s_TouchClick, touch_id ) )", added)
|
|
self.assertIn("if ( touch_click_drives( s_TouchClick, touch_id ) )", added)
|
|
self.assertIn("else if ( touch_click_claim( s_TouchClick, touch_id ) )", added)
|
|
self.assertIn("bClickTouch && i < WLSERVER_BUTTON_COUNT", added)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
unittest.main()
|