OLD | NEW |
| (Empty) |
1 // Copyright (c) 2011 The Chromium OS 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. | |
4 // | |
5 // DEPRECATED. TODO(satorux): Remove this file. | |
6 | |
7 #ifndef CHROMEOS_KEYBOARD_H_ | |
8 #define CHROMEOS_KEYBOARD_H_ | |
9 | |
10 #include <map> | |
11 #include <string> | |
12 #include <vector> | |
13 | |
14 namespace chromeos { | |
15 | |
16 struct AutoRepeatRate { | |
17 AutoRepeatRate() : initial_delay_in_ms(0), repeat_interval_in_ms(0) {} | |
18 unsigned int initial_delay_in_ms; | |
19 unsigned int repeat_interval_in_ms; | |
20 }; | |
21 | |
22 enum ModifierKey { | |
23 kSearchKey = 0, // Customizable. | |
24 kLeftControlKey, // Customizable. | |
25 kLeftAltKey, // Customizable. | |
26 kVoidKey, | |
27 kCapsLockKey, | |
28 // IMPORTANT: You should update kCustomizableKeys[] in .cc file, if you | |
29 // add a customizable key. | |
30 kNumModifierKeys, | |
31 }; | |
32 | |
33 struct ModifierKeyPair { | |
34 ModifierKeyPair(ModifierKey in_original, ModifierKey in_replacement) | |
35 : original(in_original), replacement(in_replacement) {} | |
36 bool operator==(const ModifierKeyPair& rhs) const { | |
37 // For CheckMap() in chromeos_keyboard_unittest.cc. | |
38 return (rhs.original == original) && (rhs.replacement == replacement); | |
39 } | |
40 ModifierKey original; // Replace the key with | |
41 ModifierKey replacement; // this key. | |
42 }; | |
43 typedef std::vector<ModifierKeyPair> ModifierMap; | |
44 | |
45 // Sets the current keyboard layout to |layout_name|. This function does not | |
46 // change the current mapping of the modifier keys. Returns true on success. | |
47 extern bool (*SetCurrentKeyboardLayoutByName)(const std::string& layout_name); | |
48 | |
49 // Remaps modifier keys. This function does not change the current keyboard | |
50 // layout. Returns true on success. | |
51 // Notice: For now, you can't remap Left Control and Left Alt keys to CapsLock. | |
52 extern bool (*RemapModifierKeys)(const ModifierMap& modifier_map); | |
53 | |
54 // Turns on and off the auto-repeat of the keyboard. Returns true on success. | |
55 extern bool (*SetAutoRepeatEnabled)(bool enabled); | |
56 | |
57 // Sets the auto-repeat rate of the keyboard, initial delay in ms, and repeat | |
58 // interval in ms. Returns true on success. | |
59 extern bool (*SetAutoRepeatRate)(const AutoRepeatRate& rate); | |
60 | |
61 // | |
62 // WARNING: DO NOT USE FUNCTIONS/CLASSES/TYPEDEFS BELOW. They are only for | |
63 // unittests. See the definitions in chromeos_keyboard.cc for details. | |
64 // | |
65 | |
66 // Converts |key| to a modifier key name which is used in | |
67 // /usr/share/X11/xkb/symbols/chromeos. | |
68 inline std::string ModifierKeyToString(ModifierKey key) { | |
69 switch (key) { | |
70 case kSearchKey: | |
71 return "search"; | |
72 case kLeftControlKey: | |
73 return "leftcontrol"; | |
74 case kLeftAltKey: | |
75 return "leftalt"; | |
76 case kVoidKey: | |
77 return "disabled"; | |
78 case kCapsLockKey: | |
79 return "capslock"; | |
80 case kNumModifierKeys: | |
81 break; | |
82 } | |
83 return ""; | |
84 } | |
85 | |
86 // Creates a full XKB layout name like | |
87 // "gb(extd)+chromeos(leftcontrol_disabled_leftalt),us" | |
88 // from modifier key mapping and |layout_name|, such as "us", "us(dvorak)", and | |
89 // "gb(extd)". Returns an empty string on error. | |
90 std::string CreateFullXkbLayoutName(const std::string& layout_name, | |
91 const ModifierMap& modifire_map); | |
92 | |
93 // Returns true if caps lock is enabled. | |
94 // ONLY FOR UNIT TEST. DO NOT USE THIS FUNCTION. | |
95 bool CapsLockIsEnabled(); | |
96 | |
97 // Sets the caps lock status to |enable_caps_lock|. | |
98 void SetCapsLockEnabled(bool enabled); | |
99 | |
100 // Returns true if |key| is in |modifier_map| as replacement. | |
101 bool ContainsModifierKeyAsReplacement( | |
102 const ModifierMap& modifier_map, ModifierKey key); | |
103 | |
104 } // namespace chromeos | |
105 | |
106 #endif // CHROMEOS_KEYBOARD_H_ | |
OLD | NEW |