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/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 14 matching lines...) Expand all Loading... |
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_device_available_(false), | 31 touch_device_available_(false), |
32 touch_events_disabled_(false), | 32 touch_events_disabled_(false), |
33 touch_device_list_(), | 33 touch_device_list_(), |
34 max_touch_points_(-1), | 34 max_touch_points_(-1), |
| 35 virtual_core_keyboard_device_(-1), |
35 id_generator_(0) { | 36 id_generator_(0) { |
36 if (!DeviceDataManagerX11::GetInstance()->IsXInput2Available()) | 37 if (!DeviceDataManagerX11::GetInstance()->IsXInput2Available()) |
37 return; | 38 return; |
38 | 39 |
39 XDisplay* display = gfx::GetXDisplay(); | 40 XDisplay* display = gfx::GetXDisplay(); |
40 UpdateDeviceList(display); | 41 UpdateDeviceList(display); |
41 | 42 |
42 CommandLine* cmdline = CommandLine::ForCurrentProcess(); | 43 CommandLine* cmdline = CommandLine::ForCurrentProcess(); |
43 touch_events_disabled_ = cmdline->HasSwitch(switches::kTouchEvents) && | 44 touch_events_disabled_ = cmdline->HasSwitch(switches::kTouchEvents) && |
44 cmdline->GetSwitchValueASCII(switches::kTouchEvents) == | 45 cmdline->GetSwitchValueASCII(switches::kTouchEvents) == |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
137 touch_device_lookup_[devinfo->deviceid] = true; | 138 touch_device_lookup_[devinfo->deviceid] = true; |
138 touch_device_list_[devinfo->deviceid] = true; | 139 touch_device_list_[devinfo->deviceid] = true; |
139 touch_device_available_ = true; | 140 touch_device_available_ = true; |
140 if (tci->num_touches > 0 && tci->num_touches > max_touch_points_) | 141 if (tci->num_touches > 0 && tci->num_touches > max_touch_points_) |
141 max_touch_points_ = tci->num_touches; | 142 max_touch_points_ = tci->num_touches; |
142 } | 143 } |
143 } | 144 } |
144 } | 145 } |
145 #endif | 146 #endif |
146 pointer_device_lookup_[devinfo->deviceid] = true; | 147 pointer_device_lookup_[devinfo->deviceid] = true; |
| 148 } else if (devinfo->use == XIMasterKeyboard) { |
| 149 virtual_core_keyboard_device_ = devinfo->deviceid; |
147 } | 150 } |
148 | 151 |
149 #if defined(USE_XI2_MT) | 152 #if defined(USE_XI2_MT) |
150 if (devinfo->use == XIFloatingSlave || devinfo->use == XISlavePointer) { | 153 if (devinfo->use == XIFloatingSlave || devinfo->use == XISlavePointer) { |
151 for (int k = 0; k < devinfo->num_classes; ++k) { | 154 for (int k = 0; k < devinfo->num_classes; ++k) { |
152 XIAnyClassInfo* xiclassinfo = devinfo->classes[k]; | 155 XIAnyClassInfo* xiclassinfo = devinfo->classes[k]; |
153 if (xiclassinfo->type == XITouchClass) { | 156 if (xiclassinfo->type == XITouchClass) { |
154 XITouchClassInfo* tci = | 157 XITouchClassInfo* tci = |
155 reinterpret_cast<XITouchClassInfo*>(xiclassinfo); | 158 reinterpret_cast<XITouchClassInfo*>(xiclassinfo); |
156 // Only care direct touch device (such as touch screen) right now | 159 // Only care direct touch device (such as touch screen) right now |
(...skipping 11 matching lines...) Expand all Loading... |
168 XIEvent* event = static_cast<XIEvent*>(xev->xcookie.data); | 171 XIEvent* event = static_cast<XIEvent*>(xev->xcookie.data); |
169 XIDeviceEvent* xiev = reinterpret_cast<XIDeviceEvent*>(event); | 172 XIDeviceEvent* xiev = reinterpret_cast<XIDeviceEvent*>(event); |
170 | 173 |
171 #if defined(USE_XI2_MT) | 174 #if defined(USE_XI2_MT) |
172 if (event->evtype == XI_TouchBegin || | 175 if (event->evtype == XI_TouchBegin || |
173 event->evtype == XI_TouchUpdate || | 176 event->evtype == XI_TouchUpdate || |
174 event->evtype == XI_TouchEnd) { | 177 event->evtype == XI_TouchEnd) { |
175 return !touch_events_disabled_ && IsTouchDevice(xiev->deviceid); | 178 return !touch_events_disabled_ && IsTouchDevice(xiev->deviceid); |
176 } | 179 } |
177 #endif | 180 #endif |
178 // Make sure only key-events from the master device are processed. | 181 // Make sure only key-events from the virtual core keyboard are processed. |
179 if (event->evtype == XI_KeyPress || event->evtype == XI_KeyRelease) | 182 if (event->evtype == XI_KeyPress || event->evtype == XI_KeyRelease) { |
180 return xiev->deviceid == xiev->sourceid; | 183 return (virtual_core_keyboard_device_ < 0) || |
| 184 (virtual_core_keyboard_device_ == xiev->deviceid); |
| 185 } |
181 | 186 |
182 if (event->evtype != XI_ButtonPress && | 187 if (event->evtype != XI_ButtonPress && |
183 event->evtype != XI_ButtonRelease && | 188 event->evtype != XI_ButtonRelease && |
184 event->evtype != XI_Motion) | 189 event->evtype != XI_Motion) |
185 return true; | 190 return true; |
186 | 191 |
187 if (!pointer_device_lookup_[xiev->deviceid]) | 192 if (!pointer_device_lookup_[xiev->deviceid]) |
188 return false; | 193 return false; |
189 | 194 |
190 return IsTouchDevice(xiev->deviceid) ? !touch_events_disabled_ : true; | 195 return IsTouchDevice(xiev->deviceid) ? !touch_events_disabled_ : true; |
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
347 if (ptr[0] || ptr[1]) | 352 if (ptr[0] || ptr[1]) |
348 touchscreen_ids_.insert(std::make_pair(ptr[0], ptr[1])); | 353 touchscreen_ids_.insert(std::make_pair(ptr[0], ptr[1])); |
349 } | 354 } |
350 XFree(prop_return); | 355 XFree(prop_return); |
351 } | 356 } |
352 | 357 |
353 XCloseDevice(display, device); | 358 XCloseDevice(display, device); |
354 } | 359 } |
355 | 360 |
356 } // namespace ui | 361 } // namespace ui |
OLD | NEW |