From 60e644be815b7b77a016c1f8d25c17fc4882a750 Mon Sep 17 00:00:00 2001 From: dotCooCoo Date: Sat, 5 Dec 2026 12:45:22 -0800 Subject: [PATCH] Fix #10231: a Windows pen stroke starts and ends at the pressure the pen reports A pen that reports pressure can report 0 while its tip is in contact, as the tip touches down and lifts. pen_sample read that 0 as "no pressure" and gave the sample full pressure, so a pressure-sized Blob Brush stroke began with a half circle and ended with a full circle at the brush's largest size. A pen with the pressure mask now keeps its 0; a pen in contact that reports no pressure still presses fully, and a hovering pen still reads 0. Carries the windows_stylus.rs part of #10249. Co-authored-by: FredApps <153173854+FredApps@users.noreply.github.com> --- apps/vectorcraft/src/windows_stylus.rs | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/apps/vectorcraft/src/windows_stylus.rs b/apps/vectorcraft/src/windows_stylus.rs index b8e6b88ee1..4213398df4 100644 --- a/apps/vectorcraft/src/windows_stylus.rs +++ b/apps/vectorcraft/src/windows_stylus.rs @@ -130,14 +130,15 @@ pub fn msg_hook(msg: *const std::ffi::c_void) -> bool { } /// What a pen whose `POINTER_PEN_INFO` holds `pressure` (0..1024), `pen_mask` and `pen_flags` -/// reports: the pressure as winit gives it to a touch, 0 while it hovers, a full press for a pen -/// in contact that reports none; the eraser end while it is inverted or its eraser button is +/// reports: the pressure it reports, 0 included, which a pen in contact can report as its tip touches +/// down and lifts (#10231), 0 while it hovers, and a full press for a pen in contact that reports +/// none; the eraser end while it is inverted or its eraser button is /// pressed; how it is held, `pose` ([`pen_pose`]); and `wheel`, the airbrush finger wheel the tablet /// driver's Wintab interface reported for the message, if any ([`crate::windows_wintab`]), kept /// 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 +319,18 @@ mod tests { } #[test] - fn a_pens_pressure_is_the_one_winit_gives_its_touch() { + fn a_pen_that_reports_pressure_keeps_zero_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, + "a tip that touches down or lifts with no pressure does not press fully" + ); + assert_eq!(pen_sample(0, PEN_MASK_PRESSURE, PEN_FLAG_ERASER, true, UPRIGHT, None), eraser_sample(0.0), "the eraser end too"); assert_eq!(pen_sample(2000, PEN_MASK_PRESSURE, 0, false, UPRIGHT, None).pressure, 0.0); }