OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 // This file defines utility functions for X11 (Linux only). This code has been | 5 // This file defines utility functions for X11 (Linux only). This code has been |
6 // ported from XCB since we can't use XCB on Ubuntu while its 32-bit support | 6 // ported from XCB since we can't use XCB on Ubuntu while its 32-bit support |
7 // remains woefully incomplete. | 7 // remains woefully incomplete. |
8 | 8 |
9 #include "ui/base/x/x11_util.h" | 9 #include "ui/base/x/x11_util.h" |
10 | 10 |
(...skipping 426 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
437 } | 437 } |
438 | 438 |
439 | 439 |
440 int CoalescePendingMotionEvents(const XEvent* xev, | 440 int CoalescePendingMotionEvents(const XEvent* xev, |
441 XEvent* last_event) { | 441 XEvent* last_event) { |
442 XIDeviceEvent* xievent = static_cast<XIDeviceEvent*>(xev->xcookie.data); | 442 XIDeviceEvent* xievent = static_cast<XIDeviceEvent*>(xev->xcookie.data); |
443 int num_coalesced = 0; | 443 int num_coalesced = 0; |
444 XDisplay* display = xev->xany.display; | 444 XDisplay* display = xev->xany.display; |
445 int event_type = xev->xgeneric.evtype; | 445 int event_type = xev->xgeneric.evtype; |
446 | 446 |
447 DCHECK_EQ(event_type, XI_Motion); | 447 DCHECK(event_type == XI_Motion || event_type == XI_TouchUpdate); |
448 | 448 |
449 while (XPending(display)) { | 449 while (XPending(display)) { |
450 XEvent next_event; | 450 XEvent next_event; |
451 XPeekEvent(display, &next_event); | 451 XPeekEvent(display, &next_event); |
452 | 452 |
453 // If we can't get the cookie, abort the check. | 453 // If we can't get the cookie, abort the check. |
454 if (!XGetEventData(next_event.xgeneric.display, &next_event.xcookie)) | 454 if (!XGetEventData(next_event.xgeneric.display, &next_event.xcookie)) |
455 return num_coalesced; | 455 return num_coalesced; |
456 | 456 |
457 // If this isn't from a valid device, throw the event away, as | 457 // If this isn't from a valid device, throw the event away, as |
458 // that's what the message pump would do. Device events come in pairs | 458 // that's what the message pump would do. Device events come in pairs |
459 // with one from the master and one from the slave so there will | 459 // with one from the master and one from the slave so there will |
460 // always be at least one pending. | 460 // always be at least one pending. |
461 if (!ui::TouchFactory::GetInstance()->ShouldProcessXI2Event(&next_event)) { | 461 if (!ui::TouchFactory::GetInstance()->ShouldProcessXI2Event(&next_event)) { |
462 XFreeEventData(display, &next_event.xcookie); | 462 XFreeEventData(display, &next_event.xcookie); |
463 XNextEvent(display, &next_event); | 463 XNextEvent(display, &next_event); |
464 continue; | 464 continue; |
465 } | 465 } |
466 | 466 |
467 if (next_event.type == GenericEvent && | 467 if (next_event.type == GenericEvent && |
468 next_event.xgeneric.evtype == event_type && | 468 next_event.xgeneric.evtype == event_type && |
469 !ui::DeviceDataManager::GetInstance()->IsCMTGestureEvent( | 469 !ui::DeviceDataManager::GetInstance()->IsCMTGestureEvent( |
470 &next_event)) { | 470 &next_event)) { |
471 XIDeviceEvent* next_xievent = | 471 XIDeviceEvent* next_xievent = |
472 static_cast<XIDeviceEvent*>(next_event.xcookie.data); | 472 static_cast<XIDeviceEvent*>(next_event.xcookie.data); |
473 // Confirm that the motion event is targeted at the same window | 473 // Confirm that the motion event is targeted at the same window |
474 // and that no buttons or modifiers have changed. | 474 // and that no buttons or modifiers have changed. |
475 if (xievent->event == next_xievent->event && | 475 if (xievent->event == next_xievent->event && |
476 xievent->child == next_xievent->child && | 476 xievent->child == next_xievent->child && |
| 477 xievent->detail == next_xievent->detail && |
477 xievent->buttons.mask_len == next_xievent->buttons.mask_len && | 478 xievent->buttons.mask_len == next_xievent->buttons.mask_len && |
478 (memcmp(xievent->buttons.mask, | 479 (memcmp(xievent->buttons.mask, |
479 next_xievent->buttons.mask, | 480 next_xievent->buttons.mask, |
480 xievent->buttons.mask_len) == 0) && | 481 xievent->buttons.mask_len) == 0) && |
481 xievent->mods.base == next_xievent->mods.base && | 482 xievent->mods.base == next_xievent->mods.base && |
482 xievent->mods.latched == next_xievent->mods.latched && | 483 xievent->mods.latched == next_xievent->mods.latched && |
483 xievent->mods.locked == next_xievent->mods.locked && | 484 xievent->mods.locked == next_xievent->mods.locked && |
484 xievent->mods.effective == next_xievent->mods.effective) { | 485 xievent->mods.effective == next_xievent->mods.effective) { |
485 XFreeEventData(display, &next_event.xcookie); | 486 XFreeEventData(display, &next_event.xcookie); |
486 // Free the previous cookie. | 487 // Free the previous cookie. |
487 if (num_coalesced > 0) | 488 if (num_coalesced > 0) |
488 XFreeEventData(display, &last_event->xcookie); | 489 XFreeEventData(display, &last_event->xcookie); |
489 // Get the event and its cookie data. | 490 // Get the event and its cookie data. |
490 XNextEvent(display, last_event); | 491 XNextEvent(display, last_event); |
491 XGetEventData(display, &last_event->xcookie); | 492 XGetEventData(display, &last_event->xcookie); |
492 ++num_coalesced; | 493 ++num_coalesced; |
493 continue; | 494 continue; |
494 } | 495 } |
495 } | 496 } |
496 // This isn't an event we want so free its cookie data. | 497 // This isn't an event we want so free its cookie data. |
497 XFreeEventData(display, &next_event.xcookie); | 498 XFreeEventData(display, &next_event.xcookie); |
498 break; | 499 break; |
499 } | 500 } |
500 | 501 |
501 if (num_coalesced > 0) { | 502 if (event_type == XI_Motion && num_coalesced > 0) { |
502 base::TimeDelta delta = ui::EventTimeFromNative(last_event) - | 503 base::TimeDelta delta = ui::EventTimeFromNative(last_event) - |
503 ui::EventTimeFromNative(const_cast<XEvent*>(xev)); | 504 ui::EventTimeFromNative(const_cast<XEvent*>(xev)); |
504 UMA_HISTOGRAM_COUNTS_10000("Event.CoalescedCount.Mouse", num_coalesced); | 505 UMA_HISTOGRAM_COUNTS_10000("Event.CoalescedCount.Mouse", num_coalesced); |
505 UMA_HISTOGRAM_TIMES("Event.CoalescedLatency.Mouse", delta); | 506 UMA_HISTOGRAM_TIMES("Event.CoalescedLatency.Mouse", delta); |
506 } | 507 } |
507 return num_coalesced; | 508 return num_coalesced; |
508 } | 509 } |
509 #endif | 510 #endif |
510 | 511 |
511 void HideHostCursor() { | 512 void HideHostCursor() { |
(...skipping 1020 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1532 << "request_code " << static_cast<int>(error_event.request_code) << ", " | 1533 << "request_code " << static_cast<int>(error_event.request_code) << ", " |
1533 << "minor_code " << static_cast<int>(error_event.minor_code) | 1534 << "minor_code " << static_cast<int>(error_event.minor_code) |
1534 << " (" << request_str << ")"; | 1535 << " (" << request_str << ")"; |
1535 } | 1536 } |
1536 | 1537 |
1537 // ---------------------------------------------------------------------------- | 1538 // ---------------------------------------------------------------------------- |
1538 // End of x11_util_internal.h | 1539 // End of x11_util_internal.h |
1539 | 1540 |
1540 | 1541 |
1541 } // namespace ui | 1542 } // namespace ui |
OLD | NEW |