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

Side by Side Diff: base/message_pump_glib_x.cc

Issue 5110011: A non-GTK version of menus for touchui. (Closed) Base URL: http://git.chromium.org/git/chromium.git@trunk
Patch Set: Add TODO Created 10 years, 1 month 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « base/message_pump_glib_x.h ('k') | base/message_pump_glib_x_dispatch.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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;
sadrul 2010/11/29 15:56:56 Instead of setting |should_quit| here, we can simp
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 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
171 return; 196 return;
172 } 197 }
173 198
174 int major = 2, minor = 0; 199 int major = 2, minor = 0;
175 if (XIQueryVersion(xdisplay, &major, &minor) == BadRequest) { 200 if (XIQueryVersion(xdisplay, &major, &minor) == BadRequest) {
176 DLOG(WARNING) << "XInput2 not supported in the server."; 201 DLOG(WARNING) << "XInput2 not supported in the server.";
177 xiopcode_ = -1; 202 xiopcode_ = -1;
178 return; 203 return;
179 } 204 }
180 205
206 // TODO(sad): Here, we only setup so that the X windows created by GTK+ are
207 // setup for XInput2 events. We need a way to listen for XInput2 events for X
208 // windows created by other means (e.g. for context menus).
181 SetupGtkWidgetRealizeNotifier(this); 209 SetupGtkWidgetRealizeNotifier(this);
182 210
183 // Instead of asking X for the list of devices all the time, let's maintain a 211 // 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. 212 // list of slave (physical) and master (virtual) pointer devices.
185 int count = 0; 213 int count = 0;
186 XIDeviceInfo* devices = XIQueryDevice(xdisplay, XIAllDevices, &count); 214 XIDeviceInfo* devices = XIQueryDevice(xdisplay, XIAllDevices, &count);
187 for (int i = 0; i < count; i++) { 215 for (int i = 0; i < count; i++) {
188 XIDeviceInfo* devinfo = devices + i; 216 XIDeviceInfo* devinfo = devices + i;
189 if (devinfo->use == XISlavePointer) { 217 if (devinfo->use == XISlavePointer) {
190 slaves_.insert(devinfo->deviceid); 218 slaves_.insert(devinfo->deviceid);
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
235 XFlush(xdisplay); 263 XFlush(xdisplay);
236 } 264 }
237 265
238 #endif // HAVE_XINPUT2 266 #endif // HAVE_XINPUT2
239 267
240 void MessagePumpGlibX::EventDispatcherX(GdkEvent* event, gpointer data) { 268 void MessagePumpGlibX::EventDispatcherX(GdkEvent* event, gpointer data) {
241 MessagePumpGlibX* pump_x = reinterpret_cast<MessagePumpGlibX*>(data); 269 MessagePumpGlibX* pump_x = reinterpret_cast<MessagePumpGlibX*>(data);
242 270
243 if (!pump_x->gdksource_) { 271 if (!pump_x->gdksource_) {
244 pump_x->gdksource_ = g_main_current_source(); 272 pump_x->gdksource_ = g_main_current_source();
273 pump_x->gdkdispatcher_ = pump_x->gdksource_->source_funcs->dispatch;
245 } else if (!pump_x->IsDispatchingEvent()) { 274 } else if (!pump_x->IsDispatchingEvent()) {
246 if (event->type != GDK_NOTHING && 275 if (event->type != GDK_NOTHING &&
247 pump_x->capture_gdk_events_[event->type]) { 276 pump_x->capture_gdk_events_[event->type]) {
248 // TODO(sad): An X event is caught by the GDK handler. Put it back in the 277 // 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 278 // X queue so that we catch it in the next iteration. When done, the
250 // following DLOG statement will be removed. 279 // following DLOG statement will be removed.
251 DLOG(WARNING) << "GDK received an event it shouldn't have"; 280 DLOG(WARNING) << "GDK received an event it shouldn't have";
252 } 281 }
253 } 282 }
254 283
255 pump_x->DispatchEvents(event); 284 pump_x->DispatchEvents(event);
256 } 285 }
257 286
258 } // namespace base 287 } // namespace base
OLDNEW
« no previous file with comments | « base/message_pump_glib_x.h ('k') | base/message_pump_glib_x_dispatch.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698