Mir
key_repeat_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_KEY_REPEAT_DISPATCHER_H_
20 #define MIR_INPUT_KEY_REPEAT_DISPATCHER_H_
21 
23 
24 #include <memory>
25 #include <chrono>
26 #include <mutex>
27 #include <unordered_map>
28 
29 namespace mir
30 {
31 namespace time
32 {
33 class AlarmFactory;
34 class Alarm;
35 }
36 namespace input
37 {
38 
40 {
41 public:
42  KeyRepeatDispatcher(std::shared_ptr<InputDispatcher> const& next_dispatcher,
43  std::shared_ptr<time::AlarmFactory> const& factory,
44  bool repeat_enabled,
45  std::chrono::milliseconds repeat_timeout, /* timeout before sending first repeat */
46  std::chrono::milliseconds repeat_delay /* delay between repeated keys */);
47 
48  // InputDispatcher
49  bool dispatch(MirEvent const& event) override;
50  void start() override;
51  void stop() override;
52 
53 private:
54  std::mutex repeat_state_mutex;
55 
56  std::shared_ptr<InputDispatcher> const next_dispatcher;
57  std::shared_ptr<time::AlarmFactory> const alarm_factory;
58  bool const repeat_enabled;
59  std::chrono::milliseconds repeat_timeout;
60  std::chrono::milliseconds repeat_delay;
61 
62  struct KeyboardState
63  {
64  std::unordered_map<int, std::shared_ptr<mir::time::Alarm>> repeat_alarms_by_scancode;
65  };
66  std::unordered_map<MirInputDeviceId, KeyboardState> repeat_state_by_device;
67  KeyboardState& ensure_state_for_device_locked(std::lock_guard<std::mutex> const&, MirInputDeviceId id);
68 
69  bool handle_key_input(MirInputDeviceId id, MirKeyboardEvent const* ev);
70 };
71 
72 }
73 }
74 
75 #endif // MIR_INPUT_KEY_REPEAT_DISPATCHER_H_
All things Mir.
Definition: atomic_callback.h:25
void stop() override
Definition: key_repeat_dispatcher.cpp:140
The InputDispatchers role is to decide what should happen with user input events. ...
Definition: input_dispatcher.h:38
void start() override
Definition: key_repeat_dispatcher.cpp:135
KeyRepeatDispatcher(std::shared_ptr< InputDispatcher > const &next_dispatcher, std::shared_ptr< time::AlarmFactory > const &factory, bool repeat_enabled, std::chrono::milliseconds repeat_timeout, std::chrono::milliseconds repeat_delay)
Definition: key_repeat_dispatcher.cpp:32
int64_t MirInputDeviceId
Definition: input_event.h:34
bool dispatch(MirEvent const &event) override
Definition: key_repeat_dispatcher.cpp:52
struct MirKeyboardEvent MirKeyboardEvent
An event type describing a change in keyboard state.
Definition: keyboard_event.h:44
Definition: event_private.h:178
Definition: key_repeat_dispatcher.h:39

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