Mir

Merge lp:~mir-team/mir/port-examples-off-mir-event-access into lp:mir

Proposed by Robert Carr on 2014-12-19
Status: Merged
Approved by: Cemil Azizoglu on 2015-01-05
Approved revision: 2124
Merged at revision: 2192
Proposed branch: lp:~mir-team/mir/port-examples-off-mir-event-access
Merge into: lp:mir
Diff against target: 357 lines (+158/-82)
9 files modified
client-ABI-sha1sums (+1/-1)
common-ABI-sha1sums (+1/-1)
examples/demo_client_display_config.c (+42/-32)
examples/eglapp.c (+44/-16)
examples/server_example_input_event_filter.cpp (+12/-5)
examples/server_example_input_filter.cpp (+51/-25)
include/common/mir_toolkit/events/event.h (+5/-0)
platform-ABI-sha1sums (+1/-1)
server-ABI-sha1sums (+1/-1)
To merge this branch: bzr merge lp:~mir-team/mir/port-examples-off-mir-event-access
Reviewer Review Type Date Requested Status
PS Jenkins bot continuous-integration 2014-12-19 Approve on 2015-01-05
Alan Griffiths 2014-12-19 Abstain on 2015-01-05
Daniel van Vugt Abstain on 2014-12-29
Alberto Aguirre Approve on 2014-12-19
Kevin DuBois (community) Approve on 2014-12-19
Review via email: mp+245240@code.launchpad.net

This proposal supersedes a proposal from 2014-12-19.

Commit Message

Port examples to new event access API.

Description of the Change

Port examples to new event access API. I also updated events.h to include the particular event types...having each client include resize event, input event, etc is frustrating especially considering any realistic client will want them all.

To post a comment you must log in.
Alan Griffiths (alan-griffiths) wrote : Posted in a previous version of this proposal

222 - else if (ev->surface.value == mir_surface_visibility_occluded)
223 - printf("Surface occluded\n");

vs

179 + case mir_surface_visibility_occluded:
180 + printf("Surface exposed\n");

I think "Surface exposed" is misleading for a mir_surface_visibility_occluded event.

review: Needs Fixing
Robert Carr (robertcarr) wrote : Posted in a previous version of this proposal

Whoops! Fixed.

Alan Griffiths (alan-griffiths) wrote : Posted in a previous version of this proposal

Looks as though lp:~mir-team/mir/add-more-event-getters should be a prerequisite as we're seeing those diffs here.

review: Resubmit
Kevin DuBois (kdub) wrote :

I'm not quite sure what the goals of MirEvent2.0 are, but looks okay to me. The logic in line 205 seems more wordy with MirEvent2.0 than with 1.0...

review: Approve
Robert Carr (robertcarr) wrote :

Hey kevin, thanks.

The long term goals are a pretty big redesign of the event semantics. This includes, differentation of pointer/touch events, event synthesis, cleaned up touch model, input methods, etc...

I felt like the only way we were going to get there is if we can quickly iterate MirEvent without breaking Client ABI. The verbosity is unfortunate but the cost isn't really so high. I'd be interested in adding some C++ API to cut down on the verbosity as some of our main clients (though not all) are C++.

Alberto Aguirre (albaguirre) wrote :

opaquifying leads to wordiness but much better to easier to support a stable ABI.

review: Approve
Alberto Aguirre (albaguirre) wrote :

Heh I don't know how to write....

2123. By Robert Carr <racarr@ocelot> on 2014-12-24

Merge trunk

Daniel van Vugt (vanvugt) wrote :

I think we've now got an API that is unacceptably complex to use. First notice this proposal introduces twice the amount of code that it replaces. Second notice specific instances of using the new API:

