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 #include "ui/aura/root_window_host_linux.h" | 5 #include "ui/aura/root_window_host_linux.h" |
6 | 6 |
7 #include <X11/cursorfont.h> | 7 #include <X11/cursorfont.h> |
8 #include <X11/extensions/Xfixes.h> | 8 #include <X11/extensions/Xfixes.h> |
9 #include <X11/extensions/XInput2.h> | 9 #include <X11/extensions/XInput2.h> |
10 #include <X11/extensions/Xrandr.h> | 10 #include <X11/extensions/Xrandr.h> |
(...skipping 13 matching lines...) Expand all Loading... |
24 #include "ui/aura/client/user_action_client.h" | 24 #include "ui/aura/client/user_action_client.h" |
25 #include "ui/aura/env.h" | 25 #include "ui/aura/env.h" |
26 #include "ui/aura/root_window.h" | 26 #include "ui/aura/root_window.h" |
27 #include "ui/base/cursor/cursor.h" | 27 #include "ui/base/cursor/cursor.h" |
28 #include "ui/base/events/event.h" | 28 #include "ui/base/events/event.h" |
29 #include "ui/base/keycodes/keyboard_codes.h" | 29 #include "ui/base/keycodes/keyboard_codes.h" |
30 #include "ui/base/touch/touch_factory.h" | 30 #include "ui/base/touch/touch_factory.h" |
31 #include "ui/base/ui_base_switches.h" | 31 #include "ui/base/ui_base_switches.h" |
32 #include "ui/base/view_prop.h" | 32 #include "ui/base/view_prop.h" |
33 #include "ui/base/x/valuators.h" | 33 #include "ui/base/x/valuators.h" |
34 #include "ui/base/x/x11_util.h" | |
35 #include "ui/compositor/dip_util.h" | 34 #include "ui/compositor/dip_util.h" |
36 #include "ui/compositor/layer.h" | 35 #include "ui/compositor/layer.h" |
37 #include "ui/gfx/codec/png_codec.h" | 36 #include "ui/gfx/codec/png_codec.h" |
38 #include "ui/gfx/screen.h" | 37 #include "ui/gfx/screen.h" |
39 | 38 |
40 #if defined(OS_CHROMEOS) | 39 #if defined(OS_CHROMEOS) |
41 #include "base/chromeos/chromeos_version.h" | 40 #include "base/chromeos/chromeos_version.h" |
42 #endif | 41 #endif |
43 | 42 |
44 using std::max; | 43 using std::max; |
(...skipping 23 matching lines...) Expand all Loading... |
68 NULL | 67 NULL |
69 }; | 68 }; |
70 | 69 |
71 ::Window FindEventTarget(const base::NativeEvent& xev) { | 70 ::Window FindEventTarget(const base::NativeEvent& xev) { |
72 ::Window target = xev->xany.window; | 71 ::Window target = xev->xany.window; |
73 if (xev->type == GenericEvent) | 72 if (xev->type == GenericEvent) |
74 target = static_cast<XIDeviceEvent*>(xev->xcookie.data)->event; | 73 target = static_cast<XIDeviceEvent*>(xev->xcookie.data)->event; |
75 return target; | 74 return target; |
76 } | 75 } |
77 | 76 |
| 77 // Coalesce all pending motion events (touch or mouse) that are at the top of |
| 78 // the queue, and return the number eliminated, storing the last one in |
| 79 // |last_event|. |
| 80 int CoalescePendingMotionEvents(const XEvent* xev, XEvent* last_event) { |
| 81 XIDeviceEvent* xievent = static_cast<XIDeviceEvent*>(xev->xcookie.data); |
| 82 int num_coalesed = 0; |
| 83 Display* display = xev->xany.display; |
| 84 int event_type = xev->xgeneric.evtype; |
| 85 |
| 86 #if defined(USE_XI2_MT) |
| 87 float tracking_id = -1; |
| 88 if (event_type == XI_TouchUpdate) { |
| 89 if (!ui::ValuatorTracker::GetInstance()->ExtractValuator(*xev, |
| 90 ui::ValuatorTracker::VAL_TRACKING_ID, &tracking_id)) |
| 91 tracking_id = -1; |
| 92 } |
| 93 #endif |
| 94 |
| 95 while (XPending(display)) { |
| 96 XEvent next_event; |
| 97 XPeekEvent(display, &next_event); |
| 98 |
| 99 // If we can't get the cookie, abort the check. |
| 100 if (!XGetEventData(next_event.xgeneric.display, &next_event.xcookie)) |
| 101 return num_coalesed; |
| 102 |
| 103 // If this isn't from a valid device, throw the event away, as |
| 104 // that's what the message pump would do. Device events come in pairs |
| 105 // with one from the master and one from the slave so there will |
| 106 // always be at least one pending. |
| 107 if (!ui::TouchFactory::GetInstance()->ShouldProcessXI2Event(&next_event)) { |
| 108 XFreeEventData(display, &next_event.xcookie); |
| 109 XNextEvent(display, &next_event); |
| 110 continue; |
| 111 } |
| 112 |
| 113 if (next_event.type == GenericEvent && |
| 114 next_event.xgeneric.evtype == event_type && |
| 115 !ui::GetScrollOffsets(&next_event, NULL, NULL)) { |
| 116 XIDeviceEvent* next_xievent = |
| 117 static_cast<XIDeviceEvent*>(next_event.xcookie.data); |
| 118 #if defined(USE_XI2_MT) |
| 119 float next_tracking_id = -1; |
| 120 if (event_type == XI_TouchUpdate) { |
| 121 // If this is a touch motion event (as opposed to mouse motion event), |
| 122 // then make sure the events are from the same touch-point. |
| 123 if (!ui::ValuatorTracker::GetInstance()->ExtractValuator(next_event, |
| 124 ui::ValuatorTracker::VAL_TRACKING_ID, &next_tracking_id)) |
| 125 next_tracking_id = -1; |
| 126 } |
| 127 #endif |
| 128 // Confirm that the motion event is targeted at the same window |
| 129 // and that no buttons or modifiers have changed. |
| 130 if (xievent->event == next_xievent->event && |
| 131 xievent->child == next_xievent->child && |
| 132 #if defined(USE_XI2_MT) |
| 133 (event_type == XI_Motion || tracking_id == next_tracking_id) && |
| 134 #endif |
| 135 xievent->buttons.mask_len == next_xievent->buttons.mask_len && |
| 136 (memcmp(xievent->buttons.mask, |
| 137 next_xievent->buttons.mask, |
| 138 xievent->buttons.mask_len) == 0) && |
| 139 xievent->mods.base == next_xievent->mods.base && |
| 140 xievent->mods.latched == next_xievent->mods.latched && |
| 141 xievent->mods.locked == next_xievent->mods.locked && |
| 142 xievent->mods.effective == next_xievent->mods.effective) { |
| 143 XFreeEventData(display, &next_event.xcookie); |
| 144 // Free the previous cookie. |
| 145 if (num_coalesed > 0) |
| 146 XFreeEventData(display, &last_event->xcookie); |
| 147 // Get the event and its cookie data. |
| 148 XNextEvent(display, last_event); |
| 149 XGetEventData(display, &last_event->xcookie); |
| 150 ++num_coalesed; |
| 151 continue; |
| 152 } else { |
| 153 // This isn't an event we want so free its cookie data. |
| 154 XFreeEventData(display, &next_event.xcookie); |
| 155 } |
| 156 } |
| 157 break; |
| 158 } |
| 159 return num_coalesed; |
| 160 } |
| 161 |
78 void SelectEventsForRootWindow() { | 162 void SelectEventsForRootWindow() { |
79 Display* display = ui::GetXDisplay(); | 163 Display* display = ui::GetXDisplay(); |
80 ::Window root_window = ui::GetX11RootWindow(); | 164 ::Window root_window = ui::GetX11RootWindow(); |
81 | 165 |
82 // Receive resize events for the root-window so |x_root_bounds_| can be | 166 // Receive resize events for the root-window so |x_root_bounds_| can be |
83 // updated. | 167 // updated. |
84 XWindowAttributes attr; | 168 XWindowAttributes attr; |
85 XGetWindowAttributes(display, root_window, &attr); | 169 XGetWindowAttributes(display, root_window, &attr); |
86 if (!(attr.your_event_mask & StructureNotifyMask)) { | 170 if (!(attr.your_event_mask & StructureNotifyMask)) { |
87 XSelectInput(display, root_window, | 171 XSelectInput(display, root_window, |
(...skipping 366 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
454 XEvent* xev = event; | 538 XEvent* xev = event; |
455 if (!factory->ShouldProcessXI2Event(xev)) | 539 if (!factory->ShouldProcessXI2Event(xev)) |
456 return; | 540 return; |
457 | 541 |
458 ui::EventType type = ui::EventTypeFromNative(xev); | 542 ui::EventType type = ui::EventTypeFromNative(xev); |
459 XEvent last_event; | 543 XEvent last_event; |
460 int num_coalesced = 0; | 544 int num_coalesced = 0; |
461 | 545 |
462 switch (type) { | 546 switch (type) { |
463 case ui::ET_TOUCH_MOVED: | 547 case ui::ET_TOUCH_MOVED: |
464 num_coalesced = ui::CoalescePendingMotionEvents(xev, &last_event); | 548 num_coalesced = CoalescePendingMotionEvents(xev, &last_event); |
465 if (num_coalesced > 0) | 549 if (num_coalesced > 0) |
466 xev = &last_event; | 550 xev = &last_event; |
467 // fallthrough | 551 // fallthrough |
468 case ui::ET_TOUCH_PRESSED: | 552 case ui::ET_TOUCH_PRESSED: |
469 case ui::ET_TOUCH_RELEASED: { | 553 case ui::ET_TOUCH_RELEASED: { |
470 ui::TouchEvent touchev(xev); | 554 ui::TouchEvent touchev(xev); |
471 #if defined(OS_CHROMEOS) | 555 #if defined(OS_CHROMEOS) |
472 // X maps the touch-surface to the size of the X root-window. In | 556 // X maps the touch-surface to the size of the X root-window. In |
473 // multi-monitor setup, the X root-window size is a combination of | 557 // multi-monitor setup, the X root-window size is a combination of |
474 // both the monitor sizes. So it is necessary to remap the location of | 558 // both the monitor sizes. So it is necessary to remap the location of |
(...skipping 18 matching lines...) Expand all Loading... |
493 } | 577 } |
494 case ui::ET_MOUSE_MOVED: | 578 case ui::ET_MOUSE_MOVED: |
495 case ui::ET_MOUSE_DRAGGED: | 579 case ui::ET_MOUSE_DRAGGED: |
496 case ui::ET_MOUSE_PRESSED: | 580 case ui::ET_MOUSE_PRESSED: |
497 case ui::ET_MOUSE_RELEASED: | 581 case ui::ET_MOUSE_RELEASED: |
498 case ui::ET_MOUSE_ENTERED: | 582 case ui::ET_MOUSE_ENTERED: |
499 case ui::ET_MOUSE_EXITED: { | 583 case ui::ET_MOUSE_EXITED: { |
500 if (type == ui::ET_MOUSE_MOVED || type == ui::ET_MOUSE_DRAGGED) { | 584 if (type == ui::ET_MOUSE_MOVED || type == ui::ET_MOUSE_DRAGGED) { |
501 // If this is a motion event, we want to coalesce all pending motion | 585 // If this is a motion event, we want to coalesce all pending motion |
502 // events that are at the top of the queue. | 586 // events that are at the top of the queue. |
503 num_coalesced = ui::CoalescePendingMotionEvents(xev, &last_event); | 587 num_coalesced = CoalescePendingMotionEvents(xev, &last_event); |
504 if (num_coalesced > 0) | 588 if (num_coalesced > 0) |
505 xev = &last_event; | 589 xev = &last_event; |
506 } else if (type == ui::ET_MOUSE_PRESSED) { | 590 } else if (type == ui::ET_MOUSE_PRESSED) { |
507 XIDeviceEvent* xievent = | 591 XIDeviceEvent* xievent = |
508 static_cast<XIDeviceEvent*>(xev->xcookie.data); | 592 static_cast<XIDeviceEvent*>(xev->xcookie.data); |
509 int button = xievent->detail; | 593 int button = xievent->detail; |
510 if (button == kBackMouseButton || button == kForwardMouseButton) { | 594 if (button == kBackMouseButton || button == kForwardMouseButton) { |
511 client::UserActionClient* gesture_client = | 595 client::UserActionClient* gesture_client = |
512 client::GetUserActionClient(delegate_->AsRootWindow()); | 596 client::GetUserActionClient(delegate_->AsRootWindow()); |
513 if (gesture_client) { | 597 if (gesture_client) { |
(...skipping 347 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
861 return new RootWindowHostLinux(bounds); | 945 return new RootWindowHostLinux(bounds); |
862 } | 946 } |
863 | 947 |
864 // static | 948 // static |
865 gfx::Size RootWindowHost::GetNativeScreenSize() { | 949 gfx::Size RootWindowHost::GetNativeScreenSize() { |
866 ::Display* xdisplay = base::MessagePumpAuraX11::GetDefaultXDisplay(); | 950 ::Display* xdisplay = base::MessagePumpAuraX11::GetDefaultXDisplay(); |
867 return gfx::Size(DisplayWidth(xdisplay, 0), DisplayHeight(xdisplay, 0)); | 951 return gfx::Size(DisplayWidth(xdisplay, 0), DisplayHeight(xdisplay, 0)); |
868 } | 952 } |
869 | 953 |
870 } // namespace aura | 954 } // namespace aura |
OLD | NEW |