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 |
88 if (XPending(display)) { | 89 if (XPending(display)) { |
89 XEvent xev; | 90 XEvent xev; |
90 XPeekEvent(display, &xev); | 91 XPeekEvent(display, &xev); |
91 if (capture_x_events_[xev.type] | 92 if (capture_x_events_[xev.type] |
92 #if defined(HAVE_XINPUT2) | 93 #if defined(HAVE_XINPUT2) |
93 && (xev.type != GenericEvent || xev.xcookie.extension == xiopcode_) | 94 && (xev.type != GenericEvent || xev.xcookie.extension == xiopcode_) |
94 #endif | 95 #endif |
95 ) { | 96 ) { |
96 XNextEvent(display, &xev); | 97 XNextEvent(display, &xev); |
97 | 98 |
98 bool processed = static_cast<MessagePumpGlibXDispatcher*> | 99 #if defined(HAVE_XINPUT2) |
| 100 bool have_cookie = false; |
| 101 if (xev.type == GenericEvent && |
| 102 XGetEventData(xev.xgeneric.display, &xev.xcookie)) { |
| 103 have_cookie = true; |
| 104 } |
| 105 #endif |
| 106 |
| 107 MessagePumpGlibXDispatcher::DispatchStatus status = |
| 108 static_cast<MessagePumpGlibXDispatcher*> |
99 (GetDispatcher())->Dispatch(&xev); | 109 (GetDispatcher())->Dispatch(&xev); |
100 | 110 |
101 if (!processed) { | 111 if (status == MessagePumpGlibXDispatcher::EVENT_QUIT) { |
| 112 state_->should_quit = true; |
| 113 } else if (status == MessagePumpGlibXDispatcher::EVENT_IGNORED) { |
102 DLOG(WARNING) << "Event (" << xev.type << ") not handled."; | 114 DLOG(WARNING) << "Event (" << xev.type << ") not handled."; |
103 | 115 |
104 // TODO(sad): It is necessary to put back the event so that the default | 116 // 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 | 117 // GDK events handler can take care of it. Without this, it is |
106 // impossible to use the omnibox at the moment. However, this will | 118 // impossible to use the omnibox at the moment. However, this will |
107 // eventually be removed once the omnibox code is updated for touchui. | 119 // eventually be removed once the omnibox code is updated for touchui. |
108 XPutBackEvent(display, &xev); | 120 XPutBackEvent(display, &xev); |
| 121 if (gdksource_) |
| 122 gdksource_->source_funcs->dispatch = gdkdispatcher_; |
109 g_main_context_iteration(context, FALSE); | 123 g_main_context_iteration(context, FALSE); |
110 } | 124 } |
| 125 |
| 126 #if defined(HAVE_XINPUT2) |
| 127 if (have_cookie) { |
| 128 XFreeEventData(xev.xgeneric.display, &xev.xcookie); |
| 129 } |
| 130 #endif |
111 } else { | 131 } else { |
112 // TODO(sad): A couple of extra events can still sneak in during this. | 132 // 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 | 133 // Those should be sent back to the X queue from the dispatcher |
114 // EventDispatcherX. | 134 // EventDispatcherX. |
| 135 if (gdksource_) |
| 136 gdksource_->source_funcs->dispatch = gdkdispatcher_; |
115 g_main_context_iteration(context, FALSE); | 137 g_main_context_iteration(context, FALSE); |
116 } | 138 } |
117 } | 139 } |
118 | 140 |
| 141 if (state_->should_quit) |
| 142 return true; |
| 143 |
119 bool retvalue; | 144 bool retvalue; |
120 if (gdksource_) { | 145 if (gdksource_) { |
121 // Replace the dispatch callback of the GDK event source temporarily so that | 146 // Replace the dispatch callback of the GDK event source temporarily so that |
122 // it doesn't read events from X. | 147 // it doesn't read events from X. |
123 gboolean (*cb)(GSource*, GSourceFunc, void*) = | 148 gboolean (*cb)(GSource*, GSourceFunc, void*) = |
124 gdksource_->source_funcs->dispatch; | 149 gdksource_->source_funcs->dispatch; |
125 gdksource_->source_funcs->dispatch = PlaceholderDispatch; | 150 gdksource_->source_funcs->dispatch = PlaceholderDispatch; |
126 | 151 |
127 dispatching_event_ = true; | 152 dispatching_event_ = true; |
128 retvalue = g_main_context_iteration(context, block); | 153 retvalue = g_main_context_iteration(context, block); |
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
235 XFlush(xdisplay); | 260 XFlush(xdisplay); |
236 } | 261 } |
237 | 262 |
238 #endif // HAVE_XINPUT2 | 263 #endif // HAVE_XINPUT2 |
239 | 264 |
240 void MessagePumpGlibX::EventDispatcherX(GdkEvent* event, gpointer data) { | 265 void MessagePumpGlibX::EventDispatcherX(GdkEvent* event, gpointer data) { |
241 MessagePumpGlibX* pump_x = reinterpret_cast<MessagePumpGlibX*>(data); | 266 MessagePumpGlibX* pump_x = reinterpret_cast<MessagePumpGlibX*>(data); |
242 | 267 |
243 if (!pump_x->gdksource_) { | 268 if (!pump_x->gdksource_) { |
244 pump_x->gdksource_ = g_main_current_source(); | 269 pump_x->gdksource_ = g_main_current_source(); |
| 270 pump_x->gdkdispatcher_ = pump_x->gdksource_->source_funcs->dispatch; |
245 } else if (!pump_x->IsDispatchingEvent()) { | 271 } else if (!pump_x->IsDispatchingEvent()) { |
246 if (event->type != GDK_NOTHING && | 272 if (event->type != GDK_NOTHING && |
247 pump_x->capture_gdk_events_[event->type]) { | 273 pump_x->capture_gdk_events_[event->type]) { |
248 // TODO(sad): An X event is caught by the GDK handler. Put it back in the | 274 // 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 | 275 // X queue so that we catch it in the next iteration. When done, the |
250 // following DLOG statement will be removed. | 276 // following DLOG statement will be removed. |
251 DLOG(WARNING) << "GDK received an event it shouldn't have"; | 277 DLOG(WARNING) << "GDK received an event it shouldn't have"; |
252 } | 278 } |
253 } | 279 } |
254 | 280 |
255 pump_x->DispatchEvents(event); | 281 pump_x->DispatchEvents(event); |
256 } | 282 } |
257 | 283 |
258 } // namespace base | 284 } // namespace base |
OLD | NEW |