OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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_aurax11.h" | 5 #include "base/message_pump_aurax11.h" |
6 | 6 |
7 #include <glib.h> | 7 #include <glib.h> |
8 #include <X11/extensions/XInput2.h> | 8 #include <X11/extensions/XInput2.h> |
9 #include <X11/XKBlib.h> | 9 #include <X11/XKBlib.h> |
10 | 10 |
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
132 return InitializeXInput2(); | 132 return InitializeXInput2(); |
133 } | 133 } |
134 | 134 |
135 // static | 135 // static |
136 void MessagePumpAuraX11::SetDefaultDispatcher( | 136 void MessagePumpAuraX11::SetDefaultDispatcher( |
137 MessagePumpDispatcher* dispatcher) { | 137 MessagePumpDispatcher* dispatcher) { |
138 DCHECK(!g_default_dispatcher || !dispatcher); | 138 DCHECK(!g_default_dispatcher || !dispatcher); |
139 g_default_dispatcher = dispatcher; | 139 g_default_dispatcher = dispatcher; |
140 } | 140 } |
141 | 141 |
| 142 // static |
| 143 MessagePumpAuraX11* MessagePumpAuraX11::Current() { |
| 144 MessageLoopForUI* loop = MessageLoopForUI::current(); |
| 145 return static_cast<MessagePumpAuraX11*>(loop->pump_ui()); |
| 146 } |
| 147 |
142 bool MessagePumpAuraX11::DispatchXEvents() { | 148 bool MessagePumpAuraX11::DispatchXEvents() { |
143 Display* display = GetDefaultXDisplay(); | 149 Display* display = GetDefaultXDisplay(); |
144 DCHECK(display); | 150 DCHECK(display); |
145 MessagePumpDispatcher* dispatcher = | 151 MessagePumpDispatcher* dispatcher = |
146 GetDispatcher() ? GetDispatcher() : g_default_dispatcher; | 152 GetDispatcher() ? GetDispatcher() : g_default_dispatcher; |
147 | 153 |
148 // In the general case, we want to handle all pending events before running | 154 // In the general case, we want to handle all pending events before running |
149 // the tasks. This is what happens in the message_pump_glib case. | 155 // the tasks. This is what happens in the message_pump_glib case. |
150 while (XPending(display)) { | 156 while (XPending(display)) { |
151 XEvent xev; | 157 XEvent xev; |
152 XNextEvent(display, &xev); | 158 XNextEvent(display, &xev); |
153 if (dispatcher && ProcessXEvent(dispatcher, &xev)) | 159 if (dispatcher && ProcessXEvent(dispatcher, &xev)) |
154 return TRUE; | 160 return TRUE; |
155 } | 161 } |
156 return TRUE; | 162 return TRUE; |
157 } | 163 } |
158 | 164 |
| 165 void MessagePumpAuraX11::BlockUntilWindowMapped(unsigned long window) { |
| 166 XEvent event; |
| 167 |
| 168 Display* display = GetDefaultXDisplay(); |
| 169 DCHECK(display); |
| 170 |
| 171 MessagePumpDispatcher* dispatcher = |
| 172 GetDispatcher() ? GetDispatcher() : g_default_dispatcher; |
| 173 |
| 174 do { |
| 175 // Block until there's a message of |event_mask| type on |w|. Then remove |
| 176 // it from the queue and stuff it in |event|. |
| 177 XWindowEvent(display, window, StructureNotifyMask, &event); |
| 178 ProcessXEvent(dispatcher, &event); |
| 179 } while (event.type != MapNotify); |
| 180 } |
| 181 |
159 MessagePumpAuraX11::~MessagePumpAuraX11() { | 182 MessagePumpAuraX11::~MessagePumpAuraX11() { |
160 g_source_destroy(x_source_); | 183 g_source_destroy(x_source_); |
161 g_source_unref(x_source_); | 184 g_source_unref(x_source_); |
162 XCloseDisplay(g_xdisplay); | 185 XCloseDisplay(g_xdisplay); |
163 g_xdisplay = NULL; | 186 g_xdisplay = NULL; |
164 } | 187 } |
165 | 188 |
166 void MessagePumpAuraX11::InitXSource() { | 189 void MessagePumpAuraX11::InitXSource() { |
167 // CHECKs are to help track down crbug.com/113106. | 190 // CHECKs are to help track down crbug.com/113106. |
168 CHECK(!x_source_); | 191 CHECK(!x_source_); |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
215 return true; | 238 return true; |
216 } | 239 } |
217 return false; | 240 return false; |
218 } | 241 } |
219 | 242 |
220 void MessagePumpAuraX11::DidProcessXEvent(XEvent* xevent) { | 243 void MessagePumpAuraX11::DidProcessXEvent(XEvent* xevent) { |
221 FOR_EACH_OBSERVER(MessagePumpObserver, observers(), DidProcessEvent(xevent)); | 244 FOR_EACH_OBSERVER(MessagePumpObserver, observers(), DidProcessEvent(xevent)); |
222 } | 245 } |
223 | 246 |
224 } // namespace base | 247 } // namespace base |
OLD | NEW |