| 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 dispatching_event_(nullptr), |
| 99 dummy_initialized_(false), | 100 dummy_initialized_(false), |
| 100 continue_stream_(true) { | 101 continue_stream_(true) { |
| 101 DCHECK(!instance_); | 102 DCHECK(!instance_); |
| 102 instance_ = this; | 103 instance_ = this; |
| 103 | 104 |
| 104 DCHECK(delegate_); | 105 DCHECK(delegate_); |
| 105 DCHECK(display_); | 106 DCHECK(display_); |
| 106 DeviceDataManagerX11::CreateInstance(); | 107 DeviceDataManagerX11::CreateInstance(); |
| 107 InitializeXkb(display_); | 108 InitializeXkb(display_); |
| 108 } | 109 } |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 176 XIfEvent(display_, &event, IsPropertyNotifyForTimestamp, | 177 XIfEvent(display_, &event, IsPropertyNotifyForTimestamp, |
| 177 reinterpret_cast<XPointer>(&dummy_window_)); | 178 reinterpret_cast<XPointer>(&dummy_window_)); |
| 178 | 179 |
| 179 UMA_HISTOGRAM_CUSTOM_COUNTS( | 180 UMA_HISTOGRAM_CUSTOM_COUNTS( |
| 180 "Linux.X11.ServerRTT", (base::TimeTicks::Now() - start).InMicroseconds(), | 181 "Linux.X11.ServerRTT", (base::TimeTicks::Now() - start).InMicroseconds(), |
| 181 1, base::TimeDelta::FromMilliseconds(50).InMicroseconds(), 50); | 182 1, base::TimeDelta::FromMilliseconds(50).InMicroseconds(), 50); |
| 182 return event.xproperty.time; | 183 return event.xproperty.time; |
| 183 } | 184 } |
| 184 | 185 |
| 185 Time X11EventSource::GetTimestamp() { | 186 Time X11EventSource::GetTimestamp() { |
| 186 if (!dispatching_events_.empty()) { | 187 if (dispatching_event_) { |
| 187 DCHECK(dispatching_events_.top()); | 188 Time timestamp = ExtractTimeFromXEvent(*dispatching_event_); |
| 188 Time timestamp = ExtractTimeFromXEvent(*dispatching_events_.top()); | |
| 189 if (timestamp != CurrentTime) | 189 if (timestamp != CurrentTime) |
| 190 return timestamp; | 190 return timestamp; |
| 191 } | 191 } |
| 192 DVLOG(1) << "Making a round trip to get a recent server timestamp."; | 192 DVLOG(1) << "Making a round trip to get a recent server timestamp."; |
| 193 return GetCurrentServerTime(); | 193 return GetCurrentServerTime(); |
| 194 } | 194 } |
| 195 | 195 |
| 196 base::Optional<gfx::Point> | 196 base::Optional<gfx::Point> |
| 197 X11EventSource::GetRootCursorLocationFromCurrentEvent() const { | 197 X11EventSource::GetRootCursorLocationFromCurrentEvent() const { |
| 198 if (dispatching_events_.empty()) | 198 if (!dispatching_event_) |
| 199 return base::nullopt; | 199 return base::nullopt; |
| 200 | 200 |
| 201 XEvent* event = dispatching_events_.top(); | 201 XEvent* event = dispatching_event_; |
| 202 DCHECK(event); | 202 DCHECK(event); |
| 203 | 203 |
| 204 bool is_xi2_event = event->type == GenericEvent; | 204 bool is_xi2_event = event->type == GenericEvent; |
| 205 int event_type = is_xi2_event | 205 int event_type = is_xi2_event |
| 206 ? reinterpret_cast<XIDeviceEvent*>(event)->evtype | 206 ? reinterpret_cast<XIDeviceEvent*>(event)->evtype |
| 207 : event->type; | 207 : event->type; |
| 208 | 208 |
| 209 bool is_valid_event = false; | 209 bool is_valid_event = false; |
| 210 static_assert(XI_ButtonPress == ButtonPress, ""); | 210 static_assert(XI_ButtonPress == ButtonPress, ""); |
| 211 static_assert(XI_ButtonRelease == ButtonRelease, ""); | 211 static_assert(XI_ButtonRelease == ButtonRelease, ""); |
| (...skipping 20 matching lines...) Expand all Loading... |
| 232 //////////////////////////////////////////////////////////////////////////////// | 232 //////////////////////////////////////////////////////////////////////////////// |
| 233 // X11EventSource, protected | 233 // X11EventSource, protected |
| 234 | 234 |
| 235 void X11EventSource::ExtractCookieDataDispatchEvent(XEvent* xevent) { | 235 void X11EventSource::ExtractCookieDataDispatchEvent(XEvent* xevent) { |
| 236 bool have_cookie = false; | 236 bool have_cookie = false; |
| 237 if (xevent->type == GenericEvent && | 237 if (xevent->type == GenericEvent && |
| 238 XGetEventData(xevent->xgeneric.display, &xevent->xcookie)) { | 238 XGetEventData(xevent->xgeneric.display, &xevent->xcookie)) { |
| 239 have_cookie = true; | 239 have_cookie = true; |
| 240 } | 240 } |
| 241 | 241 |
| 242 dispatching_events_.push(xevent); | 242 dispatching_event_ = xevent; |
| 243 | 243 |
| 244 delegate_->ProcessXEvent(xevent); | 244 delegate_->ProcessXEvent(xevent); |
| 245 PostDispatchEvent(xevent); | 245 PostDispatchEvent(xevent); |
| 246 | 246 |
| 247 dispatching_events_.pop(); | 247 dispatching_event_ = nullptr; |
| 248 | 248 |
| 249 if (have_cookie) | 249 if (have_cookie) |
| 250 XFreeEventData(xevent->xgeneric.display, &xevent->xcookie); | 250 XFreeEventData(xevent->xgeneric.display, &xevent->xcookie); |
| 251 } | 251 } |
| 252 | 252 |
| 253 void X11EventSource::PostDispatchEvent(XEvent* xevent) { | 253 void X11EventSource::PostDispatchEvent(XEvent* xevent) { |
| 254 bool should_update_device_list = false; | 254 bool should_update_device_list = false; |
| 255 | 255 |
| 256 if (xevent->type == GenericEvent) { | 256 if (xevent->type == GenericEvent) { |
| 257 if (xevent->xgeneric.evtype == XI_HierarchyChanged) { | 257 if (xevent->xgeneric.evtype == XI_HierarchyChanged) { |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 298 | 298 |
| 299 void X11EventSource::OnDispatcherListChanged() { | 299 void X11EventSource::OnDispatcherListChanged() { |
| 300 if (!hotplug_event_handler_) { | 300 if (!hotplug_event_handler_) { |
| 301 hotplug_event_handler_.reset(new X11HotplugEventHandler()); | 301 hotplug_event_handler_.reset(new X11HotplugEventHandler()); |
| 302 // Force the initial device query to have an update list of active devices. | 302 // Force the initial device query to have an update list of active devices. |
| 303 hotplug_event_handler_->OnHotplugEvent(); | 303 hotplug_event_handler_->OnHotplugEvent(); |
| 304 } | 304 } |
| 305 } | 305 } |
| 306 | 306 |
| 307 } // namespace ui | 307 } // namespace ui |
| OLD | NEW |