Mir
surface_input_dispatcher.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: Robert Carr <robert.carr@canonical.com>
17  */
18 
19 #ifndef MIR_INPUT_DEFAULT_INPUT_DISPATCHER_H_
20 #define MIR_INPUT_DEFAULT_INPUT_DISPATCHER_H_
21 
24 #include "mir/geometry/point.h"
25 
26 #include <memory>
27 #include <mutex>
28 #include <unordered_map>
29 #include <unordered_set>
30 
31 namespace mir
32 {
33 namespace scene
34 {
35 class Observer;
36 class Surface;
37 }
38 namespace input
39 {
40 class Surface;
41 class Scene;
42 
44 {
45 public:
46  SurfaceInputDispatcher(std::shared_ptr<input::Scene> const& scene);
48 
49  // mir::input::InputDispatcher
50  bool dispatch(MirEvent const& event) override;
51  void start() override;
52  void stop() override;
53 
54  // InputTargeter
55  void set_focus(std::shared_ptr<input::Surface> const& target) override;
56  void clear_focus() override;
57 
58 private:
59  void device_reset(MirInputDeviceId reset_device_id, std::chrono::nanoseconds when);
60  bool dispatch_key(MirInputDeviceId id, MirKeyboardEvent const* kev);
61  bool dispatch_pointer(MirInputDeviceId id, MirPointerEvent const* pev);
62  bool dispatch_touch(MirInputDeviceId id, MirTouchEvent const* tev);
63 
64  void send_enter_exit_event(std::shared_ptr<input::Surface> const& surface,
65  MirPointerEvent const* triggering_ev, MirPointerAction action);
66 
67  std::shared_ptr<input::Surface> find_target_surface(geometry::Point const& target);
68 
69  void set_focus_locked(std::lock_guard<std::mutex> const&, std::shared_ptr<input::Surface> const&);
70 
71  void surface_removed(scene::Surface* surface);
72 
73  struct KeyInputState
74  {
75  bool handle_event(MirInputDeviceId id, MirKeyboardEvent const* kev);
76 
77  bool press_key(MirInputDeviceId id, int scan_code);
78  bool repeat_key(MirInputDeviceId id, int scan_code);
79  bool release_key(MirInputDeviceId id, int scan_code);
80 
81  void clear();
82 
83  std::unordered_map<MirInputDeviceId, std::unordered_set<int>> depressed_scancodes;
84  } focus_surface_key_state;
85 
86  // Look in to homognizing index on KeyInputState and PointerInputState (wrt to device id)
87  struct PointerInputState
88  {
89  std::shared_ptr<input::Surface> current_target;
90  std::shared_ptr<input::Surface> gesture_owner;
91  };
92  std::unordered_map<MirInputDeviceId, PointerInputState> pointer_state_by_id;
93  PointerInputState& ensure_pointer_state(MirInputDeviceId id);
94 
95  struct TouchInputState
96  {
97  std::shared_ptr<input::Surface> gesture_owner;
98  };
99  std::unordered_map<MirInputDeviceId, TouchInputState> touch_state_by_id;
100  TouchInputState& ensure_touch_state(MirInputDeviceId id);
101 
102  std::shared_ptr<input::Scene> const scene;
103 
104  std::shared_ptr<scene::Observer> scene_observer;
105 
106  std::mutex dispatcher_mutex;
107  std::weak_ptr<input::Surface> focus_surface;
108  bool started;
109 };
110 
111 }
112 }
113 
114 #endif // MIR_INPUT_DEFAULT_INPUT_DISPATCHER_H_
All things Mir.
Definition: atomic_callback.h:25
The InputDispatchers role is to decide what should happen with user input events. ...
Definition: input_dispatcher.h:38
SurfaceInputDispatcher(std::shared_ptr< input::Scene > const &scene)
Definition: surface_input_dispatcher.cpp:95
Definition: point.h:30
struct MirPointerEvent MirPointerEvent
An event type describing a change in pointer device state.
Definition: pointer_event.h:35
MirPointerAction
Possible pointer actions.
Definition: pointer_event.h:40
An interface used to control the selection of keyboard input focus.
Definition: input_targeter.h:35
void clear_focus() override
Definition: surface_input_dispatcher.cpp:430
void stop() override
Definition: surface_input_dispatcher.cpp:407
Definition: surface_input_dispatcher.h:43
struct MirTouchEvent MirTouchEvent
An event type describing a change in touch device state.
Definition: touch_event.h:33
int64_t MirInputDeviceId
Definition: input_event.h:34
~SurfaceInputDispatcher()
Definition: surface_input_dispatcher.cpp:103
struct MirKeyboardEvent MirKeyboardEvent
An event type describing a change in keyboard state.
Definition: keyboard_event.h:44
void start() override
Definition: surface_input_dispatcher.cpp:400
Definition: event_private.h:178
void set_focus(std::shared_ptr< input::Surface > const &target) override
Definition: surface_input_dispatcher.cpp:424
bool dispatch(MirEvent const &event) override
Definition: surface_input_dispatcher.cpp:369
Definition: surface.h:47

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