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 "ui/events/event_constants.h" | 13 #include "ui/events/event_constants.h" |
14 #include "ui/events/x/device_list_cache_x.h" | 14 #include "ui/events/x/device_list_cache_x.h" |
15 #include "ui/events/x/touch_factory_x11.h" | 15 #include "ui/events/x/touch_factory_x11.h" |
16 #include "ui/gfx/display.h" | |
16 #include "ui/gfx/x/x11_types.h" | 17 #include "ui/gfx/x/x11_types.h" |
17 | 18 |
18 // XIScrollClass was introduced in XI 2.1 so we need to define it here | 19 // XIScrollClass was introduced in XI 2.1 so we need to define it here |
19 // for backward-compatibility with older versions of XInput. | 20 // for backward-compatibility with older versions of XInput. |
20 #if !defined(XIScrollClass) | 21 #if !defined(XIScrollClass) |
21 #define XIScrollClass 3 | 22 #define XIScrollClass 3 |
22 #endif | 23 #endif |
23 | 24 |
24 // Multi-touch support was introduced in XI 2.2. Add XI event types here | 25 // Multi-touch support was introduced in XI 2.2. Add XI event types here |
25 // for backward-compatibility with older versions of XInput. | 26 // for backward-compatibility with older versions of XInput. |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
114 xi_opcode_(-1), | 115 xi_opcode_(-1), |
115 atom_cache_(gfx::GetXDisplay(), kCachedAtoms), | 116 atom_cache_(gfx::GetXDisplay(), kCachedAtoms), |
116 button_map_count_(0) { | 117 button_map_count_(0) { |
117 CHECK(gfx::GetXDisplay()); | 118 CHECK(gfx::GetXDisplay()); |
118 InitializeXInputInternal(); | 119 InitializeXInputInternal(); |
119 | 120 |
120 // Make sure the sizes of enum and kCachedAtoms are aligned. | 121 // Make sure the sizes of enum and kCachedAtoms are aligned. |
121 CHECK(arraysize(kCachedAtoms) == static_cast<size_t>(DT_LAST_ENTRY) + 1); | 122 CHECK(arraysize(kCachedAtoms) == static_cast<size_t>(DT_LAST_ENTRY) + 1); |
122 UpdateDeviceList(gfx::GetXDisplay()); | 123 UpdateDeviceList(gfx::GetXDisplay()); |
123 UpdateButtonMap(); | 124 UpdateButtonMap(); |
125 | |
126 for (int i = 0; i < kMaxDeviceNum; i++) | |
127 touch_device_to_display_map_[i] = gfx::Display::kInvalidDisplayID; | |
124 } | 128 } |
125 | 129 |
126 DeviceDataManager::~DeviceDataManager() { | 130 DeviceDataManager::~DeviceDataManager() { |
127 } | 131 } |
128 | 132 |
129 bool DeviceDataManager::InitializeXInputInternal() { | 133 bool DeviceDataManager::InitializeXInputInternal() { |
130 // Check if XInput is available on the system. | 134 // Check if XInput is available on the system. |
131 xi_opcode_ = -1; | 135 xi_opcode_ = -1; |
132 int opcode, event, error; | 136 int opcode, event, error; |
133 if (!XQueryExtension( | 137 if (!XQueryExtension( |
(...skipping 440 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
574 if (deviceid >= static_cast<unsigned int>(kMaxDeviceNum)) | 578 if (deviceid >= static_cast<unsigned int>(kMaxDeviceNum)) |
575 return false; | 579 return false; |
576 if (valuator_lookup_[deviceid][type] >= 0) { | 580 if (valuator_lookup_[deviceid][type] >= 0) { |
577 *min = valuator_min_[deviceid][type]; | 581 *min = valuator_min_[deviceid][type]; |
578 *max = valuator_max_[deviceid][type]; | 582 *max = valuator_max_[deviceid][type]; |
579 return true; | 583 return true; |
580 } | 584 } |
581 return false; | 585 return false; |
582 } | 586 } |
583 | 587 |
588 void DeviceDataManager::ClearTouchCTM() { | |
589 for (int i = 0; i < kMaxDeviceNum; i++) | |
590 touch_device_ctm_map_[i] = TouchCTM(); | |
591 } | |
592 | |
593 void DeviceDataManager::SetTouchCTM(int touch_device_id, | |
594 const TouchCTM& touch_ctm) { | |
595 if (touch_device_id > 0 && touch_device_id < kMaxDeviceNum) | |
596 touch_device_ctm_map_[touch_device_id] = touch_ctm; | |
597 } | |
598 | |
599 void DeviceDataManager::ApplyTouchCTM(int touch_device_id, float* x, float* y) { | |
600 if (touch_device_id > 0 && touch_device_id < kMaxDeviceNum) { | |
601 const TouchCTM ctm = touch_device_ctm_map_[touch_device_id]; | |
602 *x = *x * ctm.x_scale + ctm.x_offset; | |
603 *y = *y * ctm.y_scale + ctm.y_offset; | |
604 } | |
605 } | |
606 | |
607 void DeviceDataManager::ClearTouchDeviceToDisplayMap() { | |
608 for (int i = 0 ; i < kMaxDeviceNum; i++) | |
609 touch_device_to_display_map_[i] = gfx::Display::kInvalidDisplayID; | |
610 } | |
611 | |
612 void DeviceDataManager::MapTouchDeviceToDisplay(int touch_device_id, | |
613 int64 display_id) { | |
614 if (touch_device_id > 0 && touch_device_id < kMaxDeviceNum) | |
615 touch_device_to_display_map_[touch_device_id] = display_id; | |
616 } | |
617 | |
618 int64 DeviceDataManager::GetDisplayForTouchDevice(int touch_device_id) { | |
619 if (touch_device_id > 0 && touch_device_id < kMaxDeviceNum) | |
620 return touch_device_to_display_map_[touch_device_id]; | |
621 else | |
sadrul
2014/03/15 19:32:51
Don't need the else here.
Yufeng Shen (Slow to review)
2014/04/29 20:34:18
Done.
| |
622 return gfx::Display::kInvalidDisplayID; | |
623 } | |
624 | |
584 void DeviceDataManager::SetDeviceListForTest( | 625 void DeviceDataManager::SetDeviceListForTest( |
585 const std::vector<unsigned int>& touchscreen, | 626 const std::vector<unsigned int>& touchscreen, |
586 const std::vector<unsigned int>& cmt_devices) { | 627 const std::vector<unsigned int>& cmt_devices) { |
587 for (int i = 0; i < kMaxDeviceNum; ++i) { | 628 for (int i = 0; i < kMaxDeviceNum; ++i) { |
588 valuator_count_[i] = 0; | 629 valuator_count_[i] = 0; |
589 valuator_lookup_[i].clear(); | 630 valuator_lookup_[i].clear(); |
590 data_type_lookup_[i].clear(); | 631 data_type_lookup_[i].clear(); |
591 valuator_min_[i].clear(); | 632 valuator_min_[i].clear(); |
592 valuator_max_[i].clear(); | 633 valuator_max_[i].clear(); |
593 for (int j = 0; j < kMaxSlotNum; j++) | 634 for (int j = 0; j < kMaxSlotNum; j++) |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
643 for (int j = start_valuator; j <= end_valuator; ++j) { | 684 for (int j = start_valuator; j <= end_valuator; ++j) { |
644 valuator_lookup_[deviceid][j] = valuator_count_[deviceid]; | 685 valuator_lookup_[deviceid][j] = valuator_count_[deviceid]; |
645 data_type_lookup_[deviceid][valuator_count_[deviceid]] = j; | 686 data_type_lookup_[deviceid][valuator_count_[deviceid]] = j; |
646 valuator_min_[deviceid][j] = min_value; | 687 valuator_min_[deviceid][j] = min_value; |
647 valuator_max_[deviceid][j] = max_value; | 688 valuator_max_[deviceid][j] = max_value; |
648 valuator_count_[deviceid]++; | 689 valuator_count_[deviceid]++; |
649 } | 690 } |
650 } | 691 } |
651 | 692 |
652 } // namespace ui | 693 } // namespace ui |
OLD | NEW |