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" |
34 #include "ui/compositor/dip_util.h" | 35 #include "ui/compositor/dip_util.h" |
35 #include "ui/compositor/layer.h" | 36 #include "ui/compositor/layer.h" |
36 #include "ui/gfx/codec/png_codec.h" | 37 #include "ui/gfx/codec/png_codec.h" |
37 #include "ui/gfx/screen.h" | 38 #include "ui/gfx/screen.h" |
38 | 39 |
39 #if defined(OS_CHROMEOS) | 40 #if defined(OS_CHROMEOS) |
40 #include "base/chromeos/chromeos_version.h" | 41 #include "base/chromeos/chromeos_version.h" |
41 #endif | 42 #endif |
42 | 43 |
43 using std::max; | 44 using std::max; |
(...skipping 23 matching lines...) Expand all Loading... |
67 NULL | 68 NULL |
68 }; | 69 }; |
69 | 70 |
70 ::Window FindEventTarget(const base::NativeEvent& xev) { | 71 ::Window FindEventTarget(const base::NativeEvent& xev) { |
71 ::Window target = xev->xany.window; | 72 ::Window target = xev->xany.window; |
72 if (xev->type == GenericEvent) | 73 if (xev->type == GenericEvent) |
73 target = static_cast<XIDeviceEvent*>(xev->xcookie.data)->event; | 74 target = static_cast<XIDeviceEvent*>(xev->xcookie.data)->event; |
74 return target; | 75 return target; |
75 } | 76 } |
76 | 77 |
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 | |
162 void SelectEventsForRootWindow() { | 78 void SelectEventsForRootWindow() { |
163 Display* display = ui::GetXDisplay(); | 79 Display* display = ui::GetXDisplay(); |
164 ::Window root_window = ui::GetX11RootWindow(); | 80 ::Window root_window = ui::GetX11RootWindow(); |
165 | 81 |
166 // Receive resize events for the root-window so |x_root_bounds_| can be | 82 // Receive resize events for the root-window so |x_root_bounds_| can be |
167 // updated. | 83 // updated. |
168 XWindowAttributes attr; | 84 XWindowAttributes attr; |
169 XGetWindowAttributes(display, root_window, &attr); | 85 XGetWindowAttributes(display, root_window, &attr); |
170 if (!(attr.your_event_mask & StructureNotifyMask)) { | 86 if (!(attr.your_event_mask & StructureNotifyMask)) { |
171 XSelectInput(display, root_window, | 87 XSelectInput(display, root_window, |
(...skipping 366 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
538 XEvent* xev = event; | 454 XEvent* xev = event; |
539 if (!factory->ShouldProcessXI2Event(xev)) | 455 if (!factory->ShouldProcessXI2Event(xev)) |
540 return; | 456 return; |
541 | 457 |
542 ui::EventType type = ui::EventTypeFromNative(xev); | 458 ui::EventType type = ui::EventTypeFromNative(xev); |
543 XEvent last_event; | 459 XEvent last_event; |
544 int num_coalesced = 0; | 460 int num_coalesced = 0; |
545 | 461 |
546 switch (type) { | 462 switch (type) { |
547 case ui::ET_TOUCH_MOVED: | 463 case ui::ET_TOUCH_MOVED: |
548 num_coalesced = CoalescePendingMotionEvents(xev, &last_event); | 464 num_coalesced = ui::CoalescePendingMotionEvents(xev, &last_event); |
549 if (num_coalesced > 0) | 465 if (num_coalesced > 0) |
550 xev = &last_event; | 466 xev = &last_event; |
551 // fallthrough | 467 // fallthrough |
552 case ui::ET_TOUCH_PRESSED: | 468 case ui::ET_TOUCH_PRESSED: |
553 case ui::ET_TOUCH_RELEASED: { | 469 case ui::ET_TOUCH_RELEASED: { |
554 ui::TouchEvent touchev(xev); | 470 ui::TouchEvent touchev(xev); |
555 #if defined(OS_CHROMEOS) | 471 #if defined(OS_CHROMEOS) |
556 // X maps the touch-surface to the size of the X root-window. In | 472 // X maps the touch-surface to the size of the X root-window. In |
557 // multi-monitor setup, the X root-window size is a combination of | 473 // multi-monitor setup, the X root-window size is a combination of |
558 // both the monitor sizes. So it is necessary to remap the location of | 474 // both the monitor sizes. So it is necessary to remap the location of |
(...skipping 18 matching lines...) Expand all Loading... |
577 } | 493 } |
578 case ui::ET_MOUSE_MOVED: | 494 case ui::ET_MOUSE_MOVED: |
579 case ui::ET_MOUSE_DRAGGED: | 495 case ui::ET_MOUSE_DRAGGED: |
580 case ui::ET_MOUSE_PRESSED: | 496 case ui::ET_MOUSE_PRESSED: |
581 case ui::ET_MOUSE_RELEASED: | 497 case ui::ET_MOUSE_RELEASED: |
582 case ui::ET_MOUSE_ENTERED: | 498 case ui::ET_MOUSE_ENTERED: |
583 case ui::ET_MOUSE_EXITED: { | 499 case ui::ET_MOUSE_EXITED: { |
584 if (type == ui::ET_MOUSE_MOVED || type == ui::ET_MOUSE_DRAGGED) { | 500 if (type == ui::ET_MOUSE_MOVED || type == ui::ET_MOUSE_DRAGGED) { |
585 // If this is a motion event, we want to coalesce all pending motion | 501 // If this is a motion event, we want to coalesce all pending motion |
586 // events that are at the top of the queue. | 502 // events that are at the top of the queue. |
587 num_coalesced = CoalescePendingMotionEvents(xev, &last_event); | 503 num_coalesced = ui::CoalescePendingMotionEvents(xev, &last_event); |
588 if (num_coalesced > 0) | 504 if (num_coalesced > 0) |
589 xev = &last_event; | 505 xev = &last_event; |
590 } else if (type == ui::ET_MOUSE_PRESSED) { | 506 } else if (type == ui::ET_MOUSE_PRESSED) { |
591 XIDeviceEvent* xievent = | 507 XIDeviceEvent* xievent = |
592 static_cast<XIDeviceEvent*>(xev->xcookie.data); | 508 static_cast<XIDeviceEvent*>(xev->xcookie.data); |
593 int button = xievent->detail; | 509 int button = xievent->detail; |
594 if (button == kBackMouseButton || button == kForwardMouseButton) { | 510 if (button == kBackMouseButton || button == kForwardMouseButton) { |
595 client::UserActionClient* gesture_client = | 511 client::UserActionClient* gesture_client = |
596 client::GetUserActionClient(delegate_->AsRootWindow()); | 512 client::GetUserActionClient(delegate_->AsRootWindow()); |
597 if (gesture_client) { | 513 if (gesture_client) { |
(...skipping 347 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
945 return new RootWindowHostLinux(bounds); | 861 return new RootWindowHostLinux(bounds); |
946 } | 862 } |
947 | 863 |
948 // static | 864 // static |
949 gfx::Size RootWindowHost::GetNativeScreenSize() { | 865 gfx::Size RootWindowHost::GetNativeScreenSize() { |
950 ::Display* xdisplay = base::MessagePumpAuraX11::GetDefaultXDisplay(); | 866 ::Display* xdisplay = base::MessagePumpAuraX11::GetDefaultXDisplay(); |
951 return gfx::Size(DisplayWidth(xdisplay, 0), DisplayHeight(xdisplay, 0)); | 867 return gfx::Size(DisplayWidth(xdisplay, 0), DisplayHeight(xdisplay, 0)); |
952 } | 868 } |
953 | 869 |
954 } // namespace aura | 870 } // namespace aura |
OLD | NEW |