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/utf_string_conversions.h" | 13 #include "base/utf_string_conversions.h" |
14 | 14 |
15 namespace ui { | 15 namespace ui { |
16 | 16 |
17 // Get an ui::KeyboardCode from an X keyevent | 17 // Get an ui::KeyboardCode from an X keyevent |
18 KeyboardCode KeyboardCodeFromXKeyEvent(XEvent* xev) { | 18 KeyboardCode KeyboardCodeFromXKeyEvent(XEvent* xev) { |
19 KeySym keysym = XLookupKeysym(&xev->xkey, 0); | 19 // XLookupKeysym does not take into consideration the state of the lock/shift |
20 | 20 // etc. keys. So it is necessary to use XLookupString instead. |
| 21 KeySym keysym; |
| 22 XLookupString(&xev->xkey, NULL, 0, &keysym, NULL); |
21 KeyboardCode keycode = KeyboardCodeFromXKeysym(keysym); | 23 KeyboardCode keycode = KeyboardCodeFromXKeysym(keysym); |
22 if (keycode == VKEY_UNKNOWN) { | 24 if (keycode == VKEY_UNKNOWN) { |
23 keysym = DefaultXKeysymFromHardwareKeycode(xev->xkey.keycode); | 25 keysym = DefaultXKeysymFromHardwareKeycode(xev->xkey.keycode); |
24 keycode = KeyboardCodeFromXKeysym(keysym); | 26 keycode = KeyboardCodeFromXKeysym(keysym); |
25 } | 27 } |
26 | 28 |
27 return keycode; | 29 return keycode; |
28 } | 30 } |
29 | 31 |
30 KeyboardCode KeyboardCodeFromXKeysym(unsigned int keysym) { | 32 KeyboardCode KeyboardCodeFromXKeysym(unsigned int keysym) { |
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
148 return VKEY_W; | 150 return VKEY_W; |
149 case XK_X: | 151 case XK_X: |
150 case XK_x: | 152 case XK_x: |
151 return VKEY_X; | 153 return VKEY_X; |
152 case XK_Y: | 154 case XK_Y: |
153 case XK_y: | 155 case XK_y: |
154 return VKEY_Y; | 156 return VKEY_Y; |
155 case XK_Z: | 157 case XK_Z: |
156 case XK_z: | 158 case XK_z: |
157 return VKEY_Z; | 159 return VKEY_Z; |
| 160 |
158 case XK_0: | 161 case XK_0: |
159 return VKEY_0; | |
160 case XK_1: | 162 case XK_1: |
161 return VKEY_1; | |
162 case XK_2: | 163 case XK_2: |
163 return VKEY_2; | |
164 case XK_3: | 164 case XK_3: |
165 return VKEY_3; | |
166 case XK_4: | 165 case XK_4: |
167 return VKEY_4; | |
168 case XK_5: | 166 case XK_5: |
169 return VKEY_5; | |
170 case XK_6: | 167 case XK_6: |
171 return VKEY_6; | |
172 case XK_7: | 168 case XK_7: |
173 return VKEY_7; | |
174 case XK_8: | 169 case XK_8: |
175 return VKEY_8; | |
176 case XK_9: | 170 case XK_9: |
177 return VKEY_9; | 171 return static_cast<KeyboardCode>(VKEY_0 + (keysym - XK_0)); |
| 172 |
| 173 case XK_KP_0: |
| 174 case XK_KP_1: |
| 175 case XK_KP_2: |
| 176 case XK_KP_3: |
| 177 case XK_KP_4: |
| 178 case XK_KP_5: |
| 179 case XK_KP_6: |
| 180 case XK_KP_7: |
| 181 case XK_KP_8: |
| 182 case XK_KP_9: |
| 183 return static_cast<KeyboardCode>(VKEY_NUMPAD0 + (keysym - XK_KP_0)); |
178 | 184 |
179 case XK_multiply: | 185 case XK_multiply: |
180 case XK_KP_Multiply: | 186 case XK_KP_Multiply: |
181 return VKEY_MULTIPLY; | 187 return VKEY_MULTIPLY; |
182 case XK_KP_Add: | 188 case XK_KP_Add: |
183 return VKEY_ADD; | 189 return VKEY_ADD; |
184 case XK_KP_Separator: | 190 case XK_KP_Separator: |
185 return VKEY_SEPARATOR; | 191 return VKEY_SEPARATOR; |
186 case XK_KP_Subtract: | 192 case XK_KP_Subtract: |
187 return VKEY_SUBTRACT; | 193 return VKEY_SUBTRACT; |
(...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
382 XK_F10, // 0x4C: XK_F10 | 388 XK_F10, // 0x4C: XK_F10 |
383 XK_Num_Lock, // 0x4D: XK_Num_Lock | 389 XK_Num_Lock, // 0x4D: XK_Num_Lock |
384 XK_Scroll_Lock, // 0x4E: XK_Scroll_Lock | 390 XK_Scroll_Lock, // 0x4E: XK_Scroll_Lock |
385 }; | 391 }; |
386 | 392 |
387 return hardware_code < arraysize(kHardwareKeycodeMap) ? | 393 return hardware_code < arraysize(kHardwareKeycodeMap) ? |
388 kHardwareKeycodeMap[hardware_code] : 0; | 394 kHardwareKeycodeMap[hardware_code] : 0; |
389 } | 395 } |
390 | 396 |
391 } // namespace ui | 397 } // namespace ui |
OLD | NEW |