mirror of
https://github.com/Droid-Deck/DroidDeck.git
synced 2026-12-03 12:36:37 -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.
110 lines
3.6 KiB
Python
110 lines
3.6 KiB
Python
from pathlib import Path
|
|
import shutil
|
|
import subprocess
|
|
import tempfile
|
|
import unittest
|
|
|
|
|
|
ROOT = Path(__file__).resolve().parents[2]
|
|
HOLD = ROOT / "tools/gamescope/patches/0133-constraint-relative-when-held.patch"
|
|
DOWN = ROOT / "tools/gamescope/patches/0145-pointer-hold-skips-touch-down-warps.patch"
|
|
|
|
|
|
def added_source(patch):
|
|
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 <algorithm>
|
|
#include <cassert>
|
|
#include <cmath>
|
|
#include <cstdint>
|
|
'''
|
|
|
|
MAIN = r'''
|
|
static const uint64_t FRAME = 16'666'667ul;
|
|
|
|
struct Session {
|
|
PointerHold hold;
|
|
uint64_t now = 1'000'000'000ul;
|
|
bool skipTouchDown;
|
|
bool frame(double seatDX, double pointerDX, bool touchDown) {
|
|
now += FRAME;
|
|
if (touchDown && skipTouchDown) return hold.bHeld;
|
|
return pointer_hold_step(hold, true, seatDX, 0.0, pointerDX, 0.0, now);
|
|
}
|
|
void held() {
|
|
hold = PointerHold{};
|
|
hold.bHeld = true;
|
|
}
|
|
bool strokes() {
|
|
held();
|
|
bool result = true;
|
|
for (int i = 0; i < 17; i++) result = frame(80.0, 80.0, false);
|
|
result = frame(41.0, -1106.0, true);
|
|
for (int i = 0; i < 15; i++) result = frame(73.3, 73.0, false);
|
|
return result;
|
|
}
|
|
};
|
|
|
|
int main() {
|
|
Session counted{{}, 1'000'000'000ul, false};
|
|
assert(counted.strokes());
|
|
|
|
Session skipped{{}, 1'000'000'000ul, true};
|
|
assert(!skipped.strokes());
|
|
|
|
Session drag{{}, 1'000'000'000ul, true};
|
|
drag.held();
|
|
bool result = drag.frame(41.0, -1106.0, true);
|
|
assert(result);
|
|
for (int i = 0; i < 29; i++) result = drag.frame(12.0, 12.0, false);
|
|
assert(result);
|
|
result = drag.frame(12.0, 12.0, false);
|
|
assert(!result);
|
|
|
|
Session recentre{{}, 1'000'000'000ul, true};
|
|
for (int i = 0; i < 3; i++) result = recentre.frame(26.0, 0.0, false);
|
|
assert(result);
|
|
result = recentre.frame(-400.0, 300.0, true);
|
|
assert(result);
|
|
for (int i = 0; i < 40; i++) result = recentre.frame(12.0, 0.0, false);
|
|
assert(result);
|
|
return 0;
|
|
}
|
|
'''
|
|
|
|
|
|
class GamescopePointerHoldTouchDownTest(unittest.TestCase):
|
|
def test_touch_down_is_skipped_and_touch_drags_release_the_hold(self):
|
|
compiler = shutil.which("c++") or shutil.which("g++") or shutil.which("clang++")
|
|
if not compiler:
|
|
self.skipTest("no C++ compiler")
|
|
hold = added_source(HOLD)
|
|
source = PREAMBLE + "\n".join([
|
|
block(hold, "struct PointerHold"),
|
|
block(hold, "static bool pointer_hold_step"),
|
|
]) + MAIN
|
|
with tempfile.TemporaryDirectory() as tmp:
|
|
src = Path(tmp) / "pointer_hold_touch_down.cpp"
|
|
exe = Path(tmp) / "pointer_hold_touch_down"
|
|
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_only_touch_down_warps_are_skipped(self):
|
|
added = added_source(DOWN)
|
|
self.assertIn(" \t\t\t\twlserver_mousewarp( tx, ty, time, false, true );\n+\t\t\t\twlserver.ulTouchDownWarps++;", DOWN.read_text())
|
|
self.assertEqual(1, added.count("wlserver.ulTouchDownWarps++"))
|
|
self.assertIn("const bool bTouchDown = ulTouchDownWarps != s_ulTouchDownWarps;", added)
|
|
self.assertIn("else if ( !bTouchDown )", added)
|
|
self.assertNotIn("bFromTouch )\n\t\twlserver.ulTouchDownWarps++", added)
|
|
|
|
if __name__ == "__main__":
|
|
unittest.main()
|