From 4dfa7902db460a2eeb7090e24ae1b36606a45fad Mon Sep 17 00:00:00 2001 From: Norman Feske Date: Sun, 9 Jan 2022 18:05:44 +0100 Subject: [PATCH] os: Input::Event:Seq_number event type The new event type allows for the propagation of sequence numbers as a means to validate the freshness of input handling. E.g., an menu-view-based application can augment artificial sequence numbers to the stream of motion events supplied to 'menu_view'. Menu view, in turn, can now report the latest received sequence number in its hover reports, thereby enabling the application to robustly correlate hover results with click positions. Issue #4398 --- repos/os/include/input/event.h | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/repos/os/include/input/event.h b/repos/os/include/input/event.h index 3cf00a6d88..55111d847c 100644 --- a/repos/os/include/input/event.h +++ b/repos/os/include/input/event.h @@ -39,6 +39,7 @@ namespace Input { struct Relative_motion { int x, y; }; struct Touch { Touch_id id; float x, y; }; struct Touch_release { Touch_id id; }; + struct Seq_number { unsigned value; }; class Event; class Binding; @@ -50,7 +51,8 @@ class Input::Event private: enum Type { INVALID, PRESS, RELEASE, REL_MOTION, ABS_MOTION, WHEEL, - FOCUS_ENTER, FOCUS_LEAVE, HOVER_LEAVE, TOUCH, TOUCH_RELEASE }; + FOCUS_ENTER, FOCUS_LEAVE, HOVER_LEAVE, TOUCH, TOUCH_RELEASE, + SEQ_NUMBER }; Type _type = INVALID; @@ -64,6 +66,7 @@ class Input::Event Relative_motion rel_motion; Touch touch; Touch_release touch_release; + Seq_number seq_number; }; } _attr { }; @@ -103,6 +106,7 @@ class Input::Event Event(Hover_leave) : _type(HOVER_LEAVE) { } Event(Touch arg) : _type(TOUCH) { _attr.touch = arg; } Event(Touch_release arg) : _type(TOUCH_RELEASE) { _attr.touch_release = arg; } + Event(Seq_number arg) : _type(SEQ_NUMBER) { _attr.seq_number = arg; } /************************************ @@ -120,6 +124,7 @@ class Input::Event bool hover_leave() const { return _type == HOVER_LEAVE; } bool touch() const { return _type == TOUCH; } bool touch_release() const { return _type == TOUCH_RELEASE; } + bool seq_number() const { return _type == SEQ_NUMBER; } bool key_press(Keycode key) const { @@ -187,6 +192,13 @@ class Input::Event fn(_attr.touch_release.id); } + template + void handle_seq_number(FN const &fn) const + { + if (seq_number()) + fn(_attr.seq_number); + } + inline void print(Genode::Output &out) const; }; @@ -208,6 +220,7 @@ void Input::Event::print(Genode::Output &out) const case TOUCH_RELEASE: print(out, "TOUCH_RELEASE ", _attr.touch.id.value); break; case TOUCH: print(out, "TOUCH ", _attr.touch.id.value, " ", _xy(_attr.touch)); break; + case SEQ_NUMBER: print(out, "SEQ_NUMBER ", _attr.seq_number.value); break; }; }