Skip to content

egui-winit: pass trackpad pressure on as Event::TouchpadPressure - #45

Open
SOENTi wants to merge 3 commits into
storytold:craft/0.37-pinfrom
SOENTi:next-touchpad-pressure
Open

SOENTi wants to merge 3 commits into
storytold:craft/0.37-pinfrom
SOENTi:next-touchpad-pressure

Conversation

@SOENTi

@SOENTi SOENTi commented Nov 14, 2026

Copy link
Copy Markdown

E22 in PATCHES.md, for storytold/lightcraft#4228.

Summary

winit reports a Force Touch trackpad's pressure on macOS. egui-winit asked for a repaint and dropped the reading (TODO(emilk)), so an app could not see it.

 egui::Event
+  TouchpadPressure { pressure: f32, stage: u8 }   # 0..=1 within each stage; 0 = ended, 1 = click, 2 = force click

 egui_winit::State::on_window_event
-  WindowEvent::TouchpadPressure { .. } => repaint
+  WindowEvent::TouchpadPressure { pressure, stage, .. }
+    touchpad_pressure_event(pressure, stage)       # drops non-finite pressure and stages outside u8; clamps to 0..=1
+      -> egui_input.events
+    repaint

LightCraft uses it to keep the tone curve still while a finger comes off the trackpad. The pressure falls (stage 2 → 1, or stage 1 below its recent peak) before or just after the contact point starts to slide. Other platforms send nothing.

Evidence

  • touchpad_pressure_is_passed_on_within_range: in-range readings pass, stage 0 passes, out-of-range pressure is clamped, NaN, ∞ and stages −1 and 256 are dropped.
  • A local build of LightCraft against this patch recorded 29 gestures on a MacBook trackpad:
    • Readings arrive whenever the pressure changes, none while it holds.
    • Once in stage 2, the stage holds until the release. The pressure within stage 2 varies a lot while holding.
    • At the release, stage 2 → 1 comes 6–84 ms before the slide in 7 of 8 gestures.
  • cargo fmt --all --check and cargo clippy --workspace --all-targets -D warnings pass. cargo test -p egui -p egui-winit passes. cargo check -p eframe --target wasm32-unknown-unknown passes.

Merge Danger

Door: two-way

Blast Radius: egui::Event matches

Event is not #[non_exhaustive]. A downstream match on it without a wildcard arm stops compiling until it handles the new variant. This workspace has none.

winit reports a Force Touch trackpad's pressure on macOS as
WindowEvent::TouchpadPressure { pressure, stage }; egui-winit only asked
for a repaint and dropped it (TODO(emilk)). It now becomes
egui::Event::TouchpadPressure { pressure, stage: u8 }: a reading that is
not a finite number or a stage outside u8 is dropped, and the pressure is
kept within 0..=1.
@SOENTi

SOENTi commented Nov 14, 2026

Copy link
Copy Markdown
Author

Note for merging: the E22 row in PATCHES.md cites d8cd1d76, the patch commit on this branch. With a merge commit that hash stays on craft/0.37-pin; with a squash or rebase merge it needs updating to the new commit afterwards.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant