Mir

Merge lp:~alan-griffiths/mir/event-timestamps into lp:mir

Proposed by Alan Griffiths
Status: Rejected
Rejected by: Alan Griffiths
Proposed branch: lp:~alan-griffiths/mir/event-timestamps
Merge into: lp:mir
Diff against target: 195 lines (+95/-0)
6 files modified
include/client/mir_toolkit/events/input/keyboard_event.h (+8/-0)
include/client/mir_toolkit/events/input/pointer_event.h (+8/-0)
include/client/mir_toolkit/events/input/touch_event.h (+8/-0)
src/client/input/input_event.cpp (+18/-0)
src/client/symbols.map (+3/-0)
tests/unit-tests/input/test_input_event.cpp (+50/-0)
To merge this branch: bzr merge lp:~alan-griffiths/mir/event-timestamps
Reviewer Review Type Date Requested Status
PS Jenkins bot (community) continuous-integration Approve
Alexandros Frantzis (community) Needs Information
Andreas Pokorny (community) Needs Information
Robert Carr (community) Approve
Review via email: mp+262879@code.launchpad.net

Commit message

client API: provide access to timestamps from the various input event types

Description of the change

client API: provide access to timestamps from the various input event types

To post a comment you must log in.
Revision history for this message
Robert Carr (robertcarr) wrote :

+1

review: Approve
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
Andreas Pokorny (andreas-pokorny) wrote :

*Discussion Needed*
The input_event 'method name' is mir_input_event_get_time. The derived structures do not use '_get_' for getters. But why not stick with time instead of timestamp? That would mean 'mir_keyboard_event_time'.

Libinput has a similar thing with base and specific events and there the solution is to provide a libinput_{specific_event}_get_base_event function.

review: Needs Information
Revision history for this message
Alexandros Frantzis (afrantzis) wrote :

> The input_event 'method name' is mir_input_event_get_time. The derived structures
> do not use '_get_' for getters

Yes, this is an unfortunate inconsistency.

> Libinput has a similar thing with base and specific events and there the solution is to
> provide a libinput_{specific_event}_get_base_event function.

+1 for this solution. In addition to the event time, there is also the device id that's a common property of all input events. Having a way to get the base input event from any derived input event would elegantly allow access to both these properties (and any new ones we may add in the future).

review: Needs Information
Revision history for this message
Alan Griffiths (alan-griffiths) wrote :

> *Discussion Needed*
> The input_event 'method name' is mir_input_event_get_time. The derived
> structures do not use '_get_' for getters. But why not stick with time instead
> of timestamp? That would mean 'mir_keyboard_event_time'.
>
> Libinput has a similar thing with base and specific events and there the
> solution is to provide a libinput_{specific_event}_get_base_event function.

I considered that, but felt the code I wanted to write (in qtmir) would be clearer with this approach.

Vis:

    auto const timestamp = mir_keyboard_event_timestamp(kev);

as opposed to:

    auto const input_event = mir_keyboard_event_get_base_event(kev);
    auto const timestamp = mir_input_event_get_time(input_event);

or, more consistently:

    auto const input_event = mir_keyboard_event_input_event(kev);
    auto const timestamp = mir_input_event_get_time(input_event);

But as Alexandros mentions this suggestion would avoid writing 3*n (trivially different) functions where 3 would suffice.

