| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "chromeos/ime/xkeyboard.h" | 5 #include "chromeos/ime/xkeyboard.h" |
| 6 | 6 |
| 7 #include <cstdlib> | 7 #include <cstdlib> |
| 8 #include <cstring> | 8 #include <cstring> |
| 9 #include <queue> | 9 #include <queue> |
| 10 #include <set> | 10 #include <set> |
| (...skipping 27 matching lines...) Expand all Loading... |
| 38 // setxkbmap command finished. | 38 // setxkbmap command finished. |
| 39 const int kSetLayoutCommandCheckDelayMs = 100; | 39 const int kSetLayoutCommandCheckDelayMs = 100; |
| 40 | 40 |
| 41 // The command we use to set the current XKB layout and modifier key mapping. | 41 // The command we use to set the current XKB layout and modifier key mapping. |
| 42 // TODO(yusukes): Use libxkbfile.so instead of the command (crosbug.com/13105) | 42 // TODO(yusukes): Use libxkbfile.so instead of the command (crosbug.com/13105) |
| 43 const char kSetxkbmapCommand[] = "/usr/bin/setxkbmap"; | 43 const char kSetxkbmapCommand[] = "/usr/bin/setxkbmap"; |
| 44 | 44 |
| 45 // A string for obtaining a mask value for Num Lock. | 45 // A string for obtaining a mask value for Num Lock. |
| 46 const char kNumLockVirtualModifierString[] = "NumLock"; | 46 const char kNumLockVirtualModifierString[] = "NumLock"; |
| 47 | 47 |
| 48 const char *kISOLevel5ShiftLayoutIds[] = { |
| 49 "ca(multix)", |
| 50 "de(neo)", |
| 51 }; |
| 52 |
| 53 const char *kAltGrLayoutIds[] = { |
| 54 "be", |
| 55 "be", |
| 56 "be", |
| 57 "bg", |
| 58 "bg(phonetic)", |
| 59 "br", |
| 60 "ca", |
| 61 "ca(eng)", |
| 62 "ca(multix)", |
| 63 "ch", |
| 64 "ch(fr)", |
| 65 "cz", |
| 66 "de", |
| 67 "de(neo)", |
| 68 "dk", |
| 69 "ee", |
| 70 "es", |
| 71 "es(cat)", |
| 72 "fi", |
| 73 "fr", |
| 74 "gb(dvorak)", |
| 75 "gb(extd)", |
| 76 "gr", |
| 77 "hr", |
| 78 "il", |
| 79 "it", |
| 80 "latam", |
| 81 "lt", |
| 82 "no", |
| 83 "pl", |
| 84 "pt", |
| 85 "ro", |
| 86 "se", |
| 87 "si", |
| 88 "sk", |
| 89 "tr", |
| 90 "ua", |
| 91 "us(altgr-intl)", |
| 92 "us(intl)", |
| 93 }; |
| 94 |
| 95 |
| 48 // Returns false if |layout_name| contains a bad character. | 96 // Returns false if |layout_name| contains a bad character. |
| 49 bool CheckLayoutName(const std::string& layout_name) { | 97 bool CheckLayoutName(const std::string& layout_name) { |
| 50 static const char kValidLayoutNameCharacters[] = | 98 static const char kValidLayoutNameCharacters[] = |
| 51 "abcdefghijklmnopqrstuvwxyz0123456789()-_"; | 99 "abcdefghijklmnopqrstuvwxyz0123456789()-_"; |
| 52 | 100 |
| 53 if (layout_name.empty()) { | 101 if (layout_name.empty()) { |
| 54 DVLOG(1) << "Invalid layout_name: " << layout_name; | 102 DVLOG(1) << "Invalid layout_name: " << layout_name; |
| 55 return false; | 103 return false; |
| 56 } | 104 } |
| 57 | 105 |
| (...skipping 12 matching lines...) Expand all Loading... |
| 70 virtual ~XKeyboardImpl() {} | 118 virtual ~XKeyboardImpl() {} |
| 71 | 119 |
| 72 // Overridden from XKeyboard: | 120 // Overridden from XKeyboard: |
| 73 virtual bool SetCurrentKeyboardLayoutByName( | 121 virtual bool SetCurrentKeyboardLayoutByName( |
| 74 const std::string& layout_name) OVERRIDE; | 122 const std::string& layout_name) OVERRIDE; |
| 75 virtual bool ReapplyCurrentKeyboardLayout() OVERRIDE; | 123 virtual bool ReapplyCurrentKeyboardLayout() OVERRIDE; |
| 76 virtual void ReapplyCurrentModifierLockStatus() OVERRIDE; | 124 virtual void ReapplyCurrentModifierLockStatus() OVERRIDE; |
| 77 virtual void DisableNumLock() OVERRIDE; | 125 virtual void DisableNumLock() OVERRIDE; |
| 78 virtual void SetCapsLockEnabled(bool enable_caps_lock) OVERRIDE; | 126 virtual void SetCapsLockEnabled(bool enable_caps_lock) OVERRIDE; |
| 79 virtual bool CapsLockIsEnabled() OVERRIDE; | 127 virtual bool CapsLockIsEnabled() OVERRIDE; |
| 128 virtual bool IsISOLevel5ShiftAvailable() const OVERRIDE; |
| 129 virtual bool IsAltGrAvailable() const OVERRIDE; |
| 80 virtual bool SetAutoRepeatEnabled(bool enabled) OVERRIDE; | 130 virtual bool SetAutoRepeatEnabled(bool enabled) OVERRIDE; |
| 81 virtual bool SetAutoRepeatRate(const AutoRepeatRate& rate) OVERRIDE; | 131 virtual bool SetAutoRepeatRate(const AutoRepeatRate& rate) OVERRIDE; |
| 82 | 132 |
| 83 private: | 133 private: |
| 84 // Returns a mask for Num Lock (e.g. 1U << 4). Returns 0 on error. | 134 // Returns a mask for Num Lock (e.g. 1U << 4). Returns 0 on error. |
| 85 unsigned int GetNumLockMask(); | 135 unsigned int GetNumLockMask(); |
| 86 | 136 |
| 87 // Sets the caps-lock status. Note that calling this function always disables | 137 // Sets the caps-lock status. Note that calling this function always disables |
| 88 // the num-lock. | 138 // the num-lock. |
| 89 void SetLockedModifiers(bool caps_lock_enabled); | 139 void SetLockedModifiers(bool caps_lock_enabled); |
| (...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 281 } | 331 } |
| 282 } | 332 } |
| 283 | 333 |
| 284 bool XKeyboardImpl::CapsLockIsEnabled() { | 334 bool XKeyboardImpl::CapsLockIsEnabled() { |
| 285 DCHECK(thread_checker_.CalledOnValidThread()); | 335 DCHECK(thread_checker_.CalledOnValidThread()); |
| 286 XkbStateRec status; | 336 XkbStateRec status; |
| 287 XkbGetState(GetXDisplay(), XkbUseCoreKbd, &status); | 337 XkbGetState(GetXDisplay(), XkbUseCoreKbd, &status); |
| 288 return (status.locked_mods & LockMask); | 338 return (status.locked_mods & LockMask); |
| 289 } | 339 } |
| 290 | 340 |
| 341 bool XKeyboardImpl::IsISOLevel5ShiftAvailable() const { |
| 342 for (size_t i = 0; i < arraysize(kISOLevel5ShiftLayoutIds); ++i) { |
| 343 if (current_layout_name_ == kISOLevel5ShiftLayoutIds[i]) |
| 344 return true; |
| 345 } |
| 346 return false; |
| 347 } |
| 348 |
| 349 bool XKeyboardImpl::IsAltGrAvailable() const { |
| 350 for (size_t i = 0; i < arraysize(kAltGrLayoutIds); ++i) { |
| 351 if (current_layout_name_ == kAltGrLayoutIds[i]) |
| 352 return true; |
| 353 } |
| 354 return false; |
| 355 } |
| 356 |
| 357 |
| 291 bool XKeyboardImpl::SetAutoRepeatEnabled(bool enabled) { | 358 bool XKeyboardImpl::SetAutoRepeatEnabled(bool enabled) { |
| 292 if (enabled) | 359 if (enabled) |
| 293 XAutoRepeatOn(GetXDisplay()); | 360 XAutoRepeatOn(GetXDisplay()); |
| 294 else | 361 else |
| 295 XAutoRepeatOff(GetXDisplay()); | 362 XAutoRepeatOff(GetXDisplay()); |
| 296 DVLOG(1) << "Set auto-repeat mode to: " << (enabled ? "on" : "off"); | 363 DVLOG(1) << "Set auto-repeat mode to: " << (enabled ? "on" : "off"); |
| 297 return true; | 364 return true; |
| 298 } | 365 } |
| 299 | 366 |
| 300 bool XKeyboardImpl::SetAutoRepeatRate(const AutoRepeatRate& rate) { | 367 bool XKeyboardImpl::SetAutoRepeatRate(const AutoRepeatRate& rate) { |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 370 return CheckLayoutName(layout_name); | 437 return CheckLayoutName(layout_name); |
| 371 } | 438 } |
| 372 | 439 |
| 373 // static | 440 // static |
| 374 XKeyboard* XKeyboard::Create() { | 441 XKeyboard* XKeyboard::Create() { |
| 375 return new XKeyboardImpl(); | 442 return new XKeyboardImpl(); |
| 376 } | 443 } |
| 377 | 444 |
| 378 } // namespace input_method | 445 } // namespace input_method |
| 379 } // namespace chromeos | 446 } // namespace chromeos |
| OLD | NEW |