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 UI_BASE_IME_CHROMEOS_IME_KEYBOARD_X11_H_ | |
6 #define UI_BASE_IME_CHROMEOS_IME_KEYBOARD_X11_H_ | |
7 | |
8 #include "ui/base/ime/chromeos/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/base/ui_base_export.h" | |
28 | |
29 namespace chromeos { | |
30 namespace input_method { | |
31 | |
32 class UI_BASE_EXPORT ImeKeyboardX11 : public ImeKeyboard { | |
33 public: | |
34 ImeKeyboardX11(); | |
35 virtual ~ImeKeyboardX11(); | |
36 | |
37 // ImeKeyboard: | |
38 virtual bool SetCurrentKeyboardLayoutByName( | |
39 const std::string& layout_name) override; | |
40 virtual bool ReapplyCurrentKeyboardLayout() override; | |
41 virtual void ReapplyCurrentModifierLockStatus() override; | |
42 virtual void DisableNumLock() override; | |
43 virtual void SetCapsLockEnabled(bool enable_caps_lock) override; | |
44 virtual bool CapsLockIsEnabled() override; | |
45 virtual bool SetAutoRepeatEnabled(bool enabled) override; | |
46 virtual bool SetAutoRepeatRate(const AutoRepeatRate& rate) override; | |
47 | |
48 private: | |
49 // Returns a mask for Num Lock (e.g. 1U << 4). Returns 0 on error. | |
50 unsigned int GetNumLockMask(); | |
51 | |
52 // Sets the caps-lock status. Note that calling this function always disables | |
53 // the num-lock. | |
54 void SetLockedModifiers(); | |
55 | |
56 // This function is used by SetLayout() and RemapModifierKeys(). Calls | |
57 // setxkbmap command if needed, and updates the last_full_layout_name_ cache. | |
58 bool SetLayoutInternal(const std::string& layout_name, bool force); | |
59 | |
60 // Executes 'setxkbmap -layout ...' command asynchronously using a layout name | |
61 // in the |execute_queue_|. Do nothing if the queue is empty. | |
62 // TODO(yusukes): Use libxkbfile.so instead of the command (crosbug.com/13105) | |
63 void MaybeExecuteSetLayoutCommand(); | |
64 | |
65 // Polls to see setxkbmap process exits. | |
66 void PollUntilChildFinish(const base::ProcessHandle handle); | |
67 | |
68 // Called when execve'd setxkbmap process exits. | |
69 void OnSetLayoutFinish(); | |
70 | |
71 const bool is_running_on_chrome_os_; | |
72 unsigned int num_lock_mask_; | |
73 | |
74 // A queue for executing setxkbmap one by one. | |
75 std::queue<std::string> execute_queue_; | |
76 | |
77 base::ThreadChecker thread_checker_; | |
78 | |
79 base::WeakPtrFactory<ImeKeyboardX11> weak_factory_; | |
80 | |
81 DISALLOW_COPY_AND_ASSIGN(ImeKeyboardX11); | |
82 }; | |
83 | |
84 | |
85 } // namespace input_method | |
86 } // namespace chromeos | |
87 | |
88 #endif // UI_BASE_IME_CHROMEOS_IME_KEYBOARD_X11_H_ | |
OLD | NEW |