| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 "base/message_pump_glib_x.h" | 5 #include "base/message_pump_glib_x.h" |
| 6 | 6 |
| 7 #include <gdk/gdkx.h> | 7 #include <gdk/gdkx.h> |
| 8 #if defined(HAVE_XINPUT2) | 8 #if defined(HAVE_XINPUT2) |
| 9 #include <X11/extensions/XInput2.h> | 9 #include <X11/extensions/XInput2.h> |
| 10 #else | 10 #else |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 78 #endif | 78 #endif |
| 79 InitializeEventsToCapture(); | 79 InitializeEventsToCapture(); |
| 80 } | 80 } |
| 81 | 81 |
| 82 MessagePumpGlibX::~MessagePumpGlibX() { | 82 MessagePumpGlibX::~MessagePumpGlibX() { |
| 83 } | 83 } |
| 84 | 84 |
| 85 bool MessagePumpGlibX::RunOnce(GMainContext* context, bool block) { | 85 bool MessagePumpGlibX::RunOnce(GMainContext* context, bool block) { |
| 86 GdkDisplay* gdisp = gdk_display_get_default(); | 86 GdkDisplay* gdisp = gdk_display_get_default(); |
| 87 Display* display = GDK_DISPLAY_XDISPLAY(gdisp); | 87 Display* display = GDK_DISPLAY_XDISPLAY(gdisp); |
| 88 bool should_quit = false; |
| 89 |
| 88 if (XPending(display)) { | 90 if (XPending(display)) { |
| 89 XEvent xev; | 91 XEvent xev; |
| 90 XPeekEvent(display, &xev); | 92 XPeekEvent(display, &xev); |
| 91 if (capture_x_events_[xev.type] | 93 if (capture_x_events_[xev.type] |
| 92 #if defined(HAVE_XINPUT2) | 94 #if defined(HAVE_XINPUT2) |
| 93 && (xev.type != GenericEvent || xev.xcookie.extension == xiopcode_) | 95 && (xev.type != GenericEvent || xev.xcookie.extension == xiopcode_) |
| 94 #endif | 96 #endif |
| 95 ) { | 97 ) { |
| 96 XNextEvent(display, &xev); | 98 XNextEvent(display, &xev); |
| 97 | 99 |
| 98 bool processed = static_cast<MessagePumpGlibXDispatcher*> | 100 #if defined(HAVE_XINPUT2) |
| 101 bool have_cookie = false; |
| 102 if (xev.type == GenericEvent && |
| 103 XGetEventData(xev.xgeneric.display, &xev.xcookie)) { |
| 104 have_cookie = true; |
| 105 } |
| 106 #endif |
| 107 |
| 108 MessagePumpGlibXDispatcher::DispatchStatus status = |
| 109 static_cast<MessagePumpGlibXDispatcher*> |
| 99 (GetDispatcher())->Dispatch(&xev); | 110 (GetDispatcher())->Dispatch(&xev); |
| 100 | 111 |
| 101 if (!processed) { | 112 if (status == MessagePumpGlibXDispatcher::EVENT_QUIT) { |
| 113 should_quit = true; |
| 114 Quit(); |
| 115 } else if (status == MessagePumpGlibXDispatcher::EVENT_IGNORED) { |
| 102 DLOG(WARNING) << "Event (" << xev.type << ") not handled."; | 116 DLOG(WARNING) << "Event (" << xev.type << ") not handled."; |
| 103 | 117 |
| 104 // TODO(sad): It is necessary to put back the event so that the default | 118 // TODO(sad): It is necessary to put back the event so that the default |
| 105 // GDK events handler can take care of it. Without this, it is | 119 // GDK events handler can take care of it. Without this, it is |
| 106 // impossible to use the omnibox at the moment. However, this will | 120 // impossible to use the omnibox at the moment. However, this will |
| 107 // eventually be removed once the omnibox code is updated for touchui. | 121 // eventually be removed once the omnibox code is updated for touchui. |
| 108 XPutBackEvent(display, &xev); | 122 XPutBackEvent(display, &xev); |
| 123 if (gdksource_) |
| 124 gdksource_->source_funcs->dispatch = gdkdispatcher_; |
| 109 g_main_context_iteration(context, FALSE); | 125 g_main_context_iteration(context, FALSE); |
| 110 } | 126 } |
| 127 |
| 128 #if defined(HAVE_XINPUT2) |
| 129 if (have_cookie) { |
| 130 XFreeEventData(xev.xgeneric.display, &xev.xcookie); |
| 131 } |
| 132 #endif |
| 111 } else { | 133 } else { |
| 112 // TODO(sad): A couple of extra events can still sneak in during this. | 134 // TODO(sad): A couple of extra events can still sneak in during this. |
| 113 // Those should be sent back to the X queue from the dispatcher | 135 // Those should be sent back to the X queue from the dispatcher |
| 114 // EventDispatcherX. | 136 // EventDispatcherX. |
| 137 if (gdksource_) |
| 138 gdksource_->source_funcs->dispatch = gdkdispatcher_; |
| 115 g_main_context_iteration(context, FALSE); | 139 g_main_context_iteration(context, FALSE); |
| 116 } | 140 } |
| 117 } | 141 } |
| 118 | 142 |
| 143 if (should_quit) |
| 144 return true; |
| 145 |
| 119 bool retvalue; | 146 bool retvalue; |
| 120 if (gdksource_) { | 147 if (gdksource_) { |
| 121 // Replace the dispatch callback of the GDK event source temporarily so that | 148 // Replace the dispatch callback of the GDK event source temporarily so that |
| 122 // it doesn't read events from X. | 149 // it doesn't read events from X. |
| 123 gboolean (*cb)(GSource*, GSourceFunc, void*) = | 150 gboolean (*cb)(GSource*, GSourceFunc, void*) = |
| 124 gdksource_->source_funcs->dispatch; | 151 gdksource_->source_funcs->dispatch; |
| 125 gdksource_->source_funcs->dispatch = PlaceholderDispatch; | 152 gdksource_->source_funcs->dispatch = PlaceholderDispatch; |
| 126 | 153 |
| 127 dispatching_event_ = true; | 154 dispatching_event_ = true; |
| 128 retvalue = g_main_context_iteration(context, block); | 155 retvalue = g_main_context_iteration(context, block); |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 171 return; | 198 return; |
| 172 } | 199 } |
| 173 | 200 |
| 174 int major = 2, minor = 0; | 201 int major = 2, minor = 0; |
| 175 if (XIQueryVersion(xdisplay, &major, &minor) == BadRequest) { | 202 if (XIQueryVersion(xdisplay, &major, &minor) == BadRequest) { |
| 176 DLOG(WARNING) << "XInput2 not supported in the server."; | 203 DLOG(WARNING) << "XInput2 not supported in the server."; |
| 177 xiopcode_ = -1; | 204 xiopcode_ = -1; |
| 178 return; | 205 return; |
| 179 } | 206 } |
| 180 | 207 |
| 208 // TODO(sad): Here, we only setup so that the X windows created by GTK+ are |
| 209 // setup for XInput2 events. We need a way to listen for XInput2 events for X |
| 210 // windows created by other means (e.g. for context menus). |
| 181 SetupGtkWidgetRealizeNotifier(this); | 211 SetupGtkWidgetRealizeNotifier(this); |
| 182 | 212 |
| 183 // Instead of asking X for the list of devices all the time, let's maintain a | 213 // Instead of asking X for the list of devices all the time, let's maintain a |
| 184 // list of slave (physical) and master (virtual) pointer devices. | 214 // list of slave (physical) and master (virtual) pointer devices. |
| 185 int count = 0; | 215 int count = 0; |
| 186 XIDeviceInfo* devices = XIQueryDevice(xdisplay, XIAllDevices, &count); | 216 XIDeviceInfo* devices = XIQueryDevice(xdisplay, XIAllDevices, &count); |
| 187 for (int i = 0; i < count; i++) { | 217 for (int i = 0; i < count; i++) { |
| 188 XIDeviceInfo* devinfo = devices + i; | 218 XIDeviceInfo* devinfo = devices + i; |
| 189 if (devinfo->use == XISlavePointer) { | 219 if (devinfo->use == XISlavePointer) { |
| 190 slaves_.insert(devinfo->deviceid); | 220 slaves_.insert(devinfo->deviceid); |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 235 XFlush(xdisplay); | 265 XFlush(xdisplay); |
| 236 } | 266 } |
| 237 | 267 |
| 238 #endif // HAVE_XINPUT2 | 268 #endif // HAVE_XINPUT2 |
| 239 | 269 |
| 240 void MessagePumpGlibX::EventDispatcherX(GdkEvent* event, gpointer data) { | 270 void MessagePumpGlibX::EventDispatcherX(GdkEvent* event, gpointer data) { |
| 241 MessagePumpGlibX* pump_x = reinterpret_cast<MessagePumpGlibX*>(data); | 271 MessagePumpGlibX* pump_x = reinterpret_cast<MessagePumpGlibX*>(data); |
| 242 | 272 |
| 243 if (!pump_x->gdksource_) { | 273 if (!pump_x->gdksource_) { |
| 244 pump_x->gdksource_ = g_main_current_source(); | 274 pump_x->gdksource_ = g_main_current_source(); |
| 275 pump_x->gdkdispatcher_ = pump_x->gdksource_->source_funcs->dispatch; |
| 245 } else if (!pump_x->IsDispatchingEvent()) { | 276 } else if (!pump_x->IsDispatchingEvent()) { |
| 246 if (event->type != GDK_NOTHING && | 277 if (event->type != GDK_NOTHING && |
| 247 pump_x->capture_gdk_events_[event->type]) { | 278 pump_x->capture_gdk_events_[event->type]) { |
| 248 // TODO(sad): An X event is caught by the GDK handler. Put it back in the | 279 // TODO(sad): An X event is caught by the GDK handler. Put it back in the |
| 249 // X queue so that we catch it in the next iteration. When done, the | 280 // X queue so that we catch it in the next iteration. When done, the |
| 250 // following DLOG statement will be removed. | 281 // following DLOG statement will be removed. |
| 251 DLOG(WARNING) << "GDK received an event it shouldn't have"; | 282 DLOG(WARNING) << "GDK received an event it shouldn't have"; |
| 252 } | 283 } |
| 253 } | 284 } |
| 254 | 285 |
| 255 pump_x->DispatchEvents(event); | 286 pump_x->DispatchEvents(event); |
| 256 } | 287 } |
| 257 | 288 |
| 258 } // namespace base | 289 } // namespace base |
| OLD | NEW |