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

Side by Side Diff: ui/events/x/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: Applied sadrul's comments Created 5 years, 11 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/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
(...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after
207 207
208 void DeviceDataManagerX11::UpdateDeviceList(Display* display) { 208 void DeviceDataManagerX11::UpdateDeviceList(Display* display) {
209 cmt_devices_.reset(); 209 cmt_devices_.reset();
210 touchpads_.reset(); 210 touchpads_.reset();
211 for (int i = 0; i < kMaxDeviceNum; ++i) { 211 for (int i = 0; i < kMaxDeviceNum; ++i) {
212 valuator_count_[i] = 0; 212 valuator_count_[i] = 0;
213 valuator_lookup_[i].clear(); 213 valuator_lookup_[i].clear();
214 data_type_lookup_[i].clear(); 214 data_type_lookup_[i].clear();
215 valuator_min_[i].clear(); 215 valuator_min_[i].clear();
216 valuator_max_[i].clear(); 216 valuator_max_[i].clear();
217 scroll_data_[i].horizontal.number = -1;
218 scroll_data_[i].vertical.number = -1;
217 for (int j = 0; j < kMaxSlotNum; j++) 219 for (int j = 0; j < kMaxSlotNum; j++)
218 last_seen_valuator_[i][j].clear(); 220 last_seen_valuator_[i][j].clear();
219 } 221 }
220 222
221 // Find all the touchpad devices. 223 // Find all the touchpad devices.
222 XDeviceList dev_list = 224 XDeviceList dev_list =
223 ui::DeviceListCacheX::GetInstance()->GetXDeviceList(display); 225 ui::DeviceListCacheX::GetInstance()->GetXDeviceList(display);
224 Atom xi_touchpad = XInternAtom(display, XI_TOUCHPAD, false); 226 Atom xi_touchpad = XInternAtom(display, XI_TOUCHPAD, false);
225 for (int i = 0; i < dev_list.count; ++i) 227 for (int i = 0; i < dev_list.count; ++i)
226 if (dev_list[i].type == xi_touchpad) 228 if (dev_list[i].type == xi_touchpad)
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
259 continue; 261 continue;
260 262
261 valuator_lookup_[deviceid].resize(DT_LAST_ENTRY, -1); 263 valuator_lookup_[deviceid].resize(DT_LAST_ENTRY, -1);
262 data_type_lookup_[deviceid].resize( 264 data_type_lookup_[deviceid].resize(
263 valuator_count_[deviceid], DT_LAST_ENTRY); 265 valuator_count_[deviceid], DT_LAST_ENTRY);
264 valuator_min_[deviceid].resize(DT_LAST_ENTRY, 0); 266 valuator_min_[deviceid].resize(DT_LAST_ENTRY, 0);
265 valuator_max_[deviceid].resize(DT_LAST_ENTRY, 0); 267 valuator_max_[deviceid].resize(DT_LAST_ENTRY, 0);
266 for (int j = 0; j < kMaxSlotNum; j++) 268 for (int j = 0; j < kMaxSlotNum; j++)
267 last_seen_valuator_[deviceid][j].resize(DT_LAST_ENTRY, 0); 269 last_seen_valuator_[deviceid][j].resize(DT_LAST_ENTRY, 0);
268 for (int j = 0; j < info->num_classes; ++j) { 270 for (int j = 0; j < info->num_classes; ++j) {
269 if (info->classes[j]->type != XIValuatorClass) 271 if (info->classes[j]->type == XIValuatorClass) {
270 continue; 272 XIValuatorClassInfo* v =
271 273 reinterpret_cast<XIValuatorClassInfo*>(info->classes[j]);
272 XIValuatorClassInfo* v = 274 for (int data_type = 0; data_type < DT_LAST_ENTRY; ++data_type) {
273 reinterpret_cast<XIValuatorClassInfo*>(info->classes[j]); 275 if (v->label == atoms[data_type]) {
274 for (int data_type = 0; data_type < DT_LAST_ENTRY; ++data_type) { 276 valuator_lookup_[deviceid][data_type] = v->number;
275 if (v->label == atoms[data_type]) { 277 data_type_lookup_[deviceid][v->number] = data_type;
276 valuator_lookup_[deviceid][data_type] = v->number; 278 valuator_min_[deviceid][data_type] = v->min;
277 data_type_lookup_[deviceid][v->number] = data_type; 279 valuator_max_[deviceid][data_type] = v->max;
278 valuator_min_[deviceid][data_type] = v->min; 280 if (IsCMTDataType(data_type))
279 valuator_max_[deviceid][data_type] = v->max; 281 possible_cmt = true;
280 if (IsCMTDataType(data_type)) 282 break;
281 possible_cmt = true; 283 }
282 break;
283 } 284 }
285 } else if (info->classes[j]->type == XIScrollClass) {
286 XIScrollClassInfo* v =
287 reinterpret_cast<XIScrollClassInfo*>(info->classes[j]);
288 ScrollInfo& info = scroll_data_[deviceid];
289 switch (v->scroll_type) {
290 case XIScrollTypeVertical:
291 info.vertical.number = v->number;
292 info.vertical.increment = v->increment;
293 info.vertical.position = 0;
294 info.vertical.seen = false;
295 break;
296 case XIScrollTypeHorizontal:
297 info.horizontal.number = v->number;
298 info.horizontal.increment = v->increment;
299 info.horizontal.position = 0;
300 info.horizontal.seen = false;
301 break;
302 }
303 scrollclass_devices_[deviceid] = true;
284 } 304 }
285 } 305 }
sadrul 2015/01/30 15:49:15 Would it be possible to break this function up int
286 306
287 if (possible_cmt && !not_cmt) 307 if (possible_cmt && !not_cmt)
288 cmt_devices_[deviceid] = true; 308 cmt_devices_[deviceid] = true;
289 } 309 }
290 } 310 }
291 311
292 bool DeviceDataManagerX11::GetSlotNumber(const XIDeviceEvent* xiev, int* slot) { 312 bool DeviceDataManagerX11::GetSlotNumber(const XIDeviceEvent* xiev, int* slot) {
293 #if defined(USE_XI2_MT) 313 #if defined(USE_XI2_MT)
294 ui::TouchFactory* factory = ui::TouchFactory::GetInstance(); 314 ui::TouchFactory* factory = ui::TouchFactory::GetInstance();
295 if (!factory->IsMultiTouchDevice(xiev->sourceid)) { 315 if (!factory->IsMultiTouchDevice(xiev->sourceid)) {
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
403 if (native_event->type != GenericEvent) 423 if (native_event->type != GenericEvent)
404 return false; 424 return false;
405 425
406 XIDeviceEvent* xievent = 426 XIDeviceEvent* xievent =
407 static_cast<XIDeviceEvent*>(native_event->xcookie.data); 427 static_cast<XIDeviceEvent*>(native_event->xcookie.data);
408 if (xievent->sourceid >= kMaxDeviceNum) 428 if (xievent->sourceid >= kMaxDeviceNum)
409 return false; 429 return false;
410 return cmt_devices_[xievent->sourceid]; 430 return cmt_devices_[xievent->sourceid];
411 } 431 }
412 432
433 int DeviceDataManagerX11::GetScrollClassEventDetail(const base::NativeEvent&
434 native_event) const {
435 if (native_event->type != GenericEvent)
436 return SCROLL_TYPE_NO_SCROLL;
437
438 XIDeviceEvent* xievent =
439 static_cast<XIDeviceEvent*>(native_event->xcookie.data);
440 if (xievent->sourceid >= kMaxDeviceNum)
441 return SCROLL_TYPE_NO_SCROLL;
442 if (!scrollclass_devices_[xievent->sourceid])
443 return SCROLL_TYPE_NO_SCROLL;
444 int horizontal_id = scroll_data_[xievent->sourceid].horizontal.number;
445 int vertical_id = scroll_data_[xievent->sourceid].vertical.number;
446 return (XIMaskIsSet(xievent->valuators.mask, horizontal_id) ?
447 SCROLL_TYPE_HORIZONTAL : 0) |
448 (XIMaskIsSet(xievent->valuators.mask, vertical_id) ?
449 SCROLL_TYPE_VERTICAL : 0);
450 }
451
452 int DeviceDataManagerX11::GetScrollClassDeviceDetail(
453 const base::NativeEvent& native_event) const {
454 XEvent& xev = *native_event;
455 if (xev.type != GenericEvent)
456 return SCROLL_TYPE_NO_SCROLL;
457
458 XIDeviceEvent* xiev = static_cast<XIDeviceEvent*>(xev.xcookie.data);
459 if (xiev->sourceid >= kMaxDeviceNum || xiev->deviceid >= kMaxDeviceNum)
460 return SCROLL_TYPE_NO_SCROLL;
461 const int sourceid = xiev->sourceid;
462 ScrollInfo device_data = scroll_data_[sourceid];
463 return (device_data.vertical.number >= 0 ? SCROLL_TYPE_VERTICAL : 0) |
464 (device_data.horizontal.number >= 0 ? SCROLL_TYPE_HORIZONTAL : 0);
465 }
466
413 bool DeviceDataManagerX11::IsCMTGestureEvent( 467 bool DeviceDataManagerX11::IsCMTGestureEvent(
414 const base::NativeEvent& native_event) const { 468 const base::NativeEvent& native_event) const {
415 return (IsScrollEvent(native_event) || 469 return (IsScrollEvent(native_event) ||
416 IsFlingEvent(native_event) || 470 IsFlingEvent(native_event) ||
417 IsCMTMetricsEvent(native_event)); 471 IsCMTMetricsEvent(native_event));
418 } 472 }
419 473
420 bool DeviceDataManagerX11::HasEventData( 474 bool DeviceDataManagerX11::HasEventData(
421 const XIDeviceEvent* xiev, const DataType type) const { 475 const XIDeviceEvent* xiev, const DataType type) const {
422 const int idx = valuator_lookup_[xiev->sourceid][type]; 476 const int idx = valuator_lookup_[xiev->sourceid][type];
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
490 if (data.find(DT_CMT_SCROLL_Y) != data.end()) 544 if (data.find(DT_CMT_SCROLL_Y) != data.end())
491 *y_offset = data[DT_CMT_SCROLL_Y]; 545 *y_offset = data[DT_CMT_SCROLL_Y];
492 if (data.find(DT_CMT_ORDINAL_X) != data.end()) 546 if (data.find(DT_CMT_ORDINAL_X) != data.end())
493 *x_offset_ordinal = data[DT_CMT_ORDINAL_X]; 547 *x_offset_ordinal = data[DT_CMT_ORDINAL_X];
494 if (data.find(DT_CMT_ORDINAL_Y) != data.end()) 548 if (data.find(DT_CMT_ORDINAL_Y) != data.end())
495 *y_offset_ordinal = data[DT_CMT_ORDINAL_Y]; 549 *y_offset_ordinal = data[DT_CMT_ORDINAL_Y];
496 if (data.find(DT_CMT_FINGER_COUNT) != data.end()) 550 if (data.find(DT_CMT_FINGER_COUNT) != data.end())
497 *finger_count = static_cast<int>(data[DT_CMT_FINGER_COUNT]); 551 *finger_count = static_cast<int>(data[DT_CMT_FINGER_COUNT]);
498 } 552 }
499 553
554 void DeviceDataManagerX11::GetScrollClassOffsets(
555 const base::NativeEvent& native_event,
556 double* x_offset,
557 double* y_offset) {
558 XEvent& xev = *native_event;
559 if (xev.type != GenericEvent)
560 return;
561
562 *x_offset = 0;
563 *y_offset = 0;
564
565 XIDeviceEvent* xiev = static_cast<XIDeviceEvent*>(xev.xcookie.data);
566 if (xiev->sourceid >= kMaxDeviceNum || xiev->deviceid >= kMaxDeviceNum)
567 return;
568 const int sourceid = xiev->sourceid;
569 double* valuators = xiev->valuators.values;
570
571 ScrollInfo& info = scroll_data_[sourceid];
572
573 const int horizontal_number = info.horizontal.number;
574 const int vertical_number = info.vertical.number;
575
576 for (int i = 0; i <= valuator_count_[sourceid]; ++i) {
577 if (XIMaskIsSet(xiev->valuators.mask, i)) {
578 if (i == horizontal_number) {
579 double value = *valuators;
580 double delta = 0;
581
582 if (info.horizontal.seen)
583 delta = info.horizontal.position - value;
584
585 info.horizontal.seen = true;
586 info.horizontal.position = value;
587 *x_offset = delta;
588 NormalizeScrollData(sourceid, true, x_offset);
589 } else if (i == vertical_number) {
590 double value = *valuators;
591 double delta = 0;
592 if (info.vertical.seen)
593 delta = info.vertical.position - value;
594
595 info.vertical.seen = true;
596 info.vertical.position = value;
597 *y_offset = delta;
598 NormalizeScrollData(sourceid, false, y_offset);
599 }
600 valuators++;
601 }
602 }
603 }
604
605 void DeviceDataManagerX11::InvalidateScrollClasses() {
606 for (int i = 0; i < kMaxDeviceNum; i++) {
607 scroll_data_[i].horizontal.seen = false;
608 scroll_data_[i].vertical.seen = false;
609 }
610 }
611
500 void DeviceDataManagerX11::GetFlingData( 612 void DeviceDataManagerX11::GetFlingData(
501 const base::NativeEvent& native_event, 613 const base::NativeEvent& native_event,
502 float* vx, 614 float* vx,
503 float* vy, 615 float* vy,
504 float* vx_ordinal, 616 float* vx_ordinal,
505 float* vy_ordinal, 617 float* vy_ordinal,
506 bool* is_cancel) { 618 bool* is_cancel) {
507 *vx = 0; 619 *vx = 0;
508 *vy = 0; 620 *vy = 0;
509 *vx_ordinal = 0; 621 *vx_ordinal = 0;
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
583 double max_value; 695 double max_value;
584 double min_value; 696 double min_value;
585 if (GetDataRange(deviceid, type, &min_value, &max_value)) { 697 if (GetDataRange(deviceid, type, &min_value, &max_value)) {
586 *value = (*value - min_value) / (max_value - min_value); 698 *value = (*value - min_value) / (max_value - min_value);
587 DCHECK(*value >= 0.0 && *value <= 1.0); 699 DCHECK(*value >= 0.0 && *value <= 1.0);
588 return true; 700 return true;
589 } 701 }
590 return false; 702 return false;
591 } 703 }
592 704
705 bool DeviceDataManagerX11::NormalizeScrollData(unsigned int deviceid,
706 bool horizontal,
707 double* value) {
708 if (deviceid >= static_cast<unsigned int>(kMaxDeviceNum))
709 return false;
710 if (horizontal && scroll_data_[deviceid].horizontal.number < 0)
711 return false;
712 if (!horizontal && scroll_data_[deviceid].vertical.number < 0)
713 return false;
714 double increment = horizontal ?
715 scroll_data_[deviceid].horizontal.increment :
716 scroll_data_[deviceid].vertical.increment;
717
718 *value /= increment;
719 return true;
720 }
721
593 bool DeviceDataManagerX11::GetDataRange(unsigned int deviceid, 722 bool DeviceDataManagerX11::GetDataRange(unsigned int deviceid,
594 const DataType type, 723 const DataType type,
595 double* min, 724 double* min,
596 double* max) { 725 double* max) {
597 if (deviceid >= static_cast<unsigned int>(kMaxDeviceNum)) 726 if (deviceid >= static_cast<unsigned int>(kMaxDeviceNum))
598 return false; 727 return false;
599 if (valuator_lookup_[deviceid][type] >= 0) { 728 if (valuator_lookup_[deviceid][type] >= 0) {
600 *min = valuator_min_[deviceid][type]; 729 *min = valuator_min_[deviceid][type];
601 *max = valuator_max_[deviceid][type]; 730 *max = valuator_max_[deviceid][type];
602 return true; 731 return true;
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after
760 } else { 889 } else {
761 keyboards.erase(it); 890 keyboards.erase(it);
762 ++blocked_iter; 891 ++blocked_iter;
763 } 892 }
764 } 893 }
765 // Notify base class of updated list. 894 // Notify base class of updated list.
766 DeviceDataManager::OnKeyboardDevicesUpdated(keyboards); 895 DeviceDataManager::OnKeyboardDevicesUpdated(keyboards);
767 } 896 }
768 897
769 } // namespace ui 898 } // namespace ui
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698