| Index: base/message_pump_aurax11.cc
|
| diff --git a/base/message_pump_x.cc b/base/message_pump_aurax11.cc
|
| similarity index 59%
|
| rename from base/message_pump_x.cc
|
| rename to base/message_pump_aurax11.cc
|
| index b16cf35e29422310a9116d7abdd21caf09c591bc..405021fbd8fc884e6763869fe2d0d25b37b2f64f 100644
|
| --- a/base/message_pump_x.cc
|
| +++ b/base/message_pump_aurax11.cc
|
| @@ -2,17 +2,20 @@
|
| // Use of this source code is governed by a BSD-style license that can be
|
| // found in the LICENSE file.
|
|
|
| -#include "base/message_pump_x.h"
|
| +#include "base/message_pump_aurax11.h"
|
|
|
| #include <X11/extensions/XInput2.h>
|
|
|
| +#include <map>
|
| +
|
| #include "base/basictypes.h"
|
| +#include "base/lazy_instance.h"
|
| #include "base/message_loop.h"
|
|
|
| namespace {
|
|
|
| gboolean XSourcePrepare(GSource* source, gint* timeout_ms) {
|
| - if (XPending(base::MessagePumpX::GetDefaultXDisplay()))
|
| + if (XPending(base::MessagePumpAuraX11::GetDefaultXDisplay()))
|
| *timeout_ms = 0;
|
| else
|
| *timeout_ms = -1;
|
| @@ -20,13 +23,13 @@ gboolean XSourcePrepare(GSource* source, gint* timeout_ms) {
|
| }
|
|
|
| gboolean XSourceCheck(GSource* source) {
|
| - return XPending(base::MessagePumpX::GetDefaultXDisplay());
|
| + return XPending(base::MessagePumpAuraX11::GetDefaultXDisplay());
|
| }
|
|
|
| gboolean XSourceDispatch(GSource* source,
|
| GSourceFunc unused_func,
|
| gpointer data) {
|
| - base::MessagePumpX* pump = static_cast<base::MessagePumpX*>(data);
|
| + base::MessagePumpAuraX11* pump = static_cast<base::MessagePumpAuraX11*>(data);
|
| return pump->DispatchXEvents();
|
| }
|
|
|
| @@ -44,8 +47,31 @@ Display* g_xdisplay = NULL;
|
| // is specified.
|
| base::MessagePumpDispatcher* g_default_dispatcher = NULL;
|
|
|
| +// A cache of Atoms tied to the lifetime of |g_xdisplay|. Cleared when
|
| +// |g_xdisplay| is destroyed.
|
| +typedef std::map<base::atom::Name, ::Atom> AtomMap;
|
| +base::LazyInstance<AtomMap> g_cached_atoms = LAZY_INSTANCE_INITIALIZER;
|
| +
|
| +// A list of atoms that we'll intern on host creation to save roundtrips to the
|
| +// X11 server. Must be kept in sync with base::atom::Name
|
| +struct AtomInfo {
|
| + base::atom::Name id;
|
| + const char* name;
|
| +} const kAtomList[] = {
|
| + { base::atom::WM_DELETE_WINDOW, "WM_DELETE_WINDOW" },
|
| + { base::atom::_NET_WM_MOVERESIZE, "_NET_WM_MOVERESIZE" },
|
| + { base::atom::_NET_WM_PING, "_NET_WM_PING" },
|
| + { base::atom::_NET_WM_PID, "_NET_WM_PID" },
|
| + { base::atom::WM_S0, "WM_S0" },
|
| + { base::atom::_MOTIF_WM_HINTS, "_MOTIF_WM_HINTS" }
|
| +};
|
| +
|
| +// Our lists need to stay in sync here.
|
| +COMPILE_ASSERT(arraysize(kAtomList) == base::atom::ATOM_COUNT,
|
| + atom_lists_are_same_size);
|
| +
|
| bool InitializeXInput2Internal() {
|
| - Display* display = base::MessagePumpX::GetDefaultXDisplay();
|
| + Display* display = base::MessagePumpAuraX11::GetDefaultXDisplay();
|
| if (!display)
|
| return false;
|
|
|
| @@ -87,31 +113,57 @@ bool InitializeXInput2() {
|
|
|
| namespace base {
|
|
|
| -MessagePumpX::MessagePumpX() : MessagePumpGlib(),
|
| +MessagePumpAuraX11::MessagePumpAuraX11() : MessagePumpGlib(),
|
| x_source_(NULL) {
|
| InitializeXInput2();
|
| InitXSource();
|
| }
|
|
|
| // static
|
| -Display* MessagePumpX::GetDefaultXDisplay() {
|
| +Display* MessagePumpAuraX11::GetDefaultXDisplay() {
|
| if (!g_xdisplay)
|
| g_xdisplay = XOpenDisplay(NULL);
|
| return g_xdisplay;
|
| }
|
|
|
| // static
|
| -bool MessagePumpX::HasXInput2() {
|
| +::Atom MessagePumpAuraX11::GetAtom(atom::Name name) {
|
| + AtomMap& cached_atom_map = g_cached_atoms.Get();
|
| + if (cached_atom_map.empty()) {
|
| + // First time we're trying to use a cached atom. Intern all our atom data.
|
| + const char* all_names[atom::ATOM_COUNT];
|
| + ::Atom cached_atoms[atom::ATOM_COUNT];
|
| +
|
| + for (int i = 0; i < atom::ATOM_COUNT; ++i)
|
| + all_names[i] = kAtomList[i].name;
|
| +
|
| + // Grab all the atoms we need now to minimize roundtrips to the X11 server.
|
| + XInternAtoms(base::MessagePumpAuraX11::GetDefaultXDisplay(),
|
| + const_cast<char**>(all_names), atom::ATOM_COUNT, False,
|
| + cached_atoms);
|
| +
|
| + for (int i = 0; i < atom::ATOM_COUNT; ++i)
|
| + cached_atom_map.insert(std::make_pair(kAtomList[i].id, cached_atoms[i]));
|
| + }
|
| +
|
| + AtomMap::const_iterator it = cached_atom_map.find(name);
|
| + DCHECK(it != cached_atom_map.end());
|
| + return it->second;
|
| +}
|
| +
|
| +// static
|
| +bool MessagePumpAuraX11::HasXInput2() {
|
| return InitializeXInput2();
|
| }
|
|
|
| // static
|
| -void MessagePumpX::SetDefaultDispatcher(MessagePumpDispatcher* dispatcher) {
|
| +void MessagePumpAuraX11::SetDefaultDispatcher(
|
| + MessagePumpDispatcher* dispatcher) {
|
| DCHECK(!g_default_dispatcher || !dispatcher);
|
| g_default_dispatcher = dispatcher;
|
| }
|
|
|
| -gboolean MessagePumpX::DispatchXEvents() {
|
| +gboolean MessagePumpAuraX11::DispatchXEvents() {
|
| Display* display = GetDefaultXDisplay();
|
| DCHECK(display);
|
| MessagePumpDispatcher* dispatcher =
|
| @@ -128,14 +180,15 @@ gboolean MessagePumpX::DispatchXEvents() {
|
| return TRUE;
|
| }
|
|
|
| -MessagePumpX::~MessagePumpX() {
|
| +MessagePumpAuraX11::~MessagePumpAuraX11() {
|
| g_source_destroy(x_source_);
|
| g_source_unref(x_source_);
|
| XCloseDisplay(g_xdisplay);
|
| g_xdisplay = NULL;
|
| + g_cached_atoms.Get().clear();
|
| }
|
|
|
| -void MessagePumpX::InitXSource() {
|
| +void MessagePumpAuraX11::InitXSource() {
|
| // CHECKs are to help track down crbug.com/113106.
|
| CHECK(!x_source_);
|
| Display* display = GetDefaultXDisplay();
|
| @@ -152,8 +205,8 @@ void MessagePumpX::InitXSource() {
|
| g_source_attach(x_source_, g_main_context_default());
|
| }
|
|
|
| -bool MessagePumpX::ProcessXEvent(MessagePumpDispatcher* dispatcher,
|
| - XEvent* xev) {
|
| +bool MessagePumpAuraX11::ProcessXEvent(MessagePumpDispatcher* dispatcher,
|
| + XEvent* xev) {
|
| bool should_quit = false;
|
|
|
| bool have_cookie = false;
|
| @@ -177,7 +230,7 @@ bool MessagePumpX::ProcessXEvent(MessagePumpDispatcher* dispatcher,
|
| return should_quit;
|
| }
|
|
|
| -bool MessagePumpX::WillProcessXEvent(XEvent* xevent) {
|
| +bool MessagePumpAuraX11::WillProcessXEvent(XEvent* xevent) {
|
| if (!observers().might_have_observers())
|
| return false;
|
| ObserverListBase<MessagePumpObserver>::Iterator it(observers());
|
| @@ -189,7 +242,7 @@ bool MessagePumpX::WillProcessXEvent(XEvent* xevent) {
|
| return false;
|
| }
|
|
|
| -void MessagePumpX::DidProcessXEvent(XEvent* xevent) {
|
| +void MessagePumpAuraX11::DidProcessXEvent(XEvent* xevent) {
|
| FOR_EACH_OBSERVER(MessagePumpObserver, observers(), DidProcessEvent(xevent));
|
| }
|
|
|
|
|