205 - if (event.type == mir_event_type_key &&
206 - event.key.action == mir_key_action_down &&
207 - (event.key.modifiers & mir_key_modifier_alt) &&
208 - (event.key.modifiers & mir_key_modifier_ctrl) &&
209 - event.key.scan_code == KEY_BACKSPACE)
210 + if (mir_event_get_type(&event) != mir_event_type_input)
211 + return false;
212 + MirInputEvent const* input_event = mir_event_get_input_event(&event);
213 + if (mir_input_event_get_type(input_event) != mir_input_event_type_key)
214 + return false;
215 + MirKeyInputEvent const* kev = mir_input_event_get_key_input_event(input_event);
216 + if (mir_key_input_event_get_action(kev) != mir_key_input_event_action_down)
217 + return false;
218 + MirInputEventModifiers mods = mir_key_input_event_get_modifiers(kev);
219 + if (!(mods & mir_input_event_modifier_alt) || !(mods & mir_input_event_modifier_ctrl))
220 + return false;
221 + if (mir_key_input_event_get_scan_code(kev) == KEY_BACKSPACE)

I am not a fan. But I know it's too late to disapprove again.

review: Abstain
Robert Carr (robertcarr) wrote :

Hi Daniel. Nice to hear from you...inbox was so quiet! This is a good example you point out, where its not just find replace accessors->function name...

I had an idea for an API improvement classes of convenience functions e.g.

MirKeyEvent* mir_is_maybe_key_event(MirEvent)

Should help a little...

Ill whip something up tomorrow.

Alan Griffiths (alan-griffiths) wrote :

Yes, some event matcher functions could help. But I'm not not sure what the right design is for those...

MirKeyEvent* mir_matches_key_event(MirEvent, mir_key_action_down, mir_key_modifier_alt + mir_key_modifier_ctrl, KEY_BACKSPACE)

...is perhaps a little too specific.

review: Abstain
2124. By Robert Carr on 2015-01-05

Merge trunk

Robert Carr (robertcarr) wrote :

I thought about the mir_is_key_event accessor...but that doesnt help

it just changes

if (type != foo)
   return;
mir_event_get_foo_type(ev)

to

ev = mir_event_get_foo_type(ev)
if (!ev)
   return

I think deeper accessors, e.g. mir_matches_key_event is too specific. I think they are unlikely to be used outside of example code.

Test code uses the gmock matchers.
Realistic clients (toolkits or apps with a platform abstraction layer) translate MirEvent to something else and thus are interested in accessing every field, not matching it.

I think the cost is not that high to pay.

