OLD | NEW |
---|---|
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/devices/x11/device_data_manager_x11.h" | 5 #include "ui/events/devices/x11/device_data_manager_x11.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.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/Xlib.h> | 10 #include <X11/Xlib.h> |
(...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
225 } | 225 } |
226 | 226 |
227 void DeviceDataManagerX11::UpdateDeviceList(Display* display) { | 227 void DeviceDataManagerX11::UpdateDeviceList(Display* display) { |
228 cmt_devices_.reset(); | 228 cmt_devices_.reset(); |
229 touchpads_.reset(); | 229 touchpads_.reset(); |
230 master_pointers_.clear(); | 230 master_pointers_.clear(); |
231 for (int i = 0; i < kMaxDeviceNum; ++i) { | 231 for (int i = 0; i < kMaxDeviceNum; ++i) { |
232 valuator_count_[i] = 0; | 232 valuator_count_[i] = 0; |
233 valuator_lookup_[i].clear(); | 233 valuator_lookup_[i].clear(); |
234 data_type_lookup_[i].clear(); | 234 data_type_lookup_[i].clear(); |
235 valuator_min_[i].clear(); | |
236 valuator_max_[i].clear(); | |
237 scroll_data_[i].horizontal.number = -1; | 235 scroll_data_[i].horizontal.number = -1; |
238 scroll_data_[i].horizontal.seen = false; | 236 scroll_data_[i].horizontal.seen = false; |
239 scroll_data_[i].vertical.number = -1; | 237 scroll_data_[i].vertical.number = -1; |
240 scroll_data_[i].vertical.seen = false; | 238 scroll_data_[i].vertical.seen = false; |
241 for (int j = 0; j < kMaxSlotNum; j++) | 239 for (int j = 0; j < kMaxSlotNum; j++) |
242 last_seen_valuator_[i][j].clear(); | 240 last_seen_valuator_[i][j].clear(); |
243 } | 241 } |
244 | 242 |
245 // Find all the touchpad devices. | 243 // Find all the touchpad devices. |
246 const XDeviceList& dev_list = | 244 const XDeviceList& dev_list = |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
278 if (info.classes[j]->type == XIValuatorClass) | 276 if (info.classes[j]->type == XIValuatorClass) |
279 ++valuator_count_[deviceid]; | 277 ++valuator_count_[deviceid]; |
280 else if (info.classes[j]->type == XIScrollClass) | 278 else if (info.classes[j]->type == XIScrollClass) |
281 not_cmt = true; | 279 not_cmt = true; |
282 } | 280 } |
283 | 281 |
284 // Skip devices that don't use any valuator | 282 // Skip devices that don't use any valuator |
285 if (!valuator_count_[deviceid]) | 283 if (!valuator_count_[deviceid]) |
286 continue; | 284 continue; |
287 | 285 |
288 valuator_lookup_[deviceid].resize(DT_LAST_ENTRY, -1); | 286 valuator_lookup_[deviceid].resize(DT_LAST_ENTRY); |
289 data_type_lookup_[deviceid].resize( | 287 data_type_lookup_[deviceid].resize( |
290 valuator_count_[deviceid], DT_LAST_ENTRY); | 288 valuator_count_[deviceid], DT_LAST_ENTRY); |
291 valuator_min_[deviceid].resize(DT_LAST_ENTRY, 0); | |
292 valuator_max_[deviceid].resize(DT_LAST_ENTRY, 0); | |
293 for (int j = 0; j < kMaxSlotNum; j++) | 289 for (int j = 0; j < kMaxSlotNum; j++) |
294 last_seen_valuator_[deviceid][j].resize(DT_LAST_ENTRY, 0); | 290 last_seen_valuator_[deviceid][j].resize(DT_LAST_ENTRY, 0); |
295 for (int j = 0; j < info.num_classes; ++j) { | 291 for (int j = 0; j < info.num_classes; ++j) { |
296 if (info.classes[j]->type == XIValuatorClass) { | 292 if (info.classes[j]->type == XIValuatorClass) { |
297 if (UpdateValuatorClassDevice( | 293 if (UpdateValuatorClassDevice( |
298 reinterpret_cast<XIValuatorClassInfo*>(info.classes[j]), atoms, | 294 reinterpret_cast<XIValuatorClassInfo*>(info.classes[j]), atoms, |
299 deviceid)) | 295 deviceid)) |
300 possible_cmt = true; | 296 possible_cmt = true; |
301 } else if (info.classes[j]->type == XIScrollClass) { | 297 } else if (info.classes[j]->type == XIScrollClass) { |
302 UpdateScrollClassDevice( | 298 UpdateScrollClassDevice( |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
366 if (xiev->evtype == XI_TouchBegin || | 362 if (xiev->evtype == XI_TouchBegin || |
367 xiev->evtype == XI_TouchEnd || | 363 xiev->evtype == XI_TouchEnd || |
368 xiev->evtype == XI_TouchUpdate) { | 364 xiev->evtype == XI_TouchUpdate) { |
369 *value = xiev->detail; | 365 *value = xiev->detail; |
370 } else { | 366 } else { |
371 *value = 0; | 367 *value = 0; |
372 } | 368 } |
373 return true; | 369 return true; |
374 } | 370 } |
375 | 371 |
376 int val_index = valuator_lookup_[sourceid][type]; | 372 int val_index = valuator_lookup_[sourceid][type].number; |
377 int slot = 0; | 373 int slot = 0; |
378 if (val_index >= 0) { | 374 if (val_index >= 0) { |
379 if (XIMaskIsSet(xiev->valuators.mask, val_index)) { | 375 if (XIMaskIsSet(xiev->valuators.mask, val_index)) { |
380 double* valuators = xiev->valuators.values; | 376 double* valuators = xiev->valuators.values; |
381 while (val_index--) { | 377 while (val_index--) { |
382 if (XIMaskIsSet(xiev->valuators.mask, val_index)) | 378 if (XIMaskIsSet(xiev->valuators.mask, val_index)) |
383 ++valuators; | 379 ++valuators; |
384 } | 380 } |
385 *value = *valuators; | 381 *value = *valuators; |
386 if (IsTouchDataType(type)) { | 382 if (IsTouchDataType(type)) { |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
460 return (IsScrollEvent(xev) || IsFlingEvent(xev) || IsCMTMetricsEvent(xev)); | 456 return (IsScrollEvent(xev) || IsFlingEvent(xev) || IsCMTMetricsEvent(xev)); |
461 } | 457 } |
462 | 458 |
463 bool DeviceDataManagerX11::HasEventData( | 459 bool DeviceDataManagerX11::HasEventData( |
464 const XIDeviceEvent* xiev, const DataType type) const { | 460 const XIDeviceEvent* xiev, const DataType type) const { |
465 CHECK_GE(xiev->sourceid, 0); | 461 CHECK_GE(xiev->sourceid, 0); |
466 if (xiev->sourceid >= kMaxDeviceNum) | 462 if (xiev->sourceid >= kMaxDeviceNum) |
467 return false; | 463 return false; |
468 if (type >= valuator_lookup_[xiev->sourceid].size()) | 464 if (type >= valuator_lookup_[xiev->sourceid].size()) |
469 return false; | 465 return false; |
470 const int idx = valuator_lookup_[xiev->sourceid][type]; | 466 const int idx = valuator_lookup_[xiev->sourceid][type].number; |
471 return (idx >= 0) && XIMaskIsSet(xiev->valuators.mask, idx); | 467 return (idx >= 0) && XIMaskIsSet(xiev->valuators.mask, idx); |
472 } | 468 } |
473 | 469 |
474 bool DeviceDataManagerX11::IsScrollEvent(const XEvent& xev) const { | 470 bool DeviceDataManagerX11::IsScrollEvent(const XEvent& xev) const { |
475 if (!IsCMTDeviceEvent(xev)) | 471 if (!IsCMTDeviceEvent(xev)) |
476 return false; | 472 return false; |
477 | 473 |
478 XIDeviceEvent* xiev = static_cast<XIDeviceEvent*>(xev.xcookie.data); | 474 XIDeviceEvent* xiev = static_cast<XIDeviceEvent*>(xev.xcookie.data); |
479 return (HasEventData(xiev, DT_CMT_SCROLL_X) || | 475 return (HasEventData(xiev, DT_CMT_SCROLL_X) || |
480 HasEventData(xiev, DT_CMT_SCROLL_Y)); | 476 HasEventData(xiev, DT_CMT_SCROLL_Y)); |
(...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
675 | 671 |
676 bool DeviceDataManagerX11::GetDataRange(int deviceid, | 672 bool DeviceDataManagerX11::GetDataRange(int deviceid, |
677 const DataType type, | 673 const DataType type, |
678 double* min, | 674 double* min, |
679 double* max) { | 675 double* max) { |
680 CHECK_GE(deviceid, 0); | 676 CHECK_GE(deviceid, 0); |
681 if (deviceid >= kMaxDeviceNum) | 677 if (deviceid >= kMaxDeviceNum) |
682 return false; | 678 return false; |
683 if (valuator_lookup_[deviceid].empty()) | 679 if (valuator_lookup_[deviceid].empty()) |
684 return false; | 680 return false; |
685 if (valuator_lookup_[deviceid][type] >= 0) { | 681 if (valuator_lookup_[deviceid][type].number >= 0) { |
686 *min = valuator_min_[deviceid][type]; | 682 *min = valuator_lookup_[deviceid][type].min; |
687 *max = valuator_max_[deviceid][type]; | 683 *max = valuator_lookup_[deviceid][type].max; |
688 return true; | 684 return true; |
689 } | 685 } |
690 return false; | 686 return false; |
691 } | 687 } |
692 | 688 |
693 void DeviceDataManagerX11::SetDeviceListForTest( | 689 void DeviceDataManagerX11::SetDeviceListForTest( |
694 const std::vector<int>& touchscreen, | 690 const std::vector<int>& touchscreen, |
695 const std::vector<int>& cmt_devices, | 691 const std::vector<int>& cmt_devices, |
696 const std::vector<int>& other_devices) { | 692 const std::vector<int>& other_devices) { |
697 for (int i = 0; i < kMaxDeviceNum; ++i) { | 693 for (int i = 0; i < kMaxDeviceNum; ++i) { |
698 valuator_count_[i] = 0; | 694 valuator_count_[i] = 0; |
699 valuator_lookup_[i].clear(); | 695 valuator_lookup_[i].clear(); |
700 data_type_lookup_[i].clear(); | 696 data_type_lookup_[i].clear(); |
701 valuator_min_[i].clear(); | |
702 valuator_max_[i].clear(); | |
703 for (int j = 0; j < kMaxSlotNum; j++) | 697 for (int j = 0; j < kMaxSlotNum; j++) |
704 last_seen_valuator_[i][j].clear(); | 698 last_seen_valuator_[i][j].clear(); |
705 } | 699 } |
706 | 700 |
707 for (int deviceid : touchscreen) { | 701 for (int deviceid : touchscreen) { |
708 InitializeValuatorsForTest(deviceid, kTouchDataTypeStart, kTouchDataTypeEnd, | 702 InitializeValuatorsForTest(deviceid, kTouchDataTypeStart, kTouchDataTypeEnd, |
709 0, 1000); | 703 0, 1000); |
710 } | 704 } |
711 | 705 |
712 cmt_devices_.reset(); | 706 cmt_devices_.reset(); |
713 for (int deviceid : cmt_devices) { | 707 for (int deviceid : cmt_devices) { |
714 cmt_devices_[deviceid] = true; | 708 cmt_devices_[deviceid] = true; |
715 touchpads_[deviceid] = true; | 709 touchpads_[deviceid] = true; |
716 InitializeValuatorsForTest(deviceid, kCMTDataTypeStart, kCMTDataTypeEnd, | 710 InitializeValuatorsForTest(deviceid, kCMTDataTypeStart, kCMTDataTypeEnd, |
717 -1000, 1000); | 711 -1000, 1000); |
718 } | 712 } |
719 | 713 |
720 for (int deviceid : other_devices) { | 714 for (int deviceid : other_devices) { |
721 InitializeValuatorsForTest(deviceid, kCMTDataTypeStart, kCMTDataTypeEnd, | 715 InitializeValuatorsForTest(deviceid, kCMTDataTypeStart, kCMTDataTypeEnd, |
722 -1000, 1000); | 716 -1000, 1000); |
723 } | 717 } |
724 } | 718 } |
725 | 719 |
726 void DeviceDataManagerX11::SetValuatorDataForTest(XIDeviceEvent* xievent, | 720 void DeviceDataManagerX11::SetValuatorDataForTest(XIDeviceEvent* xievent, |
727 DataType type, | 721 DataType type, |
728 double value) { | 722 double value) { |
729 int index = valuator_lookup_[xievent->deviceid][type]; | 723 int index = valuator_lookup_[xievent->deviceid][type].number; |
730 CHECK(!XIMaskIsSet(xievent->valuators.mask, index)); | 724 CHECK(!XIMaskIsSet(xievent->valuators.mask, index)); |
731 CHECK(index >= 0 && index < valuator_count_[xievent->deviceid]); | 725 CHECK(index >= 0 && index < valuator_count_[xievent->deviceid]); |
732 XISetMask(xievent->valuators.mask, index); | 726 XISetMask(xievent->valuators.mask, index); |
733 | 727 |
734 double* valuators = xievent->valuators.values; | 728 double* valuators = xievent->valuators.values; |
735 for (int i = 0; i < index; ++i) { | 729 for (int i = 0; i < index; ++i) { |
736 if (XIMaskIsSet(xievent->valuators.mask, i)) | 730 if (XIMaskIsSet(xievent->valuators.mask, i)) |
737 valuators++; | 731 valuators++; |
738 } | 732 } |
739 for (int i = DT_LAST_ENTRY - 1; i > valuators - xievent->valuators.values; | 733 for (int i = DT_LAST_ENTRY - 1; i > valuators - xievent->valuators.values; |
740 --i) | 734 --i) |
741 xievent->valuators.values[i] = xievent->valuators.values[i - 1]; | 735 xievent->valuators.values[i] = xievent->valuators.values[i - 1]; |
742 *valuators = value; | 736 *valuators = value; |
743 } | 737 } |
744 | 738 |
745 void DeviceDataManagerX11::InitializeValuatorsForTest(int deviceid, | 739 void DeviceDataManagerX11::InitializeValuatorsForTest(int deviceid, |
746 int start_valuator, | 740 int start_valuator, |
747 int end_valuator, | 741 int end_valuator, |
748 double min_value, | 742 double min_value, |
749 double max_value) { | 743 double max_value) { |
750 valuator_lookup_[deviceid].resize(DT_LAST_ENTRY, -1); | 744 valuator_lookup_[deviceid].resize(DT_LAST_ENTRY); |
751 data_type_lookup_[deviceid].resize(DT_LAST_ENTRY, DT_LAST_ENTRY); | 745 data_type_lookup_[deviceid].resize(DT_LAST_ENTRY, DT_LAST_ENTRY); |
752 valuator_min_[deviceid].resize(DT_LAST_ENTRY, 0); | |
753 valuator_max_[deviceid].resize(DT_LAST_ENTRY, 0); | |
754 for (int j = 0; j < kMaxSlotNum; j++) | 746 for (int j = 0; j < kMaxSlotNum; j++) |
755 last_seen_valuator_[deviceid][j].resize(DT_LAST_ENTRY, 0); | 747 last_seen_valuator_[deviceid][j].resize(DT_LAST_ENTRY, 0); |
756 for (int j = start_valuator; j <= end_valuator; ++j) { | 748 for (int j = start_valuator; j <= end_valuator; ++j) { |
757 valuator_lookup_[deviceid][j] = valuator_count_[deviceid]; | 749 valuator_lookup_[deviceid][j].number = valuator_count_[deviceid]; |
sadrul
2017/05/01 16:03:56
Maybe something like:
ValuatorInfo* info = &valu
kylechar
2017/05/01 16:10:17
Done with "auto& valuator_info = ...".
| |
750 valuator_lookup_[deviceid][j].min = min_value; | |
751 valuator_lookup_[deviceid][j].max = max_value; | |
758 data_type_lookup_[deviceid][valuator_count_[deviceid]] = j; | 752 data_type_lookup_[deviceid][valuator_count_[deviceid]] = j; |
759 valuator_min_[deviceid][j] = min_value; | |
760 valuator_max_[deviceid][j] = max_value; | |
761 valuator_count_[deviceid]++; | 753 valuator_count_[deviceid]++; |
762 } | 754 } |
763 } | 755 } |
764 | 756 |
765 bool DeviceDataManagerX11::UpdateValuatorClassDevice( | 757 bool DeviceDataManagerX11::UpdateValuatorClassDevice( |
766 XIValuatorClassInfo* valuator_class_info, | 758 XIValuatorClassInfo* valuator_class_info, |
767 Atom* atoms, | 759 Atom* atoms, |
768 int deviceid) { | 760 int deviceid) { |
769 DCHECK(deviceid >= 0 && deviceid < kMaxDeviceNum); | 761 DCHECK(deviceid >= 0 && deviceid < kMaxDeviceNum); |
770 Atom* label = | 762 Atom* label = |
771 std::find(atoms, atoms + DT_LAST_ENTRY, valuator_class_info->label); | 763 std::find(atoms, atoms + DT_LAST_ENTRY, valuator_class_info->label); |
772 if (label == atoms + DT_LAST_ENTRY) { | 764 if (label == atoms + DT_LAST_ENTRY) { |
773 return false; | 765 return false; |
774 } | 766 } |
775 int data_type = label - atoms; | 767 int data_type = label - atoms; |
776 DCHECK_GE(data_type, 0); | 768 DCHECK_GE(data_type, 0); |
777 DCHECK_LT(data_type, DT_LAST_ENTRY); | 769 DCHECK_LT(data_type, DT_LAST_ENTRY); |
778 | 770 |
779 valuator_lookup_[deviceid][data_type] = valuator_class_info->number; | 771 valuator_lookup_[deviceid][data_type].number = valuator_class_info->number; |
772 valuator_lookup_[deviceid][data_type].min = valuator_class_info->min; | |
773 valuator_lookup_[deviceid][data_type].max = valuator_class_info->max; | |
sadrul
2017/05/01 16:03:56
ditto
kylechar
2017/05/01 16:10:17
Done.
| |
780 data_type_lookup_[deviceid][valuator_class_info->number] = data_type; | 774 data_type_lookup_[deviceid][valuator_class_info->number] = data_type; |
781 valuator_min_[deviceid][data_type] = valuator_class_info->min; | |
782 valuator_max_[deviceid][data_type] = valuator_class_info->max; | |
783 return IsCMTDataType(data_type); | 775 return IsCMTDataType(data_type); |
784 } | 776 } |
785 | 777 |
786 void DeviceDataManagerX11::UpdateScrollClassDevice( | 778 void DeviceDataManagerX11::UpdateScrollClassDevice( |
787 XIScrollClassInfo* scroll_class_info, | 779 XIScrollClassInfo* scroll_class_info, |
788 int deviceid) { | 780 int deviceid) { |
789 if (high_precision_scrolling_disabled_) | 781 if (high_precision_scrolling_disabled_) |
790 return; | 782 return; |
791 | 783 |
792 DCHECK(deviceid >= 0 && deviceid < kMaxDeviceNum); | 784 DCHECK(deviceid >= 0 && deviceid < kMaxDeviceNum); |
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
901 } else { | 893 } else { |
902 keyboards.erase(it); | 894 keyboards.erase(it); |
903 ++blocked_iter; | 895 ++blocked_iter; |
904 } | 896 } |
905 } | 897 } |
906 // Notify base class of updated list. | 898 // Notify base class of updated list. |
907 DeviceDataManager::OnKeyboardDevicesUpdated(keyboards); | 899 DeviceDataManager::OnKeyboardDevicesUpdated(keyboards); |
908 } | 900 } |
909 | 901 |
910 } // namespace ui | 902 } // namespace ui |
OLD | NEW |