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

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

Issue 2165083002: Linux: Refactor X11DesktopHandler (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix tests Created 4 years, 4 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/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 162 matching lines...) Expand 10 before | Expand all | Expand 10 after
173 173
174 last_seen_server_time_ = event.xproperty.time; 174 last_seen_server_time_ = event.xproperty.time;
175 175
176 UMA_HISTOGRAM_CUSTOM_COUNTS( 176 UMA_HISTOGRAM_CUSTOM_COUNTS(
177 "Event.Latency.X11EventSource.UpdateServerTime", 177 "Event.Latency.X11EventSource.UpdateServerTime",
178 (base::TimeTicks::Now() - start).InMicroseconds(), 0, 178 (base::TimeTicks::Now() - start).InMicroseconds(), 0,
179 base::TimeDelta::FromMilliseconds(1).InMicroseconds(), 50); 179 base::TimeDelta::FromMilliseconds(1).InMicroseconds(), 50);
180 return last_seen_server_time_; 180 return last_seen_server_time_;
181 } 181 }
182 182
183 void X11EventSource::SetLastSeenServerTime(Time time) {
184 if (time != CurrentTime) {
185 int64_t event_time_64 = time;
186 int64_t time_difference = last_seen_server_time_ - event_time_64;
187 // Ignore timestamps that go backwards. However, X server time is a 32-bit
188 // millisecond counter, so if the time goes backwards by more than half the
189 // range of the 32-bit counter, treat it as a rollover.
190 if (time_difference < 0 || time_difference > (UINT32_MAX >> 1))
191 last_seen_server_time_ = time;
192 }
193 }
194
183 //////////////////////////////////////////////////////////////////////////////// 195 ////////////////////////////////////////////////////////////////////////////////
184 // X11EventSource, protected 196 // X11EventSource, protected
185 197
186 void X11EventSource::ExtractCookieDataDispatchEvent(XEvent* xevent) { 198 void X11EventSource::ExtractCookieDataDispatchEvent(XEvent* xevent) {
187 bool have_cookie = false; 199 bool have_cookie = false;
188 if (xevent->type == GenericEvent && 200 if (xevent->type == GenericEvent &&
189 XGetEventData(xevent->xgeneric.display, &xevent->xcookie)) { 201 XGetEventData(xevent->xgeneric.display, &xevent->xcookie)) {
190 have_cookie = true; 202 have_cookie = true;
191 } 203 }
192 Time event_time = ExtractTimeFromXEvent(*xevent); 204 SetLastSeenServerTime(ExtractTimeFromXEvent(*xevent));
193 if (event_time != CurrentTime) {
194 int64_t event_time_64 = event_time;
195 int64_t time_difference = last_seen_server_time_ - event_time_64;
196 // Ignore timestamps that go backwards. However, X server time is a 32-bit
197 // millisecond counter, so if the time goes backwards by more than half the
198 // range of the 32-bit counter, treat it as a rollover.
199 if (time_difference < 0 || time_difference > (UINT32_MAX >> 1))
200 last_seen_server_time_ = event_time;
201 }
202 delegate_->ProcessXEvent(xevent); 205 delegate_->ProcessXEvent(xevent);
203 PostDispatchEvent(xevent); 206 PostDispatchEvent(xevent);
204 if (have_cookie) 207 if (have_cookie)
205 XFreeEventData(xevent->xgeneric.display, &xevent->xcookie); 208 XFreeEventData(xevent->xgeneric.display, &xevent->xcookie);
206 } 209 }
207 210
208 void X11EventSource::PostDispatchEvent(XEvent* xevent) { 211 void X11EventSource::PostDispatchEvent(XEvent* xevent) {
209 bool should_update_device_list = false; 212 bool should_update_device_list = false;
210 213
211 if (xevent->type == GenericEvent) { 214 if (xevent->type == GenericEvent) {
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
253 256
254 void X11EventSource::OnDispatcherListChanged() { 257 void X11EventSource::OnDispatcherListChanged() {
255 if (!hotplug_event_handler_) { 258 if (!hotplug_event_handler_) {
256 hotplug_event_handler_.reset(new X11HotplugEventHandler()); 259 hotplug_event_handler_.reset(new X11HotplugEventHandler());
257 // Force the initial device query to have an update list of active devices. 260 // Force the initial device query to have an update list of active devices.
258 hotplug_event_handler_->OnHotplugEvent(); 261 hotplug_event_handler_->OnHotplugEvent();
259 } 262 }
260 } 263 }
261 264
262 } // namespace ui 265 } // namespace ui
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698