Mir
default_input_device_hub.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: Andreas Pokorny <andreas.pokorny@canonical.com>
17  */
18 
19 #ifndef MIR_INPUT_DEFAULT_INPUT_DEVICE_HUB_H_
20 #define MIR_INPUT_DEFAULT_INPUT_DEVICE_HUB_H_
21 
22 #include "default_event_builder.h"
23 
25 #include "mir/input/input_sink.h"
29 
30 #include "mir_toolkit/event.h"
31 
32 #include <linux/input.h>
33 #include <vector>
34 #include <memory>
35 
36 namespace mir
37 {
38 class ServerActionQueue;
39 namespace dispatch
40 {
41 class Dispatchable;
42 class MultiplexingDispatchable;
43 }
44 namespace input
45 {
46 class InputDispatcher;
47 class InputSink;
48 class InputDeviceObserver;
49 class TouchVisualizer;
50 class InputRegion;
51 class CursorListener;
52 class DefaultDevice;
53 
55 {
56 public:
57  DefaultInputDeviceHub(std::shared_ptr<InputDispatcher> const& input_dispatcher,
58  std::shared_ptr<dispatch::MultiplexingDispatchable> const& input_multiplexer,
59  std::shared_ptr<ServerActionQueue> const& observer_queue,
60  std::shared_ptr<TouchVisualizer> const& touch_visualizer,
61  std::shared_ptr<CursorListener> const& cursor_listener,
62  std::shared_ptr<InputRegion> const& input_region);
63 
64  // InputDeviceRegistry - calls from mi::Platform
65  void add_device(std::shared_ptr<InputDevice> const& device) override;
66  void remove_device(std::shared_ptr<InputDevice> const& device) override;
67 
68  // InputDeviceHub - calls from server components / shell
69  void add_observer(std::shared_ptr<InputDeviceObserver> const&) override;
70  void remove_observer(std::weak_ptr<InputDeviceObserver> const&) override;
71 
72 private:
73  void update_spots();
74  void add_device_handle(std::shared_ptr<DefaultDevice> const& handle);
75  void remove_device_handle(MirInputDeviceId id);
76  MirInputDeviceId create_new_device_id();
77  std::shared_ptr<InputDispatcher> const input_dispatcher;
78  std::shared_ptr<dispatch::MultiplexingDispatchable> const input_dispatchable;
79  std::shared_ptr<ServerActionQueue> const observer_queue;
80  std::shared_ptr<TouchVisualizer> const touch_visualizer;
81  std::shared_ptr<CursorListener> const cursor_listener;
82  std::shared_ptr<InputRegion> const input_region;
83 
84  struct RegisteredDevice : public InputSink
85  {
86  public:
87  RegisteredDevice(std::shared_ptr<InputDevice> const& dev, MirInputDeviceId dev_id, std::shared_ptr<InputDispatcher> const& dispatcher, std::shared_ptr<dispatch::MultiplexingDispatchable> const& multiplexer, DefaultInputDeviceHub * hub);
88  void handle_input(MirEvent& event) override;
89  void confine_pointer(mir::geometry::Point& position) override;
90  mir::geometry::Rectangle bounding_rectangle() const override;
91  bool device_matches(std::shared_ptr<InputDevice> const& dev) const;
92  void start();
93  void stop();
94  MirInputDeviceId id();
95  std::vector<TouchVisualizer::Spot> const& spots() const;
96  private:
97  void update_spots(MirInputEvent const* event);
98  void notify_cursor_listener(MirInputEvent const* event);
99  MirInputDeviceId device_id;
100  DefaultEventBuilder builder;
101  std::shared_ptr<InputDevice> const device;
102  std::shared_ptr<InputDispatcher> const dispatcher;
103  std::shared_ptr<dispatch::MultiplexingDispatchable> const multiplexer;
104  DefaultInputDeviceHub * hub;
105  std::vector<TouchVisualizer::Spot> touch_spots;
106  friend class DefaultInputDeviceHub;
107  };
108 
109  std::vector<std::shared_ptr<DefaultDevice>> handles;
110  std::vector<std::unique_ptr<RegisteredDevice>> devices;
111  std::vector<std::shared_ptr<InputDeviceObserver>> observers;
112 
113  MirInputDeviceId device_id_generator;
114 };
115 
116 }
117 }
118 
119 #endif
All things Mir.
Definition: atomic_callback.h:25
void remove_observer(std::weak_ptr< InputDeviceObserver > const &) override
Definition: default_input_device_hub.cpp:238
Definition: point.h:30
DefaultInputDeviceHub(std::shared_ptr< InputDispatcher > const &input_dispatcher, std::shared_ptr< dispatch::MultiplexingDispatchable > const &input_multiplexer, std::shared_ptr< ServerActionQueue > const &observer_queue, std::shared_ptr< TouchVisualizer > const &touch_visualizer, std::shared_ptr< CursorListener > const &cursor_listener, std::shared_ptr< InputRegion > const &input_region)
Definition: default_input_device_hub.cpp:39
Definition: input_device_hub.h:31
Definition: default_event_builder.h:30
Definition: input_device_registry.h:31
void add_device(std::shared_ptr< InputDevice > const &device) override
Definition: default_input_device_hub.cpp:51
void add_observer(std::shared_ptr< InputDeviceObserver > const &) override
Definition: default_input_device_hub.cpp:222
int64_t MirInputDeviceId
Definition: input_event.h:34
Definition: default_input_device_hub.h:54
Definition: rectangle.h:33
struct MirInputEvent MirInputEvent
Definition: event.h:56
Definition: event_private.h:178
void remove_device(std::shared_ptr< InputDevice > const &device) override
Definition: default_input_device_hub.cpp:90
Definition: input_sink.h:31

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