In any case I have a mild preference for this approach but will conform to the majority view.

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'include/client/mir_toolkit/events/input/keyboard_event.h'
2--- include/client/mir_toolkit/events/input/keyboard_event.h 2015-04-28 07:54:10 +0000
3+++ include/client/mir_toolkit/events/input/keyboard_event.h 2015-06-25 09:33:08 +0000
4@@ -90,6 +90,14 @@
5 */
6 MirInputEventModifiers mir_keyboard_event_modifiers(MirKeyboardEvent const* event);
7
8+/*
9+ * Retrieve the time at which a keyboard event occurred.
10+ *
11+ * \param [in] event The keyboard event
12+ * \return A timestamp in nanoseconds-since-epoch
13+ */
14+int64_t mir_keyboard_event_timestamp(MirKeyboardEvent const* event);
15+
16 #ifdef __cplusplus
17 }
18 /**@}*/
19
20=== modified file 'include/client/mir_toolkit/events/input/pointer_event.h'
21--- include/client/mir_toolkit/events/input/pointer_event.h 2015-06-17 05:20:42 +0000
22+++ include/client/mir_toolkit/events/input/pointer_event.h 2015-06-25 09:33:08 +0000
23@@ -122,6 +122,14 @@
24 float mir_pointer_event_axis_value(MirPointerEvent const* event,
25 MirPointerAxis axis);
26
27+/*
28+ * Retrieve the time at which a pointer event occurred.
29+ *
30+ * \param [in] event The pointer event
31+ * \return A timestamp in nanoseconds-since-epoch
32+ */
33+int64_t mir_pointer_event_timestamp(MirPointerEvent const* event);
34+
35 #ifdef __cplusplus
36 }
37 /**@}*/
38
39=== modified file 'include/client/mir_toolkit/events/input/touch_event.h'
40--- include/client/mir_toolkit/events/input/touch_event.h 2015-04-28 07:54:10 +0000
41+++ include/client/mir_toolkit/events/input/touch_event.h 2015-06-25 09:33:08 +0000
42@@ -141,6 +141,14 @@
43 float mir_touch_event_axis_value(MirTouchEvent const* event,
44 size_t touch_index, MirTouchAxis axis);
45
46+/*
47+ * Retrieve the time at which a touch event occurred.
48+ *
49+ * \param [in] event The touch event
50+ * \return A timestamp in nanoseconds-since-epoch
51+ */
52+int64_t mir_touch_event_timestamp(MirTouchEvent const* event);
53+
54 #ifdef __cplusplus
55 }
56 /**@}*/
57
58=== modified file 'src/client/input/input_event.cpp'
59--- src/client/input/input_event.cpp 2015-06-17 05:20:42 +0000
60+++ src/client/input/input_event.cpp 2015-06-25 09:33:08 +0000
61@@ -187,6 +187,24 @@
62 }
63 }
64
65+int64_t mir_pointer_event_timestamp(MirPointerEvent const* event)
66+{
67+ auto const& old_ev = old_mev_from_new(event);
68+ return old_ev.event_time.count();
69+}
70+
71+int64_t mir_keyboard_event_timestamp(MirKeyboardEvent const* event)
72+{
73+ auto const& old_ev = old_kev_from_new(event);
74+ return old_ev.event_time.count();
75+}
76+
77+int64_t mir_touch_event_timestamp(MirTouchEvent const* event)
78+{
79+ auto const& old_ev = old_mev_from_new(event);
80+ return old_ev.event_time.count();
81+}
82+
83 /* Key event accessors */
84
85 MirKeyboardEvent const* mir_input_event_get_keyboard_event(MirInputEvent const* ev)
86
87=== modified file 'src/client/symbols.map'
88--- src/client/symbols.map 2015-06-17 14:47:11 +0000
89+++ src/client/symbols.map 2015-06-25 09:33:08 +0000
90@@ -73,6 +73,7 @@
91 mir_keyboard_event_key_code;
92 mir_keyboard_event_modifiers;
93 mir_keyboard_event_scan_code;
94+ mir_keyboard_event_timestamp;
95 mir_keymap_event_get_rules;
96 mir_omnidirectional_resize_cursor_name;
97 mir_open_hand_cursor_name;
98@@ -91,6 +92,7 @@
99 mir_pointer_event_buttons;
100 mir_pointer_event_button_state;
101 mir_pointer_event_modifiers;
102+ mir_pointer_event_timestamp;
103 mir_pointing_hand_cursor_name;
104 mir_prompt_session_error_message;
105 mir_prompt_session_event_get_state;
106@@ -152,6 +154,7 @@
107 mir_touch_event_id;
108 mir_touch_event_modifiers;
109 mir_touch_event_point_count;
110+ mir_touch_event_timestamp;
111 mir_touch_event_tooltype;
112 mir_vertical_resize_cursor_name;
113 mir_vsplit_resize_cursor_name;
114
115=== modified file 'tests/unit-tests/input/test_input_event.cpp'
116--- tests/unit-tests/input/test_input_event.cpp 2015-06-17 05:20:42 +0000
117+++ tests/unit-tests/input/test_input_event.cpp 2015-06-25 09:33:08 +0000
118@@ -21,6 +21,8 @@
119 #include "mir/events/event_private.h"
120 #include "mir_toolkit/events/input/input_event.h"
121
122+using namespace testing;
123+
124 // See: https://bugs.launchpad.net/mir/+bug/1311699
125 #define MIR_EVENT_ACTION_POINTER_INDEX_MASK 0xff00
126 #define MIR_EVENT_ACTION_POINTER_INDEX_SHIFT 8;
127@@ -127,6 +129,22 @@
128 mir_event_get_input_event(&old_ev)));
129 }
130
131+TEST(KeyInputEventProperties, timestamp_taken_from_old_style_event)
132+{
133+ std::chrono::nanoseconds event_time_1{79}, event_time_2{83};
134+ auto old_ev = a_key_ev();
135+
136+ for (auto expected : {event_time_1, event_time_2})
137+ {
138+ old_ev.key.event_time = expected;
139+
140+ auto const input_event = mir_event_get_input_event(&old_ev);
141+ auto const keyboard_event = mir_input_event_get_keyboard_event(input_event);
142+
143+ EXPECT_THAT(mir_keyboard_event_timestamp(keyboard_event), Eq(expected.count()));
144+ }
145+}
146+
147 TEST(KeyInputEventProperties, up_and_down_actions_copied_from_old_style_event)
148 {
149 auto old_ev = a_key_ev();
150@@ -157,6 +175,22 @@
151 EXPECT_EQ(modifiers, mir_keyboard_event_modifiers(new_kev));
152 }
153
154+TEST(TouchEventProperties, timestamp_taken_from_old_style_event)
155+{
156+ std::chrono::nanoseconds event_time_1{79}, event_time_2{83};
157+ auto old_ev = a_motion_ev(AINPUT_SOURCE_TOUCHSCREEN);
158+
159+ for (auto expected : {event_time_1, event_time_2})
160+ {
161+ old_ev.motion.event_time = expected;
162+
163+ auto const input_event = mir_event_get_input_event(&old_ev);
164+ auto const touch_event = mir_input_event_get_touch_event(input_event);
165+
166+ EXPECT_THAT(mir_touch_event_timestamp(touch_event), Eq(expected.count()));
167+ }
168+}
169+
170 TEST(TouchEventProperties, touch_count_taken_from_pointer_count)
171 {
172 unsigned const pointer_count = 3;
173@@ -270,6 +304,22 @@
174
175 /* Pointer event property accessors */
176
177+TEST(PointerInputEventProperties, timestamp_taken_from_old_style_event)
178+{
179+ std::chrono::nanoseconds event_time_1{79}, event_time_2{83};
180+ auto old_ev = a_motion_ev(AINPUT_SOURCE_MOUSE);
181+
182+ for (auto expected : {event_time_1, event_time_2})
183+ {
184+ old_ev.motion.event_time = expected;
185+
186+ auto const input_event = mir_event_get_input_event(&old_ev);
187+ auto const pointer_event = mir_input_event_get_pointer_event(input_event);
188+
189+ EXPECT_THAT(mir_pointer_event_timestamp(pointer_event), Eq(expected.count()));
190+ }
191+}
192+
193 TEST(PointerInputEventProperties, modifiers_taken_from_old_style_ev)
194 {
195 MirInputEventModifiers modifiers = mir_input_event_modifier_shift;

Subscribers

People subscribed via source and target branches