pub struct EventTime(/* private fields */);Expand description
When an input event happened, on the engine’s monotonic clock.
§The epoch is the contract
A timestamp whose origin is unspecified is worth nothing: you cannot subtract two of them across subsystems, and you cannot compare one to “now”. So this type states its epoch and makes matching it a backend obligation:
An
EventTimeis a duration measured from the same origin as theTimeSourcedrivingFrameClock::update— that is, fromMonotonicTime::new(process start) in a real run, and fromManualTime’s zero in a deterministic one.
That makes event.time and clock.render_dt() live on one timeline, which
is what the P2 input pipeline needs to age an input against the tick it
belongs to, and what topic 26’s client prediction needs to compute
input-to-photon latency.
§What backends have to do about it
No window system hands us this directly, so rebasing is part of writing a backend, not an optimization:
- Wayland stamps events with
CLOCK_MONOTONICmilliseconds (microseconds underwp_presentationand the high-resolution input protocols). Subtract the clock reading taken when the shell was created. - X11 stamps events with the X server’s time: a 32-bit millisecond counter with an unspecified origin that wraps every 49.7 days. The backend estimates the offset once at connection time and must detect the wrap; a backend that forwards the raw value produces an input pipeline that silently breaks after a month and a half of uptime.
- Win32 has
GetMessageTime(aGetTickCountsample, also wrapping) and raw input’sQPCtimestamps. - The browser gives
event.timeStamp, already aperformance.now()-relative double.
When a backend genuinely has no timestamp for an event — a synthesized
focus-loss key release, for instance — it stamps the event with the current
time rather than EventTime::ZERO, because a zero timestamp reads as “this
happened at process start” to every consumer downstream.
Implementations§
Source§impl EventTime
impl EventTime
Sourcepub const fn from_duration(since_epoch: Duration) -> EventTime
pub const fn from_duration(since_epoch: Duration) -> EventTime
Wraps a duration measured from the epoch described in the type docs.
Sourcepub const fn from_micros(micros: u64) -> EventTime
pub const fn from_micros(micros: u64) -> EventTime
Microseconds since the epoch — the unit Wayland’s high-resolution input protocols and libinput both use.
Sourcepub const fn from_millis(millis: u64) -> EventTime
pub const fn from_millis(millis: u64) -> EventTime
Milliseconds since the epoch — the unit core Wayland and X11 use.
Sourcepub const fn as_duration(self) -> Duration
pub const fn as_duration(self) -> Duration
Time since the epoch.
Sourcepub fn as_secs_f64(self) -> f64
pub fn as_secs_f64(self) -> f64
Time since the epoch in seconds.
Sourcepub fn saturating_since(self, earlier: EventTime) -> Duration
pub fn saturating_since(self, earlier: EventTime) -> Duration
How long after earlier this timestamp is, saturating at zero.
Saturating rather than panicking because event queues are not perfectly ordered in practice — a compositor can deliver a relative-motion event stamped fractionally before the absolute-motion event it accompanies — and an input pipeline must not die of it.
Sourcepub const fn saturating_add(self, delta: Duration) -> EventTime
pub const fn saturating_add(self, delta: Duration) -> EventTime
This timestamp moved forward by delta.