Chromium Code Reviews| 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/devices/x11/touch_factory_x11.h" | 5 #include "ui/events/devices/x11/touch_factory_x11.h" |
| 6 | 6 |
| 7 #include <X11/Xatom.h> | 7 #include <X11/Xatom.h> |
| 8 #include <X11/cursorfont.h> | 8 #include <X11/cursorfont.h> |
| 9 #include <X11/extensions/XInput.h> | 9 #include <X11/extensions/XInput.h> |
| 10 #include <X11/extensions/XInput2.h> | 10 #include <X11/extensions/XInput2.h> |
| (...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 153 } | 153 } |
| 154 | 154 |
| 155 bool TouchFactory::ShouldProcessXI2Event(XEvent* xev) { | 155 bool TouchFactory::ShouldProcessXI2Event(XEvent* xev) { |
| 156 DCHECK_EQ(GenericEvent, xev->type); | 156 DCHECK_EQ(GenericEvent, xev->type); |
| 157 XIEvent* event = static_cast<XIEvent*>(xev->xcookie.data); | 157 XIEvent* event = static_cast<XIEvent*>(xev->xcookie.data); |
| 158 XIDeviceEvent* xiev = reinterpret_cast<XIDeviceEvent*>(event); | 158 XIDeviceEvent* xiev = reinterpret_cast<XIDeviceEvent*>(event); |
| 159 | 159 |
| 160 if (event->evtype == XI_TouchBegin || | 160 if (event->evtype == XI_TouchBegin || |
| 161 event->evtype == XI_TouchUpdate || | 161 event->evtype == XI_TouchUpdate || |
| 162 event->evtype == XI_TouchEnd) { | 162 event->evtype == XI_TouchEnd) { |
| 163 return !touch_events_disabled_ && IsTouchDevice(xiev->deviceid); | 163 // Since SetupXI2ForXWindow() selects events from all devices, for a |
| 164 // touchscreen attached to a master pointer device, X11 sends two | |
| 165 // events for each touch: one from the slave (deviceid == the id of | |
| 166 // the touchscreen device), and one from the master (deviceid == the | |
| 167 // id of the master pointer device). Instead of processing both | |
| 168 // events, discard the event that comes from the slave, and only | |
| 169 // allow processing the event coming from the master. | |
| 170 // For a 'floating' touchscreen device, X11 sends only one event for | |
| 171 // each touch, with both deviceid and sourceid set to the id of the | |
| 172 // touchscreen device. | |
| 173 bool is_from_slave_device = !touch_device_list_[xiev->deviceid] && | |
| 174 (xiev->sourceid == xiev->deviceid); | |
|
sadrul
2015/03/11 07:43:49
Just one more nit:
bool is_from_master_or_float
| |
| 175 return !touch_events_disabled_ && | |
| 176 IsTouchDevice(xiev->deviceid) && | |
| 177 !is_from_slave_device; | |
| 164 } | 178 } |
| 165 | 179 |
| 166 // Make sure only key-events from the virtual core keyboard are processed. | 180 // Make sure only key-events from the virtual core keyboard are processed. |
| 167 if (event->evtype == XI_KeyPress || event->evtype == XI_KeyRelease) { | 181 if (event->evtype == XI_KeyPress || event->evtype == XI_KeyRelease) { |
| 168 return (virtual_core_keyboard_device_ < 0) || | 182 return (virtual_core_keyboard_device_ < 0) || |
| 169 (virtual_core_keyboard_device_ == xiev->deviceid); | 183 (virtual_core_keyboard_device_ == xiev->deviceid); |
| 170 } | 184 } |
| 171 | 185 |
| 172 if (event->evtype != XI_ButtonPress && | 186 if (event->evtype != XI_ButtonPress && |
| 173 event->evtype != XI_ButtonRelease && | 187 event->evtype != XI_ButtonRelease && |
| (...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 324 if (ptr[0] || ptr[1]) | 338 if (ptr[0] || ptr[1]) |
| 325 touchscreen_ids_.insert(std::make_pair(ptr[0], ptr[1])); | 339 touchscreen_ids_.insert(std::make_pair(ptr[0], ptr[1])); |
| 326 } | 340 } |
| 327 XFree(prop_return); | 341 XFree(prop_return); |
| 328 } | 342 } |
| 329 | 343 |
| 330 XCloseDevice(display, device); | 344 XCloseDevice(display, device); |
| 331 } | 345 } |
| 332 | 346 |
| 333 } // namespace ui | 347 } // namespace ui |
| OLD | NEW |