Chromium Code Reviews| 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 #include "chrome/browser/chromeos/input_method/xkeyboard.h" | 5 #include "chrome/browser/chromeos/input_method/xkeyboard.h" |
| 6 | 6 |
| 7 #include <queue> | |
| 7 #include <utility> | 8 #include <utility> |
| 8 | 9 |
| 9 #include <X11/XKBlib.h> | 10 #include <X11/XKBlib.h> |
| 10 #include <X11/Xlib.h> | 11 #include <X11/Xlib.h> |
| 11 #include <glib.h> | 12 #include <glib.h> |
| 12 #include <stdlib.h> | 13 #include <stdlib.h> |
| 13 #include <string.h> | 14 #include <string.h> |
| 14 | 15 |
| 15 #include "base/memory/singleton.h" | 16 #include "base/memory/singleton.h" |
| 16 #include "base/logging.h" | 17 #include "base/logging.h" |
| (...skipping 229 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 246 // Turn off caps lock if there is no kCapsLockKey in the remapped keys. | 247 // Turn off caps lock if there is no kCapsLockKey in the remapped keys. |
| 247 if (!ContainsModifierKeyAsReplacement( | 248 if (!ContainsModifierKeyAsReplacement( |
| 248 modifier_map, kCapsLockKey)) { | 249 modifier_map, kCapsLockKey)) { |
| 249 SetCapsLockEnabled(false); | 250 SetCapsLockEnabled(false); |
| 250 } | 251 } |
| 251 | 252 |
| 252 // TODO(yusukes): Revert to VLOG(1) when crosbug.com/15851 is resolved. | 253 // TODO(yusukes): Revert to VLOG(1) when crosbug.com/15851 is resolved. |
| 253 LOG(WARNING) << (force ? "Reapply" : "Set") | 254 LOG(WARNING) << (force ? "Reapply" : "Set") |
| 254 << " layout: " << layouts_to_set; | 255 << " layout: " << layouts_to_set; |
| 255 | 256 |
| 256 ExecuteSetLayoutCommand(layouts_to_set); | 257 execute_queue_.push(layouts_to_set); |
|
Daniel Kurtz
2011/06/07 03:19:38
Is layouts_to_set a collection or a single layout?
Yusuke Sato
2011/06/07 04:54:58
Done.
| |
| 258 if (execute_queue_.size() == 1) { | |
|
satorux1
2011/06/07 03:19:27
Checking the size here looks a bit tricky. Maybe b
Yusuke Sato
2011/06/07 04:54:58
Modifed both this function and the callback. PTAL.
| |
| 259 ExecuteSetLayoutCommand(layouts_to_set); | |
| 260 } | |
| 257 return true; | 261 return true; |
| 258 } | 262 } |
| 259 | 263 |
| 260 // Executes 'setxkbmap -layout ...' command asynchronously. | 264 // Executes 'setxkbmap -layout ...' command asynchronously. |
| 261 // TODO(yusukes): Use libxkbfile.so instead of the command (crosbug.com/13105) | 265 // TODO(yusukes): Use libxkbfile.so instead of the command (crosbug.com/13105) |
| 262 void ExecuteSetLayoutCommand(const std::string& layouts_to_set) { | 266 void ExecuteSetLayoutCommand(const std::string& layouts_to_set) { |
| 263 std::vector<std::string> argv; | 267 std::vector<std::string> argv; |
| 264 base::file_handle_mapping_vector fds_to_remap; | 268 base::file_handle_mapping_vector fds_to_remap; |
| 265 base::ProcessHandle handle = base::kNullProcessHandle; | 269 base::ProcessHandle handle = base::kNullProcessHandle; |
| 266 | 270 |
| 267 argv.push_back(kSetxkbmapCommand); | 271 argv.push_back(kSetxkbmapCommand); |
| 268 argv.push_back("-layout"); | 272 argv.push_back("-layout"); |
| 269 argv.push_back(layouts_to_set); | 273 argv.push_back(layouts_to_set); |
| 274 argv.push_back("-synch"); | |
| 270 const bool result = base::LaunchApp(argv, | 275 const bool result = base::LaunchApp(argv, |
| 271 fds_to_remap, // No remapping. | 276 fds_to_remap, // No remapping. |
| 272 false, // Don't wait. | 277 false, // Don't wait. |
| 273 &handle); | 278 &handle); |
| 274 if (!result) { | 279 if (!result) { |
| 275 LOG(ERROR) << "Failed to execute setxkbmap: " << layouts_to_set; | 280 LOG(ERROR) << "Failed to execute setxkbmap: " << layouts_to_set; |
| 276 return; | 281 return; |
| 277 } | 282 } |
| 278 | 283 |
| 279 // g_child_watch_add is necessary to prevent the process from becoming a | 284 // g_child_watch_add is necessary to prevent the process from becoming a |
| 280 // zombie. | 285 // zombie. |
| 281 const base::ProcessId pid = base::GetProcId(handle); | 286 const base::ProcessId pid = base::GetProcId(handle); |
| 282 g_child_watch_add(pid, | 287 g_child_watch_add(pid, |
| 283 reinterpret_cast<GChildWatchFunc>(OnSetLayoutFinish), | 288 reinterpret_cast<GChildWatchFunc>(OnSetLayoutFinish), |
| 284 this); | 289 this); |
| 290 VLOG(1) << "ExecuteSetLayoutCommand: " << layouts_to_set << ": pid=" << pid; | |
| 285 } | 291 } |
| 286 | 292 |
| 287 static void OnSetLayoutFinish(GPid pid, gint status, XKeyboard* self) { | 293 static void OnSetLayoutFinish(GPid pid, gint status, XKeyboard* self) { |
| 288 DLOG(INFO) << "OnSetLayoutFinish: pid=" << pid; | 294 VLOG(1) << "OnSetLayoutFinish: pid=" << pid; |
| 295 DCHECK(!self->execute_queue_.empty()); | |
| 296 self->execute_queue_.pop(); | |
| 297 if (!self->execute_queue_.empty()) { | |
| 298 self->ExecuteSetLayoutCommand(self->execute_queue_.front()); | |
| 299 } | |
| 289 } | 300 } |
| 290 | 301 |
| 291 // The XKB layout name which we set last time like "us" and "us(dvorak)". | 302 // The XKB layout name which we set last time like "us" and "us(dvorak)". |
| 292 std::string current_layout_name_; | 303 std::string current_layout_name_; |
| 293 // The mapping of modifier keys we set last time. | 304 // The mapping of modifier keys we set last time. |
| 294 ModifierMap current_modifier_map_; | 305 ModifierMap current_modifier_map_; |
| 306 // A queue for executing setxkbmap one by one. | |
| 307 std::queue<std::string> execute_queue_; | |
| 295 | 308 |
| 296 DISALLOW_COPY_AND_ASSIGN(XKeyboard); | 309 DISALLOW_COPY_AND_ASSIGN(XKeyboard); |
| 297 }; | 310 }; |
| 298 | 311 |
| 299 } // namespace | 312 } // namespace |
| 300 | 313 |
| 301 std::string CreateFullXkbLayoutName(const std::string& layout_name, | 314 std::string CreateFullXkbLayoutName(const std::string& layout_name, |
| 302 const ModifierMap& modifier_map) { | 315 const ModifierMap& modifier_map) { |
| 303 static const char kValidLayoutNameCharacters[] = | 316 static const char kValidLayoutNameCharacters[] = |
| 304 "abcdefghijklmnopqrstuvwxyz0123456789()-_"; | 317 "abcdefghijklmnopqrstuvwxyz0123456789()-_"; |
| (...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 418 bool SetAutoRepeatEnabled(bool enabled) { | 431 bool SetAutoRepeatEnabled(bool enabled) { |
| 419 return XKeyboard::GetInstance()->SetAutoRepeatEnabled(enabled); | 432 return XKeyboard::GetInstance()->SetAutoRepeatEnabled(enabled); |
| 420 } | 433 } |
| 421 | 434 |
| 422 bool SetAutoRepeatRate(const AutoRepeatRate& rate) { | 435 bool SetAutoRepeatRate(const AutoRepeatRate& rate) { |
| 423 return XKeyboard::GetInstance()->SetAutoRepeatRate(rate); | 436 return XKeyboard::GetInstance()->SetAutoRepeatRate(rate); |
| 424 } | 437 } |
| 425 | 438 |
| 426 } // namespace input_method | 439 } // namespace input_method |
| 427 } // namespace chromeos | 440 } // namespace chromeos |
| OLD | NEW |