| 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 #include <X11/Xutil.h> |
| 10 | 10 |
| 11 #include "base/basictypes.h" | 11 #include "base/basictypes.h" |
| 12 #include "base/logging.h" | 12 #include "base/logging.h" |
| 13 #include "base/stringprintf.h" |
| 13 #include "base/utf_string_conversions.h" | 14 #include "base/utf_string_conversions.h" |
| 14 | 15 |
| 15 namespace ui { | 16 namespace ui { |
| 16 | 17 |
| 17 // Get an ui::KeyboardCode from an X keyevent | 18 // Get an ui::KeyboardCode from an X keyevent |
| 18 KeyboardCode KeyboardCodeFromXKeyEvent(XEvent* xev) { | 19 KeyboardCode KeyboardCodeFromXKeyEvent(XEvent* xev) { |
| 19 // XLookupKeysym does not take into consideration the state of the lock/shift | 20 // XLookupKeysym does not take into consideration the state of the lock/shift |
| 20 // etc. keys. So it is necessary to use XLookupString instead. | 21 // etc. keys. So it is necessary to use XLookupString instead. |
| 21 KeySym keysym; | 22 KeySym keysym; |
| 22 XLookupString(&xev->xkey, NULL, 0, &keysym, NULL); | 23 XLookupString(&xev->xkey, NULL, 0, &keysym, NULL); |
| (...skipping 13 matching lines...) Expand all Loading... |
| 36 // TODO(sad): Have |keysym| go through the X map list? | 37 // TODO(sad): Have |keysym| go through the X map list? |
| 37 | 38 |
| 38 switch (keysym) { | 39 switch (keysym) { |
| 39 case XK_BackSpace: | 40 case XK_BackSpace: |
| 40 return VKEY_BACK; | 41 return VKEY_BACK; |
| 41 case XK_Delete: | 42 case XK_Delete: |
| 42 case XK_KP_Delete: | 43 case XK_KP_Delete: |
| 43 return VKEY_DELETE; | 44 return VKEY_DELETE; |
| 44 case XK_Tab: | 45 case XK_Tab: |
| 45 case XK_KP_Tab: | 46 case XK_KP_Tab: |
| 47 case XK_ISO_Left_Tab: |
| 46 return VKEY_TAB; | 48 return VKEY_TAB; |
| 47 case XK_Linefeed: | 49 case XK_Linefeed: |
| 48 case XK_Return: | 50 case XK_Return: |
| 49 case XK_KP_Enter: | 51 case XK_KP_Enter: |
| 50 return VKEY_RETURN; | 52 return VKEY_RETURN; |
| 51 case XK_Clear: | 53 case XK_Clear: |
| 52 return VKEY_CLEAR; | 54 return VKEY_CLEAR; |
| 53 case XK_KP_Space: | 55 case XK_KP_Space: |
| 54 case XK_space: | 56 case XK_space: |
| 55 return VKEY_SPACE; | 57 return VKEY_SPACE; |
| (...skipping 250 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 306 case XK_F19: | 308 case XK_F19: |
| 307 case XK_F20: | 309 case XK_F20: |
| 308 case XK_F21: | 310 case XK_F21: |
| 309 case XK_F22: | 311 case XK_F22: |
| 310 case XK_F23: | 312 case XK_F23: |
| 311 case XK_F24: | 313 case XK_F24: |
| 312 return static_cast<KeyboardCode>(VKEY_F1 + (keysym - XK_F1)); | 314 return static_cast<KeyboardCode>(VKEY_F1 + (keysym - XK_F1)); |
| 313 | 315 |
| 314 // TODO(sad): some keycodes are still missing. | 316 // TODO(sad): some keycodes are still missing. |
| 315 } | 317 } |
| 316 | 318 DLOG(WARNING) << "Unknown keysym: " << StringPrintf("0x%x", keysym); |
| 317 DLOG(WARNING) << "Unknown keycode: " << keysym; | |
| 318 return VKEY_UNKNOWN; | 319 return VKEY_UNKNOWN; |
| 319 } | 320 } |
| 320 | 321 |
| 321 unsigned int DefaultSymbolFromXEvent(XEvent* xev) { | 322 unsigned int DefaultSymbolFromXEvent(XEvent* xev) { |
| 322 char buf[6]; | 323 char buf[6]; |
| 323 int bytes_written = XLookupString(&xev->xkey, buf, 6, NULL, NULL); | 324 int bytes_written = XLookupString(&xev->xkey, buf, 6, NULL, NULL); |
| 324 DCHECK_LE(bytes_written, 6); | 325 DCHECK_LE(bytes_written, 6); |
| 325 | 326 |
| 326 string16 result; | 327 string16 result; |
| 327 return (bytes_written > 0 && UTF8ToUTF16(buf, bytes_written, &result) && | 328 return (bytes_written > 0 && UTF8ToUTF16(buf, bytes_written, &result) && |
| (...skipping 281 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 609 case VKEY_F18: | 610 case VKEY_F18: |
| 610 case VKEY_F19: | 611 case VKEY_F19: |
| 611 case VKEY_F20: | 612 case VKEY_F20: |
| 612 case VKEY_F21: | 613 case VKEY_F21: |
| 613 case VKEY_F22: | 614 case VKEY_F22: |
| 614 case VKEY_F23: | 615 case VKEY_F23: |
| 615 case VKEY_F24: | 616 case VKEY_F24: |
| 616 return XK_F1 + (keycode - VKEY_F1); | 617 return XK_F1 + (keycode - VKEY_F1); |
| 617 | 618 |
| 618 default: | 619 default: |
| 620 LOG(WARNING) << "Unknown keycode:" << keycode; |
| 619 return 0; | 621 return 0; |
| 620 } | 622 } |
| 621 } | 623 } |
| 622 | 624 |
| 623 } // namespace ui | 625 } // namespace ui |
| OLD | NEW |