Mir
key_repeat_dispatcher.h
Go to the documentation of this file.
1 /*
2  * Copyright © 2015-2016 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_KEY_REPEAT_DISPATCHER_H_
20 #define MIR_INPUT_KEY_REPEAT_DISPATCHER_H_
21 
24 #include "mir/optional_value.h"
25 
26 #include <memory>
27 #include <chrono>
28 #include <mutex>
29 #include <unordered_map>
30 
31 namespace mir
32 {
33 namespace cookie
34 {
35 class Authority;
36 }
37 namespace time
38 {
39 class AlarmFactory;
40 class Alarm;
41 }
42 namespace input
43 {
44 class InputDeviceHub;
46 {
47 public:
48  KeyRepeatDispatcher(std::shared_ptr<InputDispatcher> const& next_dispatcher,
49  std::shared_ptr<time::AlarmFactory> const& factory,
50  std::shared_ptr<cookie::Authority> const& cookie_authority,
51  bool repeat_enabled,
52  std::chrono::milliseconds repeat_timeout, /* timeout before sending first repeat */
53  std::chrono::milliseconds repeat_delay, /* delay between repeated keys */
54  bool disable_repeat_on_mtk_touchpad);
55 
56  // InputDispatcher
57  bool dispatch(MirEvent const& event) override;
58  void start() override;
59  void stop() override;
60 
61  void set_input_device_hub(std::shared_ptr<InputDeviceHub> const& hub);
62 
63  void set_mtk_device(MirInputDeviceId id);
64  void remove_device(MirInputDeviceId id);
65 private:
66  std::mutex repeat_state_mutex;
67 
68  std::shared_ptr<InputDispatcher> const next_dispatcher;
69  std::shared_ptr<time::AlarmFactory> const alarm_factory;
70  std::shared_ptr<cookie::Authority> const cookie_authority;
71  bool const repeat_enabled;
72  std::chrono::milliseconds repeat_timeout;
73  std::chrono::milliseconds repeat_delay;
74  bool const disable_repeat_on_mtk_touchpad;
76 
77  struct KeyboardState
78  {
79  std::unordered_map<int, std::shared_ptr<mir::time::Alarm>> repeat_alarms_by_scancode;
80  };
81  std::unordered_map<MirInputDeviceId, KeyboardState> repeat_state_by_device;
82  KeyboardState& ensure_state_for_device_locked(std::lock_guard<std::mutex> const&, MirInputDeviceId id);
83 
84  bool handle_key_input(MirInputDeviceId id, MirKeyboardEvent const* ev);
85 };
86 
87 }
88 }
89 
90 #endif // MIR_INPUT_KEY_REPEAT_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
Definition: event_private.h:51
int64_t MirInputDeviceId
Definition: input_event.h:35
std::promise< bool > stop
Definition: in.cpp:28
Definition: event_private.h:181
Definition: key_repeat_dispatcher.h:45

Copyright © 2012-2015 Canonical Ltd.
Generated on Wed Mar 30 00:29:56 UTC 2016