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

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

Issue 2398343002: X11: Avoid round-tripping to get the cursor position (Closed)
Patch Set: Use EventSystemLocationFromNative and base::nullopt Created 4 years, 2 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 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
89 } 89 }
90 90
91 } // namespace 91 } // namespace
92 92
93 X11EventSource* X11EventSource::instance_ = nullptr; 93 X11EventSource* X11EventSource::instance_ = nullptr;
94 94
95 X11EventSource::X11EventSource(X11EventSourceDelegate* delegate, 95 X11EventSource::X11EventSource(X11EventSourceDelegate* delegate,
96 XDisplay* display) 96 XDisplay* display)
97 : delegate_(delegate), 97 : delegate_(delegate),
98 display_(display), 98 display_(display),
99 event_timestamp_(CurrentTime),
100 dummy_initialized_(false), 99 dummy_initialized_(false),
101 continue_stream_(true) { 100 continue_stream_(true) {
102 DCHECK(!instance_); 101 DCHECK(!instance_);
103 instance_ = this; 102 instance_ = this;
104 103
105 DCHECK(delegate_); 104 DCHECK(delegate_);
106 DCHECK(display_); 105 DCHECK(display_);
107 DeviceDataManagerX11::CreateInstance(); 106 DeviceDataManagerX11::CreateInstance();
108 InitializeXkb(display_); 107 InitializeXkb(display_);
109 } 108 }
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
177 XIfEvent(display_, &event, IsPropertyNotifyForTimestamp, 176 XIfEvent(display_, &event, IsPropertyNotifyForTimestamp,
178 reinterpret_cast<XPointer>(&dummy_window_)); 177 reinterpret_cast<XPointer>(&dummy_window_));
179 178
180 UMA_HISTOGRAM_CUSTOM_COUNTS( 179 UMA_HISTOGRAM_CUSTOM_COUNTS(
181 "Linux.X11.ServerRTT", (base::TimeTicks::Now() - start).InMicroseconds(), 180 "Linux.X11.ServerRTT", (base::TimeTicks::Now() - start).InMicroseconds(),
182 1, base::TimeDelta::FromMilliseconds(50).InMicroseconds(), 50); 181 1, base::TimeDelta::FromMilliseconds(50).InMicroseconds(), 50);
183 return event.xproperty.time; 182 return event.xproperty.time;
184 } 183 }
185 184
186 Time X11EventSource::GetTimestamp() { 185 Time X11EventSource::GetTimestamp() {
187 if (event_timestamp_ != CurrentTime) { 186 if (!dispatching_events_.empty()) {
188 return event_timestamp_; 187 Time timestamp = ExtractTimeFromXEvent(*dispatching_events_.top());
188 if (timestamp != CurrentTime)
189 return timestamp;
189 } 190 }
190 DVLOG(1) << "Making a round trip to get a recent server timestamp."; 191 DVLOG(1) << "Making a round trip to get a recent server timestamp.";
191 return GetCurrentServerTime(); 192 return GetCurrentServerTime();
192 } 193 }
193 194
195 base::Optional<gfx::Point>
196 X11EventSource::GetRootCursorLocationFromCurrentEvent() const {
197 if (dispatching_events_.empty())
198 return base::nullopt;
199
200 XEvent* event = dispatching_events_.top();
201 bool is_valid_event = false;
202 if (event) {
sadrul 2016/10/12 00:17:17 Should this be a DCHECK()? This should never be nu
Tom (Use chromium acct) 2016/10/12 01:03:27 Done.
203 switch (event->type) {
204 case ButtonPress:
205 case ButtonRelease:
206 case MotionNotify:
207 case EnterNotify:
208 case LeaveNotify:
209 is_valid_event = true;
210 break;
211 case GenericEvent:
212 if (!ui::TouchFactory::GetInstance()->ShouldProcessXI2Event(event))
213 break;
214 is_valid_event = true;
215 }
216 }
217
218 if (is_valid_event)
219 return ui::EventSystemLocationFromNative(event);
220 return base::nullopt;
221 }
222
194 //////////////////////////////////////////////////////////////////////////////// 223 ////////////////////////////////////////////////////////////////////////////////
195 // X11EventSource, protected 224 // X11EventSource, protected
196 225
197 void X11EventSource::ExtractCookieDataDispatchEvent(XEvent* xevent) { 226 void X11EventSource::ExtractCookieDataDispatchEvent(XEvent* xevent) {
198 bool have_cookie = false; 227 bool have_cookie = false;
199 if (xevent->type == GenericEvent && 228 if (xevent->type == GenericEvent &&
200 XGetEventData(xevent->xgeneric.display, &xevent->xcookie)) { 229 XGetEventData(xevent->xgeneric.display, &xevent->xcookie)) {
201 have_cookie = true; 230 have_cookie = true;
202 } 231 }
203 232
204 event_timestamp_ = ExtractTimeFromXEvent(*xevent); 233 dispatching_events_.push(xevent);
205 234
206 delegate_->ProcessXEvent(xevent); 235 delegate_->ProcessXEvent(xevent);
207 PostDispatchEvent(xevent); 236 PostDispatchEvent(xevent);
208 237
209 event_timestamp_ = CurrentTime; 238 dispatching_events_.pop();
210 239
211 if (have_cookie) 240 if (have_cookie)
212 XFreeEventData(xevent->xgeneric.display, &xevent->xcookie); 241 XFreeEventData(xevent->xgeneric.display, &xevent->xcookie);
213 } 242 }
214 243
215 void X11EventSource::PostDispatchEvent(XEvent* xevent) { 244 void X11EventSource::PostDispatchEvent(XEvent* xevent) {
216 bool should_update_device_list = false; 245 bool should_update_device_list = false;
217 246
218 if (xevent->type == GenericEvent) { 247 if (xevent->type == GenericEvent) {
219 if (xevent->xgeneric.evtype == XI_HierarchyChanged) { 248 if (xevent->xgeneric.evtype == XI_HierarchyChanged) {
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
260 289
261 void X11EventSource::OnDispatcherListChanged() { 290 void X11EventSource::OnDispatcherListChanged() {
262 if (!hotplug_event_handler_) { 291 if (!hotplug_event_handler_) {
263 hotplug_event_handler_.reset(new X11HotplugEventHandler()); 292 hotplug_event_handler_.reset(new X11HotplugEventHandler());
264 // Force the initial device query to have an update list of active devices. 293 // Force the initial device query to have an update list of active devices.
265 hotplug_event_handler_->OnHotplugEvent(); 294 hotplug_event_handler_->OnHotplugEvent();
266 } 295 }
267 } 296 }
268 297
269 } // namespace ui 298 } // namespace ui
OLDNEW
« no previous file with comments | « ui/events/platform/x11/x11_event_source.h ('k') | ui/views/widget/desktop_aura/desktop_screen_x11.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698