Chromium Code Reviews| Index: base/message_pump_glib_x.cc |
| diff --git a/base/message_pump_glib_x.cc b/base/message_pump_glib_x.cc |
| index b4d677ef25effef3f03bbcabe3f5708b9d7d2f51..3cc11f99fcbd6244191232835bb037253d4d8ca2 100644 |
| --- a/base/message_pump_glib_x.cc |
| +++ b/base/message_pump_glib_x.cc |
| @@ -33,6 +33,7 @@ MessagePumpGlibX::MessagePumpGlibX() : base::MessagePumpForUI(), |
| dispatching_event_(false), |
| capture_x_events_(0), |
| capture_gdk_events_(0) { |
| + gdk_window_add_filter(NULL, GdkEventFilter, this); |
|
sadrul
2011/05/24 15:34:18
To keep with the existing code, '&GdkEventFilter'
Yufeng Shen (Slow to review)
2011/05/24 18:30:50
Done.
|
| gdk_event_handler_set(&EventDispatcherX, this, NULL); |
| #if defined(HAVE_XINPUT2) |
| @@ -44,6 +45,48 @@ MessagePumpGlibX::MessagePumpGlibX() : base::MessagePumpForUI(), |
| MessagePumpGlibX::~MessagePumpGlibX() { |
| } |
| +bool MessagePumpGlibX::ShouldCaptureXEvent(XEvent* xev) { |
| + return capture_x_events_[xev->type] |
| +#if defined(HAVE_XINPUT2) |
| + && (xev->type != GenericEvent || xev->xcookie.extension == xiopcode_) |
| +#endif |
| + ; |
| +} |
| + |
| + |
| +bool MessagePumpGlibX::ProcessXEvent(XEvent* xev) { |
| + bool should_quit = false; |
| + |
| +#if defined(HAVE_XINPUT2) |
| + bool have_cookie = false; |
| + if (xev->type == GenericEvent && |
| + XGetEventData(xev->xgeneric.display, &xev->xcookie)) { |
| + have_cookie = true; |
| + } |
| +#endif |
| + |
| + if (!WillProcessXEvent(xev)) { |
| + MessagePumpGlibXDispatcher::DispatchStatus status = |
| + static_cast<MessagePumpGlibXDispatcher*> |
| + (GetDispatcher())->DispatchX(xev); |
| + |
| + if (status == MessagePumpGlibXDispatcher::EVENT_QUIT) { |
| + should_quit = true; |
| + Quit(); |
| + } else if (status == MessagePumpGlibXDispatcher::EVENT_IGNORED) { |
| + DLOG(WARNING) << "Event (" << xev->type << ") not handled."; |
| + } |
| + } |
| + |
| +#if defined(HAVE_XINPUT2) |
| + if (have_cookie) { |
| + XFreeEventData(xev->xgeneric.display, &xev->xcookie); |
| + } |
| +#endif |
| + |
| + return should_quit; |
| +} |
| + |
| bool MessagePumpGlibX::RunOnce(GMainContext* context, bool block) { |
| GdkDisplay* gdisp = gdk_display_get_default(); |
| if (!gdisp || !GetDispatcher()) |
| @@ -55,39 +98,10 @@ bool MessagePumpGlibX::RunOnce(GMainContext* context, bool block) { |
| if (XPending(display)) { |
| XEvent xev; |
| XPeekEvent(display, &xev); |
| - if (capture_x_events_[xev.type] |
| -#if defined(HAVE_XINPUT2) |
| - && (xev.type != GenericEvent || xev.xcookie.extension == xiopcode_) |
| -#endif |
| - ) { |
| - XNextEvent(display, &xev); |
| - |
| -#if defined(HAVE_XINPUT2) |
| - bool have_cookie = false; |
| - if (xev.type == GenericEvent && |
| - XGetEventData(xev.xgeneric.display, &xev.xcookie)) { |
| - have_cookie = true; |
| - } |
| -#endif |
| - |
| - if (!WillProcessXEvent(&xev)) { |
| - MessagePumpGlibXDispatcher::DispatchStatus status = |
| - static_cast<MessagePumpGlibXDispatcher*> |
| - (GetDispatcher())->DispatchX(&xev); |
| - if (status == MessagePumpGlibXDispatcher::EVENT_QUIT) { |
| - should_quit = true; |
| - Quit(); |
| - } else if (status == MessagePumpGlibXDispatcher::EVENT_IGNORED) { |
| - DLOG(WARNING) << "Event (" << xev.type << ") not handled."; |
| - } |
| - } |
| - |
| -#if defined(HAVE_XINPUT2) |
| - if (have_cookie) { |
| - XFreeEventData(xev.xgeneric.display, &xev.xcookie); |
| - } |
| -#endif |
| + if (ShouldCaptureXEvent(&xev)) { |
| + XNextEvent(display, &xev); |
| + should_quit = ProcessXEvent(&xev); |
|
sadrul
2011/05/24 15:34:18
Using should_quit isn't necessary anymore:
if (
Yufeng Shen (Slow to review)
2011/05/24 18:30:50
Done.
|
| } else { |
| // TODO(sad): A couple of extra events can still sneak in during this. |
| // Those should be sent back to the X queue from the dispatcher |
| @@ -121,6 +135,22 @@ bool MessagePumpGlibX::RunOnce(GMainContext* context, bool block) { |
| return retvalue; |
| } |
| +GdkFilterReturn MessagePumpGlibX::GdkEventFilter(GdkXEvent* gxevent, |
| + GdkEvent* gevent, |
| + gpointer data) { |
| + MessagePumpGlibX* pump = static_cast<MessagePumpGlibX*>(data); |
| + XEvent* xev = static_cast<XEvent*>(gxevent); |
| + |
| + if (pump->ShouldCaptureXEvent(xev) && pump->GetDispatcher()) { |
| + pump->ProcessXEvent(xev); |
|
sadrul
2011/05/24 15:34:18
This looks good as is. But should this do anything
Yufeng Shen (Slow to review)
2011/05/24 18:30:50
Since it is in the GDK's message processing loop,
|
| + return GDK_FILTER_REMOVE; |
| + } |
| + |
| + return GDK_FILTER_CONTINUE; |
| +} |
| + |
| + |
|
sadrul
2011/05/24 15:34:18
Too many new lines!
Yufeng Shen (Slow to review)
2011/05/24 18:30:50
Done.
|
| + |
| bool MessagePumpGlibX::WillProcessXEvent(XEvent* xevent) { |
| ObserverListBase<Observer>::Iterator it(observers()); |
| Observer* obs; |