summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authoroshima@google.com <oshima@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2011-07-23 04:52:28 +0000
committeroshima@google.com <oshima@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2011-07-23 04:52:28 +0000
commitad4d54e931fe3b556cdd9e859a8654e4e6caed68 (patch)
tree21c52ff5eb99a9307cb8fb69d619ac9367581bef
parentffa3e486354ee6492eca27852a168506d285a8ad (diff)
downloadchromium_src-ad4d54e931fe3b556cdd9e859a8654e4e6caed68.zip
chromium_src-ad4d54e931fe3b556cdd9e859a8654e4e6caed68.tar.gz
chromium_src-ad4d54e931fe3b556cdd9e859a8654e4e6caed68.tar.bz2
check xinput2 capability so that it runs on the system that doesn't support xinput2
BUG=none TEST=none Review URL: http://codereview.chromium.org/7495013 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@93777 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--base/message_pump_x.cc59
-rw-r--r--base/message_pump_x.h9
-rw-r--r--views/touchui/touch_factory.cc26
3 files changed, 60 insertions, 34 deletions
diff --git a/base/message_pump_x.cc b/base/message_pump_x.cc
index 1174e4b..ada3fa3 100644
--- a/base/message_pump_x.cc
+++ b/base/message_pump_x.cc
@@ -12,22 +12,45 @@
namespace {
+// A flag to disable GTK's message pump. This is intermediate step
+// to remove gtk and will be removed once migration is complete.
+bool use_gtk_message_pump = true;
+
+// The opcode used for checking events.
+int xiopcode = -1;
+
gboolean PlaceholderDispatch(GSource* source,
GSourceFunc cb,
gpointer data) {
return TRUE;
}
-// A flag to disable GTK's message pump. This is intermediate step
-// to remove gtk and will be removed once migration is complete.
-bool use_gtk_message_pump = true;
+void InitializeXInput2(void) {
+ Display* display = base::MessagePumpX::GetDefaultXDisplay();
+ if (!display)
+ return;
+
+ int event, err;
+
+ if (!XQueryExtension(display, "XInputExtension", &xiopcode, &event, &err)) {
+ VLOG(1) << "X Input extension not available.";
+ xiopcode = -1;
+ return;
+ }
+
+ int major = 2, minor = 0;
+ if (XIQueryVersion(display, &major, &minor) == BadRequest) {
+ VLOG(1) << "XInput2 not supported in the server.";
+ xiopcode = -1;
+ return;
+ }
+}
} // namespace
namespace base {
MessagePumpX::MessagePumpX() : MessagePumpGlib(),
- xiopcode_(-1),
gdksource_(NULL),
dispatching_event_(false),
capture_x_events_(0),
@@ -57,11 +80,14 @@ Display* MessagePumpX::GetDefaultXDisplay() {
return display ? GDK_DISPLAY_XDISPLAY(display) : NULL;
}
+// static
+bool MessagePumpX::HasXInput2() {
+ return xiopcode != -1;
+}
bool MessagePumpX::ShouldCaptureXEvent(XEvent* xev) {
return (!use_gtk_message_pump || capture_x_events_[xev->type])
- && (xev->type != GenericEvent || xev->xcookie.extension == xiopcode_)
- ;
+ && (xev->type != GenericEvent || xev->xcookie.extension == xiopcode);
}
bool MessagePumpX::ProcessXEvent(XEvent* xev) {
@@ -198,27 +224,6 @@ void MessagePumpX::InitializeEventsToCapture(void) {
capture_x_events_[GenericEvent] = true;
}
-void MessagePumpX::InitializeXInput2(void) {
- Display* display = GetDefaultXDisplay();
- if (!display)
- return;
-
- int event, err;
-
- if (!XQueryExtension(display, "XInputExtension", &xiopcode_, &event, &err)) {
- VLOG(1) << "X Input extension not available.";
- xiopcode_ = -1;
- return;
- }
-
- int major = 2, minor = 0;
- if (XIQueryVersion(display, &major, &minor) == BadRequest) {
- VLOG(1) << "XInput2 not supported in the server.";
- xiopcode_ = -1;
- return;
- }
-}
-
MessagePumpObserver::EventStatus
MessagePumpObserver::WillProcessXEvent(XEvent* xev) {
return EVENT_CONTINUE;
diff --git a/base/message_pump_x.h b/base/message_pump_x.h
index fdd1de8..49a8251 100644
--- a/base/message_pump_x.h
+++ b/base/message_pump_x.h
@@ -78,6 +78,9 @@ class BASE_API MessagePumpX : public MessagePumpGlib {
// Returns default X Display.
static Display* GetDefaultXDisplay();
+ // Returns true if the system supports XINPUT2.
+ static bool HasXInput2();
+
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
@@ -105,12 +108,6 @@ class BASE_API MessagePumpX : public MessagePumpGlib {
// processed so that GDK doesn't get to them.
void InitializeEventsToCapture(void);
- // Initialize X2 input.
- void InitializeXInput2(void);
-
- // The opcode used for checking events.
- int xiopcode_;
-
// The event source for GDK events.
GSource* gdksource_;
diff --git a/views/touchui/touch_factory.cc b/views/touchui/touch_factory.cc
index 2f3506f..6580228 100644
--- a/views/touchui/touch_factory.cc
+++ b/views/touchui/touch_factory.cc
@@ -14,6 +14,7 @@
#include "base/basictypes.h"
#include "base/compiler_specific.h"
#include "base/logging.h"
+#include "base/message_loop.h"
#include "ui/base/x/x11_util.h"
namespace {
@@ -128,6 +129,11 @@ TouchFactory::TouchFactory()
pointer_device_lookup_(),
touch_device_list_(),
slots_used_() {
+#if defined(TOUCH_UI)
+ if (!base::MessagePumpForUI::HasXInput2())
+ return;
+#endif
+
char nodata[] = { 0, 0, 0, 0, 0, 0, 0, 0 };
XColor black;
black.red = black.green = black.blue = 0;
@@ -161,6 +167,11 @@ TouchFactory::TouchFactory()
}
TouchFactory::~TouchFactory() {
+#if defined(TOUCH_UI)
+ if (!base::MessagePumpForUI::HasXInput2())
+ return;
+#endif
+
SetCursorVisible(true, false);
Display* display = ui::GetXDisplay();
XFreeCursor(display, invisible_cursor_);
@@ -286,8 +297,11 @@ void TouchFactory::SetSlotUsed(int slot, bool used) {
}
bool TouchFactory::GrabTouchDevices(Display* display, ::Window window) {
- if (touch_device_list_.empty())
+#if defined(TOUCH_UI)
+ if (!base::MessagePumpForUI::HasXInput2() ||
+ touch_device_list_.empty())
return true;
+#endif
unsigned char mask[XIMaskLen(XI_LASTEVENT)];
bool success = true;
@@ -313,6 +327,11 @@ bool TouchFactory::GrabTouchDevices(Display* display, ::Window window) {
}
bool TouchFactory::UngrabTouchDevices(Display* display) {
+#if defined(TOUCH_UI)
+ if (!base::MessagePumpForUI::HasXInput2())
+ return true;
+#endif
+
bool success = true;
for (std::vector<int>::const_iterator iter =
touch_device_list_.begin();
@@ -324,6 +343,11 @@ bool TouchFactory::UngrabTouchDevices(Display* display) {
}
void TouchFactory::SetCursorVisible(bool show, bool start_timer) {
+#if defined(TOUCH_UI)
+ if (!base::MessagePumpForUI::HasXInput2())
+ return;
+#endif
+
// The cursor is going to be shown. Reset the timer for hiding it.
if (show && start_timer) {
cursor_timer_.Stop();