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
=== modified file 'examples/CMakeLists.txt'
--- examples/CMakeLists.txt 2013-04-01 16:45:07 +0000
+++ examples/CMakeLists.txt 2013-04-12 17:40:32 +0000
@@ -27,15 +27,11 @@
27 eglapp27 eglapp
28)28)
2929
30add_executable(30add_executable(mir_demo_client
31 mir_demo_client
32
33 demo_client.c31 demo_client.c
34)32)
3533
36target_link_libraries(34target_link_libraries(mir_demo_client
37 mir_demo_client
38
39 mirclient35 mirclient
40 mirprotobuf36 mirprotobuf
4137
@@ -44,15 +40,11 @@
44 ${CMAKE_THREAD_LIBS_INIT}40 ${CMAKE_THREAD_LIBS_INIT}
45)41)
4642
47add_executable(43add_executable(mir_demo_client_unaccelerated
48 mir_demo_client_unaccelerated
49
50 demo_client_unaccelerated.c44 demo_client_unaccelerated.c
51)45)
5246
53target_link_libraries(47target_link_libraries(mir_demo_client_unaccelerated
54 mir_demo_client_unaccelerated
55
56 mirclient48 mirclient
57 mirprotobuf49 mirprotobuf
5850
@@ -61,15 +53,11 @@
61 ${CMAKE_THREAD_LIBS_INIT}53 ${CMAKE_THREAD_LIBS_INIT}
62)54)
6355
64add_executable(56add_executable(mir_demo_client_accelerated
65 mir_demo_client_accelerated
66
67 demo_client_accelerated.cpp57 demo_client_accelerated.cpp
68)58)
6959
70target_link_libraries(60target_link_libraries(mir_demo_client_accelerated
71 mir_demo_client_accelerated
72
73 mirdraw61 mirdraw
74 mirclient62 mirclient
75 mirprotobuf63 mirprotobuf
@@ -90,11 +78,11 @@
90)78)
9179
92set(RENDER_TO_FB_SOURCES render_to_fb.cpp)80set(RENDER_TO_FB_SOURCES render_to_fb.cpp)
93add_executable(render_to_fb ${RENDER_TO_FB_SOURCES})81add_executable(render_to_fb
9482 ${RENDER_TO_FB_SOURCES}
95target_link_libraries(83)
96 render_to_fb84
9785target_link_libraries(render_to_fb
98 mirserver86 mirserver
99 mirlogging87 mirlogging
100 mirdraw88 mirdraw
@@ -103,18 +91,25 @@
10391
104set(RENDER_SURFACES_SOURCES render_surfaces.cpp buffer_render_target.cpp image_renderer.cpp)92set(RENDER_SURFACES_SOURCES render_surfaces.cpp buffer_render_target.cpp image_renderer.cpp)
105add_executable(render_surfaces ${RENDER_SURFACES_SOURCES})93add_executable(render_surfaces ${RENDER_SURFACES_SOURCES})
106target_link_libraries(94target_link_libraries(render_surfaces
107 render_surfaces
108
109 mirserver95 mirserver
110 mirshell96 mirshell
111 ${Boost_LIBRARIES}97 ${Boost_LIBRARIES}
112)98)
11399
100add_executable(mir_demo_input_filter
101 demo_input_filter.cpp
102)
103
104target_link_libraries(mir_demo_input_filter
105 mirserver
106)
107
114set (DEMO_CLIENTS108set (DEMO_CLIENTS
115 mir_demo_client109 mir_demo_client
116 mir_demo_client_unaccelerated110 mir_demo_client_unaccelerated
117 mir_demo_client_accelerated111 mir_demo_client_accelerated
112 mir_demo_input_filter
118 mir_eglflash113 mir_eglflash
119 mir_egltriangle114 mir_egltriangle
120 mir_eglplasma115 mir_eglplasma
121116
=== added file 'examples/demo_input_filter.cpp'
--- examples/demo_input_filter.cpp 1970-01-01 00:00:00 +0000
+++ examples/demo_input_filter.cpp 2013-04-12 17:40:32 +0000
@@ -0,0 +1,88 @@
1/*
2 * Copyright © 2013 Canonical Ltd.
3 *
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 3 as
6 * published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 *
16 * Authored by: Robert Carr <robert.carr@canonical.com>
17 */
18
19#include "mir/run_mir.h"
20#include "mir/default_server_configuration.h"
21#include "mir/abnormal_exit.h"
22#include "mir/input/event_filter.h"
23
24#include <boost/exception/diagnostic_information.hpp>
25
26#include <iostream>
27
28namespace mi = mir::input;
29
30namespace
31{
32
33struct PrintingEventFilter : public mi::EventFilter
34{
35 bool handles(MirEvent const& ev) override
36 {
37 // TODO: Enhance printing
38 if (ev.type == mir_event_type_key)
39 {
40 std::cout << "Handling key event (time, scancode, keycode): " << ev.key.event_time << " "
41 << ev.key.scan_code << " " << ev.key.key_code << std::endl;
42 }
43 else if (ev.type == mir_event_type_motion)
44 {
45 std::cout << "Handling motion event (time, pointer0_x, pointer0_y): " << ev.motion.event_time << " "
46 << ev.motion.pointer_coordinates[0].x << " " << ev.motion.pointer_coordinates[0].y << std::endl;
47 }
48 return true;
49 }
50};
51
52struct DemoServerConfiguration : public mir::DefaultServerConfiguration
53{
54 DemoServerConfiguration(int argc, char const* argv[])
55 : DefaultServerConfiguration(argc, argv),
56 event_filter(std::make_shared<PrintingEventFilter>())
57 {
58 }
59
60 std::initializer_list<std::shared_ptr<mi::EventFilter> const> the_event_filters() override
61 {
62 static std::initializer_list<std::shared_ptr<mi::EventFilter> const> filter_list = { event_filter };
63 return filter_list;
64 }
65
66 std::shared_ptr<PrintingEventFilter> const event_filter;
67};
68
69}
70
71int main(int argc, char const* argv[])
72try
73{
74 DemoServerConfiguration config(argc, argv);
75
76 mir::run_mir(config, [](mir::DisplayServer&) {/* empty init */});
77 return 0;
78}
79catch (mir::AbnormalExit const& error)
80{
81 std::cerr << error.what() << std::endl;
82 return 1;
83}
84catch (std::exception const& error)
85{
86 std::cerr << "ERROR: " << boost::diagnostic_information(error) << std::endl;
87 return 1;
88}

Subscribers

People subscribed via source and target branches