summaryrefslogtreecommitdiffstats
path: root/ui/events
diff options
context:
space:
mode:
authorsadrul@chromium.org <sadrul@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-11-06 23:21:22 +0000
committersadrul@chromium.org <sadrul@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-11-06 23:21:22 +0000
commita9dc7a06ab0608806a76ff9dfafa8f09126eeefd (patch)
tree2bf0d42b644ae789e641625757afdcc10801b67f /ui/events
parentb8a62134ca8b60135f0d15d2127cc4051bfceab6 (diff)
downloadchromium_src-a9dc7a06ab0608806a76ff9dfafa8f09126eeefd.zip
chromium_src-a9dc7a06ab0608806a76ff9dfafa8f09126eeefd.tar.gz
chromium_src-a9dc7a06ab0608806a76ff9dfafa8f09126eeefd.tar.bz2
x11: Move XInput2 availability information out of the message pump.
BUG=302696 R=darin@chromium.org, derat@chromium.org Review URL: https://codereview.chromium.org/52823002 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@233414 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ui/events')
-rw-r--r--ui/events/x/device_data_manager.cc20
-rw-r--r--ui/events/x/device_data_manager.h3
-rw-r--r--ui/events/x/device_list_cache_x.cc12
-rw-r--r--ui/events/x/device_list_cache_x.h9
-rw-r--r--ui/events/x/touch_factory_x11.cc8
5 files changed, 40 insertions, 12 deletions
diff --git a/ui/events/x/device_data_manager.cc b/ui/events/x/device_data_manager.cc
index d97b7f3..9858ccc 100644
--- a/ui/events/x/device_data_manager.cc
+++ b/ui/events/x/device_data_manager.cc
@@ -112,8 +112,10 @@ DeviceDataManager* DeviceDataManager::GetInstance() {
DeviceDataManager::DeviceDataManager()
: natural_scroll_enabled_(false),
+ xi_opcode_(-1),
atom_cache_(gfx::GetXDisplay(), kCachedAtoms),
button_map_count_(0) {
+ CHECK(gfx::GetXDisplay());
InitializeXInputInternal();
// Make sure the sizes of enum and kCachedAtoms are aligned.
@@ -134,7 +136,6 @@ bool DeviceDataManager::InitializeXInputInternal() {
VLOG(1) << "X Input extension not available: error=" << error;
return false;
}
- xi_opcode_ = opcode;
// Check the XInput version.
#if defined(USE_XI2_MT)
@@ -146,6 +147,16 @@ bool DeviceDataManager::InitializeXInputInternal() {
VLOG(1) << "XInput2 not supported in the server.";
return false;
}
+#if defined(USE_XI2_MT)
+ if (major < 2 || (major == 2 && minor < USE_XI2_MT)) {
+ DVLOG(1) << "XI version on server is " << major << "." << minor << ". "
+ << "But 2." << USE_XI2_MT << " is required.";
+ return false;
+ }
+#endif
+
+ xi_opcode_ = opcode;
+ CHECK_NE(-1, xi_opcode_);
// Possible XI event types for XIDeviceEvent. See the XI2 protocol
// specification.
@@ -163,6 +174,10 @@ bool DeviceDataManager::InitializeXInputInternal() {
return true;
}
+bool DeviceDataManager::IsXInput2Available() const {
+ return xi_opcode_ != -1;
+}
+
float DeviceDataManager::GetNaturalScrollFactor(int sourceid) const {
// Natural scroll is touchpad-only.
if (sourceid >= kMaxDeviceNum || !touchpads_[sourceid])
@@ -192,6 +207,9 @@ void DeviceDataManager::UpdateDeviceList(Display* display) {
if (dev_list[i].type == xi_touchpad)
touchpads_[dev_list[i].id] = true;
+ if (!IsXInput2Available())
+ return;
+
// Update the structs with new valuator information
XIDeviceList info_list =
ui::DeviceListCacheX::GetInstance()->GetXI2DeviceList(display);
diff --git a/ui/events/x/device_data_manager.h b/ui/events/x/device_data_manager.h
index 399bef9..8fed194 100644
--- a/ui/events/x/device_data_manager.h
+++ b/ui/events/x/device_data_manager.h
@@ -103,6 +103,9 @@ class EVENTS_EXPORT DeviceDataManager {
natural_scroll_enabled_ = enabled;
}
+ // Returns if XInput2 is available on the system.
+ bool IsXInput2Available() const;
+
// Get the natural scroll direction multiplier (1.0f or -1.0f).
float GetNaturalScrollFactor(int sourceid) const;
diff --git a/ui/events/x/device_list_cache_x.cc b/ui/events/x/device_list_cache_x.cc
index e2eb5ee..266ee6a 100644
--- a/ui/events/x/device_list_cache_x.cc
+++ b/ui/events/x/device_list_cache_x.cc
@@ -8,12 +8,13 @@
#include "base/memory/singleton.h"
#include "base/message_loop/message_loop.h"
+#include "ui/events/x/device_data_manager.h"
namespace {
bool IsXI2Available() {
#if defined(USE_AURA)
- return base::MessagePumpForUI::HasXInput2();
+ return ui::DeviceDataManager::GetInstance()->IsXInput2Available();
#else
return false;
#endif
@@ -23,8 +24,7 @@ bool IsXI2Available() {
namespace ui {
-DeviceListCacheX::DeviceListCacheX()
- : xi2_(IsXI2Available()) {
+DeviceListCacheX::DeviceListCacheX() {
}
DeviceListCacheX::~DeviceListCacheX() {
@@ -53,8 +53,8 @@ void DeviceListCacheX::UpdateDeviceList(Display* display) {
XIDeviceList& new_xi_dev_list = xi_dev_list_map_[display];
if (new_xi_dev_list.devices)
XIFreeDeviceInfo(new_xi_dev_list.devices);
- new_xi_dev_list.devices = xi2_ ? XIQueryDevice(display, XIAllDevices,
- &new_xi_dev_list.count) : NULL;
+ new_xi_dev_list.devices = IsXI2Available() ?
+ XIQueryDevice(display, XIAllDevices, &new_xi_dev_list.count) : NULL;
}
const XDeviceList& DeviceListCacheX::GetXDeviceList(Display* display) {
@@ -67,7 +67,7 @@ const XDeviceList& DeviceListCacheX::GetXDeviceList(Display* display) {
const XIDeviceList& DeviceListCacheX::GetXI2DeviceList(Display* display) {
XIDeviceList& xi_dev_list = xi_dev_list_map_[display];
- if (xi2_ && !xi_dev_list.devices && !xi_dev_list.count) {
+ if (!xi_dev_list.devices && !xi_dev_list.count) {
xi_dev_list.devices = XIQueryDevice(display, XIAllDevices,
&xi_dev_list.count);
}
diff --git a/ui/events/x/device_list_cache_x.h b/ui/events/x/device_list_cache_x.h
index 12ce718..8a31c06 100644
--- a/ui/events/x/device_list_cache_x.h
+++ b/ui/events/x/device_list_cache_x.h
@@ -42,7 +42,14 @@ class EVENTS_EXPORT DeviceListCacheX {
void UpdateDeviceList(Display* display);
+ // Returns the list of devices associated with |display|. Uses the old X11
+ // protocol to get the list of the devices.
const XDeviceList& GetXDeviceList(Display* display);
+
+ // Returns the list of devices associated with |display|. Uses the newer
+ // XINPUT2 protocol to get the list of devices. Before making this call, make
+ // sure that XInput2 support is available (e.g. by calling
+ // IsXInput2Available()).
const XIDeviceList& GetXI2DeviceList(Display* display);
private:
@@ -54,8 +61,6 @@ class EVENTS_EXPORT DeviceListCacheX {
std::map<Display*, XDeviceList> x_dev_list_map_;
std::map<Display*, XIDeviceList> xi_dev_list_map_;
- bool xi2_;
-
DISALLOW_COPY_AND_ASSIGN(DeviceListCacheX);
};
diff --git a/ui/events/x/touch_factory_x11.cc b/ui/events/x/touch_factory_x11.cc
index 59fc8f1..84066e3 100644
--- a/ui/events/x/touch_factory_x11.cc
+++ b/ui/events/x/touch_factory_x11.cc
@@ -18,6 +18,7 @@
#include "base/strings/string_number_conversions.h"
#include "base/strings/string_split.h"
#include "ui/events/event_switches.h"
+#include "ui/events/x/device_data_manager.h"
#include "ui/events/x/device_list_cache_x.h"
#include "ui/gfx/x/x11_types.h"
@@ -29,10 +30,8 @@ TouchFactory::TouchFactory()
touch_events_disabled_(false),
touch_device_list_(),
id_generator_(0) {
-#if defined(USE_AURA)
- if (!base::MessagePumpForUI::HasXInput2())
+ if (!DeviceDataManager::GetInstance()->IsXInput2Available())
return;
-#endif
XDisplay* display = gfx::GetXDisplay();
UpdateDeviceList(display);
@@ -101,6 +100,9 @@ void TouchFactory::UpdateDeviceList(Display* display) {
}
#endif
+ if (!DeviceDataManager::GetInstance()->IsXInput2Available())
+ return;
+
// Instead of asking X for the list of devices all the time, let's maintain a
// list of pointer devices we care about.
// It should not be necessary to select for slave devices. XInput2 provides