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/x/touch_factory_x11.h" |
6 | 6 |
7 #include <X11/cursorfont.h> | 7 #include <X11/cursorfont.h> |
8 #include <X11/extensions/XInput.h> | 8 #include <X11/extensions/XInput.h> |
9 #include <X11/extensions/XInput2.h> | 9 #include <X11/extensions/XInput2.h> |
10 #include <X11/extensions/XIproto.h> | 10 #include <X11/extensions/XIproto.h> |
11 | 11 |
12 #include "base/basictypes.h" | 12 #include "base/basictypes.h" |
13 #include "base/command_line.h" | 13 #include "base/command_line.h" |
14 #include "base/compiler_specific.h" | 14 #include "base/compiler_specific.h" |
15 #include "base/logging.h" | 15 #include "base/logging.h" |
16 #include "base/memory/singleton.h" | 16 #include "base/memory/singleton.h" |
17 #include "base/message_loop/message_loop.h" | 17 #include "base/message_loop/message_loop.h" |
18 #include "base/strings/string_number_conversions.h" | 18 #include "base/strings/string_number_conversions.h" |
19 #include "base/strings/string_split.h" | 19 #include "base/strings/string_split.h" |
20 #include "ui/events/event_switches.h" | 20 #include "ui/events/event_switches.h" |
| 21 #include "ui/events/x/device_data_manager.h" |
21 #include "ui/events/x/device_list_cache_x.h" | 22 #include "ui/events/x/device_list_cache_x.h" |
22 #include "ui/gfx/x/x11_types.h" | 23 #include "ui/gfx/x/x11_types.h" |
23 | 24 |
24 namespace ui { | 25 namespace ui { |
25 | 26 |
26 TouchFactory::TouchFactory() | 27 TouchFactory::TouchFactory() |
27 : pointer_device_lookup_(), | 28 : pointer_device_lookup_(), |
28 touch_device_available_(false), | 29 touch_device_available_(false), |
29 touch_events_disabled_(false), | 30 touch_events_disabled_(false), |
30 touch_device_list_(), | 31 touch_device_list_(), |
31 id_generator_(0) { | 32 id_generator_(0) { |
32 #if defined(USE_AURA) | 33 if (!DeviceDataManager::GetInstance()->IsXInput2Available()) |
33 if (!base::MessagePumpForUI::HasXInput2()) | |
34 return; | 34 return; |
35 #endif | |
36 | 35 |
37 XDisplay* display = gfx::GetXDisplay(); | 36 XDisplay* display = gfx::GetXDisplay(); |
38 UpdateDeviceList(display); | 37 UpdateDeviceList(display); |
39 | 38 |
40 CommandLine* cmdline = CommandLine::ForCurrentProcess(); | 39 CommandLine* cmdline = CommandLine::ForCurrentProcess(); |
41 touch_events_disabled_ = cmdline->HasSwitch(switches::kTouchEvents) && | 40 touch_events_disabled_ = cmdline->HasSwitch(switches::kTouchEvents) && |
42 cmdline->GetSwitchValueASCII(switches::kTouchEvents) == | 41 cmdline->GetSwitchValueASCII(switches::kTouchEvents) == |
43 switches::kTouchEventsDisabled; | 42 switches::kTouchEventsDisabled; |
44 } | 43 } |
45 | 44 |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
94 Atom xi_touchscreen = XInternAtom(display, XI_TOUCHSCREEN, false); | 93 Atom xi_touchscreen = XInternAtom(display, XI_TOUCHSCREEN, false); |
95 for (int i = 0; i < dev_list.count; i++) { | 94 for (int i = 0; i < dev_list.count; i++) { |
96 if (dev_list[i].type == xi_touchscreen) { | 95 if (dev_list[i].type == xi_touchscreen) { |
97 touch_device_lookup_[dev_list[i].id] = true; | 96 touch_device_lookup_[dev_list[i].id] = true; |
98 touch_device_list_[dev_list[i].id] = false; | 97 touch_device_list_[dev_list[i].id] = false; |
99 touch_device_available_ = true; | 98 touch_device_available_ = true; |
100 } | 99 } |
101 } | 100 } |
102 #endif | 101 #endif |
103 | 102 |
| 103 if (!DeviceDataManager::GetInstance()->IsXInput2Available()) |
| 104 return; |
| 105 |
104 // Instead of asking X for the list of devices all the time, let's maintain a | 106 // Instead of asking X for the list of devices all the time, let's maintain a |
105 // list of pointer devices we care about. | 107 // list of pointer devices we care about. |
106 // It should not be necessary to select for slave devices. XInput2 provides | 108 // It should not be necessary to select for slave devices. XInput2 provides |
107 // enough information to the event callback to decide which slave device | 109 // enough information to the event callback to decide which slave device |
108 // triggered the event, thus decide whether the 'pointer event' is a | 110 // triggered the event, thus decide whether the 'pointer event' is a |
109 // 'mouse event' or a 'touch event'. | 111 // 'mouse event' or a 'touch event'. |
110 // However, on some desktops, some events from a master pointer are | 112 // However, on some desktops, some events from a master pointer are |
111 // not delivered to the client. So we select for slave devices instead. | 113 // not delivered to the client. So we select for slave devices instead. |
112 // If the touch device has 'GrabDevice' set and 'SendCoreEvents' unset (which | 114 // If the touch device has 'GrabDevice' set and 'SendCoreEvents' unset (which |
113 // is possible), then the device is detected as a floating device, and a | 115 // is possible), then the device is detected as a floating device, and a |
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
243 iter != devices.end(); ++iter) { | 245 iter != devices.end(); ++iter) { |
244 DCHECK(*iter < touch_device_lookup_.size()); | 246 DCHECK(*iter < touch_device_lookup_.size()); |
245 touch_device_lookup_[*iter] = true; | 247 touch_device_lookup_[*iter] = true; |
246 touch_device_list_[*iter] = true; | 248 touch_device_list_[*iter] = true; |
247 } | 249 } |
248 touch_device_available_ = true; | 250 touch_device_available_ = true; |
249 touch_events_disabled_ = false; | 251 touch_events_disabled_ = false; |
250 } | 252 } |
251 | 253 |
252 } // namespace ui | 254 } // namespace ui |
OLD | NEW |