Chromium Code Reviews| Index: ui/base/x/events_x.cc |
| diff --git a/ui/base/x/events_x.cc b/ui/base/x/events_x.cc |
| index 2c38267b45f9cad0ae87d9d22aa175592e0a898b..240fa73b3fbbd5ed0b6e4476e609174886377018 100644 |
| --- a/ui/base/x/events_x.cc |
| +++ b/ui/base/x/events_x.cc |
| @@ -11,6 +11,7 @@ |
| #include "base/logging.h" |
| #include "ui/base/keycodes/keyboard_code_conversion_x.h" |
| #include "ui/base/touch/touch_factory.h" |
| +#include "ui/base/x/x11_util.h" |
| #include "ui/gfx/point.h" |
| #if !defined(TOOLKIT_USES_GTK) |
| @@ -70,11 +71,21 @@ int GetEventFlagsForButton(int button) { |
| } |
| } |
| +int GetMappedButton(int button) { |
| + static unsigned char map[256]; |
| + static int count = 0; |
| + if (!count) |
| + count = XGetPointerMapping(ui::GetXDisplay(), map, arraysize(map)); |
|
Daniel Erat
2011/12/04 15:51:45
i think that you need to refresh the cached copy o
sadrul
2011/12/07 16:36:12
Indeed. I thought about it, and assumed perhaps th
|
| + return button > 0 && button <= count ? map[button - 1] : button; |
| +} |
| + |
| int GetButtonMaskForX2Event(XIDeviceEvent* xievent) { |
| int buttonflags = 0; |
| for (int i = 0; i < 8 * xievent->buttons.mask_len; i++) { |
| if (XIMaskIsSet(xievent->buttons.mask, i)) { |
| - buttonflags |= GetEventFlagsForButton(i); |
| + int button = (xievent->sourceid == xievent->deviceid) ? |
| + GetMappedButton(i) : i; |
|
Daniel Erat
2011/12/04 15:51:45
nit: indent one less space?
sadrul
2011/12/07 17:06:52
Done.
|
| + buttonflags |= GetEventFlagsForButton(button); |
| } |
| } |
| return buttonflags; |
| @@ -185,15 +196,16 @@ EventType EventTypeFromNative(const base::NativeEvent& native_event) { |
| static_cast<XIDeviceEvent*>(native_event->xcookie.data); |
| if (TouchFactory::GetInstance()->IsTouchDevice(xievent->sourceid)) |
| return GetTouchEventType(native_event); |
| + int button = EventButtonFromNative(native_event); |
| switch (xievent->evtype) { |
| case XI_ButtonPress: |
| - if (xievent->detail >= kMinWheelButton && |
| - xievent->detail <= kMaxWheelButton) |
| + if (button >= kMinWheelButton && |
| + button <= kMaxWheelButton) |
| return ET_MOUSEWHEEL; |
| return ET_MOUSE_PRESSED; |
| case XI_ButtonRelease: |
| - if (xievent->detail >= kMinWheelButton && |
| - xievent->detail <= kMaxWheelButton) |
| + if (button >= kMinWheelButton && |
| + button <= kMaxWheelButton) |
| return ET_MOUSEWHEEL; |
| return ET_MOUSE_RELEASED; |
| case XI_Motion: |
| @@ -233,8 +245,9 @@ int EventFlagsFromNative(const base::NativeEvent& native_event) { |
| int flags = GetButtonMaskForX2Event(xievent) | |
| GetEventFlagsFromXState(xievent->mods.effective); |
| const EventType type = EventTypeFromNative(native_event); |
| + int button = EventButtonFromNative(native_event); |
| if ((type == ET_MOUSE_PRESSED || type == ET_MOUSE_RELEASED) && !touch) |
| - flags |= GetEventFlagsForButton(xievent->detail); |
| + flags |= GetEventFlagsForButton(button); |
| return flags; |
| } |
| case XI_Motion: |
| @@ -281,6 +294,16 @@ gfx::Point EventLocationFromNative(const base::NativeEvent& native_event) { |
| return gfx::Point(); |
| } |
| +int EventButtonFromNative(const base::NativeEvent& native_event) { |
| + CHECK_EQ(GenericEvent, native_event->type); |
| + XIDeviceEvent* xievent = |
| + static_cast<XIDeviceEvent*>(native_event->xcookie.data); |
| + int button = xievent->detail; |
| + |
| + return (xievent->sourceid == xievent->deviceid) ? |
| + GetMappedButton(button) : button; |
|
Daniel Erat
2011/12/04 15:51:45
nit: indent one less space?
sadrul
2011/12/07 17:06:52
Done.
|
| +} |
| + |
| KeyboardCode KeyboardCodeFromNative(const base::NativeEvent& native_event) { |
| return KeyboardCodeFromXKeyEvent(native_event); |
| } |
| @@ -302,13 +325,10 @@ bool IsMouseEvent(const base::NativeEvent& native_event) { |
| int GetMouseWheelOffset(const base::NativeEvent& native_event) { |
| int button; |
| - if (native_event->type == GenericEvent) { |
| - XIDeviceEvent* xiev = |
| - static_cast<XIDeviceEvent*>(native_event->xcookie.data); |
| - button = xiev->detail; |
| - } else { |
| + if (native_event->type == GenericEvent) |
| + button = EventButtonFromNative(native_event); |
| + else |
| button = native_event->xbutton.button; |
| - } |
| switch (button) { |
| case 4: |
| #if defined(OS_CHROMEOS) |