Add time since pointerdown to input event handling (#4443)

Add event time to the editor pointer states

The brush trace's hot core is position plus per-sample time, and the
frame clock is too coarse for high-rate tablets: several samples share
one timestamp and speed dynamics see dt = 0. The desktop stamps
editor-routed pointer input with a monotonic arrival time since winit
does not surface hardware timestamps; the web path can thread the
PointerEvent timeStamp through later.
This commit is contained in:
Timon
2026-08-27 13:09:55 +00:00
committed by GitHub
parent 3c5e1b8a38
commit 5a16e18b2a
3 changed files with 14 additions and 0 deletions
@@ -56,6 +56,7 @@ pub struct PointerState {
pub position: ViewportPosition,
pub mouse_keys: MouseKeys,
pub scroll_delta: ScrollDelta,
pub time: Option<f64>,
pub pressure: Option<f64>,
pub tilt: Option<DVec2>,
pub twist: Option<f64>,
@@ -77,6 +78,7 @@ pub struct EditorPointerState {
pub editor_position: EditorPosition,
pub mouse_keys: MouseKeys,
pub scroll_delta: ScrollDelta,
pub time: Option<f64>,
pub pressure: Option<f64>,
pub tilt: Option<DVec2>,
pub twist: Option<f64>,
@@ -101,6 +103,7 @@ impl EditorPointerState {
position: (viewport.logical(self.editor_position) - viewport.offset()).into(),
mouse_keys: self.mouse_keys,
scroll_delta: self.scroll_delta,
time: self.time,
pressure: self.pressure,
tilt: self.tilt,
twist: self.twist,
@@ -16,6 +16,7 @@ pub struct InputPreprocessorMessageHandler {
pub time: u64,
pub keyboard: KeyStates,
pub mouse: PointerState,
pointer_down_time: f64,
}
#[message_handler_data]
@@ -144,6 +145,13 @@ impl InputPreprocessorMessageHandler {
}
}
let raw_time = new_state.time.unwrap_or(self.time as f64);
if self.mouse.mouse_keys == MouseKeys::empty() {
self.pointer_down_time = raw_time;
}
let interacting = (self.mouse.mouse_keys | new_state.mouse_keys) != MouseKeys::empty();
new_state.time = interacting.then_some(raw_time - self.pointer_down_time);
self.mouse = new_state;
}