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/extensions/XInput2.h> | 7 #include <X11/extensions/XInput2.h> |
8 #include <X11/X.h> | 8 #include <X11/X.h> |
9 #include <X11/Xlib.h> | 9 #include <X11/Xlib.h> |
10 #include <X11/XKBlib.h> | 10 #include <X11/XKBlib.h> |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
87 } | 87 } |
88 | 88 |
89 // static | 89 // static |
90 X11EventSource* X11EventSource::GetInstance() { | 90 X11EventSource* X11EventSource::GetInstance() { |
91 return static_cast<X11EventSource*>(PlatformEventSource::GetInstance()); | 91 return static_cast<X11EventSource*>(PlatformEventSource::GetInstance()); |
92 } | 92 } |
93 | 93 |
94 //////////////////////////////////////////////////////////////////////////////// | 94 //////////////////////////////////////////////////////////////////////////////// |
95 // X11EventSource, public | 95 // X11EventSource, public |
96 | 96 |
97 void X11EventSource::AddXEventDispatcher(XEventDispatcher* dispatcher) { | |
98 CHECK(dispatcher); | |
spang
2016/01/26 21:37:40
CHECK is not allowed except for security-critical
kylechar
2016/01/27 15:39:26
Done.
| |
99 x_dispatchers_.AddObserver(dispatcher); | |
100 } | |
101 | |
102 void X11EventSource::RemoveXEventDispatcher(XEventDispatcher* dispatcher) { | |
103 x_dispatchers_.RemoveObserver(dispatcher); | |
104 } | |
105 | |
97 void X11EventSource::DispatchXEvents() { | 106 void X11EventSource::DispatchXEvents() { |
98 DCHECK(display_); | 107 DCHECK(display_); |
99 // Handle all pending events. | 108 // Handle all pending events. |
100 // It may be useful to eventually align this event dispatch with vsync, but | 109 // It may be useful to eventually align this event dispatch with vsync, but |
101 // not yet. | 110 // not yet. |
102 continue_stream_ = true; | 111 continue_stream_ = true; |
103 while (XPending(display_) && continue_stream_) { | 112 while (XPending(display_) && continue_stream_) { |
104 XEvent xevent; | 113 XEvent xevent; |
105 XNextEvent(display_, &xevent); | 114 XNextEvent(display_, &xevent); |
106 ExtractCookieDataDispatchEvent(&xevent); | 115 ExtractCookieDataDispatchEvent(&xevent); |
(...skipping 18 matching lines...) Expand all Loading... | |
125 if (xevent->type == GenericEvent && | 134 if (xevent->type == GenericEvent && |
126 XGetEventData(xevent->xgeneric.display, &xevent->xcookie)) { | 135 XGetEventData(xevent->xgeneric.display, &xevent->xcookie)) { |
127 have_cookie = true; | 136 have_cookie = true; |
128 } | 137 } |
129 uint32_t action = DispatchEvent(xevent); | 138 uint32_t action = DispatchEvent(xevent); |
130 if (have_cookie) | 139 if (have_cookie) |
131 XFreeEventData(xevent->xgeneric.display, &xevent->xcookie); | 140 XFreeEventData(xevent->xgeneric.display, &xevent->xcookie); |
132 return action; | 141 return action; |
133 } | 142 } |
134 | 143 |
135 uint32_t X11EventSource::DispatchEvent(XEvent* xevent) { | 144 void X11EventSource::DispatchXEventToXEventDispatchers(XEvent* xevent) { |
136 uint32_t action = PlatformEventSource::DispatchEvent(xevent); | 145 if (x_dispatchers_.might_have_observers()) { |
146 base::ObserverList<XEventDispatcher>::Iterator iter(&x_dispatchers_); | |
147 while (XEventDispatcher* dispatcher = iter.GetNext()) { | |
148 if (dispatcher->DispatchXEvent(*xevent)) | |
149 break; | |
spang
2016/01/26 21:37:40
If DispatchXEvent returns true, do we still try to
kylechar
2016/01/27 15:39:26
It doesn't right now because it actually happens i
| |
150 } | |
151 } | |
152 } | |
153 | |
154 void X11EventSource::PostDispatchEvent(XEvent* xevent) { | |
137 if (xevent->type == GenericEvent && | 155 if (xevent->type == GenericEvent && |
138 (xevent->xgeneric.evtype == XI_HierarchyChanged || | 156 (xevent->xgeneric.evtype == XI_HierarchyChanged || |
139 xevent->xgeneric.evtype == XI_DeviceChanged)) { | 157 xevent->xgeneric.evtype == XI_DeviceChanged)) { |
140 ui::UpdateDeviceList(); | 158 ui::UpdateDeviceList(); |
141 hotplug_event_handler_->OnHotplugEvent(); | 159 hotplug_event_handler_->OnHotplugEvent(); |
142 } | 160 } |
143 | 161 |
144 if (xevent->type == EnterNotify && | 162 if (xevent->type == EnterNotify && |
145 xevent->xcrossing.detail != NotifyInferior && | 163 xevent->xcrossing.detail != NotifyInferior && |
146 xevent->xcrossing.mode != NotifyUngrab) { | 164 xevent->xcrossing.mode != NotifyUngrab) { |
147 // Clear stored scroll data | 165 // Clear stored scroll data |
148 ui::DeviceDataManagerX11::GetInstance()->InvalidateScrollClasses(); | 166 ui::DeviceDataManagerX11::GetInstance()->InvalidateScrollClasses(); |
149 } | 167 } |
150 return action; | |
151 } | 168 } |
152 | 169 |
153 void X11EventSource::StopCurrentEventStream() { | 170 void X11EventSource::StopCurrentEventStream() { |
154 continue_stream_ = false; | 171 continue_stream_ = false; |
155 } | 172 } |
156 | 173 |
157 void X11EventSource::OnDispatcherListChanged() { | 174 void X11EventSource::OnDispatcherListChanged() { |
158 if (!hotplug_event_handler_) { | 175 if (!hotplug_event_handler_) { |
159 hotplug_event_handler_.reset(new X11HotplugEventHandler()); | 176 hotplug_event_handler_.reset(new X11HotplugEventHandler()); |
160 // Force the initial device query to have an update list of active devices. | 177 // Force the initial device query to have an update list of active devices. |
161 hotplug_event_handler_->OnHotplugEvent(); | 178 hotplug_event_handler_->OnHotplugEvent(); |
162 } | 179 } |
163 } | 180 } |
164 | 181 |
165 } // namespace ui | 182 } // namespace ui |
OLD | NEW |