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

Unified 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: Don't clobber the root window event mask 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « ui/events/platform/x11/x11_event_source.h ('k') | ui/views/widget/desktop_aura/x11_desktop_handler.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ui/events/platform/x11/x11_event_source.cc
diff --git a/ui/events/platform/x11/x11_event_source.cc b/ui/events/platform/x11/x11_event_source.cc
index a50cf739e1b06a82487b494c52029048f9440936..b395b9dd84c6d8c5d3ab18d605a4e3cb4575e4d4 100644
--- a/ui/events/platform/x11/x11_event_source.cc
+++ b/ui/events/platform/x11/x11_event_source.cc
@@ -4,10 +4,12 @@
#include "ui/events/platform/x11/x11_event_source.h"
+#include <X11/Xatom.h>
#include <X11/XKBlib.h>
#include <X11/Xlib.h>
#include "base/logging.h"
+#include "base/metrics/histogram_macros.h"
#include "ui/events/devices/x11/device_data_manager_x11.h"
#include "ui/events/devices/x11/touch_factory_x11.h"
#include "ui/events/event_utils.h"
@@ -78,6 +80,14 @@ void UpdateDeviceList() {
DeviceDataManagerX11::GetInstance()->UpdateDeviceList(display);
}
+Bool IsPropertyNotifyForTimestamp(Display* display,
+ XEvent* event,
+ XPointer arg) {
+ return event->type == PropertyNotify &&
+ event->xproperty.window == DefaultRootWindow(display) &&
+ event->xproperty.atom == *(Atom*)arg;
+}
+
} // namespace
X11EventSource* X11EventSource::instance_ = nullptr;
@@ -134,6 +144,43 @@ void X11EventSource::BlockUntilWindowMapped(XID window) {
} while (event.type != MapNotify);
}
+Time X11EventSource::UpdateLastSeenServerTime() {
+ base::TimeTicks start = base::TimeTicks::Now();
+
+ const char kAtomStr[] = "X11_EVENT_SOURCE_UPDATE_SERVER_TIME_DUMMY_ATOM";
+
+ DCHECK(display_);
+ Window window = DefaultRootWindow(display_);
+ const unsigned char dummy_data = 0;
+ Atom dummy_atom = XInternAtom(display_, kAtomStr, False);
+
+ XWindowAttributes attributes;
+ XGetWindowAttributes(display_, window, &attributes);
danakj 2016/05/12 21:32:50 Round trips :( Can you just use some arbitrary ne
+ long old_event_mask = attributes.your_event_mask;
+
+ // Make a no-op property change on the root window.
+ XSelectInput(display_, window, old_event_mask | PropertyChangeMask);
+ XChangeProperty(display_, window, dummy_atom, XA_INTEGER, 8, PropModeReplace,
+ &dummy_data, 1);
+
+
+ // Observe the resulting PropertyChange to obtain the timestamp.
+ XEvent event;
+ XIfEvent(display_, &event, IsPropertyNotifyForTimestamp,
+ (XPointer)&dummy_atom);
+
+ // Clean up: don't leave a dummy property in the root window.
+ XSelectInput(display_, window, old_event_mask);
+ XDeleteProperty(display_, window, dummy_atom);
+ XFlush(display_);
+
+ last_seen_server_time_ = event.xproperty.time;
+
+ UMA_HISTOGRAM_TIMES("Event.Latency.X11EventSource.UpdateServerTime",
+ base::TimeTicks::Now() - start);
+ return last_seen_server_time_;
+}
+
////////////////////////////////////////////////////////////////////////////////
// X11EventSource, protected
« no previous file with comments | « ui/events/platform/x11/x11_event_source.h ('k') | ui/views/widget/desktop_aura/x11_desktop_handler.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698