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 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
119 void X11EventSource::BlockUntilWindowMapped(XID window) { | 121 void X11EventSource::BlockUntilWindowMapped(XID window) { |
120 XEvent event; | 122 XEvent event; |
121 do { | 123 do { |
122 // Block until there's a message of |event_mask| type on |w|. Then remove | 124 // Block until there's a message of |event_mask| type on |w|. Then remove |
123 // it from the queue and stuff it in |event|. | 125 // it from the queue and stuff it in |event|. |
124 XWindowEvent(display_, window, StructureNotifyMask, &event); | 126 XWindowEvent(display_, window, StructureNotifyMask, &event); |
125 ExtractCookieDataDispatchEvent(&event); | 127 ExtractCookieDataDispatchEvent(&event); |
126 } while (event.type != MapNotify); | 128 } while (event.type != MapNotify); |
127 } | 129 } |
128 | 130 |
131 static Bool is_property_notify_for_timestamp(Display* display, | |
132 XEvent* event, | |
133 XPointer arg) { | |
134 return event->type == PropertyNotify && | |
135 event->xproperty.window == DefaultRootWindow(display) && | |
136 event->xproperty.atom == *(Atom*)arg; | |
137 } | |
138 | |
139 Time X11EventSource::UpdateServerTime() { | |
140 base::TimeTicks start = base::TimeTicks::Now(); | |
141 | |
142 const char kAtomStr[] = __FILE__ " CHROMIUM_DUMMY_ATOM"; | |
Elliot Glaysher
2016/05/06 22:21:10
Are spaces allowed in atoms? Probably want to chan
Tom (Use chromium acct)
2016/05/06 22:44:59
The doc says atom names are ISO Latin-1 strings.
| |
143 | |
144 DCHECK(display_); | |
145 Window window = DefaultRootWindow(display_); | |
146 const unsigned char dummyData = 0; | |
147 Atom dummyAtom = XInternAtom(display_, kAtomStr, False); | |
148 | |
149 XSelectInput(display_, window, PropertyChangeMask); | |
150 | |
151 XChangeProperty(display_, window, dummyAtom, XA_INTEGER, 8, PropModeReplace, | |
152 &dummyData, 1); | |
153 | |
154 XEvent event; | |
155 XIfEvent(display_, &event, is_property_notify_for_timestamp, | |
156 (XPointer)&dummyAtom); | |
157 | |
158 XDeleteProperty(display_, window, dummyAtom); | |
159 XFlush(display_); | |
160 | |
161 last_seen_server_time_ = event.xproperty.time; | |
162 | |
163 UMA_HISTOGRAM_TIMES("Event.Latency.X11EventSource.UpdateServerTime", | |
164 base::TimeTicks::Now() - start); | |
165 return last_seen_server_time_; | |
166 } | |
167 | |
129 //////////////////////////////////////////////////////////////////////////////// | 168 //////////////////////////////////////////////////////////////////////////////// |
130 // X11EventSource, protected | 169 // X11EventSource, protected |
131 | 170 |
132 void X11EventSource::ExtractCookieDataDispatchEvent(XEvent* xevent) { | 171 void X11EventSource::ExtractCookieDataDispatchEvent(XEvent* xevent) { |
133 bool have_cookie = false; | 172 bool have_cookie = false; |
134 if (xevent->type == GenericEvent && | 173 if (xevent->type == GenericEvent && |
135 XGetEventData(xevent->xgeneric.display, &xevent->xcookie)) { | 174 XGetEventData(xevent->xgeneric.display, &xevent->xcookie)) { |
136 have_cookie = true; | 175 have_cookie = true; |
137 } | 176 } |
138 Time event_time = ExtractTimeFromXEvent(*xevent); | 177 Time event_time = ExtractTimeFromXEvent(*xevent); |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
175 | 214 |
176 void X11EventSource::OnDispatcherListChanged() { | 215 void X11EventSource::OnDispatcherListChanged() { |
177 if (!hotplug_event_handler_) { | 216 if (!hotplug_event_handler_) { |
178 hotplug_event_handler_.reset(new X11HotplugEventHandler()); | 217 hotplug_event_handler_.reset(new X11HotplugEventHandler()); |
179 // Force the initial device query to have an update list of active devices. | 218 // Force the initial device query to have an update list of active devices. |
180 hotplug_event_handler_->OnHotplugEvent(); | 219 hotplug_event_handler_->OnHotplugEvent(); |
181 } | 220 } |
182 } | 221 } |
183 | 222 |
184 } // namespace ui | 223 } // namespace ui |
OLD | NEW |