diff options
| author | Lena <lena@omega> | 2026-07-01 00:00:00 +0000 |
|---|---|---|
| committer | Lena <lena@omega> | 2026-07-01 00:00:00 +0000 |
| commit | 431a0e36f42ef3c44de4fd46f304ad2b38e4b3cd (patch) | |
| tree | de2ba58df905003676b436fdfba7b90802199291 | |
| parent | 735ca8b58dc341f4521a162346ba14fe943eb2bb (diff) | |
| download | scrcpy-android-431a0e36f42ef3c44de4fd46f304ad2b38e4b3cd.tar.gz | |
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.
| -rw-r--r-- | app/src/main/java/invalid/lena/scrcpy/Controller.java | 5 |
1 files changed, 4 insertions, 1 deletions
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 + ")"; |