Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(55)

Side by Side Diff: ui/events/platform/x11/x11_event_source.cc

Issue 1949393007: X11: Better timestamp handling for _NET_ACTIVE_WINDOW (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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";
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);
Tom (Use chromium acct) 2016/05/06 20:42:00 For some reason, XDeleteProperty doesn't actually
piman 2016/05/06 21:23:00 Maybe need an XFlush ?
Tom (Use chromium acct) 2016/05/06 22:09:43 That worked! Done.
159
160 last_seen_server_time_ = event.xproperty.time;
161
162 UMA_HISTOGRAM_TIMES("Event.Latency.X11EventSource.UpdateServerTime",
163 base::TimeTicks::Now() - start);
164 return last_seen_server_time_;
165 }
166
129 //////////////////////////////////////////////////////////////////////////////// 167 ////////////////////////////////////////////////////////////////////////////////
130 // X11EventSource, protected 168 // X11EventSource, protected
131 169
132 void X11EventSource::ExtractCookieDataDispatchEvent(XEvent* xevent) { 170 void X11EventSource::ExtractCookieDataDispatchEvent(XEvent* xevent) {
133 bool have_cookie = false; 171 bool have_cookie = false;
134 if (xevent->type == GenericEvent && 172 if (xevent->type == GenericEvent &&
135 XGetEventData(xevent->xgeneric.display, &xevent->xcookie)) { 173 XGetEventData(xevent->xgeneric.display, &xevent->xcookie)) {
136 have_cookie = true; 174 have_cookie = true;
137 } 175 }
138 Time event_time = ExtractTimeFromXEvent(*xevent); 176 Time event_time = ExtractTimeFromXEvent(*xevent);
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
175 213
176 void X11EventSource::OnDispatcherListChanged() { 214 void X11EventSource::OnDispatcherListChanged() {
177 if (!hotplug_event_handler_) { 215 if (!hotplug_event_handler_) {
178 hotplug_event_handler_.reset(new X11HotplugEventHandler()); 216 hotplug_event_handler_.reset(new X11HotplugEventHandler());
179 // Force the initial device query to have an update list of active devices. 217 // Force the initial device query to have an update list of active devices.
180 hotplug_event_handler_->OnHotplugEvent(); 218 hotplug_event_handler_->OnHotplugEvent();
181 } 219 }
182 } 220 }
183 221
184 } // namespace ui 222 } // namespace ui
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698