summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authoroshima@google.com <oshima@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2011-07-22 19:49:23 +0000
committeroshima@google.com <oshima@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2011-07-22 19:49:23 +0000
commit2656a354677e57bd271160c0edcbeb2cad541f51 (patch)
treedde422a236acb69418d0ada4819228d510d2fd4a
parent74b9241c1734b73b48aff28710509ba810b65032 (diff)
downloadchromium_src-2656a354677e57bd271160c0edcbeb2cad541f51.zip
chromium_src-2656a354677e57bd271160c0edcbeb2cad541f51.tar.gz
chromium_src-2656a354677e57bd271160c0edcbeb2cad541f51.tar.bz2
re-landing r93629
Consolidate access to X Display Change ui::GetXDisplay to use the MessagePumpForUI class to get Display. This allows us to have two different implementation for x and gtk. Remove MessageLoop::GetDisplay from message loop API. Client should use ui::GetXDisplay instead. This will also be removed in near future, and client should get display from window it is dealing with. BUG=none TEST=none Committed: http://src.chromium.org/viewvc/chrome?view=rev&revision=93629 Review URL: http://codereview.chromium.org/7484006 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@93686 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--base/message_loop.cc9
-rw-r--r--base/message_loop.h13
-rw-r--r--base/message_pump_gtk.cc8
-rw-r--r--base/message_pump_gtk.h6
-rw-r--r--base/message_pump_x.cc11
-rw-r--r--base/message_pump_x.h6
-rw-r--r--chrome/browser/chromeos/xinput_hierarchy_changed_event_listener.cc7
-rw-r--r--ui/base/x/x11_util.cc8
-rw-r--r--ui/base/x/x11_util.h4
9 files changed, 36 insertions, 36 deletions
diff --git a/base/message_loop.cc b/base/message_loop.cc
index 7f1971c..08985a4 100644
--- a/base/message_loop.cc
+++ b/base/message_loop.cc
@@ -819,15 +819,6 @@ void MessageLoopForUI::DidProcessMessage(const MSG& message) {
}
#endif // defined(OS_WIN)
-#if defined(USE_X11)
-Display* MessageLoopForUI::GetDisplay() {
- GdkDisplay* display = gdk_display_get_default();
- if (!display)
- return NULL;
- return GDK_DISPLAY_XDISPLAY(display);
-}
-#endif // defined(USE_X11)
-
#if !defined(OS_MACOSX) && !defined(OS_NACL)
void MessageLoopForUI::AddObserver(Observer* observer) {
pump_ui()->AddObserver(observer);
diff --git a/base/message_loop.h b/base/message_loop.h
index 8fd9cbc..9d500d7 100644
--- a/base/message_loop.h
+++ b/base/message_loop.h
@@ -32,7 +32,6 @@
#else
#include "base/message_pump_gtk.h"
#endif
-typedef struct _XDisplay Display;
#endif
#endif
@@ -584,18 +583,6 @@ class BASE_API MessageLoopForUI : public MessageLoop {
void DidProcessMessage(const MSG& message);
#endif // defined(OS_WIN)
-#if defined(USE_X11)
- // Returns the Xlib Display that backs the MessagePump for this MessageLoop.
- //
- // This allows for raw access to the X11 server in situations where our
- // abstractions do not provide enough power.
- //
- // Be careful how this is used. The MessagePump in general expects
- // exclusive access to the Display. Calling things like XNextEvent() will
- // likely break things in subtle, hard to detect, ways.
- Display* GetDisplay();
-#endif // defined(OS_X11)
-
#if !defined(OS_MACOSX)
// Please see message_pump_win/message_pump_glib for definitions of these
// methods.
diff --git a/base/message_pump_gtk.cc b/base/message_pump_gtk.cc
index f5ed042..e1cb7f6 100644
--- a/base/message_pump_gtk.cc
+++ b/base/message_pump_gtk.cc
@@ -5,6 +5,7 @@
#include "base/message_pump_gtk.h"
#include <gtk/gtk.h>
+#include <gdk/gdkx.h>
namespace base {
@@ -29,6 +30,12 @@ void MessagePumpGtk::DispatchEvents(GdkEvent* event) {
DidProcessEvent(event);
}
+// static
+Display* MessagePumpGtk::GetDefaultXDisplay() {
+ static GdkDisplay* display = gdk_display_get_default();
+ return display ? GDK_DISPLAY_XDISPLAY(display) : NULL;
+}
+
bool MessagePumpGtk::RunOnce(GMainContext* context, bool block) {
// g_main_context_iteration returns true if events have been dispatched.
return g_main_context_iteration(context, block);
@@ -49,4 +56,3 @@ void MessagePumpGtk::EventDispatcher(GdkEvent* event, gpointer data) {
}
} // namespace base
-
diff --git a/base/message_pump_gtk.h b/base/message_pump_gtk.h
index 72eaafa..5fa21f7 100644
--- a/base/message_pump_gtk.h
+++ b/base/message_pump_gtk.h
@@ -9,6 +9,7 @@
#include "base/message_pump_glib.h"
typedef union _GdkEvent GdkEvent;
+typedef struct _XDisplay Display;
namespace base {
@@ -40,7 +41,7 @@ class MessagePumpDispatcher {
};
// This class implements a message-pump for dispatching GTK events.
-class MessagePumpGtk : public MessagePumpGlib {
+class BASE_API MessagePumpGtk : public MessagePumpGlib {
public:
MessagePumpGtk();
virtual ~MessagePumpGtk();
@@ -49,6 +50,9 @@ class MessagePumpGtk : public MessagePumpGlib {
// some task before/after calling the default handler (EventDispatcher).
void DispatchEvents(GdkEvent* event);
+ // Returns default X Display.
+ static Display* GetDefaultXDisplay();
+
private:
// Overridden from MessagePumpGlib
virtual bool RunOnce(GMainContext* context, bool block) OVERRIDE;
diff --git a/base/message_pump_x.cc b/base/message_pump_x.cc
index 20c8b0e..1174e4b 100644
--- a/base/message_pump_x.cc
+++ b/base/message_pump_x.cc
@@ -51,6 +51,13 @@ void MessagePumpX::DisableGtkMessagePump() {
use_gtk_message_pump = false;
}
+// static
+Display* MessagePumpX::GetDefaultXDisplay() {
+ static GdkDisplay* display = gdk_display_get_default();
+ return display ? GDK_DISPLAY_XDISPLAY(display) : NULL;
+}
+
+
bool MessagePumpX::ShouldCaptureXEvent(XEvent* xev) {
return (!use_gtk_message_pump || capture_x_events_[xev->type])
&& (xev->type != GenericEvent || xev->xcookie.extension == xiopcode_)
@@ -86,7 +93,7 @@ bool MessagePumpX::ProcessXEvent(XEvent* xev) {
}
bool MessagePumpX::RunOnce(GMainContext* context, bool block) {
- Display* display = MessageLoopForUI::current()->GetDisplay();
+ Display* display = GetDefaultXDisplay();
if (!display || !GetDispatcher())
return g_main_context_iteration(context, block);
@@ -192,7 +199,7 @@ void MessagePumpX::InitializeEventsToCapture(void) {
}
void MessagePumpX::InitializeXInput2(void) {
- Display* display = MessageLoopForUI::current()->GetDisplay();
+ Display* display = GetDefaultXDisplay();
if (!display)
return;
diff --git a/base/message_pump_x.h b/base/message_pump_x.h
index ecadc1f..fdd1de8 100644
--- a/base/message_pump_x.h
+++ b/base/message_pump_x.h
@@ -14,6 +14,7 @@
#include <gtk/gtk.h>
typedef union _XEvent XEvent;
+typedef struct _XDisplay Display;
namespace base {
@@ -58,7 +59,7 @@ class MessagePumpDispatcher {
};
// This class implements a message-pump for dispatching X events.
-class MessagePumpX : public MessagePumpGlib {
+class BASE_API MessagePumpX : public MessagePumpGlib {
public:
MessagePumpX();
virtual ~MessagePumpX();
@@ -74,6 +75,9 @@ class MessagePumpX : public MessagePumpGlib {
// NativeWidgetX is enabled.
static void DisableGtkMessagePump();
+ // Returns default X Display.
+ static Display* GetDefaultXDisplay();
+
private:
// Some XEvent's can't be directly read from X event queue and will go
// through GDK's dispatching process and may get discarded. This function
diff --git a/chrome/browser/chromeos/xinput_hierarchy_changed_event_listener.cc b/chrome/browser/chromeos/xinput_hierarchy_changed_event_listener.cc
index bf1ab56..7daba16 100644
--- a/chrome/browser/chromeos/xinput_hierarchy_changed_event_listener.cc
+++ b/chrome/browser/chromeos/xinput_hierarchy_changed_event_listener.cc
@@ -9,6 +9,7 @@
#include <X11/extensions/XInput2.h>
#include "chrome/browser/chromeos/input_method/xkeyboard.h"
+#include "ui/base/x/x11_util.h"
namespace {
@@ -19,8 +20,8 @@ int GetXInputOpCode() {
int event;
int error;
- Display* display = MessageLoopForUI::current()->GetDisplay();
- if (!XQueryExtension(display, kExtensionName, &xi_opcode, &event, &error)) {
+ if (!XQueryExtension(
+ ui::GetXDisplay(), kExtensionName, &xi_opcode, &event, &error)) {
VLOG(1) << "X Input extension not available: error=" << error;
return -1;
}
@@ -37,7 +38,7 @@ void SelectXInputEvents() {
evmask.mask_len = sizeof(mask);
evmask.mask = mask;
- Display* display = MessageLoopForUI::current()->GetDisplay();
+ Display* display = ui::GetXDisplay();
XISelectEvents(display, DefaultRootWindow(display), &evmask, 1);
}
diff --git a/ui/base/x/x11_util.cc b/ui/base/x/x11_util.cc
index 51f52e2..d7d51cf 100644
--- a/ui/base/x/x11_util.cc
+++ b/ui/base/x/x11_util.cc
@@ -20,6 +20,7 @@
#include "base/command_line.h"
#include "base/logging.h"
+#include "base/message_loop.h"
#include "base/stringprintf.h"
#include "base/string_number_conversions.h"
#include "base/threading/thread.h"
@@ -96,12 +97,7 @@ bool XDisplayExists() {
}
Display* GetXDisplay() {
- static Display* display = NULL;
-
- if (!display)
- display = gdk_x11_get_default_xdisplay();
-
- return display;
+ return base::MessagePumpForUI::GetDefaultXDisplay();
}
static SharedMemorySupport DoQuerySharedMemorySupport(Display* dpy) {
diff --git a/ui/base/x/x11_util.h b/ui/base/x/x11_util.h
index ab455a0..6728c1e 100644
--- a/ui/base/x/x11_util.h
+++ b/ui/base/x/x11_util.h
@@ -39,6 +39,10 @@ namespace ui {
// Check if there's an open connection to an X server.
UI_API bool XDisplayExists();
// Return an X11 connection for the current, primary display.
+
+// TODO(oshima|evan): This assume there is one display and dosn't work
+// undef mutiple displays/monitor environment. Remove this and change the
+// chrome codebase to get the display from window.
UI_API Display* GetXDisplay();
// X shared memory comes in three flavors: