| Index: ui/events/keycodes/keyboard_code_conversion_x.cc
|
| diff --git a/ui/events/keycodes/keyboard_code_conversion_x.cc b/ui/events/keycodes/keyboard_code_conversion_x.cc
|
| index 5d6c6ace60609550e06a34e47da506a94bef181b..7d203e9535e1ceeb060f226718d777609c479585 100644
|
| --- a/ui/events/keycodes/keyboard_code_conversion_x.cc
|
| +++ b/ui/events/keycodes/keyboard_code_conversion_x.cc
|
| @@ -5,10 +5,11 @@
|
| #include "ui/events/keycodes/keyboard_code_conversion_x.h"
|
|
|
| #define XK_3270 // for XK_3270_BackTab
|
| -#include <X11/keysym.h>
|
| +#include <X11/XF86keysym.h>
|
| #include <X11/Xlib.h>
|
| #include <X11/Xutil.h>
|
| -#include <X11/XF86keysym.h>
|
| +#include <X11/extensions/XInput2.h>
|
| +#include <X11/keysym.h>
|
|
|
| #include "base/basictypes.h"
|
| #include "base/logging.h"
|
| @@ -21,13 +22,23 @@ namespace ui {
|
|
|
| // Get an ui::KeyboardCode from an X keyevent
|
| KeyboardCode KeyboardCodeFromXKeyEvent(XEvent* xev) {
|
| + XEvent xkeyevent;
|
| + XKeyEvent* xkey = NULL;
|
| + if (xev->type == GenericEvent) {
|
| + // Convert the XI2 key event into a core key event so that we can
|
| + // continue to use XLookupString() until crbug.com/367732 is complete.
|
| + InitXKeyEventFromXIDeviceEvent(*xev, &xkeyevent);
|
| + xkey = &xkeyevent.xkey;
|
| + } else {
|
| + xkey = &xev->xkey;
|
| + }
|
| // XLookupKeysym does not take into consideration the state of the lock/shift
|
| // etc. keys. So it is necessary to use XLookupString instead.
|
| KeySym keysym;
|
| - XLookupString(&xev->xkey, NULL, 0, &keysym, NULL);
|
| + XLookupString(xkey, NULL, 0, &keysym, NULL);
|
| KeyboardCode keycode = KeyboardCodeFromXKeysym(keysym);
|
| if (keycode == VKEY_UNKNOWN) {
|
| - keysym = DefaultXKeysymFromHardwareKeycode(xev->xkey.keycode);
|
| + keysym = DefaultXKeysymFromHardwareKeycode(xkey->keycode);
|
| keycode = KeyboardCodeFromXKeysym(keysym);
|
| }
|
|
|
| @@ -428,13 +439,25 @@ KeyboardCode KeyboardCodeFromXKeysym(unsigned int keysym) {
|
| }
|
|
|
| const char* CodeFromXEvent(XEvent* xev) {
|
| - return KeycodeConverter::GetInstance()->NativeKeycodeToCode(
|
| - xev->xkey.keycode);
|
| + int keycode = (xev->type == GenericEvent)
|
| + ? static_cast<XIDeviceEvent*>(xev->xcookie.data)->detail
|
| + : xev->xkey.keycode;
|
| + return KeycodeConverter::GetInstance()->NativeKeycodeToCode(keycode);
|
| }
|
|
|
| uint16 GetCharacterFromXEvent(XEvent* xev) {
|
| + XEvent xkeyevent;
|
| + XKeyEvent* xkey = NULL;
|
| char buf[6];
|
| - int bytes_written = XLookupString(&xev->xkey, buf, 6, NULL, NULL);
|
| + if (xev->type == GenericEvent) {
|
| + // Convert the XI2 key event into a core key event so that we can
|
| + // continue to use XLookupString() until crbug.com/367732 is complete.
|
| + InitXKeyEventFromXIDeviceEvent(*xev, &xkeyevent);
|
| + xkey = &xkeyevent.xkey;
|
| + } else {
|
| + xkey = &xev->xkey;
|
| + }
|
| + int bytes_written = XLookupString(xkey, buf, 6, NULL, NULL);
|
| DCHECK_LE(bytes_written, 6);
|
|
|
| if (bytes_written <= 0)
|
| @@ -876,4 +899,33 @@ int XKeysymForWindowsKeyCode(KeyboardCode keycode, bool shift) {
|
| }
|
| }
|
|
|
| +void InitXKeyEventFromXIDeviceEvent(const XEvent& src, XEvent* xkeyevent) {
|
| + DCHECK(src.type == GenericEvent);
|
| + XIDeviceEvent* xievent = static_cast<XIDeviceEvent*>(src.xcookie.data);
|
| + switch (xievent->evtype) {
|
| + case XI_KeyPress:
|
| + xkeyevent->type = KeyPress;
|
| + break;
|
| + case XI_KeyRelease:
|
| + xkeyevent->type = KeyRelease;
|
| + break;
|
| + default:
|
| + NOTREACHED();
|
| + }
|
| + xkeyevent->xkey.serial = xievent->serial;
|
| + xkeyevent->xkey.send_event = xievent->send_event;
|
| + xkeyevent->xkey.display = xievent->display;
|
| + xkeyevent->xkey.window = xievent->event;
|
| + xkeyevent->xkey.root = xievent->root;
|
| + xkeyevent->xkey.subwindow = xievent->child;
|
| + xkeyevent->xkey.time = xievent->time;
|
| + xkeyevent->xkey.x = xievent->event_x;
|
| + xkeyevent->xkey.y = xievent->event_y;
|
| + xkeyevent->xkey.x_root = xievent->root_x;
|
| + xkeyevent->xkey.y_root = xievent->root_y;
|
| + xkeyevent->xkey.state = xievent->mods.effective;
|
| + xkeyevent->xkey.keycode = xievent->detail;
|
| + xkeyevent->xkey.same_screen = 1;
|
| +}
|
| +
|
| } // namespace ui
|
|
|