Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1295)

Unified Diff: base/message_pump_glib_x.cc

Issue 7050030: Fixing the issue of GDK discarding unsupported XInput events. (Closed) Base URL: http://git.chromium.org/git/chromium.git@trunk
Patch Set: Created 9 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « base/message_pump_glib_x.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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;
« no previous file with comments | « base/message_pump_glib_x.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698