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/events.h" | 5 #include "ui/base/events.h" |
6 | 6 |
7 #include <X11/Xlib.h> | 7 #include <X11/Xlib.h> |
8 #include <X11/extensions/XInput2.h> | 8 #include <X11/extensions/XInput2.h> |
9 | 9 |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
(...skipping 230 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
241 gfx::Point EventLocationFromNative(const base::NativeEvent& native_event) { | 241 gfx::Point EventLocationFromNative(const base::NativeEvent& native_event) { |
242 switch (native_event->type) { | 242 switch (native_event->type) { |
243 case ButtonPress: | 243 case ButtonPress: |
244 case ButtonRelease: | 244 case ButtonRelease: |
245 return gfx::Point(native_event->xbutton.x, native_event->xbutton.y); | 245 return gfx::Point(native_event->xbutton.x, native_event->xbutton.y); |
246 case MotionNotify: | 246 case MotionNotify: |
247 return gfx::Point(native_event->xmotion.x, native_event->xmotion.y); | 247 return gfx::Point(native_event->xmotion.x, native_event->xmotion.y); |
248 case GenericEvent: { | 248 case GenericEvent: { |
249 XIDeviceEvent* xievent = | 249 XIDeviceEvent* xievent = |
250 static_cast<XIDeviceEvent*>(native_event->xcookie.data); | 250 static_cast<XIDeviceEvent*>(native_event->xcookie.data); |
251 return gfx::Point(static_cast<int>(xievent->event_x), | 251 |
252 static_cast<int>(xievent->event_y)); | 252 if (xievent->sourceid == xievent->deviceid) { |
| 253 // This event is coming from a slave device. Read the position from the |
| 254 // valuators, because the events reported for a slave device seems to be |
| 255 // behind the master device by one event. See more on crbug.com/103981. |
| 256 // The position in the valuators is in the global screen coordinates. |
| 257 // But it is necessary to convert it into the window's coordinates. If |
| 258 // the valuator is not set, that means the value hasn't changed, and so |
| 259 // we can use the value from event_x/event_y (which are in the window's |
| 260 // coordinates). |
| 261 double* valuators = xievent->valuators.values; |
| 262 |
| 263 double x = xievent->event_x; |
| 264 if (XIMaskIsSet(xievent->valuators.mask, 0)) |
| 265 x = *valuators++ - (xievent->root_x - xievent->event_x); |
| 266 |
| 267 double y = xievent->event_y; |
| 268 if (XIMaskIsSet(xievent->valuators.mask, 1)) |
| 269 y = *valuators++ - (xievent->root_y - xievent->event_y); |
| 270 |
| 271 return gfx::Point(static_cast<int>(x), static_cast<int>(y)); |
| 272 } else { |
| 273 return gfx::Point(static_cast<int>(xievent->event_x), |
| 274 static_cast<int>(xievent->event_y)); |
| 275 } |
253 } | 276 } |
254 } | 277 } |
255 return gfx::Point(); | 278 return gfx::Point(); |
256 } | 279 } |
257 | 280 |
258 KeyboardCode KeyboardCodeFromNative(const base::NativeEvent& native_event) { | 281 KeyboardCode KeyboardCodeFromNative(const base::NativeEvent& native_event) { |
259 return KeyboardCodeFromXKeyEvent(native_event); | 282 return KeyboardCodeFromXKeyEvent(native_event); |
260 } | 283 } |
261 | 284 |
262 bool IsMouseEvent(const base::NativeEvent& native_event) { | 285 bool IsMouseEvent(const base::NativeEvent& native_event) { |
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
359 static XEvent* noop = new XEvent(); | 382 static XEvent* noop = new XEvent(); |
360 noop->xclient.type = ClientMessage; | 383 noop->xclient.type = ClientMessage; |
361 noop->xclient.display = NULL; | 384 noop->xclient.display = NULL; |
362 noop->xclient.window = None; | 385 noop->xclient.window = None; |
363 noop->xclient.message_type = 0; | 386 noop->xclient.message_type = 0; |
364 noop->xclient.format = 0; | 387 noop->xclient.format = 0; |
365 return noop; | 388 return noop; |
366 } | 389 } |
367 | 390 |
368 } // namespace ui | 391 } // namespace ui |
OLD | NEW |