OLD | NEW |
---|---|
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/platform/x11/x11_event_source.h" | 5 #include "ui/events/platform/x11/x11_event_source.h" |
6 | 6 |
7 #include <X11/Xatom.h> | 7 #include <X11/Xatom.h> |
8 #include <X11/XKBlib.h> | 8 #include <X11/XKBlib.h> |
9 #include <X11/Xlib.h> | 9 #include <X11/Xlib.h> |
10 | 10 |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
89 } | 89 } |
90 | 90 |
91 } // namespace | 91 } // namespace |
92 | 92 |
93 X11EventSource* X11EventSource::instance_ = nullptr; | 93 X11EventSource* X11EventSource::instance_ = nullptr; |
94 | 94 |
95 X11EventSource::X11EventSource(X11EventSourceDelegate* delegate, | 95 X11EventSource::X11EventSource(X11EventSourceDelegate* delegate, |
96 XDisplay* display) | 96 XDisplay* display) |
97 : delegate_(delegate), | 97 : delegate_(delegate), |
98 display_(display), | 98 display_(display), |
99 event_timestamp_(CurrentTime), | |
100 dummy_initialized_(false), | 99 dummy_initialized_(false), |
101 continue_stream_(true) { | 100 continue_stream_(true) { |
102 DCHECK(!instance_); | 101 DCHECK(!instance_); |
103 instance_ = this; | 102 instance_ = this; |
104 | 103 |
105 DCHECK(delegate_); | 104 DCHECK(delegate_); |
106 DCHECK(display_); | 105 DCHECK(display_); |
107 DeviceDataManagerX11::CreateInstance(); | 106 DeviceDataManagerX11::CreateInstance(); |
108 InitializeXkb(display_); | 107 InitializeXkb(display_); |
109 } | 108 } |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
177 XIfEvent(display_, &event, IsPropertyNotifyForTimestamp, | 176 XIfEvent(display_, &event, IsPropertyNotifyForTimestamp, |
178 reinterpret_cast<XPointer>(&dummy_window_)); | 177 reinterpret_cast<XPointer>(&dummy_window_)); |
179 | 178 |
180 UMA_HISTOGRAM_CUSTOM_COUNTS( | 179 UMA_HISTOGRAM_CUSTOM_COUNTS( |
181 "Linux.X11.ServerRTT", (base::TimeTicks::Now() - start).InMicroseconds(), | 180 "Linux.X11.ServerRTT", (base::TimeTicks::Now() - start).InMicroseconds(), |
182 1, base::TimeDelta::FromMilliseconds(50).InMicroseconds(), 50); | 181 1, base::TimeDelta::FromMilliseconds(50).InMicroseconds(), 50); |
183 return event.xproperty.time; | 182 return event.xproperty.time; |
184 } | 183 } |
185 | 184 |
186 Time X11EventSource::GetTimestamp() { | 185 Time X11EventSource::GetTimestamp() { |
187 if (event_timestamp_ != CurrentTime) { | 186 if (!dispatching_events_.empty()) { |
188 return event_timestamp_; | 187 Time timestamp = ExtractTimeFromXEvent(*dispatching_events_.top()); |
188 if (timestamp != CurrentTime) | |
189 return timestamp; | |
189 } | 190 } |
190 DVLOG(1) << "Making a round trip to get a recent server timestamp."; | 191 DVLOG(1) << "Making a round trip to get a recent server timestamp."; |
191 return GetCurrentServerTime(); | 192 return GetCurrentServerTime(); |
192 } | 193 } |
193 | 194 |
195 base::Optional<gfx::Point> | |
196 X11EventSource::GetRootCursorLocationFromCurrentEvent() const { | |
197 XEvent* event = | |
sadrul
2016/10/11 16:25:02
Early return if |dispatching_events_| is empty.
Tom (Use chromium acct)
2016/10/11 18:00:19
Done.
| |
198 dispatching_events_.empty() ? nullptr : dispatching_events_.top(); | |
199 | |
200 if (event) { | |
201 switch (event->type) { | |
202 case ButtonPress: | |
203 case ButtonRelease: | |
204 return gfx::Point(event->xbutton.x_root, event->xbutton.y_root); | |
205 case MotionNotify: | |
206 return gfx::Point(event->xmotion.x_root, event->xmotion.y_root); | |
207 case EnterNotify: | |
208 case LeaveNotify: | |
209 return gfx::Point(event->xcrossing.x_root, event->xcrossing.y_root); | |
210 case GenericEvent: | |
211 if (!ui::TouchFactory::GetInstance()->ShouldProcessXI2Event(event)) | |
212 break; | |
213 const XIEvent* xi_event = | |
214 static_cast<const XIEvent*>(event->xcookie.data); | |
215 switch (xi_event->evtype) { | |
216 case XI_ButtonPress: | |
217 case XI_ButtonRelease: | |
218 case XI_Motion: { | |
219 const XIDeviceEvent* device_event = | |
220 static_cast<const XIDeviceEvent*>(event->xcookie.data); | |
221 return gfx::Point(device_event->root_x, device_event->root_y); | |
222 } | |
223 case XI_Enter: | |
224 case XI_Leave: { | |
225 const XIEnterEvent* enter_event = | |
226 static_cast<const XIEnterEvent*>(event->xcookie.data); | |
227 return gfx::Point(enter_event->root_x, enter_event->root_y); | |
228 } | |
229 } | |
230 } | |
231 } | |
sadrul
2016/10/11 16:25:02
Use ui::EventSystemLocationFromNative(), e.g.:
b
Tom (Use chromium acct)
2016/10/11 18:00:19
Done.
| |
232 | |
233 return base::Optional<gfx::Point>(); | |
sadrul
2016/10/11 16:25:02
return base::nullopt?
Tom (Use chromium acct)
2016/10/11 18:00:19
Done.
| |
234 } | |
235 | |
194 //////////////////////////////////////////////////////////////////////////////// | 236 //////////////////////////////////////////////////////////////////////////////// |
195 // X11EventSource, protected | 237 // X11EventSource, protected |
196 | 238 |
197 void X11EventSource::ExtractCookieDataDispatchEvent(XEvent* xevent) { | 239 void X11EventSource::ExtractCookieDataDispatchEvent(XEvent* xevent) { |
198 bool have_cookie = false; | 240 bool have_cookie = false; |
199 if (xevent->type == GenericEvent && | 241 if (xevent->type == GenericEvent && |
200 XGetEventData(xevent->xgeneric.display, &xevent->xcookie)) { | 242 XGetEventData(xevent->xgeneric.display, &xevent->xcookie)) { |
201 have_cookie = true; | 243 have_cookie = true; |
202 } | 244 } |
203 | 245 |
204 event_timestamp_ = ExtractTimeFromXEvent(*xevent); | 246 dispatching_events_.push(xevent); |
205 | 247 |
206 delegate_->ProcessXEvent(xevent); | 248 delegate_->ProcessXEvent(xevent); |
207 PostDispatchEvent(xevent); | 249 PostDispatchEvent(xevent); |
208 | 250 |
209 event_timestamp_ = CurrentTime; | 251 dispatching_events_.pop(); |
210 | 252 |
211 if (have_cookie) | 253 if (have_cookie) |
212 XFreeEventData(xevent->xgeneric.display, &xevent->xcookie); | 254 XFreeEventData(xevent->xgeneric.display, &xevent->xcookie); |
213 } | 255 } |
214 | 256 |
215 void X11EventSource::PostDispatchEvent(XEvent* xevent) { | 257 void X11EventSource::PostDispatchEvent(XEvent* xevent) { |
216 bool should_update_device_list = false; | 258 bool should_update_device_list = false; |
217 | 259 |
218 if (xevent->type == GenericEvent) { | 260 if (xevent->type == GenericEvent) { |
219 if (xevent->xgeneric.evtype == XI_HierarchyChanged) { | 261 if (xevent->xgeneric.evtype == XI_HierarchyChanged) { |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
260 | 302 |
261 void X11EventSource::OnDispatcherListChanged() { | 303 void X11EventSource::OnDispatcherListChanged() { |
262 if (!hotplug_event_handler_) { | 304 if (!hotplug_event_handler_) { |
263 hotplug_event_handler_.reset(new X11HotplugEventHandler()); | 305 hotplug_event_handler_.reset(new X11HotplugEventHandler()); |
264 // Force the initial device query to have an update list of active devices. | 306 // Force the initial device query to have an update list of active devices. |
265 hotplug_event_handler_->OnHotplugEvent(); | 307 hotplug_event_handler_->OnHotplugEvent(); |
266 } | 308 } |
267 } | 309 } |
268 | 310 |
269 } // namespace ui | 311 } // namespace ui |
OLD | NEW |