OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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) | |
9 #include <X11/extensions/XInput2.h> | 8 #include <X11/extensions/XInput2.h> |
10 #else | |
11 #include <X11/Xlib.h> | |
12 #endif | |
13 | 9 |
14 #include "base/message_pump_glib_x_dispatch.h" | 10 #include "base/message_pump_glib_x_dispatch.h" |
15 | 11 |
16 namespace { | 12 namespace { |
17 | 13 |
18 gboolean PlaceholderDispatch(GSource* source, | 14 gboolean PlaceholderDispatch(GSource* source, |
19 GSourceFunc cb, | 15 GSourceFunc cb, |
20 gpointer data) { | 16 gpointer data) { |
21 return TRUE; | 17 return TRUE; |
22 } | 18 } |
23 | 19 |
24 } // namespace | 20 } // namespace |
25 | 21 |
26 namespace base { | 22 namespace base { |
27 | 23 |
28 MessagePumpGlibX::MessagePumpGlibX() : base::MessagePumpForUI(), | 24 MessagePumpGlibX::MessagePumpGlibX() : base::MessagePumpForUI(), |
29 #if defined(HAVE_XINPUT2) | |
30 xiopcode_(-1), | 25 xiopcode_(-1), |
31 #endif | |
32 gdksource_(NULL), | 26 gdksource_(NULL), |
33 dispatching_event_(false), | 27 dispatching_event_(false), |
34 capture_x_events_(0), | 28 capture_x_events_(0), |
35 capture_gdk_events_(0) { | 29 capture_gdk_events_(0) { |
36 gdk_window_add_filter(NULL, &GdkEventFilter, this); | 30 gdk_window_add_filter(NULL, &GdkEventFilter, this); |
37 gdk_event_handler_set(&EventDispatcherX, this, NULL); | 31 gdk_event_handler_set(&EventDispatcherX, this, NULL); |
38 | 32 |
39 #if defined(HAVE_XINPUT2) | |
40 InitializeXInput2(); | 33 InitializeXInput2(); |
41 #endif | |
42 InitializeEventsToCapture(); | 34 InitializeEventsToCapture(); |
43 } | 35 } |
44 | 36 |
45 MessagePumpGlibX::~MessagePumpGlibX() { | 37 MessagePumpGlibX::~MessagePumpGlibX() { |
46 gdk_window_remove_filter(NULL, &GdkEventFilter, this); | 38 gdk_window_remove_filter(NULL, &GdkEventFilter, this); |
47 | 39 |
48 // It is not necessary to reset the GDK event handler using | 40 // It is not necessary to reset the GDK event handler using |
49 // gdk_event_handler_set since it's done in the destructor for | 41 // gdk_event_handler_set since it's done in the destructor for |
50 // MessagePumpForUI. | 42 // MessagePumpForUI. |
51 } | 43 } |
52 | 44 |
53 bool MessagePumpGlibX::ShouldCaptureXEvent(XEvent* xev) { | 45 bool MessagePumpGlibX::ShouldCaptureXEvent(XEvent* xev) { |
54 return capture_x_events_[xev->type] | 46 return capture_x_events_[xev->type] && |
55 #if defined(HAVE_XINPUT2) | 47 (xev->type != GenericEvent || xev->xcookie.extension == xiopcode_); |
56 && (xev->type != GenericEvent || xev->xcookie.extension == xiopcode_) | |
57 #endif | |
58 ; | |
59 } | 48 } |
60 | 49 |
61 | 50 |
62 bool MessagePumpGlibX::ProcessXEvent(XEvent* xev) { | 51 bool MessagePumpGlibX::ProcessXEvent(XEvent* xev) { |
63 bool should_quit = false; | 52 bool should_quit = false; |
64 | 53 |
65 #if defined(HAVE_XINPUT2) | |
66 bool have_cookie = false; | 54 bool have_cookie = false; |
67 if (xev->type == GenericEvent && | 55 if (xev->type == GenericEvent && |
68 XGetEventData(xev->xgeneric.display, &xev->xcookie)) { | 56 XGetEventData(xev->xgeneric.display, &xev->xcookie)) { |
69 have_cookie = true; | 57 have_cookie = true; |
70 } | 58 } |
71 #endif | |
72 | 59 |
73 if (!WillProcessXEvent(xev)) { | 60 if (!WillProcessXEvent(xev)) { |
74 MessagePumpGlibXDispatcher::DispatchStatus status = | 61 MessagePumpGlibXDispatcher::DispatchStatus status = |
75 static_cast<MessagePumpGlibXDispatcher*> | 62 static_cast<MessagePumpGlibXDispatcher*> |
76 (GetDispatcher())->DispatchX(xev); | 63 (GetDispatcher())->DispatchX(xev); |
77 | 64 |
78 if (status == MessagePumpGlibXDispatcher::EVENT_QUIT) { | 65 if (status == MessagePumpGlibXDispatcher::EVENT_QUIT) { |
79 should_quit = true; | 66 should_quit = true; |
80 Quit(); | 67 Quit(); |
81 } else if (status == MessagePumpGlibXDispatcher::EVENT_IGNORED) { | 68 } else if (status == MessagePumpGlibXDispatcher::EVENT_IGNORED) { |
82 DLOG(WARNING) << "Event (" << xev->type << ") not handled."; | 69 DLOG(WARNING) << "Event (" << xev->type << ") not handled."; |
83 } | 70 } |
84 } | 71 } |
85 | 72 |
86 #if defined(HAVE_XINPUT2) | |
87 if (have_cookie) { | 73 if (have_cookie) { |
88 XFreeEventData(xev->xgeneric.display, &xev->xcookie); | 74 XFreeEventData(xev->xgeneric.display, &xev->xcookie); |
89 } | 75 } |
90 #endif | |
91 | 76 |
92 return should_quit; | 77 return should_quit; |
93 } | 78 } |
94 | 79 |
95 bool MessagePumpGlibX::RunOnce(GMainContext* context, bool block) { | 80 bool MessagePumpGlibX::RunOnce(GMainContext* context, bool block) { |
96 GdkDisplay* gdisp = gdk_display_get_default(); | 81 GdkDisplay* gdisp = gdk_display_get_default(); |
97 if (!gdisp || !GetDispatcher()) | 82 if (!gdisp || !GetDispatcher()) |
98 return MessagePumpForUI::RunOnce(context, block); | 83 return MessagePumpForUI::RunOnce(context, block); |
99 | 84 |
100 Display* display = GDK_DISPLAY_XDISPLAY(gdisp); | 85 Display* display = GDK_DISPLAY_XDISPLAY(gdisp); |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
191 | 176 |
192 capture_x_events_[ButtonPress] = true; | 177 capture_x_events_[ButtonPress] = true; |
193 capture_gdk_events_[GDK_BUTTON_PRESS] = true; | 178 capture_gdk_events_[GDK_BUTTON_PRESS] = true; |
194 | 179 |
195 capture_x_events_[ButtonRelease] = true; | 180 capture_x_events_[ButtonRelease] = true; |
196 capture_gdk_events_[GDK_BUTTON_RELEASE] = true; | 181 capture_gdk_events_[GDK_BUTTON_RELEASE] = true; |
197 | 182 |
198 capture_x_events_[MotionNotify] = true; | 183 capture_x_events_[MotionNotify] = true; |
199 capture_gdk_events_[GDK_MOTION_NOTIFY] = true; | 184 capture_gdk_events_[GDK_MOTION_NOTIFY] = true; |
200 | 185 |
201 #if defined(HAVE_XINPUT2) | |
202 capture_x_events_[GenericEvent] = true; | 186 capture_x_events_[GenericEvent] = true; |
203 #endif | |
204 } | 187 } |
205 | 188 |
206 #if defined(HAVE_XINPUT2) | |
207 void MessagePumpGlibX::InitializeXInput2(void) { | 189 void MessagePumpGlibX::InitializeXInput2(void) { |
208 GdkDisplay* display = gdk_display_get_default(); | 190 GdkDisplay* display = gdk_display_get_default(); |
209 if (!display) | 191 if (!display) |
210 return; | 192 return; |
211 | 193 |
212 Display* xdisplay = GDK_DISPLAY_XDISPLAY(display); | 194 Display* xdisplay = GDK_DISPLAY_XDISPLAY(display); |
213 int event, err; | 195 int event, err; |
214 | 196 |
215 if (!XQueryExtension(xdisplay, "XInputExtension", &xiopcode_, &event, &err)) { | 197 if (!XQueryExtension(xdisplay, "XInputExtension", &xiopcode_, &event, &err)) { |
216 DLOG(WARNING) << "X Input extension not available."; | 198 DLOG(WARNING) << "X Input extension not available."; |
217 xiopcode_ = -1; | 199 xiopcode_ = -1; |
218 return; | 200 return; |
219 } | 201 } |
220 | 202 |
221 int major = 2, minor = 0; | 203 int major = 2, minor = 0; |
222 if (XIQueryVersion(xdisplay, &major, &minor) == BadRequest) { | 204 if (XIQueryVersion(xdisplay, &major, &minor) == BadRequest) { |
223 DLOG(WARNING) << "XInput2 not supported in the server."; | 205 DLOG(WARNING) << "XInput2 not supported in the server."; |
224 xiopcode_ = -1; | 206 xiopcode_ = -1; |
225 return; | 207 return; |
226 } | 208 } |
227 } | 209 } |
228 #endif // HAVE_XINPUT2 | |
229 | 210 |
230 bool MessagePumpXObserver::WillProcessXEvent(XEvent* xev) { | 211 bool MessagePumpXObserver::WillProcessXEvent(XEvent* xev) { |
231 return false; | 212 return false; |
232 } | 213 } |
233 | 214 |
234 } // namespace base | 215 } // namespace base |
OLD | NEW |