absolute-axes.rst 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. .. _absolute_axes:
  2. ==============================================================================
  3. Absolute axes
  4. ==============================================================================
  5. Devices with absolute axes are those that send positioning data for an axis in
  6. a device-specific coordinate range, defined by a minimum and a maximum value.
  7. Compare this to relative devices (e.g. a mouse) that can only detect
  8. directional data, not positional data.
  9. libinput supports three types of devices with absolute axes:
  10. - multi-touch screens
  11. - single-touch screens
  12. - :ref:`graphics tablets <tablet-support>`
  13. Touchpads are technically absolute devices but libinput converts the axis values
  14. to directional motion and posts events as relative events. Touchpads do not count
  15. as absolute devices in libinput.
  16. For all absolute devices in libinput, the default unit for x/y coordinates is
  17. in mm off the top left corner on the device, or more specifically off the
  18. device's sensor. If the device is physically rotated from its natural
  19. position and this rotation was communicated to libinput (e.g. by setting
  20. the device left-handed),
  21. the coordinate origin is the top left corner in the current rotation.
  22. .. _absolute_axes_handling:
  23. ------------------------------------------------------------------------------
  24. Handling of absolute coordinates
  25. ------------------------------------------------------------------------------
  26. In most use-cases, absolute input devices are mapped to a single screen. For
  27. direct input devices such as touchscreens the aspect ratio of the screen and
  28. the device match. Mapping the input device position to the output position is
  29. thus a simple mapping between two coordinates. libinput provides the API for
  30. this with
  31. - **libinput_event_pointer_get_absolute_x_transformed()** for pointer events
  32. - **libinput_event_touch_get_x_transformed()** for touch events
  33. libinput's API only provides the call to map into a single coordinate range.
  34. If the coordinate range has an offset, the compositor is responsible for
  35. applying that offset after the mapping. For example, if the device is mapped
  36. to the right of two outputs, add the output offset to the transformed
  37. coordinate.
  38. .. _absolute_axes_nores:
  39. ------------------------------------------------------------------------------
  40. Devices without x/y resolution
  41. ------------------------------------------------------------------------------
  42. An absolute device that does not provide a valid resolution is considered
  43. buggy and must be fixed in the kernel. Some touchpad devices do not
  44. provide resolution, those devices are correctly handled within libinput
  45. (touchpads are not absolute devices, as mentioned above).
  46. .. _calibration:
  47. ------------------------------------------------------------------------------
  48. Calibration of absolute devices
  49. ------------------------------------------------------------------------------
  50. Absolute devices may require calibration to map precisely into the output
  51. range required. This is done by setting a transformation matrix, see
  52. **libinput_device_config_calibration_set_matrix()** which is applied to
  53. each input coordinate.
  54. .. math::
  55. \begin{pmatrix}
  56. cos\theta & -sin\theta & xoff \\
  57. sin\theta & cos\theta & yoff \\
  58. 0 & 0 & 1
  59. \end{pmatrix} \begin{pmatrix}
  60. x \\ y \\ 1
  61. \end{pmatrix}
  62. :math:`\theta` is the rotation angle. The offsets :math:`xoff` and :math:`yoff` are
  63. specified in device dimensions, i.e. a value of 1 equals one device width or
  64. height. Note that rotation applies to the device's origin, rotation usually
  65. requires an offset to move the coordinates back into the original range.
  66. The most common matrices are:
  67. - 90 degree clockwise:
  68. .. math::
  69. \begin{pmatrix}
  70. 0 & -1 & 1 \\
  71. 1 & 0 & 0 \\
  72. 0 & 0 & 1
  73. \end{pmatrix}
  74. - 180 degree clockwise:
  75. .. math::
  76. \begin{pmatrix}
  77. -1 & 0 & 1 \\
  78. 0 & -1 & 1 \\
  79. 0 & 0 & 1
  80. \end{pmatrix}
  81. - 270 degree clockwise:
  82. .. math::
  83. \begin{pmatrix}
  84. 0 & 1 & 0 \\
  85. -1 & 0 & 1 \\
  86. 0 & 0 & 1
  87. \end{pmatrix}
  88. - reflection along y axis:
  89. .. math::
  90. \begin{pmatrix}
  91. -1 & 0 & 1 \\
  92. 0 & 1 & 0 \\
  93. 0 & 0 & 1
  94. \end{pmatrix}
  95. See Wikipedia's
  96. `Transformation Matrix article <http://en.wikipedia.org/wiki/Transformation_matrix>`_
  97. for more information on the matrix maths. See
  98. **libinput_device_config_calibration_get_default_matrix()** for how these
  99. matrices must be supplied to libinput.
  100. Once applied, any x and y axis value has the calibration applied before it
  101. is made available to the caller. libinput does not provide access to the
  102. raw coordinates before the calibration is applied.
  103. .. _absolute_axes_nonorm:
  104. ------------------------------------------------------------------------------
  105. Why x/y coordinates are not normalized
  106. ------------------------------------------------------------------------------
  107. x/y are not given in :ref:`normalized coordinates <motion_normalization>`
  108. ([0..1]) for one simple reason: the aspect ratio of virtually all current
  109. devices is something other than 1:1. A normalized axes thus is only useful to
  110. determine that the stylus is e.g. at 78% from the left, 34% from the top of
  111. the device. Without knowing the per-axis resolution, these numbers are
  112. meaningless. Worse, calculation based on previous coordinates is simply wrong:
  113. a movement from 0/0 to 50%/50% is not a 45-degree line.
  114. This could be alleviated by providing resolution and information about the
  115. aspect ratio to the caller. Which shifts processing and likely errors into the
  116. caller for little benefit. Providing the x/y axes in mm from the outset
  117. removes these errors.