• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1.. _tablet-support:
2
3==============================================================================
4Tablet support
5==============================================================================
6
7This page provides details about the graphics tablet
8support in libinput. Note that the term "tablet" in libinput refers to
9graphics tablets only (e.g. Wacom Intuos), not to tablet devices like the
10Apple iPad.
11
12.. figure:: tablet.svg
13    :align: center
14
15    Illustration of a graphics tablet
16
17.. _tablet-tools:
18
19------------------------------------------------------------------------------
20Pad buttons vs. tablet tools
21------------------------------------------------------------------------------
22
23Most tablets provide two types of devices. The physical tablet often
24provides a number of buttons and a touch ring or strip. Interaction on the
25drawing surface of the tablet requires a tool, usually in the shape of a
26stylus.  The libinput interface exposed by devices with the
27**LIBINPUT_DEVICE_CAP_TABLET_TOOL** capability applies only to events generated
28by tools.
29
30Buttons, rings or strips on the physical tablet hardware (the "pad") are
31exposed by devices with the **LIBINPUT_DEVICE_CAP_TABLET_PAD** capability.
32Pad events do not require a tool to be in proximity. Note that both
33capabilities may exist on the same device though usually they are split
34across multiple kernel devices.
35
36.. figure:: tablet-interfaces.svg
37    :align: center
38
39    Difference between Pad and Tool buttons
40
41Touch events on the tablet integrated into a screen itself are exposed
42through the **LIBINPUT_DEVICE_CAP_TOUCH** capability. Touch events on a
43standalone tablet are exposed through the **LIBINPUT_DEVICE_CAP_POINTER**
44capability.  In both cases, the kernel usually provides a separate event
45node for the touch device, resulting in a separate libinput device.
46See **libinput_device_get_device_group()** for information on how to associate
47the touch part with other devices exposed by the same physical hardware.
48
49.. _tablet-tip:
50
51------------------------------------------------------------------------------
52Tool tip events vs. tool button events
53------------------------------------------------------------------------------
54
55The primary use of a tablet tool is to draw on the surface of the tablet.
56When the tool tip comes into contact with the surface, libinput sends an
57event of type **LIBINPUT_EVENT_TABLET_TOOL_TIP**, and again when the tip
58ceases contact with the surface.
59
60Tablet tools may send button events; these are exclusively for extra buttons
61unrelated to the tip. A button event is independent of the tip and can while
62the tip is down or up.
63
64Some tablet tools' pressure detection is too sensitive, causing phantom
65touches when the user only slightly brushes the surfaces. For example, some
66tools are capable of detecting 1 gram of pressure.
67
68libinput uses a device-specific pressure threshold to determine when the tip
69is considered logically down. As a result, libinput may send a nonzero
70pressure value while the tip is logically up. Most application can and
71should ignore pressure information until they receive the event of type
72**LIBINPUT_EVENT_TABLET_TOOL_TIP**. Applications that require extremely
73fine-grained pressure sensitivity should use the pressure data instead of
74the tip events to determine a logical tip down state and treat the tip
75events like axis events otherwise.
76
77Note that the pressure threshold to trigger a logical tip event may be zero
78on some devices. On tools without pressure sensitivity, determining when a
79tip is down is device-specific.
80
81.. _tablet-relative-motion:
82
83------------------------------------------------------------------------------
84Relative motion for tablet tools
85------------------------------------------------------------------------------
86
87libinput calculates the relative motion vector for each event and converts
88it to the same coordinate space that a normal mouse device would use. For
89the caller, this means that the delta coordinates returned by
90**libinput_event_tablet_tool_get_dx()** and
91**libinput_event_tablet_tool_get_dy()** can be used identical to the delta
92coordinates from any other pointer event. Any resolution differences between
93the x and y axes are accommodated for, a delta of N/N represents a 45 degree
94diagonal move on the tablet.
95
96The delta coordinates are available for all tablet events, it is up to the
97caller to decide when a tool should be used in relative mode. It is
98recommended that mouse and lens cursor tool default to relative mode and
99all pen-like tools to absolute mode.
100
101If a tool in relative mode must not use pointer acceleration, callers
102should use the absolute coordinates returned by
103**libinput_event_tablet_tool_get_x()** and libinput_event_tablet_tool_get_y()
104and calculate the delta themselves. Callers that require exact physical
105distance should also use these functions to calculate delta movements.
106
107.. _tablet-axes:
108
109------------------------------------------------------------------------------
110Special axes on tablet tools
111------------------------------------------------------------------------------
112
113A tablet tool usually provides additional information beyond x/y positional
114information and the tip state. A tool may provide the distance to the tablet
115surface and the pressure exerted on the tip when in contact. Some tablets
116additionally provide tilt information along the x and y axis.
117
118.. figure:: tablet-axes.svg
119    :align: center
120
121    Illustration of the distance, pressure and tilt axes
122
123The granularity and precision of the distance and pressure axes varies
124between tablet devices and cannot usually be mapped into a physical unit.
125libinput normalizes distance and pressure into the [0, 1] range.
126
127While the normalization range is identical for these axes, a caller should
128not interpret identical values as identical across axes, i.e. a value v1 on
129the distance axis has no relation to the same value v1 on the pressure axis.
130
131The tilt axes provide the angle in degrees between a vertical line out of
132the tablet and the top of the stylus. The angle is measured along the x and
133y axis, respectively, a positive tilt angle thus means that the stylus' top
134is tilted towards the logical right and/or bottom of the tablet.
135
136.. _tablet-fake-proximity:
137
138------------------------------------------------------------------------------
139Handling of proximity events
140------------------------------------------------------------------------------
141
142libinput's **LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY** events notify a caller
143when a tool comes into sensor range or leaves the sensor range. On some
144tools this range does not represent the physical range but a reduced
145tool-specific logical range. If the range is reduced, this is done
146transparent to the caller.
147
148For example, the Wacom mouse and lens cursor tools are usually
149used in relative mode, lying flat on the tablet. Movement typically follows
150the interaction normal mouse movements have, i.e. slightly lift the tool and
151place it in a separate location. The proximity detection on Wacom
152tablets however extends further than the user may lift the mouse, i.e. the
153tool may not be lifted out of physical proximity. For such tools, libinput
154provides software-emulated proximity.
155
156Events from the pad do not require proximity, they may be sent any time.
157
158.. _tablet-pressure-offset:
159
160------------------------------------------------------------------------------
161Pressure offset on worn-out tools
162------------------------------------------------------------------------------
163
164When a tool is used for an extended period it can wear down physically. A
165worn-down tool may never return a zero pressure value. Even when hovering
166above the surface, the pressure value returned by the tool is nonzero,
167creating a fake surface touch and making interaction with the tablet less
168predictable.
169
170libinput automatically detects pressure offsets and rescales the remaining
171pressure range into the available range, making pressure-offsets transparent
172to the caller. A tool with a pressure offset will thus send a 0 pressure
173value for the detected offset and nonzero pressure values for values higher
174than that offset.
175
176Some limitations apply to avoid misdetection of pressure offsets,
177specifically:
178
179- pressure offset is only detected on proximity in, and if a device is
180  capable of detection distances,
181- pressure offset is only detected if the distance between the tool and the
182  tablet is high enough,
183- pressure offset is only used if it is 20% or less of the pressure range
184  available to the tool. A pressure offset higher than 20% indicates either
185  a misdetection or a tool that should be replaced, and
186- if a pressure value less than the current pressure offset is seen, the
187  offset resets to that value.
188
189Pressure offsets are not detected on **LIBINPUT_TABLET_TOOL_TYPE_MOUSE**
190and **LIBINPUT_TABLET_TOOL_TYPE_LENS** tools.
191
192.. _tablet-serial-numbers:
193
194------------------------------------------------------------------------------
195Tracking unique tools
196------------------------------------------------------------------------------
197
198Some tools provide hardware information that enables libinput to uniquely
199identify the physical device. For example, tools compatible with the Wacom
200Intuos 4, Intuos 5, Intuos Pro and Cintiq series are uniquely identifiable
201through a serial number. libinput does not specify how a tool can be
202identified uniquely, a caller should use **libinput_tablet_tool_is_unique()** to
203check if the tool is unique.
204
205libinput creates a struct libinput_tablet_tool on the first proximity in of
206this tool. By default, this struct is destroyed on proximity out and
207re-initialized on the next proximity in. If a caller keeps a reference to
208the tool by using **libinput_tablet_tool_ref()** libinput re-uses this struct
209whenever that same physical tool comes into proximity on any tablet
210recognized by libinput. It is possible to attach tool-specific virtual state
211to the tool. For example, a graphics program such as the GIMP may assign a
212specific color to each tool, allowing the artist to use the tools like
213physical pens of different color. In multi-tablet setups it is also
214possible to track the tool across devices.
215
216If the tool does not have a unique identifier, libinput creates a single
217struct libinput_tablet_tool per tool type on each tablet the tool is used
218on.
219
220.. _tablet-tool-types:
221
222------------------------------------------------------------------------------
223Vendor-specific tablet tool types
224------------------------------------------------------------------------------
225
226libinput supports a number of high-level tool types that describe the
227general interaction expected with the tool. For example, a user would expect
228a tool of type **LIBINPUT_TABLET_TOOL_TYPE_PEN** to interact with a
229graphics application taking pressure and tilt into account. The default
230virtual tool assigned should be a drawing tool, e.g. a virtual pen or brush.
231A tool of type **LIBINPUT_TABLET_TOOL_TYPE_ERASER** would normally be
232mapped to an eraser-like virtual tool. See **libinput_tablet_tool_type**
233for the list of all available tools.
234
235Vendors may provide more fine-grained information about the tool in use by
236adding a hardware-specific tool ID. libinput provides this ID to the caller
237with **libinput_tablet_tool_get_tool_id()** but makes no promises about the
238content or format of the ID.
239
240libinput currently supports Wacom-style tool IDs as provided on the Wacom
241Intuos 3, 4, 5, Wacon Cintiq and Wacom Intuos Pro series. The tool ID can
242be used to distinguish between e.g. a Wacom Classic Pen or a Wacom Pro Pen.
243It is  the caller's responsibility to interpret the tool ID.
244
245.. _tablet-bounds:
246
247------------------------------------------------------------------------------
248Out-of-bounds motion events
249------------------------------------------------------------------------------
250
251Some tablets integrated into a screen (e.g. Wacom Cintiq 24HD, 27QHD and
25213HD series, etc.) have a sensor larger than the display area. libinput uses
253the range advertised by the kernel as the valid range unless device-specific
254quirks are present. Events outside this range will produce coordinates that
255may be negative or larger than the tablet's width and/or height. It is up to
256the caller to ignore these events.
257
258.. figure:: tablet-out-of-bounds.svg
259    :align: center
260
261    Illustration of the out-of-bounds area on a tablet
262
263In the image above, the display area is shown in black. The red area around
264the display illustrates the sensor area that generates input events. Events
265within this area will have negative coordinate or coordinates larger than
266the width/height of the tablet.
267
268If events outside the logical bounds of the input area are scaled into a
269custom range with **libinput_event_tablet_tool_get_x_transformed()** and
270**libinput_event_tablet_tool_get_y_transformed()** the resulting value may be
271less than 0 or larger than the upper range provided. It is up to the caller
272to test for this and handle or ignore these events accordingly.
273
274.. _tablet-pad-buttons:
275
276------------------------------------------------------------------------------
277Tablet pad button numbers
278------------------------------------------------------------------------------
279
280Tablet Pad buttons are numbered sequentially, starting with button 0. Thus
281button numbers returned by **libinput_event_tablet_pad_get_button_number()**
282have no semantic meaning, a notable difference to the button codes returned
283by other libinput interfaces (e.g. **libinput_event_tablet_tool_get_button()**).
284
285The Linux kernel requires all input events to have semantic event codes,
286but generic buttons like those on a pad cannot easily be assigned semantic
287codes. The kernel supports generic codes in the form of BTN_0 through to
288BTN_9 and additional unnamed space up until code 0x10f. Additional generic
289buttons are available as BTN_A in the range dedicated for gamepads and
290joysticks. Thus, tablet with a large number of buttons have to map across
291two semantic ranges, have to use unnamed kernel button codes or risk leaking
292into an unrelated range. libinput transparently maps the kernel event codes
293into a sequential button range on the pad. Callers should use external
294sources like libwacom to associate button numbers to their position on the
295tablet.
296
297Some buttons may have expected default behaviors. For example, on Wacom
298Intuos Pro series tablets, the button inside the touch ring is expected to
299switch between modes, see :ref:`tablet-pad-modes`. Callers should use
300external sources like libwacom to identify which buttons have semantic
301behaviors.
302
303.. _tablet-left-handed:
304
305------------------------------------------------------------------------------
306Tablets in left-handed mode
307------------------------------------------------------------------------------
308
309Left-handed mode on tablet devices usually means rotating the physical
310tablet by 180 degrees to move the tablet pad button area to right side of
311the tablet.  When left-handed mode is enabled on a tablet device (see
312**libinput_device_config_left_handed_set()**) the tablet tool and tablet pad
313behavior changes. In left-handed mode, the tools' axes are adjusted
314so that the origin of each axis remains the logical north-east of
315the physical tablet. For example, the x and y axes are inverted and the
316positive x/y coordinates are down/right of the top-left corner of the tablet
317in its current orientation. On a tablet pad, the ring and strip are
318similarly adjusted. The origin of the ring and strips remain the top-most
319point.
320
321.. figure:: tablet-left-handed.svg
322    :align: center
323
324    Tablet axes in right- and left-handed mode
325
326Pad buttons are not affected by left-handed mode; the number of each button
327remains the same even when the perceived physical location of the button
328changes. This is a conscious design decision:
329
330- Tablet pad buttons do not have intrinsic semantic meanings. Re-ordering
331  the button numbers would not change any functionality.
332- Button numbers should not be exposed directly to the user but handled in
333  the intermediate layers. Re-ordering button numbers thus has no
334  user-visible effect.
335- Re-ordering button numbers may complicate the intermediate layers.
336
337Left-handed mode is only available on some tablets, some tablets are
338symmetric and thus do not support left-handed mode. libinput requires
339libwacom to determine if a tablet is capable of being switched to
340left-handed mode.
341
342.. _tablet-pad-modes:
343
344------------------------------------------------------------------------------
345Tablet pad modes
346------------------------------------------------------------------------------
347
348Tablet pad modes are virtual groupings of button, ring and strip
349functionality. A caller may assign different functionalities depending on
350the mode the tablet is in. For example, in mode 0 the touch ring may emulate
351scrolling, in mode 1 the touch ring may emulate zooming, etc. libinput
352handles the modes and mode switching but does not assign specific
353functionality to buttons, rings or strips based on the mode. It is up to the
354caller to decide whether the mode only applies to buttons, rings and strips
355or only to rings and strips (this is the case with the Wacom OS X and
356Windows driver).
357
358The availability of modes on a touchpad usually depends on visual feedback
359such as LEDs around the touch ring. If no visual feedback is available, only
360one mode may be available.
361
362Mode switching is controlled by libinput and usually toggled by one or
363more buttons on the device. For example, on the Wacom Intuos 4, 5, and
364Pro series tablets the mode button is the button centered in the touch
365ring and toggles the modes sequentially. On the Wacom Cintiq 24HD the
366three buttons next to each touch ring allow for directly changing the
367mode to the desired setting.
368
369Multiple modes may exist on the tablet, libinput uses the term "mode group"
370for such groupings of buttons that share a mode and mode toggle. For
371example, the Wacom Cintiq 24HD has two separate mode groups, one for the
372left set of buttons, strips, and touch rings and one for the right set.
373libinput handles the mode groups independently and returns the mode for each
374button as appropriate. The mode group is static for the lifetime of the
375device.
376
377.. figure:: tablet-intuos-modes.svg
378    :align: center
379
380    Modes on an Intuos Pro-like tablet
381
382In the image above, the Intuos Pro-like tablet provides 4 LEDs to indicate
383the currently active modes. The button inside the touch ring cycles through
384the modes in a clockwise fashion. The upper-right LED indicates that the
385currently active mode is 1, based on 0-indexed mode numbering.
386**libinput_event_tablet_pad_get_mode()** would thus return 1 for all button and
387ring events on this tablet. When the center button is pressed, the mode
388switches to mode 2, the LED changes to the bottom-right and
389**libinput_event_tablet_pad_get_mode()** returns 2 for the center button event
390and all subsequent events.
391
392.. figure:: tablet-cintiq24hd-modes.svg
393    :align: center
394
395    Modes on an Cintiq 24HD-like tablet
396
397In the image above, the Cintiq 24HD-like tablet provides 3 LEDs on each side
398of the tablet to indicate the currently active mode for that group of
399buttons and the respective ring. The buttons next to the touch ring select
400the mode directly. The two LEDs indicate that the mode for the left set of
401buttons is currently 0, the mode for the right set of buttons is currently
4021, based on 0-indexed mode numbering. **libinput_event_tablet_pad_get_mode()**
403would thus return 0 for all button and ring events on the left and 1 for all
404button and ring events on the right. When one of the three mode toggle
405buttons on the right is pressed, the right mode switches to that button's
406mode but the left mode remains unchanged.
407
408.. _tablet-touch-arbitration:
409
410------------------------------------------------------------------------------
411Tablet touch arbitration
412------------------------------------------------------------------------------
413
414"Touch arbitration" is the terminology used when touch events are suppressed
415while the pen is in proximity. Since it is almost impossible to use a stylus
416or other tool without triggering touches with the hand holding the tool,
417touch arbitration serves to reduce the number of accidental inputs.
418The wacom kernel driver currently provides touch arbitration but for other
419devices arbitration has to be done in userspace.
420
421libinput uses the **libinput_device_group** to decide on touch arbitration
422and automatically discards touch events whenever a tool is in proximity.
423The exact behavior is device-dependent.
424
425