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/x/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> |
11 #include <X11/extensions/XIproto.h> | 11 #include <X11/extensions/XIproto.h> |
12 | 12 |
13 #include "base/basictypes.h" | 13 #include "base/basictypes.h" |
14 #include "base/command_line.h" | 14 #include "base/command_line.h" |
15 #include "base/compiler_specific.h" | 15 #include "base/compiler_specific.h" |
16 #include "base/logging.h" | 16 #include "base/logging.h" |
17 #include "base/memory/singleton.h" | 17 #include "base/memory/singleton.h" |
18 #include "base/message_loop/message_loop.h" | 18 #include "base/message_loop/message_loop.h" |
19 #include "base/strings/string_number_conversions.h" | 19 #include "base/strings/string_number_conversions.h" |
20 #include "base/strings/string_split.h" | 20 #include "base/strings/string_split.h" |
21 #include "base/sys_info.h" | 21 #include "base/sys_info.h" |
| 22 #include "ui/events/devices/x11/device_data_manager_x11.h" |
| 23 #include "ui/events/devices/x11/device_list_cache_x11.h" |
22 #include "ui/events/event_switches.h" | 24 #include "ui/events/event_switches.h" |
23 #include "ui/events/x/device_data_manager_x11.h" | |
24 #include "ui/events/x/device_list_cache_x.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), | 33 max_touch_points_(-1), |
34 virtual_core_keyboard_device_(-1), | 34 virtual_core_keyboard_device_(-1), |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
86 max_touch_points_ = -1; | 86 max_touch_points_ = -1; |
87 | 87 |
88 #if !defined(USE_XI2_MT) | 88 #if !defined(USE_XI2_MT) |
89 // NOTE: The new API for retrieving the list of devices (XIQueryDevice) does | 89 // NOTE: The new API for retrieving the list of devices (XIQueryDevice) does |
90 // not provide enough information to detect a touch device. As a result, the | 90 // not provide enough information to detect a touch device. As a result, the |
91 // old version of query function (XListInputDevices) is used instead. | 91 // old version of query function (XListInputDevices) is used instead. |
92 // If XInput2 is not supported, this will return null (with count of -1) so | 92 // If XInput2 is not supported, this will return null (with count of -1) so |
93 // we assume there cannot be any touch devices. | 93 // we assume there cannot be any touch devices. |
94 // With XI2.1 or older, we allow only single touch devices. | 94 // With XI2.1 or older, we allow only single touch devices. |
95 XDeviceList dev_list = | 95 XDeviceList dev_list = |
96 DeviceListCacheX::GetInstance()->GetXDeviceList(display); | 96 DeviceListCacheX11::GetInstance()->GetXDeviceList(display); |
97 Atom xi_touchscreen = XInternAtom(display, XI_TOUCHSCREEN, false); | 97 Atom xi_touchscreen = XInternAtom(display, XI_TOUCHSCREEN, false); |
98 for (int i = 0; i < dev_list.count; i++) { | 98 for (int i = 0; i < dev_list.count; i++) { |
99 if (dev_list[i].type == xi_touchscreen) { | 99 if (dev_list[i].type == xi_touchscreen) { |
100 touch_device_lookup_[dev_list[i].id] = true; | 100 touch_device_lookup_[dev_list[i].id] = true; |
101 touch_device_list_[dev_list[i].id] = false; | 101 touch_device_list_[dev_list[i].id] = false; |
102 } | 102 } |
103 } | 103 } |
104 #endif | 104 #endif |
105 | 105 |
106 if (!DeviceDataManagerX11::GetInstance()->IsXInput2Available()) | 106 if (!DeviceDataManagerX11::GetInstance()->IsXInput2Available()) |
107 return; | 107 return; |
108 | 108 |
109 // Instead of asking X for the list of devices all the time, let's maintain a | 109 // Instead of asking X for the list of devices all the time, let's maintain a |
110 // list of pointer devices we care about. | 110 // list of pointer devices we care about. |
111 // It should not be necessary to select for slave devices. XInput2 provides | 111 // It should not be necessary to select for slave devices. XInput2 provides |
112 // enough information to the event callback to decide which slave device | 112 // enough information to the event callback to decide which slave device |
113 // triggered the event, thus decide whether the 'pointer event' is a | 113 // triggered the event, thus decide whether the 'pointer event' is a |
114 // 'mouse event' or a 'touch event'. | 114 // 'mouse event' or a 'touch event'. |
115 // However, on some desktops, some events from a master pointer are | 115 // However, on some desktops, some events from a master pointer are |
116 // not delivered to the client. So we select for slave devices instead. | 116 // not delivered to the client. So we select for slave devices instead. |
117 // If the touch device has 'GrabDevice' set and 'SendCoreEvents' unset (which | 117 // If the touch device has 'GrabDevice' set and 'SendCoreEvents' unset (which |
118 // is possible), then the device is detected as a floating device, and a | 118 // is possible), then the device is detected as a floating device, and a |
119 // floating device is not connected to a master device. So it is necessary to | 119 // floating device is not connected to a master device. So it is necessary to |
120 // also select on the floating devices. | 120 // also select on the floating devices. |
121 pointer_device_lookup_.reset(); | 121 pointer_device_lookup_.reset(); |
122 XIDeviceList xi_dev_list = | 122 XIDeviceList xi_dev_list = |
123 DeviceListCacheX::GetInstance()->GetXI2DeviceList(display); | 123 DeviceListCacheX11::GetInstance()->GetXI2DeviceList(display); |
124 for (int i = 0; i < xi_dev_list.count; i++) { | 124 for (int i = 0; i < xi_dev_list.count; i++) { |
125 XIDeviceInfo* devinfo = xi_dev_list.devices + i; | 125 XIDeviceInfo* devinfo = xi_dev_list.devices + i; |
126 if (devinfo->use == XIFloatingSlave || devinfo->use == XIMasterPointer) { | 126 if (devinfo->use == XIFloatingSlave || devinfo->use == XIMasterPointer) { |
127 #if defined(USE_XI2_MT) | 127 #if defined(USE_XI2_MT) |
128 for (int k = 0; k < devinfo->num_classes; ++k) { | 128 for (int k = 0; k < devinfo->num_classes; ++k) { |
129 XIAnyClassInfo* xiclassinfo = devinfo->classes[k]; | 129 XIAnyClassInfo* xiclassinfo = devinfo->classes[k]; |
130 if (xiclassinfo->type == XITouchClass) { | 130 if (xiclassinfo->type == XITouchClass) { |
131 XITouchClassInfo* tci = | 131 XITouchClassInfo* tci = |
132 reinterpret_cast<XITouchClassInfo*>(xiclassinfo); | 132 reinterpret_cast<XITouchClassInfo*>(xiclassinfo); |
133 // Only care direct touch device (such as touch screen) right now | 133 // Only care direct touch device (such as touch screen) right now |
(...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
346 if (ptr[0] || ptr[1]) | 346 if (ptr[0] || ptr[1]) |
347 touchscreen_ids_.insert(std::make_pair(ptr[0], ptr[1])); | 347 touchscreen_ids_.insert(std::make_pair(ptr[0], ptr[1])); |
348 } | 348 } |
349 XFree(prop_return); | 349 XFree(prop_return); |
350 } | 350 } |
351 | 351 |
352 XCloseDevice(display, device); | 352 XCloseDevice(display, device); |
353 } | 353 } |
354 | 354 |
355 } // namespace ui | 355 } // namespace ui |
OLD | NEW |