ChromiumTouch

Attachment 'multi_touch_device_x11.cc'

Download

   1 #include "ui/base/touch/multi_touch_device_x11.h"
   2 
   3 #include "ui/base/touch/multi_touch_device.h"
   4 
   5 #include "ui/base/x/x11_util.h"
   6 
   7 #include <xorg/xserver-properties.h>
   8 
   9 #include <X11/extensions/XInput.h>
  10 #include <X11/extensions/XInput2.h>
  11 #include <X11/extensions/XIproto.h>
  12 
  13 namespace {
  14 
  15 const char * AxisNameForType(ui::Axis::Type type) {
  16 
  17   // Defines are taken from xorg/xserver-properties.h
  18   static const char* names[ui::Axis::AXIS_TYPE_LAST+1] = {
  19     AXIS_LABEL_PROP_ABS_MT_POSITION_X,
  20     AXIS_LABEL_PROP_ABS_MT_POSITION_Y,
  21     AXIS_LABEL_PROP_ABS_MT_TOUCH_MAJOR,
  22     AXIS_LABEL_PROP_ABS_MT_TOUCH_MINOR,
  23     AXIS_LABEL_PROP_ABS_MT_WIDTH_MAJOR,
  24     AXIS_LABEL_PROP_ABS_MT_WIDTH_MINOR,
  25     AXIS_LABEL_PROP_ABS_MT_ORIENTATION,
  26     AXIS_LABEL_PROP_ABS_MT_TOOL_TYPE,
  27     AXIS_LABEL_PROP_ABS_MT_BLOB_ID,
  28     AXIS_LABEL_PROP_ABS_MT_TRACKING_ID,
  29     AXIS_LABEL_PROP_ABS_MT_PRESSURE,
  30     AXIS_LABEL_PROP_ABS_MISC,
  31     "Unknown axis type",
  32     "ui::Axis::AXIS_TYPE_LAST"
  33   };
  34 
  35   return names[type];
  36 }
  37 
  38 ui::Axis::Type AxisTypeForLabel(Display* display, Atom label) {
  39   if (label == XInternAtom(display, AXIS_LABEL_PROP_ABS_MT_TOUCH_MAJOR,
  40                            True))
  41     return ui::Axis::AXIS_TYPE_TOUCH_MAJOR;
  42   if (label == XInternAtom(display, AXIS_LABEL_PROP_ABS_MT_TOUCH_MINOR,
  43                            True))
  44     return ui::Axis::AXIS_TYPE_TOUCH_MINOR;
  45   if (label == XInternAtom(display, AXIS_LABEL_PROP_ABS_MT_WIDTH_MAJOR,
  46                            True))
  47     return ui::Axis::AXIS_TYPE_WIDTH_MAJOR;
  48   if (label == XInternAtom(display, AXIS_LABEL_PROP_ABS_MT_WIDTH_MINOR,
  49                            True))
  50     return ui::Axis::AXIS_TYPE_WIDTH_MINOR;
  51   if (label == XInternAtom(display, AXIS_LABEL_PROP_ABS_MT_ORIENTATION,
  52                            True))
  53     return ui::Axis::AXIS_TYPE_ORIENTATION;
  54   if (label == XInternAtom(display, AXIS_LABEL_PROP_ABS_MT_TOOL_TYPE,
  55                            True))
  56     return ui::Axis::AXIS_TYPE_TOOL;
  57   if (label == XInternAtom(display, AXIS_LABEL_PROP_ABS_MT_BLOB_ID,
  58                            True))
  59     return ui::Axis::AXIS_TYPE_BLOB_ID;
  60   if (label == XInternAtom(display, AXIS_LABEL_PROP_ABS_MT_TRACKING_ID,
  61                            True))
  62     return ui::Axis::AXIS_TYPE_TRACKING_ID;
  63   if (label == XInternAtom(display, AXIS_LABEL_PROP_ABS_MT_PRESSURE,
  64                            True))
  65     return ui::Axis::AXIS_TYPE_PRESSURE;
  66 
  67   return ui::Axis::AXIS_TYPE_UNKNOWN;
  68 }
  69 
  70 } // namespace
  71 
  72 namespace ui {
  73 bool xi_device_info_to_mt_device(XIDeviceInfo * info,
  74                                  MultiTouchDevice & out) {
  75 
  76   if(info == NULL)
  77     return false;
  78   
  79   out.set_id(info->deviceid);
  80   out.set_name(info->name);
  81   MultiTouchDevice::Axes axes;
  82 
  83   for (int i = 0; i < info->num_classes; ++i) {
  84     switch (info->classes[i]->type) {
  85       case XITouchClass: {
  86         XITouchClassInfo* touch_info =
  87           reinterpret_cast<XITouchClassInfo*>(info->classes[i]);
  88 
  89         switch(touch_info->mode) {
  90           case XIDirectTouch:
  91             out.set_type(MultiTouchDevice::DIRECT_TOUCH_DEVICE_TYPE);
  92             break;
  93           case XIDependentTouch:
  94             out.set_type(MultiTouchDevice::DEPENDENT_TOUCH_DEVICE_TYPE);
  95             break;
  96         }
  97 
  98         out.set_max_num_touches(touch_info->num_touches);
  99         break;
 100       }
 101 
 102       case XIValuatorClass: {
 103         XIValuatorClassInfo* valuator_info =
 104           reinterpret_cast<XIValuatorClassInfo*>(info->classes[i]);
 105 
 106         Axis::Type type;
 107 
 108         /* X and Y axes are always 0 and 1 in X11. Due to historical reasons,
 109          * the labels of these axes may not be consistent across input modules.
 110          * Hard code them here instead. */
 111         if (valuator_info->number == 0)
 112           type = Axis::AXIS_TYPE_X;
 113         else if (valuator_info->number == 1)
 114           type = Axis::AXIS_TYPE_Y;
 115         else {
 116           type = AxisTypeForLabel(ui::GetXDisplay(), valuator_info->label);
 117         }
 118 
 119         if(type==Axis::AXIS_TYPE_UNKNOWN)
 120           continue;
 121 
 122         Axis axis;
 123         axis.set_name(AxisNameForType(type));
 124         axis.set_type(type);
 125         axis.set_min(valuator_info->min);
 126         axis.set_max(valuator_info->max);
 127         axis.set_resolution(valuator_info->resolution);
 128 
 129         axes[type] = axis;
 130 
 131         break;
 132       }
 133 
 134       default:
 135         break;
 136     }
 137   }
 138 
 139   out.set_axes(axes);
 140 
 141   out.set_window_resolution_x(0.f);
 142   out.set_window_resolution_y(0.f);
 143 
 144   return true;
 145 }
 146 
 147 }

Attached Files

To refer to attachments on a page, use attachment:filename, as shown below in the list of files. Do NOT use the URL of the [get] link, since this is subject to change and can break easily.
  • [get | view] (2012-02-03 06:39:50, 116.0 KB) [[attachment:ChromiumTouchArchitecture.png]]
  • [get | view] (2012-02-03 08:24:50, 41.3 KB) [[attachment:ChromiumTouchGestureCentricView.png]]
  • [get | view] (2012-02-07 09:57:43, 2.2 KB) [[attachment:axis.h]]
  • [get | view] (2012-02-07 09:57:33, 1.8 KB) [[attachment:multi_touch_device.h]]
  • [get | view] (2012-02-07 09:58:03, 4.3 KB) [[attachment:multi_touch_device_x11.cc]]
  • [get | view] (2012-02-07 09:57:54, 0.4 KB) [[attachment:multi_touch_device_x11.h]]
  • [get | view] (2012-02-03 06:40:18, 1301.0 KB) [[attachment:video2.mkv]]
 All files | Selected Files: delete move to page

You are not allowed to attach a file to this page.