OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/device_data_manager_x11.h" | 5 #include "ui/events/x/device_data_manager_x11.h" |
6 | 6 |
7 #include <X11/extensions/XInput.h> | 7 #include <X11/extensions/XInput.h> |
8 #include <X11/extensions/XInput2.h> | 8 #include <X11/extensions/XInput2.h> |
9 #include <X11/Xlib.h> | 9 #include <X11/Xlib.h> |
10 | 10 |
11 #include "base/logging.h" | 11 #include "base/logging.h" |
12 #include "base/memory/singleton.h" | 12 #include "base/memory/singleton.h" |
13 #include "base/sys_info.h" | 13 #include "base/sys_info.h" |
14 #include "ui/events/event_constants.h" | 14 #include "ui/events/event_constants.h" |
15 #include "ui/events/event_switches.h" | 15 #include "ui/events/event_switches.h" |
| 16 #include "ui/events/input_device_event_observer.h" |
16 #include "ui/events/x/device_list_cache_x.h" | 17 #include "ui/events/x/device_list_cache_x.h" |
17 #include "ui/events/x/touch_factory_x11.h" | 18 #include "ui/events/x/touch_factory_x11.h" |
18 #include "ui/gfx/display.h" | 19 #include "ui/gfx/display.h" |
19 #include "ui/gfx/point3_f.h" | 20 #include "ui/gfx/point3_f.h" |
20 #include "ui/gfx/x/x11_types.h" | 21 #include "ui/gfx/x/x11_types.h" |
21 | 22 |
22 // XIScrollClass was introduced in XI 2.1 so we need to define it here | 23 // XIScrollClass was introduced in XI 2.1 so we need to define it here |
23 // for backward-compatibility with older versions of XInput. | 24 // for backward-compatibility with older versions of XInput. |
24 #if !defined(XIScrollClass) | 25 #if !defined(XIScrollClass) |
25 #define XIScrollClass 3 | 26 #define XIScrollClass 3 |
(...skipping 230 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
256 if (IsCMTDataType(data_type)) | 257 if (IsCMTDataType(data_type)) |
257 possible_cmt = true; | 258 possible_cmt = true; |
258 break; | 259 break; |
259 } | 260 } |
260 } | 261 } |
261 } | 262 } |
262 | 263 |
263 if (possible_cmt && !not_cmt) | 264 if (possible_cmt && !not_cmt) |
264 cmt_devices_[deviceid] = true; | 265 cmt_devices_[deviceid] = true; |
265 } | 266 } |
| 267 |
| 268 FOR_EACH_OBSERVER(InputDeviceEventObserver, |
| 269 observers_, |
| 270 OnInputDeviceConfigurationChanged()); |
266 } | 271 } |
267 | 272 |
268 bool DeviceDataManagerX11::GetSlotNumber(const XIDeviceEvent* xiev, int* slot) { | 273 bool DeviceDataManagerX11::GetSlotNumber(const XIDeviceEvent* xiev, int* slot) { |
269 #if defined(USE_XI2_MT) | 274 #if defined(USE_XI2_MT) |
270 ui::TouchFactory* factory = ui::TouchFactory::GetInstance(); | 275 ui::TouchFactory* factory = ui::TouchFactory::GetInstance(); |
271 if (!factory->IsMultiTouchDevice(xiev->sourceid)) { | 276 if (!factory->IsMultiTouchDevice(xiev->sourceid)) { |
272 *slot = 0; | 277 *slot = 0; |
273 return true; | 278 return true; |
274 } | 279 } |
275 return factory->QuerySlotForTrackingID(xiev->detail, slot); | 280 return factory->QuerySlotForTrackingID(xiev->detail, slot); |
(...skipping 376 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
652 #if defined(OS_CHROMEOS) && defined(USE_XI2_MT) | 657 #if defined(OS_CHROMEOS) && defined(USE_XI2_MT) |
653 int64 touch_display_id = GetDisplayForTouchDevice(touch_device_id); | 658 int64 touch_display_id = GetDisplayForTouchDevice(touch_device_id); |
654 if (base::SysInfo::IsRunningOnChromeOS() && | 659 if (base::SysInfo::IsRunningOnChromeOS() && |
655 touch_display_id == gfx::Display::InternalDisplayId()) { | 660 touch_display_id == gfx::Display::InternalDisplayId()) { |
656 return true; | 661 return true; |
657 } | 662 } |
658 #endif // defined(OS_CHROMEOS) && defined(USE_XI2_MT) | 663 #endif // defined(OS_CHROMEOS) && defined(USE_XI2_MT) |
659 return false; | 664 return false; |
660 } | 665 } |
661 | 666 |
| 667 std::vector<TouchscreenDevice> DeviceDataManagerX11::GetTouchscreenDevices() { |
| 668 std::vector<TouchscreenDevice> devices; |
| 669 Display* display = gfx::GetXDisplay(); |
| 670 |
| 671 Atom valuator_x = XInternAtom(display, "Abs MT Position X", False); |
| 672 Atom valuator_y = XInternAtom(display, "Abs MT Position Y", False); |
| 673 if (valuator_x == None || valuator_y == None) |
| 674 return devices; |
| 675 |
| 676 XIDeviceList native_devices = |
| 677 DeviceListCacheX::GetInstance()->GetXI2DeviceList(display); |
| 678 for (int i = 0; i < native_devices.count; ++i) { |
| 679 if (!native_devices[i].enabled || native_devices[i].use != XIFloatingSlave) |
| 680 continue; // Assume all touchscreens are floating slaves |
| 681 |
| 682 double width = -1.0; |
| 683 double height = -1.0; |
| 684 bool is_direct_touch = false; |
| 685 |
| 686 for (int j = 0; j < native_devices[i].num_classes; j++) { |
| 687 XIAnyClassInfo* class_info = native_devices[i].classes[j]; |
| 688 |
| 689 if (class_info->type == XIValuatorClass) { |
| 690 XIValuatorClassInfo* valuator_info = |
| 691 reinterpret_cast<XIValuatorClassInfo*>(class_info); |
| 692 |
| 693 if (valuator_x == valuator_info->label) { |
| 694 // Ignore X axis valuator with unexpected properties |
| 695 if (valuator_info->number == 0 && valuator_info->mode == Absolute && |
| 696 valuator_info->min == 0.0) { |
| 697 width = valuator_info->max; |
| 698 } |
| 699 } else if (valuator_y == valuator_info->label) { |
| 700 // Ignore Y axis valuator with unexpected properties |
| 701 if (valuator_info->number == 1 && valuator_info->mode == Absolute && |
| 702 valuator_info->min == 0.0) { |
| 703 height = valuator_info->max; |
| 704 } |
| 705 } |
| 706 } |
| 707 #if defined(USE_XI2_MT) |
| 708 if (class_info->type == XITouchClass) { |
| 709 XITouchClassInfo* touch_info = |
| 710 reinterpret_cast<XITouchClassInfo*>(class_info); |
| 711 is_direct_touch = touch_info->mode == XIDirectTouch; |
| 712 } |
| 713 #endif |
| 714 } |
| 715 |
| 716 // Touchscreens should have absolute X and Y axes, and be direct touch |
| 717 // devices. |
| 718 if (width > 0.0 && height > 0.0 && is_direct_touch) { |
| 719 devices.push_back(TouchscreenDevice(native_devices[i].deviceid, |
| 720 gfx::Size(width, height))); |
| 721 } |
| 722 } |
| 723 |
| 724 return devices; |
| 725 } |
| 726 |
662 } // namespace ui | 727 } // namespace ui |
OLD | NEW |