summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorrbyers@chromium.org <rbyers@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-03-25 22:52:54 +0000
committerrbyers@chromium.org <rbyers@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-03-25 22:52:54 +0000
commit009d54e9ad9defb5c73198091c587ac5dbf91a37 (patch)
tree8a820270913ea4df8fe8b8e68204b2034a335191
parent9f08e8bba1f4c14a4cb98c55067c1c6c21cedb03 (diff)
downloadchromium_src-009d54e9ad9defb5c73198091c587ac5dbf91a37.zip
chromium_src-009d54e9ad9defb5c73198091c587ac5dbf91a37.tar.gz
chromium_src-009d54e9ad9defb5c73198091c587ac5dbf91a37.tar.bz2
Tweak XInput2 event subscription
Combine MessagePumpGlibXs masters_ and floats_ fields into a single pointer_devices_ field. This is to make it easier for us to select the pointer devices of interest in one place. Also, don't attempt to call XFreeDeviceList if XListInputDevices returns null. This should only happen when XInput2 isn't supported, which isn't a real touchui scenario, but is useful for development scenarios. BUG=None TEST=None Review URL: http://codereview.chromium.org/6736029 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@79466 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--base/message_pump_glib_x.cc40
-rw-r--r--base/message_pump_glib_x.h10
-rw-r--r--views/touchui/touch_factory.cc5
3 files changed, 24 insertions, 31 deletions
diff --git a/base/message_pump_glib_x.cc b/base/message_pump_glib_x.cc
index 35cfc1a..34313e5 100644
--- a/base/message_pump_glib_x.cc
+++ b/base/message_pump_glib_x.cc
@@ -79,8 +79,7 @@ namespace base {
MessagePumpGlibX::MessagePumpGlibX() : base::MessagePumpForUI(),
#if defined(HAVE_XINPUT2)
xiopcode_(-1),
- masters_(),
- floats_(),
+ pointer_devices_(),
#endif
gdksource_(NULL),
dispatching_event_(false),
@@ -112,29 +111,17 @@ void MessagePumpGlibX::SetupXInput2ForXWindow(Window xwindow) {
XISetMask(mask, XI_ButtonRelease);
XISetMask(mask, XI_Motion);
- // It is not necessary to select for slave devices. XInput2 provides enough
- // information to the event callback to decide which slave device triggered
- // the event, thus decide whether the 'pointer event' is a 'mouse event' or a
- // 'touch event'.
- // If the touch device has 'GrabDevice' set and 'SendCoreEvents' unset (which
- // is possible), then the device is detected as a floating device, and a
- // floating device is not connected to a master device. So it is necessary to
- // also select on the floating devices.
- std::set<int> devices;
- std::set_union(masters_.begin(), masters_.end(),
- floats_.begin(), floats_.end(),
- std::inserter(devices, devices.begin()));
- XIEventMask evmasks[devices.size()];
+ XIEventMask evmasks[pointer_devices_.size()];
int count = 0;
- for (std::set<int>::const_iterator iter = devices.begin();
- iter != devices.end();
+ for (std::set<int>::const_iterator iter = pointer_devices_.begin();
+ iter != pointer_devices_.end();
++iter, ++count) {
evmasks[count].deviceid = *iter;
evmasks[count].mask_len = sizeof(mask);
evmasks[count].mask = mask;
}
- XISelectEvents(xdisplay, xwindow, evmasks, devices.size());
+ XISelectEvents(xdisplay, xwindow, evmasks, pointer_devices_.size());
// TODO(sad): Setup masks for keyboard events.
@@ -297,16 +284,21 @@ void MessagePumpGlibX::InitializeXInput2(void) {
SetupGtkWidgetRealizeNotifier(this);
// Instead of asking X for the list of devices all the time, let's maintain a
- // list of slave (physical) and master (virtual) pointer devices.
+ // list of pointer devices we care about.
+ // It is not necessary to select for slave devices. XInput2 provides enough
+ // information to the event callback to decide which slave device triggered
+ // the event, thus decide whether the 'pointer event' is a 'mouse event' or a
+ // 'touch event'.
+ // If the touch device has 'GrabDevice' set and 'SendCoreEvents' unset (which
+ // is possible), then the device is detected as a floating device, and a
+ // floating device is not connected to a master device. So it is necessary to
+ // also select on the floating devices.
int count = 0;
XIDeviceInfo* devices = XIQueryDevice(xdisplay, XIAllDevices, &count);
for (int i = 0; i < count; i++) {
XIDeviceInfo* devinfo = devices + i;
- if (devinfo->use == XIFloatingSlave) {
- floats_.insert(devinfo->deviceid);
- } else if (devinfo->use == XIMasterPointer) {
- masters_.insert(devinfo->deviceid);
- }
+ if (devinfo->use == XIFloatingSlave || devinfo->use == XIMasterPointer)
+ pointer_devices_.insert(devinfo->deviceid);
}
XIFreeDeviceInfo(devices);
diff --git a/base/message_pump_glib_x.h b/base/message_pump_glib_x.h
index 2959ef0..e8e92d6 100644
--- a/base/message_pump_glib_x.h
+++ b/base/message_pump_glib_x.h
@@ -48,12 +48,10 @@ class MessagePumpGlibX : public MessagePumpForUI {
// The opcode used for checking events.
int xiopcode_;
- // The list of master pointer devices. We maintain this list so that it is not
- // necessary to query X for the list of devices for each GdkWindow created.
- std::set<int> masters_;
-
- // The list of floating pointer devices.
- std::set<int> floats_;
+ // The list of pointer devices we care about. We maintain this list so that
+ // it is not necessary to query X for the list of devices for each
+ // GdkWindow created.
+ std::set<int> pointer_devices_;
#endif
// The event source for GDK events.
diff --git a/views/touchui/touch_factory.cc b/views/touchui/touch_factory.cc
index 66cdf6b..aeb1de2 100644
--- a/views/touchui/touch_factory.cc
+++ b/views/touchui/touch_factory.cc
@@ -43,6 +43,8 @@ TouchFactory::TouchFactory()
// NOTE: The new API for retrieving the list of devices (XIQueryDevice) does
// not provide enough information to detect a touch device. As a result, the
// old version of query function (XListInputDevices) is used instead.
+ // If XInput2 is not supported, this will return null (with count of -1) so
+ // we assume there cannot be any touch devices.
int count = 0;
XDeviceInfo* devlist = XListInputDevices(display, &count);
for (int i = 0; i < count; i++) {
@@ -52,7 +54,8 @@ TouchFactory::TouchFactory()
touch_device_list_.push_back(devlist[i].id);
}
}
- XFreeDeviceList(devlist);
+ if (devlist)
+ XFreeDeviceList(devlist);
}
TouchFactory::~TouchFactory() {