review: Approve (continuous-integration)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'client-ABI-sha1sums'
2--- client-ABI-sha1sums 2014-12-19 23:15:04 +0000
3+++ client-ABI-sha1sums 2015-01-05 17:06:41 +0000
4@@ -14,7 +14,7 @@
5 fce4c1a9e0d037244f7e9e96ea2d8eaab4fc404c include/common/mir_toolkit/cursors.h
6 f4d39e9893ce6308bddd83a49b90f0051f565323 include/common/mir_toolkit/event.h
7 2507f2929415aa423f9551d3c595c439fe1c6efd include/common/mir_toolkit/events/event_deprecated.h
8-d929f623c98b3842ae72059edeba9c89c04edd0f include/common/mir_toolkit/events/event.h
9+cb2358a701db2b9c8d9ba1c877f29f834af259a7 include/common/mir_toolkit/events/event.h
10 c591a02a8e9851db342c310cf829d018a1eddb51 include/common/mir_toolkit/events/input/input_event.h
11 7748a12138474e9be218eeb8f14b372af0fcec7e include/common/mir_toolkit/events/input/key_input_event.h
12 de7c23453e6d897296f32e49d9ba952a1baa0200 include/common/mir_toolkit/events/input/touch_input_event.h
13
14=== modified file 'common-ABI-sha1sums'
15--- common-ABI-sha1sums 2014-12-19 23:15:04 +0000
16+++ common-ABI-sha1sums 2015-01-05 17:06:41 +0000
17@@ -21,7 +21,7 @@
18 fce4c1a9e0d037244f7e9e96ea2d8eaab4fc404c include/common/mir_toolkit/cursors.h
19 f4d39e9893ce6308bddd83a49b90f0051f565323 include/common/mir_toolkit/event.h
20 2507f2929415aa423f9551d3c595c439fe1c6efd include/common/mir_toolkit/events/event_deprecated.h
21-d929f623c98b3842ae72059edeba9c89c04edd0f include/common/mir_toolkit/events/event.h
22+cb2358a701db2b9c8d9ba1c877f29f834af259a7 include/common/mir_toolkit/events/event.h
23 c591a02a8e9851db342c310cf829d018a1eddb51 include/common/mir_toolkit/events/input/input_event.h
24 7748a12138474e9be218eeb8f14b372af0fcec7e include/common/mir_toolkit/events/input/key_input_event.h
25 de7c23453e6d897296f32e49d9ba952a1baa0200 include/common/mir_toolkit/events/input/touch_input_event.h
26
27=== modified file 'examples/demo_client_display_config.c'
28--- examples/demo_client_display_config.c 2013-10-21 10:40:19 +0000
29+++ examples/demo_client_display_config.c 2015-01-05 17:06:41 +0000
30@@ -295,42 +295,52 @@
31 ctx->reconfigure = 1;
32 }
33
34+static void handle_key_input_event(struct ClientContext *ctx, MirKeyInputEvent const* event)
35+{
36+ if (mir_key_input_event_get_action(event) != mir_key_input_event_action_up)
37+ return;
38+ xkb_keysym_t key_code = mir_key_input_event_get_key_code(event);
39+
40+ if (key_code >= XKB_KEY_1 &&
41+ key_code <= XKB_KEY_9)
42+ {
43+ configure_display(ctx, configuration_mode_single,
44+ key_code - XKB_KEY_0);
45+ }
46+
47+ switch (key_code)
48+ {
49+ case XKB_KEY_q:
50+ ctx->running = 0;
51+ break;
52+ case XKB_KEY_c:
53+ configure_display(ctx, configuration_mode_clone, 0);
54+ break;
55+ case XKB_KEY_h:
56+ configure_display(ctx, configuration_mode_horizontal, 0);
57+ break;
58+ case XKB_KEY_v:
59+ configure_display(ctx, configuration_mode_vertical, 0);
60+ break;
61+ case XKB_KEY_p:
62+ print_current_configuration(ctx->connection);
63+ break;
64+ }
65+}
66+
67 static void event_callback(
68 MirSurface* surface, MirEvent const* event, void* context)
69 {
70- (void)surface;
71+ (void) surface;
72 struct ClientContext *ctx = (struct ClientContext*) context;
73-
74- if (event->type == mir_event_type_key &&
75- event->key.action == mir_key_action_up)
76- {
77- if (event->key.key_code == XKB_KEY_q)
78- {
79- ctx->running = 0;
80- }
81- else if (event->key.key_code == XKB_KEY_c)
82- {
83- configure_display(ctx, configuration_mode_clone, 0);
84- }
85- else if (event->key.key_code == XKB_KEY_h)
86- {
87- configure_display(ctx, configuration_mode_horizontal, 0);
88- }
89- else if (event->key.key_code == XKB_KEY_v)
90- {
91- configure_display(ctx, configuration_mode_vertical, 0);
92- }
93- else if (event->key.key_code >= XKB_KEY_1 &&
94- event->key.key_code <= XKB_KEY_9)
95- {
96- configure_display(ctx, configuration_mode_single,
97- event->key.key_code - XKB_KEY_0);
98- }
99- else if (event->key.key_code == XKB_KEY_p)
100- {
101- print_current_configuration(ctx->connection);
102- }
103- }
104+
105+ if (mir_event_get_type(event) != mir_event_type_input)
106+ return;
107+ MirInputEvent const* input_event = mir_event_get_input_event(event);
108+ if (mir_input_event_get_type(input_event) != mir_input_event_type_key)
109+ return;
110+
111+ handle_key_input_event(ctx, mir_input_event_get_key_input_event(input_event));
112 }
113
114 int main(int argc, char *argv[])
115
116=== modified file 'examples/eglapp.c'
117--- examples/eglapp.c 2014-12-15 06:24:03 +0000
118+++ examples/eglapp.c 2015-01-05 17:06:41 +0000
119@@ -90,18 +90,51 @@
120 }
121 }
122
123+static void mir_eglapp_handle_input_event(MirInputEvent const* event)
124+{
125+ if (mir_input_event_get_type(event) != mir_input_event_type_key)
126+ return;
127+ MirKeyInputEvent const* kev = mir_input_event_get_key_input_event(event);
128+ if (mir_key_input_event_get_action(kev) != mir_key_input_event_action_up)
129+ return;
130+ if (mir_key_input_event_get_key_code(kev) != XKB_KEY_q)
131+ return;
132+
133+ running = 0;
134+}
135+
136+static void mir_eglapp_handle_surface_event(MirSurfaceEvent const* sev)
137+{
138+ MirSurfaceAttrib attrib = mir_surface_event_get_attribute(sev);
139+ if (attrib != mir_surface_attrib_visibility)
140+ return;
141+ switch (mir_surface_event_get_attribute_value(sev))
142+ {
143+ case mir_surface_visibility_exposed:
144+ printf("Surface exposed\n");
145+ break;
146+ case mir_surface_visibility_occluded:
147+ printf("Surface occluded\n");
148+ break;
149+ default:
150+ break;
151+ }
152+}
153+
154 static void mir_eglapp_handle_event(MirSurface* surface, MirEvent const* ev, void* context)
155 {
156 (void) surface;
157 (void) context;
158- if (ev->type == mir_event_type_key &&
159- ev->key.key_code == XKB_KEY_q &&
160- ev->key.action == mir_key_action_up)
161- {
162- running = 0;
163- }
164- else if (ev->type == mir_event_type_resize)
165- {
166+
167+ switch (mir_event_get_type(ev))
168+ {
169+ case mir_event_type_input:
170+ mir_eglapp_handle_input_event(mir_event_get_input_event(ev));
171+ break;
172+ case mir_event_type_surface:
173+ mir_eglapp_handle_surface_event(mir_event_get_surface_event(ev));
174+ break;
175+ case mir_event_type_resize:
176 /*
177 * FIXME: https://bugs.launchpad.net/mir/+bug/1194384
178 * It is unsafe to set the width and height here because we're in a
179@@ -110,14 +143,9 @@
180 * full single-threaded callbacks. (LP: #1194384).
181 */
182 printf("Resized to %dx%d\n", ev->resize.width, ev->resize.height);
183- }
184- else if (ev->type == mir_event_type_surface &&
185- ev->surface.attrib == mir_surface_attrib_visibility)
186- {
187- if (ev->surface.value == mir_surface_visibility_exposed)
188- printf("Surface exposed\n");
189- else if (ev->surface.value == mir_surface_visibility_occluded)
190- printf("Surface occluded\n");
191+ break;
192+ default:
193+ break;
194 }
195 }
196
197
198=== modified file 'examples/server_example_input_event_filter.cpp'
199--- examples/server_example_input_event_filter.cpp 2014-12-11 02:43:01 +0000
200+++ examples/server_example_input_event_filter.cpp 2015-01-05 17:06:41 +0000
201@@ -35,11 +35,18 @@
202
203 bool me::QuitFilter::handle(MirEvent const& event)
204 {
205- if (event.type == mir_event_type_key &&
206- event.key.action == mir_key_action_down &&
207- (event.key.modifiers & mir_key_modifier_alt) &&
208- (event.key.modifiers & mir_key_modifier_ctrl) &&
209- event.key.scan_code == KEY_BACKSPACE)
210+ if (mir_event_get_type(&event) != mir_event_type_input)
211+ return false;
212+ MirInputEvent const* input_event = mir_event_get_input_event(&event);
213+ if (mir_input_event_get_type(input_event) != mir_input_event_type_key)
214+ return false;
215+ MirKeyInputEvent const* kev = mir_input_event_get_key_input_event(input_event);
216+ if (mir_key_input_event_get_action(kev) != mir_key_input_event_action_down)
217+ return false;
218+ MirInputEventModifiers mods = mir_key_input_event_get_modifiers(kev);
219+ if (!(mods & mir_input_event_modifier_alt) || !(mods & mir_input_event_modifier_ctrl))
220+ return false;
221+ if (mir_key_input_event_get_scan_code(kev) == KEY_BACKSPACE)
222 {
223 quit_action();
224 return true;
225
226=== modified file 'examples/server_example_input_filter.cpp'
227--- examples/server_example_input_filter.cpp 2014-12-08 17:10:25 +0000
228+++ examples/server_example_input_filter.cpp 2015-01-05 17:06:41 +0000
229@@ -32,35 +32,61 @@
230 /// Demonstrate adding a custom input filter to a server
231 namespace
232 {
233+void print_key_event(MirInputEvent const* ev)
234+{
235+ auto event_time = mir_input_event_get_event_time(ev);
236+ auto kev = mir_input_event_get_key_input_event(ev);
237+ auto scan_code = mir_key_input_event_get_scan_code(kev);
238+ auto key_code = mir_key_input_event_get_key_code(kev);
239+
240+ std::cout << "Handling key event (time, scancode, keycode): " << event_time << " " <<
241+ scan_code << " " << key_code << std::endl;
242+}
243+
244+void print_touch_event(MirInputEvent const* ev)
245+{
246+ auto event_time = mir_input_event_get_event_time(ev);
247+ auto tev = mir_input_event_get_touch_input_event(ev);
248+ auto tc = mir_touch_input_event_get_touch_count(tev);
249+
250+ std::cout << "Handline touch event time=" << event_time
251+ << " touch_count=" << tc << std::endl;
252+ for (unsigned i = 0; i < tc; i++)
253+ {
254+ auto id = mir_touch_input_event_get_touch_id(tev, i);
255+ auto px = mir_touch_input_event_get_touch_axis_value(tev, i,
256+ mir_touch_input_axis_x);
257+ auto py = mir_touch_input_event_get_touch_axis_value(tev, i,
258+ mir_touch_input_axis_y);
259+
260+ std::cout << " "
261+ << " id=" << id
262+ << " pos=(" << px << ", " << py << ")"
263+ << std::endl;
264+ }
265+ std::cout << "----------------" << std::endl << std::endl;
266+}
267+
268 struct PrintingEventFilter : public mi::EventFilter
269 {
270- void print_motion_event(MirMotionEvent const& ev)
271- {
272- std::cout << "Motion Event time=" << ev.event_time
273- << " pointer_count=" << ev.pointer_count << std::endl;
274-
275- for (size_t i = 0; i < ev.pointer_count; ++i)
276- {
277- std::cout << " "
278- << " id=" << ev.pointer_coordinates[i].id
279- << " pos=(" << ev.pointer_coordinates[i].x << ", " << ev.pointer_coordinates[i].y << ")"
280- << std::endl;
281- }
282- std::cout << "----------------" << std::endl << std::endl;
283- }
284-
285 bool handle(MirEvent const& ev) override
286 {
287- // TODO: Enhance printing
288- if (ev.type == mir_event_type_key)
289- {
290- std::cout << "Handling key event (time, scancode, keycode): " << ev.key.event_time << " "
291- << ev.key.scan_code << " " << ev.key.key_code << std::endl;
292- }
293- else if (ev.type == mir_event_type_motion)
294- {
295- print_motion_event(ev.motion);
296- }
297+ if (mir_event_get_type(&ev) != mir_event_type_input)
298+ return false;
299+ auto input_event = mir_event_get_input_event(&ev);
300+
301+ switch (mir_input_event_get_type(input_event))
302+ {
303+ case mir_input_event_type_key:
304+ print_key_event(input_event);
305+ break;
306+ case mir_input_event_type_touch:
307+ print_touch_event(input_event);
308+ break;
309+ default:
310+ abort();
311+ }
312+
313 return false;
314 }
315 };
316
317=== modified file 'include/common/mir_toolkit/events/event.h'
318--- include/common/mir_toolkit/events/event.h 2014-12-18 19:11:01 +0000
319+++ include/common/mir_toolkit/events/event.h 2015-01-05 17:06:41 +0000
320@@ -60,6 +60,11 @@
321 #endif
322
323 #include "mir_toolkit/events/event_deprecated.h"
324+#include "mir_toolkit/events/input/input_event.h"
325+#include "mir_toolkit/events/resize_event.h"
326+#include "mir_toolkit/events/surface_event.h"
327+#include "mir_toolkit/events/orientation_event.h"
328+#include "mir_toolkit/events/prompt_session_event.h"
329
330 #ifdef __cplusplus
331 /**
332
333=== modified file 'platform-ABI-sha1sums'
334--- platform-ABI-sha1sums 2014-12-20 00:20:16 +0000
335+++ platform-ABI-sha1sums 2015-01-05 17:06:41 +0000
336@@ -21,7 +21,7 @@
337 fce4c1a9e0d037244f7e9e96ea2d8eaab4fc404c include/common/mir_toolkit/cursors.h
338 f4d39e9893ce6308bddd83a49b90f0051f565323 include/common/mir_toolkit/event.h
339 2507f2929415aa423f9551d3c595c439fe1c6efd include/common/mir_toolkit/events/event_deprecated.h
340-d929f623c98b3842ae72059edeba9c89c04edd0f include/common/mir_toolkit/events/event.h
341+cb2358a701db2b9c8d9ba1c877f29f834af259a7 include/common/mir_toolkit/events/event.h
342 c591a02a8e9851db342c310cf829d018a1eddb51 include/common/mir_toolkit/events/input/input_event.h
343 7748a12138474e9be218eeb8f14b372af0fcec7e include/common/mir_toolkit/events/input/key_input_event.h
344 de7c23453e6d897296f32e49d9ba952a1baa0200 include/common/mir_toolkit/events/input/touch_input_event.h
345
346=== modified file 'server-ABI-sha1sums'
347--- server-ABI-sha1sums 2014-12-20 00:20:16 +0000
348+++ server-ABI-sha1sums 2015-01-05 17:06:41 +0000
349@@ -21,7 +21,7 @@
350 fce4c1a9e0d037244f7e9e96ea2d8eaab4fc404c include/common/mir_toolkit/cursors.h
351 f4d39e9893ce6308bddd83a49b90f0051f565323 include/common/mir_toolkit/event.h
352 2507f2929415aa423f9551d3c595c439fe1c6efd include/common/mir_toolkit/events/event_deprecated.h
353-d929f623c98b3842ae72059edeba9c89c04edd0f include/common/mir_toolkit/events/event.h
354+cb2358a701db2b9c8d9ba1c877f29f834af259a7 include/common/mir_toolkit/events/event.h
355 c591a02a8e9851db342c310cf829d018a1eddb51 include/common/mir_toolkit/events/input/input_event.h
356 7748a12138474e9be218eeb8f14b372af0fcec7e include/common/mir_toolkit/events/input/key_input_event.h
357 de7c23453e6d897296f32e49d9ba952a1baa0200 include/common/mir_toolkit/events/input/touch_input_event.h

Subscribers

People subscribed via source and target branches