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/XKBlib.h> | 8 #include <X11/XKBlib.h> |
8 #include <X11/Xlib.h> | 9 #include <X11/Xlib.h> |
9 | 10 |
10 #include "base/logging.h" | 11 #include "base/logging.h" |
| 12 #include "base/metrics/histogram_macros.h" |
11 #include "ui/events/devices/x11/device_data_manager_x11.h" | 13 #include "ui/events/devices/x11/device_data_manager_x11.h" |
12 #include "ui/events/event_utils.h" | 14 #include "ui/events/event_utils.h" |
13 #include "ui/events/platform/platform_event_dispatcher.h" | 15 #include "ui/events/platform/platform_event_dispatcher.h" |
14 #include "ui/events/platform/x11/x11_hotplug_event_handler.h" | 16 #include "ui/events/platform/x11/x11_hotplug_event_handler.h" |
15 | 17 |
16 namespace ui { | 18 namespace ui { |
17 | 19 |
18 namespace { | 20 namespace { |
19 | 21 |
20 bool InitializeXkb(XDisplay* display) { | 22 bool InitializeXkb(XDisplay* display) { |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
63 return xevent.xselection.time; | 65 return xevent.xselection.time; |
64 case GenericEvent: | 66 case GenericEvent: |
65 if (DeviceDataManagerX11::GetInstance()->IsXIDeviceEvent(xevent)) | 67 if (DeviceDataManagerX11::GetInstance()->IsXIDeviceEvent(xevent)) |
66 return static_cast<XIDeviceEvent*>(xevent.xcookie.data)->time; | 68 return static_cast<XIDeviceEvent*>(xevent.xcookie.data)->time; |
67 else | 69 else |
68 break; | 70 break; |
69 } | 71 } |
70 return CurrentTime; | 72 return CurrentTime; |
71 } | 73 } |
72 | 74 |
| 75 Bool IsPropertyNotifyForTimestamp(Display* display, |
| 76 XEvent* event, |
| 77 XPointer arg) { |
| 78 return event->type == PropertyNotify && |
| 79 event->xproperty.window == DefaultRootWindow(display) && |
| 80 event->xproperty.atom == *(Atom*)arg; |
| 81 } |
| 82 |
73 } // namespace | 83 } // namespace |
74 | 84 |
75 X11EventSource* X11EventSource::instance_ = nullptr; | 85 X11EventSource* X11EventSource::instance_ = nullptr; |
76 | 86 |
77 X11EventSource::X11EventSource(X11EventSourceDelegate* delegate, | 87 X11EventSource::X11EventSource(X11EventSourceDelegate* delegate, |
78 XDisplay* display) | 88 XDisplay* display) |
79 : delegate_(delegate), | 89 : delegate_(delegate), |
80 display_(display), | 90 display_(display), |
81 last_seen_server_time_(CurrentTime), | 91 last_seen_server_time_(CurrentTime), |
82 continue_stream_(true) { | 92 continue_stream_(true) { |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
119 void X11EventSource::BlockUntilWindowMapped(XID window) { | 129 void X11EventSource::BlockUntilWindowMapped(XID window) { |
120 XEvent event; | 130 XEvent event; |
121 do { | 131 do { |
122 // Block until there's a message of |event_mask| type on |w|. Then remove | 132 // Block until there's a message of |event_mask| type on |w|. Then remove |
123 // it from the queue and stuff it in |event|. | 133 // it from the queue and stuff it in |event|. |
124 XWindowEvent(display_, window, StructureNotifyMask, &event); | 134 XWindowEvent(display_, window, StructureNotifyMask, &event); |
125 ExtractCookieDataDispatchEvent(&event); | 135 ExtractCookieDataDispatchEvent(&event); |
126 } while (event.type != MapNotify); | 136 } while (event.type != MapNotify); |
127 } | 137 } |
128 | 138 |
| 139 Time X11EventSource::UpdateLastSeenServerTime() { |
| 140 base::TimeTicks start = base::TimeTicks::Now(); |
| 141 |
| 142 const char kAtomStr[] = "X11_EVENT_SOURCE_UPDATE_SERVER_TIME_DUMMY_ATOM"; |
| 143 |
| 144 DCHECK(display_); |
| 145 Window window = DefaultRootWindow(display_); |
| 146 const unsigned char dummy_data = 0; |
| 147 Atom dummy_atom = XInternAtom(display_, kAtomStr, False); |
| 148 |
| 149 // Make a no-op property change on the root window. |
| 150 XSelectInput(display_, window, PropertyChangeMask); |
| 151 XChangeProperty(display_, window, dummy_atom, XA_INTEGER, 8, PropModeReplace, |
| 152 &dummy_data, 1); |
| 153 |
| 154 // Observe the resulting PropertyChange to obtain the timestamp. |
| 155 XEvent event; |
| 156 XIfEvent(display_, &event, IsPropertyNotifyForTimestamp, |
| 157 (XPointer)&dummy_atom); |
| 158 |
| 159 // Clean up: don't leave a dummy property in the root window. |
| 160 XDeleteProperty(display_, window, dummy_atom); |
| 161 XFlush(display_); |
| 162 |
| 163 last_seen_server_time_ = event.xproperty.time; |
| 164 |
| 165 UMA_HISTOGRAM_TIMES("Event.Latency.X11EventSource.UpdateServerTime", |
| 166 base::TimeTicks::Now() - start); |
| 167 return last_seen_server_time_; |
| 168 } |
| 169 |
129 //////////////////////////////////////////////////////////////////////////////// | 170 //////////////////////////////////////////////////////////////////////////////// |
130 // X11EventSource, protected | 171 // X11EventSource, protected |
131 | 172 |
132 void X11EventSource::ExtractCookieDataDispatchEvent(XEvent* xevent) { | 173 void X11EventSource::ExtractCookieDataDispatchEvent(XEvent* xevent) { |
133 bool have_cookie = false; | 174 bool have_cookie = false; |
134 if (xevent->type == GenericEvent && | 175 if (xevent->type == GenericEvent && |
135 XGetEventData(xevent->xgeneric.display, &xevent->xcookie)) { | 176 XGetEventData(xevent->xgeneric.display, &xevent->xcookie)) { |
136 have_cookie = true; | 177 have_cookie = true; |
137 } | 178 } |
138 Time event_time = ExtractTimeFromXEvent(*xevent); | 179 Time event_time = ExtractTimeFromXEvent(*xevent); |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
175 | 216 |
176 void X11EventSource::OnDispatcherListChanged() { | 217 void X11EventSource::OnDispatcherListChanged() { |
177 if (!hotplug_event_handler_) { | 218 if (!hotplug_event_handler_) { |
178 hotplug_event_handler_.reset(new X11HotplugEventHandler()); | 219 hotplug_event_handler_.reset(new X11HotplugEventHandler()); |
179 // Force the initial device query to have an update list of active devices. | 220 // Force the initial device query to have an update list of active devices. |
180 hotplug_event_handler_->OnHotplugEvent(); | 221 hotplug_event_handler_->OnHotplugEvent(); |
181 } | 222 } |
182 } | 223 } |
183 | 224 |
184 } // namespace ui | 225 } // namespace ui |
OLD | NEW |