1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #ifndef UI_EVENTS_OZONE_EVDEV_KEYBOARD_EVDEV_H_
6 #define UI_EVENTS_OZONE_EVDEV_KEYBOARD_EVDEV_H_
9 #include <linux/input.h>
11 #include "base/time/time.h"
12 #include "base/timer/timer.h"
13 #include "ui/events/ozone/evdev/event_device_util.h"
14 #include "ui/events/ozone/evdev/event_dispatch_callback.h"
15 #include "ui/events/ozone/evdev/events_ozone_evdev_export.h"
16 #include "ui/events/ozone/layout/keyboard_layout_engine.h"
20 class EventModifiersEvdev
;
23 // Keyboard for evdev.
25 // This object is responsible for combining all attached keyboards into
26 // one logical keyboard, applying modifiers & implementing key repeat.
28 // It also currently also applies the layout.
29 class EVENTS_OZONE_EVDEV_EXPORT KeyboardEvdev
{
31 KeyboardEvdev(EventModifiersEvdev
* modifiers
,
32 KeyboardLayoutEngine
* keyboard_layout_engine
,
33 const EventDispatchCallback
& callback
);
36 // Handlers for raw key presses & releases.
38 // |code| is a Linux key code (from <linux/input.h>). |down| represents the
39 // key state. |suppress_auto_repeat| prevents the event from triggering
40 // auto-repeat, if enabled. |device_id| uniquely identifies the source
42 void OnKeyChange(unsigned int code
,
44 bool suppress_auto_repeat
,
45 base::TimeDelta timestamp
,
48 // Handle Caps Lock modifier.
49 void SetCapsLockEnabled(bool enabled
);
50 bool IsCapsLockEnabled();
52 // Configuration for key repeat.
53 bool IsAutoRepeatEnabled();
54 void SetAutoRepeatEnabled(bool enabled
);
55 void SetAutoRepeatRate(const base::TimeDelta
& delay
,
56 const base::TimeDelta
& interval
);
57 void GetAutoRepeatRate(base::TimeDelta
* delay
, base::TimeDelta
* interval
);
60 void UpdateModifier(int modifier_flag
, bool down
);
61 void UpdateCapsLockLed();
62 void UpdateKeyRepeat(unsigned int key
,
64 bool suppress_auto_repeat
,
66 void StartKeyRepeat(unsigned int key
, int device_id
);
68 void ScheduleKeyRepeat(const base::TimeDelta
& delay
);
69 void OnRepeatTimeout(unsigned int sequence
);
70 void OnRepeatCommit(unsigned int sequence
);
71 void DispatchKey(unsigned int key
,
74 base::TimeDelta timestamp
,
77 // Aggregated key state. There is only one bit of state per key; we do not
78 // attempt to count presses of the same key on multiple keyboards.
80 // A key is down iff the most recent event pertaining to that key was a key
81 // down event rather than a key up event. Therefore, a particular key position
82 // can be considered released even if it is being depresssed on one or more
84 std::bitset
<KEY_CNT
> key_state_
;
86 // Callback for dispatching events.
87 EventDispatchCallback callback_
;
89 // Shared modifier state.
90 EventModifiersEvdev
* modifiers_
;
92 // Shared layout engine.
93 KeyboardLayoutEngine
* keyboard_layout_engine_
;
96 bool auto_repeat_enabled_
= true;
97 unsigned int repeat_key_
= KEY_RESERVED
;
98 unsigned int repeat_sequence_
= 0;
99 int repeat_device_id_
= 0;
100 base::TimeDelta repeat_delay_
;
101 base::TimeDelta repeat_interval_
;
103 base::WeakPtrFactory
<KeyboardEvdev
> weak_ptr_factory_
;
105 DISALLOW_COPY_AND_ASSIGN(KeyboardEvdev
);
110 #endif // UI_EVENTS_OZONE_EVDEV_KEYBOARD_EVDEV_H_