Mir

Merge lp:~robertcarr/mir/demo-input-filters into lp:~mir-team/mir/trunk

Proposed by Robert Carr
Status: Merged
Approved by: Kevin DuBois
Approved revision: no longer in the source branch.
Merged at revision: 587
Proposed branch: lp:~robertcarr/mir/demo-input-filters
Merge into: lp:~mir-team/mir/trunk
Diff against target: 196 lines (+109/-26)
2 files modified
examples/CMakeLists.txt (+21/-26)
examples/demo_input_filter.cpp (+88/-0)
To merge this branch: bzr merge lp:~robertcarr/mir/demo-input-filters
Reviewer Review Type Date Requested Status
PS Jenkins bot (community) continuous-integration Approve
Alexandros Frantzis (community) Approve
Daniel van Vugt Approve
Review via email: mp+158199@code.launchpad.net

Commit message

Add example demonstrating usage of input filters

Description of the change

Demonstrate usage of input filters.

There is a slight quirk in the static reference to the event filter list (would be nice to just return { event_filter }...see

https://bugs.launchpad.net/mir/+bug/1167133

To post a comment you must log in.
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
kevin gunn (kgunn72) wrote :

really ?

+ * Authored by: Alan Griffiths <email address hidden>

Revision history for this message
Robert Carr (robertcarr) wrote :

Whoops!

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

Sorry, my fault again...

/home/dan/bzr/mir/tmp.demo/examples/demo_input_filter.cpp: In member function ‘virtual bool {anonymous}::PrintingEventFilter::handles(const MirEvent&)’:
/home/dan/bzr/mir/tmp.demo/examples/demo_input_filter.cpp:39:81: error: ‘const union MirEvent’ has no member named ‘details’
/home/dan/bzr/mir/tmp.demo/examples/demo_input_filter.cpp:40:23: error: ‘const union MirEvent’ has no member named ‘details’
/home/dan/bzr/mir/tmp.demo/examples/demo_input_filter.cpp:40:58: error: ‘const union MirEvent’ has no member named ‘details’
/home/dan/bzr/mir/tmp.demo/examples/demo_input_filter.cpp:42:89: error: ‘const union MirEvent’ has no member named ‘details’
/home/dan/bzr/mir/tmp.demo/examples/demo_input_filter.cpp:43:23: error: ‘const union MirEvent’ has no member named ‘details’
/home/dan/bzr/mir/tmp.demo/examples/demo_input_filter.cpp:43:76: error: ‘const union MirEvent’ has no member named ‘details’
make[2]: *** [examples/CMakeFiles/mir_demo_input_filter.dir/demo_input_filter.cpp.o] Error 1
make[1]: *** [examples/CMakeFiles/mir_demo_input_filter.dir/all] Error 2

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

Nits:

68 + if (ev.type == mir_event_type_key)

It would be a bit cleaner to add curly braces around the multi-line statement that follows.

93 + std::shared_ptr<PrintingEventFilter> event_filter;

Can be const.

Revision history for this message
Robert Carr (robertcarr) wrote :

Trunk merged, MirEventUsage updated, Nits applied!

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

I have no opinion until I get back to this, later. :)

review: Abstain
Revision history for this message
Daniel van Vugt (vanvugt) wrote :

OK, looks good.

If I had to nitpick then:

1. Use a consistent CMake syntax. I would recommend:
  add_executable (A
    B.cpp
    C.cpp
    D.cpp
  )
  target_link_libraries (A
    X
    Y
    Z
  )
Because the first argument/s is fixed and required. And subsequent arguments are often part of a variable-length list.

2. This style is confusing and potentially dangerous. Because it's less clear where the real end of the function will be:
  int main()
  try ()
  {
    return 0;
  }
  catch ()
  {
    return 1;
  }
  catch ()
  {
    return 1;
  }
  // There might be more...
  catch ()
  {
    ...
  }

I think it would be clearer as:
  int main()
  {
    int ret = 0;
    try ()
    {
    }
    catch ()
    {
      ret = 1;
    }
    catch ()
    {
      ret = 1;
    }
    return ret;
  }

But overall, it's nice and instructive to see a simple server in action.

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

Looks good.

review: Approve
Revision history for this message
Robert Carr (robertcarr) wrote :

Did some minor cmake cleanup :)

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
Kevin DuBois (kdub) wrote :

