OLD | NEW |
---|---|
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/XKBlib.h> | 7 #include <X11/XKBlib.h> |
8 #include <X11/Xlib.h> | 8 #include <X11/Xlib.h> |
9 | 9 |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
(...skipping 28 matching lines...) Expand all Loading... | |
39 | 39 |
40 return true; | 40 return true; |
41 } | 41 } |
42 | 42 |
43 } // namespace | 43 } // namespace |
44 | 44 |
45 X11EventSource* X11EventSource::instance_ = nullptr; | 45 X11EventSource* X11EventSource::instance_ = nullptr; |
46 | 46 |
47 X11EventSource::X11EventSource(X11EventSourceDelegate* delegate, | 47 X11EventSource::X11EventSource(X11EventSourceDelegate* delegate, |
48 XDisplay* display) | 48 XDisplay* display) |
49 : delegate_(delegate), display_(display), continue_stream_(true) { | 49 : delegate_(delegate), |
50 display_(display), | |
51 last_seen_server_time_(CurrentTime), | |
52 continue_stream_(true) { | |
50 DCHECK(!instance_); | 53 DCHECK(!instance_); |
51 instance_ = this; | 54 instance_ = this; |
52 | 55 |
53 DCHECK(delegate_); | 56 DCHECK(delegate_); |
54 DCHECK(display_); | 57 DCHECK(display_); |
55 DeviceDataManagerX11::CreateInstance(); | 58 DeviceDataManagerX11::CreateInstance(); |
56 InitializeXkb(display_); | 59 InitializeXkb(display_); |
57 } | 60 } |
58 | 61 |
59 X11EventSource::~X11EventSource() { | 62 X11EventSource::~X11EventSource() { |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
95 | 98 |
96 //////////////////////////////////////////////////////////////////////////////// | 99 //////////////////////////////////////////////////////////////////////////////// |
97 // X11EventSource, protected | 100 // X11EventSource, protected |
98 | 101 |
99 void X11EventSource::ExtractCookieDataDispatchEvent(XEvent* xevent) { | 102 void X11EventSource::ExtractCookieDataDispatchEvent(XEvent* xevent) { |
100 bool have_cookie = false; | 103 bool have_cookie = false; |
101 if (xevent->type == GenericEvent && | 104 if (xevent->type == GenericEvent && |
102 XGetEventData(xevent->xgeneric.display, &xevent->xcookie)) { | 105 XGetEventData(xevent->xgeneric.display, &xevent->xcookie)) { |
103 have_cookie = true; | 106 have_cookie = true; |
104 } | 107 } |
108 ExtractTimeFromXEvent(*xevent); | |
105 delegate_->ProcessXEvent(xevent); | 109 delegate_->ProcessXEvent(xevent); |
106 PostDispatchEvent(xevent); | 110 PostDispatchEvent(xevent); |
107 if (have_cookie) | 111 if (have_cookie) |
108 XFreeEventData(xevent->xgeneric.display, &xevent->xcookie); | 112 XFreeEventData(xevent->xgeneric.display, &xevent->xcookie); |
109 } | 113 } |
110 | 114 |
111 void X11EventSource::PostDispatchEvent(XEvent* xevent) { | 115 void X11EventSource::PostDispatchEvent(XEvent* xevent) { |
112 if (xevent->type == GenericEvent && | 116 if (xevent->type == GenericEvent && |
113 (xevent->xgeneric.evtype == XI_HierarchyChanged || | 117 (xevent->xgeneric.evtype == XI_HierarchyChanged || |
114 (xevent->xgeneric.evtype == XI_DeviceChanged && | 118 (xevent->xgeneric.evtype == XI_DeviceChanged && |
115 static_cast<XIDeviceChangedEvent*>(xevent->xcookie.data)->reason == | 119 static_cast<XIDeviceChangedEvent*>(xevent->xcookie.data)->reason == |
116 XIDeviceChange))) { | 120 XIDeviceChange))) { |
117 ui::UpdateDeviceList(); | 121 ui::UpdateDeviceList(); |
118 hotplug_event_handler_->OnHotplugEvent(); | 122 hotplug_event_handler_->OnHotplugEvent(); |
119 } | 123 } |
120 | 124 |
121 if (xevent->type == EnterNotify && | 125 if (xevent->type == EnterNotify && |
122 xevent->xcrossing.detail != NotifyInferior && | 126 xevent->xcrossing.detail != NotifyInferior && |
123 xevent->xcrossing.mode != NotifyUngrab) { | 127 xevent->xcrossing.mode != NotifyUngrab) { |
124 // Clear stored scroll data | 128 // Clear stored scroll data |
125 ui::DeviceDataManagerX11::GetInstance()->InvalidateScrollClasses(); | 129 ui::DeviceDataManagerX11::GetInstance()->InvalidateScrollClasses(); |
126 } | 130 } |
127 } | 131 } |
128 | 132 |
133 void X11EventSource::ExtractTimeFromXEvent(const XEvent& xevent) { | |
dcheng
2016/04/19 21:56:45
An alternative was to stash the timestamp off http
| |
134 switch (xevent.type) { | |
135 case KeyPress: | |
136 case KeyRelease: | |
137 last_seen_server_time_ = xevent.xkey.time; | |
138 return; | |
139 case ButtonPress: | |
140 case ButtonRelease: | |
141 last_seen_server_time_ = xevent.xbutton.time; | |
142 return; | |
143 case MotionNotify: | |
144 last_seen_server_time_ = xevent.xmotion.time; | |
145 return; | |
146 case EnterNotify: | |
147 case LeaveNotify: | |
148 last_seen_server_time_ = xevent.xcrossing.time; | |
149 return; | |
150 case PropertyNotify: | |
151 last_seen_server_time_ = xevent.xproperty.time; | |
152 return; | |
153 case SelectionClear: | |
154 last_seen_server_time_ = xevent.xselectionclear.time; | |
155 return; | |
156 case SelectionRequest: | |
157 last_seen_server_time_ = xevent.xselectionrequest.time; | |
158 return; | |
159 case SelectionNotify: | |
160 last_seen_server_time_ = xevent.xselection.time; | |
161 return; | |
162 case GenericEvent: | |
163 last_seen_server_time_ = | |
dcheng
2016/04/19 21:56:45
I have no idea how this is safe, but other code se
| |
164 static_cast<XIDeviceEvent*>(xevent.xcookie.data)->time; | |
165 return; | |
166 } | |
167 } | |
168 | |
129 void X11EventSource::StopCurrentEventStream() { | 169 void X11EventSource::StopCurrentEventStream() { |
130 continue_stream_ = false; | 170 continue_stream_ = false; |
131 } | 171 } |
132 | 172 |
133 void X11EventSource::OnDispatcherListChanged() { | 173 void X11EventSource::OnDispatcherListChanged() { |
134 if (!hotplug_event_handler_) { | 174 if (!hotplug_event_handler_) { |
135 hotplug_event_handler_.reset(new X11HotplugEventHandler()); | 175 hotplug_event_handler_.reset(new X11HotplugEventHandler()); |
136 // Force the initial device query to have an update list of active devices. | 176 // Force the initial device query to have an update list of active devices. |
137 hotplug_event_handler_->OnHotplugEvent(); | 177 hotplug_event_handler_->OnHotplugEvent(); |
138 } | 178 } |
139 } | 179 } |
140 | 180 |
141 } // namespace ui | 181 } // namespace ui |
OLD | NEW |