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

Unified Diff: ui/events/platform/x11/x11_event_source.cc

Issue 2398343002: X11: Avoid round-tripping to get the cursor position (Closed)
Patch Set: Actually add event stack 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 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/desktop_screen_x11.cc » ('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 a49cda90a74ed351b5a6c367e8120fa359dbf70c..e0bf5ae30571c40ee797a5a1fad1fa946dcee09c 100644
--- a/ui/events/platform/x11/x11_event_source.cc
+++ b/ui/events/platform/x11/x11_event_source.cc
@@ -96,7 +96,6 @@ X11EventSource::X11EventSource(X11EventSourceDelegate* delegate,
XDisplay* display)
: delegate_(delegate),
display_(display),
- event_timestamp_(CurrentTime),
dummy_initialized_(false),
continue_stream_(true) {
DCHECK(!instance_);
@@ -184,13 +183,56 @@ Time X11EventSource::GetCurrentServerTime() {
}
Time X11EventSource::GetTimestamp() {
- if (event_timestamp_ != CurrentTime) {
- return event_timestamp_;
+ if (!dispatching_events_.empty()) {
+ Time timestamp = ExtractTimeFromXEvent(*dispatching_events_.top());
+ if (timestamp != CurrentTime)
+ return timestamp;
}
DVLOG(1) << "Making a round trip to get a recent server timestamp.";
return GetCurrentServerTime();
}
+base::Optional<gfx::Point>
+X11EventSource::GetRootCursorLocationFromCurrentEvent() const {
+ XEvent* event =
sadrul 2016/10/11 16:25:02 Early return if |dispatching_events_| is empty.
Tom (Use chromium acct) 2016/10/11 18:00:19 Done.
+ dispatching_events_.empty() ? nullptr : dispatching_events_.top();
+
+ if (event) {
+ switch (event->type) {
+ case ButtonPress:
+ case ButtonRelease:
+ return gfx::Point(event->xbutton.x_root, event->xbutton.y_root);
+ case MotionNotify:
+ return gfx::Point(event->xmotion.x_root, event->xmotion.y_root);
+ case EnterNotify:
+ case LeaveNotify:
+ return gfx::Point(event->xcrossing.x_root, event->xcrossing.y_root);
+ case GenericEvent:
+ if (!ui::TouchFactory::GetInstance()->ShouldProcessXI2Event(event))
+ break;
+ const XIEvent* xi_event =
+ static_cast<const XIEvent*>(event->xcookie.data);
+ switch (xi_event->evtype) {
+ case XI_ButtonPress:
+ case XI_ButtonRelease:
+ case XI_Motion: {
+ const XIDeviceEvent* device_event =
+ static_cast<const XIDeviceEvent*>(event->xcookie.data);
+ return gfx::Point(device_event->root_x, device_event->root_y);
+ }
+ case XI_Enter:
+ case XI_Leave: {
+ const XIEnterEvent* enter_event =
+ static_cast<const XIEnterEvent*>(event->xcookie.data);
+ return gfx::Point(enter_event->root_x, enter_event->root_y);
+ }
+ }
+ }
+ }
sadrul 2016/10/11 16:25:02 Use ui::EventSystemLocationFromNative(), e.g.: b
Tom (Use chromium acct) 2016/10/11 18:00:19 Done.
+
+ return base::Optional<gfx::Point>();
sadrul 2016/10/11 16:25:02 return base::nullopt?
Tom (Use chromium acct) 2016/10/11 18:00:19 Done.
+}
+
////////////////////////////////////////////////////////////////////////////////
// X11EventSource, protected
@@ -201,12 +243,12 @@ void X11EventSource::ExtractCookieDataDispatchEvent(XEvent* xevent) {
have_cookie = true;
}
- event_timestamp_ = ExtractTimeFromXEvent(*xevent);
+ dispatching_events_.push(xevent);
delegate_->ProcessXEvent(xevent);
PostDispatchEvent(xevent);
- event_timestamp_ = CurrentTime;
+ dispatching_events_.pop();
if (have_cookie)
XFreeEventData(xevent->xgeneric.display, &xevent->xcookie);
« 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