Mir
libinput_device.h
Go to the documentation of this file.
1 /*
2  * Copyright © 2015 Canonical Ltd.
3  *
4  * This program is free software: you can redistribute it and/or modify it
5  * under the terms of the GNU Lesser General Public License version 3,
6  * as 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 Lesser General Public License for more details.
12  *
13  * You should have received a copy of the GNU Lesser General Public License
14  * along with this program. If not, see <http://www.gnu.org/licenses/>.
15  *
16  * Authored by: Andreas Pokorny <andreas.pokorny@canonical.com>
17  */
18 
19 #ifndef MIR_INPUT_EVDEV_LIBINPUT_DEVICE_H_
20 #define MIR_INPUT_EVDEV_LIBINPUT_DEVICE_H_
21 
22 #include "libinput_ptr.h"
23 #include "libinput_device_ptr.h"
24 
26 #include "mir/input/input_device.h"
28 #include "mir/geometry/point.h"
29 
30 #include <vector>
31 #include <unordered_map>
32 
33 struct libinput_event;
34 struct libinput_event_keyboard;
35 struct libinput_event_touch;
36 struct libinput_event_pointer;
37 struct libinput_device_group;
38 
39 namespace mir
40 {
41 namespace input
42 {
43 class InputReport;
44 namespace evdev
45 {
46 struct PointerState;
47 struct KeyboardState;
48 
50 {
51 public:
52  LibInputDevice(std::shared_ptr<InputReport> const& report, char const* path, LibInputDevicePtr dev);
54  void start(InputSink* sink, EventBuilder* builder) override;
55  void stop() override;
57 
58  void process_event(libinput_event* event);
59  ::libinput_device* device() const;
60  ::libinput_device_group* group();
61  void add_device_of_group(char const* path, LibInputDevicePtr ptr);
62  bool is_in_group(char const* path);
63 private:
64  EventUPtr convert_event(libinput_event_keyboard* keyboard);
65  EventUPtr convert_button_event(libinput_event_pointer* pointer);
66  EventUPtr convert_motion_event(libinput_event_pointer* pointer);
67  EventUPtr convert_absolute_motion_event(libinput_event_pointer* pointer);
68  EventUPtr convert_axis_event(libinput_event_pointer* pointer);
69  void add_touch_down_event(libinput_event_touch* touch);
70  void add_touch_up_event(libinput_event_touch* touch);
71  void add_touch_motion_event(libinput_event_touch* touch);
72  MirEvent& get_accumulated_touch_event(std::chrono::nanoseconds timestamp);
73  void update_device_info();
74 
75  std::shared_ptr<InputReport> report;
76  std::shared_ptr<::libinput> lib;
77  std::vector<std::string> paths;
78  std::vector<LibInputDevicePtr> devices;
79  std::shared_ptr<dispatch::Dispatchable> dispatchable_fd;
80 
81  InputSink* sink{nullptr};
82  EventBuilder* builder{nullptr};
83  EventUPtr accumulated_touch_event;
84 
85  InputDeviceInfo info;
86  mir::geometry::Point pointer_pos;
87  MirInputEventModifiers modifier_state;
88  MirPointerButtons button_state;
89 
90  struct ContactData
91  {
92  ContactData() {}
93  float x{0}, y{0}, major{0}, minor{0}, pressure{0};
94  };
95  std::unordered_map<MirTouchId,ContactData> last_seen_properties;
96 
97  void update_contact_data(ContactData &data, libinput_event_touch* touch);
98 };
99 }
100 }
101 }
102 
103 #endif
LibInputDevice(std::shared_ptr< InputReport > const &report, char const *path, LibInputDevicePtr dev)
All things Mir.
Definition: atomic_callback.h:25
void add_device_of_group(char const *path, LibInputDevicePtr ptr)
::libinput_device * device() const
Definition: point.h:30
void start(InputSink *sink, EventBuilder *builder) override
Represents an input device.
Definition: input_device.h:40
Definition: libinput_device.h:49
bool is_in_group(char const *path)
void process_event(libinput_event *event)
unsigned int MirInputEventModifiers
Definition: input_event.h:65
std::unique_ptr< libinput_device, libinput_device *(*)(libinput_device *)> LibInputDevicePtr
Definition: libinput_device_ptr.h:33
std::unique_ptr< MirEvent, void(*)(MirEvent *)> EventUPtr
Definition: event_builders.h:33
unsigned int MirPointerButtons
Definition: pointer_event.h:82
InputDeviceInfo get_device_info() override
Definition: input_device_info.h:32
Definition: event_private.h:178
Definition: event_builder.h:34
Definition: input_sink.h:31
::libinput_device_group * group()

Copyright © 2012-2015 Canonical Ltd.
Generated on Thu Oct 8 16:20:16 UTC 2015