OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/events/keycodes/keyboard_code_conversion_x.h" | 5 #include "ui/events/keycodes/keyboard_code_conversion_x.h" |
6 | 6 |
7 #define XK_3270 // for XK_3270_BackTab | 7 #define XK_3270 // for XK_3270_BackTab |
8 #include <X11/keysym.h> | 8 #include <X11/keysym.h> |
9 #include <X11/Xlib.h> | 9 #include <X11/Xlib.h> |
10 #include <X11/Xutil.h> | 10 #include <X11/Xutil.h> |
11 #include <X11/XF86keysym.h> | 11 #include <X11/XF86keysym.h> |
12 | 12 |
13 #include "base/basictypes.h" | 13 #include "base/basictypes.h" |
14 #include "base/logging.h" | 14 #include "base/logging.h" |
15 #include "base/strings/stringprintf.h" | 15 #include "base/strings/stringprintf.h" |
16 #include "base/strings/utf_string_conversions.h" | 16 #include "base/strings/utf_string_conversions.h" |
17 #include "ui/events/event_constants.h" | |
17 #include "ui/events/keycodes/dom4/keycode_converter.h" | 18 #include "ui/events/keycodes/dom4/keycode_converter.h" |
18 | 19 |
19 namespace ui { | 20 namespace ui { |
20 | 21 |
21 // Get an ui::KeyboardCode from an X keyevent | 22 // Get an ui::KeyboardCode from an X keyevent |
22 KeyboardCode KeyboardCodeFromXKeyEvent(XEvent* xev) { | 23 KeyboardCode KeyboardCodeFromXKeyEvent(XEvent* xev) { |
23 // XLookupKeysym does not take into consideration the state of the lock/shift | 24 // XLookupKeysym does not take into consideration the state of the lock/shift |
24 // etc. keys. So it is necessary to use XLookupString instead. | 25 // etc. keys. So it is necessary to use XLookupString instead. |
25 KeySym keysym; | 26 KeySym keysym; |
26 XLookupString(&xev->xkey, NULL, 0, &keysym, NULL); | 27 XLookupString(&xev->xkey, NULL, 0, &keysym, NULL); |
(...skipping 392 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
419 return VKEY_KBD_BRIGHTNESS_DOWN; | 420 return VKEY_KBD_BRIGHTNESS_DOWN; |
420 case XF86XK_KbdBrightnessUp: | 421 case XF86XK_KbdBrightnessUp: |
421 return VKEY_KBD_BRIGHTNESS_UP; | 422 return VKEY_KBD_BRIGHTNESS_UP; |
422 | 423 |
423 // TODO(sad): some keycodes are still missing. | 424 // TODO(sad): some keycodes are still missing. |
424 } | 425 } |
425 DLOG(WARNING) << "Unknown keysym: " << base::StringPrintf("0x%x", keysym); | 426 DLOG(WARNING) << "Unknown keysym: " << base::StringPrintf("0x%x", keysym); |
426 return VKEY_UNKNOWN; | 427 return VKEY_UNKNOWN; |
427 } | 428 } |
428 | 429 |
430 int EventFlagsFromXKeysym(unsigned int keysym) { | |
431 static const unsigned int numpad_keysyms[] = { | |
sadrul
2014/04/14 21:51:32
Does this need to be static?
kpschoedel
2014/04/14 22:25:45
If it's not static, the compiler is expected to tr
| |
432 XK_KP_Delete, | |
433 XK_KP_Tab, | |
434 XK_KP_Enter, | |
435 XK_KP_Begin, | |
436 XK_KP_Space, | |
437 XK_KP_Home, | |
438 XK_KP_End, | |
439 XK_KP_Page_Up, // aka XK_KP_Prior | |
440 XK_KP_Page_Down, // aka XK_KP_Next | |
441 XK_KP_Left, | |
442 XK_KP_Right, | |
443 XK_KP_Down, | |
444 XK_KP_Up, | |
445 XK_KP_0, | |
446 XK_KP_1, | |
447 XK_KP_2, | |
448 XK_KP_3, | |
449 XK_KP_4, | |
450 XK_KP_5, | |
451 XK_KP_6, | |
452 XK_KP_7, | |
453 XK_KP_8, | |
454 XK_KP_9, | |
455 XK_KP_Multiply, | |
456 XK_KP_Add, | |
457 XK_KP_Separator, | |
458 XK_KP_Subtract, | |
459 XK_KP_Decimal, | |
460 XK_KP_Divide, | |
461 XK_KP_Equal, | |
462 XK_KP_Insert, | |
463 XK_KP_F1, | |
464 XK_KP_F2, | |
465 XK_KP_F3, | |
466 XK_KP_F4, | |
467 }; | |
468 for (size_t i = 0; i < arraysize(numpad_keysyms); ++i) { | |
469 if (numpad_keysyms[i] == keysym) | |
470 return EF_NUMPAD; | |
sadrul
2014/04/14 21:51:32
There's an IsKeypadKey macro in X11/Xutil.h. Can w
kpschoedel
2014/04/14 22:25:45
Yes, thanks for pointing that out.
| |
471 } | |
472 return EF_NONE; | |
473 } | |
474 | |
429 const char* CodeFromXEvent(XEvent* xev) { | 475 const char* CodeFromXEvent(XEvent* xev) { |
430 return KeycodeConverter::GetInstance()->NativeKeycodeToCode( | 476 return KeycodeConverter::GetInstance()->NativeKeycodeToCode( |
431 xev->xkey.keycode); | 477 xev->xkey.keycode); |
432 } | 478 } |
433 | 479 |
434 uint16 GetCharacterFromXEvent(XEvent* xev) { | 480 uint16 GetCharacterFromXEvent(XEvent* xev) { |
435 char buf[6]; | 481 char buf[6]; |
436 int bytes_written = XLookupString(&xev->xkey, buf, 6, NULL, NULL); | 482 int bytes_written = XLookupString(&xev->xkey, buf, 6, NULL, NULL); |
437 DCHECK_LE(bytes_written, 6); | 483 DCHECK_LE(bytes_written, 6); |
438 | 484 |
(...skipping 365 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
804 case VKEY_KBD_BRIGHTNESS_UP: | 850 case VKEY_KBD_BRIGHTNESS_UP: |
805 return XF86XK_KbdBrightnessUp; | 851 return XF86XK_KbdBrightnessUp; |
806 | 852 |
807 default: | 853 default: |
808 LOG(WARNING) << "Unknown keycode:" << keycode; | 854 LOG(WARNING) << "Unknown keycode:" << keycode; |
809 return 0; | 855 return 0; |
810 } | 856 } |
811 } | 857 } |
812 | 858 |
813 } // namespace ui | 859 } // namespace ui |
OLD | NEW |