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 12 matching lines...) Expand all Loading... |
23 #include "ui/events/devices/x11/device_list_cache_x11.h" | 23 #include "ui/events/devices/x11/device_list_cache_x11.h" |
24 #include "ui/events/event_switches.h" | 24 #include "ui/events/event_switches.h" |
25 #include "ui/gfx/x/x11_types.h" | 25 #include "ui/gfx/x/x11_types.h" |
26 | 26 |
27 namespace ui { | 27 namespace ui { |
28 | 28 |
29 TouchFactory::TouchFactory() | 29 TouchFactory::TouchFactory() |
30 : pointer_device_lookup_(), | 30 : pointer_device_lookup_(), |
31 touch_events_disabled_(false), | 31 touch_events_disabled_(false), |
32 touch_device_list_(), | 32 touch_device_list_(), |
33 max_touch_points_(-1), | |
34 virtual_core_keyboard_device_(-1), | 33 virtual_core_keyboard_device_(-1), |
35 id_generator_(0) { | 34 id_generator_(0) { |
36 if (!DeviceDataManagerX11::GetInstance()->IsXInput2Available()) | 35 if (!DeviceDataManagerX11::GetInstance()->IsXInput2Available()) |
37 return; | 36 return; |
38 | 37 |
39 XDisplay* display = gfx::GetXDisplay(); | 38 XDisplay* display = gfx::GetXDisplay(); |
40 UpdateDeviceList(display); | 39 UpdateDeviceList(display); |
41 | 40 |
42 base::CommandLine* cmdline = base::CommandLine::ForCurrentProcess(); | 41 base::CommandLine* cmdline = base::CommandLine::ForCurrentProcess(); |
43 touch_events_disabled_ = cmdline->HasSwitch(switches::kTouchEvents) && | 42 touch_events_disabled_ = cmdline->HasSwitch(switches::kTouchEvents) && |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
76 } | 75 } |
77 ui::TouchFactory::GetInstance()->SetTouchDeviceList(device_ids); | 76 ui::TouchFactory::GetInstance()->SetTouchDeviceList(device_ids); |
78 } | 77 } |
79 } | 78 } |
80 | 79 |
81 void TouchFactory::UpdateDeviceList(Display* display) { | 80 void TouchFactory::UpdateDeviceList(Display* display) { |
82 // Detect touch devices. | 81 // Detect touch devices. |
83 touch_device_lookup_.reset(); | 82 touch_device_lookup_.reset(); |
84 touch_device_list_.clear(); | 83 touch_device_list_.clear(); |
85 touchscreen_ids_.clear(); | 84 touchscreen_ids_.clear(); |
86 max_touch_points_ = -1; | |
87 | 85 |
88 // NOTE: The new API for retrieving the list of devices (XIQueryDevice) does | 86 // NOTE: The new API for retrieving the list of devices (XIQueryDevice) does |
89 // not provide enough information to detect a touch device. As a result, the | 87 // not provide enough information to detect a touch device. As a result, the |
90 // old version of query function (XListInputDevices) is used instead. | 88 // old version of query function (XListInputDevices) is used instead. |
91 // If XInput2 is not supported, this will return null (with count of -1) so | 89 // If XInput2 is not supported, this will return null (with count of -1) so |
92 // we assume there cannot be any touch devices. | 90 // we assume there cannot be any touch devices. |
93 // With XI2.1 or older, we allow only single touch devices. | 91 // With XI2.1 or older, we allow only single touch devices. |
94 XDeviceList dev_list = | 92 XDeviceList dev_list = |
95 DeviceListCacheX11::GetInstance()->GetXDeviceList(display); | 93 DeviceListCacheX11::GetInstance()->GetXDeviceList(display); |
96 Atom xi_touchscreen = XInternAtom(display, XI_TOUCHSCREEN, false); | 94 Atom xi_touchscreen = XInternAtom(display, XI_TOUCHSCREEN, false); |
(...skipping 27 matching lines...) Expand all Loading... |
124 if (devinfo->use == XIFloatingSlave || devinfo->use == XIMasterPointer) { | 122 if (devinfo->use == XIFloatingSlave || devinfo->use == XIMasterPointer) { |
125 for (int k = 0; k < devinfo->num_classes; ++k) { | 123 for (int k = 0; k < devinfo->num_classes; ++k) { |
126 XIAnyClassInfo* xiclassinfo = devinfo->classes[k]; | 124 XIAnyClassInfo* xiclassinfo = devinfo->classes[k]; |
127 if (xiclassinfo->type == XITouchClass) { | 125 if (xiclassinfo->type == XITouchClass) { |
128 XITouchClassInfo* tci = | 126 XITouchClassInfo* tci = |
129 reinterpret_cast<XITouchClassInfo*>(xiclassinfo); | 127 reinterpret_cast<XITouchClassInfo*>(xiclassinfo); |
130 // Only care direct touch device (such as touch screen) right now | 128 // Only care direct touch device (such as touch screen) right now |
131 if (tci->mode == XIDirectTouch) { | 129 if (tci->mode == XIDirectTouch) { |
132 touch_device_lookup_[devinfo->deviceid] = true; | 130 touch_device_lookup_[devinfo->deviceid] = true; |
133 touch_device_list_[devinfo->deviceid] = true; | 131 touch_device_list_[devinfo->deviceid] = true; |
134 if (tci->num_touches > 0 && tci->num_touches > max_touch_points_) | |
135 max_touch_points_ = tci->num_touches; | |
136 } | 132 } |
137 } | 133 } |
138 } | 134 } |
139 pointer_device_lookup_[devinfo->deviceid] = true; | 135 pointer_device_lookup_[devinfo->deviceid] = true; |
140 } else if (devinfo->use == XIMasterKeyboard) { | 136 } else if (devinfo->use == XIMasterKeyboard) { |
141 virtual_core_keyboard_device_ = devinfo->deviceid; | 137 virtual_core_keyboard_device_ = devinfo->deviceid; |
142 } | 138 } |
143 | 139 |
144 if (devinfo->use == XIFloatingSlave || devinfo->use == XISlavePointer) { | 140 if (devinfo->use == XIFloatingSlave || devinfo->use == XISlavePointer) { |
145 for (int k = 0; k < devinfo->num_classes; ++k) { | 141 for (int k = 0; k < devinfo->num_classes; ++k) { |
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
261 void TouchFactory::ReleaseSlotForTrackingID(uint32 tracking_id) { | 257 void TouchFactory::ReleaseSlotForTrackingID(uint32 tracking_id) { |
262 tracking_id_refcounts_[tracking_id]--; | 258 tracking_id_refcounts_[tracking_id]--; |
263 if (tracking_id_refcounts_[tracking_id] == 0) | 259 if (tracking_id_refcounts_[tracking_id] == 0) |
264 id_generator_.ReleaseNumber(tracking_id); | 260 id_generator_.ReleaseNumber(tracking_id); |
265 } | 261 } |
266 | 262 |
267 bool TouchFactory::IsTouchDevicePresent() { | 263 bool TouchFactory::IsTouchDevicePresent() { |
268 return !touch_events_disabled_ && touch_device_lookup_.any(); | 264 return !touch_events_disabled_ && touch_device_lookup_.any(); |
269 } | 265 } |
270 | 266 |
271 int TouchFactory::GetMaxTouchPoints() const { | |
272 return max_touch_points_; | |
273 } | |
274 | |
275 void TouchFactory::ResetForTest() { | 267 void TouchFactory::ResetForTest() { |
276 pointer_device_lookup_.reset(); | 268 pointer_device_lookup_.reset(); |
277 touch_device_lookup_.reset(); | 269 touch_device_lookup_.reset(); |
278 touch_events_disabled_ = false; | 270 touch_events_disabled_ = false; |
279 touch_device_list_.clear(); | 271 touch_device_list_.clear(); |
280 touchscreen_ids_.clear(); | 272 touchscreen_ids_.clear(); |
281 tracking_id_refcounts_.clear(); | 273 tracking_id_refcounts_.clear(); |
282 max_touch_points_ = -1; | |
283 id_generator_.ResetForTest(); | 274 id_generator_.ResetForTest(); |
284 } | 275 } |
285 | 276 |
286 void TouchFactory::SetTouchDeviceForTest( | 277 void TouchFactory::SetTouchDeviceForTest( |
287 const std::vector<unsigned int>& devices) { | 278 const std::vector<unsigned int>& devices) { |
288 touch_device_lookup_.reset(); | 279 touch_device_lookup_.reset(); |
289 touch_device_list_.clear(); | 280 touch_device_list_.clear(); |
290 for (std::vector<unsigned int>::const_iterator iter = devices.begin(); | 281 for (std::vector<unsigned int>::const_iterator iter = devices.begin(); |
291 iter != devices.end(); ++iter) { | 282 iter != devices.end(); ++iter) { |
292 DCHECK(*iter < touch_device_lookup_.size()); | 283 DCHECK(*iter < touch_device_lookup_.size()); |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
338 if (ptr[0] || ptr[1]) | 329 if (ptr[0] || ptr[1]) |
339 touchscreen_ids_.insert(std::make_pair(ptr[0], ptr[1])); | 330 touchscreen_ids_.insert(std::make_pair(ptr[0], ptr[1])); |
340 } | 331 } |
341 XFree(prop_return); | 332 XFree(prop_return); |
342 } | 333 } |
343 | 334 |
344 XCloseDevice(display, device); | 335 XCloseDevice(display, device); |
345 } | 336 } |
346 | 337 |
347 } // namespace ui | 338 } // namespace ui |
OLD | NEW |