| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef CHROME_BROWSER_CHROMEOS_INPUT_METHOD_XKEYBOARD_H_ | 5 #ifndef CHROME_BROWSER_CHROMEOS_INPUT_METHOD_XKEYBOARD_H_ |
| 6 #define CHROME_BROWSER_CHROMEOS_INPUT_METHOD_XKEYBOARD_H_ | 6 #define CHROME_BROWSER_CHROMEOS_INPUT_METHOD_XKEYBOARD_H_ |
| 7 #pragma once | 7 #pragma once |
| 8 | 8 |
| 9 #include <queue> | 9 #include <queue> |
| 10 #include <set> | 10 #include <set> |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 61 // Remaps modifier keys. This function does not change the current keyboard | 61 // Remaps modifier keys. This function does not change the current keyboard |
| 62 // layout. Returns true on success. For now, you can't remap Left Control and | 62 // layout. Returns true on success. For now, you can't remap Left Control and |
| 63 // Left Alt keys to caps lock. | 63 // Left Alt keys to caps lock. |
| 64 bool RemapModifierKeys(const ModifierMap& modifier_map); | 64 bool RemapModifierKeys(const ModifierMap& modifier_map); |
| 65 | 65 |
| 66 // Sets the current keyboard layout again. We have to call the function every | 66 // Sets the current keyboard layout again. We have to call the function every |
| 67 // time when "XI_HierarchyChanged" XInput2 event is sent to Chrome. See | 67 // time when "XI_HierarchyChanged" XInput2 event is sent to Chrome. See |
| 68 // xinput_hierarchy_changed_event_listener.h for details. | 68 // xinput_hierarchy_changed_event_listener.h for details. |
| 69 bool ReapplyCurrentKeyboardLayout(); | 69 bool ReapplyCurrentKeyboardLayout(); |
| 70 | 70 |
| 71 // Updates keyboard LEDs on all keyboards. |
| 72 // XKB asymmetrically propagates keyboard modifier indicator state changes to |
| 73 // slave keyboards. If the state change is initiated from a client to the |
| 74 // "core/master keyboard", XKB changes global state and pushes an indication |
| 75 // change down to all keyboards. If the state change is initiated by one slave |
| 76 // (physical) keyboard, it changes global state but only pushes an indicator |
| 77 // state change down to that one keyboard. |
| 78 // This function changes LEDs on all keyboards by explicitly updating |
| 79 // "core/master keyboard". |
| 80 void ReapplyCurrentModifierLockStatus(); |
| 81 |
| 82 // Returns true if num lock is enabled. Do not call the function from non-UI |
| 83 // threads. |
| 84 static bool NumLockIsEnabled(unsigned int num_lock_mask); |
| 85 |
| 86 // Sets the num lock status to |enable_num_lock|. Do not call the function |
| 87 // from non-UI threads. |
| 88 void SetNumLockEnabled(bool enable_num_lock); |
| 89 |
| 90 // Returns true if caps lock is enabled. Do not call the function from non-UI |
| 91 // threads. |
| 92 static bool CapsLockIsEnabled(); |
| 93 |
| 94 // Sets the caps lock status to |enable_caps_lock|. Do not call the function |
| 95 // from non-UI threads. |
| 96 void SetCapsLockEnabled(bool enable_caps_lock); |
| 97 |
| 71 // Turns on and off the auto-repeat of the keyboard. Returns true on success. | 98 // Turns on and off the auto-repeat of the keyboard. Returns true on success. |
| 72 // Do not call the function from non-UI threads. | 99 // Do not call the function from non-UI threads. |
| 73 static bool SetAutoRepeatEnabled(bool enabled); | 100 static bool SetAutoRepeatEnabled(bool enabled); |
| 74 | 101 |
| 75 // Sets the auto-repeat rate of the keyboard, initial delay in ms, and repeat | 102 // Sets the auto-repeat rate of the keyboard, initial delay in ms, and repeat |
| 76 // interval in ms. Returns true on success. Do not call the function from | 103 // interval in ms. Returns true on success. Do not call the function from |
| 77 // non-UI threads. | 104 // non-UI threads. |
| 78 static bool SetAutoRepeatRate(const AutoRepeatRate& rate); | 105 static bool SetAutoRepeatRate(const AutoRepeatRate& rate); |
| 79 | 106 |
| 80 // Returns true if caps lock is enabled. Do not call the function from non-UI | 107 // Returns a mask (e.g. 1U<<4) for Num Lock. On error, returns 0. |
| 81 // threads. | 108 static unsigned int GetNumLockMask(); |
| 82 static bool CapsLockIsEnabled(); | |
| 83 | |
| 84 // Sets the caps lock status to |enable_caps_lock|. Do not call the function | |
| 85 // from non-UI threads. | |
| 86 static void SetCapsLockEnabled(bool enabled); | |
| 87 | 109 |
| 88 protected: | 110 protected: |
| 89 // Creates a full XKB layout name like | 111 // Creates a full XKB layout name like |
| 90 // "gb(extd)+chromeos(leftcontrol_disabled_leftalt),us" | 112 // "gb(extd)+chromeos(leftcontrol_disabled_leftalt),us" |
| 91 // from modifier key mapping and |layout_name|, such as "us", "us(dvorak)", | 113 // from modifier key mapping and |layout_name|, such as "us", "us(dvorak)", |
| 92 // and "gb(extd)". Returns an empty string on error. This function is | 114 // and "gb(extd)". Returns an empty string on error. This function is |
| 93 // protected: for testability. | 115 // protected: for testability. |
| 94 std::string CreateFullXkbLayoutName(const std::string& layout_name, | 116 std::string CreateFullXkbLayoutName(const std::string& layout_name, |
| 95 const ModifierMap& modifire_map); | 117 const ModifierMap& modifire_map); |
| 96 | 118 |
| (...skipping 23 matching lines...) Expand all Loading... |
| 120 // KeepCapsLock("us(colemak)") would return true. | 142 // KeepCapsLock("us(colemak)") would return true. |
| 121 bool KeepCapsLock(const std::string& xkb_layout_name) const; | 143 bool KeepCapsLock(const std::string& xkb_layout_name) const; |
| 122 | 144 |
| 123 // Converts |key| to a modifier key name which is used in | 145 // Converts |key| to a modifier key name which is used in |
| 124 // /usr/share/X11/xkb/symbols/chromeos. | 146 // /usr/share/X11/xkb/symbols/chromeos. |
| 125 static std::string ModifierKeyToString(ModifierKey key); | 147 static std::string ModifierKeyToString(ModifierKey key); |
| 126 | 148 |
| 127 // Called when execve'd setxkbmap process exits. | 149 // Called when execve'd setxkbmap process exits. |
| 128 static void OnSetLayoutFinish(pid_t pid, int status, XKeyboard* self); | 150 static void OnSetLayoutFinish(pid_t pid, int status, XKeyboard* self); |
| 129 | 151 |
| 152 const bool is_running_on_chrome_os_; |
| 153 unsigned int num_lock_mask_; |
| 154 |
| 155 // The current Num Lock and Caps Lock status. If true, enabled. |
| 156 bool current_num_lock_status_; |
| 157 bool current_caps_lock_status_; |
| 130 // The XKB layout name which we set last time like "us" and "us(dvorak)". | 158 // The XKB layout name which we set last time like "us" and "us(dvorak)". |
| 131 std::string current_layout_name_; | 159 std::string current_layout_name_; |
| 132 // The mapping of modifier keys we set last time. | 160 // The mapping of modifier keys we set last time. |
| 133 ModifierMap current_modifier_map_; | 161 ModifierMap current_modifier_map_; |
| 162 |
| 134 // A queue for executing setxkbmap one by one. | 163 // A queue for executing setxkbmap one by one. |
| 135 std::queue<std::string> execute_queue_; | 164 std::queue<std::string> execute_queue_; |
| 136 | 165 |
| 137 std::set<std::string> keep_right_alt_xkb_layout_names_; | 166 std::set<std::string> keep_right_alt_xkb_layout_names_; |
| 138 std::set<std::string> caps_lock_remapped_xkb_layout_names_; | 167 std::set<std::string> caps_lock_remapped_xkb_layout_names_; |
| 139 | 168 |
| 140 const bool is_running_on_chrome_os_; | |
| 141 | |
| 142 DISALLOW_COPY_AND_ASSIGN(XKeyboard); | 169 DISALLOW_COPY_AND_ASSIGN(XKeyboard); |
| 143 }; | 170 }; |
| 144 | 171 |
| 145 } // namespace input_method | 172 } // namespace input_method |
| 146 } // namespace chromeos | 173 } // namespace chromeos |
| 147 | 174 |
| 148 #endif // CHROME_BROWSER_CHROMEOS_INPUT_METHOD_XKEYBOARD_H_ | 175 #endif // CHROME_BROWSER_CHROMEOS_INPUT_METHOD_XKEYBOARD_H_ |
| OLD | NEW |