From 11e89a3f569285d821ca7d69ff39004c46b0d0b6 Mon Sep 17 00:00:00 2001 From: Codex Date: Mon, 30 Nov 2026 13:41:32 +0100 Subject: [PATCH] Keep zero pressure at Windows pen contact boundaries --- apps/vectorcraft/src/windows_stylus.rs | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/apps/vectorcraft/src/windows_stylus.rs b/apps/vectorcraft/src/windows_stylus.rs index b8e6b88ee1..018282c2f0 100644 --- a/apps/vectorcraft/src/windows_stylus.rs +++ b/apps/vectorcraft/src/windows_stylus.rs @@ -137,7 +137,7 @@ pub fn msg_hook(msg: *const std::ffi::c_void) -> bool { /// within 0..1 and none when it is not a number. fn pen_sample(pressure: u32, pen_mask: u32, pen_flags: u32, in_contact: bool, (tilt, rotation): Pose, wheel: Option) -> PointerSample { let pressure = match pressure { - 1..=1024 if pen_mask & PEN_MASK_PRESSURE != 0 => pressure as f32 / 1024.0, + 0..=1024 if pen_mask & PEN_MASK_PRESSURE != 0 => pressure as f32 / 1024.0, _ if in_contact => 1.0, _ => 0.0, }; @@ -318,13 +318,17 @@ mod tests { } #[test] - fn a_pens_pressure_is_the_one_winit_gives_its_touch() { + fn pressure_capable_pens_keep_zero_pressure_at_the_ends_of_a_stroke() { assert_eq!(pen_sample(512, PEN_MASK_PRESSURE, 0, true, UPRIGHT, None).pressure, 0.5); assert_eq!(pen_sample(1024, PEN_MASK_PRESSURE, 0, true, UPRIGHT, None).pressure, 1.0); assert_eq!(pen_sample(0, PEN_MASK_PRESSURE, PEN_FLAG_INVERTED, false, UPRIGHT, None), eraser_sample(0.0), "hovering"); assert_eq!(pen_sample(0, 0, 0, true, UPRIGHT, None).pressure, 1.0, "a pen in contact that reports no pressure presses fully"); assert_eq!(pen_sample(300, 0, 0, true, UPRIGHT, None).pressure, 1.0, "a pressure without the pressure mask is not one"); - assert_eq!(pen_sample(0, PEN_MASK_PRESSURE, 0, true, UPRIGHT, None).pressure, 1.0, "as winit, which gives no force for 0"); + assert_eq!( + pen_sample(0, PEN_MASK_PRESSURE, 0, true, UPRIGHT, None).pressure, + 0.0, + "zero pressure at first or last contact must not paint a full-width tip" + ); assert_eq!(pen_sample(2000, PEN_MASK_PRESSURE, 0, false, UPRIGHT, None).pressure, 0.0); }