| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium OS Authors. All rights reserved. | 1 // Copyright (c) 2010 The Chromium OS 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 "chromeos_keyboard.h" | 5 #include "chromeos_keyboard.h" |
| 6 | 6 |
| 7 #include <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include <X11/XKBlib.h> | 9 #include <X11/XKBlib.h> |
| 10 #include <X11/Xlib.h> | 10 #include <X11/Xlib.h> |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 73 // layout. Returns true on success. | 73 // layout. Returns true on success. |
| 74 bool RemapModifierKeys(const chromeos::ModifierMap& modifier_map) { | 74 bool RemapModifierKeys(const chromeos::ModifierMap& modifier_map) { |
| 75 // TODO(yusukes): write auto tests for the function. | 75 // TODO(yusukes): write auto tests for the function. |
| 76 const std::string layout_name = GetLayout(); | 76 const std::string layout_name = GetLayout(); |
| 77 if (layout_name.empty()) { | 77 if (layout_name.empty()) { |
| 78 return false; | 78 return false; |
| 79 } | 79 } |
| 80 return SetLayoutInternal(layout_name, modifier_map); | 80 return SetLayoutInternal(layout_name, modifier_map); |
| 81 } | 81 } |
| 82 | 82 |
| 83 // Returns the hardware layout name. |
| 84 std::string GetHardwareLayout() { |
| 85 // TODO(peria): write practical code. |
| 86 return "xkb:us::eng"; |
| 87 } |
| 88 |
| 83 // Returns the current layout name like "us". On error, returns "". | 89 // Returns the current layout name like "us". On error, returns "". |
| 84 std::string GetLayout() { | 90 std::string GetLayout() { |
| 85 // TODO(yusukes): write auto tests for the function. | 91 // TODO(yusukes): write auto tests for the function. |
| 86 std::string command_output = last_full_layout_name_; | 92 std::string command_output = last_full_layout_name_; |
| 87 | 93 |
| 88 if (command_output.empty()) { | 94 if (command_output.empty()) { |
| 89 // Cache is not available. Execute setxkbmap to get the current layout. | 95 // Cache is not available. Execute setxkbmap to get the current layout. |
| 90 if (!ExecuteGetLayoutCommand(&command_output)) { | 96 if (!ExecuteGetLayoutCommand(&command_output)) { |
| 91 return ""; | 97 return ""; |
| 92 } | 98 } |
| (...skipping 426 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 519 bool ChromeOSSetCurrentKeyboardLayoutByName(const std::string& layout_name) { | 525 bool ChromeOSSetCurrentKeyboardLayoutByName(const std::string& layout_name) { |
| 520 return XKeyboard::Get()->SetLayout(layout_name); | 526 return XKeyboard::Get()->SetLayout(layout_name); |
| 521 } | 527 } |
| 522 | 528 |
| 523 extern "C" | 529 extern "C" |
| 524 bool ChromeOSRemapModifierKeys(const chromeos::ModifierMap& modifier_map) { | 530 bool ChromeOSRemapModifierKeys(const chromeos::ModifierMap& modifier_map) { |
| 525 return XKeyboard::Get()->RemapModifierKeys(modifier_map); | 531 return XKeyboard::Get()->RemapModifierKeys(modifier_map); |
| 526 } | 532 } |
| 527 | 533 |
| 528 extern "C" | 534 extern "C" |
| 535 const std::string ChromeOSGetHardwareKeyboardLayoutName() { |
| 536 return XKeyboard::Get()->GetHardwareLayout(); |
| 537 } |
| 538 |
| 539 extern "C" |
| 529 const std::string ChromeOSGetCurrentKeyboardLayoutName() { | 540 const std::string ChromeOSGetCurrentKeyboardLayoutName() { |
| 530 return XKeyboard::Get()->GetLayout(); | 541 return XKeyboard::Get()->GetLayout(); |
| 531 } | 542 } |
| 532 | 543 |
| 533 extern "C" | 544 extern "C" |
| 534 bool ChromeOSGetAutoRepeatEnabled(bool* enabled) { | 545 bool ChromeOSGetAutoRepeatEnabled(bool* enabled) { |
| 535 return XKeyboard::Get()->GetAutoRepeatEnabled(enabled); | 546 return XKeyboard::Get()->GetAutoRepeatEnabled(enabled); |
| 536 } | 547 } |
| 537 | 548 |
| 538 extern "C" | 549 extern "C" |
| 539 bool ChromeOSSetAutoRepeatEnabled(bool enabled) { | 550 bool ChromeOSSetAutoRepeatEnabled(bool enabled) { |
| 540 return XKeyboard::Get()->SetAutoRepeatEnabled(enabled); | 551 return XKeyboard::Get()->SetAutoRepeatEnabled(enabled); |
| 541 } | 552 } |
| 542 | 553 |
| 543 extern "C" | 554 extern "C" |
| 544 bool ChromeOSGetAutoRepeatRate(chromeos::AutoRepeatRate* out_rate) { | 555 bool ChromeOSGetAutoRepeatRate(chromeos::AutoRepeatRate* out_rate) { |
| 545 return XKeyboard::Get()->GetAutoRepeatRate(out_rate); | 556 return XKeyboard::Get()->GetAutoRepeatRate(out_rate); |
| 546 } | 557 } |
| 547 | 558 |
| 548 extern "C" | 559 extern "C" |
| 549 bool ChromeOSSetAutoRepeatRate(const chromeos::AutoRepeatRate& rate) { | 560 bool ChromeOSSetAutoRepeatRate(const chromeos::AutoRepeatRate& rate) { |
| 550 return XKeyboard::Get()->SetAutoRepeatRate(rate); | 561 return XKeyboard::Get()->SetAutoRepeatRate(rate); |
| 551 } | 562 } |
| OLD | NEW |