Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(73)

Side by Side Diff: ui/events/devices/x11/touch_factory_x11.cc

Issue 1186833005: Fix touch screen on Linux with or without flag --touch-devices (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « ui/events/devices/x11/touch_factory_x11.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
96 // not delivered to the client. So we select for slave devices instead. 96 // not delivered to the client. So we select for slave devices instead.
97 // If the touch device has 'GrabDevice' set and 'SendCoreEvents' unset (which 97 // If the touch device has 'GrabDevice' set and 'SendCoreEvents' unset (which
98 // is possible), then the device is detected as a floating device, and a 98 // is possible), then the device is detected as a floating device, and a
99 // floating device is not connected to a master device. So it is necessary to 99 // floating device is not connected to a master device. So it is necessary to
100 // also select on the floating devices. 100 // also select on the floating devices.
101 pointer_device_lookup_.reset(); 101 pointer_device_lookup_.reset();
102 const XIDeviceList& xi_dev_list = 102 const XIDeviceList& xi_dev_list =
103 DeviceListCacheX11::GetInstance()->GetXI2DeviceList(display); 103 DeviceListCacheX11::GetInstance()->GetXI2DeviceList(display);
104 for (int i = 0; i < xi_dev_list.count; i++) { 104 for (int i = 0; i < xi_dev_list.count; i++) {
105 const XIDeviceInfo& devinfo = xi_dev_list[i]; 105 const XIDeviceInfo& devinfo = xi_dev_list[i];
106 device_master_id_list_[devinfo.deviceid] = devinfo.attachment;
sadrul 2015/06/17 03:33:52 We should do this only for XISlavePointer device?
lanwei 2015/06/17 17:59:15 Done.
106 if (devinfo.use == XIFloatingSlave || devinfo.use == XIMasterPointer) { 107 if (devinfo.use == XIFloatingSlave || devinfo.use == XIMasterPointer) {
107 for (int k = 0; k < devinfo.num_classes; ++k) { 108 for (int k = 0; k < devinfo.num_classes; ++k) {
108 XIAnyClassInfo* xiclassinfo = devinfo.classes[k]; 109 XIAnyClassInfo* xiclassinfo = devinfo.classes[k];
109 if (xiclassinfo->type == XITouchClass) { 110 if (xiclassinfo->type == XITouchClass) {
110 XITouchClassInfo* tci = 111 XITouchClassInfo* tci =
111 reinterpret_cast<XITouchClassInfo*>(xiclassinfo); 112 reinterpret_cast<XITouchClassInfo*>(xiclassinfo);
112 // Only care direct touch device (such as touch screen) right now 113 // Only care direct touch device (such as touch screen) right now
113 if (tci->mode == XIDirectTouch) { 114 if (tci->mode == XIDirectTouch) {
114 touch_device_lookup_[devinfo.deviceid] = true; 115 touch_device_lookup_[devinfo.deviceid] = true;
115 touch_device_list_[devinfo.deviceid] = true; 116 touch_device_list_[devinfo.deviceid] = true;
116 } 117 }
117 } 118 }
118 } 119 }
119 pointer_device_lookup_[devinfo.deviceid] = true; 120 pointer_device_lookup_[devinfo.deviceid] = true;
120 } else if (devinfo.use == XIMasterKeyboard) { 121 } else if (devinfo.use == XIMasterKeyboard) {
121 virtual_core_keyboard_device_ = devinfo.deviceid; 122 virtual_core_keyboard_device_ = devinfo.deviceid;
122 } 123 }
123 124
124 if (devinfo.use == XIFloatingSlave || devinfo.use == XISlavePointer) { 125 if (devinfo.use == XIFloatingSlave || devinfo.use == XISlavePointer) {
125 for (int k = 0; k < devinfo.num_classes; ++k) { 126 for (int k = 0; k < devinfo.num_classes; ++k) {
126 XIAnyClassInfo* xiclassinfo = devinfo.classes[k]; 127 XIAnyClassInfo* xiclassinfo = devinfo.classes[k];
127 if (xiclassinfo->type == XITouchClass) { 128 if (xiclassinfo->type == XITouchClass) {
128 XITouchClassInfo* tci = 129 XITouchClassInfo* tci =
129 reinterpret_cast<XITouchClassInfo*>(xiclassinfo); 130 reinterpret_cast<XITouchClassInfo*>(xiclassinfo);
130 // Only care direct touch device (such as touch screen) right now 131 // Only care direct touch device (such as touch screen) right now
131 if (tci->mode == XIDirectTouch) 132 if (tci->mode == XIDirectTouch)
132 CacheTouchscreenIds(devinfo.deviceid); 133 CacheTouchscreenIds(devinfo.deviceid);
134 // If the device is direct touch device, we also set its master
135 // device to be touch device.
136 touch_device_lookup_[device_master_id_list_[devinfo.deviceid]] =
137 true;
138 touch_device_list_[device_master_id_list_[devinfo.deviceid]] = true;
sadrul 2015/06/17 03:33:52 We should do this only for XISlavePointer? Also,
lanwei 2015/06/17 17:59:15 Done.
133 } 139 }
134 } 140 }
135 } 141 }
136 } 142 }
137 } 143 }
138 144
139 bool TouchFactory::ShouldProcessXI2Event(XEvent* xev) { 145 bool TouchFactory::ShouldProcessXI2Event(XEvent* xev) {
140 DCHECK_EQ(GenericEvent, xev->type); 146 DCHECK_EQ(GenericEvent, xev->type);
141 XIEvent* event = static_cast<XIEvent*>(xev->xcookie.data); 147 XIEvent* event = static_cast<XIEvent*>(xev->xcookie.data);
142 XIDeviceEvent* xiev = reinterpret_cast<XIDeviceEvent*>(event); 148 XIDeviceEvent* xiev = reinterpret_cast<XIDeviceEvent*>(event);
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
212 evmask.deviceid = XIAllDevices; 218 evmask.deviceid = XIAllDevices;
213 evmask.mask_len = sizeof(mask); 219 evmask.mask_len = sizeof(mask);
214 evmask.mask = mask; 220 evmask.mask = mask;
215 XISelectEvents(display, window, &evmask, 1); 221 XISelectEvents(display, window, &evmask, 1);
216 XFlush(display); 222 XFlush(display);
217 } 223 }
218 224
219 void TouchFactory::SetTouchDeviceList(const std::vector<int>& devices) { 225 void TouchFactory::SetTouchDeviceList(const std::vector<int>& devices) {
220 touch_device_lookup_.reset(); 226 touch_device_lookup_.reset();
221 touch_device_list_.clear(); 227 touch_device_list_.clear();
222 for (std::vector<int>::const_iterator iter = devices.begin(); 228 for (std::vector<int>::const_iterator iter = devices.begin();
sadrul 2015/06/17 03:33:52 Since you are here: can you change this to: for
lanwei 2015/06/17 17:59:15 Done.
223 iter != devices.end(); ++iter) { 229 iter != devices.end(); ++iter) {
224 DCHECK(IsValidDevice(*iter)); 230 DCHECK(IsValidDevice(*iter));
225 touch_device_lookup_[*iter] = true; 231 touch_device_lookup_[*iter] = true;
226 touch_device_list_[*iter] = false; 232 touch_device_list_[*iter] = false;
233 // When we set the device through the "--touch-devices" flag to touch
234 // device, we also set its master device to be touch device.
235 touch_device_lookup_[device_master_id_list_[*iter]] = true;
sadrul 2015/06/17 03:33:52 Check to see if |*iter| exists in |device_master_i
lanwei 2015/06/17 17:59:15 Done.
236 touch_device_list_[device_master_id_list_[*iter]] = false;
227 } 237 }
228 } 238 }
229 239
230 bool TouchFactory::IsValidDevice(int deviceid) const { 240 bool TouchFactory::IsValidDevice(int deviceid) const {
231 return (deviceid >= 0) && 241 return (deviceid >= 0) &&
232 (static_cast<size_t>(deviceid) < touch_device_lookup_.size()); 242 (static_cast<size_t>(deviceid) < touch_device_lookup_.size());
233 } 243 }
234 244
235 bool TouchFactory::IsTouchDevice(int deviceid) const { 245 bool TouchFactory::IsTouchDevice(int deviceid) const {
236 return IsValidDevice(deviceid) ? touch_device_lookup_[deviceid] : false; 246 return IsValidDevice(deviceid) ? touch_device_lookup_[deviceid] : false;
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
301 std::find_if(touchscreens.begin(), touchscreens.end(), 311 std::find_if(touchscreens.begin(), touchscreens.end(),
302 [device_id](const TouchscreenDevice& touchscreen) { 312 [device_id](const TouchscreenDevice& touchscreen) {
303 return touchscreen.id == device_id; 313 return touchscreen.id == device_id;
304 }); 314 });
305 // Internal displays will have a vid and pid of 0. Ignore them. 315 // Internal displays will have a vid and pid of 0. Ignore them.
306 if (it != touchscreens.end() && it->vendor_id && it->product_id) 316 if (it != touchscreens.end() && it->vendor_id && it->product_id)
307 touchscreen_ids_.insert(std::make_pair(it->vendor_id, it->product_id)); 317 touchscreen_ids_.insert(std::make_pair(it->vendor_id, it->product_id));
308 } 318 }
309 319
310 } // namespace ui 320 } // namespace ui
OLDNEW
« no previous file with comments | « ui/events/devices/x11/touch_factory_x11.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698