Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(7)

Side by Side Diff: ui/events/devices/x11/device_data_manager_x11.cc

Issue 688253002: Implemented smooth scrolling using xinput2 in X11. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebased Created 5 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 <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
(...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after
202 void DeviceDataManagerX11::UpdateDeviceList(Display* display) { 202 void DeviceDataManagerX11::UpdateDeviceList(Display* display) {
203 cmt_devices_.reset(); 203 cmt_devices_.reset();
204 touchpads_.reset(); 204 touchpads_.reset();
205 master_pointers_.clear(); 205 master_pointers_.clear();
206 for (int i = 0; i < kMaxDeviceNum; ++i) { 206 for (int i = 0; i < kMaxDeviceNum; ++i) {
207 valuator_count_[i] = 0; 207 valuator_count_[i] = 0;
208 valuator_lookup_[i].clear(); 208 valuator_lookup_[i].clear();
209 data_type_lookup_[i].clear(); 209 data_type_lookup_[i].clear();
210 valuator_min_[i].clear(); 210 valuator_min_[i].clear();
211 valuator_max_[i].clear(); 211 valuator_max_[i].clear();
212 scroll_data_[i].horizontal.number = -1;
213 scroll_data_[i].vertical.number = -1;
212 for (int j = 0; j < kMaxSlotNum; j++) 214 for (int j = 0; j < kMaxSlotNum; j++)
213 last_seen_valuator_[i][j].clear(); 215 last_seen_valuator_[i][j].clear();
214 } 216 }
215 217
216 // Find all the touchpad devices. 218 // Find all the touchpad devices.
217 const XDeviceList& dev_list = 219 const XDeviceList& dev_list =
218 ui::DeviceListCacheX11::GetInstance()->GetXDeviceList(display); 220 ui::DeviceListCacheX11::GetInstance()->GetXDeviceList(display);
219 Atom xi_touchpad = XInternAtom(display, XI_TOUCHPAD, false); 221 Atom xi_touchpad = XInternAtom(display, XI_TOUCHPAD, false);
220 for (int i = 0; i < dev_list.count; ++i) 222 for (int i = 0; i < dev_list.count; ++i)
221 if (dev_list[i].type == xi_touchpad) 223 if (dev_list[i].type == xi_touchpad)
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
257 continue; 259 continue;
258 260
259 valuator_lookup_[deviceid].resize(DT_LAST_ENTRY, -1); 261 valuator_lookup_[deviceid].resize(DT_LAST_ENTRY, -1);
260 data_type_lookup_[deviceid].resize( 262 data_type_lookup_[deviceid].resize(
261 valuator_count_[deviceid], DT_LAST_ENTRY); 263 valuator_count_[deviceid], DT_LAST_ENTRY);
262 valuator_min_[deviceid].resize(DT_LAST_ENTRY, 0); 264 valuator_min_[deviceid].resize(DT_LAST_ENTRY, 0);
263 valuator_max_[deviceid].resize(DT_LAST_ENTRY, 0); 265 valuator_max_[deviceid].resize(DT_LAST_ENTRY, 0);
264 for (int j = 0; j < kMaxSlotNum; j++) 266 for (int j = 0; j < kMaxSlotNum; j++)
265 last_seen_valuator_[deviceid][j].resize(DT_LAST_ENTRY, 0); 267 last_seen_valuator_[deviceid][j].resize(DT_LAST_ENTRY, 0);
266 for (int j = 0; j < info.num_classes; ++j) { 268 for (int j = 0; j < info.num_classes; ++j) {
267 if (info.classes[j]->type != XIValuatorClass) 269 if (info.classes[j]->type == XIValuatorClass) {
268 continue; 270 if (UpdateValuatorClassDevice(
269 271 reinterpret_cast<XIValuatorClassInfo*>(info.classes[j]),
270 XIValuatorClassInfo* v = 272 atoms,
271 reinterpret_cast<XIValuatorClassInfo*>(info.classes[j]); 273 deviceid))
272 for (int data_type = 0; data_type < DT_LAST_ENTRY; ++data_type) { 274 possible_cmt = true;
273 if (v->label == atoms[data_type]) { 275 } else if (info.classes[j]->type == XIScrollClass) {
274 valuator_lookup_[deviceid][data_type] = v->number; 276 UpdateScrollClassDevice(
275 data_type_lookup_[deviceid][v->number] = data_type; 277 reinterpret_cast<XIScrollClassInfo*>(info.classes[j]), deviceid);
276 valuator_min_[deviceid][data_type] = v->min;
277 valuator_max_[deviceid][data_type] = v->max;
278 if (IsCMTDataType(data_type))
279 possible_cmt = true;
280 break;
281 }
282 } 278 }
283 } 279 }
284 280
285 if (possible_cmt && !not_cmt) 281 if (possible_cmt && !not_cmt)
286 cmt_devices_[deviceid] = true; 282 cmt_devices_[deviceid] = true;
287 } 283 }
288 } 284 }
289 285
286 bool DeviceDataManagerX11::UpdateValuatorClassDevice(
287 XIValuatorClassInfo* valuator_class_info,
288 Atom *atoms,
289 int deviceid) {
sadrul 2015/08/18 16:57:45 Add a DCHECK here that deviceid is valid.
Will Shackleton 2015/08/26 19:52:48 Acknowledged.
290 for (int data_type = 0; data_type < DT_LAST_ENTRY; ++data_type) {
291 if (valuator_class_info->label == atoms[data_type]) {
292 valuator_lookup_[deviceid][data_type] = valuator_class_info->number;
293 data_type_lookup_[deviceid][valuator_class_info->number] = data_type;
294 valuator_min_[deviceid][data_type] = valuator_class_info->min;
295 valuator_max_[deviceid][data_type] = valuator_class_info->max;
296 if (IsCMTDataType(data_type))
sadrul 2015/08/18 16:57:45 Can you clarify why cmt-data type matters here?
Will Shackleton 2015/08/26 19:52:48 This method is moved from above (line 279, left) -
297 return true;
298 }
299 }
300 return false;
301 }
302
303 void DeviceDataManagerX11::UpdateScrollClassDevice(
304 XIScrollClassInfo* scroll_class_info,
305 int deviceid) {
sadrul 2015/08/18 16:57:45 DCHECK for deviceid
Will Shackleton 2015/08/26 19:52:48 Acknowledged.
306 ScrollInfo& info = scroll_data_[deviceid];
307 switch (scroll_class_info->scroll_type) {
308 case XIScrollTypeVertical:
309 info.vertical.number = scroll_class_info->number;
310 info.vertical.increment = scroll_class_info->increment;
311 info.vertical.position = 0;
312 info.vertical.seen = false;
313 break;
314 case XIScrollTypeHorizontal:
315 info.horizontal.number = scroll_class_info->number;
316 info.horizontal.increment = scroll_class_info->increment;
317 info.horizontal.position = 0;
318 info.horizontal.seen = false;
319 break;
320 }
321 scrollclass_devices_[deviceid] = true;
322 }
323
290 bool DeviceDataManagerX11::GetSlotNumber(const XIDeviceEvent* xiev, int* slot) { 324 bool DeviceDataManagerX11::GetSlotNumber(const XIDeviceEvent* xiev, int* slot) {
291 ui::TouchFactory* factory = ui::TouchFactory::GetInstance(); 325 ui::TouchFactory* factory = ui::TouchFactory::GetInstance();
292 if (!factory->IsMultiTouchDevice(xiev->sourceid)) { 326 if (!factory->IsMultiTouchDevice(xiev->sourceid)) {
293 *slot = 0; 327 *slot = 0;
294 return true; 328 return true;
295 } 329 }
296 return factory->QuerySlotForTrackingID(xiev->detail, slot); 330 return factory->QuerySlotForTrackingID(xiev->detail, slot);
297 } 331 }
298 332
299 void DeviceDataManagerX11::GetEventRawData(const XEvent& xev, EventData* data) { 333 void DeviceDataManagerX11::GetEventRawData(const XEvent& xev, EventData* data) {
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
402 return false; 436 return false;
403 437
404 XIDeviceEvent* xievent = 438 XIDeviceEvent* xievent =
405 static_cast<XIDeviceEvent*>(native_event->xcookie.data); 439 static_cast<XIDeviceEvent*>(native_event->xcookie.data);
406 CHECK(xievent->sourceid >= 0); 440 CHECK(xievent->sourceid >= 0);
407 if (xievent->sourceid >= kMaxDeviceNum) 441 if (xievent->sourceid >= kMaxDeviceNum)
408 return false; 442 return false;
409 return cmt_devices_[xievent->sourceid]; 443 return cmt_devices_[xievent->sourceid];
410 } 444 }
411 445
446 int DeviceDataManagerX11::GetScrollClassEventDetail(const base::NativeEvent&
447 native_event) const {
448 if (native_event->type != GenericEvent)
449 return SCROLL_TYPE_NO_SCROLL;
450
451 XIDeviceEvent* xievent =
452 static_cast<XIDeviceEvent*>(native_event->xcookie.data);
453 if (xievent->sourceid >= kMaxDeviceNum)
454 return SCROLL_TYPE_NO_SCROLL;
455 if (!scrollclass_devices_[xievent->sourceid])
456 return SCROLL_TYPE_NO_SCROLL;
457 int horizontal_id = scroll_data_[xievent->sourceid].horizontal.number;
458 int vertical_id = scroll_data_[xievent->sourceid].vertical.number;
459 return (XIMaskIsSet(xievent->valuators.mask, horizontal_id) ?
460 SCROLL_TYPE_HORIZONTAL : 0) |
461 (XIMaskIsSet(xievent->valuators.mask, vertical_id) ?
462 SCROLL_TYPE_VERTICAL : 0);
463 }
464
465 int DeviceDataManagerX11::GetScrollClassDeviceDetail(
466 const base::NativeEvent& native_event) const {
467 XEvent& xev = *native_event;
468 if (xev.type != GenericEvent)
469 return SCROLL_TYPE_NO_SCROLL;
470
471 XIDeviceEvent* xiev = static_cast<XIDeviceEvent*>(xev.xcookie.data);
472 if (xiev->sourceid >= kMaxDeviceNum || xiev->deviceid >= kMaxDeviceNum)
473 return SCROLL_TYPE_NO_SCROLL;
474 const int sourceid = xiev->sourceid;
475 ScrollInfo device_data = scroll_data_[sourceid];
476 return (device_data.vertical.number >= 0 ? SCROLL_TYPE_VERTICAL : 0) |
477 (device_data.horizontal.number >= 0 ? SCROLL_TYPE_HORIZONTAL : 0);
478 }
479
412 bool DeviceDataManagerX11::IsCMTGestureEvent( 480 bool DeviceDataManagerX11::IsCMTGestureEvent(
413 const base::NativeEvent& native_event) const { 481 const base::NativeEvent& native_event) const {
414 return (IsScrollEvent(native_event) || 482 return (IsScrollEvent(native_event) ||
415 IsFlingEvent(native_event) || 483 IsFlingEvent(native_event) ||
416 IsCMTMetricsEvent(native_event)); 484 IsCMTMetricsEvent(native_event));
417 } 485 }
418 486
419 bool DeviceDataManagerX11::HasEventData( 487 bool DeviceDataManagerX11::HasEventData(
420 const XIDeviceEvent* xiev, const DataType type) const { 488 const XIDeviceEvent* xiev, const DataType type) const {
421 const int idx = valuator_lookup_[xiev->sourceid][type]; 489 const int idx = valuator_lookup_[xiev->sourceid][type];
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
489 if (data.find(DT_CMT_SCROLL_Y) != data.end()) 557 if (data.find(DT_CMT_SCROLL_Y) != data.end())
490 *y_offset = data[DT_CMT_SCROLL_Y]; 558 *y_offset = data[DT_CMT_SCROLL_Y];
491 if (data.find(DT_CMT_ORDINAL_X) != data.end()) 559 if (data.find(DT_CMT_ORDINAL_X) != data.end())
492 *x_offset_ordinal = data[DT_CMT_ORDINAL_X]; 560 *x_offset_ordinal = data[DT_CMT_ORDINAL_X];
493 if (data.find(DT_CMT_ORDINAL_Y) != data.end()) 561 if (data.find(DT_CMT_ORDINAL_Y) != data.end())
494 *y_offset_ordinal = data[DT_CMT_ORDINAL_Y]; 562 *y_offset_ordinal = data[DT_CMT_ORDINAL_Y];
495 if (data.find(DT_CMT_FINGER_COUNT) != data.end()) 563 if (data.find(DT_CMT_FINGER_COUNT) != data.end())
496 *finger_count = static_cast<int>(data[DT_CMT_FINGER_COUNT]); 564 *finger_count = static_cast<int>(data[DT_CMT_FINGER_COUNT]);
497 } 565 }
498 566
567 void DeviceDataManagerX11::GetScrollClassOffsets(
568 const base::NativeEvent& native_event,
569 double* x_offset,
570 double* y_offset) {
571 XEvent& xev = *native_event;
572 if (xev.type != GenericEvent)
573 return;
574
575 *x_offset = 0;
576 *y_offset = 0;
577
578 XIDeviceEvent* xiev = static_cast<XIDeviceEvent*>(xev.xcookie.data);
579 if (xiev->sourceid >= kMaxDeviceNum || xiev->deviceid >= kMaxDeviceNum)
580 return;
581 const int sourceid = xiev->sourceid;
582 double* valuators = xiev->valuators.values;
583
584 ScrollInfo& info = scroll_data_[sourceid];
585
586 const int horizontal_number = info.horizontal.number;
587 const int vertical_number = info.vertical.number;
588
589 for (int i = 0; i <= valuator_count_[sourceid]; ++i) {
590 if (XIMaskIsSet(xiev->valuators.mask, i)) {
sadrul 2015/08/18 16:57:45 if (!mask-set) continue;
Will Shackleton 2015/08/26 19:52:48 Acknowledged.
591 if (i == horizontal_number) {
592 double value = *valuators;
593 double delta = 0;
594
595 if (info.horizontal.seen)
596 delta = info.horizontal.position - value;
597
598 info.horizontal.seen = true;
599 info.horizontal.position = value;
600 *x_offset = delta;
601 NormalizeScrollData(sourceid, true, x_offset);
602 } else if (i == vertical_number) {
603 double value = *valuators;
604 double delta = 0;
605 if (info.vertical.seen)
606 delta = info.vertical.position - value;
607
608 info.vertical.seen = true;
609 info.vertical.position = value;
610 *y_offset = delta;
611 NormalizeScrollData(sourceid, false, y_offset);
612 }
613 valuators++;
614 }
615 }
616 }
617
618 void DeviceDataManagerX11::InvalidateScrollClasses() {
619 for (int i = 0; i < kMaxDeviceNum; i++) {
620 scroll_data_[i].horizontal.seen = false;
621 scroll_data_[i].vertical.seen = false;
622 }
623 }
624
499 void DeviceDataManagerX11::GetFlingData( 625 void DeviceDataManagerX11::GetFlingData(
500 const base::NativeEvent& native_event, 626 const base::NativeEvent& native_event,
501 float* vx, 627 float* vx,
502 float* vy, 628 float* vy,
503 float* vx_ordinal, 629 float* vx_ordinal,
504 float* vy_ordinal, 630 float* vy_ordinal,
505 bool* is_cancel) { 631 bool* is_cancel) {
506 *vx = 0; 632 *vx = 0;
507 *vy = 0; 633 *vy = 0;
508 *vx_ordinal = 0; 634 *vx_ordinal = 0;
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
582 double max_value; 708 double max_value;
583 double min_value; 709 double min_value;
584 if (GetDataRange(deviceid, type, &min_value, &max_value)) { 710 if (GetDataRange(deviceid, type, &min_value, &max_value)) {
585 *value = (*value - min_value) / (max_value - min_value); 711 *value = (*value - min_value) / (max_value - min_value);
586 DCHECK(*value >= 0.0 && *value <= 1.0); 712 DCHECK(*value >= 0.0 && *value <= 1.0);
587 return true; 713 return true;
588 } 714 }
589 return false; 715 return false;
590 } 716 }
591 717
718 bool DeviceDataManagerX11::NormalizeScrollData(unsigned int deviceid,
719 bool horizontal,
720 double* value) {
721 if (deviceid >= static_cast<unsigned int>(kMaxDeviceNum))
722 return false;
723 if (horizontal && scroll_data_[deviceid].horizontal.number < 0)
724 return false;
725 if (!horizontal && scroll_data_[deviceid].vertical.number < 0)
726 return false;
727 double increment = horizontal ?
728 scroll_data_[deviceid].horizontal.increment :
729 scroll_data_[deviceid].vertical.increment;
730
731 *value /= increment;
732 return true;
733 }
734
592 bool DeviceDataManagerX11::GetDataRange(int deviceid, 735 bool DeviceDataManagerX11::GetDataRange(int deviceid,
593 const DataType type, 736 const DataType type,
594 double* min, 737 double* min,
595 double* max) { 738 double* max) {
596 CHECK(deviceid >= 0); 739 CHECK(deviceid >= 0);
597 if (deviceid >= kMaxDeviceNum) 740 if (deviceid >= kMaxDeviceNum)
598 return false; 741 return false;
599 if (valuator_lookup_[deviceid][type] >= 0) { 742 if (valuator_lookup_[deviceid][type] >= 0) {
600 *min = valuator_min_[deviceid][type]; 743 *min = valuator_min_[deviceid][type];
601 *max = valuator_max_[deviceid][type]; 744 *max = valuator_max_[deviceid][type];
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after
761 } else { 904 } else {
762 keyboards.erase(it); 905 keyboards.erase(it);
763 ++blocked_iter; 906 ++blocked_iter;
764 } 907 }
765 } 908 }
766 // Notify base class of updated list. 909 // Notify base class of updated list.
767 DeviceDataManager::OnKeyboardDevicesUpdated(keyboards); 910 DeviceDataManager::OnKeyboardDevicesUpdated(keyboards);
768 } 911 }
769 912
770 } // namespace ui 913 } // namespace ui
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698