From 431a0e36f42ef3c44de4fd46f304ad2b38e4b3cd Mon Sep 17 00:00:00 2001 From: Lena Date: Wed, 1 Jul 2026 00:00:00 +0000 Subject: app: clamp forwarded touch pressure to u16 MotionEvent.getPressure() is calibrated around 1.0 but may exceed it on some digitizers. Masking with 0xffff wrapped hard presses around to a light touch; clamp instead. --- app/src/main/java/invalid/lena/scrcpy/Controller.java | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'app/src/main/java/invalid/lena/scrcpy') diff --git a/app/src/main/java/invalid/lena/scrcpy/Controller.java b/app/src/main/java/invalid/lena/scrcpy/Controller.java index 88b9442..188ac34 100644 --- a/app/src/main/java/invalid/lena/scrcpy/Controller.java +++ b/app/src/main/java/invalid/lena/scrcpy/Controller.java @@ -135,8 +135,11 @@ public final class Controller implements ControlStream.InboundSink { int y = (int) ev.getY(index); int tx = (int) ((long) x * tw / vw); int ty = (int) ((long) y * th / vh); + // getPressure is calibrated around 1.0 but may exceed it on some + // digitizers; clamp instead of masking so hard presses don't wrap + // around to a light touch. int pressure = (action == MotionEvent.ACTION_UP) ? 0 - : (int)(ev.getPressure(index) * 0xffff) & 0xffff; + : Math.min((int)(ev.getPressure(index) * 0xffff), 0xffff); sender.accept(ControlMessages.touch(action, pointerId, tx, ty, tw, th, pressure, /* actionButton */ 0, /* buttons */ 0)); lastEvent = "touch a=" + action + " (" + tx + "," + ty + ")"; -- cgit v1.2.3