| 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_loop/message_pump_aurax11.h" | 5 #include "base/message_loop/message_pump_aurax11.h" |
| 6 | 6 |
| 7 #include <glib.h> | 7 #include <glib.h> |
| 8 #include <X11/X.h> | 8 #include <X11/X.h> |
| 9 #include <X11/extensions/XInput2.h> | 9 #include <X11/extensions/XInput2.h> |
| 10 #include <X11/XKBlib.h> | 10 #include <X11/XKBlib.h> |
| (...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 132 x_source_(NULL) { | 132 x_source_(NULL) { |
| 133 InitializeXInput2(); | 133 InitializeXInput2(); |
| 134 InitializeXkb(); | 134 InitializeXkb(); |
| 135 InitXSource(); | 135 InitXSource(); |
| 136 | 136 |
| 137 // Can't put this in the initializer list because g_xdisplay may not exist | 137 // Can't put this in the initializer list because g_xdisplay may not exist |
| 138 // until after InitXSource(). | 138 // until after InitXSource(). |
| 139 x_root_window_ = DefaultRootWindow(g_xdisplay); | 139 x_root_window_ = DefaultRootWindow(g_xdisplay); |
| 140 } | 140 } |
| 141 | 141 |
| 142 MessagePumpAuraX11::~MessagePumpAuraX11() { |
| 143 g_source_destroy(x_source_); |
| 144 g_source_unref(x_source_); |
| 145 XCloseDisplay(g_xdisplay); |
| 146 g_xdisplay = NULL; |
| 147 } |
| 148 |
| 142 // static | 149 // static |
| 143 Display* MessagePumpAuraX11::GetDefaultXDisplay() { | 150 Display* MessagePumpAuraX11::GetDefaultXDisplay() { |
| 144 if (!g_xdisplay) | 151 if (!g_xdisplay) |
| 145 g_xdisplay = XOpenDisplay(NULL); | 152 g_xdisplay = XOpenDisplay(NULL); |
| 146 return g_xdisplay; | 153 return g_xdisplay; |
| 147 } | 154 } |
| 148 | 155 |
| 149 // static | 156 // static |
| 150 bool MessagePumpAuraX11::HasXInput2() { | 157 bool MessagePumpAuraX11::HasXInput2() { |
| 151 return InitializeXInput2(); | 158 return InitializeXInput2(); |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 204 GetDispatcher() ? GetDispatcher() : this; | 211 GetDispatcher() ? GetDispatcher() : this; |
| 205 | 212 |
| 206 do { | 213 do { |
| 207 // Block until there's a message of |event_mask| type on |w|. Then remove | 214 // Block until there's a message of |event_mask| type on |w|. Then remove |
| 208 // it from the queue and stuff it in |event|. | 215 // it from the queue and stuff it in |event|. |
| 209 XWindowEvent(display, xid, StructureNotifyMask, &event); | 216 XWindowEvent(display, xid, StructureNotifyMask, &event); |
| 210 ProcessXEvent(dispatcher, &event); | 217 ProcessXEvent(dispatcher, &event); |
| 211 } while (event.type != MapNotify); | 218 } while (event.type != MapNotify); |
| 212 } | 219 } |
| 213 | 220 |
| 214 MessagePumpAuraX11::~MessagePumpAuraX11() { | |
| 215 g_source_destroy(x_source_); | |
| 216 g_source_unref(x_source_); | |
| 217 XCloseDisplay(g_xdisplay); | |
| 218 g_xdisplay = NULL; | |
| 219 } | |
| 220 | |
| 221 void MessagePumpAuraX11::InitXSource() { | 221 void MessagePumpAuraX11::InitXSource() { |
| 222 // CHECKs are to help track down crbug.com/113106. | 222 // CHECKs are to help track down crbug.com/113106. |
| 223 CHECK(!x_source_); | 223 CHECK(!x_source_); |
| 224 Display* display = GetDefaultXDisplay(); | 224 Display* display = GetDefaultXDisplay(); |
| 225 CHECK(display) << "Unable to get connection to X server"; | 225 CHECK(display) << "Unable to get connection to X server"; |
| 226 x_poll_.reset(new GPollFD()); | 226 x_poll_.reset(new GPollFD()); |
| 227 CHECK(x_poll_.get()); | 227 CHECK(x_poll_.get()); |
| 228 x_poll_->fd = ConnectionNumber(display); | 228 x_poll_->fd = ConnectionNumber(display); |
| 229 x_poll_->events = G_IO_IN; | 229 x_poll_->events = G_IO_IN; |
| 230 | 230 |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 298 if (FindEventTarget(xev) == x_root_window_) { | 298 if (FindEventTarget(xev) == x_root_window_) { |
| 299 FOR_EACH_OBSERVER(MessagePumpDispatcher, root_window_dispatchers_, | 299 FOR_EACH_OBSERVER(MessagePumpDispatcher, root_window_dispatchers_, |
| 300 Dispatch(xev)); | 300 Dispatch(xev)); |
| 301 return true; | 301 return true; |
| 302 } | 302 } |
| 303 MessagePumpDispatcher* dispatcher = GetDispatcherForXEvent(xev); | 303 MessagePumpDispatcher* dispatcher = GetDispatcherForXEvent(xev); |
| 304 return dispatcher ? dispatcher->Dispatch(xev) : true; | 304 return dispatcher ? dispatcher->Dispatch(xev) : true; |
| 305 } | 305 } |
| 306 | 306 |
| 307 } // namespace base | 307 } // namespace base |
| OLD | NEW |