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 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
123 | 123 |
124 if (devinfo.use == XIFloatingSlave || devinfo.use == XISlavePointer) { | 124 if (devinfo.use == XIFloatingSlave || devinfo.use == XISlavePointer) { |
125 for (int k = 0; k < devinfo.num_classes; ++k) { | 125 for (int k = 0; k < devinfo.num_classes; ++k) { |
126 XIAnyClassInfo* xiclassinfo = devinfo.classes[k]; | 126 XIAnyClassInfo* xiclassinfo = devinfo.classes[k]; |
127 if (xiclassinfo->type == XITouchClass) { | 127 if (xiclassinfo->type == XITouchClass) { |
128 XITouchClassInfo* tci = | 128 XITouchClassInfo* tci = |
129 reinterpret_cast<XITouchClassInfo*>(xiclassinfo); | 129 reinterpret_cast<XITouchClassInfo*>(xiclassinfo); |
130 // Only care direct touch device (such as touch screen) right now | 130 // Only care direct touch device (such as touch screen) right now |
131 if (tci->mode == XIDirectTouch) | 131 if (tci->mode == XIDirectTouch) |
132 CacheTouchscreenIds(devinfo.deviceid); | 132 CacheTouchscreenIds(devinfo.deviceid); |
| 133 if (devinfo.use == XISlavePointer) { |
| 134 device_master_id_list_[devinfo.deviceid] = devinfo.attachment; |
| 135 // If the slave device is direct touch device, we also set its |
| 136 // master device to be touch device. |
| 137 touch_device_lookup_[devinfo.attachment] = true; |
| 138 touch_device_list_[devinfo.attachment] = true; |
| 139 } |
133 } | 140 } |
134 } | 141 } |
135 } | 142 } |
136 } | 143 } |
137 } | 144 } |
138 | 145 |
139 bool TouchFactory::ShouldProcessXI2Event(XEvent* xev) { | 146 bool TouchFactory::ShouldProcessXI2Event(XEvent* xev) { |
140 DCHECK_EQ(GenericEvent, xev->type); | 147 DCHECK_EQ(GenericEvent, xev->type); |
141 XIEvent* event = static_cast<XIEvent*>(xev->xcookie.data); | 148 XIEvent* event = static_cast<XIEvent*>(xev->xcookie.data); |
142 XIDeviceEvent* xiev = reinterpret_cast<XIDeviceEvent*>(event); | 149 XIDeviceEvent* xiev = reinterpret_cast<XIDeviceEvent*>(event); |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
212 evmask.deviceid = XIAllDevices; | 219 evmask.deviceid = XIAllDevices; |
213 evmask.mask_len = sizeof(mask); | 220 evmask.mask_len = sizeof(mask); |
214 evmask.mask = mask; | 221 evmask.mask = mask; |
215 XISelectEvents(display, window, &evmask, 1); | 222 XISelectEvents(display, window, &evmask, 1); |
216 XFlush(display); | 223 XFlush(display); |
217 } | 224 } |
218 | 225 |
219 void TouchFactory::SetTouchDeviceList(const std::vector<int>& devices) { | 226 void TouchFactory::SetTouchDeviceList(const std::vector<int>& devices) { |
220 touch_device_lookup_.reset(); | 227 touch_device_lookup_.reset(); |
221 touch_device_list_.clear(); | 228 touch_device_list_.clear(); |
222 for (std::vector<int>::const_iterator iter = devices.begin(); | 229 for (int deviceid : devices) { |
223 iter != devices.end(); ++iter) { | 230 DCHECK(IsValidDevice(deviceid)); |
224 DCHECK(IsValidDevice(*iter)); | 231 touch_device_lookup_[deviceid] = true; |
225 touch_device_lookup_[*iter] = true; | 232 touch_device_list_[deviceid] = false; |
226 touch_device_list_[*iter] = false; | 233 if (device_master_id_list_.find(deviceid) != device_master_id_list_.end()) { |
| 234 // When we set the device through the "--touch-devices" flag to slave |
| 235 // touch device, we also set its master device to be touch device. |
| 236 touch_device_lookup_[device_master_id_list_[deviceid]] = true; |
| 237 touch_device_list_[device_master_id_list_[deviceid]] = false; |
| 238 } |
227 } | 239 } |
228 } | 240 } |
229 | 241 |
230 bool TouchFactory::IsValidDevice(int deviceid) const { | 242 bool TouchFactory::IsValidDevice(int deviceid) const { |
231 return (deviceid >= 0) && | 243 return (deviceid >= 0) && |
232 (static_cast<size_t>(deviceid) < touch_device_lookup_.size()); | 244 (static_cast<size_t>(deviceid) < touch_device_lookup_.size()); |
233 } | 245 } |
234 | 246 |
235 bool TouchFactory::IsTouchDevice(int deviceid) const { | 247 bool TouchFactory::IsTouchDevice(int deviceid) const { |
236 return IsValidDevice(deviceid) ? touch_device_lookup_[deviceid] : false; | 248 return IsValidDevice(deviceid) ? touch_device_lookup_[deviceid] : false; |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
301 std::find_if(touchscreens.begin(), touchscreens.end(), | 313 std::find_if(touchscreens.begin(), touchscreens.end(), |
302 [device_id](const TouchscreenDevice& touchscreen) { | 314 [device_id](const TouchscreenDevice& touchscreen) { |
303 return touchscreen.id == device_id; | 315 return touchscreen.id == device_id; |
304 }); | 316 }); |
305 // Internal displays will have a vid and pid of 0. Ignore them. | 317 // Internal displays will have a vid and pid of 0. Ignore them. |
306 if (it != touchscreens.end() && it->vendor_id && it->product_id) | 318 if (it != touchscreens.end() && it->vendor_id && it->product_id) |
307 touchscreen_ids_.insert(std::make_pair(it->vendor_id, it->product_id)); | 319 touchscreen_ids_.insert(std::make_pair(it->vendor_id, it->product_id)); |
308 } | 320 } |
309 | 321 |
310 } // namespace ui | 322 } // namespace ui |
OLD | NEW |