Mir
seat_input_device_tracker.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 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 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:
17  * Andreas Pokorny <andreas.pokorny@canonical.com>
18  */
19 
20 #ifndef MIR_INPUT_SEAT_INPUT_DEVICE_TRACKER_H
21 #define MIR_INPUT_SEAT_INPUT_DEVICE_TRACKER_H
22 
24 #include "mir/geometry/point.h"
26 #include "mir_toolkit/event.h"
27 #include <unordered_map>
28 #include <memory>
29 
30 namespace mir
31 {
32 using EventUPtr = std::unique_ptr<MirEvent, void(*)(MirEvent*)>;
33 namespace time
34 {
35 class Clock;
36 }
37 namespace input
38 {
39 class CursorListener;
40 class InputRegion;
41 class InputDispatcher;
42 class KeyMapper;
43 
44 /*
45  * The SeatInputDeviceTracker bundles the input device properties of a group of devices defined by a seat:
46  * - a single cursor position,
47  * - modifier key states (i.e alt, ctrl ..)
48  * - a single mouse button state for all pointing devices
49  * - visible touch spots
50  */
52 {
53 public:
54  SeatInputDeviceTracker(std::shared_ptr<InputDispatcher> const& dispatcher,
55  std::shared_ptr<TouchVisualizer> const& touch_visualizer,
56  std::shared_ptr<CursorListener> const& cursor_listener,
57  std::shared_ptr<InputRegion> const& input_region,
58  std::shared_ptr<KeyMapper> const& key_mapper,
59  std::shared_ptr<time::Clock> const& clock);
60  void add_device(MirInputDeviceId);
61  void remove_device(MirInputDeviceId);
62 
63  void dispatch(MirEvent & event);
64 
65  MirPointerButtons button_state() const;
66  geometry::Point cursor_position() const;
67  EventUPtr create_device_state() const;
68 
69  void set_key_state(MirInputDeviceId id, std::vector<uint32_t> const& scan_codes);
70  void set_pointer_state(MirInputDeviceId id, MirPointerButtons buttons);
71  void set_cursor_position(float cursor_x, float cursor_y);
72  void set_confinement_regions(geometry::Rectangles const& region);
73  void reset_confinement_regions();
74 private:
75  void update_seat_properties(MirInputEvent const* event);
76  void update_cursor(MirPointerEvent const* event);
77  void update_spots();
78  void update_states();
79  bool filter_input_event(MirInputEvent const* event);
80  void confine_pointer();
81 
82  std::shared_ptr<InputDispatcher> const dispatcher;
83  std::shared_ptr<TouchVisualizer> const touch_visualizer;
84  std::shared_ptr<CursorListener> const cursor_listener;
85  std::shared_ptr<InputRegion> const input_region;
86  std::shared_ptr<KeyMapper> const key_mapper;
87  std::shared_ptr<time::Clock> const clock;
88 
89  struct DeviceData
90  {
91  DeviceData() {}
92  bool update_button_state(MirPointerButtons button_state);
93  bool update_spots(MirTouchEvent const* event);
94  void update_scan_codes(MirKeyboardEvent const* event);
95  bool allowed_scan_code_action(MirKeyboardEvent const* event) const;
96 
97  MirPointerButtons buttons{0};
98  std::vector<TouchVisualizer::Spot> spots;
99  std::vector<uint32_t> scan_codes;
100  };
101 
102  // Libinput's acceleration curve means the cursor moves by non-integer
103  // increments, and often less than 1.0, so float is required...
104  float cursor_x = 0.0f, cursor_y = 0.0f;
105 
106  MirPointerButtons buttons;
107  std::unordered_map<MirInputDeviceId, DeviceData> device_data;
108  std::vector<TouchVisualizer::Spot> spots;
109  std::function<void(mir::geometry::Point&)> confine_function;
110 };
111 
112 }
113 }
114 
115 #endif
All things Mir.
Definition: atomic_callback.h:25
A collection of rectangles (with possible duplicates).
Definition: rectangles.h:34
Definition: point.h:30
Definition: keyboard_event.h:28
Definition: motion_event.h:143
void set_cursor_position(MirEvent &event, mir::geometry::Point const &pos)
Definition: event_builders.cpp:213
Definition: seat_input_device_tracker.h:51
int64_t MirInputDeviceId
Definition: input_event.h:35
std::unique_ptr< MirEvent, void(*)(MirEvent *)> EventUPtr
Definition: seat.h:32
unsigned int MirPointerButtons
Definition: pointer_event.h:85
Definition: input_event.h:24
Definition: motion_event.h:147
Definition: event.h:30

Copyright © 2012-2015 Canonical Ltd.
Generated on Thu Sep 8 14:50:19 UTC 2016