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.h" | 5 #include "ui/events/x/device_data_manager.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 "ui/events/event_constants.h" | 14 #include "ui/events/event_constants.h" |
| 15 #include "ui/events/event_switches.h" |
14 #include "ui/events/x/device_list_cache_x.h" | 16 #include "ui/events/x/device_list_cache_x.h" |
15 #include "ui/events/x/touch_factory_x11.h" | 17 #include "ui/events/x/touch_factory_x11.h" |
| 18 #include "ui/gfx/display.h" |
| 19 #include "ui/gfx/point3_f.h" |
16 #include "ui/gfx/x/x11_types.h" | 20 #include "ui/gfx/x/x11_types.h" |
17 | 21 |
18 // XIScrollClass was introduced in XI 2.1 so we need to define it here | 22 // XIScrollClass was introduced in XI 2.1 so we need to define it here |
19 // for backward-compatibility with older versions of XInput. | 23 // for backward-compatibility with older versions of XInput. |
20 #if !defined(XIScrollClass) | 24 #if !defined(XIScrollClass) |
21 #define XIScrollClass 3 | 25 #define XIScrollClass 3 |
22 #endif | 26 #endif |
23 | 27 |
24 // Multi-touch support was introduced in XI 2.2. Add XI event types here | 28 // Multi-touch support was introduced in XI 2.2. Add XI event types here |
25 // for backward-compatibility with older versions of XInput. | 29 // for backward-compatibility with older versions of XInput. |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
113 : xi_opcode_(-1), | 117 : xi_opcode_(-1), |
114 atom_cache_(gfx::GetXDisplay(), kCachedAtoms), | 118 atom_cache_(gfx::GetXDisplay(), kCachedAtoms), |
115 button_map_count_(0) { | 119 button_map_count_(0) { |
116 CHECK(gfx::GetXDisplay()); | 120 CHECK(gfx::GetXDisplay()); |
117 InitializeXInputInternal(); | 121 InitializeXInputInternal(); |
118 | 122 |
119 // Make sure the sizes of enum and kCachedAtoms are aligned. | 123 // Make sure the sizes of enum and kCachedAtoms are aligned. |
120 CHECK(arraysize(kCachedAtoms) == static_cast<size_t>(DT_LAST_ENTRY) + 1); | 124 CHECK(arraysize(kCachedAtoms) == static_cast<size_t>(DT_LAST_ENTRY) + 1); |
121 UpdateDeviceList(gfx::GetXDisplay()); | 125 UpdateDeviceList(gfx::GetXDisplay()); |
122 UpdateButtonMap(); | 126 UpdateButtonMap(); |
| 127 for (int i = 0; i < kMaxDeviceNum; i++) |
| 128 touch_device_to_display_map_[i] = gfx::Display::kInvalidDisplayID; |
123 } | 129 } |
124 | 130 |
125 DeviceDataManager::~DeviceDataManager() { | 131 DeviceDataManager::~DeviceDataManager() { |
126 } | 132 } |
127 | 133 |
128 bool DeviceDataManager::InitializeXInputInternal() { | 134 bool DeviceDataManager::InitializeXInputInternal() { |
129 // Check if XInput is available on the system. | 135 // Check if XInput is available on the system. |
130 xi_opcode_ = -1; | 136 xi_opcode_ = -1; |
131 int opcode, event, error; | 137 int opcode, event, error; |
132 if (!XQueryExtension( | 138 if (!XQueryExtension( |
(...skipping 494 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
627 last_seen_valuator_[deviceid][j].resize(DT_LAST_ENTRY, 0); | 633 last_seen_valuator_[deviceid][j].resize(DT_LAST_ENTRY, 0); |
628 for (int j = start_valuator; j <= end_valuator; ++j) { | 634 for (int j = start_valuator; j <= end_valuator; ++j) { |
629 valuator_lookup_[deviceid][j] = valuator_count_[deviceid]; | 635 valuator_lookup_[deviceid][j] = valuator_count_[deviceid]; |
630 data_type_lookup_[deviceid][valuator_count_[deviceid]] = j; | 636 data_type_lookup_[deviceid][valuator_count_[deviceid]] = j; |
631 valuator_min_[deviceid][j] = min_value; | 637 valuator_min_[deviceid][j] = min_value; |
632 valuator_max_[deviceid][j] = max_value; | 638 valuator_max_[deviceid][j] = max_value; |
633 valuator_count_[deviceid]++; | 639 valuator_count_[deviceid]++; |
634 } | 640 } |
635 } | 641 } |
636 | 642 |
| 643 bool DeviceDataManager::TouchEventNeedsCalibrate(int touch_device_id) const { |
| 644 #if defined(OS_CHROMEOS) && defined(USE_XI2_MT) |
| 645 int64 touch_display_id = GetDisplayForTouchDevice(touch_device_id); |
| 646 if (base::SysInfo::IsRunningOnChromeOS() && |
| 647 touch_display_id == gfx::Display::InternalDisplayId()) { |
| 648 return true; |
| 649 } |
| 650 #endif // defined(OS_CHROMEOS) && defined(USE_XI2_MT) |
| 651 return false; |
| 652 } |
| 653 |
| 654 void DeviceDataManager::ClearTouchTransformerRecord() { |
| 655 for (int i = 0; i < kMaxDeviceNum; i++) { |
| 656 touch_device_transformer_map_[i] = gfx::Transform(); |
| 657 touch_device_to_display_map_[i] = gfx::Display::kInvalidDisplayID; |
| 658 } |
| 659 } |
| 660 |
| 661 bool DeviceDataManager::IsTouchDeviceIdValid(int touch_device_id) const { |
| 662 return (touch_device_id > 0 && touch_device_id < kMaxDeviceNum); |
| 663 } |
| 664 |
| 665 void DeviceDataManager::UpdateTouchInfoForDisplay( |
| 666 int64 display_id, |
| 667 int touch_device_id, |
| 668 const gfx::Transform& touch_transformer) { |
| 669 if (IsTouchDeviceIdValid(touch_device_id)) { |
| 670 touch_device_to_display_map_[touch_device_id] = display_id; |
| 671 touch_device_transformer_map_[touch_device_id] = touch_transformer; |
| 672 } |
| 673 } |
| 674 |
| 675 void DeviceDataManager::ApplyTouchTransformer(int touch_device_id, |
| 676 float* x, float* y) { |
| 677 if (IsTouchDeviceIdValid(touch_device_id)) { |
| 678 gfx::Point3F point(*x, *y, 0.0); |
| 679 const gfx::Transform& trans = |
| 680 touch_device_transformer_map_[touch_device_id]; |
| 681 trans.TransformPoint(&point); |
| 682 *x = point.x(); |
| 683 *y = point.y(); |
| 684 } |
| 685 } |
| 686 |
| 687 int64 DeviceDataManager::GetDisplayForTouchDevice(int touch_device_id) const { |
| 688 if (IsTouchDeviceIdValid(touch_device_id)) |
| 689 return touch_device_to_display_map_[touch_device_id]; |
| 690 return gfx::Display::kInvalidDisplayID; |
| 691 } |
| 692 |
637 } // namespace ui | 693 } // namespace ui |
OLD | NEW |