| OLD | NEW |
| (Empty) |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "base/message_loop/message_pump_x11.h" | |
| 6 | |
| 7 #include <glib.h> | |
| 8 #include <X11/X.h> | |
| 9 #include <X11/extensions/XInput2.h> | |
| 10 #include <X11/XKBlib.h> | |
| 11 | |
| 12 #include "base/basictypes.h" | |
| 13 #include "base/message_loop/message_loop.h" | |
| 14 | |
| 15 namespace base { | |
| 16 | |
| 17 namespace { | |
| 18 | |
| 19 // The connection is essentially a global that's accessed through a static | |
| 20 // method and destroyed whenever ~MessagePumpX11() is called. We do this | |
| 21 // for historical reasons so user code can call | |
| 22 // MessagePumpForUI::GetDefaultXDisplay() where MessagePumpForUI is a typedef | |
| 23 // to whatever type in the current build. | |
| 24 // | |
| 25 // TODO(erg): This can be changed to something more sane like | |
| 26 // MessagePumpX11::Current()->display() once MessagePumpGtk goes away. | |
| 27 Display* g_xdisplay = NULL; | |
| 28 | |
| 29 } // namespace | |
| 30 | |
| 31 MessagePumpX11::MessagePumpX11() : MessagePumpGlib() { | |
| 32 GetDefaultXDisplay(); | |
| 33 } | |
| 34 | |
| 35 MessagePumpX11::~MessagePumpX11() { | |
| 36 if (g_xdisplay) { | |
| 37 XCloseDisplay(g_xdisplay); | |
| 38 g_xdisplay = NULL; | |
| 39 } | |
| 40 } | |
| 41 | |
| 42 // static | |
| 43 Display* MessagePumpX11::GetDefaultXDisplay() { | |
| 44 if (!g_xdisplay) | |
| 45 g_xdisplay = XOpenDisplay(NULL); | |
| 46 return g_xdisplay; | |
| 47 } | |
| 48 | |
| 49 #if defined(TOOLKIT_GTK) | |
| 50 // static | |
| 51 MessagePumpX11* MessagePumpX11::Current() { | |
| 52 MessageLoop* loop = MessageLoop::current(); | |
| 53 return static_cast<MessagePumpX11*>(loop->pump_gpu()); | |
| 54 } | |
| 55 #else | |
| 56 // static | |
| 57 MessagePumpX11* MessagePumpX11::Current() { | |
| 58 MessageLoopForUI* loop = MessageLoopForUI::current(); | |
| 59 return static_cast<MessagePumpX11*>(loop->pump_ui()); | |
| 60 } | |
| 61 #endif | |
| 62 | |
| 63 } // namespace base | |
| OLD | NEW |