Gesture, Ui, project: Crafter.Graphics at 364d210, whose pointer and touch events carry their time

The pinned library dropped the compositor's time of every pointer and
touch event, so the app dated them by its own clock at dispatch. Events
queued while the main loop was busy — a List importing a backlog, each
Import an fdatasync — all carried the time the loop came back: a swipe's
backlog read as a few milliseconds' travel and flung the list to its far
end, and a press whose down and up both waited out a stall had them at
one time, a tap where the user held — on a Failed bubble a Retry, an SMS
the user did not ask for. Crafter.Graphics 364d210 keeps the time on the
window (lastInputTime, set before the event fires), one commit on the
master of 2026-11-02, which added the library's review configuration and
no code.

The gesture detector now gets each event's own time, unwrapped past the
wrap at 2^32 into one running clock (an event stamped 0, which the
compositor's time reads for one millisecond in 2^32, gets the host's
clock), and the long-press timer's expiry is the host's elapsed since
the press put on that clock, so a press and its release keep their
distance however late the loop dispatches them — and a release or a move
the detector sees past the long-press time with no timer fired is the
long press itself, at the press, where the press can be one, since the
hold is measured on the events' clock (tests/Gesture pins both). The pin
moves from 3f646ec; the contracts this app relies on are unchanged by
the two commits between.
This commit is contained in:
Jorijn van der Graaf 2026-11-02 16:09:33 +01:00
commit e6b343985d
Signed by: jorijnvdgraaf
GPG key ID: 2937E59CDCC1BCFB
4 changed files with 55 additions and 6 deletions

View file

@ -596,7 +596,7 @@ export namespace ImsdMessages::Ui {
// forwarded link's or a notification's Open by the other thumb, Back
// from a key), and its long press does not fire.
void CancelGesture() {
if (gestures.Pressed()) gestures.Feed(PointerPhase::Cancel, Point{}, NowMs());
if (gestures.Pressed()) gestures.Feed(PointerPhase::Cancel, Point{}, eventClock);
if (longPressTimer) {
g_source_remove(longPressTimer);
longPressTimer = 0;
@ -691,6 +691,24 @@ export namespace ImsdMessages::Ui {
canvas->Window().SetTextInput(want.active, static_cast<std::int32_t>(want.caret.x), static_cast<std::int32_t>(want.caret.y), static_cast<std::int32_t>(want.caret.w), static_cast<std::int32_t>(want.caret.h), want.purpose);
}
// The event's own time: the compositor's stamp of the pointer or touch
// event the listener is being invoked for (Window::lastInputTime, ms
// from an undefined base, wrapping at 2^32), unwrapped into one
// running clock. Events queued while the loop was busy keep the
// times they happened at, so a backlog is not read as a burst: a
// swipe's as a fling at many times the finger's speed, a held press
// as a tap. The host's clock where the stamp is 0: the one
// millisecond in 2^32 that the compositor's time reads 0, and before
// the first event that has a time.
std::int64_t EventTimeMs() {
const std::uint32_t raw = canvas->Window().lastInputTime;
if (raw == 0) return NowMs();
if (lastRawEventMs != 0) eventClock += static_cast<std::int32_t>(raw - lastRawEventMs);
else eventClock = raw;
lastRawEventMs = raw;
return eventClock;
}
void Pointer(PointerPhase phase) {
const Point p{ canvas->Window().currentMousePos.x, canvas->Window().currentMousePos.y };
// Buffer pixels: the slop and the fling threshold follow the
@ -708,8 +726,11 @@ export namespace ImsdMessages::Ui {
// held: a slow finger presses the button all the same.
gestures.longPress = pressedOn && pressedOn->id >= Hit::rowBase;
}
Handle(gestures.Feed(phase, p, NowMs()));
const std::int64_t at = EventTimeMs();
Handle(gestures.Feed(phase, p, at));
if (phase == PointerPhase::Down) {
downEventMs = at;
downHostMs = NowMs();
if (longPressTimer) g_source_remove(longPressTimer);
longPressTimer = gestures.longPress ? g_timeout_add(static_cast<guint>(gestures.longPressMs), OnLongPress, this) : 0;
} else if (phase != PointerPhase::Move && longPressTimer) {
@ -721,7 +742,7 @@ export namespace ImsdMessages::Ui {
static gboolean OnLongPress(gpointer data) {
App& self = *static_cast<App*>(data);
self.longPressTimer = 0;
self.Handle(self.gestures.Timeout(NowMs()));
self.Handle(self.gestures.Timeout(self.downEventMs + (NowMs() - self.downHostMs))); // the host's elapsed since the press, on the events' clock
return G_SOURCE_REMOVE;
}
@ -992,6 +1013,10 @@ export namespace ImsdMessages::Ui {
GestureDetector gestures;
std::vector<HitRegion> hits;
guint longPressTimer = 0;
std::int64_t eventClock = 0; // the events' own clock (EventTimeMs), unwrapped
std::uint32_t lastRawEventMs = 0;
std::int64_t downEventMs = 0; // the press on both clocks: the long-press timer's expiry is mapped from the host's
std::int64_t downHostMs = 0;
guint repeatTimer = 0;
std::optional<Crafter::KeyCode> spentKey; // the key whose press changed the screen (Key)
guint blinkTimer = 0;