]> rtime.felk.cvut.cz Git - l4.git/blob - l4/pkg/mag/plugins/input_libinput/input_libinput.cc
update
[l4.git] / l4 / pkg / mag / plugins / input_libinput / input_libinput.cc
1 /*
2  * (c) 2010 Adam Lackorzynski <adam@os.inf.tu-dresden.de>,
3  *          Alexander Warg <warg@os.inf.tu-dresden.de>
4  *     economic rights: Technische Universität Dresden (Germany)
5  *
6  * This file is part of TUD:OS and distributed under the terms of the
7  * GNU General Public License 2.
8  * Please see the COPYING-GPL-2 file for details.
9  */
10 #include <l4/mag/server/input_driver>
11
12 #include <l4/input/libinput.h>
13
14 namespace {
15 using Mag_server::Input_driver;
16 using Mag_server::Input_source;
17 using Mag_server::Core_api;
18 using Mag_server::User_state;
19 using Mag_server::Motion_fwd;
20
21 struct Emit
22 {
23   User_state *u;
24   Emit(User_state *u) : u(u) {}
25   void operator () (L4Re::Event_buffer::Event const &e) const
26   { u->handle_event(e); }
27 };
28
29 class Input_driver_libinput : public Input_driver, public Input_source
30 {
31 public:
32   Input_driver_libinput() : Input_driver("libinput") {}
33   void start(Core_api *core)
34   {
35     if (l4input_init(0xff, 0) == 0)
36       {
37         _core = core;
38         core->add_input_source(this);
39       }
40   }
41
42   void poll_events()
43   {
44     if (!l4input_ispending())
45       return;
46
47     enum { N=20 };
48     L4Re::Event_buffer::Event _evb[N];
49
50     int max = l4input_flush(_evb, N);
51     //Motion_merger<10> mm;
52     Motion_fwd mm;
53     mm.process/*<L4Re::Event_buffer::Event>*/(&_evb[0], _evb + max, Emit(_core->user_state()));
54   }
55 };
56
57 static Input_driver_libinput _libinput;
58 }