jenkins fails with
keyserver.ubuntu.com: No route to host
?

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

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'examples/CMakeLists.txt'
2--- examples/CMakeLists.txt 2013-04-01 16:45:07 +0000
3+++ examples/CMakeLists.txt 2013-04-12 17:40:32 +0000
4@@ -27,15 +27,11 @@
5 eglapp
6 )
7
8-add_executable(
9- mir_demo_client
10-
11+add_executable(mir_demo_client
12 demo_client.c
13 )
14
15-target_link_libraries(
16- mir_demo_client
17-
18+target_link_libraries(mir_demo_client
19 mirclient
20 mirprotobuf
21
22@@ -44,15 +40,11 @@
23 ${CMAKE_THREAD_LIBS_INIT}
24 )
25
26-add_executable(
27- mir_demo_client_unaccelerated
28-
29+add_executable(mir_demo_client_unaccelerated
30 demo_client_unaccelerated.c
31 )
32
33-target_link_libraries(
34- mir_demo_client_unaccelerated
35-
36+target_link_libraries(mir_demo_client_unaccelerated
37 mirclient
38 mirprotobuf
39
40@@ -61,15 +53,11 @@
41 ${CMAKE_THREAD_LIBS_INIT}
42 )
43
44-add_executable(
45- mir_demo_client_accelerated
46-
47+add_executable(mir_demo_client_accelerated
48 demo_client_accelerated.cpp
49 )
50
51-target_link_libraries(
52- mir_demo_client_accelerated
53-
54+target_link_libraries(mir_demo_client_accelerated
55 mirdraw
56 mirclient
57 mirprotobuf
58@@ -90,11 +78,11 @@
59 )
60
61 set(RENDER_TO_FB_SOURCES render_to_fb.cpp)
62-add_executable(render_to_fb ${RENDER_TO_FB_SOURCES})
63-
64-target_link_libraries(
65- render_to_fb
66-
67+add_executable(render_to_fb
68+ ${RENDER_TO_FB_SOURCES}
69+)
70+
71+target_link_libraries(render_to_fb
72 mirserver
73 mirlogging
74 mirdraw
75@@ -103,18 +91,25 @@
76
77 set(RENDER_SURFACES_SOURCES render_surfaces.cpp buffer_render_target.cpp image_renderer.cpp)
78 add_executable(render_surfaces ${RENDER_SURFACES_SOURCES})
79-target_link_libraries(
80- render_surfaces
81-
82+target_link_libraries(render_surfaces
83 mirserver
84 mirshell
85 ${Boost_LIBRARIES}
86 )
87
88+add_executable(mir_demo_input_filter
89+ demo_input_filter.cpp
90+)
91+
92+target_link_libraries(mir_demo_input_filter
93+ mirserver
94+)
95+
96 set (DEMO_CLIENTS
97 mir_demo_client
98 mir_demo_client_unaccelerated
99 mir_demo_client_accelerated
100+ mir_demo_input_filter
101 mir_eglflash
102 mir_egltriangle
103 mir_eglplasma
104
105=== added file 'examples/demo_input_filter.cpp'
106--- examples/demo_input_filter.cpp 1970-01-01 00:00:00 +0000
107+++ examples/demo_input_filter.cpp 2013-04-12 17:40:32 +0000
108@@ -0,0 +1,88 @@
109+/*
110+ * Copyright © 2013 Canonical Ltd.
111+ *
112+ * This program is free software: you can redistribute it and/or modify
113+ * it under the terms of the GNU General Public License version 3 as
114+ * published by the Free Software Foundation.
115+ *
116+ * This program is distributed in the hope that it will be useful,
117+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
118+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
119+ * GNU General Public License for more details.
120+ *
121+ * You should have received a copy of the GNU General Public License
122+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
123+ *
124+ * Authored by: Robert Carr <robert.carr@canonical.com>
125+ */
126+
127+#include "mir/run_mir.h"
128+#include "mir/default_server_configuration.h"
129+#include "mir/abnormal_exit.h"
130+#include "mir/input/event_filter.h"
131+
132+#include <boost/exception/diagnostic_information.hpp>
133+
134+#include <iostream>
135+
136+namespace mi = mir::input;
137+
138+namespace
139+{
140+
141+struct PrintingEventFilter : public mi::EventFilter
142+{
143+ bool handles(MirEvent const& ev) override
144+ {
145+ // TODO: Enhance printing
146+ if (ev.type == mir_event_type_key)
147+ {
148+ std::cout << "Handling key event (time, scancode, keycode): " << ev.key.event_time << " "
149+ << ev.key.scan_code << " " << ev.key.key_code << std::endl;
150+ }
151+ else if (ev.type == mir_event_type_motion)
152+ {
153+ std::cout << "Handling motion event (time, pointer0_x, pointer0_y): " << ev.motion.event_time << " "
154+ << ev.motion.pointer_coordinates[0].x << " " << ev.motion.pointer_coordinates[0].y << std::endl;
155+ }
156+ return true;
157+ }
158+};
159+
160+struct DemoServerConfiguration : public mir::DefaultServerConfiguration
161+{
162+ DemoServerConfiguration(int argc, char const* argv[])
163+ : DefaultServerConfiguration(argc, argv),
164+ event_filter(std::make_shared<PrintingEventFilter>())
165+ {
166+ }
167+
168+ std::initializer_list<std::shared_ptr<mi::EventFilter> const> the_event_filters() override
169+ {
170+ static std::initializer_list<std::shared_ptr<mi::EventFilter> const> filter_list = { event_filter };
171+ return filter_list;
172+ }
173+
174+ std::shared_ptr<PrintingEventFilter> const event_filter;
175+};
176+
177+}
178+
179+int main(int argc, char const* argv[])
180+try
181+{
182+ DemoServerConfiguration config(argc, argv);
183+
184+ mir::run_mir(config, [](mir::DisplayServer&) {/* empty init */});
185+ return 0;
186+}
187+catch (mir::AbnormalExit const& error)
188+{
189+ std::cerr << error.what() << std::endl;
190+ return 1;
191+}
192+catch (std::exception const& error)
193+{
194+ std::cerr << "ERROR: " << boost::diagnostic_information(error) << std::endl;
195+ return 1;
196+}

Subscribers

People subscribed via source and target branches