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 #include <string.h> | 9 #include <string.h> |
10 | 10 |
(...skipping 238 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
249 gfx::Point EventLocationFromNative(const base::NativeEvent& native_event) { | 249 gfx::Point EventLocationFromNative(const base::NativeEvent& native_event) { |
250 switch (native_event->type) { | 250 switch (native_event->type) { |
251 case ButtonPress: | 251 case ButtonPress: |
252 case ButtonRelease: | 252 case ButtonRelease: |
253 return gfx::Point(native_event->xbutton.x, native_event->xbutton.y); | 253 return gfx::Point(native_event->xbutton.x, native_event->xbutton.y); |
254 case MotionNotify: | 254 case MotionNotify: |
255 return gfx::Point(native_event->xmotion.x, native_event->xmotion.y); | 255 return gfx::Point(native_event->xmotion.x, native_event->xmotion.y); |
256 case GenericEvent: { | 256 case GenericEvent: { |
257 XIDeviceEvent* xievent = | 257 XIDeviceEvent* xievent = |
258 static_cast<XIDeviceEvent*>(native_event->xcookie.data); | 258 static_cast<XIDeviceEvent*>(native_event->xcookie.data); |
259 return gfx::Point(static_cast<int>(xievent->event_x), | 259 |
260 static_cast<int>(xievent->event_y)); | 260 if (xievent->sourceid == xievent->deviceid) { |
| 261 // This event is coming from a slave device. Read the position from the |
| 262 // valuators, because the events reported for a slave device seems to be |
| 263 // behind the master device by one event. See more on crbug.com/103981. |
| 264 // The position in the valuators is in the global screen coordinates. |
| 265 // But it is necessary to convert it into the window's coordinates. If |
| 266 // the valuator is not set, that means the value hasn't changed, and so |
| 267 // we can use the value from event_x/event_y (which are in the window's |
| 268 // coordinates). |
| 269 double* valuators = xievent->valuators.values; |
| 270 |
| 271 double x = xievent->event_x; |
| 272 if (XIMaskIsSet(xievent->valuators.mask, 0)) |
| 273 x = *valuators++ - (xievent->root_x - xievent->event_x); |
| 274 |
| 275 double y = xievent->event_y; |
| 276 if (XIMaskIsSet(xievent->valuators.mask, 1)) |
| 277 y = *valuators++ - (xievent->root_y - xievent->event_y); |
| 278 |
| 279 return gfx::Point(static_cast<int>(x), static_cast<int>(y)); |
| 280 } else { |
| 281 return gfx::Point(static_cast<int>(xievent->event_x), |
| 282 static_cast<int>(xievent->event_y)); |
| 283 } |
261 } | 284 } |
262 } | 285 } |
263 return gfx::Point(); | 286 return gfx::Point(); |
264 } | 287 } |
265 | 288 |
266 KeyboardCode KeyboardCodeFromNative(const base::NativeEvent& native_event) { | 289 KeyboardCode KeyboardCodeFromNative(const base::NativeEvent& native_event) { |
267 return KeyboardCodeFromXKeyEvent(native_event); | 290 return KeyboardCodeFromXKeyEvent(native_event); |
268 } | 291 } |
269 | 292 |
270 bool IsMouseEvent(const base::NativeEvent& native_event) { | 293 bool IsMouseEvent(const base::NativeEvent& native_event) { |
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
380 // Make sure we use atom from current xdisplay, which may | 403 // Make sure we use atom from current xdisplay, which may |
381 // change during the test. | 404 // change during the test. |
382 noop->xclient.message_type = XInternAtom( | 405 noop->xclient.message_type = XInternAtom( |
383 base::MessagePumpX::GetDefaultXDisplay(), | 406 base::MessagePumpX::GetDefaultXDisplay(), |
384 "noop", False); | 407 "noop", False); |
385 #endif | 408 #endif |
386 return noop; | 409 return noop; |
387 } | 410 } |
388 | 411 |
389 } // namespace ui | 412 } // namespace ui |
OLD | NEW |