| OLD | NEW | 
|    1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |    1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 
|    2 // Use of this source code is governed by a BSD-style license that can be |    2 // Use of this source code is governed by a BSD-style license that can be | 
|    3 // found in the LICENSE file. |    3 // found in the LICENSE file. | 
|    4  |    4  | 
|    5 #include "ui/events/devices/x11/touch_factory_x11.h" |    5 #include "ui/events/devices/x11/touch_factory_x11.h" | 
|    6  |    6  | 
|    7 #include <X11/Xatom.h> |    7 #include <X11/Xatom.h> | 
|    8 #include <X11/cursorfont.h> |    8 #include <X11/cursorfont.h> | 
|    9 #include <X11/extensions/XInput.h> |    9 #include <X11/extensions/XInput.h> | 
|   10 #include <X11/extensions/XInput2.h> |   10 #include <X11/extensions/XInput2.h> | 
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|   82   touch_device_lookup_.reset(); |   82   touch_device_lookup_.reset(); | 
|   83   touch_device_list_.clear(); |   83   touch_device_list_.clear(); | 
|   84   touchscreen_ids_.clear(); |   84   touchscreen_ids_.clear(); | 
|   85  |   85  | 
|   86   // NOTE: The new API for retrieving the list of devices (XIQueryDevice) does |   86   // NOTE: The new API for retrieving the list of devices (XIQueryDevice) does | 
|   87   // not provide enough information to detect a touch device. As a result, the |   87   // not provide enough information to detect a touch device. As a result, the | 
|   88   // old version of query function (XListInputDevices) is used instead. |   88   // old version of query function (XListInputDevices) is used instead. | 
|   89   // If XInput2 is not supported, this will return null (with count of -1) so |   89   // If XInput2 is not supported, this will return null (with count of -1) so | 
|   90   // we assume there cannot be any touch devices. |   90   // we assume there cannot be any touch devices. | 
|   91   // With XI2.1 or older, we allow only single touch devices. |   91   // With XI2.1 or older, we allow only single touch devices. | 
|   92   XDeviceList dev_list = |   92   const XDeviceList& dev_list = | 
|   93       DeviceListCacheX11::GetInstance()->GetXDeviceList(display); |   93       DeviceListCacheX11::GetInstance()->GetXDeviceList(display); | 
|   94   Atom xi_touchscreen = XInternAtom(display, XI_TOUCHSCREEN, false); |   94   Atom xi_touchscreen = XInternAtom(display, XI_TOUCHSCREEN, false); | 
|   95   for (int i = 0; i < dev_list.count; i++) { |   95   for (int i = 0; i < dev_list.count; i++) { | 
|   96     if (dev_list[i].type == xi_touchscreen) { |   96     if (dev_list[i].type == xi_touchscreen) { | 
|   97       touch_device_lookup_[dev_list[i].id] = true; |   97       touch_device_lookup_[dev_list[i].id] = true; | 
|   98       touch_device_list_[dev_list[i].id] = false; |   98       touch_device_list_[dev_list[i].id] = false; | 
|   99     } |   99     } | 
|  100   } |  100   } | 
|  101  |  101  | 
|  102   if (!DeviceDataManagerX11::GetInstance()->IsXInput2Available()) |  102   if (!DeviceDataManagerX11::GetInstance()->IsXInput2Available()) | 
|  103     return; |  103     return; | 
|  104  |  104  | 
|  105   // Instead of asking X for the list of devices all the time, let's maintain a |  105   // Instead of asking X for the list of devices all the time, let's maintain a | 
|  106   // list of pointer devices we care about. |  106   // list of pointer devices we care about. | 
|  107   // It should not be necessary to select for slave devices. XInput2 provides |  107   // It should not be necessary to select for slave devices. XInput2 provides | 
|  108   // enough information to the event callback to decide which slave device |  108   // enough information to the event callback to decide which slave device | 
|  109   // triggered the event, thus decide whether the 'pointer event' is a |  109   // triggered the event, thus decide whether the 'pointer event' is a | 
|  110   // 'mouse event' or a 'touch event'. |  110   // 'mouse event' or a 'touch event'. | 
|  111   // However, on some desktops, some events from a master pointer are |  111   // However, on some desktops, some events from a master pointer are | 
|  112   // not delivered to the client. So we select for slave devices instead. |  112   // not delivered to the client. So we select for slave devices instead. | 
|  113   // If the touch device has 'GrabDevice' set and 'SendCoreEvents' unset (which |  113   // If the touch device has 'GrabDevice' set and 'SendCoreEvents' unset (which | 
|  114   // is possible), then the device is detected as a floating device, and a |  114   // is possible), then the device is detected as a floating device, and a | 
|  115   // floating device is not connected to a master device. So it is necessary to |  115   // floating device is not connected to a master device. So it is necessary to | 
|  116   // also select on the floating devices. |  116   // also select on the floating devices. | 
|  117   pointer_device_lookup_.reset(); |  117   pointer_device_lookup_.reset(); | 
|  118   XIDeviceList xi_dev_list = |  118   const XIDeviceList& xi_dev_list = | 
|  119       DeviceListCacheX11::GetInstance()->GetXI2DeviceList(display); |  119       DeviceListCacheX11::GetInstance()->GetXI2DeviceList(display); | 
|  120   for (int i = 0; i < xi_dev_list.count; i++) { |  120   for (int i = 0; i < xi_dev_list.count; i++) { | 
|  121     XIDeviceInfo* devinfo = xi_dev_list.devices + i; |  121     const XIDeviceInfo& devinfo = xi_dev_list[i]; | 
|  122     if (devinfo->use == XIFloatingSlave || devinfo->use == XIMasterPointer) { |  122     if (devinfo.use == XIFloatingSlave || devinfo.use == XIMasterPointer) { | 
|  123       for (int k = 0; k < devinfo->num_classes; ++k) { |  123       for (int k = 0; k < devinfo.num_classes; ++k) { | 
|  124         XIAnyClassInfo* xiclassinfo = devinfo->classes[k]; |  124         XIAnyClassInfo* xiclassinfo = devinfo.classes[k]; | 
|  125         if (xiclassinfo->type == XITouchClass) { |  125         if (xiclassinfo->type == XITouchClass) { | 
|  126           XITouchClassInfo* tci = |  126           XITouchClassInfo* tci = | 
|  127               reinterpret_cast<XITouchClassInfo*>(xiclassinfo); |  127               reinterpret_cast<XITouchClassInfo*>(xiclassinfo); | 
|  128           // Only care direct touch device (such as touch screen) right now |  128           // Only care direct touch device (such as touch screen) right now | 
|  129           if (tci->mode == XIDirectTouch) { |  129           if (tci->mode == XIDirectTouch) { | 
|  130             touch_device_lookup_[devinfo->deviceid] = true; |  130             touch_device_lookup_[devinfo.deviceid] = true; | 
|  131             touch_device_list_[devinfo->deviceid] = true; |  131             touch_device_list_[devinfo.deviceid] = true; | 
|  132           } |  132           } | 
|  133         } |  133         } | 
|  134       } |  134       } | 
|  135       pointer_device_lookup_[devinfo->deviceid] = true; |  135       pointer_device_lookup_[devinfo.deviceid] = true; | 
|  136     } else if (devinfo->use == XIMasterKeyboard) { |  136     } else if (devinfo.use == XIMasterKeyboard) { | 
|  137       virtual_core_keyboard_device_ = devinfo->deviceid; |  137       virtual_core_keyboard_device_ = devinfo.deviceid; | 
|  138     } |  138     } | 
|  139  |  139  | 
|  140     if (devinfo->use == XIFloatingSlave || devinfo->use == XISlavePointer) { |  140     if (devinfo.use == XIFloatingSlave || devinfo.use == XISlavePointer) { | 
|  141       for (int k = 0; k < devinfo->num_classes; ++k) { |  141       for (int k = 0; k < devinfo.num_classes; ++k) { | 
|  142         XIAnyClassInfo* xiclassinfo = devinfo->classes[k]; |  142         XIAnyClassInfo* xiclassinfo = devinfo.classes[k]; | 
|  143         if (xiclassinfo->type == XITouchClass) { |  143         if (xiclassinfo->type == XITouchClass) { | 
|  144           XITouchClassInfo* tci = |  144           XITouchClassInfo* tci = | 
|  145               reinterpret_cast<XITouchClassInfo*>(xiclassinfo); |  145               reinterpret_cast<XITouchClassInfo*>(xiclassinfo); | 
|  146           // Only care direct touch device (such as touch screen) right now |  146           // Only care direct touch device (such as touch screen) right now | 
|  147           if (tci->mode == XIDirectTouch) |  147           if (tci->mode == XIDirectTouch) | 
|  148             CacheTouchscreenIds(display, devinfo->deviceid); |  148             CacheTouchscreenIds(display, devinfo.deviceid); | 
|  149         } |  149         } | 
|  150       } |  150       } | 
|  151     } |  151     } | 
|  152   } |  152   } | 
|  153 } |  153 } | 
|  154  |  154  | 
|  155 bool TouchFactory::ShouldProcessXI2Event(XEvent* xev) { |  155 bool TouchFactory::ShouldProcessXI2Event(XEvent* xev) { | 
|  156   DCHECK_EQ(GenericEvent, xev->type); |  156   DCHECK_EQ(GenericEvent, xev->type); | 
|  157   XIEvent* event = static_cast<XIEvent*>(xev->xcookie.data); |  157   XIEvent* event = static_cast<XIEvent*>(xev->xcookie.data); | 
|  158   XIDeviceEvent* xiev = reinterpret_cast<XIDeviceEvent*>(event); |  158   XIDeviceEvent* xiev = reinterpret_cast<XIDeviceEvent*>(event); | 
| (...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|  324       if (ptr[0] || ptr[1]) |  324       if (ptr[0] || ptr[1]) | 
|  325         touchscreen_ids_.insert(std::make_pair(ptr[0], ptr[1])); |  325         touchscreen_ids_.insert(std::make_pair(ptr[0], ptr[1])); | 
|  326     } |  326     } | 
|  327     XFree(prop_return); |  327     XFree(prop_return); | 
|  328   } |  328   } | 
|  329  |  329  | 
|  330   XCloseDevice(display, device); |  330   XCloseDevice(display, device); | 
|  331 } |  331 } | 
|  332  |  332  | 
|  333 }  // namespace ui |  333 }  // namespace ui | 
| OLD | NEW |