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 #define XK_3270 // for XK_3270_BackTab |
7 #include <X11/keysym.h> | 8 #include <X11/keysym.h> |
8 #include <X11/Xlib.h> | 9 #include <X11/Xlib.h> |
9 #include <X11/Xutil.h> | 10 #include <X11/Xutil.h> |
10 | 11 |
11 #include "base/basictypes.h" | 12 #include "base/basictypes.h" |
12 #include "base/logging.h" | 13 #include "base/logging.h" |
13 #include "base/stringprintf.h" | 14 #include "base/stringprintf.h" |
14 #include "base/utf_string_conversions.h" | 15 #include "base/utf_string_conversions.h" |
15 | 16 |
16 namespace ui { | 17 namespace ui { |
17 | 18 |
18 // Get an ui::KeyboardCode from an X keyevent | 19 // Get an ui::KeyboardCode from an X keyevent |
19 KeyboardCode KeyboardCodeFromXKeyEvent(XEvent* xev) { | 20 KeyboardCode KeyboardCodeFromXKeyEvent(XEvent* xev) { |
20 // XLookupKeysym does not take into consideration the state of the lock/shift | 21 // XLookupKeysym does not take into consideration the state of the lock/shift |
21 // etc. keys. So it is necessary to use XLookupString instead. | 22 // etc. keys. So it is necessary to use XLookupString instead. |
22 KeySym keysym; | 23 KeySym keysym; |
23 XLookupString(&xev->xkey, NULL, 0, &keysym, NULL); | 24 XLookupString(&xev->xkey, NULL, 0, &keysym, NULL); |
24 KeyboardCode keycode = KeyboardCodeFromXKeysym(keysym); | 25 KeyboardCode keycode = KeyboardCodeFromXKeysym(keysym); |
25 if (keycode == VKEY_UNKNOWN) { | 26 if (keycode == VKEY_UNKNOWN) { |
26 keysym = DefaultXKeysymFromHardwareKeycode(xev->xkey.keycode); | 27 keysym = DefaultXKeysymFromHardwareKeycode(xev->xkey.keycode); |
27 keycode = KeyboardCodeFromXKeysym(keysym); | 28 keycode = KeyboardCodeFromXKeysym(keysym); |
28 } | 29 } |
29 | 30 |
30 return keycode; | 31 return keycode; |
31 } | 32 } |
32 | 33 |
33 KeyboardCode KeyboardCodeFromXKeysym(unsigned int keysym) { | 34 KeyboardCode KeyboardCodeFromXKeysym(unsigned int keysym) { |
34 // Consult GDK key translation (in WindowsKeyCodeForGdkKeyCode) for details | |
35 // about the following translations. | |
36 | |
37 // TODO(sad): Have |keysym| go through the X map list? | 35 // TODO(sad): Have |keysym| go through the X map list? |
38 | 36 |
39 switch (keysym) { | 37 switch (keysym) { |
40 case XK_BackSpace: | 38 case XK_BackSpace: |
41 return VKEY_BACK; | 39 return VKEY_BACK; |
42 case XK_Delete: | 40 case XK_Delete: |
43 case XK_KP_Delete: | 41 case XK_KP_Delete: |
44 return VKEY_DELETE; | 42 return VKEY_DELETE; |
45 case XK_Tab: | 43 case XK_Tab: |
46 case XK_KP_Tab: | 44 case XK_KP_Tab: |
47 case XK_ISO_Left_Tab: | 45 case XK_ISO_Left_Tab: |
| 46 case XK_3270_BackTab: |
48 return VKEY_TAB; | 47 return VKEY_TAB; |
49 case XK_Linefeed: | 48 case XK_Linefeed: |
50 case XK_Return: | 49 case XK_Return: |
51 case XK_KP_Enter: | 50 case XK_KP_Enter: |
| 51 case XK_ISO_Enter: |
52 return VKEY_RETURN; | 52 return VKEY_RETURN; |
53 case XK_Clear: | 53 case XK_Clear: |
54 return VKEY_CLEAR; | 54 return VKEY_CLEAR; |
55 case XK_KP_Space: | 55 case XK_KP_Space: |
56 case XK_space: | 56 case XK_space: |
57 return VKEY_SPACE; | 57 return VKEY_SPACE; |
58 case XK_Home: | 58 case XK_Home: |
59 case XK_KP_Home: | 59 case XK_KP_Home: |
60 return VKEY_HOME; | 60 return VKEY_HOME; |
61 case XK_End: | 61 case XK_End: |
(...skipping 12 matching lines...) Expand all Loading... |
74 case XK_KP_Right: | 74 case XK_KP_Right: |
75 return VKEY_RIGHT; | 75 return VKEY_RIGHT; |
76 case XK_Down: | 76 case XK_Down: |
77 case XK_KP_Down: | 77 case XK_KP_Down: |
78 return VKEY_DOWN; | 78 return VKEY_DOWN; |
79 case XK_Up: | 79 case XK_Up: |
80 case XK_KP_Up: | 80 case XK_KP_Up: |
81 return VKEY_UP; | 81 return VKEY_UP; |
82 case XK_Escape: | 82 case XK_Escape: |
83 return VKEY_ESCAPE; | 83 return VKEY_ESCAPE; |
| 84 case XK_Kana_Lock: |
| 85 case XK_Kana_Shift: |
| 86 return VKEY_KANA; |
| 87 case XK_Hangul: |
| 88 return VKEY_HANGUL; |
| 89 case XK_Hangul_Hanja: |
| 90 return VKEY_HANJA; |
| 91 case XK_Kanji: |
| 92 return VKEY_KANJI; |
84 case XK_A: | 93 case XK_A: |
85 case XK_a: | 94 case XK_a: |
86 return VKEY_A; | 95 return VKEY_A; |
87 case XK_B: | 96 case XK_B: |
88 case XK_b: | 97 case XK_b: |
89 return VKEY_B; | 98 return VKEY_B; |
90 case XK_C: | 99 case XK_C: |
91 case XK_c: | 100 case XK_c: |
92 return VKEY_C; | 101 return VKEY_C; |
93 case XK_D: | 102 case XK_D: |
(...skipping 522 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
616 case VKEY_F24: | 625 case VKEY_F24: |
617 return XK_F1 + (keycode - VKEY_F1); | 626 return XK_F1 + (keycode - VKEY_F1); |
618 | 627 |
619 default: | 628 default: |
620 LOG(WARNING) << "Unknown keycode:" << keycode; | 629 LOG(WARNING) << "Unknown keycode:" << keycode; |
621 return 0; | 630 return 0; |
622 } | 631 } |
623 } | 632 } |
624 | 633 |
625 } // namespace ui | 634 } // namespace ui |
OLD | NEW |