| 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 "ui/base/keycodes/keyboard_code_conversion_x.h" | 5 #include "ui/base/keycodes/keyboard_code_conversion_x.h" |
| 6 | 6 |
| 7 #include <X11/keysym.h> | 7 #include <X11/keysym.h> |
| 8 #include <X11/Xlib.h> | 8 #include <X11/Xlib.h> |
| 9 #include <X11/Xutil.h> |
| 9 | 10 |
| 10 #include "base/basictypes.h" | 11 #include "base/basictypes.h" |
| 11 #include "base/logging.h" | 12 #include "base/logging.h" |
| 13 #include "base/utf_string_conversions.h" |
| 12 | 14 |
| 13 namespace ui { | 15 namespace ui { |
| 14 | 16 |
| 15 // Get an ui::KeyboardCode from an X keyevent | 17 // Get an ui::KeyboardCode from an X keyevent |
| 16 KeyboardCode KeyboardCodeFromXKeyEvent(XEvent* xev) { | 18 KeyboardCode KeyboardCodeFromXKeyEvent(XEvent* xev) { |
| 17 KeySym keysym = XLookupKeysym(&xev->xkey, 0); | 19 KeySym keysym = XLookupKeysym(&xev->xkey, 0); |
| 18 | 20 |
| 19 KeyboardCode keycode = KeyboardCodeFromXKeysym(keysym); | 21 KeyboardCode keycode = KeyboardCodeFromXKeysym(keysym); |
| 20 if (keycode == VKEY_UNKNOWN) { | 22 if (keycode == VKEY_UNKNOWN) { |
| 21 keysym = DefaultXKeysymFromHardwareKeycode(xev->xkey.keycode); | 23 keysym = DefaultXKeysymFromHardwareKeycode(xev->xkey.keycode); |
| (...skipping 260 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 282 case XK_F24: | 284 case XK_F24: |
| 283 return static_cast<KeyboardCode>(VKEY_F1 + (keysym - XK_F1)); | 285 return static_cast<KeyboardCode>(VKEY_F1 + (keysym - XK_F1)); |
| 284 | 286 |
| 285 // TODO(sad): some keycodes are still missing. | 287 // TODO(sad): some keycodes are still missing. |
| 286 } | 288 } |
| 287 | 289 |
| 288 DLOG(WARNING) << "Unknown keycode: " << keysym; | 290 DLOG(WARNING) << "Unknown keycode: " << keysym; |
| 289 return VKEY_UNKNOWN; | 291 return VKEY_UNKNOWN; |
| 290 } | 292 } |
| 291 | 293 |
| 294 unsigned int DefaultSymbolFromXEvent(XEvent* xev) { |
| 295 char buf[6]; |
| 296 int bytes_written = XLookupString(&xev->xkey, buf, 6, NULL, NULL); |
| 297 DCHECK_LE(bytes_written, 6); |
| 298 |
| 299 string16 result; |
| 300 return (bytes_written > 0 && UTF8ToUTF16(buf, bytes_written, &result) && |
| 301 result.length() == 1) ? result[0] : 0; |
| 302 } |
| 303 |
| 292 unsigned int DefaultXKeysymFromHardwareKeycode(unsigned int hardware_code) { | 304 unsigned int DefaultXKeysymFromHardwareKeycode(unsigned int hardware_code) { |
| 293 static const unsigned int kHardwareKeycodeMap[] = { | 305 static const unsigned int kHardwareKeycodeMap[] = { |
| 294 0, // 0x00: | 306 0, // 0x00: |
| 295 0, // 0x01: | 307 0, // 0x01: |
| 296 0, // 0x02: | 308 0, // 0x02: |
| 297 0, // 0x03: | 309 0, // 0x03: |
| 298 0, // 0x04: | 310 0, // 0x04: |
| 299 0, // 0x05: | 311 0, // 0x05: |
| 300 0, // 0x06: | 312 0, // 0x06: |
| 301 0, // 0x07: | 313 0, // 0x07: |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 370 XK_F10, // 0x4C: XK_F10 | 382 XK_F10, // 0x4C: XK_F10 |
| 371 XK_Num_Lock, // 0x4D: XK_Num_Lock | 383 XK_Num_Lock, // 0x4D: XK_Num_Lock |
| 372 XK_Scroll_Lock, // 0x4E: XK_Scroll_Lock | 384 XK_Scroll_Lock, // 0x4E: XK_Scroll_Lock |
| 373 }; | 385 }; |
| 374 | 386 |
| 375 return hardware_code < arraysize(kHardwareKeycodeMap) ? | 387 return hardware_code < arraysize(kHardwareKeycodeMap) ? |
| 376 kHardwareKeycodeMap[hardware_code] : 0; | 388 kHardwareKeycodeMap[hardware_code] : 0; |
| 377 } | 389 } |
| 378 | 390 |
| 379 } // namespace ui | 391 } // namespace ui |
| OLD | NEW |