Commit a9dc7a06 authored by sadrul@chromium.org's avatar sadrul@chromium.org

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
parent b8a62134
...@@ -53,7 +53,7 @@ GSourceFuncs XSourceFuncs = { ...@@ -53,7 +53,7 @@ GSourceFuncs XSourceFuncs = {
Display* g_xdisplay = NULL; Display* g_xdisplay = NULL;
int g_xinput_opcode = -1; int g_xinput_opcode = -1;
bool InitializeXInput2Internal() { bool InitializeXInput2() {
Display* display = MessagePumpX11::GetDefaultXDisplay(); Display* display = MessagePumpX11::GetDefaultXDisplay();
if (!display) if (!display)
return false; return false;
...@@ -97,11 +97,6 @@ Window FindEventTarget(const NativeEvent& xev) { ...@@ -97,11 +97,6 @@ Window FindEventTarget(const NativeEvent& xev) {
return target; return target;
} }
bool InitializeXInput2() {
static bool xinput2_supported = InitializeXInput2Internal();
return xinput2_supported;
}
bool InitializeXkb() { bool InitializeXkb() {
Display* display = MessagePumpX11::GetDefaultXDisplay(); Display* display = MessagePumpX11::GetDefaultXDisplay();
if (!display) if (!display)
...@@ -153,11 +148,6 @@ Display* MessagePumpX11::GetDefaultXDisplay() { ...@@ -153,11 +148,6 @@ Display* MessagePumpX11::GetDefaultXDisplay() {
return g_xdisplay; return g_xdisplay;
} }
// static
bool MessagePumpX11::HasXInput2() {
return InitializeXInput2();
}
#if defined(TOOLKIT_GTK) #if defined(TOOLKIT_GTK)
// static // static
MessagePumpX11* MessagePumpX11::Current() { MessagePumpX11* MessagePumpX11::Current() {
......
...@@ -40,9 +40,6 @@ class BASE_EXPORT MessagePumpX11 : public MessagePumpGlib, ...@@ -40,9 +40,6 @@ class BASE_EXPORT MessagePumpX11 : public MessagePumpGlib,
// Returns default X Display. // Returns default X Display.
static Display* GetDefaultXDisplay(); static Display* GetDefaultXDisplay();
// Returns true if the system supports XINPUT2.
static bool HasXInput2();
// Returns the UI or GPU message pump. // Returns the UI or GPU message pump.
static MessagePumpX11* Current(); static MessagePumpX11* Current();
......
...@@ -97,7 +97,7 @@ void SelectEventsForRootWindow() { ...@@ -97,7 +97,7 @@ void SelectEventsForRootWindow() {
StructureNotifyMask | attr.your_event_mask); StructureNotifyMask | attr.your_event_mask);
} }
if (!base::MessagePumpForUI::HasXInput2()) if (!ui::IsXInput2Available())
return; return;
unsigned char mask[XIMaskLen(XI_LASTEVENT)] = {}; unsigned char mask[XIMaskLen(XI_LASTEVENT)] = {};
...@@ -398,7 +398,7 @@ RootWindowHostX11::RootWindowHostX11(const gfx::Rect& bounds) ...@@ -398,7 +398,7 @@ RootWindowHostX11::RootWindowHostX11(const gfx::Rect& bounds)
XSelectInput(xdisplay_, xwindow_, event_mask); XSelectInput(xdisplay_, xwindow_, event_mask);
XFlush(xdisplay_); XFlush(xdisplay_);
if (base::MessagePumpForUI::HasXInput2()) if (ui::IsXInput2Available())
ui::TouchFactory::GetInstance()->SetupXI2ForXWindow(xwindow_); ui::TouchFactory::GetInstance()->SetupXI2ForXWindow(xwindow_);
SelectEventsForRootWindow(); SelectEventsForRootWindow();
...@@ -1057,6 +1057,8 @@ void RootWindowHostX11::UpdateIsInternalDisplay() { ...@@ -1057,6 +1057,8 @@ void RootWindowHostX11::UpdateIsInternalDisplay() {
void RootWindowHostX11::SetCrOSTapPaused(bool state) { void RootWindowHostX11::SetCrOSTapPaused(bool state) {
#if defined(OS_CHROMEOS) #if defined(OS_CHROMEOS)
if (!ui::IsXInput2Available())
return;
// Temporarily pause tap-to-click when the cursor is hidden. // Temporarily pause tap-to-click when the cursor is hidden.
Atom prop = atom_cache_.GetAtom("Tap Paused"); Atom prop = atom_cache_.GetAtom("Tap Paused");
unsigned char value = state; unsigned char value = state;
......
...@@ -266,6 +266,10 @@ bool XDisplayExists() { ...@@ -266,6 +266,10 @@ bool XDisplayExists() {
return (gfx::GetXDisplay() != NULL); return (gfx::GetXDisplay() != NULL);
} }
bool IsXInput2Available() {
return DeviceDataManager::GetInstance()->IsXInput2Available();
}
static SharedMemorySupport DoQuerySharedMemorySupport(XDisplay* dpy) { static SharedMemorySupport DoQuerySharedMemorySupport(XDisplay* dpy) {
int dummy; int dummy;
Bool pixmaps_supported; Bool pixmaps_supported;
......
...@@ -51,7 +51,9 @@ namespace ui { ...@@ -51,7 +51,9 @@ namespace ui {
// Check if there's an open connection to an X server. // Check if there's an open connection to an X server.
UI_EXPORT bool XDisplayExists(); UI_EXPORT bool XDisplayExists();
// Return an X11 connection for the current, primary display.
// Returns true if the system supports XINPUT2.
UI_EXPORT bool IsXInput2Available();
// X shared memory comes in three flavors: // X shared memory comes in three flavors:
// 1) No SHM support, // 1) No SHM support,
......
...@@ -112,8 +112,10 @@ DeviceDataManager* DeviceDataManager::GetInstance() { ...@@ -112,8 +112,10 @@ DeviceDataManager* DeviceDataManager::GetInstance() {
DeviceDataManager::DeviceDataManager() DeviceDataManager::DeviceDataManager()
: natural_scroll_enabled_(false), : natural_scroll_enabled_(false),
xi_opcode_(-1),
atom_cache_(gfx::GetXDisplay(), kCachedAtoms), atom_cache_(gfx::GetXDisplay(), kCachedAtoms),
button_map_count_(0) { button_map_count_(0) {
CHECK(gfx::GetXDisplay());
InitializeXInputInternal(); InitializeXInputInternal();
// Make sure the sizes of enum and kCachedAtoms are aligned. // Make sure the sizes of enum and kCachedAtoms are aligned.
...@@ -134,7 +136,6 @@ bool DeviceDataManager::InitializeXInputInternal() { ...@@ -134,7 +136,6 @@ bool DeviceDataManager::InitializeXInputInternal() {
VLOG(1) << "X Input extension not available: error=" << error; VLOG(1) << "X Input extension not available: error=" << error;
return false; return false;
} }
xi_opcode_ = opcode;
// Check the XInput version. // Check the XInput version.
#if defined(USE_XI2_MT) #if defined(USE_XI2_MT)
...@@ -146,6 +147,16 @@ bool DeviceDataManager::InitializeXInputInternal() { ...@@ -146,6 +147,16 @@ bool DeviceDataManager::InitializeXInputInternal() {
VLOG(1) << "XInput2 not supported in the server."; VLOG(1) << "XInput2 not supported in the server.";
return false; 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 // Possible XI event types for XIDeviceEvent. See the XI2 protocol
// specification. // specification.
...@@ -163,6 +174,10 @@ bool DeviceDataManager::InitializeXInputInternal() { ...@@ -163,6 +174,10 @@ bool DeviceDataManager::InitializeXInputInternal() {
return true; return true;
} }
bool DeviceDataManager::IsXInput2Available() const {
return xi_opcode_ != -1;
}
float DeviceDataManager::GetNaturalScrollFactor(int sourceid) const { float DeviceDataManager::GetNaturalScrollFactor(int sourceid) const {
// Natural scroll is touchpad-only. // Natural scroll is touchpad-only.
if (sourceid >= kMaxDeviceNum || !touchpads_[sourceid]) if (sourceid >= kMaxDeviceNum || !touchpads_[sourceid])
...@@ -192,6 +207,9 @@ void DeviceDataManager::UpdateDeviceList(Display* display) { ...@@ -192,6 +207,9 @@ void DeviceDataManager::UpdateDeviceList(Display* display) {
if (dev_list[i].type == xi_touchpad) if (dev_list[i].type == xi_touchpad)
touchpads_[dev_list[i].id] = true; touchpads_[dev_list[i].id] = true;
if (!IsXInput2Available())
return;
// Update the structs with new valuator information // Update the structs with new valuator information
XIDeviceList info_list = XIDeviceList info_list =
ui::DeviceListCacheX::GetInstance()->GetXI2DeviceList(display); ui::DeviceListCacheX::GetInstance()->GetXI2DeviceList(display);
......
...@@ -103,6 +103,9 @@ class EVENTS_EXPORT DeviceDataManager { ...@@ -103,6 +103,9 @@ class EVENTS_EXPORT DeviceDataManager {
natural_scroll_enabled_ = enabled; 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). // Get the natural scroll direction multiplier (1.0f or -1.0f).
float GetNaturalScrollFactor(int sourceid) const; float GetNaturalScrollFactor(int sourceid) const;
......
...@@ -8,12 +8,13 @@ ...@@ -8,12 +8,13 @@
#include "base/memory/singleton.h" #include "base/memory/singleton.h"
#include "base/message_loop/message_loop.h" #include "base/message_loop/message_loop.h"
#include "ui/events/x/device_data_manager.h"
namespace { namespace {
bool IsXI2Available() { bool IsXI2Available() {
#if defined(USE_AURA) #if defined(USE_AURA)
return base::MessagePumpForUI::HasXInput2(); return ui::DeviceDataManager::GetInstance()->IsXInput2Available();
#else #else
return false; return false;
#endif #endif
...@@ -23,8 +24,7 @@ bool IsXI2Available() { ...@@ -23,8 +24,7 @@ bool IsXI2Available() {
namespace ui { namespace ui {
DeviceListCacheX::DeviceListCacheX() DeviceListCacheX::DeviceListCacheX() {
: xi2_(IsXI2Available()) {
} }
DeviceListCacheX::~DeviceListCacheX() { DeviceListCacheX::~DeviceListCacheX() {
...@@ -53,8 +53,8 @@ void DeviceListCacheX::UpdateDeviceList(Display* display) { ...@@ -53,8 +53,8 @@ void DeviceListCacheX::UpdateDeviceList(Display* display) {
XIDeviceList& new_xi_dev_list = xi_dev_list_map_[display]; XIDeviceList& new_xi_dev_list = xi_dev_list_map_[display];
if (new_xi_dev_list.devices) if (new_xi_dev_list.devices)
XIFreeDeviceInfo(new_xi_dev_list.devices); XIFreeDeviceInfo(new_xi_dev_list.devices);
new_xi_dev_list.devices = xi2_ ? XIQueryDevice(display, XIAllDevices, new_xi_dev_list.devices = IsXI2Available() ?
&new_xi_dev_list.count) : NULL; XIQueryDevice(display, XIAllDevices, &new_xi_dev_list.count) : NULL;
} }
const XDeviceList& DeviceListCacheX::GetXDeviceList(Display* display) { const XDeviceList& DeviceListCacheX::GetXDeviceList(Display* display) {
...@@ -67,7 +67,7 @@ const XDeviceList& DeviceListCacheX::GetXDeviceList(Display* display) { ...@@ -67,7 +67,7 @@ const XDeviceList& DeviceListCacheX::GetXDeviceList(Display* display) {
const XIDeviceList& DeviceListCacheX::GetXI2DeviceList(Display* display) { const XIDeviceList& DeviceListCacheX::GetXI2DeviceList(Display* display) {
XIDeviceList& xi_dev_list = xi_dev_list_map_[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.devices = XIQueryDevice(display, XIAllDevices,
&xi_dev_list.count); &xi_dev_list.count);
} }
......
...@@ -42,7 +42,14 @@ class EVENTS_EXPORT DeviceListCacheX { ...@@ -42,7 +42,14 @@ class EVENTS_EXPORT DeviceListCacheX {
void UpdateDeviceList(Display* display); 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); 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); const XIDeviceList& GetXI2DeviceList(Display* display);
private: private:
...@@ -54,8 +61,6 @@ class EVENTS_EXPORT DeviceListCacheX { ...@@ -54,8 +61,6 @@ class EVENTS_EXPORT DeviceListCacheX {
std::map<Display*, XDeviceList> x_dev_list_map_; std::map<Display*, XDeviceList> x_dev_list_map_;
std::map<Display*, XIDeviceList> xi_dev_list_map_; std::map<Display*, XIDeviceList> xi_dev_list_map_;
bool xi2_;
DISALLOW_COPY_AND_ASSIGN(DeviceListCacheX); DISALLOW_COPY_AND_ASSIGN(DeviceListCacheX);
}; };
......
...@@ -18,6 +18,7 @@ ...@@ -18,6 +18,7 @@
#include "base/strings/string_number_conversions.h" #include "base/strings/string_number_conversions.h"
#include "base/strings/string_split.h" #include "base/strings/string_split.h"
#include "ui/events/event_switches.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/events/x/device_list_cache_x.h"
#include "ui/gfx/x/x11_types.h" #include "ui/gfx/x/x11_types.h"
...@@ -29,10 +30,8 @@ TouchFactory::TouchFactory() ...@@ -29,10 +30,8 @@ TouchFactory::TouchFactory()
touch_events_disabled_(false), touch_events_disabled_(false),
touch_device_list_(), touch_device_list_(),
id_generator_(0) { id_generator_(0) {
#if defined(USE_AURA) if (!DeviceDataManager::GetInstance()->IsXInput2Available())
if (!base::MessagePumpForUI::HasXInput2())
return; return;
#endif
XDisplay* display = gfx::GetXDisplay(); XDisplay* display = gfx::GetXDisplay();
UpdateDeviceList(display); UpdateDeviceList(display);
...@@ -101,6 +100,9 @@ void TouchFactory::UpdateDeviceList(Display* display) { ...@@ -101,6 +100,9 @@ void TouchFactory::UpdateDeviceList(Display* display) {
} }
#endif #endif
if (!DeviceDataManager::GetInstance()->IsXInput2Available())
return;
// Instead of asking X for the list of devices all the time, let's maintain a // Instead of asking X for the list of devices all the time, let's maintain a
// list of pointer devices we care about. // list of pointer devices we care about.
// It should not be necessary to select for slave devices. XInput2 provides // It should not be necessary to select for slave devices. XInput2 provides
......
...@@ -25,6 +25,7 @@ ...@@ -25,6 +25,7 @@
#include "ui/base/x/x11_util.h" #include "ui/base/x/x11_util.h"
#include "ui/events/event_utils.h" #include "ui/events/event_utils.h"
#include "ui/events/x/device_data_manager.h" #include "ui/events/x/device_data_manager.h"
#include "ui/events/x/device_list_cache_x.h"
#include "ui/events/x/touch_factory_x11.h" #include "ui/events/x/touch_factory_x11.h"
#include "ui/gfx/insets.h" #include "ui/gfx/insets.h"
#include "ui/gfx/path.h" #include "ui/gfx/path.h"
...@@ -934,7 +935,7 @@ void DesktopRootWindowHostX11::InitX11Window( ...@@ -934,7 +935,7 @@ void DesktopRootWindowHostX11::InitX11Window(
XSelectInput(xdisplay_, xwindow_, event_mask); XSelectInput(xdisplay_, xwindow_, event_mask);
XFlush(xdisplay_); XFlush(xdisplay_);
if (base::MessagePumpForUI::HasXInput2()) if (ui::IsXInput2Available())
ui::TouchFactory::GetInstance()->SetupXI2ForXWindow(xwindow_); ui::TouchFactory::GetInstance()->SetupXI2ForXWindow(xwindow_);
// TODO(erg): We currently only request window deletion events. We also // TODO(erg): We currently only request window deletion events. We also
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment