OLD | NEW |
(Empty) | |
| 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. |
| 4 |
| 5 #ifndef CHROMEOS_IME_IME_KEYBOARD_X11_H_ |
| 6 #define CHROMEOS_IME_IME_KEYBOARD_X11_H_ |
| 7 |
| 8 #include "chromeos/ime/ime_keyboard.h" |
| 9 |
| 10 #include <cstdlib> |
| 11 #include <cstring> |
| 12 #include <queue> |
| 13 #include <set> |
| 14 #include <utility> |
| 15 |
| 16 #include "base/bind.h" |
| 17 #include "base/logging.h" |
| 18 #include "base/memory/scoped_ptr.h" |
| 19 #include "base/message_loop/message_loop.h" |
| 20 #include "base/process/kill.h" |
| 21 #include "base/process/launch.h" |
| 22 #include "base/process/process_handle.h" |
| 23 #include "base/strings/string_util.h" |
| 24 #include "base/strings/stringprintf.h" |
| 25 #include "base/sys_info.h" |
| 26 #include "base/threading/thread_checker.h" |
| 27 #include "ui/gfx/x/x11_types.h" |
| 28 |
| 29 // These includes conflict with base/tracked_objects.h so must come last. |
| 30 #include <X11/XKBlib.h> |
| 31 #include <X11/Xlib.h> |
| 32 |
| 33 |
| 34 namespace chromeos { |
| 35 namespace input_method { |
| 36 |
| 37 class CHROMEOS_EXPORT ImeKeyboardX11 : public ImeKeyboard { |
| 38 public: |
| 39 ImeKeyboardX11(); |
| 40 virtual ~ImeKeyboardX11(); |
| 41 |
| 42 // ImeKeyboard: |
| 43 virtual bool SetCurrentKeyboardLayoutByName( |
| 44 const std::string& layout_name) override; |
| 45 virtual bool ReapplyCurrentKeyboardLayout() override; |
| 46 virtual void ReapplyCurrentModifierLockStatus() override; |
| 47 virtual void DisableNumLock() override; |
| 48 virtual void SetCapsLockEnabled(bool enable_caps_lock) override; |
| 49 virtual bool CapsLockIsEnabled() override; |
| 50 virtual bool SetAutoRepeatEnabled(bool enabled) override; |
| 51 virtual bool SetAutoRepeatRate(const AutoRepeatRate& rate) override; |
| 52 |
| 53 private: |
| 54 // Returns a mask for Num Lock (e.g. 1U << 4). Returns 0 on error. |
| 55 unsigned int GetNumLockMask(); |
| 56 |
| 57 // Sets the caps-lock status. Note that calling this function always disables |
| 58 // the num-lock. |
| 59 void SetLockedModifiers(); |
| 60 |
| 61 // This function is used by SetLayout() and RemapModifierKeys(). Calls |
| 62 // setxkbmap command if needed, and updates the last_full_layout_name_ cache. |
| 63 bool SetLayoutInternal(const std::string& layout_name, bool force); |
| 64 |
| 65 // Executes 'setxkbmap -layout ...' command asynchronously using a layout name |
| 66 // in the |execute_queue_|. Do nothing if the queue is empty. |
| 67 // TODO(yusukes): Use libxkbfile.so instead of the command (crosbug.com/13105) |
| 68 void MaybeExecuteSetLayoutCommand(); |
| 69 |
| 70 // Polls to see setxkbmap process exits. |
| 71 void PollUntilChildFinish(const base::ProcessHandle handle); |
| 72 |
| 73 // Called when execve'd setxkbmap process exits. |
| 74 void OnSetLayoutFinish(); |
| 75 |
| 76 const bool is_running_on_chrome_os_; |
| 77 unsigned int num_lock_mask_; |
| 78 |
| 79 // A queue for executing setxkbmap one by one. |
| 80 std::queue<std::string> execute_queue_; |
| 81 |
| 82 base::ThreadChecker thread_checker_; |
| 83 |
| 84 base::WeakPtrFactory<ImeKeyboardX11> weak_factory_; |
| 85 |
| 86 DISALLOW_COPY_AND_ASSIGN(ImeKeyboardX11); |
| 87 }; |
| 88 |
| 89 |
| 90 } // namespace input_method |
| 91 } // namespace chromeos |
| 92 |
| 93 #endif // CHROMEOS_IME_IME_KEYBOARD_X11_H_ |
OLD | NEW |