libinput-1.28.1/doc/api/style/libinputdoxygen.css000066400000000000000000000032121477265155700220660ustar00rootroot00000000000000@import url("https://fonts.googleapis.com/css?family=Roboto+Mono");
dd {
margin-left: 30px;
}
.title {
font-size: 200%;
font-weight: bold;
}
.title .ingroups {
font-size: 50%;
}
h1 {
font-size: 150%;
color: #354C7B;
background: none;
border-bottom: 1px solid #879ECB;
font-size: 150%;
font-weight: normal;
padding-top: 8px;
padding-bottom: 8px;
padding-left: 0px;
width: 100%;
}
h2 {
font-size: 120%;
color: #354C7B;
background: none;
border-bottom: 1px solid #879ECB;
font-size: 150%;
font-weight: normal;
padding-top: 8px;
padding-bottom: 8px;
padding-left: 0px;
width: 100%;
}
.sm-dox li {
float:left;
border-top: 0;
padding-right: 20px;
}
.sm li, .sm a {
position: relative;
}
.sm, .sm ul, .sm li {
list-style: none;
display: block;
line-height: normal;
direction: ltr;
text-align: left;
}
.sm, .sm *, .sm *::before, .sm *::after {
box-sizing: border-box;
}
#main-nav {
padding: 30px;
}
/* Main menu sub-items like file-list, etc */
#main-menu li ul {
display: none;
}
.paramname {
padding-right: 10px;
}
.memtitle {
background-image: none;
background-color: #F0F0F0;
}
.memproto {
background-color: #F0F0F0;
}
.headertitle {
background-image: none;
background-color: #F0F0F0;
}
div.header {
border: none;
}
td.fieldname {
font-family: 'Roboto Mono', monospace;
}
.fieldtable th {
background-image: none;
background-color: #F0F0F0;
}
body {
letter-spacing: 0px;
}
.mdescLeft, .mdescRight, .memItemLeft, .memItemRight, .memTemplItemLeft, .memTemplItemRight, .memTemplParams {
background-color: #F0F0F0;
}
a {
color: #2873b0;
}
.navpath ul {
background-image: none;
background-color: #F0F0F0;
}
libinput-1.28.1/doc/button-debouncing-state-machine.svg000066400000000000000000003022271477265155700231160ustar00rootroot00000000000000
libinput-1.28.1/doc/button-debouncing-wave-diagram.txt000066400000000000000000000040501477265155700227510ustar00rootroot00000000000000# Source for the button debouncing wave diagram
# Paste into http://wavedrom.com/editor.html
{signal: [
{name:'current mode', wave: '3............', data: ['normal button press and release']},
{name:'physical button', wave: '01......0....'},
{name:'application ', wave: '01......0....'},
{},
['bounce mode',
{name:'current mode', wave: '4............', data: ['debounced button press']},
{name:'physical button', wave: '0101...0.....'},
{name: 'timeouts', wave: '01...0.1...0.'},
{name:'application ', wave: '01.....0.....'},
{},
{name:'current mode', wave: '4............', data: ['debounced button release']},
{name:'physical button', wave: '1...010......'},
{name: 'timeouts', wave: '0...1...0....'},
{name:'application ', wave: '1...0........'},
{},
{name:'current mode', wave: '5............', data: ['delayed button press']},
{name:'physical button', wave: '1...01.......'},
{name: 'timeouts', wave: '0...1...0....'},
{name:'application ', wave: '1...0...1....'},
{},
{name:'current mode', wave: '5............', data: ['delayed button release']},
{name:'physical button', wave: '0...10.......'},
{name: 'timeouts', wave: '0...1...0....'},
{name:'application ', wave: '0...1...0....'},
],
{},
['spurious mode',
{name:'current mode', wave: '3............', data: ['first spurious button release ']},
{name:'physical button', wave: '1.......01...'},
{name:'application ', wave: '1.......01...'},
{},
{name:'current mode', wave: '3............', data: ['later spurious button release ']},
{name:'physical button', wave: '1....01......'},
{name: 'timeouts', wave: '0....1..0....'},
{name:'application ', wave: '1............'},
{},
{name:'current mode', wave: '3............', data: ['delayed release in spurious mode ']},
{name:'physical button', wave: '1....0.......'},
{name: 'timeouts', wave: '0....1..0....'},
{name:'application ', wave: '1.......0....'}
],
],
head:{
text:'Button Debouncing Scenarios',
},
}
libinput-1.28.1/doc/middle-button-emulation.svg000066400000000000000000003406621477265155700215170ustar00rootroot00000000000000
libinput-1.28.1/doc/touchpad-edge-scrolling-state-machine.svg000066400000000000000000000531221477265155700241700ustar00rootroot00000000000000
libinput-1.28.1/doc/touchpad-gestures-state-machine.svg000066400000000000000000004464631477265155700231510ustar00rootroot00000000000000
libinput-1.28.1/doc/touchpad-softbutton-state-machine.svg000066400000000000000000001040051477265155700234760ustar00rootroot00000000000000
libinput-1.28.1/doc/touchpad-tap-state-machine.svg000066400000000000000000005521461477265155700220700ustar00rootroot00000000000000
libinput-1.28.1/doc/user/000077500000000000000000000000001477265155700151775ustar00rootroot00000000000000libinput-1.28.1/doc/user/404.rst000066400000000000000000000001771477265155700162450ustar00rootroot00000000000000:orphan:
===
404
===
This page has permanently moved, probably to `<@TARGET@>`_
This placeholder page will be removed soon.
libinput-1.28.1/doc/user/absolute-axes.rst000066400000000000000000000131441477265155700205100ustar00rootroot00000000000000.. _absolute_axes:
==============================================================================
Absolute axes
==============================================================================
Devices with absolute axes are those that send positioning data for an axis in
a device-specific coordinate range, defined by a minimum and a maximum value.
Compare this to relative devices (e.g. a mouse) that can only detect
directional data, not positional data.
libinput supports three types of devices with absolute axes:
- multi-touch screens
- single-touch screens
- :ref:`graphics tablets `
Touchpads are technically absolute devices but libinput converts the axis values
to directional motion and posts events as relative events. Touchpads do not count
as absolute devices in libinput.
For all absolute devices in libinput, the default unit for x/y coordinates is
in mm off the top left corner on the device, or more specifically off the
device's sensor. If the device is physically rotated from its natural
position and this rotation was communicated to libinput (e.g. by setting
the device left-handed),
the coordinate origin is the top left corner in the current rotation.
.. _absolute_axes_handling:
------------------------------------------------------------------------------
Handling of absolute coordinates
------------------------------------------------------------------------------
In most use-cases, absolute input devices are mapped to a single screen. For
direct input devices such as touchscreens the aspect ratio of the screen and
the device match. Mapping the input device position to the output position is
thus a simple mapping between two coordinates. libinput provides the API for
this with
- **libinput_event_pointer_get_absolute_x_transformed()** for pointer events
- **libinput_event_touch_get_x_transformed()** for touch events
libinput's API only provides the call to map into a single coordinate range.
If the coordinate range has an offset, the compositor is responsible for
applying that offset after the mapping. For example, if the device is mapped
to the right of two outputs, add the output offset to the transformed
coordinate.
.. _absolute_axes_nores:
------------------------------------------------------------------------------
Devices without x/y resolution
------------------------------------------------------------------------------
An absolute device that does not provide a valid resolution is considered
buggy and must be fixed in the kernel. Some touchpad devices do not
provide resolution, those devices are correctly handled within libinput
(touchpads are not absolute devices, as mentioned above).
.. _calibration:
------------------------------------------------------------------------------
Calibration of absolute devices
------------------------------------------------------------------------------
Absolute devices may require calibration to map precisely into the output
range required. This is done by setting a transformation matrix, see
**libinput_device_config_calibration_set_matrix()** which is applied to
each input coordinate.
.. math::
\begin{pmatrix}
cos\theta & -sin\theta & xoff \\
sin\theta & cos\theta & yoff \\
0 & 0 & 1
\end{pmatrix} \begin{pmatrix}
x \\ y \\ 1
\end{pmatrix}
:math:`\theta` is the rotation angle. The offsets :math:`xoff` and :math:`yoff` are
specified in device dimensions, i.e. a value of 1 equals one device width or
height. Note that rotation applies to the device's origin, rotation usually
requires an offset to move the coordinates back into the original range.
The most common matrices are:
- 90 degree clockwise:
.. math::
\begin{pmatrix}
0 & -1 & 1 \\
1 & 0 & 0 \\
0 & 0 & 1
\end{pmatrix}
- 180 degree clockwise:
.. math::
\begin{pmatrix}
-1 & 0 & 1 \\
0 & -1 & 1 \\
0 & 0 & 1
\end{pmatrix}
- 270 degree clockwise:
.. math::
\begin{pmatrix}
0 & 1 & 0 \\
-1 & 0 & 1 \\
0 & 0 & 1
\end{pmatrix}
- reflection along y axis:
.. math::
\begin{pmatrix}
-1 & 0 & 1 \\
1 & 0 & 0 \\
0 & 0 & 1
\end{pmatrix}
See Wikipedia's
`Transformation Matrix article `_
for more information on the matrix maths. See
**libinput_device_config_calibration_get_default_matrix()** for how these
matrices must be supplied to libinput.
Once applied, any x and y axis value has the calibration applied before it
is made available to the caller. libinput does not provide access to the
raw coordinates before the calibration is applied.
.. _absolute_axes_nonorm:
------------------------------------------------------------------------------
Why x/y coordinates are not normalized
------------------------------------------------------------------------------
x/y are not given in :ref:`normalized coordinates `
([0..1]) for one simple reason: the aspect ratio of virtually all current
devices is something other than 1:1. A normalized axes thus is only useful to
determine that the stylus is e.g. at 78% from the left, 34% from the top of
the device. Without knowing the per-axis resolution, these numbers are
meaningless. Worse, calculation based on previous coordinates is simply wrong:
a movement from 0/0 to 50%/50% is not a 45-degree line.
This could be alleviated by providing resolution and information about the
aspect ratio to the caller. Which shifts processing and likely errors into the
caller for little benefit. Providing the x/y axes in mm from the outset
removes these errors.
libinput-1.28.1/doc/user/absolute-coordinate-ranges.rst000066400000000000000000000137231477265155700231570ustar00rootroot00000000000000.. _absolute_coordinate_ranges:
==============================================================================
Coordinate ranges for absolute axes
==============================================================================
libinput requires that all touchpads provide a correct axis range and
resolution. These are used to enable or disable certain features or adapt
the interaction with the touchpad. For example, the software button area is
narrower on small touchpads to avoid reducing the interactive surface too
much. Likewise, palm detection works differently on small touchpads as palm
interference is less likely to happen.
Touchpads with incorrect axis ranges generate error messages
in the form:
`_.
Detailed explanations are below.
.. note:: ``libinput measure touchpad-size`` was introduced in libinput
1.16. For earlier versions, use `libevdev `_'s
``touchpad-edge-detector`` tool.
The ``libinput measure touchpad-size`` tool is an interactive tool. It must
be called with the physical dimensions of the touchpad in mm. In the example
below, we use 100mm wide and 55mm high. The tool will find the touchpad device
automatically.
::
$> sudo libinput measure touchpad-size 100x55
Using "Touchpad SynPS/2 Synaptics TouchPad": /dev/input/event4
Kernel specified touchpad size: 99.7x75.9mm
User specified touchpad size: 100.0x55.0mm
Kernel axis range: x [1024..5112], y [2024..4832]
Detected axis range: x [ 0.. 0], y [ 0.. 0]
Move one finger along all edges of the touchpad
until the detected axis range stops changing.
...
Move the finger around until the detected axis range matches the data sent
by the device. ``Ctrl+C`` terminates the tool and prints a
suggested hwdb entry. ::
...
Kernel axis range: x [1024..5112], y [2024..4832]
^C
Detected axis range: x [2072..4880], y [2159..4832]
Resolutions calculated based on user-specified size: x 28, y 49 units/mm
Suggested hwdb entry:
Note: the dmi modalias match is a guess based on your machine's modalias:
dmi:bvnLENOVO:bvrGJET72WW(2.22):bd02/21/2014:svnLENOVO:pn20ARS25701:pvrThinkPadT440s:rvnLENOVO:rn20ARS25701:rvrSDK0E50512STD:cvnLENOVO:ct10:cvrNotAvailable:
Please verify that this is the most sensible match and adjust if necessary.
-8<--------------------------
# Laptop model description (e.g. Lenovo X1 Carbon 5th)
evdev:name:SynPS/2 Synaptics TouchPad:dmi:*svnLENOVO:*pvrThinkPadT440s*
EVDEV_ABS_00=2072:4880:28
EVDEV_ABS_01=2159:4832:49
EVDEV_ABS_35=2072:4880:28
EVDEV_ABS_36=2159:4832:49
-8<--------------------------
Instructions on what to do with this snippet are in /usr/lib/udev/hwdb.d/60-evdev.hwdb
If there are discrepancies between the coordinate range the kernels
advertises and what what the touchpad sends, the hwdb entry should be added to the
``60-evdev.hwdb`` file provided by the `systemd project `_.
An example commit can be found
`here `_.
The ``libinput measure touchpad-size`` tool attempts to provide the correct
dmi match but it does require user verification.
In most cases the dmi match can and should be trimmed to the system vendor (``svn``)
and the product version (``pvr``) or product name (``pn``), with everything else
replaced by a wildcard (``*``). In the above case, the match string is:
::
evdev:name:SynPS/2 Synaptics TouchPad:dmi:*svnLENOVO:*pvrThinkPadT440s*
As a general rule: for Lenovo devices use ``pvr`` and for all others use
``pn``.
.. note:: hwdb match strings only allow for alphanumeric ascii characters. Use a
wildcard (* or ?, whichever appropriate) for special characters.
The actual axis overrides are in the form:
::
# axis number=min:max:resolution
EVDEV_ABS_00=2072:4880:28
or, if the range is correct but the resolution is wrong
::
# axis number=::resolution
EVDEV_ABS_00=::28
Note the leading single space. The axis numbers are in hex and can be found
in ``linux/input-event-codes.h``. For touchpads ``ABS_X``, ``ABS_Y``,
``ABS_MT_POSITION_X`` and ``ABS_MT_POSITION_Y`` are required.
.. note:: The touchpad's ranges and/or resolution should only be fixed when
there is a significant discrepancy. A few units do not make a
difference and a resolution that is off by 2 or less usually does
not matter either.
Once a match and override rule has been found, follow the instructions at
the top of the
`60-evdev.hwdb `_
file to save it locally and trigger the udev hwdb reload. Rebooting is
always a good idea. If the match string is correct, the new properties will
show up in the
output of
::
udevadm info /sys/class/input/event4
Adjust the command for the event node of your touchpad.
A udev builtin will apply the new axis ranges automatically.
When the axis override is confirmed to work, please submit it as a pull
request to the `systemd project `_.
libinput-1.28.1/doc/user/architecture.rst000066400000000000000000000220551477265155700204170ustar00rootroot00000000000000.. _architecture:
==============================================================================
libinput's internal architecture
==============================================================================
This page provides an outline of libinput's internal architecture. The goal
here is to get the high-level picture across and point out the components
and their interplay to new developers.
The public facing API is in ``libinput.c``, this file is thus the entry point
for almost all API calls. General device handling is in ``evdev.c`` with the
device-type-specific implementations in ``evdev-.c``. It is not
necessary to understand all of libinput to contribute a patch.
:ref:`architecture-contexts` is the only user-visible implementation detail,
everything else is purely internal implementation and may change when
required.
.. _architecture-contexts:
------------------------------------------------------------------------------
The udev and path contexts
------------------------------------------------------------------------------
The first building block is the "context" which can be one of
two types, "path" and "udev". See **libinput_path_create_context()** and
**libinput_udev_create_context()**. The path/udev specific bits are in
``path-seat.c`` and ``udev-seat.c``. This includes the functions that add new
devices to a context.
.. graphviz::
digraph context
{
compound=true;
rankdir="LR";
node [
shape="box";
]
libudev [label="libudev 'add' event"]
udev [label="**libinput_udev_create_context()**"];
udev_backend [label="udev-specific backend"];
context [label="libinput context"]
udev -> udev_backend;
libudev -> udev_backend;
udev_backend -> context;
}
The udev context provides automatic device hotplugging as udev's "add"
events are handled directly by libinput. The path context requires that the
caller adds devices.
.. graphviz::
digraph context
{
compound=true;
rankdir="LR";
node [
shape="box";
]
path [label="**libinput_path_create_context()**"];
path_backend [label="path-specific backend"];
xdriver [label="**libinput_path_add_device()**"]
context [label="libinput context"]
path -> path_backend;
xdriver -> path_backend;
path_backend -> context;
}
As a general rule: all Wayland compositors use a udev context, the X.org
stack uses a path context.
Which context was initialized only matters for creating/destroying a context
and adding devices. The device handling itself is the same for both types of
context.
.. _architecture-device:
------------------------------------------------------------------------------
Device initialization
------------------------------------------------------------------------------
libinput only supports evdev devices, all the device initialization is done
in ``evdev.c``. Much of the libinput public API is also a thin wrapper around
the matching implementation in the evdev device.
There is a 1:1 mapping between libinput devices and ``/dev/input/eventX``
device nodes.
.. graphviz::
digraph context
{
compound=true;
rankdir="LR";
node [
shape="box";
]
devnode [label="/dev/input/event0"]
libudev [label="libudev 'add' event"]
xdriver [label="**libinput_path_add_device()**"]
context [label="libinput context"]
evdev [label="evdev_device_create()"]
devnode -> xdriver;
devnode -> libudev;
xdriver -> context;
libudev -> context;
context->evdev;
}
Entry point for all devices is ``evdev_device_create()``, this function
decides to create a ``struct evdev_device`` for the given device node.
Based on the udev tags (e.g. ``ID_INPUT_TOUCHPAD``), a
:ref:`architecture-dispatch` is initialized. All event handling is then in this
dispatch.
Rejection of devices and the application of quirks is generally handled in
``evdev.c`` as well. Common functionality shared across multiple device types
(like button-scrolling) is also handled here.
.. _architecture-dispatch:
------------------------------------------------------------------------------
Device-type specific event dispatch
------------------------------------------------------------------------------
Depending on the device type, ``evdev_configure_device`` creates the matching
``struct evdev_dispatch``. This dispatch interface contains the function
pointers to handle events. Four such dispatch methods are currently
implemented: touchpad, tablet, tablet pad, and the fallback dispatch which
handles mice, keyboards and touchscreens.
.. graphviz::
digraph context
{
compound=true;
rankdir="LR";
node [
shape="box";
]
evdev [label="evdev_device_create()"]
fallback [label="evdev-fallback.c"]
touchpad [label="evdev-mt-touchpad.c"]
tablet [label="evdev-tablet.c"]
pad [label="evdev-tablet-pad.c"]
evdev -> fallback;
evdev -> touchpad;
evdev -> tablet;
evdev -> pad;
}
While ``evdev.c`` pulls the event out of libevdev, the actual handling of the
events is performed within the dispatch method.
.. graphviz::
digraph context
{
compound=true;
rankdir="LR";
node [
shape="box";
]
evdev [label="evdev_device_dispatch()"]
fallback [label="fallback_interface_process()"];
touchpad [label="tp_interface_process()"]
tablet [label="tablet_process()"]
pad [label="pad_process()"]
evdev -> fallback;
evdev -> touchpad;
evdev -> tablet;
evdev -> pad;
}
The dispatch methods then look at the ``struct input_event`` and proceed to
update the state. Note: the serialized nature of the kernel evdev protocol
requires that the device updates the state with each event but to delay
processing until the ``SYN_REPORT`` event is received.
.. _architecture-configuration:
------------------------------------------------------------------------------
Device configuration
------------------------------------------------------------------------------
All device-specific configuration is handled through ``struct
libinput_device_config_FOO`` instances. These are set up during device init
and provide the function pointers for the ``get``, ``set``, ``get_default``
triplet of configuration queries (or more, where applicable).
For example, the ``struct tablet_dispatch`` for tablet devices has a
``struct libinput_device_config_accel``. This struct is set up with the
required function pointers to change the profiles.
.. graphviz::
digraph context
{
compound=true;
rankdir="LR";
node [
shape="box";
]
tablet [label="struct tablet_dispatch"]
config [label="struct libinput_device_config_accel"];
tablet_config [label="tablet_accel_config_set_profile()"];
tablet->config;
config->tablet_config;
}
When the matching ``**libinput_device_config_set_FOO()**`` is called, this goes
through to the config struct and invokes the function there. Thus, it is
possible to have different configuration functions for a mouse vs a
touchpad, even though the interface is the same.
.. graphviz::
digraph context
{
compound=true;
rankdir="LR";
node [
shape="box";
]
libinput [label="**libinput_device_config_accel_set_profile()**"];
tablet_config [label="tablet_accel_config_set_profile()"];
libinput->tablet_config;
}
.. _architecture-filter:
------------------------------------------------------------------------------
Pointer acceleration filters
------------------------------------------------------------------------------
All pointer acceleration is handled in the ``filter.c`` file and its
associated files.
The ``struct motion_filter`` is initialized during device init, whenever
deltas are available they are passed to ``filter_dispatch()``. This function
returns a set of :ref:`normalized coordinates `.
All actual acceleration is handled within the filter, the device itself has
no further knowledge. Thus it is possible to have different acceleration
filters for the same device types (e.g. the Lenovo X230 touchpad has a
custom filter).
.. graphviz::
digraph context
{
compound=true;
rankdir="LR";
node [
shape="box";
]
fallback [label="fallback deltas"];
touchpad [label="touchpad deltas"];
tablet [label="tablet deltas"];
filter [label="filter_dispatch"];
fallback->filter;
touchpad->filter;
tablet->filter;
flat [label="accelerator_interface_flat()"];
x230 [label="accelerator_filter_x230()"];
pen [label="tablet_accelerator_filter_flat_pen()"];
filter->flat;
filter->x230;
filter->pen;
}
Most filters convert the deltas (incl. timestamps) to a motion speed and
then apply a so-called profile function. This function returns a factor that
is then applied to the current delta, converting it into an accelerated
delta. See :ref:`pointer-acceleration` for more details.
the current
libinput-1.28.1/doc/user/building.rst000066400000000000000000000250251477265155700175320ustar00rootroot00000000000000.. _building_libinput:
==============================================================================
libinput build instructions
==============================================================================
.. contents::
:local:
:backlinks: entry
Instructions on how to build libinput and its tools and how to build against
libinput.
The build instruction on this page detail how to overwrite your
system-provided libinput with one from the git repository, see
see :ref:`reverting_install` to revert to the previous state.
.. _distribution_repos:
------------------------------------------------------------------------------
Distribution repositories for libinput from git
------------------------------------------------------------------------------
Some distributions provide package repositories for users that want to test
the latest libinput without building it manually.
.. note:: The list below is provided for convenience. The libinput community
cannot provide any guarantees that the packages in those repositories are
correct, up-to-date and/or unmodified from the git branch. Due dilligence
is recommended.
The following repositories provide an up-to-date package for libinput:
- **Arch:** https://aur.archlinux.org/packages/libinput-git/
- **Fedora:** https://copr.fedorainfracloud.org/coprs/whot/libinput-git/
Please follow the respective repositories for instructions on how to enable
the repository and install libinput.
.. _building:
------------------------------------------------------------------------------
Building libinput
------------------------------------------------------------------------------
libinput uses `meson `_ and
`ninja `_. A build is usually the three-step
process below. A successful build requires the
:ref:`building_dependencies` to be installed before running meson.
::
$> git clone https://gitlab.freedesktop.org/libinput/libinput
$> cd libinput
$> meson setup --prefix=/usr builddir/
$> ninja -C builddir/
$> sudo ninja -C builddir/ install
When running libinput versions 1.11.x or earlier, you must run
::
$> sudo systemd-hwdb update
Additional options may also be specified. For example:
::
$> meson setup --prefix=/usr -Ddocumentation=false builddir/
We recommend that users disable the documentation, it's not usually required
for testing and reduces the number of dependencies needed.
The ``prefix`` or other options can be changed later with the
``meson configure`` command. For example:
::
$> meson configure builddir/ -Dprefix=/some/other/prefix -Ddocumentation=true
$> ninja -C builddir
$> sudo ninja -C builddir/ install
Running ``meson configure builddir/`` with no other arguments lists all
configurable options meson provides.
To rebuild from scratch, simply remove the build directory and run meson
again:
::
$> rm -r builddir/
$> meson setup --prefix=....
.. _verifying_install:
..............................................................................
Verifying the install
..............................................................................
To verify the install worked correctly, check that libinput.so.x.x.x is in
the library path and that all symlinks point to the new library.
::
$> ldconfig -p | grep libinput | awk '{print $NF}' | xargs ls -l
lrwxrwxrwx 1 root root 14 lug 22 13:06 /usr/lib/x86_64-linux-gnu/libinput.so -> libinput.so.10
lrwxrwxrwx 1 root root 19 lug 22 13:06 /usr/lib/x86_64-linux-gnu/libinput.so.10 -> libinput.so.10.13.0
-rwxr-xr-x 1 root root 1064144 lug 22 13:06 /usr/lib/x86_64-linux-gnu/libinput.so.10.13.0
.. _reverting_install:
..............................................................................
Reverting to the system-provided libinput package
..............................................................................
The recommended way to revert to the system install is to use the package
manager to reinstall the libinput package. In some cases, this may leave
files in the system (e.g. ``/usr/lib/libinput.la``) but these files are
usually harmless. To definitely remove all files, run the following command
from the libinput source directory:
::
$> sudo ninja -C builddir/ uninstall
# WARNING: Do not restart the computer/X/the Wayland compositor after
# uninstall, reinstall the system package immediately!
The following commands reinstall the current system package for libinput,
overwriting manually installed files.
- **Debian/Ubuntu** based distributions: ``sudo apt-get install --reinstall libinput``
- **Fedora 22** and later: ``sudo dnf reinstall libinput``
- **RHEL/CentOS/Fedora 21** and earlier: ``sudo yum reinstall libinput``
- **openSUSE**: ``sudo zypper install --force libinput10``
- **Arch**: ``sudo pacman -S libinput``
.. _building_selinux:
..............................................................................
SELinux adjustments
..............................................................................
.. note:: This section only applies to meson version < 0.42.0
On systems with SELinux, overwriting the distribution-provided package with
a manually built libinput may cause SELinux denials. This usually manifests
when gdm does not start because it is denied access to libinput. The journal
shows a log message in the form of:
::
May 25 15:28:42 localhost.localdomain audit[23268]: AVC avc: denied { execute } for pid=23268 comm="gnome-shell" path="/usr/lib64/libinput.so.10.12.2" dev="dm-0" ino=1709093 scontext=system_u:system_r:xdm_t:s0-s0:c0.c1023 tcontext=unconfined_u:object_r:user_home_t:s0 tclass=file permissive=0
May 25 15:28:42 localhost.localdomain org.gnome.Shell.desktop[23270]: /usr/bin/gnome-shell: error while loading shared libraries: libinput.so.10: failed to map segment from shared object
The summary of this error message is that gdm's gnome-shell runs in the
``system_u:system_r:xdm_t`` context but libinput is installed with the
context ``unconfined_u:object_r:user_home_t``.
To avoid this issue, restore the SELinux context for any system files.
::
$> sudo restorecon /usr/lib*/libinput.so.*
This issue is tracked in https://github.com/mesonbuild/meson/issues/1967.
.. _building_dependencies:
------------------------------------------------------------------------------
Build dependencies
------------------------------------------------------------------------------
libinput has a few build-time dependencies that must be installed prior to
running meson.
.. hint:: The build dependencies for some distributions can be found in the
`GitLab Continuous Integration file `_.
Search for **FEDORA_PACKAGES** in the **variables:** definition
and check the list for an entry for your distribution.
In most cases, it is sufficient to install the dependencies that your
distribution uses to build the libinput package. These can be installed
with one of the following commands:
- **Debian/Ubuntu** based distributions: ``sudo apt-get build-dep libinput``
- **Fedora 22** and later: ``sudo dnf builddep libinput``
- **RHEL/CentOS/Fedora 21** and earlier: ``sudo yum-builddep libinput``
- **openSUSE**: ::
$> sudo zypper modifyrepo --enable ``zypper repos | grep source | awk '{print $5}'``
$> sudo zypper source-install -d libinput10
$> sudo zypper install autoconf automake libtool
$> sudo zypper modifyrepo --disable ``zypper repos | grep source | awk '{print $5}'``
- **Arch**: ::
$> sudo pacman -S asp
$> cd $(mktemp -d)
$> asp export libinput
$> cd libinput
$> makepkg --syncdeps --nobuild --noextract
If dependencies are missing, meson shows a message ``No package 'foo'
found``. See
`this blog post here `_
for instructions on how to fix it.
..............................................................................
Build dependencies per distribution
..............................................................................
.. include:: dependencies.rst
.. _building_conditional:
------------------------------------------------------------------------------
Conditional builds
------------------------------------------------------------------------------
libinput supports several meson options to disable parts of the build. See
the ``meson_options.txt`` file in the source tree for a full list of
available options. The default build enables most options and thus requires
more build dependencies. On systems where build dependencies are an issue,
options may be disabled with this meson command: ::
meson setup --prefix=/usr -Dsomefeature=false builddir
Where ``-Dsomefeature=false`` may be one of:
- ``-Ddocumentation=false``
Disables the documentation build (this website). Building the
documentation is only needed on the maintainer machine.
- ``-Dtests=false``
Disables the test suite. The test suite is only needed on developer
systems.
- ``-Ddebug-gui=false``
Disables the ``libinput debug-gui`` helper tool (see :ref:`tools`),
dropping GTK and other build dependencies. The debug-gui is only
required for troubleshooting.
- ``-Dlibwacom=false``
libwacom is required by libinput's tablet code to gather additional
information about tablets that is not available from the kernel device.
It is not recommended to disable libwacom unless libinput is used in an
environment where tablet support is not required. libinput provides tablet
support even without libwacom, but some features may be missing or working
differently.
.. _building_against:
------------------------------------------------------------------------------
Building against libinput
------------------------------------------------------------------------------
libinput provides a
`pkg-config `_ file.
Software that uses autotools should use the ``PKG_CHECK_MODULES`` autoconf
macro: ::
PKG_CHECK_MODULES(LIBINPUT, "libinput")
Software that uses meson should use the ``dependency()`` function: ::
pkgconfig = import('pkgconfig')
dep_libinput = dependency('libinput')
Software that uses CMake should use: ::
find_package(Libinput)
target_link_libraries(myprogram PRIVATE Libinput::Libinput)
Otherwise, the most rudimentary way to compile and link a program against
libinput is:
::
gcc -o myprogram myprogram.c ``pkg-config --cflags --libs libinput``
For further information on using pkgconfig see the pkg-config documentation.
libinput-1.28.1/doc/user/button-debouncing.rst000066400000000000000000000054041477265155700213620ustar00rootroot00000000000000
.. _button_debouncing:
==============================================================================
Button debouncing
==============================================================================
Physical buttons experience wear-and-tear with usage. On some devices this
can result in an effect called "contact bouncing" or "chatter". This effect
can cause the button to send multiple events within a short time frame, even
though the user only pressed or clicked the button once. This effect can be
counteracted by "debouncing" the buttons, usually by ignoring erroneous
events.
libinput provides two methods of debouncing buttons, referred to as the
"bounce" and "spurious" methods:
- In the "bounce" method, libinput monitors hardware bouncing on button
state changes, i.e. when a user clicks or releases a button. For example,
if a user presses a button but the hardware generates a
press-release-press sequence in quick succession, libinput ignores the
release and second press event. This method is always enabled.
- in the "spurious" method, libinput detects spurious releases of a button
while the button is physically held down by the user. These releases are
immediately followed by a press event. libinput monitors for these events
and ignores the release and press event. This method is disabled by
default and enables once libinput detects the first faulty event sequence.
The "bounce" method guarantees that all press events are delivered
immediately and most release events are delivered immediately. The
"spurious" method requires that release events are delayed, libinput thus
does not enable this method unless a faulty event sequence is detected. A
message is printed to the log when spurious deboucing was detected.
libinput's debouncing is supposed to correct hardware damage or
substandard hardware. Debouncing also exists as an accessibility feature
but the requirements are different. In the accessibility feature, multiple
physical key presses, usually caused by involuntary muscle movement, must be
filtered to only one key press. This feature must be implemented higher in
the stack, libinput is limited to hardware debouncing.
Below is an illustration of the button debouncing modes to show the relation
of the physical button state and the application state. Where applicable, an
extra line is added to show the timeouts used by libinput that
affect the button state handling. The waveform's high and low states
correspond to the buttons 'pressed' and 'released' states, respectively.
.. figure:: button-debouncing-wave-diagram.svg
:align: center
Diagram illustrating button debouncing
Some devices send events in bursts, erroneously triggering the button
debouncing detection. Please :ref:`file a bug ` if that
occurs for your device.
libinput-1.28.1/doc/user/clickpad-softbuttons.rst000066400000000000000000000140341477265155700220750ustar00rootroot00000000000000.. _clickpad_softbuttons:
==============================================================================
Clickpad software button behavior
==============================================================================
"Clickpads" are touchpads without separate physical buttons. Instead, the
whole touchpad acts as a button and left or right button clicks are
distinguished by :ref:`the location of the fingers ` or
the :ref:`number of fingers on the touchpad `.
"ClickPad" is a trademark by `Synaptics Inc. `_
but for simplicity we refer to any touchpad with the above feature as Clickpad,
regardless of the manufacturer.
The kernel marks clickpads with the
`INPUT_PROP_BUTTONPAD `_
property. Without this property, libinput would not know whether a touchpad
is a clickpad or not. To perform a right-click on a Clickpad, libinput
provides :ref:`software_buttons` and :ref:`clickfinger`.
.. note:: The term "click" refers refer to a physical button press
and/or release of the touchpad, the term "button event" refers to
the events generated by libinput in response to a click.
.. _software_buttons:
------------------------------------------------------------------------------
Software button areas
------------------------------------------------------------------------------
The bottom of the touchpad is split into three distinct areas generate left,
middle or right button events on click. The height of the button area
depends on the hardware but is usually around 10mm.
.. figure :: software-buttons-visualized.svg
:align: center
The locations of the virtual button areas.
Left, right and middle button events can be triggered as follows:
- if a finger is in the main area or the left button area, a click generates
left button events.
- if a finger is in the right area, a click generates right button events.
- if a finger is in the middle area, a click generates middle button events.
.. figure:: software-buttons.svg
:align: center
Left, right and middle-button click with software button areas
The middle button is always centered on the touchpad and smaller in size
than the left or right button. The actual size is device-dependent. Many
touchpads do not have visible markings so the exact location of the button
is unfortunately not visibly obvious.
.. note:: If :ref:`middle button emulation ` is
enabled on a clickpad, only left and right button areas are
available.
If fingers are down in the main area in addition to fingers in the
left or right button area, those fingers are are ignored.
A release event always releases the buttons logically down, regardless of
the current finger position
.. figure:: software-buttons-thumbpress.svg
:align: center
Only the location of the thumb determines whether it is a left, right or
middle click.
The movement of a finger can alter the button area behavior:
- if a finger starts in the main area and moves into the software button
area, the software buttons do not apply to that finger
- once a finger has moved out of the button area, it cannot move back in and
trigger a right or middle button event
- a finger moving within the software button area does not move the pointer
- once a finger moves out out of the button area it will control the
pointer (this only applies if there is no other finger down on the
touchpad)
.. figure:: software-buttons-conditions.svg
:align: center
**Left:** moving a finger into the right button area does not trigger a
right-button click.
**Right:** moving within the button areas does not generate pointer
motion.
On some touchpads, notably the 2015 Lenovo X1 Carbon 3rd series, the very
bottom end of the touchpad is outside of the sensor range but it is possible
to trigger a physical click there. To libinput, the click merely shows up as
a left button click without any positional finger data and it is
impossible to determine whether it is a left or a right click. libinput
ignores such button clicks, this behavior is intentional.
.. _clickfinger:
------------------------------------------------------------------------------
Clickfinger behavior
------------------------------------------------------------------------------
This is the default behavior on Apple touchpads. Here, a left, right, middle
button event is generated when one, two, or three fingers are held down on the
touchpad when a physical click is generated, given the default mapping. The
location of the fingers does not matter and there are no software-defined
button areas. It is possible to swap right and middle buttons, the same way as
with :ref:`tapping `.
.. figure:: clickfinger.svg
:align: center
One, two and three-finger click with Clickfinger behavior
On some touchpads, libinput imposes a limit on how the fingers may be placed
on the touchpad. In the most common use-case this allows for a user to
trigger a click with the thumb while leaving the pointer-moving finger on
the touchpad.
.. figure:: clickfinger-distance.svg
:align: center
Illustration of the distance detection algorithm
In the illustration above the red area marks the proximity area around the
first finger. Since the thumb is outside of that area libinput considers the
click a single-finger click rather than a two-finger click.
.. _special_clickpads:
------------------------------------------------------------------------------
Special Clickpads
------------------------------------------------------------------------------
The Lenovo \*40 series laptops have a clickpad that provides two software button sections, one at
the top and one at the bottom. See :ref:`Lenovo \*40 series touchpad support `
for details on the top software button.
Some Clickpads, notably some Cypress ones, perform right button detection in
firmware and appear to userspace as if the touchpad had physical buttons.
While physically clickpads, these are not handled by the software and
treated like traditional touchpads.
libinput-1.28.1/doc/user/clickpad-with-right-button.rst000066400000000000000000000046511477265155700231060ustar00rootroot00000000000000.. _clickpads_with_right_buttons:
==============================================================================
Clickpads with a fake right button
==============================================================================
libinput relies on the kernel to label :ref:`Clickpads `
with the ``INPUT_PROP_BUTTONPAD`` property so it can enable the correct
:ref:`clickpad_softbuttons`. Clickpads are not expected to have a right button
since the whole surface can be depressed.
A common bug encountered with :ref:`Clickpads `
is that the device advertises a physical right button where no such button
exists. This is usually a bug in the firmware of the device and causes the
following warning to be emitted by libinput::
" clickpad advertising right button"
The user-visible effect of this is usually negligible since these devices
cannot actually trigger a right click and libinput's default behaviors for
clickpads work as expected.
However, we should nonetheless correct the device to get rid of this warning
and avoid potential issues with future features. The :ref:`device-quirks`
provide a simple way to disable the fake right button on the device. The
following quirk disables the right button on the MyModel laptop from the
MyVendor OEM::
[MyVendor MyModel Touchpad]
MatchName=Foo Bar Touchpad
MatchUdevtype=touchpad
MatchDMIModAlias=dmi:*svnMyVendor:pnMyModel:*
AttrEventCode=-BTN_RIGHT
The name of the device can be obtained using :ref:`libinput record `,
the modalias match is a shell-style glob against the value of ``/sys/class/dmi/id/modalias``.
In most cases, matching should be against ``svn`` (system vendor) and one of
``pn`` (product name) or ``pvr`` (product version), whichever provides a
useful description of the individual laptop model. See the
:ref:`device-quirks` documentation for details on testing local quirks.
For reference, some example commits that add such a quirk are:
- `bf61ab9bb0694d0ac3d60a7f815779abfe4886e6 `__
- `74fac6d040ac62048882dfb6f73da567ace6a6f5 `__
- `89cd0f990e3bee9906754d6ca8484ed5aa392249 `__
libinput-1.28.1/doc/user/conf.py.in000066400000000000000000000134111477265155700171030ustar00rootroot00000000000000# -*- coding: utf-8 -*-
#
# Configuration file for the Sphinx documentation builder.
#
# This file does only contain a selection of the most common options. For a
# full list see the documentation:
# http://www.sphinx-doc.org/en/stable/config
# -- Path setup --------------------------------------------------------------
# If extensions (or modules to document with autodoc) are in another directory,
# add these directories to sys.path here. If the directory is relative to the
# documentation root, use os.path.abspath to make it absolute, like shown here.
#
# sys.path.insert(0, os.path.abspath('.'))
import sys
import os
sys.path.insert(0, os.path.abspath('@BUILDDIR@'))
# -- Project information -----------------------------------------------------
project = '@PROJECT_NAME@'
copyright = '2019, the libinput authors'
author = 'the libinput authors'
# The short X.Y version
version = '@PROJECT_VERSION@'
# The full version, including alpha/beta/rc tags
release = '@PROJECT_VERSION@'
# -- General configuration ---------------------------------------------------
# If your documentation needs a minimal Sphinx version, state it here.
#
# needs_sphinx = '1.0'
# Add any Sphinx extension module names here, as strings. They can be
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
# ones.
extensions = [
'sphinx.ext.mathjax',
'sphinx.ext.graphviz',
'sphinx.ext.extlinks',
]
# Add any paths that contain templates here, relative to this directory.
templates_path = ['_templates']
# The suffix(es) of source filenames.
# You can specify multiple suffix as a list of string:
#
# source_suffix = ['.rst', '.md']
source_suffix = '.rst'
# The master toctree document.
master_doc = 'index'
# The language for content autogenerated by Sphinx. Refer to documentation
# for a list of supported languages.
#
# This is also used if you do content translation via gettext catalogs.
# Usually you set "language" from the command line for these cases.
language = 'en'
# List of patterns, relative to source directory, that match files and
# directories to ignore when looking for source files.
# This pattern also affects html_static_path and html_extra_path .
exclude_patterns = []
# The name of the Pygments (syntax highlighting) style to use.
pygments_style = 'sphinx'
highlight_language = 'none'
# -- Options for HTML output -------------------------------------------------
# The theme to use for HTML and HTML Help pages. See the documentation for
# a list of builtin themes.
#
html_theme = 'sphinx_rtd_theme'
# Theme options are theme-specific and customize the look and feel of a theme
# further. For a list of options available for each theme, see the
# documentation.
#
html_theme_options = {
'collapse_navigation': False,
'navigation_depth': 3,
}
# Add any paths that contain custom static files (such as style sheets) here,
# relative to this directory. They are copied after the builtin static files,
# so a file named "default.css" will overwrite the builtin "default.css".
# html_static_path = ['_static']
# Custom sidebar templates, must be a dictionary that maps document names
# to template names.
#
# The default sidebars (for documents that don't match any pattern) are
# defined by theme itself. Builtin themes are using these templates by
# default: ``['localtoc.html', 'relations.html', 'sourcelink.html',
# 'searchbox.html']``.
#
# html_sidebars = {}
# -- Options for HTMLHelp output ---------------------------------------------
# Output file base name for HTML help builder.
htmlhelp_basename = '@PROJECT_NAME@doc'
# -- Options for LaTeX output ------------------------------------------------
latex_elements = {
# The paper size ('letterpaper' or 'a4paper').
#
# 'papersize': 'letterpaper',
# The font size ('10pt', '11pt' or '12pt').
#
# 'pointsize': '10pt',
# Additional stuff for the LaTeX preamble.
#
# 'preamble': '',
# Latex figure (float) alignment
#
# 'figure_align': 'htbp',
}
# Grouping the document tree into LaTeX files. List of tuples
# (source start file, target name, title,
# author, documentclass [howto, manual, or own class]).
latex_documents = [
(master_doc, '@PROJECT_NAME@.tex', '@PROJECT_NAME@ Documentation',
'Peter Hutterer', 'manual'),
]
# -- Options for manual page output ------------------------------------------
# One entry per manual page. List of tuples
# (source start file, name, description, authors, manual section).
man_pages = [
(master_doc, '@PROJECT_NAME@', '@PROJECT_NAME@ Documentation',
[author], 1)
]
# -- Options for Texinfo output ----------------------------------------------
# Grouping the document tree into Texinfo files. List of tuples
# (source start file, target name, title, author,
# dir menu entry, description, category)
texinfo_documents = [
(master_doc, '@PROJECT_NAME@', '@PROJECT_NAME@ Documentation',
author, '@PROJECT_NAME@', 'One line description of project.',
'Miscellaneous'),
]
# -- Extension configuration -------------------------------------------------
from recommonmark.parser import CommonMarkParser
extlinks = { 'commit' :
('https://gitlab.freedesktop.org/libinput/libinput/commit/%s',
'git commit %s')
}
# -- git version hack -------------------------------------------------
#
# meson doesn't take configuration_data() for vcs_tag, so we cannot replace
# two substrings in the same file.
#
# sphinx cannot do ..include:: without linebreaks, so in-line replacements
# are a no-go.
#
# Work around this by generating a mini python module in meson through
# vcs_tag, then use that to generate the replacements in rst_prolog.
import git_version
rst_prolog = """
.. |git_version| replace:: :commit:`{}`
.. |git_version_full| replace:: :commit:`{}`
""".format(git_version.get_git_version(),
git_version.get_git_version_full)
libinput-1.28.1/doc/user/configuration.rst000066400000000000000000000240141477265155700206010ustar00rootroot00000000000000.. _config_options:
==============================================================================
Configuration options
==============================================================================
Below is a list of configurable options exposed to the users.
.. hint:: Not all configuration options are available on all devices. Use
:ref:`libinput list-devices ` to show the
configuration options for local devices.
libinput's configuration interface is available to the caller only, not
directly to the user. Thus is is the responsibility of the caller to expose
the various options and how these options are exposed. For example, the
xf86-input-libinput driver exposes the options through X Input device
properties and xorg.conf.d options. See the `libinput(4)
`_ man page for more details.
------------------------------------------------------------------------------
Tap-to-click
------------------------------------------------------------------------------
See :ref:`tapping` for details on how this feature works. Configuration
options exposed by libinput are:
- how many tapping fingers are supported by this device
- a toggle to enable/disable tapping
- a toggle to enable/disable tap-and-drag, see :ref:`tapndrag`.
- a toggle to enable/disable tap-and-drag drag lock, see :ref:`tapndrag`
- The default order is 1, 2, 3 finger tap mapping to left, right, middle
click, respectively. This order can be changed to left, middle, right click,
respectively.
Tapping is usually available on touchpads and the touchpad part of external
graphics tablets. Tapping is usually **not** available on touch screens,
for those devices it is expected to be implemented by the toolkit.
------------------------------------------------------------------------------
Three-finger drag
------------------------------------------------------------------------------
Three-finger drag allows emulates the mouse button down while three fingers
are down on a touchpad without the need to press a physical button or use
:ref:`tapndrag`. See :ref:`drag_3fg` for details on how this feature works.
Three-finger drag is usually available on touchpads and the touchpad part of
external graphics tablets. Three-finger drag is usually **not** available on
touch screens, for those devices it is expected to be implemented by the
toolkit.
------------------------------------------------------------------------------
Send Events Mode
------------------------------------------------------------------------------
The Send Events Mode is libinput's terminology for disabling a device. It is
more precise in that the device only stops sending events but may not get
fully disabled. For example, disabling the touchpad on a
:ref:`Lenovo T440 and similar ` leaves the top software
buttons enabled for the trackpoint. Available options are
**enabled** (send events normally), **disabled** ( do not send events),
**disabled on external mouse** (disable the device while an external mouse
is plugged in).
.. _config_pointer_acceleration:
------------------------------------------------------------------------------
Pointer acceleration
------------------------------------------------------------------------------
Pointer acceleration is a function to convert input deltas to output deltas,
usually based on the movement speed of the device, see
:ref:`pointer-acceleration` for details.
Pointer acceleration is normalized into a [-1, 1] range, where -1 is
"slowest" and 1 is "fastest". Most devices use a default speed of 0.
The pointer acceleration profile defines **how** the input deltas are
converted, see :ref:`ptraccel-profiles`. Most devices have their default
profile (usually called "adaptive") and a "flat" profile. The flat profile
does not apply any acceleration.
------------------------------------------------------------------------------
Scrolling
------------------------------------------------------------------------------
"Natural scrolling" is the terminology for moving the content in the
direction of scrolling, i.e. moving the wheel or fingers down moves the page
down. Traditional scrolling moves the content in the opposite direction.
Natural scrolling can be turned on or off, it is usually off by default.
The scroll method defines how to trigger scroll events. On touchpads
libinput provides two-finger scrolling and edge scrolling. Two-finger
scrolling converts a movement with two fingers to a series of scroll events.
Edge scrolling converts a movement with one finger along the right or bottom
edge of the touchpad into a series of scroll events.
On other libinput provides button-scrolling - movement of the device while
the designated scroll button is down is converted to scroll events. The
button used for scrolling is configurable.
The scroll method can be chosen or disabled altogether but most devices only
support a subset of available scroll methods. libinput's default is
two-finger scrolling for multi-touch touchpads, edge scrolling for
single-touch touchpads. On tracksticks, button scrolling is enabled by
default.
See :ref:`scrolling` for more details on how the scroll methods work.
------------------------------------------------------------------------------
Left-handed Mode
------------------------------------------------------------------------------
Left-handed mode switches the device's functionality to be more
accommodating for left-handed users. On mice this usually means swapping the
left and right mouse button, on tablets this allows the tablet to be used
upside-down to present the pad buttons for the non-dominant right hand. Not
all devices have left-handed mode.
Left-handed mode can be enabled or disabled and is disabled by default.
------------------------------------------------------------------------------
Middle Button Emulation
------------------------------------------------------------------------------
Middle button emulation converts a simultaneous left and right button click
into a middle button. The emulation can be enabled or disabled. Middle
button emulation is usually enabled when the device does not provide a
middle button.
------------------------------------------------------------------------------
Click method
------------------------------------------------------------------------------
The click method defines how button events are triggered on a :ref:`clickpad
`. When set to button areas, the bottom area of the
touchpad is divided into a left, middle and right button area. When set to
clickfinger, the number of fingers on the touchpad decide the button type.
Clicking with 1, 2, 3 fingers triggers a left, right, or middle click,
respectively. The default click method is software button areas. Click
methods are usually only available on :ref:`clickpads
`.
------------------------------------------------------------------------------
Disable while typing
------------------------------------------------------------------------------
DWT is the most generic form of palm detection on touchpad. While the user
is typing on an internal keyboard the touchpad is disabled, the touchpad
is enabled again after a timeout. See :ref:`disable-while-typing` for more
info.
Disable-while-typing can be enabled or disabled, it is enabled by default on
most touchpads.
------------------------------------------------------------------------------
Disable while trackpointing
------------------------------------------------------------------------------
DWTP is a form of palm detecion for devices that have a trackpoint (like
Thinkpads). While the user is using the trackpoint, the touchpad is disabled,
being enabled again after a timeout. See :ref:`disable-while-trackpointing` for
more info.
Disable-while-trackpointing can be enabled or disabled, it is enabled by
default.
------------------------------------------------------------------------------
Calibration
------------------------------------------------------------------------------
Calibration is available for some direct-input devices (touch screens,
graphics tablets, etc.). The purpose of calibration is to ensure the input
lines up with the output and the configuration data is a transformation
matrix. It is thus not expected that the user sets this option. The desktop
environment should provide an interface for this.
------------------------------------------------------------------------------
Rotation
------------------------------------------------------------------------------
The device rotation applies a corrective angle to relative input events,
allowing the device to be used e.g. sideways or upside-down. For example, a
trackball may be used in a 90° rotated position for accessibility reasons -
such a rotated position allows triggering the buttons with the thumb or
the non-dominant hand.
Note that where a device rotation is higher than 160 but less than 200 degrees,
the direction of wheels is also inverted. For all other angles, the wheel
direction is left as-is.
.. _config-tablet-pressure-range:
------------------------------------------------------------------------------
Tablet tool pressure range
------------------------------------------------------------------------------
The pressure range on a :ref:`Tablet tool ` can be reduced
from the full available hardware range to a subset of that range. The effect
of this is that the tablet will not register pressure below the given
the given threshold is met, and will reach the maximum logical pressure
before the maximum hardware-supported pressure is reached.
See :ref:`tablet-pressure-range` for more info.
------------------------------------------------------------------------------
Area configuration
------------------------------------------------------------------------------
Area configuration is available for some indirect input devices such as
graphics tablets. This configuration allows reducing the active area of
such a device to a subset of the physically possible area.
An example use-case for this is to match the aspect ratio of the device to that
of the screen.
See :ref:`tablet-area` for more info.
libinput-1.28.1/doc/user/contributing.rst000066400000000000000000000426761477265155700204570ustar00rootroot00000000000000
.. _contributing:
==============================================================================
Contributing to libinput
==============================================================================
So you want to contribute to libinput? Great! We'd love to help you be a part
of our community. Here is some important information to help you.
.. contents::
:local:
------------------------------------------------------------------------------
Code of Conduct
------------------------------------------------------------------------------
As a freedesktop.org project, libinput follows the `freedesktop.org
Contributor Covenant `_.
Please conduct yourself in a respectful and civilised manner when
interacting with community members on mailing lists, IRC, or bug trackers.
The community represents the project as a whole, and abusive or bullying
behaviour is not tolerated by the project.
------------------------------------------------------------------------------
Contact
------------------------------------------------------------------------------
Questions can be asked on ``#wayland`` on oftc or on the
`wayland-devel@lists.freedesktop.org
`_ mailing
list.
For IRC, ping user ``whot`` (Peter Hutterer, the libinput maintainer) though
note that he lives on UTC+10 and thus the rest of the world is out of sync
by default ;)
For anything that appears to be device specific and/or related to a new
feature, just file `an issue in our issue tracker
`_. It's usually the
most efficient way to get answers.
------------------------------------------------------------------------------
What to work on?
------------------------------------------------------------------------------
If you don't already know what you want to improve or fix with libinput,
then a good way of finding something is to search for the ``help needed``
tag in our `issue tracker `_.
These are issues that have been triaged to some degree and deemed to be a
possible future feature to libinput.
.. note:: Some of these issue may require specific hardware to reproduce.
Another good place to help out with is the documentation. For anything you
find in these pages that isn't clear enough please feel free to reword it
and add what is missing.
------------------------------------------------------------------------------
Getting the code
------------------------------------------------------------------------------
The :ref:`building_libinput` have all the details but the short solution
will be:
::
$> git clone https://gitlab.freedesktop.org/libinput/libinput
$> cd libinput
$> meson setup --prefix=/usr builddir/
$> ninja -C builddir/
$> sudo ninja -C builddir/ install
You can omit the last step if you only want to test locally.
------------------------------------------------------------------------------
Working on the code
------------------------------------------------------------------------------
If you are planning to send patches, it's a good idea to set up
`pre-commit `_ with these commands::
$> pre-commit install
$> pre-commit install --hook-type pre-push
This will check a few things before you commit and/or push to your repos to
reduce the turnaround time for some common mistakes.
libinput has a roughly three-parts architecture:
- the front-end code which handles the ``libinput_some_function()`` API calls in ``libinput.c``
- the generic evdev interface handling which maps those API calls to the
backend calls (``evdev.c``).
- there are device-specific backends which do most of the actual work -
``evdev-mt-touchpad.c`` is the one for touchpads for example.
In general, things that only affect the internal workings of a device only
get implemented in the device-specific backend. You only need to touch the
API when you are adding configuration options. For more details, please read
the :ref:`architecture` document. There's also a `blog post describing the
building blocks
`_
that may help to understand how it all fits together.
Documentation is in ``/doc/api`` for the doxygen-generated API documentation.
These are extracted from the libinput source code directly. The
documentation you're reading right now is in ``/doc/user`` and generated with
sphinx. Simply running ``ninja -C builddir`` will rebuild it and the final
product ends up in ``builddir/Documentation``.
------------------------------------------------------------------------------
Testing the code
------------------------------------------------------------------------------
libinput provides a bunch of :ref:`tools` to debug any changes - without
having to install libinput.
The two most useful ones are :ref:`libinput debug-events
` and :ref:`libinput debug-gui `.
Both tools can be run from the build directory directly and are great for
quick test iterations::
$> sudo ./builddir/libinput-debug-events --verbose
$> sudo ./builddir/libinput-debug-gui --verbose
The former provides purely textual output and is useful for verifying event
streams from buttons, etc. The latter is particularly useful when you are
trying to debug pointer movement or placement. ``libinput debug-gui`` will
also visualize the raw data from the device so you can compare pointer
behavior with what comes from the kernel.
These tools create a new libinput context and will not affect your session's
behavior. Only once you've installed libinput and restarted your session
will your changes affect the X server/Wayland compositor.
Once everything seems to be correct, it's time to run the
:ref:`test-suite`::
$> sudo ./builddir/libinput-test-suite
This test suite can take test names etc. as arguments, have a look at
:ref:`test-suite` for more info. There are a bunch of other tests that are
run by the CI on merge requests, you can run those locally with ::
$> sudo ninja -C builddir check
So it always pays to run that before submitting. This will also run the code
through valgrind and pick up any memory leaks.
.. _contributing_submitting_code:
------------------------------------------------------------------------------
Submitting Code
------------------------------------------------------------------------------
Any patches should be sent via a Merge Request (see the `GitLab docs
`_)
in the `libinput GitLab instance hosted by freedesktop.org
`_.
.. note:: freedesktop.org's GitLab instance has restrictions to prevent Spam
and you cannot fork libinput until you have successfully
`applied for fork permissions `_.
Below are the steps required to submit a merge request. They do not
replace `learning git `__ but they should be
sufficient to make some of the more confusing steps obvious.
- `Register an account `_ in
the freedesktop.org GitLab instance and
`apply for fork permissions `_.
- `Fork libinput `_
into your username's namespace. Select public visibility.
- Get libinput's main repository. git will call this repository ``origin``. ::
git clone https://gitlab.freedesktop.org/libinput/libinput.git
- Add the forked git repository to your remotes (replace ``USERNAME``
with your username). git will call this repository ``gitlab``. ::
cd /path/to/libinput.git
git remote add gitlab git@gitlab.freedesktop.org:USERNAME/libinput.git
git fetch gitlab
- Create a new branch and commit your changes to that branch. ::
git switch -C mynewbranch
# edit files, make changes
git add file1 file2
git commit -s
# edit commit message in the editor
Replace ``mynewbranch`` (here and in the commands below) with a meaningful
name. See :ref:`contributing_commit_messages` for details on the commit
message format.
- Push your changes to your fork and submit a merge request ::
git push gitlab mynewbranch
This command will print the URL to file a merge request, you then only
have to click through. Alternatively you can go to:
https://gitlab.freedesktop.org/USERNAME/libinput/merge_requests
Select your branch name to merge and ``libinput/libinput`` ``main`` as target branch.
- Verify that the CI completes successfully by visiting the merge request
page. A successful pipeline shows only green ticks, failure is indicated
by a red cross or a yellow exclamation mark (see
the `GitLab Docs
`__). For
details about the failures, click on the failed jobs in the pipelines
and/or click the ``Expand`` button in the box for the test summaries.
A merge request without a successful pipeline may never be looked at by a
maintainer.
- If changes are requested by the maintainers, please **amend** the
commit(s) and **force-push** the updated branch. ::
# edits in file foo.c
git add foo.c
git commit --amend
git push -f gitlab mynewbranch
A force-push will re-trigger the CI and notify the merge request that new
changes are available.
If the branch contains more than one commit, please look at
`git interactive rebases
`__
to learn how to change multiple commits, or squash new changes into older
commits.
------------------------------------------------------------------------------
Commit History
------------------------------------------------------------------------------
libinput strives to have a
`linear, 'recipe' style history `_
This means that every commit should be small, digestible, stand-alone, and
functional. Rather than a purely chronological commit history like this: ::
doc: final docs for view transforms
fix tests when disabled, redo broken doc formatting
better transformed-view iteration (thanks Hannah!)
try to catch more cases in tests
tests: add new spline test
fix compilation on splines
doc: notes on reticulating splines
compositor: add spline reticulation for view transforms
We aim to have a clean history which only reflects the final state, broken up
into functional groupings: ::
compositor: add spline reticulation for view transforms
compositor: new iterator for view transforms
tests: add view-transform correctness tests
doc: fix Doxygen formatting for view transforms
This ensures that the final patch series only contains the final state,
without the changes and missteps taken along the development process.
The first line of a commit message should contain a prefix indicating
what part is affected by the patch followed by one sentence that
describes the change. For example: ::
touchpad: add software button behavior
fallback: disable button debouncing on device foo
If in doubt what prefix to use, look at other commits that change the
same file(s) as the patch being sent.
.. _contributing_commit_messages:
------------------------------------------------------------------------------
Commit Messages
------------------------------------------------------------------------------
When you re-send patches, revised or not, it would be very good to document the
changes compared to the previous revision in the commit message and/or the
merge request. If you have already received Reviewed-by or Acked-by tags, you
should evaluate whether they still apply and include them in the respective
commit messages. Otherwise the tags may be lost, reviewers miss the credit they
deserve, and the patches may cause redundant review effort.
If your commit solves a GitLab issue, add a ``Closes:`` tag followed by the
issue number at the end of your commit message. For example: ::
Closes: #974
If your commit fixes an issue introduced by another commit, use a ``Fixes`` tag
followed by the first 12 characters of the SHA-1 ID and the commit one line
summary at the end of your commit message. For example: ::
Fixes: 123456789012 ("The commit that caused the issue")
For further reading, please see
`'on commit messages' `_
as a general guideline on what commit messages should contain.
------------------------------------------------------------------------------
Coding Style
------------------------------------------------------------------------------
Please see the `CODING_STYLE.md
`_
document in the source tree.
------------------------------------------------------------------------------
Tracking patches and follow-ups
------------------------------------------------------------------------------
Once submitted to GitLab, your patches will be reviewed by the libinput
development team on GitLab. Review may be entirely positive and result in your
code landing instantly, in which case, great! You're done. However, we may ask
you to make some revisions: fixing some bugs we've noticed, working to a
slightly different design, or adding documentation and tests.
If you do get asked to revise the patches, please bear in mind the notes above.
You should use ``git rebase -i`` to make revisions, so that your patches
follow the clear linear split documented above. Following that split makes
it easier for reviewers to understand your work, and to verify that the code
you're submitting is correct.
A common request is to split single large patch into multiple patches. This can
happen, for example, if when adding a new feature you notice a bug in
libinput's core which you need to fix to progress. Separating these changes
into separate commits will allow us to verify and land the bugfix quickly,
pushing part of your work for the good of everyone, whilst revision and
discussion continues on the larger feature part. It also allows us to direct
you towards reviewers who best understand the different areas you are
working on.
When you have made any requested changes, please rebase the commits, verify
that they still individually look good, then force-push your new branch to
GitLab. This will update the merge request and notify everyone subscribed to
your merge request, so they can review it again.
There are also many GitLab CLI clients, if you prefer to avoid the web
interface. It may be difficult to follow review comments without using the
web interface though, so we do recommend using this to go through the review
process, even if you use other clients to track the list of available
patches.
------------------------------------------------------------------------------
Failed pipeline errors
------------------------------------------------------------------------------
After submitting your merge request to GitLab, you might receive an email
informing you that your pipeline failed.
Visit your merge request page and check the `pipeline mini graph
`_ to know which
step failed.
Follow the appropriate section to fix the errors.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Committed gitlab-ci.yml differs from generated gitlab-ci.yml. Please verify
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
When your merge request modifies the CI templates, you might see this error
mainly due two reasons: the wrong file was modified and/or
``ci-fairy generate-template`` wasn't run.
``.gitlab-ci.yaml`` is auto generated, changes should be made in:
- ``.gitlab-ci/ci.template``
- ``.gitlab-ci/config.yaml``
Once the changes are ready, run
`ci-fairy `_
to update ``.gitlab-ci.yaml``: ::
ci-fairy generate-template
Finally, force-push you changes. See :ref:`contributing_submitting_code` for
more details.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Build errors
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Usually, checking the CI log is enough to catch this errors. However, your merge
request is built using different configurations you might have not tested.
In order to fix this kind of problems, you can compile libinput using the same
flags used by the CI.
For example, if an error is found in the ``build-no-libwacom`` step, open the
log and search the build options: ::
[...]
+ rm -rf 'build dir'
+ meson 'build dir' -Dlibwacom=false
The Meson build system
[...]
Use the same flags to fix the issue and force-push you changes. See
:ref:`contributing_submitting_code` for more details.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Test errors
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
The test suite is run for your merge request to check for bugs, regressions and
memory leaks among other issues.
Open the CI error log and search for a message similar to: ::
:: Failure: ../test/test-touchpad.c:465: touchpad_2fg_scroll_slow_distance(synaptics-t440)
See :ref:`test-suite` to learn how to run the failing tests.
Once the tests are fixed, force-push you changes. See
:ref:`contributing_submitting_code` for more details.
libinput-1.28.1/doc/user/dependencies.rst000066400000000000000000000005741477265155700203650ustar00rootroot00000000000000.. warning:: The package lists are autogenerated from the `CI `_.
- Fedora: ::
dnf install @FEDORA_PACKAGES@
- Ubuntu: ::
apt install @UBUNTU_PACKAGES@
- Debian: ::
apt install @DEBIAN_PACKAGES@
- Arch: ::
pacman -S @ARCH_PACKAGES@
- Alpine: ::
apk add @ALPINE_PACKAGES@
libinput-1.28.1/doc/user/development.rst000066400000000000000000000031531477265155700202550ustar00rootroot00000000000000.. _development:
==============================================================================
Information for developers
==============================================================================
Below is a list of topics of interest to developers, divided into
information for those :ref:`using_libinput_as_library` in a Wayland compositor
or other project. The :ref:`hacking_on_libinput` section applies to developers working on
libinput itself.
.. note:: If you use or work on libinput you should get in touch with the
libinput developers on the wayland-devel@lists.freedesktop.org
mailing lists
.. _using_libinput_as_library:
------------------------------------------------------------------------------
Using libinput as library
------------------------------------------------------------------------------
See :ref:`building_against` for information on how to integrate libinput
with your project's build system.
.. note:: **libinput's API documentation is available here:**
http://wayland.freedesktop.org/libinput/doc/latest/api/
Topics below explain some behaviors of libinput.
.. toctree::
:maxdepth: 1
absolute-axes.rst
absolute-coordinate-ranges.rst
normalization-of-relative-motion.rst
seats.rst
timestamps.rst
wheel-api.rst
.. _hacking_on_libinput:
------------------------------------------------------------------------------
Hacking on libinput
------------------------------------------------------------------------------
.. toctree::
:maxdepth: 1
architecture
test-suite.rst
pointer-acceleration.rst
device-configuration-via-udev.rst
libinput-1.28.1/doc/user/device-configuration-via-udev.rst000066400000000000000000000240331477265155700235550ustar00rootroot00000000000000.. _udev_config:
==============================================================================
Static device configuration via udev
==============================================================================
libinput supports some static configuration through udev properties.
These properties are read when the device is initially added
to libinput's device list, i.e. before the
**LIBINPUT_EVENT_DEVICE_ADDED** event is generated.
The following udev properties are supported:
LIBINPUT_CALIBRATION_MATRIX
Sets the calibration matrix, see
**libinput_device_config_calibration_get_default_matrix()**. If unset,
defaults to the identity matrix.
The udev property is parsed as 6 floating point numbers separated by a
single space each (scanf(3) format ``"%f %f %f %f %f %f"``).
The 6 values represent the first two rows of the calibration matrix as
described in **libinput_device_config_calibration_set_matrix()**.
Example values are: ::
ENV{LIBINPUT_CALIBRATION_MATRIX}="1 0 0 0 1 0" # default
ENV{LIBINPUT_CALIBRATION_MATRIX}="0 -1 1 1 0 0" # 90 degree clockwise
ENV{LIBINPUT_CALIBRATION_MATRIX}="-1 0 1 0 -1 1" # 180 degree clockwise
ENV{LIBINPUT_CALIBRATION_MATRIX}="0 1 0 -1 0 1" # 270 degree clockwise
ENV{LIBINPUT_CALIBRATION_MATRIX}="-1 0 1 0 1 0" # reflect along y axis
LIBINPUT_DEVICE_GROUP
A string identifying the **libinput_device_group** for this device. Two
devices with the same property value are grouped into the same device group,
the value itself is irrelevant otherwise.
LIBINPUT_IGNORE_DEVICE
If set to anything other than "0", the device is ignored by libinput.
See :ref:`ignoring_devices` for more details.
ID_SEAT
Assigns the physical :ref:`seat ` for this device. See
**libinput_seat_get_physical_name()**. Defaults to "seat0".
ID_INPUT
If this property is set, the device is considered an input device. Any
device with this property missing will be ignored, see :ref:`udev_device_type`.
ID_INPUT_KEYBOARD, ID_INPUT_KEY, ID_INPUT_MOUSE, ID_INPUT_TOUCHPAD, ID_INPUT_TOUCHSCREEN, ID_INPUT_TABLET, ID_INPUT_JOYSTICK, ID_INPUT_ACCELEROMETER
If any of the above is set, libinput initializes the device as the given
type, see :ref:`udev_device_type`. Note that for historical reasons more than
one of these may be set at any time, libinput will select only one of these
to determine the device type. To ensure libinput selects the correct device
type, only set one of them.
WL_SEAT
Assigns the logical :ref:`seat ` for this device. See
**libinput_seat_get_logical_name()** context. Defaults to "default".
MOUSE_DPI
HW resolution and sampling frequency of a relative pointer device.
See :ref:`motion_normalization` for details.
MOUSE_WHEEL_CLICK_ANGLE
The angle in degrees for each click on a mouse wheel. See
**libinput_pointer_get_axis_source()** for details.
Below is an example udev rule to assign "seat1" to a device from vendor
``0x012a`` with the model ID of ``0x034b``. ::
$ cat /etc/udev/rules.d/99-my-device-is-on-seat1.rules
ACTION!="remove", KERNEL=="event[0-9]*", \
ENV{ID_VENDOR_ID}=="012a", \
ENV{ID_MODEL_ID}=="034b", \
ENV{ID_SEAT}="seat1"
.. _udev_device_type:
------------------------------------------------------------------------------
Device type assignment via udev
------------------------------------------------------------------------------
libinput requires the **ID_INPUT** property to be set on a device,
otherwise the device will be ignored. In addition, one of
**ID_INPUT_KEYBOARD, ID_INPUT_KEY, ID_INPUT_MOUSE, ID_INPUT_TOUCHPAD,
ID_INPUT_TOUCHSCREEN, ID_INPUT_TABLET, ID_INPUT_JOYSTICK,
ID_INPUT_ACCELEROMETER** must be set on the device to determine the
device type. The usual error handling applies within libinput and a device
type label does not guarantee that the device is initialized by libinput.
If a device fails to meet the requirements for a device type (e.g. a keyboard
labelled as touchpad) the device will not be available through libinput.
Only one device type should be set per device at a type, though libinput can
handle some combinations for historical reasons.
Below is an example udev rule to remove an **ID_INPUT_TOUCHPAD** setting
and change it into an **ID_INPUT_TABLET** setting. This rule would apply
for a device with the vendor/model ID of ``012a``/``034b``. ::
$ cat /etc/udev/rules.d/99-my-device-is-a-tablet.rules
ACTION!="remove", KERNEL=="event[0-9]*", \
ENV{ID_VENDOR_ID}=="012a", \
ENV{ID_MODEL_ID}=="034b", \
ENV{ID_INPUT_TOUCHPAD}="", ENV{ID_INPUT_TABLET}="1"
.. _model_specific_configuration:
------------------------------------------------------------------------------
Model-specific configuration
------------------------------------------------------------------------------
As of libinput 1.12, model-specific configuration is stored in the
:ref:`device-quirks` and not in the hwdb anymore. Please see
:ref:`device-quirks` for
details.
.. _model_specific_configuration_x220fw81:
..............................................................................
Lenovo x220 with touchpad firmware v8.1
..............................................................................
The property **LIBINPUT_MODEL_LENOVO_X220_TOUCHPAD_FW81** may be set by a
user in a local hwdb file. This property designates the touchpad on a Lenovo
x220 with a touchpad firmware version 8.1. When this firmware version is
installed, the touchpad is imprecise. The touchpad device does not send
continuous x/y axis position updates, a behavior also observed on its
successor model, the Lenovo x230 which has the same firmware version. If the
above property is set, libinput adjusts its behavior to better suit this
particular model.
The touchpad firmware version cannot be detected automatically by libinput,
local configuration is required to set this property. Refer to the libinput
model quirks hwdb for instructions.
This property must not be used for any other purpose, no specific behavior
is guaranteed.
.. _hwdb:
------------------------------------------------------------------------------
Configuring the hwdb
------------------------------------------------------------------------------
This section outlines how to query the
`udev hwdb `_
and reload properties so they are available to libinput.
The hwdb contains a set of match rules that assign udev properties that are
available to libinput when the device is connected and/or libinput is
initialized. This section only describes the hwdb in relation to libinput,
it is not a full documentation on how the hwdb works.
libinput's use of the hwdb is limited to properties systemd and custom
rules files (where available) provide. Hardware-specific quirks as used by
libinput are in the :ref:`device-quirks` system.
.. _hwdb_querying:
..............................................................................
Querying the hwdb
..............................................................................
libinput only uses device nodes in the form of ``/dev/input/eventX`` where X
is the number of the specific device. Running ``libinput debug-events`` lists
all devices currently available to libinput and their event node name: ::
$> sudo libinput debug-events
-event2 DEVICE_ADDED Power Button seat0 default group1 cap:k
-event5 DEVICE_ADDED Video Bus seat0 default group2 cap:k
-event0 DEVICE_ADDED Lid Switch seat0 default group3 cap:S
...
Note the event node name for your device and translate it into a syspath in
the form of ``/sys/class/input/eventX``. This path can be supplied to ``udevadm
info`` ::
$> udevadm info
P: /devices/LNXSYSTM:00/LNXSYBUS:00/PNP0C0D:00/input/input0/event0
N: input/event0
E: DEVNAME=/dev/input/event0
E: DEVPATH=/devices/LNXSYSTM:00/LNXSYBUS:00/PNP0C0D:00/input/input0/event0
E: ID_INPUT=1
E: ID_INPUT_SWITCH=1
E: MAJOR=13
E: MINOR=64
E: SUBSYSTEM=input
E: TAGS=:power-switch:
E: USEC_INITIALIZED=7167898
Lines starting with ``E:`` are udev properties available to libinput. For
example, the above device's ``ID_INPUT_SWITCH`` property will cause libinput
to treat this device as switch device.
.. _hwdb_reloading:
..............................................................................
Reloading the hwdb
..............................................................................
The actual hwdb is stored in binary file on-disk and must be updated
manually whenever a ``.hwdb`` file changes. This is required both when a user
manually edits the ``.hwdb`` file but also when the git tree is updated (and
that update causes a hwdb change).
To update the binary file on-disk, run: ::
sudo systemd-hwdb update
Then, to trigger a reload of all properties on your device, run: ::
sudo udevadm trigger /sys/class/input/eventX
Then check with ``udevadm info`` whether the properties were updated, see
:ref:`hwdb_querying`. If a new property does not appear on the device, use ``udevadm
test`` to check for error messages by udev and the hwdb (e.g. syntax errors
in the udev rules files). ::
sudo udevadm test /sys/class/input/eventX
.. warning:: ``udevadm test`` does not run commands specified in ``RUN``
directives. This affects the udev properties relying on e.g.
the udev keyboard builtin such as the :ref:`touchpad_jitter`
workarounds.
.. _hwdb_modifying:
..............................................................................
Modifying the hwdb
..............................................................................
.. warning:: This section has been removed as it no longer applies in libinput 1.12
and later. libinput users should not need to modify the hwdb, any
device-specific quirks must go in to the :ref:`device-quirks` system.
For information about older libinput versions, please see the documentation
for your version available in: https://wayland.freedesktop.org/libinput/doc/
libinput-1.28.1/doc/user/device-quirks.rst000066400000000000000000000273521477265155700205150ustar00rootroot00000000000000.. _device-quirks:
==============================================================================
Device quirks
==============================================================================
libinput requires extra information from devices that is not always readily
available. For example, some touchpads are known to have jumping cursors
under specific conditions. libinput ships a set of files containing the
so-called model quirks to provide that information. Model quirks are usually
installed under ``/usr/share/libinput/.quirks`` and are standard
``.ini`` files. A file may contain multiple section headers (``[some
identifier]``) followed by one or more :ref:`MatchFoo=Bar `
directives, followed by at least one of ``ModelFoo=1`` or ``AttrFoo=bar`` directive.
See the ``quirks/README.md`` file in the libinput source repository for more
details on their contents.
.. warning:: Model quirks are internal API and may change at any time. No
backwards-compatibility is guaranteed.
For example, a quirks file may have this content to label all keyboards on
the serial bus (PS/2) as internal keyboards: ::
[Serial Keyboards]
MatchUdevType=keyboard
MatchBus=serial
AttrKeyboardIntegration=internal
The model quirks are part of the source distribution and should never be
modified locally. Updates to libinput may overwrite modifications or even
stop parsing any property. For temporary local workarounds, see
:ref:`device-quirks-local`.
Device quirks are parsed on libinput initialization. A parsing error in the
device quirks disables **all** device quirks and may negatively impact
device behavior on the host. If the quirks cannot be loaded, an error
message is posted to the log and users should use the information in
:ref:`device-quirks-debugging` to verify their quirks files.
.. _device-quirks-local:
------------------------------------------------------------------------------
Installing temporary local device quirks
------------------------------------------------------------------------------
The model quirks are part of the source distribution and should never be
modified. For temporary local workarounds, libinput reads the
``/etc/libinput/local-overrides.quirks`` file. Users may add a sections to
this file to add a device quirk for a local device but beware that **any
modification must be upstreamed** or it may cease to work at any time.
.. warning:: Model quirks are internal API and may change at any time. No
backwards-compatibility is guaranteed. Local overrides should only
be used until the distribution updates the libinput packages.
The ``local-overrides.quirks`` file usually needs to be created by the user.
Once the required section has been added, use the information from section
:ref:`device-quirks-debugging` to validate and test the quirks.
.. _device-quirks-debugging:
------------------------------------------------------------------------------
Debugging device quirks
------------------------------------------------------------------------------
libinput provides the ``libinput quirks`` tool to debug the quirks database.
This tool takes an action as first argument, the most common invocation is
``libinput quirks list`` to list model quirks that apply to one or more local
devices. ::
$ libinput quirks list /dev/input/event19
$ libinput quirks list /dev/input/event0
AttrLidSwitchReliability=unreliable
The device `event19` does not have any quirks assigned.
When called with the ``--verbose`` argument, ``libinput quirks list`` prints
information about all files and its attempts to match the device: ::
$ libinput quirks list --verbose /dev/input/event0
quirks debug: /usr/share/share/libinput is data root
quirks debug: /usr/share/share/libinput/10-generic-keyboard.quirks
quirks debug: /usr/share/share/libinput/10-generic-lid.quirks
[...]
quirks debug: /usr/share/etc/libinput/local-overrides.quirks
quirks debug: /dev/input/event0: fetching quirks
quirks debug: [Serial Keyboards] (10-generic-keyboard.quirks) wants MatchBus but we don't have that
quirks debug: [Lid Switch Ct9] (10-generic-lid.quirks) matches for MatchName
quirks debug: [Lid Switch Ct10] (10-generic-lid.quirks) matches for MatchName
quirks debug: [Lid Switch Ct10] (10-generic-lid.quirks) matches for MatchDMIModalias
quirks debug: [Lid Switch Ct10] (10-generic-lid.quirks) is full match
quirks debug: property added: AttrLidSwitchReliability from [Lid Switch Ct10] (10-generic-lid.quirks)
quirks debug: [Aiptek No Tilt Tablet] (30-vendor-aiptek.quirks) wants MatchBus but we don't have that
[...]
quirks debug: [HUION PenTablet] (30-vendor-huion.quirks) wants MatchBus but we don't have that
quirks debug: [Logitech Marble Mouse Trackball] (30-vendor-logitech.quirks) wants MatchBus but we don't have that
quirks debug: [Logitech K400] (30-vendor-logitech.quirks) wants MatchBus but we don't have that
quirks debug: [Logitech K400r] (30-vendor-logitech.quirks) wants MatchBus but we don't have that
quirks debug: [Logitech K830] (30-vendor-logitech.quirks) wants MatchBus but we don't have that
quirks debug: [Logitech K400Plus] (30-vendor-logitech.quirks) wants MatchBus but we don't have that
quirks debug: [Logitech Wireless Touchpad] (30-vendor-logitech.quirks) wants MatchBus but we don't have that
quirks debug: [Microsoft Surface 3 Lid Switch] (30-vendor-microsoft.quirks) matches for MatchName
[...]
AttrLidSwitchReliability
Note that this is an example only, the output may change over time. The tool
uses the same parser as libinput and any parsing errors will show up in the
output.
.. _device-quirks-list:
------------------------------------------------------------------------------
List of currently available device quirks
------------------------------------------------------------------------------
This list is a guide for developers to ease the process of submitting
patches upstream. This section shows device quirks currently available in
|git_version|.
.. warning:: Quirks are internal API and may change at any time for any reason.
No guarantee is given that any quirk below works on your version of
libinput.
In the documentation below, the letters N, M, O, P refer to arbitrary integer
values.
Quirks starting with **Model*** triggers implementation-defined behaviour
for this device not needed for any other device. Only the more
general-purpose **Model*** flags are listed here.
ModelALPSTouchpad, ModelAppleTouchpad, ModelWacomTouchpad, ModelChromebook
Reserved for touchpads made by the respective vendors
ModelTouchpadVisibleMarker
Indicates the touchpad has a drawn-on visible marker between the software
buttons.
ModelTabletModeNoSuspend
Indicates that the device does not need to be
suspended in :ref:`switches_tablet_mode`.
ModelTabletModeSwitchUnreliable
Indicates that this tablet mode switch's state cannot be relied upon.
ModelTrackball
Reserved for trackballs
ModelBouncingKeys
Indicates that the device may send fake bouncing key events and
timestamps can not be relied upon.
ModelSynapticsSerialTouchpad
Reserved for touchpads made by Synaptics on the serial bus
ModelPressurePad
Unlike in traditional touchpads, whose pressure value equals contact size,
on pressure pads pressure is a real physical axis.
Indicates that the device is a pressure pad.
ModelTouchpadPhantomClicks
Some laptops are prone to registering touchpad clicks when the case is
bent. Indicates that clicks should be ignored if no fingers are on the
touchpad.
AttrSizeHint=NxM, AttrResolutionHint=N
Hints at the width x height of the device in mm, or the resolution
of the x/y axis in units/mm. These may only be used where they apply to
a large proportion of matching devices. They should not be used for any
specific device, override ``EVDEV_ABS_*`` instead, see
:ref:`absolute_coordinate_ranges_fix`.
AttrTouchSizeRange=N:M, AttrPalmSizeThreshold=O
Specifies the touch size required to trigger a press (N) and to trigger
a release (M). O > N > M. See :ref:`touchpad_touch_size_hwdb` for more
details.
An AttrPalmSizeThreshold of zero unsets any threshold that has been
inherited from another quirk.
AttrPressureRange=N:M, AttrPalmPressureThreshold=O, AttrThumbPressureThreshold=P
Specifies the touch pressure required to trigger a press (N) and to
trigger a release (M), when a palm touch is triggered (O) and when a
thumb touch is triggered (P). O > P > N > M. See
:ref:`touchpad_pressure_hwdb` for more details.
An AttrPalmPressureThreshold of zero unsets any threshold that has been
inherited from another quirk.
AttrLidSwitchReliability=reliable|unreliable|write_open
Indicates the reliability of the lid switch. This is a string enum.
Very few devices need this, if in doubt do not set. See :ref:`switches_lid`
for details. libinput 1.21.0 changed the default from unreliable to
reliable, which may be removed from local overrides.
AttrKeyboardIntegration=internal|external
Indicates the integration of the keyboard. This is a string enum.
Generally only needed for USB keyboards.
AttrTPKComboLayout=below
Indicates the position of the touchpad on an external touchpad+keyboard
combination device. This is a string enum. Don't specify it unless the
touchpad is below.
AttrEventCode=+EV_ABS;-BTN_STYLUS;+EV_KEY:0x123;
Enables or disables the evdev event type/code tuples on the device. The prefix
for each entry is either '+' (enable) or '-' (disable). Entries may be
a named event type, or a named event code, or a named event type with a
hexadecimal event code, separated by a single colon.
AttrInputProp=+INPUT_PROP_BUTTONPAD;-INPUT_PROP_POINTER;
Enables or disables the evdev input property on the device. The prefix
for each entry is either '+' (enable) or '-' (disable). Entries may be
a named input property or the hexadecimal value of that property.
AttrPointingStickIntegration=internal|external
Indicates the integration of the pointing stick. This is a string enum.
Only needed for external pointing sticks. These are rare.
AttrTabletSmoothing=1|0
Enables (1) or disables (0) input smoothing for tablet devices. Smoothing is enabled
by default, except on AES devices.
.. _device-quirks-matches:
------------------------------------------------------------------------------
List of currently available matches
------------------------------------------------------------------------------
``Match*`` statements are how quirks are assigned to a device. Quirks with multiple
match statements must match all of those to apply.
.. warning:: Quirks are internal API and may change at any time for any reason.
No guarantee is given that any ``Match`` statement below works on
your version of libinput.
MatchName, MatchUniq
Match on the ``NAME`` or ``UNIQ`` udev property on this device. These properties
are typically derived from the device's kernel name or uniq but may be overridden
by a udev rule. These matches use ``fnmatch()`` globs.
MatchBus
A lower-case bus name. Currently supported are ``usb``, ``bluetooth``, ``ps2``,
``rmi``, ``i2c``, and ``spi``.
MatchVendor, MatchProduct, MatchVersion
The hexadecmial 4-digit vendor ID, product ID or driver version as exported, without
a ``0x`` prefix.
MatchDMIModalias, MatchDeviceTree
An ``fnmatch()`` glob for the DMI modalias or the DeviceTree ``compatible`` string.
See ``/sys/class/dmi/id/modalias`` and ``/sys/firmware/devicetree/base/compatible``.
MatchUdevType
One of ``touchpad``, ``mouse``, ``pointingstick``, ``keyboard``, ``joystick``,
``tablet``, ``tablet-pad``. Matches the corresponding ``ID_INPUT_*`` udev
property.
libinput-1.28.1/doc/user/dot/000077500000000000000000000000001477265155700157655ustar00rootroot00000000000000libinput-1.28.1/doc/user/dot/evemu.gv000066400000000000000000000003511477265155700174430ustar00rootroot00000000000000digraph stack
{
compound=true;
rankdir="LR";
node [
shape="box";
]
kernel [label="Kernel"];
libinput;
xserver [label="X Server"];
kernel -> libinput
libinput -> xserver
kernel -> evemu
evemu -> stdout
}
libinput-1.28.1/doc/user/dot/libinput-record.gv000066400000000000000000000004201477265155700214210ustar00rootroot00000000000000digraph stack
{
compound=true;
rankdir="LR";
node [
shape="box";
]
kernel [label="Kernel"];
libinput;
xserver [label="X Server"];
record [label="libinput record"];
kernel -> libinput
libinput -> xserver
kernel -> record;
record -> stdout
}
libinput-1.28.1/doc/user/dot/libinput-stack-gnome.gv000066400000000000000000000006521477265155700223620ustar00rootroot00000000000000digraph stack
{
compound=true;
rankdir="LR";
node [
shape="box";
]
gcc -> gsettings
xf86libinput -> libinput
subgraph cluster0 {
label="X.Org";
xf86libinput [label="xf86-input-libinput"];
xserver [label="X Server"];
xserver -> xf86libinput;
}
gcc [label="gnome-control-center"];
subgraph cluster3 {
gsettings
}
gsd [label="mutter"];
gsd -> gsettings
gsd -> xserver
}
libinput-1.28.1/doc/user/dot/libinput-stack-wayland.gv000066400000000000000000000006461477265155700227170ustar00rootroot00000000000000digraph stack
{
compound=true;
rankdir="LR";
node [
shape="box";
]
subgraph cluster_2 {
label="Kernel";
event0 [label="/dev/input/event0"]
event1 [label="/dev/input/event1"]
}
subgraph cluster_0 {
label="Compositor process";
libinput;
}
client [label="Wayland client"];
event0 -> libinput;
event1 -> libinput;
libinput -> client [ltail=cluster_0 label="Wayland protocol"];
}
libinput-1.28.1/doc/user/dot/libinput-stack-xorg.gv000066400000000000000000000007441477265155700222360ustar00rootroot00000000000000digraph stack
{
compound=true;
rankdir="LR";
node [
shape="box";
]
subgraph cluster_2 {
label="Kernel";
event0 [label="/dev/input/event0"]
event1 [label="/dev/input/event1"]
}
subgraph cluster_0 {
label="X server process";
subgraph cluster_1 {
label="xf86-input-libinput"
libinput;
}
}
libinput;
client [label="X11 client"];
event0 -> libinput;
event1 -> libinput;
libinput -> client [ltail=cluster_0 label="X protocol"];
}
libinput-1.28.1/doc/user/dot/seats-sketch-libinput.gv000066400000000000000000000010711477265155700225440ustar00rootroot00000000000000digraph seats_libinput
{
rankdir="BT";
node [
shape="box";
]
ctx1 [label="libinput context 1"; URL="\ref libinput"];
ctx2 [label="libinput context 2"; URL="\ref libinput"];
seat0 [ label="seat phys 0 logical A"];
seat1 [ label="seat phys 0 logical B"];
seat2 [ label="seat phys 1 logical C"];
dev1 [label="device 'Foo'"];
dev2 [label="device 'Bar'"];
dev3 [label="device 'Spam'"];
dev4 [label="device 'Egg'"];
ctx1 -> dev1
ctx1 -> dev2
ctx1 -> dev3
ctx2 -> dev4
dev1 -> seat0
dev2 -> seat0
dev3 -> seat1
dev4 -> seat2
}
libinput-1.28.1/doc/user/dot/seats-sketch.gv000066400000000000000000000022401477265155700207170ustar00rootroot00000000000000digraph seats
{
rankdir="BT";
node [
shape="box";
]
kernel [label="Kernel"];
event0 [URL="\ref libinput_event"];
event1 [URL="\ref libinput_event"];
event2 [URL="\ref libinput_event"];
event3 [URL="\ref libinput_event"];
pseat0 [label="phys seat0"; URL="\ref libinput_seat_get_physical_name"];
pseat1 [label="phys seat1"; URL="\ref libinput_seat_get_physical_name"];
lseatA [label="logical seat A"; URL="\ref libinput_seat_get_logical_name"];
lseatB [label="logical seat B"; URL="\ref libinput_seat_get_logical_name"];
lseatC [label="logical seat C"; URL="\ref libinput_seat_get_logical_name"];
ctx1 [label="libinput context 1"; URL="\ref libinput"];
ctx2 [label="libinput context 2"; URL="\ref libinput"];
dev1 [label="device 'Foo'"];
dev2 [label="device 'Bar'"];
dev3 [label="device 'Spam'"];
dev4 [label="device 'Egg'"];
kernel -> event0
kernel -> event1
kernel -> event2
kernel -> event3
event0 -> pseat0
event1 -> pseat0
event2 -> pseat0
event3 -> pseat1
pseat0 -> ctx1
pseat1 -> ctx2
ctx1 -> lseatA
ctx1 -> lseatB
ctx2 -> lseatC
lseatA -> dev1
lseatA -> dev2
lseatB -> dev3
lseatC -> dev4
}
libinput-1.28.1/doc/user/drag-3fg.rst000066400000000000000000000036361477265155700173330ustar00rootroot00000000000000.. _drag_3fg:
==============================================================================
Three-finger drag
==============================================================================
Three-finger drag is a feature available on touchpads that emulates logical
button presses if three fingers are moving on the touchpad.
Three-finger drag is independent from :ref:`tapping` though some specific
behaviors may change when both features are enabled. For example, with
tapping *disabled* a three-finger gesture will virtually always be a three-finger
drag. With tapping *enabled* a three finger gesture may be a three finger drag
and a short delay is required to disambiguate between the two.
The exact behavior of three-finger drag is implementation defined and may
subtly change. As a general rule, the following constraints can be expected:
- three fingers down and movement trigger a button down and subsequent motion
events (i.e. a drag)
- releasing one finger while keeping two fingers down will keep the drag
and *not* switch to :ref:`twofinger_scrolling`.
- releasing two fingers while keeping one finger down will end the drag
(and thus release the button) and switch to normal pointer motion
- releasing all three fingers and putting three fingers back on the touchpad
immediately will keep the drag (i.e. behave as if the fingers were
never lifted)
- if tapping is enabled: a three finger tap immediately after a three-finger
drag will *not* tap, the user needs to wait past the timeout to
three-finger tap
- releasing all three fingers and putting one or two fingers back on
the touchpad will end the drag (and thus release the button)
and proceed with pointer motion or two-finger scrolling, if applicable
- if tapping is enabled: a one or two finger tap immediately after a
three-finger drag will trigger a one or two finger tap. The user does
not have to wait past the drag release timeout
libinput-1.28.1/doc/user/faqs.rst000066400000000000000000000405701477265155700166710ustar00rootroot00000000000000.. _faq:
==============================================================================
FAQs - Frequently Asked Questions
==============================================================================
Frequently asked questions about libinput.
.. contents::
:local:
:backlinks: entry
.. _faq_feature:
------------------------------------------------------------------------------
Why doesn't libinput support ...?
------------------------------------------------------------------------------
First, read :ref:`what_is_libinput` If you have a feature that you think
libinput needs to support, please file a bug report. See :ref:`reporting_bugs`
for more details.
.. _faq_fast_mouse:
------------------------------------------------------------------------------
My mouse moves too fast, even at the slowest setting
------------------------------------------------------------------------------
This is a symptom of high-dpi mice (greater than 1000dpi). These devices
need a udev hwdb entry to normalize their motion. See
:ref:`motion_normalization` for a detailed explanation.
.. _faq_fast_trackpoint:
------------------------------------------------------------------------------
My trackpoint moves too slow or too fast
------------------------------------------------------------------------------
This is a symptom of an invalid trackpoint multiplier. These devices need
:ref:`device-quirks` to specify the range available so libinput can adjust the
pointer acceleration accordingly. See :ref:`trackpoint_range` for a detailed
explanation.
.. _faq_pointer_acceleration:
------------------------------------------------------------------------------
Why is libinput's pointer acceleration worse than synaptics/evdev
------------------------------------------------------------------------------
This is a known problem affecting some devices and/or use-case but the exact
cause is still unknown. It may be a device-specific issue, it may be a bug
in libinput's acceleration code, it may be a disagreement about how pointer
acceleration should feel. Unfortunately this is something that affected
users need to investigate and analyze.
.. _faq_enable_tapping:
------------------------------------------------------------------------------
Why isn't touchpad tap-to-click enabled by default
------------------------------------------------------------------------------
See :ref:`tapping_default`
.. _faq_touchpad_pressure:
------------------------------------------------------------------------------
Why does my touchpad lose track of touches
------------------------------------------------------------------------------
The most common cause for this is an incorrect pressure threshold range.
See :ref:`touchpad_pressure` for more info.
.. _faq_kinetic_scrolling:
------------------------------------------------------------------------------
Kinetic scrolling does not work
------------------------------------------------------------------------------
The X.Org synaptics driver implemented kinetic scrolling in the driver. It
measures the scroll speed and once the finger leaves the touchpad the driver
keeps sending scroll events for a predetermined time. This effectively
provides for kinetic scrolling without client support but triggers an
unfixable `bug `_: the
client cannot know that the events are from a kinetic scroll source. Scroll
events in X are always sent to the current cursor position, a movement of the
cursor after lifting the finger will send the kinetic scroll events to the
new client, something the user does not usually expect. A key event during
the kinetic scroll procedure causes side-effects such as triggering zoom.
libinput does not implement kinetic scrolling for touchpads. Instead it
provides the **libinput_event_pointer_get_axis_source()** function that enables
callers to implement kinetic scrolling on a per-widget basis, see
:ref:`scroll_sources`.
.. _faq_gpl:
------------------------------------------------------------------------------
Is libinput GPL-licensed?
------------------------------------------------------------------------------
No, libinput is MIT licensed. The Linux kernel header file linux/input.h in
libinput's tree is provided to ensure the same behavior regardless of which
kernel version libinput is built on. It does not make libinput GPL-licensed.
.. _faq_config_options:
------------------------------------------------------------------------------
Where is the configuration stored?
------------------------------------------------------------------------------
libinput does not store configuration options, it is up to the caller to
manage these and decide which configuration option to apply to each device.
This must be done at startup, after a resume and whenever a new device is
detected.
One commonly used way to configure libinput is to have the Wayland
compositor expose a compositor-specific configuration option. For example,
in a GNOME stack, the gnome-control-center modifies dconf entries. These
changes are read by mutter and applied to libinput. Changing these entries
via the gsettings commandline tool has the same effect.
Another commonly used way to configure libinput is to have xorg.conf.d
snippets. When libinput is used with the xf86-input-libinput driver in an
X.Org stack, these options are read on startup and apply to each device.
Changing properties at runtime with the xinput commandline tool has the same
effect.
In both cases, the selection of available options and how they are exposed
depends on the libinput caller (e.g. mutter or xf86-input-libinput).
.. graphviz:: libinput-stack-gnome.gv
This has an effect on the availability of configuration options: if an
option is not exposed by the intermediary, it cannot be configured by the
client. Also some configuration options that are provided by the
intermediary may not be libinput-specific configuration options.
.. _faq_configure_wayland:
------------------------------------------------------------------------------
How do I configure my device on Wayland?
------------------------------------------------------------------------------
See :ref:`faq_config_options` Use the configuration tool provided by your
desktop environment (e.g. gnome-control-center) or direct access to your
desktop environment's configuration storage (e.g. gsettings).
.. _faq_configure_xorg:
------------------------------------------------------------------------------
How do I configure my device on X?
------------------------------------------------------------------------------
See :ref:`faq_config_options` If your desktop environment does not provide a
graphical configuration tool you can use an
`xorg.conf.d snippet `_.
Usually, such a snippet looks like this:
::
$> cat /etc/X11/xorg.conf.d/99-libinput-custom-config.conf
Section "InputClass"
Identifier "something to identify this snippet"
MatchDriver "libinput"
MatchProduct "substring of the device name"
Option "some option name" "the option value"
EndSection
The identifier is merely a human-readable string that shows up in the log
file. The MatchProduct line should contain the device name or a substring of
the device name that the snippet should apply to. For a full list of option
names and permitted values, see the
`libinput man page `_.
xorg.conf.d snippets like the above apply to hotplugged devices but can be
overwritten at runtime by desktop tools. Multiple snippets may be placed
into the same file.
For run-time configuration and testing, the
`xinput `_
debugging tool can modify a devices' properties. See the
`libinput man page `_
for supported property names and values. Usually, an invocation looks like
this:
::
$> xinput set-prop "the device name" "the property name" value [value2] [value3]
.. note:: Changes performed by xinput do not persist across device hotplugs. xinput
is considered a debugging and testing tool only and should not be used
for permanent configurations.
.. _faq_configuration:
------------------------------------------------------------------------------
Can you add a configuration option for $FEATURE?
------------------------------------------------------------------------------
No. At least that's going to be the initial answer. Read
`Why libinput doesn't have a lot of configuration options `_
first. Configuration options for most features are a signal that we are incapable
of handling it correctly. To get to that point, we want to be sure we're
truly incapable of doing so. libinput has several features that
are handled automatically (and correctly) that users wanted to have
configuration options for initially.
So the answer to this question will almost always be 'no'. A configuration
option is, in most cases, a cop-out.
.. _faq_synclient:
------------------------------------------------------------------------------
Why don't synclient and syndaemon work with libinput?
------------------------------------------------------------------------------
Synclient and syndaemon rely on X input device properties that are specific
to the xf86-input-synaptics X.Org input driver. Both were written when the
synaptics driver was the only common touchpad driver in existence. They
assume that if the properties aren't available, no touchpad is available
either. The xf86-input-libinput X.Org input driver does not export these
driver-specific properties, synclient/syndaemon will thus not detect the
touchpad and refuse to work. Other tools that rely on synclient/syndaemon or
those same properties also do not work with xf86-input-libinput.
Most of syndaemon's functionality is built into libinput, see
:ref:`disable-while-typing`. synclient is merely a configuration tool, see
:ref:`faq_configure_xorg` for similar functionality.
See also the blog posts
`The definitive guide to synclient `_ and
`The future of xinput, xmodmap, setxkbmap, xsetwacom and other tools under Wayland `_
.. _faq_tablets:
------------------------------------------------------------------------------
Does libinput support non-Wacom tablets?
------------------------------------------------------------------------------
Yes, though unfortunately many non-Wacom tablets suffer from bad firmware
and don't send the required events. But they should all work nonetheless. If
you have a tablet that does not work with libinput, please
:ref:`file a bug `.
.. _faq_tablet_capabilities:
------------------------------------------------------------------------------
My tablet doesn't work
------------------------------------------------------------------------------
If you see the message
::
libinput bug: device does not meet tablet criteria. Ignoring this device.
or the message
::
missing tablet capabilities [...] Ignoring this device.
your tablet device does not have the required capabilities to be treated as
a tablet. This is usually a problem with the device and the kernel driver.
See :ref:`tablet-capabilities` for more details.
.. _faq_hwdb_changes:
------------------------------------------------------------------------------
How to apply hwdb changes
------------------------------------------------------------------------------
Sometimes users are asked to test updates to the
`udev hwdb `_
or patches that include a change to the hwdb. See :ref:`hwdb` for
details on the hwdb and how to modify it locally.
.. note:: As of libinput 1.12, libinput-specific properties are now stored in
the :ref:`device-quirks` system. There are no libinput-specific hwdb
entries anymore and any changes to the hwdb must be merged into the
systemd repository.
.. _faq_timer_offset:
------------------------------------------------------------------------------
What causes the "your system is too slow" warning?
------------------------------------------------------------------------------
libinput relies on the caller to call **libinput_dispatch()** whenever data is
available. **libinput_dispatch()** will process the state of all devices,
including some time-sensitive features (e.g. palm detection, tap-to-click,
disable-while-typing, etc.).
If the time between the event and the call to **libinput_dispatch()**
is excessive, those features may not work correctly. For example, a delay in
touch event processing may cause wrong or missing tap-to-click events or
a palm may not be detected correctly.
When this warning appears, it simply means that too much time has passed
between the event occurring and the current time. In almost all cases this
is an indication of the caller being overloaded and not handling events as
speedily as required.
The warning has no immediate effect on libinput's behavior but some of the
functionality that relies on the timer may be impeded. This is not a bug in
libinput. libinput does not control how quickly **libinput_dispatch()** is
called.
.. _faq_wayland:
------------------------------------------------------------------------------
Is libinput required for Wayland?
------------------------------------------------------------------------------
Technically - no. But for your use-case - probably.
Wayland is a display server communication protocol. libinput is a low-level
library to simplify handling input devices and their events. They have no
direct connection. As a technical analogy, the question is similar to "is
glibc required for HTTP", or (stretching the analogy a bit further) "Is a
pen required to write English". No, it isn't.
You can use libinput without a Wayland compositor, you can write a Wayland
compositor without libinput. On most major distributions, libinput is the
standard input stack used with the X.Org X server through the
xf86-input-libinput driver.
So why "for your use-case - probably"? All general-purpose Wayland
compositors use libinput for their input stack. Wayland compositors that
are more specialized (e.g. in-vehicle infotainment or IVI) can handle input
devices directly but the compositor you want to use
on your desktop needs an input stack that is more complex. And right now,
libinput is the only input stack that exists for this use-case.
.. _faq_separate_contexts:
------------------------------------------------------------------------------
Can I write a program to make libinput do $FOO
------------------------------------------------------------------------------
A common question is whether it's possible to write a program that can change
libinput's behavior - specifically the libinput that is used inside the
compositor. This indicates a misunderstanding of how libinput works:
libinput is a library that converts kernel events into libinput events, much
like ``sed`` reads data in, modifies it, and provides it to stdout.
If ``sed`` is used by a shell-script, that script has full control over how
``sed`` processes data. In this analogy, ``sed`` is libinput and the
shell script is the compositor. It is not possible to write a program
to modify the behavior of the ``sed`` instance used inside that shell script
Writing a program that uses libinput is akin to writing a new script that
invoke ``sed``. It will not have any effect on the original ``sed`` instance.
The only way to modify libinput's behavior is to use the configuration options
exposed by the respective compositor. Those affect the libinput context inside
the compositor and thus have an effect on the input device behavior.
------------------------------------------------------------------------------
Can I configure scroll speed?
------------------------------------------------------------------------------
No, or at least, not as a libinput option.
When using a mouse, libinput notifies callers about physical scroll wheel
movement. When using another device, libinput notifies scroll in scroll units.
It is up to the caller to transform those events into a number of pixels to
scroll and, if desired, provide a way to adjust scroll speed.
This transformation cannot be done in libinput because it may depend on context
only known by the caller. For example, a caller may want to scroll faster
depending on how many pages a document has or depending on the widget that
receives the scroll events.
libinput-1.28.1/doc/user/features.rst000066400000000000000000000013701477265155700175500ustar00rootroot00000000000000.. _features:
==============================================================================
libinput Features
==============================================================================
Below is a list of features supported by libinput. The availability of
features usually depends on the device type and a device's capabilities.
Not all features are user-configurable, some rely on :ref:`device-quirks`
to be useful.
.. toctree::
:maxdepth: 1
button-debouncing.rst
clickpad-softbuttons.rst
gestures.rst
middle-button-emulation.rst
palm-detection.rst
touchpad-thumb-detection.rst
scrolling.rst
t440-support.rst
tapping.rst
drag-3fg.rst
tablet-support.rst
switches.rst
touchpad-pressure.rst
trackpoints.rst
libinput-1.28.1/doc/user/gestures.rst000066400000000000000000000425771477265155700176110ustar00rootroot00000000000000.. _gestures:
==============================================================================
Gestures
==============================================================================
libinput supports :ref:`gestures_pinch` and :ref:`gestures_swipe` on most
modern touchpads and other indirect touch devices. Note that libinput **does
not** support gestures on touchscreens, see :ref:`gestures_touchscreens`.
.. _gestures_lifetime:
-----------------------------------------------------------------------------
Lifetime of a gesture
-----------------------------------------------------------------------------
A gesture starts when the finger position and/or finger motion is
unambiguous as to what gesture to trigger and continues until the first
finger belonging to this gesture is lifted.
A single gesture cannot change the finger count. For example, if a user
puts down a fourth finger during a three-finger swipe gesture, libinput will
end (cancel) the three-finger gesture and, if applicable, start a
four-finger swipe gesture. A caller may however decide that those gestures
are semantically identical and continue the two gestures as one single
gesture.
.. _gestures_pinch:
------------------------------------------------------------------------------
Pinch gestures
------------------------------------------------------------------------------
Pinch gestures are executed when two or more fingers are located on the
touchpad and are either changing the relative distance to each other
(pinching) or are changing the relative angle (rotate). Pinch gestures may
change both rotation and distance at the same time. For such gestures,
libinput calculates a logical center for the gestures and provides the
caller with the delta x/y coordinates of that center, the relative angle of
the fingers compared to the previous event, and the absolute scale compared
to the initial finger position.
.. figure:: pinch-gestures.svg
:align: center
The pinch and rotate gestures
The illustration above shows a basic pinch in the left image and a rotate in
the right angle. Not shown is a movement of the logical center if the
fingers move unevenly. Such a movement is supported by libinput, it is
merely left out of the illustration.
Note that while position and angle is relative to the previous event, the
scale is always absolute and a multiplier of the initial finger position's
scale.
.. _gestures_swipe:
------------------------------------------------------------------------------
Swipe gestures
------------------------------------------------------------------------------
Swipe gestures are executed when three or more fingers are moved
synchronously in the same direction. libinput provides x and y coordinates
in the gesture and thus allows swipe gestures in any direction, including
the tracing of complex paths. It is up to the caller to interpret the
gesture into an action or limit a gesture to specific directions only.
.. figure:: swipe-gestures.svg
:align: center
The swipe gestures
The illustration above shows a vertical three-finger swipe. The coordinates
provided during the gesture are the movements of the logical center.
.. _gestures_hold:
------------------------------------------------------------------------------
Hold gestures
------------------------------------------------------------------------------
A hold gesture is one where the user places one or more fingers on the
device without significant movement. The exact conditions when a hold gesture
transitions to pointer motion, scrolling or other gestures
are implementation-defined.
The hold gesture is intended to allow for the implementation of two specific
features:
- where a two-finger scrolling starts kinetic scrolling in the caller, a
subsequent hold gesture can be used to stop that kinetic scroll motion,
and
- hold-to-trigger interactions where the interaction could be a click, a
context menu, or some other context-specific interaction.
Hold gestures have three potential logical states:
- **begin**: one or more fingers are placed on the device at the same time
- **end**: all fingers are removed and the device enters a neutral logical state
- **end(cancelled)**: all fingers are part of a known interaction and the
currenthold gesture is no longer active. This may also occurs when
switching between hold gestures with different finger counts.
.. note:: By definition, a hold gesture does not move and thus no coordinate
updates are available.
For example, a user that puts one finger, then a second finger down and
releases them later may trigger the following event sequence:
============= ============ ============
Action Event Finger count
============= ============ ============
Finger 1 down
Finger 2 down **begin** 2
Finger 2 up **end** 2
Finger 1 up
============= ============ ============
A hold gesture may by be **cancelled**. This occurs
when the hold gesture changes into some other interaction and should no
longer be considered the current hold gesture. A **end(cancelled)** event
applies to the whole gesture (all fingers). For example, a pointer motion on
a touchpad may trigger this sequence:
+-------------------+-----------------------+
| Action | Event |
+===================+=======================+
| | Finger 1 down | | **hold begin** |
+-------------------+-----------------------+
| | Finger 1 motion | | **hold cancel** |
| | | | **pointer motion** |
+-------------------+-----------------------+
| | Finger 1 motion | | **pointer motion** |
+-------------------+-----------------------+
| | Finger 1 up | | *no event* |
+-------------------+-----------------------+
.. note:: Many interactions with a touchpad will start with a hold
gesture that is then cancelled as that gesture turns into e.g.
pointer motion. A caller **must** handle hold gesture
cancellations correctly.
A two-finger scroll motion on a touchpad may trigger this sequence:
+------------------------+---------------------+--------------+
| Action | Event | Finger count |
+========================+=====================+==============+
| | Finger 1 down | | **hold begin** | | 1 |
+------------------------+---------------------+--------------+
| | Finger 2 down | | **hold cancel** | | 1 |
| | | | **hold begin** | | 2 |
+------------------------+---------------------+--------------+
| | Finger 1+2 motion | | **hold cancel** | | 2 |
| | | | **pointer axis** | | |
+------------------------+---------------------+--------------+
| | Finger 1+2 motion | | **pointer axis** | |
+------------------------+---------------------+--------------+
| | Finger 1 up | | **pointer axis** | |
| | Finger 2 up | | (scroll stop) | |
+------------------------+---------------------+--------------+
A three-finger-swipe on a touchpad may trigger this sequence:
+---------------------+---------------------+--------------+
| Action | Event | Finger count |
+=====================+=====================+==============+
| | Finger 1 down | | **hold begin** | | 1 |
+---------------------+---------------------+--------------+
| | Finger 2 down | | **hold cancel** | | 1 |
| | | | **hold begin** | | 2 |
+---------------------+---------------------+--------------+
| | Finger 3 down | | **hold cancel** | | 2 |
| | | | **hold begin** | | 3 |
+---------------------+---------------------+--------------+
| | Finger motion | | **hold cancel** | | 3 |
| | | | **swipe begin** | | 3 |
+---------------------+---------------------+--------------+
| | Finger motion | | **swipe update** | | 3 |
+---------------------+---------------------+--------------+
| | Finger 1 up | | **swipe end** | | 3 |
| | Finger 2 up | | | | |
| | Finger 3 up | | | | |
+---------------------+---------------------+--------------+
Single-finger hold gestures
...........................
libinput uses implementation-defined timeouts based on other interactions
to determine whether a single-finger hold gestures should start. In other
words, a caller **must not** rely on a hold gesture always being triggered
as soon as a single finger is placed on the touchpad. This is true for any
hold gesture but especially so for single-finger hold gestures.
Hold gestures with a single finger are prone to being extremely short-lived.
On many devices it is impossible to hold a finger still enough for there to
be no pointer motion events, even if those deltas are miniscule. Changing
movement thresholds to rely on hold gestures would reduce device
responsiveness.
It is thus the responsibility of the caller to determine where hold gestures
transition in and out of other interactions. For example, a two-finger hold
may produce a cancelled single-finger hold gesture first:
+--------------------+----------------------+--------------+--------------+
| Action | Event | Finger count | Notes |
+====================+======================+==============+==============+
| | Finger 1 down | | **hold begin** | | 1 | |
+--------------------+----------------------+--------------+--------------+
| | Finger 1 motion | | **hold cancel** | | 1 | | tiny deltas|
| | | | **pointer motion** | | | | |
+--------------------+----------------------+--------------+--------------+
| | Finger 2 down | | **hold begin** | | 2 | |
+--------------------+----------------------+--------------+--------------+
| | Finger 1 up | | **hold end** | | | |
| | Finger 2 up | | | | | |
+--------------------+----------------------+--------------+--------------+
Note how the second hold gesture started with a finger count of 2 - without
the user ever lifting the first finger. Cancellation of hold gesture does
not imply the user has lifted a finger.
A hold gesture may start after a previous gesture completed. For example, a
single finger move-and-hold may trigger different sequences for the same
user interaction:
+--------------------+---------------------+-------------------+--------------+
| Action | Device 1 | Device 2 | Notes |
+====================+=====================+===================+==============+
| | Finger 1 down | | **hold begin** | | **hold begin** | |
+--------------------+---------------------+-------------------+--------------+
| | Finger 1 motion | | **hold cancel** | | | tiny deltas|
| | | **pointer motion**| | | |
+--------------------+---------------------+-------------------+--------------+
| | | **hold begin** | | |
+--------------------+---------------------+-------------------+--------------+
| | Finger 1 up | | **hold end** | | **hold end** | |
+--------------------+---------------------+-------------------+--------------+
A caller that wants to use hold gestures must thus be able to infer the same
interaction based on a stream of pointer motion events with small deltas.
libinput may start a new hold begin gesture once the pointer stops moving.
The time between the last pointer motion event and the hold begin event is
implementation-defined.
Hold gestures and thumb/palm detection
......................................
Thumb and palm detection effectively remove touches from being counted
towards an interaction, see :ref:`thumb_detection` and
:ref:`palm_detection` for details.
In the context of hold gestures, thumbs and palms are treated by libinput as
if the finger was removed from the device. Where other non-thumb/non-palm
fingers remain on the device, an **hold update** event is sent. Otherwise,
the hold gesture terminates with a **hold cancel** event.
Notably, libinput's thumb and palm detection is not a simple boolean per
touch but specific to the state of that touch in the overall context. For
example, a touch may be a thumb for tapping but not for clickfinger
interactions. A caller must not infer the number of physical fingers from
the hold gesture.
Likewise, libinput may classify a finger as thumb in the same hardware event
as a new finger is placed on the touchpad. In that case, the hold gesture
**may** continue as one-finger gesture despite there being two physical
touch points.
Information to determine whether a touch is a thumb or a palm may not be
available until some time into an interaction. Thus very short brushes
of the touchpad by a palm may trigger a **hold begin** followed by an
immediate **hold end** as libinput lacks sufficient information to identify
the touch as thumb/palm and send the corresponding **hold cancel**
event. A caller must not assume that a hold gesture always represents a
valid finger down.
Hold gestures and tap-to-click
..............................
:ref:`tapping` is the feature that enables short-lived touches to trigger
button presses.
.. warning:: Summary: do not use hold gestures to do your own tap-to-click
implementation
In the context of hold gestures, tap-to-click cancels current hold gestures
and a finger dragging (see :ref:`tapndrag`) does not begin a hold
gesture. Where tap-to-click is disabled a tap-like gesture may create
**hold begin** followed by a **hold end** event. Callers **must not** use
hold gestures for their own tap-to-click implementation as the data is not
reliable enough. libinput may change internal timeouts and thresholds
depending on whether tap-to-click is enabled and the hold gesture event may
not match touch sequences that a user would expect to be a tap-to-click
interaction.
.. _gestures_touchscreens:
------------------------------------------------------------------------------
Touchscreen gestures
------------------------------------------------------------------------------
Touchscreen gestures are **not** interpreted by libinput. Rather, any touch
point is passed to the caller and any interpretation of gestures is up to
the caller or, eventually, the X or Wayland client.
Interpreting gestures on a touchscreen requires context that libinput does
not have, such as the location of windows and other virtual objects on the
screen as well as the context of those virtual objects:
.. figure:: touchscreen-gestures.svg
:align: center
Context-sensitivity of touchscreen gestures
In the above example, the finger movements are identical but in the left
case both fingers are located within the same window, thus suggesting an
attempt to zoom. In the right case both fingers are located on a window
border, thus suggesting a window movement. libinput has no knowledge of the
window coordinates and thus cannot differentiate the two.
.. _gestures_softbuttons:
------------------------------------------------------------------------------
Gestures with enabled software buttons
------------------------------------------------------------------------------
If the touchpad device is a :ref:`Clickpad `, it
is recommended that a caller switches to :ref:`clickfinger`.
Usually fingers placed in a :ref:`software button area `
are not considered for gestures, resulting in some gestures to be
interpreted as pointer motion or two-finger scroll events.
.. figure:: pinch-gestures-softbuttons.svg
:align: center
Interference of software buttons and pinch gestures
In the example above, the software button area is highlighted in red. The
user executes a three-finger pinch gesture, with the thumb remaining in the
software button area. libinput ignores fingers within the software button
areas, the movement of the remaining fingers is thus interpreted as a
two-finger scroll motion.
.. _gestures_twofinger_touchpads:
------------------------------------------------------------------------------
Gestures on two-finger touchpads
------------------------------------------------------------------------------
As of kernel 4.2, many :ref:`touchpads_touch_partial_mt` provide only two
slots. This affects how gestures can be interpreted. Touchpads with only two
slots can identify two touches by position but can usually tell that there
is a third (or fourth) finger down on the touchpad - without providing
positional information for that finger.
Touchpoints are assigned in sequential order and only the first two touch
points are trackable. For libinput this produces an ambiguity where it is
impossible to detect whether a gesture is a pinch gesture or a swipe gesture
whenever a user puts the index and middle finger down first. Since the third
finger does not have positional information, it's location cannot be
determined.
.. figure:: gesture-2fg-ambiguity.svg
:align: center
Ambiguity of three-finger gestures on two-finger touchpads
The image above illustrates this ambiguity. The index and middle finger are
set down first, the data stream from both finger positions looks identical.
In this case, libinput assumes the fingers are in a horizontal arrangement
(the right image above) and use a swipe gesture.
libinput-1.28.1/doc/user/git_version.py.in000066400000000000000000000001541477265155700205060ustar00rootroot00000000000000def get_git_version():
return "__GIT_VERSION__"[:7]
def get_git_version_full():
return "__GIT_VERSION__"
libinput-1.28.1/doc/user/ignoring-devices.rst000066400000000000000000000032211477265155700211630ustar00rootroot00000000000000.. _ignoring_devices:
==============================================================================
Ignoring specific devices
==============================================================================
If a device has the **LIBINPUT_IGNORE_DEVICE** udev property set to any
value but "0", that device is not initialized by libinput.
For a context created with **libinput_udev_create_context()**, the device is
silently ignored and never shows up. If the device is added with
**libinput_path_add_device()** to a context created with
**libinput_path_create_context()**, adding the device will fail and return NULL
(see that function's documentation for more
information).
If the property value is exactly "0", then the property is considered unset
and libinput initializes the device normally.
This property should be used for devices that are correctly detected as
input devices (see :ref:`udev_device_type`) but that should not be used by
libinput. It is recommended that devices that should not be handled as input
devices at all unset the **ID_INPUT** and related properties instead. The
**LIBINPUT_IGNORE_DEVICE** property signals that only libinput should
ignore this property but other parts of the stack (if any) should continue
treating this device normally.
Below is an example udev rule to assign **LIBINPUT_IGNORE_DEVICE** to the
device with the vendor/model ID of ``012a``/``034b``. ::
$ cat /etc/udev/rules.d/99-ignore-my-device.rules
ACTION!="remove", KERNEL=="event[0-9]*", \
ENV{ID_VENDOR_ID}=="012a", \
ENV{ID_MODEL_ID}=="034b", \
ENV{LIBINPUT_IGNORE_DEVICE}="1"
See :ref:`udev_config` for more details on libinput's udev properties.
libinput-1.28.1/doc/user/incorrectly-enabled-hires.rst000066400000000000000000000047371477265155700230010ustar00rootroot00000000000000.. _incorrectly_enabled_hires:
==============================================================================
Incorrectly enabled high-resolution scroll
==============================================================================
Some devices might announce support for high-resolution scroll wheel by enabling
``REL_WHEEL_HI_RES`` and/or ``REL_HWHEEL_HI_RES`` but never send a
high-resolution scroll event.
When the first low-resolution scroll event is received without any previous
high-resolution event, libinput prints a bug warning with the text **"device
supports high-resolution scroll but only low-resolution events have been
received"** and a link to this page.
.. note:: This warning will be printed only once
In most cases this is a bug on the device firmware, the kernel driver or in a
software used to create user-space devices through uinput.
Once the bug is detected, libinput will start emulating high-resolution scroll
events.
------------------------------------------------------------------------------
Detecting and fixing the issue
------------------------------------------------------------------------------
Events sent by a buggy device can be shown in the
:ref:`libinput record ` output for the device. Notice that
``REL_WHEEL_HI_RES`` and ``REL_HWHEEL_HI_RES`` are set but only ``REL_WHEEL``
events are sent: ::
# Supported Events:
# Event type 0 (EV_SYN)
# Event type 1 (EV_KEY)
# Event code 272 (BTN_LEFT)
# Event type 2 (EV_REL)
# Event code 0 (REL_X)
# Event code 1 (REL_Y)
# Event code 6 (REL_HWHEEL)
# Event code 8 (REL_WHEEL)
# Event code 11 (REL_WHEEL_HI_RES)
# Event code 12 (REL_HWHEEL_HI_RES)
[...]
quirks:
events:
- evdev:
- [ 0, 0, 2, 8, 1] # EV_REL / REL_WHEEL 1
- [ 0, 0, 0, 0, 0] # ------------ SYN_REPORT (0) ---------- +0ms
- evdev:
- [ 0, 15126, 2, 8, 1] # EV_REL / REL_WHEEL 1
- [ 0, 15126, 0, 0, 0] # ------------ SYN_REPORT (0) ---------- +15ms
- evdev:
- [ 0, 30250, 2, 8, 1] # EV_REL / REL_WHEEL 1
- [ 0, 30250, 0, 0, 0] # ------------ SYN_REPORT (0) ---------- +15ms
The issue can be fixed by adding a quirk to unset the ``REL_WHEEL_HI_RES`` and
``REL_HWHEEL_HI_RES`` event codes: ::
AttrEventCode=-REL_WHEEL_HI_RES;-REL_HWHEEL_HI_RES;
Please see :ref:`device-quirks` for details.
libinput-1.28.1/doc/user/index.rst000066400000000000000000000041251477265155700170420ustar00rootroot00000000000000
.. toctree::
:maxdepth: 2
:hidden:
what-is-libinput
features
configuration
building
faqs
reporting-bugs
troubleshooting
contributing
development
API documentation <@HTTP_DOC_LINK@/api/>
++++++++++++++++++++++++++++++
libinput
++++++++++++++++++++++++++++++
libinput is a library that provides a full input stack for display servers
and other applications that need to handle input devices provided by the
kernel.
libinput provides device detection, event handling and abstraction so
minimize the amount of custom input code the user of libinput need to
provide the common set of functionality that users expect. Input event
processing includes scaling touch coordinates, generating
relative pointer events from touchpads, pointer acceleration, etc.
libinput is not used directly by applications. Think of it more as a device
driver than an application library. See :ref:`what_is_libinput` for more details.
--------------------
Users and Developers
--------------------
Please use the side-bar to nagivate through the various documentation items.
-----------------
API documentation
-----------------
The API documentation is available here:
https://wayland.freedesktop.org/libinput/doc/latest/api/
.. note:: This documentation is generally only needed by authors of Wayland
compositors or other developers dealing with input events directly.
-------
License
-------
libinput is licensed under the MIT license
.. code-block:: none
Permission is hereby granted, free of charge, to any person obtaining a
copy of this software and associated documentation files (the "Software"),
to deal in the Software without restriction, including without limitation
the rights to use, copy, modify, merge, publish, distribute, sublicense,
and/or sell copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following conditions: [...]
See the
`COPYING `_
file for the full license information.
.....
About
.....
Documentation generated from |git_version|
libinput-1.28.1/doc/user/meson.build000066400000000000000000000161041477265155700173430ustar00rootroot00000000000000# Sphinx build
sphinx = find_program('sphinx-build-3', 'sphinx-build', required : false)
if not sphinx.found()
error('Program "sphinx-build" not found or not executable. Try building with -Ddocumentation=false')
endif
yq = find_program('yq', required : false)
if not yq.found()
warning('Program "yq" not found or not executable. Dependency list will not be built.')
endif
sphinx_config = configuration_data()
sphinx_config.set('PROJECT_NAME', meson.project_name())
sphinx_config.set('PROJECT_VERSION', meson.project_version())
sphinx_config.set('BUILDDIR', meson.current_build_dir())
sphinx_config.set('HTTP_DOC_LINK', doc_url)
git_version_page = vcs_tag(command : ['git', 'log', '-1', '--format=%H'],
fallback : 'unknown',
input : 'git_version.py.in',
output : 'git_version.py',
replace_string: '__GIT_VERSION__')
sphinx_conf_py = configure_file(input : 'conf.py.in',
output : 'conf.py',
configuration : sphinx_config)
# 404 replacements for old URLs
# The switch to sphinx caused a few pages to be renamed, sphinx uses
# filename.html whereas doxygen used whatever the @page foo was. So old docs
# *mostly* used underscores, now we're consistent with dashes.
# We can't use htaccess on the server, so let's auto-generate a 404 list
# with a basic page telling users that the link has moved. This can be
# removed in a few months, towards the end of 2018.
#
# File list is: [current-sphinx-input-file, old-generated-page]
# If they're the same they'll be ignored.
src_404s = [
[ 'absolute-axes.rst', 'absolute_axes.html'],
[ 'absolute-coordinate-ranges.rst', 'absolute_coordinate_ranges.html'],
[ 'architecture.rst', 'architecture.html'],
[ 'building.rst', 'building_libinput.html'],
[ 'button-debouncing.rst', 'button_debouncing.html'],
[ 'clickpad-softbuttons.rst', 'clickpad_softbuttons.html'],
[ 'configuration.rst', 'config_options.html'],
[ 'contributing.rst', 'contributing.html'],
[ 'development.rst', 'development.html'],
[ 'device-configuration-via-udev.rst', 'udev_config.html'],
[ 'device-quirks.rst', 'device-quirks.html'],
[ 'faqs.rst', 'faq.html'],
[ 'features.rst', 'features.html'],
[ 'gestures.rst', 'gestures.html'],
[ 'incorrectly-enabled-hires.rst', 'incorrectly-enabled-hires.html'],
[ 'middle-button-emulation.rst', 'middle_button_emulation.html'],
[ 'normalization-of-relative-motion.rst', 'motion_normalization.html'],
[ 'palm-detection.rst', 'palm_detection.html'],
[ 'pointer-acceleration.rst', 'pointer-acceleration.html'],
[ 'reporting-bugs.rst', 'reporting_bugs.html'],
[ 'scrolling.rst', 'scrolling.html'],
[ 'seats.rst', 'seats.html'],
[ 'switches.rst', 'switches.html'],
[ 't440-support.rst', 't440_support.html'],
[ 'tablet-support.rst', 'tablet-support.html'],
[ 'tapping.rst', 'tapping.html'],
[ 'test-suite.rst', 'test-suite.html'],
[ 'timestamps.rst', 'timestamps.html'],
[ 'tools.rst', 'tools.html'],
[ 'touchpad-jitter.rst', 'touchpad_jitter.html'],
[ 'touchpad-jumping-cursors.rst', 'touchpad_jumping_cursor.html'],
[ 'touchpad-pressure.rst', 'touchpad_pressure.html'],
[ 'touchpads.rst', 'touchpads.html'],
[ 'trackpoints.rst', 'trackpoints.html'],
[ 'troubleshooting.rst', 'troubleshooting.html'],
[ 'what-is-libinput.rst', 'what_is_libinput.html'],
]
dst_404s = []
foreach s404 : src_404s
target = s404[0]
oldpage = s404[1]
tname = target.split('.rst')[0]
oname = oldpage.split('.html')[0]
if tname != oname
config_404 = configuration_data()
config_404.set('TARGET', '@0@.html'.format(tname))
c = configure_file(input : '404.rst',
output : '@0@.rst'.format(oname),
configuration : config_404)
dst_404s += [c]
endif
endforeach
src_rst = files(
# dot drawings
'dot/seats-sketch.gv',
'dot/seats-sketch-libinput.gv',
'dot/libinput-stack-wayland.gv',
'dot/libinput-stack-xorg.gv',
'dot/libinput-stack-gnome.gv',
'dot/evemu.gv',
'dot/libinput-record.gv',
# svgs
'svg/button-debouncing-wave-diagram.svg',
'svg/button-scrolling.svg',
'svg/clickfinger.svg',
'svg/clickfinger-distance.svg',
'svg/edge-scrolling.svg',
'svg/gesture-2fg-ambiguity.svg',
'svg/palm-detection.svg',
'svg/pinch-gestures.svg',
'svg/pinch-gestures-softbuttons.svg',
'svg/ptraccel-custom.svg',
'svg/ptraccel-linear.svg',
'svg/ptraccel-low-dpi.svg',
'svg/ptraccel-touchpad.svg',
'svg/ptraccel-trackpoint.svg',
'svg/software-buttons.svg',
'svg/software-buttons-conditions.svg',
'svg/software-buttons-thumbpress.svg',
'svg/software-buttons-visualized.svg',
'svg/swipe-gestures.svg',
'svg/tablet-area.svg',
'svg/tablet-axes.svg',
'svg/tablet-cintiq24hd-modes.svg',
'svg/tablet-interfaces.svg',
'svg/tablet-intuos-modes.svg',
'svg/tablet-left-handed.svg',
'svg/tablet-out-of-bounds.svg',
'svg/tablet.svg',
'svg/tap-n-drag.svg',
'svg/thumb-detection.svg',
'svg/top-software-buttons.svg',
'svg/touchscreen-gestures.svg',
'svg/trackpoint-delta-illustration.svg',
'svg/twofinger-scrolling.svg',
# rst files
'absolute-axes.rst',
'absolute-coordinate-ranges.rst',
'architecture.rst',
'building.rst',
'button-debouncing.rst',
'clickpad-softbuttons.rst',
'clickpad-with-right-button.rst',
'contributing.rst',
'device-configuration-via-udev.rst',
'device-quirks.rst',
'drag-3fg.rst',
'faqs.rst',
'gestures.rst',
'incorrectly-enabled-hires.rst',
'ignoring-devices.rst',
'middle-button-emulation.rst',
'normalization-of-relative-motion.rst',
'palm-detection.rst',
'pointer-acceleration.rst',
'reporting-bugs.rst',
'scrolling.rst',
'seats.rst',
'switches.rst',
't440-support.rst',
'tablet-support.rst',
'tapping.rst',
'test-suite.rst',
'timestamps.rst',
'tablet-debugging.rst',
'tools.rst',
'touchpad-jumping-cursors.rst',
'touchpad-pressure.rst',
'touchpad-pressure-debugging.rst',
'touchpad-jitter.rst',
'touchpad-thumb-detection.rst',
'touchpads.rst',
'trackpoints.rst',
'trackpoint-configuration.rst',
'what-is-libinput.rst',
'wheel-api.rst',
'features.rst',
'development.rst',
'troubleshooting.rst',
'configuration.rst',
)
src_sphinx = []
foreach f : src_rst
sf = configure_file(input: f,
output: '@PLAINNAME@',
copy : true)
src_sphinx += [ sf ]
endforeach
configure_file(input: 'index.rst',
output: 'index.rst',
configuration: sphinx_config)
dependencies_config = configuration_data()
if yq.found()
distributions = ['fedora', 'ubuntu', 'debian', 'arch', 'alpine']
foreach distro : distributions
yq_filter = '.distributions[] | select(.name == "@0@") | .packages | join(" ")'.format(distro)
deps = run_command(yq, '-r', yq_filter,
dir_gitlab_ci / 'config.yml',
check: true).stdout()
dependencies_config.set('@0@_PACKAGES'.format(distro.to_upper()), deps)
endforeach
endif
configure_file(input: 'dependencies.rst',
output: 'dependencies.rst',
configuration: dependencies_config)
# do not use -j, it breaks on Ubuntu
sphinx_output_dir = 'Documentation'
custom_target('sphinx',
input : [ sphinx_conf_py, git_version_page ] + src_sphinx + dst_404s,
output : [ sphinx_output_dir ],
command : [ sphinx, '-q', '-b', 'html',
'-d', meson.current_build_dir() / 'doctrees',
meson.current_build_dir(), sphinx_output_dir],
build_by_default : true)
libinput-1.28.1/doc/user/middle-button-emulation.rst000066400000000000000000000034541477265155700225010ustar00rootroot00000000000000.. _middle_button_emulation:
==============================================================================
Middle button emulation
==============================================================================
Middle button emulation provides users with the ability to generate a middle
click even when the device does not have a physical middle button available.
When middle button emulation is enabled, a simultaneous press of the left
and right button generates a middle mouse button event. Releasing the
buttons generates a middle mouse button release, the left and right button
events are discarded otherwise.
The middle button release event may be generated when either button is
released, or when both buttons have been released. The exact behavior is
device-dependent, libinput will implement the behavior that is most
appropriate to the physical device.
The middle button emulation behavior when combined with other device
buttons, including a physical middle button is device-dependent.
For example, :ref:`clickpad_softbuttons` provides a middle button area when
middle button emulation is disabled. That middle button area disappears
when middle button emulation is enabled - a middle click can then only be
triggered by a simultaneous left + right click.
Some devices provide middle mouse button emulation but do not allow
enabling/disabling that emulation. Likewise, some devices may allow middle
button emulation but have it disabled by default. This is the case for most
mouse-like devices where a middle button is detected.
libinput provides **libinput_device_config_middle_emulation_set_enabled()** to
enable or disable middle button emulation. See :ref:`faq_configure_wayland`
and :ref:`faq_configure_xorg` for info on how to enable or disable middle
button emulation in the Wayland compositor or the X stack.
libinput-1.28.1/doc/user/normalization-of-relative-motion.rst000066400000000000000000000101351477265155700243350ustar00rootroot00000000000000.. _motion_normalization:
==============================================================================
Normalization of relative motion
==============================================================================
Most relative input devices generate input in so-called "mickeys". A
mickey is in device-specific units that depend on the resolution
of the sensor. Most optical mice use sensors with 1000dpi resolution, but
some devices range from 100dpi to well above 8000dpi.
Without a physical reference point, a relative coordinate cannot be
interpreted correctly. A delta of 10 mickeys may be a millimeter of
physical movement or 10 millimeters, depending on the sensor. This
affects pointer acceleration in libinput and interpretation of relative
coordinates in callers.
libinput does partial normalization of relative input. For devices with a
resolution of 1000dpi and higher, motion events are normalized to a default
of 1000dpi before pointer acceleration is applied. As a result, devices with
1000dpi and above feel the same.
Devices below 1000dpi are not normalized (normalization of a 1-device unit
movement on a 400dpi mouse would cause a 2.5 pixel movement). Instead,
libinput applies a dpi-dependent acceleration function. At low speeds, a
1-device unit movement usually translates into a 1-pixel movements. As the
movement speed increases, acceleration is applied - at high speeds a low-dpi
device will roughly feel the same as a higher-dpi mouse.
The reason for the normalization is convenience: a caller can assume that a
delta of 1 should result in a movement of 1 pixel on a traditional
(low-dpi) screen. On screens with high resolutions, the caller must scale
according to the UI scale factors.
This normalization only applies to accelerated coordinates, unaccelerated
coordinates are left in device-units. It is up to the caller to interpret
those coordinates correctly.
.. _motion_normalization_touchpad:
------------------------------------------------------------------------------
Normalization of touchpad coordinates
------------------------------------------------------------------------------
Touchpads may have a different resolution for the horizontal and vertical
axis. Interpreting coordinates from the touchpad without taking resolution
into account results in uneven motion.
libinput scales unaccelerated touchpad motion to the resolution of the
touchpad's x axis, i.e. the unaccelerated value for the y axis is:
``y = (x / resolution_x) * resolution_y``.
.. _motion_normalization_tablet:
------------------------------------------------------------------------------
Normalization of tablet coordinates
------------------------------------------------------------------------------
See :ref:`tablet-relative-motion`
.. _motion_normalization_customization:
------------------------------------------------------------------------------
Setting custom DPI settings
------------------------------------------------------------------------------
Devices usually do not advertise their resolution and libinput relies on
the udev property **MOUSE_DPI** for this information. This property is usually
set via the
`udev hwdb `_.
The ``mouse-dpi-tool`` utility provided by
`libevdev `_ should be
used to measure a device's resolution.
The format of the property for single-resolution mice is: ::
MOUSE_DPI=resolution@frequency
The resolution is in dots per inch, the frequency in Hz.
The format of the property for multi-resolution mice may list multiple
resolutions and frequencies: ::
MOUSE_DPI=r1@f1 *r2@f2 r3@f3
The default frequency must be pre-fixed with an asterisk.
For example, these two properties are valid: ::
MOUSE_DPI=800@125
MOUSE_DPI=400@125 800@125 *1000@500 5500@500
The behavior for a malformed property is undefined. If the property is
unset, libinput assumes the resolution is 1000dpi.
Note that HW does not usually provide information about run-time
resolution changes, libinput will thus not detect when a resolution
changes to the non-default value.
libinput-1.28.1/doc/user/palm-detection.rst000066400000000000000000000236461477265155700206510ustar00rootroot00000000000000.. _palm_detection:
==============================================================================
Palm detection
==============================================================================
Palm detection tries to identify accidental touches while typing, while
using the trackpoint and/or during general use of the touchpad area.
On most laptops typing on the keyboard generates accidental touches on the
touchpad with the palm (usually the area below the thumb). This can lead to
cursor jumps or accidental clicks. On large touchpads, the palm may also
touch the bottom edges of the touchpad during normal interaction.
Interference from a palm depends on the size of the touchpad and the position
of the user's hand. Data from touchpads showed that almost all palm events
during tying on a Lenovo T440 happened in the left-most and right-most 5% of
the touchpad. The T440 series has one of the largest touchpads, other
touchpads are less affected by palm touches.
libinput has multiple ways of detecting a palm, each of which depends on
hardware-specific capabilities.
- :ref:`palm_tool`
- :ref:`palm_pressure`
- :ref:`palm_touch_size`
- :ref:`palm_exclusion_zones`
- :ref:`trackpoint-disabling`
- :ref:`disable-while-typing`
- :ref:`disable-while-trackpointing`
- :ref:`stylus-touch-arbitration`
Palm detection is always enabled, with the exception of
disable-while-typing.
.. _palm_tool:
------------------------------------------------------------------------------
Palm detection based on firmware labelling
------------------------------------------------------------------------------
Some devices provide palm detection in the firmware, forwarded by the kernel
as the ``EV_ABS/ABS_MT_TOOL`` axis with a value of ``MT_TOOL_PALM``
(whenever a palm is detected). libinput honors that value and switches that
touch to a palm.
.. _palm_pressure:
------------------------------------------------------------------------------
Palm detection based on pressure
------------------------------------------------------------------------------
The simplest form of palm detection labels a touch as palm when the pressure
value goes above a certain threshold. This threshold is usually high enough
that it cannot be triggered by a finger movement. One a touch is labelled as
palm based on pressure, it will remain so even if the pressure drops below
the threshold again. This ensures that a palm remains a palm even when the
pressure changes as the user is typing.
For some information on how to detect pressure on a touch and debug the
pressure ranges, see :ref:`touchpad_pressure`.
.. _palm_touch_size:
------------------------------------------------------------------------------
Palm detection based on touch size
------------------------------------------------------------------------------
On touchpads that support the ``ABS_MT_TOUCH_MAJOR`` axes, libinput can perform
palm detection based on the size of the touch ellipse. This works similar to
the pressure-based palm detection in that a touch is labelled as palm when
it exceeds the (device-specific) touch size threshold.
For some information on how to detect the size of a touch and debug the
touch size ranges, see :ref:`touchpad_pressure`.
.. _palm_exclusion_zones:
------------------------------------------------------------------------------
Palm exclusion zones
------------------------------------------------------------------------------
libinput enables palm detection on the left, right and top edges of the
touchpad. Two exclusion zones are defined on the left and right edge of the
touchpad. If a touch starts in the exclusion zone, it is considered a palm
and the touch point is ignored. However, for fast cursor movements across
the screen, it is common for a finger to start inside an exclusion zone and
move rapidly across the touchpad. libinput detects such movements and avoids
palm detection on such touch sequences.
Another exclusion zone is defined on the top edge of the touchpad. As with
the edge zones, libinput detects vertical movements out of the edge zone and
avoids palm detection on such touch sequences.
A touch starting in the exclusion zone does not trigger a tap (see
:ref:`tapping`).
In the diagram below, the exclusion zones are painted red.
Touch 'A' starts inside the exclusion zone and moves
almost vertically. It is considered a palm and ignored for cursor movement,
despite moving out of the exclusion zone.
Touch 'B' starts inside the exclusion zone but moves horizontally out of the
zone. It is considered a valid touch and controls the cursor.
Touch 'C' occurs in the exclusion zone. Despite being a tapping motion, it does
not generate an emulated button event.
.. figure:: palm-detection.svg
:align: center
.. _trackpoint-disabling:
------------------------------------------------------------------------------
Palm detection during trackpoint use
------------------------------------------------------------------------------
If a device provides a
`trackpoint `_, it is
usually located above the touchpad. This increases the likelihood of
accidental touches whenever the trackpoint is used.
libinput disables the touchpad whenever it detects trackpoint activity for a
certain timeout until after trackpoint activity stops. Touches generated
during this timeout will not move the pointer, and touches started during
this timeout will likewise not move the pointer (allowing for a user to rest
the palm on the touchpad while using the trackstick).
If the touchpad is disabled, the :ref:`top software buttons `
remain enabled.
.. _disable-while-typing:
------------------------------------------------------------------------------
Disable-while-typing
------------------------------------------------------------------------------
libinput automatically disables the touchpad for a timeout after a key
press, a feature traditionally referred to as "disable while typing" and
previously available through the
`syndaemon(1) `_ command. libinput does
not require an external command and the feature is currently enabled for all
touchpads but will be reduced in the future to only apply to touchpads where
finger width or pressure data is unreliable.
Notable behaviors of libinput's disable-while-typing feature:
- Two different timeouts are used, after a single key press the timeout is
short to ensure responsiveness. After multiple key events, the timeout is
longer to avoid accidental pointer manipulation while typing.
- Some keys do not trigger the timeout, specifically some modifier keys
(Ctrl, Alt, Shift, and Fn). Actions such as Ctrl + click thus stay
responsive.
- Touches started while typing do not control the cursor even after typing
has stopped, it is thus possible to rest the palm on the touchpad while
typing.
- Physical buttons work even while the touchpad is disabled. This includes
:ref:`software-emulated buttons `.
- libinput pairs touchpads and keyboards for the disable-while-typing
feature. In the most common case, the internal touchpad is paired only
with the internal keyboard. Typing on an external keyboard will thus not
disable the touchpad. Some devices require a :ref:`quirk `
to be correctly paired.
Disable-while-typing can be enabled and disabled by calling
**libinput_device_config_dwt_set_enabled()**.
.. _disable-while-trackpointing:
------------------------------------------------------------------------------
Disable-while-trackpointing
------------------------------------------------------------------------------
libinput automatically disables the touchpad for a timeout after the trackpoint
is moved, a feature referred to as "disable while trackpointing". libinput does
not require an external command and the feature is currently enabled for all
touchpads.
Disable-while-trackpointing can be enabled and disabled by calling
**libinput_device_config_dwtp_set_enabled()**.
.. _stylus-touch-arbitration:
------------------------------------------------------------------------------
Stylus-touch arbitration
------------------------------------------------------------------------------
A special case of palm detection is touch arbitration on devices that
support styli. When interacting with a stylus on the screen, parts of the
hand may touch the surface and trigger touches. As the user is currently
interacting with the stylus, these touches would interfer with the correct
working of the stylus.
libinput employs a method similar to :ref:`disable-while-typing` to detect
these touches and disables the touchpad accordingly.
.. _thumb-detection:
------------------------------------------------------------------------------
Thumb detection
------------------------------------------------------------------------------
Many users rest their thumb on the touchpad while using the index finger to
move the finger around. For clicks, often the thumb is used rather than the
finger. The thumb should otherwise be ignored as a touch, i.e. it should not
count towards :ref:`clickfinger` and it should not cause a single-finger
movement to trigger :ref:`twofinger_scrolling`.
libinput uses two triggers for thumb detection: pressure and
location. A touch exceeding a pressure threshold is considered a thumb if it
is within the thumb detection zone.
.. note:: "Pressure" on touchpads is synonymous with "contact area." A large touch
surface area has a higher pressure and thus hints at a thumb or palm
touching the surface.
Pressure readings are unreliable at the far bottom of the touchpad as a
thumb hanging mostly off the touchpad will have a small surface area.
libinput has a definitive thumb zone where any touch is considered a resting
thumb.
.. figure:: thumb-detection.svg
:align: center
The picture above shows the two detection areas. In the larger (light red)
area, a touch is labelled as thumb when it exceeds a device-specific
pressure threshold. In the lower (dark red) area, a touch is labelled as
thumb if it remains in that area for a time without moving outside.
libinput-1.28.1/doc/user/pointer-acceleration.rst000066400000000000000000000323631477265155700220470ustar00rootroot00000000000000.. _pointer-acceleration:
==============================================================================
Pointer acceleration
==============================================================================
libinput uses device-specific pointer acceleration methods, with the default
being the :ref:`ptraccel-linear`. The methods share common properties, such as
:ref:`ptraccel-velocity`.
This page explains the high-level concepts used in the code. It aims to
provide an overview for developers and is not necessarily useful for
users.
.. _ptraccel-profiles:
------------------------------------------------------------------------------
Pointer acceleration profiles
------------------------------------------------------------------------------
The profile decides the general method of pointer acceleration.
libinput currently supports three profiles: **"adaptive"**, **"flat"** and
**"custom"**.
- The **adaptive** profile is the default profile for all devices and takes the
current speed of the device into account when deciding on acceleration.
- The **flat** profile is simply a constant factor applied to all device deltas,
regardless of the speed of motion (see :ref:`ptraccel-profile-flat`).
- The **custom** profile allows the user to define a custom acceleration
function, giving full control over accelerations behavior at different speed
(see :ref:`ptraccel-profile-custom`).
Most of this document describes the adaptive pointer acceleration.
.. _ptraccel-velocity:
------------------------------------------------------------------------------
Velocity calculation
------------------------------------------------------------------------------
The device's speed of movement is measured across multiple input events
through so-called "trackers". Each event prepends a the tracker item, each
subsequent tracker contains the delta of that item to the current position,
the timestamp of the event that created it and the cardinal direction of the
movement at the time. If a device moves into the same direction, the
velocity is calculated across multiple trackers. For example, if a device
moves steadily for 10 events to the left, the velocity is calculated across
all 10 events.
Whenever the movement changes direction or significantly changes speed, the
velocity is calculated from the direction/speed change only. For example, if
a device moves steadily for 8 events to the left and then 2 events to the
right, the velocity is only that of the last 2 events.
An extra time limit prevents events that are too old to factor into the
velocity calculation. For example, if a device moves steadily for 5 events
to the left, then pauses, then moves again for 5 events to the left, only
the last 5 events are used for velocity calculation.
The velocity is then used to calculate the acceleration factor
.. _ptraccel-factor:
------------------------------------------------------------------------------
Acceleration factor
------------------------------------------------------------------------------
The acceleration factor is the final outcome of the pointer acceleration
calculations. It is a unitless factor that is applied to the current delta,
a factor of 2 doubles the delta (i.e. speeds up the movement), a factor of
less than 1 reduces the delta (i.e. slows the movement).
Any factor less than 1 requires the user to move the device further to move
the visible pointer. This is called deceleration and enables high precision
target selection through subpixel movements. libinput's current maximum
deceleration factor is 0.3 (i.e. slow down to 30% of the pointer speed).
A factor higher than 1 moves the pointer further than the physical device
moves. This is acceleration and allows a user to cross the screen quickly
but effectively skips pixels. libinput's current maximum acceleration factor
is 3.5.
.. _ptraccel-linear:
------------------------------------------------------------------------------
Linear pointer acceleration
------------------------------------------------------------------------------
The linear pointer acceleration method is the default for most pointer
devices. It provides deceleration at very slow movements, a 1:1 mapping for
regular movements and a linear increase to the maximum acceleration factor
for fast movements.
Linear pointer acceleration applies to devices with above 1000dpi resolution
and after :ref:`motion_normalization` is applied.
.. figure:: ptraccel-linear.svg
:align: center
Linear pointer acceleration
The image above shows the linear pointer acceleration settings at various
speeds. The line for 0.0 is the default acceleration curve, speed settings
above 0.0 accelerate sooner, faster and to a higher maximum acceleration.
Speed settings below 0 delay when acceleration kicks in, how soon the
maximum acceleration is reached and the maximum acceleration factor.
Extremely low speed settings provide no acceleration and additionally
decelerate all movement by a constant factor.
.. _ptraccel-low-dpi:
------------------------------------------------------------------------------
Pointer acceleration for low-dpi devices
------------------------------------------------------------------------------
Low-dpi devices are those with a physical resolution of less than 1000 dots
per inch (dpi). The pointer acceleration is adjusted to provide roughly the
same feel for all devices at normal to high speeds. At slow speeds, the
pointer acceleration works on device-units rather than normalized
coordinates (see :ref:`motion_normalization`).
.. figure:: ptraccel-low-dpi.svg
:align: center
Pointer acceleration for low-dpi devices
The image above shows the default pointer acceleration curve for a speed of
0.0 at different DPI settings. A device with low DPI has the acceleration
applied sooner and with a stronger acceleration factor.
.. _ptraccel-touchpad:
------------------------------------------------------------------------------
Pointer acceleration on touchpads
------------------------------------------------------------------------------
Touchpad pointer acceleration uses the same approach as the
:ref:`ptraccel-linear` profile, with a constant deceleration factor applied. The
user expectation of how much a pointer should move in response to finger
movement is different to that of a mouse device, hence the constant
deceleration factor.
.. figure:: ptraccel-touchpad.svg
:align: center
Pointer acceleration curve for touchpads
The image above shows the touchpad acceleration profile in comparison to the
:ref:`ptraccel-linear`. The shape of the curve is identical but vertically squashed.
.. _ptraccel-trackpoint:
------------------------------------------------------------------------------
Pointer acceleration on trackpoints
------------------------------------------------------------------------------
The main difference between trackpoint hardware and mice or touchpads is
that trackpoint speed is a function of pressure rather than moving speed.
But trackpoint hardware is quite varied in how it reacts to user pressure
and unlike other devices it cannot easily be normalized for physical
properties. Measuring pressure objectively across a variety of hardware is
nontrivial. See :ref:`trackpoints` for more details.
The deltas for trackpoints are converted units/ms but there is no common
physical reference point for a unit. Thus, the same pressure on different
trackpoints will generate different speeds and thus different acceleration
behaviors. Additionally, some trackpoints provide the ability to adjust the
sensitivity in hardware by modifying a sysfs file on the serio node. A
higher sensitivity results in higher deltas, thus changing the definition of
what is a unit again.
libinput attempts to normalize unit data to the best of its abilities, see
:ref:`trackpoint_multiplier`. Beyond this, it is not possible to have
consistent behavior across different trackpoint devices.
.. figure:: ptraccel-trackpoint.svg
:align: center
Pointer acceleration curves for trackpoints
The image above shows the trackpoint acceleration profile for the speed in
units/ms.
.. _ptraccel-profile-flat:
------------------------------------------------------------------------------
The flat pointer acceleration profile
------------------------------------------------------------------------------
In a flat profile, the acceleration factor is constant regardless of the
velocity of the pointer and each delta (dx, dy) results in an accelerated delta
(dx * factor, dy * factor). This provides 1:1 movement between the device
and the pointer on-screen.
.. _ptraccel-tablet:
------------------------------------------------------------------------------
Pointer acceleration on tablets
------------------------------------------------------------------------------
Pointer acceleration for relative motion on tablet devices is a flat
acceleration, with the speed setting slowing down or speeding up the pointer
motion by a constant factor. Tablets do not allow for switchable profiles.
.. _ptraccel-profile-custom:
------------------------------------------------------------------------------
The custom acceleration profile
------------------------------------------------------------------------------
libinput supports a user-defined custom acceleration profile, which can be
adjusted for different movement types supported by a device. Movement types
include pointer movement, scrolling, etc. but the set of supported
movement types depends on the device.
The custom pointer acceleration profile gives users full control over the
acceleration behavior at different speeds. libinput exposes
an acceleration function ``f(x)`` where the x axis is the device speed in
device units per millisecond and the y axis is the pointer speed. By
supplying the y axis values for this function, users can control the
behavior of the device.
The user should take into account the native device dpi and screen dpi in
order to achieve the desired behavior/feel.
The custom acceleration function is defined using ``n`` points which are spaced
uniformly along the x axis, starting from 0 and continuing in constant steps.
At least two points must be defined and there is an implementation-defined
limit on how many points may be added.
Thus the points defining the custom function are:
``(0 * step, f[0]), (1 * step, f[1]), ..., ((n-1) * step, f[n-1])``
where ``f`` is a list of ``n`` values defining the output velocity for each
input velocity.
The acceleration factor is defined by the ratio of the output velocity to the
input velocity.
When a velocity value does not lie exactly on those points, a linear
interpolation of the two closest points will be calculated.
When a velocity value is greater than the max point defined, a linear
extrapolation of the two biggest points will be calculated.
the calculation made by libinput: ::
input_delta = device delta units
delta_time = time in ms since last input_delta
input_speed = hypot(input_delta) / delta_time
output_speed = user_custom_function(input_speed)
acceleration_factor = output_speed / input_speed
output_delta = input_delta * acceleration_factor
An example is the curve of ``0.0, 1.0`` with a step of ``1.0``. This curve
is the equivalent of the flat acceleration profile with any input speed ``N``
mapped to the same pointer speed ``N``. The curve ``1.0, 1.0`` neutralizes
any input speed differences and results in a fixed pointer speed.
Another example is the custom acceleration function ``x**2``,
sampling the function at ``4`` points up to
a maximum input speed of ``9`` will give us a custom function with
a step of ``3`` and points ``[0.0, 9.0, 36.0, 81.0]``:
.. figure:: ptraccel-custom.svg
:align: center
More sampled points can be added to improve the accuracy of the user custom
function.
Supported Movement types:
+---------------+---------------------------------+----------------------+
| Movement type | Uses | supported by |
+===============+=================================+======================+
| Fallback | Catch-all default movement type | All devices |
+---------------+---------------------------------+----------------------+
| Motion | Used for pointer motion | All devices |
+---------------+---------------------------------+----------------------+
| Scroll | Used for scroll movement | Mouse, Touchpad |
+---------------+---------------------------------+----------------------+
If a user does not provide the fallback custom acceleration function, a
flat acceleration function is used, i.e. no acceleration.
The fallback acceleration may be used for different types of movements, it is
strongly recommended that this acceleration function is a constant function.
For example, a touchpad has multiple movement types: pointer
movement, scroll movement, zoom movement (pinch), etc. As there is no separate
movement type for zoom yet, zoom movement is accelerated using the Fallback
acceleration function. Pointer movement is accelerated using the Motion
acceleration function, and Scroll movement is accelerated using the Scroll
acceleration function. If no Motion/Scroll acceleration function is set, the
Fallback acceleration function is used.
When using custom acceleration profile, any calls to set the speed have no
effect on the behavior of the custom acceleration function, but any future calls to
get the speed will reflect the requested speed setting.
libinput-1.28.1/doc/user/reporting-bugs.rst000066400000000000000000000406401477265155700207040ustar00rootroot00000000000000.. _reporting_bugs:
==============================================================================
Reporting bugs
==============================================================================
A new bug can be filed here:
https://gitlab.freedesktop.org/libinput/libinput/issues/new
.. hint:: libinput has lots of users but very few developers. It is in your
own interest to follow the steps here precisely to ensure your bug can be
dealt with efficiently.
When reporting bugs against libinput, you will need:
- a reliable :ref:`reproducer ` for the bug
- a :ref:`recording ` of the device while the bug is reproduced
- device-specific information, see
- :ref:`reporting_bugs_touchpad`
- :ref:`reporting_bugs_mouse`
- :ref:`reporting_bugs_keyboard`
- :ref:`reporting_bugs_trackpoint`
- :ref:`reporting_bugs_other`
- the :ref:`libinput version ` you are on.
- the :ref:`configuration options ` you have set
- a `gitlab account `_
Stay technical, on-topic, and keep the description concise.
.. _reporting_bugs_version:
------------------------------------------------------------------------------
Obtaining the libinput version
------------------------------------------------------------------------------
If your libinput version is older than the current stable branch, please try
the latest version. If you run a distribution-provided
libinput, use the package manager to get the **full** package name and
version of libinput, e.g.
- ``rpm -q libinput``
- ``dpkg -s libinput10``
If you run a self-compiled version of libinput provide the git commit you
have built or the tarball name.
As a last resort, use ``libinput --version``
.. _reporting_bugs_reproducer:
------------------------------------------------------------------------------
Reproducing bugs
------------------------------------------------------------------------------
Try to identify the bug by reproducing it reliably. Bugs without a
reliable reproducer will have lowest priority. The more specific a bug
description and reproducer is, the easier it is to fix.
Try to replicate the series of events that lead to the bug being triggered.
Narrow it down until you have a reliable sequence that can trigger the bug.
For the vast majority of bugs you should not take longer than 5 seconds or
three interactions (clicks, touches, taps, ...) with the device to
reproduce. If it takes longer than that, you can narrow it down further.
Once you can reproduce it, use the :ref:`libinput-debug-events` helper
tool::
$> libinput debug-events --verbose
The output is textual and can help identify whether the bug is in libinput
at all. Note that any configuration options you have set must be specified
on the commandline, see the :ref:`libinput-debug-events`
man page. Use the ``--verbose`` flag to get more information about how
libinput processes events.
If the bug cannot be reproduced with the :ref:`libinput-debug-events` helper,
even with the correct configuration options set, it is likely not a bug in
libinput.
.. _reporting_bugs_options:
------------------------------------------------------------------------------
libinput configuration settings
------------------------------------------------------------------------------
libinput has a number of device-specific default configuration settings that
may differ from the ones your desktop environment picks by default. You may
have changed some options in a settings panel or in an the xorg.conf snippet
yourself.
You must provide these options in the bug report, otherwise a developer
reproducing the issue may not be able to do so.
If you are on X11, the current settings can be can be obtained with
``xinput list-props "your device name"``. Use ``xinput list`` to
obtain the device name.
If you are on Wayland, provide a manual summary of the options you have
changed from the default (e.g. "I enabled tap-to-click").
.. _reporting_bugs_touchpad:
------------------------------------------------------------------------------
Reporting touchpad bugs
------------------------------------------------------------------------------
When you file a bug, please attach the following information:
- a virtual description of your input device, see :ref:`libinput-record`.
This is the most important piece of information, do not forget it!
- the output from udevadm info, see :ref:`udev_info`.
- the vendor model number of your laptop (e.g. "Lenovo Thinkpad T440s")
- and the content of ``/sys/class/dmi/id/modalias``.
- run the ``touchpad-edge-detector`` tool (provided by libevdev) and verify
that the ranges and sizes it prints match the touchpad (up to 5mm
difference is ok)
If you are reporting a bug related to button event generation:
- does your touchpad have (separate) physical hardware buttons or is the
whole touchpad clickable?
- Are you using software buttons or clickfinger? See :ref:`clickpad_softbuttons`.
- Do you have :ref:`tapping` enabled?
.. _reporting_bugs_mouse:
------------------------------------------------------------------------------
Reporting mouse bugs
------------------------------------------------------------------------------
When you file a bug, please attach the following information:
- a virtual description of your input device, see :ref:`libinput-record`.
This is the most important piece of information, do not forget it!
- the vendor model number of the device (e.g. "Logitech M325")
- the output from udevadm info, see :ref:`udev_info`.
If the bug is related to the :ref:`speed of the mouse `:
- the resolution of the mouse as specified by the vendor (in DPI)
- the output of the ``mouse-dpi-tool`` (provided by libevdev)
.. _reporting_bugs_keyboard:
------------------------------------------------------------------------------
Reporting keyboard bugs
------------------------------------------------------------------------------
Is your bug related to a keyboard layout? libinput does not handle keyboard
layouts and merely forwards the physical key events. File the bug with your
desktop environment instead (e.g. GNOME, KDE, ...), that's most likely where
the issue is.
When you file a bug, please attach the following information:
- a virtual description of your input device, see :ref:`libinput-record`.
This is the most important piece of information, do not forget it!
.. _reporting_bugs_trackpoint:
------------------------------------------------------------------------------
Reporting trackpoint bugs
------------------------------------------------------------------------------
When you file a bug, please attach the following information:
- a virtual description of your input device, see :ref:`libinput-record`.
This is the most important piece of information, do not forget it!
- the vendor model number of the device (e.g. "Logitech M325")
- the output from udevadm info, see :ref:`udev_info`.
- the sensitivity of the trackpoint if it exists (adjust the event node number as needed): ::
$ cat /sys/class/input/event17/device/device/sensitivity
.. _reporting_bugs_other:
------------------------------------------------------------------------------
All other devices
------------------------------------------------------------------------------
When you file a bug, please attach the following information:
- a virtual description of your input device, see :ref:`libinput-record`.
This is the most important piece of information, do not forget it!
- the vendor model number of the device (e.g. "Sony Plastation3 controller")
.. _udev_info:
------------------------------------------------------------------------------
udev information for the device
------------------------------------------------------------------------------
In many cases, we require the udev properties assigned to the device to
verify whether device-specific quirks were applied. This can be obtained
with ``udevadm info /sys/class/input/eventX``, with the correct event
node for your device. An example output is below: ::
$ udevadm info /sys/class/input/event4
P: /devices/platform/i8042/serio1/input/input5/event4
N: input/event4
E: DEVNAME=/dev/input/event4
E: DEVPATH=/devices/platform/i8042/serio1/input/input5/event4
E: EVDEV_ABS_00=::41
E: EVDEV_ABS_01=::37
E: EVDEV_ABS_35=::41
E: EVDEV_ABS_36=::37
E: ID_INPUT=1
E: ID_INPUT_HEIGHT_MM=66
E: ID_INPUT_TOUCHPAD=1
E: ID_INPUT_WIDTH_MM=97
E: MAJOR=13
E: MINOR=68
E: SUBSYSTEM=input
E: USEC_INITIALIZED=5463031
.. _evemu:
------------------------------------------------------------------------------
Recording devices with evemu
------------------------------------------------------------------------------
.. warning:: Where available, the :ref:`libinput-record` tools should be used instead
of evemu
`evemu-record `_ records the
device capabilities together with the event stream from the kernel. On our
side, this allows us to recreate a virtual device identical to your device
and re-play the event sequence, hopefully triggering the same bug.
evemu-record takes a ``/dev/input/eventX`` event node, but without arguments
it will simply show the list of devices and let you select: ::
$ sudo evemu-record > scroll.evemu
Available devices:
/dev/input/event0: Lid Switch
/dev/input/event1: Sleep Button
/dev/input/event2: Power Button
/dev/input/event3: AT Translated Set 2 keyboard
/dev/input/event4: SynPS/2 Synaptics TouchPad
/dev/input/event5: Video Bus
/dev/input/event6: ELAN Touchscreen
/dev/input/event10: ThinkPad Extra Buttons
/dev/input/event11: HDA Intel HDMI HDMI/DP,pcm=3
/dev/input/event12: HDA Intel HDMI HDMI/DP,pcm=7
/dev/input/event13: HDA Intel HDMI HDMI/DP,pcm=8
/dev/input/event14: HDA Intel PCH Dock Mic
/dev/input/event15: HDA Intel PCH Mic
/dev/input/event16: HDA Intel PCH Dock Headphone
/dev/input/event17: HDA Intel PCH Headphone
/dev/input/event18: Integrated Camera
/dev/input/event19: TPPS/2 IBM TrackPoint
Select the device event number [0-19]:
Select the device that triggers the issue, then reproduce the bug and Ctrl+C
the process. The resulting recording, ("scroll.evemu" in this example) will
contain the sequence required to reproduce the bug. If the bug fails to
reproduce during recording, simply Ctrl+C and restart evemu-record.
Always start the recording from a neutral state, i.e. without any buttons or
keys down, with the position of the device in the neutral position, without
touching the screen/touchpad.
.. note:: The longer the recording, the harder it is to identify the event
sequence triggering the bug. Please keep the event sequence as short
as possible.
To verify that the recording contains the bug, you can replay it on your
device. For example, to replay the sequence recorded in the example above: ::
$ sudo evemu-play /dev/input/event4 < scroll.evemu
If the bug is triggered by replaying on your device, attach the recording to
the bug report.
libinput does not affect the evemu recording. libinput and evemu talk
directly to the kernel's device nodes. An evemu recording is not
influenced by the libinput version or whether a libinput context is
currently active.
.. graphviz:: evemu.gv
.. _fixed_bugs:
------------------------------------------------------------------------------
My bug was closed as fixed, what now?
------------------------------------------------------------------------------
libinput's policy on closing bugs is: once the fix for a given bug is on git
master, the bug is considered fixed and the gitlab issue will be closed
accordingly.
Of course, unless you actually run git master, the bug will continue to
affect you on your local machine. You are most likely running the
distribution's package and you will need to wait until the distribution has
updated its package accordingly.
.. warning:: Do not re-open a bug just because it hasn't trickled down to
your distribution's package version yet.
Whether the bug fix ends up in your distribution depends on a number of
things. Any given bug fix **may** be cherry-picked into the current stable
branch, depending on its severity, impact, and likelihood to cause
regressions. Once cherry-picked it will land in the next stable branch
release. These are usually a few weeks apart.
.. warning:: Do not re-open a bug because it wasn't picked into a stable branch
release or because your distribution didn't update to the latest stable
branch release.
Stable branches are usually discontinued when the next release comes out.
Your distribution may pick a patch up immediately and ship the fix
even before the next stable branch update is released. For example, Fedora
does this frequently.
.. hint:: If a bug needs to be fixed urgently, file a bug in your
distribution's bug tracker.
Patches on git master will end up in the next libinput release. Once your
distribution updates to that release, your local libinput version will
contain the fix.
.. warning:: Do not re-open a bug because your distribution didn't update to
the release.
You can always run libinput from git master (see :ref:`building_libinput`).
Even while in development, libinput is very stable so this option isn't as
scary as it may sounds.
.. _reporting_bugs_reopen:
..............................................................................
When is it ok to re-open a fixed bug?
..............................................................................
Any time the bug was considered fixed but it turns out that the fix is
insufficient and/or causes a regression.
However, if the regression is in behavior unrelated to the fix itself it is
usually better to file a new bug to reduce the noise. For example, if a fix
to improve tapping breaks two-finger scrolling behavior, you should file a
new bug but reference the original bug.
.. _reporting_bugs_tags:
------------------------------------------------------------------------------
Gitlab issue tracker tags
------------------------------------------------------------------------------
The gitlab issue tracker allows developers to add tags to bugs to classify
them.
- **being worked on**: someone is currently working on this feature. This
tag is used for features that will take a long time to implement fully and
prevents others from having to duplicate the work. Do reach out and ask if
help and/or further testing is needed.
- **bug**: issue is confirmed to be a bug
- **cantfix**: for technical reasons, this bug cannot be fixed, or at least
it cannot be fixed in libinput.
- **enhancement**: this issue describes a future feature, not a bug.
- **help needed**: this issue requires someone outside the libinput core
developer team to implement it. It is unlikely to be implemented
without someone stepping up to do the work. If you do see this tag, do ask
for guidance on how to implement it.
- **hw issue**: an issue that affects a specific device and is a hardware
bug, not a software bug. Often these needs to be worked around in libinput
but there are cases where a hw issue ends up as *cantfix*.
- **janitor**: a cleanup task that does not substantially affect how
libinput works. These are usually good bugs for newcomers to start on.
- **kernel**: this issue is a kernel bug, not a libinput bug. Often closed
as *cantfix* of *wontfix* as we wait for the kernel to address the issue
instead.
- **needs triage**: bug has not yet been confirmed by a core developer.
- **not our bug**: the issue is in some other component of the stack and
needs to be addressed there.
- **please test**: a fix is available but not yet merged and should be
tested by the reporter or others affected by the issue.
- **quirk**: this is issue needs :ref:`device-quirks` to be fixed
- **regression**: the issue is a regression to previous versions of
libinput. These issues get priorities.
- **waiting on reporter**: some more information is required from the
reporter and the issue cannot be fixed until the issue has been provided.
Where a bug is left in this state for too long, the bug will be closed as
*cantfix*.
- **wontfix**: this issue will not get fixed. This tag is usually assigned
to feature requests that are outside the scope of libinput or would put an
unreasonable maintenance burdern on the maintainers.
These tags are high-level categories only, always look for the comments in
the issue to get further details.
libinput-1.28.1/doc/user/scrolling.rst000066400000000000000000000172361477265155700177360ustar00rootroot00000000000000.. _scrolling:
==============================================================================
Scrolling
==============================================================================
libinput supports three different types of scrolling methods:
:ref:`twofinger_scrolling`, :ref:`edge_scrolling` and
:ref:`button_scrolling`. Some devices support multiple methods, though only
one can be enabled at a time. As a general overview:
- touchpad devices with physical buttons below the touchpad support edge and
two-finger scrolling
- touchpad devices without physical buttons (:ref:`ClickPads `)
support two-finger scrolling only
- pointing sticks provide on-button scrolling by default
- mice and other pointing devices support on-button scrolling but it is not
enabled by default
A device may differ from the above based on its capabilities. See
**libinput_device_config_scroll_set_method()** for documentation on how to
switch methods and **libinput_device_config_scroll_get_methods()** for
documentation on how to query a device for available scroll methods.
.. _horizontal_scrolling:
------------------------------------------------------------------------------
Horizontal scrolling
------------------------------------------------------------------------------
Scroll movements provide vertical and horizontal directions, each
scroll event contains both directions where applicable, see
**libinput_event_pointer_get_axis_value()**. libinput does not provide separate
toggles to enable or disable horizontal scrolling. Instead, horizontal
scrolling is always enabled. This is intentional, libinput does not have
enough context to know when horizontal scrolling is appropriate for a given
widget. The task of filtering horizontal movements is up to the caller.
.. _twofinger_scrolling:
------------------------------------------------------------------------------
Two-finger scrolling
------------------------------------------------------------------------------
The default on two-finger capable touchpads (almost all modern touchpads are
capable of detecting two fingers). Scrolling is triggered by two fingers
being placed on the surface of the touchpad, then moving those fingers
vertically or horizontally.
.. figure:: twofinger-scrolling.svg
:align: center
Vertical and horizontal two-finger scrolling
For scrolling to trigger, a built-in distance threshold has to be met, but once
engaged, any movement will scroll. In other words: to start scrolling, a
sufficiently large movement is required; once scrolling, tiny amounts of
movements will translate into tiny scroll movements.
Scrolling in both directions at once is possible by meeting the required
distance thresholds to enable each direction separately.
When a scroll gesture remains close to perfectly straight, it will be held to
exact 90-degree angles; but if the gesture moves diagonally, it is free to
scroll in any direction.
Two-finger scrolling requires the touchpad to track both touch points with
reasonable precision. Unfortunately, some so-called "semi-mt" touchpads can
only track the bounding box of the two fingers rather than the actual
position of each finger. In addition, that bounding box usually suffers from
a low resolution, causing jumpy movement during two-finger scrolling.
libinput does not provide two-finger scrolling on those touchpads.
.. _edge_scrolling:
------------------------------------------------------------------------------
Edge scrolling
------------------------------------------------------------------------------
On some touchpads, edge scrolling is available, triggered by moving a single
finger along the right edge (vertical scroll) or bottom edge (horizontal
scroll).
.. figure:: edge-scrolling.svg
:align: center
Vertical and horizontal edge scrolling
Due to the layout of the edges, diagonal scrolling is not possible. The
behavior of edge scrolling using both edges at the same time is undefined.
Edge scrolling overlaps with :ref:`clickpad_softbuttons`. A physical click on
a clickpad ends scrolling.
.. _button_scrolling:
------------------------------------------------------------------------------
On-Button scrolling
------------------------------------------------------------------------------
On-button scrolling converts the motion of a device into scroll events while
a designated button is held down. For example, Lenovo devices provide a
`pointing stick `_ that emulates
scroll events when the trackstick's middle mouse button is held down.
.. note:: On-button scrolling is enabled by default for pointing sticks. This
prevents middle-button dragging; all motion events while the middle
button is down are converted to scroll events.
.. figure:: button-scrolling.svg
:align: center
Button scrolling
The button may be changed with
**libinput_device_config_scroll_set_button()** but must be on the same device as
the motion events. Cross-device scrolling is not supported but
for one exception: libinput's :ref:`t440_support` enables the use of the middle
button for button scrolling (even when the touchpad is disabled).
If the scroll button lock is enabled (see
**libinput_device_config_scroll_set_button_lock()**), the button does not
need to be held down. Pressing and releasing the button once enables the
button lock, the button is now considered logically held down. Pressing and
releasing the button a second time logically releases the button. While the
button is logically held down, motion events are converted to scroll events.
.. _scroll_sources:
------------------------------------------------------------------------------
Scroll sources
------------------------------------------------------------------------------
.. note:: Scroll sources are deprecated with libinput 1.19. The scroll
source is now encoded in the event type.
libinput provides a pointer axis *source* for each scroll event. The
source can be obtained with the **libinput_event_pointer_get_axis_source()**
function and is one of **wheel**, **finger**, or **continuous**. The source
information lets a caller decide when to implement kinetic scrolling.
Usually, a caller will process events of source wheel as they come in.
For events of source finger a caller should calculate the velocity of the
scroll motion and upon finger release start a kinetic scrolling motion (i.e.
continue executing a scroll according to some friction factor).
libinput expects the caller to be in charge of widget handling, the source
information is thus enough to provide kinetic scrolling on a per-widget
basis. A caller should cancel kinetic scrolling when the pointer leaves the
current widget or when a key is pressed.
See the **libinput_event_pointer_get_axis_source()** for details on the
behavior of each scroll source.
See also http://who-t.blogspot.com.au/2015/03/libinput-scroll-sources.html
.. _natural_scrolling:
------------------------------------------------------------------------------
Natural scrolling vs. traditional scrolling
------------------------------------------------------------------------------
Natural scrolling is the term (probably) coined by Apple for matching
the motion of the scroll device with the direction of the **content**.
In traditional scrolling, moving the wheel down causes the scroll bar
indicators to move down and the content to move up. In natural scrolling,
moving the wheel down causes the content to move down and the scroll bar
indicators to move up. This method of scrolling matches the interaction
with content on touch screens where a movement down also moves the content
down.
libinput supports natural scrolling for all its scroll methods; it can
be enabled with the
**libinput_device_config_scroll_set_natural_scroll_enabled()** function.
libinput-1.28.1/doc/user/seats.rst000066400000000000000000000072231477265155700170540ustar00rootroot00000000000000.. _seats:
==============================================================================
Seats
==============================================================================
Each device in libinput is assigned to one seat.
A seat has two identifiers, the physical name and the logical name. The
physical name is summarized as the list of devices a process on the same
physical seat has access to. The logical seat name is the seat name for a
logical group of devices. A compositor may use that to create additional
seats as independent device sets. Alternatively, a compositor may limit
itself to a single logical seat, leaving a second compositor to manage
devices on the other logical seats.
.. _seats_overview:
------------------------------------------------------------------------------
Overview
------------------------------------------------------------------------------
Below is an illustration of how physical seats and logical seats interact:
.. graphviz:: seats-sketch.gv
The devices "Foo", "Bar" and "Spam" share the same physical seat and are
thus available in the same libinput context. Only "Foo" and "Bar" share the
same logical seat. The device "Egg" is not available in the libinput context
associated with the physical seat 0.
The above graph is for illustration purposes only. In libinput, a struct
**libinput_seat** comprises both physical seat and logical seat. From a
caller's point-of-view the above device layout is presented as:
.. graphviz:: seats-sketch-libinput.gv
Thus, devices "Foo" and "Bar" both reference the same struct
**libinput_seat**, all other devices reference their own respective seats.
.. _seats_and_features:
------------------------------------------------------------------------------
The effect of seat assignment
------------------------------------------------------------------------------
A logical set is interpreted as a group of devices that usually belong to a
single user that interacts with a computer. Thus, the devices are
semantically related. This means for devices within the same logical seat:
- if the same button is pressed on different devices, the button should only
be considered logically pressed once.
- if the same button is released on one device, the button should be
considered logically down if still down on another device.
- if two different buttons or keys are pressed on different devices, the
logical state is that of both buttons/keys down.
- if a button is pressed on one device and another device moves, this should
count as dragging.
- if two touches are down on different devices, the logical state is that of
two touches down.
libinput provides functions to aid with the above:
**libinput_event_pointer_get_seat_button_count()**,
**libinput_event_keyboard_get_seat_key_count()**, and
**libinput_event_touch_get_seat_slot()**.
Internally, libinput counts devices within the same logical seat as related.
Cross-device features only activate if all required devices are in the same
logical seat. For example, libinput will only activate the top software
buttons (see :ref:`t440_support`) if both trackstick and touchpad are assigned
to the same logical seat.
.. _changing_seats:
------------------------------------------------------------------------------
Changing seats
------------------------------------------------------------------------------
A device may change the logical seat it is assigned to at runtime with
**libinput_device_set_seat_logical_name()**. The physical seat is immutable and
may not be changed.
Changing the logical seat for a device is equivalent to unplugging the
device and plugging it back in with the new logical seat. No device state
carries over across a logical seat change.
libinput-1.28.1/doc/user/svg/000077500000000000000000000000001477265155700157765ustar00rootroot00000000000000libinput-1.28.1/doc/user/svg/button-debouncing-wave-diagram.svg000066400000000000000000003225771477265155700245270ustar00rootroot00000000000000
libinput-1.28.1/doc/user/svg/button-scrolling.svg000066400000000000000000000417641477265155700220400ustar00rootroot00000000000000
libinput-1.28.1/doc/user/svg/clickfinger-distance.svg000066400000000000000000000136121477265155700225720ustar00rootroot00000000000000
libinput-1.28.1/doc/user/svg/clickfinger.svg000066400000000000000000000371671477265155700210150ustar00rootroot00000000000000
libinput-1.28.1/doc/user/svg/edge-scrolling.svg000066400000000000000000000160361477265155700214230ustar00rootroot00000000000000
libinput-1.28.1/doc/user/svg/gesture-2fg-ambiguity.svg000066400000000000000000000707671477265155700226620ustar00rootroot00000000000000
libinput-1.28.1/doc/user/svg/palm-detection.svg000066400000000000000000000170551477265155700214340ustar00rootroot00000000000000
libinput-1.28.1/doc/user/svg/pinch-gestures-softbuttons.svg000066400000000000000000000407231477265155700240550ustar00rootroot00000000000000
libinput-1.28.1/doc/user/svg/pinch-gestures.svg000066400000000000000000001046261477265155700214700ustar00rootroot00000000000000
libinput-1.28.1/doc/user/svg/ptraccel-custom.svg000066400000000000000000000665561477265155700216460ustar00rootroot00000000000000
libinput-1.28.1/doc/user/svg/ptraccel-linear.svg000066400000000000000000001317401477265155700215720ustar00rootroot00000000000000
libinput-1.28.1/doc/user/svg/ptraccel-low-dpi.svg000066400000000000000000013611721477265155700217000ustar00rootroot00000000000000
libinput-1.28.1/doc/user/svg/ptraccel-touchpad.svg000066400000000000000000001462641477265155700221360ustar00rootroot00000000000000
libinput-1.28.1/doc/user/svg/ptraccel-trackpoint.svg000066400000000000000000000343151477265155700224760ustar00rootroot00000000000000
libinput-1.28.1/doc/user/svg/software-buttons-conditions.svg000066400000000000000000000246431477265155700242250ustar00rootroot00000000000000
libinput-1.28.1/doc/user/svg/software-buttons-thumbpress.svg000066400000000000000000000133651477265155700242470ustar00rootroot00000000000000
libinput-1.28.1/doc/user/svg/software-buttons-visualized.svg000066400000000000000000000146641477265155700242350ustar00rootroot00000000000000
libinput-1.28.1/doc/user/svg/software-buttons.svg000066400000000000000000000224331477265155700220510ustar00rootroot00000000000000
libinput-1.28.1/doc/user/svg/swipe-gestures.svg000066400000000000000000000546701477265155700215210ustar00rootroot00000000000000
libinput-1.28.1/doc/user/svg/tablet-area.svg000066400000000000000000000234461477265155700207110ustar00rootroot00000000000000
libinput-1.28.1/doc/user/svg/tablet-axes.svg000066400000000000000000000632271477265155700207420ustar00rootroot00000000000000
libinput-1.28.1/doc/user/svg/tablet-cintiq24hd-modes.svg000066400000000000000000000520611477265155700230520ustar00rootroot00000000000000
libinput-1.28.1/doc/user/svg/tablet-interfaces.svg000066400000000000000000000365031477265155700221220ustar00rootroot00000000000000
libinput-1.28.1/doc/user/svg/tablet-intuos-modes.svg000066400000000000000000000355221477265155700224250ustar00rootroot00000000000000
libinput-1.28.1/doc/user/svg/tablet-left-handed.svg000066400000000000000000000536541477265155700221600ustar00rootroot00000000000000
libinput-1.28.1/doc/user/svg/tablet-out-of-bounds.svg000066400000000000000000000263041477265155700224760ustar00rootroot00000000000000
libinput-1.28.1/doc/user/svg/tablet.svg000066400000000000000000000214441477265155700177770ustar00rootroot00000000000000
libinput-1.28.1/doc/user/svg/tap-n-drag.svg000066400000000000000000001346131477265155700204610ustar00rootroot00000000000000
libinput-1.28.1/doc/user/svg/thumb-detection.svg000066400000000000000000000144201477265155700216130ustar00rootroot00000000000000
libinput-1.28.1/doc/user/svg/top-software-buttons.svg000066400000000000000000000317241477265155700226540ustar00rootroot00000000000000
libinput-1.28.1/doc/user/svg/touchscreen-gestures.svg000066400000000000000000000673061477265155700227140ustar00rootroot00000000000000
libinput-1.28.1/doc/user/svg/trackpoint-delta-illustration.svg000066400000000000000000000216771477265155700245300ustar00rootroot00000000000000
libinput-1.28.1/doc/user/svg/twofinger-scrolling.svg000066400000000000000000000266351477265155700225310ustar00rootroot00000000000000
libinput-1.28.1/doc/user/switches.rst000066400000000000000000000055301477265155700175650ustar00rootroot00000000000000.. _switches:
==============================================================================
Switches
==============================================================================
libinput supports the lid and tablet-mode switches. Unlike button events
that come in press and release pairs, switches are usually toggled once and
left at the setting for an extended period of time.
Only some switches are handled by libinput, see **libinput_switch** for a
list of supported switches. Switch events are exposed to the caller, but
libinput may handle some switch events internally and enable or disable
specific features based on a switch state.
The order of switch events is guaranteed to be correct, i.e., a switch will
never send consecutive switch on, or switch off, events.
.. _switches_lid:
------------------------------------------------------------------------------
Lid switch handling
------------------------------------------------------------------------------
Where available, libinput listens to devices providing a lid switch.
The evdev event code ``EV_SW`` ``SW_LID`` is provided as
**LIBINPUT_SWITCH_LID**. If devices with a lid switch have a touchpad device,
the device is disabled while the lid is logically closed. This is to avoid
ghost touches that can be caused by interference with touchpads and the
closed lid. The touchpad is automatically re-enabled whenever the lid is
opened.
This handling of lid switches is transparent to the user, no notifications
are sent and the device appears as enabled at all times.
On some devices, the device's lid state does not always reflect the physical
state and the lid state may report as closed even when the lid is physically
open. libinput employs some heuristics to detect user input (specifically
typing) to re-enable the touchpad on those devices. Where input is detected,
libinput updates the lid status of the kernel device so other consumers of
the kernel events also get the accurate state.
.. _switches_tablet_mode:
------------------------------------------------------------------------------
Tablet mode switch handling
------------------------------------------------------------------------------
Where available, libinput listens to devices providing a tablet mode switch.
This switch is usually triggered on devices that can switch between a normal
laptop layout and a tablet-like layout. One example for such a device is the
Lenovo Yoga.
The event sent by the kernel is ``EV_SW`` ``SW_TABLET_MODE`` and is provided as
**LIBINPUT_SWITCH_TABLET_MODE**. When the device switches to tablet mode,
the touchpad and internal keyboard are disabled. If a trackpoint exists,
it is disabled too. The input devices are automatically re-enabled whenever
tablet mode is disengaged.
This handling of tablet mode switches is transparent to the user, no
notifications are sent and the device appears as enabled at all times.
libinput-1.28.1/doc/user/t440-support.rst000066400000000000000000000112201477265155700201320ustar00rootroot00000000000000.. _t440_support:
==============================================================================
Lenovo \*40 series touchpad support
==============================================================================
The Lenovo \*40 series emulates trackstick buttons on the top part of the
touchpads.
.. _t440_support_overview:
------------------------------------------------------------------------------
Overview
------------------------------------------------------------------------------
The Lenovo \*40 series introduced a new type of touchpad. Previously, all
laptops had a separate set of physical buttons for the
`trackstick `_. This
series removed these buttons, relying on a software emulation of the top
section of the touchpad. This is visually marked on the trackpad itself,
and clicks can be triggered by pressing the touchpad down with a finger in
the respective area:
.. figure:: top-software-buttons.svg
:align: center
Left, right and middle-button click with top software button areas
This page only covers the top software buttons, the bottom button behavior
is covered in :ref:`Clickpad software buttons `.
Clickpads with a top button area are marked with the
`INPUT_PROP_TOPBUTTONPAD `_
property.
.. _t440_support_btn_size:
------------------------------------------------------------------------------
Size of the buttons
------------------------------------------------------------------------------
The size of the buttons matches the visual markings on this touchpad.
The width of the left and right buttons is approximately 42% of the
touchpad's width, the middle button is centered and assigned 16% of the
touchpad width.
The line of the buttons is 5mm from the top edge of the touchpad,
measurements of button presses showed that the size of the buttons needs to
be approximately 10mm high to work reliable (especially when using the
thumb to press the button).
.. _t440_support_btn_behavior:
------------------------------------------------------------------------------
Button behavior
------------------------------------------------------------------------------
Movement in the top button area does not generate pointer movement. These
buttons are not replacement buttons for the bottom button area but have
their own behavior. Semantically attached to the trackstick device, libinput
re-routes events from these buttons to appear through the trackstick device.
.. graphviz::
digraph top_button_routing
{
rankdir="LR";
node [shape="box";]
trackstick [label="trackstick kernel device"];
touchpad [label="touchpad kernel device"];
subgraph cluster0 {
bgcolor = floralwhite
label = "libinput"
libinput_ts [label="trackstick libinput_device"
style=filled
fillcolor=white];
libinput_tp [label="touchpad libinput_device"
style=filled
fillcolor=white];
libinput_tp -> libinput_ts [constraint=false
color="red4"];
}
trackstick -> libinput_ts [arrowhead="none"]
touchpad -> libinput_tp [color="red4"]
events_tp [label="other touchpad events"];
events_topbutton [label="top software button events"];
libinput_tp -> events_tp [arrowhead="none"]
libinput_ts -> events_topbutton [color="red4"]
}
The top button areas work even if the touchpad is disabled but will be
disabled when the trackstick device is disabled. If the finger starts inside
the top area and moves outside the button area the finger is treated as dead
and must be lifted to generate future buttons. Likewise, movement into the
top button area does not trigger button events, a click has to start inside
this area to take effect.
.. _t440_support_identification:
------------------------------------------------------------------------------
Kernel support
------------------------------------------------------------------------------
The firmware on the first generation of touchpads providing top software
buttons is buggy and announces wrong ranges.
`Kernel patches `_ are required;
these fixes are available in kernels 3.14.1, 3.15 and later but each
touchpad needs a separate fix.
The October 2014 refresh of these laptops do not have this firmware bug
anymore and should work without per-device patches, though
`this kernel commit `_
is required.
For a complete list of supported touchpads check
`the kernel source `_
(search for "topbuttonpad_pnp_ids").
libinput-1.28.1/doc/user/tablet-debugging.rst000066400000000000000000000035231477265155700211400ustar00rootroot00000000000000.. _tablet-debugging:
==============================================================================
Debugging tablet issues
==============================================================================
.. _tablet-capabilities:
------------------------------------------------------------------------------
Required tablet capabilities
------------------------------------------------------------------------------
To handle a tablet correctly, libinput requires a set of capabilities
on the device. When these capabilities are missing, libinput ignores the
device and prints an error to the log. This error messages reads
::
missing tablet capabilities: xy pen btn-stylus resolution. Ignoring this device.
or in older versions of libinput simply:
::
libinput bug: device does not meet tablet criteria. Ignoring this device.
When a tablet is rejected, it is usually possible to verify the issue with
the ``libinput record`` tool.
- **xy** indicates that the tablet is missing the ``ABS_X`` and/or ``ABS_Y``
axis. This indicates that the device is mislabelled and the udev tag
``ID_INPUT_TABLET`` is applied to a device that is not a tablet.
A bug should be filed against `systemd `__.
- **pen** or **btn-stylus** indicates that the tablet does not have the
``BTN_TOOL_PEN`` or ``BTN_STYLUS`` bit set. libinput requires either or both
of them to be present. This indicates a bug in the kernel driver
or the HID descriptors of the device.
- **resolution** indicates that the device does not have a resolution set
for the x and y axes. This can be fixed with a hwdb entry, locate and read
the `60-evdev.hwdb
`__ file
on your machine and file a pull request with the fixes against
`systemd `__.
libinput-1.28.1/doc/user/tablet-support.rst000066400000000000000000000565061477265155700207320ustar00rootroot00000000000000.. _tablet-support:
==============================================================================
Tablet support
==============================================================================
This page provides details about the graphics tablet
support in libinput. Note that the term "tablet" in libinput refers to
graphics tablets only (e.g. Wacom Intuos), not to tablet devices like the
Apple iPad.
.. figure:: tablet.svg
:align: center
Illustration of a graphics tablet
.. _tablet-tools:
------------------------------------------------------------------------------
Pad buttons vs. tablet tools
------------------------------------------------------------------------------
Most tablets provide two types of devices. The physical tablet often
provides a number of buttons and a touch ring or strip. Interaction on the
drawing surface of the tablet requires a tool, usually in the shape of a
stylus. The libinput interface exposed by devices with the
**LIBINPUT_DEVICE_CAP_TABLET_TOOL** capability applies only to events generated
by tools.
Buttons, rings or strips on the physical tablet hardware (the "pad") are
exposed by devices with the **LIBINPUT_DEVICE_CAP_TABLET_PAD** capability.
Pad events do not require a tool to be in proximity. Note that both
capabilities may exist on the same device though usually they are split
across multiple kernel devices.
.. figure:: tablet-interfaces.svg
:align: center
Difference between Pad and Tool buttons
Touch events on the tablet integrated into a screen itself are exposed
through the **LIBINPUT_DEVICE_CAP_TOUCH** capability. Touch events on a
standalone tablet are exposed through the **LIBINPUT_DEVICE_CAP_POINTER**
capability. In both cases, the kernel usually provides a separate event
node for the touch device, resulting in a separate libinput device.
See **libinput_device_get_device_group()** for information on how to associate
the touch part with other devices exposed by the same physical hardware.
.. _tablet-tip:
------------------------------------------------------------------------------
Tool tip events vs. tool button events
------------------------------------------------------------------------------
The primary use of a tablet tool is to draw on the surface of the tablet.
When the tool tip comes into contact with the surface, libinput sends an
event of type **LIBINPUT_EVENT_TABLET_TOOL_TIP**, and again when the tip
ceases contact with the surface.
Tablet tools may send button events; these are exclusively for extra buttons
unrelated to the tip. A button event is independent of the tip and can while
the tip is down or up.
Some tablet tools' pressure detection is too sensitive, causing phantom
touches when the user only slightly brushes the surfaces. For example, some
tools are capable of detecting 1 gram of pressure.
libinput uses a device-specific pressure threshold to determine when the tip
is considered logically down. As a result, libinput may send a nonzero
pressure value while the tip is logically up. Most application can and
should ignore pressure information until they receive the event of type
**LIBINPUT_EVENT_TABLET_TOOL_TIP**. Applications that require extremely
fine-grained pressure sensitivity should use the pressure data instead of
the tip events to determine a logical tip down state and treat the tip
events like axis events otherwise.
Note that the pressure threshold to trigger a logical tip event may be zero
on some devices. On tools without pressure sensitivity, determining when a
tip is down is device-specific.
.. _tablet-relative-motion:
------------------------------------------------------------------------------
Relative motion for tablet tools
------------------------------------------------------------------------------
libinput calculates the relative motion vector for each event and converts
it to the same coordinate space that a normal mouse device would use. For
the caller, this means that the delta coordinates returned by
**libinput_event_tablet_tool_get_dx()** and
**libinput_event_tablet_tool_get_dy()** can be used identical to the delta
coordinates from any other pointer event. Any resolution differences between
the x and y axes are accommodated for, a delta of N/N represents a 45 degree
diagonal move on the tablet.
The delta coordinates are available for all tablet events, it is up to the
caller to decide when a tool should be used in relative mode. It is
recommended that mouse and lens cursor tool default to relative mode and
all pen-like tools to absolute mode.
If a tool in relative mode must not use pointer acceleration, callers
should use the absolute coordinates returned by
**libinput_event_tablet_tool_get_x()** and libinput_event_tablet_tool_get_y()
and calculate the delta themselves. Callers that require exact physical
distance should also use these functions to calculate delta movements.
.. _tablet-axes:
------------------------------------------------------------------------------
Special axes on tablet tools
------------------------------------------------------------------------------
A tablet tool usually provides additional information beyond x/y positional
information and the tip state. A tool may provide the distance to the tablet
surface and the pressure exerted on the tip when in contact. Some tablets
additionally provide tilt information along the x and y axis.
.. figure:: tablet-axes.svg
:align: center
Illustration of the distance, pressure and tilt axes
The granularity and precision of the distance and pressure axes varies
between tablet devices and cannot usually be mapped into a physical unit.
libinput normalizes distance and pressure into the [0, 1] range.
While the normalization range is identical for these axes, a caller should
not interpret identical values as identical across axes, i.e. a value v1 on
the distance axis has no relation to the same value v1 on the pressure axis.
The tilt axes provide the angle in degrees between a vertical line out of
the tablet and the top of the stylus. The angle is measured along the x and
y axis, respectively, a positive tilt angle thus means that the stylus' top
is tilted towards the logical right and/or bottom of the tablet.
.. _tablet-fake-proximity:
------------------------------------------------------------------------------
Handling of proximity events
------------------------------------------------------------------------------
libinput's **LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY** events notify a caller
when a tool comes into sensor range or leaves the sensor range. On some
tools this range does not represent the physical range but a reduced
tool-specific logical range. If the range is reduced, this is done
transparent to the caller.
For example, the Wacom mouse and lens cursor tools are usually
used in relative mode, lying flat on the tablet. Movement typically follows
the interaction normal mouse movements have, i.e. slightly lift the tool and
place it in a separate location. The proximity detection on Wacom
tablets however extends further than the user may lift the mouse, i.e. the
tool may not be lifted out of physical proximity. For such tools, libinput
provides software-emulated proximity.
Events from the pad do not require proximity, they may be sent any time.
.. _tablet-pressure-offset:
------------------------------------------------------------------------------
Pressure offset on worn-out tools
------------------------------------------------------------------------------
When a tool is used for an extended period it can wear down physically. A
worn-down tool may never return a zero pressure value. Even when hovering
above the surface, the pressure value returned by the tool is nonzero,
creating a fake surface touch and making interaction with the tablet less
predictable.
libinput automatically detects pressure offsets and rescales the remaining
pressure range into the available range, making pressure-offsets transparent
to the caller. A tool with a pressure offset will thus send a 0 pressure
value for the detected offset and nonzero pressure values for values higher
than that offset.
Some limitations apply to avoid misdetection of pressure offsets,
specifically:
- pressure offset is only detected on proximity in, and if a device is
capable of detection distances,
- pressure offset is only detected if the distance between the tool and the
tablet is high enough,
- pressure offset is only used if it is 50% or less of the pressure range
available to the tool. A pressure offset higher than 50% indicates either
a misdetection or a tool that should be replaced, and
- if a pressure value less than the current pressure offset is seen, the
offset resets to that value.
Pressure offsets are not detected on **LIBINPUT_TABLET_TOOL_TYPE_MOUSE**
and **LIBINPUT_TABLET_TOOL_TYPE_LENS** tools.
.. _tablet-pressure-range:
------------------------------------------------------------------------------
Custom tablet tool pressure ranges
------------------------------------------------------------------------------
On tablets supporting pressure, libinput provides that hardware pressure as
a logical range of ``0.0`` up to ``1.0`` for the maximum supported pressure.
By default, the hardware range thus maps into the following logical range::
hw minimum hw maximum
hw range: |------|-----------------------------------|
logical range: |----|-----------------------------------|
0.0 | 1.0
Tip
Note that libinput always has some built-in thresholds to filter out erroneous
touches with near-zero pressure but otherwise the hardware range maps as-is
into the logical range. The :ref:`tip event ` threshold is defined
within this range.
For some use-cases the full hardware range is not suitable, it may require either
too light a pressure for the user to interact or it may require too hard a
pressure before the logical maximum is reached. libinput provides
the **libinput_tablet_tool_config_pressure_range_set()** function that allows
reducing the usable range of the tablet::
hw minimum hw maximum
hw range: |----------|-------------------------------|
adjusted range: |------|---------------------|
logical range: |----|---------------------|
0.0 | 1.0
Tip
A reduced range as shown above will result in
- all hw pressure below the new minimum to register as logical pressure ``0.0``
- all hw pressure above the new maximum to register as logical pressure ``1.0``
- the tip event threshold to be relative to the new minimum
In other words, adjusting the pressure range of a tablet tool is equivalent to
reducing the hardware range of said tool. Note that where a custom pressure
range is set, detection of :ref:`tablet-pressure-offset` is disabled.
.. _tablet-serial-numbers:
------------------------------------------------------------------------------
Tracking unique tools
------------------------------------------------------------------------------
Some tools provide hardware information that enables libinput to uniquely
identify the physical device. For example, tools compatible with the Wacom
Intuos 4, Intuos 5, Intuos Pro and Cintiq series are uniquely identifiable
through a serial number. libinput does not specify how a tool can be
identified uniquely, a caller should use **libinput_tablet_tool_is_unique()** to
check if the tool is unique.
libinput creates a struct libinput_tablet_tool on the first proximity in of
this tool. By default, this struct is destroyed on proximity out and
re-initialized on the next proximity in. If a caller keeps a reference to
the tool by using **libinput_tablet_tool_ref()** libinput re-uses this struct
whenever that same physical tool comes into proximity on any tablet
recognized by libinput. It is possible to attach tool-specific virtual state
to the tool. For example, a graphics program such as the GIMP may assign a
specific color to each tool, allowing the artist to use the tools like
physical pens of different color. In multi-tablet setups it is also
possible to track the tool across devices.
If the tool does not have a unique identifier, libinput creates a single
struct libinput_tablet_tool per tool type on each tablet the tool is used
on.
.. _tablet-tool-types:
------------------------------------------------------------------------------
Vendor-specific tablet tool types
------------------------------------------------------------------------------
libinput supports a number of high-level tool types that describe the
general interaction expected with the tool. For example, a user would expect
a tool of type **LIBINPUT_TABLET_TOOL_TYPE_PEN** to interact with a
graphics application taking pressure and tilt into account. The default
virtual tool assigned should be a drawing tool, e.g. a virtual pen or brush.
A tool of type **LIBINPUT_TABLET_TOOL_TYPE_ERASER** would normally be
mapped to an eraser-like virtual tool. See **libinput_tablet_tool_type**
for the list of all available tools.
Vendors may provide more fine-grained information about the tool in use by
adding a hardware-specific tool ID. libinput provides this ID to the caller
with **libinput_tablet_tool_get_tool_id()** but makes no promises about the
content or format of the ID.
libinput currently supports Wacom-style tool IDs as provided on the Wacom
Intuos 3, 4, 5, Wacon Cintiq and Wacom Intuos Pro series. The tool ID can
be used to distinguish between e.g. a Wacom Classic Pen or a Wacom Pro Pen.
It is the caller's responsibility to interpret the tool ID.
.. _tablet-bounds:
------------------------------------------------------------------------------
Out-of-bounds motion events
------------------------------------------------------------------------------
Some tablets integrated into a screen (e.g. Wacom Cintiq 24HD, 27QHD and
13HD series, etc.) have a sensor larger than the display area. libinput uses
the range advertised by the kernel as the valid range unless device-specific
quirks are present. Events outside this range will produce coordinates that
may be negative or larger than the tablet's width and/or height. It is up to
the caller to ignore these events.
.. figure:: tablet-out-of-bounds.svg
:align: center
Illustration of the out-of-bounds area on a tablet
In the image above, the display area is shown in black. The red area around
the display illustrates the sensor area that generates input events. Events
within this area will have negative coordinate or coordinates larger than
the width/height of the tablet.
If events outside the logical bounds of the input area are scaled into a
custom range with **libinput_event_tablet_tool_get_x_transformed()** and
**libinput_event_tablet_tool_get_y_transformed()** the resulting value may be
less than 0 or larger than the upper range provided. It is up to the caller
to test for this and handle or ignore these events accordingly.
.. _tablet-pad-buttons:
------------------------------------------------------------------------------
Tablet pad button numbers
------------------------------------------------------------------------------
Tablet Pad buttons are numbered sequentially, starting with button 0. Thus
button numbers returned by **libinput_event_tablet_pad_get_button_number()**
have no semantic meaning, a notable difference to the button codes returned
by other libinput interfaces (e.g. **libinput_event_tablet_tool_get_button()**).
The Linux kernel requires all input events to have semantic event codes,
but generic buttons like those on a pad cannot easily be assigned semantic
codes. The kernel supports generic codes in the form of BTN_0 through to
BTN_9 and additional unnamed space up until code 0x10f. Additional generic
buttons are available as BTN_A in the range dedicated for gamepads and
joysticks. Thus, tablet with a large number of buttons have to map across
two semantic ranges, have to use unnamed kernel button codes or risk leaking
into an unrelated range. libinput transparently maps the kernel event codes
into a sequential button range on the pad. Callers should use external
sources like libwacom to associate button numbers to their position on the
tablet.
Some buttons may have expected default behaviors. For example, on Wacom
Intuos Pro series tablets, the button inside the touch ring is expected to
switch between modes, see :ref:`tablet-pad-modes`. Callers should use
external sources like libwacom to identify which buttons have semantic
behaviors.
.. _tablet-left-handed:
------------------------------------------------------------------------------
Tablets in left-handed mode
------------------------------------------------------------------------------
Left-handed mode on tablet devices usually means rotating the physical
tablet by 180 degrees to move the tablet pad button area to right side of
the tablet. When left-handed mode is enabled on a tablet device (see
**libinput_device_config_left_handed_set()**) the tablet tool and tablet pad
behavior changes. In left-handed mode, the tools' axes are adjusted
so that the origin of each axis remains the logical north-east of
the physical tablet. For example, the x and y axes are inverted and the
positive x/y coordinates are down/right of the top-left corner of the tablet
in its current orientation. On a tablet pad, the ring and strip are
similarly adjusted. The origin of the ring and strips remain the top-most
point.
.. figure:: tablet-left-handed.svg
:align: center
Tablet axes in right- and left-handed mode
Pad buttons are not affected by left-handed mode; the number of each button
remains the same even when the perceived physical location of the button
changes. This is a conscious design decision:
- Tablet pad buttons do not have intrinsic semantic meanings. Re-ordering
the button numbers would not change any functionality.
- Button numbers should not be exposed directly to the user but handled in
the intermediate layers. Re-ordering button numbers thus has no
user-visible effect.
- Re-ordering button numbers may complicate the intermediate layers.
Left-handed mode is only available on some tablets, some tablets are
symmetric and thus do not support left-handed mode. libinput requires
libwacom to determine if a tablet is capable of being switched to
left-handed mode.
.. _tablet-pad-modes:
------------------------------------------------------------------------------
Tablet pad modes
------------------------------------------------------------------------------
Tablet pad modes are virtual groupings of button, ring and strip
functionality. A caller may assign different functionalities depending on
the mode the tablet is in. For example, in mode 0 the touch ring may emulate
scrolling, in mode 1 the touch ring may emulate zooming, etc. libinput
handles the modes and mode switching but does not assign specific
functionality to buttons, rings or strips based on the mode. It is up to the
caller to decide whether the mode only applies to buttons, rings and strips
or only to rings and strips (this is the case with the Wacom OS X and
Windows driver).
The availability of modes on a touchpad usually depends on visual feedback
such as LEDs around the touch ring. If no visual feedback is available, only
one mode may be available.
Mode switching is controlled by libinput and usually toggled by one or
more buttons on the device. For example, on the Wacom Intuos 4, 5, and
Pro series tablets the mode button is the button centered in the touch
ring and toggles the modes sequentially. On the Wacom Cintiq 24HD the
three buttons next to each touch ring allow for directly changing the
mode to the desired setting.
Multiple modes may exist on the tablet, libinput uses the term "mode group"
for such groupings of buttons that share a mode and mode toggle. For
example, the Wacom Cintiq 24HD has two separate mode groups, one for the
left set of buttons, strips, and touch rings and one for the right set.
libinput handles the mode groups independently and returns the mode for each
button as appropriate. The mode group is static for the lifetime of the
device.
.. figure:: tablet-intuos-modes.svg
:align: center
Modes on an Intuos Pro-like tablet
In the image above, the Intuos Pro-like tablet provides 4 LEDs to indicate
the currently active modes. The button inside the touch ring cycles through
the modes in a clockwise fashion. The upper-right LED indicates that the
currently active mode is 1, based on 0-indexed mode numbering.
**libinput_event_tablet_pad_get_mode()** would thus return 1 for all button and
ring events on this tablet. When the center button is pressed, the mode
switches to mode 2, the LED changes to the bottom-right and
**libinput_event_tablet_pad_get_mode()** returns 2 for the center button event
and all subsequent events.
.. figure:: tablet-cintiq24hd-modes.svg
:align: center
Modes on an Cintiq 24HD-like tablet
In the image above, the Cintiq 24HD-like tablet provides 3 LEDs on each side
of the tablet to indicate the currently active mode for that group of
buttons and the respective ring. The buttons next to the touch ring select
the mode directly. The two LEDs indicate that the mode for the left set of
buttons is currently 0, the mode for the right set of buttons is currently
1, based on 0-indexed mode numbering. **libinput_event_tablet_pad_get_mode()**
would thus return 0 for all button and ring events on the left and 1 for all
button and ring events on the right. When one of the three mode toggle
buttons on the right is pressed, the right mode switches to that button's
mode but the left mode remains unchanged.
.. _tablet-touch-arbitration:
------------------------------------------------------------------------------
Tablet touch arbitration
------------------------------------------------------------------------------
"Touch arbitration" is the terminology used when touch events are suppressed
while the pen is in proximity. Since it is almost impossible to use a stylus
or other tool without triggering touches with the hand holding the tool,
touch arbitration serves to reduce the number of accidental inputs.
The wacom kernel driver currently provides touch arbitration but for other
devices arbitration has to be done in userspace.
libinput uses the **libinput_device_group** to decide on touch arbitration
and automatically discards touch events whenever a tool is in proximity.
The exact behavior is device-dependent.
.. _tablet-area:
------------------------------------------------------------------------------
Tablet area
------------------------------------------------------------------------------
External tablet devices such as e.g. the Wacom Intuos series can be configured
to reduce the available logical input area. Typically the logical input area
is equivalent to the physical input area but it can be reduced with the
**libinput_device_config_area_set_rectangle()** call. Once reduced, input
events outside the logical input area are ignored and the logical input area
acts as if it represented the extents of the physical tablet.
.. figure:: tablet-area.svg
:align: center
Tablet area configuration example
In the image above, the area is set to the rectangle 0.25/0.25 to 0.5/0.75.
Even though the tool is roughly at the physical position ``0.5 * width`` and
``0.75 * height``, the return values of
**libinput_event_tablet_tool_get_x_transformed()** and
**libinput_event_tablet_tool_get_y_transformed()** would be close to the
maximum provided in this call.
The size of the tablet reported by **libinput_device_get_size()** always reflects
the physical area, not the logical area.
libinput-1.28.1/doc/user/tapping.rst000066400000000000000000000122431477265155700173750ustar00rootroot00000000000000.. _tapping:
==============================================================================
Tap-to-click behaviour
==============================================================================
"Tapping" or "tap-to-click" is the name given to the behavior where a short
finger touch down/up sequence maps into a button click. This is most
commonly used on touchpads, but may be available on other devices.
libinput implements tapping for one, two, and three fingers, where supported by
the hardware, and maps those taps into a left, right, and middle button click,
respectively. This mapping can be switched to left, middle and right through
configuration. Not all devices support three fingers, libinput will support
tapping up to whatever is supported by the hardware. libinput does not support
four-finger taps or any tapping with more than four fingers, even though some
hardware can distinguish between that many fingers.
.. _tapping_default:
------------------------------------------------------------------------------
Tap-to-click default setting
------------------------------------------------------------------------------
Tapping is **disabled** by default on most devices, see
:commit:`2219c12c3` because:
- if you don't know that tapping is a thing (or enabled by default), you get
spurious button events that make the desktop feel buggy.
- if you do know what tapping is and you want it, you usually know where to
enable it, or at least you can search for it.
Tapping is **enabled** by default on devices where tapping is the only
method to trigger button clicks. This includes devices without physical
buttons such as touch-capable graphics tablets.
.. note:: Unfortunately due to the current API design, devices that require
tapping effectively prevent us from changing this default. For details see
`this comment `_.
Tapping can be enabled/disabled on a per-device basis. See
**libinput_device_config_tap_set_enabled()** for details.
.. _tapndrag:
------------------------------------------------------------------------------
Tap-and-drag
------------------------------------------------------------------------------
libinput also supports "tap-and-drag" where a tap immediately followed by a
finger down and that finger being held down emulates a button press. Moving
the finger around can thus drag the selected item on the screen.
Tap-and-drag is optional and can be enabled or disabled with
**libinput_device_config_tap_set_drag_enabled()**. Most devices have
tap-and-drag enabled by default.
.. note:: Dragging is always done with one finger. The number of fingers on
the initial tap decide the type of button click. For example, to
middle-click drag, tap with three fingers followed by a
single-finger drag.
Also optional is a feature called "drag lock". With drag lock disabled, lifting
the finger will stop any drag process. When enabled, the drag
process continues even after lifting a finger but can be ended
with an additional tap. If timeout-based drag-locks are enabled
the drag process will also automatically end once the finger has
been lifted for an implementation-specific timeout. Drag lock can be
enabled and disabled with **libinput_device_config_tap_set_drag_lock_enabled()**.
Note that drag lock only applies if tap-and-drag is enabled.
.. figure:: tap-n-drag.svg
:align: center
Tap-and-drag process
The above diagram explains the process, a tap (a) followed by a finger held
down (b) starts the drag process and logically holds the left mouse button
down. A movement of the finger (c) will drag the selected item until the
finger is released (e). If needed and drag lock is enabled, the finger's
position can be reset by lifting and quickly setting it down again on the
touchpad (d). This will be interpreted as continuing move and is especially
useful on small touchpads or with slow pointer acceleration.
If drag lock is enabled, the release of the mouse buttons after the finger
release (e) is triggered by a timeout. To release the button immediately,
simply tap again (f).
If drag lock is enabled in sticky mode there is no timeout after
releasing a finger and an extra tap is required to release the button.
If two fingers are supported by the hardware, a second finger can be used to
drag while the first is held in-place.
.. _tap_constraints:
------------------------------------------------------------------------------
Constraints while tapping
------------------------------------------------------------------------------
A couple of constraints apply to the contact to be converted into a press, the most common ones are:
- the touch down and touch up must happen within an implementation-defined timeout
- if a finger moves more than an implementation-defined distance while in contact, it's not a tap
- tapping within :ref:`clickpad software buttons ` may not trigger an event
- a tap not meeting required pressure thresholds can be ignored as accidental touch
- a tap exceeding certain pressure thresholds can be ignored (see :ref:`palm_detection`)
- a tap on the edges of the touchpad can usually be ignored (see :ref:`palm_detection`)
libinput-1.28.1/doc/user/test-suite.rst000066400000000000000000000206721477265155700200460ustar00rootroot00000000000000.. _test-suite:
==============================================================================
libinput test suite
==============================================================================
libinput's primary test suite can be invoked with
::
$ sudo ./builddir/libinput-test-suite
When developing libinput, the ``libinput-test-suite`` should always be
run to check for behavior changes and/or regressions. For quick iteration,
the number of tests to run can be filtered, see :ref:`test-filtering`.
This allows for developers to verify a subset of tests (e.g.
touchpad tap-to-click) while hacking on that specific feature and only run
the full suite when development is done finished.
.. note:: The test suite relies on udev and the kernel, specifically uinput.
It creates virtual input devices and replays the events. This may
interfere with your running session. The test suite is not suitable
for running inside containers.
In addition, libinput ships with a set of (primarily janitorial) tests that
must pass for any merge request. These tests are invoked by calling
``meson test -C builddir`` (or ``ninja test``). The ``libinput-test-suite`` is
part of that test set by default.
The upstream CI runs all these tests and is run for every merge request.
.. _test-job-control:
------------------------------------------------------------------------------
Job control in the test suite
------------------------------------------------------------------------------
The test suite runner has a make-like job control enabled by the ``-j`` or
``--jobs`` flag and will fork off as many parallel processes as given by this
flag. The default if unspecified is 8. When debugging a specific test case
failure it is recommended to employ test filtures (see :ref:`test-filtering`)
and disable parallel tests. The test suite automatically disables parallel
make when run in gdb.
.. _test-config:
------------------------------------------------------------------------------
X.Org config to avoid interference
------------------------------------------------------------------------------
uinput devices created by the test suite are usually recognised by X as
input devices. All events sent through these devices will generate X events
and interfere with your desktop.
Copy the file ``$srcdir/test/50-litest.conf`` into your ``/etc/X11/xorg.conf.d``
and restart X. This will ignore any litest devices and thus not interfere
with your desktop.
.. _test-root:
------------------------------------------------------------------------------
Permissions required to run tests
------------------------------------------------------------------------------
Most tests require the creation of uinput devices and access to the
resulting ``/dev/input/eventX`` nodes. Some tests require temporary udev rules.
**This usually requires the tests to be run as root**. If not run as
root, the test suite runner will exit with status 77, an exit status
interpreted as "skipped".
.. _test-filtering:
------------------------------------------------------------------------------
Selective running of tests
------------------------------------------------------------------------------
litest's tests are grouped into test groups, test names and devices. A test
group is e.g. "touchpad:tap" and incorporates all tapping-related tests for
touchpads. Each test function is (usually) run with one or more specific
devices. The ``--list`` commandline argument shows the list of suites and
tests. This is useful when trying to figure out if a specific test is
run for a device.
::
$ ./builddir/libinput-test-suite --list
...
pointer:left-handed:
pointer_left_handed_during_click_multiple_buttons:
trackpoint
ms-surface-cover
mouse-wheelclickcount
mouse-wheelclickangle
low-dpi-mouse
mouse-roccat
mouse-wheel-tilt
mouse
logitech-trackball
cyborg-rat
magicmouse
pointer_left_handed_during_click:
trackpoint
ms-surface-cover
mouse-wheelclickcount
mouse-wheelclickangle
low-dpi-mouse
mouse-roccat
mouse-wheel-tilt
mouse
logitech-trackball
cyborg-rat
litest-magicmouse-device
pointer_left_handed:
trackpoint
ms-surface-cover
mouse-wheelclickcount
mouse-wheelclickangle
low-dpi-mouse
mouse-roccat
mouse-wheel-tilt
mouse
...
In the above example, the "pointer:left-handed" suite contains multiple
tests, e.g. "pointer_left_handed_during_click" (this is also the function
name of the test, making it easy to grep for). This particular test is run
for various devices including the trackpoint device and the magic mouse
device.
The "no device" entry signals that litest does not instantiate a uinput
device for a specific test (though the test itself may
instantiate one).
The ``--filter-test`` argument enables selective running of tests through
basic shell-style function name matching. For example:
::
$ ./builddir/libinput-test-suite --filter-test="*1fg_tap*"
The ``--filter-device`` argument enables selective running of tests through
basic shell-style device name matching. The device names matched are the
litest-specific shortnames, see the output of ``--list``. For example:
::
$ ./builddir/libinput-test-suite --filter-device="synaptics*"
The ``--filter-group`` argument enables selective running of test groups
through basic shell-style test group matching. The test groups matched are
litest-specific test groups, see the output of ``--list``. For example:
::
$ ./builddir/libinput-test-suite --filter-group="touchpad:*hover*"
The ``--filter-device`` and ``--filter-group`` arguments can be combined with
``--list`` to show which groups and devices will be affected.
.. _test-verbosity:
------------------------------------------------------------------------------
Controlling test output
------------------------------------------------------------------------------
Each test supports the ``--verbose`` commandline option to enable debugging
output, see **libinput_log_set_priority()** for details. The ``LITEST_VERBOSE``
environment variable, if set, also enables verbose mode.
::
$ ./builddir/libinput-test-suite --verbose
$ LITEST_VERBOSE=1 meson test -C builddir
.. _test-installed:
------------------------------------------------------------------------------
Installing the test suite
------------------------------------------------------------------------------
If libinput is configured to install the tests, the test suite is available
as the ``libinput test-suite`` command. When run as installed binary, the
behavior of the test suite changes:
- the ``libinput.so`` used is the one in the library lookup paths
- no system-wide quirks are installed by the test suite, only those specific
to the test devices
- test device-specific quirks are installed in the system-wide quirks
directory, usually ``/usr/share/libinput/``.
It is not advisable to run ``libinput test-suite`` on a production machine.
Data loss may occur. The primary use-case for the installed test suite is
verification of distribution composes.
.. note:: The ``prefix`` is still used by the test suite. For verification
of a system package, the test suite must be configured with the same prefix.
To configure libinput to install the tests, use the ``-Dinstall-tests=true``
meson option::
$ meson setup builddir -Dtests=true -Dinstall-tests=true
.. _test-meson-suites:
------------------------------------------------------------------------------
Meson test suites
------------------------------------------------------------------------------
This section is primarily of interest to distributors that want to run test
or developers working on libinput's CI.
Tests invoked by ``meson test`` are grouped into test suites, the test suite
names identify when the respective test can be run:
- ``valgrind``: tests that can be run under valgrind (in addition to a
normal run)
- ``root``: tests that must be run as root
- ``hardware``: tests that require a VM or physical machine
- ``all``: all tests, only needed because of
`meson bug 5340 `_
The suite names can be provided as filters to ``meson test
--suite=`` or ``meson test --no-suite=``.
For example, if running a container-based CI, you may specify the test
suites as:
::
$ meson test --no-suite=machine # only run container-friendly tests
$ meson test --suite=valgrind --setup=valgrind # run all valgrind-compatible tests
$ meson test --no-suite=root # run all tests not requiring root
These suites are subject to change at any time.
libinput-1.28.1/doc/user/timestamps.rst000066400000000000000000000032331477265155700201200ustar00rootroot00000000000000
.. _timestamps:
==============================================================================
Timestamps
==============================================================================
.. _event_timestamps:
------------------------------------------------------------------------------
Event timestamps
------------------------------------------------------------------------------
Most libinput events provide a timestamp in millisecond and/or microsecond
resolution. These timestamp usually increase monotonically, but libinput
does not guarantee that this always the case. In other words, it is possible
to receive an event with a timestamp earlier than the previous event.
For example, if a touchpad has :ref:`tapping` enabled, a button event may have a
lower timestamp than an event from a different device. Tapping requires the
use of timeouts to detect multi-finger taps and/or :ref:`tapndrag`.
Consider the following event sequences from a touchpad and a mouse:
::
Time Touchpad Mouse
---------------------------------
t1 finger down
t2 finger up
t3 movement
t4 tap timeout
For this event sequence, the first event to be sent to a caller is in
response to the mouse movement: an event of type
**LIBINPUT_EVENT_POINTER_MOTION** with the timestamp t3.
Once the timeout expires at t4, libinput generates an event of
**LIBINPUT_EVENT_POINTER_BUTTON** (press) with a timestamp t1 and an event
**LIBINPUT_EVENT_POINTER_BUTTON** (release) with a timestamp t2.
Thus, the caller gets events with timestamps in the order t3, t1, t2,
despite t3 > t2 > t1.
libinput timestamps use **CLOCK_MONOTONIC**.
libinput-1.28.1/doc/user/tools.rst000066400000000000000000000405631477265155700171010ustar00rootroot00000000000000.. _tools:
==============================================================================
Helper tools
==============================================================================
libinput provides a ``libinput`` tool to query state and events. This tool
takes a subcommand as argument, similar to the **git** command. A full
explanation of the various commands available in the libinput tool is
available in the **libinput(1)** man page.
The most common tools used are:
- ``libinput list-devices``: to list locally available devices as seen by libinput,
see :ref:`here `
- ``libinput list-kernel-devices``: to list locally available devices as seen by the kernel,
see :ref:`here `
- ``libinput debug-events``: to monitor and debug events,
see :ref:`here `
- ``libinput debug-gui``: to visualize events,
see :ref:`here `
- ``libinput record``: to record an event sequence for replaying,
see :ref:`here `
- ``libinput measure``: measure properties on a kernel device,
see :ref:`here `
- ``libinput analyze``: analyse event recordings from a kernel device,
see :ref:`here `
- ``libinput quirks``: show quirks assigned to a device, see
:ref:`here `
Most of the tools must be run as root to have access to the kernel's
``/dev/input/event*`` device files.
.. _libinput-list-devices:
------------------------------------------------------------------------------
libinput list-devices
------------------------------------------------------------------------------
The ``libinput list-devices`` command shows information about devices
recognized by libinput and can help identifying why a device behaves
different than expected. For example, if a device does not show up in the
output, it is not a supported input device.
.. note:: This tool does **not** show your desktop's configuration, just the
libinput built-in defaults.
::
$ sudo libinput list-devices
[...]
Device: SynPS/2 Synaptics TouchPad
Kernel: /dev/input/event4
Group: 9
Seat: seat0, default
Size: 97.33x66.86mm
Capabilities: pointer
Tap-to-click: disabled
Tap drag lock: disabled
Left-handed: disabled
Nat.scrolling: disabled
Middle emulation: n/a
Calibration: n/a
Scroll methods: *two-finger
Click methods: *button-areas clickfinger
[...]
The above listing shows example output for a touchpad. The
``libinput list-devices`` command lists general information about the device
(the kernel event node) but also the configuration options. If an option is
``n/a`` it does not exist on this device. Otherwise, the tool will show the
default configuration for this device, for options that have more than a
binary state all available options are listed, with the default one prefixed
with an asterisk (``*``). In the example above, the default click method is
button-areas but clickfinger is available.
.. note:: This tool is intended for human-consumption and may change its output
at any time.
.. _libinput-list-kernel-devices:
------------------------------------------------------------------------------
libinput list-kernel-devices
------------------------------------------------------------------------------
The ``libinput list-kernel-devices`` command shows the devices known by **the
kernel**. This command can help identify issues when a device is not handled by
libinput.
::
$ libinput list-kernel-devices
/dev/input/event0: Sleep Button
/dev/input/event1: Power Button
/dev/input/event2: Power Button
/dev/input/event3: Microsoft Microsoft® 2.4GHz Transceiver v9.0
/dev/input/event4: Microsoft Microsoft® 2.4GHz Transceiver v9.0 Mouse
[...]
In some cases, knowing about the HID devices behind the kernel's event nodes
can be useful. To list HID devices, supply the ``--hid`` commandline flag:
::
$ libinput list-kernel-devices --hid
hid:
- name: 'Logitech Gaming Mouse G303'
id: '046d:c080'
driver: 'hid-generic'
hidraw: ['/dev/hidraw6']
evdev: ['/dev/input/event13']
- name: 'Logitech Gaming Mouse G303'
id: '046d:c080'
driver: 'hid-generic'
hidraw: ['/dev/hidraw7']
evdev: ['/dev/input/event14']
- name: 'Microsoft Microsoft® 2.4GHz Transceiver v9.0'
id: '045e:07a5'
driver: 'hid-generic'
hidraw: ['/dev/hidraw0']
evdev: ['/dev/input/event3']
.. note:: This tool is intended for human-consumption and may change its output
at any time.
.. _libinput-debug-events:
------------------------------------------------------------------------------
libinput debug-events
------------------------------------------------------------------------------
The ``libinput debug-events`` command prints events from devices and can help
to identify why a device behaves different than expected. ::
$ sudo libinput debug-events --enable-tapping --set-click-method=clickfinger
All configuration options (enable/disable tapping,
etc.) are available as commandline arguments. To reproduce the event
sequence as your desktop session sees it, ensure that all options are turned
on or off as required. See the **libinput-debug-events(1)** man page or the
``--help`` output for information about the available options.
.. note:: When submitting a bug report, always use the ``--verbose`` flag to get
additional information: ``libinput debug-events --verbose ``
An example output from this tool may look like the snippet below. ::
$ sudo libinput debug-events --enable-tapping --set-click-method=clickfinger
-event2 DEVICE_ADDED Power Button seat0 default group1 cap:k
-event5 DEVICE_ADDED Video Bus seat0 default group2 cap:k
-event0 DEVICE_ADDED Lid Switch seat0 default group3 cap:S
-event1 DEVICE_ADDED Sleep Button seat0 default group4 cap:k
-event4 DEVICE_ADDED HDA Intel HDMI HDMI/DP,pcm=3 seat0 default group5 cap:
-event11 DEVICE_ADDED HDA Intel HDMI HDMI/DP,pcm=7 seat0 default group6 cap:
-event12 DEVICE_ADDED HDA Intel HDMI HDMI/DP,pcm=8 seat0 default group7 cap:
-event13 DEVICE_ADDED HDA Intel HDMI HDMI/DP,pcm=9 seat0 default group8 cap:
-event14 DEVICE_ADDED HDA Intel HDMI HDMI/DP,pcm=10 seat0 default group9 cap:
-event19 DEVICE_ADDED Integrated Camera: Integrated C seat0 default group10 cap:k
-event15 DEVICE_ADDED HDA Intel PCH Dock Mic seat0 default group11 cap:
-event16 DEVICE_ADDED HDA Intel PCH Mic seat0 default group12 cap:
-event17 DEVICE_ADDED HDA Intel PCH Dock Headphone seat0 default group13 cap:
-event18 DEVICE_ADDED HDA Intel PCH Headphone seat0 default group14 cap:
-event6 DEVICE_ADDED ELAN Touchscreen seat0 default group15 cap:t size 305x172mm ntouches 10 calib
-event3 DEVICE_ADDED AT Translated Set 2 keyboard seat0 default group16 cap:k
-event20 DEVICE_ADDED SynPS/2 Synaptics TouchPad seat0 default group17 cap:pg size 100x76mm tap(dl off) left scroll-nat scroll-2fg-edge click-buttonareas-clickfinger dwt-on
-event21 DEVICE_ADDED TPPS/2 IBM TrackPoint seat0 default group18 cap:p left scroll-nat scroll-button
-event7 DEVICE_ADDED ThinkPad Extra Buttons seat0 default group19 cap:k
-event20 POINTER_MOTION +3.62s 2.72/ -0.93
event20 POINTER_MOTION +3.63s 1.80/ -1.42
event20 POINTER_MOTION +3.65s 6.16/ -2.28
event20 POINTER_MOTION +3.66s 6.42/ -1.99
event20 POINTER_MOTION +3.67s 8.99/ -1.42
event20 POINTER_MOTION +3.68s 11.30/ 0.00
event20 POINTER_MOTION +3.69s 21.32/ 1.42
.. _libinput-debug-gui:
------------------------------------------------------------------------------
libinput debug-gui
------------------------------------------------------------------------------
A simple GTK-based graphical tool that shows the behavior and location of
touch events, pointer motion, scroll axes and gestures. Since this tool
gathers data directly from libinput, it is thus suitable for
pointer-acceleration testing.
.. note:: This tool does **not** use your desktop's configuration, just the
libinput built-in defaults.
::
$ sudo libinput debug-gui --enable-tapping
As with :ref:`libinput-debug-events`, all options must be specified on the
commandline to emulate the correct behavior.
See the **libinput-debug-gui(1)** man page or the ``--help`` output for information about
the available options.
.. _libinput-record:
------------------------------------------------------------------------------
libinput record and libinput replay
------------------------------------------------------------------------------
.. note:: For libinput versions 1.10 and older, use :ref:`evemu`.
The ``libinput record`` command records the **kernel** events from a specific
device node. The recorded sequence can be replayed with the ``libinput
replay`` command. This pair of tools is crucial to capturing bugs and
reproducing them on a developer's machine.
.. graphviz:: libinput-record.gv
:align: center
The recorded events are **kernel events** and independent of the
libinput context. libinput does not need to be running, it does
not matter whether a user is running X.Org or Wayland or even what
version of libinput is currently running.
The use of the tools is straightforward, just run without arguments, piping
the output into a file: ::
$ sudo libinput record > touchpad.yml
Available devices:
/dev/input/event0: Lid Switch
/dev/input/event1: Sleep Button
/dev/input/event2: Power Button
/dev/input/event3: AT Translated Set 2 keyboard
/dev/input/event4: ThinkPad Extra Buttons
/dev/input/event5: ELAN Touchscreen
/dev/input/event6: Video Bus
/dev/input/event7: HDA Intel HDMI HDMI/DP,pcm=3
/dev/input/event8: HDA Intel HDMI HDMI/DP,pcm=7
/dev/input/event9: HDA Intel HDMI HDMI/DP,pcm=8
/dev/input/event10: HDA Intel HDMI HDMI/DP,pcm=9
/dev/input/event11: HDA Intel HDMI HDMI/DP,pcm=10
/dev/input/event12: HDA Intel PCH Dock Mic
/dev/input/event13: HDA Intel PCH Mic
/dev/input/event14: HDA Intel PCH Dock Headphone
/dev/input/event15: HDA Intel PCH Headphone
/dev/input/event16: Integrated Camera: Integrated C
/dev/input/event17: SynPS/2 Synaptics TouchPad
/dev/input/event18: TPPS/2 IBM TrackPoint
Select the device event number: 17
/dev/input/event17 recording to stdout
Without arguments, ``libinput record`` displays the available devices and lets
the user select one. Supply the number (17 in this case for
``/dev/input/event17``) and the tool will print the device information and
events to the file it is redirected to. More arguments are available, see
the **libinput-record(1)** man page.
.. note:: When reproducing a bug that crashes libinput, run inside ``screen`` or
``tmux``.
Reproduce the bug, ctrl+c and attach the output file to a bug report.
For data protection, ``libinput record`` obscures key codes by default, any
alphanumeric key shows up as letter "a".
.. warning:: The longer the recording, the harder it is to identify the event
sequence triggering the bug. Please keep the event sequence as
short as possible.
The recording can be replayed with the ``libinput replay`` command: ::
$ sudo libinput replay touchpad.yml
SynPS/2 Synaptics TouchPad: /dev/input/event19
Hit enter to start replaying
``libinput replay`` creates a new virtual device based on the description in
the log file. Hitting enter replays the event sequence once and the tool
stops once all events have been replayed. Hitting enter again replays the
sequence again, Ctrl+C stops it and removes the virtual device.
Users are advised to always replay a recorded event sequence to ensure they
have captured the bug.
More arguments are available, see the **libinput-record(1)** and
**libinput-replay(1)** man pages.
.. _libinput-record-autorestart:
..............................................................................
libinput record's autorestart feature
..............................................................................
``libinput record`` often collects thousands of events per minute. However,
the output of ``libinput record`` usually needs to be visually inspected
or replayed in realtime on a developer machine. It is thus imperative that
the event log is kept as short as possible.
For bugs that are difficult to reproduce use
``libinput record --autorestart=2 --output-file=recording.yml``.
All events will be recorded to a file named
``recording.yml.`` and whenever the device does not
send events for 2 seconds, a new file is created. This helps to keep
individual recordings short.
To use the ``--autorestart`` option correctly:
- run ``libinput record --autorestart=2 --output-file=.yml``.
You may provide a timeout other than 2 if needed.
- use the device to reproduce the bug, pausing frequently for 2s and longer
to rotate the logs
- when the bug triggers, **immediately stop using the device** and wait
several seconds for the log to rotate
- Ctrl+C the ``libinput record`` process without using the device
again. Attach the **last recording** to the bug report.
If you have to use the recorded device to stop ``libinput record`` (e.g. to
switch windows), remember that this will cause a new recording to be
created. Thus, attach the **second-to-last recording** to the bug report
because this one contains the bug trigger.
.. _libinput-record-multiple:
..............................................................................
Recording multiple devices at once
..............................................................................
In some cases, an interaction between multiple devices is the cause for a
specific bug. For example, a touchpad may not work in response to keyboard
events. To accurately reproduce this sequence, the timing between multiple
devices must be correct and we need to record the events in one go.
``libinput record`` has a ``--multiple`` argument to record multiple devices at
once. Unlike the normal invocation, this one requires a number of arguments: ::
$ sudo libinput record --multiple --output-file=touchpad-bug.yml /dev/input/event17 /dev/input/event3
recording to 'touchpad-bug.yml'
As seen above, a user must specify ``--multiple`` and the ``--output-file``.
Finally, all devices to be recorded must be specified on the commandline as
well.
Replaying events is the same as for a single recording: ::
$ sudo libinput replay touchpad-bug.yml
.. _libinput-measure:
------------------------------------------------------------------------------
Measuring device properties with libinput measure
------------------------------------------------------------------------------
The ``libinput measure`` tool is a multiplexer for various sub-tools that can
measure specific properties on the device. These tools generally measure one
thing and one thing only and their usage is highly specific to the tool.
Please see the **libinput-measure(1)** man page for information about what
tools are available and the man page for each respective tool.
.. _libinput-analyze:
------------------------------------------------------------------------------
Analyzing device events with libinput analyze
------------------------------------------------------------------------------
The ``libinput analyze`` tool is a multiplexer for various sub-tools that
can analyze input events previously recorded from a device.
Please see the **libinput-analyze(1)** man page for information about what
tools are available and the man page for each respective too.
.. _libinput-quirks:
------------------------------------------------------------------------------
Listing quirks assigned to a device
------------------------------------------------------------------------------
The ``libinput quirks`` tool can show quirks applied for any given device. ::
$ libinput quirks list /dev/input/event0
AttrLidSwitchReliability=unreliable
If the tool's output is empty, no quirk is applied. See :ref:`device-quirks`
for more information.
libinput-1.28.1/doc/user/touchpad-jitter.rst000066400000000000000000000100521477265155700210350ustar00rootroot00000000000000.. _touchpad_jitter:
==============================================================================
Touchpad jitter
==============================================================================
Touchpad jitter describes random movement by a few pixels even when the
user's finger is unmoving.
libinput has a mechanism called a **hysteresis** to avoid that jitter. When
active, movement with in the **hysteresis margin** is discarded. If the
movement delta is larger than the margin, the movement is passed on as
pointer movement. This is a simplified summary, developers should
read the implementation of the hysteresis in ``src/evdev.c``.
libinput uses the kernel ``fuzz`` value to determine the size of the
hysteresis. Users should override this with a udev hwdb entry where the
device itself does not provide the correct value.
.. _touchpad_jitter_fuzz_override:
------------------------------------------------------------------------------
Overriding the hysteresis margins
------------------------------------------------------------------------------
libinput provides the debugging tool ``libinput measure fuzz`` to help edit or
test a fuzz value. This tool is interactive and provides a udev hwdb entry
that matches the device. To check if a fuzz is currently present, simply run
without arguments or with the touchpad's device node:
::
$ sudo libinput measure fuzz
Using Synaptics TM2668-002: /dev/input/event17
Checking udev property... not set
Checking axes... x=16 y=16
In the above output, the axis fuzz is set to 16. To set a specific fuzz, run
with the ``--fuzz=`` argument.
::
$ sudo libinput measure fuzz --fuzz=8
The tool will attempt to construct a hwdb file that matches your touchpad
device. Follow the printed prompts.
In the ideal case, the tool will provide you with a file that can be
submitted to the systemd repo for inclusion.
However, hwdb entry creation is difficult to automate and it's likely
that the tools fails in doing so, especially if an existing entry is already
present.
Below is the outline of what a user needs to do to override a device's fuzz
value in case the ``libinput measure fuzz`` tool fails.
Check with ``udevadm info /sys/class/input/eventX`` (replace your device node
number) whether an existing hwdb override exists. If the ``EVDEV_ABS_``
properties are present, the hwdb override exists. Find the file that
contains that entry, most likely in ``/etc/udev/hwdb.d`` or
``/usr/lib/udev/hwdb.d``.
The content of the property is a set of values in the format
``EVDEV_ABS_00=min:max:resolution:fuzz``. You need to set the ``fuzz`` part,
leaving the remainder of the property as-is. Values may be empty, e.g. a
property that only sets resolution and fuzz reads as ``EVDEV_ABS_00=::32:8``.
If no properties exist, your hwdb.entry should look approximately like this:
::
evdev:name:Synaptics TM2668-002:dmi:*:svnLENOVO*:pvrThinkPadT440s*:
EVDEV_ABS_00=:::8
EVDEV_ABS_01=:::8
EVDEV_ABS_35=:::8
EVDEV_ABS_36=:::8
Substitute the ``name`` field with the device name (see the output of
``libinput measure fuzz`` and the DMI match content with your hardware. See
:ref:`hwdb_modifying` for details.
Once the hwdb entry has been modified, added, or created,
:ref:`reload the hwdb `. Once reloaded, :ref:`libinput-record`
"libinput record" should show the new fuzz value for the axes.
Restart the host and libinput should pick up the revised fuzz values.
.. _kernel_fuzz:
------------------------------------------------------------------------------
Kernel fuzz
------------------------------------------------------------------------------
A fuzz set on an absolute axis in the kernel causes the kernel to apply
hysteresis-like behavior to the axis. Unfortunately, this behavior leads to
inconsistent deltas. To avoid this, libinput sets the kernel fuzz on the
device to 0 to disable this kernel behavior but remembers what the fuzz was
on startup. The fuzz is stored in the ``LIBINPUT_FUZZ_XX`` udev property, on
startup libinput will check that property as well as the axis itself.
libinput-1.28.1/doc/user/touchpad-jumping-cursors.rst000066400000000000000000000107311477265155700227070ustar00rootroot00000000000000.. _touchpad_jumping_cursor:
==============================================================================
Touchpad jumping cursor bugs
==============================================================================
A common bug encountered on touchpads is a cursor jump when alternating
between fingers on a multi-touch-capable touchpad. For example, after moving
the cursor a user may use a second finger in the software button area to
physically click the touchpad. Upon setting the finger down, the cursor
exhibits a jump towards the bottom left or right, depending on the finger
position.
When libinput detects a cursor jump it prints a bug warning to the log with
the text **"Touch jump detected and discarded."** and a link to this page.
.. note:: This warning is ratelimited and will stop appearing after a few
times, even if the touchpad jumps continue.
In most cases, this is a bug in the firmware (or kernel driver) and to
libinput it appears that the touch point moves from its previous position.
The pointer jump can usually be seen in the :ref:`libinput record
` output for the device:
::
E: 249.206319 0000 0000 0000 # ------------ SYN_REPORT (0) ----------
E: 249.218008 0003 0035 3764 # EV_ABS / ABS_MT_POSITION_X 3764
E: 249.218008 0003 0036 2221 # EV_ABS / ABS_MT_POSITION_Y 2221
E: 249.218008 0003 003a 0065 # EV_ABS / ABS_MT_PRESSURE 65
E: 249.218008 0003 0000 3764 # EV_ABS / ABS_X 3764
E: 249.218008 0003 0001 2216 # EV_ABS / ABS_Y 2216
E: 249.218008 0003 0018 0065 # EV_ABS / ABS_PRESSURE 65
E: 249.218008 0000 0000 0000 # ------------ SYN_REPORT (0) ----------
E: 249.230881 0003 0035 3752 # EV_ABS / ABS_MT_POSITION_X 3752
E: 249.230881 0003 003a 0046 # EV_ABS / ABS_MT_PRESSURE 46
E: 249.230881 0003 0000 3758 # EV_ABS / ABS_X 3758
E: 249.230881 0003 0018 0046 # EV_ABS / ABS_PRESSURE 46
E: 249.230881 0000 0000 0000 # ------------ SYN_REPORT (0) ----------
E: 249.242648 0003 0035 1640 # EV_ABS / ABS_MT_POSITION_X 1640
E: 249.242648 0003 0036 4681 # EV_ABS / ABS_MT_POSITION_Y 4681
E: 249.242648 0003 003a 0025 # EV_ABS / ABS_MT_PRESSURE 25
E: 249.242648 0003 0000 1640 # EV_ABS / ABS_X 1640
E: 249.242648 0003 0001 4681 # EV_ABS / ABS_Y 4681
E: 249.242648 0003 0018 0025 # EV_ABS / ABS_PRESSURE 25
E: 249.242648 0000 0000 0000 # ------------ SYN_REPORT (0) ----------
E: 249.254568 0003 0035 1648 # EV_ABS / ABS_MT_POSITION_X 1648
E: 249.254568 0003 003a 0027 # EV_ABS / ABS_MT_PRESSURE 27
E: 249.254568 0003 0000 1644 # EV_ABS / ABS_X 1644
E: 249.254568 0003 0018 0027 # EV_ABS / ABS_PRESSURE 27
In this recording, the pointer jumps from its position 3752/2216 to
1640/4681 within a single frame. On this particular touchpad, this would
represent a physical move of almost 50mm. libinput detects some of these
jumps and discards the movement but otherwise continues as usual.
If your only encounter with these jumps is the warning printed to the log,
libinput functions as intended.
When you encounter the warning in the log, please generate a recording of
your touchpad with :ref:`libinput record ` and file a bug.
See :ref:`reporting_bugs` for more details.
Note that it most cases, libinput cannot actually fix the issue. Filing a
bug is useful to figure out if there are other factors at play or whether
there are heuristics we can employ to reduce the impact.
------------------------------------------------------------------------------
AlpsPS/2 ALPS DualPoint TouchPad jumping to 4095/0
------------------------------------------------------------------------------
A special case of pointer jumps happens on ``AlpsPS/2 ALPS DualPoint TouchPad``
devices found in the Lenovo ThinkPad E465 and E550 and likely others with
the same touchpad hardware. On those devices, the touchpad occasionally
sends an event for the second finger to move to position 4095/0 before
moving back to the original position. libinput detects this movement and
removes it but depending on the interaction this may cause a smaller jump
later when the coordinates reset to the new position of the finger.
Some more information is available in `Gitlab Issue #492 `__.
libinput-1.28.1/doc/user/touchpad-pressure-debugging.rst000066400000000000000000000240571477265155700233470ustar00rootroot00000000000000==============================================================================
Debugging touchpad pressure/size ranges
==============================================================================
:ref:`Touchpad pressure/size ranges ` depend on
:ref:`device-quirks` entry specific to each laptop model. To check if a
pressure/size range is already defined for your device, use the
:ref:`libinput quirks ` tool: ::
$ libinput quirks list /dev/input/event19
If your device does not list any quirks, it probably needs a touch
pressure/size range, a palm threshold and a thumb threshold. Start with
:ref:`touchpad_pressure_hwdb`, then :ref:`touchpad_touch_size_hwdb`. The
respective tools will exit if the required axis is not supported.
.. _touchpad_pressure_hwdb:
------------------------------------------------------------------------------
Debugging touchpad pressure ranges
------------------------------------------------------------------------------
This section describes how to determine the touchpad pressure ranges
required for a touchpad device and how to add the required
:ref:`device-quirks` locally. Note that the quirk is **not public API** and **may
change at any time**. Users are advised to :ref:`report a bug `
with the updated pressure ranges when testing has completed.
.. note:: Most distributions ship ``libinput measure`` in a separate
``libinput-utils`` package.
Use the ``libinput measure touchpad-pressure`` tool provided by libinput.
This tool will search for your touchpad device and print some pressure
statistics, including whether a touch is/was considered logically down.
.. note:: This tool will only work on touchpads with pressure.
Example output of the tool is below: ::
$ sudo libinput measure touchpad-pressure
Using Synaptics TM2668-002: /dev/input/event21
This is an interactive tool
Place a single finger on the touchpad to measure pressure values.
Check that:
- touches subjectively perceived as down are tagged as down
- touches with a thumb are tagged as thumb
- touches with a palm are tagged as palm
If the touch states do not match the interaction, re-run
with --touch-thresholds=down:up using observed pressure values.
See --help for more options.
Press Ctrl+C to exit
+-------------------------------------------------------------------------------+
| Thresh | 70 | 60 | 130 | 100 | |
+-------------------------------------------------------------------------------+
| Touch | down | up | palm | thumb | min | max | p | avg | median |
+-------------------------------------------------------------------------------+
| 178 | x | x | | | 75 | 75 | 0 | 75 | 75 |
| 179 | x | x | | | 35 | 88 | 0 | 77 | 81 |
| 180 | x | x | | x | 65 | 113 | 0 | 98 | 98 |
| 181 | x | x | | x | 50 | 101 | 0 | 86 | 90 |
| 182 | x | x | | | 40 | 80 | 0 | 66 | 70 |
| 183 | x | | | | 43 | 78 | 78 | |
...
The example output shows five completed touch sequences and one ongoing one.
For each, the respective minimum and maximum pressure values are printed as
well as some statistics. The ``down`` column show that each sequence was
considered logically down at some point, two of the sequences were considered
thumbs. This is an interactive tool and its output may change frequently. Refer
to the **libinput-measure-touchpad-pressure(1)** man page for more details.
By default, this tool uses the :ref:`device-quirks` for the pressure range. To
narrow down on the best values for your device, specify the 'logically down'
and 'logically up' pressure thresholds with the ``--touch-thresholds``
argument: ::
$ sudo libinput measure touchpad-pressure --touch-thresholds=10:8 --palm-threshold=20
Interact with the touchpad and check if the output of this tool matches your
expectations.
.. note:: This is an interactive process. You will need to re-run the
tool with varying thresholds until you find the right range for
your touchpad. Attaching output logs to a bug will not help, only
you with access to the hardware can figure out the correct
ranges.
Once the thresholds are decided on (e.g. 10 and 8), they can be enabled with
:ref:`device-quirks` entry similar to this: ::
$> cat /etc/libinput/local-overrides.quirks
[Touchpad pressure override]
MatchUdevType=touchpad
MatchName=*SynPS/2 Synaptics TouchPad
MatchDMIModalias=dmi:*svnLENOVO:*:pvrThinkPadX230*
AttrPressureRange=10:8
AttrPalmPressureThreshold=150
AttrThumbPressureThreshold=100
The file name **must** be ``/etc/libinput/local-overrides.quirks``. The
The first line is the section name and can be free-form. The ``Match``
directives limit the quirk to your touchpad, make sure the device name
matches your device's name (see ``libinput record``'s output). The dmi
modalias match should be based on the information in
``/sys/class/dmi/id/modalias``. This modalias should be shortened to the
specific system's information, usually system vendor (svn)
and product name (pn).
Once in place, run the following command to verify the quirk is valid and
works for your device: ::
$ sudo libinput list-quirks /dev/input/event10
AttrPressureRange=10:8
Replace the event node with the one from your device. If the
``AttrPressureRange`` quirk does not show up, re-run with ``--verbose`` and
check the output for any error messages.
If the pressure range quirk shows up correctly, restart X or the
Wayland compositor and libinput should now use the correct pressure
thresholds. The :ref:`tools` can be used to verify the correct
functionality first without the need for a restart.
Once the pressure ranges are deemed correct,
:ref:`report a bug ` to get the pressure ranges into the
repository.
.. _touchpad_touch_size_hwdb:
------------------------------------------------------------------------------
Debugging touch size ranges
------------------------------------------------------------------------------
This section describes how to determine the touchpad size ranges
required for a touchpad device and how to add the required
:ref:`device-quirks` locally. Note that the quirk is **not public API** and **may
change at any time**. Users are advised to :ref:`report a bug `
with the updated pressure ranges when testing has completed.
.. note:: Most distributions ship ``libinput measure`` in a separate
``libinput-utils`` package.
Use the ``libinput measure touch-size`` tool provided by libinput.
This tool will search for your touchpad device and print some touch size
statistics, including whether a touch is/was considered logically down.
.. note:: This tool will only work on touchpads with the ``ABS_MT_MAJOR`` axis.
Example output of the tool is below: ::
$ sudo libinput measure touch-size --touch-thresholds 10:8 --palm-threshold 14
Using ELAN Touchscreen: /dev/input/event5
Ready for recording data.
Touch sizes used: 10:8
Palm size used: 14
Place a single finger on the device to measure touch size.
Ctrl+C to exit
Sequence: major: [ 9.. 11] minor: [ 7.. 9]
Sequence: major: [ 9.. 10] minor: [ 7.. 7]
Sequence: major: [ 9.. 14] minor: [ 6.. 9] down
Sequence: major: [ 11.. 11] minor: [ 9.. 9] down
Sequence: major: [ 4.. 33] minor: [ 1.. 5] down palm
The example output shows five completed touch sequences. For each, the
respective minimum and maximum pressure values are printed as well as some
statistics. The ``down`` and ``palm`` tags show that sequence was considered
logically down or a palm at some point. This is an interactive tool and its
output may change frequently. Refer to the **libinput-measure-touch-size(1)** man
page for more details.
By default, this tool uses the :ref:`device-quirks` for the touch size range. To
narrow down on the best values for your device, specify the 'logically down'
and 'logically up' pressure thresholds with the ``--touch-thresholds``
arguments as in the example above.
Interact with the touchpad and check if the output of this tool matches your
expectations.
.. note:: This is an interactive process. You will need to re-run the
tool with varying thresholds until you find the right range for
your touchpad. Attaching output logs to a bug will not help, only
you with access to the hardware can figure out the correct
ranges.
Once the thresholds are decided on (e.g. 10 and 8), they can be enabled with
:ref:`device-quirks` entry similar to this: ::
$> cat /etc/libinput/local-overrides.quirks
[Touchpad touch size override]
MatchUdevType=touchpad
MatchName=*SynPS/2 Synaptics TouchPad
MatchDMIModalias=dmi:*svnLENOVO:*:pvrThinkPadX230*
AttrTouchSizeRange=10:8
The first line is the match line and should be adjusted for the device name
(see :ref:`libinput record `'s output) and for the local system, based on the
information in ``/sys/class/dmi/id/modalias``. The modalias should be
shortened to the specific system's information, usually system vendor (svn)
and product name (pn).
Once in place, run the following command to verify the quirk is valid and
works for your device: ::
$ sudo libinput list-quirks /dev/input/event10
AttrTouchSizeRange=10:8
Replace the event node with the one from your device. If the
``AttrTouchSizeRange`` quirk does not show up, re-run with ``--verbose`` and
check the output for any error messages.
If the touch size range property shows up correctly, restart X or the
Wayland compositor and libinput should now use the correct thresholds.
The :ref:`tools` can be used to verify the correct functionality first without
the need for a restart.
Once the touch size ranges are deemed correct, :ref:`reporting_bugs` "report a
bug" to get the thresholds into the repository.
libinput-1.28.1/doc/user/touchpad-pressure.rst000066400000000000000000000062501477265155700214110ustar00rootroot00000000000000.. _touchpad_pressure:
==============================================================================
Touchpad pressure-based touch detection
==============================================================================
libinput uses the touchpad pressure values and/or touch size values to
detect whether a finger has been placed on the touchpad. This is
:ref:`kernel_pressure_information` and combines with a libinput-specific hardware
database to adjust the thresholds on a per-device basis. libinput uses
these thresholds primarily to filter out accidental light touches but
the information is also used for some :ref:`palm_detection`.
Most devices only support one of either touch pressure or touch size.
libinput uses whichever is available but a preference is given to touch size
as it provides more specific information. Since most devices only provide
one type anyway, this internal preference does not usually matter.
Pressure and touch size thresholds are **not** directly configurable by the
user. Instead, libinput provides these thresholds for each device where
necessary. See :ref:`touchpad_pressure_hwdb` for instructions on how to adjust
the pressure ranges and :ref:`touchpad_touch_size_hwdb` for instructions on
how to adjust the touch size ranges.
.. _kernel_pressure_information:
------------------------------------------------------------------------------
Information provided by the kernel
------------------------------------------------------------------------------
The kernel sends multiple values to inform userspace about a finger touching
the touchpad. The most basic is the ``EV_KEY/BTN_TOUCH`` boolean event
that simply announces physical contact with the touchpad. The decision when
this event is sent is usually made by the kernel driver and may depend on
device-specific thresholds. These thresholds are transparent to userspace
and cannot be modified. On touchpads where pressure or touch size is not
available, libinput uses ``BTN_TOUCH`` to determine when a finger is
logically down.
Many contemporary touchpad devices provide an absolute pressure axis in
addition to ``BTN_TOUCH``. This pressure generally increases as the pressure
increases, however few touchpads are capable of detecting true pressure. The
pressure value is usually related to the covered area - as the pressure
increases a finger flattens and thus covers a larger area. The range
provided by the kernel is not mapped to a specific physical range and
often requires adjustment. Pressure is sent by the ``ABS_PRESSURE`` axis
for single-touch touchpads or ``ABS_MT_PRESSURE`` on multi-touch capable
touchpads. Some devices can detect multiple fingers but only provide
``ABS_PRESSURE``.
Some devices provide additional touch size information through
the ``ABS_MT_TOUCH_MAJOR/ABS_MT_TOUCH_MINOR`` axes and/or
the ``ABS_MT_WIDTH_MAJOR/ABS_MT_WIDTH_MINOR`` axes. These axes specifcy
the size of the touch ellipse. While the kernel documentation specifies how
these axes are supposed to be mapped, few devices forward reliable
information. libinput uses these values together with a device-specific
:ref:`device-quirks` entry. In other words, touch size detection does not work
unless a device quirk is present for the device.
libinput-1.28.1/doc/user/touchpad-thumb-detection.rst000066400000000000000000000075611477265155700226420ustar00rootroot00000000000000.. _thumb_detection:
==============================================================================
Thumb detection
==============================================================================
Thumb detection tries to identify touches triggered by a thumb rather than a
pointer-moving finger. This is necessary on :ref:`touchpads_buttons_clickpads`
as a finger pressing a button always creates a new touch, causing
misinterpretation of gestures. Click-and-drag with two fingers (one holding
the button, one moving) would be interpreted as two-finger scrolling without
working thumb detection.
libinput has built-in thumb detection, partially dependent on
hardware-specific capabilities.
- :ref:`thumb_pressure`
- :ref:`thumb_areas`
- :ref:`thumb_speed`
Thumb detection uses multiple approaches and the final decision on whether
to ignore a thumb depends on the interaction at the time.
.. _thumb_pressure:
------------------------------------------------------------------------------
Thumb detection based on pressure or size
------------------------------------------------------------------------------
The simplest form of thumb detection identifies a touch as thumb when the
pressure value goes above a certain threshold. This threshold is usually
high enough that it cannot be triggered by a finger movement.
On touchpads that support the ``ABS_MT_TOUCH_MAJOR`` axes, libinput can perform
thumb detection based on the size of the touch ellipse. This works similar to
the pressure-based palm detection in that a touch is labelled as palm when
it exceeds the (device-specific) touch size threshold.
Pressure- and size-based thumb detection depends on the location of the
thumb and usually only applies within the :ref:`thumb_areas`.
For some information on how to detect pressure on a touch and debug the
pressure ranges, see :ref:`touchpad_pressure`. Pressure- and size-based
thumb detection require thresholds set in the :ref:`device-quirks`.
.. _thumb_areas:
------------------------------------------------------------------------------
Thumb detection areas
------------------------------------------------------------------------------
Pressure and size readings are unreliable at the far bottom of the touchpad.
A thumb hanging mostly off the touchpad will have a small surface area.
libinput has a definitive thumb zone where any touch is considered a
thumb. Immediately above that area is the area where libinput will label a
thumb as such if the pressure or size thresholds are exceeded.
.. figure:: thumb-detection.svg
:align: center
The picture above shows the two detection areas. In the larger (light red)
area, a touch is labelled as thumb when it exceeds a device-specific
pressure threshold. In the lower (dark red) area, a touch is always labelled
as thumb.
Moving outside the areas generally releases the thumb from being a thumb.
.. _thumb_speed:
------------------------------------------------------------------------------
Thumb movement based on speed
------------------------------------------------------------------------------
Regular interactions with thumbs do not usually move the thumb. When fingers
are moving across the touchpad and a thumb is dropped, this can cause
erroneous scroll motion or similar issues. libinput observes the finger
motion speed for all touches - where a finger has been moving a newly
dropped finger is more likely to be labeled as thumb.
------------------------------------------------------------------------------
Thumb detection based on finger positions
------------------------------------------------------------------------------
The shape of the human hand and the interactions that usually involve a
thumb imply that a thumb is situated in a specific position relative to
other fingers (usually to the side and below). This is used by libinput to
detect thumbs during some interactions that do not implicitly require a
thumb (e.g. pinch-and-rotate).
libinput-1.28.1/doc/user/touchpads.rst000066400000000000000000000233011477265155700177220ustar00rootroot00000000000000:orphan:
.. _touchpads:
==============================================================================
Touchpads
==============================================================================
This page provides an outline of touchpad devices. Touchpads aren't simply
categorised into a single type, instead they have a set of properties, a
combination of number of physical buttons, multitouch support abilities and
other properties.
.. _touchpads_buttons:
------------------------------------------------------------------------------
Number of buttons
------------------------------------------------------------------------------
.. _touchapds_buttons_phys:
..............................................................................
Physically separate buttons
..............................................................................
Touchpads with physical buttons usually provide two buttons, left and right.
A few touchpads with three buttons exist, and Apple used to have touchpads
with a single physical buttons until ca 2008. Touchpads with only two
buttons require the software stack to emulate a middle button. libinput does
this when both buttons are pressed simultaneously.
Note that many Lenovo laptops provide a pointing stick above the touchpad.
This pointing stick has a set of physical buttons just above the touchpad.
While many users use those as substitute touchpad buttons, they logically
belong to the pointing stick. The \*40 and \*50 series are an exception here,
the former had no physical buttons on the touchpad and required the top
section of the pad to emulate pointing stick buttons, the \*50 series has
physical buttons but they are wired to the touchpads. The kernel re-routes
those buttons through the trackstick device. See :ref:`t440_support` for more
information.
.. _touchpads_buttons_clickpads:
..............................................................................
Clickpads
..............................................................................
Clickpads are the most common type of touchpads these days. A Clickpad has
no separate physical buttons, instead the touchpad itself is clickable as a
whole, i.e. a user presses down on the touch area and triggers a physical
click. Clickpads thus only provide a single button, everything else needs to
be software-emulated. See :ref:`clickpad_softbuttons` for more information.
Clickpads are labelled by the kernel with the **INPUT_PROP_BUTTONPAD** input
property.
.. _touchpads_buttons_forcepads:
..............................................................................
Forcepads
..............................................................................
Forcepads are Clickpads without a physical button underneath the hardware.
They provide pressure and may have a vibration element that is
software-controlled. This element can simulate the feel of a physical
click or be co-opted for other tasks.
.. _touchpads_touch:
------------------------------------------------------------------------------
Touch capabilities
------------------------------------------------------------------------------
Virtually all touchpads available now can **detect** multiple fingers on
the touchpad, i.e. provide information on how many fingers are on the
touchpad. The touch capabilities described here specify how many fingers a
device can **track**, i.e. provide reliable positional information for.
In the kernel each finger is tracked in a so-called "slot", the number of
slots thus equals the number of simultaneous touches a device can track.
.. _touchapds_touch_st:
..............................................................................
Single-touch touchpads
..............................................................................
Single-finger touchpads can track a single touchpoint. Most single-touch
touchpads can also detect three fingers on the touchpad, but no positional
information is provided for those. In libinput, these touches are termed
"fake touches". The kernel sends **BTN_TOOL_DOUBLETAP**,
**BTN_TOOL_TRIPLETAP**, **BTN_TOOL_QUADTAP** and **BTN_TOOL_QUINTTAP**
events when multiple fingers are detected.
.. _touchpads_touch_mt:
..............................................................................
Pure multi-touch touchpads
..............................................................................
Pure multi-touch touchpads are those that can track, i.e. identify the
location of all fingers on the touchpad. Apple's touchpads support 16
touches, others support 5 touches like the Synaptics touchpads when using
SMBus.
These touchpads usually also provide extra information. Apple touchpads
provide an ellipse and the orientation of the ellipse for each touch point.
Other touchpads provide a pressure value for each touch point (see
:ref:`touchpads_pressure_handling`).
Note that the kernel sends **BTN_TOOL_DOUBLETAP**,
**BTN_TOOL_TRIPLETAP**, **BTN_TOOL_QUADTAP** and **BTN_TOOL_QUINTTAP**
events for all touches for backwards compatibility. libinput ignores these
events if the touchpad can track touches correctly.
.. _touchpads_touch_partial_mt:
..............................................................................
Partial multi-touch touchpads
..............................................................................
The vast majority of touchpads fall into this category, the half-way
point between single-touch and pure multi-touch. These devices can track N
fingers, but detect more than N. For example, when using the serial
protocol, Synaptics touchpads can track two fingers but may detect up to
five.
The number of slots may limit which features are available in libinput.
Any device with two slots can support two-finger scrolling, but
:ref:`thumb-detection` or :ref:`palm_detection` may be limited if only two
slots are available.
.. _touchpads_touch_semi_mt:
..............................................................................
Semi-mt touchpads
..............................................................................
A sub-class of partial multi-touch touchpads. These touchpads can
technically detect two fingers but the location of both is limited to the
bounding box, i.e. the first touch is always the top-left one and the second
touch is the bottom-right one. Coordinates jump around as fingers move past
each other.
Many semi-mt touchpads also have a lower resolution for the second touch, or
both touches. This may limit some features such as :ref:`gestures` or
:ref:`scrolling`.
Semi-mt are labelled by the kernel with the **INPUT_PROP_SEMI_MT** input
property.
.. _touchpads_mis:
------------------------------------------------------------------------------
Other touchpad properties
------------------------------------------------------------------------------
.. _touchpads_external:
..............................................................................
External touchpads
..............................................................................
External touchpads are USB or Bluetooth touchpads not in a laptop chassis,
e.g. Apple Magic Trackpad or the Logitech T650. These are usually
:ref:`touchpads_buttons_clickpads` the biggest difference is that they can be
removed or added at runtime.
One interaction method that is only possible on external touchpads is a
thumb resting on the very edge/immediately next to the touchpad. On the far
edge, touchpads don't always detect the finger location so clicking with a
thumb barely touching the edge makes it hard or impossible to figure out
which software button area the finger is on.
These touchpads also don't need :ref:`palm_detection` - since they're not
located underneath the keyboard, accidental palm touches are a non-issue.
.. _touchpads_pressure_handling:
..............................................................................
Touchpads pressure handling
..............................................................................
Pressure is usually directly related to contact area. Human fingers flatten
out as the pressure on the pad increases, resulting in a bigger contact area
and the firmware then calculates that back into a pressure reading.
libinput uses pressure to detect accidental palm contact and thumbs, though
pressure data is often device-specific and unreliable.
.. _touchpads_circular:
..............................................................................
Circular touchpads
..............................................................................
Only listed for completeness, circular touchpads have not been used in
laptops for a number of years. These touchpad shaped in an ellipse or
straight.
.. _touchpads_tablets:
..............................................................................
Graphics tablets
..............................................................................
Touch-capable graphics tablets are effectively external touchpads, with two
differentiators: they are larger than normal touchpads and they have no
regular touchpad buttons. They either work like a
:ref:`touchpads_buttons_forcepads` Forcepad, or rely on interaction methods that
don't require buttons (like :ref:`tapping`). Since the physical device is
shared with the pen input, some touch arbitration is required to avoid touch
input interfering when the pen is in use.
.. _touchpads_edge_zone:
..............................................................................
Dedicated edge scroll area
..............................................................................
Before :ref:`twofinger_scrolling` became the default scroll method, some
touchpads provided a marking on the touch area that designates the
edge to be used for scrolling. A finger movement in that edge zone should
trigger vertical motions. Some touchpads had markers for a horizontal
scroll area too at the bottom of the touchpad.
libinput-1.28.1/doc/user/trackpoint-configuration.rst000066400000000000000000000133451477265155700227620ustar00rootroot00000000000000.. _trackpoint_configuration:
==============================================================================
Trackpoint configuration
==============================================================================
The sections below describe the trackpoint magic multiplier and how to apply
it to your local device. See :ref:`trackpoint_range` for an explanation on
why this multiplier is needed.
.. note:: The magic trackpoint multiplier **is not user visible configuration**. It is
part of the :ref:`device-quirks` system and provided once per device.
User-specific preferences can be adjusted with the
:ref:`config_pointer_acceleration` setting.
.. _trackpoint_multiplier:
------------------------------------------------------------------------------
The magic trackpoint multiplier
------------------------------------------------------------------------------
To accommodate for the wildly different input data on trackpoint, libinput
uses a multiplier that is applied to input deltas. Trackpoints that send
comparatively high deltas can be "slowed down", trackpoints that send low
deltas can be "sped up" to match the expected range. The actual acceleration
profile is applied to these pre-multiplied deltas.
Given a trackpoint delta ``(dx, dy)``, a multiplier ``M`` and a pointer acceleration
function ``f(dx, dy) → (dx', dy')``, the algorithm is effectively:
::
f(M * dx, M * dy) → (dx', dy')
.. _trackpoint_multiplier_adjustment:
..............................................................................
Adjusting the magic trackpoint multiplier
..............................................................................
This section only applies if:
- the trackpoint default speed (speed setting 0) is unusably slow or
unusably fast, **and**
- the lowest speed setting (-1) is still too fast **or** the highest speed
setting is still too slow, **and**
- the :ref:`device-quirks` for this device do not list a trackpoint multiplier
(see :ref:`device-quirks-debugging`)
If the only satisfactory speed settings are less than -0.75 or greater than
0.75, a multiplier *may* be required.
A specific multiplier will apply to **all users with the same laptop
model**, so proceed with caution. You must be capable/willing to adjust
device quirks, build libinput from source and restart the session frequently
to adjust the multiplier. If this does not apply, wait for someone else with
the same hardware to do this.
Finding the correct multiplier is difficult and requires some trial and
error. The default multiplier is always 1.0. A value between 0.0 and 1.0
slows the trackpoint down, a value above 1.0 speeds the trackpoint up.
Values below zero are invalid.
.. warning:: The multiplier is not a configuration to adjust to personal
preferences. The multiplier normalizes the input data into a range that
can then be configured with the speed setting.
To adjust the local multiplier, first
:ref:`build libinput from git master `. It is not
required to install libinput from git. The below assumes that all
:ref:`building_dependencies` are already
installed.
::
$ cd path/to/libinput.git
# Use an approximate multiplier in the quirks file
$ cat > quirks/99-trackpoint-override.quirks <` with the contents of
the file. Alternatively, file a merge request with the data added.
.. _trackpoint_range_measure:
------------------------------------------------------------------------------
Measuring the trackpoint range
------------------------------------------------------------------------------
This section only applied to libinput version 1.9.x, 1.10.x, and 1.11.x and
has been removed. See :ref:`trackpoint_multiplier` for versions 1.12.x and later.
If using libinput version 1.11.x or earlier, please see
`the 1.11.0 documentation `_
libinput-1.28.1/doc/user/trackpoints.rst000066400000000000000000000056261477265155700203030ustar00rootroot00000000000000.. _trackpoints:
==============================================================================
Trackpoints and Pointing Sticks
==============================================================================
This page provides an overview of trackpoint handling in libinput, also
referred to as Pointing Stick or Trackstick. The device itself is usually a
round plastic stick between the G, H and B keys with a set of buttons below
the space bar.
.. figure:: button-scrolling.svg
:align: center
A trackpoint
libinput always treats the buttons below the space bar as the buttons that
belong to the trackpoint even on the few laptops where the buttons are not
physically wired to the trackpoint device anyway, see :ref:`t440_support`.
.. _trackpoint_buttonscroll:
------------------------------------------------------------------------------
Button scrolling on trackpoints
------------------------------------------------------------------------------
Trackpoint devices have :ref:`button_scrolling` enabled by default. This may
interfer with middle-button dragging, if middle-button dragging is required
by a user then button scrolling must be disabled.
.. _trackpoint_range:
------------------------------------------------------------------------------
Motion range on trackpoints
------------------------------------------------------------------------------
It is difficult to associate motion on a trackpoint with a physical
reference. Unlike mice or touchpads where the motion can be
measured in mm, the trackpoint only responds to pressure. Without special
equipment it is impossible to measure identical pressure values across
multiple laptops.
The values provided by a trackpoint are motion deltas, usually corresponding
to the pressure applied to the trackstick. For example, pressure towards the
screen on a laptop provides negative y deltas. The reporting rate increases
as the pressure increases and once events are reported at the maximum rate,
the delta values increase. The figure below shows a rough illustration of
this concept. As the pressure
decreases, the delta decrease first, then the reporting rate until the
trackpoint is in a neutral state and no events are reported. Trackpoint data
is hard to generalize, see
`Observations on trackpoint input data
`_
for more details.
.. figure:: trackpoint-delta-illustration.svg
:align: center
Illustration of the relationship between reporting rate and delta values on a trackpoint
The delta range itself can vary greatly between laptops, some devices send a
maximum delta value of 30, others can go beyond 100. However, the useful
delta range is a fraction of the maximum range. It is uncomfortable to exert
sufficient pressure to even get close to the maximum ranges.
libinput provides a :ref:`Magic Trackpoint Multiplier
` to normalize the trackpoint input data.
libinput-1.28.1/doc/user/troubleshooting.rst000066400000000000000000000007621477265155700211650ustar00rootroot00000000000000.. _troubleshooting:
==============================================================================
Troubleshooting
==============================================================================
.. toctree::
:maxdepth: 2
tools.rst
device-quirks.rst
touchpad-jumping-cursors.rst
touchpad-jitter.rst
touchpad-pressure-debugging.rst
trackpoint-configuration.rst
tablet-debugging.rst
incorrectly-enabled-hires.rst
clickpad-with-right-button.rst
ignoring-devices.rst
libinput-1.28.1/doc/user/what-is-libinput.rst000066400000000000000000000156031477265155700211360ustar00rootroot00000000000000
.. _what_is_libinput:
==============================================================================
What is libinput?
==============================================================================
This page describes what libinput is, but more importantly it also describes
what libinput is **not**.
.. _what_libinput_is:
------------------------------------------------------------------------------
What libinput is
------------------------------------------------------------------------------
libinput is an input stack for processes that need to provide events from
commonly used input devices. That includes mice, keyboards, touchpads,
touchscreens and graphics tablets. libinput handles device-specific quirks
and provides an easy-to-use API to receive events from devices.
libinput is designed to handle all input devices available on a system but
it is possible to limit which devices libinput has access to.
For example, the use of xf86-input-libinput depends on xorg.conf snippets
for specific devices. But libinput works best if it handles all input
devices as this allows for smarter handling of features that affect multiple
devices.
libinput restricts device-specific features to those devices that require
those features. One example for this are the top software buttons on the
touchpad in the Lenovo T440. While there may be use-cases for providing top
software buttons on other devices, libinput does not do so.
`This introductory blog post from 2015
`_
describes some of the motivations.
.. _what_libinput_is_not:
------------------------------------------------------------------------------
What libinput is not
------------------------------------------------------------------------------
libinput is **not** a project to support experimental devices. Unless a
device is commonly available off-the-shelf, libinput will not support this
device. libinput can serve as a useful base for getting experimental devices
enabled and reduce the amount of boilerplate required. But such support will
not land in libinput master until the devices are commonly available.
libinput is **not** a box of legos. It does not provide the pieces to
assemble a selection of features. Many features can be disabled through
configuration options, but some features are hardcoded and/or only available
on some devices. There are plenty of use-cases to provide niche features,
but libinput is not the place to support these.
libinput is **not** a showcase for features. There are a lot of potential
features that could be provided on input devices. But unless they have
common usage, libinput is not the place to implement them. Every feature
multiplies the maintenance effort, any feature that is provided but unused
is a net drain on the already sparse developer resources libinput has
available.
libinput is boring. It does not intend to break new grounds on how devices
are handled. Instead, it takes best practice and the common use-cases and
provides it in an easy-to-consume package for compositors or other processes
that need those interactions typically expected by users.
.. _libinput-wayland:
------------------------------------------------------------------------------
libinput and Wayland
------------------------------------------------------------------------------
libinput is not used directly by Wayland applications, it is an input stack
used by the compositor. The typical software stack for a system running
Wayland is:
.. graphviz:: libinput-stack-wayland.gv
The Wayland compositor may be Weston, mutter, KWin, etc. Note that
Wayland encourages the use of toolkits, so the Wayland client (your
application) does not usually talk directly to the compositor but rather
employs a toolkit (e.g. GTK) to do so. The Wayland client does not know
whether libinput is in use.
libinput is not a requirement for Wayland or even a Wayland compositor.
There are some specialized compositors that do not need or want libinput.
.. _libinput-xorg:
------------------------------------------------------------------------------
libinput and X.Org
------------------------------------------------------------------------------
libinput is not used directly by X applications but rather through the
custom xf86-input-libinput driver. The simplified software stack for a
system running X.Org is:
.. graphviz:: libinput-stack-xorg.gv
libinput is not employed directly by the X server but by the
xf86-input-libinput driver instead. That driver is loaded by the server
on demand, depending on the xorg.conf.d configuration snippets. The X client
does not know whether libinput is in use.
libinput and xf86-input-libinput are not a requirement, the driver will only
handle those devices explicitly assigned through an xorg.conf.d snippets. It
is possible to mix xf86-input-libinput with other X.Org drivers.
------------------------------------------------------------------------------
Device types
------------------------------------------------------------------------------
libinput handles all common devices used to interact with a desktop system.
This includes mice, keyboards, touchscreens, touchpads and graphics tablets.
libinput does not expose the device type to the caller, it solely provides
capabilities and the attached features (see
`this blog post `_).
For example, a touchpad in libinput is a device that provides pointer
events, gestures and has a number of :ref:`config_options` such as
:ref:`tapping`. A caller may present the device as touchpad to the user, or
simply as device with a config knob to enable or disable tapping.
..............................................................................
Handled device types
..............................................................................
- :ref:`Touchpads`
- Touchscreens
- Mice
- Keyboards
- Virtual absolute pointing devices such as those used by QEMU or VirtualBox
- Switches (Lid Switch and Tablet Mode switch)
- Graphics tablets
- :ref:`Trackpoints`
If a device falls into one of the above categories but does not work as
expected, please :ref:`file a bug `.
..............................................................................
Unhandled device types
..............................................................................
libinput does not handle some devices. The primary reason is that these
device have no clear interaction with a desktop environment.
Joysticks:
Joysticks have one or more axes and one or more buttons. Beyond that it is
difficult to find common ground between joysticks and much of the
interaction is application-specific, not system-specific. libinput does not
provide support for joysticks for that reason, any abstraction libinput
would provide for joysticks would be so generic that libinput would
merely introduce complexity and processing delays for no real benefit.
libinput-1.28.1/doc/user/wheel-api.rst000066400000000000000000000221661477265155700176130ustar00rootroot00000000000000.. _wheel_scrolling:
==============================================================================
Wheel scrolling
==============================================================================
libinput provides two events to handle wheel scrolling:
- ``LIBINPUT_EVENT_POINTER_AXIS`` events are sent for regular wheel clicks,
usually those representing one detent on the device. These wheel clicks
usually require a rotation of 15 or 20 degrees.
**This event is deprecated as of libinput 1.19.**
- ``LIBINPUT_EVENT_POINTER_SCROLL_WHEEL`` events are sent for regular and/or
high resolution wheel movements. High-resolution events are often 4 or 8
times more frequent than wheel clicks and require the device to be switched
into high-resolution mode (Linux kernel 5.0 and later). Where
high-resolution wheels are not provided by the kernel, libinput emulates
these events for regular wheel clicks.
**This event is available since libinput 1.19.**
The events are separate for historical reasons. Both events are
generated for the same device but are independent event streams. Callers
must not assume any relation between the two, i.e. there is no guarantee
that an axis event is sent before or after any specific high-resolution
event and vice versa. Callers should not handle both events.
.. warning:: do not handle both ``LIBINPUT_EVENT_POINTER_AXIS`` and
``LIBINPUT_EVENT_POINTER_SCROLL_WHEEL``. Always use the latter where
possible, otherwise only use the former.
Both events have their own set of APIs to access the data within:
- ``LIBINPUT_EVENT_POINTER_AXIS``: Deprecated as of libinput 1.19, where
possible it is recommended to handle **only**
``LIBINPUT_EVENT_POINTER_SCROLL_WHEEL``.
* ``libinput_event_pointer_get_axis_value()`` returns the angle of movement
in degrees.
* ``libinput_event_pointer_get_axis_source()`` returns the source of the
event: wheel, finger or continuous.
* ``libinput_event_pointer_get_axis_value_discrete()`` returns the number of
logical wheel clicks.
- ``LIBINPUT_EVENT_POINTER_SCROLL_WHEEL`` available since libinput 1.19.
* ``libinput_event_pointer_get_scroll_value_v120()`` returns a value
normalized into the 0..120 range, see below. Any multiple of 120 should
be treated as one full wheel click.
.. note:: Where possible, the ``libinput_event_pointer_get_axis_value()``,
``libinput_event_pointer_get_axis_source()`` and
``libinput_event_pointer_get_axis_value_discrete()`` API should be
avoided.
------------------------------------------------------------------------------
The v120 Wheel API
------------------------------------------------------------------------------
The ``v120`` value matches the Windows API for wheel scrolling. Wheel
movements are normalized into multiples (or fractions) of 120 with each
multiple of 120 representing one detent of movement. The ``v120`` API is the
recommended API for callers that do not care about the exact physical
motion and is the simplest API to handle high-resolution scrolling.
Most wheels provide 24 detents per 360 degree rotation (click angle of 15),
others provide 18 detents per 360 degree rotation (click angle 20). Mice
falling outside these two are rare but do exist. Below is a table showing
the various values for a single event, depending on the click angle of the
wheel:
+-------------+------------+---------------+------+
| Click angle | Axis value | Discrete value| v120 |
+=============+============+===============+======+
| 15 | 15 | 1 | 120 |
+-------------+------------+---------------+------+
| 20 | 20 | 1 | 120 |
+-------------+------------+---------------+------+
Fast scrolling may trigger cover than one detent per event and thus each
event may contain multiples of the value, discrete or v120 value:
+-------------+------------+---------------+------+
| Click angle | Axis value | Discrete value| v120 |
+=============+============+===============+======+
| 15 | 30 | 2 | 240 |
+-------------+------------+---------------+------+
| 20 | 60 | 3 | 360 |
+-------------+------------+---------------+------+
Scrolling on high-resolution wheels will produce fractions of 120, depending
on the resolution of the wheel. The example below shows a mouse with click
angle 15 and a resolution of 3 events per wheel click and a mouse with click
angle 20 and a resolution of 2 events per wheel click.
+-------------+------------+---------------+------+
| Click angle | Axis value | Discrete value| v120 |
+=============+============+===============+======+
| 15 | 5 | 0 | 40 |
+-------------+------------+---------------+------+
| 20 | 10 | 0 | 60 |
+-------------+------------+---------------+------+
------------------------------------------------------------------------------
Event sequences for high-resolution wheel mice
------------------------------------------------------------------------------
High-resolution scroll wheels provide multiple events for each detent is
hit. For those mice, an event sequence covering two detents may look like
this:
+--------------+---------+------------+---------------+------+
| Event number | Type | Axis value | Discrete value| v120 |
+==============+=========+============+===============+======+
| 1 | WHEEL | 5 | n/a | 40 |
+--------------+---------+------------+---------------+------+
| 2 | WHEEL | 5 | n/a | 40 |
+--------------+---------+------------+---------------+------+
| 3 | WHEEL | 5 | n/a | 40 |
+--------------+---------+------------+---------------+------+
| 4 | AXIS | 15 | 1 | 120 |
+--------------+---------+------------+---------------+------+
| 5 | WHEEL | 5 | n/a | 40 |
+--------------+---------+------------+---------------+------+
| 6 | WHEEL | 5 | n/a | 40 |
+--------------+---------+------------+---------------+------+
| 7 | AXIS | 15 | 1 | 120 |
+--------------+---------+------------+---------------+------+
The above assumes a click angle of 15 for the physical detents. Note how the
second set of high-resolution events do **not** add up to a multiple of
120 before the low-resolution event. A caller must not assume any relation
between ``LIBINPUT_EVENT_POINTER_SCROLL_WHEEL`` and
``LIBINPUT_EVENT_POINTER_AXIS``.
Fast-scrolling on a high-resolution mouse may trigger multiple fractions per
hardware scanout cycle and result in an event sequence like this:
+---------------+---------+------------+---------------+------+
| Event number | Type | Axis value | Discrete value| v120 |
+===============+=========+============+===============+======+
| 1 | WHEEL | 5 | n/a | 40 |
+---------------+---------+------------+---------------+------+
| 2 | WHEEL | 10 | n/a | 80 |
+---------------+---------+------------+---------------+------+
| 3 | AXIS | 15 | 1 | 120 |
+---------------+---------+------------+---------------+------+
| 4 | WHEEL | 10 | n/a | 80 |
+---------------+---------+------------+---------------+------+
| 5 | WHEEL | 10 | n/a | 80 |
+---------------+---------+------------+---------------+------+
| 6 | AXIS | 15 | 1 | 120 |
+---------------+---------+------------+---------------+------+
| 7 | WHEEL | 5 | n/a | 40 |
+---------------+---------+------------+---------------+------+
Note how the first low-resolution event is sent at an accumulated 15
degrees, the second at an accumulated 20 degrees. The libinput API does not
specify the smallest fraction a wheel supports.
------------------------------------------------------------------------------
Event sequences for regular wheel mice
------------------------------------------------------------------------------
``LIBINPUT_EVENT_POINTER_SCROLL_WHEEL`` for low-resolution mice are virtually
identical to ``LIBINPUT_EVENT_POINTER_AXIS`` events. Note that the discrete
value is always 0 for ``LIBINPUT_EVENT_POINTER_SCROLL_WHEEL``.
+--------------+---------+------------+---------------+------+
| Event number | Type | Axis value | Discrete value| v120 |
+==============+=========+============+===============+======+
| 1 | AXIS | 15 | 1 | 120 |
+--------------+---------+------------+---------------+------+
| 2 | WHEEL | 15 | n/a | 120 |
+--------------+---------+------------+---------------+------+
| 3 | WHEEL | 15 | n/a | 120 |
+--------------+---------+------------+---------------+------+
| 4 | AXIS | 15 | 1 | 120 |
+--------------+---------+------------+---------------+------+
Note that the order of ``LIBINPUT_EVENT_POINTER_AXIS`` vs
``LIBINPUT_EVENT_POINTER_SCROLL_WHEEL`` events is not guaranteed, as shown in
the example above.
libinput-1.28.1/include/000077500000000000000000000000001477265155700150775ustar00rootroot00000000000000libinput-1.28.1/include/linux/000077500000000000000000000000001477265155700162365ustar00rootroot00000000000000libinput-1.28.1/include/linux/freebsd/000077500000000000000000000000001477265155700176505ustar00rootroot00000000000000libinput-1.28.1/include/linux/freebsd/input-event-codes.h000066400000000000000000000672351477265155700234070ustar00rootroot00000000000000/* SPDX-License-Identifier: GPL-2.0-only WITH Linux-syscall-note */
/*
* Input event codes
*
* *** IMPORTANT ***
* This file is not only included from C-code but also from devicetree source
* files. As such this file MUST only contain comments and defines.
*
* Copyright (c) 1999-2002 Vojtech Pavlik
* Copyright (c) 2015 Hans de Goede
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 as published by
* the Free Software Foundation.
*/
#ifndef _UAPI_INPUT_EVENT_CODES_H
#define _UAPI_INPUT_EVENT_CODES_H
/*
* Device properties and quirks
*/
#define INPUT_PROP_POINTER 0x00 /* needs a pointer */
#define INPUT_PROP_DIRECT 0x01 /* direct input devices */
#define INPUT_PROP_BUTTONPAD 0x02 /* has button(s) under pad */
#define INPUT_PROP_SEMI_MT 0x03 /* touch rectangle only */
#define INPUT_PROP_TOPBUTTONPAD 0x04 /* softbuttons at top of pad */
#define INPUT_PROP_POINTING_STICK 0x05 /* is a pointing stick */
#define INPUT_PROP_ACCELEROMETER 0x06 /* has accelerometer */
#define INPUT_PROP_MAX 0x1f
#define INPUT_PROP_CNT (INPUT_PROP_MAX + 1)
/*
* Event types
*/
#define EV_SYN 0x00
#define EV_KEY 0x01
#define EV_REL 0x02
#define EV_ABS 0x03
#define EV_MSC 0x04
#define EV_SW 0x05
#define EV_LED 0x11
#define EV_SND 0x12
#define EV_REP 0x14
#define EV_FF 0x15
#define EV_PWR 0x16
#define EV_FF_STATUS 0x17
#define EV_MAX 0x1f
#define EV_CNT (EV_MAX+1)
/*
* Synchronization events.
*/
#define SYN_REPORT 0
#define SYN_CONFIG 1
#define SYN_MT_REPORT 2
#define SYN_DROPPED 3
#define SYN_MAX 0xf
#define SYN_CNT (SYN_MAX+1)
/*
* Keys and buttons
*
* Most of the keys/buttons are modeled after USB HUT 1.12
* (see http://www.usb.org/developers/hidpage).
* Abbreviations in the comments:
* AC - Application Control
* AL - Application Launch Button
* SC - System Control
*/
#define KEY_RESERVED 0
#define KEY_ESC 1
#define KEY_1 2
#define KEY_2 3
#define KEY_3 4
#define KEY_4 5
#define KEY_5 6
#define KEY_6 7
#define KEY_7 8
#define KEY_8 9
#define KEY_9 10
#define KEY_0 11
#define KEY_MINUS 12
#define KEY_EQUAL 13
#define KEY_BACKSPACE 14
#define KEY_TAB 15
#define KEY_Q 16
#define KEY_W 17
#define KEY_E 18
#define KEY_R 19
#define KEY_T 20
#define KEY_Y 21
#define KEY_U 22
#define KEY_I 23
#define KEY_O 24
#define KEY_P 25
#define KEY_LEFTBRACE 26
#define KEY_RIGHTBRACE 27
#define KEY_ENTER 28
#define KEY_LEFTCTRL 29
#define KEY_A 30
#define KEY_S 31
#define KEY_D 32
#define KEY_F 33
#define KEY_G 34
#define KEY_H 35
#define KEY_J 36
#define KEY_K 37
#define KEY_L 38
#define KEY_SEMICOLON 39
#define KEY_APOSTROPHE 40
#define KEY_GRAVE 41
#define KEY_LEFTSHIFT 42
#define KEY_BACKSLASH 43
#define KEY_Z 44
#define KEY_X 45
#define KEY_C 46
#define KEY_V 47
#define KEY_B 48
#define KEY_N 49
#define KEY_M 50
#define KEY_COMMA 51
#define KEY_DOT 52
#define KEY_SLASH 53
#define KEY_RIGHTSHIFT 54
#define KEY_KPASTERISK 55
#define KEY_LEFTALT 56
#define KEY_SPACE 57
#define KEY_CAPSLOCK 58
#define KEY_F1 59
#define KEY_F2 60
#define KEY_F3 61
#define KEY_F4 62
#define KEY_F5 63
#define KEY_F6 64
#define KEY_F7 65
#define KEY_F8 66
#define KEY_F9 67
#define KEY_F10 68
#define KEY_NUMLOCK 69
#define KEY_SCROLLLOCK 70
#define KEY_KP7 71
#define KEY_KP8 72
#define KEY_KP9 73
#define KEY_KPMINUS 74
#define KEY_KP4 75
#define KEY_KP5 76
#define KEY_KP6 77
#define KEY_KPPLUS 78
#define KEY_KP1 79
#define KEY_KP2 80
#define KEY_KP3 81
#define KEY_KP0 82
#define KEY_KPDOT 83
#define KEY_ZENKAKUHANKAKU 85
#define KEY_102ND 86
#define KEY_F11 87
#define KEY_F12 88
#define KEY_RO 89
#define KEY_KATAKANA 90
#define KEY_HIRAGANA 91
#define KEY_HENKAN 92
#define KEY_KATAKANAHIRAGANA 93
#define KEY_MUHENKAN 94
#define KEY_KPJPCOMMA 95
#define KEY_KPENTER 96
#define KEY_RIGHTCTRL 97
#define KEY_KPSLASH 98
#define KEY_SYSRQ 99
#define KEY_RIGHTALT 100
#define KEY_LINEFEED 101
#define KEY_HOME 102
#define KEY_UP 103
#define KEY_PAGEUP 104
#define KEY_LEFT 105
#define KEY_RIGHT 106
#define KEY_END 107
#define KEY_DOWN 108
#define KEY_PAGEDOWN 109
#define KEY_INSERT 110
#define KEY_DELETE 111
#define KEY_MACRO 112
#define KEY_MUTE 113
#define KEY_VOLUMEDOWN 114
#define KEY_VOLUMEUP 115
#define KEY_POWER 116 /* SC System Power Down */
#define KEY_KPEQUAL 117
#define KEY_KPPLUSMINUS 118
#define KEY_PAUSE 119
#define KEY_SCALE 120 /* AL Compiz Scale (Expose) */
#define KEY_KPCOMMA 121
#define KEY_HANGEUL 122
#define KEY_HANGUEL KEY_HANGEUL
#define KEY_HANJA 123
#define KEY_YEN 124
#define KEY_LEFTMETA 125
#define KEY_RIGHTMETA 126
#define KEY_COMPOSE 127
#define KEY_STOP 128 /* AC Stop */
#define KEY_AGAIN 129
#define KEY_PROPS 130 /* AC Properties */
#define KEY_UNDO 131 /* AC Undo */
#define KEY_FRONT 132
#define KEY_COPY 133 /* AC Copy */
#define KEY_OPEN 134 /* AC Open */
#define KEY_PASTE 135 /* AC Paste */
#define KEY_FIND 136 /* AC Search */
#define KEY_CUT 137 /* AC Cut */
#define KEY_HELP 138 /* AL Integrated Help Center */
#define KEY_MENU 139 /* Menu (show menu) */
#define KEY_CALC 140 /* AL Calculator */
#define KEY_SETUP 141
#define KEY_SLEEP 142 /* SC System Sleep */
#define KEY_WAKEUP 143 /* System Wake Up */
#define KEY_FILE 144 /* AL Local Machine Browser */
#define KEY_SENDFILE 145
#define KEY_DELETEFILE 146
#define KEY_XFER 147
#define KEY_PROG1 148
#define KEY_PROG2 149
#define KEY_WWW 150 /* AL Internet Browser */
#define KEY_MSDOS 151
#define KEY_COFFEE 152 /* AL Terminal Lock/Screensaver */
#define KEY_SCREENLOCK KEY_COFFEE
#define KEY_ROTATE_DISPLAY 153 /* Display orientation for e.g. tablets */
#define KEY_DIRECTION KEY_ROTATE_DISPLAY
#define KEY_CYCLEWINDOWS 154
#define KEY_MAIL 155
#define KEY_BOOKMARKS 156 /* AC Bookmarks */
#define KEY_COMPUTER 157
#define KEY_BACK 158 /* AC Back */
#define KEY_FORWARD 159 /* AC Forward */
#define KEY_CLOSECD 160
#define KEY_EJECTCD 161
#define KEY_EJECTCLOSECD 162
#define KEY_NEXTSONG 163
#define KEY_PLAYPAUSE 164
#define KEY_PREVIOUSSONG 165
#define KEY_STOPCD 166
#define KEY_RECORD 167
#define KEY_REWIND 168
#define KEY_PHONE 169 /* Media Select Telephone */
#define KEY_ISO 170
#define KEY_CONFIG 171 /* AL Consumer Control Configuration */
#define KEY_HOMEPAGE 172 /* AC Home */
#define KEY_REFRESH 173 /* AC Refresh */
#define KEY_EXIT 174 /* AC Exit */
#define KEY_MOVE 175
#define KEY_EDIT 176
#define KEY_SCROLLUP 177
#define KEY_SCROLLDOWN 178
#define KEY_KPLEFTPAREN 179
#define KEY_KPRIGHTPAREN 180
#define KEY_NEW 181 /* AC New */
#define KEY_REDO 182 /* AC Redo/Repeat */
#define KEY_F13 183
#define KEY_F14 184
#define KEY_F15 185
#define KEY_F16 186
#define KEY_F17 187
#define KEY_F18 188
#define KEY_F19 189
#define KEY_F20 190
#define KEY_F21 191
#define KEY_F22 192
#define KEY_F23 193
#define KEY_F24 194
#define KEY_PLAYCD 200
#define KEY_PAUSECD 201
#define KEY_PROG3 202
#define KEY_PROG4 203
#define KEY_DASHBOARD 204 /* AL Dashboard */
#define KEY_SUSPEND 205
#define KEY_CLOSE 206 /* AC Close */
#define KEY_PLAY 207
#define KEY_FASTFORWARD 208
#define KEY_BASSBOOST 209
#define KEY_PRINT 210 /* AC Print */
#define KEY_HP 211
#define KEY_CAMERA 212
#define KEY_SOUND 213
#define KEY_QUESTION 214
#define KEY_EMAIL 215
#define KEY_CHAT 216
#define KEY_SEARCH 217
#define KEY_CONNECT 218
#define KEY_FINANCE 219 /* AL Checkbook/Finance */
#define KEY_SPORT 220
#define KEY_SHOP 221
#define KEY_ALTERASE 222
#define KEY_CANCEL 223 /* AC Cancel */
#define KEY_BRIGHTNESSDOWN 224
#define KEY_BRIGHTNESSUP 225
#define KEY_MEDIA 226
#define KEY_SWITCHVIDEOMODE 227 /* Cycle between available video
outputs (Monitor/LCD/TV-out/etc) */
#define KEY_KBDILLUMTOGGLE 228
#define KEY_KBDILLUMDOWN 229
#define KEY_KBDILLUMUP 230
#define KEY_SEND 231 /* AC Send */
#define KEY_REPLY 232 /* AC Reply */
#define KEY_FORWARDMAIL 233 /* AC Forward Msg */
#define KEY_SAVE 234 /* AC Save */
#define KEY_DOCUMENTS 235
#define KEY_BATTERY 236
#define KEY_BLUETOOTH 237
#define KEY_WLAN 238
#define KEY_UWB 239
#define KEY_UNKNOWN 240
#define KEY_VIDEO_NEXT 241 /* drive next video source */
#define KEY_VIDEO_PREV 242 /* drive previous video source */
#define KEY_BRIGHTNESS_CYCLE 243 /* brightness up, after max is min */
#define KEY_BRIGHTNESS_AUTO 244 /* Set Auto Brightness: manual
brightness control is off,
rely on ambient */
#define KEY_BRIGHTNESS_ZERO KEY_BRIGHTNESS_AUTO
#define KEY_DISPLAY_OFF 245 /* display device to off state */
#define KEY_WWAN 246 /* Wireless WAN (LTE, UMTS, GSM, etc.) */
#define KEY_WIMAX KEY_WWAN
#define KEY_RFKILL 247 /* Key that controls all radios */
#define KEY_MICMUTE 248 /* Mute / unmute the microphone */
/* Code 255 is reserved for special needs of AT keyboard driver */
#define BTN_MISC 0x100
#define BTN_0 0x100
#define BTN_1 0x101
#define BTN_2 0x102
#define BTN_3 0x103
#define BTN_4 0x104
#define BTN_5 0x105
#define BTN_6 0x106
#define BTN_7 0x107
#define BTN_8 0x108
#define BTN_9 0x109
#define BTN_MOUSE 0x110
#define BTN_LEFT 0x110
#define BTN_RIGHT 0x111
#define BTN_MIDDLE 0x112
#define BTN_SIDE 0x113
#define BTN_EXTRA 0x114
#define BTN_FORWARD 0x115
#define BTN_BACK 0x116
#define BTN_TASK 0x117
#define BTN_JOYSTICK 0x120
#define BTN_TRIGGER 0x120
#define BTN_THUMB 0x121
#define BTN_THUMB2 0x122
#define BTN_TOP 0x123
#define BTN_TOP2 0x124
#define BTN_PINKIE 0x125
#define BTN_BASE 0x126
#define BTN_BASE2 0x127
#define BTN_BASE3 0x128
#define BTN_BASE4 0x129
#define BTN_BASE5 0x12a
#define BTN_BASE6 0x12b
#define BTN_DEAD 0x12f
#define BTN_GAMEPAD 0x130
#define BTN_SOUTH 0x130
#define BTN_A BTN_SOUTH
#define BTN_EAST 0x131
#define BTN_B BTN_EAST
#define BTN_C 0x132
#define BTN_NORTH 0x133
#define BTN_X BTN_NORTH
#define BTN_WEST 0x134
#define BTN_Y BTN_WEST
#define BTN_Z 0x135
#define BTN_TL 0x136
#define BTN_TR 0x137
#define BTN_TL2 0x138
#define BTN_TR2 0x139
#define BTN_SELECT 0x13a
#define BTN_START 0x13b
#define BTN_MODE 0x13c
#define BTN_THUMBL 0x13d
#define BTN_THUMBR 0x13e
#define BTN_DIGI 0x140
#define BTN_TOOL_PEN 0x140
#define BTN_TOOL_RUBBER 0x141
#define BTN_TOOL_BRUSH 0x142
#define BTN_TOOL_PENCIL 0x143
#define BTN_TOOL_AIRBRUSH 0x144
#define BTN_TOOL_FINGER 0x145
#define BTN_TOOL_MOUSE 0x146
#define BTN_TOOL_LENS 0x147
#define BTN_TOOL_QUINTTAP 0x148 /* Five fingers on trackpad */
#define BTN_STYLUS3 0x149
#define BTN_TOUCH 0x14a
#define BTN_STYLUS 0x14b
#define BTN_STYLUS2 0x14c
#define BTN_TOOL_DOUBLETAP 0x14d
#define BTN_TOOL_TRIPLETAP 0x14e
#define BTN_TOOL_QUADTAP 0x14f /* Four fingers on trackpad */
#define BTN_WHEEL 0x150
#define BTN_GEAR_DOWN 0x150
#define BTN_GEAR_UP 0x151
#define KEY_OK 0x160
#define KEY_SELECT 0x161
#define KEY_GOTO 0x162
#define KEY_CLEAR 0x163
#define KEY_POWER2 0x164
#define KEY_OPTION 0x165
#define KEY_INFO 0x166 /* AL OEM Features/Tips/Tutorial */
#define KEY_TIME 0x167
#define KEY_VENDOR 0x168
#define KEY_ARCHIVE 0x169
#define KEY_PROGRAM 0x16a /* Media Select Program Guide */
#define KEY_CHANNEL 0x16b
#define KEY_FAVORITES 0x16c
#define KEY_EPG 0x16d
#define KEY_PVR 0x16e /* Media Select Home */
#define KEY_MHP 0x16f
#define KEY_LANGUAGE 0x170
#define KEY_TITLE 0x171
#define KEY_SUBTITLE 0x172
#define KEY_ANGLE 0x173
#define KEY_FULL_SCREEN 0x174 /* AC View Toggle */
#define KEY_ZOOM KEY_FULL_SCREEN
#define KEY_MODE 0x175
#define KEY_KEYBOARD 0x176
#define KEY_ASPECT_RATIO 0x177 /* HUTRR37: Aspect */
#define KEY_SCREEN KEY_ASPECT_RATIO
#define KEY_PC 0x178 /* Media Select Computer */
#define KEY_TV 0x179 /* Media Select TV */
#define KEY_TV2 0x17a /* Media Select Cable */
#define KEY_VCR 0x17b /* Media Select VCR */
#define KEY_VCR2 0x17c /* VCR Plus */
#define KEY_SAT 0x17d /* Media Select Satellite */
#define KEY_SAT2 0x17e
#define KEY_CD 0x17f /* Media Select CD */
#define KEY_TAPE 0x180 /* Media Select Tape */
#define KEY_RADIO 0x181
#define KEY_TUNER 0x182 /* Media Select Tuner */
#define KEY_PLAYER 0x183
#define KEY_TEXT 0x184
#define KEY_DVD 0x185 /* Media Select DVD */
#define KEY_AUX 0x186
#define KEY_MP3 0x187
#define KEY_AUDIO 0x188 /* AL Audio Browser */
#define KEY_VIDEO 0x189 /* AL Movie Browser */
#define KEY_DIRECTORY 0x18a
#define KEY_LIST 0x18b
#define KEY_MEMO 0x18c /* Media Select Messages */
#define KEY_CALENDAR 0x18d
#define KEY_RED 0x18e
#define KEY_GREEN 0x18f
#define KEY_YELLOW 0x190
#define KEY_BLUE 0x191
#define KEY_CHANNELUP 0x192 /* Channel Increment */
#define KEY_CHANNELDOWN 0x193 /* Channel Decrement */
#define KEY_FIRST 0x194
#define KEY_LAST 0x195 /* Recall Last */
#define KEY_AB 0x196
#define KEY_NEXT 0x197
#define KEY_RESTART 0x198
#define KEY_SLOW 0x199
#define KEY_SHUFFLE 0x19a
#define KEY_BREAK 0x19b
#define KEY_PREVIOUS 0x19c
#define KEY_DIGITS 0x19d
#define KEY_TEEN 0x19e
#define KEY_TWEN 0x19f
#define KEY_VIDEOPHONE 0x1a0 /* Media Select Video Phone */
#define KEY_GAMES 0x1a1 /* Media Select Games */
#define KEY_ZOOMIN 0x1a2 /* AC Zoom In */
#define KEY_ZOOMOUT 0x1a3 /* AC Zoom Out */
#define KEY_ZOOMRESET 0x1a4 /* AC Zoom */
#define KEY_WORDPROCESSOR 0x1a5 /* AL Word Processor */
#define KEY_EDITOR 0x1a6 /* AL Text Editor */
#define KEY_SPREADSHEET 0x1a7 /* AL Spreadsheet */
#define KEY_GRAPHICSEDITOR 0x1a8 /* AL Graphics Editor */
#define KEY_PRESENTATION 0x1a9 /* AL Presentation App */
#define KEY_DATABASE 0x1aa /* AL Database App */
#define KEY_NEWS 0x1ab /* AL Newsreader */
#define KEY_VOICEMAIL 0x1ac /* AL Voicemail */
#define KEY_ADDRESSBOOK 0x1ad /* AL Contacts/Address Book */
#define KEY_MESSENGER 0x1ae /* AL Instant Messaging */
#define KEY_DISPLAYTOGGLE 0x1af /* Turn display (LCD) on and off */
#define KEY_BRIGHTNESS_TOGGLE KEY_DISPLAYTOGGLE
#define KEY_SPELLCHECK 0x1b0 /* AL Spell Check */
#define KEY_LOGOFF 0x1b1 /* AL Logoff */
#define KEY_DOLLAR 0x1b2
#define KEY_EURO 0x1b3
#define KEY_FRAMEBACK 0x1b4 /* Consumer - transport controls */
#define KEY_FRAMEFORWARD 0x1b5
#define KEY_CONTEXT_MENU 0x1b6 /* GenDesc - system context menu */
#define KEY_MEDIA_REPEAT 0x1b7 /* Consumer - transport control */
#define KEY_10CHANNELSUP 0x1b8 /* 10 channels up (10+) */
#define KEY_10CHANNELSDOWN 0x1b9 /* 10 channels down (10-) */
#define KEY_IMAGES 0x1ba /* AL Image Browser */
#define KEY_DEL_EOL 0x1c0
#define KEY_DEL_EOS 0x1c1
#define KEY_INS_LINE 0x1c2
#define KEY_DEL_LINE 0x1c3
#define KEY_FN 0x1d0
#define KEY_FN_ESC 0x1d1
#define KEY_FN_F1 0x1d2
#define KEY_FN_F2 0x1d3
#define KEY_FN_F3 0x1d4
#define KEY_FN_F4 0x1d5
#define KEY_FN_F5 0x1d6
#define KEY_FN_F6 0x1d7
#define KEY_FN_F7 0x1d8
#define KEY_FN_F8 0x1d9
#define KEY_FN_F9 0x1da
#define KEY_FN_F10 0x1db
#define KEY_FN_F11 0x1dc
#define KEY_FN_F12 0x1dd
#define KEY_FN_1 0x1de
#define KEY_FN_2 0x1df
#define KEY_FN_D 0x1e0
#define KEY_FN_E 0x1e1
#define KEY_FN_F 0x1e2
#define KEY_FN_S 0x1e3
#define KEY_FN_B 0x1e4
#define KEY_BRL_DOT1 0x1f1
#define KEY_BRL_DOT2 0x1f2
#define KEY_BRL_DOT3 0x1f3
#define KEY_BRL_DOT4 0x1f4
#define KEY_BRL_DOT5 0x1f5
#define KEY_BRL_DOT6 0x1f6
#define KEY_BRL_DOT7 0x1f7
#define KEY_BRL_DOT8 0x1f8
#define KEY_BRL_DOT9 0x1f9
#define KEY_BRL_DOT10 0x1fa
#define KEY_NUMERIC_0 0x200 /* used by phones, remote controls, */
#define KEY_NUMERIC_1 0x201 /* and other keypads */
#define KEY_NUMERIC_2 0x202
#define KEY_NUMERIC_3 0x203
#define KEY_NUMERIC_4 0x204
#define KEY_NUMERIC_5 0x205
#define KEY_NUMERIC_6 0x206
#define KEY_NUMERIC_7 0x207
#define KEY_NUMERIC_8 0x208
#define KEY_NUMERIC_9 0x209
#define KEY_NUMERIC_STAR 0x20a
#define KEY_NUMERIC_POUND 0x20b
#define KEY_NUMERIC_A 0x20c /* Phone key A - HUT Telephony 0xb9 */
#define KEY_NUMERIC_B 0x20d
#define KEY_NUMERIC_C 0x20e
#define KEY_NUMERIC_D 0x20f
#define KEY_CAMERA_FOCUS 0x210
#define KEY_WPS_BUTTON 0x211 /* WiFi Protected Setup key */
#define KEY_TOUCHPAD_TOGGLE 0x212 /* Request switch touchpad on or off */
#define KEY_TOUCHPAD_ON 0x213
#define KEY_TOUCHPAD_OFF 0x214
#define KEY_CAMERA_ZOOMIN 0x215
#define KEY_CAMERA_ZOOMOUT 0x216
#define KEY_CAMERA_UP 0x217
#define KEY_CAMERA_DOWN 0x218
#define KEY_CAMERA_LEFT 0x219
#define KEY_CAMERA_RIGHT 0x21a
#define KEY_ATTENDANT_ON 0x21b
#define KEY_ATTENDANT_OFF 0x21c
#define KEY_ATTENDANT_TOGGLE 0x21d /* Attendant call on or off */
#define KEY_LIGHTS_TOGGLE 0x21e /* Reading light on or off */
#define BTN_DPAD_UP 0x220
#define BTN_DPAD_DOWN 0x221
#define BTN_DPAD_LEFT 0x222
#define BTN_DPAD_RIGHT 0x223
#define KEY_ALS_TOGGLE 0x230 /* Ambient light sensor */
#define KEY_ROTATE_LOCK_TOGGLE 0x231 /* Display rotation lock */
#define KEY_BUTTONCONFIG 0x240 /* AL Button Configuration */
#define KEY_TASKMANAGER 0x241 /* AL Task/Project Manager */
#define KEY_JOURNAL 0x242 /* AL Log/Journal/Timecard */
#define KEY_CONTROLPANEL 0x243 /* AL Control Panel */
#define KEY_APPSELECT 0x244 /* AL Select Task/Application */
#define KEY_SCREENSAVER 0x245 /* AL Screen Saver */
#define KEY_VOICECOMMAND 0x246 /* Listening Voice Command */
#define KEY_ASSISTANT 0x247 /* AL Context-aware desktop assistant */
#define KEY_KBD_LAYOUT_NEXT 0x248 /* AC Next Keyboard Layout Select */
#define KEY_BRIGHTNESS_MIN 0x250 /* Set Brightness to Minimum */
#define KEY_BRIGHTNESS_MAX 0x251 /* Set Brightness to Maximum */
#define KEY_KBDINPUTASSIST_PREV 0x260
#define KEY_KBDINPUTASSIST_NEXT 0x261
#define KEY_KBDINPUTASSIST_PREVGROUP 0x262
#define KEY_KBDINPUTASSIST_NEXTGROUP 0x263
#define KEY_KBDINPUTASSIST_ACCEPT 0x264
#define KEY_KBDINPUTASSIST_CANCEL 0x265
/* Diagonal movement keys */
#define KEY_RIGHT_UP 0x266
#define KEY_RIGHT_DOWN 0x267
#define KEY_LEFT_UP 0x268
#define KEY_LEFT_DOWN 0x269
#define KEY_ROOT_MENU 0x26a /* Show Device's Root Menu */
/* Show Top Menu of the Media (e.g. DVD) */
#define KEY_MEDIA_TOP_MENU 0x26b
#define KEY_NUMERIC_11 0x26c
#define KEY_NUMERIC_12 0x26d
/*
* Toggle Audio Description: refers to an audio service that helps blind and
* visually impaired consumers understand the action in a program. Note: in
* some countries this is referred to as "Video Description".
*/
#define KEY_AUDIO_DESC 0x26e
#define KEY_3D_MODE 0x26f
#define KEY_NEXT_FAVORITE 0x270
#define KEY_STOP_RECORD 0x271
#define KEY_PAUSE_RECORD 0x272
#define KEY_VOD 0x273 /* Video on Demand */
#define KEY_UNMUTE 0x274
#define KEY_FASTREVERSE 0x275
#define KEY_SLOWREVERSE 0x276
/*
* Control a data application associated with the currently viewed channel,
* e.g. teletext or data broadcast application (MHEG, MHP, HbbTV, etc.)
*/
#define KEY_DATA 0x277
#define KEY_ONSCREEN_KEYBOARD 0x278
/* Electronic privacy screen control */
#define KEY_PRIVACY_SCREEN_TOGGLE 0x279
/* Select an area of screen to be copied */
#define KEY_SELECTIVE_SCREENSHOT 0x27a
/*
* Some keyboards have keys which do not have a defined meaning, these keys
* are intended to be programmed / bound to macros by the user. For most
* keyboards with these macro-keys the key-sequence to inject, or action to
* take, is all handled by software on the host side. So from the kernel's
* point of view these are just normal keys.
*
* The KEY_MACRO# codes below are intended for such keys, which may be labeled
* e.g. G1-G18, or S1 - S30. The KEY_MACRO# codes MUST NOT be used for keys
* where the marking on the key does indicate a defined meaning / purpose.
*
* The KEY_MACRO# codes MUST also NOT be used as fallback for when no existing
* KEY_FOO define matches the marking / purpose. In this case a new KEY_FOO
* define MUST be added.
*/
#define KEY_MACRO1 0x290
#define KEY_MACRO2 0x291
#define KEY_MACRO3 0x292
#define KEY_MACRO4 0x293
#define KEY_MACRO5 0x294
#define KEY_MACRO6 0x295
#define KEY_MACRO7 0x296
#define KEY_MACRO8 0x297
#define KEY_MACRO9 0x298
#define KEY_MACRO10 0x299
#define KEY_MACRO11 0x29a
#define KEY_MACRO12 0x29b
#define KEY_MACRO13 0x29c
#define KEY_MACRO14 0x29d
#define KEY_MACRO15 0x29e
#define KEY_MACRO16 0x29f
#define KEY_MACRO17 0x2a0
#define KEY_MACRO18 0x2a1
#define KEY_MACRO19 0x2a2
#define KEY_MACRO20 0x2a3
#define KEY_MACRO21 0x2a4
#define KEY_MACRO22 0x2a5
#define KEY_MACRO23 0x2a6
#define KEY_MACRO24 0x2a7
#define KEY_MACRO25 0x2a8
#define KEY_MACRO26 0x2a9
#define KEY_MACRO27 0x2aa
#define KEY_MACRO28 0x2ab
#define KEY_MACRO29 0x2ac
#define KEY_MACRO30 0x2ad
/*
* Some keyboards with the macro-keys described above have some extra keys
* for controlling the host-side software responsible for the macro handling:
* -A macro recording start/stop key. Note that not all keyboards which emit
* KEY_MACRO_RECORD_START will also emit KEY_MACRO_RECORD_STOP if
* KEY_MACRO_RECORD_STOP is not advertised, then KEY_MACRO_RECORD_START
* should be interpreted as a recording start/stop toggle;
* -Keys for switching between different macro (pre)sets, either a key for
* cycling through the configured presets or keys to directly select a preset.
*/
#define KEY_MACRO_RECORD_START 0x2b0
#define KEY_MACRO_RECORD_STOP 0x2b1
#define KEY_MACRO_PRESET_CYCLE 0x2b2
#define KEY_MACRO_PRESET1 0x2b3
#define KEY_MACRO_PRESET2 0x2b4
#define KEY_MACRO_PRESET3 0x2b5
/*
* Some keyboards have a buildin LCD panel where the contents are controlled
* by the host. Often these have a number of keys directly below the LCD
* intended for controlling a menu shown on the LCD. These keys often don't
* have any labeling so we just name them KEY_KBD_LCD_MENU#
*/
#define KEY_KBD_LCD_MENU1 0x2b8
#define KEY_KBD_LCD_MENU2 0x2b9
#define KEY_KBD_LCD_MENU3 0x2ba
#define KEY_KBD_LCD_MENU4 0x2bb
#define KEY_KBD_LCD_MENU5 0x2bc
#define BTN_TRIGGER_HAPPY 0x2c0
#define BTN_TRIGGER_HAPPY1 0x2c0
#define BTN_TRIGGER_HAPPY2 0x2c1
#define BTN_TRIGGER_HAPPY3 0x2c2
#define BTN_TRIGGER_HAPPY4 0x2c3
#define BTN_TRIGGER_HAPPY5 0x2c4
#define BTN_TRIGGER_HAPPY6 0x2c5
#define BTN_TRIGGER_HAPPY7 0x2c6
#define BTN_TRIGGER_HAPPY8 0x2c7
#define BTN_TRIGGER_HAPPY9 0x2c8
#define BTN_TRIGGER_HAPPY10 0x2c9
#define BTN_TRIGGER_HAPPY11 0x2ca
#define BTN_TRIGGER_HAPPY12 0x2cb
#define BTN_TRIGGER_HAPPY13 0x2cc
#define BTN_TRIGGER_HAPPY14 0x2cd
#define BTN_TRIGGER_HAPPY15 0x2ce
#define BTN_TRIGGER_HAPPY16 0x2cf
#define BTN_TRIGGER_HAPPY17 0x2d0
#define BTN_TRIGGER_HAPPY18 0x2d1
#define BTN_TRIGGER_HAPPY19 0x2d2
#define BTN_TRIGGER_HAPPY20 0x2d3
#define BTN_TRIGGER_HAPPY21 0x2d4
#define BTN_TRIGGER_HAPPY22 0x2d5
#define BTN_TRIGGER_HAPPY23 0x2d6
#define BTN_TRIGGER_HAPPY24 0x2d7
#define BTN_TRIGGER_HAPPY25 0x2d8
#define BTN_TRIGGER_HAPPY26 0x2d9
#define BTN_TRIGGER_HAPPY27 0x2da
#define BTN_TRIGGER_HAPPY28 0x2db
#define BTN_TRIGGER_HAPPY29 0x2dc
#define BTN_TRIGGER_HAPPY30 0x2dd
#define BTN_TRIGGER_HAPPY31 0x2de
#define BTN_TRIGGER_HAPPY32 0x2df
#define BTN_TRIGGER_HAPPY33 0x2e0
#define BTN_TRIGGER_HAPPY34 0x2e1
#define BTN_TRIGGER_HAPPY35 0x2e2
#define BTN_TRIGGER_HAPPY36 0x2e3
#define BTN_TRIGGER_HAPPY37 0x2e4
#define BTN_TRIGGER_HAPPY38 0x2e5
#define BTN_TRIGGER_HAPPY39 0x2e6
#define BTN_TRIGGER_HAPPY40 0x2e7
/* We avoid low common keys in module aliases so they don't get huge. */
#define KEY_MIN_INTERESTING KEY_MUTE
#define KEY_MAX 0x2ff
#define KEY_CNT (KEY_MAX+1)
/*
* Relative axes
*/
#define REL_X 0x00
#define REL_Y 0x01
#define REL_Z 0x02
#define REL_RX 0x03
#define REL_RY 0x04
#define REL_RZ 0x05
#define REL_HWHEEL 0x06
#define REL_DIAL 0x07
#define REL_WHEEL 0x08
#define REL_MISC 0x09
/*
* 0x0a is reserved and should not be used in input drivers.
* It was used by HID as REL_MISC+1 and userspace needs to detect if
* the next REL_* event is correct or is just REL_MISC + n.
* We define here REL_RESERVED so userspace can rely on it and detect
* the situation described above.
*/
#define REL_RESERVED 0x0a
#define REL_WHEEL_HI_RES 0x0b
#define REL_HWHEEL_HI_RES 0x0c
#define REL_MAX 0x0f
#define REL_CNT (REL_MAX+1)
/*
* Absolute axes
*/
#define ABS_X 0x00
#define ABS_Y 0x01
#define ABS_Z 0x02
#define ABS_RX 0x03
#define ABS_RY 0x04
#define ABS_RZ 0x05
#define ABS_THROTTLE 0x06
#define ABS_RUDDER 0x07
#define ABS_WHEEL 0x08
#define ABS_GAS 0x09
#define ABS_BRAKE 0x0a
#define ABS_HAT0X 0x10
#define ABS_HAT0Y 0x11
#define ABS_HAT1X 0x12
#define ABS_HAT1Y 0x13
#define ABS_HAT2X 0x14
#define ABS_HAT2Y 0x15
#define ABS_HAT3X 0x16
#define ABS_HAT3Y 0x17
#define ABS_PRESSURE 0x18
#define ABS_DISTANCE 0x19
#define ABS_TILT_X 0x1a
#define ABS_TILT_Y 0x1b
#define ABS_TOOL_WIDTH 0x1c
#define ABS_VOLUME 0x20
#define ABS_MISC 0x28
/*
* 0x2e is reserved and should not be used in input drivers.
* It was used by HID as ABS_MISC+6 and userspace needs to detect if
* the next ABS_* event is correct or is just ABS_MISC + n.
* We define here ABS_RESERVED so userspace can rely on it and detect
* the situation described above.
*/
#define ABS_RESERVED 0x2e
#define ABS_MT_SLOT 0x2f /* MT slot being modified */
#define ABS_MT_TOUCH_MAJOR 0x30 /* Major axis of touching ellipse */
#define ABS_MT_TOUCH_MINOR 0x31 /* Minor axis (omit if circular) */
#define ABS_MT_WIDTH_MAJOR 0x32 /* Major axis of approaching ellipse */
#define ABS_MT_WIDTH_MINOR 0x33 /* Minor axis (omit if circular) */
#define ABS_MT_ORIENTATION 0x34 /* Ellipse orientation */
#define ABS_MT_POSITION_X 0x35 /* Center X touch position */
#define ABS_MT_POSITION_Y 0x36 /* Center Y touch position */
#define ABS_MT_TOOL_TYPE 0x37 /* Type of touching device */
#define ABS_MT_BLOB_ID 0x38 /* Group a set of packets as a blob */
#define ABS_MT_TRACKING_ID 0x39 /* Unique ID of initiated contact */
#define ABS_MT_PRESSURE 0x3a /* Pressure on contact area */
#define ABS_MT_DISTANCE 0x3b /* Contact hover distance */
#define ABS_MT_TOOL_X 0x3c /* Center X tool position */
#define ABS_MT_TOOL_Y 0x3d /* Center Y tool position */
#define ABS_MAX 0x3f
#define ABS_CNT (ABS_MAX+1)
/*
* Switch events
*/
#define SW_LID 0x00 /* set = lid shut */
#define SW_TABLET_MODE 0x01 /* set = tablet mode */
#define SW_HEADPHONE_INSERT 0x02 /* set = inserted */
#define SW_RFKILL_ALL 0x03 /* rfkill master switch, type "any"
set = radio enabled */
#define SW_RADIO SW_RFKILL_ALL /* deprecated */
#define SW_MICROPHONE_INSERT 0x04 /* set = inserted */
#define SW_DOCK 0x05 /* set = plugged into dock */
#define SW_LINEOUT_INSERT 0x06 /* set = inserted */
#define SW_JACK_PHYSICAL_INSERT 0x07 /* set = mechanical switch set */
#define SW_VIDEOOUT_INSERT 0x08 /* set = inserted */
#define SW_CAMERA_LENS_COVER 0x09 /* set = lens covered */
#define SW_KEYPAD_SLIDE 0x0a /* set = keypad slide out */
#define SW_FRONT_PROXIMITY 0x0b /* set = front proximity sensor active */
#define SW_ROTATE_LOCK 0x0c /* set = rotate locked/disabled */
#define SW_LINEIN_INSERT 0x0d /* set = inserted */
#define SW_MUTE_DEVICE 0x0e /* set = device disabled */
#define SW_PEN_INSERTED 0x0f /* set = pen inserted */
#define SW_MACHINE_COVER 0x10 /* set = cover closed */
#define SW_MAX 0x10
#define SW_CNT (SW_MAX+1)
/*
* Misc events
*/
#define MSC_SERIAL 0x00
#define MSC_PULSELED 0x01
#define MSC_GESTURE 0x02
#define MSC_RAW 0x03
#define MSC_SCAN 0x04
#define MSC_TIMESTAMP 0x05
#define MSC_MAX 0x07
#define MSC_CNT (MSC_MAX+1)
/*
* LEDs
*/
#define LED_NUML 0x00
#define LED_CAPSL 0x01
#define LED_SCROLLL 0x02
#define LED_COMPOSE 0x03
#define LED_KANA 0x04
#define LED_SLEEP 0x05
#define LED_SUSPEND 0x06
#define LED_MUTE 0x07
#define LED_MISC 0x08
#define LED_MAIL 0x09
#define LED_CHARGING 0x0a
#define LED_MAX 0x0f
#define LED_CNT (LED_MAX+1)
/*
* Autorepeat values
*/
#define REP_DELAY 0x00
#define REP_PERIOD 0x01
#define REP_MAX 0x01
#define REP_CNT (REP_MAX+1)
/*
* Sounds
*/
#define SND_CLICK 0x00
#define SND_BELL 0x01
#define SND_TONE 0x02
#define SND_MAX 0x07
#define SND_CNT (SND_MAX+1)
#endif
libinput-1.28.1/include/linux/freebsd/input.h000066400000000000000000000372301477265155700211650ustar00rootroot00000000000000/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
/*
* Copyright (c) 1999-2002 Vojtech Pavlik
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 as published by
* the Free Software Foundation.
*/
#ifndef _UAPI_INPUT_H
#define _UAPI_INPUT_H
#ifndef __KERNEL__
#include
#include
#include
#endif
#include "input-event-codes.h"
/*
* The event structure itself
* Note that __USE_TIME_BITS64 is defined by libc based on
* application's request to use 64 bit time_t.
*/
struct input_event {
#if 1 /* (__BITS_PER_LONG != 32 || !defined(__USE_TIME_BITS64)) && !defined(__KERNEL) */
struct timeval time;
#define input_event_sec time.tv_sec
#define input_event_usec time.tv_usec
#else
__kernel_ulong_t __sec;
__kernel_ulong_t __usec;
#define input_event_sec __sec
#define input_event_usec __usec
#endif
uint16_t type;
uint16_t code;
int32_t value;
};
/*
* Protocol version.
*/
#define EV_VERSION 0x010001
/*
* IOCTLs (0x00 - 0x7f)
*/
struct input_id {
uint16_t bustype;
uint16_t vendor;
uint16_t product;
uint16_t version;
};
/**
* struct input_absinfo - used by EVIOCGABS/EVIOCSABS ioctls
* @value: latest reported value for the axis.
* @minimum: specifies minimum value for the axis.
* @maximum: specifies maximum value for the axis.
* @fuzz: specifies fuzz value that is used to filter noise from
* the event stream.
* @flat: values that are within this value will be discarded by
* joydev interface and reported as 0 instead.
* @resolution: specifies resolution for the values reported for
* the axis.
*
* Note that input core does not clamp reported values to the
* [minimum, maximum] limits, such task is left to userspace.
*
* The default resolution for main axes (ABS_X, ABS_Y, ABS_Z)
* is reported in units per millimeter (units/mm), resolution
* for rotational axes (ABS_RX, ABS_RY, ABS_RZ) is reported
* in units per radian.
* When INPUT_PROP_ACCELEROMETER is set the resolution changes.
* The main axes (ABS_X, ABS_Y, ABS_Z) are then reported in
* in units per g (units/g) and in units per degree per second
* (units/deg/s) for rotational axes (ABS_RX, ABS_RY, ABS_RZ).
*/
struct input_absinfo {
int32_t value;
int32_t minimum;
int32_t maximum;
int32_t fuzz;
int32_t flat;
int32_t resolution;
};
/**
* struct input_keymap_entry - used by EVIOCGKEYCODE/EVIOCSKEYCODE ioctls
* @scancode: scancode represented in machine-endian form.
* @len: length of the scancode that resides in @scancode buffer.
* @index: index in the keymap, may be used instead of scancode
* @flags: allows to specify how kernel should handle the request. For
* example, setting INPUT_KEYMAP_BY_INDEX flag indicates that kernel
* should perform lookup in keymap by @index instead of @scancode
* @keycode: key code assigned to this scancode
*
* The structure is used to retrieve and modify keymap data. Users have
* option of performing lookup either by @scancode itself or by @index
* in keymap entry. EVIOCGKEYCODE will also return scancode or index
* (depending on which element was used to perform lookup).
*/
struct input_keymap_entry {
#define INPUT_KEYMAP_BY_INDEX (1 << 0)
uint8_t flags;
uint8_t len;
uint16_t index;
uint32_t keycode;
uint8_t scancode[32];
};
struct input_mask {
uint32_t type;
uint32_t codes_size;
uint64_t codes_ptr;
};
#define EVIOCGVERSION _IOR('E', 0x01, int) /* get driver version */
#define EVIOCGID _IOR('E', 0x02, struct input_id) /* get device ID */
#define EVIOCGREP _IOR('E', 0x03, unsigned int[2]) /* get repeat settings */
#define EVIOCSREP _IOW('E', 0x03, unsigned int[2]) /* set repeat settings */
#define EVIOCGKEYCODE _IOWR('E', 0x04, unsigned int[2]) /* get keycode */
#define EVIOCGKEYCODE_V2 _IOWR('E', 0x04, struct input_keymap_entry)
#define EVIOCSKEYCODE _IOW('E', 0x04, unsigned int[2]) /* set keycode */
#define EVIOCSKEYCODE_V2 _IOW('E', 0x04, struct input_keymap_entry)
#define EVIOCGNAME(len) _IOC(IOC_OUT, 'E', 0x06, len) /* get device name */
#define EVIOCGPHYS(len) _IOC(IOC_OUT, 'E', 0x07, len) /* get physical location */
#define EVIOCGUNIQ(len) _IOC(IOC_OUT, 'E', 0x08, len) /* get unique identifier */
#define EVIOCGPROP(len) _IOC(IOC_OUT, 'E', 0x09, len) /* get device properties */
/**
* EVIOCGMTSLOTS(len) - get MT slot values
* @len: size of the data buffer in bytes
*
* The ioctl buffer argument should be binary equivalent to
*
* struct input_mt_request_layout {
* uint32_t code;
* int32_t values[num_slots];
* };
*
* where num_slots is the (arbitrary) number of MT slots to extract.
*
* The ioctl size argument (len) is the size of the buffer, which
* should satisfy len = (num_slots + 1) * sizeof(int32_t). If len is
* too small to fit all available slots, the first num_slots are
* returned.
*
* Before the call, code is set to the wanted ABS_MT event type. On
* return, values[] is filled with the slot values for the specified
* ABS_MT code.
*
* If the request code is not an ABS_MT value, -EINVAL is returned.
*/
#define EVIOCGMTSLOTS(len) _IOC(IOC_INOUT, 'E', 0x0a, len)
#define EVIOCGKEY(len) _IOC(IOC_OUT, 'E', 0x18, len) /* get global key state */
#define EVIOCGLED(len) _IOC(IOC_OUT, 'E', 0x19, len) /* get all LEDs */
#define EVIOCGSND(len) _IOC(IOC_OUT, 'E', 0x1a, len) /* get all sounds status */
#define EVIOCGSW(len) _IOC(IOC_OUT, 'E', 0x1b, len) /* get all switch states */
#define EVIOCGBIT(ev,len) _IOC(IOC_OUT, 'E', 0x20 + (ev), len) /* get event bits */
#define EVIOCGABS(abs) _IOR('E', 0x40 + (abs), struct input_absinfo) /* get abs value/limits */
#define EVIOCSABS(abs) _IOW('E', 0xc0 + (abs), struct input_absinfo) /* set abs value/limits */
#define EVIOCSFF _IOW('E', 0x80, struct ff_effect) /* send a force effect to a force feedback device */
#define EVIOCRMFF _IOWINT('E', 0x81) /* Erase a force effect */
#define EVIOCGEFFECTS _IOR('E', 0x84, int) /* Report number of effects playable at the same time */
#define EVIOCGRAB _IOWINT('E', 0x90) /* Grab/Release device */
#define EVIOCREVOKE _IOWINT('E', 0x91) /* Revoke device access */
/**
* EVIOCGMASK - Retrieve current event mask
*
* This ioctl allows user to retrieve the current event mask for specific
* event type. The argument must be of type "struct input_mask" and
* specifies the event type to query, the address of the receive buffer and
* the size of the receive buffer.
*
* The event mask is a per-client mask that specifies which events are
* forwarded to the client. Each event code is represented by a single bit
* in the event mask. If the bit is set, the event is passed to the client
* normally. Otherwise, the event is filtered and will never be queued on
* the client's receive buffer.
*
* Event masks do not affect global state of the input device. They only
* affect the file descriptor they are applied to.
*
* The default event mask for a client has all bits set, i.e. all events
* are forwarded to the client. If the kernel is queried for an unknown
* event type or if the receive buffer is larger than the number of
* event codes known to the kernel, the kernel returns all zeroes for those
* codes.
*
* At maximum, codes_size bytes are copied.
*
* This ioctl may fail with ENODEV in case the file is revoked, EFAULT
* if the receive-buffer points to invalid memory, or EINVAL if the kernel
* does not implement the ioctl.
*/
#define EVIOCGMASK _IOW('E', 0x92, struct input_mask) /* Get event-masks */
/**
* EVIOCSMASK - Set event mask
*
* This ioctl is the counterpart to EVIOCGMASK. Instead of receiving the
* current event mask, this changes the client's event mask for a specific
* type. See EVIOCGMASK for a description of event-masks and the
* argument-type.
*
* This ioctl provides full forward compatibility. If the passed event type
* is unknown to the kernel, or if the number of event codes specified in
* the mask is bigger than what is known to the kernel, the ioctl is still
* accepted and applied. However, any unknown codes are left untouched and
* stay cleared. That means, the kernel always filters unknown codes
* regardless of what the client requests. If the new mask doesn't cover
* all known event-codes, all remaining codes are automatically cleared and
* thus filtered.
*
* This ioctl may fail with ENODEV in case the file is revoked. EFAULT is
* returned if the receive-buffer points to invalid memory. EINVAL is returned
* if the kernel does not implement the ioctl.
*/
#define EVIOCSMASK _IOW('E', 0x93, struct input_mask) /* Set event-masks */
#define EVIOCSCLOCKID _IOW('E', 0xa0, int) /* Set clockid to be used for timestamps */
/*
* IDs.
*/
#define ID_BUS 0
#define ID_VENDOR 1
#define ID_PRODUCT 2
#define ID_VERSION 3
#define BUS_PCI 0x01
#define BUS_ISAPNP 0x02
#define BUS_USB 0x03
#define BUS_HIL 0x04
#define BUS_BLUETOOTH 0x05
#define BUS_VIRTUAL 0x06
#define BUS_ISA 0x10
#define BUS_I8042 0x11
#define BUS_XTKBD 0x12
#define BUS_RS232 0x13
#define BUS_GAMEPORT 0x14
#define BUS_PARPORT 0x15
#define BUS_AMIGA 0x16
#define BUS_ADB 0x17
#define BUS_I2C 0x18
#define BUS_HOST 0x19
#define BUS_GSC 0x1A
#define BUS_ATARI 0x1B
#define BUS_SPI 0x1C
#define BUS_RMI 0x1D
#define BUS_CEC 0x1E
#define BUS_INTEL_ISHTP 0x1F
/*
* MT_TOOL types
*/
#define MT_TOOL_FINGER 0x00
#define MT_TOOL_PEN 0x01
#define MT_TOOL_PALM 0x02
#define MT_TOOL_DIAL 0x0a
#define MT_TOOL_MAX 0x0f
/*
* Values describing the status of a force-feedback effect
*/
#define FF_STATUS_STOPPED 0x00
#define FF_STATUS_PLAYING 0x01
#define FF_STATUS_MAX 0x01
/*
* Structures used in ioctls to upload effects to a device
* They are pieces of a bigger structure (called ff_effect)
*/
/*
* All duration values are expressed in ms. Values above 32767 ms (0x7fff)
* should not be used and have unspecified results.
*/
/**
* struct ff_replay - defines scheduling of the force-feedback effect
* @length: duration of the effect
* @delay: delay before effect should start playing
*/
struct ff_replay {
uint16_t length;
uint16_t delay;
};
/**
* struct ff_trigger - defines what triggers the force-feedback effect
* @button: number of the button triggering the effect
* @interval: controls how soon the effect can be re-triggered
*/
struct ff_trigger {
uint16_t button;
uint16_t interval;
};
/**
* struct ff_envelope - generic force-feedback effect envelope
* @attack_length: duration of the attack (ms)
* @attack_level: level at the beginning of the attack
* @fade_length: duration of fade (ms)
* @fade_level: level at the end of fade
*
* The @attack_level and @fade_level are absolute values; when applying
* envelope force-feedback core will convert to positive/negative
* value based on polarity of the default level of the effect.
* Valid range for the attack and fade levels is 0x0000 - 0x7fff
*/
struct ff_envelope {
uint16_t attack_length;
uint16_t attack_level;
uint16_t fade_length;
uint16_t fade_level;
};
/**
* struct ff_constant_effect - defines parameters of a constant force-feedback effect
* @level: strength of the effect; may be negative
* @envelope: envelope data
*/
struct ff_constant_effect {
int16_t level;
struct ff_envelope envelope;
};
/**
* struct ff_ramp_effect - defines parameters of a ramp force-feedback effect
* @start_level: beginning strength of the effect; may be negative
* @end_level: final strength of the effect; may be negative
* @envelope: envelope data
*/
struct ff_ramp_effect {
int16_t start_level;
int16_t end_level;
struct ff_envelope envelope;
};
/**
* struct ff_condition_effect - defines a spring or friction force-feedback effect
* @right_saturation: maximum level when joystick moved all way to the right
* @left_saturation: same for the left side
* @right_coeff: controls how fast the force grows when the joystick moves
* to the right
* @left_coeff: same for the left side
* @deadband: size of the dead zone, where no force is produced
* @center: position of the dead zone
*/
struct ff_condition_effect {
uint16_t right_saturation;
uint16_t left_saturation;
int16_t right_coeff;
int16_t left_coeff;
uint16_t deadband;
int16_t center;
};
/**
* struct ff_periodic_effect - defines parameters of a periodic force-feedback effect
* @waveform: kind of the effect (wave)
* @period: period of the wave (ms)
* @magnitude: peak value
* @offset: mean value of the wave (roughly)
* @phase: 'horizontal' shift
* @envelope: envelope data
* @custom_len: number of samples (FF_CUSTOM only)
* @custom_data: buffer of samples (FF_CUSTOM only)
*
* Known waveforms - FF_SQUARE, FF_TRIANGLE, FF_SINE, FF_SAW_UP,
* FF_SAW_DOWN, FF_CUSTOM. The exact syntax FF_CUSTOM is undefined
* for the time being as no driver supports it yet.
*
* Note: the data pointed by custom_data is copied by the driver.
* You can therefore dispose of the memory after the upload/update.
*/
struct ff_periodic_effect {
uint16_t waveform;
uint16_t period;
int16_t magnitude;
int16_t offset;
uint16_t phase;
struct ff_envelope envelope;
uint32_t custom_len;
int16_t *custom_data;
};
/**
* struct ff_rumble_effect - defines parameters of a periodic force-feedback effect
* @strong_magnitude: magnitude of the heavy motor
* @weak_magnitude: magnitude of the light one
*
* Some rumble pads have two motors of different weight. Strong_magnitude
* represents the magnitude of the vibration generated by the heavy one.
*/
struct ff_rumble_effect {
uint16_t strong_magnitude;
uint16_t weak_magnitude;
};
/**
* struct ff_effect - defines force feedback effect
* @type: type of the effect (FF_CONSTANT, FF_PERIODIC, FF_RAMP, FF_SPRING,
* FF_FRICTION, FF_DAMPER, FF_RUMBLE, FF_INERTIA, or FF_CUSTOM)
* @id: an unique id assigned to an effect
* @direction: direction of the effect
* @trigger: trigger conditions (struct ff_trigger)
* @replay: scheduling of the effect (struct ff_replay)
* @u: effect-specific structure (one of ff_constant_effect, ff_ramp_effect,
* ff_periodic_effect, ff_condition_effect, ff_rumble_effect) further
* defining effect parameters
*
* This structure is sent through ioctl from the application to the driver.
* To create a new effect application should set its @id to -1; the kernel
* will return assigned @id which can later be used to update or delete
* this effect.
*
* Direction of the effect is encoded as follows:
* 0 deg -> 0x0000 (down)
* 90 deg -> 0x4000 (left)
* 180 deg -> 0x8000 (up)
* 270 deg -> 0xC000 (right)
*/
struct ff_effect {
uint16_t type;
int16_t id;
uint16_t direction;
struct ff_trigger trigger;
struct ff_replay replay;
union {
struct ff_constant_effect constant;
struct ff_ramp_effect ramp;
struct ff_periodic_effect periodic;
struct ff_condition_effect condition[2]; /* One for each axis */
struct ff_rumble_effect rumble;
} u;
};
/*
* Force feedback effect types
*/
#define FF_RUMBLE 0x50
#define FF_PERIODIC 0x51
#define FF_CONSTANT 0x52
#define FF_SPRING 0x53
#define FF_FRICTION 0x54
#define FF_DAMPER 0x55
#define FF_INERTIA 0x56
#define FF_RAMP 0x57
#define FF_EFFECT_MIN FF_RUMBLE
#define FF_EFFECT_MAX FF_RAMP
/*
* Force feedback periodic effect types
*/
#define FF_SQUARE 0x58
#define FF_TRIANGLE 0x59
#define FF_SINE 0x5a
#define FF_SAW_UP 0x5b
#define FF_SAW_DOWN 0x5c
#define FF_CUSTOM 0x5d
#define FF_WAVEFORM_MIN FF_SQUARE
#define FF_WAVEFORM_MAX FF_CUSTOM
/*
* Set ff device properties
*/
#define FF_GAIN 0x60
#define FF_AUTOCENTER 0x61
/*
* ff->playback(effect_id = FF_GAIN) is the first effect_id to
* cause a collision with another ff method, in this case ff->set_gain().
* Therefore the greatest safe value for effect_id is FF_GAIN - 1,
* and thus the total number of effects should never exceed FF_GAIN.
*/
#define FF_MAX_EFFECTS FF_GAIN
#define FF_MAX 0x7f
#define FF_CNT (FF_MAX+1)
#endif /* _UAPI_INPUT_H */
libinput-1.28.1/include/linux/input.h000066400000000000000000000001361477265155700175460ustar00rootroot00000000000000#ifdef __linux__
#include "linux/input.h"
#elif __FreeBSD__
#include "freebsd/input.h"
#endif
libinput-1.28.1/include/linux/linux/000077500000000000000000000000001477265155700173755ustar00rootroot00000000000000libinput-1.28.1/include/linux/linux/input-event-codes.h000066400000000000000000000672351477265155700231340ustar00rootroot00000000000000/* SPDX-License-Identifier: GPL-2.0-only WITH Linux-syscall-note */
/*
* Input event codes
*
* *** IMPORTANT ***
* This file is not only included from C-code but also from devicetree source
* files. As such this file MUST only contain comments and defines.
*
* Copyright (c) 1999-2002 Vojtech Pavlik
* Copyright (c) 2015 Hans de Goede
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 as published by
* the Free Software Foundation.
*/
#ifndef _UAPI_INPUT_EVENT_CODES_H
#define _UAPI_INPUT_EVENT_CODES_H
/*
* Device properties and quirks
*/
#define INPUT_PROP_POINTER 0x00 /* needs a pointer */
#define INPUT_PROP_DIRECT 0x01 /* direct input devices */
#define INPUT_PROP_BUTTONPAD 0x02 /* has button(s) under pad */
#define INPUT_PROP_SEMI_MT 0x03 /* touch rectangle only */
#define INPUT_PROP_TOPBUTTONPAD 0x04 /* softbuttons at top of pad */
#define INPUT_PROP_POINTING_STICK 0x05 /* is a pointing stick */
#define INPUT_PROP_ACCELEROMETER 0x06 /* has accelerometer */
#define INPUT_PROP_MAX 0x1f
#define INPUT_PROP_CNT (INPUT_PROP_MAX + 1)
/*
* Event types
*/
#define EV_SYN 0x00
#define EV_KEY 0x01
#define EV_REL 0x02
#define EV_ABS 0x03
#define EV_MSC 0x04
#define EV_SW 0x05
#define EV_LED 0x11
#define EV_SND 0x12
#define EV_REP 0x14
#define EV_FF 0x15
#define EV_PWR 0x16
#define EV_FF_STATUS 0x17
#define EV_MAX 0x1f
#define EV_CNT (EV_MAX+1)
/*
* Synchronization events.
*/
#define SYN_REPORT 0
#define SYN_CONFIG 1
#define SYN_MT_REPORT 2
#define SYN_DROPPED 3
#define SYN_MAX 0xf
#define SYN_CNT (SYN_MAX+1)
/*
* Keys and buttons
*
* Most of the keys/buttons are modeled after USB HUT 1.12
* (see http://www.usb.org/developers/hidpage).
* Abbreviations in the comments:
* AC - Application Control
* AL - Application Launch Button
* SC - System Control
*/
#define KEY_RESERVED 0
#define KEY_ESC 1
#define KEY_1 2
#define KEY_2 3
#define KEY_3 4
#define KEY_4 5
#define KEY_5 6
#define KEY_6 7
#define KEY_7 8
#define KEY_8 9
#define KEY_9 10
#define KEY_0 11
#define KEY_MINUS 12
#define KEY_EQUAL 13
#define KEY_BACKSPACE 14
#define KEY_TAB 15
#define KEY_Q 16
#define KEY_W 17
#define KEY_E 18
#define KEY_R 19
#define KEY_T 20
#define KEY_Y 21
#define KEY_U 22
#define KEY_I 23
#define KEY_O 24
#define KEY_P 25
#define KEY_LEFTBRACE 26
#define KEY_RIGHTBRACE 27
#define KEY_ENTER 28
#define KEY_LEFTCTRL 29
#define KEY_A 30
#define KEY_S 31
#define KEY_D 32
#define KEY_F 33
#define KEY_G 34
#define KEY_H 35
#define KEY_J 36
#define KEY_K 37
#define KEY_L 38
#define KEY_SEMICOLON 39
#define KEY_APOSTROPHE 40
#define KEY_GRAVE 41
#define KEY_LEFTSHIFT 42
#define KEY_BACKSLASH 43
#define KEY_Z 44
#define KEY_X 45
#define KEY_C 46
#define KEY_V 47
#define KEY_B 48
#define KEY_N 49
#define KEY_M 50
#define KEY_COMMA 51
#define KEY_DOT 52
#define KEY_SLASH 53
#define KEY_RIGHTSHIFT 54
#define KEY_KPASTERISK 55
#define KEY_LEFTALT 56
#define KEY_SPACE 57
#define KEY_CAPSLOCK 58
#define KEY_F1 59
#define KEY_F2 60
#define KEY_F3 61
#define KEY_F4 62
#define KEY_F5 63
#define KEY_F6 64
#define KEY_F7 65
#define KEY_F8 66
#define KEY_F9 67
#define KEY_F10 68
#define KEY_NUMLOCK 69
#define KEY_SCROLLLOCK 70
#define KEY_KP7 71
#define KEY_KP8 72
#define KEY_KP9 73
#define KEY_KPMINUS 74
#define KEY_KP4 75
#define KEY_KP5 76
#define KEY_KP6 77
#define KEY_KPPLUS 78
#define KEY_KP1 79
#define KEY_KP2 80
#define KEY_KP3 81
#define KEY_KP0 82
#define KEY_KPDOT 83
#define KEY_ZENKAKUHANKAKU 85
#define KEY_102ND 86
#define KEY_F11 87
#define KEY_F12 88
#define KEY_RO 89
#define KEY_KATAKANA 90
#define KEY_HIRAGANA 91
#define KEY_HENKAN 92
#define KEY_KATAKANAHIRAGANA 93
#define KEY_MUHENKAN 94
#define KEY_KPJPCOMMA 95
#define KEY_KPENTER 96
#define KEY_RIGHTCTRL 97
#define KEY_KPSLASH 98
#define KEY_SYSRQ 99
#define KEY_RIGHTALT 100
#define KEY_LINEFEED 101
#define KEY_HOME 102
#define KEY_UP 103
#define KEY_PAGEUP 104
#define KEY_LEFT 105
#define KEY_RIGHT 106
#define KEY_END 107
#define KEY_DOWN 108
#define KEY_PAGEDOWN 109
#define KEY_INSERT 110
#define KEY_DELETE 111
#define KEY_MACRO 112
#define KEY_MUTE 113
#define KEY_VOLUMEDOWN 114
#define KEY_VOLUMEUP 115
#define KEY_POWER 116 /* SC System Power Down */
#define KEY_KPEQUAL 117
#define KEY_KPPLUSMINUS 118
#define KEY_PAUSE 119
#define KEY_SCALE 120 /* AL Compiz Scale (Expose) */
#define KEY_KPCOMMA 121
#define KEY_HANGEUL 122
#define KEY_HANGUEL KEY_HANGEUL
#define KEY_HANJA 123
#define KEY_YEN 124
#define KEY_LEFTMETA 125
#define KEY_RIGHTMETA 126
#define KEY_COMPOSE 127
#define KEY_STOP 128 /* AC Stop */
#define KEY_AGAIN 129
#define KEY_PROPS 130 /* AC Properties */
#define KEY_UNDO 131 /* AC Undo */
#define KEY_FRONT 132
#define KEY_COPY 133 /* AC Copy */
#define KEY_OPEN 134 /* AC Open */
#define KEY_PASTE 135 /* AC Paste */
#define KEY_FIND 136 /* AC Search */
#define KEY_CUT 137 /* AC Cut */
#define KEY_HELP 138 /* AL Integrated Help Center */
#define KEY_MENU 139 /* Menu (show menu) */
#define KEY_CALC 140 /* AL Calculator */
#define KEY_SETUP 141
#define KEY_SLEEP 142 /* SC System Sleep */
#define KEY_WAKEUP 143 /* System Wake Up */
#define KEY_FILE 144 /* AL Local Machine Browser */
#define KEY_SENDFILE 145
#define KEY_DELETEFILE 146
#define KEY_XFER 147
#define KEY_PROG1 148
#define KEY_PROG2 149
#define KEY_WWW 150 /* AL Internet Browser */
#define KEY_MSDOS 151
#define KEY_COFFEE 152 /* AL Terminal Lock/Screensaver */
#define KEY_SCREENLOCK KEY_COFFEE
#define KEY_ROTATE_DISPLAY 153 /* Display orientation for e.g. tablets */
#define KEY_DIRECTION KEY_ROTATE_DISPLAY
#define KEY_CYCLEWINDOWS 154
#define KEY_MAIL 155
#define KEY_BOOKMARKS 156 /* AC Bookmarks */
#define KEY_COMPUTER 157
#define KEY_BACK 158 /* AC Back */
#define KEY_FORWARD 159 /* AC Forward */
#define KEY_CLOSECD 160
#define KEY_EJECTCD 161
#define KEY_EJECTCLOSECD 162
#define KEY_NEXTSONG 163
#define KEY_PLAYPAUSE 164
#define KEY_PREVIOUSSONG 165
#define KEY_STOPCD 166
#define KEY_RECORD 167
#define KEY_REWIND 168
#define KEY_PHONE 169 /* Media Select Telephone */
#define KEY_ISO 170
#define KEY_CONFIG 171 /* AL Consumer Control Configuration */
#define KEY_HOMEPAGE 172 /* AC Home */
#define KEY_REFRESH 173 /* AC Refresh */
#define KEY_EXIT 174 /* AC Exit */
#define KEY_MOVE 175
#define KEY_EDIT 176
#define KEY_SCROLLUP 177
#define KEY_SCROLLDOWN 178
#define KEY_KPLEFTPAREN 179
#define KEY_KPRIGHTPAREN 180
#define KEY_NEW 181 /* AC New */
#define KEY_REDO 182 /* AC Redo/Repeat */
#define KEY_F13 183
#define KEY_F14 184
#define KEY_F15 185
#define KEY_F16 186
#define KEY_F17 187
#define KEY_F18 188
#define KEY_F19 189
#define KEY_F20 190
#define KEY_F21 191
#define KEY_F22 192
#define KEY_F23 193
#define KEY_F24 194
#define KEY_PLAYCD 200
#define KEY_PAUSECD 201
#define KEY_PROG3 202
#define KEY_PROG4 203
#define KEY_DASHBOARD 204 /* AL Dashboard */
#define KEY_SUSPEND 205
#define KEY_CLOSE 206 /* AC Close */
#define KEY_PLAY 207
#define KEY_FASTFORWARD 208
#define KEY_BASSBOOST 209
#define KEY_PRINT 210 /* AC Print */
#define KEY_HP 211
#define KEY_CAMERA 212
#define KEY_SOUND 213
#define KEY_QUESTION 214
#define KEY_EMAIL 215
#define KEY_CHAT 216
#define KEY_SEARCH 217
#define KEY_CONNECT 218
#define KEY_FINANCE 219 /* AL Checkbook/Finance */
#define KEY_SPORT 220
#define KEY_SHOP 221
#define KEY_ALTERASE 222
#define KEY_CANCEL 223 /* AC Cancel */
#define KEY_BRIGHTNESSDOWN 224
#define KEY_BRIGHTNESSUP 225
#define KEY_MEDIA 226
#define KEY_SWITCHVIDEOMODE 227 /* Cycle between available video
outputs (Monitor/LCD/TV-out/etc) */
#define KEY_KBDILLUMTOGGLE 228
#define KEY_KBDILLUMDOWN 229
#define KEY_KBDILLUMUP 230
#define KEY_SEND 231 /* AC Send */
#define KEY_REPLY 232 /* AC Reply */
#define KEY_FORWARDMAIL 233 /* AC Forward Msg */
#define KEY_SAVE 234 /* AC Save */
#define KEY_DOCUMENTS 235
#define KEY_BATTERY 236
#define KEY_BLUETOOTH 237
#define KEY_WLAN 238
#define KEY_UWB 239
#define KEY_UNKNOWN 240
#define KEY_VIDEO_NEXT 241 /* drive next video source */
#define KEY_VIDEO_PREV 242 /* drive previous video source */
#define KEY_BRIGHTNESS_CYCLE 243 /* brightness up, after max is min */
#define KEY_BRIGHTNESS_AUTO 244 /* Set Auto Brightness: manual
brightness control is off,
rely on ambient */
#define KEY_BRIGHTNESS_ZERO KEY_BRIGHTNESS_AUTO
#define KEY_DISPLAY_OFF 245 /* display device to off state */
#define KEY_WWAN 246 /* Wireless WAN (LTE, UMTS, GSM, etc.) */
#define KEY_WIMAX KEY_WWAN
#define KEY_RFKILL 247 /* Key that controls all radios */
#define KEY_MICMUTE 248 /* Mute / unmute the microphone */
/* Code 255 is reserved for special needs of AT keyboard driver */
#define BTN_MISC 0x100
#define BTN_0 0x100
#define BTN_1 0x101
#define BTN_2 0x102
#define BTN_3 0x103
#define BTN_4 0x104
#define BTN_5 0x105
#define BTN_6 0x106
#define BTN_7 0x107
#define BTN_8 0x108
#define BTN_9 0x109
#define BTN_MOUSE 0x110
#define BTN_LEFT 0x110
#define BTN_RIGHT 0x111
#define BTN_MIDDLE 0x112
#define BTN_SIDE 0x113
#define BTN_EXTRA 0x114
#define BTN_FORWARD 0x115
#define BTN_BACK 0x116
#define BTN_TASK 0x117
#define BTN_JOYSTICK 0x120
#define BTN_TRIGGER 0x120
#define BTN_THUMB 0x121
#define BTN_THUMB2 0x122
#define BTN_TOP 0x123
#define BTN_TOP2 0x124
#define BTN_PINKIE 0x125
#define BTN_BASE 0x126
#define BTN_BASE2 0x127
#define BTN_BASE3 0x128
#define BTN_BASE4 0x129
#define BTN_BASE5 0x12a
#define BTN_BASE6 0x12b
#define BTN_DEAD 0x12f
#define BTN_GAMEPAD 0x130
#define BTN_SOUTH 0x130
#define BTN_A BTN_SOUTH
#define BTN_EAST 0x131
#define BTN_B BTN_EAST
#define BTN_C 0x132
#define BTN_NORTH 0x133
#define BTN_X BTN_NORTH
#define BTN_WEST 0x134
#define BTN_Y BTN_WEST
#define BTN_Z 0x135
#define BTN_TL 0x136
#define BTN_TR 0x137
#define BTN_TL2 0x138
#define BTN_TR2 0x139
#define BTN_SELECT 0x13a
#define BTN_START 0x13b
#define BTN_MODE 0x13c
#define BTN_THUMBL 0x13d
#define BTN_THUMBR 0x13e
#define BTN_DIGI 0x140
#define BTN_TOOL_PEN 0x140
#define BTN_TOOL_RUBBER 0x141
#define BTN_TOOL_BRUSH 0x142
#define BTN_TOOL_PENCIL 0x143
#define BTN_TOOL_AIRBRUSH 0x144
#define BTN_TOOL_FINGER 0x145
#define BTN_TOOL_MOUSE 0x146
#define BTN_TOOL_LENS 0x147
#define BTN_TOOL_QUINTTAP 0x148 /* Five fingers on trackpad */
#define BTN_STYLUS3 0x149
#define BTN_TOUCH 0x14a
#define BTN_STYLUS 0x14b
#define BTN_STYLUS2 0x14c
#define BTN_TOOL_DOUBLETAP 0x14d
#define BTN_TOOL_TRIPLETAP 0x14e
#define BTN_TOOL_QUADTAP 0x14f /* Four fingers on trackpad */
#define BTN_WHEEL 0x150
#define BTN_GEAR_DOWN 0x150
#define BTN_GEAR_UP 0x151
#define KEY_OK 0x160
#define KEY_SELECT 0x161
#define KEY_GOTO 0x162
#define KEY_CLEAR 0x163
#define KEY_POWER2 0x164
#define KEY_OPTION 0x165
#define KEY_INFO 0x166 /* AL OEM Features/Tips/Tutorial */
#define KEY_TIME 0x167
#define KEY_VENDOR 0x168
#define KEY_ARCHIVE 0x169
#define KEY_PROGRAM 0x16a /* Media Select Program Guide */
#define KEY_CHANNEL 0x16b
#define KEY_FAVORITES 0x16c
#define KEY_EPG 0x16d
#define KEY_PVR 0x16e /* Media Select Home */
#define KEY_MHP 0x16f
#define KEY_LANGUAGE 0x170
#define KEY_TITLE 0x171
#define KEY_SUBTITLE 0x172
#define KEY_ANGLE 0x173
#define KEY_FULL_SCREEN 0x174 /* AC View Toggle */
#define KEY_ZOOM KEY_FULL_SCREEN
#define KEY_MODE 0x175
#define KEY_KEYBOARD 0x176
#define KEY_ASPECT_RATIO 0x177 /* HUTRR37: Aspect */
#define KEY_SCREEN KEY_ASPECT_RATIO
#define KEY_PC 0x178 /* Media Select Computer */
#define KEY_TV 0x179 /* Media Select TV */
#define KEY_TV2 0x17a /* Media Select Cable */
#define KEY_VCR 0x17b /* Media Select VCR */
#define KEY_VCR2 0x17c /* VCR Plus */
#define KEY_SAT 0x17d /* Media Select Satellite */
#define KEY_SAT2 0x17e
#define KEY_CD 0x17f /* Media Select CD */
#define KEY_TAPE 0x180 /* Media Select Tape */
#define KEY_RADIO 0x181
#define KEY_TUNER 0x182 /* Media Select Tuner */
#define KEY_PLAYER 0x183
#define KEY_TEXT 0x184
#define KEY_DVD 0x185 /* Media Select DVD */
#define KEY_AUX 0x186
#define KEY_MP3 0x187
#define KEY_AUDIO 0x188 /* AL Audio Browser */
#define KEY_VIDEO 0x189 /* AL Movie Browser */
#define KEY_DIRECTORY 0x18a
#define KEY_LIST 0x18b
#define KEY_MEMO 0x18c /* Media Select Messages */
#define KEY_CALENDAR 0x18d
#define KEY_RED 0x18e
#define KEY_GREEN 0x18f
#define KEY_YELLOW 0x190
#define KEY_BLUE 0x191
#define KEY_CHANNELUP 0x192 /* Channel Increment */
#define KEY_CHANNELDOWN 0x193 /* Channel Decrement */
#define KEY_FIRST 0x194
#define KEY_LAST 0x195 /* Recall Last */
#define KEY_AB 0x196
#define KEY_NEXT 0x197
#define KEY_RESTART 0x198
#define KEY_SLOW 0x199
#define KEY_SHUFFLE 0x19a
#define KEY_BREAK 0x19b
#define KEY_PREVIOUS 0x19c
#define KEY_DIGITS 0x19d
#define KEY_TEEN 0x19e
#define KEY_TWEN 0x19f
#define KEY_VIDEOPHONE 0x1a0 /* Media Select Video Phone */
#define KEY_GAMES 0x1a1 /* Media Select Games */
#define KEY_ZOOMIN 0x1a2 /* AC Zoom In */
#define KEY_ZOOMOUT 0x1a3 /* AC Zoom Out */
#define KEY_ZOOMRESET 0x1a4 /* AC Zoom */
#define KEY_WORDPROCESSOR 0x1a5 /* AL Word Processor */
#define KEY_EDITOR 0x1a6 /* AL Text Editor */
#define KEY_SPREADSHEET 0x1a7 /* AL Spreadsheet */
#define KEY_GRAPHICSEDITOR 0x1a8 /* AL Graphics Editor */
#define KEY_PRESENTATION 0x1a9 /* AL Presentation App */
#define KEY_DATABASE 0x1aa /* AL Database App */
#define KEY_NEWS 0x1ab /* AL Newsreader */
#define KEY_VOICEMAIL 0x1ac /* AL Voicemail */
#define KEY_ADDRESSBOOK 0x1ad /* AL Contacts/Address Book */
#define KEY_MESSENGER 0x1ae /* AL Instant Messaging */
#define KEY_DISPLAYTOGGLE 0x1af /* Turn display (LCD) on and off */
#define KEY_BRIGHTNESS_TOGGLE KEY_DISPLAYTOGGLE
#define KEY_SPELLCHECK 0x1b0 /* AL Spell Check */
#define KEY_LOGOFF 0x1b1 /* AL Logoff */
#define KEY_DOLLAR 0x1b2
#define KEY_EURO 0x1b3
#define KEY_FRAMEBACK 0x1b4 /* Consumer - transport controls */
#define KEY_FRAMEFORWARD 0x1b5
#define KEY_CONTEXT_MENU 0x1b6 /* GenDesc - system context menu */
#define KEY_MEDIA_REPEAT 0x1b7 /* Consumer - transport control */
#define KEY_10CHANNELSUP 0x1b8 /* 10 channels up (10+) */
#define KEY_10CHANNELSDOWN 0x1b9 /* 10 channels down (10-) */
#define KEY_IMAGES 0x1ba /* AL Image Browser */
#define KEY_DEL_EOL 0x1c0
#define KEY_DEL_EOS 0x1c1
#define KEY_INS_LINE 0x1c2
#define KEY_DEL_LINE 0x1c3
#define KEY_FN 0x1d0
#define KEY_FN_ESC 0x1d1
#define KEY_FN_F1 0x1d2
#define KEY_FN_F2 0x1d3
#define KEY_FN_F3 0x1d4
#define KEY_FN_F4 0x1d5
#define KEY_FN_F5 0x1d6
#define KEY_FN_F6 0x1d7
#define KEY_FN_F7 0x1d8
#define KEY_FN_F8 0x1d9
#define KEY_FN_F9 0x1da
#define KEY_FN_F10 0x1db
#define KEY_FN_F11 0x1dc
#define KEY_FN_F12 0x1dd
#define KEY_FN_1 0x1de
#define KEY_FN_2 0x1df
#define KEY_FN_D 0x1e0
#define KEY_FN_E 0x1e1
#define KEY_FN_F 0x1e2
#define KEY_FN_S 0x1e3
#define KEY_FN_B 0x1e4
#define KEY_BRL_DOT1 0x1f1
#define KEY_BRL_DOT2 0x1f2
#define KEY_BRL_DOT3 0x1f3
#define KEY_BRL_DOT4 0x1f4
#define KEY_BRL_DOT5 0x1f5
#define KEY_BRL_DOT6 0x1f6
#define KEY_BRL_DOT7 0x1f7
#define KEY_BRL_DOT8 0x1f8
#define KEY_BRL_DOT9 0x1f9
#define KEY_BRL_DOT10 0x1fa
#define KEY_NUMERIC_0 0x200 /* used by phones, remote controls, */
#define KEY_NUMERIC_1 0x201 /* and other keypads */
#define KEY_NUMERIC_2 0x202
#define KEY_NUMERIC_3 0x203
#define KEY_NUMERIC_4 0x204
#define KEY_NUMERIC_5 0x205
#define KEY_NUMERIC_6 0x206
#define KEY_NUMERIC_7 0x207
#define KEY_NUMERIC_8 0x208
#define KEY_NUMERIC_9 0x209
#define KEY_NUMERIC_STAR 0x20a
#define KEY_NUMERIC_POUND 0x20b
#define KEY_NUMERIC_A 0x20c /* Phone key A - HUT Telephony 0xb9 */
#define KEY_NUMERIC_B 0x20d
#define KEY_NUMERIC_C 0x20e
#define KEY_NUMERIC_D 0x20f
#define KEY_CAMERA_FOCUS 0x210
#define KEY_WPS_BUTTON 0x211 /* WiFi Protected Setup key */
#define KEY_TOUCHPAD_TOGGLE 0x212 /* Request switch touchpad on or off */
#define KEY_TOUCHPAD_ON 0x213
#define KEY_TOUCHPAD_OFF 0x214
#define KEY_CAMERA_ZOOMIN 0x215
#define KEY_CAMERA_ZOOMOUT 0x216
#define KEY_CAMERA_UP 0x217
#define KEY_CAMERA_DOWN 0x218
#define KEY_CAMERA_LEFT 0x219
#define KEY_CAMERA_RIGHT 0x21a
#define KEY_ATTENDANT_ON 0x21b
#define KEY_ATTENDANT_OFF 0x21c
#define KEY_ATTENDANT_TOGGLE 0x21d /* Attendant call on or off */
#define KEY_LIGHTS_TOGGLE 0x21e /* Reading light on or off */
#define BTN_DPAD_UP 0x220
#define BTN_DPAD_DOWN 0x221
#define BTN_DPAD_LEFT 0x222
#define BTN_DPAD_RIGHT 0x223
#define KEY_ALS_TOGGLE 0x230 /* Ambient light sensor */
#define KEY_ROTATE_LOCK_TOGGLE 0x231 /* Display rotation lock */
#define KEY_BUTTONCONFIG 0x240 /* AL Button Configuration */
#define KEY_TASKMANAGER 0x241 /* AL Task/Project Manager */
#define KEY_JOURNAL 0x242 /* AL Log/Journal/Timecard */
#define KEY_CONTROLPANEL 0x243 /* AL Control Panel */
#define KEY_APPSELECT 0x244 /* AL Select Task/Application */
#define KEY_SCREENSAVER 0x245 /* AL Screen Saver */
#define KEY_VOICECOMMAND 0x246 /* Listening Voice Command */
#define KEY_ASSISTANT 0x247 /* AL Context-aware desktop assistant */
#define KEY_KBD_LAYOUT_NEXT 0x248 /* AC Next Keyboard Layout Select */
#define KEY_BRIGHTNESS_MIN 0x250 /* Set Brightness to Minimum */
#define KEY_BRIGHTNESS_MAX 0x251 /* Set Brightness to Maximum */
#define KEY_KBDINPUTASSIST_PREV 0x260
#define KEY_KBDINPUTASSIST_NEXT 0x261
#define KEY_KBDINPUTASSIST_PREVGROUP 0x262
#define KEY_KBDINPUTASSIST_NEXTGROUP 0x263
#define KEY_KBDINPUTASSIST_ACCEPT 0x264
#define KEY_KBDINPUTASSIST_CANCEL 0x265
/* Diagonal movement keys */
#define KEY_RIGHT_UP 0x266
#define KEY_RIGHT_DOWN 0x267
#define KEY_LEFT_UP 0x268
#define KEY_LEFT_DOWN 0x269
#define KEY_ROOT_MENU 0x26a /* Show Device's Root Menu */
/* Show Top Menu of the Media (e.g. DVD) */
#define KEY_MEDIA_TOP_MENU 0x26b
#define KEY_NUMERIC_11 0x26c
#define KEY_NUMERIC_12 0x26d
/*
* Toggle Audio Description: refers to an audio service that helps blind and
* visually impaired consumers understand the action in a program. Note: in
* some countries this is referred to as "Video Description".
*/
#define KEY_AUDIO_DESC 0x26e
#define KEY_3D_MODE 0x26f
#define KEY_NEXT_FAVORITE 0x270
#define KEY_STOP_RECORD 0x271
#define KEY_PAUSE_RECORD 0x272
#define KEY_VOD 0x273 /* Video on Demand */
#define KEY_UNMUTE 0x274
#define KEY_FASTREVERSE 0x275
#define KEY_SLOWREVERSE 0x276
/*
* Control a data application associated with the currently viewed channel,
* e.g. teletext or data broadcast application (MHEG, MHP, HbbTV, etc.)
*/
#define KEY_DATA 0x277
#define KEY_ONSCREEN_KEYBOARD 0x278
/* Electronic privacy screen control */
#define KEY_PRIVACY_SCREEN_TOGGLE 0x279
/* Select an area of screen to be copied */
#define KEY_SELECTIVE_SCREENSHOT 0x27a
/*
* Some keyboards have keys which do not have a defined meaning, these keys
* are intended to be programmed / bound to macros by the user. For most
* keyboards with these macro-keys the key-sequence to inject, or action to
* take, is all handled by software on the host side. So from the kernel's
* point of view these are just normal keys.
*
* The KEY_MACRO# codes below are intended for such keys, which may be labeled
* e.g. G1-G18, or S1 - S30. The KEY_MACRO# codes MUST NOT be used for keys
* where the marking on the key does indicate a defined meaning / purpose.
*
* The KEY_MACRO# codes MUST also NOT be used as fallback for when no existing
* KEY_FOO define matches the marking / purpose. In this case a new KEY_FOO
* define MUST be added.
*/
#define KEY_MACRO1 0x290
#define KEY_MACRO2 0x291
#define KEY_MACRO3 0x292
#define KEY_MACRO4 0x293
#define KEY_MACRO5 0x294
#define KEY_MACRO6 0x295
#define KEY_MACRO7 0x296
#define KEY_MACRO8 0x297
#define KEY_MACRO9 0x298
#define KEY_MACRO10 0x299
#define KEY_MACRO11 0x29a
#define KEY_MACRO12 0x29b
#define KEY_MACRO13 0x29c
#define KEY_MACRO14 0x29d
#define KEY_MACRO15 0x29e
#define KEY_MACRO16 0x29f
#define KEY_MACRO17 0x2a0
#define KEY_MACRO18 0x2a1
#define KEY_MACRO19 0x2a2
#define KEY_MACRO20 0x2a3
#define KEY_MACRO21 0x2a4
#define KEY_MACRO22 0x2a5
#define KEY_MACRO23 0x2a6
#define KEY_MACRO24 0x2a7
#define KEY_MACRO25 0x2a8
#define KEY_MACRO26 0x2a9
#define KEY_MACRO27 0x2aa
#define KEY_MACRO28 0x2ab
#define KEY_MACRO29 0x2ac
#define KEY_MACRO30 0x2ad
/*
* Some keyboards with the macro-keys described above have some extra keys
* for controlling the host-side software responsible for the macro handling:
* -A macro recording start/stop key. Note that not all keyboards which emit
* KEY_MACRO_RECORD_START will also emit KEY_MACRO_RECORD_STOP if
* KEY_MACRO_RECORD_STOP is not advertised, then KEY_MACRO_RECORD_START
* should be interpreted as a recording start/stop toggle;
* -Keys for switching between different macro (pre)sets, either a key for
* cycling through the configured presets or keys to directly select a preset.
*/
#define KEY_MACRO_RECORD_START 0x2b0
#define KEY_MACRO_RECORD_STOP 0x2b1
#define KEY_MACRO_PRESET_CYCLE 0x2b2
#define KEY_MACRO_PRESET1 0x2b3
#define KEY_MACRO_PRESET2 0x2b4
#define KEY_MACRO_PRESET3 0x2b5
/*
* Some keyboards have a buildin LCD panel where the contents are controlled
* by the host. Often these have a number of keys directly below the LCD
* intended for controlling a menu shown on the LCD. These keys often don't
* have any labeling so we just name them KEY_KBD_LCD_MENU#
*/
#define KEY_KBD_LCD_MENU1 0x2b8
#define KEY_KBD_LCD_MENU2 0x2b9
#define KEY_KBD_LCD_MENU3 0x2ba
#define KEY_KBD_LCD_MENU4 0x2bb
#define KEY_KBD_LCD_MENU5 0x2bc
#define BTN_TRIGGER_HAPPY 0x2c0
#define BTN_TRIGGER_HAPPY1 0x2c0
#define BTN_TRIGGER_HAPPY2 0x2c1
#define BTN_TRIGGER_HAPPY3 0x2c2
#define BTN_TRIGGER_HAPPY4 0x2c3
#define BTN_TRIGGER_HAPPY5 0x2c4
#define BTN_TRIGGER_HAPPY6 0x2c5
#define BTN_TRIGGER_HAPPY7 0x2c6
#define BTN_TRIGGER_HAPPY8 0x2c7
#define BTN_TRIGGER_HAPPY9 0x2c8
#define BTN_TRIGGER_HAPPY10 0x2c9
#define BTN_TRIGGER_HAPPY11 0x2ca
#define BTN_TRIGGER_HAPPY12 0x2cb
#define BTN_TRIGGER_HAPPY13 0x2cc
#define BTN_TRIGGER_HAPPY14 0x2cd
#define BTN_TRIGGER_HAPPY15 0x2ce
#define BTN_TRIGGER_HAPPY16 0x2cf
#define BTN_TRIGGER_HAPPY17 0x2d0
#define BTN_TRIGGER_HAPPY18 0x2d1
#define BTN_TRIGGER_HAPPY19 0x2d2
#define BTN_TRIGGER_HAPPY20 0x2d3
#define BTN_TRIGGER_HAPPY21 0x2d4
#define BTN_TRIGGER_HAPPY22 0x2d5
#define BTN_TRIGGER_HAPPY23 0x2d6
#define BTN_TRIGGER_HAPPY24 0x2d7
#define BTN_TRIGGER_HAPPY25 0x2d8
#define BTN_TRIGGER_HAPPY26 0x2d9
#define BTN_TRIGGER_HAPPY27 0x2da
#define BTN_TRIGGER_HAPPY28 0x2db
#define BTN_TRIGGER_HAPPY29 0x2dc
#define BTN_TRIGGER_HAPPY30 0x2dd
#define BTN_TRIGGER_HAPPY31 0x2de
#define BTN_TRIGGER_HAPPY32 0x2df
#define BTN_TRIGGER_HAPPY33 0x2e0
#define BTN_TRIGGER_HAPPY34 0x2e1
#define BTN_TRIGGER_HAPPY35 0x2e2
#define BTN_TRIGGER_HAPPY36 0x2e3
#define BTN_TRIGGER_HAPPY37 0x2e4
#define BTN_TRIGGER_HAPPY38 0x2e5
#define BTN_TRIGGER_HAPPY39 0x2e6
#define BTN_TRIGGER_HAPPY40 0x2e7
/* We avoid low common keys in module aliases so they don't get huge. */
#define KEY_MIN_INTERESTING KEY_MUTE
#define KEY_MAX 0x2ff
#define KEY_CNT (KEY_MAX+1)
/*
* Relative axes
*/
#define REL_X 0x00
#define REL_Y 0x01
#define REL_Z 0x02
#define REL_RX 0x03
#define REL_RY 0x04
#define REL_RZ 0x05
#define REL_HWHEEL 0x06
#define REL_DIAL 0x07
#define REL_WHEEL 0x08
#define REL_MISC 0x09
/*
* 0x0a is reserved and should not be used in input drivers.
* It was used by HID as REL_MISC+1 and userspace needs to detect if
* the next REL_* event is correct or is just REL_MISC + n.
* We define here REL_RESERVED so userspace can rely on it and detect
* the situation described above.
*/
#define REL_RESERVED 0x0a
#define REL_WHEEL_HI_RES 0x0b
#define REL_HWHEEL_HI_RES 0x0c
#define REL_MAX 0x0f
#define REL_CNT (REL_MAX+1)
/*
* Absolute axes
*/
#define ABS_X 0x00
#define ABS_Y 0x01
#define ABS_Z 0x02
#define ABS_RX 0x03
#define ABS_RY 0x04
#define ABS_RZ 0x05
#define ABS_THROTTLE 0x06
#define ABS_RUDDER 0x07
#define ABS_WHEEL 0x08
#define ABS_GAS 0x09
#define ABS_BRAKE 0x0a
#define ABS_HAT0X 0x10
#define ABS_HAT0Y 0x11
#define ABS_HAT1X 0x12
#define ABS_HAT1Y 0x13
#define ABS_HAT2X 0x14
#define ABS_HAT2Y 0x15
#define ABS_HAT3X 0x16
#define ABS_HAT3Y 0x17
#define ABS_PRESSURE 0x18
#define ABS_DISTANCE 0x19
#define ABS_TILT_X 0x1a
#define ABS_TILT_Y 0x1b
#define ABS_TOOL_WIDTH 0x1c
#define ABS_VOLUME 0x20
#define ABS_MISC 0x28
/*
* 0x2e is reserved and should not be used in input drivers.
* It was used by HID as ABS_MISC+6 and userspace needs to detect if
* the next ABS_* event is correct or is just ABS_MISC + n.
* We define here ABS_RESERVED so userspace can rely on it and detect
* the situation described above.
*/
#define ABS_RESERVED 0x2e
#define ABS_MT_SLOT 0x2f /* MT slot being modified */
#define ABS_MT_TOUCH_MAJOR 0x30 /* Major axis of touching ellipse */
#define ABS_MT_TOUCH_MINOR 0x31 /* Minor axis (omit if circular) */
#define ABS_MT_WIDTH_MAJOR 0x32 /* Major axis of approaching ellipse */
#define ABS_MT_WIDTH_MINOR 0x33 /* Minor axis (omit if circular) */
#define ABS_MT_ORIENTATION 0x34 /* Ellipse orientation */
#define ABS_MT_POSITION_X 0x35 /* Center X touch position */
#define ABS_MT_POSITION_Y 0x36 /* Center Y touch position */
#define ABS_MT_TOOL_TYPE 0x37 /* Type of touching device */
#define ABS_MT_BLOB_ID 0x38 /* Group a set of packets as a blob */
#define ABS_MT_TRACKING_ID 0x39 /* Unique ID of initiated contact */
#define ABS_MT_PRESSURE 0x3a /* Pressure on contact area */
#define ABS_MT_DISTANCE 0x3b /* Contact hover distance */
#define ABS_MT_TOOL_X 0x3c /* Center X tool position */
#define ABS_MT_TOOL_Y 0x3d /* Center Y tool position */
#define ABS_MAX 0x3f
#define ABS_CNT (ABS_MAX+1)
/*
* Switch events
*/
#define SW_LID 0x00 /* set = lid shut */
#define SW_TABLET_MODE 0x01 /* set = tablet mode */
#define SW_HEADPHONE_INSERT 0x02 /* set = inserted */
#define SW_RFKILL_ALL 0x03 /* rfkill master switch, type "any"
set = radio enabled */
#define SW_RADIO SW_RFKILL_ALL /* deprecated */
#define SW_MICROPHONE_INSERT 0x04 /* set = inserted */
#define SW_DOCK 0x05 /* set = plugged into dock */
#define SW_LINEOUT_INSERT 0x06 /* set = inserted */
#define SW_JACK_PHYSICAL_INSERT 0x07 /* set = mechanical switch set */
#define SW_VIDEOOUT_INSERT 0x08 /* set = inserted */
#define SW_CAMERA_LENS_COVER 0x09 /* set = lens covered */
#define SW_KEYPAD_SLIDE 0x0a /* set = keypad slide out */
#define SW_FRONT_PROXIMITY 0x0b /* set = front proximity sensor active */
#define SW_ROTATE_LOCK 0x0c /* set = rotate locked/disabled */
#define SW_LINEIN_INSERT 0x0d /* set = inserted */
#define SW_MUTE_DEVICE 0x0e /* set = device disabled */
#define SW_PEN_INSERTED 0x0f /* set = pen inserted */
#define SW_MACHINE_COVER 0x10 /* set = cover closed */
#define SW_MAX 0x10
#define SW_CNT (SW_MAX+1)
/*
* Misc events
*/
#define MSC_SERIAL 0x00
#define MSC_PULSELED 0x01
#define MSC_GESTURE 0x02
#define MSC_RAW 0x03
#define MSC_SCAN 0x04
#define MSC_TIMESTAMP 0x05
#define MSC_MAX 0x07
#define MSC_CNT (MSC_MAX+1)
/*
* LEDs
*/
#define LED_NUML 0x00
#define LED_CAPSL 0x01
#define LED_SCROLLL 0x02
#define LED_COMPOSE 0x03
#define LED_KANA 0x04
#define LED_SLEEP 0x05
#define LED_SUSPEND 0x06
#define LED_MUTE 0x07
#define LED_MISC 0x08
#define LED_MAIL 0x09
#define LED_CHARGING 0x0a
#define LED_MAX 0x0f
#define LED_CNT (LED_MAX+1)
/*
* Autorepeat values
*/
#define REP_DELAY 0x00
#define REP_PERIOD 0x01
#define REP_MAX 0x01
#define REP_CNT (REP_MAX+1)
/*
* Sounds
*/
#define SND_CLICK 0x00
#define SND_BELL 0x01
#define SND_TONE 0x02
#define SND_MAX 0x07
#define SND_CNT (SND_MAX+1)
#endif
libinput-1.28.1/include/linux/linux/input.h000066400000000000000000000370111477265155700207070ustar00rootroot00000000000000/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
/*
* Copyright (c) 1999-2002 Vojtech Pavlik
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 as published by
* the Free Software Foundation.
*/
#ifndef _INPUT_H
#define _INPUT_H
#include
#include
#include
#include
#include "input-event-codes.h"
/*
* The event structure itself
* Note that __USE_TIME_BITS64 is defined by libc based on
* application's request to use 64 bit time_t.
*/
struct input_event {
#if (__BITS_PER_LONG != 32 || !defined(__USE_TIME_BITS64)) && !defined(__KERNEL)
struct timeval time;
#define input_event_sec time.tv_sec
#define input_event_usec time.tv_usec
#else
__kernel_ulong_t __sec;
__kernel_ulong_t __usec;
#define input_event_sec __sec
#define input_event_usec __usec
#endif
__u16 type;
__u16 code;
__s32 value;
};
/*
* Protocol version.
*/
#define EV_VERSION 0x010001
/*
* IOCTLs (0x00 - 0x7f)
*/
struct input_id {
__u16 bustype;
__u16 vendor;
__u16 product;
__u16 version;
};
/**
* struct input_absinfo - used by EVIOCGABS/EVIOCSABS ioctls
* @value: latest reported value for the axis.
* @minimum: specifies minimum value for the axis.
* @maximum: specifies maximum value for the axis.
* @fuzz: specifies fuzz value that is used to filter noise from
* the event stream.
* @flat: values that are within this value will be discarded by
* joydev interface and reported as 0 instead.
* @resolution: specifies resolution for the values reported for
* the axis.
*
* Note that input core does not clamp reported values to the
* [minimum, maximum] limits, such task is left to userspace.
*
* The default resolution for main axes (ABS_X, ABS_Y, ABS_Z)
* is reported in units per millimeter (units/mm), resolution
* for rotational axes (ABS_RX, ABS_RY, ABS_RZ) is reported
* in units per radian.
* When INPUT_PROP_ACCELEROMETER is set the resolution changes.
* The main axes (ABS_X, ABS_Y, ABS_Z) are then reported in
* in units per g (units/g) and in units per degree per second
* (units/deg/s) for rotational axes (ABS_RX, ABS_RY, ABS_RZ).
*/
struct input_absinfo {
__s32 value;
__s32 minimum;
__s32 maximum;
__s32 fuzz;
__s32 flat;
__s32 resolution;
};
/**
* struct input_keymap_entry - used by EVIOCGKEYCODE/EVIOCSKEYCODE ioctls
* @scancode: scancode represented in machine-endian form.
* @len: length of the scancode that resides in @scancode buffer.
* @index: index in the keymap, may be used instead of scancode
* @flags: allows to specify how kernel should handle the request. For
* example, setting INPUT_KEYMAP_BY_INDEX flag indicates that kernel
* should perform lookup in keymap by @index instead of @scancode
* @keycode: key code assigned to this scancode
*
* The structure is used to retrieve and modify keymap data. Users have
* option of performing lookup either by @scancode itself or by @index
* in keymap entry. EVIOCGKEYCODE will also return scancode or index
* (depending on which element was used to perform lookup).
*/
struct input_keymap_entry {
#define INPUT_KEYMAP_BY_INDEX (1 << 0)
__u8 flags;
__u8 len;
__u16 index;
__u32 keycode;
__u8 scancode[32];
};
struct input_mask {
__u32 type;
__u32 codes_size;
__u64 codes_ptr;
};
#define EVIOCGVERSION _IOR('E', 0x01, int) /* get driver version */
#define EVIOCGID _IOR('E', 0x02, struct input_id) /* get device ID */
#define EVIOCGREP _IOR('E', 0x03, unsigned int[2]) /* get repeat settings */
#define EVIOCSREP _IOW('E', 0x03, unsigned int[2]) /* set repeat settings */
#define EVIOCGKEYCODE _IOR('E', 0x04, unsigned int[2]) /* get keycode */
#define EVIOCGKEYCODE_V2 _IOR('E', 0x04, struct input_keymap_entry)
#define EVIOCSKEYCODE _IOW('E', 0x04, unsigned int[2]) /* set keycode */
#define EVIOCSKEYCODE_V2 _IOW('E', 0x04, struct input_keymap_entry)
#define EVIOCGNAME(len) _IOC(_IOC_READ, 'E', 0x06, len) /* get device name */
#define EVIOCGPHYS(len) _IOC(_IOC_READ, 'E', 0x07, len) /* get physical location */
#define EVIOCGUNIQ(len) _IOC(_IOC_READ, 'E', 0x08, len) /* get unique identifier */
#define EVIOCGPROP(len) _IOC(_IOC_READ, 'E', 0x09, len) /* get device properties */
/**
* EVIOCGMTSLOTS(len) - get MT slot values
* @len: size of the data buffer in bytes
*
* The ioctl buffer argument should be binary equivalent to
*
* struct input_mt_request_layout {
* __u32 code;
* __s32 values[num_slots];
* };
*
* where num_slots is the (arbitrary) number of MT slots to extract.
*
* The ioctl size argument (len) is the size of the buffer, which
* should satisfy len = (num_slots + 1) * sizeof(__s32). If len is
* too small to fit all available slots, the first num_slots are
* returned.
*
* Before the call, code is set to the wanted ABS_MT event type. On
* return, values[] is filled with the slot values for the specified
* ABS_MT code.
*
* If the request code is not an ABS_MT value, -EINVAL is returned.
*/
#define EVIOCGMTSLOTS(len) _IOC(_IOC_READ, 'E', 0x0a, len)
#define EVIOCGKEY(len) _IOC(_IOC_READ, 'E', 0x18, len) /* get global key state */
#define EVIOCGLED(len) _IOC(_IOC_READ, 'E', 0x19, len) /* get all LEDs */
#define EVIOCGSND(len) _IOC(_IOC_READ, 'E', 0x1a, len) /* get all sounds status */
#define EVIOCGSW(len) _IOC(_IOC_READ, 'E', 0x1b, len) /* get all switch states */
#define EVIOCGBIT(ev,len) _IOC(_IOC_READ, 'E', 0x20 + (ev), len) /* get event bits */
#define EVIOCGABS(abs) _IOR('E', 0x40 + (abs), struct input_absinfo) /* get abs value/limits */
#define EVIOCSABS(abs) _IOW('E', 0xc0 + (abs), struct input_absinfo) /* set abs value/limits */
#define EVIOCSFF _IOW('E', 0x80, struct ff_effect) /* send a force effect to a force feedback device */
#define EVIOCRMFF _IOW('E', 0x81, int) /* Erase a force effect */
#define EVIOCGEFFECTS _IOR('E', 0x84, int) /* Report number of effects playable at the same time */
#define EVIOCGRAB _IOW('E', 0x90, int) /* Grab/Release device */
#define EVIOCREVOKE _IOW('E', 0x91, int) /* Revoke device access */
/**
* EVIOCGMASK - Retrieve current event mask
*
* This ioctl allows user to retrieve the current event mask for specific
* event type. The argument must be of type "struct input_mask" and
* specifies the event type to query, the address of the receive buffer and
* the size of the receive buffer.
*
* The event mask is a per-client mask that specifies which events are
* forwarded to the client. Each event code is represented by a single bit
* in the event mask. If the bit is set, the event is passed to the client
* normally. Otherwise, the event is filtered and will never be queued on
* the client's receive buffer.
*
* Event masks do not affect global state of the input device. They only
* affect the file descriptor they are applied to.
*
* The default event mask for a client has all bits set, i.e. all events
* are forwarded to the client. If the kernel is queried for an unknown
* event type or if the receive buffer is larger than the number of
* event codes known to the kernel, the kernel returns all zeroes for those
* codes.
*
* At maximum, codes_size bytes are copied.
*
* This ioctl may fail with ENODEV in case the file is revoked, EFAULT
* if the receive-buffer points to invalid memory, or EINVAL if the kernel
* does not implement the ioctl.
*/
#define EVIOCGMASK _IOR('E', 0x92, struct input_mask) /* Get event-masks */
/**
* EVIOCSMASK - Set event mask
*
* This ioctl is the counterpart to EVIOCGMASK. Instead of receiving the
* current event mask, this changes the client's event mask for a specific
* type. See EVIOCGMASK for a description of event-masks and the
* argument-type.
*
* This ioctl provides full forward compatibility. If the passed event type
* is unknown to the kernel, or if the number of event codes specified in
* the mask is bigger than what is known to the kernel, the ioctl is still
* accepted and applied. However, any unknown codes are left untouched and
* stay cleared. That means, the kernel always filters unknown codes
* regardless of what the client requests. If the new mask doesn't cover
* all known event-codes, all remaining codes are automatically cleared and
* thus filtered.
*
* This ioctl may fail with ENODEV in case the file is revoked. EFAULT is
* returned if the receive-buffer points to invalid memory. EINVAL is returned
* if the kernel does not implement the ioctl.
*/
#define EVIOCSMASK _IOW('E', 0x93, struct input_mask) /* Set event-masks */
#define EVIOCSCLOCKID _IOW('E', 0xa0, int) /* Set clockid to be used for timestamps */
/*
* IDs.
*/
#define ID_BUS 0
#define ID_VENDOR 1
#define ID_PRODUCT 2
#define ID_VERSION 3
#define BUS_PCI 0x01
#define BUS_ISAPNP 0x02
#define BUS_USB 0x03
#define BUS_HIL 0x04
#define BUS_BLUETOOTH 0x05
#define BUS_VIRTUAL 0x06
#define BUS_ISA 0x10
#define BUS_I8042 0x11
#define BUS_XTKBD 0x12
#define BUS_RS232 0x13
#define BUS_GAMEPORT 0x14
#define BUS_PARPORT 0x15
#define BUS_AMIGA 0x16
#define BUS_ADB 0x17
#define BUS_I2C 0x18
#define BUS_HOST 0x19
#define BUS_GSC 0x1A
#define BUS_ATARI 0x1B
#define BUS_SPI 0x1C
#define BUS_RMI 0x1D
#define BUS_CEC 0x1E
#define BUS_INTEL_ISHTP 0x1F
/*
* MT_TOOL types
*/
#define MT_TOOL_FINGER 0x00
#define MT_TOOL_PEN 0x01
#define MT_TOOL_PALM 0x02
#define MT_TOOL_DIAL 0x0a
#define MT_TOOL_MAX 0x0f
/*
* Values describing the status of a force-feedback effect
*/
#define FF_STATUS_STOPPED 0x00
#define FF_STATUS_PLAYING 0x01
#define FF_STATUS_MAX 0x01
/*
* Structures used in ioctls to upload effects to a device
* They are pieces of a bigger structure (called ff_effect)
*/
/*
* All duration values are expressed in ms. Values above 32767 ms (0x7fff)
* should not be used and have unspecified results.
*/
/**
* struct ff_replay - defines scheduling of the force-feedback effect
* @length: duration of the effect
* @delay: delay before effect should start playing
*/
struct ff_replay {
__u16 length;
__u16 delay;
};
/**
* struct ff_trigger - defines what triggers the force-feedback effect
* @button: number of the button triggering the effect
* @interval: controls how soon the effect can be re-triggered
*/
struct ff_trigger {
__u16 button;
__u16 interval;
};
/**
* struct ff_envelope - generic force-feedback effect envelope
* @attack_length: duration of the attack (ms)
* @attack_level: level at the beginning of the attack
* @fade_length: duration of fade (ms)
* @fade_level: level at the end of fade
*
* The @attack_level and @fade_level are absolute values; when applying
* envelope force-feedback core will convert to positive/negative
* value based on polarity of the default level of the effect.
* Valid range for the attack and fade levels is 0x0000 - 0x7fff
*/
struct ff_envelope {
__u16 attack_length;
__u16 attack_level;
__u16 fade_length;
__u16 fade_level;
};
/**
* struct ff_constant_effect - defines parameters of a constant force-feedback effect
* @level: strength of the effect; may be negative
* @envelope: envelope data
*/
struct ff_constant_effect {
__s16 level;
struct ff_envelope envelope;
};
/**
* struct ff_ramp_effect - defines parameters of a ramp force-feedback effect
* @start_level: beginning strength of the effect; may be negative
* @end_level: final strength of the effect; may be negative
* @envelope: envelope data
*/
struct ff_ramp_effect {
__s16 start_level;
__s16 end_level;
struct ff_envelope envelope;
};
/**
* struct ff_condition_effect - defines a spring or friction force-feedback effect
* @right_saturation: maximum level when joystick moved all way to the right
* @left_saturation: same for the left side
* @right_coeff: controls how fast the force grows when the joystick moves
* to the right
* @left_coeff: same for the left side
* @deadband: size of the dead zone, where no force is produced
* @center: position of the dead zone
*/
struct ff_condition_effect {
__u16 right_saturation;
__u16 left_saturation;
__s16 right_coeff;
__s16 left_coeff;
__u16 deadband;
__s16 center;
};
/**
* struct ff_periodic_effect - defines parameters of a periodic force-feedback effect
* @waveform: kind of the effect (wave)
* @period: period of the wave (ms)
* @magnitude: peak value
* @offset: mean value of the wave (roughly)
* @phase: 'horizontal' shift
* @envelope: envelope data
* @custom_len: number of samples (FF_CUSTOM only)
* @custom_data: buffer of samples (FF_CUSTOM only)
*
* Known waveforms - FF_SQUARE, FF_TRIANGLE, FF_SINE, FF_SAW_UP,
* FF_SAW_DOWN, FF_CUSTOM. The exact syntax FF_CUSTOM is undefined
* for the time being as no driver supports it yet.
*
* Note: the data pointed by custom_data is copied by the driver.
* You can therefore dispose of the memory after the upload/update.
*/
struct ff_periodic_effect {
__u16 waveform;
__u16 period;
__s16 magnitude;
__s16 offset;
__u16 phase;
struct ff_envelope envelope;
__u32 custom_len;
__s16 *custom_data;
};
/**
* struct ff_rumble_effect - defines parameters of a periodic force-feedback effect
* @strong_magnitude: magnitude of the heavy motor
* @weak_magnitude: magnitude of the light one
*
* Some rumble pads have two motors of different weight. Strong_magnitude
* represents the magnitude of the vibration generated by the heavy one.
*/
struct ff_rumble_effect {
__u16 strong_magnitude;
__u16 weak_magnitude;
};
/**
* struct ff_effect - defines force feedback effect
* @type: type of the effect (FF_CONSTANT, FF_PERIODIC, FF_RAMP, FF_SPRING,
* FF_FRICTION, FF_DAMPER, FF_RUMBLE, FF_INERTIA, or FF_CUSTOM)
* @id: an unique id assigned to an effect
* @direction: direction of the effect
* @trigger: trigger conditions (struct ff_trigger)
* @replay: scheduling of the effect (struct ff_replay)
* @u: effect-specific structure (one of ff_constant_effect, ff_ramp_effect,
* ff_periodic_effect, ff_condition_effect, ff_rumble_effect) further
* defining effect parameters
*
* This structure is sent through ioctl from the application to the driver.
* To create a new effect application should set its @id to -1; the kernel
* will return assigned @id which can later be used to update or delete
* this effect.
*
* Direction of the effect is encoded as follows:
* 0 deg -> 0x0000 (down)
* 90 deg -> 0x4000 (left)
* 180 deg -> 0x8000 (up)
* 270 deg -> 0xC000 (right)
*/
struct ff_effect {
__u16 type;
__s16 id;
__u16 direction;
struct ff_trigger trigger;
struct ff_replay replay;
union {
struct ff_constant_effect constant;
struct ff_ramp_effect ramp;
struct ff_periodic_effect periodic;
struct ff_condition_effect condition[2]; /* One for each axis */
struct ff_rumble_effect rumble;
} u;
};
/*
* Force feedback effect types
*/
#define FF_RUMBLE 0x50
#define FF_PERIODIC 0x51
#define FF_CONSTANT 0x52
#define FF_SPRING 0x53
#define FF_FRICTION 0x54
#define FF_DAMPER 0x55
#define FF_INERTIA 0x56
#define FF_RAMP 0x57
#define FF_EFFECT_MIN FF_RUMBLE
#define FF_EFFECT_MAX FF_RAMP
/*
* Force feedback periodic effect types
*/
#define FF_SQUARE 0x58
#define FF_TRIANGLE 0x59
#define FF_SINE 0x5a
#define FF_SAW_UP 0x5b
#define FF_SAW_DOWN 0x5c
#define FF_CUSTOM 0x5d
#define FF_WAVEFORM_MIN FF_SQUARE
#define FF_WAVEFORM_MAX FF_CUSTOM
/*
* Set ff device properties
*/
#define FF_GAIN 0x60
#define FF_AUTOCENTER 0x61
/*
* ff->playback(effect_id = FF_GAIN) is the first effect_id to
* cause a collision with another ff method, in this case ff->set_gain().
* Therefore the greatest safe value for effect_id is FF_GAIN - 1,
* and thus the total number of effects should never exceed FF_GAIN.
*/
#define FF_MAX_EFFECTS FF_GAIN
#define FF_MAX 0x7f
#define FF_CNT (FF_MAX+1)
#endif /* _INPUT_H */
libinput-1.28.1/include/valgrind/000077500000000000000000000000001477265155700167055ustar00rootroot00000000000000libinput-1.28.1/include/valgrind/valgrind.h000066400000000000000000014721271477265155700207020ustar00rootroot00000000000000/* -*- c -*-
----------------------------------------------------------------
Notice that the following BSD-style license applies to this one
file (valgrind.h) only. The rest of Valgrind is licensed under the
terms of the GNU General Public License, version 2, unless
otherwise indicated. See the COPYING file in the source
distribution for details.
----------------------------------------------------------------
This file is part of Valgrind, a dynamic binary instrumentation
framework.
Copyright (C) 2000-2017 Julian Seward. All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
2. The origin of this software must not be misrepresented; you must
not claim that you wrote the original software. If you use this
software in a product, an acknowledgment in the product
documentation would be appreciated but is not required.
3. Altered source versions must be plainly marked as such, and must
not be misrepresented as being the original software.
4. The name of the author may not be used to endorse or promote
products derived from this software without specific prior written
permission.
THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
----------------------------------------------------------------
Notice that the above BSD-style license applies to this one file
(valgrind.h) only. The entire rest of Valgrind is licensed under
the terms of the GNU General Public License, version 2. See the
COPYING file in the source distribution for details.
----------------------------------------------------------------
*/
/* This file is for inclusion into client (your!) code.
You can use these macros to manipulate and query Valgrind's
execution inside your own programs.
The resulting executables will still run without Valgrind, just a
little bit more slowly than they otherwise would, but otherwise
unchanged. When not running on valgrind, each client request
consumes very few (eg. 7) instructions, so the resulting performance
loss is negligible unless you plan to execute client requests
millions of times per second. Nevertheless, if that is still a
problem, you can compile with the NVALGRIND symbol defined (gcc
-DNVALGRIND) so that client requests are not even compiled in. */
#ifndef __VALGRIND_H
#define __VALGRIND_H
/* ------------------------------------------------------------------ */
/* VERSION NUMBER OF VALGRIND */
/* ------------------------------------------------------------------ */
/* Specify Valgrind's version number, so that user code can
conditionally compile based on our version number. Note that these
were introduced at version 3.6 and so do not exist in version 3.5
or earlier. The recommended way to use them to check for "version
X.Y or later" is (eg)
#if defined(__VALGRIND_MAJOR__) && defined(__VALGRIND_MINOR__) \
&& (__VALGRIND_MAJOR__ > 3 \
|| (__VALGRIND_MAJOR__ == 3 && __VALGRIND_MINOR__ >= 6))
*/
#define __VALGRIND_MAJOR__ 3
#define __VALGRIND_MINOR__ 18
#include
/* Nb: this file might be included in a file compiled with -ansi. So
we can't use C++ style "//" comments nor the "asm" keyword (instead
use "__asm__"). */
/* Derive some tags indicating what the target platform is. Note
that in this file we're using the compiler's CPP symbols for
identifying architectures, which are different to the ones we use
within the rest of Valgrind. Note, __powerpc__ is active for both
32 and 64-bit PPC, whereas __powerpc64__ is only active for the
latter (on Linux, that is).
Misc note: how to find out what's predefined in gcc by default:
gcc -Wp,-dM somefile.c
*/
#undef PLAT_x86_darwin
#undef PLAT_amd64_darwin
#undef PLAT_x86_freebsd
#undef PLAT_amd64_freebsd
#undef PLAT_x86_win32
#undef PLAT_amd64_win64
#undef PLAT_x86_linux
#undef PLAT_amd64_linux
#undef PLAT_ppc32_linux
#undef PLAT_ppc64be_linux
#undef PLAT_ppc64le_linux
#undef PLAT_arm_linux
#undef PLAT_arm64_linux
#undef PLAT_s390x_linux
#undef PLAT_mips32_linux
#undef PLAT_mips64_linux
#undef PLAT_nanomips_linux
#undef PLAT_x86_solaris
#undef PLAT_amd64_solaris
#if defined(__APPLE__) && defined(__i386__)
# define PLAT_x86_darwin 1
#elif defined(__APPLE__) && defined(__x86_64__)
# define PLAT_amd64_darwin 1
#elif defined(__FreeBSD__) && defined(__i386__)
# define PLAT_x86_freebsd 1
#elif defined(__FreeBSD__) && defined(__amd64__)
# define PLAT_amd64_freebsd 1
#elif (defined(__MINGW32__) && defined(__i386__)) \
|| defined(__CYGWIN32__) \
|| (defined(_WIN32) && defined(_M_IX86))
# define PLAT_x86_win32 1
#elif (defined(__MINGW32__) && defined(__x86_64__)) \
|| (defined(_WIN32) && defined(_M_X64))
/* __MINGW32__ and _WIN32 are defined in 64 bit mode as well. */
# define PLAT_amd64_win64 1
#elif defined(__linux__) && defined(__i386__)
# define PLAT_x86_linux 1
#elif defined(__linux__) && defined(__x86_64__) && !defined(__ILP32__)
# define PLAT_amd64_linux 1
#elif defined(__linux__) && defined(__powerpc__) && !defined(__powerpc64__)
# define PLAT_ppc32_linux 1
#elif defined(__linux__) && defined(__powerpc__) && defined(__powerpc64__) && _CALL_ELF != 2
/* Big Endian uses ELF version 1 */
# define PLAT_ppc64be_linux 1
#elif defined(__linux__) && defined(__powerpc__) && defined(__powerpc64__) && _CALL_ELF == 2
/* Little Endian uses ELF version 2 */
# define PLAT_ppc64le_linux 1
#elif defined(__linux__) && defined(__arm__) && !defined(__aarch64__)
# define PLAT_arm_linux 1
#elif defined(__linux__) && defined(__aarch64__) && !defined(__arm__)
# define PLAT_arm64_linux 1
#elif defined(__linux__) && defined(__s390__) && defined(__s390x__)
# define PLAT_s390x_linux 1
#elif defined(__linux__) && defined(__mips__) && (__mips==64)
# define PLAT_mips64_linux 1
#elif defined(__linux__) && defined(__mips__) && (__mips==32)
# define PLAT_mips32_linux 1
#elif defined(__linux__) && defined(__nanomips__)
# define PLAT_nanomips_linux 1
#elif defined(__sun) && defined(__i386__)
# define PLAT_x86_solaris 1
#elif defined(__sun) && defined(__x86_64__)
# define PLAT_amd64_solaris 1
#else
/* If we're not compiling for our target platform, don't generate
any inline asms. */
# if !defined(NVALGRIND)
# define NVALGRIND 1
# endif
#endif
/* ------------------------------------------------------------------ */
/* ARCHITECTURE SPECIFICS for SPECIAL INSTRUCTIONS. There is nothing */
/* in here of use to end-users -- skip to the next section. */
/* ------------------------------------------------------------------ */
/*
* VALGRIND_DO_CLIENT_REQUEST(): a statement that invokes a Valgrind client
* request. Accepts both pointers and integers as arguments.
*
* VALGRIND_DO_CLIENT_REQUEST_STMT(): a statement that invokes a Valgrind
* client request that does not return a value.
* VALGRIND_DO_CLIENT_REQUEST_EXPR(): a C expression that invokes a Valgrind
* client request and whose value equals the client request result. Accepts
* both pointers and integers as arguments. Note that such calls are not
* necessarily pure functions -- they may have side effects.
*/
#define VALGRIND_DO_CLIENT_REQUEST(_zzq_rlval, _zzq_default, \
_zzq_request, _zzq_arg1, _zzq_arg2, \
_zzq_arg3, _zzq_arg4, _zzq_arg5) \
do { (_zzq_rlval) = VALGRIND_DO_CLIENT_REQUEST_EXPR((_zzq_default), \
(_zzq_request), (_zzq_arg1), (_zzq_arg2), \
(_zzq_arg3), (_zzq_arg4), (_zzq_arg5)); } while (0)
#define VALGRIND_DO_CLIENT_REQUEST_STMT(_zzq_request, _zzq_arg1, \
_zzq_arg2, _zzq_arg3, _zzq_arg4, _zzq_arg5) \
do { (void) VALGRIND_DO_CLIENT_REQUEST_EXPR(0, \
(_zzq_request), (_zzq_arg1), (_zzq_arg2), \
(_zzq_arg3), (_zzq_arg4), (_zzq_arg5)); } while (0)
#if defined(NVALGRIND)
/* Define NVALGRIND to completely remove the Valgrind magic sequence
from the compiled code (analogous to NDEBUG's effects on
assert()) */
#define VALGRIND_DO_CLIENT_REQUEST_EXPR( \
_zzq_default, _zzq_request, \
_zzq_arg1, _zzq_arg2, _zzq_arg3, _zzq_arg4, _zzq_arg5) \
(_zzq_default)
#else /* ! NVALGRIND */
/* The following defines the magic code sequences which the JITter
spots and handles magically. Don't look too closely at them as
they will rot your brain.
The assembly code sequences for all architectures is in this one
file. This is because this file must be stand-alone, and we don't
want to have multiple files.
For VALGRIND_DO_CLIENT_REQUEST, we must ensure that the default
value gets put in the return slot, so that everything works when
this is executed not under Valgrind. Args are passed in a memory
block, and so there's no intrinsic limit to the number that could
be passed, but it's currently five.
The macro args are:
_zzq_rlval result lvalue
_zzq_default default value (result returned when running on real CPU)
_zzq_request request code
_zzq_arg1..5 request params
The other two macros are used to support function wrapping, and are
a lot simpler. VALGRIND_GET_NR_CONTEXT returns the value of the
guest's NRADDR pseudo-register and whatever other information is
needed to safely run the call original from the wrapper: on
ppc64-linux, the R2 value at the divert point is also needed. This
information is abstracted into a user-visible type, OrigFn.
VALGRIND_CALL_NOREDIR_* behaves the same as the following on the
guest, but guarantees that the branch instruction will not be
redirected: x86: call *%eax, amd64: call *%rax, ppc32/ppc64:
branch-and-link-to-r11. VALGRIND_CALL_NOREDIR is just text, not a
complete inline asm, since it needs to be combined with more magic
inline asm stuff to be useful.
*/
/* ----------------- x86-{linux,darwin,solaris} ---------------- */
#if defined(PLAT_x86_linux) || defined(PLAT_x86_darwin) \
|| (defined(PLAT_x86_win32) && defined(__GNUC__)) \
|| defined(PLAT_x86_solaris) || defined(PLAT_x86_freebsd)
typedef
struct {
unsigned int nraddr; /* where's the code? */
}
OrigFn;
#define __SPECIAL_INSTRUCTION_PREAMBLE \
"roll $3, %%edi ; roll $13, %%edi\n\t" \
"roll $29, %%edi ; roll $19, %%edi\n\t"
#define VALGRIND_DO_CLIENT_REQUEST_EXPR( \
_zzq_default, _zzq_request, \
_zzq_arg1, _zzq_arg2, _zzq_arg3, _zzq_arg4, _zzq_arg5) \
__extension__ \
({volatile unsigned int _zzq_args[6]; \
volatile unsigned int _zzq_result; \
_zzq_args[0] = (unsigned int)(_zzq_request); \
_zzq_args[1] = (unsigned int)(_zzq_arg1); \
_zzq_args[2] = (unsigned int)(_zzq_arg2); \
_zzq_args[3] = (unsigned int)(_zzq_arg3); \
_zzq_args[4] = (unsigned int)(_zzq_arg4); \
_zzq_args[5] = (unsigned int)(_zzq_arg5); \
__asm__ volatile(__SPECIAL_INSTRUCTION_PREAMBLE \
/* %EDX = client_request ( %EAX ) */ \
"xchgl %%ebx,%%ebx" \
: "=d" (_zzq_result) \
: "a" (&_zzq_args[0]), "0" (_zzq_default) \
: "cc", "memory" \
); \
_zzq_result; \
})
#define VALGRIND_GET_NR_CONTEXT(_zzq_rlval) \
{ volatile OrigFn* _zzq_orig = &(_zzq_rlval); \
volatile unsigned int __addr; \
__asm__ volatile(__SPECIAL_INSTRUCTION_PREAMBLE \
/* %EAX = guest_NRADDR */ \
"xchgl %%ecx,%%ecx" \
: "=a" (__addr) \
: \
: "cc", "memory" \
); \
_zzq_orig->nraddr = __addr; \
}
#define VALGRIND_CALL_NOREDIR_EAX \
__SPECIAL_INSTRUCTION_PREAMBLE \
/* call-noredir *%EAX */ \
"xchgl %%edx,%%edx\n\t"
#define VALGRIND_VEX_INJECT_IR() \
do { \
__asm__ volatile(__SPECIAL_INSTRUCTION_PREAMBLE \
"xchgl %%edi,%%edi\n\t" \
: : : "cc", "memory" \
); \
} while (0)
#endif /* PLAT_x86_linux || PLAT_x86_darwin || (PLAT_x86_win32 && __GNUC__)
|| PLAT_x86_solaris */
/* ------------------------- x86-Win32 ------------------------- */
#if defined(PLAT_x86_win32) && !defined(__GNUC__)
typedef
struct {
unsigned int nraddr; /* where's the code? */
}
OrigFn;
#if defined(_MSC_VER)
#define __SPECIAL_INSTRUCTION_PREAMBLE \
__asm rol edi, 3 __asm rol edi, 13 \
__asm rol edi, 29 __asm rol edi, 19
#define VALGRIND_DO_CLIENT_REQUEST_EXPR( \
_zzq_default, _zzq_request, \
_zzq_arg1, _zzq_arg2, _zzq_arg3, _zzq_arg4, _zzq_arg5) \
valgrind_do_client_request_expr((uintptr_t)(_zzq_default), \
(uintptr_t)(_zzq_request), (uintptr_t)(_zzq_arg1), \
(uintptr_t)(_zzq_arg2), (uintptr_t)(_zzq_arg3), \
(uintptr_t)(_zzq_arg4), (uintptr_t)(_zzq_arg5))
static __inline uintptr_t
valgrind_do_client_request_expr(uintptr_t _zzq_default, uintptr_t _zzq_request,
uintptr_t _zzq_arg1, uintptr_t _zzq_arg2,
uintptr_t _zzq_arg3, uintptr_t _zzq_arg4,
uintptr_t _zzq_arg5)
{
volatile uintptr_t _zzq_args[6];
volatile unsigned int _zzq_result;
_zzq_args[0] = (uintptr_t)(_zzq_request);
_zzq_args[1] = (uintptr_t)(_zzq_arg1);
_zzq_args[2] = (uintptr_t)(_zzq_arg2);
_zzq_args[3] = (uintptr_t)(_zzq_arg3);
_zzq_args[4] = (uintptr_t)(_zzq_arg4);
_zzq_args[5] = (uintptr_t)(_zzq_arg5);
__asm { __asm lea eax, _zzq_args __asm mov edx, _zzq_default
__SPECIAL_INSTRUCTION_PREAMBLE
/* %EDX = client_request ( %EAX ) */
__asm xchg ebx,ebx
__asm mov _zzq_result, edx
}
return _zzq_result;
}
#define VALGRIND_GET_NR_CONTEXT(_zzq_rlval) \
{ volatile OrigFn* _zzq_orig = &(_zzq_rlval); \
volatile unsigned int __addr; \
__asm { __SPECIAL_INSTRUCTION_PREAMBLE \
/* %EAX = guest_NRADDR */ \
__asm xchg ecx,ecx \
__asm mov __addr, eax \
} \
_zzq_orig->nraddr = __addr; \
}
#define VALGRIND_CALL_NOREDIR_EAX ERROR
#define VALGRIND_VEX_INJECT_IR() \
do { \
__asm { __SPECIAL_INSTRUCTION_PREAMBLE \
__asm xchg edi,edi \
} \
} while (0)
#else
#error Unsupported compiler.
#endif
#endif /* PLAT_x86_win32 */
/* ----------------- amd64-{linux,darwin,solaris} --------------- */
#if defined(PLAT_amd64_linux) || defined(PLAT_amd64_darwin) \
|| defined(PLAT_amd64_solaris) \
|| defined(PLAT_amd64_freebsd) \
|| (defined(PLAT_amd64_win64) && defined(__GNUC__))
typedef
struct {
unsigned long int nraddr; /* where's the code? */
}
OrigFn;
#define __SPECIAL_INSTRUCTION_PREAMBLE \
"rolq $3, %%rdi ; rolq $13, %%rdi\n\t" \
"rolq $61, %%rdi ; rolq $51, %%rdi\n\t"
#define VALGRIND_DO_CLIENT_REQUEST_EXPR( \
_zzq_default, _zzq_request, \
_zzq_arg1, _zzq_arg2, _zzq_arg3, _zzq_arg4, _zzq_arg5) \
__extension__ \
({ volatile unsigned long int _zzq_args[6]; \
volatile unsigned long int _zzq_result; \
_zzq_args[0] = (unsigned long int)(_zzq_request); \
_zzq_args[1] = (unsigned long int)(_zzq_arg1); \
_zzq_args[2] = (unsigned long int)(_zzq_arg2); \
_zzq_args[3] = (unsigned long int)(_zzq_arg3); \
_zzq_args[4] = (unsigned long int)(_zzq_arg4); \
_zzq_args[5] = (unsigned long int)(_zzq_arg5); \
__asm__ volatile(__SPECIAL_INSTRUCTION_PREAMBLE \
/* %RDX = client_request ( %RAX ) */ \
"xchgq %%rbx,%%rbx" \
: "=d" (_zzq_result) \
: "a" (&_zzq_args[0]), "0" (_zzq_default) \
: "cc", "memory" \
); \
_zzq_result; \
})
#define VALGRIND_GET_NR_CONTEXT(_zzq_rlval) \
{ volatile OrigFn* _zzq_orig = &(_zzq_rlval); \
volatile unsigned long int __addr; \
__asm__ volatile(__SPECIAL_INSTRUCTION_PREAMBLE \
/* %RAX = guest_NRADDR */ \
"xchgq %%rcx,%%rcx" \
: "=a" (__addr) \
: \
: "cc", "memory" \
); \
_zzq_orig->nraddr = __addr; \
}
#define VALGRIND_CALL_NOREDIR_RAX \
__SPECIAL_INSTRUCTION_PREAMBLE \
/* call-noredir *%RAX */ \
"xchgq %%rdx,%%rdx\n\t"
#define VALGRIND_VEX_INJECT_IR() \
do { \
__asm__ volatile(__SPECIAL_INSTRUCTION_PREAMBLE \
"xchgq %%rdi,%%rdi\n\t" \
: : : "cc", "memory" \
); \
} while (0)
#endif /* PLAT_amd64_linux || PLAT_amd64_darwin || PLAT_amd64_solaris */
/* ------------------------- amd64-Win64 ------------------------- */
#if defined(PLAT_amd64_win64) && !defined(__GNUC__)
#error Unsupported compiler.
#endif /* PLAT_amd64_win64 */
/* ------------------------ ppc32-linux ------------------------ */
#if defined(PLAT_ppc32_linux)
typedef
struct {
unsigned int nraddr; /* where's the code? */
}
OrigFn;
#define __SPECIAL_INSTRUCTION_PREAMBLE \
"rlwinm 0,0,3,0,31 ; rlwinm 0,0,13,0,31\n\t" \
"rlwinm 0,0,29,0,31 ; rlwinm 0,0,19,0,31\n\t"
#define VALGRIND_DO_CLIENT_REQUEST_EXPR( \
_zzq_default, _zzq_request, \
_zzq_arg1, _zzq_arg2, _zzq_arg3, _zzq_arg4, _zzq_arg5) \
\
__extension__ \
({ unsigned int _zzq_args[6]; \
unsigned int _zzq_result; \
unsigned int* _zzq_ptr; \
_zzq_args[0] = (unsigned int)(_zzq_request); \
_zzq_args[1] = (unsigned int)(_zzq_arg1); \
_zzq_args[2] = (unsigned int)(_zzq_arg2); \
_zzq_args[3] = (unsigned int)(_zzq_arg3); \
_zzq_args[4] = (unsigned int)(_zzq_arg4); \
_zzq_args[5] = (unsigned int)(_zzq_arg5); \
_zzq_ptr = _zzq_args; \
__asm__ volatile("mr 3,%1\n\t" /*default*/ \
"mr 4,%2\n\t" /*ptr*/ \
__SPECIAL_INSTRUCTION_PREAMBLE \
/* %R3 = client_request ( %R4 ) */ \
"or 1,1,1\n\t" \
"mr %0,3" /*result*/ \
: "=b" (_zzq_result) \
: "b" (_zzq_default), "b" (_zzq_ptr) \
: "cc", "memory", "r3", "r4"); \
_zzq_result; \
})
#define VALGRIND_GET_NR_CONTEXT(_zzq_rlval) \
{ volatile OrigFn* _zzq_orig = &(_zzq_rlval); \
unsigned int __addr; \
__asm__ volatile(__SPECIAL_INSTRUCTION_PREAMBLE \
/* %R3 = guest_NRADDR */ \
"or 2,2,2\n\t" \
"mr %0,3" \
: "=b" (__addr) \
: \
: "cc", "memory", "r3" \
); \
_zzq_orig->nraddr = __addr; \
}
#define VALGRIND_BRANCH_AND_LINK_TO_NOREDIR_R11 \
__SPECIAL_INSTRUCTION_PREAMBLE \
/* branch-and-link-to-noredir *%R11 */ \
"or 3,3,3\n\t"
#define VALGRIND_VEX_INJECT_IR() \
do { \
__asm__ volatile(__SPECIAL_INSTRUCTION_PREAMBLE \
"or 5,5,5\n\t" \
); \
} while (0)
#endif /* PLAT_ppc32_linux */
/* ------------------------ ppc64-linux ------------------------ */
#if defined(PLAT_ppc64be_linux)
typedef
struct {
unsigned long int nraddr; /* where's the code? */
unsigned long int r2; /* what tocptr do we need? */
}
OrigFn;
#define __SPECIAL_INSTRUCTION_PREAMBLE \
"rotldi 0,0,3 ; rotldi 0,0,13\n\t" \
"rotldi 0,0,61 ; rotldi 0,0,51\n\t"
#define VALGRIND_DO_CLIENT_REQUEST_EXPR( \
_zzq_default, _zzq_request, \
_zzq_arg1, _zzq_arg2, _zzq_arg3, _zzq_arg4, _zzq_arg5) \
\
__extension__ \
({ unsigned long int _zzq_args[6]; \
unsigned long int _zzq_result; \
unsigned long int* _zzq_ptr; \
_zzq_args[0] = (unsigned long int)(_zzq_request); \
_zzq_args[1] = (unsigned long int)(_zzq_arg1); \
_zzq_args[2] = (unsigned long int)(_zzq_arg2); \
_zzq_args[3] = (unsigned long int)(_zzq_arg3); \
_zzq_args[4] = (unsigned long int)(_zzq_arg4); \
_zzq_args[5] = (unsigned long int)(_zzq_arg5); \
_zzq_ptr = _zzq_args; \
__asm__ volatile("mr 3,%1\n\t" /*default*/ \
"mr 4,%2\n\t" /*ptr*/ \
__SPECIAL_INSTRUCTION_PREAMBLE \
/* %R3 = client_request ( %R4 ) */ \
"or 1,1,1\n\t" \
"mr %0,3" /*result*/ \
: "=b" (_zzq_result) \
: "b" (_zzq_default), "b" (_zzq_ptr) \
: "cc", "memory", "r3", "r4"); \
_zzq_result; \
})
#define VALGRIND_GET_NR_CONTEXT(_zzq_rlval) \
{ volatile OrigFn* _zzq_orig = &(_zzq_rlval); \
unsigned long int __addr; \
__asm__ volatile(__SPECIAL_INSTRUCTION_PREAMBLE \
/* %R3 = guest_NRADDR */ \
"or 2,2,2\n\t" \
"mr %0,3" \
: "=b" (__addr) \
: \
: "cc", "memory", "r3" \
); \
_zzq_orig->nraddr = __addr; \
__asm__ volatile(__SPECIAL_INSTRUCTION_PREAMBLE \
/* %R3 = guest_NRADDR_GPR2 */ \
"or 4,4,4\n\t" \
"mr %0,3" \
: "=b" (__addr) \
: \
: "cc", "memory", "r3" \
); \
_zzq_orig->r2 = __addr; \
}
#define VALGRIND_BRANCH_AND_LINK_TO_NOREDIR_R11 \
__SPECIAL_INSTRUCTION_PREAMBLE \
/* branch-and-link-to-noredir *%R11 */ \
"or 3,3,3\n\t"
#define VALGRIND_VEX_INJECT_IR() \
do { \
__asm__ volatile(__SPECIAL_INSTRUCTION_PREAMBLE \
"or 5,5,5\n\t" \
); \
} while (0)
#endif /* PLAT_ppc64be_linux */
#if defined(PLAT_ppc64le_linux)
typedef
struct {
unsigned long int nraddr; /* where's the code? */
unsigned long int r2; /* what tocptr do we need? */
}
OrigFn;
#define __SPECIAL_INSTRUCTION_PREAMBLE \
"rotldi 0,0,3 ; rotldi 0,0,13\n\t" \
"rotldi 0,0,61 ; rotldi 0,0,51\n\t"
#define VALGRIND_DO_CLIENT_REQUEST_EXPR( \
_zzq_default, _zzq_request, \
_zzq_arg1, _zzq_arg2, _zzq_arg3, _zzq_arg4, _zzq_arg5) \
\
__extension__ \
({ unsigned long int _zzq_args[6]; \
unsigned long int _zzq_result; \
unsigned long int* _zzq_ptr; \
_zzq_args[0] = (unsigned long int)(_zzq_request); \
_zzq_args[1] = (unsigned long int)(_zzq_arg1); \
_zzq_args[2] = (unsigned long int)(_zzq_arg2); \
_zzq_args[3] = (unsigned long int)(_zzq_arg3); \
_zzq_args[4] = (unsigned long int)(_zzq_arg4); \
_zzq_args[5] = (unsigned long int)(_zzq_arg5); \
_zzq_ptr = _zzq_args; \
__asm__ volatile("mr 3,%1\n\t" /*default*/ \
"mr 4,%2\n\t" /*ptr*/ \
__SPECIAL_INSTRUCTION_PREAMBLE \
/* %R3 = client_request ( %R4 ) */ \
"or 1,1,1\n\t" \
"mr %0,3" /*result*/ \
: "=b" (_zzq_result) \
: "b" (_zzq_default), "b" (_zzq_ptr) \
: "cc", "memory", "r3", "r4"); \
_zzq_result; \
})
#define VALGRIND_GET_NR_CONTEXT(_zzq_rlval) \
{ volatile OrigFn* _zzq_orig = &(_zzq_rlval); \
unsigned long int __addr; \
__asm__ volatile(__SPECIAL_INSTRUCTION_PREAMBLE \
/* %R3 = guest_NRADDR */ \
"or 2,2,2\n\t" \
"mr %0,3" \
: "=b" (__addr) \
: \
: "cc", "memory", "r3" \
); \
_zzq_orig->nraddr = __addr; \
__asm__ volatile(__SPECIAL_INSTRUCTION_PREAMBLE \
/* %R3 = guest_NRADDR_GPR2 */ \
"or 4,4,4\n\t" \
"mr %0,3" \
: "=b" (__addr) \
: \
: "cc", "memory", "r3" \
); \
_zzq_orig->r2 = __addr; \
}
#define VALGRIND_BRANCH_AND_LINK_TO_NOREDIR_R12 \
__SPECIAL_INSTRUCTION_PREAMBLE \
/* branch-and-link-to-noredir *%R12 */ \
"or 3,3,3\n\t"
#define VALGRIND_VEX_INJECT_IR() \
do { \
__asm__ volatile(__SPECIAL_INSTRUCTION_PREAMBLE \
"or 5,5,5\n\t" \
); \
} while (0)
#endif /* PLAT_ppc64le_linux */
/* ------------------------- arm-linux ------------------------- */
#if defined(PLAT_arm_linux)
typedef
struct {
unsigned int nraddr; /* where's the code? */
}
OrigFn;
#define __SPECIAL_INSTRUCTION_PREAMBLE \
"mov r12, r12, ror #3 ; mov r12, r12, ror #13 \n\t" \
"mov r12, r12, ror #29 ; mov r12, r12, ror #19 \n\t"
#define VALGRIND_DO_CLIENT_REQUEST_EXPR( \
_zzq_default, _zzq_request, \
_zzq_arg1, _zzq_arg2, _zzq_arg3, _zzq_arg4, _zzq_arg5) \
\
__extension__ \
({volatile unsigned int _zzq_args[6]; \
volatile unsigned int _zzq_result; \
_zzq_args[0] = (unsigned int)(_zzq_request); \
_zzq_args[1] = (unsigned int)(_zzq_arg1); \
_zzq_args[2] = (unsigned int)(_zzq_arg2); \
_zzq_args[3] = (unsigned int)(_zzq_arg3); \
_zzq_args[4] = (unsigned int)(_zzq_arg4); \
_zzq_args[5] = (unsigned int)(_zzq_arg5); \
__asm__ volatile("mov r3, %1\n\t" /*default*/ \
"mov r4, %2\n\t" /*ptr*/ \
__SPECIAL_INSTRUCTION_PREAMBLE \
/* R3 = client_request ( R4 ) */ \
"orr r10, r10, r10\n\t" \
"mov %0, r3" /*result*/ \
: "=r" (_zzq_result) \
: "r" (_zzq_default), "r" (&_zzq_args[0]) \
: "cc","memory", "r3", "r4"); \
_zzq_result; \
})
#define VALGRIND_GET_NR_CONTEXT(_zzq_rlval) \
{ volatile OrigFn* _zzq_orig = &(_zzq_rlval); \
unsigned int __addr; \
__asm__ volatile(__SPECIAL_INSTRUCTION_PREAMBLE \
/* R3 = guest_NRADDR */ \
"orr r11, r11, r11\n\t" \
"mov %0, r3" \
: "=r" (__addr) \
: \
: "cc", "memory", "r3" \
); \
_zzq_orig->nraddr = __addr; \
}
#define VALGRIND_BRANCH_AND_LINK_TO_NOREDIR_R4 \
__SPECIAL_INSTRUCTION_PREAMBLE \
/* branch-and-link-to-noredir *%R4 */ \
"orr r12, r12, r12\n\t"
#define VALGRIND_VEX_INJECT_IR() \
do { \
__asm__ volatile(__SPECIAL_INSTRUCTION_PREAMBLE \
"orr r9, r9, r9\n\t" \
: : : "cc", "memory" \
); \
} while (0)
#endif /* PLAT_arm_linux */
/* ------------------------ arm64-linux ------------------------- */
#if defined(PLAT_arm64_linux)
typedef
struct {
unsigned long int nraddr; /* where's the code? */
}
OrigFn;
#define __SPECIAL_INSTRUCTION_PREAMBLE \
"ror x12, x12, #3 ; ror x12, x12, #13 \n\t" \
"ror x12, x12, #51 ; ror x12, x12, #61 \n\t"
#define VALGRIND_DO_CLIENT_REQUEST_EXPR( \
_zzq_default, _zzq_request, \
_zzq_arg1, _zzq_arg2, _zzq_arg3, _zzq_arg4, _zzq_arg5) \
\
__extension__ \
({volatile unsigned long int _zzq_args[6]; \
volatile unsigned long int _zzq_result; \
_zzq_args[0] = (unsigned long int)(_zzq_request); \
_zzq_args[1] = (unsigned long int)(_zzq_arg1); \
_zzq_args[2] = (unsigned long int)(_zzq_arg2); \
_zzq_args[3] = (unsigned long int)(_zzq_arg3); \
_zzq_args[4] = (unsigned long int)(_zzq_arg4); \
_zzq_args[5] = (unsigned long int)(_zzq_arg5); \
__asm__ volatile("mov x3, %1\n\t" /*default*/ \
"mov x4, %2\n\t" /*ptr*/ \
__SPECIAL_INSTRUCTION_PREAMBLE \
/* X3 = client_request ( X4 ) */ \
"orr x10, x10, x10\n\t" \
"mov %0, x3" /*result*/ \
: "=r" (_zzq_result) \
: "r" ((unsigned long int)(_zzq_default)), \
"r" (&_zzq_args[0]) \
: "cc","memory", "x3", "x4"); \
_zzq_result; \
})
#define VALGRIND_GET_NR_CONTEXT(_zzq_rlval) \
{ volatile OrigFn* _zzq_orig = &(_zzq_rlval); \
unsigned long int __addr; \
__asm__ volatile(__SPECIAL_INSTRUCTION_PREAMBLE \
/* X3 = guest_NRADDR */ \
"orr x11, x11, x11\n\t" \
"mov %0, x3" \
: "=r" (__addr) \
: \
: "cc", "memory", "x3" \
); \
_zzq_orig->nraddr = __addr; \
}
#define VALGRIND_BRANCH_AND_LINK_TO_NOREDIR_X8 \
__SPECIAL_INSTRUCTION_PREAMBLE \
/* branch-and-link-to-noredir X8 */ \
"orr x12, x12, x12\n\t"
#define VALGRIND_VEX_INJECT_IR() \
do { \
__asm__ volatile(__SPECIAL_INSTRUCTION_PREAMBLE \
"orr x9, x9, x9\n\t" \
: : : "cc", "memory" \
); \
} while (0)
#endif /* PLAT_arm64_linux */
/* ------------------------ s390x-linux ------------------------ */
#if defined(PLAT_s390x_linux)
typedef
struct {
unsigned long int nraddr; /* where's the code? */
}
OrigFn;
/* __SPECIAL_INSTRUCTION_PREAMBLE will be used to identify Valgrind specific
* code. This detection is implemented in platform specific toIR.c
* (e.g. VEX/priv/guest_s390_decoder.c).
*/
#define __SPECIAL_INSTRUCTION_PREAMBLE \
"lr 15,15\n\t" \
"lr 1,1\n\t" \
"lr 2,2\n\t" \
"lr 3,3\n\t"
#define __CLIENT_REQUEST_CODE "lr 2,2\n\t"
#define __GET_NR_CONTEXT_CODE "lr 3,3\n\t"
#define __CALL_NO_REDIR_CODE "lr 4,4\n\t"
#define __VEX_INJECT_IR_CODE "lr 5,5\n\t"
#define VALGRIND_DO_CLIENT_REQUEST_EXPR( \
_zzq_default, _zzq_request, \
_zzq_arg1, _zzq_arg2, _zzq_arg3, _zzq_arg4, _zzq_arg5) \
__extension__ \
({volatile unsigned long int _zzq_args[6]; \
volatile unsigned long int _zzq_result; \
_zzq_args[0] = (unsigned long int)(_zzq_request); \
_zzq_args[1] = (unsigned long int)(_zzq_arg1); \
_zzq_args[2] = (unsigned long int)(_zzq_arg2); \
_zzq_args[3] = (unsigned long int)(_zzq_arg3); \
_zzq_args[4] = (unsigned long int)(_zzq_arg4); \
_zzq_args[5] = (unsigned long int)(_zzq_arg5); \
__asm__ volatile(/* r2 = args */ \
"lgr 2,%1\n\t" \
/* r3 = default */ \
"lgr 3,%2\n\t" \
__SPECIAL_INSTRUCTION_PREAMBLE \
__CLIENT_REQUEST_CODE \
/* results = r3 */ \
"lgr %0, 3\n\t" \
: "=d" (_zzq_result) \
: "a" (&_zzq_args[0]), \
"0" ((unsigned long int)_zzq_default) \
: "cc", "2", "3", "memory" \
); \
_zzq_result; \
})
#define VALGRIND_GET_NR_CONTEXT(_zzq_rlval) \
{ volatile OrigFn* _zzq_orig = &(_zzq_rlval); \
volatile unsigned long int __addr; \
__asm__ volatile(__SPECIAL_INSTRUCTION_PREAMBLE \
__GET_NR_CONTEXT_CODE \
"lgr %0, 3\n\t" \
: "=a" (__addr) \
: \
: "cc", "3", "memory" \
); \
_zzq_orig->nraddr = __addr; \
}
#define VALGRIND_CALL_NOREDIR_R1 \
__SPECIAL_INSTRUCTION_PREAMBLE \
__CALL_NO_REDIR_CODE
#define VALGRIND_VEX_INJECT_IR() \
do { \
__asm__ volatile(__SPECIAL_INSTRUCTION_PREAMBLE \
__VEX_INJECT_IR_CODE); \
} while (0)
#endif /* PLAT_s390x_linux */
/* ------------------------- mips32-linux ---------------- */
#if defined(PLAT_mips32_linux)
typedef
struct {
unsigned int nraddr; /* where's the code? */
}
OrigFn;
/* .word 0x342
* .word 0x742
* .word 0xC2
* .word 0x4C2*/
#define __SPECIAL_INSTRUCTION_PREAMBLE \
"srl $0, $0, 13\n\t" \
"srl $0, $0, 29\n\t" \
"srl $0, $0, 3\n\t" \
"srl $0, $0, 19\n\t"
#define VALGRIND_DO_CLIENT_REQUEST_EXPR( \
_zzq_default, _zzq_request, \
_zzq_arg1, _zzq_arg2, _zzq_arg3, _zzq_arg4, _zzq_arg5) \
__extension__ \
({ volatile unsigned int _zzq_args[6]; \
volatile unsigned int _zzq_result; \
_zzq_args[0] = (unsigned int)(_zzq_request); \
_zzq_args[1] = (unsigned int)(_zzq_arg1); \
_zzq_args[2] = (unsigned int)(_zzq_arg2); \
_zzq_args[3] = (unsigned int)(_zzq_arg3); \
_zzq_args[4] = (unsigned int)(_zzq_arg4); \
_zzq_args[5] = (unsigned int)(_zzq_arg5); \
__asm__ volatile("move $11, %1\n\t" /*default*/ \
"move $12, %2\n\t" /*ptr*/ \
__SPECIAL_INSTRUCTION_PREAMBLE \
/* T3 = client_request ( T4 ) */ \
"or $13, $13, $13\n\t" \
"move %0, $11\n\t" /*result*/ \
: "=r" (_zzq_result) \
: "r" (_zzq_default), "r" (&_zzq_args[0]) \
: "$11", "$12", "memory"); \
_zzq_result; \
})
#define VALGRIND_GET_NR_CONTEXT(_zzq_rlval) \
{ volatile OrigFn* _zzq_orig = &(_zzq_rlval); \
volatile unsigned int __addr; \
__asm__ volatile(__SPECIAL_INSTRUCTION_PREAMBLE \
/* %t9 = guest_NRADDR */ \
"or $14, $14, $14\n\t" \
"move %0, $11" /*result*/ \
: "=r" (__addr) \
: \
: "$11" \
); \
_zzq_orig->nraddr = __addr; \
}
#define VALGRIND_CALL_NOREDIR_T9 \
__SPECIAL_INSTRUCTION_PREAMBLE \
/* call-noredir *%t9 */ \
"or $15, $15, $15\n\t"
#define VALGRIND_VEX_INJECT_IR() \
do { \
__asm__ volatile(__SPECIAL_INSTRUCTION_PREAMBLE \
"or $11, $11, $11\n\t" \
); \
} while (0)
#endif /* PLAT_mips32_linux */
/* ------------------------- mips64-linux ---------------- */
#if defined(PLAT_mips64_linux)
typedef
struct {
unsigned long nraddr; /* where's the code? */
}
OrigFn;
/* dsll $0,$0, 3
* dsll $0,$0, 13
* dsll $0,$0, 29
* dsll $0,$0, 19*/
#define __SPECIAL_INSTRUCTION_PREAMBLE \
"dsll $0,$0, 3 ; dsll $0,$0,13\n\t" \
"dsll $0,$0,29 ; dsll $0,$0,19\n\t"
#define VALGRIND_DO_CLIENT_REQUEST_EXPR( \
_zzq_default, _zzq_request, \
_zzq_arg1, _zzq_arg2, _zzq_arg3, _zzq_arg4, _zzq_arg5) \
__extension__ \
({ volatile unsigned long int _zzq_args[6]; \
volatile unsigned long int _zzq_result; \
_zzq_args[0] = (unsigned long int)(_zzq_request); \
_zzq_args[1] = (unsigned long int)(_zzq_arg1); \
_zzq_args[2] = (unsigned long int)(_zzq_arg2); \
_zzq_args[3] = (unsigned long int)(_zzq_arg3); \
_zzq_args[4] = (unsigned long int)(_zzq_arg4); \
_zzq_args[5] = (unsigned long int)(_zzq_arg5); \
__asm__ volatile("move $11, %1\n\t" /*default*/ \
"move $12, %2\n\t" /*ptr*/ \
__SPECIAL_INSTRUCTION_PREAMBLE \
/* $11 = client_request ( $12 ) */ \
"or $13, $13, $13\n\t" \
"move %0, $11\n\t" /*result*/ \
: "=r" (_zzq_result) \
: "r" (_zzq_default), "r" (&_zzq_args[0]) \
: "$11", "$12", "memory"); \
_zzq_result; \
})
#define VALGRIND_GET_NR_CONTEXT(_zzq_rlval) \
{ volatile OrigFn* _zzq_orig = &(_zzq_rlval); \
volatile unsigned long int __addr; \
__asm__ volatile(__SPECIAL_INSTRUCTION_PREAMBLE \
/* $11 = guest_NRADDR */ \
"or $14, $14, $14\n\t" \
"move %0, $11" /*result*/ \
: "=r" (__addr) \
: \
: "$11"); \
_zzq_orig->nraddr = __addr; \
}
#define VALGRIND_CALL_NOREDIR_T9 \
__SPECIAL_INSTRUCTION_PREAMBLE \
/* call-noredir $25 */ \
"or $15, $15, $15\n\t"
#define VALGRIND_VEX_INJECT_IR() \
do { \
__asm__ volatile(__SPECIAL_INSTRUCTION_PREAMBLE \
"or $11, $11, $11\n\t" \
); \
} while (0)
#endif /* PLAT_mips64_linux */
#if defined(PLAT_nanomips_linux)
typedef
struct {
unsigned int nraddr; /* where's the code? */
}
OrigFn;
/*
8000 c04d srl zero, zero, 13
8000 c05d srl zero, zero, 29
8000 c043 srl zero, zero, 3
8000 c053 srl zero, zero, 19
*/
#define __SPECIAL_INSTRUCTION_PREAMBLE "srl[32] $zero, $zero, 13 \n\t" \
"srl[32] $zero, $zero, 29 \n\t" \
"srl[32] $zero, $zero, 3 \n\t" \
"srl[32] $zero, $zero, 19 \n\t"
#define VALGRIND_DO_CLIENT_REQUEST_EXPR( \
_zzq_default, _zzq_request, \
_zzq_arg1, _zzq_arg2, _zzq_arg3, _zzq_arg4, _zzq_arg5) \
__extension__ \
({ volatile unsigned int _zzq_args[6]; \
volatile unsigned int _zzq_result; \
_zzq_args[0] = (unsigned int)(_zzq_request); \
_zzq_args[1] = (unsigned int)(_zzq_arg1); \
_zzq_args[2] = (unsigned int)(_zzq_arg2); \
_zzq_args[3] = (unsigned int)(_zzq_arg3); \
_zzq_args[4] = (unsigned int)(_zzq_arg4); \
_zzq_args[5] = (unsigned int)(_zzq_arg5); \
__asm__ volatile("move $a7, %1\n\t" /* default */ \
"move $t0, %2\n\t" /* ptr */ \
__SPECIAL_INSTRUCTION_PREAMBLE \
/* $a7 = client_request( $t0 ) */ \
"or[32] $t0, $t0, $t0\n\t" \
"move %0, $a7\n\t" /* result */ \
: "=r" (_zzq_result) \
: "r" (_zzq_default), "r" (&_zzq_args[0]) \
: "$a7", "$t0", "memory"); \
_zzq_result; \
})
#define VALGRIND_GET_NR_CONTEXT(_zzq_rlval) \
{ volatile OrigFn* _zzq_orig = &(_zzq_rlval); \
volatile unsigned long int __addr; \
__asm__ volatile(__SPECIAL_INSTRUCTION_PREAMBLE \
/* $a7 = guest_NRADDR */ \
"or[32] $t1, $t1, $t1\n\t" \
"move %0, $a7" /*result*/ \
: "=r" (__addr) \
: \
: "$a7"); \
_zzq_orig->nraddr = __addr; \
}
#define VALGRIND_CALL_NOREDIR_T9 \
__SPECIAL_INSTRUCTION_PREAMBLE \
/* call-noredir $25 */ \
"or[32] $t2, $t2, $t2\n\t"
#define VALGRIND_VEX_INJECT_IR() \
do { \
__asm__ volatile(__SPECIAL_INSTRUCTION_PREAMBLE \
"or[32] $t3, $t3, $t3\n\t" \
); \
} while (0)
#endif
/* Insert assembly code for other platforms here... */
#endif /* NVALGRIND */
/* ------------------------------------------------------------------ */
/* PLATFORM SPECIFICS for FUNCTION WRAPPING. This is all very */
/* ugly. It's the least-worst tradeoff I can think of. */
/* ------------------------------------------------------------------ */
/* This section defines magic (a.k.a appalling-hack) macros for doing
guaranteed-no-redirection macros, so as to get from function
wrappers to the functions they are wrapping. The whole point is to
construct standard call sequences, but to do the call itself with a
special no-redirect call pseudo-instruction that the JIT
understands and handles specially. This section is long and
repetitious, and I can't see a way to make it shorter.
The naming scheme is as follows:
CALL_FN_{W,v}_{v,W,WW,WWW,WWWW,5W,6W,7W,etc}
'W' stands for "word" and 'v' for "void". Hence there are
different macros for calling arity 0, 1, 2, 3, 4, etc, functions,
and for each, the possibility of returning a word-typed result, or
no result.
*/
/* Use these to write the name of your wrapper. NOTE: duplicates
VG_WRAP_FUNCTION_Z{U,Z} in pub_tool_redir.h. NOTE also: inserts
the default behaviour equivalance class tag "0000" into the name.
See pub_tool_redir.h for details -- normally you don't need to
think about this, though. */
/* Use an extra level of macroisation so as to ensure the soname/fnname
args are fully macro-expanded before pasting them together. */
#define VG_CONCAT4(_aa,_bb,_cc,_dd) _aa##_bb##_cc##_dd
#define I_WRAP_SONAME_FNNAME_ZU(soname,fnname) \
VG_CONCAT4(_vgw00000ZU_,soname,_,fnname)
#define I_WRAP_SONAME_FNNAME_ZZ(soname,fnname) \
VG_CONCAT4(_vgw00000ZZ_,soname,_,fnname)
/* Use this macro from within a wrapper function to collect the
context (address and possibly other info) of the original function.
Once you have that you can then use it in one of the CALL_FN_
macros. The type of the argument _lval is OrigFn. */
#define VALGRIND_GET_ORIG_FN(_lval) VALGRIND_GET_NR_CONTEXT(_lval)
/* Also provide end-user facilities for function replacement, rather
than wrapping. A replacement function differs from a wrapper in
that it has no way to get hold of the original function being
called, and hence no way to call onwards to it. In a replacement
function, VALGRIND_GET_ORIG_FN always returns zero. */
#define I_REPLACE_SONAME_FNNAME_ZU(soname,fnname) \
VG_CONCAT4(_vgr00000ZU_,soname,_,fnname)
#define I_REPLACE_SONAME_FNNAME_ZZ(soname,fnname) \
VG_CONCAT4(_vgr00000ZZ_,soname,_,fnname)
/* Derivatives of the main macros below, for calling functions
returning void. */
#define CALL_FN_v_v(fnptr) \
do { volatile unsigned long _junk; \
CALL_FN_W_v(_junk,fnptr); } while (0)
#define CALL_FN_v_W(fnptr, arg1) \
do { volatile unsigned long _junk; \
CALL_FN_W_W(_junk,fnptr,arg1); } while (0)
#define CALL_FN_v_WW(fnptr, arg1,arg2) \
do { volatile unsigned long _junk; \
CALL_FN_W_WW(_junk,fnptr,arg1,arg2); } while (0)
#define CALL_FN_v_WWW(fnptr, arg1,arg2,arg3) \
do { volatile unsigned long _junk; \
CALL_FN_W_WWW(_junk,fnptr,arg1,arg2,arg3); } while (0)
#define CALL_FN_v_WWWW(fnptr, arg1,arg2,arg3,arg4) \
do { volatile unsigned long _junk; \
CALL_FN_W_WWWW(_junk,fnptr,arg1,arg2,arg3,arg4); } while (0)
#define CALL_FN_v_5W(fnptr, arg1,arg2,arg3,arg4,arg5) \
do { volatile unsigned long _junk; \
CALL_FN_W_5W(_junk,fnptr,arg1,arg2,arg3,arg4,arg5); } while (0)
#define CALL_FN_v_6W(fnptr, arg1,arg2,arg3,arg4,arg5,arg6) \
do { volatile unsigned long _junk; \
CALL_FN_W_6W(_junk,fnptr,arg1,arg2,arg3,arg4,arg5,arg6); } while (0)
#define CALL_FN_v_7W(fnptr, arg1,arg2,arg3,arg4,arg5,arg6,arg7) \
do { volatile unsigned long _junk; \
CALL_FN_W_7W(_junk,fnptr,arg1,arg2,arg3,arg4,arg5,arg6,arg7); } while (0)
/* ----------------- x86-{linux,darwin,solaris} ---------------- */
#if defined(PLAT_x86_linux) || defined(PLAT_x86_darwin) \
|| defined(PLAT_x86_solaris) || defined(PLAT_x86_freebsd)
/* These regs are trashed by the hidden call. No need to mention eax
as gcc can already see that, plus causes gcc to bomb. */
#define __CALLER_SAVED_REGS /*"eax"*/ "ecx", "edx"
/* Macros to save and align the stack before making a function
call and restore it afterwards as gcc may not keep the stack
pointer aligned if it doesn't realise calls are being made
to other functions. */
#define VALGRIND_ALIGN_STACK \
"movl %%esp,%%edi\n\t" \
"andl $0xfffffff0,%%esp\n\t"
#define VALGRIND_RESTORE_STACK \
"movl %%edi,%%esp\n\t"
/* These CALL_FN_ macros assume that on x86-linux, sizeof(unsigned
long) == 4. */
#define CALL_FN_W_v(lval, orig) \
do { \
volatile OrigFn _orig = (orig); \
volatile unsigned long _argvec[1]; \
volatile unsigned long _res; \
_argvec[0] = (unsigned long)_orig.nraddr; \
__asm__ volatile( \
VALGRIND_ALIGN_STACK \
"movl (%%eax), %%eax\n\t" /* target->%eax */ \
VALGRIND_CALL_NOREDIR_EAX \
VALGRIND_RESTORE_STACK \
: /*out*/ "=a" (_res) \
: /*in*/ "a" (&_argvec[0]) \
: /*trash*/ "cc", "memory", __CALLER_SAVED_REGS, "edi" \
); \
lval = (__typeof__(lval)) _res; \
} while (0)
#define CALL_FN_W_W(lval, orig, arg1) \
do { \
volatile OrigFn _orig = (orig); \
volatile unsigned long _argvec[2]; \
volatile unsigned long _res; \
_argvec[0] = (unsigned long)_orig.nraddr; \
_argvec[1] = (unsigned long)(arg1); \
__asm__ volatile( \
VALGRIND_ALIGN_STACK \
"subl $12, %%esp\n\t" \
"pushl 4(%%eax)\n\t" \
"movl (%%eax), %%eax\n\t" /* target->%eax */ \
VALGRIND_CALL_NOREDIR_EAX \
VALGRIND_RESTORE_STACK \
: /*out*/ "=a" (_res) \
: /*in*/ "a" (&_argvec[0]) \
: /*trash*/ "cc", "memory", __CALLER_SAVED_REGS, "edi" \
); \
lval = (__typeof__(lval)) _res; \
} while (0)
#define CALL_FN_W_WW(lval, orig, arg1,arg2) \
do { \
volatile OrigFn _orig = (orig); \
volatile unsigned long _argvec[3]; \
volatile unsigned long _res; \
_argvec[0] = (unsigned long)_orig.nraddr; \
_argvec[1] = (unsigned long)(arg1); \
_argvec[2] = (unsigned long)(arg2); \
__asm__ volatile( \
VALGRIND_ALIGN_STACK \
"subl $8, %%esp\n\t" \
"pushl 8(%%eax)\n\t" \
"pushl 4(%%eax)\n\t" \
"movl (%%eax), %%eax\n\t" /* target->%eax */ \
VALGRIND_CALL_NOREDIR_EAX \
VALGRIND_RESTORE_STACK \
: /*out*/ "=a" (_res) \
: /*in*/ "a" (&_argvec[0]) \
: /*trash*/ "cc", "memory", __CALLER_SAVED_REGS, "edi" \
); \
lval = (__typeof__(lval)) _res; \
} while (0)
#define CALL_FN_W_WWW(lval, orig, arg1,arg2,arg3) \
do { \
volatile OrigFn _orig = (orig); \
volatile unsigned long _argvec[4]; \
volatile unsigned long _res; \
_argvec[0] = (unsigned long)_orig.nraddr; \
_argvec[1] = (unsigned long)(arg1); \
_argvec[2] = (unsigned long)(arg2); \
_argvec[3] = (unsigned long)(arg3); \
__asm__ volatile( \
VALGRIND_ALIGN_STACK \
"subl $4, %%esp\n\t" \
"pushl 12(%%eax)\n\t" \
"pushl 8(%%eax)\n\t" \
"pushl 4(%%eax)\n\t" \
"movl (%%eax), %%eax\n\t" /* target->%eax */ \
VALGRIND_CALL_NOREDIR_EAX \
VALGRIND_RESTORE_STACK \
: /*out*/ "=a" (_res) \
: /*in*/ "a" (&_argvec[0]) \
: /*trash*/ "cc", "memory", __CALLER_SAVED_REGS, "edi" \
); \
lval = (__typeof__(lval)) _res; \
} while (0)
#define CALL_FN_W_WWWW(lval, orig, arg1,arg2,arg3,arg4) \
do { \
volatile OrigFn _orig = (orig); \
volatile unsigned long _argvec[5]; \
volatile unsigned long _res; \
_argvec[0] = (unsigned long)_orig.nraddr; \
_argvec[1] = (unsigned long)(arg1); \
_argvec[2] = (unsigned long)(arg2); \
_argvec[3] = (unsigned long)(arg3); \
_argvec[4] = (unsigned long)(arg4); \
__asm__ volatile( \
VALGRIND_ALIGN_STACK \
"pushl 16(%%eax)\n\t" \
"pushl 12(%%eax)\n\t" \
"pushl 8(%%eax)\n\t" \
"pushl 4(%%eax)\n\t" \
"movl (%%eax), %%eax\n\t" /* target->%eax */ \
VALGRIND_CALL_NOREDIR_EAX \
VALGRIND_RESTORE_STACK \
: /*out*/ "=a" (_res) \
: /*in*/ "a" (&_argvec[0]) \
: /*trash*/ "cc", "memory", __CALLER_SAVED_REGS, "edi" \
); \
lval = (__typeof__(lval)) _res; \
} while (0)
#define CALL_FN_W_5W(lval, orig, arg1,arg2,arg3,arg4,arg5) \
do { \
volatile OrigFn _orig = (orig); \
volatile unsigned long _argvec[6]; \
volatile unsigned long _res; \
_argvec[0] = (unsigned long)_orig.nraddr; \
_argvec[1] = (unsigned long)(arg1); \
_argvec[2] = (unsigned long)(arg2); \
_argvec[3] = (unsigned long)(arg3); \
_argvec[4] = (unsigned long)(arg4); \
_argvec[5] = (unsigned long)(arg5); \
__asm__ volatile( \
VALGRIND_ALIGN_STACK \
"subl $12, %%esp\n\t" \
"pushl 20(%%eax)\n\t" \
"pushl 16(%%eax)\n\t" \
"pushl 12(%%eax)\n\t" \
"pushl 8(%%eax)\n\t" \
"pushl 4(%%eax)\n\t" \
"movl (%%eax), %%eax\n\t" /* target->%eax */ \
VALGRIND_CALL_NOREDIR_EAX \
VALGRIND_RESTORE_STACK \
: /*out*/ "=a" (_res) \
: /*in*/ "a" (&_argvec[0]) \
: /*trash*/ "cc", "memory", __CALLER_SAVED_REGS, "edi" \
); \
lval = (__typeof__(lval)) _res; \
} while (0)
#define CALL_FN_W_6W(lval, orig, arg1,arg2,arg3,arg4,arg5,arg6) \
do { \
volatile OrigFn _orig = (orig); \
volatile unsigned long _argvec[7]; \
volatile unsigned long _res; \
_argvec[0] = (unsigned long)_orig.nraddr; \
_argvec[1] = (unsigned long)(arg1); \
_argvec[2] = (unsigned long)(arg2); \
_argvec[3] = (unsigned long)(arg3); \
_argvec[4] = (unsigned long)(arg4); \
_argvec[5] = (unsigned long)(arg5); \
_argvec[6] = (unsigned long)(arg6); \
__asm__ volatile( \
VALGRIND_ALIGN_STACK \
"subl $8, %%esp\n\t" \
"pushl 24(%%eax)\n\t" \
"pushl 20(%%eax)\n\t" \
"pushl 16(%%eax)\n\t" \
"pushl 12(%%eax)\n\t" \
"pushl 8(%%eax)\n\t" \
"pushl 4(%%eax)\n\t" \
"movl (%%eax), %%eax\n\t" /* target->%eax */ \
VALGRIND_CALL_NOREDIR_EAX \
VALGRIND_RESTORE_STACK \
: /*out*/ "=a" (_res) \
: /*in*/ "a" (&_argvec[0]) \
: /*trash*/ "cc", "memory", __CALLER_SAVED_REGS, "edi" \
); \
lval = (__typeof__(lval)) _res; \
} while (0)
#define CALL_FN_W_7W(lval, orig, arg1,arg2,arg3,arg4,arg5,arg6, \
arg7) \
do { \
volatile OrigFn _orig = (orig); \
volatile unsigned long _argvec[8]; \
volatile unsigned long _res; \
_argvec[0] = (unsigned long)_orig.nraddr; \
_argvec[1] = (unsigned long)(arg1); \
_argvec[2] = (unsigned long)(arg2); \
_argvec[3] = (unsigned long)(arg3); \
_argvec[4] = (unsigned long)(arg4); \
_argvec[5] = (unsigned long)(arg5); \
_argvec[6] = (unsigned long)(arg6); \
_argvec[7] = (unsigned long)(arg7); \
__asm__ volatile( \
VALGRIND_ALIGN_STACK \
"subl $4, %%esp\n\t" \
"pushl 28(%%eax)\n\t" \
"pushl 24(%%eax)\n\t" \
"pushl 20(%%eax)\n\t" \
"pushl 16(%%eax)\n\t" \
"pushl 12(%%eax)\n\t" \
"pushl 8(%%eax)\n\t" \
"pushl 4(%%eax)\n\t" \
"movl (%%eax), %%eax\n\t" /* target->%eax */ \
VALGRIND_CALL_NOREDIR_EAX \
VALGRIND_RESTORE_STACK \
: /*out*/ "=a" (_res) \
: /*in*/ "a" (&_argvec[0]) \
: /*trash*/ "cc", "memory", __CALLER_SAVED_REGS, "edi" \
); \
lval = (__typeof__(lval)) _res; \
} while (0)
#define CALL_FN_W_8W(lval, orig, arg1,arg2,arg3,arg4,arg5,arg6, \
arg7,arg8) \
do { \
volatile OrigFn _orig = (orig); \
volatile unsigned long _argvec[9]; \
volatile unsigned long _res; \
_argvec[0] = (unsigned long)_orig.nraddr; \
_argvec[1] = (unsigned long)(arg1); \
_argvec[2] = (unsigned long)(arg2); \
_argvec[3] = (unsigned long)(arg3); \
_argvec[4] = (unsigned long)(arg4); \
_argvec[5] = (unsigned long)(arg5); \
_argvec[6] = (unsigned long)(arg6); \
_argvec[7] = (unsigned long)(arg7); \
_argvec[8] = (unsigned long)(arg8); \
__asm__ volatile( \
VALGRIND_ALIGN_STACK \
"pushl 32(%%eax)\n\t" \
"pushl 28(%%eax)\n\t" \
"pushl 24(%%eax)\n\t" \
"pushl 20(%%eax)\n\t" \
"pushl 16(%%eax)\n\t" \
"pushl 12(%%eax)\n\t" \
"pushl 8(%%eax)\n\t" \
"pushl 4(%%eax)\n\t" \
"movl (%%eax), %%eax\n\t" /* target->%eax */ \
VALGRIND_CALL_NOREDIR_EAX \
VALGRIND_RESTORE_STACK \
: /*out*/ "=a" (_res) \
: /*in*/ "a" (&_argvec[0]) \
: /*trash*/ "cc", "memory", __CALLER_SAVED_REGS, "edi" \
); \
lval = (__typeof__(lval)) _res; \
} while (0)
#define CALL_FN_W_9W(lval, orig, arg1,arg2,arg3,arg4,arg5,arg6, \
arg7,arg8,arg9) \
do { \
volatile OrigFn _orig = (orig); \
volatile unsigned long _argvec[10]; \
volatile unsigned long _res; \
_argvec[0] = (unsigned long)_orig.nraddr; \
_argvec[1] = (unsigned long)(arg1); \
_argvec[2] = (unsigned long)(arg2); \
_argvec[3] = (unsigned long)(arg3); \
_argvec[4] = (unsigned long)(arg4); \
_argvec[5] = (unsigned long)(arg5); \
_argvec[6] = (unsigned long)(arg6); \
_argvec[7] = (unsigned long)(arg7); \
_argvec[8] = (unsigned long)(arg8); \
_argvec[9] = (unsigned long)(arg9); \
__asm__ volatile( \
VALGRIND_ALIGN_STACK \
"subl $12, %%esp\n\t" \
"pushl 36(%%eax)\n\t" \
"pushl 32(%%eax)\n\t" \
"pushl 28(%%eax)\n\t" \
"pushl 24(%%eax)\n\t" \
"pushl 20(%%eax)\n\t" \
"pushl 16(%%eax)\n\t" \
"pushl 12(%%eax)\n\t" \
"pushl 8(%%eax)\n\t" \
"pushl 4(%%eax)\n\t" \
"movl (%%eax), %%eax\n\t" /* target->%eax */ \
VALGRIND_CALL_NOREDIR_EAX \
VALGRIND_RESTORE_STACK \
: /*out*/ "=a" (_res) \
: /*in*/ "a" (&_argvec[0]) \
: /*trash*/ "cc", "memory", __CALLER_SAVED_REGS, "edi" \
); \
lval = (__typeof__(lval)) _res; \
} while (0)
#define CALL_FN_W_10W(lval, orig, arg1,arg2,arg3,arg4,arg5,arg6, \
arg7,arg8,arg9,arg10) \
do { \
volatile OrigFn _orig = (orig); \
volatile unsigned long _argvec[11]; \
volatile unsigned long _res; \
_argvec[0] = (unsigned long)_orig.nraddr; \
_argvec[1] = (unsigned long)(arg1); \
_argvec[2] = (unsigned long)(arg2); \
_argvec[3] = (unsigned long)(arg3); \
_argvec[4] = (unsigned long)(arg4); \
_argvec[5] = (unsigned long)(arg5); \
_argvec[6] = (unsigned long)(arg6); \
_argvec[7] = (unsigned long)(arg7); \
_argvec[8] = (unsigned long)(arg8); \
_argvec[9] = (unsigned long)(arg9); \
_argvec[10] = (unsigned long)(arg10); \
__asm__ volatile( \
VALGRIND_ALIGN_STACK \
"subl $8, %%esp\n\t" \
"pushl 40(%%eax)\n\t" \
"pushl 36(%%eax)\n\t" \
"pushl 32(%%eax)\n\t" \
"pushl 28(%%eax)\n\t" \
"pushl 24(%%eax)\n\t" \
"pushl 20(%%eax)\n\t" \
"pushl 16(%%eax)\n\t" \
"pushl 12(%%eax)\n\t" \
"pushl 8(%%eax)\n\t" \
"pushl 4(%%eax)\n\t" \
"movl (%%eax), %%eax\n\t" /* target->%eax */ \
VALGRIND_CALL_NOREDIR_EAX \
VALGRIND_RESTORE_STACK \
: /*out*/ "=a" (_res) \
: /*in*/ "a" (&_argvec[0]) \
: /*trash*/ "cc", "memory", __CALLER_SAVED_REGS, "edi" \
); \
lval = (__typeof__(lval)) _res; \
} while (0)
#define CALL_FN_W_11W(lval, orig, arg1,arg2,arg3,arg4,arg5, \
arg6,arg7,arg8,arg9,arg10, \
arg11) \
do { \
volatile OrigFn _orig = (orig); \
volatile unsigned long _argvec[12]; \
volatile unsigned long _res; \
_argvec[0] = (unsigned long)_orig.nraddr; \
_argvec[1] = (unsigned long)(arg1); \
_argvec[2] = (unsigned long)(arg2); \
_argvec[3] = (unsigned long)(arg3); \
_argvec[4] = (unsigned long)(arg4); \
_argvec[5] = (unsigned long)(arg5); \
_argvec[6] = (unsigned long)(arg6); \
_argvec[7] = (unsigned long)(arg7); \
_argvec[8] = (unsigned long)(arg8); \
_argvec[9] = (unsigned long)(arg9); \
_argvec[10] = (unsigned long)(arg10); \
_argvec[11] = (unsigned long)(arg11); \
__asm__ volatile( \
VALGRIND_ALIGN_STACK \
"subl $4, %%esp\n\t" \
"pushl 44(%%eax)\n\t" \
"pushl 40(%%eax)\n\t" \
"pushl 36(%%eax)\n\t" \
"pushl 32(%%eax)\n\t" \
"pushl 28(%%eax)\n\t" \
"pushl 24(%%eax)\n\t" \
"pushl 20(%%eax)\n\t" \
"pushl 16(%%eax)\n\t" \
"pushl 12(%%eax)\n\t" \
"pushl 8(%%eax)\n\t" \
"pushl 4(%%eax)\n\t" \
"movl (%%eax), %%eax\n\t" /* target->%eax */ \
VALGRIND_CALL_NOREDIR_EAX \
VALGRIND_RESTORE_STACK \
: /*out*/ "=a" (_res) \
: /*in*/ "a" (&_argvec[0]) \
: /*trash*/ "cc", "memory", __CALLER_SAVED_REGS, "edi" \
); \
lval = (__typeof__(lval)) _res; \
} while (0)
#define CALL_FN_W_12W(lval, orig, arg1,arg2,arg3,arg4,arg5, \
arg6,arg7,arg8,arg9,arg10, \
arg11,arg12) \
do { \
volatile OrigFn _orig = (orig); \
volatile unsigned long _argvec[13]; \
volatile unsigned long _res; \
_argvec[0] = (unsigned long)_orig.nraddr; \
_argvec[1] = (unsigned long)(arg1); \
_argvec[2] = (unsigned long)(arg2); \
_argvec[3] = (unsigned long)(arg3); \
_argvec[4] = (unsigned long)(arg4); \
_argvec[5] = (unsigned long)(arg5); \
_argvec[6] = (unsigned long)(arg6); \
_argvec[7] = (unsigned long)(arg7); \
_argvec[8] = (unsigned long)(arg8); \
_argvec[9] = (unsigned long)(arg9); \
_argvec[10] = (unsigned long)(arg10); \
_argvec[11] = (unsigned long)(arg11); \
_argvec[12] = (unsigned long)(arg12); \
__asm__ volatile( \
VALGRIND_ALIGN_STACK \
"pushl 48(%%eax)\n\t" \
"pushl 44(%%eax)\n\t" \
"pushl 40(%%eax)\n\t" \
"pushl 36(%%eax)\n\t" \
"pushl 32(%%eax)\n\t" \
"pushl 28(%%eax)\n\t" \
"pushl 24(%%eax)\n\t" \
"pushl 20(%%eax)\n\t" \
"pushl 16(%%eax)\n\t" \
"pushl 12(%%eax)\n\t" \
"pushl 8(%%eax)\n\t" \
"pushl 4(%%eax)\n\t" \
"movl (%%eax), %%eax\n\t" /* target->%eax */ \
VALGRIND_CALL_NOREDIR_EAX \
VALGRIND_RESTORE_STACK \
: /*out*/ "=a" (_res) \
: /*in*/ "a" (&_argvec[0]) \
: /*trash*/ "cc", "memory", __CALLER_SAVED_REGS, "edi" \
); \
lval = (__typeof__(lval)) _res; \
} while (0)
#endif /* PLAT_x86_linux || PLAT_x86_darwin || PLAT_x86_solaris */
/* ---------------- amd64-{linux,darwin,solaris} --------------- */
#if defined(PLAT_amd64_linux) || defined(PLAT_amd64_darwin) \
|| defined(PLAT_amd64_solaris) || defined(PLAT_amd64_freebsd)
/* ARGREGS: rdi rsi rdx rcx r8 r9 (the rest on stack in R-to-L order) */
/* These regs are trashed by the hidden call. */
#define __CALLER_SAVED_REGS /*"rax",*/ "rcx", "rdx", "rsi", \
"rdi", "r8", "r9", "r10", "r11"
/* This is all pretty complex. It's so as to make stack unwinding
work reliably. See bug 243270. The basic problem is the sub and
add of 128 of %rsp in all of the following macros. If gcc believes
the CFA is in %rsp, then unwinding may fail, because what's at the
CFA is not what gcc "expected" when it constructs the CFIs for the
places where the macros are instantiated.
But we can't just add a CFI annotation to increase the CFA offset
by 128, to match the sub of 128 from %rsp, because we don't know
whether gcc has chosen %rsp as the CFA at that point, or whether it
has chosen some other register (eg, %rbp). In the latter case,
adding a CFI annotation to change the CFA offset is simply wrong.
So the solution is to get hold of the CFA using
__builtin_dwarf_cfa(), put it in a known register, and add a
CFI annotation to say what the register is. We choose %rbp for
this (perhaps perversely), because:
(1) %rbp is already subject to unwinding. If a new register was
chosen then the unwinder would have to unwind it in all stack
traces, which is expensive, and
(2) %rbp is already subject to precise exception updates in the
JIT. If a new register was chosen, we'd have to have precise
exceptions for it too, which reduces performance of the
generated code.
However .. one extra complication. We can't just whack the result
of __builtin_dwarf_cfa() into %rbp and then add %rbp to the
list of trashed registers at the end of the inline assembly
fragments; gcc won't allow %rbp to appear in that list. Hence
instead we need to stash %rbp in %r15 for the duration of the asm,
and say that %r15 is trashed instead. gcc seems happy to go with
that.
Oh .. and this all needs to be conditionalised so that it is
unchanged from before this commit, when compiled with older gccs
that don't support __builtin_dwarf_cfa. Furthermore, since
this header file is freestanding, it has to be independent of
config.h, and so the following conditionalisation cannot depend on
configure time checks.
Although it's not clear from
'defined(__GNUC__) && defined(__GCC_HAVE_DWARF2_CFI_ASM)',
this expression excludes Darwin.
.cfi directives in Darwin assembly appear to be completely
different and I haven't investigated how they work.
For even more entertainment value, note we have to use the
completely undocumented __builtin_dwarf_cfa(), which appears to
really compute the CFA, whereas __builtin_frame_address(0) claims
to but actually doesn't. See
https://bugs.kde.org/show_bug.cgi?id=243270#c47
*/
#if defined(__GNUC__) && defined(__GCC_HAVE_DWARF2_CFI_ASM)
# define __FRAME_POINTER \
,"r"(__builtin_dwarf_cfa())
# define VALGRIND_CFI_PROLOGUE \
"movq %%rbp, %%r15\n\t" \
"movq %2, %%rbp\n\t" \
".cfi_remember_state\n\t" \
".cfi_def_cfa rbp, 0\n\t"
# define VALGRIND_CFI_EPILOGUE \
"movq %%r15, %%rbp\n\t" \
".cfi_restore_state\n\t"
#else
# define __FRAME_POINTER
# define VALGRIND_CFI_PROLOGUE
# define VALGRIND_CFI_EPILOGUE
#endif
/* Macros to save and align the stack before making a function
call and restore it afterwards as gcc may not keep the stack
pointer aligned if it doesn't realise calls are being made
to other functions. */
#define VALGRIND_ALIGN_STACK \
"movq %%rsp,%%r14\n\t" \
"andq $0xfffffffffffffff0,%%rsp\n\t"
#define VALGRIND_RESTORE_STACK \
"movq %%r14,%%rsp\n\t"
/* These CALL_FN_ macros assume that on amd64-linux, sizeof(unsigned
long) == 8. */
/* NB 9 Sept 07. There is a nasty kludge here in all these CALL_FN_
macros. In order not to trash the stack redzone, we need to drop
%rsp by 128 before the hidden call, and restore afterwards. The
nastyness is that it is only by luck that the stack still appears
to be unwindable during the hidden call - since then the behaviour
of any routine using this macro does not match what the CFI data
says. Sigh.
Why is this important? Imagine that a wrapper has a stack
allocated local, and passes to the hidden call, a pointer to it.
Because gcc does not know about the hidden call, it may allocate
that local in the redzone. Unfortunately the hidden call may then
trash it before it comes to use it. So we must step clear of the
redzone, for the duration of the hidden call, to make it safe.
Probably the same problem afflicts the other redzone-style ABIs too
(ppc64-linux); but for those, the stack is
self describing (none of this CFI nonsense) so at least messing
with the stack pointer doesn't give a danger of non-unwindable
stack. */
#define CALL_FN_W_v(lval, orig) \
do { \
volatile OrigFn _orig = (orig); \
volatile unsigned long _argvec[1]; \
volatile unsigned long _res; \
_argvec[0] = (unsigned long)_orig.nraddr; \
__asm__ volatile( \
VALGRIND_CFI_PROLOGUE \
VALGRIND_ALIGN_STACK \
"subq $128,%%rsp\n\t" \
"movq (%%rax), %%rax\n\t" /* target->%rax */ \
VALGRIND_CALL_NOREDIR_RAX \
VALGRIND_RESTORE_STACK \
VALGRIND_CFI_EPILOGUE \
: /*out*/ "=a" (_res) \
: /*in*/ "a" (&_argvec[0]) __FRAME_POINTER \
: /*trash*/ "cc", "memory", __CALLER_SAVED_REGS, "r14", "r15" \
); \
lval = (__typeof__(lval)) _res; \
} while (0)
#define CALL_FN_W_W(lval, orig, arg1) \
do { \
volatile OrigFn _orig = (orig); \
volatile unsigned long _argvec[2]; \
volatile unsigned long _res; \
_argvec[0] = (unsigned long)_orig.nraddr; \
_argvec[1] = (unsigned long)(arg1); \
__asm__ volatile( \
VALGRIND_CFI_PROLOGUE \
VALGRIND_ALIGN_STACK \
"subq $128,%%rsp\n\t" \
"movq 8(%%rax), %%rdi\n\t" \
"movq (%%rax), %%rax\n\t" /* target->%rax */ \
VALGRIND_CALL_NOREDIR_RAX \
VALGRIND_RESTORE_STACK \
VALGRIND_CFI_EPILOGUE \
: /*out*/ "=a" (_res) \
: /*in*/ "a" (&_argvec[0]) __FRAME_POINTER \
: /*trash*/ "cc", "memory", __CALLER_SAVED_REGS, "r14", "r15" \
); \
lval = (__typeof__(lval)) _res; \
} while (0)
#define CALL_FN_W_WW(lval, orig, arg1,arg2) \
do { \
volatile OrigFn _orig = (orig); \
volatile unsigned long _argvec[3]; \
volatile unsigned long _res; \
_argvec[0] = (unsigned long)_orig.nraddr; \
_argvec[1] = (unsigned long)(arg1); \
_argvec[2] = (unsigned long)(arg2); \
__asm__ volatile( \
VALGRIND_CFI_PROLOGUE \
VALGRIND_ALIGN_STACK \
"subq $128,%%rsp\n\t" \
"movq 16(%%rax), %%rsi\n\t" \
"movq 8(%%rax), %%rdi\n\t" \
"movq (%%rax), %%rax\n\t" /* target->%rax */ \
VALGRIND_CALL_NOREDIR_RAX \
VALGRIND_RESTORE_STACK \
VALGRIND_CFI_EPILOGUE \
: /*out*/ "=a" (_res) \
: /*in*/ "a" (&_argvec[0]) __FRAME_POINTER \
: /*trash*/ "cc", "memory", __CALLER_SAVED_REGS, "r14", "r15" \
); \
lval = (__typeof__(lval)) _res; \
} while (0)
#define CALL_FN_W_WWW(lval, orig, arg1,arg2,arg3) \
do { \
volatile OrigFn _orig = (orig); \
volatile unsigned long _argvec[4]; \
volatile unsigned long _res; \
_argvec[0] = (unsigned long)_orig.nraddr; \
_argvec[1] = (unsigned long)(arg1); \
_argvec[2] = (unsigned long)(arg2); \
_argvec[3] = (unsigned long)(arg3); \
__asm__ volatile( \
VALGRIND_CFI_PROLOGUE \
VALGRIND_ALIGN_STACK \
"subq $128,%%rsp\n\t" \
"movq 24(%%rax), %%rdx\n\t" \
"movq 16(%%rax), %%rsi\n\t" \
"movq 8(%%rax), %%rdi\n\t" \
"movq (%%rax), %%rax\n\t" /* target->%rax */ \
VALGRIND_CALL_NOREDIR_RAX \
VALGRIND_RESTORE_STACK \
VALGRIND_CFI_EPILOGUE \
: /*out*/ "=a" (_res) \
: /*in*/ "a" (&_argvec[0]) __FRAME_POINTER \
: /*trash*/ "cc", "memory", __CALLER_SAVED_REGS, "r14", "r15" \
); \
lval = (__typeof__(lval)) _res; \
} while (0)
#define CALL_FN_W_WWWW(lval, orig, arg1,arg2,arg3,arg4) \
do { \
volatile OrigFn _orig = (orig); \
volatile unsigned long _argvec[5]; \
volatile unsigned long _res; \
_argvec[0] = (unsigned long)_orig.nraddr; \
_argvec[1] = (unsigned long)(arg1); \
_argvec[2] = (unsigned long)(arg2); \
_argvec[3] = (unsigned long)(arg3); \
_argvec[4] = (unsigned long)(arg4); \
__asm__ volatile( \
VALGRIND_CFI_PROLOGUE \
VALGRIND_ALIGN_STACK \
"subq $128,%%rsp\n\t" \
"movq 32(%%rax), %%rcx\n\t" \
"movq 24(%%rax), %%rdx\n\t" \
"movq 16(%%rax), %%rsi\n\t" \
"movq 8(%%rax), %%rdi\n\t" \
"movq (%%rax), %%rax\n\t" /* target->%rax */ \
VALGRIND_CALL_NOREDIR_RAX \
VALGRIND_RESTORE_STACK \
VALGRIND_CFI_EPILOGUE \
: /*out*/ "=a" (_res) \
: /*in*/ "a" (&_argvec[0]) __FRAME_POINTER \
: /*trash*/ "cc", "memory", __CALLER_SAVED_REGS, "r14", "r15" \
); \
lval = (__typeof__(lval)) _res; \
} while (0)
#define CALL_FN_W_5W(lval, orig, arg1,arg2,arg3,arg4,arg5) \
do { \
volatile OrigFn _orig = (orig); \
volatile unsigned long _argvec[6]; \
volatile unsigned long _res; \
_argvec[0] = (unsigned long)_orig.nraddr; \
_argvec[1] = (unsigned long)(arg1); \
_argvec[2] = (unsigned long)(arg2); \
_argvec[3] = (unsigned long)(arg3); \
_argvec[4] = (unsigned long)(arg4); \
_argvec[5] = (unsigned long)(arg5); \
__asm__ volatile( \
VALGRIND_CFI_PROLOGUE \
VALGRIND_ALIGN_STACK \
"subq $128,%%rsp\n\t" \
"movq 40(%%rax), %%r8\n\t" \
"movq 32(%%rax), %%rcx\n\t" \
"movq 24(%%rax), %%rdx\n\t" \
"movq 16(%%rax), %%rsi\n\t" \
"movq 8(%%rax), %%rdi\n\t" \
"movq (%%rax), %%rax\n\t" /* target->%rax */ \
VALGRIND_CALL_NOREDIR_RAX \
VALGRIND_RESTORE_STACK \
VALGRIND_CFI_EPILOGUE \
: /*out*/ "=a" (_res) \
: /*in*/ "a" (&_argvec[0]) __FRAME_POINTER \
: /*trash*/ "cc", "memory", __CALLER_SAVED_REGS, "r14", "r15" \
); \
lval = (__typeof__(lval)) _res; \
} while (0)
#define CALL_FN_W_6W(lval, orig, arg1,arg2,arg3,arg4,arg5,arg6) \
do { \
volatile OrigFn _orig = (orig); \
volatile unsigned long _argvec[7]; \
volatile unsigned long _res; \
_argvec[0] = (unsigned long)_orig.nraddr; \
_argvec[1] = (unsigned long)(arg1); \
_argvec[2] = (unsigned long)(arg2); \
_argvec[3] = (unsigned long)(arg3); \
_argvec[4] = (unsigned long)(arg4); \
_argvec[5] = (unsigned long)(arg5); \
_argvec[6] = (unsigned long)(arg6); \
__asm__ volatile( \
VALGRIND_CFI_PROLOGUE \
VALGRIND_ALIGN_STACK \
"subq $128,%%rsp\n\t" \
"movq 48(%%rax), %%r9\n\t" \
"movq 40(%%rax), %%r8\n\t" \
"movq 32(%%rax), %%rcx\n\t" \
"movq 24(%%rax), %%rdx\n\t" \
"movq 16(%%rax), %%rsi\n\t" \
"movq 8(%%rax), %%rdi\n\t" \
"movq (%%rax), %%rax\n\t" /* target->%rax */ \
VALGRIND_CALL_NOREDIR_RAX \
VALGRIND_RESTORE_STACK \
VALGRIND_CFI_EPILOGUE \
: /*out*/ "=a" (_res) \
: /*in*/ "a" (&_argvec[0]) __FRAME_POINTER \
: /*trash*/ "cc", "memory", __CALLER_SAVED_REGS, "r14", "r15" \
); \
lval = (__typeof__(lval)) _res; \
} while (0)
#define CALL_FN_W_7W(lval, orig, arg1,arg2,arg3,arg4,arg5,arg6, \
arg7) \
do { \
volatile OrigFn _orig = (orig); \
volatile unsigned long _argvec[8]; \
volatile unsigned long _res; \
_argvec[0] = (unsigned long)_orig.nraddr; \
_argvec[1] = (unsigned long)(arg1); \
_argvec[2] = (unsigned long)(arg2); \
_argvec[3] = (unsigned long)(arg3); \
_argvec[4] = (unsigned long)(arg4); \
_argvec[5] = (unsigned long)(arg5); \
_argvec[6] = (unsigned long)(arg6); \
_argvec[7] = (unsigned long)(arg7); \
__asm__ volatile( \
VALGRIND_CFI_PROLOGUE \
VALGRIND_ALIGN_STACK \
"subq $136,%%rsp\n\t" \
"pushq 56(%%rax)\n\t" \
"movq 48(%%rax), %%r9\n\t" \
"movq 40(%%rax), %%r8\n\t" \
"movq 32(%%rax), %%rcx\n\t" \
"movq 24(%%rax), %%rdx\n\t" \
"movq 16(%%rax), %%rsi\n\t" \
"movq 8(%%rax), %%rdi\n\t" \
"movq (%%rax), %%rax\n\t" /* target->%rax */ \
VALGRIND_CALL_NOREDIR_RAX \
VALGRIND_RESTORE_STACK \
VALGRIND_CFI_EPILOGUE \
: /*out*/ "=a" (_res) \
: /*in*/ "a" (&_argvec[0]) __FRAME_POINTER \
: /*trash*/ "cc", "memory", __CALLER_SAVED_REGS, "r14", "r15" \
); \
lval = (__typeof__(lval)) _res; \
} while (0)
#define CALL_FN_W_8W(lval, orig, arg1,arg2,arg3,arg4,arg5,arg6, \
arg7,arg8) \
do { \
volatile OrigFn _orig = (orig); \
volatile unsigned long _argvec[9]; \
volatile unsigned long _res; \
_argvec[0] = (unsigned long)_orig.nraddr; \
_argvec[1] = (unsigned long)(arg1); \
_argvec[2] = (unsigned long)(arg2); \
_argvec[3] = (unsigned long)(arg3); \
_argvec[4] = (unsigned long)(arg4); \
_argvec[5] = (unsigned long)(arg5); \
_argvec[6] = (unsigned long)(arg6); \
_argvec[7] = (unsigned long)(arg7); \
_argvec[8] = (unsigned long)(arg8); \
__asm__ volatile( \
VALGRIND_CFI_PROLOGUE \
VALGRIND_ALIGN_STACK \
"subq $128,%%rsp\n\t" \
"pushq 64(%%rax)\n\t" \
"pushq 56(%%rax)\n\t" \
"movq 48(%%rax), %%r9\n\t" \
"movq 40(%%rax), %%r8\n\t" \
"movq 32(%%rax), %%rcx\n\t" \
"movq 24(%%rax), %%rdx\n\t" \
"movq 16(%%rax), %%rsi\n\t" \
"movq 8(%%rax), %%rdi\n\t" \
"movq (%%rax), %%rax\n\t" /* target->%rax */ \
VALGRIND_CALL_NOREDIR_RAX \
VALGRIND_RESTORE_STACK \
VALGRIND_CFI_EPILOGUE \
: /*out*/ "=a" (_res) \
: /*in*/ "a" (&_argvec[0]) __FRAME_POINTER \
: /*trash*/ "cc", "memory", __CALLER_SAVED_REGS, "r14", "r15" \
); \
lval = (__typeof__(lval)) _res; \
} while (0)
#define CALL_FN_W_9W(lval, orig, arg1,arg2,arg3,arg4,arg5,arg6, \
arg7,arg8,arg9) \
do { \
volatile OrigFn _orig = (orig); \
volatile unsigned long _argvec[10]; \
volatile unsigned long _res; \
_argvec[0] = (unsigned long)_orig.nraddr; \
_argvec[1] = (unsigned long)(arg1); \
_argvec[2] = (unsigned long)(arg2); \
_argvec[3] = (unsigned long)(arg3); \
_argvec[4] = (unsigned long)(arg4); \
_argvec[5] = (unsigned long)(arg5); \
_argvec[6] = (unsigned long)(arg6); \
_argvec[7] = (unsigned long)(arg7); \
_argvec[8] = (unsigned long)(arg8); \
_argvec[9] = (unsigned long)(arg9); \
__asm__ volatile( \
VALGRIND_CFI_PROLOGUE \
VALGRIND_ALIGN_STACK \
"subq $136,%%rsp\n\t" \
"pushq 72(%%rax)\n\t" \
"pushq 64(%%rax)\n\t" \
"pushq 56(%%rax)\n\t" \
"movq 48(%%rax), %%r9\n\t" \
"movq 40(%%rax), %%r8\n\t" \
"movq 32(%%rax), %%rcx\n\t" \
"movq 24(%%rax), %%rdx\n\t" \
"movq 16(%%rax), %%rsi\n\t" \
"movq 8(%%rax), %%rdi\n\t" \
"movq (%%rax), %%rax\n\t" /* target->%rax */ \
VALGRIND_CALL_NOREDIR_RAX \
VALGRIND_RESTORE_STACK \
VALGRIND_CFI_EPILOGUE \
: /*out*/ "=a" (_res) \
: /*in*/ "a" (&_argvec[0]) __FRAME_POINTER \
: /*trash*/ "cc", "memory", __CALLER_SAVED_REGS, "r14", "r15" \
); \
lval = (__typeof__(lval)) _res; \
} while (0)
#define CALL_FN_W_10W(lval, orig, arg1,arg2,arg3,arg4,arg5,arg6, \
arg7,arg8,arg9,arg10) \
do { \
volatile OrigFn _orig = (orig); \
volatile unsigned long _argvec[11]; \
volatile unsigned long _res; \
_argvec[0] = (unsigned long)_orig.nraddr; \
_argvec[1] = (unsigned long)(arg1); \
_argvec[2] = (unsigned long)(arg2); \
_argvec[3] = (unsigned long)(arg3); \
_argvec[4] = (unsigned long)(arg4); \
_argvec[5] = (unsigned long)(arg5); \
_argvec[6] = (unsigned long)(arg6); \
_argvec[7] = (unsigned long)(arg7); \
_argvec[8] = (unsigned long)(arg8); \
_argvec[9] = (unsigned long)(arg9); \
_argvec[10] = (unsigned long)(arg10); \
__asm__ volatile( \
VALGRIND_CFI_PROLOGUE \
VALGRIND_ALIGN_STACK \
"subq $128,%%rsp\n\t" \
"pushq 80(%%rax)\n\t" \
"pushq 72(%%rax)\n\t" \
"pushq 64(%%rax)\n\t" \
"pushq 56(%%rax)\n\t" \
"movq 48(%%rax), %%r9\n\t" \
"movq 40(%%rax), %%r8\n\t" \
"movq 32(%%rax), %%rcx\n\t" \
"movq 24(%%rax), %%rdx\n\t" \
"movq 16(%%rax), %%rsi\n\t" \
"movq 8(%%rax), %%rdi\n\t" \
"movq (%%rax), %%rax\n\t" /* target->%rax */ \
VALGRIND_CALL_NOREDIR_RAX \
VALGRIND_RESTORE_STACK \
VALGRIND_CFI_EPILOGUE \
: /*out*/ "=a" (_res) \
: /*in*/ "a" (&_argvec[0]) __FRAME_POINTER \
: /*trash*/ "cc", "memory", __CALLER_SAVED_REGS, "r14", "r15" \
); \
lval = (__typeof__(lval)) _res; \
} while (0)
#define CALL_FN_W_11W(lval, orig, arg1,arg2,arg3,arg4,arg5,arg6, \
arg7,arg8,arg9,arg10,arg11) \
do { \
volatile OrigFn _orig = (orig); \
volatile unsigned long _argvec[12]; \
volatile unsigned long _res; \
_argvec[0] = (unsigned long)_orig.nraddr; \
_argvec[1] = (unsigned long)(arg1); \
_argvec[2] = (unsigned long)(arg2); \
_argvec[3] = (unsigned long)(arg3); \
_argvec[4] = (unsigned long)(arg4); \
_argvec[5] = (unsigned long)(arg5); \
_argvec[6] = (unsigned long)(arg6); \
_argvec[7] = (unsigned long)(arg7); \
_argvec[8] = (unsigned long)(arg8); \
_argvec[9] = (unsigned long)(arg9); \
_argvec[10] = (unsigned long)(arg10); \
_argvec[11] = (unsigned long)(arg11); \
__asm__ volatile( \
VALGRIND_CFI_PROLOGUE \
VALGRIND_ALIGN_STACK \
"subq $136,%%rsp\n\t" \
"pushq 88(%%rax)\n\t" \
"pushq 80(%%rax)\n\t" \
"pushq 72(%%rax)\n\t" \
"pushq 64(%%rax)\n\t" \
"pushq 56(%%rax)\n\t" \
"movq 48(%%rax), %%r9\n\t" \
"movq 40(%%rax), %%r8\n\t" \
"movq 32(%%rax), %%rcx\n\t" \
"movq 24(%%rax), %%rdx\n\t" \
"movq 16(%%rax), %%rsi\n\t" \
"movq 8(%%rax), %%rdi\n\t" \
"movq (%%rax), %%rax\n\t" /* target->%rax */ \
VALGRIND_CALL_NOREDIR_RAX \
VALGRIND_RESTORE_STACK \
VALGRIND_CFI_EPILOGUE \
: /*out*/ "=a" (_res) \
: /*in*/ "a" (&_argvec[0]) __FRAME_POINTER \
: /*trash*/ "cc", "memory", __CALLER_SAVED_REGS, "r14", "r15" \
); \
lval = (__typeof__(lval)) _res; \
} while (0)
#define CALL_FN_W_12W(lval, orig, arg1,arg2,arg3,arg4,arg5,arg6, \
arg7,arg8,arg9,arg10,arg11,arg12) \
do { \
volatile OrigFn _orig = (orig); \
volatile unsigned long _argvec[13]; \
volatile unsigned long _res; \
_argvec[0] = (unsigned long)_orig.nraddr; \
_argvec[1] = (unsigned long)(arg1); \
_argvec[2] = (unsigned long)(arg2); \
_argvec[3] = (unsigned long)(arg3); \
_argvec[4] = (unsigned long)(arg4); \
_argvec[5] = (unsigned long)(arg5); \
_argvec[6] = (unsigned long)(arg6); \
_argvec[7] = (unsigned long)(arg7); \
_argvec[8] = (unsigned long)(arg8); \
_argvec[9] = (unsigned long)(arg9); \
_argvec[10] = (unsigned long)(arg10); \
_argvec[11] = (unsigned long)(arg11); \
_argvec[12] = (unsigned long)(arg12); \
__asm__ volatile( \
VALGRIND_CFI_PROLOGUE \
VALGRIND_ALIGN_STACK \
"subq $128,%%rsp\n\t" \
"pushq 96(%%rax)\n\t" \
"pushq 88(%%rax)\n\t" \
"pushq 80(%%rax)\n\t" \
"pushq 72(%%rax)\n\t" \
"pushq 64(%%rax)\n\t" \
"pushq 56(%%rax)\n\t" \
"movq 48(%%rax), %%r9\n\t" \
"movq 40(%%rax), %%r8\n\t" \
"movq 32(%%rax), %%rcx\n\t" \
"movq 24(%%rax), %%rdx\n\t" \
"movq 16(%%rax), %%rsi\n\t" \
"movq 8(%%rax), %%rdi\n\t" \
"movq (%%rax), %%rax\n\t" /* target->%rax */ \
VALGRIND_CALL_NOREDIR_RAX \
VALGRIND_RESTORE_STACK \
VALGRIND_CFI_EPILOGUE \
: /*out*/ "=a" (_res) \
: /*in*/ "a" (&_argvec[0]) __FRAME_POINTER \
: /*trash*/ "cc", "memory", __CALLER_SAVED_REGS, "r14", "r15" \
); \
lval = (__typeof__(lval)) _res; \
} while (0)
#endif /* PLAT_amd64_linux || PLAT_amd64_darwin || PLAT_amd64_solaris */
/* ------------------------ ppc32-linux ------------------------ */
#if defined(PLAT_ppc32_linux)
/* This is useful for finding out about the on-stack stuff:
extern int f9 ( int,int,int,int,int,int,int,int,int );
extern int f10 ( int,int,int,int,int,int,int,int,int,int );
extern int f11 ( int,int,int,int,int,int,int,int,int,int,int );
extern int f12 ( int,int,int,int,int,int,int,int,int,int,int,int );
int g9 ( void ) {
return f9(11,22,33,44,55,66,77,88,99);
}
int g10 ( void ) {
return f10(11,22,33,44,55,66,77,88,99,110);
}
int g11 ( void ) {
return f11(11,22,33,44,55,66,77,88,99,110,121);
}
int g12 ( void ) {
return f12(11,22,33,44,55,66,77,88,99,110,121,132);
}
*/
/* ARGREGS: r3 r4 r5 r6 r7 r8 r9 r10 (the rest on stack somewhere) */
/* These regs are trashed by the hidden call. */
#define __CALLER_SAVED_REGS \
"lr", "ctr", "xer", \
"cr0", "cr1", "cr2", "cr3", "cr4", "cr5", "cr6", "cr7", \
"r0", "r2", "r3", "r4", "r5", "r6", "r7", "r8", "r9", "r10", \
"r11", "r12", "r13"
/* Macros to save and align the stack before making a function
call and restore it afterwards as gcc may not keep the stack
pointer aligned if it doesn't realise calls are being made
to other functions. */
#define VALGRIND_ALIGN_STACK \
"mr 28,1\n\t" \
"rlwinm 1,1,0,0,27\n\t"
#define VALGRIND_RESTORE_STACK \
"mr 1,28\n\t"
/* These CALL_FN_ macros assume that on ppc32-linux,
sizeof(unsigned long) == 4. */
#define CALL_FN_W_v(lval, orig) \
do { \
volatile OrigFn _orig = (orig); \
volatile unsigned long _argvec[1]; \
volatile unsigned long _res; \
_argvec[0] = (unsigned long)_orig.nraddr; \
__asm__ volatile( \
VALGRIND_ALIGN_STACK \
"mr 11,%1\n\t" \
"lwz 11,0(11)\n\t" /* target->r11 */ \
VALGRIND_BRANCH_AND_LINK_TO_NOREDIR_R11 \
VALGRIND_RESTORE_STACK \
"mr %0,3" \
: /*out*/ "=r" (_res) \
: /*in*/ "r" (&_argvec[0]) \
: /*trash*/ "cc", "memory", __CALLER_SAVED_REGS, "r28" \
); \
lval = (__typeof__(lval)) _res; \
} while (0)
#define CALL_FN_W_W(lval, orig, arg1) \
do { \
volatile OrigFn _orig = (orig); \
volatile unsigned long _argvec[2]; \
volatile unsigned long _res; \
_argvec[0] = (unsigned long)_orig.nraddr; \
_argvec[1] = (unsigned long)arg1; \
__asm__ volatile( \
VALGRIND_ALIGN_STACK \
"mr 11,%1\n\t" \
"lwz 3,4(11)\n\t" /* arg1->r3 */ \
"lwz 11,0(11)\n\t" /* target->r11 */ \
VALGRIND_BRANCH_AND_LINK_TO_NOREDIR_R11 \
VALGRIND_RESTORE_STACK \
"mr %0,3" \
: /*out*/ "=r" (_res) \
: /*in*/ "r" (&_argvec[0]) \
: /*trash*/ "cc", "memory", __CALLER_SAVED_REGS, "r28" \
); \
lval = (__typeof__(lval)) _res; \
} while (0)
#define CALL_FN_W_WW(lval, orig, arg1,arg2) \
do { \
volatile OrigFn _orig = (orig); \
volatile unsigned long _argvec[3]; \
volatile unsigned long _res; \
_argvec[0] = (unsigned long)_orig.nraddr; \
_argvec[1] = (unsigned long)arg1; \
_argvec[2] = (unsigned long)arg2; \
__asm__ volatile( \
VALGRIND_ALIGN_STACK \
"mr 11,%1\n\t" \
"lwz 3,4(11)\n\t" /* arg1->r3 */ \
"lwz 4,8(11)\n\t" \
"lwz 11,0(11)\n\t" /* target->r11 */ \
VALGRIND_BRANCH_AND_LINK_TO_NOREDIR_R11 \
VALGRIND_RESTORE_STACK \
"mr %0,3" \
: /*out*/ "=r" (_res) \
: /*in*/ "r" (&_argvec[0]) \
: /*trash*/ "cc", "memory", __CALLER_SAVED_REGS, "r28" \
); \
lval = (__typeof__(lval)) _res; \
} while (0)
#define CALL_FN_W_WWW(lval, orig, arg1,arg2,arg3) \
do { \
volatile OrigFn _orig = (orig); \
volatile unsigned long _argvec[4]; \
volatile unsigned long _res; \
_argvec[0] = (unsigned long)_orig.nraddr; \
_argvec[1] = (unsigned long)arg1; \
_argvec[2] = (unsigned long)arg2; \
_argvec[3] = (unsigned long)arg3; \
__asm__ volatile( \
VALGRIND_ALIGN_STACK \
"mr 11,%1\n\t" \
"lwz 3,4(11)\n\t" /* arg1->r3 */ \
"lwz 4,8(11)\n\t" \
"lwz 5,12(11)\n\t" \
"lwz 11,0(11)\n\t" /* target->r11 */ \
VALGRIND_BRANCH_AND_LINK_TO_NOREDIR_R11 \
VALGRIND_RESTORE_STACK \
"mr %0,3" \
: /*out*/ "=r" (_res) \
: /*in*/ "r" (&_argvec[0]) \
: /*trash*/ "cc", "memory", __CALLER_SAVED_REGS, "r28" \
); \
lval = (__typeof__(lval)) _res; \
} while (0)
#define CALL_FN_W_WWWW(lval, orig, arg1,arg2,arg3,arg4) \
do { \
volatile OrigFn _orig = (orig); \
volatile unsigned long _argvec[5]; \
volatile unsigned long _res; \
_argvec[0] = (unsigned long)_orig.nraddr; \
_argvec[1] = (unsigned long)arg1; \
_argvec[2] = (unsigned long)arg2; \
_argvec[3] = (unsigned long)arg3; \
_argvec[4] = (unsigned long)arg4; \
__asm__ volatile( \
VALGRIND_ALIGN_STACK \
"mr 11,%1\n\t" \
"lwz 3,4(11)\n\t" /* arg1->r3 */ \
"lwz 4,8(11)\n\t" \
"lwz 5,12(11)\n\t" \
"lwz 6,16(11)\n\t" /* arg4->r6 */ \
"lwz 11,0(11)\n\t" /* target->r11 */ \
VALGRIND_BRANCH_AND_LINK_TO_NOREDIR_R11 \
VALGRIND_RESTORE_STACK \
"mr %0,3" \
: /*out*/ "=r" (_res) \
: /*in*/ "r" (&_argvec[0]) \
: /*trash*/ "cc", "memory", __CALLER_SAVED_REGS, "r28" \
); \
lval = (__typeof__(lval)) _res; \
} while (0)
#define CALL_FN_W_5W(lval, orig, arg1,arg2,arg3,arg4,arg5) \
do { \
volatile OrigFn _orig = (orig); \
volatile unsigned long _argvec[6]; \
volatile unsigned long _res; \
_argvec[0] = (unsigned long)_orig.nraddr; \
_argvec[1] = (unsigned long)arg1; \
_argvec[2] = (unsigned long)arg2; \
_argvec[3] = (unsigned long)arg3; \
_argvec[4] = (unsigned long)arg4; \
_argvec[5] = (unsigned long)arg5; \
__asm__ volatile( \
VALGRIND_ALIGN_STACK \
"mr 11,%1\n\t" \
"lwz 3,4(11)\n\t" /* arg1->r3 */ \
"lwz 4,8(11)\n\t" \
"lwz 5,12(11)\n\t" \
"lwz 6,16(11)\n\t" /* arg4->r6 */ \
"lwz 7,20(11)\n\t" \
"lwz 11,0(11)\n\t" /* target->r11 */ \
VALGRIND_BRANCH_AND_LINK_TO_NOREDIR_R11 \
VALGRIND_RESTORE_STACK \
"mr %0,3" \
: /*out*/ "=r" (_res) \
: /*in*/ "r" (&_argvec[0]) \
: /*trash*/ "cc", "memory", __CALLER_SAVED_REGS, "r28" \
); \
lval = (__typeof__(lval)) _res; \
} while (0)
#define CALL_FN_W_6W(lval, orig, arg1,arg2,arg3,arg4,arg5,arg6) \
do { \
volatile OrigFn _orig = (orig); \
volatile unsigned long _argvec[7]; \
volatile unsigned long _res; \
_argvec[0] = (unsigned long)_orig.nraddr; \
_argvec[1] = (unsigned long)arg1; \
_argvec[2] = (unsigned long)arg2; \
_argvec[3] = (unsigned long)arg3; \
_argvec[4] = (unsigned long)arg4; \
_argvec[5] = (unsigned long)arg5; \
_argvec[6] = (unsigned long)arg6; \
__asm__ volatile( \
VALGRIND_ALIGN_STACK \
"mr 11,%1\n\t" \
"lwz 3,4(11)\n\t" /* arg1->r3 */ \
"lwz 4,8(11)\n\t" \
"lwz 5,12(11)\n\t" \
"lwz 6,16(11)\n\t" /* arg4->r6 */ \
"lwz 7,20(11)\n\t" \
"lwz 8,24(11)\n\t" \
"lwz 11,0(11)\n\t" /* target->r11 */ \
VALGRIND_BRANCH_AND_LINK_TO_NOREDIR_R11 \
VALGRIND_RESTORE_STACK \
"mr %0,3" \
: /*out*/ "=r" (_res) \
: /*in*/ "r" (&_argvec[0]) \
: /*trash*/ "cc", "memory", __CALLER_SAVED_REGS, "r28" \
); \
lval = (__typeof__(lval)) _res; \
} while (0)
#define CALL_FN_W_7W(lval, orig, arg1,arg2,arg3,arg4,arg5,arg6, \
arg7) \
do { \
volatile OrigFn _orig = (orig); \
volatile unsigned long _argvec[8]; \
volatile unsigned long _res; \
_argvec[0] = (unsigned long)_orig.nraddr; \
_argvec[1] = (unsigned long)arg1; \
_argvec[2] = (unsigned long)arg2; \
_argvec[3] = (unsigned long)arg3; \
_argvec[4] = (unsigned long)arg4; \
_argvec[5] = (unsigned long)arg5; \
_argvec[6] = (unsigned long)arg6; \
_argvec[7] = (unsigned long)arg7; \
__asm__ volatile( \
VALGRIND_ALIGN_STACK \
"mr 11,%1\n\t" \
"lwz 3,4(11)\n\t" /* arg1->r3 */ \
"lwz 4,8(11)\n\t" \
"lwz 5,12(11)\n\t" \
"lwz 6,16(11)\n\t" /* arg4->r6 */ \
"lwz 7,20(11)\n\t" \
"lwz 8,24(11)\n\t" \
"lwz 9,28(11)\n\t" \
"lwz 11,0(11)\n\t" /* target->r11 */ \
VALGRIND_BRANCH_AND_LINK_TO_NOREDIR_R11 \
VALGRIND_RESTORE_STACK \
"mr %0,3" \
: /*out*/ "=r" (_res) \
: /*in*/ "r" (&_argvec[0]) \
: /*trash*/ "cc", "memory", __CALLER_SAVED_REGS, "r28" \
); \
lval = (__typeof__(lval)) _res; \
} while (0)
#define CALL_FN_W_8W(lval, orig, arg1,arg2,arg3,arg4,arg5,arg6, \
arg7,arg8) \
do { \
volatile OrigFn _orig = (orig); \
volatile unsigned long _argvec[9]; \
volatile unsigned long _res; \
_argvec[0] = (unsigned long)_orig.nraddr; \
_argvec[1] = (unsigned long)arg1; \
_argvec[2] = (unsigned long)arg2; \
_argvec[3] = (unsigned long)arg3; \
_argvec[4] = (unsigned long)arg4; \
_argvec[5] = (unsigned long)arg5; \
_argvec[6] = (unsigned long)arg6; \
_argvec[7] = (unsigned long)arg7; \
_argvec[8] = (unsigned long)arg8; \
__asm__ volatile( \
VALGRIND_ALIGN_STACK \
"mr 11,%1\n\t" \
"lwz 3,4(11)\n\t" /* arg1->r3 */ \
"lwz 4,8(11)\n\t" \
"lwz 5,12(11)\n\t" \
"lwz 6,16(11)\n\t" /* arg4->r6 */ \
"lwz 7,20(11)\n\t" \
"lwz 8,24(11)\n\t" \
"lwz 9,28(11)\n\t" \
"lwz 10,32(11)\n\t" /* arg8->r10 */ \
"lwz 11,0(11)\n\t" /* target->r11 */ \
VALGRIND_BRANCH_AND_LINK_TO_NOREDIR_R11 \
VALGRIND_RESTORE_STACK \
"mr %0,3" \
: /*out*/ "=r" (_res) \
: /*in*/ "r" (&_argvec[0]) \
: /*trash*/ "cc", "memory", __CALLER_SAVED_REGS, "r28" \
); \
lval = (__typeof__(lval)) _res; \
} while (0)
#define CALL_FN_W_9W(lval, orig, arg1,arg2,arg3,arg4,arg5,arg6, \
arg7,arg8,arg9) \
do { \
volatile OrigFn _orig = (orig); \
volatile unsigned long _argvec[10]; \
volatile unsigned long _res; \
_argvec[0] = (unsigned long)_orig.nraddr; \
_argvec[1] = (unsigned long)arg1; \
_argvec[2] = (unsigned long)arg2; \
_argvec[3] = (unsigned long)arg3; \
_argvec[4] = (unsigned long)arg4; \
_argvec[5] = (unsigned long)arg5; \
_argvec[6] = (unsigned long)arg6; \
_argvec[7] = (unsigned long)arg7; \
_argvec[8] = (unsigned long)arg8; \
_argvec[9] = (unsigned long)arg9; \
__asm__ volatile( \
VALGRIND_ALIGN_STACK \
"mr 11,%1\n\t" \
"addi 1,1,-16\n\t" \
/* arg9 */ \
"lwz 3,36(11)\n\t" \
"stw 3,8(1)\n\t" \
/* args1-8 */ \
"lwz 3,4(11)\n\t" /* arg1->r3 */ \
"lwz 4,8(11)\n\t" \
"lwz 5,12(11)\n\t" \
"lwz 6,16(11)\n\t" /* arg4->r6 */ \
"lwz 7,20(11)\n\t" \
"lwz 8,24(11)\n\t" \
"lwz 9,28(11)\n\t" \
"lwz 10,32(11)\n\t" /* arg8->r10 */ \
"lwz 11,0(11)\n\t" /* target->r11 */ \
VALGRIND_BRANCH_AND_LINK_TO_NOREDIR_R11 \
VALGRIND_RESTORE_STACK \
"mr %0,3" \
: /*out*/ "=r" (_res) \
: /*in*/ "r" (&_argvec[0]) \
: /*trash*/ "cc", "memory", __CALLER_SAVED_REGS, "r28" \
); \
lval = (__typeof__(lval)) _res; \
} while (0)
#define CALL_FN_W_10W(lval, orig, arg1,arg2,arg3,arg4,arg5,arg6, \
arg7,arg8,arg9,arg10) \
do { \
volatile OrigFn _orig = (orig); \
volatile unsigned long _argvec[11]; \
volatile unsigned long _res; \
_argvec[0] = (unsigned long)_orig.nraddr; \
_argvec[1] = (unsigned long)arg1; \
_argvec[2] = (unsigned long)arg2; \
_argvec[3] = (unsigned long)arg3; \
_argvec[4] = (unsigned long)arg4; \
_argvec[5] = (unsigned long)arg5; \
_argvec[6] = (unsigned long)arg6; \
_argvec[7] = (unsigned long)arg7; \
_argvec[8] = (unsigned long)arg8; \
_argvec[9] = (unsigned long)arg9; \
_argvec[10] = (unsigned long)arg10; \
__asm__ volatile( \
VALGRIND_ALIGN_STACK \
"mr 11,%1\n\t" \
"addi 1,1,-16\n\t" \
/* arg10 */ \
"lwz 3,40(11)\n\t" \
"stw 3,12(1)\n\t" \
/* arg9 */ \
"lwz 3,36(11)\n\t" \
"stw 3,8(1)\n\t" \
/* args1-8 */ \
"lwz 3,4(11)\n\t" /* arg1->r3 */ \
"lwz 4,8(11)\n\t" \
"lwz 5,12(11)\n\t" \
"lwz 6,16(11)\n\t" /* arg4->r6 */ \
"lwz 7,20(11)\n\t" \
"lwz 8,24(11)\n\t" \
"lwz 9,28(11)\n\t" \
"lwz 10,32(11)\n\t" /* arg8->r10 */ \
"lwz 11,0(11)\n\t" /* target->r11 */ \
VALGRIND_BRANCH_AND_LINK_TO_NOREDIR_R11 \
VALGRIND_RESTORE_STACK \
"mr %0,3" \
: /*out*/ "=r" (_res) \
: /*in*/ "r" (&_argvec[0]) \
: /*trash*/ "cc", "memory", __CALLER_SAVED_REGS, "r28" \
); \
lval = (__typeof__(lval)) _res; \
} while (0)
#define CALL_FN_W_11W(lval, orig, arg1,arg2,arg3,arg4,arg5,arg6, \
arg7,arg8,arg9,arg10,arg11) \
do { \
volatile OrigFn _orig = (orig); \
volatile unsigned long _argvec[12]; \
volatile unsigned long _res; \
_argvec[0] = (unsigned long)_orig.nraddr; \
_argvec[1] = (unsigned long)arg1; \
_argvec[2] = (unsigned long)arg2; \
_argvec[3] = (unsigned long)arg3; \
_argvec[4] = (unsigned long)arg4; \
_argvec[5] = (unsigned long)arg5; \
_argvec[6] = (unsigned long)arg6; \
_argvec[7] = (unsigned long)arg7; \
_argvec[8] = (unsigned long)arg8; \
_argvec[9] = (unsigned long)arg9; \
_argvec[10] = (unsigned long)arg10; \
_argvec[11] = (unsigned long)arg11; \
__asm__ volatile( \
VALGRIND_ALIGN_STACK \
"mr 11,%1\n\t" \
"addi 1,1,-32\n\t" \
/* arg11 */ \
"lwz 3,44(11)\n\t" \
"stw 3,16(1)\n\t" \
/* arg10 */ \
"lwz 3,40(11)\n\t" \
"stw 3,12(1)\n\t" \
/* arg9 */ \
"lwz 3,36(11)\n\t" \
"stw 3,8(1)\n\t" \
/* args1-8 */ \
"lwz 3,4(11)\n\t" /* arg1->r3 */ \
"lwz 4,8(11)\n\t" \
"lwz 5,12(11)\n\t" \
"lwz 6,16(11)\n\t" /* arg4->r6 */ \
"lwz 7,20(11)\n\t" \
"lwz 8,24(11)\n\t" \
"lwz 9,28(11)\n\t" \
"lwz 10,32(11)\n\t" /* arg8->r10 */ \
"lwz 11,0(11)\n\t" /* target->r11 */ \
VALGRIND_BRANCH_AND_LINK_TO_NOREDIR_R11 \
VALGRIND_RESTORE_STACK \
"mr %0,3" \
: /*out*/ "=r" (_res) \
: /*in*/ "r" (&_argvec[0]) \
: /*trash*/ "cc", "memory", __CALLER_SAVED_REGS, "r28" \
); \
lval = (__typeof__(lval)) _res; \
} while (0)
#define CALL_FN_W_12W(lval, orig, arg1,arg2,arg3,arg4,arg5,arg6, \
arg7,arg8,arg9,arg10,arg11,arg12) \
do { \
volatile OrigFn _orig = (orig); \
volatile unsigned long _argvec[13]; \
volatile unsigned long _res; \
_argvec[0] = (unsigned long)_orig.nraddr; \
_argvec[1] = (unsigned long)arg1; \
_argvec[2] = (unsigned long)arg2; \
_argvec[3] = (unsigned long)arg3; \
_argvec[4] = (unsigned long)arg4; \
_argvec[5] = (unsigned long)arg5; \
_argvec[6] = (unsigned long)arg6; \
_argvec[7] = (unsigned long)arg7; \
_argvec[8] = (unsigned long)arg8; \
_argvec[9] = (unsigned long)arg9; \
_argvec[10] = (unsigned long)arg10; \
_argvec[11] = (unsigned long)arg11; \
_argvec[12] = (unsigned long)arg12; \
__asm__ volatile( \
VALGRIND_ALIGN_STACK \
"mr 11,%1\n\t" \
"addi 1,1,-32\n\t" \
/* arg12 */ \
"lwz 3,48(11)\n\t" \
"stw 3,20(1)\n\t" \
/* arg11 */ \
"lwz 3,44(11)\n\t" \
"stw 3,16(1)\n\t" \
/* arg10 */ \
"lwz 3,40(11)\n\t" \
"stw 3,12(1)\n\t" \
/* arg9 */ \
"lwz 3,36(11)\n\t" \
"stw 3,8(1)\n\t" \
/* args1-8 */ \
"lwz 3,4(11)\n\t" /* arg1->r3 */ \
"lwz 4,8(11)\n\t" \
"lwz 5,12(11)\n\t" \
"lwz 6,16(11)\n\t" /* arg4->r6 */ \
"lwz 7,20(11)\n\t" \
"lwz 8,24(11)\n\t" \
"lwz 9,28(11)\n\t" \
"lwz 10,32(11)\n\t" /* arg8->r10 */ \
"lwz 11,0(11)\n\t" /* target->r11 */ \
VALGRIND_BRANCH_AND_LINK_TO_NOREDIR_R11 \
VALGRIND_RESTORE_STACK \
"mr %0,3" \
: /*out*/ "=r" (_res) \
: /*in*/ "r" (&_argvec[0]) \
: /*trash*/ "cc", "memory", __CALLER_SAVED_REGS, "r28" \
); \
lval = (__typeof__(lval)) _res; \
} while (0)
#endif /* PLAT_ppc32_linux */
/* ------------------------ ppc64-linux ------------------------ */
#if defined(PLAT_ppc64be_linux)
/* ARGREGS: r3 r4 r5 r6 r7 r8 r9 r10 (the rest on stack somewhere) */
/* These regs are trashed by the hidden call. */
#define __CALLER_SAVED_REGS \
"lr", "ctr", "xer", \
"cr0", "cr1", "cr2", "cr3", "cr4", "cr5", "cr6", "cr7", \
"r0", "r3", "r4", "r5", "r6", "r7", "r8", "r9", "r10", \
"r11", "r12", "r13"
/* Macros to save and align the stack before making a function
call and restore it afterwards as gcc may not keep the stack
pointer aligned if it doesn't realise calls are being made
to other functions. */
#define VALGRIND_ALIGN_STACK \
"mr 28,1\n\t" \
"rldicr 1,1,0,59\n\t"
#define VALGRIND_RESTORE_STACK \
"mr 1,28\n\t"
/* These CALL_FN_ macros assume that on ppc64-linux, sizeof(unsigned
long) == 8. */
#define CALL_FN_W_v(lval, orig) \
do { \
volatile OrigFn _orig = (orig); \
volatile unsigned long _argvec[3+0]; \
volatile unsigned long _res; \
/* _argvec[0] holds current r2 across the call */ \
_argvec[1] = (unsigned long)_orig.r2; \
_argvec[2] = (unsigned long)_orig.nraddr; \
__asm__ volatile( \
VALGRIND_ALIGN_STACK \
"mr 11,%1\n\t" \
"std 2,-16(11)\n\t" /* save tocptr */ \
"ld 2,-8(11)\n\t" /* use nraddr's tocptr */ \
"ld 11, 0(11)\n\t" /* target->r11 */ \
VALGRIND_BRANCH_AND_LINK_TO_NOREDIR_R11 \
"mr 11,%1\n\t" \
"mr %0,3\n\t" \
"ld 2,-16(11)\n\t" /* restore tocptr */ \
VALGRIND_RESTORE_STACK \
: /*out*/ "=r" (_res) \
: /*in*/ "r" (&_argvec[2]) \
: /*trash*/ "cc", "memory", __CALLER_SAVED_REGS, "r28" \
); \
lval = (__typeof__(lval)) _res; \
} while (0)
#define CALL_FN_W_W(lval, orig, arg1) \
do { \
volatile OrigFn _orig = (orig); \
volatile unsigned long _argvec[3+1]; \
volatile unsigned long _res; \
/* _argvec[0] holds current r2 across the call */ \
_argvec[1] = (unsigned long)_orig.r2; \
_argvec[2] = (unsigned long)_orig.nraddr; \
_argvec[2+1] = (unsigned long)arg1; \
__asm__ volatile( \
VALGRIND_ALIGN_STACK \
"mr 11,%1\n\t" \
"std 2,-16(11)\n\t" /* save tocptr */ \
"ld 2,-8(11)\n\t" /* use nraddr's tocptr */ \
"ld 3, 8(11)\n\t" /* arg1->r3 */ \
"ld 11, 0(11)\n\t" /* target->r11 */ \
VALGRIND_BRANCH_AND_LINK_TO_NOREDIR_R11 \
"mr 11,%1\n\t" \
"mr %0,3\n\t" \
"ld 2,-16(11)\n\t" /* restore tocptr */ \
VALGRIND_RESTORE_STACK \
: /*out*/ "=r" (_res) \
: /*in*/ "r" (&_argvec[2]) \
: /*trash*/ "cc", "memory", __CALLER_SAVED_REGS, "r28" \
); \
lval = (__typeof__(lval)) _res; \
} while (0)
#define CALL_FN_W_WW(lval, orig, arg1,arg2) \
do { \
volatile OrigFn _orig = (orig); \
volatile unsigned long _argvec[3+2]; \
volatile unsigned long _res; \
/* _argvec[0] holds current r2 across the call */ \
_argvec[1] = (unsigned long)_orig.r2; \
_argvec[2] = (unsigned long)_orig.nraddr; \
_argvec[2+1] = (unsigned long)arg1; \
_argvec[2+2] = (unsigned long)arg2; \
__asm__ volatile( \
VALGRIND_ALIGN_STACK \
"mr 11,%1\n\t" \
"std 2,-16(11)\n\t" /* save tocptr */ \
"ld 2,-8(11)\n\t" /* use nraddr's tocptr */ \
"ld 3, 8(11)\n\t" /* arg1->r3 */ \
"ld 4, 16(11)\n\t" /* arg2->r4 */ \
"ld 11, 0(11)\n\t" /* target->r11 */ \
VALGRIND_BRANCH_AND_LINK_TO_NOREDIR_R11 \
"mr 11,%1\n\t" \
"mr %0,3\n\t" \
"ld 2,-16(11)\n\t" /* restore tocptr */ \
VALGRIND_RESTORE_STACK \
: /*out*/ "=r" (_res) \
: /*in*/ "r" (&_argvec[2]) \
: /*trash*/ "cc", "memory", __CALLER_SAVED_REGS, "r28" \
); \
lval = (__typeof__(lval)) _res; \
} while (0)
#define CALL_FN_W_WWW(lval, orig, arg1,arg2,arg3) \
do { \
volatile OrigFn _orig = (orig); \
volatile unsigned long _argvec[3+3]; \
volatile unsigned long _res; \
/* _argvec[0] holds current r2 across the call */ \
_argvec[1] = (unsigned long)_orig.r2; \
_argvec[2] = (unsigned long)_orig.nraddr; \
_argvec[2+1] = (unsigned long)arg1; \
_argvec[2+2] = (unsigned long)arg2; \
_argvec[2+3] = (unsigned long)arg3; \
__asm__ volatile( \
VALGRIND_ALIGN_STACK \
"mr 11,%1\n\t" \
"std 2,-16(11)\n\t" /* save tocptr */ \
"ld 2,-8(11)\n\t" /* use nraddr's tocptr */ \
"ld 3, 8(11)\n\t" /* arg1->r3 */ \
"ld 4, 16(11)\n\t" /* arg2->r4 */ \
"ld 5, 24(11)\n\t" /* arg3->r5 */ \
"ld 11, 0(11)\n\t" /* target->r11 */ \
VALGRIND_BRANCH_AND_LINK_TO_NOREDIR_R11 \
"mr 11,%1\n\t" \
"mr %0,3\n\t" \
"ld 2,-16(11)\n\t" /* restore tocptr */ \
VALGRIND_RESTORE_STACK \
: /*out*/ "=r" (_res) \
: /*in*/ "r" (&_argvec[2]) \
: /*trash*/ "cc", "memory", __CALLER_SAVED_REGS, "r28" \
); \
lval = (__typeof__(lval)) _res; \
} while (0)
#define CALL_FN_W_WWWW(lval, orig, arg1,arg2,arg3,arg4) \
do { \
volatile OrigFn _orig = (orig); \
volatile unsigned long _argvec[3+4]; \
volatile unsigned long _res; \
/* _argvec[0] holds current r2 across the call */ \
_argvec[1] = (unsigned long)_orig.r2; \
_argvec[2] = (unsigned long)_orig.nraddr; \
_argvec[2+1] = (unsigned long)arg1; \
_argvec[2+2] = (unsigned long)arg2; \
_argvec[2+3] = (unsigned long)arg3; \
_argvec[2+4] = (unsigned long)arg4; \
__asm__ volatile( \
VALGRIND_ALIGN_STACK \
"mr 11,%1\n\t" \
"std 2,-16(11)\n\t" /* save tocptr */ \
"ld 2,-8(11)\n\t" /* use nraddr's tocptr */ \
"ld 3, 8(11)\n\t" /* arg1->r3 */ \
"ld 4, 16(11)\n\t" /* arg2->r4 */ \
"ld 5, 24(11)\n\t" /* arg3->r5 */ \
"ld 6, 32(11)\n\t" /* arg4->r6 */ \
"ld 11, 0(11)\n\t" /* target->r11 */ \
VALGRIND_BRANCH_AND_LINK_TO_NOREDIR_R11 \
"mr 11,%1\n\t" \
"mr %0,3\n\t" \
"ld 2,-16(11)\n\t" /* restore tocptr */ \
VALGRIND_RESTORE_STACK \
: /*out*/ "=r" (_res) \
: /*in*/ "r" (&_argvec[2]) \
: /*trash*/ "cc", "memory", __CALLER_SAVED_REGS, "r28" \
); \
lval = (__typeof__(lval)) _res; \
} while (0)
#define CALL_FN_W_5W(lval, orig, arg1,arg2,arg3,arg4,arg5) \
do { \
volatile OrigFn _orig = (orig); \
volatile unsigned long _argvec[3+5]; \
volatile unsigned long _res; \
/* _argvec[0] holds current r2 across the call */ \
_argvec[1] = (unsigned long)_orig.r2; \
_argvec[2] = (unsigned long)_orig.nraddr; \
_argvec[2+1] = (unsigned long)arg1; \
_argvec[2+2] = (unsigned long)arg2; \
_argvec[2+3] = (unsigned long)arg3; \
_argvec[2+4] = (unsigned long)arg4; \
_argvec[2+5] = (unsigned long)arg5; \
__asm__ volatile( \
VALGRIND_ALIGN_STACK \
"mr 11,%1\n\t" \
"std 2,-16(11)\n\t" /* save tocptr */ \
"ld 2,-8(11)\n\t" /* use nraddr's tocptr */ \
"ld 3, 8(11)\n\t" /* arg1->r3 */ \
"ld 4, 16(11)\n\t" /* arg2->r4 */ \
"ld 5, 24(11)\n\t" /* arg3->r5 */ \
"ld 6, 32(11)\n\t" /* arg4->r6 */ \
"ld 7, 40(11)\n\t" /* arg5->r7 */ \
"ld 11, 0(11)\n\t" /* target->r11 */ \
VALGRIND_BRANCH_AND_LINK_TO_NOREDIR_R11 \
"mr 11,%1\n\t" \
"mr %0,3\n\t" \
"ld 2,-16(11)\n\t" /* restore tocptr */ \
VALGRIND_RESTORE_STACK \
: /*out*/ "=r" (_res) \
: /*in*/ "r" (&_argvec[2]) \
: /*trash*/ "cc", "memory", __CALLER_SAVED_REGS, "r28" \
); \
lval = (__typeof__(lval)) _res; \
} while (0)
#define CALL_FN_W_6W(lval, orig, arg1,arg2,arg3,arg4,arg5,arg6) \
do { \
volatile OrigFn _orig = (orig); \
volatile unsigned long _argvec[3+6]; \
volatile unsigned long _res; \
/* _argvec[0] holds current r2 across the call */ \
_argvec[1] = (unsigned long)_orig.r2; \
_argvec[2] = (unsigned long)_orig.nraddr; \
_argvec[2+1] = (unsigned long)arg1; \
_argvec[2+2] = (unsigned long)arg2; \
_argvec[2+3] = (unsigned long)arg3; \
_argvec[2+4] = (unsigned long)arg4; \
_argvec[2+5] = (unsigned long)arg5; \
_argvec[2+6] = (unsigned long)arg6; \
__asm__ volatile( \
VALGRIND_ALIGN_STACK \
"mr 11,%1\n\t" \
"std 2,-16(11)\n\t" /* save tocptr */ \
"ld 2,-8(11)\n\t" /* use nraddr's tocptr */ \
"ld 3, 8(11)\n\t" /* arg1->r3 */ \
"ld 4, 16(11)\n\t" /* arg2->r4 */ \
"ld 5, 24(11)\n\t" /* arg3->r5 */ \
"ld 6, 32(11)\n\t" /* arg4->r6 */ \
"ld 7, 40(11)\n\t" /* arg5->r7 */ \
"ld 8, 48(11)\n\t" /* arg6->r8 */ \
"ld 11, 0(11)\n\t" /* target->r11 */ \
VALGRIND_BRANCH_AND_LINK_TO_NOREDIR_R11 \
"mr 11,%1\n\t" \
"mr %0,3\n\t" \
"ld 2,-16(11)\n\t" /* restore tocptr */ \
VALGRIND_RESTORE_STACK \
: /*out*/ "=r" (_res) \
: /*in*/ "r" (&_argvec[2]) \
: /*trash*/ "cc", "memory", __CALLER_SAVED_REGS, "r28" \
); \
lval = (__typeof__(lval)) _res; \
} while (0)
#define CALL_FN_W_7W(lval, orig, arg1,arg2,arg3,arg4,arg5,arg6, \
arg7) \
do { \
volatile OrigFn _orig = (orig); \
volatile unsigned long _argvec[3+7]; \
volatile unsigned long _res; \
/* _argvec[0] holds current r2 across the call */ \
_argvec[1] = (unsigned long)_orig.r2; \
_argvec[2] = (unsigned long)_orig.nraddr; \
_argvec[2+1] = (unsigned long)arg1; \
_argvec[2+2] = (unsigned long)arg2; \
_argvec[2+3] = (unsigned long)arg3; \
_argvec[2+4] = (unsigned long)arg4; \
_argvec[2+5] = (unsigned long)arg5; \
_argvec[2+6] = (unsigned long)arg6; \
_argvec[2+7] = (unsigned long)arg7; \
__asm__ volatile( \
VALGRIND_ALIGN_STACK \
"mr 11,%1\n\t" \
"std 2,-16(11)\n\t" /* save tocptr */ \
"ld 2,-8(11)\n\t" /* use nraddr's tocptr */ \
"ld 3, 8(11)\n\t" /* arg1->r3 */ \
"ld 4, 16(11)\n\t" /* arg2->r4 */ \
"ld 5, 24(11)\n\t" /* arg3->r5 */ \
"ld 6, 32(11)\n\t" /* arg4->r6 */ \
"ld 7, 40(11)\n\t" /* arg5->r7 */ \
"ld 8, 48(11)\n\t" /* arg6->r8 */ \
"ld 9, 56(11)\n\t" /* arg7->r9 */ \
"ld 11, 0(11)\n\t" /* target->r11 */ \
VALGRIND_BRANCH_AND_LINK_TO_NOREDIR_R11 \
"mr 11,%1\n\t" \
"mr %0,3\n\t" \
"ld 2,-16(11)\n\t" /* restore tocptr */ \
VALGRIND_RESTORE_STACK \
: /*out*/ "=r" (_res) \
: /*in*/ "r" (&_argvec[2]) \
: /*trash*/ "cc", "memory", __CALLER_SAVED_REGS, "r28" \
); \
lval = (__typeof__(lval)) _res; \
} while (0)
#define CALL_FN_W_8W(lval, orig, arg1,arg2,arg3,arg4,arg5,arg6, \
arg7,arg8) \
do { \
volatile OrigFn _orig = (orig); \
volatile unsigned long _argvec[3+8]; \
volatile unsigned long _res; \
/* _argvec[0] holds current r2 across the call */ \
_argvec[1] = (unsigned long)_orig.r2; \
_argvec[2] = (unsigned long)_orig.nraddr; \
_argvec[2+1] = (unsigned long)arg1; \
_argvec[2+2] = (unsigned long)arg2; \
_argvec[2+3] = (unsigned long)arg3; \
_argvec[2+4] = (unsigned long)arg4; \
_argvec[2+5] = (unsigned long)arg5; \
_argvec[2+6] = (unsigned long)arg6; \
_argvec[2+7] = (unsigned long)arg7; \
_argvec[2+8] = (unsigned long)arg8; \
__asm__ volatile( \
VALGRIND_ALIGN_STACK \
"mr 11,%1\n\t" \
"std 2,-16(11)\n\t" /* save tocptr */ \
"ld 2,-8(11)\n\t" /* use nraddr's tocptr */ \
"ld 3, 8(11)\n\t" /* arg1->r3 */ \
"ld 4, 16(11)\n\t" /* arg2->r4 */ \
"ld 5, 24(11)\n\t" /* arg3->r5 */ \
"ld 6, 32(11)\n\t" /* arg4->r6 */ \
"ld 7, 40(11)\n\t" /* arg5->r7 */ \
"ld 8, 48(11)\n\t" /* arg6->r8 */ \
"ld 9, 56(11)\n\t" /* arg7->r9 */ \
"ld 10, 64(11)\n\t" /* arg8->r10 */ \
"ld 11, 0(11)\n\t" /* target->r11 */ \
VALGRIND_BRANCH_AND_LINK_TO_NOREDIR_R11 \
"mr 11,%1\n\t" \
"mr %0,3\n\t" \
"ld 2,-16(11)\n\t" /* restore tocptr */ \
VALGRIND_RESTORE_STACK \
: /*out*/ "=r" (_res) \
: /*in*/ "r" (&_argvec[2]) \
: /*trash*/ "cc", "memory", __CALLER_SAVED_REGS, "r28" \
); \
lval = (__typeof__(lval)) _res; \
} while (0)
#define CALL_FN_W_9W(lval, orig, arg1,arg2,arg3,arg4,arg5,arg6, \
arg7,arg8,arg9) \
do { \
volatile OrigFn _orig = (orig); \
volatile unsigned long _argvec[3+9]; \
volatile unsigned long _res; \
/* _argvec[0] holds current r2 across the call */ \
_argvec[1] = (unsigned long)_orig.r2; \
_argvec[2] = (unsigned long)_orig.nraddr; \
_argvec[2+1] = (unsigned long)arg1; \
_argvec[2+2] = (unsigned long)arg2; \
_argvec[2+3] = (unsigned long)arg3; \
_argvec[2+4] = (unsigned long)arg4; \
_argvec[2+5] = (unsigned long)arg5; \
_argvec[2+6] = (unsigned long)arg6; \
_argvec[2+7] = (unsigned long)arg7; \
_argvec[2+8] = (unsigned long)arg8; \
_argvec[2+9] = (unsigned long)arg9; \
__asm__ volatile( \
VALGRIND_ALIGN_STACK \
"mr 11,%1\n\t" \
"std 2,-16(11)\n\t" /* save tocptr */ \
"ld 2,-8(11)\n\t" /* use nraddr's tocptr */ \
"addi 1,1,-128\n\t" /* expand stack frame */ \
/* arg9 */ \
"ld 3,72(11)\n\t" \
"std 3,112(1)\n\t" \
/* args1-8 */ \
"ld 3, 8(11)\n\t" /* arg1->r3 */ \
"ld 4, 16(11)\n\t" /* arg2->r4 */ \
"ld 5, 24(11)\n\t" /* arg3->r5 */ \
"ld 6, 32(11)\n\t" /* arg4->r6 */ \
"ld 7, 40(11)\n\t" /* arg5->r7 */ \
"ld 8, 48(11)\n\t" /* arg6->r8 */ \
"ld 9, 56(11)\n\t" /* arg7->r9 */ \
"ld 10, 64(11)\n\t" /* arg8->r10 */ \
"ld 11, 0(11)\n\t" /* target->r11 */ \
VALGRIND_BRANCH_AND_LINK_TO_NOREDIR_R11 \
"mr 11,%1\n\t" \
"mr %0,3\n\t" \
"ld 2,-16(11)\n\t" /* restore tocptr */ \
VALGRIND_RESTORE_STACK \
: /*out*/ "=r" (_res) \
: /*in*/ "r" (&_argvec[2]) \
: /*trash*/ "cc", "memory", __CALLER_SAVED_REGS, "r28" \
); \
lval = (__typeof__(lval)) _res; \
} while (0)
#define CALL_FN_W_10W(lval, orig, arg1,arg2,arg3,arg4,arg5,arg6, \
arg7,arg8,arg9,arg10) \
do { \
volatile OrigFn _orig = (orig); \
volatile unsigned long _argvec[3+10]; \
volatile unsigned long _res; \
/* _argvec[0] holds current r2 across the call */ \
_argvec[1] = (unsigned long)_orig.r2; \
_argvec[2] = (unsigned long)_orig.nraddr; \
_argvec[2+1] = (unsigned long)arg1; \
_argvec[2+2] = (unsigned long)arg2; \
_argvec[2+3] = (unsigned long)arg3; \
_argvec[2+4] = (unsigned long)arg4; \
_argvec[2+5] = (unsigned long)arg5; \
_argvec[2+6] = (unsigned long)arg6; \
_argvec[2+7] = (unsigned long)arg7; \
_argvec[2+8] = (unsigned long)arg8; \
_argvec[2+9] = (unsigned long)arg9; \
_argvec[2+10] = (unsigned long)arg10; \
__asm__ volatile( \
VALGRIND_ALIGN_STACK \
"mr 11,%1\n\t" \
"std 2,-16(11)\n\t" /* save tocptr */ \
"ld 2,-8(11)\n\t" /* use nraddr's tocptr */ \
"addi 1,1,-128\n\t" /* expand stack frame */ \
/* arg10 */ \
"ld 3,80(11)\n\t" \
"std 3,120(1)\n\t" \
/* arg9 */ \
"ld 3,72(11)\n\t" \
"std 3,112(1)\n\t" \
/* args1-8 */ \
"ld 3, 8(11)\n\t" /* arg1->r3 */ \
"ld 4, 16(11)\n\t" /* arg2->r4 */ \
"ld 5, 24(11)\n\t" /* arg3->r5 */ \
"ld 6, 32(11)\n\t" /* arg4->r6 */ \
"ld 7, 40(11)\n\t" /* arg5->r7 */ \
"ld 8, 48(11)\n\t" /* arg6->r8 */ \
"ld 9, 56(11)\n\t" /* arg7->r9 */ \
"ld 10, 64(11)\n\t" /* arg8->r10 */ \
"ld 11, 0(11)\n\t" /* target->r11 */ \
VALGRIND_BRANCH_AND_LINK_TO_NOREDIR_R11 \
"mr 11,%1\n\t" \
"mr %0,3\n\t" \
"ld 2,-16(11)\n\t" /* restore tocptr */ \
VALGRIND_RESTORE_STACK \
: /*out*/ "=r" (_res) \
: /*in*/ "r" (&_argvec[2]) \
: /*trash*/ "cc", "memory", __CALLER_SAVED_REGS, "r28" \
); \
lval = (__typeof__(lval)) _res; \
} while (0)
#define CALL_FN_W_11W(lval, orig, arg1,arg2,arg3,arg4,arg5,arg6, \
arg7,arg8,arg9,arg10,arg11) \
do { \
volatile OrigFn _orig = (orig); \
volatile unsigned long _argvec[3+11]; \
volatile unsigned long _res; \
/* _argvec[0] holds current r2 across the call */ \
_argvec[1] = (unsigned long)_orig.r2; \
_argvec[2] = (unsigned long)_orig.nraddr; \
_argvec[2+1] = (unsigned long)arg1; \
_argvec[2+2] = (unsigned long)arg2; \
_argvec[2+3] = (unsigned long)arg3; \
_argvec[2+4] = (unsigned long)arg4; \
_argvec[2+5] = (unsigned long)arg5; \
_argvec[2+6] = (unsigned long)arg6; \
_argvec[2+7] = (unsigned long)arg7; \
_argvec[2+8] = (unsigned long)arg8; \
_argvec[2+9] = (unsigned long)arg9; \
_argvec[2+10] = (unsigned long)arg10; \
_argvec[2+11] = (unsigned long)arg11; \
__asm__ volatile( \
VALGRIND_ALIGN_STACK \
"mr 11,%1\n\t" \
"std 2,-16(11)\n\t" /* save tocptr */ \
"ld 2,-8(11)\n\t" /* use nraddr's tocptr */ \
"addi 1,1,-144\n\t" /* expand stack frame */ \
/* arg11 */ \
"ld 3,88(11)\n\t" \
"std 3,128(1)\n\t" \
/* arg10 */ \
"ld 3,80(11)\n\t" \
"std 3,120(1)\n\t" \
/* arg9 */ \
"ld 3,72(11)\n\t" \
"std 3,112(1)\n\t" \
/* args1-8 */ \
"ld 3, 8(11)\n\t" /* arg1->r3 */ \
"ld 4, 16(11)\n\t" /* arg2->r4 */ \
"ld 5, 24(11)\n\t" /* arg3->r5 */ \
"ld 6, 32(11)\n\t" /* arg4->r6 */ \
"ld 7, 40(11)\n\t" /* arg5->r7 */ \
"ld 8, 48(11)\n\t" /* arg6->r8 */ \
"ld 9, 56(11)\n\t" /* arg7->r9 */ \
"ld 10, 64(11)\n\t" /* arg8->r10 */ \
"ld 11, 0(11)\n\t" /* target->r11 */ \
VALGRIND_BRANCH_AND_LINK_TO_NOREDIR_R11 \
"mr 11,%1\n\t" \
"mr %0,3\n\t" \
"ld 2,-16(11)\n\t" /* restore tocptr */ \
VALGRIND_RESTORE_STACK \
: /*out*/ "=r" (_res) \
: /*in*/ "r" (&_argvec[2]) \
: /*trash*/ "cc", "memory", __CALLER_SAVED_REGS, "r28" \
); \
lval = (__typeof__(lval)) _res; \
} while (0)
#define CALL_FN_W_12W(lval, orig, arg1,arg2,arg3,arg4,arg5,arg6, \
arg7,arg8,arg9,arg10,arg11,arg12) \
do { \
volatile OrigFn _orig = (orig); \
volatile unsigned long _argvec[3+12]; \
volatile unsigned long _res; \
/* _argvec[0] holds current r2 across the call */ \
_argvec[1] = (unsigned long)_orig.r2; \
_argvec[2] = (unsigned long)_orig.nraddr; \
_argvec[2+1] = (unsigned long)arg1; \
_argvec[2+2] = (unsigned long)arg2; \
_argvec[2+3] = (unsigned long)arg3; \
_argvec[2+4] = (unsigned long)arg4; \
_argvec[2+5] = (unsigned long)arg5; \
_argvec[2+6] = (unsigned long)arg6; \
_argvec[2+7] = (unsigned long)arg7; \
_argvec[2+8] = (unsigned long)arg8; \
_argvec[2+9] = (unsigned long)arg9; \
_argvec[2+10] = (unsigned long)arg10; \
_argvec[2+11] = (unsigned long)arg11; \
_argvec[2+12] = (unsigned long)arg12; \
__asm__ volatile( \
VALGRIND_ALIGN_STACK \
"mr 11,%1\n\t" \
"std 2,-16(11)\n\t" /* save tocptr */ \
"ld 2,-8(11)\n\t" /* use nraddr's tocptr */ \
"addi 1,1,-144\n\t" /* expand stack frame */ \
/* arg12 */ \
"ld 3,96(11)\n\t" \
"std 3,136(1)\n\t" \
/* arg11 */ \
"ld 3,88(11)\n\t" \
"std 3,128(1)\n\t" \
/* arg10 */ \
"ld 3,80(11)\n\t" \
"std 3,120(1)\n\t" \
/* arg9 */ \
"ld 3,72(11)\n\t" \
"std 3,112(1)\n\t" \
/* args1-8 */ \
"ld 3, 8(11)\n\t" /* arg1->r3 */ \
"ld 4, 16(11)\n\t" /* arg2->r4 */ \
"ld 5, 24(11)\n\t" /* arg3->r5 */ \
"ld 6, 32(11)\n\t" /* arg4->r6 */ \
"ld 7, 40(11)\n\t" /* arg5->r7 */ \
"ld 8, 48(11)\n\t" /* arg6->r8 */ \
"ld 9, 56(11)\n\t" /* arg7->r9 */ \
"ld 10, 64(11)\n\t" /* arg8->r10 */ \
"ld 11, 0(11)\n\t" /* target->r11 */ \
VALGRIND_BRANCH_AND_LINK_TO_NOREDIR_R11 \
"mr 11,%1\n\t" \
"mr %0,3\n\t" \
"ld 2,-16(11)\n\t" /* restore tocptr */ \
VALGRIND_RESTORE_STACK \
: /*out*/ "=r" (_res) \
: /*in*/ "r" (&_argvec[2]) \
: /*trash*/ "cc", "memory", __CALLER_SAVED_REGS, "r28" \
); \
lval = (__typeof__(lval)) _res; \
} while (0)
#endif /* PLAT_ppc64be_linux */
/* ------------------------- ppc64le-linux ----------------------- */
#if defined(PLAT_ppc64le_linux)
/* ARGREGS: r3 r4 r5 r6 r7 r8 r9 r10 (the rest on stack somewhere) */
/* These regs are trashed by the hidden call. */
#define __CALLER_SAVED_REGS \
"lr", "ctr", "xer", \
"cr0", "cr1", "cr2", "cr3", "cr4", "cr5", "cr6", "cr7", \
"r0", "r3", "r4", "r5", "r6", "r7", "r8", "r9", "r10", \
"r11", "r12", "r13"
/* Macros to save and align the stack before making a function
call and restore it afterwards as gcc may not keep the stack
pointer aligned if it doesn't realise calls are being made
to other functions. */
#define VALGRIND_ALIGN_STACK \
"mr 28,1\n\t" \
"rldicr 1,1,0,59\n\t"
#define VALGRIND_RESTORE_STACK \
"mr 1,28\n\t"
/* These CALL_FN_ macros assume that on ppc64-linux, sizeof(unsigned
long) == 8. */
#define CALL_FN_W_v(lval, orig) \
do { \
volatile OrigFn _orig = (orig); \
volatile unsigned long _argvec[3+0]; \
volatile unsigned long _res; \
/* _argvec[0] holds current r2 across the call */ \
_argvec[1] = (unsigned long)_orig.r2; \
_argvec[2] = (unsigned long)_orig.nraddr; \
__asm__ volatile( \
VALGRIND_ALIGN_STACK \
"mr 12,%1\n\t" \
"std 2,-16(12)\n\t" /* save tocptr */ \
"ld 2,-8(12)\n\t" /* use nraddr's tocptr */ \
"ld 12, 0(12)\n\t" /* target->r12 */ \
VALGRIND_BRANCH_AND_LINK_TO_NOREDIR_R12 \
"mr 12,%1\n\t" \
"mr %0,3\n\t" \
"ld 2,-16(12)\n\t" /* restore tocptr */ \
VALGRIND_RESTORE_STACK \
: /*out*/ "=r" (_res) \
: /*in*/ "r" (&_argvec[2]) \
: /*trash*/ "cc", "memory", __CALLER_SAVED_REGS, "r28" \
); \
lval = (__typeof__(lval)) _res; \
} while (0)
#define CALL_FN_W_W(lval, orig, arg1) \
do { \
volatile OrigFn _orig = (orig); \
volatile unsigned long _argvec[3+1]; \
volatile unsigned long _res; \
/* _argvec[0] holds current r2 across the call */ \
_argvec[1] = (unsigned long)_orig.r2; \
_argvec[2] = (unsigned long)_orig.nraddr; \
_argvec[2+1] = (unsigned long)arg1; \
__asm__ volatile( \
VALGRIND_ALIGN_STACK \
"mr 12,%1\n\t" \
"std 2,-16(12)\n\t" /* save tocptr */ \
"ld 2,-8(12)\n\t" /* use nraddr's tocptr */ \
"ld 3, 8(12)\n\t" /* arg1->r3 */ \
"ld 12, 0(12)\n\t" /* target->r12 */ \
VALGRIND_BRANCH_AND_LINK_TO_NOREDIR_R12 \
"mr 12,%1\n\t" \
"mr %0,3\n\t" \
"ld 2,-16(12)\n\t" /* restore tocptr */ \
VALGRIND_RESTORE_STACK \
: /*out*/ "=r" (_res) \
: /*in*/ "r" (&_argvec[2]) \
: /*trash*/ "cc", "memory", __CALLER_SAVED_REGS, "r28" \
); \
lval = (__typeof__(lval)) _res; \
} while (0)
#define CALL_FN_W_WW(lval, orig, arg1,arg2) \
do { \
volatile OrigFn _orig = (orig); \
volatile unsigned long _argvec[3+2]; \
volatile unsigned long _res; \
/* _argvec[0] holds current r2 across the call */ \
_argvec[1] = (unsigned long)_orig.r2; \
_argvec[2] = (unsigned long)_orig.nraddr; \
_argvec[2+1] = (unsigned long)arg1; \
_argvec[2+2] = (unsigned long)arg2; \
__asm__ volatile( \
VALGRIND_ALIGN_STACK \
"mr 12,%1\n\t" \
"std 2,-16(12)\n\t" /* save tocptr */ \
"ld 2,-8(12)\n\t" /* use nraddr's tocptr */ \
"ld 3, 8(12)\n\t" /* arg1->r3 */ \
"ld 4, 16(12)\n\t" /* arg2->r4 */ \
"ld 12, 0(12)\n\t" /* target->r12 */ \
VALGRIND_BRANCH_AND_LINK_TO_NOREDIR_R12 \
"mr 12,%1\n\t" \
"mr %0,3\n\t" \
"ld 2,-16(12)\n\t" /* restore tocptr */ \
VALGRIND_RESTORE_STACK \
: /*out*/ "=r" (_res) \
: /*in*/ "r" (&_argvec[2]) \
: /*trash*/ "cc", "memory", __CALLER_SAVED_REGS, "r28" \
); \
lval = (__typeof__(lval)) _res; \
} while (0)
#define CALL_FN_W_WWW(lval, orig, arg1,arg2,arg3) \
do { \
volatile OrigFn _orig = (orig); \
volatile unsigned long _argvec[3+3]; \
volatile unsigned long _res; \
/* _argvec[0] holds current r2 across the call */ \
_argvec[1] = (unsigned long)_orig.r2; \
_argvec[2] = (unsigned long)_orig.nraddr; \
_argvec[2+1] = (unsigned long)arg1; \
_argvec[2+2] = (unsigned long)arg2; \
_argvec[2+3] = (unsigned long)arg3; \
__asm__ volatile( \
VALGRIND_ALIGN_STACK \
"mr 12,%1\n\t" \
"std 2,-16(12)\n\t" /* save tocptr */ \
"ld 2,-8(12)\n\t" /* use nraddr's tocptr */ \
"ld 3, 8(12)\n\t" /* arg1->r3 */ \
"ld 4, 16(12)\n\t" /* arg2->r4 */ \
"ld 5, 24(12)\n\t" /* arg3->r5 */ \
"ld 12, 0(12)\n\t" /* target->r12 */ \
VALGRIND_BRANCH_AND_LINK_TO_NOREDIR_R12 \
"mr 12,%1\n\t" \
"mr %0,3\n\t" \
"ld 2,-16(12)\n\t" /* restore tocptr */ \
VALGRIND_RESTORE_STACK \
: /*out*/ "=r" (_res) \
: /*in*/ "r" (&_argvec[2]) \
: /*trash*/ "cc", "memory", __CALLER_SAVED_REGS, "r28" \
); \
lval = (__typeof__(lval)) _res; \
} while (0)
#define CALL_FN_W_WWWW(lval, orig, arg1,arg2,arg3,arg4) \
do { \
volatile OrigFn _orig = (orig); \
volatile unsigned long _argvec[3+4]; \
volatile unsigned long _res; \
/* _argvec[0] holds current r2 across the call */ \
_argvec[1] = (unsigned long)_orig.r2; \
_argvec[2] = (unsigned long)_orig.nraddr; \
_argvec[2+1] = (unsigned long)arg1; \
_argvec[2+2] = (unsigned long)arg2; \
_argvec[2+3] = (unsigned long)arg3; \
_argvec[2+4] = (unsigned long)arg4; \
__asm__ volatile( \
VALGRIND_ALIGN_STACK \
"mr 12,%1\n\t" \
"std 2,-16(12)\n\t" /* save tocptr */ \
"ld 2,-8(12)\n\t" /* use nraddr's tocptr */ \
"ld 3, 8(12)\n\t" /* arg1->r3 */ \
"ld 4, 16(12)\n\t" /* arg2->r4 */ \
"ld 5, 24(12)\n\t" /* arg3->r5 */ \
"ld 6, 32(12)\n\t" /* arg4->r6 */ \
"ld 12, 0(12)\n\t" /* target->r12 */ \
VALGRIND_BRANCH_AND_LINK_TO_NOREDIR_R12 \
"mr 12,%1\n\t" \
"mr %0,3\n\t" \
"ld 2,-16(12)\n\t" /* restore tocptr */ \
VALGRIND_RESTORE_STACK \
: /*out*/ "=r" (_res) \
: /*in*/ "r" (&_argvec[2]) \
: /*trash*/ "cc", "memory", __CALLER_SAVED_REGS, "r28" \
); \
lval = (__typeof__(lval)) _res; \
} while (0)
#define CALL_FN_W_5W(lval, orig, arg1,arg2,arg3,arg4,arg5) \
do { \
volatile OrigFn _orig = (orig); \
volatile unsigned long _argvec[3+5]; \
volatile unsigned long _res; \
/* _argvec[0] holds current r2 across the call */ \
_argvec[1] = (unsigned long)_orig.r2; \
_argvec[2] = (unsigned long)_orig.nraddr; \
_argvec[2+1] = (unsigned long)arg1; \
_argvec[2+2] = (unsigned long)arg2; \
_argvec[2+3] = (unsigned long)arg3; \
_argvec[2+4] = (unsigned long)arg4; \
_argvec[2+5] = (unsigned long)arg5; \
__asm__ volatile( \
VALGRIND_ALIGN_STACK \
"mr 12,%1\n\t" \
"std 2,-16(12)\n\t" /* save tocptr */ \
"ld 2,-8(12)\n\t" /* use nraddr's tocptr */ \
"ld 3, 8(12)\n\t" /* arg1->r3 */ \
"ld 4, 16(12)\n\t" /* arg2->r4 */ \
"ld 5, 24(12)\n\t" /* arg3->r5 */ \
"ld 6, 32(12)\n\t" /* arg4->r6 */ \
"ld 7, 40(12)\n\t" /* arg5->r7 */ \
"ld 12, 0(12)\n\t" /* target->r12 */ \
VALGRIND_BRANCH_AND_LINK_TO_NOREDIR_R12 \
"mr 12,%1\n\t" \
"mr %0,3\n\t" \
"ld 2,-16(12)\n\t" /* restore tocptr */ \
VALGRIND_RESTORE_STACK \
: /*out*/ "=r" (_res) \
: /*in*/ "r" (&_argvec[2]) \
: /*trash*/ "cc", "memory", __CALLER_SAVED_REGS, "r28" \
); \
lval = (__typeof__(lval)) _res; \
} while (0)
#define CALL_FN_W_6W(lval, orig, arg1,arg2,arg3,arg4,arg5,arg6) \
do { \
volatile OrigFn _orig = (orig); \
volatile unsigned long _argvec[3+6]; \
volatile unsigned long _res; \
/* _argvec[0] holds current r2 across the call */ \
_argvec[1] = (unsigned long)_orig.r2; \
_argvec[2] = (unsigned long)_orig.nraddr; \
_argvec[2+1] = (unsigned long)arg1; \
_argvec[2+2] = (unsigned long)arg2; \
_argvec[2+3] = (unsigned long)arg3; \
_argvec[2+4] = (unsigned long)arg4; \
_argvec[2+5] = (unsigned long)arg5; \
_argvec[2+6] = (unsigned long)arg6; \
__asm__ volatile( \
VALGRIND_ALIGN_STACK \
"mr 12,%1\n\t" \
"std 2,-16(12)\n\t" /* save tocptr */ \
"ld 2,-8(12)\n\t" /* use nraddr's tocptr */ \
"ld 3, 8(12)\n\t" /* arg1->r3 */ \
"ld 4, 16(12)\n\t" /* arg2->r4 */ \
"ld 5, 24(12)\n\t" /* arg3->r5 */ \
"ld 6, 32(12)\n\t" /* arg4->r6 */ \
"ld 7, 40(12)\n\t" /* arg5->r7 */ \
"ld 8, 48(12)\n\t" /* arg6->r8 */ \
"ld 12, 0(12)\n\t" /* target->r12 */ \
VALGRIND_BRANCH_AND_LINK_TO_NOREDIR_R12 \
"mr 12,%1\n\t" \
"mr %0,3\n\t" \
"ld 2,-16(12)\n\t" /* restore tocptr */ \
VALGRIND_RESTORE_STACK \
: /*out*/ "=r" (_res) \
: /*in*/ "r" (&_argvec[2]) \
: /*trash*/ "cc", "memory", __CALLER_SAVED_REGS, "r28" \
); \
lval = (__typeof__(lval)) _res; \
} while (0)
#define CALL_FN_W_7W(lval, orig, arg1,arg2,arg3,arg4,arg5,arg6, \
arg7) \
do { \
volatile OrigFn _orig = (orig); \
volatile unsigned long _argvec[3+7]; \
volatile unsigned long _res; \
/* _argvec[0] holds current r2 across the call */ \
_argvec[1] = (unsigned long)_orig.r2; \
_argvec[2] = (unsigned long)_orig.nraddr; \
_argvec[2+1] = (unsigned long)arg1; \
_argvec[2+2] = (unsigned long)arg2; \
_argvec[2+3] = (unsigned long)arg3; \
_argvec[2+4] = (unsigned long)arg4; \
_argvec[2+5] = (unsigned long)arg5; \
_argvec[2+6] = (unsigned long)arg6; \
_argvec[2+7] = (unsigned long)arg7; \
__asm__ volatile( \
VALGRIND_ALIGN_STACK \
"mr 12,%1\n\t" \
"std 2,-16(12)\n\t" /* save tocptr */ \
"ld 2,-8(12)\n\t" /* use nraddr's tocptr */ \
"ld 3, 8(12)\n\t" /* arg1->r3 */ \
"ld 4, 16(12)\n\t" /* arg2->r4 */ \
"ld 5, 24(12)\n\t" /* arg3->r5 */ \
"ld 6, 32(12)\n\t" /* arg4->r6 */ \
"ld 7, 40(12)\n\t" /* arg5->r7 */ \
"ld 8, 48(12)\n\t" /* arg6->r8 */ \
"ld 9, 56(12)\n\t" /* arg7->r9 */ \
"ld 12, 0(12)\n\t" /* target->r12 */ \
VALGRIND_BRANCH_AND_LINK_TO_NOREDIR_R12 \
"mr 12,%1\n\t" \
"mr %0,3\n\t" \
"ld 2,-16(12)\n\t" /* restore tocptr */ \
VALGRIND_RESTORE_STACK \
: /*out*/ "=r" (_res) \
: /*in*/ "r" (&_argvec[2]) \
: /*trash*/ "cc", "memory", __CALLER_SAVED_REGS, "r28" \
); \
lval = (__typeof__(lval)) _res; \
} while (0)
#define CALL_FN_W_8W(lval, orig, arg1,arg2,arg3,arg4,arg5,arg6, \
arg7,arg8) \
do { \
volatile OrigFn _orig = (orig); \
volatile unsigned long _argvec[3+8]; \
volatile unsigned long _res; \
/* _argvec[0] holds current r2 across the call */ \
_argvec[1] = (unsigned long)_orig.r2; \
_argvec[2] = (unsigned long)_orig.nraddr; \
_argvec[2+1] = (unsigned long)arg1; \
_argvec[2+2] = (unsigned long)arg2; \
_argvec[2+3] = (unsigned long)arg3; \
_argvec[2+4] = (unsigned long)arg4; \
_argvec[2+5] = (unsigned long)arg5; \
_argvec[2+6] = (unsigned long)arg6; \
_argvec[2+7] = (unsigned long)arg7; \
_argvec[2+8] = (unsigned long)arg8; \
__asm__ volatile( \
VALGRIND_ALIGN_STACK \
"mr 12,%1\n\t" \
"std 2,-16(12)\n\t" /* save tocptr */ \
"ld 2,-8(12)\n\t" /* use nraddr's tocptr */ \
"ld 3, 8(12)\n\t" /* arg1->r3 */ \
"ld 4, 16(12)\n\t" /* arg2->r4 */ \
"ld 5, 24(12)\n\t" /* arg3->r5 */ \
"ld 6, 32(12)\n\t" /* arg4->r6 */ \
"ld 7, 40(12)\n\t" /* arg5->r7 */ \
"ld 8, 48(12)\n\t" /* arg6->r8 */ \
"ld 9, 56(12)\n\t" /* arg7->r9 */ \
"ld 10, 64(12)\n\t" /* arg8->r10 */ \
"ld 12, 0(12)\n\t" /* target->r12 */ \
VALGRIND_BRANCH_AND_LINK_TO_NOREDIR_R12 \
"mr 12,%1\n\t" \
"mr %0,3\n\t" \
"ld 2,-16(12)\n\t" /* restore tocptr */ \
VALGRIND_RESTORE_STACK \
: /*out*/ "=r" (_res) \
: /*in*/ "r" (&_argvec[2]) \
: /*trash*/ "cc", "memory", __CALLER_SAVED_REGS, "r28" \
); \
lval = (__typeof__(lval)) _res; \
} while (0)
#define CALL_FN_W_9W(lval, orig, arg1,arg2,arg3,arg4,arg5,arg6, \
arg7,arg8,arg9) \
do { \
volatile OrigFn _orig = (orig); \
volatile unsigned long _argvec[3+9]; \
volatile unsigned long _res; \
/* _argvec[0] holds current r2 across the call */ \
_argvec[1] = (unsigned long)_orig.r2; \
_argvec[2] = (unsigned long)_orig.nraddr; \
_argvec[2+1] = (unsigned long)arg1; \
_argvec[2+2] = (unsigned long)arg2; \
_argvec[2+3] = (unsigned long)arg3; \
_argvec[2+4] = (unsigned long)arg4; \
_argvec[2+5] = (unsigned long)arg5; \
_argvec[2+6] = (unsigned long)arg6; \
_argvec[2+7] = (unsigned long)arg7; \
_argvec[2+8] = (unsigned long)arg8; \
_argvec[2+9] = (unsigned long)arg9; \
__asm__ volatile( \
VALGRIND_ALIGN_STACK \
"mr 12,%1\n\t" \
"std 2,-16(12)\n\t" /* save tocptr */ \
"ld 2,-8(12)\n\t" /* use nraddr's tocptr */ \
"addi 1,1,-128\n\t" /* expand stack frame */ \
/* arg9 */ \
"ld 3,72(12)\n\t" \
"std 3,96(1)\n\t" \
/* args1-8 */ \
"ld 3, 8(12)\n\t" /* arg1->r3 */ \
"ld 4, 16(12)\n\t" /* arg2->r4 */ \
"ld 5, 24(12)\n\t" /* arg3->r5 */ \
"ld 6, 32(12)\n\t" /* arg4->r6 */ \
"ld 7, 40(12)\n\t" /* arg5->r7 */ \
"ld 8, 48(12)\n\t" /* arg6->r8 */ \
"ld 9, 56(12)\n\t" /* arg7->r9 */ \
"ld 10, 64(12)\n\t" /* arg8->r10 */ \
"ld 12, 0(12)\n\t" /* target->r12 */ \
VALGRIND_BRANCH_AND_LINK_TO_NOREDIR_R12 \
"mr 12,%1\n\t" \
"mr %0,3\n\t" \
"ld 2,-16(12)\n\t" /* restore tocptr */ \
VALGRIND_RESTORE_STACK \
: /*out*/ "=r" (_res) \
: /*in*/ "r" (&_argvec[2]) \
: /*trash*/ "cc", "memory", __CALLER_SAVED_REGS, "r28" \
); \
lval = (__typeof__(lval)) _res; \
} while (0)
#define CALL_FN_W_10W(lval, orig, arg1,arg2,arg3,arg4,arg5,arg6, \
arg7,arg8,arg9,arg10) \
do { \
volatile OrigFn _orig = (orig); \
volatile unsigned long _argvec[3+10]; \
volatile unsigned long _res; \
/* _argvec[0] holds current r2 across the call */ \
_argvec[1] = (unsigned long)_orig.r2; \
_argvec[2] = (unsigned long)_orig.nraddr; \
_argvec[2+1] = (unsigned long)arg1; \
_argvec[2+2] = (unsigned long)arg2; \
_argvec[2+3] = (unsigned long)arg3; \
_argvec[2+4] = (unsigned long)arg4; \
_argvec[2+5] = (unsigned long)arg5; \
_argvec[2+6] = (unsigned long)arg6; \
_argvec[2+7] = (unsigned long)arg7; \
_argvec[2+8] = (unsigned long)arg8; \
_argvec[2+9] = (unsigned long)arg9; \
_argvec[2+10] = (unsigned long)arg10; \
__asm__ volatile( \
VALGRIND_ALIGN_STACK \
"mr 12,%1\n\t" \
"std 2,-16(12)\n\t" /* save tocptr */ \
"ld 2,-8(12)\n\t" /* use nraddr's tocptr */ \
"addi 1,1,-128\n\t" /* expand stack frame */ \
/* arg10 */ \
"ld 3,80(12)\n\t" \
"std 3,104(1)\n\t" \
/* arg9 */ \
"ld 3,72(12)\n\t" \
"std 3,96(1)\n\t" \
/* args1-8 */ \
"ld 3, 8(12)\n\t" /* arg1->r3 */ \
"ld 4, 16(12)\n\t" /* arg2->r4 */ \
"ld 5, 24(12)\n\t" /* arg3->r5 */ \
"ld 6, 32(12)\n\t" /* arg4->r6 */ \
"ld 7, 40(12)\n\t" /* arg5->r7 */ \
"ld 8, 48(12)\n\t" /* arg6->r8 */ \
"ld 9, 56(12)\n\t" /* arg7->r9 */ \
"ld 10, 64(12)\n\t" /* arg8->r10 */ \
"ld 12, 0(12)\n\t" /* target->r12 */ \
VALGRIND_BRANCH_AND_LINK_TO_NOREDIR_R12 \
"mr 12,%1\n\t" \
"mr %0,3\n\t" \
"ld 2,-16(12)\n\t" /* restore tocptr */ \
VALGRIND_RESTORE_STACK \
: /*out*/ "=r" (_res) \
: /*in*/ "r" (&_argvec[2]) \
: /*trash*/ "cc", "memory", __CALLER_SAVED_REGS, "r28" \
); \
lval = (__typeof__(lval)) _res; \
} while (0)
#define CALL_FN_W_11W(lval, orig, arg1,arg2,arg3,arg4,arg5,arg6, \
arg7,arg8,arg9,arg10,arg11) \
do { \
volatile OrigFn _orig = (orig); \
volatile unsigned long _argvec[3+11]; \
volatile unsigned long _res; \
/* _argvec[0] holds current r2 across the call */ \
_argvec[1] = (unsigned long)_orig.r2; \
_argvec[2] = (unsigned long)_orig.nraddr; \
_argvec[2+1] = (unsigned long)arg1; \
_argvec[2+2] = (unsigned long)arg2; \
_argvec[2+3] = (unsigned long)arg3; \
_argvec[2+4] = (unsigned long)arg4; \
_argvec[2+5] = (unsigned long)arg5; \
_argvec[2+6] = (unsigned long)arg6; \
_argvec[2+7] = (unsigned long)arg7; \
_argvec[2+8] = (unsigned long)arg8; \
_argvec[2+9] = (unsigned long)arg9; \
_argvec[2+10] = (unsigned long)arg10; \
_argvec[2+11] = (unsigned long)arg11; \
__asm__ volatile( \
VALGRIND_ALIGN_STACK \
"mr 12,%1\n\t" \
"std 2,-16(12)\n\t" /* save tocptr */ \
"ld 2,-8(12)\n\t" /* use nraddr's tocptr */ \
"addi 1,1,-144\n\t" /* expand stack frame */ \
/* arg11 */ \
"ld 3,88(12)\n\t" \
"std 3,112(1)\n\t" \
/* arg10 */ \
"ld 3,80(12)\n\t" \
"std 3,104(1)\n\t" \
/* arg9 */ \
"ld 3,72(12)\n\t" \
"std 3,96(1)\n\t" \
/* args1-8 */ \
"ld 3, 8(12)\n\t" /* arg1->r3 */ \
"ld 4, 16(12)\n\t" /* arg2->r4 */ \
"ld 5, 24(12)\n\t" /* arg3->r5 */ \
"ld 6, 32(12)\n\t" /* arg4->r6 */ \
"ld 7, 40(12)\n\t" /* arg5->r7 */ \
"ld 8, 48(12)\n\t" /* arg6->r8 */ \
"ld 9, 56(12)\n\t" /* arg7->r9 */ \
"ld 10, 64(12)\n\t" /* arg8->r10 */ \
"ld 12, 0(12)\n\t" /* target->r12 */ \
VALGRIND_BRANCH_AND_LINK_TO_NOREDIR_R12 \
"mr 12,%1\n\t" \
"mr %0,3\n\t" \
"ld 2,-16(12)\n\t" /* restore tocptr */ \
VALGRIND_RESTORE_STACK \
: /*out*/ "=r" (_res) \
: /*in*/ "r" (&_argvec[2]) \
: /*trash*/ "cc", "memory", __CALLER_SAVED_REGS, "r28" \
); \
lval = (__typeof__(lval)) _res; \
} while (0)
#define CALL_FN_W_12W(lval, orig, arg1,arg2,arg3,arg4,arg5,arg6, \
arg7,arg8,arg9,arg10,arg11,arg12) \
do { \
volatile OrigFn _orig = (orig); \
volatile unsigned long _argvec[3+12]; \
volatile unsigned long _res; \
/* _argvec[0] holds current r2 across the call */ \
_argvec[1] = (unsigned long)_orig.r2; \
_argvec[2] = (unsigned long)_orig.nraddr; \
_argvec[2+1] = (unsigned long)arg1; \
_argvec[2+2] = (unsigned long)arg2; \
_argvec[2+3] = (unsigned long)arg3; \
_argvec[2+4] = (unsigned long)arg4; \
_argvec[2+5] = (unsigned long)arg5; \
_argvec[2+6] = (unsigned long)arg6; \
_argvec[2+7] = (unsigned long)arg7; \
_argvec[2+8] = (unsigned long)arg8; \
_argvec[2+9] = (unsigned long)arg9; \
_argvec[2+10] = (unsigned long)arg10; \
_argvec[2+11] = (unsigned long)arg11; \
_argvec[2+12] = (unsigned long)arg12; \
__asm__ volatile( \
VALGRIND_ALIGN_STACK \
"mr 12,%1\n\t" \
"std 2,-16(12)\n\t" /* save tocptr */ \
"ld 2,-8(12)\n\t" /* use nraddr's tocptr */ \
"addi 1,1,-144\n\t" /* expand stack frame */ \
/* arg12 */ \
"ld 3,96(12)\n\t" \
"std 3,120(1)\n\t" \
/* arg11 */ \
"ld 3,88(12)\n\t" \
"std 3,112(1)\n\t" \
/* arg10 */ \
"ld 3,80(12)\n\t" \
"std 3,104(1)\n\t" \
/* arg9 */ \
"ld 3,72(12)\n\t" \
"std 3,96(1)\n\t" \
/* args1-8 */ \
"ld 3, 8(12)\n\t" /* arg1->r3 */ \
"ld 4, 16(12)\n\t" /* arg2->r4 */ \
"ld 5, 24(12)\n\t" /* arg3->r5 */ \
"ld 6, 32(12)\n\t" /* arg4->r6 */ \
"ld 7, 40(12)\n\t" /* arg5->r7 */ \
"ld 8, 48(12)\n\t" /* arg6->r8 */ \
"ld 9, 56(12)\n\t" /* arg7->r9 */ \
"ld 10, 64(12)\n\t" /* arg8->r10 */ \
"ld 12, 0(12)\n\t" /* target->r12 */ \
VALGRIND_BRANCH_AND_LINK_TO_NOREDIR_R12 \
"mr 12,%1\n\t" \
"mr %0,3\n\t" \
"ld 2,-16(12)\n\t" /* restore tocptr */ \
VALGRIND_RESTORE_STACK \
: /*out*/ "=r" (_res) \
: /*in*/ "r" (&_argvec[2]) \
: /*trash*/ "cc", "memory", __CALLER_SAVED_REGS, "r28" \
); \
lval = (__typeof__(lval)) _res; \
} while (0)
#endif /* PLAT_ppc64le_linux */
/* ------------------------- arm-linux ------------------------- */
#if defined(PLAT_arm_linux)
/* These regs are trashed by the hidden call. */
#define __CALLER_SAVED_REGS "r0", "r1", "r2", "r3","r4", "r12", "r14"
/* Macros to save and align the stack before making a function
call and restore it afterwards as gcc may not keep the stack
pointer aligned if it doesn't realise calls are being made
to other functions. */
/* This is a bit tricky. We store the original stack pointer in r10
as it is callee-saves. gcc doesn't allow the use of r11 for some
reason. Also, we can't directly "bic" the stack pointer in thumb
mode since r13 isn't an allowed register number in that context.
So use r4 as a temporary, since that is about to get trashed
anyway, just after each use of this macro. Side effect is we need
to be very careful about any future changes, since
VALGRIND_ALIGN_STACK simply assumes r4 is usable. */
#define VALGRIND_ALIGN_STACK \
"mov r10, sp\n\t" \
"mov r4, sp\n\t" \
"bic r4, r4, #7\n\t" \
"mov sp, r4\n\t"
#define VALGRIND_RESTORE_STACK \
"mov sp, r10\n\t"
/* These CALL_FN_ macros assume that on arm-linux, sizeof(unsigned
long) == 4. */
#define CALL_FN_W_v(lval, orig) \
do { \
volatile OrigFn _orig = (orig); \
volatile unsigned long _argvec[1]; \
volatile unsigned long _res; \
_argvec[0] = (unsigned long)_orig.nraddr; \
__asm__ volatile( \
VALGRIND_ALIGN_STACK \
"ldr r4, [%1] \n\t" /* target->r4 */ \
VALGRIND_BRANCH_AND_LINK_TO_NOREDIR_R4 \
VALGRIND_RESTORE_STACK \
"mov %0, r0\n" \
: /*out*/ "=r" (_res) \
: /*in*/ "0" (&_argvec[0]) \
: /*trash*/ "cc", "memory", __CALLER_SAVED_REGS, "r10" \
); \
lval = (__typeof__(lval)) _res; \
} while (0)
#define CALL_FN_W_W(lval, orig, arg1) \
do { \
volatile OrigFn _orig = (orig); \
volatile unsigned long _argvec[2]; \
volatile unsigned long _res; \
_argvec[0] = (unsigned long)_orig.nraddr; \
_argvec[1] = (unsigned long)(arg1); \
__asm__ volatile( \
VALGRIND_ALIGN_STACK \
"ldr r0, [%1, #4] \n\t" \
"ldr r4, [%1] \n\t" /* target->r4 */ \
VALGRIND_BRANCH_AND_LINK_TO_NOREDIR_R4 \
VALGRIND_RESTORE_STACK \
"mov %0, r0\n" \
: /*out*/ "=r" (_res) \
: /*in*/ "0" (&_argvec[0]) \
: /*trash*/ "cc", "memory", __CALLER_SAVED_REGS, "r10" \
); \
lval = (__typeof__(lval)) _res; \
} while (0)
#define CALL_FN_W_WW(lval, orig, arg1,arg2) \
do { \
volatile OrigFn _orig = (orig); \
volatile unsigned long _argvec[3]; \
volatile unsigned long _res; \
_argvec[0] = (unsigned long)_orig.nraddr; \
_argvec[1] = (unsigned long)(arg1); \
_argvec[2] = (unsigned long)(arg2); \
__asm__ volatile( \
VALGRIND_ALIGN_STACK \
"ldr r0, [%1, #4] \n\t" \
"ldr r1, [%1, #8] \n\t" \
"ldr r4, [%1] \n\t" /* target->r4 */ \
VALGRIND_BRANCH_AND_LINK_TO_NOREDIR_R4 \
VALGRIND_RESTORE_STACK \
"mov %0, r0\n" \
: /*out*/ "=r" (_res) \
: /*in*/ "0" (&_argvec[0]) \
: /*trash*/ "cc", "memory", __CALLER_SAVED_REGS, "r10" \
); \
lval = (__typeof__(lval)) _res; \
} while (0)
#define CALL_FN_W_WWW(lval, orig, arg1,arg2,arg3) \
do { \
volatile OrigFn _orig = (orig); \
volatile unsigned long _argvec[4]; \
volatile unsigned long _res; \
_argvec[0] = (unsigned long)_orig.nraddr; \
_argvec[1] = (unsigned long)(arg1); \
_argvec[2] = (unsigned long)(arg2); \
_argvec[3] = (unsigned long)(arg3); \
__asm__ volatile( \
VALGRIND_ALIGN_STACK \
"ldr r0, [%1, #4] \n\t" \
"ldr r1, [%1, #8] \n\t" \
"ldr r2, [%1, #12] \n\t" \
"ldr r4, [%1] \n\t" /* target->r4 */ \
VALGRIND_BRANCH_AND_LINK_TO_NOREDIR_R4 \
VALGRIND_RESTORE_STACK \
"mov %0, r0\n" \
: /*out*/ "=r" (_res) \
: /*in*/ "0" (&_argvec[0]) \
: /*trash*/ "cc", "memory", __CALLER_SAVED_REGS, "r10" \
); \
lval = (__typeof__(lval)) _res; \
} while (0)
#define CALL_FN_W_WWWW(lval, orig, arg1,arg2,arg3,arg4) \
do { \
volatile OrigFn _orig = (orig); \
volatile unsigned long _argvec[5]; \
volatile unsigned long _res; \
_argvec[0] = (unsigned long)_orig.nraddr; \
_argvec[1] = (unsigned long)(arg1); \
_argvec[2] = (unsigned long)(arg2); \
_argvec[3] = (unsigned long)(arg3); \
_argvec[4] = (unsigned long)(arg4); \
__asm__ volatile( \
VALGRIND_ALIGN_STACK \
"ldr r0, [%1, #4] \n\t" \
"ldr r1, [%1, #8] \n\t" \
"ldr r2, [%1, #12] \n\t" \
"ldr r3, [%1, #16] \n\t" \
"ldr r4, [%1] \n\t" /* target->r4 */ \
VALGRIND_BRANCH_AND_LINK_TO_NOREDIR_R4 \
VALGRIND_RESTORE_STACK \
"mov %0, r0" \
: /*out*/ "=r" (_res) \
: /*in*/ "0" (&_argvec[0]) \
: /*trash*/ "cc", "memory", __CALLER_SAVED_REGS, "r10" \
); \
lval = (__typeof__(lval)) _res; \
} while (0)
#define CALL_FN_W_5W(lval, orig, arg1,arg2,arg3,arg4,arg5) \
do { \
volatile OrigFn _orig = (orig); \
volatile unsigned long _argvec[6]; \
volatile unsigned long _res; \
_argvec[0] = (unsigned long)_orig.nraddr; \
_argvec[1] = (unsigned long)(arg1); \
_argvec[2] = (unsigned long)(arg2); \
_argvec[3] = (unsigned long)(arg3); \
_argvec[4] = (unsigned long)(arg4); \
_argvec[5] = (unsigned long)(arg5); \
__asm__ volatile( \
VALGRIND_ALIGN_STACK \
"sub sp, sp, #4 \n\t" \
"ldr r0, [%1, #20] \n\t" \
"push {r0} \n\t" \
"ldr r0, [%1, #4] \n\t" \
"ldr r1, [%1, #8] \n\t" \
"ldr r2, [%1, #12] \n\t" \
"ldr r3, [%1, #16] \n\t" \
"ldr r4, [%1] \n\t" /* target->r4 */ \
VALGRIND_BRANCH_AND_LINK_TO_NOREDIR_R4 \
VALGRIND_RESTORE_STACK \
"mov %0, r0" \
: /*out*/ "=r" (_res) \
: /*in*/ "0" (&_argvec[0]) \
: /*trash*/ "cc", "memory", __CALLER_SAVED_REGS, "r10" \
); \
lval = (__typeof__(lval)) _res; \
} while (0)
#define CALL_FN_W_6W(lval, orig, arg1,arg2,arg3,arg4,arg5,arg6) \
do { \
volatile OrigFn _orig = (orig); \
volatile unsigned long _argvec[7]; \
volatile unsigned long _res; \
_argvec[0] = (unsigned long)_orig.nraddr; \
_argvec[1] = (unsigned long)(arg1); \
_argvec[2] = (unsigned long)(arg2); \
_argvec[3] = (unsigned long)(arg3); \
_argvec[4] = (unsigned long)(arg4); \
_argvec[5] = (unsigned long)(arg5); \
_argvec[6] = (unsigned long)(arg6); \
__asm__ volatile( \
VALGRIND_ALIGN_STACK \
"ldr r0, [%1, #20] \n\t" \
"ldr r1, [%1, #24] \n\t" \
"push {r0, r1} \n\t" \
"ldr r0, [%1, #4] \n\t" \
"ldr r1, [%1, #8] \n\t" \
"ldr r2, [%1, #12] \n\t" \
"ldr r3, [%1, #16] \n\t" \
"ldr r4, [%1] \n\t" /* target->r4 */ \
VALGRIND_BRANCH_AND_LINK_TO_NOREDIR_R4 \
VALGRIND_RESTORE_STACK \
"mov %0, r0" \
: /*out*/ "=r" (_res) \
: /*in*/ "0" (&_argvec[0]) \
: /*trash*/ "cc", "memory", __CALLER_SAVED_REGS, "r10" \
); \
lval = (__typeof__(lval)) _res; \
} while (0)
#define CALL_FN_W_7W(lval, orig, arg1,arg2,arg3,arg4,arg5,arg6, \
arg7) \
do { \
volatile OrigFn _orig = (orig); \
volatile unsigned long _argvec[8]; \
volatile unsigned long _res; \
_argvec[0] = (unsigned long)_orig.nraddr; \
_argvec[1] = (unsigned long)(arg1); \
_argvec[2] = (unsigned long)(arg2); \
_argvec[3] = (unsigned long)(arg3); \
_argvec[4] = (unsigned long)(arg4); \
_argvec[5] = (unsigned long)(arg5); \
_argvec[6] = (unsigned long)(arg6); \
_argvec[7] = (unsigned long)(arg7); \
__asm__ volatile( \
VALGRIND_ALIGN_STACK \
"sub sp, sp, #4 \n\t" \
"ldr r0, [%1, #20] \n\t" \
"ldr r1, [%1, #24] \n\t" \
"ldr r2, [%1, #28] \n\t" \
"push {r0, r1, r2} \n\t" \
"ldr r0, [%1, #4] \n\t" \
"ldr r1, [%1, #8] \n\t" \
"ldr r2, [%1, #12] \n\t" \
"ldr r3, [%1, #16] \n\t" \
"ldr r4, [%1] \n\t" /* target->r4 */ \
VALGRIND_BRANCH_AND_LINK_TO_NOREDIR_R4 \
VALGRIND_RESTORE_STACK \
"mov %0, r0" \
: /*out*/ "=r" (_res) \
: /*in*/ "0" (&_argvec[0]) \
: /*trash*/ "cc", "memory", __CALLER_SAVED_REGS, "r10" \
); \
lval = (__typeof__(lval)) _res; \
} while (0)
#define CALL_FN_W_8W(lval, orig, arg1,arg2,arg3,arg4,arg5,arg6, \
arg7,arg8) \
do { \
volatile OrigFn _orig = (orig); \
volatile unsigned long _argvec[9]; \
volatile unsigned long _res; \
_argvec[0] = (unsigned long)_orig.nraddr; \
_argvec[1] = (unsigned long)(arg1); \
_argvec[2] = (unsigned long)(arg2); \
_argvec[3] = (unsigned long)(arg3); \
_argvec[4] = (unsigned long)(arg4); \
_argvec[5] = (unsigned long)(arg5); \
_argvec[6] = (unsigned long)(arg6); \
_argvec[7] = (unsigned long)(arg7); \
_argvec[8] = (unsigned long)(arg8); \
__asm__ volatile( \
VALGRIND_ALIGN_STACK \
"ldr r0, [%1, #20] \n\t" \
"ldr r1, [%1, #24] \n\t" \
"ldr r2, [%1, #28] \n\t" \
"ldr r3, [%1, #32] \n\t" \
"push {r0, r1, r2, r3} \n\t" \
"ldr r0, [%1, #4] \n\t" \
"ldr r1, [%1, #8] \n\t" \
"ldr r2, [%1, #12] \n\t" \
"ldr r3, [%1, #16] \n\t" \
"ldr r4, [%1] \n\t" /* target->r4 */ \
VALGRIND_BRANCH_AND_LINK_TO_NOREDIR_R4 \
VALGRIND_RESTORE_STACK \
"mov %0, r0" \
: /*out*/ "=r" (_res) \
: /*in*/ "0" (&_argvec[0]) \
: /*trash*/ "cc", "memory", __CALLER_SAVED_REGS, "r10" \
); \
lval = (__typeof__(lval)) _res; \
} while (0)
#define CALL_FN_W_9W(lval, orig, arg1,arg2,arg3,arg4,arg5,arg6, \
arg7,arg8,arg9) \
do { \
volatile OrigFn _orig = (orig); \
volatile unsigned long _argvec[10]; \
volatile unsigned long _res; \
_argvec[0] = (unsigned long)_orig.nraddr; \
_argvec[1] = (unsigned long)(arg1); \
_argvec[2] = (unsigned long)(arg2); \
_argvec[3] = (unsigned long)(arg3); \
_argvec[4] = (unsigned long)(arg4); \
_argvec[5] = (unsigned long)(arg5); \
_argvec[6] = (unsigned long)(arg6); \
_argvec[7] = (unsigned long)(arg7); \
_argvec[8] = (unsigned long)(arg8); \
_argvec[9] = (unsigned long)(arg9); \
__asm__ volatile( \
VALGRIND_ALIGN_STACK \
"sub sp, sp, #4 \n\t" \
"ldr r0, [%1, #20] \n\t" \
"ldr r1, [%1, #24] \n\t" \
"ldr r2, [%1, #28] \n\t" \
"ldr r3, [%1, #32] \n\t" \
"ldr r4, [%1, #36] \n\t" \
"push {r0, r1, r2, r3, r4} \n\t" \
"ldr r0, [%1, #4] \n\t" \
"ldr r1, [%1, #8] \n\t" \
"ldr r2, [%1, #12] \n\t" \
"ldr r3, [%1, #16] \n\t" \
"ldr r4, [%1] \n\t" /* target->r4 */ \
VALGRIND_BRANCH_AND_LINK_TO_NOREDIR_R4 \
VALGRIND_RESTORE_STACK \
"mov %0, r0" \
: /*out*/ "=r" (_res) \
: /*in*/ "0" (&_argvec[0]) \
: /*trash*/ "cc", "memory", __CALLER_SAVED_REGS, "r10" \
); \
lval = (__typeof__(lval)) _res; \
} while (0)
#define CALL_FN_W_10W(lval, orig, arg1,arg2,arg3,arg4,arg5,arg6, \
arg7,arg8,arg9,arg10) \
do { \
volatile OrigFn _orig = (orig); \
volatile unsigned long _argvec[11]; \
volatile unsigned long _res; \
_argvec[0] = (unsigned long)_orig.nraddr; \
_argvec[1] = (unsigned long)(arg1); \
_argvec[2] = (unsigned long)(arg2); \
_argvec[3] = (unsigned long)(arg3); \
_argvec[4] = (unsigned long)(arg4); \
_argvec[5] = (unsigned long)(arg5); \
_argvec[6] = (unsigned long)(arg6); \
_argvec[7] = (unsigned long)(arg7); \
_argvec[8] = (unsigned long)(arg8); \
_argvec[9] = (unsigned long)(arg9); \
_argvec[10] = (unsigned long)(arg10); \
__asm__ volatile( \
VALGRIND_ALIGN_STACK \
"ldr r0, [%1, #40] \n\t" \
"push {r0} \n\t" \
"ldr r0, [%1, #20] \n\t" \
"ldr r1, [%1, #24] \n\t" \
"ldr r2, [%1, #28] \n\t" \
"ldr r3, [%1, #32] \n\t" \
"ldr r4, [%1, #36] \n\t" \
"push {r0, r1, r2, r3, r4} \n\t" \
"ldr r0, [%1, #4] \n\t" \
"ldr r1, [%1, #8] \n\t" \
"ldr r2, [%1, #12] \n\t" \
"ldr r3, [%1, #16] \n\t" \
"ldr r4, [%1] \n\t" /* target->r4 */ \
VALGRIND_BRANCH_AND_LINK_TO_NOREDIR_R4 \
VALGRIND_RESTORE_STACK \
"mov %0, r0" \
: /*out*/ "=r" (_res) \
: /*in*/ "0" (&_argvec[0]) \
: /*trash*/ "cc", "memory", __CALLER_SAVED_REGS, "r10" \
); \
lval = (__typeof__(lval)) _res; \
} while (0)
#define CALL_FN_W_11W(lval, orig, arg1,arg2,arg3,arg4,arg5, \
arg6,arg7,arg8,arg9,arg10, \
arg11) \
do { \
volatile OrigFn _orig = (orig); \
volatile unsigned long _argvec[12]; \
volatile unsigned long _res; \
_argvec[0] = (unsigned long)_orig.nraddr; \
_argvec[1] = (unsigned long)(arg1); \
_argvec[2] = (unsigned long)(arg2); \
_argvec[3] = (unsigned long)(arg3); \
_argvec[4] = (unsigned long)(arg4); \
_argvec[5] = (unsigned long)(arg5); \
_argvec[6] = (unsigned long)(arg6); \
_argvec[7] = (unsigned long)(arg7); \
_argvec[8] = (unsigned long)(arg8); \
_argvec[9] = (unsigned long)(arg9); \
_argvec[10] = (unsigned long)(arg10); \
_argvec[11] = (unsigned long)(arg11); \
__asm__ volatile( \
VALGRIND_ALIGN_STACK \
"sub sp, sp, #4 \n\t" \
"ldr r0, [%1, #40] \n\t" \
"ldr r1, [%1, #44] \n\t" \
"push {r0, r1} \n\t" \
"ldr r0, [%1, #20] \n\t" \
"ldr r1, [%1, #24] \n\t" \
"ldr r2, [%1, #28] \n\t" \
"ldr r3, [%1, #32] \n\t" \
"ldr r4, [%1, #36] \n\t" \
"push {r0, r1, r2, r3, r4} \n\t" \
"ldr r0, [%1, #4] \n\t" \
"ldr r1, [%1, #8] \n\t" \
"ldr r2, [%1, #12] \n\t" \
"ldr r3, [%1, #16] \n\t" \
"ldr r4, [%1] \n\t" /* target->r4 */ \
VALGRIND_BRANCH_AND_LINK_TO_NOREDIR_R4 \
VALGRIND_RESTORE_STACK \
"mov %0, r0" \
: /*out*/ "=r" (_res) \
: /*in*/ "0" (&_argvec[0]) \
: /*trash*/ "cc", "memory", __CALLER_SAVED_REGS, "r10" \
); \
lval = (__typeof__(lval)) _res; \
} while (0)
#define CALL_FN_W_12W(lval, orig, arg1,arg2,arg3,arg4,arg5, \
arg6,arg7,arg8,arg9,arg10, \
arg11,arg12) \
do { \
volatile OrigFn _orig = (orig); \
volatile unsigned long _argvec[13]; \
volatile unsigned long _res; \
_argvec[0] = (unsigned long)_orig.nraddr; \
_argvec[1] = (unsigned long)(arg1); \
_argvec[2] = (unsigned long)(arg2); \
_argvec[3] = (unsigned long)(arg3); \
_argvec[4] = (unsigned long)(arg4); \
_argvec[5] = (unsigned long)(arg5); \
_argvec[6] = (unsigned long)(arg6); \
_argvec[7] = (unsigned long)(arg7); \
_argvec[8] = (unsigned long)(arg8); \
_argvec[9] = (unsigned long)(arg9); \
_argvec[10] = (unsigned long)(arg10); \
_argvec[11] = (unsigned long)(arg11); \
_argvec[12] = (unsigned long)(arg12); \
__asm__ volatile( \
VALGRIND_ALIGN_STACK \
"ldr r0, [%1, #40] \n\t" \
"ldr r1, [%1, #44] \n\t" \
"ldr r2, [%1, #48] \n\t" \
"push {r0, r1, r2} \n\t" \
"ldr r0, [%1, #20] \n\t" \
"ldr r1, [%1, #24] \n\t" \
"ldr r2, [%1, #28] \n\t" \
"ldr r3, [%1, #32] \n\t" \
"ldr r4, [%1, #36] \n\t" \
"push {r0, r1, r2, r3, r4} \n\t" \
"ldr r0, [%1, #4] \n\t" \
"ldr r1, [%1, #8] \n\t" \
"ldr r2, [%1, #12] \n\t" \
"ldr r3, [%1, #16] \n\t" \
"ldr r4, [%1] \n\t" /* target->r4 */ \
VALGRIND_BRANCH_AND_LINK_TO_NOREDIR_R4 \
VALGRIND_RESTORE_STACK \
"mov %0, r0" \
: /*out*/ "=r" (_res) \
: /*in*/ "0" (&_argvec[0]) \
: /*trash*/ "cc", "memory", __CALLER_SAVED_REGS, "r10" \
); \
lval = (__typeof__(lval)) _res; \
} while (0)
#endif /* PLAT_arm_linux */
/* ------------------------ arm64-linux ------------------------ */
#if defined(PLAT_arm64_linux)
/* These regs are trashed by the hidden call. */
#define __CALLER_SAVED_REGS \
"x0", "x1", "x2", "x3","x4", "x5", "x6", "x7", "x8", "x9", \
"x10", "x11", "x12", "x13", "x14", "x15", "x16", "x17", \
"x18", "x19", "x20", "x30", \
"v0", "v1", "v2", "v3", "v4", "v5", "v6", "v7", "v8", "v9", \
"v10", "v11", "v12", "v13", "v14", "v15", "v16", "v17", \
"v18", "v19", "v20", "v21", "v22", "v23", "v24", "v25", \
"v26", "v27", "v28", "v29", "v30", "v31"
/* x21 is callee-saved, so we can use it to save and restore SP around
the hidden call. */
#define VALGRIND_ALIGN_STACK \
"mov x21, sp\n\t" \
"bic sp, x21, #15\n\t"
#define VALGRIND_RESTORE_STACK \
"mov sp, x21\n\t"
/* These CALL_FN_ macros assume that on arm64-linux,
sizeof(unsigned long) == 8. */
#define CALL_FN_W_v(lval, orig) \
do { \
volatile OrigFn _orig = (orig); \
volatile unsigned long _argvec[1]; \
volatile unsigned long _res; \
_argvec[0] = (unsigned long)_orig.nraddr; \
__asm__ volatile( \
VALGRIND_ALIGN_STACK \
"ldr x8, [%1] \n\t" /* target->x8 */ \
VALGRIND_BRANCH_AND_LINK_TO_NOREDIR_X8 \
VALGRIND_RESTORE_STACK \
"mov %0, x0\n" \
: /*out*/ "=r" (_res) \
: /*in*/ "0" (&_argvec[0]) \
: /*trash*/ "cc", "memory", __CALLER_SAVED_REGS, "x21" \
); \
lval = (__typeof__(lval)) _res; \
} while (0)
#define CALL_FN_W_W(lval, orig, arg1) \
do { \
volatile OrigFn _orig = (orig); \
volatile unsigned long _argvec[2]; \
volatile unsigned long _res; \
_argvec[0] = (unsigned long)_orig.nraddr; \
_argvec[1] = (unsigned long)(arg1); \
__asm__ volatile( \
VALGRIND_ALIGN_STACK \
"ldr x0, [%1, #8] \n\t" \
"ldr x8, [%1] \n\t" /* target->x8 */ \
VALGRIND_BRANCH_AND_LINK_TO_NOREDIR_X8 \
VALGRIND_RESTORE_STACK \
"mov %0, x0\n" \
: /*out*/ "=r" (_res) \
: /*in*/ "0" (&_argvec[0]) \
: /*trash*/ "cc", "memory", __CALLER_SAVED_REGS, "x21" \
); \
lval = (__typeof__(lval)) _res; \
} while (0)
#define CALL_FN_W_WW(lval, orig, arg1,arg2) \
do { \
volatile OrigFn _orig = (orig); \
volatile unsigned long _argvec[3]; \
volatile unsigned long _res; \
_argvec[0] = (unsigned long)_orig.nraddr; \
_argvec[1] = (unsigned long)(arg1); \
_argvec[2] = (unsigned long)(arg2); \
__asm__ volatile( \
VALGRIND_ALIGN_STACK \
"ldr x0, [%1, #8] \n\t" \
"ldr x1, [%1, #16] \n\t" \
"ldr x8, [%1] \n\t" /* target->x8 */ \
VALGRIND_BRANCH_AND_LINK_TO_NOREDIR_X8 \
VALGRIND_RESTORE_STACK \
"mov %0, x0\n" \
: /*out*/ "=r" (_res) \
: /*in*/ "0" (&_argvec[0]) \
: /*trash*/ "cc", "memory", __CALLER_SAVED_REGS, "x21" \
); \
lval = (__typeof__(lval)) _res; \
} while (0)
#define CALL_FN_W_WWW(lval, orig, arg1,arg2,arg3) \
do { \
volatile OrigFn _orig = (orig); \
volatile unsigned long _argvec[4]; \
volatile unsigned long _res; \
_argvec[0] = (unsigned long)_orig.nraddr; \
_argvec[1] = (unsigned long)(arg1); \
_argvec[2] = (unsigned long)(arg2); \
_argvec[3] = (unsigned long)(arg3); \
__asm__ volatile( \
VALGRIND_ALIGN_STACK \
"ldr x0, [%1, #8] \n\t" \
"ldr x1, [%1, #16] \n\t" \
"ldr x2, [%1, #24] \n\t" \
"ldr x8, [%1] \n\t" /* target->x8 */ \
VALGRIND_BRANCH_AND_LINK_TO_NOREDIR_X8 \
VALGRIND_RESTORE_STACK \
"mov %0, x0\n" \
: /*out*/ "=r" (_res) \
: /*in*/ "0" (&_argvec[0]) \
: /*trash*/ "cc", "memory", __CALLER_SAVED_REGS, "x21" \
); \
lval = (__typeof__(lval)) _res; \
} while (0)
#define CALL_FN_W_WWWW(lval, orig, arg1,arg2,arg3,arg4) \
do { \
volatile OrigFn _orig = (orig); \
volatile unsigned long _argvec[5]; \
volatile unsigned long _res; \
_argvec[0] = (unsigned long)_orig.nraddr; \
_argvec[1] = (unsigned long)(arg1); \
_argvec[2] = (unsigned long)(arg2); \
_argvec[3] = (unsigned long)(arg3); \
_argvec[4] = (unsigned long)(arg4); \
__asm__ volatile( \
VALGRIND_ALIGN_STACK \
"ldr x0, [%1, #8] \n\t" \
"ldr x1, [%1, #16] \n\t" \
"ldr x2, [%1, #24] \n\t" \
"ldr x3, [%1, #32] \n\t" \
"ldr x8, [%1] \n\t" /* target->x8 */ \
VALGRIND_BRANCH_AND_LINK_TO_NOREDIR_X8 \
VALGRIND_RESTORE_STACK \
"mov %0, x0" \
: /*out*/ "=r" (_res) \
: /*in*/ "0" (&_argvec[0]) \
: /*trash*/ "cc", "memory", __CALLER_SAVED_REGS, "x21" \
); \
lval = (__typeof__(lval)) _res; \
} while (0)
#define CALL_FN_W_5W(lval, orig, arg1,arg2,arg3,arg4,arg5) \
do { \
volatile OrigFn _orig = (orig); \
volatile unsigned long _argvec[6]; \
volatile unsigned long _res; \
_argvec[0] = (unsigned long)_orig.nraddr; \
_argvec[1] = (unsigned long)(arg1); \
_argvec[2] = (unsigned long)(arg2); \
_argvec[3] = (unsigned long)(arg3); \
_argvec[4] = (unsigned long)(arg4); \
_argvec[5] = (unsigned long)(arg5); \
__asm__ volatile( \
VALGRIND_ALIGN_STACK \
"ldr x0, [%1, #8] \n\t" \
"ldr x1, [%1, #16] \n\t" \
"ldr x2, [%1, #24] \n\t" \
"ldr x3, [%1, #32] \n\t" \
"ldr x4, [%1, #40] \n\t" \
"ldr x8, [%1] \n\t" /* target->x8 */ \
VALGRIND_BRANCH_AND_LINK_TO_NOREDIR_X8 \
VALGRIND_RESTORE_STACK \
"mov %0, x0" \
: /*out*/ "=r" (_res) \
: /*in*/ "0" (&_argvec[0]) \
: /*trash*/ "cc", "memory", __CALLER_SAVED_REGS, "x21" \
); \
lval = (__typeof__(lval)) _res; \
} while (0)
#define CALL_FN_W_6W(lval, orig, arg1,arg2,arg3,arg4,arg5,arg6) \
do { \
volatile OrigFn _orig = (orig); \
volatile unsigned long _argvec[7]; \
volatile unsigned long _res; \
_argvec[0] = (unsigned long)_orig.nraddr; \
_argvec[1] = (unsigned long)(arg1); \
_argvec[2] = (unsigned long)(arg2); \
_argvec[3] = (unsigned long)(arg3); \
_argvec[4] = (unsigned long)(arg4); \
_argvec[5] = (unsigned long)(arg5); \
_argvec[6] = (unsigned long)(arg6); \
__asm__ volatile( \
VALGRIND_ALIGN_STACK \
"ldr x0, [%1, #8] \n\t" \
"ldr x1, [%1, #16] \n\t" \
"ldr x2, [%1, #24] \n\t" \
"ldr x3, [%1, #32] \n\t" \
"ldr x4, [%1, #40] \n\t" \
"ldr x5, [%1, #48] \n\t" \
"ldr x8, [%1] \n\t" /* target->x8 */ \
VALGRIND_BRANCH_AND_LINK_TO_NOREDIR_X8 \
VALGRIND_RESTORE_STACK \
"mov %0, x0" \
: /*out*/ "=r" (_res) \
: /*in*/ "0" (&_argvec[0]) \
: /*trash*/ "cc", "memory", __CALLER_SAVED_REGS, "x21" \
); \
lval = (__typeof__(lval)) _res; \
} while (0)
#define CALL_FN_W_7W(lval, orig, arg1,arg2,arg3,arg4,arg5,arg6, \
arg7) \
do { \
volatile OrigFn _orig = (orig); \
volatile unsigned long _argvec[8]; \
volatile unsigned long _res; \
_argvec[0] = (unsigned long)_orig.nraddr; \
_argvec[1] = (unsigned long)(arg1); \
_argvec[2] = (unsigned long)(arg2); \
_argvec[3] = (unsigned long)(arg3); \
_argvec[4] = (unsigned long)(arg4); \
_argvec[5] = (unsigned long)(arg5); \
_argvec[6] = (unsigned long)(arg6); \
_argvec[7] = (unsigned long)(arg7); \
__asm__ volatile( \
VALGRIND_ALIGN_STACK \
"ldr x0, [%1, #8] \n\t" \
"ldr x1, [%1, #16] \n\t" \
"ldr x2, [%1, #24] \n\t" \
"ldr x3, [%1, #32] \n\t" \
"ldr x4, [%1, #40] \n\t" \
"ldr x5, [%1, #48] \n\t" \
"ldr x6, [%1, #56] \n\t" \
"ldr x8, [%1] \n\t" /* target->x8 */ \
VALGRIND_BRANCH_AND_LINK_TO_NOREDIR_X8 \
VALGRIND_RESTORE_STACK \
"mov %0, x0" \
: /*out*/ "=r" (_res) \
: /*in*/ "0" (&_argvec[0]) \
: /*trash*/ "cc", "memory", __CALLER_SAVED_REGS, "x21" \
); \
lval = (__typeof__(lval)) _res; \
} while (0)
#define CALL_FN_W_8W(lval, orig, arg1,arg2,arg3,arg4,arg5,arg6, \
arg7,arg8) \
do { \
volatile OrigFn _orig = (orig); \
volatile unsigned long _argvec[9]; \
volatile unsigned long _res; \
_argvec[0] = (unsigned long)_orig.nraddr; \
_argvec[1] = (unsigned long)(arg1); \
_argvec[2] = (unsigned long)(arg2); \
_argvec[3] = (unsigned long)(arg3); \
_argvec[4] = (unsigned long)(arg4); \
_argvec[5] = (unsigned long)(arg5); \
_argvec[6] = (unsigned long)(arg6); \
_argvec[7] = (unsigned long)(arg7); \
_argvec[8] = (unsigned long)(arg8); \
__asm__ volatile( \
VALGRIND_ALIGN_STACK \
"ldr x0, [%1, #8] \n\t" \
"ldr x1, [%1, #16] \n\t" \
"ldr x2, [%1, #24] \n\t" \
"ldr x3, [%1, #32] \n\t" \
"ldr x4, [%1, #40] \n\t" \
"ldr x5, [%1, #48] \n\t" \
"ldr x6, [%1, #56] \n\t" \
"ldr x7, [%1, #64] \n\t" \
"ldr x8, [%1] \n\t" /* target->x8 */ \
VALGRIND_BRANCH_AND_LINK_TO_NOREDIR_X8 \
VALGRIND_RESTORE_STACK \
"mov %0, x0" \
: /*out*/ "=r" (_res) \
: /*in*/ "0" (&_argvec[0]) \
: /*trash*/ "cc", "memory", __CALLER_SAVED_REGS, "x21" \
); \
lval = (__typeof__(lval)) _res; \
} while (0)
#define CALL_FN_W_9W(lval, orig, arg1,arg2,arg3,arg4,arg5,arg6, \
arg7,arg8,arg9) \
do { \
volatile OrigFn _orig = (orig); \
volatile unsigned long _argvec[10]; \
volatile unsigned long _res; \
_argvec[0] = (unsigned long)_orig.nraddr; \
_argvec[1] = (unsigned long)(arg1); \
_argvec[2] = (unsigned long)(arg2); \
_argvec[3] = (unsigned long)(arg3); \
_argvec[4] = (unsigned long)(arg4); \
_argvec[5] = (unsigned long)(arg5); \
_argvec[6] = (unsigned long)(arg6); \
_argvec[7] = (unsigned long)(arg7); \
_argvec[8] = (unsigned long)(arg8); \
_argvec[9] = (unsigned long)(arg9); \
__asm__ volatile( \
VALGRIND_ALIGN_STACK \
"sub sp, sp, #0x20 \n\t" \
"ldr x0, [%1, #8] \n\t" \
"ldr x1, [%1, #16] \n\t" \
"ldr x2, [%1, #24] \n\t" \
"ldr x3, [%1, #32] \n\t" \
"ldr x4, [%1, #40] \n\t" \
"ldr x5, [%1, #48] \n\t" \
"ldr x6, [%1, #56] \n\t" \
"ldr x7, [%1, #64] \n\t" \
"ldr x8, [%1, #72] \n\t" \
"str x8, [sp, #0] \n\t" \
"ldr x8, [%1] \n\t" /* target->x8 */ \
VALGRIND_BRANCH_AND_LINK_TO_NOREDIR_X8 \
VALGRIND_RESTORE_STACK \
"mov %0, x0" \
: /*out*/ "=r" (_res) \
: /*in*/ "0" (&_argvec[0]) \
: /*trash*/ "cc", "memory", __CALLER_SAVED_REGS, "x21" \
); \
lval = (__typeof__(lval)) _res; \
} while (0)
#define CALL_FN_W_10W(lval, orig, arg1,arg2,arg3,arg4,arg5,arg6, \
arg7,arg8,arg9,arg10) \
do { \
volatile OrigFn _orig = (orig); \
volatile unsigned long _argvec[11]; \
volatile unsigned long _res; \
_argvec[0] = (unsigned long)_orig.nraddr; \
_argvec[1] = (unsigned long)(arg1); \
_argvec[2] = (unsigned long)(arg2); \
_argvec[3] = (unsigned long)(arg3); \
_argvec[4] = (unsigned long)(arg4); \
_argvec[5] = (unsigned long)(arg5); \
_argvec[6] = (unsigned long)(arg6); \
_argvec[7] = (unsigned long)(arg7); \
_argvec[8] = (unsigned long)(arg8); \
_argvec[9] = (unsigned long)(arg9); \
_argvec[10] = (unsigned long)(arg10); \
__asm__ volatile( \
VALGRIND_ALIGN_STACK \
"sub sp, sp, #0x20 \n\t" \
"ldr x0, [%1, #8] \n\t" \
"ldr x1, [%1, #16] \n\t" \
"ldr x2, [%1, #24] \n\t" \
"ldr x3, [%1, #32] \n\t" \
"ldr x4, [%1, #40] \n\t" \
"ldr x5, [%1, #48] \n\t" \
"ldr x6, [%1, #56] \n\t" \
"ldr x7, [%1, #64] \n\t" \
"ldr x8, [%1, #72] \n\t" \
"str x8, [sp, #0] \n\t" \
"ldr x8, [%1, #80] \n\t" \
"str x8, [sp, #8] \n\t" \
"ldr x8, [%1] \n\t" /* target->x8 */ \
VALGRIND_BRANCH_AND_LINK_TO_NOREDIR_X8 \
VALGRIND_RESTORE_STACK \
"mov %0, x0" \
: /*out*/ "=r" (_res) \
: /*in*/ "0" (&_argvec[0]) \
: /*trash*/ "cc", "memory", __CALLER_SAVED_REGS, "x21" \
); \
lval = (__typeof__(lval)) _res; \
} while (0)
#define CALL_FN_W_11W(lval, orig, arg1,arg2,arg3,arg4,arg5,arg6, \
arg7,arg8,arg9,arg10,arg11) \
do { \
volatile OrigFn _orig = (orig); \
volatile unsigned long _argvec[12]; \
volatile unsigned long _res; \
_argvec[0] = (unsigned long)_orig.nraddr; \
_argvec[1] = (unsigned long)(arg1); \
_argvec[2] = (unsigned long)(arg2); \
_argvec[3] = (unsigned long)(arg3); \
_argvec[4] = (unsigned long)(arg4); \
_argvec[5] = (unsigned long)(arg5); \
_argvec[6] = (unsigned long)(arg6); \
_argvec[7] = (unsigned long)(arg7); \
_argvec[8] = (unsigned long)(arg8); \
_argvec[9] = (unsigned long)(arg9); \
_argvec[10] = (unsigned long)(arg10); \
_argvec[11] = (unsigned long)(arg11); \
__asm__ volatile( \
VALGRIND_ALIGN_STACK \
"sub sp, sp, #0x30 \n\t" \
"ldr x0, [%1, #8] \n\t" \
"ldr x1, [%1, #16] \n\t" \
"ldr x2, [%1, #24] \n\t" \
"ldr x3, [%1, #32] \n\t" \
"ldr x4, [%1, #40] \n\t" \
"ldr x5, [%1, #48] \n\t" \
"ldr x6, [%1, #56] \n\t" \
"ldr x7, [%1, #64] \n\t" \
"ldr x8, [%1, #72] \n\t" \
"str x8, [sp, #0] \n\t" \
"ldr x8, [%1, #80] \n\t" \
"str x8, [sp, #8] \n\t" \
"ldr x8, [%1, #88] \n\t" \
"str x8, [sp, #16] \n\t" \
"ldr x8, [%1] \n\t" /* target->x8 */ \
VALGRIND_BRANCH_AND_LINK_TO_NOREDIR_X8 \
VALGRIND_RESTORE_STACK \
"mov %0, x0" \
: /*out*/ "=r" (_res) \
: /*in*/ "0" (&_argvec[0]) \
: /*trash*/ "cc", "memory", __CALLER_SAVED_REGS, "x21" \
); \
lval = (__typeof__(lval)) _res; \
} while (0)
#define CALL_FN_W_12W(lval, orig, arg1,arg2,arg3,arg4,arg5,arg6, \
arg7,arg8,arg9,arg10,arg11, \
arg12) \
do { \
volatile OrigFn _orig = (orig); \
volatile unsigned long _argvec[13]; \
volatile unsigned long _res; \
_argvec[0] = (unsigned long)_orig.nraddr; \
_argvec[1] = (unsigned long)(arg1); \
_argvec[2] = (unsigned long)(arg2); \
_argvec[3] = (unsigned long)(arg3); \
_argvec[4] = (unsigned long)(arg4); \
_argvec[5] = (unsigned long)(arg5); \
_argvec[6] = (unsigned long)(arg6); \
_argvec[7] = (unsigned long)(arg7); \
_argvec[8] = (unsigned long)(arg8); \
_argvec[9] = (unsigned long)(arg9); \
_argvec[10] = (unsigned long)(arg10); \
_argvec[11] = (unsigned long)(arg11); \
_argvec[12] = (unsigned long)(arg12); \
__asm__ volatile( \
VALGRIND_ALIGN_STACK \
"sub sp, sp, #0x30 \n\t" \
"ldr x0, [%1, #8] \n\t" \
"ldr x1, [%1, #16] \n\t" \
"ldr x2, [%1, #24] \n\t" \
"ldr x3, [%1, #32] \n\t" \
"ldr x4, [%1, #40] \n\t" \
"ldr x5, [%1, #48] \n\t" \
"ldr x6, [%1, #56] \n\t" \
"ldr x7, [%1, #64] \n\t" \
"ldr x8, [%1, #72] \n\t" \
"str x8, [sp, #0] \n\t" \
"ldr x8, [%1, #80] \n\t" \
"str x8, [sp, #8] \n\t" \
"ldr x8, [%1, #88] \n\t" \
"str x8, [sp, #16] \n\t" \
"ldr x8, [%1, #96] \n\t" \
"str x8, [sp, #24] \n\t" \
"ldr x8, [%1] \n\t" /* target->x8 */ \
VALGRIND_BRANCH_AND_LINK_TO_NOREDIR_X8 \
VALGRIND_RESTORE_STACK \
"mov %0, x0" \
: /*out*/ "=r" (_res) \
: /*in*/ "0" (&_argvec[0]) \
: /*trash*/ "cc", "memory", __CALLER_SAVED_REGS, "x21" \
); \
lval = (__typeof__(lval)) _res; \
} while (0)
#endif /* PLAT_arm64_linux */
/* ------------------------- s390x-linux ------------------------- */
#if defined(PLAT_s390x_linux)
/* Similar workaround as amd64 (see above), but we use r11 as frame
pointer and save the old r11 in r7. r11 might be used for
argvec, therefore we copy argvec in r1 since r1 is clobbered
after the call anyway. */
#if defined(__GNUC__) && defined(__GCC_HAVE_DWARF2_CFI_ASM)
# define __FRAME_POINTER \
,"d"(__builtin_dwarf_cfa())
# define VALGRIND_CFI_PROLOGUE \
".cfi_remember_state\n\t" \
"lgr 1,%1\n\t" /* copy the argvec pointer in r1 */ \
"lgr 7,11\n\t" \
"lgr 11,%2\n\t" \
".cfi_def_cfa r11, 0\n\t"
# define VALGRIND_CFI_EPILOGUE \
"lgr 11, 7\n\t" \
".cfi_restore_state\n\t"
#else
# define __FRAME_POINTER
# define VALGRIND_CFI_PROLOGUE \
"lgr 1,%1\n\t"
# define VALGRIND_CFI_EPILOGUE
#endif
/* Nb: On s390 the stack pointer is properly aligned *at all times*
according to the s390 GCC maintainer. (The ABI specification is not
precise in this regard.) Therefore, VALGRIND_ALIGN_STACK and
VALGRIND_RESTORE_STACK are not defined here. */
/* These regs are trashed by the hidden call. Note that we overwrite
r14 in s390_irgen_noredir (VEX/priv/guest_s390_irgen.c) to give the
function a proper return address. All others are ABI defined call
clobbers. */
#if defined(__VX__) || defined(__S390_VX__)
#define __CALLER_SAVED_REGS "0", "1", "2", "3", "4", "5", "14", \
"v0", "v1", "v2", "v3", "v4", "v5", "v6", "v7", \
"v8", "v9", "v10", "v11", "v12", "v13", "v14", "v15", \
"v16", "v17", "v18", "v19", "v20", "v21", "v22", "v23", \
"v24", "v25", "v26", "v27", "v28", "v29", "v30", "v31"
#else
#define __CALLER_SAVED_REGS "0", "1", "2", "3", "4", "5", "14", \
"f0", "f1", "f2", "f3", "f4", "f5", "f6", "f7"
#endif
/* Nb: Although r11 is modified in the asm snippets below (inside
VALGRIND_CFI_PROLOGUE) it is not listed in the clobber section, for
two reasons:
(1) r11 is restored in VALGRIND_CFI_EPILOGUE, so effectively it is not
modified
(2) GCC will complain that r11 cannot appear inside a clobber section,
when compiled with -O -fno-omit-frame-pointer
*/
#define CALL_FN_W_v(lval, orig) \
do { \
volatile OrigFn _orig = (orig); \
volatile unsigned long _argvec[1]; \
volatile unsigned long _res; \
_argvec[0] = (unsigned long)_orig.nraddr; \
__asm__ volatile( \
VALGRIND_CFI_PROLOGUE \
"aghi 15,-160\n\t" \
"lg 1, 0(1)\n\t" /* target->r1 */ \
VALGRIND_CALL_NOREDIR_R1 \
"aghi 15,160\n\t" \
VALGRIND_CFI_EPILOGUE \
"lgr %0, 2\n\t" \
: /*out*/ "=d" (_res) \
: /*in*/ "d" (&_argvec[0]) __FRAME_POINTER \
: /*trash*/ "cc", "memory", __CALLER_SAVED_REGS,"7" \
); \
lval = (__typeof__(lval)) _res; \
} while (0)
/* The call abi has the arguments in r2-r6 and stack */
#define CALL_FN_W_W(lval, orig, arg1) \
do { \
volatile OrigFn _orig = (orig); \
volatile unsigned long _argvec[2]; \
volatile unsigned long _res; \
_argvec[0] = (unsigned long)_orig.nraddr; \
_argvec[1] = (unsigned long)arg1; \
__asm__ volatile( \
VALGRIND_CFI_PROLOGUE \
"aghi 15,-160\n\t" \
"lg 2, 8(1)\n\t" \
"lg 1, 0(1)\n\t" \
VALGRIND_CALL_NOREDIR_R1 \
"aghi 15,160\n\t" \
VALGRIND_CFI_EPILOGUE \
"lgr %0, 2\n\t" \
: /*out*/ "=d" (_res) \
: /*in*/ "a" (&_argvec[0]) __FRAME_POINTER \
: /*trash*/ "cc", "memory", __CALLER_SAVED_REGS,"7" \
); \
lval = (__typeof__(lval)) _res; \
} while (0)
#define CALL_FN_W_WW(lval, orig, arg1, arg2) \
do { \
volatile OrigFn _orig = (orig); \
volatile unsigned long _argvec[3]; \
volatile unsigned long _res; \
_argvec[0] = (unsigned long)_orig.nraddr; \
_argvec[1] = (unsigned long)arg1; \
_argvec[2] = (unsigned long)arg2; \
__asm__ volatile( \
VALGRIND_CFI_PROLOGUE \
"aghi 15,-160\n\t" \
"lg 2, 8(1)\n\t" \
"lg 3,16(1)\n\t" \
"lg 1, 0(1)\n\t" \
VALGRIND_CALL_NOREDIR_R1 \
"aghi 15,160\n\t" \
VALGRIND_CFI_EPILOGUE \
"lgr %0, 2\n\t" \
: /*out*/ "=d" (_res) \
: /*in*/ "a" (&_argvec[0]) __FRAME_POINTER \
: /*trash*/ "cc", "memory", __CALLER_SAVED_REGS,"7" \
); \
lval = (__typeof__(lval)) _res; \
} while (0)
#define CALL_FN_W_WWW(lval, orig, arg1, arg2, arg3) \
do { \
volatile OrigFn _orig = (orig); \
volatile unsigned long _argvec[4]; \
volatile unsigned long _res; \
_argvec[0] = (unsigned long)_orig.nraddr; \
_argvec[1] = (unsigned long)arg1; \
_argvec[2] = (unsigned long)arg2; \
_argvec[3] = (unsigned long)arg3; \
__asm__ volatile( \
VALGRIND_CFI_PROLOGUE \
"aghi 15,-160\n\t" \
"lg 2, 8(1)\n\t" \
"lg 3,16(1)\n\t" \
"lg 4,24(1)\n\t" \
"lg 1, 0(1)\n\t" \
VALGRIND_CALL_NOREDIR_R1 \
"aghi 15,160\n\t" \
VALGRIND_CFI_EPILOGUE \
"lgr %0, 2\n\t" \
: /*out*/ "=d" (_res) \
: /*in*/ "a" (&_argvec[0]) __FRAME_POINTER \
: /*trash*/ "cc", "memory", __CALLER_SAVED_REGS,"7" \
); \
lval = (__typeof__(lval)) _res; \
} while (0)
#define CALL_FN_W_WWWW(lval, orig, arg1, arg2, arg3, arg4) \
do { \
volatile OrigFn _orig = (orig); \
volatile unsigned long _argvec[5]; \
volatile unsigned long _res; \
_argvec[0] = (unsigned long)_orig.nraddr; \
_argvec[1] = (unsigned long)arg1; \
_argvec[2] = (unsigned long)arg2; \
_argvec[3] = (unsigned long)arg3; \
_argvec[4] = (unsigned long)arg4; \
__asm__ volatile( \
VALGRIND_CFI_PROLOGUE \
"aghi 15,-160\n\t" \
"lg 2, 8(1)\n\t" \
"lg 3,16(1)\n\t" \
"lg 4,24(1)\n\t" \
"lg 5,32(1)\n\t" \
"lg 1, 0(1)\n\t" \
VALGRIND_CALL_NOREDIR_R1 \
"aghi 15,160\n\t" \
VALGRIND_CFI_EPILOGUE \
"lgr %0, 2\n\t" \
: /*out*/ "=d" (_res) \
: /*in*/ "a" (&_argvec[0]) __FRAME_POINTER \
: /*trash*/ "cc", "memory", __CALLER_SAVED_REGS,"7" \
); \
lval = (__typeof__(lval)) _res; \
} while (0)
#define CALL_FN_W_5W(lval, orig, arg1, arg2, arg3, arg4, arg5) \
do { \
volatile OrigFn _orig = (orig); \
volatile unsigned long _argvec[6]; \
volatile unsigned long _res; \
_argvec[0] = (unsigned long)_orig.nraddr; \
_argvec[1] = (unsigned long)arg1; \
_argvec[2] = (unsigned long)arg2; \
_argvec[3] = (unsigned long)arg3; \
_argvec[4] = (unsigned long)arg4; \
_argvec[5] = (unsigned long)arg5; \
__asm__ volatile( \
VALGRIND_CFI_PROLOGUE \
"aghi 15,-160\n\t" \
"lg 2, 8(1)\n\t" \
"lg 3,16(1)\n\t" \
"lg 4,24(1)\n\t" \
"lg 5,32(1)\n\t" \
"lg 6,40(1)\n\t" \
"lg 1, 0(1)\n\t" \
VALGRIND_CALL_NOREDIR_R1 \
"aghi 15,160\n\t" \
VALGRIND_CFI_EPILOGUE \
"lgr %0, 2\n\t" \
: /*out*/ "=d" (_res) \
: /*in*/ "a" (&_argvec[0]) __FRAME_POINTER \
: /*trash*/ "cc", "memory", __CALLER_SAVED_REGS,"6","7" \
); \
lval = (__typeof__(lval)) _res; \
} while (0)
#define CALL_FN_W_6W(lval, orig, arg1, arg2, arg3, arg4, arg5, \
arg6) \
do { \
volatile OrigFn _orig = (orig); \
volatile unsigned long _argvec[7]; \
volatile unsigned long _res; \
_argvec[0] = (unsigned long)_orig.nraddr; \
_argvec[1] = (unsigned long)arg1; \
_argvec[2] = (unsigned long)arg2; \
_argvec[3] = (unsigned long)arg3; \
_argvec[4] = (unsigned long)arg4; \
_argvec[5] = (unsigned long)arg5; \
_argvec[6] = (unsigned long)arg6; \
__asm__ volatile( \
VALGRIND_CFI_PROLOGUE \
"aghi 15,-168\n\t" \
"lg 2, 8(1)\n\t" \
"lg 3,16(1)\n\t" \
"lg 4,24(1)\n\t" \
"lg 5,32(1)\n\t" \
"lg 6,40(1)\n\t" \
"mvc 160(8,15), 48(1)\n\t" \
"lg 1, 0(1)\n\t" \
VALGRIND_CALL_NOREDIR_R1 \
"aghi 15,168\n\t" \
VALGRIND_CFI_EPILOGUE \
"lgr %0, 2\n\t" \
: /*out*/ "=d" (_res) \
: /*in*/ "a" (&_argvec[0]) __FRAME_POINTER \
: /*trash*/ "cc", "memory", __CALLER_SAVED_REGS,"6","7" \
); \
lval = (__typeof__(lval)) _res; \
} while (0)
#define CALL_FN_W_7W(lval, orig, arg1, arg2, arg3, arg4, arg5, \
arg6, arg7) \
do { \
volatile OrigFn _orig = (orig); \
volatile unsigned long _argvec[8]; \
volatile unsigned long _res; \
_argvec[0] = (unsigned long)_orig.nraddr; \
_argvec[1] = (unsigned long)arg1; \
_argvec[2] = (unsigned long)arg2; \
_argvec[3] = (unsigned long)arg3; \
_argvec[4] = (unsigned long)arg4; \
_argvec[5] = (unsigned long)arg5; \
_argvec[6] = (unsigned long)arg6; \
_argvec[7] = (unsigned long)arg7; \
__asm__ volatile( \
VALGRIND_CFI_PROLOGUE \
"aghi 15,-176\n\t" \
"lg 2, 8(1)\n\t" \
"lg 3,16(1)\n\t" \
"lg 4,24(1)\n\t" \
"lg 5,32(1)\n\t" \
"lg 6,40(1)\n\t" \
"mvc 160(8,15), 48(1)\n\t" \
"mvc 168(8,15), 56(1)\n\t" \
"lg 1, 0(1)\n\t" \
VALGRIND_CALL_NOREDIR_R1 \
"aghi 15,176\n\t" \
VALGRIND_CFI_EPILOGUE \
"lgr %0, 2\n\t" \
: /*out*/ "=d" (_res) \
: /*in*/ "a" (&_argvec[0]) __FRAME_POINTER \
: /*trash*/ "cc", "memory", __CALLER_SAVED_REGS,"6","7" \
); \
lval = (__typeof__(lval)) _res; \
} while (0)
#define CALL_FN_W_8W(lval, orig, arg1, arg2, arg3, arg4, arg5, \
arg6, arg7 ,arg8) \
do { \
volatile OrigFn _orig = (orig); \
volatile unsigned long _argvec[9]; \
volatile unsigned long _res; \
_argvec[0] = (unsigned long)_orig.nraddr; \
_argvec[1] = (unsigned long)arg1; \
_argvec[2] = (unsigned long)arg2; \
_argvec[3] = (unsigned long)arg3; \
_argvec[4] = (unsigned long)arg4; \
_argvec[5] = (unsigned long)arg5; \
_argvec[6] = (unsigned long)arg6; \
_argvec[7] = (unsigned long)arg7; \
_argvec[8] = (unsigned long)arg8; \
__asm__ volatile( \
VALGRIND_CFI_PROLOGUE \
"aghi 15,-184\n\t" \
"lg 2, 8(1)\n\t" \
"lg 3,16(1)\n\t" \
"lg 4,24(1)\n\t" \
"lg 5,32(1)\n\t" \
"lg 6,40(1)\n\t" \
"mvc 160(8,15), 48(1)\n\t" \
"mvc 168(8,15), 56(1)\n\t" \
"mvc 176(8,15), 64(1)\n\t" \
"lg 1, 0(1)\n\t" \
VALGRIND_CALL_NOREDIR_R1 \
"aghi 15,184\n\t" \
VALGRIND_CFI_EPILOGUE \
"lgr %0, 2\n\t" \
: /*out*/ "=d" (_res) \
: /*in*/ "a" (&_argvec[0]) __FRAME_POINTER \
: /*trash*/ "cc", "memory", __CALLER_SAVED_REGS,"6","7" \
); \
lval = (__typeof__(lval)) _res; \
} while (0)
#define CALL_FN_W_9W(lval, orig, arg1, arg2, arg3, arg4, arg5, \
arg6, arg7 ,arg8, arg9) \
do { \
volatile OrigFn _orig = (orig); \
volatile unsigned long _argvec[10]; \
volatile unsigned long _res; \
_argvec[0] = (unsigned long)_orig.nraddr; \
_argvec[1] = (unsigned long)arg1; \
_argvec[2] = (unsigned long)arg2; \
_argvec[3] = (unsigned long)arg3; \
_argvec[4] = (unsigned long)arg4; \
_argvec[5] = (unsigned long)arg5; \
_argvec[6] = (unsigned long)arg6; \
_argvec[7] = (unsigned long)arg7; \
_argvec[8] = (unsigned long)arg8; \
_argvec[9] = (unsigned long)arg9; \
__asm__ volatile( \
VALGRIND_CFI_PROLOGUE \
"aghi 15,-192\n\t" \
"lg 2, 8(1)\n\t" \
"lg 3,16(1)\n\t" \
"lg 4,24(1)\n\t" \
"lg 5,32(1)\n\t" \
"lg 6,40(1)\n\t" \
"mvc 160(8,15), 48(1)\n\t" \
"mvc 168(8,15), 56(1)\n\t" \
"mvc 176(8,15), 64(1)\n\t" \
"mvc 184(8,15), 72(1)\n\t" \
"lg 1, 0(1)\n\t" \
VALGRIND_CALL_NOREDIR_R1 \
"aghi 15,192\n\t" \
VALGRIND_CFI_EPILOGUE \
"lgr %0, 2\n\t" \
: /*out*/ "=d" (_res) \
: /*in*/ "a" (&_argvec[0]) __FRAME_POINTER \
: /*trash*/ "cc", "memory", __CALLER_SAVED_REGS,"6","7" \
); \
lval = (__typeof__(lval)) _res; \
} while (0)
#define CALL_FN_W_10W(lval, orig, arg1, arg2, arg3, arg4, arg5, \
arg6, arg7 ,arg8, arg9, arg10) \
do { \
volatile OrigFn _orig = (orig); \
volatile unsigned long _argvec[11]; \
volatile unsigned long _res; \
_argvec[0] = (unsigned long)_orig.nraddr; \
_argvec[1] = (unsigned long)arg1; \
_argvec[2] = (unsigned long)arg2; \
_argvec[3] = (unsigned long)arg3; \
_argvec[4] = (unsigned long)arg4; \
_argvec[5] = (unsigned long)arg5; \
_argvec[6] = (unsigned long)arg6; \
_argvec[7] = (unsigned long)arg7; \
_argvec[8] = (unsigned long)arg8; \
_argvec[9] = (unsigned long)arg9; \
_argvec[10] = (unsigned long)arg10; \
__asm__ volatile( \
VALGRIND_CFI_PROLOGUE \
"aghi 15,-200\n\t" \
"lg 2, 8(1)\n\t" \
"lg 3,16(1)\n\t" \
"lg 4,24(1)\n\t" \
"lg 5,32(1)\n\t" \
"lg 6,40(1)\n\t" \
"mvc 160(8,15), 48(1)\n\t" \
"mvc 168(8,15), 56(1)\n\t" \
"mvc 176(8,15), 64(1)\n\t" \
"mvc 184(8,15), 72(1)\n\t" \
"mvc 192(8,15), 80(1)\n\t" \
"lg 1, 0(1)\n\t" \
VALGRIND_CALL_NOREDIR_R1 \
"aghi 15,200\n\t" \
VALGRIND_CFI_EPILOGUE \
"lgr %0, 2\n\t" \
: /*out*/ "=d" (_res) \
: /*in*/ "a" (&_argvec[0]) __FRAME_POINTER \
: /*trash*/ "cc", "memory", __CALLER_SAVED_REGS,"6","7" \
); \
lval = (__typeof__(lval)) _res; \
} while (0)
#define CALL_FN_W_11W(lval, orig, arg1, arg2, arg3, arg4, arg5, \
arg6, arg7 ,arg8, arg9, arg10, arg11) \
do { \
volatile OrigFn _orig = (orig); \
volatile unsigned long _argvec[12]; \
volatile unsigned long _res; \
_argvec[0] = (unsigned long)_orig.nraddr; \
_argvec[1] = (unsigned long)arg1; \
_argvec[2] = (unsigned long)arg2; \
_argvec[3] = (unsigned long)arg3; \
_argvec[4] = (unsigned long)arg4; \
_argvec[5] = (unsigned long)arg5; \
_argvec[6] = (unsigned long)arg6; \
_argvec[7] = (unsigned long)arg7; \
_argvec[8] = (unsigned long)arg8; \
_argvec[9] = (unsigned long)arg9; \
_argvec[10] = (unsigned long)arg10; \
_argvec[11] = (unsigned long)arg11; \
__asm__ volatile( \
VALGRIND_CFI_PROLOGUE \
"aghi 15,-208\n\t" \
"lg 2, 8(1)\n\t" \
"lg 3,16(1)\n\t" \
"lg 4,24(1)\n\t" \
"lg 5,32(1)\n\t" \
"lg 6,40(1)\n\t" \
"mvc 160(8,15), 48(1)\n\t" \
"mvc 168(8,15), 56(1)\n\t" \
"mvc 176(8,15), 64(1)\n\t" \
"mvc 184(8,15), 72(1)\n\t" \
"mvc 192(8,15), 80(1)\n\t" \
"mvc 200(8,15), 88(1)\n\t" \
"lg 1, 0(1)\n\t" \
VALGRIND_CALL_NOREDIR_R1 \
"aghi 15,208\n\t" \
VALGRIND_CFI_EPILOGUE \
"lgr %0, 2\n\t" \
: /*out*/ "=d" (_res) \
: /*in*/ "a" (&_argvec[0]) __FRAME_POINTER \
: /*trash*/ "cc", "memory", __CALLER_SAVED_REGS,"6","7" \
); \
lval = (__typeof__(lval)) _res; \
} while (0)
#define CALL_FN_W_12W(lval, orig, arg1, arg2, arg3, arg4, arg5, \
arg6, arg7 ,arg8, arg9, arg10, arg11, arg12)\
do { \
volatile OrigFn _orig = (orig); \
volatile unsigned long _argvec[13]; \
volatile unsigned long _res; \
_argvec[0] = (unsigned long)_orig.nraddr; \
_argvec[1] = (unsigned long)arg1; \
_argvec[2] = (unsigned long)arg2; \
_argvec[3] = (unsigned long)arg3; \
_argvec[4] = (unsigned long)arg4; \
_argvec[5] = (unsigned long)arg5; \
_argvec[6] = (unsigned long)arg6; \
_argvec[7] = (unsigned long)arg7; \
_argvec[8] = (unsigned long)arg8; \
_argvec[9] = (unsigned long)arg9; \
_argvec[10] = (unsigned long)arg10; \
_argvec[11] = (unsigned long)arg11; \
_argvec[12] = (unsigned long)arg12; \
__asm__ volatile( \
VALGRIND_CFI_PROLOGUE \
"aghi 15,-216\n\t" \
"lg 2, 8(1)\n\t" \
"lg 3,16(1)\n\t" \
"lg 4,24(1)\n\t" \
"lg 5,32(1)\n\t" \
"lg 6,40(1)\n\t" \
"mvc 160(8,15), 48(1)\n\t" \
"mvc 168(8,15), 56(1)\n\t" \
"mvc 176(8,15), 64(1)\n\t" \
"mvc 184(8,15), 72(1)\n\t" \
"mvc 192(8,15), 80(1)\n\t" \
"mvc 200(8,15), 88(1)\n\t" \
"mvc 208(8,15), 96(1)\n\t" \
"lg 1, 0(1)\n\t" \
VALGRIND_CALL_NOREDIR_R1 \
"aghi 15,216\n\t" \
VALGRIND_CFI_EPILOGUE \
"lgr %0, 2\n\t" \
: /*out*/ "=d" (_res) \
: /*in*/ "a" (&_argvec[0]) __FRAME_POINTER \
: /*trash*/ "cc", "memory", __CALLER_SAVED_REGS,"6","7" \
); \
lval = (__typeof__(lval)) _res; \
} while (0)
#endif /* PLAT_s390x_linux */
/* ------------------------- mips32-linux ----------------------- */
#if defined(PLAT_mips32_linux)
/* These regs are trashed by the hidden call. */
#define __CALLER_SAVED_REGS "$2", "$3", "$4", "$5", "$6", \
"$7", "$8", "$9", "$10", "$11", "$12", "$13", "$14", "$15", "$24", \
"$25", "$31"
/* These CALL_FN_ macros assume that on mips-linux, sizeof(unsigned
long) == 4. */
#define CALL_FN_W_v(lval, orig) \
do { \
volatile OrigFn _orig = (orig); \
volatile unsigned long _argvec[1]; \
volatile unsigned long _res; \
_argvec[0] = (unsigned long)_orig.nraddr; \
__asm__ volatile( \
"subu $29, $29, 8 \n\t" \
"sw $28, 0($29) \n\t" \
"sw $31, 4($29) \n\t" \
"subu $29, $29, 16 \n\t" \
"lw $25, 0(%1) \n\t" /* target->t9 */ \
VALGRIND_CALL_NOREDIR_T9 \
"addu $29, $29, 16\n\t" \
"lw $28, 0($29) \n\t" \
"lw $31, 4($29) \n\t" \
"addu $29, $29, 8 \n\t" \
"move %0, $2\n" \
: /*out*/ "=r" (_res) \
: /*in*/ "0" (&_argvec[0]) \
: /*trash*/ "memory", __CALLER_SAVED_REGS \
); \
lval = (__typeof__(lval)) _res; \
} while (0)
#define CALL_FN_W_W(lval, orig, arg1) \
do { \
volatile OrigFn _orig = (orig); \
volatile unsigned long _argvec[2]; \
volatile unsigned long _res; \
_argvec[0] = (unsigned long)_orig.nraddr; \
_argvec[1] = (unsigned long)(arg1); \
__asm__ volatile( \
"subu $29, $29, 8 \n\t" \
"sw $28, 0($29) \n\t" \
"sw $31, 4($29) \n\t" \
"subu $29, $29, 16 \n\t" \
"lw $4, 4(%1) \n\t" /* arg1*/ \
"lw $25, 0(%1) \n\t" /* target->t9 */ \
VALGRIND_CALL_NOREDIR_T9 \
"addu $29, $29, 16 \n\t" \
"lw $28, 0($29) \n\t" \
"lw $31, 4($29) \n\t" \
"addu $29, $29, 8 \n\t" \
"move %0, $2\n" \
: /*out*/ "=r" (_res) \
: /*in*/ "0" (&_argvec[0]) \
: /*trash*/ "memory", __CALLER_SAVED_REGS \
); \
lval = (__typeof__(lval)) _res; \
} while (0)
#define CALL_FN_W_WW(lval, orig, arg1,arg2) \
do { \
volatile OrigFn _orig = (orig); \
volatile unsigned long _argvec[3]; \
volatile unsigned long _res; \
_argvec[0] = (unsigned long)_orig.nraddr; \
_argvec[1] = (unsigned long)(arg1); \
_argvec[2] = (unsigned long)(arg2); \
__asm__ volatile( \
"subu $29, $29, 8 \n\t" \
"sw $28, 0($29) \n\t" \
"sw $31, 4($29) \n\t" \
"subu $29, $29, 16 \n\t" \
"lw $4, 4(%1) \n\t" \
"lw $5, 8(%1) \n\t" \
"lw $25, 0(%1) \n\t" /* target->t9 */ \
VALGRIND_CALL_NOREDIR_T9 \
"addu $29, $29, 16 \n\t" \
"lw $28, 0($29) \n\t" \
"lw $31, 4($29) \n\t" \
"addu $29, $29, 8 \n\t" \
"move %0, $2\n" \
: /*out*/ "=r" (_res) \
: /*in*/ "0" (&_argvec[0]) \
: /*trash*/ "memory", __CALLER_SAVED_REGS \
); \
lval = (__typeof__(lval)) _res; \
} while (0)
#define CALL_FN_W_WWW(lval, orig, arg1,arg2,arg3) \
do { \
volatile OrigFn _orig = (orig); \
volatile unsigned long _argvec[4]; \
volatile unsigned long _res; \
_argvec[0] = (unsigned long)_orig.nraddr; \
_argvec[1] = (unsigned long)(arg1); \
_argvec[2] = (unsigned long)(arg2); \
_argvec[3] = (unsigned long)(arg3); \
__asm__ volatile( \
"subu $29, $29, 8 \n\t" \
"sw $28, 0($29) \n\t" \
"sw $31, 4($29) \n\t" \
"subu $29, $29, 16 \n\t" \
"lw $4, 4(%1) \n\t" \
"lw $5, 8(%1) \n\t" \
"lw $6, 12(%1) \n\t" \
"lw $25, 0(%1) \n\t" /* target->t9 */ \
VALGRIND_CALL_NOREDIR_T9 \
"addu $29, $29, 16 \n\t" \
"lw $28, 0($29) \n\t" \
"lw $31, 4($29) \n\t" \
"addu $29, $29, 8 \n\t" \
"move %0, $2\n" \
: /*out*/ "=r" (_res) \
: /*in*/ "0" (&_argvec[0]) \
: /*trash*/ "memory", __CALLER_SAVED_REGS \
); \
lval = (__typeof__(lval)) _res; \
} while (0)
#define CALL_FN_W_WWWW(lval, orig, arg1,arg2,arg3,arg4) \
do { \
volatile OrigFn _orig = (orig); \
volatile unsigned long _argvec[5]; \
volatile unsigned long _res; \
_argvec[0] = (unsigned long)_orig.nraddr; \
_argvec[1] = (unsigned long)(arg1); \
_argvec[2] = (unsigned long)(arg2); \
_argvec[3] = (unsigned long)(arg3); \
_argvec[4] = (unsigned long)(arg4); \
__asm__ volatile( \
"subu $29, $29, 8 \n\t" \
"sw $28, 0($29) \n\t" \
"sw $31, 4($29) \n\t" \
"subu $29, $29, 16 \n\t" \
"lw $4, 4(%1) \n\t" \
"lw $5, 8(%1) \n\t" \
"lw $6, 12(%1) \n\t" \
"lw $7, 16(%1) \n\t" \
"lw $25, 0(%1) \n\t" /* target->t9 */ \
VALGRIND_CALL_NOREDIR_T9 \
"addu $29, $29, 16 \n\t" \
"lw $28, 0($29) \n\t" \
"lw $31, 4($29) \n\t" \
"addu $29, $29, 8 \n\t" \
"move %0, $2\n" \
: /*out*/ "=r" (_res) \
: /*in*/ "0" (&_argvec[0]) \
: /*trash*/ "memory", __CALLER_SAVED_REGS \
); \
lval = (__typeof__(lval)) _res; \
} while (0)
#define CALL_FN_W_5W(lval, orig, arg1,arg2,arg3,arg4,arg5) \
do { \
volatile OrigFn _orig = (orig); \
volatile unsigned long _argvec[6]; \
volatile unsigned long _res; \
_argvec[0] = (unsigned long)_orig.nraddr; \
_argvec[1] = (unsigned long)(arg1); \
_argvec[2] = (unsigned long)(arg2); \
_argvec[3] = (unsigned long)(arg3); \
_argvec[4] = (unsigned long)(arg4); \
_argvec[5] = (unsigned long)(arg5); \
__asm__ volatile( \
"subu $29, $29, 8 \n\t" \
"sw $28, 0($29) \n\t" \
"sw $31, 4($29) \n\t" \
"lw $4, 20(%1) \n\t" \
"subu $29, $29, 24\n\t" \
"sw $4, 16($29) \n\t" \
"lw $4, 4(%1) \n\t" \
"lw $5, 8(%1) \n\t" \
"lw $6, 12(%1) \n\t" \
"lw $7, 16(%1) \n\t" \
"lw $25, 0(%1) \n\t" /* target->t9 */ \
VALGRIND_CALL_NOREDIR_T9 \
"addu $29, $29, 24 \n\t" \
"lw $28, 0($29) \n\t" \
"lw $31, 4($29) \n\t" \
"addu $29, $29, 8 \n\t" \
"move %0, $2\n" \
: /*out*/ "=r" (_res) \
: /*in*/ "0" (&_argvec[0]) \
: /*trash*/ "memory", __CALLER_SAVED_REGS \
); \
lval = (__typeof__(lval)) _res; \
} while (0)
#define CALL_FN_W_6W(lval, orig, arg1,arg2,arg3,arg4,arg5,arg6) \
do { \
volatile OrigFn _orig = (orig); \
volatile unsigned long _argvec[7]; \
volatile unsigned long _res; \
_argvec[0] = (unsigned long)_orig.nraddr; \
_argvec[1] = (unsigned long)(arg1); \
_argvec[2] = (unsigned long)(arg2); \
_argvec[3] = (unsigned long)(arg3); \
_argvec[4] = (unsigned long)(arg4); \
_argvec[5] = (unsigned long)(arg5); \
_argvec[6] = (unsigned long)(arg6); \
__asm__ volatile( \
"subu $29, $29, 8 \n\t" \
"sw $28, 0($29) \n\t" \
"sw $31, 4($29) \n\t" \
"lw $4, 20(%1) \n\t" \
"subu $29, $29, 32\n\t" \
"sw $4, 16($29) \n\t" \
"lw $4, 24(%1) \n\t" \
"nop\n\t" \
"sw $4, 20($29) \n\t" \
"lw $4, 4(%1) \n\t" \
"lw $5, 8(%1) \n\t" \
"lw $6, 12(%1) \n\t" \
"lw $7, 16(%1) \n\t" \
"lw $25, 0(%1) \n\t" /* target->t9 */ \
VALGRIND_CALL_NOREDIR_T9 \
"addu $29, $29, 32 \n\t" \
"lw $28, 0($29) \n\t" \
"lw $31, 4($29) \n\t" \
"addu $29, $29, 8 \n\t" \
"move %0, $2\n" \
: /*out*/ "=r" (_res) \
: /*in*/ "0" (&_argvec[0]) \
: /*trash*/ "memory", __CALLER_SAVED_REGS \
); \
lval = (__typeof__(lval)) _res; \
} while (0)
#define CALL_FN_W_7W(lval, orig, arg1,arg2,arg3,arg4,arg5,arg6, \
arg7) \
do { \
volatile OrigFn _orig = (orig); \
volatile unsigned long _argvec[8]; \
volatile unsigned long _res; \
_argvec[0] = (unsigned long)_orig.nraddr; \
_argvec[1] = (unsigned long)(arg1); \
_argvec[2] = (unsigned long)(arg2); \
_argvec[3] = (unsigned long)(arg3); \
_argvec[4] = (unsigned long)(arg4); \
_argvec[5] = (unsigned long)(arg5); \
_argvec[6] = (unsigned long)(arg6); \
_argvec[7] = (unsigned long)(arg7); \
__asm__ volatile( \
"subu $29, $29, 8 \n\t" \
"sw $28, 0($29) \n\t" \
"sw $31, 4($29) \n\t" \
"lw $4, 20(%1) \n\t" \
"subu $29, $29, 32\n\t" \
"sw $4, 16($29) \n\t" \
"lw $4, 24(%1) \n\t" \
"sw $4, 20($29) \n\t" \
"lw $4, 28(%1) \n\t" \
"sw $4, 24($29) \n\t" \
"lw $4, 4(%1) \n\t" \
"lw $5, 8(%1) \n\t" \
"lw $6, 12(%1) \n\t" \
"lw $7, 16(%1) \n\t" \
"lw $25, 0(%1) \n\t" /* target->t9 */ \
VALGRIND_CALL_NOREDIR_T9 \
"addu $29, $29, 32 \n\t" \
"lw $28, 0($29) \n\t" \
"lw $31, 4($29) \n\t" \
"addu $29, $29, 8 \n\t" \
"move %0, $2\n" \
: /*out*/ "=r" (_res) \
: /*in*/ "0" (&_argvec[0]) \
: /*trash*/ "memory", __CALLER_SAVED_REGS \
); \
lval = (__typeof__(lval)) _res; \
} while (0)
#define CALL_FN_W_8W(lval, orig, arg1,arg2,arg3,arg4,arg5,arg6, \
arg7,arg8) \
do { \
volatile OrigFn _orig = (orig); \
volatile unsigned long _argvec[9]; \
volatile unsigned long _res; \
_argvec[0] = (unsigned long)_orig.nraddr; \
_argvec[1] = (unsigned long)(arg1); \
_argvec[2] = (unsigned long)(arg2); \
_argvec[3] = (unsigned long)(arg3); \
_argvec[4] = (unsigned long)(arg4); \
_argvec[5] = (unsigned long)(arg5); \
_argvec[6] = (unsigned long)(arg6); \
_argvec[7] = (unsigned long)(arg7); \
_argvec[8] = (unsigned long)(arg8); \
__asm__ volatile( \
"subu $29, $29, 8 \n\t" \
"sw $28, 0($29) \n\t" \
"sw $31, 4($29) \n\t" \
"lw $4, 20(%1) \n\t" \
"subu $29, $29, 40\n\t" \
"sw $4, 16($29) \n\t" \
"lw $4, 24(%1) \n\t" \
"sw $4, 20($29) \n\t" \
"lw $4, 28(%1) \n\t" \
"sw $4, 24($29) \n\t" \
"lw $4, 32(%1) \n\t" \
"sw $4, 28($29) \n\t" \
"lw $4, 4(%1) \n\t" \
"lw $5, 8(%1) \n\t" \
"lw $6, 12(%1) \n\t" \
"lw $7, 16(%1) \n\t" \
"lw $25, 0(%1) \n\t" /* target->t9 */ \
VALGRIND_CALL_NOREDIR_T9 \
"addu $29, $29, 40 \n\t" \
"lw $28, 0($29) \n\t" \
"lw $31, 4($29) \n\t" \
"addu $29, $29, 8 \n\t" \
"move %0, $2\n" \
: /*out*/ "=r" (_res) \
: /*in*/ "0" (&_argvec[0]) \
: /*trash*/ "memory", __CALLER_SAVED_REGS \
); \
lval = (__typeof__(lval)) _res; \
} while (0)
#define CALL_FN_W_9W(lval, orig, arg1,arg2,arg3,arg4,arg5,arg6, \
arg7,arg8,arg9) \
do { \
volatile OrigFn _orig = (orig); \
volatile unsigned long _argvec[10]; \
volatile unsigned long _res; \
_argvec[0] = (unsigned long)_orig.nraddr; \
_argvec[1] = (unsigned long)(arg1); \
_argvec[2] = (unsigned long)(arg2); \
_argvec[3] = (unsigned long)(arg3); \
_argvec[4] = (unsigned long)(arg4); \
_argvec[5] = (unsigned long)(arg5); \
_argvec[6] = (unsigned long)(arg6); \
_argvec[7] = (unsigned long)(arg7); \
_argvec[8] = (unsigned long)(arg8); \
_argvec[9] = (unsigned long)(arg9); \
__asm__ volatile( \
"subu $29, $29, 8 \n\t" \
"sw $28, 0($29) \n\t" \
"sw $31, 4($29) \n\t" \
"lw $4, 20(%1) \n\t" \
"subu $29, $29, 40\n\t" \
"sw $4, 16($29) \n\t" \
"lw $4, 24(%1) \n\t" \
"sw $4, 20($29) \n\t" \
"lw $4, 28(%1) \n\t" \
"sw $4, 24($29) \n\t" \
"lw $4, 32(%1) \n\t" \
"sw $4, 28($29) \n\t" \
"lw $4, 36(%1) \n\t" \
"sw $4, 32($29) \n\t" \
"lw $4, 4(%1) \n\t" \
"lw $5, 8(%1) \n\t" \
"lw $6, 12(%1) \n\t" \
"lw $7, 16(%1) \n\t" \
"lw $25, 0(%1) \n\t" /* target->t9 */ \
VALGRIND_CALL_NOREDIR_T9 \
"addu $29, $29, 40 \n\t" \
"lw $28, 0($29) \n\t" \
"lw $31, 4($29) \n\t" \
"addu $29, $29, 8 \n\t" \
"move %0, $2\n" \
: /*out*/ "=r" (_res) \
: /*in*/ "0" (&_argvec[0]) \
: /*trash*/ "memory", __CALLER_SAVED_REGS \
); \
lval = (__typeof__(lval)) _res; \
} while (0)
#define CALL_FN_W_10W(lval, orig, arg1,arg2,arg3,arg4,arg5,arg6, \
arg7,arg8,arg9,arg10) \
do { \
volatile OrigFn _orig = (orig); \
volatile unsigned long _argvec[11]; \
volatile unsigned long _res; \
_argvec[0] = (unsigned long)_orig.nraddr; \
_argvec[1] = (unsigned long)(arg1); \
_argvec[2] = (unsigned long)(arg2); \
_argvec[3] = (unsigned long)(arg3); \
_argvec[4] = (unsigned long)(arg4); \
_argvec[5] = (unsigned long)(arg5); \
_argvec[6] = (unsigned long)(arg6); \
_argvec[7] = (unsigned long)(arg7); \
_argvec[8] = (unsigned long)(arg8); \
_argvec[9] = (unsigned long)(arg9); \
_argvec[10] = (unsigned long)(arg10); \
__asm__ volatile( \
"subu $29, $29, 8 \n\t" \
"sw $28, 0($29) \n\t" \
"sw $31, 4($29) \n\t" \
"lw $4, 20(%1) \n\t" \
"subu $29, $29, 48\n\t" \
"sw $4, 16($29) \n\t" \
"lw $4, 24(%1) \n\t" \
"sw $4, 20($29) \n\t" \
"lw $4, 28(%1) \n\t" \
"sw $4, 24($29) \n\t" \
"lw $4, 32(%1) \n\t" \
"sw $4, 28($29) \n\t" \
"lw $4, 36(%1) \n\t" \
"sw $4, 32($29) \n\t" \
"lw $4, 40(%1) \n\t" \
"sw $4, 36($29) \n\t" \
"lw $4, 4(%1) \n\t" \
"lw $5, 8(%1) \n\t" \
"lw $6, 12(%1) \n\t" \
"lw $7, 16(%1) \n\t" \
"lw $25, 0(%1) \n\t" /* target->t9 */ \
VALGRIND_CALL_NOREDIR_T9 \
"addu $29, $29, 48 \n\t" \
"lw $28, 0($29) \n\t" \
"lw $31, 4($29) \n\t" \
"addu $29, $29, 8 \n\t" \
"move %0, $2\n" \
: /*out*/ "=r" (_res) \
: /*in*/ "0" (&_argvec[0]) \
: /*trash*/ "memory", __CALLER_SAVED_REGS \
); \
lval = (__typeof__(lval)) _res; \
} while (0)
#define CALL_FN_W_11W(lval, orig, arg1,arg2,arg3,arg4,arg5, \
arg6,arg7,arg8,arg9,arg10, \
arg11) \
do { \
volatile OrigFn _orig = (orig); \
volatile unsigned long _argvec[12]; \
volatile unsigned long _res; \
_argvec[0] = (unsigned long)_orig.nraddr; \
_argvec[1] = (unsigned long)(arg1); \
_argvec[2] = (unsigned long)(arg2); \
_argvec[3] = (unsigned long)(arg3); \
_argvec[4] = (unsigned long)(arg4); \
_argvec[5] = (unsigned long)(arg5); \
_argvec[6] = (unsigned long)(arg6); \
_argvec[7] = (unsigned long)(arg7); \
_argvec[8] = (unsigned long)(arg8); \
_argvec[9] = (unsigned long)(arg9); \
_argvec[10] = (unsigned long)(arg10); \
_argvec[11] = (unsigned long)(arg11); \
__asm__ volatile( \
"subu $29, $29, 8 \n\t" \
"sw $28, 0($29) \n\t" \
"sw $31, 4($29) \n\t" \
"lw $4, 20(%1) \n\t" \
"subu $29, $29, 48\n\t" \
"sw $4, 16($29) \n\t" \
"lw $4, 24(%1) \n\t" \
"sw $4, 20($29) \n\t" \
"lw $4, 28(%1) \n\t" \
"sw $4, 24($29) \n\t" \
"lw $4, 32(%1) \n\t" \
"sw $4, 28($29) \n\t" \
"lw $4, 36(%1) \n\t" \
"sw $4, 32($29) \n\t" \
"lw $4, 40(%1) \n\t" \
"sw $4, 36($29) \n\t" \
"lw $4, 44(%1) \n\t" \
"sw $4, 40($29) \n\t" \
"lw $4, 4(%1) \n\t" \
"lw $5, 8(%1) \n\t" \
"lw $6, 12(%1) \n\t" \
"lw $7, 16(%1) \n\t" \
"lw $25, 0(%1) \n\t" /* target->t9 */ \
VALGRIND_CALL_NOREDIR_T9 \
"addu $29, $29, 48 \n\t" \
"lw $28, 0($29) \n\t" \
"lw $31, 4($29) \n\t" \
"addu $29, $29, 8 \n\t" \
"move %0, $2\n" \
: /*out*/ "=r" (_res) \
: /*in*/ "0" (&_argvec[0]) \
: /*trash*/ "memory", __CALLER_SAVED_REGS \
); \
lval = (__typeof__(lval)) _res; \
} while (0)
#define CALL_FN_W_12W(lval, orig, arg1,arg2,arg3,arg4,arg5, \
arg6,arg7,arg8,arg9,arg10, \
arg11,arg12) \
do { \
volatile OrigFn _orig = (orig); \
volatile unsigned long _argvec[13]; \
volatile unsigned long _res; \
_argvec[0] = (unsigned long)_orig.nraddr; \
_argvec[1] = (unsigned long)(arg1); \
_argvec[2] = (unsigned long)(arg2); \
_argvec[3] = (unsigned long)(arg3); \
_argvec[4] = (unsigned long)(arg4); \
_argvec[5] = (unsigned long)(arg5); \
_argvec[6] = (unsigned long)(arg6); \
_argvec[7] = (unsigned long)(arg7); \
_argvec[8] = (unsigned long)(arg8); \
_argvec[9] = (unsigned long)(arg9); \
_argvec[10] = (unsigned long)(arg10); \
_argvec[11] = (unsigned long)(arg11); \
_argvec[12] = (unsigned long)(arg12); \
__asm__ volatile( \
"subu $29, $29, 8 \n\t" \
"sw $28, 0($29) \n\t" \
"sw $31, 4($29) \n\t" \
"lw $4, 20(%1) \n\t" \
"subu $29, $29, 56\n\t" \
"sw $4, 16($29) \n\t" \
"lw $4, 24(%1) \n\t" \
"sw $4, 20($29) \n\t" \
"lw $4, 28(%1) \n\t" \
"sw $4, 24($29) \n\t" \
"lw $4, 32(%1) \n\t" \
"sw $4, 28($29) \n\t" \
"lw $4, 36(%1) \n\t" \
"sw $4, 32($29) \n\t" \
"lw $4, 40(%1) \n\t" \
"sw $4, 36($29) \n\t" \
"lw $4, 44(%1) \n\t" \
"sw $4, 40($29) \n\t" \
"lw $4, 48(%1) \n\t" \
"sw $4, 44($29) \n\t" \
"lw $4, 4(%1) \n\t" \
"lw $5, 8(%1) \n\t" \
"lw $6, 12(%1) \n\t" \
"lw $7, 16(%1) \n\t" \
"lw $25, 0(%1) \n\t" /* target->t9 */ \
VALGRIND_CALL_NOREDIR_T9 \
"addu $29, $29, 56 \n\t" \
"lw $28, 0($29) \n\t" \
"lw $31, 4($29) \n\t" \
"addu $29, $29, 8 \n\t" \
"move %0, $2\n" \
: /*out*/ "=r" (_res) \
: /*in*/ "r" (&_argvec[0]) \
: /*trash*/ "memory", __CALLER_SAVED_REGS \
); \
lval = (__typeof__(lval)) _res; \
} while (0)
#endif /* PLAT_mips32_linux */
/* ------------------------- nanomips-linux -------------------- */
#if defined(PLAT_nanomips_linux)
/* These regs are trashed by the hidden call. */
#define __CALLER_SAVED_REGS "$t4", "$t5", "$a0", "$a1", "$a2", \
"$a3", "$a4", "$a5", "$a6", "$a7", "$t0", "$t1", "$t2", "$t3", \
"$t8","$t9", "$at"
/* These CALL_FN_ macros assume that on mips-linux, sizeof(unsigned
long) == 4. */
#define CALL_FN_W_v(lval, orig) \
do { \
volatile OrigFn _orig = (orig); \
volatile unsigned long _argvec[1]; \
volatile unsigned long _res; \
_argvec[0] = (unsigned long)_orig.nraddr; \
__asm__ volatile( \
"lw $t9, 0(%1)\n\t" \
VALGRIND_CALL_NOREDIR_T9 \
"move %0, $a0\n" \
: /*out*/ "=r" (_res) \
: /*in*/ "r" (&_argvec[0]) \
: /*trash*/ "memory", __CALLER_SAVED_REGS \
); \
lval = (__typeof__(lval)) _res; \
} while (0)
#define CALL_FN_W_W(lval, orig, arg1) \
do { \
volatile OrigFn _orig = (orig); \
volatile unsigned long _argvec[2]; \
volatile unsigned long _res; \
_argvec[0] = (unsigned long)_orig.nraddr; \
_argvec[1] = (unsigned long)(arg1); \
__asm__ volatile( \
"lw $t9, 0(%1)\n\t" \
"lw $a0, 4(%1)\n\t" \
VALGRIND_CALL_NOREDIR_T9 \
"move %0, $a0\n" \
: /*out*/ "=r" (_res) \
: /*in*/ "r" (&_argvec[0]) \
: /*trash*/ "memory", __CALLER_SAVED_REGS \
); \
lval = (__typeof__(lval)) _res; \
} while (0)
#define CALL_FN_W_WW(lval, orig, arg1,arg2) \
do { \
volatile OrigFn _orig = (orig); \
volatile unsigned long _argvec[3]; \
volatile unsigned long _res; \
_argvec[0] = (unsigned long)_orig.nraddr; \
_argvec[1] = (unsigned long)(arg1); \
_argvec[2] = (unsigned long)(arg2); \
__asm__ volatile( \
"lw $t9, 0(%1)\n\t" \
"lw $a0, 4(%1)\n\t" \
"lw $a1, 8(%1)\n\t" \
VALGRIND_CALL_NOREDIR_T9 \
"move %0, $a0\n" \
: /*out*/ "=r" (_res) \
: /*in*/ "r" (&_argvec[0]) \
: /*trash*/ "memory", __CALLER_SAVED_REGS \
); \
lval = (__typeof__(lval)) _res; \
} while (0)
#define CALL_FN_W_WWW(lval, orig, arg1,arg2,arg3) \
do { \
volatile OrigFn _orig = (orig); \
volatile unsigned long _argvec[4]; \
volatile unsigned long _res; \
_argvec[0] = (unsigned long)_orig.nraddr; \
_argvec[1] = (unsigned long)(arg1); \
_argvec[2] = (unsigned long)(arg2); \
_argvec[3] = (unsigned long)(arg3); \
__asm__ volatile( \
"lw $t9, 0(%1)\n\t" \
"lw $a0, 4(%1)\n\t" \
"lw $a1, 8(%1)\n\t" \
"lw $a2,12(%1)\n\t" \
VALGRIND_CALL_NOREDIR_T9 \
"move %0, $a0\n" \
: /*out*/ "=r" (_res) \
: /*in*/ "r" (&_argvec[0]) \
: /*trash*/ "memory", __CALLER_SAVED_REGS \
); \
lval = (__typeof__(lval)) _res; \
} while (0)
#define CALL_FN_W_WWWW(lval, orig, arg1,arg2,arg3,arg4) \
do { \
volatile OrigFn _orig = (orig); \
volatile unsigned long _argvec[5]; \
volatile unsigned long _res; \
_argvec[0] = (unsigned long)_orig.nraddr; \
_argvec[1] = (unsigned long)(arg1); \
_argvec[2] = (unsigned long)(arg2); \
_argvec[3] = (unsigned long)(arg3); \
_argvec[4] = (unsigned long)(arg4); \
__asm__ volatile( \
"lw $t9, 0(%1)\n\t" \
"lw $a0, 4(%1)\n\t" \
"lw $a1, 8(%1)\n\t" \
"lw $a2,12(%1)\n\t" \
"lw $a3,16(%1)\n\t" \
VALGRIND_CALL_NOREDIR_T9 \
"move %0, $a0\n" \
: /*out*/ "=r" (_res) \
: /*in*/ "r" (&_argvec[0]) \
: /*trash*/ "memory", __CALLER_SAVED_REGS \
); \
lval = (__typeof__(lval)) _res; \
} while (0)
#define CALL_FN_W_5W(lval, orig, arg1,arg2,arg3,arg4,arg5) \
do { \
volatile OrigFn _orig = (orig); \
volatile unsigned long _argvec[6]; \
volatile unsigned long _res; \
_argvec[0] = (unsigned long)_orig.nraddr; \
_argvec[1] = (unsigned long)(arg1); \
_argvec[2] = (unsigned long)(arg2); \
_argvec[3] = (unsigned long)(arg3); \
_argvec[4] = (unsigned long)(arg4); \
_argvec[5] = (unsigned long)(arg5); \
__asm__ volatile( \
"lw $t9, 0(%1)\n\t" \
"lw $a0, 4(%1)\n\t" \
"lw $a1, 8(%1)\n\t" \
"lw $a2,12(%1)\n\t" \
"lw $a3,16(%1)\n\t" \
"lw $a4,20(%1)\n\t" \
VALGRIND_CALL_NOREDIR_T9 \
"move %0, $a0\n" \
: /*out*/ "=r" (_res) \
: /*in*/ "r" (&_argvec[0]) \
: /*trash*/ "memory", __CALLER_SAVED_REGS \
); \
lval = (__typeof__(lval)) _res; \
} while (0)
#define CALL_FN_W_6W(lval, orig, arg1,arg2,arg3,arg4,arg5,arg6) \
do { \
volatile OrigFn _orig = (orig); \
volatile unsigned long _argvec[7]; \
volatile unsigned long _res; \
_argvec[0] = (unsigned long)_orig.nraddr; \
_argvec[1] = (unsigned long)(arg1); \
_argvec[2] = (unsigned long)(arg2); \
_argvec[3] = (unsigned long)(arg3); \
_argvec[4] = (unsigned long)(arg4); \
_argvec[5] = (unsigned long)(arg5); \
_argvec[6] = (unsigned long)(arg6); \
__asm__ volatile( \
"lw $t9, 0(%1)\n\t" \
"lw $a0, 4(%1)\n\t" \
"lw $a1, 8(%1)\n\t" \
"lw $a2,12(%1)\n\t" \
"lw $a3,16(%1)\n\t" \
"lw $a4,20(%1)\n\t" \
"lw $a5,24(%1)\n\t" \
VALGRIND_CALL_NOREDIR_T9 \
"move %0, $a0\n" \
: /*out*/ "=r" (_res) \
: /*in*/ "r" (&_argvec[0]) \
: /*trash*/ "memory", __CALLER_SAVED_REGS \
); \
lval = (__typeof__(lval)) _res; \
} while (0)
#define CALL_FN_W_7W(lval, orig, arg1,arg2,arg3,arg4,arg5,arg6, \
arg7) \
do { \
volatile OrigFn _orig = (orig); \
volatile unsigned long _argvec[8]; \
volatile unsigned long _res; \
_argvec[0] = (unsigned long)_orig.nraddr; \
_argvec[1] = (unsigned long)(arg1); \
_argvec[2] = (unsigned long)(arg2); \
_argvec[3] = (unsigned long)(arg3); \
_argvec[4] = (unsigned long)(arg4); \
_argvec[5] = (unsigned long)(arg5); \
_argvec[6] = (unsigned long)(arg6); \
_argvec[7] = (unsigned long)(arg7); \
__asm__ volatile( \
"lw $t9, 0(%1)\n\t" \
"lw $a0, 4(%1)\n\t" \
"lw $a1, 8(%1)\n\t" \
"lw $a2,12(%1)\n\t" \
"lw $a3,16(%1)\n\t" \
"lw $a4,20(%1)\n\t" \
"lw $a5,24(%1)\n\t" \
"lw $a6,28(%1)\n\t" \
VALGRIND_CALL_NOREDIR_T9 \
"move %0, $a0\n" \
: /*out*/ "=r" (_res) \
: /*in*/ "r" (&_argvec[0]) \
: /*trash*/ "memory", __CALLER_SAVED_REGS \
); \
lval = (__typeof__(lval)) _res; \
} while (0)
#define CALL_FN_W_8W(lval, orig, arg1,arg2,arg3,arg4,arg5,arg6, \
arg7,arg8) \
do { \
volatile OrigFn _orig = (orig); \
volatile unsigned long _argvec[9]; \
volatile unsigned long _res; \
_argvec[0] = (unsigned long)_orig.nraddr; \
_argvec[1] = (unsigned long)(arg1); \
_argvec[2] = (unsigned long)(arg2); \
_argvec[3] = (unsigned long)(arg3); \
_argvec[4] = (unsigned long)(arg4); \
_argvec[5] = (unsigned long)(arg5); \
_argvec[6] = (unsigned long)(arg6); \
_argvec[7] = (unsigned long)(arg7); \
_argvec[8] = (unsigned long)(arg8); \
__asm__ volatile( \
"lw $t9, 0(%1)\n\t" \
"lw $a0, 4(%1)\n\t" \
"lw $a1, 8(%1)\n\t" \
"lw $a2,12(%1)\n\t" \
"lw $a3,16(%1)\n\t" \
"lw $a4,20(%1)\n\t" \
"lw $a5,24(%1)\n\t" \
"lw $a6,28(%1)\n\t" \
"lw $a7,32(%1)\n\t" \
VALGRIND_CALL_NOREDIR_T9 \
"move %0, $a0\n" \
: /*out*/ "=r" (_res) \
: /*in*/ "r" (&_argvec[0]) \
: /*trash*/ "memory", __CALLER_SAVED_REGS \
); \
lval = (__typeof__(lval)) _res; \
} while (0)
#define CALL_FN_W_9W(lval, orig, arg1,arg2,arg3,arg4,arg5,arg6, \
arg7,arg8,arg9) \
do { \
volatile OrigFn _orig = (orig); \
volatile unsigned long _argvec[10]; \
volatile unsigned long _res; \
_argvec[0] = (unsigned long)_orig.nraddr; \
_argvec[1] = (unsigned long)(arg1); \
_argvec[2] = (unsigned long)(arg2); \
_argvec[3] = (unsigned long)(arg3); \
_argvec[4] = (unsigned long)(arg4); \
_argvec[5] = (unsigned long)(arg5); \
_argvec[6] = (unsigned long)(arg6); \
_argvec[7] = (unsigned long)(arg7); \
_argvec[8] = (unsigned long)(arg8); \
_argvec[9] = (unsigned long)(arg9); \
__asm__ volatile( \
"addiu $sp, $sp, -16 \n\t" \
"lw $t9,36(%1) \n\t" \
"sw $t9, 0($sp) \n\t" \
"lw $t9, 0(%1) \n\t" \
"lw $a0, 4(%1) \n\t" \
"lw $a1, 8(%1) \n\t" \
"lw $a2,12(%1) \n\t" \
"lw $a3,16(%1) \n\t" \
"lw $a4,20(%1) \n\t" \
"lw $a5,24(%1) \n\t" \
"lw $a6,28(%1) \n\t" \
"lw $a7,32(%1) \n\t" \
VALGRIND_CALL_NOREDIR_T9 \
"move %0, $a0 \n\t" \
"addiu $sp, $sp, 16 \n\t" \
: /*out*/ "=r" (_res) \
: /*in*/ "r" (&_argvec[0]) \
: /*trash*/ "memory", __CALLER_SAVED_REGS \
); \
lval = (__typeof__(lval)) _res; \
} while (0)
#define CALL_FN_W_10W(lval, orig, arg1,arg2,arg3,arg4,arg5,arg6, \
arg7,arg8,arg9,arg10) \
do { \
volatile OrigFn _orig = (orig); \
volatile unsigned long _argvec[11]; \
volatile unsigned long _res; \
_argvec[0] = (unsigned long)_orig.nraddr; \
_argvec[1] = (unsigned long)(arg1); \
_argvec[2] = (unsigned long)(arg2); \
_argvec[3] = (unsigned long)(arg3); \
_argvec[4] = (unsigned long)(arg4); \
_argvec[5] = (unsigned long)(arg5); \
_argvec[6] = (unsigned long)(arg6); \
_argvec[7] = (unsigned long)(arg7); \
_argvec[8] = (unsigned long)(arg8); \
_argvec[9] = (unsigned long)(arg9); \
_argvec[10] = (unsigned long)(arg10); \
__asm__ volatile( \
"addiu $sp, $sp, -16 \n\t" \
"lw $t9,36(%1) \n\t" \
"sw $t9, 0($sp) \n\t" \
"lw $t9,40(%1) \n\t" \
"sw $t9, 4($sp) \n\t" \
"lw $t9, 0(%1) \n\t" \
"lw $a0, 4(%1) \n\t" \
"lw $a1, 8(%1) \n\t" \
"lw $a2,12(%1) \n\t" \
"lw $a3,16(%1) \n\t" \
"lw $a4,20(%1) \n\t" \
"lw $a5,24(%1) \n\t" \
"lw $a6,28(%1) \n\t" \
"lw $a7,32(%1) \n\t" \
VALGRIND_CALL_NOREDIR_T9 \
"move %0, $a0 \n\t" \
"addiu $sp, $sp, 16 \n\t" \
: /*out*/ "=r" (_res) \
: /*in*/ "r" (&_argvec[0]) \
: /*trash*/ "memory", __CALLER_SAVED_REGS \
); \
lval = (__typeof__(lval)) _res; \
} while (0)
#define CALL_FN_W_11W(lval, orig, arg1,arg2,arg3,arg4,arg5, \
arg6,arg7,arg8,arg9,arg10, \
arg11) \
do { \
volatile OrigFn _orig = (orig); \
volatile unsigned long _argvec[12]; \
volatile unsigned long _res; \
_argvec[0] = (unsigned long)_orig.nraddr; \
_argvec[1] = (unsigned long)(arg1); \
_argvec[2] = (unsigned long)(arg2); \
_argvec[3] = (unsigned long)(arg3); \
_argvec[4] = (unsigned long)(arg4); \
_argvec[5] = (unsigned long)(arg5); \
_argvec[6] = (unsigned long)(arg6); \
_argvec[7] = (unsigned long)(arg7); \
_argvec[8] = (unsigned long)(arg8); \
_argvec[9] = (unsigned long)(arg9); \
_argvec[10] = (unsigned long)(arg10); \
_argvec[11] = (unsigned long)(arg11); \
__asm__ volatile( \
"addiu $sp, $sp, -16 \n\t" \
"lw $t9,36(%1) \n\t" \
"sw $t9, 0($sp) \n\t" \
"lw $t9,40(%1) \n\t" \
"sw $t9, 4($sp) \n\t" \
"lw $t9,44(%1) \n\t" \
"sw $t9, 8($sp) \n\t" \
"lw $t9, 0(%1) \n\t" \
"lw $a0, 4(%1) \n\t" \
"lw $a1, 8(%1) \n\t" \
"lw $a2,12(%1) \n\t" \
"lw $a3,16(%1) \n\t" \
"lw $a4,20(%1) \n\t" \
"lw $a5,24(%1) \n\t" \
"lw $a6,28(%1) \n\t" \
"lw $a7,32(%1) \n\t" \
VALGRIND_CALL_NOREDIR_T9 \
"move %0, $a0 \n\t" \
"addiu $sp, $sp, 16 \n\t" \
: /*out*/ "=r" (_res) \
: /*in*/ "r" (&_argvec[0]) \
: /*trash*/ "memory", __CALLER_SAVED_REGS \
); \
lval = (__typeof__(lval)) _res; \
} while (0)
#define CALL_FN_W_12W(lval, orig, arg1,arg2,arg3,arg4,arg5, \
arg6,arg7,arg8,arg9,arg10, \
arg11,arg12) \
do { \
volatile OrigFn _orig = (orig); \
volatile unsigned long _argvec[13]; \
volatile unsigned long _res; \
_argvec[0] = (unsigned long)_orig.nraddr; \
_argvec[1] = (unsigned long)(arg1); \
_argvec[2] = (unsigned long)(arg2); \
_argvec[3] = (unsigned long)(arg3); \
_argvec[4] = (unsigned long)(arg4); \
_argvec[5] = (unsigned long)(arg5); \
_argvec[6] = (unsigned long)(arg6); \
_argvec[7] = (unsigned long)(arg7); \
_argvec[8] = (unsigned long)(arg8); \
_argvec[9] = (unsigned long)(arg9); \
_argvec[10] = (unsigned long)(arg10); \
_argvec[11] = (unsigned long)(arg11); \
_argvec[12] = (unsigned long)(arg12); \
__asm__ volatile( \
"addiu $sp, $sp, -16 \n\t" \
"lw $t9,36(%1) \n\t" \
"sw $t9, 0($sp) \n\t" \
"lw $t9,40(%1) \n\t" \
"sw $t9, 4($sp) \n\t" \
"lw $t9,44(%1) \n\t" \
"sw $t9, 8($sp) \n\t" \
"lw $t9,48(%1) \n\t" \
"sw $t9,12($sp) \n\t" \
"lw $t9, 0(%1) \n\t" \
"lw $a0, 4(%1) \n\t" \
"lw $a1, 8(%1) \n\t" \
"lw $a2,12(%1) \n\t" \
"lw $a3,16(%1) \n\t" \
"lw $a4,20(%1) \n\t" \
"lw $a5,24(%1) \n\t" \
"lw $a6,28(%1) \n\t" \
"lw $a7,32(%1) \n\t" \
VALGRIND_CALL_NOREDIR_T9 \
"move %0, $a0 \n\t" \
"addiu $sp, $sp, 16 \n\t" \
: /*out*/ "=r" (_res) \
: /*in*/ "r" (&_argvec[0]) \
: /*trash*/ "memory", __CALLER_SAVED_REGS \
); \
lval = (__typeof__(lval)) _res; \
} while (0)
#endif /* PLAT_nanomips_linux */
/* ------------------------- mips64-linux ------------------------- */
#if defined(PLAT_mips64_linux)
/* These regs are trashed by the hidden call. */
#define __CALLER_SAVED_REGS "$2", "$3", "$4", "$5", "$6", \
"$7", "$8", "$9", "$10", "$11", "$12", "$13", "$14", "$15", "$24", \
"$25", "$31"
/* These CALL_FN_ macros assume that on mips64-linux,
sizeof(long long) == 8. */
#define MIPS64_LONG2REG_CAST(x) ((long long)(long)x)
#define CALL_FN_W_v(lval, orig) \
do { \
volatile OrigFn _orig = (orig); \
volatile unsigned long long _argvec[1]; \
volatile unsigned long long _res; \
_argvec[0] = MIPS64_LONG2REG_CAST(_orig.nraddr); \
__asm__ volatile( \
"ld $25, 0(%1)\n\t" /* target->t9 */ \
VALGRIND_CALL_NOREDIR_T9 \
"move %0, $2\n" \
: /*out*/ "=r" (_res) \
: /*in*/ "0" (&_argvec[0]) \
: /*trash*/ "memory", __CALLER_SAVED_REGS \
); \
lval = (__typeof__(lval)) (long)_res; \
} while (0)
#define CALL_FN_W_W(lval, orig, arg1) \
do { \
volatile OrigFn _orig = (orig); \
volatile unsigned long long _argvec[2]; \
volatile unsigned long long _res; \
_argvec[0] = MIPS64_LONG2REG_CAST(_orig.nraddr); \
_argvec[1] = MIPS64_LONG2REG_CAST(arg1); \
__asm__ volatile( \
"ld $4, 8(%1)\n\t" /* arg1*/ \
"ld $25, 0(%1)\n\t" /* target->t9 */ \
VALGRIND_CALL_NOREDIR_T9 \
"move %0, $2\n" \
: /*out*/ "=r" (_res) \
: /*in*/ "r" (&_argvec[0]) \
: /*trash*/ "memory", __CALLER_SAVED_REGS \
); \
lval = (__typeof__(lval)) (long)_res; \
} while (0)
#define CALL_FN_W_WW(lval, orig, arg1,arg2) \
do { \
volatile OrigFn _orig = (orig); \
volatile unsigned long long _argvec[3]; \
volatile unsigned long long _res; \
_argvec[0] = _orig.nraddr; \
_argvec[1] = MIPS64_LONG2REG_CAST(arg1); \
_argvec[2] = MIPS64_LONG2REG_CAST(arg2); \
__asm__ volatile( \
"ld $4, 8(%1)\n\t" \
"ld $5, 16(%1)\n\t" \
"ld $25, 0(%1)\n\t" /* target->t9 */ \
VALGRIND_CALL_NOREDIR_T9 \
"move %0, $2\n" \
: /*out*/ "=r" (_res) \
: /*in*/ "r" (&_argvec[0]) \
: /*trash*/ "memory", __CALLER_SAVED_REGS \
); \
lval = (__typeof__(lval)) (long)_res; \
} while (0)
#define CALL_FN_W_WWW(lval, orig, arg1,arg2,arg3) \
do { \
volatile OrigFn _orig = (orig); \
volatile unsigned long long _argvec[4]; \
volatile unsigned long long _res; \
_argvec[0] = _orig.nraddr; \
_argvec[1] = MIPS64_LONG2REG_CAST(arg1); \
_argvec[2] = MIPS64_LONG2REG_CAST(arg2); \
_argvec[3] = MIPS64_LONG2REG_CAST(arg3); \
__asm__ volatile( \
"ld $4, 8(%1)\n\t" \
"ld $5, 16(%1)\n\t" \
"ld $6, 24(%1)\n\t" \
"ld $25, 0(%1)\n\t" /* target->t9 */ \
VALGRIND_CALL_NOREDIR_T9 \
"move %0, $2\n" \
: /*out*/ "=r" (_res) \
: /*in*/ "r" (&_argvec[0]) \
: /*trash*/ "memory", __CALLER_SAVED_REGS \
); \
lval = (__typeof__(lval)) (long)_res; \
} while (0)
#define CALL_FN_W_WWWW(lval, orig, arg1,arg2,arg3,arg4) \
do { \
volatile OrigFn _orig = (orig); \
volatile unsigned long long _argvec[5]; \
volatile unsigned long long _res; \
_argvec[0] = MIPS64_LONG2REG_CAST(_orig.nraddr); \
_argvec[1] = MIPS64_LONG2REG_CAST(arg1); \
_argvec[2] = MIPS64_LONG2REG_CAST(arg2); \
_argvec[3] = MIPS64_LONG2REG_CAST(arg3); \
_argvec[4] = MIPS64_LONG2REG_CAST(arg4); \
__asm__ volatile( \
"ld $4, 8(%1)\n\t" \
"ld $5, 16(%1)\n\t" \
"ld $6, 24(%1)\n\t" \
"ld $7, 32(%1)\n\t" \
"ld $25, 0(%1)\n\t" /* target->t9 */ \
VALGRIND_CALL_NOREDIR_T9 \
"move %0, $2\n" \
: /*out*/ "=r" (_res) \
: /*in*/ "r" (&_argvec[0]) \
: /*trash*/ "memory", __CALLER_SAVED_REGS \
); \
lval = (__typeof__(lval)) (long)_res; \
} while (0)
#define CALL_FN_W_5W(lval, orig, arg1,arg2,arg3,arg4,arg5) \
do { \
volatile OrigFn _orig = (orig); \
volatile unsigned long long _argvec[6]; \
volatile unsigned long long _res; \
_argvec[0] = MIPS64_LONG2REG_CAST(_orig.nraddr); \
_argvec[1] = MIPS64_LONG2REG_CAST(arg1); \
_argvec[2] = MIPS64_LONG2REG_CAST(arg2); \
_argvec[3] = MIPS64_LONG2REG_CAST(arg3); \
_argvec[4] = MIPS64_LONG2REG_CAST(arg4); \
_argvec[5] = MIPS64_LONG2REG_CAST(arg5); \
__asm__ volatile( \
"ld $4, 8(%1)\n\t" \
"ld $5, 16(%1)\n\t" \
"ld $6, 24(%1)\n\t" \
"ld $7, 32(%1)\n\t" \
"ld $8, 40(%1)\n\t" \
"ld $25, 0(%1)\n\t" /* target->t9 */ \
VALGRIND_CALL_NOREDIR_T9 \
"move %0, $2\n" \
: /*out*/ "=r" (_res) \
: /*in*/ "r" (&_argvec[0]) \
: /*trash*/ "memory", __CALLER_SAVED_REGS \
); \
lval = (__typeof__(lval)) (long)_res; \
} while (0)
#define CALL_FN_W_6W(lval, orig, arg1,arg2,arg3,arg4,arg5,arg6) \
do { \
volatile OrigFn _orig = (orig); \
volatile unsigned long long _argvec[7]; \
volatile unsigned long long _res; \
_argvec[0] = MIPS64_LONG2REG_CAST(_orig.nraddr); \
_argvec[1] = MIPS64_LONG2REG_CAST(arg1); \
_argvec[2] = MIPS64_LONG2REG_CAST(arg2); \
_argvec[3] = MIPS64_LONG2REG_CAST(arg3); \
_argvec[4] = MIPS64_LONG2REG_CAST(arg4); \
_argvec[5] = MIPS64_LONG2REG_CAST(arg5); \
_argvec[6] = MIPS64_LONG2REG_CAST(arg6); \
__asm__ volatile( \
"ld $4, 8(%1)\n\t" \
"ld $5, 16(%1)\n\t" \
"ld $6, 24(%1)\n\t" \
"ld $7, 32(%1)\n\t" \
"ld $8, 40(%1)\n\t" \
"ld $9, 48(%1)\n\t" \
"ld $25, 0(%1)\n\t" /* target->t9 */ \
VALGRIND_CALL_NOREDIR_T9 \
"move %0, $2\n" \
: /*out*/ "=r" (_res) \
: /*in*/ "r" (&_argvec[0]) \
: /*trash*/ "memory", __CALLER_SAVED_REGS \
); \
lval = (__typeof__(lval)) (long)_res; \
} while (0)
#define CALL_FN_W_7W(lval, orig, arg1,arg2,arg3,arg4,arg5,arg6, \
arg7) \
do { \
volatile OrigFn _orig = (orig); \
volatile unsigned long long _argvec[8]; \
volatile unsigned long long _res; \
_argvec[0] = MIPS64_LONG2REG_CAST(_orig.nraddr); \
_argvec[1] = MIPS64_LONG2REG_CAST(arg1); \
_argvec[2] = MIPS64_LONG2REG_CAST(arg2); \
_argvec[3] = MIPS64_LONG2REG_CAST(arg3); \
_argvec[4] = MIPS64_LONG2REG_CAST(arg4); \
_argvec[5] = MIPS64_LONG2REG_CAST(arg5); \
_argvec[6] = MIPS64_LONG2REG_CAST(arg6); \
_argvec[7] = MIPS64_LONG2REG_CAST(arg7); \
__asm__ volatile( \
"ld $4, 8(%1)\n\t" \
"ld $5, 16(%1)\n\t" \
"ld $6, 24(%1)\n\t" \
"ld $7, 32(%1)\n\t" \
"ld $8, 40(%1)\n\t" \
"ld $9, 48(%1)\n\t" \
"ld $10, 56(%1)\n\t" \
"ld $25, 0(%1) \n\t" /* target->t9 */ \
VALGRIND_CALL_NOREDIR_T9 \
"move %0, $2\n" \
: /*out*/ "=r" (_res) \
: /*in*/ "r" (&_argvec[0]) \
: /*trash*/ "memory", __CALLER_SAVED_REGS \
); \
lval = (__typeof__(lval)) (long)_res; \
} while (0)
#define CALL_FN_W_8W(lval, orig, arg1,arg2,arg3,arg4,arg5,arg6, \
arg7,arg8) \
do { \
volatile OrigFn _orig = (orig); \
volatile unsigned long long _argvec[9]; \
volatile unsigned long long _res; \
_argvec[0] = MIPS64_LONG2REG_CAST(_orig.nraddr); \
_argvec[1] = MIPS64_LONG2REG_CAST(arg1); \
_argvec[2] = MIPS64_LONG2REG_CAST(arg2); \
_argvec[3] = MIPS64_LONG2REG_CAST(arg3); \
_argvec[4] = MIPS64_LONG2REG_CAST(arg4); \
_argvec[5] = MIPS64_LONG2REG_CAST(arg5); \
_argvec[6] = MIPS64_LONG2REG_CAST(arg6); \
_argvec[7] = MIPS64_LONG2REG_CAST(arg7); \
_argvec[8] = MIPS64_LONG2REG_CAST(arg8); \
__asm__ volatile( \
"ld $4, 8(%1)\n\t" \
"ld $5, 16(%1)\n\t" \
"ld $6, 24(%1)\n\t" \
"ld $7, 32(%1)\n\t" \
"ld $8, 40(%1)\n\t" \
"ld $9, 48(%1)\n\t" \
"ld $10, 56(%1)\n\t" \
"ld $11, 64(%1)\n\t" \
"ld $25, 0(%1) \n\t" /* target->t9 */ \
VALGRIND_CALL_NOREDIR_T9 \
"move %0, $2\n" \
: /*out*/ "=r" (_res) \
: /*in*/ "r" (&_argvec[0]) \
: /*trash*/ "memory", __CALLER_SAVED_REGS \
); \
lval = (__typeof__(lval)) (long)_res; \
} while (0)
#define CALL_FN_W_9W(lval, orig, arg1,arg2,arg3,arg4,arg5,arg6, \
arg7,arg8,arg9) \
do { \
volatile OrigFn _orig = (orig); \
volatile unsigned long long _argvec[10]; \
volatile unsigned long long _res; \
_argvec[0] = MIPS64_LONG2REG_CAST(_orig.nraddr); \
_argvec[1] = MIPS64_LONG2REG_CAST(arg1); \
_argvec[2] = MIPS64_LONG2REG_CAST(arg2); \
_argvec[3] = MIPS64_LONG2REG_CAST(arg3); \
_argvec[4] = MIPS64_LONG2REG_CAST(arg4); \
_argvec[5] = MIPS64_LONG2REG_CAST(arg5); \
_argvec[6] = MIPS64_LONG2REG_CAST(arg6); \
_argvec[7] = MIPS64_LONG2REG_CAST(arg7); \
_argvec[8] = MIPS64_LONG2REG_CAST(arg8); \
_argvec[9] = MIPS64_LONG2REG_CAST(arg9); \
__asm__ volatile( \
"dsubu $29, $29, 8\n\t" \
"ld $4, 72(%1)\n\t" \
"sd $4, 0($29)\n\t" \
"ld $4, 8(%1)\n\t" \
"ld $5, 16(%1)\n\t" \
"ld $6, 24(%1)\n\t" \
"ld $7, 32(%1)\n\t" \
"ld $8, 40(%1)\n\t" \
"ld $9, 48(%1)\n\t" \
"ld $10, 56(%1)\n\t" \
"ld $11, 64(%1)\n\t" \
"ld $25, 0(%1)\n\t" /* target->t9 */ \
VALGRIND_CALL_NOREDIR_T9 \
"daddu $29, $29, 8\n\t" \
"move %0, $2\n" \
: /*out*/ "=r" (_res) \
: /*in*/ "r" (&_argvec[0]) \
: /*trash*/ "memory", __CALLER_SAVED_REGS \
); \
lval = (__typeof__(lval)) (long)_res; \
} while (0)
#define CALL_FN_W_10W(lval, orig, arg1,arg2,arg3,arg4,arg5,arg6, \
arg7,arg8,arg9,arg10) \
do { \
volatile OrigFn _orig = (orig); \
volatile unsigned long long _argvec[11]; \
volatile unsigned long long _res; \
_argvec[0] = MIPS64_LONG2REG_CAST(_orig.nraddr); \
_argvec[1] = MIPS64_LONG2REG_CAST(arg1); \
_argvec[2] = MIPS64_LONG2REG_CAST(arg2); \
_argvec[3] = MIPS64_LONG2REG_CAST(arg3); \
_argvec[4] = MIPS64_LONG2REG_CAST(arg4); \
_argvec[5] = MIPS64_LONG2REG_CAST(arg5); \
_argvec[6] = MIPS64_LONG2REG_CAST(arg6); \
_argvec[7] = MIPS64_LONG2REG_CAST(arg7); \
_argvec[8] = MIPS64_LONG2REG_CAST(arg8); \
_argvec[9] = MIPS64_LONG2REG_CAST(arg9); \
_argvec[10] = MIPS64_LONG2REG_CAST(arg10); \
__asm__ volatile( \
"dsubu $29, $29, 16\n\t" \
"ld $4, 72(%1)\n\t" \
"sd $4, 0($29)\n\t" \
"ld $4, 80(%1)\n\t" \
"sd $4, 8($29)\n\t" \
"ld $4, 8(%1)\n\t" \
"ld $5, 16(%1)\n\t" \
"ld $6, 24(%1)\n\t" \
"ld $7, 32(%1)\n\t" \
"ld $8, 40(%1)\n\t" \
"ld $9, 48(%1)\n\t" \
"ld $10, 56(%1)\n\t" \
"ld $11, 64(%1)\n\t" \
"ld $25, 0(%1)\n\t" /* target->t9 */ \
VALGRIND_CALL_NOREDIR_T9 \
"daddu $29, $29, 16\n\t" \
"move %0, $2\n" \
: /*out*/ "=r" (_res) \
: /*in*/ "r" (&_argvec[0]) \
: /*trash*/ "memory", __CALLER_SAVED_REGS \
); \
lval = (__typeof__(lval)) (long)_res; \
} while (0)
#define CALL_FN_W_11W(lval, orig, arg1,arg2,arg3,arg4,arg5, \
arg6,arg7,arg8,arg9,arg10, \
arg11) \
do { \
volatile OrigFn _orig = (orig); \
volatile unsigned long long _argvec[12]; \
volatile unsigned long long _res; \
_argvec[0] = MIPS64_LONG2REG_CAST(_orig.nraddr); \
_argvec[1] = MIPS64_LONG2REG_CAST(arg1); \
_argvec[2] = MIPS64_LONG2REG_CAST(arg2); \
_argvec[3] = MIPS64_LONG2REG_CAST(arg3); \
_argvec[4] = MIPS64_LONG2REG_CAST(arg4); \
_argvec[5] = MIPS64_LONG2REG_CAST(arg5); \
_argvec[6] = MIPS64_LONG2REG_CAST(arg6); \
_argvec[7] = MIPS64_LONG2REG_CAST(arg7); \
_argvec[8] = MIPS64_LONG2REG_CAST(arg8); \
_argvec[9] = MIPS64_LONG2REG_CAST(arg9); \
_argvec[10] = MIPS64_LONG2REG_CAST(arg10); \
_argvec[11] = MIPS64_LONG2REG_CAST(arg11); \
__asm__ volatile( \
"dsubu $29, $29, 24\n\t" \
"ld $4, 72(%1)\n\t" \
"sd $4, 0($29)\n\t" \
"ld $4, 80(%1)\n\t" \
"sd $4, 8($29)\n\t" \
"ld $4, 88(%1)\n\t" \
"sd $4, 16($29)\n\t" \
"ld $4, 8(%1)\n\t" \
"ld $5, 16(%1)\n\t" \
"ld $6, 24(%1)\n\t" \
"ld $7, 32(%1)\n\t" \
"ld $8, 40(%1)\n\t" \
"ld $9, 48(%1)\n\t" \
"ld $10, 56(%1)\n\t" \
"ld $11, 64(%1)\n\t" \
"ld $25, 0(%1)\n\t" /* target->t9 */ \
VALGRIND_CALL_NOREDIR_T9 \
"daddu $29, $29, 24\n\t" \
"move %0, $2\n" \
: /*out*/ "=r" (_res) \
: /*in*/ "r" (&_argvec[0]) \
: /*trash*/ "memory", __CALLER_SAVED_REGS \
); \
lval = (__typeof__(lval)) (long)_res; \
} while (0)
#define CALL_FN_W_12W(lval, orig, arg1,arg2,arg3,arg4,arg5, \
arg6,arg7,arg8,arg9,arg10, \
arg11,arg12) \
do { \
volatile OrigFn _orig = (orig); \
volatile unsigned long long _argvec[13]; \
volatile unsigned long long _res; \
_argvec[0] = MIPS64_LONG2REG_CAST(_orig.nraddr); \
_argvec[1] = MIPS64_LONG2REG_CAST(arg1); \
_argvec[2] = MIPS64_LONG2REG_CAST(arg2); \
_argvec[3] = MIPS64_LONG2REG_CAST(arg3); \
_argvec[4] = MIPS64_LONG2REG_CAST(arg4); \
_argvec[5] = MIPS64_LONG2REG_CAST(arg5); \
_argvec[6] = MIPS64_LONG2REG_CAST(arg6); \
_argvec[7] = MIPS64_LONG2REG_CAST(arg7); \
_argvec[8] = MIPS64_LONG2REG_CAST(arg8); \
_argvec[9] = MIPS64_LONG2REG_CAST(arg9); \
_argvec[10] = MIPS64_LONG2REG_CAST(arg10); \
_argvec[11] = MIPS64_LONG2REG_CAST(arg11); \
_argvec[12] = MIPS64_LONG2REG_CAST(arg12); \
__asm__ volatile( \
"dsubu $29, $29, 32\n\t" \
"ld $4, 72(%1)\n\t" \
"sd $4, 0($29)\n\t" \
"ld $4, 80(%1)\n\t" \
"sd $4, 8($29)\n\t" \
"ld $4, 88(%1)\n\t" \
"sd $4, 16($29)\n\t" \
"ld $4, 96(%1)\n\t" \
"sd $4, 24($29)\n\t" \
"ld $4, 8(%1)\n\t" \
"ld $5, 16(%1)\n\t" \
"ld $6, 24(%1)\n\t" \
"ld $7, 32(%1)\n\t" \
"ld $8, 40(%1)\n\t" \
"ld $9, 48(%1)\n\t" \
"ld $10, 56(%1)\n\t" \
"ld $11, 64(%1)\n\t" \
"ld $25, 0(%1)\n\t" /* target->t9 */ \
VALGRIND_CALL_NOREDIR_T9 \
"daddu $29, $29, 32\n\t" \
"move %0, $2\n" \
: /*out*/ "=r" (_res) \
: /*in*/ "r" (&_argvec[0]) \
: /*trash*/ "memory", __CALLER_SAVED_REGS \
); \
lval = (__typeof__(lval)) (long)_res; \
} while (0)
#endif /* PLAT_mips64_linux */
/* ------------------------------------------------------------------ */
/* ARCHITECTURE INDEPENDENT MACROS for CLIENT REQUESTS. */
/* */
/* ------------------------------------------------------------------ */
/* Some request codes. There are many more of these, but most are not
exposed to end-user view. These are the public ones, all of the
form 0x1000 + small_number.
Core ones are in the range 0x00000000--0x0000ffff. The non-public
ones start at 0x2000.
*/
/* These macros are used by tools -- they must be public, but don't
embed them into other programs. */
#define VG_USERREQ_TOOL_BASE(a,b) \
((unsigned int)(((a)&0xff) << 24 | ((b)&0xff) << 16))
#define VG_IS_TOOL_USERREQ(a, b, v) \
(VG_USERREQ_TOOL_BASE(a,b) == ((v) & 0xffff0000))
/* !! ABIWARNING !! ABIWARNING !! ABIWARNING !! ABIWARNING !!
This enum comprises an ABI exported by Valgrind to programs
which use client requests. DO NOT CHANGE THE NUMERIC VALUES OF THESE
ENTRIES, NOR DELETE ANY -- add new ones at the end of the most
relevant group. */
typedef
enum { VG_USERREQ__RUNNING_ON_VALGRIND = 0x1001,
VG_USERREQ__DISCARD_TRANSLATIONS = 0x1002,
/* These allow any function to be called from the simulated
CPU but run on the real CPU. Nb: the first arg passed to
the function is always the ThreadId of the running
thread! So CLIENT_CALL0 actually requires a 1 arg
function, etc. */
VG_USERREQ__CLIENT_CALL0 = 0x1101,
VG_USERREQ__CLIENT_CALL1 = 0x1102,
VG_USERREQ__CLIENT_CALL2 = 0x1103,
VG_USERREQ__CLIENT_CALL3 = 0x1104,
/* Can be useful in regression testing suites -- eg. can
send Valgrind's output to /dev/null and still count
errors. */
VG_USERREQ__COUNT_ERRORS = 0x1201,
/* Allows the client program and/or gdbserver to execute a monitor
command. */
VG_USERREQ__GDB_MONITOR_COMMAND = 0x1202,
/* Allows the client program to change a dynamic command line
option. */
VG_USERREQ__CLO_CHANGE = 0x1203,
/* These are useful and can be interpreted by any tool that
tracks malloc() et al, by using vg_replace_malloc.c. */
VG_USERREQ__MALLOCLIKE_BLOCK = 0x1301,
VG_USERREQ__RESIZEINPLACE_BLOCK = 0x130b,
VG_USERREQ__FREELIKE_BLOCK = 0x1302,
/* Memory pool support. */
VG_USERREQ__CREATE_MEMPOOL = 0x1303,
VG_USERREQ__DESTROY_MEMPOOL = 0x1304,
VG_USERREQ__MEMPOOL_ALLOC = 0x1305,
VG_USERREQ__MEMPOOL_FREE = 0x1306,
VG_USERREQ__MEMPOOL_TRIM = 0x1307,
VG_USERREQ__MOVE_MEMPOOL = 0x1308,
VG_USERREQ__MEMPOOL_CHANGE = 0x1309,
VG_USERREQ__MEMPOOL_EXISTS = 0x130a,
/* Allow printfs to valgrind log. */
/* The first two pass the va_list argument by value, which
assumes it is the same size as or smaller than a UWord,
which generally isn't the case. Hence are deprecated.
The second two pass the vargs by reference and so are
immune to this problem. */
/* both :: char* fmt, va_list vargs (DEPRECATED) */
VG_USERREQ__PRINTF = 0x1401,
VG_USERREQ__PRINTF_BACKTRACE = 0x1402,
/* both :: char* fmt, va_list* vargs */
VG_USERREQ__PRINTF_VALIST_BY_REF = 0x1403,
VG_USERREQ__PRINTF_BACKTRACE_VALIST_BY_REF = 0x1404,
/* Stack support. */
VG_USERREQ__STACK_REGISTER = 0x1501,
VG_USERREQ__STACK_DEREGISTER = 0x1502,
VG_USERREQ__STACK_CHANGE = 0x1503,
/* Wine support */
VG_USERREQ__LOAD_PDB_DEBUGINFO = 0x1601,
/* Querying of debug info. */
VG_USERREQ__MAP_IP_TO_SRCLOC = 0x1701,
/* Disable/enable error reporting level. Takes a single
Word arg which is the delta to this thread's error
disablement indicator. Hence 1 disables or further
disables errors, and -1 moves back towards enablement.
Other values are not allowed. */
VG_USERREQ__CHANGE_ERR_DISABLEMENT = 0x1801,
/* Some requests used for Valgrind internal, such as
self-test or self-hosting. */
/* Initialise IR injection */
VG_USERREQ__VEX_INIT_FOR_IRI = 0x1901,
/* Used by Inner Valgrind to inform Outer Valgrind where to
find the list of inner guest threads */
VG_USERREQ__INNER_THREADS = 0x1902
} Vg_ClientRequest;
#if !defined(__GNUC__)
# define __extension__ /* */
#endif
/* Returns the number of Valgrinds this code is running under. That
is, 0 if running natively, 1 if running under Valgrind, 2 if
running under Valgrind which is running under another Valgrind,
etc. */
#define RUNNING_ON_VALGRIND \
(unsigned)VALGRIND_DO_CLIENT_REQUEST_EXPR(0 /* if not */, \
VG_USERREQ__RUNNING_ON_VALGRIND, \
0, 0, 0, 0, 0) \
/* Discard translation of code in the range [_qzz_addr .. _qzz_addr +
_qzz_len - 1]. Useful if you are debugging a JITter or some such,
since it provides a way to make sure valgrind will retranslate the
invalidated area. Returns no value. */
#define VALGRIND_DISCARD_TRANSLATIONS(_qzz_addr,_qzz_len) \
VALGRIND_DO_CLIENT_REQUEST_STMT(VG_USERREQ__DISCARD_TRANSLATIONS, \
_qzz_addr, _qzz_len, 0, 0, 0)
#define VALGRIND_INNER_THREADS(_qzz_addr) \
VALGRIND_DO_CLIENT_REQUEST_STMT(VG_USERREQ__INNER_THREADS, \
_qzz_addr, 0, 0, 0, 0)
/* These requests are for getting Valgrind itself to print something.
Possibly with a backtrace. This is a really ugly hack. The return value
is the number of characters printed, excluding the "**** " part at the
start and the backtrace (if present). */
#if defined(__GNUC__) || defined(__INTEL_COMPILER) && !defined(_MSC_VER)
/* Modern GCC will optimize the static routine out if unused,
and unused attribute will shut down warnings about it. */
static int VALGRIND_PRINTF(const char *format, ...)
__attribute__((format(__printf__, 1, 2), __unused__));
#endif
static int
#if defined(_MSC_VER)
__inline
#endif
VALGRIND_PRINTF(const char *format, ...)
{
#if defined(NVALGRIND)
(void)format;
return 0;
#else /* NVALGRIND */
#if defined(_MSC_VER) || defined(__MINGW64__)
uintptr_t _qzz_res;
#else
unsigned long _qzz_res;
#endif
va_list vargs;
va_start(vargs, format);
#if defined(_MSC_VER) || defined(__MINGW64__)
_qzz_res = VALGRIND_DO_CLIENT_REQUEST_EXPR(0,
VG_USERREQ__PRINTF_VALIST_BY_REF,
(uintptr_t)format,
(uintptr_t)&vargs,
0, 0, 0);
#else
_qzz_res = VALGRIND_DO_CLIENT_REQUEST_EXPR(0,
VG_USERREQ__PRINTF_VALIST_BY_REF,
(unsigned long)format,
(unsigned long)&vargs,
0, 0, 0);
#endif
va_end(vargs);
return (int)_qzz_res;
#endif /* NVALGRIND */
}
#if defined(__GNUC__) || defined(__INTEL_COMPILER) && !defined(_MSC_VER)
static int VALGRIND_PRINTF_BACKTRACE(const char *format, ...)
__attribute__((format(__printf__, 1, 2), __unused__));
#endif
static int
#if defined(_MSC_VER)
__inline
#endif
VALGRIND_PRINTF_BACKTRACE(const char *format, ...)
{
#if defined(NVALGRIND)
(void)format;
return 0;
#else /* NVALGRIND */
#if defined(_MSC_VER) || defined(__MINGW64__)
uintptr_t _qzz_res;
#else
unsigned long _qzz_res;
#endif
va_list vargs;
va_start(vargs, format);
#if defined(_MSC_VER) || defined(__MINGW64__)
_qzz_res = VALGRIND_DO_CLIENT_REQUEST_EXPR(0,
VG_USERREQ__PRINTF_BACKTRACE_VALIST_BY_REF,
(uintptr_t)format,
(uintptr_t)&vargs,
0, 0, 0);
#else
_qzz_res = VALGRIND_DO_CLIENT_REQUEST_EXPR(0,
VG_USERREQ__PRINTF_BACKTRACE_VALIST_BY_REF,
(unsigned long)format,
(unsigned long)&vargs,
0, 0, 0);
#endif
va_end(vargs);
return (int)_qzz_res;
#endif /* NVALGRIND */
}
/* These requests allow control to move from the simulated CPU to the
real CPU, calling an arbitrary function.
Note that the current ThreadId is inserted as the first argument.
So this call:
VALGRIND_NON_SIMD_CALL2(f, arg1, arg2)
requires f to have this signature:
Word f(Word tid, Word arg1, Word arg2)
where "Word" is a word-sized type.
Note that these client requests are not entirely reliable. For example,
if you call a function with them that subsequently calls printf(),
there's a high chance Valgrind will crash. Generally, your prospects of
these working are made higher if the called function does not refer to
any global variables, and does not refer to any libc or other functions
(printf et al). Any kind of entanglement with libc or dynamic linking is
likely to have a bad outcome, for tricky reasons which we've grappled
with a lot in the past.
*/
#define VALGRIND_NON_SIMD_CALL0(_qyy_fn) \
VALGRIND_DO_CLIENT_REQUEST_EXPR(0 /* default return */, \
VG_USERREQ__CLIENT_CALL0, \
_qyy_fn, \
0, 0, 0, 0)
#define VALGRIND_NON_SIMD_CALL1(_qyy_fn, _qyy_arg1) \
VALGRIND_DO_CLIENT_REQUEST_EXPR(0 /* default return */, \
VG_USERREQ__CLIENT_CALL1, \
_qyy_fn, \
_qyy_arg1, 0, 0, 0)
#define VALGRIND_NON_SIMD_CALL2(_qyy_fn, _qyy_arg1, _qyy_arg2) \
VALGRIND_DO_CLIENT_REQUEST_EXPR(0 /* default return */, \
VG_USERREQ__CLIENT_CALL2, \
_qyy_fn, \
_qyy_arg1, _qyy_arg2, 0, 0)
#define VALGRIND_NON_SIMD_CALL3(_qyy_fn, _qyy_arg1, _qyy_arg2, _qyy_arg3) \
VALGRIND_DO_CLIENT_REQUEST_EXPR(0 /* default return */, \
VG_USERREQ__CLIENT_CALL3, \
_qyy_fn, \
_qyy_arg1, _qyy_arg2, \
_qyy_arg3, 0)
/* Counts the number of errors that have been recorded by a tool. Nb:
the tool must record the errors with VG_(maybe_record_error)() or
VG_(unique_error)() for them to be counted. */
#define VALGRIND_COUNT_ERRORS \
(unsigned)VALGRIND_DO_CLIENT_REQUEST_EXPR( \
0 /* default return */, \
VG_USERREQ__COUNT_ERRORS, \
0, 0, 0, 0, 0)
/* Several Valgrind tools (Memcheck, Massif, Helgrind, DRD) rely on knowing
when heap blocks are allocated in order to give accurate results. This
happens automatically for the standard allocator functions such as
malloc(), calloc(), realloc(), memalign(), new, new[], free(), delete,
delete[], etc.
But if your program uses a custom allocator, this doesn't automatically
happen, and Valgrind will not do as well. For example, if you allocate
superblocks with mmap() and then allocates chunks of the superblocks, all
Valgrind's observations will be at the mmap() level and it won't know that
the chunks should be considered separate entities. In Memcheck's case,
that means you probably won't get heap block overrun detection (because
there won't be redzones marked as unaddressable) and you definitely won't
get any leak detection.
The following client requests allow a custom allocator to be annotated so
that it can be handled accurately by Valgrind.
VALGRIND_MALLOCLIKE_BLOCK marks a region of memory as having been allocated
by a malloc()-like function. For Memcheck (an illustrative case), this
does two things:
- It records that the block has been allocated. This means any addresses
within the block mentioned in error messages will be
identified as belonging to the block. It also means that if the block
isn't freed it will be detected by the leak checker.
- It marks the block as being addressable and undefined (if 'is_zeroed' is
not set), or addressable and defined (if 'is_zeroed' is set). This
controls how accesses to the block by the program are handled.
'addr' is the start of the usable block (ie. after any
redzone), 'sizeB' is its size. 'rzB' is the redzone size if the allocator
can apply redzones -- these are blocks of padding at the start and end of
each block. Adding redzones is recommended as it makes it much more likely
Valgrind will spot block overruns. `is_zeroed' indicates if the memory is
zeroed (or filled with another predictable value), as is the case for
calloc().
VALGRIND_MALLOCLIKE_BLOCK should be put immediately after the point where a
heap block -- that will be used by the client program -- is allocated.
It's best to put it at the outermost level of the allocator if possible;
for example, if you have a function my_alloc() which calls
internal_alloc(), and the client request is put inside internal_alloc(),
stack traces relating to the heap block will contain entries for both
my_alloc() and internal_alloc(), which is probably not what you want.
For Memcheck users: if you use VALGRIND_MALLOCLIKE_BLOCK to carve out
custom blocks from within a heap block, B, that has been allocated with
malloc/calloc/new/etc, then block B will be *ignored* during leak-checking
-- the custom blocks will take precedence.
VALGRIND_FREELIKE_BLOCK is the partner to VALGRIND_MALLOCLIKE_BLOCK. For
Memcheck, it does two things:
- It records that the block has been deallocated. This assumes that the
block was annotated as having been allocated via
VALGRIND_MALLOCLIKE_BLOCK. Otherwise, an error will be issued.
- It marks the block as being unaddressable.
VALGRIND_FREELIKE_BLOCK should be put immediately after the point where a
heap block is deallocated.
VALGRIND_RESIZEINPLACE_BLOCK informs a tool about reallocation. For
Memcheck, it does four things:
- It records that the size of a block has been changed. This assumes that
the block was annotated as having been allocated via
VALGRIND_MALLOCLIKE_BLOCK. Otherwise, an error will be issued.
- If the block shrunk, it marks the freed memory as being unaddressable.
- If the block grew, it marks the new area as undefined and defines a red
zone past the end of the new block.
- The V-bits of the overlap between the old and the new block are preserved.
VALGRIND_RESIZEINPLACE_BLOCK should be put after allocation of the new block
and before deallocation of the old block.
In many cases, these three client requests will not be enough to get your
allocator working well with Memcheck. More specifically, if your allocator
writes to freed blocks in any way then a VALGRIND_MAKE_MEM_UNDEFINED call
will be necessary to mark the memory as addressable just before the zeroing
occurs, otherwise you'll get a lot of invalid write errors. For example,
you'll need to do this if your allocator recycles freed blocks, but it
zeroes them before handing them back out (via VALGRIND_MALLOCLIKE_BLOCK).
Alternatively, if your allocator reuses freed blocks for allocator-internal
data structures, VALGRIND_MAKE_MEM_UNDEFINED calls will also be necessary.
Really, what's happening is a blurring of the lines between the client
program and the allocator... after VALGRIND_FREELIKE_BLOCK is called, the
memory should be considered unaddressable to the client program, but the
allocator knows more than the rest of the client program and so may be able
to safely access it. Extra client requests are necessary for Valgrind to
understand the distinction between the allocator and the rest of the
program.
Ignored if addr == 0.
*/
#define VALGRIND_MALLOCLIKE_BLOCK(addr, sizeB, rzB, is_zeroed) \
VALGRIND_DO_CLIENT_REQUEST_STMT(VG_USERREQ__MALLOCLIKE_BLOCK, \
addr, sizeB, rzB, is_zeroed, 0)
/* See the comment for VALGRIND_MALLOCLIKE_BLOCK for details.
Ignored if addr == 0.
*/
#define VALGRIND_RESIZEINPLACE_BLOCK(addr, oldSizeB, newSizeB, rzB) \
VALGRIND_DO_CLIENT_REQUEST_STMT(VG_USERREQ__RESIZEINPLACE_BLOCK, \
addr, oldSizeB, newSizeB, rzB, 0)
/* See the comment for VALGRIND_MALLOCLIKE_BLOCK for details.
Ignored if addr == 0.
*/
#define VALGRIND_FREELIKE_BLOCK(addr, rzB) \
VALGRIND_DO_CLIENT_REQUEST_STMT(VG_USERREQ__FREELIKE_BLOCK, \
addr, rzB, 0, 0, 0)
/* Create a memory pool. */
#define VALGRIND_CREATE_MEMPOOL(pool, rzB, is_zeroed) \
VALGRIND_DO_CLIENT_REQUEST_STMT(VG_USERREQ__CREATE_MEMPOOL, \
pool, rzB, is_zeroed, 0, 0)
/* Create a memory pool with some flags specifying extended behaviour.
When flags is zero, the behaviour is identical to VALGRIND_CREATE_MEMPOOL.
The flag VALGRIND_MEMPOOL_METAPOOL specifies that the pieces of memory
associated with the pool using VALGRIND_MEMPOOL_ALLOC will be used
by the application as superblocks to dole out MALLOC_LIKE blocks using
VALGRIND_MALLOCLIKE_BLOCK. In other words, a meta pool is a "2 levels"
pool : first level is the blocks described by VALGRIND_MEMPOOL_ALLOC.
The second level blocks are described using VALGRIND_MALLOCLIKE_BLOCK.
Note that the association between the pool and the second level blocks
is implicit : second level blocks will be located inside first level
blocks. It is necessary to use the VALGRIND_MEMPOOL_METAPOOL flag
for such 2 levels pools, as otherwise valgrind will detect overlapping
memory blocks, and will abort execution (e.g. during leak search).
Such a meta pool can also be marked as an 'auto free' pool using the flag
VALGRIND_MEMPOOL_AUTO_FREE, which must be OR-ed together with the
VALGRIND_MEMPOOL_METAPOOL. For an 'auto free' pool, VALGRIND_MEMPOOL_FREE
will automatically free the second level blocks that are contained
inside the first level block freed with VALGRIND_MEMPOOL_FREE.
In other words, calling VALGRIND_MEMPOOL_FREE will cause implicit calls
to VALGRIND_FREELIKE_BLOCK for all the second level blocks included
in the first level block.
Note: it is an error to use the VALGRIND_MEMPOOL_AUTO_FREE flag
without the VALGRIND_MEMPOOL_METAPOOL flag.
*/
#define VALGRIND_MEMPOOL_AUTO_FREE 1
#define VALGRIND_MEMPOOL_METAPOOL 2
#define VALGRIND_CREATE_MEMPOOL_EXT(pool, rzB, is_zeroed, flags) \
VALGRIND_DO_CLIENT_REQUEST_STMT(VG_USERREQ__CREATE_MEMPOOL, \
pool, rzB, is_zeroed, flags, 0)
/* Destroy a memory pool. */
#define VALGRIND_DESTROY_MEMPOOL(pool) \
VALGRIND_DO_CLIENT_REQUEST_STMT(VG_USERREQ__DESTROY_MEMPOOL, \
pool, 0, 0, 0, 0)
/* Associate a piece of memory with a memory pool. */
#define VALGRIND_MEMPOOL_ALLOC(pool, addr, size) \
VALGRIND_DO_CLIENT_REQUEST_STMT(VG_USERREQ__MEMPOOL_ALLOC, \
pool, addr, size, 0, 0)
/* Disassociate a piece of memory from a memory pool. */
#define VALGRIND_MEMPOOL_FREE(pool, addr) \
VALGRIND_DO_CLIENT_REQUEST_STMT(VG_USERREQ__MEMPOOL_FREE, \
pool, addr, 0, 0, 0)
/* Disassociate any pieces outside a particular range. */
#define VALGRIND_MEMPOOL_TRIM(pool, addr, size) \
VALGRIND_DO_CLIENT_REQUEST_STMT(VG_USERREQ__MEMPOOL_TRIM, \
pool, addr, size, 0, 0)
/* Resize and/or move a piece associated with a memory pool. */
#define VALGRIND_MOVE_MEMPOOL(poolA, poolB) \
VALGRIND_DO_CLIENT_REQUEST_STMT(VG_USERREQ__MOVE_MEMPOOL, \
poolA, poolB, 0, 0, 0)
/* Resize and/or move a piece associated with a memory pool. */
#define VALGRIND_MEMPOOL_CHANGE(pool, addrA, addrB, size) \
VALGRIND_DO_CLIENT_REQUEST_STMT(VG_USERREQ__MEMPOOL_CHANGE, \
pool, addrA, addrB, size, 0)
/* Return 1 if a mempool exists, else 0. */
#define VALGRIND_MEMPOOL_EXISTS(pool) \
(unsigned)VALGRIND_DO_CLIENT_REQUEST_EXPR(0, \
VG_USERREQ__MEMPOOL_EXISTS, \
pool, 0, 0, 0, 0)
/* Mark a piece of memory as being a stack. Returns a stack id.
start is the lowest addressable stack byte, end is the highest
addressable stack byte. */
#define VALGRIND_STACK_REGISTER(start, end) \
(unsigned)VALGRIND_DO_CLIENT_REQUEST_EXPR(0, \
VG_USERREQ__STACK_REGISTER, \
start, end, 0, 0, 0)
/* Unmark the piece of memory associated with a stack id as being a
stack. */
#define VALGRIND_STACK_DEREGISTER(id) \
VALGRIND_DO_CLIENT_REQUEST_STMT(VG_USERREQ__STACK_DEREGISTER, \
id, 0, 0, 0, 0)
/* Change the start and end address of the stack id.
start is the new lowest addressable stack byte, end is the new highest
addressable stack byte. */
#define VALGRIND_STACK_CHANGE(id, start, end) \
VALGRIND_DO_CLIENT_REQUEST_STMT(VG_USERREQ__STACK_CHANGE, \
id, start, end, 0, 0)
/* Load PDB debug info for Wine PE image_map. */
#define VALGRIND_LOAD_PDB_DEBUGINFO(fd, ptr, total_size, delta) \
VALGRIND_DO_CLIENT_REQUEST_STMT(VG_USERREQ__LOAD_PDB_DEBUGINFO, \
fd, ptr, total_size, delta, 0)
/* Map a code address to a source file name and line number. buf64
must point to a 64-byte buffer in the caller's address space. The
result will be dumped in there and is guaranteed to be zero
terminated. If no info is found, the first byte is set to zero. */
#define VALGRIND_MAP_IP_TO_SRCLOC(addr, buf64) \
(unsigned)VALGRIND_DO_CLIENT_REQUEST_EXPR(0, \
VG_USERREQ__MAP_IP_TO_SRCLOC, \
addr, buf64, 0, 0, 0)
/* Disable error reporting for this thread. Behaves in a stack like
way, so you can safely call this multiple times provided that
VALGRIND_ENABLE_ERROR_REPORTING is called the same number of times
to re-enable reporting. The first call of this macro disables
reporting. Subsequent calls have no effect except to increase the
number of VALGRIND_ENABLE_ERROR_REPORTING calls needed to re-enable
reporting. Child threads do not inherit this setting from their
parents -- they are always created with reporting enabled. */
#define VALGRIND_DISABLE_ERROR_REPORTING \
VALGRIND_DO_CLIENT_REQUEST_STMT(VG_USERREQ__CHANGE_ERR_DISABLEMENT, \
1, 0, 0, 0, 0)
/* Re-enable error reporting, as per comments on
VALGRIND_DISABLE_ERROR_REPORTING. */
#define VALGRIND_ENABLE_ERROR_REPORTING \
VALGRIND_DO_CLIENT_REQUEST_STMT(VG_USERREQ__CHANGE_ERR_DISABLEMENT, \
-1, 0, 0, 0, 0)
/* Execute a monitor command from the client program.
If a connection is opened with GDB, the output will be sent
according to the output mode set for vgdb.
If no connection is opened, output will go to the log output.
Returns 1 if command not recognised, 0 otherwise. */
#define VALGRIND_MONITOR_COMMAND(command) \
VALGRIND_DO_CLIENT_REQUEST_EXPR(0, VG_USERREQ__GDB_MONITOR_COMMAND, \
command, 0, 0, 0, 0)
/* Change the value of a dynamic command line option.
Note that unknown or not dynamically changeable options
will cause a warning message to be output. */
#define VALGRIND_CLO_CHANGE(option) \
VALGRIND_DO_CLIENT_REQUEST_STMT(VG_USERREQ__CLO_CHANGE, \
option, 0, 0, 0, 0)
#undef PLAT_x86_darwin
#undef PLAT_amd64_darwin
#undef PLAT_x86_win32
#undef PLAT_amd64_win64
#undef PLAT_x86_linux
#undef PLAT_amd64_linux
#undef PLAT_ppc32_linux
#undef PLAT_ppc64be_linux
#undef PLAT_ppc64le_linux
#undef PLAT_arm_linux
#undef PLAT_s390x_linux
#undef PLAT_mips32_linux
#undef PLAT_mips64_linux
#undef PLAT_nanomips_linux
#undef PLAT_x86_solaris
#undef PLAT_amd64_solaris
#endif /* __VALGRIND_H */
libinput-1.28.1/meson.build000066400000000000000000001067541477265155700156330ustar00rootroot00000000000000project('libinput', 'c',
version : '1.28.1',
license : 'MIT/Expat',
default_options : [ 'c_std=gnu99', 'warning_level=2' ],
meson_version : '>= 0.56.0')
libinput_version = meson.project_version().split('.')
dir_data = get_option('prefix') / get_option('datadir') / 'libinput'
dir_etc = get_option('prefix') / get_option('sysconfdir')
dir_overrides = get_option('prefix') / get_option('sysconfdir') / 'libinput'
dir_libexec = get_option('prefix') / get_option('libexecdir') / 'libinput'
dir_lib = get_option('prefix') / get_option('libdir')
dir_man1 = get_option('prefix') / get_option('mandir') / 'man1'
dir_system_udev = get_option('prefix') / 'lib' / 'udev'
dir_src_quirks = meson.current_source_dir() / 'quirks'
dir_src_test = meson.current_source_dir() / 'test'
dir_src = meson.current_source_dir() / 'src'
dir_gitlab_ci = meson.current_source_dir() / '.gitlab-ci'
dir_udev = get_option('udev-dir')
if dir_udev == ''
dir_udev = dir_system_udev
endif
dir_udev_callouts = dir_udev
dir_udev_rules = dir_udev / 'rules.d'
# Collection of man pages, we'll append to that
src_man = files()
# We use libtool-version numbers because it's easier to understand.
# Before making a release, the libinput_so_*
# numbers should be modified. The components are of the form C:R:A.
# a) If binary compatibility has been broken (eg removed or changed interfaces)
# change to C+1:0:0.
# b) If interfaces have been changed or added, but binary compatibility has
# been preserved, change to C+1:0:A+1
# c) If the interface is the same as the previous version, change to C:R+1:A
libinput_lt_c=23
libinput_lt_r=0
libinput_lt_a=13
# convert to soname
libinput_so_version = '@0@.@1@.@2@'.format((libinput_lt_c - libinput_lt_a),
libinput_lt_a, libinput_lt_r)
# Compiler setup
cc = meson.get_compiler('c')
cflags = [
'-Wno-unused-parameter',
'-Wmissing-prototypes',
'-Wstrict-prototypes',
'-Wundef',
'-Wlogical-op',
'-Wpointer-arith',
'-Wuninitialized',
'-Winit-self',
'-Wstrict-prototypes',
'-Wimplicit-fallthrough',
'-Wredundant-decls',
'-Wincompatible-pointer-types',
'-Wformat=2',
'-Wno-missing-field-initializers',
'-Wmissing-declarations',
'-fvisibility=hidden',
]
add_project_arguments(cc.get_supported_arguments(cflags), language : 'c')
# config.h
config_h = configuration_data()
doc_url_base = 'https://wayland.freedesktop.org/libinput/doc'
if libinput_version[2].to_int() >= 90
doc_url = '@0@/latest'.format(doc_url_base)
else
doc_url = '@0@/@1@'.format(doc_url_base, meson.project_version())
endif
config_h.set_quoted('HTTP_DOC_LINK', doc_url)
config_h.set('_GNU_SOURCE', '1')
if get_option('buildtype') == 'debug' or get_option('buildtype') == 'debugoptimized'
config_h.set_quoted('MESON_BUILD_ROOT', meson.current_build_dir())
else
config_h.set_quoted('MESON_BUILD_ROOT', '')
endif
prefix = '''#define _GNU_SOURCE 1
#include
'''
if cc.get_define('static_assert', prefix : prefix) == ''
config_h.set('static_assert(...)', '/* */')
endif
# Coverity breaks because it doesn't define _Float128 correctly, you'll end
# up with a bunch of messages in the form:
# "/usr/include/stdlib.h", line 133: error #20: identifier "_Float128" is
# undefined
# extern _Float128 strtof128 (const char *__restrict __nptr,
# ^
# We don't use float128 ourselves, it gets pulled in from math.h or
# something, so let's just define it as uint128 and move on.
# Unfortunately we can't detect the coverity build at meson configure
# time, we only know it fails at runtime. So make this an option instead, to
# be removed when coverity fixes this again.
if get_option('coverity')
config_h.set('_Float128', '__uint128_t')
config_h.set('_Float32', 'int')
config_h.set('_Float32x', 'int')
config_h.set('_Float64', 'long')
config_h.set('_Float64x', 'long')
endif
if cc.has_header_symbol('dirent.h', 'versionsort', prefix : prefix)
config_h.set('HAVE_VERSIONSORT', '1')
endif
if cc.get_define('SYS_pidfd_open', prefix: '#include ') != ''
config_h.set('HAVE_PIDFD_OPEN', '1')
endif
if cc.has_function('sigabbrev_np', prefix: '#define _GNU_SOURCE 1\n#include ')
config_h.set('HAVE_SIGABBREV_NP', '1')
endif
if not cc.has_header_symbol('errno.h', 'program_invocation_short_name', prefix : prefix)
if cc.has_header_symbol('stdlib.h', 'getprogname')
config_h.set('program_invocation_short_name', 'getprogname()')
endif
endif
if cc.has_header('xlocale.h')
config_h.set('HAVE_XLOCALE_H', '1')
endif
code = '''
#include
void main(void) { newlocale(LC_NUMERIC_MASK, "C", (locale_t)0); }
'''
if cc.links(code, name : 'locale.h')
config_h.set('HAVE_LOCALE_H', '1')
endif
if not cc.has_header_symbol('sys/ptrace.h', 'PTRACE_ATTACH', prefix : prefix)
config_h.set('PTRACE_ATTACH', 'PT_ATTACH')
config_h.set('PTRACE_CONT', 'PT_CONTINUE')
config_h.set('PTRACE_DETACH', 'PT_DETACH')
endif
config_h.set10('HAVE_INSTALLED_TESTS', get_option('install-tests'))
# Dependencies
pkgconfig = import('pkgconfig')
dep_udev = dependency('libudev')
dep_mtdev = dependency('mtdev', version : '>= 1.1.0')
dep_libevdev = dependency('libevdev')
config_h.set10('HAVE_LIBEVDEV_DISABLE_PROPERTY',
dep_libevdev.version().version_compare('>= 1.9.902'))
dep_lm = cc.find_library('m', required : false)
dep_rt = cc.find_library('rt', required : false)
# Include directories
includes_include = include_directories('include')
includes_src = include_directories('src')
############ libwacom configuration ############
have_libwacom = get_option('libwacom')
config_h.set10('HAVE_LIBWACOM', have_libwacom)
if have_libwacom
dep_libwacom = dependency('libwacom', version : '>= 0.27')
if cc.has_header_symbol('libwacom/libwacom.h', 'WACOM_BUTTON_DIAL_MODESWITCH',
dependencies : dep_libwacom)
config_h.set('HAVE_LIBWACOM_BUTTON_DIAL_MODESWITCH', '1')
endif
if cc.has_function('libwacom_get_button_modeswitch_mode',
dependencies: dep_libwacom)
config_h.set('HAVE_LIBWACOM_BUTTON_MODESWITCH_MODE', '1')
endif
else
dep_libwacom = declare_dependency()
endif
############ udev bits ############
executable('libinput-device-group',
'udev/libinput-device-group.c',
dependencies : [dep_udev, dep_libwacom],
include_directories : [includes_src, includes_include],
install : true,
install_dir : dir_udev_callouts)
executable('libinput-fuzz-extract',
'udev/libinput-fuzz-extract.c',
'src/util-strings.c',
'src/util-prop-parsers.c',
dependencies : [dep_udev, dep_libevdev, dep_lm],
include_directories : [includes_src, includes_include],
install : true,
install_dir : dir_udev_callouts)
executable('libinput-fuzz-to-zero',
'udev/libinput-fuzz-to-zero.c',
dependencies : [dep_udev, dep_libevdev],
include_directories : [includes_src, includes_include],
install : true,
install_dir : dir_udev_callouts)
udev_rules_config = configuration_data()
udev_rules_config.set('UDEV_TEST_PATH', '')
configure_file(input : 'udev/80-libinput-device-groups.rules.in',
output : '80-libinput-device-groups.rules',
install_dir : dir_udev_rules,
configuration : udev_rules_config)
configure_file(input : 'udev/90-libinput-fuzz-override.rules.in',
output : '90-libinput-fuzz-override.rules',
install_dir : dir_udev_rules,
configuration : udev_rules_config)
litest_udev_rules_config = configuration_data()
litest_udev_rules_config.set('UDEV_TEST_PATH', meson.current_build_dir() + '/')
litest_groups_rules_file = configure_file(input : 'udev/80-libinput-device-groups.rules.in',
output : '80-libinput-device-groups-litest.rules',
configuration : litest_udev_rules_config)
litest_fuzz_override_file = configure_file(input : 'udev/90-libinput-fuzz-override.rules.in',
output : '90-libinput-fuzz-override-litest.rules',
configuration : litest_udev_rules_config)
############ Check for leftover udev rules ########
# This test should be defined first so we don't waste time testing anything
# else if we're about to fail anyway. ninja test will execute tests in the
# order of them defined in meson.build
if get_option('tests')
test('leftover-rules',
find_program('test/check-leftover-udev-rules.sh'),
is_parallel : false,
suite : ['all'])
endif
############ libepoll-shim (BSD) ############
if cc.has_header_symbol('sys/epoll.h', 'epoll_create1', prefix : prefix)
# epoll is built-in (Linux, illumos)
dep_libepoll = declare_dependency()
else
# epoll is implemented in userspace by libepoll-shim (FreeBSD)
dir_libepoll = get_option('epoll-dir')
if dir_libepoll == ''
dir_libepoll = get_option('prefix')
endif
includes_epoll = include_directories(dir_libepoll / 'include' / 'libepoll-shim')
dep_libepoll = cc.find_library('epoll-shim', dirs : dir_libepoll / 'lib')
code = '''
#include
int main(void) { epoll_create1(0); }
'''
if not cc.links(code,
name : 'libepoll-shim check',
dependencies : [dep_libepoll, dep_rt],
include_directories : includes_epoll) # note: wants an include_directories object
error('No built-in epoll or libepoll-shim found.')
endif
dep_libepoll = declare_dependency(
include_directories : includes_epoll,
dependencies : [dep_libepoll, dep_rt])
endif
############ libinput-util.a ############
# Basic compilation test to make sure the headers include and define all the
# necessary bits.
util_headers = [
'util-backtrace.h',
'util-bits.h',
'util-input-event.h',
'util-list.h',
'util-files.h',
'util-macros.h',
'util-matrix.h',
'util-prop-parsers.h',
'util-ratelimit.h',
'util-stringbuf.h',
'util-strings.h',
'util-time.h',
]
foreach h: util_headers
c = configuration_data()
c.set_quoted('FILE', h)
testfile = configure_file(input : 'test/test-util-includes.c',
output : 'test-util-includes-@0@.c'.format(h),
configuration : c)
executable('test-build-@0@'.format(h),
testfile,
include_directories : [includes_src, includes_include],
install : false)
endforeach
src_libinput_util = [
'src/util-list.c',
'src/util-ratelimit.c',
'src/util-strings.c',
'src/util-prop-parsers.c',
]
libinput_util = static_library('libinput-util',
src_libinput_util,
dependencies : [dep_udev, dep_libevdev, dep_libwacom],
include_directories : includes_include)
dep_libinput_util = declare_dependency(link_with : libinput_util)
############ libfilter.a ############
src_libfilter = [
'src/filter.c',
'src/filter-custom.c',
'src/filter-flat.c',
'src/filter-low-dpi.c',
'src/filter-mouse.c',
'src/filter-touchpad.c',
'src/filter-touchpad-flat.c',
'src/filter-touchpad-x230.c',
'src/filter-tablet.c',
'src/filter-trackpoint.c',
'src/filter-trackpoint-flat.c',
]
libfilter = static_library('filter', src_libfilter,
dependencies : [dep_udev, dep_libwacom],
include_directories : includes_include)
dep_libfilter = declare_dependency(link_with : libfilter)
############ libquirks.a #############
libinput_data_path = dir_data
libinput_data_override_path = dir_overrides / 'local-overrides.quirks'
config_h.set_quoted('LIBINPUT_QUIRKS_DIR', dir_data)
config_h.set_quoted('LIBINPUT_QUIRKS_OVERRIDE_FILE', libinput_data_override_path)
config_h.set_quoted('LIBINPUT_QUIRKS_SRCDIR', dir_src_quirks)
install_subdir('quirks',
exclude_files: ['README.md'],
install_dir : dir_data,
strip_directory : true)
src_libquirks = [
'src/quirks.c',
]
deps_libquirks = [dep_udev, dep_libwacom, dep_libinput_util]
libquirks = static_library('quirks', src_libquirks,
dependencies : deps_libquirks,
include_directories : includes_include)
dep_libquirks = declare_dependency(link_with : libquirks)
# Create /etc/libinput
if meson.version().version_compare('>= 0.60')
install_emptydir(dir_etc / 'libinput')
else
install_subdir('libinput', install_dir : dir_etc)
endif
############ libinput.so ############
config_h.set10('EVENT_DEBUGGING', get_option('internal-event-debugging'))
install_headers('src/libinput.h')
src_libinput = src_libfilter + [
'src/libinput.c',
'src/libinput-private-config.c',
'src/evdev.c',
'src/evdev-debounce.c',
'src/evdev-fallback.c',
'src/evdev-totem.c',
'src/evdev-middle-button.c',
'src/evdev-mt-touchpad.c',
'src/evdev-mt-touchpad-tap.c',
'src/evdev-mt-touchpad-thumb.c',
'src/evdev-mt-touchpad-buttons.c',
'src/evdev-mt-touchpad-edge-scroll.c',
'src/evdev-mt-touchpad-gestures.c',
'src/evdev-tablet.c',
'src/evdev-tablet-pad.c',
'src/evdev-tablet-pad-leds.c',
'src/evdev-wheel.c',
'src/path-seat.c',
'src/udev-seat.c',
'src/timer.c',
'src/util-libinput.c',
]
deps_libinput = [
dep_mtdev,
dep_udev,
dep_libevdev,
dep_libepoll,
dep_lm,
dep_rt,
dep_libwacom,
dep_libinput_util,
dep_libquirks
]
libinput_version_h_config = configuration_data()
libinput_version_h_config.set('LIBINPUT_VERSION_MAJOR', libinput_version[0])
libinput_version_h_config.set('LIBINPUT_VERSION_MINOR', libinput_version[1])
libinput_version_h_config.set('LIBINPUT_VERSION_MICRO', libinput_version[2])
libinput_version_h_config.set('LIBINPUT_VERSION', meson.project_version())
libinput_version_h = configure_file(
input : 'src/libinput-version.h.in',
output : 'libinput-version.h',
configuration : libinput_version_h_config,
)
mapfile = dir_src / 'libinput.sym'
version_flag = '-Wl,--version-script,@0@'.format(mapfile)
lib_libinput = shared_library('input',
src_libinput,
include_directories : [include_directories('.'), includes_include],
dependencies : deps_libinput,
version : libinput_so_version,
link_args : version_flag,
link_depends : mapfile,
install : true
)
dep_libinput = declare_dependency(
link_with : lib_libinput,
dependencies : deps_libinput)
if meson.version().version_compare('>= 0.54.0')
meson.override_dependency('libinput', dep_libinput)
endif
pkgconfig.generate(
filebase : 'libinput',
name : 'Libinput',
description : 'Input device library',
version : meson.project_version(),
libraries : lib_libinput
)
git_version_h = vcs_tag(command : ['git', 'describe'],
fallback : 'unknown',
input : 'src/libinput-git-version.h.in',
output :'libinput-git-version.h')
############ documentation ############
if get_option('documentation')
subdir('doc/api')
subdir('doc/user')
endif
############ shell completion #########
subdir('completion/zsh')
############ libinput-util-libinput.a ############
# This one needs libinput itself
src_libinput_util_libinput = [
'src/util-libinput.c'
]
libinput_util_libinput = static_library('libinput-util-libinput',
src_libinput_util_libinput,
dependencies : [dep_libevdev, dep_libinput_util, dep_libinput],
include_directories : includes_include)
dep_libinput_util_libinput = declare_dependency(link_with : libinput_util_libinput)
############ tools ############
libinput_tool_path = dir_libexec
config_h.set_quoted('LIBINPUT_TOOL_PATH', libinput_tool_path)
tools_shared_sources = [ 'tools/shared.c' ]
deps_tools_shared = [ dep_libinput, dep_libevdev, dep_libinput_util_libinput ]
lib_tools_shared = static_library('tools_shared',
tools_shared_sources,
include_directories : [includes_src, includes_include],
dependencies : deps_tools_shared)
dep_tools_shared = declare_dependency(link_with : lib_tools_shared,
dependencies : deps_tools_shared)
deps_tools = [ dep_tools_shared, dep_libinput ]
libinput_debug_events_sources = [
'tools/libinput-debug-events.c',
libinput_version_h,
]
executable('libinput-debug-events',
libinput_debug_events_sources,
dependencies : deps_tools,
include_directories : [includes_src, includes_include],
install_dir : libinput_tool_path,
install : true
)
libinput_debug_tablet_sources = [ 'tools/libinput-debug-tablet.c' ]
executable('libinput-debug-tablet',
libinput_debug_tablet_sources,
dependencies : deps_tools,
include_directories : [includes_src, includes_include],
install_dir : libinput_tool_path,
install : true)
libinput_quirks_sources = [ 'tools/libinput-quirks.c' ]
libinput_quirks = executable('libinput-quirks',
libinput_quirks_sources,
dependencies : [dep_libquirks, dep_tools_shared, dep_libinput],
include_directories : [includes_src, includes_include],
install_dir : libinput_tool_path,
install : true
)
test('validate-quirks',
libinput_quirks,
args: ['validate', '--data-dir=@0@'.format(dir_src_quirks)],
suite : ['all']
)
quirks_file_tester = find_program('test/test_quirks_files.py')
test('validate-quirks-files',
quirks_file_tester,
suite : ['all'],
env: ['MESON_SOURCE_ROOT=@0@'.format(meson.project_source_root())],
)
libinput_list_devices_sources = [ 'tools/libinput-list-devices.c' ]
libinput_list_devices = executable('libinput-list-devices',
libinput_list_devices_sources,
dependencies : deps_tools,
include_directories : [includes_src, includes_include],
install_dir : libinput_tool_path,
install : true,
)
test('list-devices',
libinput_list_devices,
suite : ['all', 'root', 'hardware'])
libinput_measure_sources = [ 'tools/libinput-measure.c' ]
executable('libinput-measure',
libinput_measure_sources,
dependencies : deps_tools,
include_directories : [includes_src, includes_include],
install_dir : libinput_tool_path,
install : true,
)
libinput_analyze_sources = [ 'tools/libinput-analyze.c' ]
executable('libinput-analyze',
libinput_analyze_sources,
dependencies : deps_tools,
include_directories : [includes_src, includes_include],
install_dir : libinput_tool_path,
install : true,
)
src_python_tools = files(
'tools/libinput-analyze-buttons.py',
'tools/libinput-analyze-per-slot-delta.py',
'tools/libinput-analyze-recording.py',
'tools/libinput-analyze-touch-down-state.py',
'tools/libinput-list-kernel-devices.py',
'tools/libinput-measure-fuzz.py',
'tools/libinput-measure-touchpad-size.py',
'tools/libinput-measure-touchpad-tap.py',
'tools/libinput-measure-touchpad-pressure.py',
'tools/libinput-measure-touch-size.py',
'tools/libinput-replay.py'
)
foreach t : src_python_tools
configure_file(input: t,
output: '@BASENAME@',
copy: true,
install_dir : libinput_tool_path
)
endforeach
libinput_record_sources = [ 'tools/libinput-record.c', git_version_h ]
executable('libinput-record',
libinput_record_sources,
dependencies : deps_tools + [dep_udev],
include_directories : [includes_src, includes_include],
install_dir : libinput_tool_path,
install : true,
)
config_h.set10('HAVE_DEBUG_GUI', get_option('debug-gui'))
if get_option('debug-gui')
dep_gtk = dependency('gtk4', version : '>= 4.0', required : false)
config_h.set10('HAVE_GTK4', dep_gtk.found())
if not dep_gtk.found()
dep_gtk = dependency('gtk+-3.0', version : '>= 3.20')
config_h.set10('HAVE_GTK3', dep_gtk.found())
endif
if meson.version().version_compare('>= 0.58')
gtk_targets = dep_gtk.get_variable('targets')
else
gtk_targets = dep_gtk.get_pkgconfig_variable('targets')
endif
have_gtk_wayland = gtk_targets.contains('wayland')
have_gtk_x11 = gtk_targets.contains('x11')
dep_cairo = dependency('cairo')
dep_glib = dependency('glib-2.0')
dep_x11 = dependency('x11', required : false)
dep_wayland_client = dependency('wayland-client', required : false)
dep_wayland_protocols = dependency('wayland-protocols', required : false)
config_h.set10('HAVE_GTK_X11', have_gtk_x11 and dep_x11.found())
config_h.set10('HAVE_GTK_WAYLAND', false)
debug_gui_sources = [ 'tools/libinput-debug-gui.c' ]
if have_gtk_wayland and dep_wayland_client.found() and dep_wayland_protocols.found()
wayland_scanner = find_program('wayland-scanner')
if meson.version().version_compare('>= 0.58')
wlproto_dir = dep_wayland_protocols.get_variable('pkgdatadir')
else
wlproto_dir = dep_wayland_protocols.get_pkgconfig_variable('pkgdatadir')
endif
proto_name = 'pointer-constraints-unstable-v1'
input = files(wlproto_dir / 'unstable' / 'pointer-constraints' / '@0@.xml'.format(proto_name))
wayland_headers = custom_target('@0@ client header'.format(proto_name),
input: input,
output: '@0@-client-protocol.h'.format(proto_name),
command: [wayland_scanner, 'client-header', '@INPUT@', '@OUTPUT@'],
)
wayland_sources = custom_target('@0@ source'.format(proto_name),
input: input,
output: '@0@-protocol.c'.format(proto_name),
command: [wayland_scanner, 'private-code', '@INPUT@', '@OUTPUT@'],
)
debug_gui_sources += [ wayland_headers, wayland_sources ]
config_h.set10('HAVE_GTK_WAYLAND', true)
endif
deps_debug_gui = [
dep_gtk,
dep_cairo,
dep_glib,
dep_wayland_client,
dep_wayland_protocols,
dep_x11,
] + deps_tools
executable('libinput-debug-gui',
debug_gui_sources,
dependencies : deps_debug_gui,
include_directories : [includes_src, includes_include],
install_dir : libinput_tool_path,
install : true
)
src_man += files('tools/libinput-debug-gui.man')
endif
libinput_sources = [ 'tools/libinput-tool.c' ]
libinput_tool = executable('libinput',
libinput_sources,
dependencies : deps_tools,
include_directories : [includes_src, includes_include],
install : true
)
ptraccel_debug_sources = [ 'tools/ptraccel-debug.c' ]
executable('ptraccel-debug',
ptraccel_debug_sources,
dependencies : [ dep_libfilter, dep_libinput ],
include_directories : [includes_src, includes_include],
install : false
)
# Don't run the test during a release build because we rely on the magic
# subtool lookup
if get_option('buildtype') == 'debug' or get_option('buildtype') == 'debugoptimized'
config_tool_option_test = configuration_data()
config_tool_option_test.set('DISABLE_WARNING', 'yes')
config_tool_option_test.set('MESON_ENABLED_DEBUG_GUI', get_option('debug-gui'))
config_tool_option_test.set('MESON_BUILD_ROOT', meson.current_build_dir())
config_tool_option_test.set('TOOL_PATH', libinput_tool.full_path())
tool_option_test = configure_file(input: 'tools/test_tool_option_parsing.py',
output: '@PLAINNAME@',
configuration : config_tool_option_test)
test('tool-option-parsing',
tool_option_test,
args : [tool_option_test],
suite : ['all', 'root'],
timeout : 240)
endif
# the libinput tools check whether we execute from the builddir, this is
# the test to verify that lookup. We test twice, once as normal test
# run from the builddir, once after copying to /tmp
test_builddir_lookup = executable('test-builddir-lookup',
'test/test-builddir-lookup.c',
dependencies : [ dep_tools_shared],
include_directories : [includes_src, includes_include],
install : false)
test('tools-builddir-lookup',
test_builddir_lookup,
args : ['--builddir-is-set'],
suite : ['all'])
test('tools-builddir-lookup-installed',
find_program('test/helper-copy-and-exec-from-tmp.sh'),
args : [test_builddir_lookup.full_path(), '--builddir-is-null'],
env : ['LD_LIBRARY_PATH=@0@'.format(meson.current_build_dir())],
suite : ['all'],
workdir : '/tmp')
############ tests ############
test('symbols-leak-test',
find_program('test/symbols-leak-test'),
args : [ dir_src / 'libinput.sym', dir_src],
suite : ['all'])
# build-test only
executable('test-build-pedantic',
'test/build-pedantic.c',
dependencies : [dep_udev],
include_directories : [includes_src, includes_include],
c_args : ['-std=c99', '-pedantic', '-Werror'],
install : false)
# build-test only
executable('test-build-std-gnuc90',
'test/build-pedantic.c',
dependencies : [dep_udev],
include_directories : [includes_src, includes_include],
c_args : ['-std=gnu89', '-Werror'],
install : false)
# test for linking with the minimal linker flags
executable('test-build-linker',
'test/build-pedantic.c',
include_directories : [includes_src, includes_include],
dependencies : [ dep_libinput, dep_libinput_util ],
install : false)
# test including from C++ (in case CPP compiler is available)
if add_languages('cpp', native: false, required: false)
executable('test-build-cxx',
'test/build-cxx.cc',
dependencies : [dep_udev],
include_directories : [includes_src, includes_include],
install : false)
endif
libinput_test_sources = [ 'tools/libinput-test.c' ]
executable('libinput-test',
libinput_test_sources,
dependencies : deps_tools,
include_directories : [includes_src, includes_include],
install_dir : libinput_tool_path,
install : true,
)
# This is the test suite runner, we allow disabling that one because of
# dependencies
if get_option('tests')
dep_check = dependency('check', version : '>= 0.9.10', required: false)
gstack = find_program('gstack', required : false)
config_h.set10('HAVE_GSTACK', gstack.found())
# for inhibit support during test run
dep_libsystemd = dependency('libsystemd', version : '>= 221', required : false)
config_h.set10('HAVE_LIBSYSTEMD', dep_libsystemd.found())
litest_sources = [
'src/libinput-private-config.c',
'test/litest-device-absinfo-override.c',
'test/litest-device-acer-hawaii-keyboard.c',
'test/litest-device-acer-hawaii-touchpad.c',
'test/litest-device-aiptek-tablet.c',
'test/litest-device-alps-3fg.c',
'test/litest-device-alps-semi-mt.c',
'test/litest-device-alps-dualpoint.c',
'test/litest-device-anker-mouse-kbd.c',
'test/litest-device-apple-appletouch.c',
'test/litest-device-apple-internal-keyboard.c',
'test/litest-device-apple-magicmouse.c',
'test/litest-device-asus-rog-gladius.c',
'test/litest-device-atmel-hover.c',
'test/litest-device-bcm5974.c',
'test/litest-device-calibrated-touchscreen.c',
'test/litest-device-cyborg-rat-5.c',
'test/litest-device-dell-canvas-totem.c',
'test/litest-device-dell-canvas-totem-touch.c',
'test/litest-device-elantech-touchpad.c',
'test/litest-device-elan-tablet.c',
'test/litest-device-format-string.c',
'test/litest-device-generic-pressurepad.c',
'test/litest-device-generic-singletouch.c',
'test/litest-device-gpio-keys.c',
'test/litest-device-huion-pentablet.c',
'test/litest-device-huion-q620m-dial.c',
'test/litest-device-hp-wmi-hotkeys.c',
'test/litest-device-ignored-mouse.c',
'test/litest-device-keyboard.c',
'test/litest-device-keyboard-all-codes.c',
'test/litest-device-keyboard-quirked.c',
'test/litest-device-keyboard-razer-blackwidow.c',
'test/litest-device-keyboard-razer-blade-stealth.c',
'test/litest-device-keyboard-razer-blade-stealth-videoswitch.c',
'test/litest-device-lenovo-scrollpoint.c',
'test/litest-device-lid-switch.c',
'test/litest-device-lid-switch-surface3.c',
'test/litest-device-logitech-media-keyboard-elite.c',
'test/litest-device-logitech-trackball.c',
'test/litest-device-nexus4-touch-screen.c',
'test/litest-device-magic-trackpad.c',
'test/litest-device-mouse.c',
'test/litest-device-mouse-wheel-tilt.c',
'test/litest-device-mouse-roccat.c',
'test/litest-device-mouse-low-dpi.c',
'test/litest-device-mouse-wheel-click-angle.c',
'test/litest-device-mouse-wheel-click-count.c',
'test/litest-device-ms-nano-transceiver-mouse.c',
'test/litest-device-ms-surface-cover.c',
'test/litest-device-protocol-a-touch-screen.c',
'test/litest-device-qemu-usb-tablet.c',
'test/litest-device-sony-vaio-keys.c',
'test/litest-device-synaptics-x220.c',
'test/litest-device-synaptics-hover.c',
'test/litest-device-synaptics-i2c.c',
'test/litest-device-synaptics-pressurepad.c',
'test/litest-device-synaptics-rmi4.c',
'test/litest-device-synaptics-st.c',
'test/litest-device-synaptics-t440.c',
'test/litest-device-synaptics-x1-carbon-3rd.c',
'test/litest-device-synaptics-phantomclicks.c',
'test/litest-device-tablet-doubledial.c',
'test/litest-device-tablet-mode-switch.c',
'test/litest-device-tablet-rel-dial.c',
'test/litest-device-thinkpad-extrabuttons.c',
'test/litest-device-trackpoint.c',
'test/litest-device-touch-screen.c',
'test/litest-device-touchpad-palm-threshold-zero.c',
'test/litest-device-touchscreen-invalid-range.c',
'test/litest-device-touchscreen-fuzz.c',
'test/litest-device-touchscreen-mt-tool.c',
'test/litest-device-uclogic-tablet.c',
'test/litest-device-wacom-bamboo-2fg-finger.c',
'test/litest-device-wacom-bamboo-2fg-pad.c',
'test/litest-device-wacom-bamboo-2fg-pen.c',
'test/litest-device-wacom-bamboo-16fg-pen.c',
'test/litest-device-wacom-calibrated-tablet.c',
'test/litest-device-wacom-cintiq-12wx-pen.c',
'test/litest-device-wacom-cintiq-13hdt-finger.c',
'test/litest-device-wacom-cintiq-13hdt-pad.c',
'test/litest-device-wacom-cintiq-13hdt-pen.c',
'test/litest-device-wacom-cintiq-24hd-pen.c',
'test/litest-device-wacom-cintiq-24hdt-pad.c',
'test/litest-device-wacom-cintiq-pro-16-finger.c',
'test/litest-device-wacom-cintiq-pro-16-pad.c',
'test/litest-device-wacom-cintiq-pro-16-pen.c',
'test/litest-device-wacom-ekr.c',
'test/litest-device-wacom-hid4800-pen.c',
'test/litest-device-wacom-intuos3-pad.c',
'test/litest-device-wacom-intuos5-finger.c',
'test/litest-device-wacom-intuos5-pad.c',
'test/litest-device-wacom-intuos5-pen.c',
'test/litest-device-wacom-isdv4-4200-pen.c',
'test/litest-device-wacom-isdv4-524c-pen.c',
'test/litest-device-wacom-isdv4-e6-pen.c',
'test/litest-device-wacom-isdv4-e6-finger.c',
'test/litest-device-wacom-mobilestudio-pro-pad.c',
'test/litest-device-waltop-tablet.c',
'test/litest-device-wheel-only.c',
'test/litest-device-xen-virtual-pointer.c',
'test/litest-device-vmware-virtual-usb-mouse.c',
'test/litest-device-yubikey.c',
'test/litest-runner.c',
'test/litest.c',
]
dep_dl = cc.find_library('dl')
deps_litest = [
dep_libinput,
dep_udev,
dep_libevdev,
dep_dl,
dep_lm,
dep_libsystemd,
dep_libquirks,
dep_libinput_util_libinput,
]
litest_config_h = configuration_data()
litest_config_h.set_quoted('LIBINPUT_DEVICE_GROUPS_RULES_FILE',
meson.current_build_dir() /
'80-libinput-device-groups-litest.rules')
litest_config_h.set_quoted('LIBINPUT_FUZZ_OVERRIDE_UDEV_RULES_FILE',
meson.current_build_dir() /
'90-libinput-fuzz-override-litest.rules')
def_no_main = '-DLITEST_NO_MAIN'
if dep_check.found()
def_disable_backtrace = '-DLITEST_DISABLE_BACKTRACE_LOGGING'
defs_litest_selftest = [
def_no_main,
def_disable_backtrace,
'-Wno-unused',
]
test_litest_selftest_sources = [
'test/litest-selftest.c',
'test/litest-runner.c',
'test/litest.c',
]
test_litest_selftest = executable('test-litest-selftest',
test_litest_selftest_sources,
include_directories : [includes_src, includes_include],
dependencies : [deps_litest, dep_check],
c_args : defs_litest_selftest,
install : false)
test('test-litest-selftest',
test_litest_selftest,
suite : ['all'],
timeout : 100)
endif
def_LT_VERSION = '-DLIBINPUT_LT_VERSION="@0@:@1@:@2@"'.format(libinput_lt_c, libinput_lt_r, libinput_lt_a)
test_library_version = executable('test-library-version',
['test/test-library-version.c'],
c_args : [ def_LT_VERSION ],
install : false)
test('test-library-version',
test_library_version,
suite : ['all'])
test_utils_sources = [
'test/test-utils.c',
'test/litest-runner.c',
'test/litest.c',
]
test_utils = executable('libinput-test-utils',
test_utils_sources,
include_directories : [includes_src, includes_include],
c_args : [def_no_main],
dependencies : deps_litest,
install_dir : libinput_tool_path,
install : get_option('install-tests'))
test('test-utils',
test_utils,
suite : ['all'])
tests_sources = [
'test/test-udev.c',
'test/test-path.c',
'test/test-pointer.c',
'test/test-touch.c',
'test/test-log.c',
'test/test-tablet.c',
'test/test-totem.c',
'test/test-pad.c',
'test/test-touchpad.c',
'test/test-touchpad-tap.c',
'test/test-touchpad-buttons.c',
'test/test-trackpoint.c',
'test/test-trackball.c',
'test/test-misc.c',
'test/test-keyboard.c',
'test/test-device.c',
'test/test-gestures.c',
'test/test-switch.c',
'test/test-quirks.c',
]
libinput_test_runner_sources = litest_sources + tests_sources
libinput_test_runner = executable('libinput-test-suite',
libinput_test_runner_sources,
include_directories : [includes_src, includes_include],
dependencies : deps_litest,
install_dir : libinput_tool_path,
install : get_option('install-tests'))
src_man += 'test/libinput-test-suite.man'
# When adding new TEST_COLLECTION() macros, add to this list and the CI
# $ git grep TEST_COLLECTION test/test-* | sed -e "s|.*TEST_COLLECTION(\(.*\))|\t\t'\1',|" | sort
collections = [
'device',
'gestures',
'keyboard',
'log',
'misc',
'pad',
'path',
'pointer',
'quirks',
'switch',
'tablet',
'tablet_left_handed',
'totem',
'touch',
'touchpad',
'touchpad_buttons',
'touchpad_dwt',
'touchpad_palm',
'touchpad_tap',
'touchpad_tap_drag',
'touchpad_tap_palm',
'trackball',
'trackpoint',
'udev',
]
foreach group : collections
test('libinput-test-suite-@0@'.format(group),
libinput_test_runner,
suite : ['all', 'valgrind', 'root', 'hardware'],
args : ['--filter-group=@0@'.format(group)],
is_parallel : false,
timeout : 1200)
endforeach
test('libinput-test-deviceless',
libinput_test_runner,
suite : ['all', 'valgrind'],
args: ['--filter-deviceless'])
valgrind = find_program('valgrind', required : false)
if valgrind.found()
valgrind_env = environment()
valgrind_suppressions_file = dir_src_test / 'valgrind.suppressions'
add_test_setup('valgrind',
exe_wrapper : [ valgrind,
'--log-file=valgrind.%p.log',
'--leak-check=full',
'--gen-suppressions=all',
'--error-exitcode=3',
'--suppressions=' + valgrind_suppressions_file ],
env : valgrind_env,
timeout_multiplier : 100)
else
message('valgrind not found, disabling valgrind test suite')
endif
configure_file(output : 'litest-config.h',
configuration : litest_config_h)
endif
############ man pages ############
man_config = configuration_data()
man_config.set('LIBINPUT_VERSION', meson.project_version())
man_config.set('LIBINPUT_DATA_DIR', dir_data)
if get_option('install-tests')
man_config.set('HAVE_INSTALLED_TESTS', '.\"')
else
man_config.set('HAVE_INSTALLED_TESTS', '')
endif
if get_option('debug-gui')
man_config.set('HAVE_DEBUG_GUI', '')
else
man_config.set('HAVE_DEBUG_GUI', '.\"')
endif
src_man += files(
'tools/libinput.man',
'tools/libinput-analyze.man',
'tools/libinput-analyze-buttons.man',
'tools/libinput-analyze-per-slot-delta.man',
'tools/libinput-analyze-recording.man',
'tools/libinput-analyze-touch-down-state.man',
'tools/libinput-debug-events.man',
'tools/libinput-debug-tablet.man',
'tools/libinput-list-devices.man',
'tools/libinput-list-kernel-devices.man',
'tools/libinput-measure.man',
'tools/libinput-measure-fuzz.man',
'tools/libinput-measure-touchpad-size.man',
'tools/libinput-measure-touchpad-tap.man',
'tools/libinput-measure-touchpad-pressure.man',
'tools/libinput-measure-touch-size.man',
'tools/libinput-quirks.man',
'tools/libinput-record.man',
'tools/libinput-replay.man',
'tools/libinput-test.man',
)
foreach m : src_man
configure_file(input : m,
output : '@BASENAME@.1',
configuration : man_config,
install_dir : dir_man1)
endforeach
# Same man page for the subtools to stay consistent with the other tools
configure_file(input : 'tools/libinput-quirks.man',
output : 'libinput-quirks-list.1',
configuration : man_config,
install_dir : dir_man1,
)
configure_file(input : 'tools/libinput-quirks.man',
output : 'libinput-quirks-validate.1',
configuration : man_config,
install_dir : dir_man1,
)
############ output files ############
configure_file(output : 'config.h', configuration : config_h)
libinput-1.28.1/meson_options.txt000066400000000000000000000027201477265155700171120ustar00rootroot00000000000000option('udev-dir',
type: 'string',
value: '',
description: 'udev base directory [default=$prefix/lib/udev]')
option('epoll-dir',
type: 'string',
value: '',
description: 'libepoll-shim base directory (for non-Linux OS) [default=$prefix]')
option('libwacom',
type: 'boolean',
value: true,
description: 'Use libwacom for tablet identification (default=true)')
option('debug-gui',
type: 'boolean',
value: true,
description: 'Enable the "debug-gui" feature in the libinput tool [default=true]')
option('tests',
type: 'boolean',
value: true,
description: 'Build the tests [default=true]')
option('install-tests',
type: 'boolean',
value: false,
description: 'Install the libinput test command [default=false]')
option('documentation',
type: 'boolean',
value: false,
description: 'Build the documentation [default=false]')
option('coverity',
type: 'boolean',
value: false,
description: 'Enable coverity build fixes, see meson.build for details [default=false]')
option('zshcompletiondir',
type: 'string',
value: '',
description: 'Directory for zsh completion scripts ["no" disables]')
option('internal-event-debugging',
type: 'boolean',
value: false,
description: 'Enable additional internal event debug tracing. This will print key values to the logs and thus must never be enabled in a release build')
libinput-1.28.1/quirks/000077500000000000000000000000001477265155700147725ustar00rootroot00000000000000libinput-1.28.1/quirks/10-generic-keyboard.quirks000066400000000000000000000003651477265155700216660ustar00rootroot00000000000000# Do not edit this file, it will be overwritten on update
[Serial Keyboards]
MatchUdevType=keyboard
MatchBus=ps2
AttrKeyboardIntegration=internal
[Bluetooth Keyboards]
MatchUdevType=keyboard
MatchBus=bluetooth
AttrKeyboardIntegration=external
libinput-1.28.1/quirks/10-generic-mouse.quirks000066400000000000000000000003051477265155700212100ustar00rootroot00000000000000# Do not edit this file, it will be overwritten on update
# https://gitlab.freedesktop.org/libinput/libinput/-/issues/656
[Emulated Mouse]
MatchName=ImPS/2 Generic Wheel Mouse
ModelBouncingKeys=1
libinput-1.28.1/quirks/10-generic-trackball.quirks000066400000000000000000000001561477265155700220230ustar00rootroot00000000000000# Do not edit this file, it will be overwritten on update
[Trackball]
MatchName=*Trackball*
ModelTrackball=1
libinput-1.28.1/quirks/30-vendor-a4tech.quirks000066400000000000000000000001441477265155700211140ustar00rootroot00000000000000[A4TECH USB X-710BK]
MatchVendor=0x09DA
MatchProduct=0x9090
MatchUdevType=mouse
ModelBouncingKeys=1
libinput-1.28.1/quirks/30-vendor-aiptek.quirks000066400000000000000000000004631477265155700212250ustar00rootroot00000000000000# Do not edit this file, it will be overwritten on update
[Aiptek No Tilt Tablet]
MatchUdevType=tablet
MatchBus=usb
MatchVendor=0x08CA
AttrEventCode=-ABS_TILT_X;-ABS_TILT_Y;
[Aiptek 8000U pressure threshold]
MatchUdevType=tablet
MatchBus=usb
MatchVendor=0x08CA
MatchProduct=0x0010
AttrPressureRange=70:50
libinput-1.28.1/quirks/30-vendor-alps.quirks000066400000000000000000000015761477265155700207150ustar00rootroot00000000000000# Do not edit this file, it will be overwritten on update
# ALPS firmware versions:
# V1 = 0x100
# V2 = 0x200
# V3 = 0x300
# V3_RUSHMORE = 0x310
# V4 = 0x400
# V5 = 0x500
# V6 = 0x600
# V7 = 0x700 /* t3btl t4s */
# V8 = 0x800 /* SS4btl SS4s */
# V9 = 0x900 /* ss3btl */
[ALPS Serial Touchpads]
MatchUdevType=touchpad
MatchBus=ps2
MatchVendor=0x0002
MatchProduct=0x0008
ModelALPSSerialTouchpad=1
[ALPS i2c Touchpads]
MatchUdevType=touchpad
MatchBus=i2c
MatchVendor=0x0488
AttrPalmPressureThreshold=180
[ALPS v8 Touchpads]
MatchUdevType=touchpad
MatchBus=ps2
MatchVendor=0x0002
MatchProduct=0x0008
MatchVersion=0x0800
AttrSizeHint=100x55
[ALPS v8 Trackpoint]
MatchUdevType=pointingstick
MatchBus=ps2
MatchVendor=0x0002
MatchProduct=0x0008
MatchVersion=0x0800
AttrTrackpointMultiplier=0.125
libinput-1.28.1/quirks/30-vendor-contour.quirks000066400000000000000000000010771477265155700214430ustar00rootroot00000000000000[Contour Design RollerMouse Free 2]
MatchVendor=0x0B33
MatchProduct=0x0401
MatchUdevType=mouse
ModelBouncingKeys=1
[Contour Design RollerMouse Free 3]
MatchVendor=0x0B33
MatchProduct=0x0404
MatchUdevType=mouse
ModelBouncingKeys=1
[Contour Design RollerMouse Re:d]
MatchVendor=0x0B33
MatchProduct=0x1000
MatchUdevType=mouse
ModelBouncingKeys=1
[Contour Design RollerMouse Red v3]
MatchVendor=0x0B33
MatchProduct=0x1004
MatchUdevType=mouse
ModelBouncingKeys=1
[Contour Design RollerMouse Pro3]
MatchVendor=0x0B33
MatchProduct=0x0703
MatchUdevType=mouse
ModelBouncingKeys=1
libinput-1.28.1/quirks/30-vendor-cypress.quirks000066400000000000000000000004201477265155700214310ustar00rootroot00000000000000# Do not edit this file, it will be overwritten on update
[Cyapa Touchpads]
MatchName=*Cypress APA Trackpad ?cyapa?
AttrPressureRange=10:8
[Cypress Touchpads]
MatchUdevType=touchpad
MatchName=*CyPS/2 Cypress Trackpad
AttrPressureRange=10:8
AttrPalmPressureThreshold=254
libinput-1.28.1/quirks/30-vendor-elantech.quirks000066400000000000000000000003721477265155700215320ustar00rootroot00000000000000# Do not edit this file, it will be overwritten on update
[Elantech Touchpads]
MatchName=*Elantech Touchpad*
AttrResolutionHint=31x31
AttrPressureRange=10:8
[Elan Touchpads]
MatchName=*Elan Touchpad*
AttrResolutionHint=31x31
AttrPressureRange=10:8
libinput-1.28.1/quirks/30-vendor-glorious.quirks000066400000000000000000000001571477265155700216130ustar00rootroot00000000000000[Glorious Model O]
MatchUdevType=mouse
MatchBus=usb
MatchVendor=0x258A
MatchProduct=0x0036
ModelBouncingKeys=1
libinput-1.28.1/quirks/30-vendor-huion.quirks000066400000000000000000000003151477265155700210660ustar00rootroot00000000000000# Do not edit this file, it will be overwritten on update
# This will match several vendors that all
# re-use the same vendor ID 256C.
[Huion/Gaomon Tablets]
MatchVendor=0x256C
AttrResolutionHint=205x328
libinput-1.28.1/quirks/30-vendor-ibm.quirks000066400000000000000000000021131477265155700205110ustar00rootroot00000000000000# Do not edit this file, it will be overwritten on update
# IBM/Lenovo Scrollpoint mouse. Instead of a scroll wheel these mice
# feature trackpoint-like sticks which generate a huge amount of scroll
# events that need to be handled differently than scroll wheel events
[IBM ScrollPoint Mouse 3100]
MatchUdevType=mouse
MatchVendor=0x04B3
MatchProduct=0x3100
ModelLenovoScrollPoint=1
[IBM ScrollPoint Mouse 3103]
MatchUdevType=mouse
MatchVendor=0x04B3
MatchProduct=0x3103
ModelLenovoScrollPoint=1
[IBM ScrollPoint Mouse 3105]
MatchUdevType=mouse
MatchVendor=0x04B3
MatchProduct=0x3105
ModelLenovoScrollPoint=1
[IBM ScrollPoint Mouse 3108]
MatchUdevType=mouse
MatchVendor=0x04B3
MatchProduct=0x3108
ModelLenovoScrollPoint=1
[IBM ScrollPoint Mouse 3109]
MatchUdevType=mouse
MatchVendor=0x04B3
MatchProduct=0x3109
ModelLenovoScrollPoint=1
[IBM ScrollPoint Mouse 6049]
MatchUdevType=mouse
MatchVendor=0x17EF
MatchProduct=0x6049
ModelLenovoScrollPoint=1
[IBM USB Travel Keyboard with Ultra Nav Mouse]
MatchUdevType=pointingstick
MatchVendor=0x04B3
MatchProduct=0x301E
AttrTrackpointMultiplier=1.50
libinput-1.28.1/quirks/30-vendor-ite.quirks000066400000000000000000000003461477265155700205310ustar00rootroot00000000000000# Do not edit this file, it will be overwritten on update
# Tested on PCSpecialist Recoil 17
[ITE Device(8176) Keyboard]
MatchUdevType=keyboard
MatchBus=usb
MatchVendor=0x048D
MatchProduct=0x5000
AttrKeyboardIntegration=internal
libinput-1.28.1/quirks/30-vendor-kensington.quirks000066400000000000000000000002731477265155700221260ustar00rootroot00000000000000# Kensington Orbit claims to have a middle button, same for
[Kensington Orbit Scroll Wheel]
MatchBus=usb
MatchVendor=0x047D
MatchProduct=0x2048
ModelTrackball=1
AttrEventCode=-BTN_MIDDLE
libinput-1.28.1/quirks/30-vendor-logitech.quirks000066400000000000000000000047271477265155700215550ustar00rootroot00000000000000# Do not edit this file, it will be overwritten on update
[Logitech M570]
MatchName=*Logitech M570*
ModelTrackball=1
# This will also work for the newer 'S' version — Logitech ERGO M575S
[Logitech ERGO M575]
MatchName=*Logitech*M575*
ModelTrackball=1
# Logitech Marble Mouse claims to have a middle button
[Logitech Marble Mouse Trackball]
MatchUdevType=mouse
MatchBus=usb
MatchVendor=0x046D
MatchProduct=0xC408
AttrEventCode=-BTN_MIDDLE
[Logitech K400]
MatchUdevType=mouse
MatchBus=usb
MatchVendor=0x046D
MatchProduct=0x4024
ModelBouncingKeys=1
[Logitech K400r]
MatchUdevType=mouse
MatchBus=usb
MatchVendor=0x046D
MatchProduct=0x404B
ModelBouncingKeys=1
[Logitech K830]
MatchUdevType=mouse
MatchBus=usb
MatchVendor=0x046D
MatchProduct=0x404C
ModelBouncingKeys=1
[Logitech K400Plus]
MatchUdevType=mouse
MatchBus=usb
MatchVendor=0x046D
MatchProduct=0x404D
ModelBouncingKeys=1
[Logitech Wireless Touchpad]
MatchBus=usb
MatchVendor=0x046D
MatchProduct=0x4011
AttrPalmPressureThreshold=400
[Logitech MX Master (4041)]
MatchVendor=0x046D
MatchProduct=0x4041
ModelInvertHorizontalScrolling=1
[Logitech MX Master (4060)]
MatchVendor=0x046D
MatchProduct=0x4060
ModelInvertHorizontalScrolling=1
[Logitech MX Master (4071)]
MatchVendor=0x046D
MatchProduct=0x4071
ModelInvertHorizontalScrolling=1
# MX Master has a different PID on bluetooth
[Logitech MX Master (Bluetooth B012)]
MatchVendor=0x046D
MatchProduct=0xB012
ModelInvertHorizontalScrolling=1
[Logitech MX Master (Bluetooth B017)]
MatchVendor=0x046D
MatchProduct=0xB017
ModelInvertHorizontalScrolling=1
[Logitech MX Master (Bluetooth B01E)]
MatchVendor=0x046D
MatchProduct=0xB01E
ModelInvertHorizontalScrolling=1
[Logitech MX Master 2S USB]
MatchVendor=0x046D
MatchProduct=0x4069
ModelInvertHorizontalScrolling=1
# MX Master 2S has a different PID on bluetooth
[Logitech MX Master 2S Bluetooth]
MatchVendor=0x046D
MatchProduct=0xB019
ModelInvertHorizontalScrolling=1
[Logitech MX Master 3 USB]
MatchVendor=0x046D
MatchProduct=0x4082
ModelInvertHorizontalScrolling=1
# MX Master 3 has a different PID on bluetooth
[Logitech MX Master 3 Bluetooth]
MatchVendor=0x046D
MatchProduct=0xB023
ModelInvertHorizontalScrolling=1
[Logitech MX Master 3S]
MatchVendor=0x046D
MatchProduct=0xB034
ModelInvertHorizontalScrolling=1
[Logitech MX Master 3B]
MatchVendor=0x046D
MatchProduct=0xB028
ModelInvertHorizontalScrolling=1
# Don't add quirks for the Logitech Bolt Receiver:
# MatchVendor=0x046D
# MatchProduct=0xC548
# This receiver can be used with multiple mice.
libinput-1.28.1/quirks/30-vendor-madcatz.quirks000066400000000000000000000036401477265155700213730ustar00rootroot00000000000000# Do not edit this file, it will be overwritten on update
# The Madcatz RAT3 has a mode button that cycles through event codes.
# On press, we get a release for the current mode and a press for the
# next mode:
# -event21 DEVICE_ADDED Madcatz Mad Catz R.A.T.3 Mouse seat0 default group1 cap:p left scroll-nat scroll-button
# event21 POINTER_BUTTON +2.35s BTN_BACK (278) pressed, seat count: 1
# event21 POINTER_BUTTON +3.08s BTN_BACK (278) released, seat count: 0
# event21 POINTER_BUTTON +3.08s BTN_TASK (279) pressed, seat count: 1
# event21 POINTER_BUTTON +6.69s BTN_FORWARD (277) pressed, seat count: 1
# event21 POINTER_BUTTON +6.69s BTN_TASK (279) released, seat count: 0
# event21 POINTER_BUTTON +7.32s BTN_FORWARD (277) released, seat count: 0
# event21 POINTER_BUTTON +7.32s BTN_BACK (278) pressed, seat count: 1
# event21 POINTER_BUTTON +7.84s BTN_BACK (278) released, seat count: 0
# event21 POINTER_BUTTON +7.84s BTN_TASK (279) pressed, seat count: 1
#
# Disable the event codes to avoid stuck buttons.
[Madcatz RAT3]
MatchUdevType=mouse
MatchBus=usb
MatchVendor=0x0738
MatchProduct=0x1703
# EV_KEY 0x115, 0x116, 0x117
AttrEventCode=-EV_KEY:0x115;-EV_KEY:0x116;-EV_KEY:0x117
# Like the Madcatz RAT3, but with different codes:
# event8 POINTER_BUTTON +0.488s ??? (280) pressed, seat count: 1
# event8 POINTER_BUTTON +1.275s ??? (280) released, seat count: 0
# event8 POINTER_BUTTON +1.275s ??? (281) pressed, seat count: 1
# event8 POINTER_BUTTON +3.585s ??? (281) released, seat count: 0
# event8 POINTER_BUTTON +3.585s ??? (282) pressed, seat count: 1
# event8 POINTER_BUTTON +4.184s ??? (280) pressed, seat count: 1
# event8 POINTER_BUTTON +4.184s ??? (282) released, seat count: 0
[Madcatz RAT7]
MatchUdevType=mouse
MatchBus=usb
MatchVendor=0x0738
MatchProduct=0x1708
# EV_KEY 0x118, 0x119, 0x11A
AttrEventCode=-EV_KEY:0x118;-EV_KEY:0x119;-EV_KEY:0x11A
libinput-1.28.1/quirks/30-vendor-microsoft.quirks000066400000000000000000000022671477265155700217610ustar00rootroot00000000000000# Do not edit this file, it will be overwritten on update
[Microsoft Surface 3 Lid Switch]
MatchName=*Lid Switch*
MatchDMIModalias=dmi:*svnMicrosoftCorporation:pnSurface3:*
AttrLidSwitchReliability=write_open
# Matches both Surface Laptop keyboards as well as type covers.
# i.e.
# - Surface 3: Microsoft Surface 3 Type Cover Keyboard
# - Surface Laptop 3: Microsoft Surface 045E:09AE Keyboard
# - Surface Book 2: Microsoft Surface Keyboard
[Microsoft Surface Keyboard]
MatchName=*Microsoft Surface *Keyboard*
MatchDMIModalias=dmi:*svnMicrosoftCorporation:*
AttrKeyboardIntegration=internal
[Microsoft Surface Cover]
MatchName=*Microsoft Surface *Cover*
MatchDMIModalias=dmi:*svnMicrosoftCorporation:*
AttrKeyboardIntegration=internal
[Microsoft Surface Laptop Studio Touchpad]
MatchVendor=0x045E
MatchProduct=0x09AF
MatchUdevType=touchpad
AttrPressureRange=25:10
AttrPalmPressureThreshold=500
[Microsoft Surface Laptop Studio Built-In Peripherals]
MatchName=*Microsoft Surface*
MatchDMIModalias=dmi:*svnMicrosoftCorporation:*pnSurfaceLaptopStudio
ModelTabletModeNoSuspend=1
[Microsoft Nano Transceiver v2.0]
MatchUdevType=mouse
MatchBus=usb
MatchVendor=0x045E
MatchProduct=0x0800
ModelBouncingKeys=1
libinput-1.28.1/quirks/30-vendor-oracle.quirks000066400000000000000000000001341477265155700212100ustar00rootroot00000000000000[VirtualBox mouse integration]
MatchName=*VirtualBox mouse integration*
ModelBouncingKeys=1
libinput-1.28.1/quirks/30-vendor-qemu.quirks000066400000000000000000000001221477265155700207070ustar00rootroot00000000000000[QEMU/KVM mouse integration]
MatchName=*spice vdagent tablet*
ModelBouncingKeys=1
libinput-1.28.1/quirks/30-vendor-razer.quirks000066400000000000000000000141431477265155700210730ustar00rootroot00000000000000# Do not edit this file, it will be overwritten on update
[Razer Blade Lid Switch]
MatchName=*Lid Switch*
MatchDMIModalias=dmi:*svnRazer:pnBlade*
AttrLidSwitchReliability=write_open
# Manually added entries must go above this line.
# Entries below this line are autogenerated
# AUTOGENERATED
[RazerBladeStealth Keyboard]
MatchUdevType=keyboard
MatchBus=usb
MatchVendor=0x1532
MatchProduct=0x0205
AttrKeyboardIntegration=internal
[RazerBladeQHD Keyboard]
MatchUdevType=keyboard
MatchBus=usb
MatchVendor=0x1532
MatchProduct=0x020F
AttrKeyboardIntegration=internal
[RazerBladeProLate2016 Keyboard]
MatchUdevType=keyboard
MatchBus=usb
MatchVendor=0x1532
MatchProduct=0x0210
AttrKeyboardIntegration=internal
[RazerBladeStealthLate2016 Keyboard]
MatchUdevType=keyboard
MatchBus=usb
MatchVendor=0x1532
MatchProduct=0x0220
AttrKeyboardIntegration=internal
[RazerBladeLate2016 Keyboard]
MatchUdevType=keyboard
MatchBus=usb
MatchVendor=0x1532
MatchProduct=0x0224
AttrKeyboardIntegration=internal
[RazerBladePro2017 Keyboard]
MatchUdevType=keyboard
MatchBus=usb
MatchVendor=0x1532
MatchProduct=0x0225
AttrKeyboardIntegration=internal
[RazerBladeStealthMid2017 Keyboard]
MatchUdevType=keyboard
MatchBus=usb
MatchVendor=0x1532
MatchProduct=0x022D
AttrKeyboardIntegration=internal
[RazerBladePro2017FullHD Keyboard]
MatchUdevType=keyboard
MatchBus=usb
MatchVendor=0x1532
MatchProduct=0x022F
AttrKeyboardIntegration=internal
[RazerBladeStealthLate2017 Keyboard]
MatchUdevType=keyboard
MatchBus=usb
MatchVendor=0x1532
MatchProduct=0x0232
AttrKeyboardIntegration=internal
[RazerBlade2018 Keyboard]
MatchUdevType=keyboard
MatchBus=usb
MatchVendor=0x1532
MatchProduct=0x0233
AttrKeyboardIntegration=internal
[RazerBladePro2019 Keyboard]
MatchUdevType=keyboard
MatchBus=usb
MatchVendor=0x1532
MatchProduct=0x0234
AttrKeyboardIntegration=internal
[RazerBladeStealth2019 Keyboard]
MatchUdevType=keyboard
MatchBus=usb
MatchVendor=0x1532
MatchProduct=0x0239
AttrKeyboardIntegration=internal
[RazerBlade2019Adv Keyboard]
MatchUdevType=keyboard
MatchBus=usb
MatchVendor=0x1532
MatchProduct=0x023A
AttrKeyboardIntegration=internal
[RazerBlade2018Base Keyboard]
MatchUdevType=keyboard
MatchBus=usb
MatchVendor=0x1532
MatchProduct=0x023B
AttrKeyboardIntegration=internal
[RazerBlade2018Mercury Keyboard]
MatchUdevType=keyboard
MatchBus=usb
MatchVendor=0x1532
MatchProduct=0x0240
AttrKeyboardIntegration=internal
[RazerBladeMid2019Mercury Keyboard]
MatchUdevType=keyboard
MatchBus=usb
MatchVendor=0x1532
MatchProduct=0x0245
AttrKeyboardIntegration=internal
[RazerBlade2019Base Keyboard]
MatchUdevType=keyboard
MatchBus=usb
MatchVendor=0x1532
MatchProduct=0x0246
AttrKeyboardIntegration=internal
[RazerBladeStealthLate2019 Keyboard]
MatchUdevType=keyboard
MatchBus=usb
MatchVendor=0x1532
MatchProduct=0x024A
AttrKeyboardIntegration=internal
[RazerBladeAdvancedLate2019 Keyboard]
MatchUdevType=keyboard
MatchBus=usb
MatchVendor=0x1532
MatchProduct=0x024B
AttrKeyboardIntegration=internal
[RazerBladeProLate2019 Keyboard]
MatchUdevType=keyboard
MatchBus=usb
MatchVendor=0x1532
MatchProduct=0x024C
AttrKeyboardIntegration=internal
[RazerBlade2019StudioEdition Keyboard]
MatchUdevType=keyboard
MatchBus=usb
MatchVendor=0x1532
MatchProduct=0x024D
AttrKeyboardIntegration=internal
[RazerBladeStealthEarly2020 Keyboard]
MatchUdevType=keyboard
MatchBus=usb
MatchVendor=0x1532
MatchProduct=0x0252
AttrKeyboardIntegration=internal
[RazerBlade15Advanced2020 Keyboard]
MatchUdevType=keyboard
MatchBus=usb
MatchVendor=0x1532
MatchProduct=0x0253
AttrKeyboardIntegration=internal
[RazerBladeEarly2020Base Keyboard]
MatchUdevType=keyboard
MatchBus=usb
MatchVendor=0x1532
MatchProduct=0x0255
AttrKeyboardIntegration=internal
[RazerBladeProEarly2020 Keyboard]
MatchUdevType=keyboard
MatchBus=usb
MatchVendor=0x1532
MatchProduct=0x0256
AttrKeyboardIntegration=internal
[RazerBladeStealthLate2020 Keyboard]
MatchUdevType=keyboard
MatchBus=usb
MatchVendor=0x1532
MatchProduct=0x0259
AttrKeyboardIntegration=internal
[RazerBlade15AdvancedEarly2021 Keyboard]
MatchUdevType=keyboard
MatchBus=usb
MatchVendor=0x1532
MatchProduct=0x026D
AttrKeyboardIntegration=internal
[RazerBlade17ProEarly2021 Keyboard]
MatchUdevType=keyboard
MatchBus=usb
MatchVendor=0x1532
MatchProduct=0x026E
AttrKeyboardIntegration=internal
[RazerBladeEarly2021Base Keyboard]
MatchUdevType=keyboard
MatchBus=usb
MatchVendor=0x1532
MatchProduct=0x026F
AttrKeyboardIntegration=internal
[RazerBlade142021 Keyboard]
MatchUdevType=keyboard
MatchBus=usb
MatchVendor=0x1532
MatchProduct=0x0270
AttrKeyboardIntegration=internal
[RazerBlade15Advanced2021 Keyboard]
MatchUdevType=keyboard
MatchBus=usb
MatchVendor=0x1532
MatchProduct=0x0276
AttrKeyboardIntegration=internal
[RazerBlade17Pro2021 Keyboard]
MatchUdevType=keyboard
MatchBus=usb
MatchVendor=0x1532
MatchProduct=0x0279
AttrKeyboardIntegration=internal
[RazerBladeEarly2022Base Keyboard]
MatchUdevType=keyboard
MatchBus=usb
MatchVendor=0x1532
MatchProduct=0x027A
AttrKeyboardIntegration=internal
[RazerBlade15AdvancedEarly2022 Keyboard]
MatchUdevType=keyboard
MatchBus=usb
MatchVendor=0x1532
MatchProduct=0x028A
AttrKeyboardIntegration=internal
[RazerBlade172022 Keyboard]
MatchUdevType=keyboard
MatchBus=usb
MatchVendor=0x1532
MatchProduct=0x028B
AttrKeyboardIntegration=internal
[RazerBlade142022 Keyboard]
MatchUdevType=keyboard
MatchBus=usb
MatchVendor=0x1532
MatchProduct=0x028C
AttrKeyboardIntegration=internal
[RazerBlade142023 Keyboard]
MatchUdevType=keyboard
MatchBus=usb
MatchVendor=0x1532
MatchProduct=0x029D
AttrKeyboardIntegration=internal
[RazerBlade152023 Keyboard]
MatchUdevType=keyboard
MatchBus=usb
MatchVendor=0x1532
MatchProduct=0x029E
AttrKeyboardIntegration=internal
[RazerBlade162023 Keyboard]
MatchUdevType=keyboard
MatchBus=usb
MatchVendor=0x1532
MatchProduct=0x029F
AttrKeyboardIntegration=internal
[RazerBlade182023 Keyboard]
MatchUdevType=keyboard
MatchBus=usb
MatchVendor=0x1532
MatchProduct=0x02A0
AttrKeyboardIntegration=internal
[RazerBlade142024 Keyboard]
MatchUdevType=keyboard
MatchBus=usb
MatchVendor=0x1532
MatchProduct=0x02B6
AttrKeyboardIntegration=internal
[RazerBlade182024 Keyboard]
MatchUdevType=keyboard
MatchBus=usb
MatchVendor=0x1532
MatchProduct=0x02B8
AttrKeyboardIntegration=internal
libinput-1.28.1/quirks/30-vendor-synaptics.quirks000066400000000000000000000007761477265155700217740ustar00rootroot00000000000000# Do not edit this file, it will be overwritten on update
[Synaptics Serial Touchpads]
MatchUdevType=touchpad
MatchBus=ps2
MatchVendor=0x0002
MatchProduct=0x0007
ModelSynapticsSerialTouchpad=1
# SYNA3602:00 0911:5288 touchpad, clickpad pretending it has a right button.
# Integrated into several systems, including
# Purism Librem 14v1
# Prestigio Smartbook 141 C2
# StarLite Mk II
# Iota IOTA2320
[Synaptics 0911:5288 Touchpad]
MatchUdevType=touchpad
MatchName=* 0911:5288 Touchpad
AttrEventCode=-BTN_RIGHT
libinput-1.28.1/quirks/30-vendor-trust.quirks000066400000000000000000000001701477265155700211240ustar00rootroot00000000000000[Trust GXT 25 Gaming Mouse]
MatchUdevType=mouse
MatchBus=usb
MatchVendor=0x1D57
MatchProduct=0xAD03
ModelBouncingKeys=1
libinput-1.28.1/quirks/30-vendor-uniwill.quirks000066400000000000000000000003251477265155700214300ustar00rootroot00000000000000# Do not edit this file, it will be overwritten on update
# Tested on PCSpecialist Recoil 17
[Uniwill Touchpad]
MatchUdevType=touchpad
MatchBus=i2c
MatchVendor=0x093A
MatchProduct=0x0274
AttrEventCode=-BTN_RIGHT
libinput-1.28.1/quirks/30-vendor-vmware.quirks000066400000000000000000000003651477265155700212520ustar00rootroot00000000000000# Do not edit this file, it will be overwritten on update
[VMWare Virtual PS/2 Mouse]
MatchName=*VirtualPS/2 VMware VMMouse*
ModelBouncingKeys=1
[VMware VMware Virtual USB Mouse]
MatchName=*VMware VMware Virtual USB Mouse*
ModelBouncingKeys=1
libinput-1.28.1/quirks/30-vendor-wacom.quirks000066400000000000000000000014511477265155700210540ustar00rootroot00000000000000# Do not edit this file, it will be overwritten on update
[Wacom Touchpads]
MatchUdevType=touchpad
MatchBus=usb
MatchVendor=0x056A
ModelWacomTouchpad=1
[Wacom Bamboo Fun Pen]
MatchUdevType=tablet
MatchBus=usb
MatchVendor=0x056A
MatchProduct=0x0018
AttrEventCode=-ABS_DISTANCE
[Wacom Bamboo 2FG 6x8]
MatchUdevType=touchpad
MatchBus=usb
MatchVendor=0x056A
MatchProduct=0x00D3
AttrInputProp=+INPUT_PROP_SEMI_MT
[Wacom Intuos Pro PTH660]
MatchUdevType=touchpad
MatchBus=usb
MatchVendor=0x056A
MatchProduct=0x0357
AttrPalmSizeThreshold=5
[Wacom ISDV4 4200 Pen]
MatchUdevType=tablet
MatchBus=usb
MatchVendor=0x056A
MatchProduct=0x4200
AttrEventCode=-ABS_TILT_X;-ABS_TILT_Y;
[Wacom ISDV4 524c Pen]
MatchUdevType=tablet
MatchBus=usb
MatchVendor=0x2D1F
MatchProduct=0x524C
AttrEventCode=-ABS_TILT_X;-ABS_TILT_Y;
libinput-1.28.1/quirks/50-system-acer.quirks000066400000000000000000000004121477265155700207050ustar00rootroot00000000000000[Acer Switch Alpha 12]
MatchName=AT Translated Set 2 keyboard
MatchDMIModalias=dmi:*svnAcer:pnSwitchSA5-271:*
ModelTabletModeNoSuspend=1
[Acer Spin 5]
MatchName=AT Translated Set 2 keyboard
MatchDMIModalias=dmi:*svnAcer:pnSpinSP513-52N:*
ModelTabletModeNoSuspend=1
libinput-1.28.1/quirks/50-system-apple.quirks000066400000000000000000000071651477265155700211100ustar00rootroot00000000000000# Do not edit this file, it will be overwritten on update
[Apple Touchpads USB]
MatchVendor=0x05AC
MatchBus=usb
MatchUdevType=touchpad
ModelAppleTouchpad=1
AttrSizeHint=104x75
AttrTouchSizeRange=150:130
AttrPalmSizeThreshold=1600
[Apple Touchpads Bluetooth]
MatchVendor=0x05AC
MatchBus=bluetooth
MatchUdevType=touchpad
ModelAppleTouchpad=1
AttrTouchSizeRange=150:130
[Apple Touchpads Bluetooth (new vendor ID)]
MatchVendor=0x004C
MatchBus=bluetooth
MatchUdevType=touchpad
ModelAppleTouchpad=1
AttrTouchSizeRange=150:130
[Apple Internal Keyboard]
MatchName=*Apple Inc. Apple Internal Keyboard*
AttrKeyboardIntegration=internal
[Apple Internal Keyboard (SPI)]
MatchUdevType=keyboard
MatchBus=spi
MatchVendor=0x05AC
AttrKeyboardIntegration=internal
# The Apple MagicMouse has a touchpad built-in but the kernel still
# emulates a full 2/3 button mouse for us. Ignore anything from the
# ABS interface
[Apple MagicMouse]
MatchUdevType=mouse
MatchBus=bluetooth
MatchVendor=0x05AC
MatchProduct=0x030D
AttrEventCode=-EV_ABS
# The External Apple "Magic" trackpads, both the 1st and 2nd generations, have
# pretty good built-in spurious touch filtering in the device firmware. Using
# low enough values such as 20:10 effectively disables libinput's filtering.
[Apple Magic Trackpad v1 (2010, clickpad)]
MatchUdevType=touchpad
MatchBus=bluetooth
MatchVendor=0x05AC
MatchProduct=0x030E
AttrSizeHint=130x110
AttrTouchSizeRange=20:10
AttrPalmSizeThreshold=900
AttrThumbSizeThreshold=700
# 2nd generation trackpad can be connected over Bluetooth as well as USB.
[Apple Magic Trackpad v2 (2015)]
MatchVendor=0x05AC
MatchProduct=0x0265
AttrSizeHint=162x115
AttrTouchSizeRange=20:10
AttrPalmSizeThreshold=900
AttrThumbSizeThreshold=800
AttrPalmPressureThreshold=190
[Apple Magic Trackpad v2 (new vendor ID)]
MatchVendor=0x004C
MatchProduct=0x0265
AttrSizeHint=162x115
AttrTouchSizeRange=20:10
AttrPalmSizeThreshold=900
AttrThumbSizeThreshold=800
AttrPalmPressureThreshold=190
[Apple Magic Trackpad v2 Bluetooth (2024)]
MatchVendor=0x004C
MatchProduct=0x0324
AttrSizeHint=162x115
AttrTouchSizeRange=20:10
AttrPressureRange=3:0
AttrPalmSizeThreshold=900
AttrThumbSizeThreshold=700
[Apple Magic Trackpad v2 USB-C (2024)]
MatchBus=usb
MatchVendor=0x05AC
MatchProduct=0x0324
AttrTouchSizeRange=20:10
AttrPressureRange=3:0
AttrPalmSizeThreshold=900
AttrThumbSizeThreshold=700
[Apple Touchpad OneButton]
MatchUdevType=touchpad
MatchBus=usb
MatchVendor=0x05AC
MatchProduct=0x021A
ModelAppleTouchpadOneButton=1
[Apple Touchpad OneButton A1181]
MatchUdevType=touchpad
MatchBus=usb
MatchVendor=0x05AC
MatchProduct=0x022A
ModelAppleTouchpadOneButton=1
[Apple Touchpad MacbookPro5,5]
MatchUdevType=touchpad
MatchBus=usb
MatchVendor=0x05AC
MatchProduct=0x0237
AttrPalmSizeThreshold=1000
[Apple Laptop Touchpad (MacBookPro11,2 among others)]
MatchUdevType=touchpad
MatchBus=usb
MatchVendor=0x05AC
MatchProduct=0x0262
AttrPalmSizeThreshold=1600
[Apple Laptop Touchpad (SPI)]
MatchUdevType=touchpad
MatchBus=spi
MatchVendor=0x05AC
ModelAppleTouchpad=1
AttrSizeHint=104x75
AttrTouchSizeRange=150:130
AttrPalmSizeThreshold=1600
[Apple Laptop Touchpad (MTP)]
MatchUdevType=touchpad
MatchName=Apple*MTP*
MatchVendor=0x05AC
ModelAppleTouchpad=1
AttrSizeHint=104x75
AttrTouchSizeRange=150:130
AttrPalmSizeThreshold=1600
[Apple Laptop Keyboard (MTP)]
MatchUdevType=keyboard
MatchName=Apple*MTP*
MatchVendor=0x05AC
AttrKeyboardIntegration=internal
# The Linux applespi driver currently uses the Synaptics vendor for some reason
[Apple Laptop Touchpad (SPI) applespi driver]
MatchUdevType=touchpad
MatchBus=spi
MatchVendor=0x06CB
ModelAppleTouchpad=1
AttrSizeHint=104x75
AttrTouchSizeRange=150:130
AttrPalmSizeThreshold=1600
libinput-1.28.1/quirks/50-system-asus.quirks000066400000000000000000000027771477265155700207660ustar00rootroot00000000000000# Do not edit this file, it will be overwritten on update
[Asus X555LAB]
MatchName=*ETPS/2 Elantech Touchpad*
MatchDMIModalias=dmi:*svnASUSTeKCOMPUTERINC.:pnX555LAB:*
ModelTouchpadVisibleMarker=1
[Asus UX21E]
MatchName=*ETPS/2 Elantech Touchpad*
MatchDMIModalias=dmi:*svnASUSTeKComputerInc.:pnUX21E:*
AttrPressureRange=24:10
# Asus UX302LA touchpad doesn't update the pressure values once two
# fingers are down. So let's just pretend it doesn't have pressure
# at all. https://gitlab.freedesktop.org/libinput/libinput/issues/145
[Asus UX302LA]
MatchName=*ETPS/2 Elantech Touchpad*
MatchDMIModalias=dmi:*svnASUSTeKCOMPUTERINC.:pnUX302LA:*
AttrEventCode=-ABS_MT_PRESSURE;-ABS_PRESSURE;
# Asus VivoBook Flip 14 TP412UA tablet switch seems misbehaving, always
# indicating tablet position
[Asus TP412UA Tablet Mode Switch]
MatchName=*Intel Virtual Button*
MatchDMIModalias=dmi:*svnASUSTeKCOMPUTERINC.:pnVivoBookFlip14_ASUSFlipTP412UA:*
ModelTabletModeSwitchUnreliable=1
# keyboard has a different vid/pid to the touchpad
# so libinput won't pair the two together and dwt isn't active.
# see: https://gitlab.freedesktop.org/libinput/libinput/-/issues/615
[Asus ROG Zephyrus G15 2021 keyboard]
MatchVendor=0x0B05
MatchProduct=0x19B6
MatchUdevType=keyboard
AttrKeyboardIntegration=internal
# keyboard has a different vid/pid to the touchpad
# so libinput won't pair the two together and dwt isn't active.
[Asus ROG Strix G15 2021 keyboard]
MatchVendor=0x0B05
MatchProduct=0x1866
MatchUdevType=keyboard
AttrKeyboardIntegration=internal
libinput-1.28.1/quirks/50-system-chicony.quirks000066400000000000000000000006511477265155700214340ustar00rootroot00000000000000# Do not edit this file, it will be overwritten on update
# Acer Hawaii Keyboard, uses Chicony VID
[Acer Hawaii Keyboard]
MatchUdevType=touchpad
MatchBus=usb
MatchVendor=0x04F2
MatchProduct=0x1558
AttrTPKComboLayout=below
# Lenovo MIIX 720 comes with a detachable touchpad-keyboard combo
[Chicony Lenovo MIIX 720 Touchpad]
MatchUdevType=touchpad
MatchBus=usb
MatchVendor=0x17EF
MatchProduct=0x60A6
AttrTPKComboLayout=below
libinput-1.28.1/quirks/50-system-chuwi.quirks000066400000000000000000000003321477265155700211130ustar00rootroot00000000000000[Chuwi Gemibook]
MatchName=HTIX5288:00 093A:1336 Touchpad
MatchUdevType=touchpad
AttrEventCode=-BTN_RIGHT
[Chuwi AeroBook Plus]
MatchName=SYNA3602:01 093A:1336 Touchpad
MatchUdevType=touchpad
AttrEventCode=-BTN_RIGHT
libinput-1.28.1/quirks/50-system-cyborg.quirks000066400000000000000000000027621477265155700212720ustar00rootroot00000000000000# Do not edit this file, it will be overwritten on update
# The Cyborg RAT has a mode button that cycles through event codes.
# On press, we get a release for the current mode and a press for the
# next mode:
# E: 0.000001 0004 0004 589833 # EV_MSC / MSC_SCAN 589833
# E: 0.000001 0001 0118 0000 # EV_KEY / (null) 0
# E: 0.000001 0004 0004 589834 # EV_MSC / MSC_SCAN 589834
# E: 0.000001 0001 0119 0001 # EV_KEY / (null) 1
# E: 0.000001 0000 0000 0000 # ------------ SYN_REPORT (0) ---------- +0ms
# E: 0.705000 0004 0004 589834 # EV_MSC / MSC_SCAN 589834
# E: 0.705000 0001 0119 0000 # EV_KEY / (null) 0
# E: 0.705000 0004 0004 589835 # EV_MSC / MSC_SCAN 589835
# E: 0.705000 0001 011a 0001 # EV_KEY / (null) 1
# E: 0.705000 0000 0000 0000 # ------------ SYN_REPORT (0) ---------- +705ms
# E: 1.496995 0004 0004 589833 # EV_MSC / MSC_SCAN 589833
# E: 1.496995 0001 0118 0001 # EV_KEY / (null) 1
# E: 1.496995 0004 0004 589835 # EV_MSC / MSC_SCAN 589835
# E: 1.496995 0001 011a 0000 # EV_KEY / (null) 0
# E: 1.496995 0000 0000 0000 # ------------ SYN_REPORT (0) ---------- +791ms
#
# https://bugs.freedesktop.org/show_bug.cgi?id=92127
#
# Disable the event codes to avoid stuck buttons.
[Saitek Cyborg RAT5]
MatchUdevType=mouse
MatchBus=usb
MatchVendor=0x06A3
MatchProduct=0x0CD5
# EV_KEY 0x118, 0x119, 0x11a
AttrEventCode=-EV_KEY:0x118;-EV_KEY:0x119;-EV_KEY:0x11a
libinput-1.28.1/quirks/50-system-dell.quirks000066400000000000000000000100271477265155700207160ustar00rootroot00000000000000# Do not edit this file, it will be overwritten on update
[Dell Touchpads]
MatchName=* Touchpad
MatchDMIModalias=dmi:*svnDellInc.:*
ModelTouchpadVisibleMarker=1
[Dell i2c Touchpads]
MatchBus=i2c
MatchUdevType=touchpad
MatchDMIModalias=dmi:*svnDellInc.:*
AttrMscTimestamp=watch
[Dell Inspiron 15R N5110 Touchpad]
MatchUdevType=touchpad
MatchName=*AlpsPS/2 ALPS GlidePoint
MatchVersion=0x0300
MatchDMIModalias=dmi:*svnDellInc.:*pnInspironN5110*
AttrPressureRange=100:95
[Dell Latitude E5510 Touchpad]
MatchUdevType=touchpad
MatchName=*AlpsPS/2 ALPS GlidePoint
MatchDMIModalias=dmi:*svnDellInc.:pnLatitudeE5510:*
AttrPressureRange=100:90
[Dell Latitude E6220 Touchpad]
MatchName=*AlpsPS/2 ALPS GlidePoint
MatchDMIModalias=dmi:*svnDellInc.:pnLatitudeE6220:*
AttrPressureRange=100:90
[Dell XPS L322X Touchpad]
MatchName=*CyPS/2 Cypress Trackpad
MatchDMIModalias=dmi:*svnDell*:*XPSL322X*
AttrPressureRange=30:20
AttrPalmPressureThreshold=254
[Dell XPS13 9333 Touchpad]
MatchName=*Synaptics s3203
MatchDMIModalias=dmi:*svnDellInc.:*pnXPS139333*
AttrPressureRange=15:10
AttrPalmPressureThreshold=150
[Dell XPS 15 9500 Touchpad]
MatchName=* Touchpad
MatchDMIModalias=dmi:*svnDellInc.:pnXPS159500:*
ModelTouchpadVisibleMarker=0
ModelTouchpadPhantomClicks=1
[Dell Latitude D620 Trackpoint]
MatchName=*DualPoint Stick
MatchDMIModalias=dmi:*svnDellInc.:pnLatitudeD620*
AttrTrackpointMultiplier=0.5
[Latitude E5480 Trackpoint]
MatchName=*DualPoint Stick
MatchUdevType=pointingstick
MatchDMIModalias=dmi:**bvnDellInc.:*:pnLatitude5480*
AttrTrackpointMultiplier=0.5
[Latitude 5580 Trackpoint]
MatchName=*DualPoint Stick
MatchUdevType=pointingstick
MatchDMIModalias=dmi:**bvnDellInc.:*:pnLatitude5580*
AttrTrackpointMultiplier=0.5
[Latitude E5570 Trackpoint]
MatchName=*DualPoint Stick
MatchDMIModalias=dmi:*svnDellInc.:pnLatitudeE5570*
AttrTrackpointMultiplier=0.1
[Latitude E6320 Trackpoint]
MatchName=*DualPoint Stick
MatchDMIModalias=dmi:*svnDellInc.:pnLatitudeE6320*
AttrTrackpointMultiplier=2.0
[Latitude E6400 Trackpoint]
MatchName=*DualPoint Stick
MatchDMIModalias=dmi:*svnDellInc.:pnLatitudeE6400*
AttrTrackpointMultiplier=1.5
[Latitude E7470 Trackpoint]
MatchName=*DualPoint Stick
MatchDMIModalias=dmi:*svnDellInc.:pnLatitudeE7470*
AttrTrackpointMultiplier=0.125
[Latitude 7275]
MatchName=*AT Translated Set 2 keyboard*
MatchDMIModalias=dmi:*:svnDellInc.:pnLatitude7275:*
ModelTabletModeNoSuspend=1
[Latitude 7480 Touchpad]
MatchName=DLL07A0*
MatchDMIModalias=dmi:**bvnDellInc.:*:pnLatitude7480*
AttrPressureRange=35:34
[Latitude 7490 Trackpoint]
MatchName=*Mouse
MatchUdevType=pointingstick
MatchDMIModalias=dmi:**bvnDellInc.:*:pnLatitude7490*
AttrTrackpointMultiplier=0.3
[Precision 7x50 Touchpad]
MatchBus=i2c
MatchUdevType=touchpad
MatchDMIModalias=dmi:*svnDellInc.:pnPrecision7?50*
AttrInputProp=-INPUT_PROP_BUTTONPAD
# The touch device has the same vid/pid as the totem, the MatchName
# directive is required here
[Canvas Totem]
MatchName=*System Multi Axis
MatchBus=usb
MatchVendor=0x2575
MatchProduct=0x0204
ModelDellCanvasTotem=1
[Dell 2-in-1 Models]
MatchName=AT Translated Set 2 keyboard
MatchDMIModalias=dmi:*:svnDellInc.:pn*2-in-1:*
ModelTabletModeNoSuspend=1
# This is a true pressurepad so disable pressure for contact size
# https://gitlab.freedesktop.org/libinput/libinput/-/issues/849
[Dell Precision5680 Touchpad]
MatchBus=i2c
MatchVendor=0x27C6
MatchProduct=0x0F60
ModelPressurePad=1
[Dell Mayabay Touchpad]
MatchBus=i2c
MatchVendor=0x06CB
MatchProduct=0xCFA0
ModelPressurePad=1
[Dell Precision 5480]
MatchBus=i2c
MatchVendor=0x0488
MatchProduct=0x1063
MatchUdevType=touchpad
MatchDMIModalias=dmi:*svnDellInc.:pnPrecision5480*
ModelTouchpadVisibleMarker=0
[Dell laptop 14 Synaptics touchpad]
MatchBus=i2c
MatchVendor=0x06CB
MatchProduct=0xCFF8
ModelPressurePad=1
[Dell laptop 16 Synaptics touchpad]
MatchBus=i2c
MatchVendor=0x06CB
MatchProduct=0xCFF9
ModelPressurePad=1
[Dell laptop 14 Goodix touchpad]
MatchBus=i2c
MatchVendor=0x27C6
MatchProduct=0x0F61
ModelPressurePad=1
[Dell laptop 16 Goodix touchpad]
MatchBus=i2c
MatchVendor=0x27C6
MatchProduct=0x0F62
ModelPressurePad=1
libinput-1.28.1/quirks/50-system-framework.quirks000066400000000000000000000005371477265155700220000ustar00rootroot00000000000000[Framework Laptop Touchpad]
MatchName=PIXA3854:00 093A:0274 Touchpad
MatchUdevType=touchpad
MatchDMIModalias=dmi:*svnFramework:pnLaptop*
AttrEventCode=-BTN_RIGHT
[Framework Laptop 16 Keyboard Module]
MatchName=Framework Laptop 16 Keyboard Module*
MatchUdevType=keyboard
MatchDMIModalias=dmi:*svnFramework:pnLaptop16*
AttrKeyboardIntegration=internal
libinput-1.28.1/quirks/50-system-gigabyte.quirks000066400000000000000000000002371477265155700215730ustar00rootroot00000000000000[Gigabyte Aero 15 touchpad]
MatchUdevType=touchpad
MatchName=ETPS/2 Elantech Touchpad
MatchDMIModalias=dmi:*svnGIGABYTE:pnAERO15-XA*
AttrPalmSizeThreshold=800
libinput-1.28.1/quirks/50-system-google.quirks000066400000000000000000000101761477265155700212570ustar00rootroot00000000000000# Do not edit this file, it will be overwritten on update
[Generic Google ARM device with Touchpad]
MatchName=*Elan Touchpad*
MatchDeviceTree=*google*
ModelChromebook=1
[Google Chromebook R13 CB5-312T]
MatchName=*Elan Touchpad*
MatchDeviceTree=*Chromebook R13 CB5-312T*
AttrPressureRange=6:4
[Google Chromebook CB5-312T]
MatchName=*Elan Touchpad*
MatchDeviceTree=*CB5-312T*
AttrPressureRange=6:4
[Google Chromebook Elm]
MatchName=*Elan Touchpad*
MatchDeviceTree=*Elm*
AttrPressureRange=6:4
[Google Chromebook Falco]
MatchUdevType=touchpad
MatchName=Cypress APA Trackpad ?cyapa?
MatchDMIModalias=dmi:*pn*Falco*
ModelChromebook=1
[Google Chromebook Mario]
MatchUdevType=touchpad
MatchName=SynPS/2 Synaptics TouchPad
MatchDMIModalias=dmi:*pn*Mario*
ModelChromebook=1
[Google Chromebook Butterfly]
MatchUdevType=touchpad
MatchName=Cypress APA Trackpad ?cyapa?
MatchDMIModalias=dmi:*pn*Butterfly*
ModelChromebook=1
[Google Chromebook Peppy]
MatchUdevType=touchpad
MatchName=Cypress APA Trackpad ?cyapa?
MatchDMIModalias=dmi:*pn*Peppy*
ModelChromebook=1
[Google Chromebook ZGB]
MatchUdevType=touchpad
MatchName=SynPS/2 Synaptics TouchPad
MatchDMIModalias=dmi:*pn*ZGB*
ModelChromebook=1
[Google Chromebook Parrot]
MatchUdevType=touchpad
MatchName=Cypress APA Trackpad ?cyapa?
MatchDMIModalias=dmi:*pn*Parrot*
ModelChromebook=1
[Google Chromebook Leon]
MatchUdevType=touchpad
MatchName=Cypress APA Trackpad ?cyapa?
MatchDMIModalias=dmi:*bvn*coreboot*:pn*Leon*
ModelChromebook=1
[Google Chromebook Wolf]
MatchUdevType=touchpad
MatchName=Cypress APA Trackpad ?cyapa?
MatchDMIModalias=dmi:*bvn*coreboot*:pn*Wolf*
ModelChromebook=1
[Google Chromebook Link]
MatchUdevType=touchpad
MatchName=Cypress APA Trackpad ?cyapa?
MatchDMIModalias=dmi:*svn*GOOGLE*:pn*Link*
ModelChromebook=1
[Google Chromebook Alex]
MatchUdevType=touchpad
MatchName=SynPS/2 Synaptics TouchPad
MatchDMIModalias=dmi:*pn*Alex*
ModelChromebook=1
[Google Chromebook Lumpy]
MatchUdevType=touchpad
MatchName=Cypress APA Trackpad ?cyapa?
MatchDMIModalias=dmi:*svn*SAMSUNG*:pn*Lumpy*
ModelChromebook=1
[Google Chromebook Samus]
MatchUdevType=touchpad
MatchName=Atmel maXTouch Touchpad
MatchDMIModalias=dmi:*svn*GOOGLE*:pn*Samus*
ModelChromebook=1
[Google Chromebook Eve]
MatchUdevType=touchpad
MatchName=ACPI0C50:00 18D1:5028*
MatchDMIModalias=dmi:*svnGoogle:pnEve*
ModelChromebook=1
AttrPressureRange=6:4
AttrThumbPressureThreshold=45
[Google Chromebook Atlas]
MatchUdevType=touchpad
MatchName=ACPI0C50:01 04F3:30C5 Touchpad
MatchDMIModalias=dmi:*svnGoogle:*pnAtlas*
ModelChromebook=1
AttrPressureRange=6:4
[Google Chromebook Lazor Keyboard]
MatchName=*cros_ec*
MatchDeviceTree=*lazor*
AttrKeyboardIntegration=internal
[Google Chromebook Redrix]
MatchUdevType=touchpad
MatchName=ELAN2703:00 04F3:323B Touchpad
MatchDMIModalias=dmi:*pn*Redrix*
ModelChromebook=1
AttrPressureRange=-0:-2
AttrThumbPressureThreshold=45
AttrPalmPressureThreshold=0
[Google Chromebook Drobit]
MatchUdevType=touchpad
MatchName=ELAN2701:00 04F3:31C6 Touchpad
MatchDMIModalias=dmi:*svnGoogle:*pnDrobit*
ModelChromebook=1
AttrPressureRange=6:4
[HP Dragonfly Pro Chromebook]
MatchName=*ELAN2703*
MatchDMIModalias=dmi:*pn*Vell*
ModelChromebook=1
AttrPressureRange=1:0
AttrThumbPressureThreshold=25
AttrPalmPressureThreshold=0
[Google Chromebook Krane]
MatchUdevType=touchpad
MatchName=Google Inc. Hammer
MatchBus=usb
MatchVendor=0x18D1
MatchDeviceTree=*krane*
ModelChromebook=1
AttrPressureRange=20:10
[Google Chromebook Wormdingler]
MatchUdevType=touchpad
MatchName=Google Inc. Hammer
MatchBus=usb
MatchVendor=0x18D1
MatchDeviceTree=*wormdingler*
ModelChromebook=1
AttrPressureRange=20:10
[Google Chromebook Coachz]
MatchUdevType=touchpad
MatchName=Google Inc. Hammer
MatchBus=usb
MatchVendor=0x18D1
MatchDeviceTree=*coachz*
ModelChromebook=1
AttrPressureRange=20:10
[Google Chromebook Cret]
MatchUdevType=touchpad
MatchName=GDIX0000:00 27C6:0D55 Touchpad
MatchDMIModalias=dmi:*svnGoogle:*pnCret*
ModelChromebook=1
AttrPressureRange=6:4
[Google Chromebook Banshee]
MatchUdevType=touchpad
MatchName=PNP0C50:00 093A:0274 Touchpad
MatchDMIModalias=dmi:*svnGoogle:*pnBanshee*
ModelChromebook=1
AttrPressureRange=0:-2
AttrThumbPressureThreshold=45
AttrPalmPressureThreshold=0
libinput-1.28.1/quirks/50-system-gpd.quirks000066400000000000000000000002361477265155700205510ustar00rootroot00000000000000[GPD Win Max - All versions]
MatchName=HTIX5288:00 093A:0255 Touchpad
MatchUdevType=touchpad
MatchDMIModalias=dmi:*svnGPD:*pnG1619-*
AttrEventCode=-BTN_RIGHT
libinput-1.28.1/quirks/50-system-graviton.quirks000066400000000000000000000007721477265155700216350ustar00rootroot00000000000000# Touchpad is not a clickpad but INPUT_PROP_BUTTONPAD is set
[Synaptics ALPS0001:00 0911:5288 Touchpad]
MatchUdevType=touchpad
MatchName=ALPS0001:00 0911:5288 Touchpad
MatchDMIModalias=dmi:*svn3LogicGroup:*:pnGravitonN15i-K2*:*
AttrInputProp=-INPUT_PROP_BUTTONPAD
AttrEventCode=+BTN_RIGHT
[PCTel PCT2342:00 0911:5288 Touchpad]
MatchUdevType=touchpad
MatchName=PCT2342:00 0911:5288 Touchpad
MatchDMIModalias=dmi:*svn3LogicGroup:pnGravitonN15i:*
AttrInputProp=-INPUT_PROP_BUTTONPAD
AttrEventCode=+BTN_RIGHT
libinput-1.28.1/quirks/50-system-honor.quirks000066400000000000000000000003361477265155700211250ustar00rootroot00000000000000# Clickpad that announces BTN_RIGHT
# requires ModelPressurePad=1
[HONOR MagicBook Art 14]
MatchName=*TOPS0102*
MatchDMIModalias=dmi:*svnHONOR:*pnMRA-XXX*
MatchUdevType=touchpad
AttrEventCode=-BTN_RIGHT
ModelPressurePad=1
libinput-1.28.1/quirks/50-system-hp.quirks000066400000000000000000000066271477265155700204200ustar00rootroot00000000000000# Do not edit this file, it will be overwritten on update
#
# Claims to have double/tripletap but doesn't actually send it
# https://bugs.freedesktop.org/show_bug.cgi?id=98538
[HP Compaq 6910p]
MatchName=*SynPS/2 Synaptics TouchPad
MatchDMIModalias=dmi:*svnHewlett-Packard:*pnHPCompaq6910p*
AttrEventCode=-BTN_TOOL_DOUBLETAP;-BTN_TOOL_TRIPLETAP;
# Claims to have double/tripletap but doesn't actually send it
# https://bugzilla.redhat.com/show_bug.cgi?id=1351285 and
[HP Compaq 8510w]
MatchName=*SynPS/2 Synaptics TouchPad
MatchDMIModalias=dmi:*svnHewlett-Packard:*pnHPCompaq8510w*
AttrEventCode=-BTN_TOOL_DOUBLETAP;-BTN_TOOL_TRIPLETAP;
[HP Pavilion dmi4]
MatchName=*SynPS/2 Synaptics TouchPad
MatchDMIModalias=dmi:*svnHewlett-Packard:*pnHPPaviliondm4NotebookPC*
ModelHPPavilionDM4Touchpad=1
# Touchpad is a clickpad but INPUT_PROP_BUTTONPAD is not set, see
# https://bugs.freedesktop.org/show_bug.cgi?id=97147
[HP Stream 11]
MatchName=SYN1EDE:00 06CB:7442*
MatchDMIModalias=dmi:*svnHewlett-Packard:pnHPStreamNotebookPC11*
AttrInputProp=+INPUT_PROP_BUTTONPAD
# The HP stream x360's embedded-controller filters out events form its builtin
# keyboard when in tablet-mode itself; and it has a capacitive home-button
# (windows logo) underneath its display which also sends PS/2 key-events.
# Do not suspend the keyboard when in tablet-mode so that the home button
# keeps working when in tablet-mode.
[HP Stream x360 11]
MatchName=AT Translated Set 2 keyboard
MatchDMIModalias=dmi:*:svnHewlett-Packard:pnHPStreamx360ConvertiblePC11:*
ModelTabletModeNoSuspend=1
[HP Spectre x360 Convertible 15-bl000]
MatchName=AT Translated Set 2 keyboard
MatchDMIModalias=dmi:*:svnHP:pnHPSpectrex360Convertible15-bl0XX:*
ModelTabletModeNoSuspend=1
[HP ZBook Studio G3]
MatchName=AlpsPS/2 ALPS GlidePoint
MatchDMIModalias=dmi:*svnHP:pnHPZBookStudioG3:*
ModelHPZBookStudioG3=1
[HP Chromebook 14]
MatchName=*Cypress APA Trackpad *cyapa*
MatchDMIModalias=dmi:*svnHewlett-Packard*:pnFalco*
AttrPressureRange=12:8
[HP Spectre x360 Convertible 15-bl1xx]
MatchUdevType=touchpad
MatchName=*SynPS/2 Synaptics TouchPad
MatchDMIModalias=dmi:*svnHP:pnHPSpectrex360Convertible15-bl1XX:*
AttrPressureRange=55:40
AttrThumbPressureThreshold=90
AttrPalmPressureThreshold=100
[HP Spectre x360 Convertible 15-ch0xx]
MatchUdevType=touchpad
MatchName=*SynPS/2 Synaptics TouchPad
MatchDMIModalias=dmi:*svnHP:pnHPSpectrex360Convertible15-ch0xx:*
AttrThumbPressureThreshold=90
AttrPalmPressureThreshold=100
# The HP stream x360's embedded-controller filters out events form its builtin
# keyboard when in tablet-mode itself; and it has a volume up/down on the side.
# Do not suspend the keyboard when in tablet-mode so that the volume up/down
# button keeps working when in tablet-mode.
[HP Spectre x360 Convertible 15-ch0xx Tablet Mode Switch]
MatchName=AT Translated Set 2 keyboard
MatchDMIModalias=dmi:*svnHP:pnHPSpectrex360Convertible15-ch0xx:*
ModelTabletModeNoSuspend=1
[HP Elite x2 1013 G3 Tablet Mode Switch]
MatchName=*Intel Virtual Button*
MatchDMIModalias=dmi:*svnHP:pnHPElitex21013G3:*
ModelTabletModeSwitchUnreliable=1
[HP Elite x2 1013 G3 Touchpad]
MatchUdevType=touchpad
MatchBus=usb
MatchVendor=0x044E
MatchProduct=0x1221
AttrTPKComboLayout=below
[HP Elite x2 1013 G3 Keyboard]
MatchUdevType=keyboard
MatchBus=ps2
MatchDMIModalias=dmi:*svnHP:pnHPElitex21013G3:*
AttrKeyboardIntegration=external
[HP Haptics Touchpad CFD2]
MatchBus=i2c
MatchVendor=0x06CB
MatchProduct=0xCFD2
ModelPressurePad=1
libinput-1.28.1/quirks/50-system-huawei.quirks000066400000000000000000000012221477265155700212550ustar00rootroot00000000000000# Clickpad that announces BTN_RIGHT
# https://bugzilla.redhat.com/show_bug.cgi?id=1972370
[Huawei MateBook 2020 Touchpad]
MatchName=ELAN2604:00 04F3:3114 Touchpad
MatchUdevType=touchpad
MatchDMIModalias=dmi:*svnHUAWEI:*pvrM1010*
AttrEventCode=-BTN_RIGHT
[Huawei MateBook X Pro 2022 Touchpad]
MatchName=GXTP7863:00 27C6:01E0 Touchpad
MatchUdevType=touchpad
MatchDMIModalias=dmi:*svnHUAWEI:*pnMRGF-XX*
AttrEventCode=-BTN_RIGHT
# 2024 model requires ModelPressurePad=1
[Huawei MateBook X Pro 2024 Touchpad]
MatchName=GXTP7863:00 27C6:01E0 Touchpad
MatchUdevType=touchpad
MatchDMIModalias=dmi:*svnHUAWEI:*pnVGHH-XX*
AttrEventCode=-BTN_RIGHT
ModelPressurePad=1
libinput-1.28.1/quirks/50-system-icl.quirks000066400000000000000000000004241477265155700205450ustar00rootroot00000000000000# Touchpad is not a clickpad but INPUT_PROP_BUTTONPAD is set
[Synaptics ALPS0001:00 0911:5288 Touchpad]
MatchUdevType=touchpad
MatchName=ALPS0001:00 0911:5288 Touchpad
MatchDMIModalias=dmi:*svnICL:*:rvnICL:rnSi16:*
AttrInputProp=-INPUT_PROP_BUTTONPAD
AttrEventCode=+BTN_RIGHT
libinput-1.28.1/quirks/50-system-lenovo.quirks000066400000000000000000000302621477265155700213030ustar00rootroot00000000000000# Do not edit this file, it will be overwritten on update
[Lenovo Thinkpad Touchpad]
MatchName=*Synaptics*
MatchDMIModalias=dmi:*svnLENOVO:*:pvrThinkPad*:*
AttrThumbPressureThreshold=100
[Lenovo x230 Touchpad]
MatchName=*SynPS/2 Synaptics TouchPad
MatchDMIModalias=dmi:*svnLENOVO:*:pvrThinkPadX230*
ModelLenovoX230=1
[Lenovo T440p Touchpad PS/2]
MatchName=SynPS/2 Synaptics TouchPad
MatchDMIModalias=dmi:*svnLENOVO:*:pvrThinkPadT440p*
ModelLenovoT450Touchpad=1
[Lenovo T440p Touchpad RMI4]
MatchName=Synaptics tm2964-001
MatchDMIModalias=dmi:*svnLENOVO:*:pvrThinkPadT440p*
ModelLenovoT450Touchpad=1
[Lenovo T470 Trackpoint]
MatchName=*TPPS/2 IBM TrackPoint
MatchDMIModalias=dmi:*svnLENOVO:*:pvrThinkPadT470:*
AttrTrackpointMultiplier=0.75
[Lenovo T480 Trackpoint]
MatchName=*TPPS/2 IBM TrackPoint
MatchDMIModalias=dmi:*svnLENOVO:*:pvrThinkPadT480:*
AttrTrackpointMultiplier=0.75
[Lenovo A485 Trackpoint]
MatchName=*TPPS/2 IBM TrackPoint
MatchDMIModalias=dmi:*svnLENOVO:*:pvrThinkPadA485:*
AttrTrackpointMultiplier=0.75
# Touchpad is a clickpad but INPUT_PROP_BUTTONPAD is not set, see
# https://gitlab.freedesktop.org/libinput/libinput/issues/177
[Lenovo T480s Touchpad]
MatchName=Elan Touchpad
MatchDMIModalias=dmi:*svnLENOVO:*:pvrThinkPadT480s*
AttrInputProp=+INPUT_PROP_BUTTONPAD
# Touchpad is a clickpad but INPUT_PROP_BUTTONPAD is not set, see
# https://gitlab.freedesktop.org/libinput/libinput/issues/177
[Lenovo T490s Touchpad]
MatchName=Elan Touchpad
MatchDMIModalias=dmi:*svnLENOVO:*:pvrThinkPadT490s*
AttrInputProp=+INPUT_PROP_BUTTONPAD
[Lenovo T490s Trackpoint]
MatchName=*TPPS/2 IBM TrackPoint
MatchDMIModalias=dmi:*svnLENOVO:*:pvrThinkPadT490s:*
AttrTrackpointMultiplier=0.4
[Lenovo P14s Gen 1 AMD Trackpoint]
MatchUdevType=pointingstick
MatchName=*TPPS/2 Elan TrackPoint*
MatchDMIModalias=dmi:*svnLENOVO:*:pvrThinkPadP14sGen1*
AttrTrackpointMultiplier=0.4
# Touchpad is a clickpad but INPUT_PROP_BUTTONPAD is not set, see
# https://gitlab.freedesktop.org/libinput/libinput/issues/234
[Lenovo L380 Touchpad]
MatchName=Elan Touchpad
MatchDMIModalias=dmi:*svnLENOVO:*:pvrThinkPadL380*
AttrInputProp=+INPUT_PROP_BUTTONPAD
[Lenovo X200/201 Trackpoint]
MatchName=*TPPS/2 IBM TrackPoint
MatchDMIModalias=dmi:*svnLENOVO:*pvrThinkPadX20?:*
AttrTrackpointMultiplier=0.25
[Lenovo X200s/201s Trackpoint]
MatchName=*TPPS/2 IBM TrackPoint
MatchDMIModalias=dmi:*svnLENOVO:*pvrThinkPadX20??:*
AttrTrackpointMultiplier=0.25
[Lenovo X230 Trackpoint]
MatchName=*TPPS/2 IBM TrackPoint
MatchDMIModalias=dmi:*svnLENOVO:*pvrThinkPadX230:*
AttrTrackpointMultiplier=0.25
[Lenovo X280 Trackpoint]
MatchName=*TPPS/2 Elan TrackPoint
MatchDMIModalias=dmi:*svnLENOVO:*pvrThinkPadX280:*
AttrTrackpointMultiplier=0.5
[Lenovo X280 Touchpad]
MatchName=Synaptics TM3381-002
MatchDMIModalias=dmi:*svnLENOVO:*:pvrThinkPadX280*
AttrPalmSizeThreshold=6
[Lenovo P50 Touchpad]
MatchName=SynPS/2 Synaptics TouchPad
MatchDMIModalias=dmi:*svnLENOVO:*:pvrThinkPadP50*:
ModelLenovoT450Touchpad=1
AttrPalmPressureThreshold=150
[Lenovo *50 Touchpad]
MatchName=SynPS/2 Synaptics TouchPad
MatchDMIModalias=dmi:*svnLENOVO:*:pvrThinkPad??50*:
ModelLenovoT450Touchpad=1
AttrPalmPressureThreshold=150
[Lenovo *60 Touchpad]
MatchName=SynPS/2 Synaptics TouchPad
MatchDMIModalias=dmi:*svnLENOVO:*:pvrThinkPad??60*:
ModelLenovoT450Touchpad=1
AttrPalmPressureThreshold=150
[Lenovo X1 Carbon 3rd Touchpad]
MatchName=SynPS/2 Synaptics TouchPad
MatchDMIModalias=dmi:*svnLENOVO:*:pvrThinkPadX1Carbon3rd:*
ModelLenovoT450Touchpad=1
AttrPalmPressureThreshold=150
[Lenovo X1 Carbon 4th Trackpoint]
MatchUdevType=pointingstick
MatchName=*TPPS/2 IBM TrackPoint*
MatchDMIModalias=dmi:*svnLENOVO:*:pvrThinkPadX1Carbon4th*
AttrTrackpointMultiplier=0.5
[Lenovo X1 Carbon 6th Trackpoint]
MatchUdevType=pointingstick
MatchName=*TPPS/2 Elan TrackPoint*
MatchDMIModalias=dmi:*svnLENOVO:*:pvrThinkPadX1Carbon6th*
AttrTrackpointMultiplier=0.4
[Lenovo ThinkPad Compact USB Keyboard with TrackPoint (keyboard)]
MatchUdevType=keyboard
MatchBus=usb
MatchVendor=0x17EF
MatchProduct=0x6047
AttrKeyboardIntegration=external
[Lenovo ThinkPad Compact USB Keyboard with TrackPoint (trackpoint)]
MatchUdevType=pointingstick
MatchBus=usb
MatchVendor=0x17EF
MatchProduct=0x6047
AttrPointingStickIntegration=external
# Lenovo Thinkpad Yoga (not the consumer versions) disables the keyboard
# mechanically. We must not disable the keyboard because some keys are
# still accessible on the screen and volume rocker.
# Initially #103749 and extended by #106799 comment 7
[Lenovo Thinkpad Yoga]
MatchName=AT Translated Set 2 keyboard
MatchDMIModalias=dmi:*svnLENOVO:*pvrThinkPad*Yoga*:*
ModelTabletModeNoSuspend=1
[Lenovo X1 Yoga Trackpoint 1st gen]
MatchName=*TPPS/2 IBM TrackPoint
MatchDMIModalias=dmi:*svnLENOVO:*:pvrThinkPadX1Yoga1st:*
AttrTrackpointMultiplier=1.25
# A true pressurepad so let's not use pressure for contact size
# https://gitlab.freedesktop.org/libinput/libinput/-/issues/562
[Lenovo Yoga 9i Pressurepad]
MatchBus=i2c
MatchVendor=0x06CB
MatchProduct=0xCE37
ModelPressurePad=1
[Lenovo Yoga C930 Tablet]
MatchBus=i2c
MatchVendor=0x056A
MatchProduct=0x5196
AttrTabletSmoothing=1
# Lenovo Carbon X1 6th gen (RMI4 only, PS/2 is broken on this device,
# sends bogus ABS_MT_TOOL_TYPE events for MT_TOOL_PALM
[Lenovo Carbon X1 6th gen]
MatchName=Synaptics TM3288-011
MatchDMIModalias=dmi:*svnLENOVO:*pvrThinkPadX1Carbon6th:*
AttrEventCode=-ABS_MT_TOOL_TYPE
ModelLenovoX1Gen6Touchpad=1
[Lenovo X41 Tablet]
MatchName=AT Translated Set 2 keyboard
MatchDMIModalias=dmi:*svnIBM:*pvrThinkPadX41Tablet:*
ModelTabletModeNoSuspend=1
[Lenovo X60 Tablet]
MatchName=AT Translated Set 2 keyboard
MatchDMIModalias=dmi:*svnLENOVO:*pvrThinkPadX60Tablet:*
ModelTabletModeNoSuspend=1
[Lenovo X61 Tablet]
MatchName=AT Translated Set 2 keyboard
MatchDMIModalias=dmi:*svnLENOVO:*pvrThinkPadX61Tablet:*
ModelTabletModeNoSuspend=1
# Lenovo X220 Tablet special bezel buttons are associated to the
# keyboard and would therefore mistakenly be deactivated as well.
# See https://gitlab.freedesktop.org/libinput/libinput/issues/154
[Lenovo X220 Tablet]
MatchName=AT Translated Set 2 keyboard
MatchDMIModalias=dmi:*svnLENOVO:*pvrThinkPadX220Tablet:*
ModelTabletModeNoSuspend=1
# Special bezel button deactivation with
# keyboard also applies to X230 Tablet
[Lenovo X230 Tablet]
MatchName=AT Translated Set 2 keyboard
MatchDMIModalias=dmi:*svnLENOVO:*pvrThinkPadX230Tablet:*
ModelTabletModeNoSuspend=1
# Special bezel button deactivation with
# keyboard also applies to X200 Tablet
[Lenovo X200 Tablet]
MatchName=AT Translated Set 2 keyboard
MatchDMIModalias=dmi:*svnLENOVO:*pvrThinkPadX200Tablet:*
ModelTabletModeNoSuspend=1
[Lenovo X201 Tablet]
MatchName=AT Translated Set 2 keyboard
MatchDMIModalias=dmi:*svnLENOVO:*pvrThinkPadX201Tablet:*
ModelTabletModeNoSuspend=1
# Lenovo MIIX 720 comes with a detachable keyboard. We must not disable
# the keyboard because some keys are still accessible on the screen and
# volume rocker. See
# https://gitlab.freedesktop.org/libinput/libinput/issues/115
[Lenovo MIIX 720]
MatchName=AT Raw Set 2 keyboard
MatchDMIModalias=dmi:*svnLENOVO:*pvrLenovoMIIX720-12IKB:*
ModelTabletModeNoSuspend=1
# Lenovo ThinkPad X1 Tablet (1st Gen) also comes with a detachable keyboard.
# We must not disable the keyboard because some keys are still accessible on
# volume rocker.
[Lenovo ThinkPad X1 Tablet (1st Gen)]
MatchName=AT Raw Set 2 keyboard
MatchDMIModalias=dmi:*svnLENOVO:*pvrThinkPadX1Tablet:*
ModelTabletModeNoSuspend=1
# Misidentified as an external keyboard by libinput
# Tested on Legion 5 15AR05H
[Lenovo Legion 5 Keyboard (C100)]
MatchUdevType=keyboard
MatchBus=usb
MatchVendor=0x048D
MatchProduct=0xC100
AttrKeyboardIntegration=internal
# Tested on Legion 5 15ARH7H, should also work for Legion 5 Pro 16ARH7H
# 048d:c102 Integrated Technology Express, Inc. ITE Device(8910)
[Lenovo Legion 5 Keyboard (C102)]
MatchUdevType=keyboard
MatchBus=usb
MatchVendor=0x048D
MatchProduct=0xC102
AttrKeyboardIntegration=internal
# Tested on Legion Pro 5 16IRX8
# 048d:c103 Integrated Technology Express, Inc. ITE Device(8910)
[Lenovo Legion 5 Keyboard (C103)]
MatchUdevType=keyboard
MatchBus=usb
MatchVendor=0x048D
MatchProduct=0xC103
AttrKeyboardIntegration=internal
[Lenovo Legion 5 Keyboard (C955)]
MatchUdevType=keyboard
MatchBus=usb
MatchVendor=0x048D
MatchProduct=0xC955
AttrKeyboardIntegration=internal
# Tested on Lenovo Legion 5 Pro 16ACH6H
[Lenovo Legion 5 Pro Keyboard]
MatchUdevType=keyboard
MatchBus=usb
MatchVendor=0x048D
MatchProduct=0xC101
AttrKeyboardIntegration=internal
[Lenovo Legion 5i Keyboard]
MatchName=ITE Tech. Inc. ITE Device(8910) Keyboard
MatchDMIModalias=dmi:*svnLENOVO:*pvrLegion515IAH7H:*
AttrKeyboardIntegration=internal
[Lenovo Legion 7 Keyboard]
MatchUdevType=keyboard
MatchBus=usb
MatchVendor=0x048D
MatchProduct=0xC968
AttrKeyboardIntegration=internal
[Lenovo Legion Y740 Keyboard]
MatchUdevType=keyboard
MatchBus=usb
MatchVendor=0x048D
MatchProduct=0xC936
AttrKeyboardIntegration=internal
[Lenovo Legion Slim 7]
MatchUdevType=keyboard
MatchBus=usb
MatchVendor=0x048D
MatchProduct=0xC967
AttrKeyboardIntegration=internal
[Lenovo Legion Slim 7 Gen 8]
MatchUdevType=keyboard
MatchBus=usb
MatchVendor=0x048D
MatchProduct=0xC987
AttrKeyboardIntegration=internal
# https://gitlab.freedesktop.org/libinput/libinput/-/issues/604
[Lenovo Yoga Slim 9 14ITL5 Pressurepad]
MatchBus=i2c
MatchVendor=0x27C6
MatchProduct=0x01E8
ModelPressurePad=1
# Duet 7i tablet switch activated by folding keyboard cover, or removing it.
# We must not disable volume rocker 'keyboard'.
[Lenovo Duet 7i]
MatchName=AT Raw Set 2 keyboard
MatchDMIModalias=dmi:*svnLENOVO:*pvrYogaDuet713IML05:*
ModelTabletModeNoSuspend=1
# Lenovo IdeaPad Duet 3 also comes with a detachable keyboard.
[Lenovo IdeaPad Duet 3]
MatchName=AT Raw Set 2 keyboard
MatchDMIModalias=dmi:*svnLENOVO:*pvrIdeaPadDuet3*:*
ModelTabletModeNoSuspend=1
# Modifies pressure range to avoid random jumps.
# https://gitlab.freedesktop.org/libinput/libinput/-/issues/407
[Lenovo Yoga 2 Pro touchpad]
MatchUdevType=touchpad
MatchName=*SynPS/2 Synaptics TouchPad
MatchDMIModalias=dmi:*svnLENOVO:*:pvrLenovoYoga2Pro*
AttrPressureRange=50:45
[Lenovo Legion 7i 4090 Keyboard]
MatchUdevType=keyboard
MatchBus=usb
MatchDMIModalias=dmi:*svnLENOVO:*:pvrLegionY9000PIRX8H*
AttrKeyboardIntegration=internal
[Lenovo LOQ 15IRH8 Keyboard]
MatchUdevType=keyboard
MatchBus=usb
MatchVendor=0x048D
MatchProduct=0xC986
AttrKeyboardIntegration=internal
[Lenovo ThinkPad E14 v2]
MatchUdevType=touchpad
MatchName=*Elan Touchpad
MatchDMIModalias=dmi:*svnLENOVO:*:pvrThinkPadE14Gen2*
AttrPalmPressureThreshold=300
AttrPressureRange=10:8
# White Backlit Keyboard
[Lenovo Ideapad Gaming 3]
MatchUdevType=keyboard
MatchBus=usb
MatchVendor=0x048D
MatchProduct=0xC966
AttrKeyboardIntegration=internal
[Lenovo Thinkpad Yoga X390]
MatchUdevType=pointingstick
MatchName=*TPPS/2 Elan TrackPoint*
MatchDMIModalias=dmi:*svnLENOVO:*pvrThinkPadX390Yoga*:*
AttrTrackpointMultiplier=0.4
# This should cover all keyboards that are misidentified as external.
# Tested on Lenovo Legion 5 Pro (2023)
[Lenovo 16ARX8 keyboard]
MatchName=ITE Tech. Inc. ITE Device(8910) Keyboard
MatchUdevType=keyboard
MatchDMIModalias=dmi:*svnLENOVO:*
AttrKeyboardIntegration=internal
# Some ThinkBook 14 G7+ ASP models come with pressure pads that were not
# correctly declared as such.
[Lenovo ThinkBook 14 G7+ ASP touchpad]
MatchName=*GXTP5100*
MatchDMIModalias=dmi:*svnLENOVO:*pvrThinkBook14G7+ASP*:*
MatchUdevType=touchpad
ModelPressurePad=1
# The ThinkBook 14 G6+ IMH also has a similar issue as the G7+ mentioned above.
[Lenovo ThinkBook 14 G6+ IMH]
MatchName=*GXTP5100*
MatchDMIModalias=dmi:*svnLENOVO:*pvrThinkBook14G6+IMH*:*
MatchUdevType=touchpad
ModelPressurePad=1
# Lenovo Yoga Slim 7i Carbon sends bogus ABS_MT_TOOL_TYPE MT_TOOL_PALM events
[Lenovo Yoga Slim 7i Carbon]
MatchName=* Touchpad
MatchDMIModalias=dmi:*:svnLENOVO:*pvrYogaSlim7Carbon13IAP7:*
AttrEventCode=-ABS_MT_TOOL_TYPE
# The ThinkPad X9 15 Gen 1 Forcepad touchpad is not
# detected as a pressure pad
[Lenovo ThinkPad X9 15 Gen 1]
MatchName=*GXTP5100*
MatchDMIModalias=dmi:*svnLENOVO:*pvrThinkPadX9-15Gen1*:*
MatchUdevType=touchpad
ModelPressurePad=1
# The ThinkBook 14 G7+ IAH also has a similar issue as the ASP mentioned above.
[Lenovo ThinkBook 14 G7+ IAH touchpad]
MatchName=*GXTP5100*
MatchDMIModalias=dmi:*svnLENOVO:*pvrThinkBook14G7+IAH*:*
MatchUdevType=touchpad
ModelPressurePad=1
libinput-1.28.1/quirks/50-system-lg.quirks000066400000000000000000000003021477265155700203730ustar00rootroot00000000000000# Do not edit this file, it will be overwritten on update
[LG gram 14 2023 Touchpad]
MatchName=* Touchpad
MatchDMIModalias=dmi:*svnLGElectronics:pn14Z90R-G.AA79G:*
ModelTouchpadPhantomClicks=1
libinput-1.28.1/quirks/50-system-minisforum.quirks000066400000000000000000000005511477265155700221670ustar00rootroot00000000000000# Do not edit this file, it will be overwritten on update
[Minisforum V3 volume keys]
MatchName=AT Translated Set 2 keyboard
MatchDMIModalias=dmi:*svnMicroComputer(HK)TechLimited:pnV3:*
ModelTabletModeNoSuspend=1
[Minisforum V3 touchpad dwt]
MatchName=USB Keyboard
MatchDMIModalias=dmi:*svnMicroComputer(HK)TechLimited:pnV3:*
AttrKeyboardIntegration=internal
libinput-1.28.1/quirks/50-system-pine64.quirks000066400000000000000000000002041477265155700210770ustar00rootroot00000000000000[PineBook Pro Keyboard]
MatchVendor=0x258A
MatchProduct=0x001E
MatchUdevType=keyboard
MatchBus=usb
AttrKeyboardIntegration=internal
libinput-1.28.1/quirks/50-system-sony.quirks000066400000000000000000000003661477265155700207730ustar00rootroot00000000000000# Do not edit this file, it will be overwritten on update
[Sony Vaio VPCEG Series Touchpad Pressure Override]
MatchUdevType=touchpad
MatchName=*SynPS/2 Synaptics TouchPad
MatchDMIModalias=dmi:*svnSonyCorporation:pnVPCEG*
AttrPressureRange=45:40
libinput-1.28.1/quirks/50-system-starlabs.quirks000066400000000000000000000002411477265155700216060ustar00rootroot00000000000000[Star Labs Touchpad]
MatchName=*Touchpad
MatchUdevType=touchpad
MatchDMIModalias=dmi:*svnStarLabs:*
AttrEventCode=-BTN_RIGHT
AttrInputProp=+INPUT_PROP_BUTTONPAD
libinput-1.28.1/quirks/50-system-system76.quirks000066400000000000000000000010771477265155700215040ustar00rootroot00000000000000# Do not edit this file, it will be overwritten on update
[System76 Bonobo Professional]
MatchName=SynPS/2 Synaptics TouchPad
MatchDMIModalias=dmi:*svnSystem76*pvrbonp5*
ModelSystem76Bonobo=1
[System76 Clevo]
MatchName=SynPS/2 Synaptics TouchPad
MatchDMIModalias=dmi:*pnW740SU*rnW740SU*
ModelClevoW740SU=1
[System76 Galago Ultra Pro]
MatchName=SynPS/2 Synaptics TouchPad
MatchDMIModalias=dmi:*svnSystem76*pvrgalu1*
ModelSystem76Galago=1
[System76 Kudu Professional]
MatchName=SynPS/2 Synaptics TouchPad
MatchDMIModalias=dmi:*svnSystem76*pvrkudp1*
ModelSystem76Kudu=1
libinput-1.28.1/quirks/50-system-toshiba.quirks000066400000000000000000000002261477265155700214270ustar00rootroot00000000000000[Toshiba Satellite L855-14E Touchpad]
MatchName=*SynPS/2 Synaptics TouchPad
MatchDMIModalias=dmi:*svnTOSHIBA:pnSATELLITEL855*
AttrPressureRange=45:44
libinput-1.28.1/quirks/50-system-vaio.quirks000066400000000000000000000002551477265155700207360ustar00rootroot00000000000000[Positivo-Vaio Touchpad]
MatchName=SYNA3602:00 0911:5288 Touchpad
MatchDMIModalias=dmi:*svnPositivoBahia-VAIO:pnVJ[FP][EWX]*
MatchUdevType=touchpad
AttrEventCode=+BTN_RIGHT
libinput-1.28.1/quirks/README.md000066400000000000000000000055061477265155700162570ustar00rootroot00000000000000libinput quirks file format
===========================
This directory contains hardware quirks used by libinput to work around bugs
in the hardware, device behavior and to supply information not obtained
through the kernel device.
**THIS IS NOT STABLE API**
The data format may change at any time. If your quirks file is not part of
the libinput git tree, do not expect it to work after an update. Absolutely
no guarantees are made for backwards-compatibility.
**THIS IS NOT A CONFIGURATION API**
Use the `libinput_device_config_foo()` functions for device configuration.
Quirks here are hardware quirks only.
Data file naming
----------------
Data files are read in versionsort order, read order determines how values
override each other. Values read later override previously read values. The
current structure is:
- `10-generic-foo.quirks` for generic settings,
- `30-vendor-foo.quirks` for vendor-specific settings, and
- `50-system-foo.quirks` for system vendors.
This is not a fixed naming scheme and may change at any time. It's an
approximation only because some vendors are also system vendors, e.g.
Microsoft makes devices and laptops.
Laptop-specific quirks should always go into the laptop vendor's file even
where they apply to a component of a different vendor. For example, a quirk
for a Synaptics touchpad specific to a Dell laptop should go into the Dell
quirks file.
Sections, matches and values
----------------------------
A data file must contain at least one section, each section must have at
least one `Match` tag and at least one of either `Attr` or `Model`. Section
names are free-form and may contain spaces.
```
# This is a comment
[Some touchpad]
MatchBus=usb
# No quotes around strings
MatchName=*Synaptics Touchpad*
AttrSizeHint=50x50
ModelSynapticsTouchpad=1
[Apple touchpad]
MatchVendor=0x5AC
MatchProduct=0x123
ModelAppleTouchpad=1
```
Comments are lines starting with `#`.
All `Model` tags take a value of either `1` or `0`.
All `Attr` tag values are specific to that attribute.
Parser errors
-------------
The following requirements must be met:
* No whitespace is allowed at the beginning of the line
* A Section must have at least one `Match*` entry
* A Section must not repeat `Match*` entry
* A Section must have at least one of `Model*` or `Attr*` entries
* A `Model` tag may only have the value `1` or `0`
* String properties must not be enclosed in quotes
* Hex numbers must use uppercase letters (e.g. `0x12AB`)
Failure to meet these requirements will cause a parser error and the quirks
files will not be used.
Debugging
---------
When modifying a data file, use the `libinput list-quirks` tool to
verify the changes. The tool can be pointed at the data directory to
analyse, use `--verbose` to get more info. For example:
```
libinput list-quirks --data-dir /path/to/git/repo/quirks/ --verbose /dev/input/event0
```
libinput-1.28.1/src/000077500000000000000000000000001477265155700142435ustar00rootroot00000000000000libinput-1.28.1/src/builddir.h000066400000000000000000000037621477265155700162220ustar00rootroot00000000000000/*
* Copyright © 2019 Red Hat, Inc.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice (including the next
* paragraph) shall be included in all copies or substantial portions of the
* Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
*/
#include
#pragma once
#include
#include "util-strings.h"
/**
* Try to figure out the directory we're executing from and if it matches
* the builddir, return that directory. Otherwise, return NULL.
*/
static inline char *
builddir_lookup(void)
{
char execdir[PATH_MAX];
char *pathsep;
ssize_t nread;
/* In the case of release builds, the builddir is
the empty string */
if (streq(MESON_BUILD_ROOT, ""))
return NULL;
nread = readlink("/proc/self/exe", execdir, sizeof(execdir) - 1);
if (nread <= 0 || nread == sizeof(execdir) - 1)
return NULL;
/* readlink doesn't terminate the string and readlink says
anything past sz is undefined */
execdir[nread] = '\0';
pathsep = strrchr(execdir, '/');
if (!pathsep)
return NULL;
*pathsep = '\0';
if (!streq(execdir, MESON_BUILD_ROOT))
return NULL;
return safe_strdup(execdir);
}
libinput-1.28.1/src/evdev-debounce.c000066400000000000000000000432051477265155700173060ustar00rootroot00000000000000/*
* Copyright © 2017 Red Hat, Inc.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice (including the next
* paragraph) shall be included in all copies or substantial portions of the
* Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
*/
#include "config.h"
#include "evdev-fallback.h"
/* Debounce cases to handle
P ... button press
R ... button release
---| timeout duration
'normal' .... event sent when it happens
'filtered' .. event is not sent (but may be sent later)
'delayed' ... event is sent with wall-clock delay
1) P---| R P normal, R normal
2) R---| P R normal, P normal
3) P---R--| P P normal, R filtered, delayed, P normal
4) R---P--| R R normal, P filtered, delayed, R normal
4.1) P---| R--P--| P normal, R filtered
5) P--R-P-| R P normal, R filtered, P filtered, R normal
6) R--P-R-| P R normal, P filtered, R filtered, P normal
7) P--R--|
---P-| P normal, R filtered, P filtered
8) R--P--|
---R-| R normal, P filtered, R filtered
1, 2 are the normal click cases without debouncing taking effect
3, 4 are fast clicks where the second event is delivered with a delay
5, 6 are contact bounces, fast
7, 8 are contact bounces, slow
4.1 is a special case with the same event sequence as 4 but we want to
filter the *release* event out, it's a button losing contact while being
held down.
7 and 8 are cases where the first event happens within the first timeout
but the second event is outside that timeout (but within the timeout of
the second event). These cases are handled by restarting the timer on every
event that could be part of a bouncing sequence, which makes these cases
indistinguishable from 5 and 6.
*/
enum debounce_event {
DEBOUNCE_EVENT_PRESS = 50,
DEBOUNCE_EVENT_RELEASE,
DEBOUNCE_EVENT_TIMEOUT,
DEBOUNCE_EVENT_TIMEOUT_SHORT,
DEBOUNCE_EVENT_OTHERBUTTON,
};
static inline const char *
debounce_state_to_str(enum debounce_state state)
{
switch(state) {
CASE_RETURN_STRING(DEBOUNCE_STATE_IS_UP);
CASE_RETURN_STRING(DEBOUNCE_STATE_IS_DOWN);
CASE_RETURN_STRING(DEBOUNCE_STATE_IS_DOWN_WAITING);
CASE_RETURN_STRING(DEBOUNCE_STATE_IS_UP_DELAYING);
CASE_RETURN_STRING(DEBOUNCE_STATE_IS_UP_DELAYING_SPURIOUS);
CASE_RETURN_STRING(DEBOUNCE_STATE_IS_UP_DETECTING_SPURIOUS);
CASE_RETURN_STRING(DEBOUNCE_STATE_IS_DOWN_DETECTING_SPURIOUS);
CASE_RETURN_STRING(DEBOUNCE_STATE_IS_UP_WAITING);
CASE_RETURN_STRING(DEBOUNCE_STATE_IS_DOWN_DELAYING);
CASE_RETURN_STRING(DEBOUNCE_STATE_DISABLED);
}
return NULL;
}
static inline const char*
debounce_event_to_str(enum debounce_event event)
{
switch(event) {
CASE_RETURN_STRING(DEBOUNCE_EVENT_PRESS);
CASE_RETURN_STRING(DEBOUNCE_EVENT_RELEASE);
CASE_RETURN_STRING(DEBOUNCE_EVENT_TIMEOUT);
CASE_RETURN_STRING(DEBOUNCE_EVENT_TIMEOUT_SHORT);
CASE_RETURN_STRING(DEBOUNCE_EVENT_OTHERBUTTON);
}
return NULL;
}
static inline void
log_debounce_bug(struct fallback_dispatch *fallback, enum debounce_event event)
{
evdev_log_bug_libinput(fallback->device,
"invalid debounce event %s in state %s\n",
debounce_event_to_str(event),
debounce_state_to_str(fallback->debounce.state));
}
static inline void
debounce_set_state(struct fallback_dispatch *fallback,
enum debounce_state new_state)
{
assert(new_state >= DEBOUNCE_STATE_IS_UP &&
new_state <= DEBOUNCE_STATE_IS_DOWN_DELAYING);
fallback->debounce.state = new_state;
}
static inline void
debounce_set_timer(struct fallback_dispatch *fallback,
uint64_t time)
{
const int DEBOUNCE_TIMEOUT_BOUNCE = ms2us(25);
libinput_timer_set(&fallback->debounce.timer,
time + DEBOUNCE_TIMEOUT_BOUNCE);
}
static inline void
debounce_set_timer_short(struct fallback_dispatch *fallback,
uint64_t time)
{
const int DEBOUNCE_TIMEOUT_SPURIOUS = ms2us(12);
libinput_timer_set(&fallback->debounce.timer_short,
time + DEBOUNCE_TIMEOUT_SPURIOUS);
}
static inline void
debounce_cancel_timer(struct fallback_dispatch *fallback)
{
libinput_timer_cancel(&fallback->debounce.timer);
}
static inline void
debounce_cancel_timer_short(struct fallback_dispatch *fallback)
{
libinput_timer_cancel(&fallback->debounce.timer_short);
}
static inline void
debounce_enable_spurious(struct fallback_dispatch *fallback)
{
if (fallback->debounce.spurious_enabled)
evdev_log_bug_libinput(fallback->device,
"tried to enable spurious debouncing twice\n");
fallback->debounce.spurious_enabled = true;
evdev_log_info(fallback->device,
"Enabling spurious button debouncing, "
"see %s/button-debouncing.html for details\n",
HTTP_DOC_LINK);
}
static void
debounce_notify_button(struct fallback_dispatch *fallback,
enum libinput_button_state state)
{
struct evdev_device *device = fallback->device;
unsigned int code = fallback->debounce.button_code;
uint64_t time = fallback->debounce.button_time;
code = evdev_to_left_handed(device, code);
fallback_notify_physical_button(fallback, device, time, code, state);
}
static void
debounce_is_up_handle_event(struct fallback_dispatch *fallback, enum debounce_event event, uint64_t time)
{
switch (event) {
case DEBOUNCE_EVENT_PRESS:
fallback->debounce.button_time = time;
debounce_set_timer(fallback, time);
debounce_set_state(fallback, DEBOUNCE_STATE_IS_DOWN_WAITING);
debounce_notify_button(fallback,
LIBINPUT_BUTTON_STATE_PRESSED);
break;
case DEBOUNCE_EVENT_RELEASE:
case DEBOUNCE_EVENT_TIMEOUT:
case DEBOUNCE_EVENT_TIMEOUT_SHORT:
log_debounce_bug(fallback, event);
break;
case DEBOUNCE_EVENT_OTHERBUTTON:
break;
}
}
static void
debounce_is_down_handle_event(struct fallback_dispatch *fallback, enum debounce_event event, uint64_t time)
{
switch (event) {
case DEBOUNCE_EVENT_PRESS:
log_debounce_bug(fallback, event);
break;
case DEBOUNCE_EVENT_RELEASE:
fallback->debounce.button_time = time;
debounce_set_timer(fallback, time);
debounce_set_timer_short(fallback, time);
if (fallback->debounce.spurious_enabled) {
debounce_set_state(fallback, DEBOUNCE_STATE_IS_UP_DELAYING_SPURIOUS);
} else {
debounce_set_state(fallback, DEBOUNCE_STATE_IS_UP_DETECTING_SPURIOUS);
debounce_notify_button(fallback,
LIBINPUT_BUTTON_STATE_RELEASED);
}
break;
case DEBOUNCE_EVENT_TIMEOUT:
case DEBOUNCE_EVENT_TIMEOUT_SHORT:
log_debounce_bug(fallback, event);
break;
case DEBOUNCE_EVENT_OTHERBUTTON:
break;
}
}
static void
debounce_is_down_waiting_handle_event(struct fallback_dispatch *fallback, enum debounce_event event, uint64_t time)
{
switch (event) {
case DEBOUNCE_EVENT_PRESS:
log_debounce_bug(fallback, event);
break;
case DEBOUNCE_EVENT_RELEASE:
debounce_set_timer(fallback, time);
debounce_set_state(fallback, DEBOUNCE_STATE_IS_UP_DELAYING);
/* Note: In the debouncing RPR case, we use the last
* release's time stamp */
fallback->debounce.button_time = time;
break;
case DEBOUNCE_EVENT_TIMEOUT:
debounce_set_state(fallback, DEBOUNCE_STATE_IS_DOWN);
break;
case DEBOUNCE_EVENT_TIMEOUT_SHORT:
log_debounce_bug(fallback, event);
break;
case DEBOUNCE_EVENT_OTHERBUTTON:
debounce_set_state(fallback, DEBOUNCE_STATE_IS_DOWN);
break;
}
}
static void
debounce_is_up_delaying_handle_event(struct fallback_dispatch *fallback, enum debounce_event event, uint64_t time)
{
switch (event) {
case DEBOUNCE_EVENT_PRESS:
debounce_set_timer(fallback, time);
debounce_set_state(fallback, DEBOUNCE_STATE_IS_DOWN_WAITING);
break;
case DEBOUNCE_EVENT_RELEASE:
case DEBOUNCE_EVENT_TIMEOUT_SHORT:
log_debounce_bug(fallback, event);
break;
case DEBOUNCE_EVENT_TIMEOUT:
case DEBOUNCE_EVENT_OTHERBUTTON:
debounce_set_state(fallback, DEBOUNCE_STATE_IS_UP);
debounce_notify_button(fallback,
LIBINPUT_BUTTON_STATE_RELEASED);
break;
}
}
static void
debounce_is_up_delaying_spurious_handle_event(struct fallback_dispatch *fallback, enum debounce_event event, uint64_t time)
{
switch (event) {
case DEBOUNCE_EVENT_PRESS:
debounce_set_state(fallback, DEBOUNCE_STATE_IS_DOWN);
debounce_cancel_timer(fallback);
debounce_cancel_timer_short(fallback);
break;
case DEBOUNCE_EVENT_RELEASE:
case DEBOUNCE_EVENT_TIMEOUT:
log_debounce_bug(fallback, event);
break;
case DEBOUNCE_EVENT_TIMEOUT_SHORT:
debounce_set_state(fallback, DEBOUNCE_STATE_IS_UP_WAITING);
debounce_notify_button(fallback,
LIBINPUT_BUTTON_STATE_RELEASED);
break;
case DEBOUNCE_EVENT_OTHERBUTTON:
debounce_set_state(fallback, DEBOUNCE_STATE_IS_UP);
debounce_notify_button(fallback,
LIBINPUT_BUTTON_STATE_RELEASED);
break;
}
}
static void
debounce_is_up_detecting_spurious_handle_event(struct fallback_dispatch *fallback, enum debounce_event event, uint64_t time)
{
switch (event) {
case DEBOUNCE_EVENT_PRESS:
debounce_set_timer(fallback, time);
debounce_set_timer_short(fallback, time);
/* Note: in a bouncing PRP case, we use the last press
* event time */
fallback->debounce.button_time = time;
debounce_set_state(fallback, DEBOUNCE_STATE_IS_DOWN_DETECTING_SPURIOUS);
break;
case DEBOUNCE_EVENT_RELEASE:
log_debounce_bug(fallback, event);
break;
case DEBOUNCE_EVENT_TIMEOUT:
debounce_set_state(fallback, DEBOUNCE_STATE_IS_UP);
break;
case DEBOUNCE_EVENT_TIMEOUT_SHORT:
debounce_set_state(fallback, DEBOUNCE_STATE_IS_UP_WAITING);
break;
case DEBOUNCE_EVENT_OTHERBUTTON:
debounce_set_state(fallback, DEBOUNCE_STATE_IS_UP);
break;
}
}
static void
debounce_is_down_detecting_spurious_handle_event(struct fallback_dispatch *fallback, enum debounce_event event, uint64_t time)
{
switch (event) {
case DEBOUNCE_EVENT_PRESS:
log_debounce_bug(fallback, event);
break;
case DEBOUNCE_EVENT_RELEASE:
debounce_set_timer(fallback, time);
debounce_set_timer_short(fallback, time);
debounce_set_state(fallback, DEBOUNCE_STATE_IS_UP_DETECTING_SPURIOUS);
break;
case DEBOUNCE_EVENT_TIMEOUT_SHORT:
debounce_cancel_timer(fallback);
debounce_set_state(fallback, DEBOUNCE_STATE_IS_DOWN);
debounce_enable_spurious(fallback);
debounce_notify_button(fallback,
LIBINPUT_BUTTON_STATE_PRESSED);
break;
case DEBOUNCE_EVENT_TIMEOUT:
case DEBOUNCE_EVENT_OTHERBUTTON:
debounce_set_state(fallback, DEBOUNCE_STATE_IS_DOWN);
debounce_notify_button(fallback,
LIBINPUT_BUTTON_STATE_PRESSED);
break;
}
}
static void
debounce_is_up_waiting_handle_event(struct fallback_dispatch *fallback, enum debounce_event event, uint64_t time)
{
switch (event) {
case DEBOUNCE_EVENT_PRESS:
debounce_set_timer(fallback, time);
/* Note: in a debouncing PRP case, we use the last press'
* time */
fallback->debounce.button_time = time;
debounce_set_state(fallback, DEBOUNCE_STATE_IS_DOWN_DELAYING);
break;
case DEBOUNCE_EVENT_RELEASE:
case DEBOUNCE_EVENT_TIMEOUT_SHORT:
log_debounce_bug(fallback, event);
break;
case DEBOUNCE_EVENT_TIMEOUT:
case DEBOUNCE_EVENT_OTHERBUTTON:
debounce_set_state(fallback, DEBOUNCE_STATE_IS_UP);
break;
}
}
static void
debounce_is_down_delaying_handle_event(struct fallback_dispatch *fallback, enum debounce_event event, uint64_t time)
{
switch (event) {
case DEBOUNCE_EVENT_PRESS:
log_debounce_bug(fallback, event);
break;
case DEBOUNCE_EVENT_RELEASE:
debounce_set_timer(fallback, time);
debounce_set_state(fallback, DEBOUNCE_STATE_IS_UP_WAITING);
break;
case DEBOUNCE_EVENT_TIMEOUT_SHORT:
log_debounce_bug(fallback, event);
break;
case DEBOUNCE_EVENT_TIMEOUT:
case DEBOUNCE_EVENT_OTHERBUTTON:
debounce_set_state(fallback, DEBOUNCE_STATE_IS_DOWN);
debounce_notify_button(fallback,
LIBINPUT_BUTTON_STATE_PRESSED);
break;
}
}
static void
debounce_disabled_handle_event(struct fallback_dispatch *fallback,
enum debounce_event event,
uint64_t time)
{
switch (event) {
case DEBOUNCE_EVENT_PRESS:
fallback->debounce.button_time = time;
debounce_notify_button(fallback,
LIBINPUT_BUTTON_STATE_PRESSED);
break;
case DEBOUNCE_EVENT_RELEASE:
fallback->debounce.button_time = time;
debounce_notify_button(fallback,
LIBINPUT_BUTTON_STATE_RELEASED);
break;
case DEBOUNCE_EVENT_TIMEOUT_SHORT:
case DEBOUNCE_EVENT_TIMEOUT:
log_debounce_bug(fallback, event);
break;
case DEBOUNCE_EVENT_OTHERBUTTON:
break;
}
}
static void
debounce_handle_event(struct fallback_dispatch *fallback,
enum debounce_event event,
uint64_t time)
{
enum debounce_state current = fallback->debounce.state;
if (event == DEBOUNCE_EVENT_OTHERBUTTON) {
debounce_cancel_timer(fallback);
debounce_cancel_timer_short(fallback);
}
switch(current) {
case DEBOUNCE_STATE_IS_UP:
debounce_is_up_handle_event(fallback, event, time);
break;
case DEBOUNCE_STATE_IS_DOWN:
debounce_is_down_handle_event(fallback, event, time);
break;
case DEBOUNCE_STATE_IS_DOWN_WAITING:
debounce_is_down_waiting_handle_event(fallback, event, time);
break;
case DEBOUNCE_STATE_IS_UP_DELAYING:
debounce_is_up_delaying_handle_event(fallback, event, time);
break;
case DEBOUNCE_STATE_IS_UP_DELAYING_SPURIOUS:
debounce_is_up_delaying_spurious_handle_event(fallback, event, time);
break;
case DEBOUNCE_STATE_IS_UP_DETECTING_SPURIOUS:
debounce_is_up_detecting_spurious_handle_event(fallback, event, time);
break;
case DEBOUNCE_STATE_IS_DOWN_DETECTING_SPURIOUS:
debounce_is_down_detecting_spurious_handle_event(fallback, event, time);
break;
case DEBOUNCE_STATE_IS_UP_WAITING:
debounce_is_up_waiting_handle_event(fallback, event, time);
break;
case DEBOUNCE_STATE_IS_DOWN_DELAYING:
debounce_is_down_delaying_handle_event(fallback, event, time);
break;
case DEBOUNCE_STATE_DISABLED:
debounce_disabled_handle_event(fallback, event, time);
break;
}
evdev_log_debug(fallback->device,
"debounce state: %s → %s → %s\n",
debounce_state_to_str(current),
debounce_event_to_str(event),
debounce_state_to_str(fallback->debounce.state));
}
void
fallback_debounce_handle_state(struct fallback_dispatch *dispatch,
uint64_t time)
{
unsigned int changed[16] = {0}; /* event codes of changed buttons */
size_t nchanged = 0;
bool flushed = false;
for (unsigned int code = 0; code <= KEY_MAX; code++) {
if (get_key_type(code) != KEY_TYPE_BUTTON)
continue;
if (hw_key_has_changed(dispatch, code))
changed[nchanged++] = code;
/* If you manage to press more than 16 buttons in the same
* frame, we just quietly ignore the rest of them */
if (nchanged == ARRAY_LENGTH(changed))
break;
}
/* If we have more than one button this frame or a different button,
* flush the state machine with otherbutton */
if (nchanged > 1 ||
changed[0] != dispatch->debounce.button_code) {
debounce_handle_event(dispatch,
DEBOUNCE_EVENT_OTHERBUTTON,
time);
flushed = true;
}
/* The state machine has some pre-conditions:
* - the IS_DOWN and IS_UP states are neutral entry states without
* any timeouts
* - a OTHERBUTTON event always flushes the state to IS_DOWN or
* IS_UP
*/
for (size_t i = 0; i < nchanged; i++) {
bool is_down = hw_is_key_down(dispatch, changed[i]);
if (flushed &&
dispatch->debounce.state != DEBOUNCE_STATE_DISABLED) {
debounce_set_state(dispatch,
!is_down ?
DEBOUNCE_STATE_IS_DOWN :
DEBOUNCE_STATE_IS_UP);
flushed = false;
}
dispatch->debounce.button_code = changed[i];
debounce_handle_event(dispatch,
is_down ?
DEBOUNCE_EVENT_PRESS :
DEBOUNCE_EVENT_RELEASE,
time);
/* if we have more than one event, we flush the state
* machine immediately after the event itself */
if (nchanged > 1) {
debounce_handle_event(dispatch,
DEBOUNCE_EVENT_OTHERBUTTON,
time);
flushed = true;
}
}
}
static void
debounce_timeout(uint64_t now, void *data)
{
struct evdev_device *device = data;
struct fallback_dispatch *dispatch =
fallback_dispatch(device->dispatch);
debounce_handle_event(dispatch, DEBOUNCE_EVENT_TIMEOUT, now);
}
static void
debounce_timeout_short(uint64_t now, void *data)
{
struct evdev_device *device = data;
struct fallback_dispatch *dispatch =
fallback_dispatch(device->dispatch);
debounce_handle_event(dispatch, DEBOUNCE_EVENT_TIMEOUT_SHORT, now);
}
void
fallback_init_debounce(struct fallback_dispatch *dispatch)
{
struct evdev_device *device = dispatch->device;
char timer_name[64];
if (evdev_device_has_model_quirk(device, QUIRK_MODEL_BOUNCING_KEYS)) {
dispatch->debounce.state = DEBOUNCE_STATE_DISABLED;
return;
}
dispatch->debounce.state = DEBOUNCE_STATE_IS_UP;
snprintf(timer_name,
sizeof(timer_name),
"%s debounce short",
evdev_device_get_sysname(device));
libinput_timer_init(&dispatch->debounce.timer_short,
evdev_libinput_context(device),
timer_name,
debounce_timeout_short,
device);
snprintf(timer_name,
sizeof(timer_name),
"%s debounce",
evdev_device_get_sysname(device));
libinput_timer_init(&dispatch->debounce.timer,
evdev_libinput_context(device),
timer_name,
debounce_timeout,
device);
}
libinput-1.28.1/src/evdev-fallback.c000066400000000000000000001302221477265155700172550ustar00rootroot00000000000000/*
* Copyright © 2010 Intel Corporation
* Copyright © 2013 Jonas Ådahl
* Copyright © 2013-2017 Red Hat, Inc.
* Copyright © 2017 James Ye
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice (including the next
* paragraph) shall be included in all copies or substantial portions of the
* Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
*/
#include "config.h"
#include
#include "evdev-fallback.h"
#include "util-input-event.h"
static void
fallback_keyboard_notify_key(struct fallback_dispatch *dispatch,
struct evdev_device *device,
uint64_t time,
int key,
enum libinput_key_state state)
{
int down_count;
down_count = evdev_update_key_down_count(device, key, state);
if ((state == LIBINPUT_KEY_STATE_PRESSED && down_count == 1) ||
(state == LIBINPUT_KEY_STATE_RELEASED && down_count == 0))
keyboard_notify_key(&device->base, time, key, state);
}
static void
fallback_lid_notify_toggle(struct fallback_dispatch *dispatch,
struct evdev_device *device,
uint64_t time)
{
if (dispatch->lid.is_closed ^ dispatch->lid.is_closed_client_state) {
switch_notify_toggle(&device->base,
time,
LIBINPUT_SWITCH_LID,
dispatch->lid.is_closed);
dispatch->lid.is_closed_client_state = dispatch->lid.is_closed;
}
}
void
fallback_notify_physical_button(struct fallback_dispatch *dispatch,
struct evdev_device *device,
uint64_t time,
int button,
enum libinput_button_state state)
{
evdev_pointer_notify_physical_button(device, time, button, state);
}
static enum libinput_switch_state
fallback_interface_get_switch_state(struct evdev_dispatch *evdev_dispatch,
enum libinput_switch sw)
{
struct fallback_dispatch *dispatch = fallback_dispatch(evdev_dispatch);
switch (sw) {
case LIBINPUT_SWITCH_TABLET_MODE:
break;
default:
/* Internal function only, so we can abort here */
abort();
}
return dispatch->tablet_mode.sw.state ?
LIBINPUT_SWITCH_STATE_ON :
LIBINPUT_SWITCH_STATE_OFF;
}
static inline bool
post_button_scroll(struct evdev_device *device,
struct device_float_coords raw,
uint64_t time)
{
if (device->scroll.method != LIBINPUT_CONFIG_SCROLL_ON_BUTTON_DOWN)
return false;
switch(device->scroll.button_scroll_state) {
case BUTTONSCROLL_IDLE:
return false;
case BUTTONSCROLL_BUTTON_DOWN:
/* if the button is down but scroll is not active, we're within the
timeout where we swallow motion events but don't post
scroll buttons */
evdev_log_debug(device, "btnscroll: discarding\n");
return true;
case BUTTONSCROLL_READY:
device->scroll.button_scroll_state = BUTTONSCROLL_SCROLLING;
_fallthrough_;
case BUTTONSCROLL_SCROLLING:
{
const struct normalized_coords normalized =
filter_dispatch_scroll(device->pointer.filter,
&raw,
device,
time);
evdev_post_scroll(device, time,
LIBINPUT_POINTER_AXIS_SOURCE_CONTINUOUS,
&normalized);
}
return true;
}
assert(!"invalid scroll button state");
}
static inline bool
fallback_filter_defuzz_touch(struct fallback_dispatch *dispatch,
struct evdev_device *device,
struct mt_slot *slot)
{
struct device_coords point;
if (!dispatch->mt.want_hysteresis)
return false;
point = evdev_hysteresis(&slot->point,
&slot->hysteresis_center,
&dispatch->mt.hysteresis_margin);
slot->point = point;
if (point.x == slot->hysteresis_center.x &&
point.y == slot->hysteresis_center.y)
return true;
slot->hysteresis_center = point;
return false;
}
static inline struct device_float_coords
fallback_rotate_relative(struct fallback_dispatch *dispatch,
struct evdev_device *device)
{
struct device_float_coords rel = { dispatch->rel.x, dispatch->rel.y };
if (!device->base.config.rotation)
return rel;
matrix_mult_vec_double(&dispatch->rotation.matrix, &rel.x, &rel.y);
return rel;
}
static void
fallback_flush_relative_motion(struct fallback_dispatch *dispatch,
struct evdev_device *device,
uint64_t time)
{
struct libinput_device *base = &device->base;
struct normalized_coords accel;
if (!(device->seat_caps & EVDEV_DEVICE_POINTER))
return;
struct device_float_coords raw = fallback_rotate_relative(dispatch, device);
dispatch->rel.x = 0;
dispatch->rel.y = 0;
/* Use unaccelerated deltas for pointing stick scroll */
if (post_button_scroll(device, raw, time))
return;
if (device->pointer.filter) {
/* Apply pointer acceleration. */
accel = filter_dispatch(device->pointer.filter,
&raw,
device,
time);
} else {
evdev_log_bug_libinput(device,
"accel filter missing\n");
accel.x = accel.y = 0;
}
if (normalized_is_zero(accel))
return;
pointer_notify_motion(base, time, &accel, &raw);
}
static void
fallback_flush_absolute_motion(struct fallback_dispatch *dispatch,
struct evdev_device *device,
uint64_t time)
{
struct libinput_device *base = &device->base;
struct device_coords point;
if (!(device->seat_caps & EVDEV_DEVICE_POINTER))
return;
point = dispatch->abs.point;
evdev_transform_absolute(device, &point);
pointer_notify_motion_absolute(base, time, &point);
}
static bool
fallback_flush_mt_down(struct fallback_dispatch *dispatch,
struct evdev_device *device,
int slot_idx,
uint64_t time)
{
struct libinput_device *base = &device->base;
struct libinput_seat *seat = base->seat;
struct device_coords point;
struct mt_slot *slot;
int seat_slot;
if (!(device->seat_caps & EVDEV_DEVICE_TOUCH))
return false;
slot = &dispatch->mt.slots[slot_idx];
if (slot->seat_slot != -1) {
evdev_log_bug_kernel(device,
"driver sent multiple touch down for the same slot");
return false;
}
seat_slot = ffs(~seat->slot_map) - 1;
slot->seat_slot = seat_slot;
if (seat_slot == -1)
return false;
seat->slot_map |= bit(seat_slot);
point = slot->point;
slot->hysteresis_center = point;
evdev_transform_absolute(device, &point);
touch_notify_touch_down(base, time, slot_idx, seat_slot,
&point);
return true;
}
static bool
fallback_flush_mt_motion(struct fallback_dispatch *dispatch,
struct evdev_device *device,
int slot_idx,
uint64_t time)
{
struct libinput_device *base = &device->base;
struct device_coords point;
struct mt_slot *slot;
int seat_slot;
if (!(device->seat_caps & EVDEV_DEVICE_TOUCH))
return false;
slot = &dispatch->mt.slots[slot_idx];
seat_slot = slot->seat_slot;
point = slot->point;
if (seat_slot == -1)
return false;
if (fallback_filter_defuzz_touch(dispatch, device, slot))
return false;
evdev_transform_absolute(device, &point);
touch_notify_touch_motion(base, time, slot_idx, seat_slot,
&point);
return true;
}
static bool
fallback_flush_mt_up(struct fallback_dispatch *dispatch,
struct evdev_device *device,
int slot_idx,
uint64_t time)
{
struct libinput_device *base = &device->base;
struct libinput_seat *seat = base->seat;
struct mt_slot *slot;
int seat_slot;
if (!(device->seat_caps & EVDEV_DEVICE_TOUCH))
return false;
slot = &dispatch->mt.slots[slot_idx];
seat_slot = slot->seat_slot;
slot->seat_slot = -1;
if (seat_slot == -1)
return false;
seat->slot_map &= ~bit(seat_slot);
touch_notify_touch_up(base, time, slot_idx, seat_slot);
return true;
}
static bool
fallback_flush_mt_cancel(struct fallback_dispatch *dispatch,
struct evdev_device *device,
int slot_idx,
uint64_t time)
{
struct libinput_device *base = &device->base;
struct libinput_seat *seat = base->seat;
struct mt_slot *slot;
int seat_slot;
if (!(device->seat_caps & EVDEV_DEVICE_TOUCH))
return false;
slot = &dispatch->mt.slots[slot_idx];
seat_slot = slot->seat_slot;
slot->seat_slot = -1;
if (seat_slot == -1)
return false;
seat->slot_map &= ~bit(seat_slot);
touch_notify_touch_cancel(base, time, slot_idx, seat_slot);
return true;
}
static bool
fallback_flush_st_down(struct fallback_dispatch *dispatch,
struct evdev_device *device,
uint64_t time)
{
struct libinput_device *base = &device->base;
struct libinput_seat *seat = base->seat;
struct device_coords point;
int seat_slot;
if (!(device->seat_caps & EVDEV_DEVICE_TOUCH))
return false;
if (dispatch->abs.seat_slot != -1) {
evdev_log_bug_kernel(device,
"driver sent multiple touch down for the same slot");
return false;
}
seat_slot = ffs(~seat->slot_map) - 1;
dispatch->abs.seat_slot = seat_slot;
if (seat_slot == -1)
return false;
seat->slot_map |= bit(seat_slot);
point = dispatch->abs.point;
evdev_transform_absolute(device, &point);
touch_notify_touch_down(base, time, -1, seat_slot, &point);
return true;
}
static bool
fallback_flush_st_motion(struct fallback_dispatch *dispatch,
struct evdev_device *device,
uint64_t time)
{
struct libinput_device *base = &device->base;
struct device_coords point;
int seat_slot;
point = dispatch->abs.point;
evdev_transform_absolute(device, &point);
seat_slot = dispatch->abs.seat_slot;
if (seat_slot == -1)
return false;
touch_notify_touch_motion(base, time, -1, seat_slot, &point);
return true;
}
static bool
fallback_flush_st_up(struct fallback_dispatch *dispatch,
struct evdev_device *device,
uint64_t time)
{
struct libinput_device *base = &device->base;
struct libinput_seat *seat = base->seat;
int seat_slot;
if (!(device->seat_caps & EVDEV_DEVICE_TOUCH))
return false;
seat_slot = dispatch->abs.seat_slot;
dispatch->abs.seat_slot = -1;
if (seat_slot == -1)
return false;
seat->slot_map &= ~bit(seat_slot);
touch_notify_touch_up(base, time, -1, seat_slot);
return true;
}
static bool
fallback_flush_st_cancel(struct fallback_dispatch *dispatch,
struct evdev_device *device,
uint64_t time)
{
struct libinput_device *base = &device->base;
struct libinput_seat *seat = base->seat;
int seat_slot;
if (!(device->seat_caps & EVDEV_DEVICE_TOUCH))
return false;
seat_slot = dispatch->abs.seat_slot;
dispatch->abs.seat_slot = -1;
if (seat_slot == -1)
return false;
seat->slot_map &= ~bit(seat_slot);
touch_notify_touch_cancel(base, time, -1, seat_slot);
return true;
}
static void
fallback_process_touch_button(struct fallback_dispatch *dispatch,
struct evdev_device *device,
uint64_t time, int value)
{
dispatch->pending_event |= (value) ?
EVDEV_ABSOLUTE_TOUCH_DOWN :
EVDEV_ABSOLUTE_TOUCH_UP;
}
static inline void
fallback_process_key(struct fallback_dispatch *dispatch,
struct evdev_device *device,
struct input_event *e, uint64_t time)
{
enum key_type type;
/* ignore kernel key repeat */
if (e->value == 2)
return;
if (e->code == BTN_TOUCH) {
if (!device->is_mt)
fallback_process_touch_button(dispatch,
device,
time,
e->value);
return;
}
type = get_key_type(e->code);
/* Ignore key release events from the kernel for keys that libinput
* never got a pressed event for or key presses for keys that we
* think are still down */
switch (type) {
case KEY_TYPE_NONE:
break;
case KEY_TYPE_KEY:
case KEY_TYPE_BUTTON:
if ((e->value && hw_is_key_down(dispatch, e->code)) ||
(e->value == 0 && !hw_is_key_down(dispatch, e->code)))
return;
dispatch->pending_event |= EVDEV_KEY;
break;
}
hw_set_key_down(dispatch, e->code, e->value);
switch (type) {
case KEY_TYPE_NONE:
break;
case KEY_TYPE_KEY:
fallback_keyboard_notify_key(
dispatch,
device,
time,
e->code,
e->value ? LIBINPUT_KEY_STATE_PRESSED :
LIBINPUT_KEY_STATE_RELEASED);
break;
case KEY_TYPE_BUTTON:
break;
}
}
static void
fallback_process_touch(struct fallback_dispatch *dispatch,
struct evdev_device *device,
struct input_event *e,
uint64_t time)
{
struct mt_slot *slot = &dispatch->mt.slots[dispatch->mt.slot];
if (e->code == ABS_MT_SLOT) {
if ((size_t)e->value >= dispatch->mt.slots_len) {
evdev_log_bug_libinput(device,
"exceeded slot count (%d of max %zd)\n",
e->value,
dispatch->mt.slots_len);
e->value = dispatch->mt.slots_len - 1;
}
dispatch->mt.slot = e->value;
return;
}
switch (e->code) {
case ABS_MT_TRACKING_ID:
if (e->value >= 0) {
dispatch->pending_event |= EVDEV_ABSOLUTE_MT;
slot->state = SLOT_STATE_BEGIN;
if (dispatch->mt.has_palm) {
int v;
v = libevdev_get_slot_value(device->evdev,
dispatch->mt.slot,
ABS_MT_TOOL_TYPE);
switch (v) {
case MT_TOOL_PALM:
/* new touch, no cancel needed */
slot->palm_state = PALM_WAS_PALM;
break;
default:
slot->palm_state = PALM_NONE;
break;
}
} else {
slot->palm_state = PALM_NONE;
}
} else {
dispatch->pending_event |= EVDEV_ABSOLUTE_MT;
slot->state = SLOT_STATE_END;
}
slot->dirty = true;
break;
case ABS_MT_POSITION_X:
evdev_device_check_abs_axis_range(device, e->code, e->value);
dispatch->mt.slots[dispatch->mt.slot].point.x = e->value;
dispatch->pending_event |= EVDEV_ABSOLUTE_MT;
slot->dirty = true;
break;
case ABS_MT_POSITION_Y:
evdev_device_check_abs_axis_range(device, e->code, e->value);
dispatch->mt.slots[dispatch->mt.slot].point.y = e->value;
dispatch->pending_event |= EVDEV_ABSOLUTE_MT;
slot->dirty = true;
break;
case ABS_MT_TOOL_TYPE:
/* The transitions matter - we (may) need to send a touch
* cancel event if we just switched to a palm touch. And the
* kernel may switch back to finger but we keep the touch as
* palm - but then we need to reset correctly on a new touch
* sequence.
*/
switch (e->value) {
case MT_TOOL_PALM:
if (slot->palm_state == PALM_NONE)
slot->palm_state = PALM_NEW;
break;
default:
if (slot->palm_state == PALM_IS_PALM)
slot->palm_state = PALM_WAS_PALM;
break;
}
dispatch->pending_event |= EVDEV_ABSOLUTE_MT;
slot->dirty = true;
break;
}
}
static inline void
fallback_process_absolute_motion(struct fallback_dispatch *dispatch,
struct evdev_device *device,
struct input_event *e)
{
switch (e->code) {
case ABS_X:
evdev_device_check_abs_axis_range(device, e->code, e->value);
dispatch->abs.point.x = e->value;
dispatch->pending_event |= EVDEV_ABSOLUTE_MOTION;
break;
case ABS_Y:
evdev_device_check_abs_axis_range(device, e->code, e->value);
dispatch->abs.point.y = e->value;
dispatch->pending_event |= EVDEV_ABSOLUTE_MOTION;
break;
}
}
static void
fallback_lid_keyboard_event(uint64_t time,
struct libinput_event *event,
void *data)
{
struct fallback_dispatch *dispatch = fallback_dispatch(data);
if (!dispatch->lid.is_closed)
return;
if (event->type != LIBINPUT_EVENT_KEYBOARD_KEY)
return;
if (dispatch->lid.reliability == RELIABILITY_WRITE_OPEN) {
int fd = libevdev_get_fd(dispatch->device->evdev);
int rc;
struct input_event ev[2];
ev[0] = input_event_init(0, EV_SW, SW_LID, 0);
ev[1] = input_event_init(0, EV_SYN, SYN_REPORT, 0);
rc = write(fd, ev, sizeof(ev));
if (rc < 0)
evdev_log_error(dispatch->device,
"failed to write SW_LID state (%s)",
strerror(errno));
/* In case write() fails, we sync the lid state manually
* regardless. */
}
/* Posting the event here means we preempt the keyboard events that
* caused us to wake up, so the lid event is always passed on before
* the key event.
*/
dispatch->lid.is_closed = false;
fallback_lid_notify_toggle(dispatch, dispatch->device, time);
}
static void
fallback_lid_toggle_keyboard_listener(struct fallback_dispatch *dispatch,
struct evdev_paired_keyboard *kbd,
bool is_closed)
{
assert(kbd->device);
libinput_device_remove_event_listener(&kbd->listener);
if (is_closed) {
libinput_device_add_event_listener(
&kbd->device->base,
&kbd->listener,
fallback_lid_keyboard_event,
dispatch);
} else {
libinput_device_init_event_listener(&kbd->listener);
}
}
static void
fallback_lid_toggle_keyboard_listeners(struct fallback_dispatch *dispatch,
bool is_closed)
{
struct evdev_paired_keyboard *kbd;
list_for_each(kbd, &dispatch->lid.paired_keyboard_list, link) {
if (!kbd->device)
continue;
fallback_lid_toggle_keyboard_listener(dispatch,
kbd,
is_closed);
}
}
static inline void
fallback_process_switch(struct fallback_dispatch *dispatch,
struct evdev_device *device,
struct input_event *e,
uint64_t time)
{
enum libinput_switch_state state;
bool is_closed;
/* TODO: this should to move to handle_state */
switch (e->code) {
case SW_LID:
is_closed = !!e->value;
fallback_lid_toggle_keyboard_listeners(dispatch, is_closed);
if (dispatch->lid.is_closed == is_closed)
return;
dispatch->lid.is_closed = is_closed;
fallback_lid_notify_toggle(dispatch, device, time);
break;
case SW_TABLET_MODE:
if (dispatch->tablet_mode.sw.state == e->value)
return;
dispatch->tablet_mode.sw.state = e->value;
if (e->value)
state = LIBINPUT_SWITCH_STATE_ON;
else
state = LIBINPUT_SWITCH_STATE_OFF;
switch_notify_toggle(&device->base,
time,
LIBINPUT_SWITCH_TABLET_MODE,
state);
break;
}
}
static inline bool
fallback_reject_relative(struct evdev_device *device,
const struct input_event *e,
uint64_t time)
{
if ((e->code == REL_X || e->code == REL_Y) &&
(device->seat_caps & EVDEV_DEVICE_POINTER) == 0) {
evdev_log_bug_libinput_ratelimit(device,
&device->nonpointer_rel_limit,
"REL_X/Y from a non-pointer device\n");
return true;
}
return false;
}
static inline void
fallback_process_relative(struct fallback_dispatch *dispatch,
struct evdev_device *device,
struct input_event *e, uint64_t time)
{
if (fallback_reject_relative(device, e, time))
return;
switch (e->code) {
case REL_X:
dispatch->rel.x += e->value;
dispatch->pending_event |= EVDEV_RELATIVE_MOTION;
break;
case REL_Y:
dispatch->rel.y += e->value;
dispatch->pending_event |= EVDEV_RELATIVE_MOTION;
break;
}
fallback_wheel_process_relative(dispatch, device, e, time);
}
static inline void
fallback_process_absolute(struct fallback_dispatch *dispatch,
struct evdev_device *device,
struct input_event *e,
uint64_t time)
{
if (device->is_mt) {
fallback_process_touch(dispatch, device, e, time);
} else {
fallback_process_absolute_motion(dispatch, device, e);
}
}
static inline bool
fallback_any_button_down(struct fallback_dispatch *dispatch,
struct evdev_device *device)
{
unsigned int button;
for (button = BTN_LEFT; button < BTN_JOYSTICK; button++) {
if (libevdev_has_event_code(device->evdev, EV_KEY, button) &&
hw_is_key_down(dispatch, button))
return true;
}
return false;
}
static inline bool
fallback_arbitrate_touch(struct fallback_dispatch *dispatch,
struct mt_slot *slot)
{
bool discard = false;
struct device_coords point = slot->point;
evdev_transform_absolute(dispatch->device, &point);
if (dispatch->arbitration.state == ARBITRATION_IGNORE_RECT &&
point_in_rect(&point, &dispatch->arbitration.rect)) {
slot->palm_state = PALM_IS_PALM;
discard = true;
}
return discard;
}
static inline bool
fallback_flush_mt_events(struct fallback_dispatch *dispatch,
struct evdev_device *device,
uint64_t time)
{
bool sent = false;
for (size_t i = 0; i < dispatch->mt.slots_len; i++) {
struct mt_slot *slot = &dispatch->mt.slots[i];
if (!slot->dirty)
continue;
slot->dirty = false;
/* Any palm state other than PALM_NEW means we've either
* already cancelled the touch or the touch was never
* a finger anyway and we didn't send the begin.
*/
if (slot->palm_state == PALM_NEW) {
if (slot->state != SLOT_STATE_BEGIN)
sent = fallback_flush_mt_cancel(dispatch,
device,
i,
time);
slot->palm_state = PALM_IS_PALM;
} else if (slot->palm_state == PALM_NONE) {
switch (slot->state) {
case SLOT_STATE_BEGIN:
if (!fallback_arbitrate_touch(dispatch,
slot)) {
sent = fallback_flush_mt_down(dispatch,
device,
i,
time);
}
break;
case SLOT_STATE_UPDATE:
sent = fallback_flush_mt_motion(dispatch,
device,
i,
time);
break;
case SLOT_STATE_END:
sent = fallback_flush_mt_up(dispatch,
device,
i,
time);
break;
case SLOT_STATE_NONE:
break;
}
}
/* State machine continues independent of the palm state */
switch (slot->state) {
case SLOT_STATE_BEGIN:
slot->state = SLOT_STATE_UPDATE;
break;
case SLOT_STATE_UPDATE:
break;
case SLOT_STATE_END:
slot->state = SLOT_STATE_NONE;
break;
case SLOT_STATE_NONE:
/* touch arbitration may swallow the begin,
* so we may get updates for a touch still
* in NONE state */
break;
}
}
return sent;
}
static void
fallback_handle_state(struct fallback_dispatch *dispatch,
struct evdev_device *device,
uint64_t time)
{
bool need_touch_frame = false;
/* Relative motion */
if (dispatch->pending_event & EVDEV_RELATIVE_MOTION)
fallback_flush_relative_motion(dispatch, device, time);
/* Single touch or absolute pointer devices */
if (dispatch->pending_event & EVDEV_ABSOLUTE_TOUCH_DOWN) {
if (fallback_flush_st_down(dispatch, device, time))
need_touch_frame = true;
} else if (dispatch->pending_event & EVDEV_ABSOLUTE_MOTION) {
if (device->seat_caps & EVDEV_DEVICE_TOUCH) {
if (fallback_flush_st_motion(dispatch,
device,
time))
need_touch_frame = true;
} else if (device->seat_caps & EVDEV_DEVICE_POINTER) {
fallback_flush_absolute_motion(dispatch,
device,
time);
}
}
if (dispatch->pending_event & EVDEV_ABSOLUTE_TOUCH_UP) {
if (fallback_flush_st_up(dispatch, device, time))
need_touch_frame = true;
}
/* Multitouch devices */
if (dispatch->pending_event & EVDEV_ABSOLUTE_MT)
need_touch_frame = fallback_flush_mt_events(dispatch,
device,
time);
if (need_touch_frame)
touch_notify_frame(&device->base, time);
fallback_wheel_handle_state(dispatch, device, time);
/* Buttons and keys */
if (dispatch->pending_event & EVDEV_KEY) {
bool want_debounce = false;
for (unsigned int code = 0; code <= KEY_MAX; code++) {
if (!hw_key_has_changed(dispatch, code))
continue;
if (get_key_type(code) == KEY_TYPE_BUTTON) {
want_debounce = true;
break;
}
}
if (want_debounce)
fallback_debounce_handle_state(dispatch, time);
hw_key_update_last_state(dispatch);
}
dispatch->pending_event = EVDEV_NONE;
}
static void
fallback_interface_process(struct evdev_dispatch *evdev_dispatch,
struct evdev_device *device,
struct input_event *event,
uint64_t time)
{
struct fallback_dispatch *dispatch = fallback_dispatch(evdev_dispatch);
static bool warned = false;
if (dispatch->arbitration.in_arbitration) {
if (!warned) {
evdev_log_debug(device, "dropping events due to touch arbitration\n");
warned = true;
}
return;
}
warned = false;
switch (event->type) {
case EV_REL:
fallback_process_relative(dispatch, device, event, time);
break;
case EV_ABS:
fallback_process_absolute(dispatch, device, event, time);
break;
case EV_KEY:
fallback_process_key(dispatch, device, event, time);
break;
case EV_SW:
fallback_process_switch(dispatch, device, event, time);
break;
case EV_SYN:
fallback_handle_state(dispatch, device, time);
break;
}
}
static void
cancel_touches(struct fallback_dispatch *dispatch,
struct evdev_device *device,
const struct device_coord_rect *rect,
uint64_t time)
{
unsigned int idx;
bool need_frame = false;
struct device_coords point;
point = dispatch->abs.point;
evdev_transform_absolute(device, &point);
if (!rect || point_in_rect(&point, rect))
need_frame = fallback_flush_st_cancel(dispatch,
device,
time);
for (idx = 0; idx < dispatch->mt.slots_len; idx++) {
struct mt_slot *slot = &dispatch->mt.slots[idx];
point = slot->point;
evdev_transform_absolute(device, &point);
if (slot->seat_slot == -1)
continue;
if ((!rect || point_in_rect(&point, rect)) &&
fallback_flush_mt_cancel(dispatch, device, idx, time))
need_frame = true;
}
if (need_frame)
touch_notify_frame(&device->base, time);
}
static void
release_pressed_keys(struct fallback_dispatch *dispatch,
struct evdev_device *device,
uint64_t time)
{
int code;
for (code = 0; code < KEY_CNT; code++) {
int count = get_key_down_count(device, code);
if (count == 0)
continue;
if (count > 1) {
evdev_log_bug_libinput(device,
"key %d is down %d times.\n",
code,
count);
}
switch (get_key_type(code)) {
case KEY_TYPE_NONE:
break;
case KEY_TYPE_KEY:
fallback_keyboard_notify_key(
dispatch,
device,
time,
code,
LIBINPUT_KEY_STATE_RELEASED);
break;
case KEY_TYPE_BUTTON:
/* Note: the left-handed configuration is nonzero for
* the mapped button (not the physical button), in
* get_key_down_count(). We must not map this to left-handed
* again, see #881.
*/
evdev_pointer_notify_button(
device,
time,
code,
LIBINPUT_BUTTON_STATE_RELEASED);
break;
}
count = get_key_down_count(device, code);
if (count != 0) {
evdev_log_bug_libinput(device,
"releasing key %d failed.\n",
code);
break;
}
}
}
static void
fallback_return_to_neutral_state(struct fallback_dispatch *dispatch,
struct evdev_device *device)
{
struct libinput *libinput = evdev_libinput_context(device);
uint64_t time;
if ((time = libinput_now(libinput)) == 0)
return;
cancel_touches(dispatch, device, NULL, time);
release_pressed_keys(dispatch, device, time);
memset(dispatch->hw_key_mask, 0, sizeof(dispatch->hw_key_mask));
memset(dispatch->hw_key_mask, 0, sizeof(dispatch->last_hw_key_mask));
}
static void
fallback_interface_suspend(struct evdev_dispatch *evdev_dispatch,
struct evdev_device *device)
{
struct fallback_dispatch *dispatch = fallback_dispatch(evdev_dispatch);
fallback_return_to_neutral_state(dispatch, device);
}
static void
fallback_interface_remove(struct evdev_dispatch *evdev_dispatch)
{
struct fallback_dispatch *dispatch = fallback_dispatch(evdev_dispatch);
struct evdev_paired_keyboard *kbd;
libinput_timer_cancel(&dispatch->wheel.scroll_timer);
libinput_timer_cancel(&dispatch->debounce.timer);
libinput_timer_cancel(&dispatch->debounce.timer_short);
libinput_timer_cancel(&dispatch->arbitration.arbitration_timer);
libinput_device_remove_event_listener(&dispatch->tablet_mode.other.listener);
list_for_each_safe(kbd,
&dispatch->lid.paired_keyboard_list,
link) {
evdev_paired_keyboard_destroy(kbd);
}
}
static void
fallback_interface_sync_initial_state(struct evdev_device *device,
struct evdev_dispatch *evdev_dispatch)
{
struct fallback_dispatch *dispatch = fallback_dispatch(evdev_dispatch);
uint64_t time = libinput_now(evdev_libinput_context(device));
if (device->tags & EVDEV_TAG_LID_SWITCH) {
struct libevdev *evdev = device->evdev;
dispatch->lid.is_closed = libevdev_get_event_value(evdev,
EV_SW,
SW_LID);
dispatch->lid.is_closed_client_state = false;
/* For the initial state sync, we depend on whether the lid switch
* is reliable. If we know it's reliable, we sync as expected.
* If we're not sure, we ignore the initial state and only sync on
* the first future lid close event. Laptops with a broken switch
* that always have the switch in 'on' state thus don't mess up our
* touchpad.
*/
if (dispatch->lid.is_closed &&
dispatch->lid.reliability == RELIABILITY_RELIABLE) {
fallback_lid_notify_toggle(dispatch, device, time);
}
}
if (dispatch->tablet_mode.sw.state) {
switch_notify_toggle(&device->base,
time,
LIBINPUT_SWITCH_TABLET_MODE,
LIBINPUT_SWITCH_STATE_ON);
}
}
static void
fallback_interface_update_rect(struct evdev_dispatch *evdev_dispatch,
struct evdev_device *device,
const struct phys_rect *phys_rect,
uint64_t time)
{
struct fallback_dispatch *dispatch = fallback_dispatch(evdev_dispatch);
struct device_coord_rect rect;
assert(phys_rect);
/* Existing touches do not change, we just update the rect and only
* new touches in these areas will be ignored. If you want to paint
* over your finger, be my guest. */
rect = evdev_phys_rect_to_units(device, phys_rect);
dispatch->arbitration.rect = rect;
}
static void
fallback_interface_toggle_touch(struct evdev_dispatch *evdev_dispatch,
struct evdev_device *device,
enum evdev_arbitration_state which,
const struct phys_rect *phys_rect,
uint64_t time)
{
struct fallback_dispatch *dispatch = fallback_dispatch(evdev_dispatch);
struct device_coord_rect rect = {0};
const char *state = NULL;
if (which == dispatch->arbitration.state)
return;
switch (which) {
case ARBITRATION_NOT_ACTIVE:
/* if in-kernel arbitration is in use and there is a touch
* and a pen in proximity, lifting the pen out of proximity
* causes a touch begin for the touch. On a hand-lift the
* proximity out precedes the touch up by a few ms, so we
* get what looks like a tap. Fix this by delaying
* arbitration by just a little bit so that any touch in
* event is caught as palm touch. */
libinput_timer_set(&dispatch->arbitration.arbitration_timer,
time + ms2us(90));
state = "not-active";
break;
case ARBITRATION_IGNORE_RECT:
assert(phys_rect);
rect = evdev_phys_rect_to_units(device, phys_rect);
cancel_touches(dispatch, device, &rect, time);
dispatch->arbitration.rect = rect;
state = "ignore-rect";
break;
case ARBITRATION_IGNORE_ALL:
libinput_timer_cancel(&dispatch->arbitration.arbitration_timer);
fallback_return_to_neutral_state(dispatch, device);
dispatch->arbitration.in_arbitration = true;
state = "ignore-all";
break;
}
evdev_log_debug(device, "Touch arbitration state now %s\n", state);
dispatch->arbitration.state = which;
}
static void
fallback_interface_destroy(struct evdev_dispatch *evdev_dispatch)
{
struct fallback_dispatch *dispatch = fallback_dispatch(evdev_dispatch);
libinput_timer_destroy(&dispatch->wheel.scroll_timer);
libinput_timer_destroy(&dispatch->arbitration.arbitration_timer);
libinput_timer_destroy(&dispatch->debounce.timer);
libinput_timer_destroy(&dispatch->debounce.timer_short);
free(dispatch->mt.slots);
free(dispatch);
}
static void
fallback_lid_pair_keyboard(struct evdev_device *lid_switch,
struct evdev_device *keyboard)
{
struct fallback_dispatch *dispatch =
fallback_dispatch(lid_switch->dispatch);
struct evdev_paired_keyboard *kbd;
size_t count = 0;
if ((keyboard->tags & EVDEV_TAG_KEYBOARD) == 0 ||
(lid_switch->tags & EVDEV_TAG_LID_SWITCH) == 0)
return;
if ((keyboard->tags & EVDEV_TAG_INTERNAL_KEYBOARD) == 0)
return;
list_for_each(kbd, &dispatch->lid.paired_keyboard_list, link) {
count++;
if (count > 3) {
evdev_log_info(lid_switch,
"lid: too many internal keyboards\n");
break;
}
}
kbd = zalloc(sizeof(*kbd));
kbd->device = keyboard;
libinput_device_init_event_listener(&kbd->listener);
list_insert(&dispatch->lid.paired_keyboard_list, &kbd->link);
evdev_log_debug(lid_switch,
"lid: keyboard paired with %s<->%s\n",
lid_switch->devname,
keyboard->devname);
/* We need to init the event listener now only if the
* reported state is closed. */
if (dispatch->lid.is_closed)
fallback_lid_toggle_keyboard_listener(dispatch,
kbd,
dispatch->lid.is_closed);
}
static void
fallback_resume(struct fallback_dispatch *dispatch,
struct evdev_device *device)
{
if (dispatch->base.sendevents.current_mode ==
LIBINPUT_CONFIG_SEND_EVENTS_DISABLED)
return;
evdev_device_resume(device);
}
static void
fallback_suspend(struct fallback_dispatch *dispatch,
struct evdev_device *device)
{
evdev_device_suspend(device);
}
static void
fallback_tablet_mode_switch_event(uint64_t time,
struct libinput_event *event,
void *data)
{
struct fallback_dispatch *dispatch = data;
struct evdev_device *device = dispatch->device;
struct libinput_event_switch *swev;
if (libinput_event_get_type(event) != LIBINPUT_EVENT_SWITCH_TOGGLE)
return;
swev = libinput_event_get_switch_event(event);
if (libinput_event_switch_get_switch(swev) !=
LIBINPUT_SWITCH_TABLET_MODE)
return;
switch (libinput_event_switch_get_switch_state(swev)) {
case LIBINPUT_SWITCH_STATE_OFF:
fallback_resume(dispatch, device);
evdev_log_debug(device, "tablet-mode: resuming device\n");
break;
case LIBINPUT_SWITCH_STATE_ON:
fallback_suspend(dispatch, device);
evdev_log_debug(device, "tablet-mode: suspending device\n");
break;
}
}
static void
fallback_pair_tablet_mode(struct evdev_device *keyboard,
struct evdev_device *tablet_mode_switch)
{
struct fallback_dispatch *dispatch =
fallback_dispatch(keyboard->dispatch);
if ((keyboard->tags & EVDEV_TAG_EXTERNAL_KEYBOARD))
return;
if ((keyboard->tags & EVDEV_TAG_TRACKPOINT)) {
if (keyboard->tags & EVDEV_TAG_EXTERNAL_MOUSE)
return;
/* This filters out all internal keyboard-like devices (Video
* Switch) */
} else if ((keyboard->tags & EVDEV_TAG_INTERNAL_KEYBOARD) == 0) {
return;
}
if (evdev_device_has_model_quirk(keyboard,
QUIRK_MODEL_TABLET_MODE_NO_SUSPEND))
return;
if ((tablet_mode_switch->tags & EVDEV_TAG_TABLET_MODE_SWITCH) == 0)
return;
if (dispatch->tablet_mode.other.sw_device)
return;
evdev_log_debug(keyboard,
"tablet-mode: paired %s<->%s\n",
keyboard->devname,
tablet_mode_switch->devname);
libinput_device_add_event_listener(&tablet_mode_switch->base,
&dispatch->tablet_mode.other.listener,
fallback_tablet_mode_switch_event,
dispatch);
dispatch->tablet_mode.other.sw_device = tablet_mode_switch;
if (evdev_device_switch_get_state(tablet_mode_switch,
LIBINPUT_SWITCH_TABLET_MODE)
== LIBINPUT_SWITCH_STATE_ON) {
evdev_log_debug(keyboard, "tablet-mode: suspending device\n");
fallback_suspend(dispatch, keyboard);
}
}
static void
fallback_interface_device_added(struct evdev_device *device,
struct evdev_device *added_device)
{
fallback_lid_pair_keyboard(device, added_device);
fallback_pair_tablet_mode(device, added_device);
}
static void
fallback_interface_device_removed(struct evdev_device *device,
struct evdev_device *removed_device)
{
struct fallback_dispatch *dispatch =
fallback_dispatch(device->dispatch);
struct evdev_paired_keyboard *kbd;
list_for_each_safe(kbd,
&dispatch->lid.paired_keyboard_list,
link) {
if (!kbd->device)
continue;
if (kbd->device != removed_device)
continue;
evdev_paired_keyboard_destroy(kbd);
}
if (removed_device == dispatch->tablet_mode.other.sw_device) {
libinput_device_remove_event_listener(
&dispatch->tablet_mode.other.listener);
libinput_device_init_event_listener(
&dispatch->tablet_mode.other.listener);
dispatch->tablet_mode.other.sw_device = NULL;
}
}
static struct evdev_dispatch_interface fallback_interface = {
.process = fallback_interface_process,
.suspend = fallback_interface_suspend,
.remove = fallback_interface_remove,
.destroy = fallback_interface_destroy,
.device_added = fallback_interface_device_added,
.device_removed = fallback_interface_device_removed,
.device_suspended = fallback_interface_device_removed, /* treat as remove */
.device_resumed = fallback_interface_device_added, /* treat as add */
.post_added = fallback_interface_sync_initial_state,
.touch_arbitration_toggle = fallback_interface_toggle_touch,
.touch_arbitration_update_rect = fallback_interface_update_rect,
.get_switch_state = fallback_interface_get_switch_state,
};
static void
fallback_change_to_left_handed(struct evdev_device *device)
{
struct fallback_dispatch *dispatch = fallback_dispatch(device->dispatch);
if (device->left_handed.want_enabled == device->left_handed.enabled)
return;
if (fallback_any_button_down(dispatch, device))
return;
device->left_handed.enabled = device->left_handed.want_enabled;
}
static void
fallback_change_scroll_method(struct evdev_device *device)
{
struct fallback_dispatch *dispatch = fallback_dispatch(device->dispatch);
if (device->scroll.want_method == device->scroll.method &&
device->scroll.want_button == device->scroll.button &&
device->scroll.want_lock_enabled == device->scroll.lock_enabled)
return;
if (fallback_any_button_down(dispatch, device))
return;
device->scroll.method = device->scroll.want_method;
device->scroll.button = device->scroll.want_button;
device->scroll.lock_enabled = device->scroll.want_lock_enabled;
evdev_set_button_scroll_lock_enabled(device, device->scroll.lock_enabled);
}
static int
fallback_rotation_config_is_available(struct libinput_device *device)
{
/* This function only gets called when we support rotation */
return 1;
}
static enum libinput_config_status
fallback_rotation_config_set_angle(struct libinput_device *libinput_device,
unsigned int degrees_cw)
{
struct evdev_device *device = evdev_device(libinput_device);
struct fallback_dispatch *dispatch = fallback_dispatch(device->dispatch);
dispatch->rotation.angle = degrees_cw;
matrix_init_rotate(&dispatch->rotation.matrix, degrees_cw);
return LIBINPUT_CONFIG_STATUS_SUCCESS;
}
static unsigned int
fallback_rotation_config_get_angle(struct libinput_device *libinput_device)
{
struct evdev_device *device = evdev_device(libinput_device);
struct fallback_dispatch *dispatch = fallback_dispatch(device->dispatch);
return dispatch->rotation.angle;
}
static unsigned int
fallback_rotation_config_get_default_angle(struct libinput_device *device)
{
return 0;
}
static void
fallback_init_rotation(struct fallback_dispatch *dispatch,
struct evdev_device *device)
{
if (device->tags & EVDEV_TAG_TRACKPOINT)
return;
dispatch->rotation.config.is_available = fallback_rotation_config_is_available;
dispatch->rotation.config.set_angle = fallback_rotation_config_set_angle;
dispatch->rotation.config.get_angle = fallback_rotation_config_get_angle;
dispatch->rotation.config.get_default_angle = fallback_rotation_config_get_default_angle;
matrix_init_identity(&dispatch->rotation.matrix);
device->base.config.rotation = &dispatch->rotation.config;
}
static inline int
fallback_dispatch_init_slots(struct fallback_dispatch *dispatch,
struct evdev_device *device)
{
struct libevdev *evdev = device->evdev;
struct mt_slot *slots;
int num_slots;
int active_slot;
int slot;
if (evdev_is_fake_mt_device(device) ||
!libevdev_has_event_code(evdev, EV_ABS, ABS_MT_POSITION_X) ||
!libevdev_has_event_code(evdev, EV_ABS, ABS_MT_POSITION_Y))
return 0;
/* We only handle the slotted Protocol B in libinput.
Devices with ABS_MT_POSITION_* but not ABS_MT_SLOT
require mtdev for conversion. */
if (evdev_need_mtdev(device)) {
device->mtdev = mtdev_new_open(device->fd);
if (!device->mtdev)
return -1;
/* pick 10 slots as default for type A
devices. */
num_slots = 10;
active_slot = device->mtdev->caps.slot.value;
} else {
num_slots = libevdev_get_num_slots(device->evdev);
active_slot = libevdev_get_current_slot(evdev);
}
slots = zalloc(num_slots * sizeof(struct mt_slot));
for (slot = 0; slot < num_slots; ++slot) {
slots[slot].seat_slot = -1;
if (evdev_need_mtdev(device))
continue;
slots[slot].point.x = libevdev_get_slot_value(evdev,
slot,
ABS_MT_POSITION_X);
slots[slot].point.y = libevdev_get_slot_value(evdev,
slot,
ABS_MT_POSITION_Y);
}
dispatch->mt.slots = slots;
dispatch->mt.slots_len = num_slots;
dispatch->mt.slot = active_slot;
dispatch->mt.has_palm = libevdev_has_event_code(evdev,
EV_ABS,
ABS_MT_TOOL_TYPE);
if (device->abs.absinfo_x->fuzz || device->abs.absinfo_y->fuzz) {
dispatch->mt.want_hysteresis = true;
dispatch->mt.hysteresis_margin.x = device->abs.absinfo_x->fuzz/2;
dispatch->mt.hysteresis_margin.y = device->abs.absinfo_y->fuzz/2;
}
return 0;
}
static inline void
fallback_dispatch_init_rel(struct fallback_dispatch *dispatch,
struct evdev_device *device)
{
dispatch->rel.x = 0;
dispatch->rel.y = 0;
}
static inline void
fallback_dispatch_init_abs(struct fallback_dispatch *dispatch,
struct evdev_device *device)
{
if (!libevdev_has_event_code(device->evdev, EV_ABS, ABS_X))
return;
dispatch->abs.point.x = device->abs.absinfo_x->value;
dispatch->abs.point.y = device->abs.absinfo_y->value;
dispatch->abs.seat_slot = -1;
evdev_device_init_abs_range_warnings(device);
}
static inline void
fallback_dispatch_init_switch(struct fallback_dispatch *dispatch,
struct evdev_device *device)
{
int val;
list_init(&dispatch->lid.paired_keyboard_list);
if (device->tags & EVDEV_TAG_LID_SWITCH) {
dispatch->lid.reliability = evdev_read_switch_reliability_prop(device);
dispatch->lid.is_closed = false;
}
if (device->tags & EVDEV_TAG_TABLET_MODE_SWITCH) {
val = libevdev_get_event_value(device->evdev,
EV_SW,
SW_TABLET_MODE);
dispatch->tablet_mode.sw.state = val;
}
libinput_device_init_event_listener(&dispatch->tablet_mode.other.listener);
}
static void
fallback_arbitration_timeout(uint64_t now, void *data)
{
struct fallback_dispatch *dispatch = data;
if (dispatch->arbitration.in_arbitration)
dispatch->arbitration.in_arbitration = false;
evdev_log_debug(dispatch->device, "touch arbitration timeout\n");
}
static void
fallback_init_arbitration(struct fallback_dispatch *dispatch,
struct evdev_device *device)
{
char timer_name[64];
snprintf(timer_name,
sizeof(timer_name),
"%s arbitration",
evdev_device_get_sysname(device));
libinput_timer_init(&dispatch->arbitration.arbitration_timer,
evdev_libinput_context(device),
timer_name,
fallback_arbitration_timeout,
dispatch);
dispatch->arbitration.in_arbitration = false;
}
struct evdev_dispatch *
fallback_dispatch_create(struct libinput_device *libinput_device)
{
struct evdev_device *device = evdev_device(libinput_device);
struct fallback_dispatch *dispatch;
dispatch = zalloc(sizeof *dispatch);
dispatch->device = evdev_device(libinput_device);
dispatch->base.dispatch_type = DISPATCH_FALLBACK;
dispatch->base.interface = &fallback_interface;
dispatch->pending_event = EVDEV_NONE;
list_init(&dispatch->lid.paired_keyboard_list);
fallback_dispatch_init_rel(dispatch, device);
fallback_dispatch_init_abs(dispatch, device);
if (fallback_dispatch_init_slots(dispatch, device) == -1) {
free(dispatch);
return NULL;
}
fallback_dispatch_init_switch(dispatch, device);
if (device->left_handed.want_enabled)
evdev_init_left_handed(device,
fallback_change_to_left_handed);
if (device->scroll.want_button)
evdev_init_button_scroll(device,
fallback_change_scroll_method);
if (device->scroll.natural_scrolling_enabled)
evdev_init_natural_scroll(device);
evdev_init_calibration(device, &dispatch->calibration);
evdev_init_sendevents(device, &dispatch->base);
fallback_init_rotation(dispatch, device);
/* BTN_MIDDLE is set on mice even when it's not present. So
* we can only use the absence of BTN_MIDDLE to mean something, i.e.
* we enable it by default on anything that only has L&R.
* If we have L&R and no middle, we don't expose it as config
* option */
if (libevdev_has_event_code(device->evdev, EV_KEY, BTN_LEFT) &&
libevdev_has_event_code(device->evdev, EV_KEY, BTN_RIGHT)) {
bool has_middle = libevdev_has_event_code(device->evdev,
EV_KEY,
BTN_MIDDLE);
bool want_config = has_middle;
bool enable_by_default = !has_middle;
evdev_init_middlebutton(device,
enable_by_default,
want_config);
}
fallback_init_wheel(dispatch, device);
fallback_init_debounce(dispatch);
fallback_init_arbitration(dispatch, device);
return &dispatch->base;
}
libinput-1.28.1/src/evdev-fallback.h000066400000000000000000000162171477265155700172710ustar00rootroot00000000000000/*
* Copyright © 2010 Intel Corporation
* Copyright © 2013 Jonas Ådahl
* Copyright © 2013-2017 Red Hat, Inc.
* Copyright © 2017 James Ye
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice (including the next
* paragraph) shall be included in all copies or substantial portions of the
* Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
*/
#include "config.h"
#ifndef EVDEV_FALLBACK_H
#define EVDEV_FALLBACK_H
#include "evdev.h"
enum debounce_state {
DEBOUNCE_STATE_IS_UP = 100,
DEBOUNCE_STATE_IS_DOWN,
DEBOUNCE_STATE_IS_DOWN_WAITING,
DEBOUNCE_STATE_IS_UP_DELAYING,
DEBOUNCE_STATE_IS_UP_DELAYING_SPURIOUS,
DEBOUNCE_STATE_IS_UP_DETECTING_SPURIOUS,
DEBOUNCE_STATE_IS_DOWN_DETECTING_SPURIOUS,
DEBOUNCE_STATE_IS_UP_WAITING,
DEBOUNCE_STATE_IS_DOWN_DELAYING,
DEBOUNCE_STATE_DISABLED = 999,
};
enum mt_slot_state {
SLOT_STATE_NONE,
SLOT_STATE_BEGIN,
SLOT_STATE_UPDATE,
SLOT_STATE_END,
};
enum palm_state {
PALM_NONE,
PALM_NEW,
PALM_IS_PALM,
PALM_WAS_PALM, /* this touch sequence was a palm but isn't now */
};
enum wheel_state {
WHEEL_STATE_NONE,
WHEEL_STATE_ACCUMULATING_SCROLL,
WHEEL_STATE_SCROLLING,
};
enum wheel_direction {
WHEEL_DIR_UNKNOW,
WHEEL_DIR_VPOS,
WHEEL_DIR_VNEG,
WHEEL_DIR_HPOS,
WHEEL_DIR_HNEG,
};
struct mt_slot {
bool dirty;
enum mt_slot_state state;
int32_t seat_slot;
struct device_coords point;
struct device_coords hysteresis_center;
enum palm_state palm_state;
};
struct fallback_dispatch {
struct evdev_dispatch base;
struct evdev_device *device;
struct libinput_device_config_calibration calibration;
struct {
int angle;
struct matrix matrix;
struct libinput_device_config_rotation config;
} rotation;
struct {
struct device_coords point;
int32_t seat_slot;
} abs;
struct {
int slot;
struct mt_slot *slots;
size_t slots_len;
bool want_hysteresis;
struct device_coords hysteresis_margin;
bool has_palm;
} mt;
struct device_coords rel;
struct {
enum wheel_state state;
struct device_coords lo_res;
struct device_coords hi_res;
bool emulate_hi_res_wheel;
bool hi_res_event_received;
struct libinput_timer scroll_timer;
enum wheel_direction dir;
} wheel;
struct {
/* The struct for the tablet mode switch device itself */
struct {
int state;
} sw;
/* The struct for other devices listening to the tablet mode
switch */
struct {
struct evdev_device *sw_device;
struct libinput_event_listener listener;
} other;
} tablet_mode;
/* Bitmask of pressed keys used to ignore initial release events from
* the kernel. */
unsigned long hw_key_mask[NLONGS(KEY_CNT)];
unsigned long last_hw_key_mask[NLONGS(KEY_CNT)];
enum evdev_event_type pending_event;
struct {
unsigned int button_code;
uint64_t button_time;
struct libinput_timer timer;
struct libinput_timer timer_short;
enum debounce_state state;
bool spurious_enabled;
} debounce;
struct {
enum switch_reliability reliability;
bool is_closed;
bool is_closed_client_state;
/* We allow multiple paired keyboards for the lid switch
* listener. Only one keyboard should exist, but that can
* have more than one event node. And it's a list because
* otherwise the test suite run fails too often.
*/
struct list paired_keyboard_list;
} lid;
/* pen/touch arbitration has a delayed state,
* in_arbitration is what decides when to filter.
*/
struct {
enum evdev_arbitration_state state;
bool in_arbitration;
struct device_coord_rect rect;
struct libinput_timer arbitration_timer;
} arbitration;
};
static inline struct fallback_dispatch*
fallback_dispatch(struct evdev_dispatch *dispatch)
{
evdev_verify_dispatch_type(dispatch, DISPATCH_FALLBACK);
return container_of(dispatch, struct fallback_dispatch, base);
}
enum key_type {
KEY_TYPE_NONE,
KEY_TYPE_KEY,
KEY_TYPE_BUTTON,
};
static inline enum key_type
get_key_type(uint16_t code)
{
switch (code) {
case BTN_TOOL_PEN:
case BTN_TOOL_RUBBER:
case BTN_TOOL_BRUSH:
case BTN_TOOL_PENCIL:
case BTN_TOOL_AIRBRUSH:
case BTN_TOOL_MOUSE:
case BTN_TOOL_LENS:
case BTN_TOOL_QUINTTAP:
case BTN_TOOL_DOUBLETAP:
case BTN_TOOL_TRIPLETAP:
case BTN_TOOL_QUADTAP:
case BTN_TOOL_FINGER:
case BTN_TOUCH:
return KEY_TYPE_NONE;
}
if (code >= KEY_ESC && code <= KEY_MICMUTE)
return KEY_TYPE_KEY;
if (code >= BTN_MISC && code <= BTN_GEAR_UP)
return KEY_TYPE_BUTTON;
if (code >= KEY_OK && code <= KEY_LIGHTS_TOGGLE)
return KEY_TYPE_KEY;
if (code >= BTN_DPAD_UP && code <= BTN_DPAD_RIGHT)
return KEY_TYPE_BUTTON;
if (code >= KEY_ALS_TOGGLE && code < BTN_TRIGGER_HAPPY)
return KEY_TYPE_KEY;
if (code >= BTN_TRIGGER_HAPPY && code <= BTN_TRIGGER_HAPPY40)
return KEY_TYPE_BUTTON;
return KEY_TYPE_NONE;
}
static inline void
hw_set_key_down(struct fallback_dispatch *dispatch, int code, int pressed)
{
long_set_bit_state(dispatch->hw_key_mask, code, pressed);
}
static inline bool
hw_key_has_changed(struct fallback_dispatch *dispatch, int code)
{
return long_bit_is_set(dispatch->hw_key_mask, code) !=
long_bit_is_set(dispatch->last_hw_key_mask, code);
}
static inline void
hw_key_update_last_state(struct fallback_dispatch *dispatch)
{
static_assert(sizeof(dispatch->hw_key_mask) ==
sizeof(dispatch->last_hw_key_mask),
"Mismatching key mask size");
memcpy(dispatch->last_hw_key_mask,
dispatch->hw_key_mask,
sizeof(dispatch->hw_key_mask));
}
static inline bool
hw_is_key_down(struct fallback_dispatch *dispatch, int code)
{
return long_bit_is_set(dispatch->hw_key_mask, code);
}
static inline int
get_key_down_count(struct evdev_device *device, int code)
{
return device->key_count[code];
}
void fallback_init_debounce(struct fallback_dispatch *dispatch);
void fallback_debounce_handle_state(struct fallback_dispatch *dispatch,
uint64_t time);
void
fallback_notify_physical_button(struct fallback_dispatch *dispatch,
struct evdev_device *device,
uint64_t time,
int button,
enum libinput_button_state state);
void
fallback_init_wheel(struct fallback_dispatch *dispatch,
struct evdev_device *device);
void
fallback_wheel_process_relative(struct fallback_dispatch *dispatch,
struct evdev_device *device,
struct input_event *e, uint64_t time);
void
fallback_wheel_handle_state(struct fallback_dispatch *dispatch,
struct evdev_device *device,
uint64_t time);
#endif
libinput-1.28.1/src/evdev-middle-button.c000066400000000000000000000456411477265155700202770ustar00rootroot00000000000000/*
* Copyright © 2014-2015 Red Hat, Inc.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice (including the next
* paragraph) shall be included in all copies or substantial portions of the
* Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
*/
#include "config.h"
#include
#include "evdev.h"
#define MIDDLEBUTTON_TIMEOUT ms2us(50)
/*****************************************
* BEFORE YOU EDIT THIS FILE, look at the state diagram in
* doc/middle-button-emulation-state-machine.svg (generated with
* https://www.diagrams.net).
*
* Any changes in this file must be represented in the diagram.
*
* Note in regards to the state machine: it only handles left, right and
* emulated middle button clicks, all other button events are passed
* through. When in the PASSTHROUGH state, all events are passed through
* as-is.
*/
static inline const char*
middlebutton_state_to_str(enum evdev_middlebutton_state state)
{
switch (state) {
CASE_RETURN_STRING(MIDDLEBUTTON_IDLE);
CASE_RETURN_STRING(MIDDLEBUTTON_LEFT_DOWN);
CASE_RETURN_STRING(MIDDLEBUTTON_RIGHT_DOWN);
CASE_RETURN_STRING(MIDDLEBUTTON_MIDDLE);
CASE_RETURN_STRING(MIDDLEBUTTON_LEFT_UP_PENDING);
CASE_RETURN_STRING(MIDDLEBUTTON_RIGHT_UP_PENDING);
CASE_RETURN_STRING(MIDDLEBUTTON_PASSTHROUGH);
CASE_RETURN_STRING(MIDDLEBUTTON_IGNORE_LR);
CASE_RETURN_STRING(MIDDLEBUTTON_IGNORE_L);
CASE_RETURN_STRING(MIDDLEBUTTON_IGNORE_R);
}
return NULL;
}
static inline const char*
middlebutton_event_to_str(enum evdev_middlebutton_event event)
{
switch (event) {
CASE_RETURN_STRING(MIDDLEBUTTON_EVENT_L_DOWN);
CASE_RETURN_STRING(MIDDLEBUTTON_EVENT_R_DOWN);
CASE_RETURN_STRING(MIDDLEBUTTON_EVENT_OTHER);
CASE_RETURN_STRING(MIDDLEBUTTON_EVENT_L_UP);
CASE_RETURN_STRING(MIDDLEBUTTON_EVENT_R_UP);
CASE_RETURN_STRING(MIDDLEBUTTON_EVENT_TIMEOUT);
CASE_RETURN_STRING(MIDDLEBUTTON_EVENT_ALL_UP);
}
return NULL;
}
static void
middlebutton_state_error(struct evdev_device *device,
enum evdev_middlebutton_event event)
{
evdev_log_bug_libinput(device,
"Invalid event %s in middle btn state %s\n",
middlebutton_event_to_str(event),
middlebutton_state_to_str(device->middlebutton.state));
}
static void
middlebutton_timer_set(struct evdev_device *device, uint64_t now)
{
libinput_timer_set(&device->middlebutton.timer,
now + MIDDLEBUTTON_TIMEOUT);
}
static void
middlebutton_timer_cancel(struct evdev_device *device)
{
libinput_timer_cancel(&device->middlebutton.timer);
}
static inline void
middlebutton_set_state(struct evdev_device *device,
enum evdev_middlebutton_state state,
uint64_t now)
{
switch (state) {
case MIDDLEBUTTON_LEFT_DOWN:
case MIDDLEBUTTON_RIGHT_DOWN:
middlebutton_timer_set(device, now);
device->middlebutton.first_event_time = now;
break;
case MIDDLEBUTTON_IDLE:
case MIDDLEBUTTON_MIDDLE:
case MIDDLEBUTTON_LEFT_UP_PENDING:
case MIDDLEBUTTON_RIGHT_UP_PENDING:
case MIDDLEBUTTON_PASSTHROUGH:
case MIDDLEBUTTON_IGNORE_LR:
case MIDDLEBUTTON_IGNORE_L:
case MIDDLEBUTTON_IGNORE_R:
middlebutton_timer_cancel(device);
break;
}
device->middlebutton.state = state;
}
static void
middlebutton_post_event(struct evdev_device *device,
uint64_t now,
int button,
enum libinput_button_state state)
{
evdev_pointer_notify_button(device,
now,
button,
state);
}
static int
evdev_middlebutton_idle_handle_event(struct evdev_device *device,
uint64_t time,
enum evdev_middlebutton_event event)
{
switch (event) {
case MIDDLEBUTTON_EVENT_L_DOWN:
middlebutton_set_state(device, MIDDLEBUTTON_LEFT_DOWN, time);
break;
case MIDDLEBUTTON_EVENT_R_DOWN:
middlebutton_set_state(device, MIDDLEBUTTON_RIGHT_DOWN, time);
break;
case MIDDLEBUTTON_EVENT_OTHER:
return 0;
case MIDDLEBUTTON_EVENT_R_UP:
case MIDDLEBUTTON_EVENT_L_UP:
case MIDDLEBUTTON_EVENT_TIMEOUT:
middlebutton_state_error(device, event);
break;
case MIDDLEBUTTON_EVENT_ALL_UP:
break;
}
return 1;
}
static int
evdev_middlebutton_ldown_handle_event(struct evdev_device *device,
uint64_t time,
enum evdev_middlebutton_event event)
{
switch (event) {
case MIDDLEBUTTON_EVENT_L_DOWN:
middlebutton_state_error(device, event);
break;
case MIDDLEBUTTON_EVENT_R_DOWN:
middlebutton_post_event(device, time,
BTN_MIDDLE,
LIBINPUT_BUTTON_STATE_PRESSED);
middlebutton_set_state(device, MIDDLEBUTTON_MIDDLE, time);
break;
case MIDDLEBUTTON_EVENT_OTHER:
middlebutton_post_event(device, time,
BTN_LEFT,
LIBINPUT_BUTTON_STATE_PRESSED);
middlebutton_set_state(device,
MIDDLEBUTTON_PASSTHROUGH,
time);
return 0;
case MIDDLEBUTTON_EVENT_R_UP:
middlebutton_state_error(device, event);
break;
case MIDDLEBUTTON_EVENT_L_UP:
middlebutton_post_event(device,
device->middlebutton.first_event_time,
BTN_LEFT,
LIBINPUT_BUTTON_STATE_PRESSED);
middlebutton_post_event(device, time,
BTN_LEFT,
LIBINPUT_BUTTON_STATE_RELEASED);
middlebutton_set_state(device, MIDDLEBUTTON_IDLE, time);
break;
case MIDDLEBUTTON_EVENT_TIMEOUT:
middlebutton_post_event(device,
device->middlebutton.first_event_time,
BTN_LEFT,
LIBINPUT_BUTTON_STATE_PRESSED);
middlebutton_set_state(device,
MIDDLEBUTTON_PASSTHROUGH,
time);
break;
case MIDDLEBUTTON_EVENT_ALL_UP:
middlebutton_state_error(device, event);
break;
}
return 1;
}
static int
evdev_middlebutton_rdown_handle_event(struct evdev_device *device,
uint64_t time,
enum evdev_middlebutton_event event)
{
switch (event) {
case MIDDLEBUTTON_EVENT_L_DOWN:
middlebutton_post_event(device, time,
BTN_MIDDLE,
LIBINPUT_BUTTON_STATE_PRESSED);
middlebutton_set_state(device, MIDDLEBUTTON_MIDDLE, time);
break;
case MIDDLEBUTTON_EVENT_R_DOWN:
middlebutton_state_error(device, event);
break;
case MIDDLEBUTTON_EVENT_OTHER:
middlebutton_post_event(device,
device->middlebutton.first_event_time,
BTN_RIGHT,
LIBINPUT_BUTTON_STATE_PRESSED);
middlebutton_set_state(device,
MIDDLEBUTTON_PASSTHROUGH,
time);
return 0;
case MIDDLEBUTTON_EVENT_R_UP:
middlebutton_post_event(device,
device->middlebutton.first_event_time,
BTN_RIGHT,
LIBINPUT_BUTTON_STATE_PRESSED);
middlebutton_post_event(device, time,
BTN_RIGHT,
LIBINPUT_BUTTON_STATE_RELEASED);
middlebutton_set_state(device, MIDDLEBUTTON_IDLE, time);
break;
case MIDDLEBUTTON_EVENT_L_UP:
middlebutton_state_error(device, event);
break;
case MIDDLEBUTTON_EVENT_TIMEOUT:
middlebutton_post_event(device,
device->middlebutton.first_event_time,
BTN_RIGHT,
LIBINPUT_BUTTON_STATE_PRESSED);
middlebutton_set_state(device,
MIDDLEBUTTON_PASSTHROUGH,
time);
break;
case MIDDLEBUTTON_EVENT_ALL_UP:
middlebutton_state_error(device, event);
break;
}
return 1;
}
static int
evdev_middlebutton_middle_handle_event(struct evdev_device *device,
uint64_t time,
enum evdev_middlebutton_event event)
{
switch (event) {
case MIDDLEBUTTON_EVENT_L_DOWN:
case MIDDLEBUTTON_EVENT_R_DOWN:
middlebutton_state_error(device, event);
break;
case MIDDLEBUTTON_EVENT_OTHER:
middlebutton_post_event(device, time,
BTN_MIDDLE,
LIBINPUT_BUTTON_STATE_RELEASED);
middlebutton_set_state(device, MIDDLEBUTTON_IGNORE_LR, time);
return 0;
case MIDDLEBUTTON_EVENT_R_UP:
middlebutton_post_event(device, time,
BTN_MIDDLE,
LIBINPUT_BUTTON_STATE_RELEASED);
middlebutton_set_state(device,
MIDDLEBUTTON_LEFT_UP_PENDING,
time);
break;
case MIDDLEBUTTON_EVENT_L_UP:
middlebutton_post_event(device, time,
BTN_MIDDLE,
LIBINPUT_BUTTON_STATE_RELEASED);
middlebutton_set_state(device,
MIDDLEBUTTON_RIGHT_UP_PENDING,
time);
break;
case MIDDLEBUTTON_EVENT_TIMEOUT:
middlebutton_state_error(device, event);
break;
case MIDDLEBUTTON_EVENT_ALL_UP:
middlebutton_state_error(device, event);
break;
}
return 1;
}
static int
evdev_middlebutton_lup_pending_handle_event(struct evdev_device *device,
uint64_t time,
enum evdev_middlebutton_event event)
{
switch (event) {
case MIDDLEBUTTON_EVENT_L_DOWN:
middlebutton_state_error(device, event);
break;
case MIDDLEBUTTON_EVENT_R_DOWN:
middlebutton_post_event(device, time,
BTN_MIDDLE,
LIBINPUT_BUTTON_STATE_PRESSED);
middlebutton_set_state(device, MIDDLEBUTTON_MIDDLE, time);
break;
case MIDDLEBUTTON_EVENT_OTHER:
middlebutton_set_state(device, MIDDLEBUTTON_IGNORE_L, time);
return 0;
case MIDDLEBUTTON_EVENT_R_UP:
middlebutton_state_error(device, event);
break;
case MIDDLEBUTTON_EVENT_L_UP:
middlebutton_set_state(device, MIDDLEBUTTON_IDLE, time);
break;
case MIDDLEBUTTON_EVENT_TIMEOUT:
middlebutton_state_error(device, event);
break;
case MIDDLEBUTTON_EVENT_ALL_UP:
middlebutton_state_error(device, event);
break;
}
return 1;
}
static int
evdev_middlebutton_rup_pending_handle_event(struct evdev_device *device,
uint64_t time,
enum evdev_middlebutton_event event)
{
switch (event) {
case MIDDLEBUTTON_EVENT_L_DOWN:
middlebutton_post_event(device, time,
BTN_MIDDLE,
LIBINPUT_BUTTON_STATE_PRESSED);
middlebutton_set_state(device, MIDDLEBUTTON_MIDDLE, time);
break;
case MIDDLEBUTTON_EVENT_R_DOWN:
middlebutton_state_error(device, event);
break;
case MIDDLEBUTTON_EVENT_OTHER:
middlebutton_set_state(device, MIDDLEBUTTON_IGNORE_R, time);
return 0;
case MIDDLEBUTTON_EVENT_R_UP:
middlebutton_set_state(device, MIDDLEBUTTON_IDLE, time);
break;
case MIDDLEBUTTON_EVENT_L_UP:
middlebutton_state_error(device, event);
break;
case MIDDLEBUTTON_EVENT_TIMEOUT:
middlebutton_state_error(device, event);
break;
case MIDDLEBUTTON_EVENT_ALL_UP:
middlebutton_state_error(device, event);
break;
}
return 1;
}
static int
evdev_middlebutton_passthrough_handle_event(struct evdev_device *device,
uint64_t time,
enum evdev_middlebutton_event event)
{
switch (event) {
case MIDDLEBUTTON_EVENT_L_DOWN:
case MIDDLEBUTTON_EVENT_R_DOWN:
case MIDDLEBUTTON_EVENT_OTHER:
case MIDDLEBUTTON_EVENT_R_UP:
case MIDDLEBUTTON_EVENT_L_UP:
return 0;
case MIDDLEBUTTON_EVENT_TIMEOUT:
middlebutton_state_error(device, event);
break;
case MIDDLEBUTTON_EVENT_ALL_UP:
middlebutton_set_state(device, MIDDLEBUTTON_IDLE, time);
break;
}
return 1;
}
static int
evdev_middlebutton_ignore_lr_handle_event(struct evdev_device *device,
uint64_t time,
enum evdev_middlebutton_event event)
{
switch (event) {
case MIDDLEBUTTON_EVENT_L_DOWN:
case MIDDLEBUTTON_EVENT_R_DOWN:
middlebutton_state_error(device, event);
break;
case MIDDLEBUTTON_EVENT_OTHER:
return 0;
case MIDDLEBUTTON_EVENT_R_UP:
middlebutton_set_state(device, MIDDLEBUTTON_IGNORE_L, time);
break;
case MIDDLEBUTTON_EVENT_L_UP:
middlebutton_set_state(device, MIDDLEBUTTON_IGNORE_R, time);
break;
case MIDDLEBUTTON_EVENT_TIMEOUT:
middlebutton_state_error(device, event);
break;
case MIDDLEBUTTON_EVENT_ALL_UP:
middlebutton_state_error(device, event);
break;
}
return 1;
}
static int
evdev_middlebutton_ignore_l_handle_event(struct evdev_device *device,
uint64_t time,
enum evdev_middlebutton_event event)
{
switch (event) {
case MIDDLEBUTTON_EVENT_L_DOWN:
middlebutton_state_error(device, event);
break;
case MIDDLEBUTTON_EVENT_R_DOWN:
return 0;
case MIDDLEBUTTON_EVENT_OTHER:
case MIDDLEBUTTON_EVENT_R_UP:
return 0;
case MIDDLEBUTTON_EVENT_L_UP:
middlebutton_set_state(device,
MIDDLEBUTTON_PASSTHROUGH,
time);
break;
case MIDDLEBUTTON_EVENT_TIMEOUT:
case MIDDLEBUTTON_EVENT_ALL_UP:
middlebutton_state_error(device, event);
break;
}
return 1;
}
static int
evdev_middlebutton_ignore_r_handle_event(struct evdev_device *device,
uint64_t time,
enum evdev_middlebutton_event event)
{
switch (event) {
case MIDDLEBUTTON_EVENT_L_DOWN:
return 0;
case MIDDLEBUTTON_EVENT_R_DOWN:
middlebutton_state_error(device, event);
break;
case MIDDLEBUTTON_EVENT_OTHER:
return 0;
case MIDDLEBUTTON_EVENT_R_UP:
middlebutton_set_state(device,
MIDDLEBUTTON_PASSTHROUGH,
time);
break;
case MIDDLEBUTTON_EVENT_L_UP:
return 0;
case MIDDLEBUTTON_EVENT_TIMEOUT:
case MIDDLEBUTTON_EVENT_ALL_UP:
break;
}
return 1;
}
static int
evdev_middlebutton_handle_event(struct evdev_device *device,
uint64_t time,
enum evdev_middlebutton_event event)
{
int rc = 0;
enum evdev_middlebutton_state current;
current = device->middlebutton.state;
switch (current) {
case MIDDLEBUTTON_IDLE:
rc = evdev_middlebutton_idle_handle_event(device, time, event);
break;
case MIDDLEBUTTON_LEFT_DOWN:
rc = evdev_middlebutton_ldown_handle_event(device, time, event);
break;
case MIDDLEBUTTON_RIGHT_DOWN:
rc = evdev_middlebutton_rdown_handle_event(device, time, event);
break;
case MIDDLEBUTTON_MIDDLE:
rc = evdev_middlebutton_middle_handle_event(device, time, event);
break;
case MIDDLEBUTTON_LEFT_UP_PENDING:
rc = evdev_middlebutton_lup_pending_handle_event(device,
time,
event);
break;
case MIDDLEBUTTON_RIGHT_UP_PENDING:
rc = evdev_middlebutton_rup_pending_handle_event(device,
time,
event);
break;
case MIDDLEBUTTON_PASSTHROUGH:
rc = evdev_middlebutton_passthrough_handle_event(device,
time,
event);
break;
case MIDDLEBUTTON_IGNORE_LR:
rc = evdev_middlebutton_ignore_lr_handle_event(device,
time,
event);
break;
case MIDDLEBUTTON_IGNORE_L:
rc = evdev_middlebutton_ignore_l_handle_event(device,
time,
event);
break;
case MIDDLEBUTTON_IGNORE_R:
rc = evdev_middlebutton_ignore_r_handle_event(device,
time,
event);
break;
default:
evdev_log_bug_libinput(device,
"Invalid middle button state %d\n",
current);
break;
}
evdev_log_debug(device,
"middlebutton state: %s → %s → %s, rc %d\n",
middlebutton_state_to_str(current),
middlebutton_event_to_str(event),
middlebutton_state_to_str(device->middlebutton.state),
rc);
return rc;
}
static inline void
evdev_middlebutton_apply_config(struct evdev_device *device)
{
if (device->middlebutton.want_enabled ==
device->middlebutton.enabled)
return;
if (device->middlebutton.button_mask != 0)
return;
device->middlebutton.enabled = device->middlebutton.want_enabled;
}
bool
evdev_middlebutton_filter_button(struct evdev_device *device,
uint64_t time,
int button,
enum libinput_button_state state)
{
enum evdev_middlebutton_event event;
bool is_press = state == LIBINPUT_BUTTON_STATE_PRESSED;
int rc;
unsigned int btnbit = (button - BTN_LEFT);
uint32_t old_mask = 0;
if (!device->middlebutton.enabled)
return false;
switch (button) {
case BTN_LEFT:
if (is_press)
event = MIDDLEBUTTON_EVENT_L_DOWN;
else
event = MIDDLEBUTTON_EVENT_L_UP;
break;
case BTN_RIGHT:
if (is_press)
event = MIDDLEBUTTON_EVENT_R_DOWN;
else
event = MIDDLEBUTTON_EVENT_R_UP;
break;
/* BTN_MIDDLE counts as "other" and resets middle button
* emulation */
case BTN_MIDDLE:
default:
event = MIDDLEBUTTON_EVENT_OTHER;
break;
}
if (button < BTN_LEFT ||
btnbit >= sizeof(device->middlebutton.button_mask) * 8) {
evdev_log_bug_libinput(device,
"Button mask too small for %s\n",
libevdev_event_code_get_name(EV_KEY,
button));
return true;
}
rc = evdev_middlebutton_handle_event(device, time, event);
old_mask = device->middlebutton.button_mask;
if (is_press)
device->middlebutton.button_mask |= bit(btnbit);
else
device->middlebutton.button_mask &= ~bit(btnbit);
if (old_mask != device->middlebutton.button_mask &&
device->middlebutton.button_mask == 0) {
evdev_middlebutton_handle_event(device,
time,
MIDDLEBUTTON_EVENT_ALL_UP);
evdev_middlebutton_apply_config(device);
}
return rc;
}
static void
evdev_middlebutton_handle_timeout(uint64_t now, void *data)
{
struct evdev_device *device = evdev_device(data);
evdev_middlebutton_handle_event(device, now, MIDDLEBUTTON_EVENT_TIMEOUT);
}
int
evdev_middlebutton_is_available(struct libinput_device *device)
{
return 1;
}
static enum libinput_config_status
evdev_middlebutton_set(struct libinput_device *device,
enum libinput_config_middle_emulation_state enable)
{
struct evdev_device *evdev = evdev_device(device);
switch (enable) {
case LIBINPUT_CONFIG_MIDDLE_EMULATION_ENABLED:
evdev->middlebutton.want_enabled = true;
break;
case LIBINPUT_CONFIG_MIDDLE_EMULATION_DISABLED:
evdev->middlebutton.want_enabled = false;
break;
default:
return LIBINPUT_CONFIG_STATUS_INVALID;
}
evdev_middlebutton_apply_config(evdev);
return LIBINPUT_CONFIG_STATUS_SUCCESS;
}
enum libinput_config_middle_emulation_state
evdev_middlebutton_get(struct libinput_device *device)
{
struct evdev_device *evdev = evdev_device(device);
return evdev->middlebutton.want_enabled ?
LIBINPUT_CONFIG_MIDDLE_EMULATION_ENABLED :
LIBINPUT_CONFIG_MIDDLE_EMULATION_DISABLED;
}
enum libinput_config_middle_emulation_state
evdev_middlebutton_get_default(struct libinput_device *device)
{
struct evdev_device *evdev = evdev_device(device);
return evdev->middlebutton.enabled_default ?
LIBINPUT_CONFIG_MIDDLE_EMULATION_ENABLED :
LIBINPUT_CONFIG_MIDDLE_EMULATION_DISABLED;
}
void
evdev_init_middlebutton(struct evdev_device *device,
bool enable,
bool want_config)
{
char timer_name[64];
snprintf(timer_name,
sizeof(timer_name),
"%s middlebutton",
evdev_device_get_sysname(device));
libinput_timer_init(&device->middlebutton.timer,
evdev_libinput_context(device),
timer_name,
evdev_middlebutton_handle_timeout,
device);
device->middlebutton.enabled_default = enable;
device->middlebutton.want_enabled = enable;
device->middlebutton.enabled = enable;
if (!want_config)
return;
device->middlebutton.config.available = evdev_middlebutton_is_available;
device->middlebutton.config.set = evdev_middlebutton_set;
device->middlebutton.config.get = evdev_middlebutton_get;
device->middlebutton.config.get_default = evdev_middlebutton_get_default;
device->base.config.middle_emulation = &device->middlebutton.config;
}
libinput-1.28.1/src/evdev-mt-touchpad-buttons.c000066400000000000000000001116501477265155700214430ustar00rootroot00000000000000/*
* Copyright © 2014-2015 Red Hat, Inc.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice (including the next
* paragraph) shall be included in all copies or substantial portions of the
* Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
*/
#include "config.h"
#include
#include
#include
#include "linux/input.h"
#include "util-input-event.h"
#include "evdev-mt-touchpad.h"
#define DEFAULT_BUTTON_ENTER_TIMEOUT ms2us(100)
#define DEFAULT_BUTTON_LEAVE_TIMEOUT ms2us(300)
/*****************************************
* BEFORE YOU EDIT THIS FILE, look at the state diagram in
* doc/touchpad-softbutton-state-machine.svg (generated with
* https://www.diagrams.net).
* Any changes in this file must be represented in the diagram.
*
* The state machine only affects the soft button area code.
*/
static inline const char*
button_state_to_str(enum button_state state)
{
switch(state) {
CASE_RETURN_STRING(BUTTON_STATE_NONE);
CASE_RETURN_STRING(BUTTON_STATE_AREA);
CASE_RETURN_STRING(BUTTON_STATE_BOTTOM);
CASE_RETURN_STRING(BUTTON_STATE_TOP);
CASE_RETURN_STRING(BUTTON_STATE_TOP_NEW);
CASE_RETURN_STRING(BUTTON_STATE_TOP_TO_IGNORE);
CASE_RETURN_STRING(BUTTON_STATE_IGNORE);
}
return NULL;
}
static inline const char*
button_event_to_str(enum button_event event)
{
switch(event) {
CASE_RETURN_STRING(BUTTON_EVENT_IN_BOTTOM_R);
CASE_RETURN_STRING(BUTTON_EVENT_IN_BOTTOM_M);
CASE_RETURN_STRING(BUTTON_EVENT_IN_BOTTOM_L);
CASE_RETURN_STRING(BUTTON_EVENT_IN_TOP_R);
CASE_RETURN_STRING(BUTTON_EVENT_IN_TOP_M);
CASE_RETURN_STRING(BUTTON_EVENT_IN_TOP_L);
CASE_RETURN_STRING(BUTTON_EVENT_IN_AREA);
CASE_RETURN_STRING(BUTTON_EVENT_UP);
CASE_RETURN_STRING(BUTTON_EVENT_PRESS);
CASE_RETURN_STRING(BUTTON_EVENT_RELEASE);
CASE_RETURN_STRING(BUTTON_EVENT_TIMEOUT);
}
return NULL;
}
static inline bool
is_inside_bottom_button_area(const struct tp_dispatch *tp,
const struct tp_touch *t)
{
return t->point.y >= tp->buttons.bottom_area.top_edge;
}
static inline bool
is_inside_bottom_right_area(const struct tp_dispatch *tp,
const struct tp_touch *t)
{
return is_inside_bottom_button_area(tp, t) &&
t->point.x > tp->buttons.bottom_area.rightbutton_left_edge;
}
static inline bool
is_inside_bottom_middle_area(const struct tp_dispatch *tp,
const struct tp_touch *t)
{
return is_inside_bottom_button_area(tp, t) &&
!is_inside_bottom_right_area(tp, t) &&
t->point.x > tp->buttons.bottom_area.middlebutton_left_edge;
}
static inline bool
is_inside_top_button_area(const struct tp_dispatch *tp,
const struct tp_touch *t)
{
return t->point.y <= tp->buttons.top_area.bottom_edge;
}
static inline bool
is_inside_top_right_area(const struct tp_dispatch *tp,
const struct tp_touch *t)
{
return is_inside_top_button_area(tp, t) &&
t->point.x > tp->buttons.top_area.rightbutton_left_edge;
}
static inline bool
is_inside_top_middle_area(const struct tp_dispatch *tp,
const struct tp_touch *t)
{
return is_inside_top_button_area(tp, t) &&
t->point.x >= tp->buttons.top_area.leftbutton_right_edge &&
t->point.x <= tp->buttons.top_area.rightbutton_left_edge;
}
static void
tp_button_set_enter_timer(struct tp_dispatch *tp,
struct tp_touch *t,
uint64_t time)
{
libinput_timer_set(&t->button.timer,
time + DEFAULT_BUTTON_ENTER_TIMEOUT);
}
static void
tp_button_set_leave_timer(struct tp_dispatch *tp,
struct tp_touch *t,
uint64_t time)
{
libinput_timer_set(&t->button.timer,
time + DEFAULT_BUTTON_LEAVE_TIMEOUT);
}
/*
* tp_button_set_state, change state and implement on-entry behavior
* as described in the state machine diagram.
*/
static void
tp_button_set_state(struct tp_dispatch *tp,
struct tp_touch *t,
enum button_state new_state,
enum button_event event,
uint64_t time)
{
libinput_timer_cancel(&t->button.timer);
t->button.state = new_state;
switch (t->button.state) {
case BUTTON_STATE_NONE:
t->button.current = 0;
break;
case BUTTON_STATE_AREA:
t->button.current = BUTTON_EVENT_IN_AREA;
break;
case BUTTON_STATE_BOTTOM:
t->button.current = event;
break;
case BUTTON_STATE_TOP:
break;
case BUTTON_STATE_TOP_NEW:
t->button.current = event;
tp_button_set_enter_timer(tp, t, time);
break;
case BUTTON_STATE_TOP_TO_IGNORE:
tp_button_set_leave_timer(tp, t, time);
break;
case BUTTON_STATE_IGNORE:
t->button.current = 0;
break;
}
}
static void
tp_button_none_handle_event(struct tp_dispatch *tp,
struct tp_touch *t,
enum button_event event,
uint64_t time)
{
switch (event) {
case BUTTON_EVENT_IN_BOTTOM_R:
case BUTTON_EVENT_IN_BOTTOM_M:
case BUTTON_EVENT_IN_BOTTOM_L:
tp_button_set_state(tp, t, BUTTON_STATE_BOTTOM, event, time);
break;
case BUTTON_EVENT_IN_TOP_R:
case BUTTON_EVENT_IN_TOP_M:
case BUTTON_EVENT_IN_TOP_L:
tp_button_set_state(tp, t, BUTTON_STATE_TOP_NEW, event, time);
break;
case BUTTON_EVENT_IN_AREA:
tp_button_set_state(tp, t, BUTTON_STATE_AREA, event, time);
break;
case BUTTON_EVENT_UP:
tp_button_set_state(tp, t, BUTTON_STATE_NONE, event, time);
break;
case BUTTON_EVENT_PRESS:
case BUTTON_EVENT_RELEASE:
case BUTTON_EVENT_TIMEOUT:
break;
}
}
static void
tp_button_area_handle_event(struct tp_dispatch *tp,
struct tp_touch *t,
enum button_event event,
uint64_t time)
{
switch (event) {
case BUTTON_EVENT_IN_BOTTOM_R:
case BUTTON_EVENT_IN_BOTTOM_M:
case BUTTON_EVENT_IN_BOTTOM_L:
case BUTTON_EVENT_IN_TOP_R:
case BUTTON_EVENT_IN_TOP_M:
case BUTTON_EVENT_IN_TOP_L:
case BUTTON_EVENT_IN_AREA:
break;
case BUTTON_EVENT_UP:
tp_button_set_state(tp, t, BUTTON_STATE_NONE, event, time);
break;
case BUTTON_EVENT_PRESS:
case BUTTON_EVENT_RELEASE:
case BUTTON_EVENT_TIMEOUT:
break;
}
}
/**
* Release any button in the bottom area, provided it started within a
* threshold around start_time (i.e. simultaneously with the other touch
* that triggered this call).
*/
static inline void
tp_button_release_other_bottom_touches(struct tp_dispatch *tp,
uint64_t other_start_time)
{
struct tp_touch *t;
tp_for_each_touch(tp, t) {
uint64_t tdelta;
if (t->button.state != BUTTON_STATE_BOTTOM ||
t->button.has_moved)
continue;
if (other_start_time > t->button.initial_time)
tdelta = other_start_time - t->button.initial_time;
else
tdelta = t->button.initial_time - other_start_time;
if (tdelta > ms2us(80))
continue;
t->button.has_moved = true;
}
}
static void
tp_button_bottom_handle_event(struct tp_dispatch *tp,
struct tp_touch *t,
enum button_event event,
uint64_t time)
{
switch (event) {
case BUTTON_EVENT_IN_BOTTOM_R:
case BUTTON_EVENT_IN_BOTTOM_M:
case BUTTON_EVENT_IN_BOTTOM_L:
if (event != t->button.current)
tp_button_set_state(tp,
t,
BUTTON_STATE_BOTTOM,
event,
time);
break;
case BUTTON_EVENT_IN_TOP_R:
case BUTTON_EVENT_IN_TOP_M:
case BUTTON_EVENT_IN_TOP_L:
case BUTTON_EVENT_IN_AREA:
tp_button_set_state(tp, t, BUTTON_STATE_AREA, event, time);
/* We just transitioned one finger from BOTTOM to AREA,
* if there are other fingers in BOTTOM that started
* simultaneously with this finger, release those fingers
* because they're part of a gesture.
*/
tp_button_release_other_bottom_touches(tp,
t->button.initial_time);
break;
case BUTTON_EVENT_UP:
tp_button_set_state(tp, t, BUTTON_STATE_NONE, event, time);
break;
case BUTTON_EVENT_PRESS:
case BUTTON_EVENT_RELEASE:
case BUTTON_EVENT_TIMEOUT:
break;
}
}
static void
tp_button_top_handle_event(struct tp_dispatch *tp,
struct tp_touch *t,
enum button_event event,
uint64_t time)
{
switch (event) {
case BUTTON_EVENT_IN_BOTTOM_R:
case BUTTON_EVENT_IN_BOTTOM_M:
case BUTTON_EVENT_IN_BOTTOM_L:
tp_button_set_state(tp, t, BUTTON_STATE_TOP_TO_IGNORE, event, time);
break;
case BUTTON_EVENT_IN_TOP_R:
case BUTTON_EVENT_IN_TOP_M:
case BUTTON_EVENT_IN_TOP_L:
if (event != t->button.current)
tp_button_set_state(tp,
t,
BUTTON_STATE_TOP_NEW,
event,
time);
break;
case BUTTON_EVENT_IN_AREA:
tp_button_set_state(tp, t, BUTTON_STATE_TOP_TO_IGNORE, event, time);
break;
case BUTTON_EVENT_UP:
tp_button_set_state(tp, t, BUTTON_STATE_NONE, event, time);
break;
case BUTTON_EVENT_PRESS:
case BUTTON_EVENT_RELEASE:
case BUTTON_EVENT_TIMEOUT:
break;
}
}
static void
tp_button_top_new_handle_event(struct tp_dispatch *tp,
struct tp_touch *t,
enum button_event event,
uint64_t time)
{
switch(event) {
case BUTTON_EVENT_IN_BOTTOM_R:
case BUTTON_EVENT_IN_BOTTOM_M:
case BUTTON_EVENT_IN_BOTTOM_L:
tp_button_set_state(tp, t, BUTTON_STATE_AREA, event, time);
break;
case BUTTON_EVENT_IN_TOP_R:
case BUTTON_EVENT_IN_TOP_M:
case BUTTON_EVENT_IN_TOP_L:
if (event != t->button.current)
tp_button_set_state(tp,
t,
BUTTON_STATE_TOP_NEW,
event,
time);
break;
case BUTTON_EVENT_IN_AREA:
tp_button_set_state(tp, t, BUTTON_STATE_AREA, event, time);
break;
case BUTTON_EVENT_UP:
tp_button_set_state(tp, t, BUTTON_STATE_NONE, event, time);
break;
case BUTTON_EVENT_PRESS:
tp_button_set_state(tp, t, BUTTON_STATE_TOP, event, time);
break;
case BUTTON_EVENT_RELEASE:
break;
case BUTTON_EVENT_TIMEOUT:
tp_button_set_state(tp, t, BUTTON_STATE_TOP, event, time);
break;
}
}
static void
tp_button_top_to_ignore_handle_event(struct tp_dispatch *tp,
struct tp_touch *t,
enum button_event event,
uint64_t time)
{
switch(event) {
case BUTTON_EVENT_IN_TOP_R:
case BUTTON_EVENT_IN_TOP_M:
case BUTTON_EVENT_IN_TOP_L:
if (event == t->button.current)
tp_button_set_state(tp,
t,
BUTTON_STATE_TOP,
event,
time);
else
tp_button_set_state(tp,
t,
BUTTON_STATE_TOP_NEW,
event,
time);
break;
case BUTTON_EVENT_IN_BOTTOM_R:
case BUTTON_EVENT_IN_BOTTOM_M:
case BUTTON_EVENT_IN_BOTTOM_L:
case BUTTON_EVENT_IN_AREA:
break;
case BUTTON_EVENT_UP:
tp_button_set_state(tp, t, BUTTON_STATE_NONE, event, time);
break;
case BUTTON_EVENT_PRESS:
case BUTTON_EVENT_RELEASE:
break;
case BUTTON_EVENT_TIMEOUT:
tp_button_set_state(tp, t, BUTTON_STATE_IGNORE, event, time);
break;
}
}
static void
tp_button_ignore_handle_event(struct tp_dispatch *tp,
struct tp_touch *t,
enum button_event event,
uint64_t time)
{
switch (event) {
case BUTTON_EVENT_IN_BOTTOM_R:
case BUTTON_EVENT_IN_BOTTOM_M:
case BUTTON_EVENT_IN_BOTTOM_L:
case BUTTON_EVENT_IN_TOP_R:
case BUTTON_EVENT_IN_TOP_M:
case BUTTON_EVENT_IN_TOP_L:
case BUTTON_EVENT_IN_AREA:
break;
case BUTTON_EVENT_UP:
tp_button_set_state(tp, t, BUTTON_STATE_NONE, event, time);
break;
case BUTTON_EVENT_PRESS:
t->button.current = BUTTON_EVENT_IN_AREA;
break;
case BUTTON_EVENT_RELEASE:
break;
case BUTTON_EVENT_TIMEOUT:
break;
}
}
static void
tp_button_handle_event(struct tp_dispatch *tp,
struct tp_touch *t,
enum button_event event,
uint64_t time)
{
enum button_state current = t->button.state;
switch(t->button.state) {
case BUTTON_STATE_NONE:
tp_button_none_handle_event(tp, t, event, time);
break;
case BUTTON_STATE_AREA:
tp_button_area_handle_event(tp, t, event, time);
break;
case BUTTON_STATE_BOTTOM:
tp_button_bottom_handle_event(tp, t, event, time);
break;
case BUTTON_STATE_TOP:
tp_button_top_handle_event(tp, t, event, time);
break;
case BUTTON_STATE_TOP_NEW:
tp_button_top_new_handle_event(tp, t, event, time);
break;
case BUTTON_STATE_TOP_TO_IGNORE:
tp_button_top_to_ignore_handle_event(tp, t, event, time);
break;
case BUTTON_STATE_IGNORE:
tp_button_ignore_handle_event(tp, t, event, time);
break;
}
if (current != t->button.state)
evdev_log_debug(tp->device,
"button state: touch %d from %-20s event %-24s to %-20s\n",
t->index,
button_state_to_str(current),
button_event_to_str(event),
button_state_to_str(t->button.state));
}
static inline void
tp_button_check_for_movement(struct tp_dispatch *tp, struct tp_touch *t)
{
struct device_coords delta;
struct phys_coords mm;
double vector_length;
if (t->button.has_moved)
return;
switch (t->button.state) {
case BUTTON_STATE_NONE:
case BUTTON_STATE_AREA:
case BUTTON_STATE_TOP:
case BUTTON_STATE_TOP_NEW:
case BUTTON_STATE_TOP_TO_IGNORE:
case BUTTON_STATE_IGNORE:
/* No point calculating if we're not going to use it */
return;
case BUTTON_STATE_BOTTOM:
break;
}
delta.x = t->point.x - t->button.initial.x;
delta.y = t->point.y - t->button.initial.y;
mm = evdev_device_unit_delta_to_mm(tp->device, &delta);
vector_length = hypot(mm.x, mm.y);
if (vector_length > 5.0 /* mm */) {
t->button.has_moved = true;
tp_button_release_other_bottom_touches(tp,
t->button.initial_time);
}
}
void
tp_button_handle_state(struct tp_dispatch *tp, uint64_t time)
{
struct tp_touch *t;
tp_for_each_touch(tp, t) {
if (t->state == TOUCH_NONE || t->state == TOUCH_HOVERING)
continue;
if (t->state == TOUCH_BEGIN) {
t->button.initial = t->point;
t->button.initial_time = time;
t->button.has_moved = false;
}
if (t->state == TOUCH_END) {
tp_button_handle_event(tp, t, BUTTON_EVENT_UP, time);
} else if (t->dirty) {
enum button_event event;
if (is_inside_bottom_button_area(tp, t)) {
if (is_inside_bottom_right_area(tp, t))
event = BUTTON_EVENT_IN_BOTTOM_R;
else if (is_inside_bottom_middle_area(tp, t))
event = BUTTON_EVENT_IN_BOTTOM_M;
else
event = BUTTON_EVENT_IN_BOTTOM_L;
/* In the bottom area we check for movement
* within the area. Top area - meh */
tp_button_check_for_movement(tp, t);
} else if (is_inside_top_button_area(tp, t)) {
if (is_inside_top_right_area(tp, t))
event = BUTTON_EVENT_IN_TOP_R;
else if (is_inside_top_middle_area(tp, t))
event = BUTTON_EVENT_IN_TOP_M;
else
event = BUTTON_EVENT_IN_TOP_L;
} else {
event = BUTTON_EVENT_IN_AREA;
}
tp_button_handle_event(tp, t, event, time);
}
if (tp->queued & TOUCHPAD_EVENT_BUTTON_RELEASE)
tp_button_handle_event(tp, t, BUTTON_EVENT_RELEASE, time);
if (tp->queued & TOUCHPAD_EVENT_BUTTON_PRESS)
tp_button_handle_event(tp, t, BUTTON_EVENT_PRESS, time);
}
}
static void
tp_button_handle_timeout(uint64_t now, void *data)
{
struct tp_touch *t = data;
tp_button_handle_event(t->tp, t, BUTTON_EVENT_TIMEOUT, now);
}
void
tp_process_button(struct tp_dispatch *tp,
const struct input_event *e,
uint64_t time)
{
uint32_t mask = bit(e->code - BTN_LEFT);
/* Ignore other buttons on clickpads */
if (tp->buttons.is_clickpad && e->code != BTN_LEFT) {
evdev_log_bug_kernel(tp->device,
"received %s button event on a clickpad\n",
libevdev_event_code_get_name(EV_KEY, e->code));
return;
}
if (e->value) {
tp->buttons.state |= mask;
tp->queued |= TOUCHPAD_EVENT_BUTTON_PRESS;
} else {
tp->buttons.state &= ~mask;
tp->queued |= TOUCHPAD_EVENT_BUTTON_RELEASE;
}
}
void
tp_release_all_buttons(struct tp_dispatch *tp,
uint64_t time)
{
if (tp->buttons.state) {
tp->buttons.state = 0;
tp->queued |= TOUCHPAD_EVENT_BUTTON_RELEASE;
}
}
static void
tp_init_softbuttons(struct tp_dispatch *tp,
struct evdev_device *device)
{
double width, height;
struct device_coords edges;
int mb_le, mb_re; /* middle button left/right edge */
struct phys_coords mm = { 0.0, 0.0 };
evdev_device_get_size(device, &width, &height);
/* button height: 10mm or 15% or the touchpad height,
whichever is smaller */
if (height * 0.15 > 10)
mm.y = height - 10;
else
mm.y = height * 0.85;
mm.x = width * 0.5;
edges = evdev_device_mm_to_units(device, &mm);
tp->buttons.bottom_area.top_edge = edges.y;
tp->buttons.bottom_area.rightbutton_left_edge = edges.x;
tp->buttons.bottom_area.middlebutton_left_edge = INT_MAX;
/* if middlebutton emulation is enabled, don't init a software area */
if (device->middlebutton.want_enabled)
return;
/* The middle button is 25% of the touchpad and centered. Many
* touchpads don't have markings for the middle button at all so we
* need to make it big enough to reliably hit it but not too big so
* it takes away all the space.
*
* On touchpads with visible markings we reduce the size of the
* middle button since users have a visual guide.
*/
if (evdev_device_has_model_quirk(device,
QUIRK_MODEL_TOUCHPAD_VISIBLE_MARKER)) {
mm.x = width/2 - 5; /* 10mm wide */
edges = evdev_device_mm_to_units(device, &mm);
mb_le = edges.x;
mm.x = width/2 + 5; /* 10mm wide */
edges = evdev_device_mm_to_units(device, &mm);
mb_re = edges.x;
} else {
mm.x = width * 0.375;
edges = evdev_device_mm_to_units(device, &mm);
mb_le = edges.x;
mm.x = width * 0.625;
edges = evdev_device_mm_to_units(device, &mm);
mb_re = edges.x;
}
tp->buttons.bottom_area.middlebutton_left_edge = mb_le;
tp->buttons.bottom_area.rightbutton_left_edge = mb_re;
}
void
tp_init_top_softbuttons(struct tp_dispatch *tp,
struct evdev_device *device,
double topbutton_size_mult)
{
struct device_coords edges;
if (tp->buttons.has_topbuttons) {
/* T440s has the top button line 5mm from the top, event
analysis has shown events to start down to ~10mm from the
top - which maps to 15%. We allow the caller to enlarge the
area using a multiplier for the touchpad disabled case. */
double topsize_mm = 10 * topbutton_size_mult;
struct phys_coords mm;
double width, height;
evdev_device_get_size(device, &width, &height);
mm.x = width * 0.60;
mm.y = topsize_mm;
edges = evdev_device_mm_to_units(device, &mm);
tp->buttons.top_area.bottom_edge = edges.y;
tp->buttons.top_area.rightbutton_left_edge = edges.x;
mm.x = width * 0.40;
edges = evdev_device_mm_to_units(device, &mm);
tp->buttons.top_area.leftbutton_right_edge = edges.x;
} else {
tp->buttons.top_area.bottom_edge = INT_MIN;
}
}
static inline uint32_t
tp_button_config_click_get_methods(struct libinput_device *device)
{
struct evdev_device *evdev = evdev_device(device);
struct tp_dispatch *tp = (struct tp_dispatch*)evdev->dispatch;
uint32_t methods = LIBINPUT_CONFIG_CLICK_METHOD_NONE;
if (tp->buttons.is_clickpad) {
methods |= LIBINPUT_CONFIG_CLICK_METHOD_BUTTON_AREAS;
if (tp->has_mt)
methods |= LIBINPUT_CONFIG_CLICK_METHOD_CLICKFINGER;
}
if (evdev->model_flags & EVDEV_MODEL_APPLE_TOUCHPAD_ONEBUTTON)
methods |= LIBINPUT_CONFIG_CLICK_METHOD_CLICKFINGER;
return methods;
}
static void
tp_switch_click_method(struct tp_dispatch *tp)
{
/*
* All we need to do when switching click methods is to change the
* bottom_area.top_edge so that when in clickfinger mode the bottom
* touchpad area is not dead wrt finger movement starting there.
*
* We do not need to take any state into account, fingers which are
* already down will simply keep the state / area they have assigned
* until they are released, and the post_button_events path is state
* agnostic.
*/
switch (tp->buttons.click_method) {
case LIBINPUT_CONFIG_CLICK_METHOD_BUTTON_AREAS:
tp_init_softbuttons(tp, tp->device);
break;
case LIBINPUT_CONFIG_CLICK_METHOD_CLICKFINGER:
case LIBINPUT_CONFIG_CLICK_METHOD_NONE:
tp->buttons.bottom_area.top_edge = INT_MAX;
break;
}
}
static enum libinput_config_status
tp_button_config_click_set_method(struct libinput_device *device,
enum libinput_config_click_method method)
{
struct evdev_device *evdev = evdev_device(device);
struct tp_dispatch *tp = (struct tp_dispatch*)evdev->dispatch;
tp->buttons.click_method = method;
tp_switch_click_method(tp);
return LIBINPUT_CONFIG_STATUS_SUCCESS;
}
static enum libinput_config_click_method
tp_button_config_click_get_method(struct libinput_device *device)
{
struct evdev_device *evdev = evdev_device(device);
struct tp_dispatch *tp = (struct tp_dispatch*)evdev->dispatch;
return tp->buttons.click_method;
}
static enum libinput_config_click_method
tp_click_get_default_method(struct tp_dispatch *tp)
{
struct evdev_device *device = tp->device;
if (evdev_device_has_model_quirk(device, QUIRK_MODEL_CHROMEBOOK) ||
evdev_device_has_model_quirk(device, QUIRK_MODEL_SYSTEM76_BONOBO) ||
evdev_device_has_model_quirk(device, QUIRK_MODEL_SYSTEM76_GALAGO) ||
evdev_device_has_model_quirk(device, QUIRK_MODEL_SYSTEM76_KUDU) ||
evdev_device_has_model_quirk(device, QUIRK_MODEL_CLEVO_W740SU) ||
evdev_device_has_model_quirk(device, QUIRK_MODEL_APPLE_TOUCHPAD_ONEBUTTON))
return LIBINPUT_CONFIG_CLICK_METHOD_CLICKFINGER;
if (!tp->buttons.is_clickpad)
return LIBINPUT_CONFIG_CLICK_METHOD_NONE;
if (evdev_device_has_model_quirk(device, QUIRK_MODEL_APPLE_TOUCHPAD))
return LIBINPUT_CONFIG_CLICK_METHOD_CLICKFINGER;
return LIBINPUT_CONFIG_CLICK_METHOD_BUTTON_AREAS;
}
static enum libinput_config_click_method
tp_button_config_click_get_default_method(struct libinput_device *device)
{
struct evdev_device *evdev = evdev_device(device);
struct tp_dispatch *tp = (struct tp_dispatch*)evdev->dispatch;
return tp_click_get_default_method(tp);
}
void
tp_clickpad_middlebutton_apply_config(struct evdev_device *device)
{
struct tp_dispatch *tp = (struct tp_dispatch*)device->dispatch;
if (!tp->buttons.is_clickpad ||
tp->buttons.state != 0)
return;
if (device->middlebutton.want_enabled ==
device->middlebutton.enabled)
return;
device->middlebutton.enabled = device->middlebutton.want_enabled;
if (tp->buttons.click_method ==
LIBINPUT_CONFIG_CLICK_METHOD_BUTTON_AREAS)
tp_init_softbuttons(tp, device);
}
static int
tp_clickpad_middlebutton_is_available(struct libinput_device *device)
{
return evdev_middlebutton_is_available(device);
}
static enum libinput_config_status
tp_clickpad_middlebutton_set(struct libinput_device *device,
enum libinput_config_middle_emulation_state enable)
{
struct evdev_device *evdev = evdev_device(device);
switch (enable) {
case LIBINPUT_CONFIG_MIDDLE_EMULATION_ENABLED:
evdev->middlebutton.want_enabled = true;
break;
case LIBINPUT_CONFIG_MIDDLE_EMULATION_DISABLED:
evdev->middlebutton.want_enabled = false;
break;
default:
return LIBINPUT_CONFIG_STATUS_INVALID;
}
tp_clickpad_middlebutton_apply_config(evdev);
return LIBINPUT_CONFIG_STATUS_SUCCESS;
}
static enum libinput_config_middle_emulation_state
tp_clickpad_middlebutton_get(struct libinput_device *device)
{
return evdev_middlebutton_get(device);
}
static enum libinput_config_middle_emulation_state
tp_clickpad_middlebutton_get_default(struct libinput_device *device)
{
return evdev_middlebutton_get_default(device);
}
static inline void
tp_init_clickpad_middlebutton_emulation(struct tp_dispatch *tp,
struct evdev_device *device)
{
device->middlebutton.enabled_default = false;
device->middlebutton.want_enabled = false;
device->middlebutton.enabled = false;
device->middlebutton.config.available = tp_clickpad_middlebutton_is_available;
device->middlebutton.config.set = tp_clickpad_middlebutton_set;
device->middlebutton.config.get = tp_clickpad_middlebutton_get;
device->middlebutton.config.get_default = tp_clickpad_middlebutton_get_default;
device->base.config.middle_emulation = &device->middlebutton.config;
}
static inline void
tp_init_middlebutton_emulation(struct tp_dispatch *tp,
struct evdev_device *device)
{
bool enable_by_default,
want_config_option;
/* On clickpads we provide the config option but disable by default.
When enabled, the middle software button disappears */
if (tp->buttons.is_clickpad) {
tp_init_clickpad_middlebutton_emulation(tp, device);
return;
}
/* init middle button emulation on non-clickpads, but only if we
* don't have a middle button. Exception: ALPS touchpads don't know
* if they have a middle button, so we always want the option there
* and enabled by default.
*/
if (!libevdev_has_event_code(device->evdev, EV_KEY, BTN_MIDDLE)) {
enable_by_default = true;
want_config_option = false;
} else if (evdev_device_has_model_quirk(device,
QUIRK_MODEL_ALPS_SERIAL_TOUCHPAD)) {
enable_by_default = true;
want_config_option = true;
} else
return;
evdev_init_middlebutton(tp->device,
enable_by_default,
want_config_option);
}
static bool
tp_guess_clickpad(const struct tp_dispatch *tp, struct evdev_device *device)
{
bool is_clickpad;
bool has_left = libevdev_has_event_code(device->evdev, EV_KEY, BTN_LEFT),
has_middle = libevdev_has_event_code(device->evdev, EV_KEY, BTN_MIDDLE),
has_right = libevdev_has_event_code(device->evdev, EV_KEY, BTN_RIGHT);
is_clickpad = libevdev_has_property(device->evdev, INPUT_PROP_BUTTONPAD);
/* A non-clickpad without a right button is a clickpad, assume the
* kernel is wrong.
* Exceptions here:
* - The one-button Apple touchpad (discontinued in 2008) has a
* single physical button
* - Wacom touch devices have neither left nor right buttons
*/
if (!is_clickpad && has_left && !has_right &&
(tp->device->model_flags & EVDEV_MODEL_APPLE_TOUCHPAD_ONEBUTTON) == 0) {
evdev_log_bug_kernel(device,
"missing right button, assuming it is a clickpad.\n");
is_clickpad = true;
}
if (has_middle || has_right) {
if (is_clickpad)
evdev_log_bug_kernel(device,
"clickpad advertising right button. "
"See %s/clickpad-with-right-button.html for details\n",
HTTP_DOC_LINK);
} else if (has_left &&
!is_clickpad &&
libevdev_get_id_vendor(device->evdev) != VENDOR_ID_APPLE) {
evdev_log_bug_kernel(device,
"non clickpad without right button?\n");
}
return is_clickpad;
}
static inline void
tp_button_update_clickfinger_map(struct tp_dispatch *tp)
{
if (tp->buttons.state != BUTTON_STATE_NONE)
return;
if (tp->buttons.map != tp->buttons.want_map)
tp->buttons.map = tp->buttons.want_map;
}
void
tp_button_post_process_state(struct tp_dispatch *tp)
{
tp_button_update_clickfinger_map(tp);
}
static enum libinput_config_status
tp_button_config_set_clickfinger_map(struct libinput_device *device,
enum libinput_config_clickfinger_button_map map)
{
struct evdev_dispatch *dispatch = evdev_device(device)->dispatch;
struct tp_dispatch *tp = tp_dispatch(dispatch);
tp->buttons.want_map = map;
tp_button_update_clickfinger_map(tp);
return LIBINPUT_CONFIG_STATUS_SUCCESS;
}
static enum libinput_config_clickfinger_button_map
tp_button_config_get_clickfinger_map(struct libinput_device *device)
{
struct evdev_dispatch *dispatch = evdev_device(device)->dispatch;
struct tp_dispatch *tp = tp_dispatch(dispatch);
return tp->buttons.want_map;
}
static enum libinput_config_clickfinger_button_map
tp_button_config_get_default_clickfinger_map(struct libinput_device *device)
{
return LIBINPUT_CONFIG_CLICKFINGER_MAP_LRM;
}
void
tp_init_buttons(struct tp_dispatch *tp,
struct evdev_device *device)
{
struct tp_touch *t;
const struct input_absinfo *absinfo_x, *absinfo_y;
int i;
tp->buttons.is_clickpad = tp_guess_clickpad(tp, device);
tp->buttons.has_topbuttons = libevdev_has_property(device->evdev,
INPUT_PROP_TOPBUTTONPAD);
absinfo_x = device->abs.absinfo_x;
absinfo_y = device->abs.absinfo_y;
/* pinned-finger motion threshold, see tp_unpin_finger. */
tp->buttons.motion_dist.x_scale_coeff = 1.0/absinfo_x->resolution;
tp->buttons.motion_dist.y_scale_coeff = 1.0/absinfo_y->resolution;
tp->buttons.config_method.get_methods = tp_button_config_click_get_methods;
tp->buttons.config_method.set_method = tp_button_config_click_set_method;
tp->buttons.config_method.get_method = tp_button_config_click_get_method;
tp->buttons.config_method.get_default_method = tp_button_config_click_get_default_method;
tp->buttons.config_method.set_clickfinger_map = tp_button_config_set_clickfinger_map;
tp->buttons.config_method.get_clickfinger_map = tp_button_config_get_clickfinger_map;
tp->buttons.config_method.get_default_clickfinger_map = tp_button_config_get_default_clickfinger_map;
tp->device->base.config.click_method = &tp->buttons.config_method;
tp->buttons.map = LIBINPUT_CONFIG_CLICKFINGER_MAP_LRM;
tp->buttons.want_map = tp->buttons.map;
tp->buttons.click_method = tp_click_get_default_method(tp);
tp_switch_click_method(tp);
tp_init_top_softbuttons(tp, device, 1.0);
tp_init_middlebutton_emulation(tp, device);
i = 0;
tp_for_each_touch(tp, t) {
char timer_name[64];
i++;
snprintf(timer_name,
sizeof(timer_name),
"%s (%d) button",
evdev_device_get_sysname(device),
i);
t->button.state = BUTTON_STATE_NONE;
libinput_timer_init(&t->button.timer,
tp_libinput_context(tp),
timer_name,
tp_button_handle_timeout, t);
}
}
void
tp_remove_buttons(struct tp_dispatch *tp)
{
struct tp_touch *t;
tp_for_each_touch(tp, t) {
libinput_timer_cancel(&t->button.timer);
libinput_timer_destroy(&t->button.timer);
}
}
static int
tp_post_physical_buttons(struct tp_dispatch *tp, uint64_t time)
{
uint32_t current, old, button;
current = tp->buttons.state;
old = tp->buttons.old_state;
button = BTN_LEFT;
while (current || old) {
enum libinput_button_state state;
if ((current & 0x1) ^ (old & 0x1)) {
uint32_t b;
if (!!(current & 0x1))
state = LIBINPUT_BUTTON_STATE_PRESSED;
else
state = LIBINPUT_BUTTON_STATE_RELEASED;
b = evdev_to_left_handed(tp->device, button);
evdev_pointer_notify_physical_button(tp->device,
time,
b,
state);
}
button++;
current >>= 1;
old >>= 1;
}
return 0;
}
static inline bool
tp_clickfinger_within_distance(struct tp_dispatch *tp,
struct tp_touch *t1,
struct tp_touch *t2)
{
double x, y;
bool within_distance = false;
int xres, yres;
int bottom_threshold;
if (!t1 || !t2)
return 0;
if (tp_thumb_ignored(tp, t1) || tp_thumb_ignored(tp, t2))
return 0;
x = abs(t1->point.x - t2->point.x);
y = abs(t1->point.y - t2->point.y);
xres = tp->device->abs.absinfo_x->resolution;
yres = tp->device->abs.absinfo_y->resolution;
x /= xres;
y /= yres;
/* maximum horiz spread is 40mm horiz, 30mm vert, anything wider
* than that is probably a gesture. */
if (x > 40 || y > 30)
goto out;
within_distance = true;
/* if y spread is <= 20mm, they're definitely together. */
if (y <= 20)
goto out;
/* if they're vertically spread between 20-40mm, they're not
* together if:
* - the touchpad's vertical size is >50mm, anything smaller is
* unlikely to have a thumb resting on it
* - and one of the touches is in the bottom 20mm of the touchpad
* and the other one isn't
*/
if (tp->device->abs.dimensions.y/yres < 50)
goto out;
bottom_threshold = tp->device->abs.absinfo_y->maximum - 20 * yres;
if ((t1->point.y > bottom_threshold) !=
(t2->point.y > bottom_threshold))
within_distance = 0;
out:
return within_distance;
}
static uint32_t
tp_clickfinger_set_button(struct tp_dispatch *tp)
{
uint32_t button;
unsigned int nfingers = 0;
struct tp_touch *t;
struct tp_touch *first = NULL,
*second = NULL;
int32_t button_map[2][3] = {
{ BTN_LEFT, BTN_RIGHT, BTN_MIDDLE },
{ BTN_LEFT, BTN_MIDDLE, BTN_RIGHT },
};
tp_for_each_touch(tp, t) {
if (t->state != TOUCH_BEGIN && t->state != TOUCH_UPDATE)
continue;
if (tp_thumb_ignored(tp, t))
continue;
if (t->palm.state != PALM_NONE)
continue;
nfingers++;
if (!first)
first = t;
else if (!second)
second = t;
}
/* Only check for finger distance when there are 2 fingers on the
* touchpad */
if (nfingers != 2)
goto out;
if (tp_clickfinger_within_distance(tp, first, second))
nfingers = 2;
else
nfingers = 1;
out:
nfingers = max(1, nfingers);
switch (nfingers) {
case 1:
case 2:
case 3: button = button_map[tp->buttons.map][nfingers-1]; break;
default:
button = 0;
break;
}
return button;
}
static int
tp_notify_clickpadbutton(struct tp_dispatch *tp,
uint64_t time,
uint32_t button,
uint32_t is_topbutton,
enum libinput_button_state state)
{
/* If we've a trackpoint, send top buttons through the trackpoint */
if (tp->buttons.trackpoint) {
if (is_topbutton) {
struct evdev_dispatch *dispatch = tp->buttons.trackpoint->dispatch;
struct input_event event, syn_report;
int value;
value = (state == LIBINPUT_BUTTON_STATE_PRESSED) ? 1 : 0;
event = input_event_init(time, EV_KEY, button, value);
syn_report = input_event_init(time, EV_SYN, SYN_REPORT, 0);
dispatch->interface->process(dispatch,
tp->buttons.trackpoint,
&event,
time);
dispatch->interface->process(dispatch,
tp->buttons.trackpoint,
&syn_report,
time);
return 1;
}
/* Ignore button events not for the trackpoint while suspended */
if (tp->device->is_suspended)
return 0;
}
/* A button click always terminates edge scrolling, even if we
* don't end up sending a button event. */
tp_edge_scroll_stop_events(tp, time);
/*
* If the user has requested clickfinger replace the button chosen
* by the softbutton code with one based on the number of fingers.
*/
if (tp->buttons.click_method == LIBINPUT_CONFIG_CLICK_METHOD_CLICKFINGER &&
state == LIBINPUT_BUTTON_STATE_PRESSED) {
button = tp_clickfinger_set_button(tp);
tp->buttons.active = button;
if (!button)
return 0;
}
evdev_pointer_notify_button(tp->device, time, button, state);
return 1;
}
static int
tp_post_clickpadbutton_buttons(struct tp_dispatch *tp, uint64_t time)
{
uint32_t current, old, button, is_top;
enum libinput_button_state state;
enum { AREA = 0x01, LEFT = 0x02, MIDDLE = 0x04, RIGHT = 0x08 };
bool want_left_handed = true;
current = tp->buttons.state;
old = tp->buttons.old_state;
is_top = 0;
if (!tp->buttons.click_pending && current == old)
return 0;
if (current) {
struct tp_touch *t;
uint32_t area = 0;
if (evdev_device_has_model_quirk(tp->device,
QUIRK_MODEL_TOUCHPAD_PHANTOM_CLICKS) &&
tp->nactive_slots == 0) {
/* Some touchpads, notably those on the Dell XPS 15 9500,
* are prone to registering touchpad clicks when the
* case is sufficiently flexed. Ignore these by
* disregarding any clicks that are registered without
* touchpad touch. */
tp->buttons.click_pending = true;
return 0;
}
tp_for_each_touch(tp, t) {
switch (t->button.current) {
case BUTTON_EVENT_IN_AREA:
area |= AREA;
break;
case BUTTON_EVENT_IN_TOP_L:
is_top = 1;
_fallthrough_;
case BUTTON_EVENT_IN_BOTTOM_L:
area |= LEFT;
break;
case BUTTON_EVENT_IN_TOP_M:
is_top = 1;
_fallthrough_;
case BUTTON_EVENT_IN_BOTTOM_M:
area |= MIDDLE;
break;
case BUTTON_EVENT_IN_TOP_R:
is_top = 1;
_fallthrough_;
case BUTTON_EVENT_IN_BOTTOM_R:
area |= RIGHT;
break;
default:
break;
}
}
if (area == 0 &&
tp->buttons.click_method != LIBINPUT_CONFIG_CLICK_METHOD_CLICKFINGER) {
/* No touches, wait for a touch before processing */
tp->buttons.click_pending = true;
return 0;
}
if ((tp->device->middlebutton.enabled || is_top) &&
(area & LEFT) && (area & RIGHT)) {
button = BTN_MIDDLE;
} else if (area & MIDDLE) {
button = BTN_MIDDLE;
} else if (area & RIGHT) {
button = BTN_RIGHT;
} else if (area & LEFT) {
button = BTN_LEFT;
} else { /* main or no area (for clickfinger) is always BTN_LEFT */
button = BTN_LEFT;
want_left_handed = false;
}
if (is_top)
want_left_handed = false;
if (want_left_handed)
button = evdev_to_left_handed(tp->device, button);
tp->buttons.active = button;
tp->buttons.active_is_topbutton = is_top;
state = LIBINPUT_BUTTON_STATE_PRESSED;
} else {
button = tp->buttons.active;
is_top = tp->buttons.active_is_topbutton;
tp->buttons.active = 0;
tp->buttons.active_is_topbutton = 0;
state = LIBINPUT_BUTTON_STATE_RELEASED;
}
tp->buttons.click_pending = false;
if (button)
return tp_notify_clickpadbutton(tp,
time,
button,
is_top,
state);
return 0;
}
int
tp_post_button_events(struct tp_dispatch *tp, uint64_t time)
{
if (tp->buttons.is_clickpad ||
tp->device->model_flags & EVDEV_MODEL_APPLE_TOUCHPAD_ONEBUTTON)
return tp_post_clickpadbutton_buttons(tp, time);
return tp_post_physical_buttons(tp, time);
}
bool
tp_button_touch_active(const struct tp_dispatch *tp,
const struct tp_touch *t)
{
return t->button.state == BUTTON_STATE_AREA || t->button.has_moved;
}
bool
tp_button_is_inside_softbutton_area(const struct tp_dispatch *tp,
const struct tp_touch *t)
{
return is_inside_top_button_area(tp, t) ||
is_inside_bottom_button_area(tp, t);
}
libinput-1.28.1/src/evdev-mt-touchpad-edge-scroll.c000066400000000000000000000320641477265155700221460ustar00rootroot00000000000000/*
* Copyright © 2014-2015 Red Hat, Inc.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice (including the next
* paragraph) shall be included in all copies or substantial portions of the
* Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
*/
#include "config.h"
#include
#include
#include
#include "evdev-mt-touchpad.h"
/* Use a reasonably large threshold until locked into scrolling mode, to
avoid accidentally locking in scrolling mode when trying to use the entire
touchpad to move the pointer. The user can wait for the timeout to trigger
to do a small scroll. */
#define DEFAULT_SCROLL_THRESHOLD TP_MM_TO_DPI_NORMALIZED(3)
enum scroll_event {
SCROLL_EVENT_TOUCH,
SCROLL_EVENT_MOTION,
SCROLL_EVENT_RELEASE,
SCROLL_EVENT_TIMEOUT,
SCROLL_EVENT_POSTED,
};
static inline const char*
edge_state_to_str(enum tp_edge_scroll_touch_state state)
{
switch (state) {
CASE_RETURN_STRING(EDGE_SCROLL_TOUCH_STATE_NONE);
CASE_RETURN_STRING(EDGE_SCROLL_TOUCH_STATE_EDGE_NEW);
CASE_RETURN_STRING(EDGE_SCROLL_TOUCH_STATE_EDGE);
CASE_RETURN_STRING(EDGE_SCROLL_TOUCH_STATE_AREA);
}
return NULL;
}
static inline const char*
edge_event_to_str(enum scroll_event event)
{
switch (event) {
CASE_RETURN_STRING(SCROLL_EVENT_TOUCH);
CASE_RETURN_STRING(SCROLL_EVENT_MOTION);
CASE_RETURN_STRING(SCROLL_EVENT_RELEASE);
CASE_RETURN_STRING(SCROLL_EVENT_TIMEOUT);
CASE_RETURN_STRING(SCROLL_EVENT_POSTED);
}
return NULL;
}
uint32_t
tp_touch_get_edge(const struct tp_dispatch *tp, const struct tp_touch *t)
{
uint32_t edge = EDGE_NONE;
if (tp->scroll.method != LIBINPUT_CONFIG_SCROLL_EDGE)
return EDGE_NONE;
if (t->point.x > tp->scroll.right_edge)
edge |= EDGE_RIGHT;
if (t->point.y > tp->scroll.bottom_edge)
edge |= EDGE_BOTTOM;
return edge;
}
static inline void
tp_edge_scroll_set_timer(struct tp_dispatch *tp,
struct tp_touch *t,
uint64_t time)
{
const int DEFAULT_SCROLL_LOCK_TIMEOUT = ms2us(300);
/* if we use software buttons, we disable timeout-based
* edge scrolling. A finger resting on the button areas is
* likely there to trigger a button event.
*/
if (tp->buttons.click_method ==
LIBINPUT_CONFIG_CLICK_METHOD_BUTTON_AREAS)
return;
libinput_timer_set(&t->scroll.timer,
time + DEFAULT_SCROLL_LOCK_TIMEOUT);
}
static void
tp_edge_scroll_set_state(struct tp_dispatch *tp,
struct tp_touch *t,
enum tp_edge_scroll_touch_state state,
uint64_t time)
{
libinput_timer_cancel(&t->scroll.timer);
t->scroll.edge_state = state;
switch (state) {
case EDGE_SCROLL_TOUCH_STATE_NONE:
t->scroll.edge = EDGE_NONE;
break;
case EDGE_SCROLL_TOUCH_STATE_EDGE_NEW:
t->scroll.edge = tp_touch_get_edge(tp, t);
t->scroll.initial = t->point;
tp_edge_scroll_set_timer(tp, t, time);
break;
case EDGE_SCROLL_TOUCH_STATE_EDGE:
break;
case EDGE_SCROLL_TOUCH_STATE_AREA:
t->scroll.edge = EDGE_NONE;
break;
}
}
static void
tp_edge_scroll_handle_none(struct tp_dispatch *tp,
struct tp_touch *t,
enum scroll_event event,
uint64_t time)
{
switch (event) {
case SCROLL_EVENT_TOUCH:
if (tp_touch_get_edge(tp, t)) {
tp_edge_scroll_set_state(tp,
t,
EDGE_SCROLL_TOUCH_STATE_EDGE_NEW,
time);
} else {
tp_edge_scroll_set_state(tp,
t,
EDGE_SCROLL_TOUCH_STATE_AREA,
time);
}
break;
case SCROLL_EVENT_MOTION:
case SCROLL_EVENT_RELEASE:
case SCROLL_EVENT_TIMEOUT:
case SCROLL_EVENT_POSTED:
evdev_log_bug_libinput(tp->device,
"edge-scroll: touch %d: unexpected scroll event %d in none state\n",
t->index,
event);
break;
}
}
static void
tp_edge_scroll_handle_edge_new(struct tp_dispatch *tp,
struct tp_touch *t,
enum scroll_event event,
uint64_t time)
{
switch (event) {
case SCROLL_EVENT_TOUCH:
evdev_log_bug_libinput(tp->device,
"edge-scroll: touch %d: unexpected scroll event %d in edge new state\n",
t->index,
event);
break;
case SCROLL_EVENT_MOTION:
t->scroll.edge &= tp_touch_get_edge(tp, t);
if (!t->scroll.edge)
tp_edge_scroll_set_state(tp,
t,
EDGE_SCROLL_TOUCH_STATE_AREA,
time);
break;
case SCROLL_EVENT_RELEASE:
tp_edge_scroll_set_state(tp,
t,
EDGE_SCROLL_TOUCH_STATE_NONE,
time);
break;
case SCROLL_EVENT_TIMEOUT:
case SCROLL_EVENT_POSTED:
tp_edge_scroll_set_state(tp,
t,
EDGE_SCROLL_TOUCH_STATE_EDGE,
time);
break;
}
}
static void
tp_edge_scroll_handle_edge(struct tp_dispatch *tp,
struct tp_touch *t,
enum scroll_event event,
uint64_t time)
{
switch (event) {
case SCROLL_EVENT_TOUCH:
case SCROLL_EVENT_TIMEOUT:
evdev_log_bug_libinput(tp->device,
"edge-scroll: touch %d: unexpected scroll event %d in edge state\n",
t->index,
event);
break;
case SCROLL_EVENT_MOTION:
/* If started at the bottom right, decide in which dir to scroll */
if (t->scroll.edge == (EDGE_RIGHT | EDGE_BOTTOM)) {
t->scroll.edge &= tp_touch_get_edge(tp, t);
if (!t->scroll.edge)
tp_edge_scroll_set_state(tp,
t,
EDGE_SCROLL_TOUCH_STATE_AREA,
time);
}
break;
case SCROLL_EVENT_RELEASE:
tp_edge_scroll_set_state(tp,
t,
EDGE_SCROLL_TOUCH_STATE_NONE,
time);
break;
case SCROLL_EVENT_POSTED:
break;
}
}
static void
tp_edge_scroll_handle_area(struct tp_dispatch *tp,
struct tp_touch *t,
enum scroll_event event,
uint64_t time)
{
switch (event) {
case SCROLL_EVENT_TOUCH:
case SCROLL_EVENT_TIMEOUT:
case SCROLL_EVENT_POSTED:
evdev_log_bug_libinput(tp->device,
"unexpected scroll event %d in area state\n",
event);
break;
case SCROLL_EVENT_MOTION:
break;
case SCROLL_EVENT_RELEASE:
tp_edge_scroll_set_state(tp,
t,
EDGE_SCROLL_TOUCH_STATE_NONE,
time);
break;
}
}
static void
tp_edge_scroll_handle_event(struct tp_dispatch *tp,
struct tp_touch *t,
enum scroll_event event,
uint64_t time)
{
enum tp_edge_scroll_touch_state current = t->scroll.edge_state;
switch (current) {
case EDGE_SCROLL_TOUCH_STATE_NONE:
tp_edge_scroll_handle_none(tp, t, event, time);
break;
case EDGE_SCROLL_TOUCH_STATE_EDGE_NEW:
tp_edge_scroll_handle_edge_new(tp, t, event, time);
break;
case EDGE_SCROLL_TOUCH_STATE_EDGE:
tp_edge_scroll_handle_edge(tp, t, event, time);
break;
case EDGE_SCROLL_TOUCH_STATE_AREA:
tp_edge_scroll_handle_area(tp, t, event, time);
break;
}
if (current != t->scroll.edge_state)
evdev_log_debug(tp->device,
"edge-scroll: touch %d state %s → %s → %s\n",
t->index,
edge_state_to_str(current),
edge_event_to_str(event),
edge_state_to_str(t->scroll.edge_state));
}
static void
tp_edge_scroll_handle_timeout(uint64_t now, void *data)
{
struct tp_touch *t = data;
tp_edge_scroll_handle_event(t->tp, t, SCROLL_EVENT_TIMEOUT, now);
}
void
tp_edge_scroll_init(struct tp_dispatch *tp, struct evdev_device *device)
{
struct tp_touch *t;
double width, height;
bool want_horiz_scroll = true;
struct device_coords edges;
struct phys_coords mm = { 0.0, 0.0 };
int i;
evdev_device_get_size(device, &width, &height);
/* Touchpads smaller than 40mm are not tall enough to have a
horizontal scroll area, it takes too much space away. But
clickpads have enough space here anyway because of the
software button area (and all these tiny clickpads were built
when software buttons were a thing, e.g. Lenovo *20 series)
*/
if (!tp->buttons.is_clickpad)
want_horiz_scroll = (height >= 40);
/* 7mm edge size */
mm.x = width - 7;
mm.y = height - 7;
edges = evdev_device_mm_to_units(device, &mm);
tp->scroll.right_edge = edges.x;
if (want_horiz_scroll)
tp->scroll.bottom_edge = edges.y;
else
tp->scroll.bottom_edge = INT_MAX;
i = 0;
tp_for_each_touch(tp, t) {
char timer_name[64];
snprintf(timer_name,
sizeof(timer_name),
"%s (%d) edgescroll",
evdev_device_get_sysname(device),
i);
t->scroll.direction = -1;
libinput_timer_init(&t->scroll.timer,
tp_libinput_context(tp),
timer_name,
tp_edge_scroll_handle_timeout, t);
}
}
void
tp_remove_edge_scroll(struct tp_dispatch *tp)
{
struct tp_touch *t;
tp_for_each_touch(tp, t) {
libinput_timer_cancel(&t->scroll.timer);
libinput_timer_destroy(&t->scroll.timer);
}
}
void
tp_edge_scroll_handle_state(struct tp_dispatch *tp, uint64_t time)
{
struct tp_touch *t;
if (tp->scroll.method != LIBINPUT_CONFIG_SCROLL_EDGE) {
tp_for_each_touch(tp, t) {
if (t->state == TOUCH_BEGIN)
t->scroll.edge_state =
EDGE_SCROLL_TOUCH_STATE_AREA;
else if (t->state == TOUCH_END)
t->scroll.edge_state =
EDGE_SCROLL_TOUCH_STATE_NONE;
}
return;
}
tp_for_each_touch(tp, t) {
if (!t->dirty)
continue;
switch (t->state) {
case TOUCH_NONE:
case TOUCH_HOVERING:
break;
case TOUCH_BEGIN:
tp_edge_scroll_handle_event(tp,
t,
SCROLL_EVENT_TOUCH,
time);
break;
case TOUCH_UPDATE:
tp_edge_scroll_handle_event(tp,
t,
SCROLL_EVENT_MOTION,
time);
break;
case TOUCH_MAYBE_END:
/* This shouldn't happen we transfer to TOUCH_END
* before processing state */
evdev_log_debug(tp->device,
"touch %d: unexpected state %d\n",
t->index,
t->state);
_fallthrough_;
case TOUCH_END:
tp_edge_scroll_handle_event(tp,
t,
SCROLL_EVENT_RELEASE,
time);
break;
}
}
}
int
tp_edge_scroll_post_events(struct tp_dispatch *tp, uint64_t time)
{
struct evdev_device *device = tp->device;
struct tp_touch *t;
enum libinput_pointer_axis axis;
double *delta;
struct device_coords raw;
struct device_float_coords fraw;
struct normalized_coords normalized, tmp;
const struct normalized_coords zero = { 0.0, 0.0 };
tp_for_each_touch(tp, t) {
if (!t->dirty)
continue;
if (t->palm.state != PALM_NONE || tp_thumb_ignored(tp, t))
continue;
/* only scroll with the finger in the previous edge */
if (t->scroll.edge &&
(tp_touch_get_edge(tp, t) & t->scroll.edge) == 0)
continue;
switch (t->scroll.edge) {
case EDGE_NONE:
if (t->scroll.direction != -1) {
/* Send stop scroll event */
evdev_notify_axis_finger(device,
time,
bit(t->scroll.direction),
&zero);
t->scroll.direction = -1;
}
continue;
case EDGE_RIGHT:
axis = LIBINPUT_POINTER_AXIS_SCROLL_VERTICAL;
delta = &normalized.y;
break;
case EDGE_BOTTOM:
axis = LIBINPUT_POINTER_AXIS_SCROLL_HORIZONTAL;
delta = &normalized.x;
break;
default: /* EDGE_RIGHT | EDGE_BOTTOM */
continue; /* Don't know direction yet, skip */
}
raw = tp_get_delta(t);
fraw.x = raw.x;
fraw.y = raw.y;
/* scroll is not accelerated */
normalized = tp_filter_motion_unaccelerated(tp, &fraw, time);
switch (t->scroll.edge_state) {
case EDGE_SCROLL_TOUCH_STATE_NONE:
case EDGE_SCROLL_TOUCH_STATE_AREA:
evdev_log_bug_libinput(device,
"unexpected scroll state %d\n",
t->scroll.edge_state);
break;
case EDGE_SCROLL_TOUCH_STATE_EDGE_NEW:
tmp = normalized;
normalized = tp_normalize_delta(tp,
device_delta(t->point,
t->scroll.initial));
if (fabs(*delta) < DEFAULT_SCROLL_THRESHOLD)
normalized = zero;
else
normalized = tmp;
break;
case EDGE_SCROLL_TOUCH_STATE_EDGE:
break;
}
if (*delta == 0.0)
continue;
evdev_notify_axis_finger(device, time,
bit(axis),
&normalized);
t->scroll.direction = axis;
tp_edge_scroll_handle_event(tp, t, SCROLL_EVENT_POSTED, time);
}
return 0; /* Edge touches are suppressed by edge_scroll_touch_active */
}
void
tp_edge_scroll_stop_events(struct tp_dispatch *tp, uint64_t time)
{
struct evdev_device *device = tp->device;
struct tp_touch *t;
const struct normalized_coords zero = { 0.0, 0.0 };
tp_for_each_touch(tp, t) {
if (t->scroll.direction != -1) {
evdev_notify_axis_finger(device,
time,
bit(t->scroll.direction),
&zero);
t->scroll.direction = -1;
/* reset touch to area state, avoids loading the
* state machine with special case handling */
t->scroll.edge = EDGE_NONE;
t->scroll.edge_state = EDGE_SCROLL_TOUCH_STATE_AREA;
}
}
}
int
tp_edge_scroll_touch_active(const struct tp_dispatch *tp,
const struct tp_touch *t)
{
return t->scroll.edge_state == EDGE_SCROLL_TOUCH_STATE_AREA;
}
libinput-1.28.1/src/evdev-mt-touchpad-gestures.c000066400000000000000000002004731477265155700216100ustar00rootroot00000000000000/*
* Copyright © 2015 Red Hat, Inc.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice (including the next
* paragraph) shall be included in all copies or substantial portions of the
* Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
*/
#include "config.h"
#include
#include
#include "evdev-mt-touchpad.h"
enum gesture_cancelled {
END_GESTURE = 0,
CANCEL_GESTURE = 1,
};
#define QUICK_GESTURE_HOLD_TIMEOUT ms2us(40)
#define DEFAULT_GESTURE_HOLD_TIMEOUT ms2us(180)
#define DEFAULT_GESTURE_SWITCH_TIMEOUT ms2us(100)
#define DEFAULT_GESTURE_SWIPE_TIMEOUT ms2us(150)
#define DEFAULT_GESTURE_PINCH_TIMEOUT ms2us(300)
#define HOLD_AND_MOTION_THRESHOLD 0.5 /* mm */
#define PINCH_DISAMBIGUATION_MOVE_THRESHOLD 1.5 /* mm */
enum gesture_event {
GESTURE_EVENT_RESET,
GESTURE_EVENT_END,
GESTURE_EVENT_CANCEL,
GESTURE_EVENT_FINGER_DETECTED,
GESTURE_EVENT_FINGER_SWITCH_TIMEOUT,
GESTURE_EVENT_TAP_TIMEOUT,
GESTURE_EVENT_HOLD_TIMEOUT,
GESTURE_EVENT_HOLD_AND_MOTION_START,
GESTURE_EVENT_POINTER_MOTION_START,
GESTURE_EVENT_SCROLL_START,
GESTURE_EVENT_SWIPE_START,
GESTURE_EVENT_PINCH_START,
GESTURE_EVENT_3FG_DRAG_START,
GESTURE_EVENT_3FG_DRAG_RELEASE_TIMEOUT,
};
/*****************************************
* DO NOT EDIT THIS FILE!
*
* Look at the state diagram in doc/touchpad-gestures-state-machine.svg
* (generated with https://www.diagrams.net)
*
* Any changes in this file must be represented in the diagram.
*/
static inline const char*
gesture_state_to_str(enum tp_gesture_state state)
{
switch (state) {
CASE_RETURN_STRING(GESTURE_STATE_NONE);
CASE_RETURN_STRING(GESTURE_STATE_UNKNOWN);
CASE_RETURN_STRING(GESTURE_STATE_HOLD);
CASE_RETURN_STRING(GESTURE_STATE_HOLD_AND_MOTION);
CASE_RETURN_STRING(GESTURE_STATE_POINTER_MOTION);
CASE_RETURN_STRING(GESTURE_STATE_SCROLL_START);
CASE_RETURN_STRING(GESTURE_STATE_SCROLL);
CASE_RETURN_STRING(GESTURE_STATE_PINCH_START);
CASE_RETURN_STRING(GESTURE_STATE_PINCH);
CASE_RETURN_STRING(GESTURE_STATE_SWIPE_START);
CASE_RETURN_STRING(GESTURE_STATE_SWIPE);
CASE_RETURN_STRING(GESTURE_STATE_3FG_DRAG_START);
CASE_RETURN_STRING(GESTURE_STATE_3FG_DRAG);
CASE_RETURN_STRING(GESTURE_STATE_3FG_DRAG_RELEASED);
}
return NULL;
}
static inline const char*
gesture_event_to_str(enum gesture_event event)
{
switch(event) {
CASE_RETURN_STRING(GESTURE_EVENT_RESET);
CASE_RETURN_STRING(GESTURE_EVENT_END);
CASE_RETURN_STRING(GESTURE_EVENT_CANCEL);
CASE_RETURN_STRING(GESTURE_EVENT_FINGER_DETECTED);
CASE_RETURN_STRING(GESTURE_EVENT_FINGER_SWITCH_TIMEOUT);
CASE_RETURN_STRING(GESTURE_EVENT_TAP_TIMEOUT);
CASE_RETURN_STRING(GESTURE_EVENT_HOLD_TIMEOUT);
CASE_RETURN_STRING(GESTURE_EVENT_HOLD_AND_MOTION_START);
CASE_RETURN_STRING(GESTURE_EVENT_POINTER_MOTION_START);
CASE_RETURN_STRING(GESTURE_EVENT_SCROLL_START);
CASE_RETURN_STRING(GESTURE_EVENT_SWIPE_START);
CASE_RETURN_STRING(GESTURE_EVENT_PINCH_START);
CASE_RETURN_STRING(GESTURE_EVENT_3FG_DRAG_START);
CASE_RETURN_STRING(GESTURE_EVENT_3FG_DRAG_RELEASE_TIMEOUT);
}
return NULL;
}
static struct device_float_coords
tp_get_touches_delta(struct tp_dispatch *tp, bool average)
{
struct tp_touch *t;
unsigned int i, nactive = 0;
struct device_float_coords delta = {0.0, 0.0};
for (i = 0; i < tp->num_slots; i++) {
t = &tp->touches[i];
if (!tp_touch_active_for_gesture(tp, t))
continue;
nactive++;
if (t->dirty) {
struct device_coords d;
d = tp_get_delta(t);
delta.x += d.x;
delta.y += d.y;
}
}
if (!average || nactive == 0)
return delta;
delta.x /= nactive;
delta.y /= nactive;
return delta;
}
static void
tp_gesture_init_scroll(struct tp_dispatch *tp)
{
struct phys_coords zero = {0.0, 0.0};
tp->scroll.active.h = false;
tp->scroll.active.v = false;
tp->scroll.duration.h = 0;
tp->scroll.duration.v = 0;
tp->scroll.vector = zero;
tp->scroll.time_prev = 0;
}
static inline struct device_float_coords
tp_get_combined_touches_delta(struct tp_dispatch *tp)
{
return tp_get_touches_delta(tp, false);
}
static inline struct device_float_coords
tp_get_average_touches_delta(struct tp_dispatch *tp)
{
return tp_get_touches_delta(tp, true);
}
static struct device_float_coords
tp_get_raw_pointer_motion(struct tp_dispatch *tp)
{
struct device_float_coords raw;
/* When a clickpad is clicked, combine motion of all active touches */
if (tp->buttons.is_clickpad && tp->buttons.state)
raw = tp_get_combined_touches_delta(tp);
else
raw = tp_get_average_touches_delta(tp);
return raw;
}
static bool
tp_has_pending_pointer_motion(struct tp_dispatch *tp, uint64_t time)
{
struct device_float_coords raw;
if (!(tp->queued & TOUCHPAD_EVENT_MOTION))
return false;
/* Checking for raw pointer motion is enough in this case.
* Calling tp_filter_motion is intentionally omitted to avoid calling
* it twice (here and in tp_gesture_post_pointer_motion) with the same
* event.
*/
raw = tp_get_raw_pointer_motion(tp);
return !device_float_is_zero(raw);
}
static void
tp_gesture_post_pointer_motion(struct tp_dispatch *tp, uint64_t time)
{
struct device_float_coords raw;
struct normalized_coords delta;
raw = tp_get_raw_pointer_motion(tp);
delta = tp_filter_motion(tp, &raw, time);
if (!normalized_is_zero(delta) || !device_float_is_zero(raw)) {
struct device_float_coords unaccel;
unaccel = tp_scale_to_xaxis(tp, raw);
pointer_notify_motion(&tp->device->base,
time,
&delta,
&unaccel);
}
}
static unsigned int
tp_gesture_get_active_touches(const struct tp_dispatch *tp,
struct tp_touch **touches,
unsigned int count)
{
unsigned int n = 0;
struct tp_touch *t;
memset(touches, 0, count * sizeof(struct tp_touch *));
tp_for_each_touch(tp, t) {
if (tp_touch_active_for_gesture(tp, t)) {
touches[n++] = t;
if (n == count)
return count;
}
}
/*
* This can happen when the user does .e.g:
* 1) Put down 1st finger in center (so active)
* 2) Put down 2nd finger in a button area (so inactive)
* 3) Put down 3th finger somewhere, gets reported as a fake finger,
* so gets same coordinates as 1st -> active
*
* We could avoid this by looking at all touches, be we really only
* want to look at real touches.
*/
return n;
}
static inline int
tp_gesture_same_directions(int dir1, int dir2)
{
/*
* In some cases (semi-mt touchpads) we may seen one finger move
* e.g. N/NE and the other W/NW so we not only check for overlapping
* directions, but also for neighboring bits being set.
* The ((dira & 0x80) && (dirb & 0x01)) checks are to check for bit 0
* and 7 being set as they also represent neighboring directions.
*/
return ((dir1 | (dir1 >> 1)) & dir2) ||
((dir2 | (dir2 >> 1)) & dir1) ||
((dir1 & 0x80) && (dir2 & 0x01)) ||
((dir2 & 0x80) && (dir1 & 0x01));
}
static struct phys_coords
tp_gesture_mm_moved(struct tp_dispatch *tp, struct tp_touch *t)
{
struct device_coords delta;
delta.x = abs(t->point.x - t->gesture.initial.x);
delta.y = abs(t->point.y - t->gesture.initial.y);
return evdev_device_unit_delta_to_mm(tp->device, &delta);
}
static uint32_t
tp_gesture_get_direction(struct tp_dispatch *tp, struct tp_touch *touch)
{
struct phys_coords mm;
struct device_float_coords delta;
delta = device_delta(touch->point, touch->gesture.initial);
mm = tp_phys_delta(tp, delta);
return phys_get_direction(mm);
}
static void
tp_gesture_get_pinch_info(struct tp_dispatch *tp,
double *distance,
double *angle,
struct device_float_coords *center)
{
struct normalized_coords normalized;
struct device_float_coords delta;
struct tp_touch *first = tp->gesture.touches[0],
*second = tp->gesture.touches[1];
delta = device_delta(first->point, second->point);
normalized = tp_normalize_delta(tp, delta);
*distance = normalized_length(normalized);
*angle = rad2deg(atan2(normalized.y, normalized.x));
*center = device_average(first->point, second->point);
}
static inline void
tp_gesture_init_pinch(struct tp_dispatch *tp)
{
tp_gesture_get_pinch_info(tp,
&tp->gesture.initial_distance,
&tp->gesture.angle,
&tp->gesture.center);
tp->gesture.prev_scale = 1.0;
}
static inline void
tp_gesture_init_3fg_drag(struct tp_dispatch *tp, uint64_t time)
{
}
static inline void
tp_gesture_stop_3fg_drag(struct tp_dispatch *tp, uint64_t time)
{
}
static void
tp_gesture_set_scroll_buildup(struct tp_dispatch *tp)
{
struct device_float_coords d0, d1;
struct device_float_coords average;
struct tp_touch *first = tp->gesture.touches[0],
*second = tp->gesture.touches[1];
d0 = device_delta(first->point, first->gesture.initial);
d1 = device_delta(second->point, second->gesture.initial);
average = device_float_average(d0, d1);
tp->device->scroll.buildup = tp_normalize_delta(tp, average);
}
static void
tp_gesture_apply_scroll_constraints(struct tp_dispatch *tp,
struct device_float_coords *raw,
struct normalized_coords *delta,
uint64_t time)
{
uint64_t tdelta = 0;
struct phys_coords delta_mm, vector;
double vector_decay, vector_length, slope;
const uint64_t ACTIVE_THRESHOLD = ms2us(100),
INACTIVE_THRESHOLD = ms2us(50),
EVENT_TIMEOUT = ms2us(100);
/* Both axes active == true means free scrolling is enabled */
if (tp->scroll.active.h && tp->scroll.active.v)
return;
/* Determine time delta since last movement event */
if (tp->scroll.time_prev != 0)
tdelta = time - tp->scroll.time_prev;
if (tdelta > EVENT_TIMEOUT)
tdelta = 0;
tp->scroll.time_prev = time;
/* Delta since last movement event in mm */
delta_mm = tp_phys_delta(tp, *raw);
/* Old vector data "fades" over time. This is a two-part linear
* approximation of an exponential function - for example, for
* EVENT_TIMEOUT of 100, vector_decay = (0.97)^tdelta. This linear
* approximation allows easier tweaking of EVENT_TIMEOUT and is faster.
*/
if (tdelta > 0) {
double recent, later;
recent = ((EVENT_TIMEOUT / 2.0) - tdelta) /
(EVENT_TIMEOUT / 2.0);
later = (EVENT_TIMEOUT - tdelta) /
(EVENT_TIMEOUT * 2.0);
vector_decay = tdelta <= (0.33 * EVENT_TIMEOUT) ?
recent : later;
} else {
vector_decay = 0.0;
}
/* Calculate windowed vector from delta + weighted historic data */
vector.x = (tp->scroll.vector.x * vector_decay) + delta_mm.x;
vector.y = (tp->scroll.vector.y * vector_decay) + delta_mm.y;
vector_length = hypot(vector.x, vector.y);
tp->scroll.vector = vector;
/* We care somewhat about distance and speed, but more about
* consistency of direction over time. Keep track of the time spent
* primarily along each axis. If one axis is active, time spent NOT
* moving much in the other axis is subtracted, allowing a switch of
* axes in a single scroll + ability to "break out" and go diagonal.
*
* Slope to degree conversions (infinity = 90°, 0 = 0°):
*/
const double DEGREE_75 = 3.73;
const double DEGREE_60 = 1.73;
const double DEGREE_30 = 0.57;
const double DEGREE_15 = 0.27;
slope = (vector.x != 0) ? fabs(vector.y / vector.x) : INFINITY;
/* Ensure vector is big enough (in mm per EVENT_TIMEOUT) to be confident
* of direction. Larger = harder to enable diagonal/free scrolling.
*/
const double MIN_VECTOR = 0.15;
if (slope >= DEGREE_30 && vector_length > MIN_VECTOR) {
tp->scroll.duration.v += tdelta;
if (tp->scroll.duration.v > ACTIVE_THRESHOLD)
tp->scroll.duration.v = ACTIVE_THRESHOLD;
if (slope >= DEGREE_75) {
if (tp->scroll.duration.h > tdelta)
tp->scroll.duration.h -= tdelta;
else
tp->scroll.duration.h = 0;
}
}
if (slope < DEGREE_60 && vector_length > MIN_VECTOR) {
tp->scroll.duration.h += tdelta;
if (tp->scroll.duration.h > ACTIVE_THRESHOLD)
tp->scroll.duration.h = ACTIVE_THRESHOLD;
if (slope < DEGREE_15) {
if (tp->scroll.duration.v > tdelta)
tp->scroll.duration.v -= tdelta;
else
tp->scroll.duration.v = 0;
}
}
if (tp->scroll.duration.h == ACTIVE_THRESHOLD) {
tp->scroll.active.h = true;
if (tp->scroll.duration.v < INACTIVE_THRESHOLD)
tp->scroll.active.v = false;
}
if (tp->scroll.duration.v == ACTIVE_THRESHOLD) {
tp->scroll.active.v = true;
if (tp->scroll.duration.h < INACTIVE_THRESHOLD)
tp->scroll.active.h = false;
}
/* If vector is big enough in a diagonal direction, always unlock
* both axes regardless of thresholds
*/
if (vector_length > 5.0 && slope < 1.73 && slope >= 0.57) {
tp->scroll.active.v = true;
tp->scroll.active.h = true;
}
/* If only one axis is active, constrain motion accordingly. If both
* are set, we've detected deliberate diagonal movement; enable free
* scrolling for the life of the gesture.
*/
if (!tp->scroll.active.h && tp->scroll.active.v)
delta->x = 0.0;
if (tp->scroll.active.h && !tp->scroll.active.v)
delta->y = 0.0;
/* If we haven't determined an axis, use the slope in the meantime */
if (!tp->scroll.active.h && !tp->scroll.active.v) {
delta->x = (slope >= DEGREE_60) ? 0.0 : delta->x;
delta->y = (slope < DEGREE_30) ? 0.0 : delta->y;
}
}
static inline void
log_gesture_bug(struct tp_dispatch *tp, enum gesture_event event)
{
evdev_log_bug_libinput(tp->device,
"invalid gesture event %s in state %s\n",
gesture_event_to_str(event),
gesture_state_to_str(tp->gesture.state));
}
static bool
tp_gesture_is_quick_hold(struct tp_dispatch *tp)
{
/* When 1 or 2 fingers are used to hold, always use a "quick" hold to
* make the hold to stop kinetic scrolling user interaction feel more
* natural.
*/
return (tp->gesture.finger_count == 1) ||
(tp->gesture.finger_count == 2);
}
static bool
tp_gesture_use_hold_timer(struct tp_dispatch *tp)
{
/* When tap is not enabled, always use the timer */
if (!tp->tap.enabled)
return true;
/* Always use the timer if it is a quick hold */
if (tp_gesture_is_quick_hold(tp))
return true;
/* If the number of fingers on the touchpad exceeds the number of
* allowed fingers to tap, use the timer.
*/
if (tp->gesture.finger_count > 3)
return true;
/* If the tap state machine is already in a hold status, for example
* when holding with 3 fingers and then holding with 2, use the timer.
*/
if (tp->tap.state == TAP_STATE_HOLD ||
tp->tap.state == TAP_STATE_TOUCH_2_HOLD ||
tp->tap.state == TAP_STATE_TOUCH_3_HOLD)
return true;
/* If the tap state machine is in dead status, use the timer. This
* happens when the user holds after cancelling a gesture/scroll.
*/
if (tp->tap.state == TAP_STATE_DEAD)
return true;
/* Otherwise, sync the hold notification with the tap state machine */
return false;
}
static void
tp_gesture_set_hold_timer(struct tp_dispatch *tp, uint64_t time)
{
uint64_t timeout;
if (!tp->gesture.hold_enabled)
return;
if (tp_gesture_use_hold_timer(tp)) {
timeout = tp_gesture_is_quick_hold(tp) ?
QUICK_GESTURE_HOLD_TIMEOUT :
DEFAULT_GESTURE_HOLD_TIMEOUT;
libinput_timer_set(&tp->gesture.hold_timer, time + timeout);
}
}
static void
tp_gesture_handle_event_on_state_none(struct tp_dispatch *tp,
enum gesture_event event,
uint64_t time)
{
switch(event) {
case GESTURE_EVENT_RESET:
case GESTURE_EVENT_END:
case GESTURE_EVENT_CANCEL:
libinput_timer_cancel(&tp->gesture.hold_timer);
break;
case GESTURE_EVENT_FINGER_DETECTED:
/* Note: this makes 3fg drag more responsive but disables
* 3fg pinch/hold. Those are niche enough to not worry about
* for now.
*/
if (!tp->tap.enabled && tp->drag_3fg.nfingers == tp->gesture.finger_count) {
tp->gesture.state = GESTURE_STATE_3FG_DRAG_START;
} else {
tp_gesture_set_hold_timer(tp, time);
tp->gesture.state = GESTURE_STATE_UNKNOWN;
}
break;
case GESTURE_EVENT_HOLD_TIMEOUT:
case GESTURE_EVENT_TAP_TIMEOUT:
break;
case GESTURE_EVENT_POINTER_MOTION_START:
tp->gesture.state = GESTURE_STATE_POINTER_MOTION;
break;
case GESTURE_EVENT_SCROLL_START:
tp->gesture.state = GESTURE_STATE_SCROLL_START;
break;
case GESTURE_EVENT_FINGER_SWITCH_TIMEOUT:
case GESTURE_EVENT_HOLD_AND_MOTION_START:
case GESTURE_EVENT_SWIPE_START:
case GESTURE_EVENT_PINCH_START:
case GESTURE_EVENT_3FG_DRAG_START:
case GESTURE_EVENT_3FG_DRAG_RELEASE_TIMEOUT:
log_gesture_bug(tp, event);
break;
}
}
static void
tp_gesture_handle_event_on_state_unknown(struct tp_dispatch *tp,
enum gesture_event event,
uint64_t time)
{
switch(event) {
case GESTURE_EVENT_RESET:
case GESTURE_EVENT_END:
case GESTURE_EVENT_CANCEL:
libinput_timer_cancel(&tp->gesture.hold_timer);
tp->gesture.state = GESTURE_STATE_NONE;
break;
case GESTURE_EVENT_FINGER_SWITCH_TIMEOUT:
break;
case GESTURE_EVENT_HOLD_TIMEOUT:
case GESTURE_EVENT_TAP_TIMEOUT:
tp->gesture.state = GESTURE_STATE_HOLD;
gesture_notify_hold_begin(&tp->device->base, time,
tp->gesture.finger_count);
break;
case GESTURE_EVENT_POINTER_MOTION_START:
/* Don't cancel the hold timer. This pointer motion can end up
* being recognised as hold and motion. */
tp->gesture.state = GESTURE_STATE_POINTER_MOTION;
break;
case GESTURE_EVENT_SCROLL_START:
libinput_timer_cancel(&tp->gesture.hold_timer);
tp_gesture_set_scroll_buildup(tp);
tp->gesture.state = GESTURE_STATE_SCROLL_START;
break;
case GESTURE_EVENT_SWIPE_START:
libinput_timer_cancel(&tp->gesture.hold_timer);
tp->gesture.state = GESTURE_STATE_SWIPE_START;
break;
case GESTURE_EVENT_PINCH_START:
libinput_timer_cancel(&tp->gesture.hold_timer);
tp_gesture_init_pinch(tp);
tp->gesture.state = GESTURE_STATE_PINCH_START;
break;
case GESTURE_EVENT_3FG_DRAG_START:
libinput_timer_cancel(&tp->gesture.hold_timer);
tp_gesture_init_3fg_drag(tp, time);
tp->gesture.state = GESTURE_STATE_3FG_DRAG_START;
break;
case GESTURE_EVENT_HOLD_AND_MOTION_START:
case GESTURE_EVENT_FINGER_DETECTED:
case GESTURE_EVENT_3FG_DRAG_RELEASE_TIMEOUT:
log_gesture_bug(tp, event);
break;
}
}
static void
tp_gesture_handle_event_on_state_hold(struct tp_dispatch *tp,
enum gesture_event event,
uint64_t time)
{
switch(event) {
case GESTURE_EVENT_RESET:
log_gesture_bug(tp, event);
break;
case GESTURE_EVENT_END:
case GESTURE_EVENT_CANCEL: {
bool cancelled = event == GESTURE_EVENT_CANCEL;
gesture_notify_hold_end(&tp->device->base, time,
tp->gesture.finger_count, cancelled);
libinput_timer_cancel(&tp->gesture.hold_timer);
tp->gesture.state = GESTURE_STATE_NONE;
break;
}
case GESTURE_EVENT_FINGER_SWITCH_TIMEOUT:
tp_gesture_cancel(tp, time);
break;
case GESTURE_EVENT_HOLD_AND_MOTION_START:
tp->gesture.state = GESTURE_STATE_HOLD_AND_MOTION;
break;
case GESTURE_EVENT_POINTER_MOTION_START:
tp_gesture_cancel(tp, time);
tp->gesture.state = GESTURE_STATE_POINTER_MOTION;
break;
case GESTURE_EVENT_SCROLL_START:
tp_gesture_set_scroll_buildup(tp);
tp_gesture_cancel(tp, time);
tp->gesture.state = GESTURE_STATE_SCROLL_START;
break;
case GESTURE_EVENT_SWIPE_START:
tp_gesture_cancel(tp, time);
tp->gesture.state = GESTURE_STATE_SWIPE_START;
break;
case GESTURE_EVENT_PINCH_START:
tp_gesture_cancel(tp, time);
tp_gesture_init_pinch(tp);
tp->gesture.state = GESTURE_STATE_PINCH_START;
break;
case GESTURE_EVENT_3FG_DRAG_START:
tp_gesture_cancel(tp, time);
tp_gesture_init_3fg_drag(tp, time);
tp->gesture.state = GESTURE_STATE_3FG_DRAG_START;
break;
case GESTURE_EVENT_HOLD_TIMEOUT:
case GESTURE_EVENT_TAP_TIMEOUT:
case GESTURE_EVENT_FINGER_DETECTED:
case GESTURE_EVENT_3FG_DRAG_RELEASE_TIMEOUT:
log_gesture_bug(tp, event);
break;
}
}
static void
tp_gesture_handle_event_on_state_hold_and_motion(struct tp_dispatch *tp,
enum gesture_event event,
uint64_t time)
{
switch(event) {
case GESTURE_EVENT_RESET:
log_gesture_bug(tp, event);
break;
case GESTURE_EVENT_END:
case GESTURE_EVENT_CANCEL: {
bool cancelled = event == GESTURE_EVENT_CANCEL;
gesture_notify_hold_end(&tp->device->base, time,
tp->gesture.finger_count, cancelled);
libinput_timer_cancel(&tp->gesture.hold_timer);
tp->gesture.state = GESTURE_STATE_NONE;
break;
}
case GESTURE_EVENT_FINGER_SWITCH_TIMEOUT:
tp_gesture_cancel(tp, time);
break;
case GESTURE_EVENT_POINTER_MOTION_START:
tp_gesture_cancel(tp, time);
tp->gesture.state = GESTURE_STATE_POINTER_MOTION;
break;
case GESTURE_EVENT_HOLD_AND_MOTION_START:
case GESTURE_EVENT_FINGER_DETECTED:
case GESTURE_EVENT_HOLD_TIMEOUT:
case GESTURE_EVENT_TAP_TIMEOUT:
case GESTURE_EVENT_SCROLL_START:
case GESTURE_EVENT_SWIPE_START:
case GESTURE_EVENT_PINCH_START:
case GESTURE_EVENT_3FG_DRAG_START:
case GESTURE_EVENT_3FG_DRAG_RELEASE_TIMEOUT:
log_gesture_bug(tp, event);
break;
}
}
static void
tp_gesture_handle_event_on_state_pointer_motion(struct tp_dispatch *tp,
enum gesture_event event,
uint64_t time)
{
struct tp_touch *first;
struct phys_coords first_moved;
double first_mm;
switch(event) {
case GESTURE_EVENT_RESET:
case GESTURE_EVENT_END:
case GESTURE_EVENT_CANCEL:
libinput_timer_cancel(&tp->gesture.hold_timer);
tp->gesture.state = GESTURE_STATE_NONE;
break;
case GESTURE_EVENT_HOLD_TIMEOUT:
case GESTURE_EVENT_TAP_TIMEOUT:
if (tp->gesture.finger_count != 1)
break;
first = tp->gesture.touches[0];
first_moved = tp_gesture_mm_moved(tp, first);
first_mm = hypot(first_moved.x, first_moved.y);
if (first_mm < HOLD_AND_MOTION_THRESHOLD) {
tp->gesture.state = GESTURE_STATE_HOLD_AND_MOTION;
gesture_notify_hold_begin(&tp->device->base, time,
tp->gesture.finger_count);
}
break;
case GESTURE_EVENT_FINGER_SWITCH_TIMEOUT:
case GESTURE_EVENT_HOLD_AND_MOTION_START:
case GESTURE_EVENT_FINGER_DETECTED:
case GESTURE_EVENT_POINTER_MOTION_START:
case GESTURE_EVENT_SCROLL_START:
case GESTURE_EVENT_SWIPE_START:
case GESTURE_EVENT_PINCH_START:
case GESTURE_EVENT_3FG_DRAG_START:
case GESTURE_EVENT_3FG_DRAG_RELEASE_TIMEOUT:
log_gesture_bug(tp, event);
break;
}
}
static void
tp_gesture_handle_event_on_state_scroll_start(struct tp_dispatch *tp,
enum gesture_event event,
uint64_t time)
{
switch(event) {
case GESTURE_EVENT_RESET:
case GESTURE_EVENT_END:
case GESTURE_EVENT_CANCEL:
libinput_timer_cancel(&tp->gesture.hold_timer);
tp->gesture.state = GESTURE_STATE_NONE;
break;
case GESTURE_EVENT_FINGER_SWITCH_TIMEOUT:
break;
case GESTURE_EVENT_PINCH_START:
tp_gesture_init_pinch(tp);
tp_gesture_cancel(tp, time);
tp->gesture.state = GESTURE_STATE_PINCH_START;
break;
case GESTURE_EVENT_HOLD_AND_MOTION_START:
case GESTURE_EVENT_FINGER_DETECTED:
case GESTURE_EVENT_HOLD_TIMEOUT:
case GESTURE_EVENT_TAP_TIMEOUT:
case GESTURE_EVENT_POINTER_MOTION_START:
case GESTURE_EVENT_SCROLL_START:
case GESTURE_EVENT_SWIPE_START:
case GESTURE_EVENT_3FG_DRAG_START:
case GESTURE_EVENT_3FG_DRAG_RELEASE_TIMEOUT:
log_gesture_bug(tp, event);
break;
}
}
static void
tp_gesture_handle_event_on_state_scroll(struct tp_dispatch *tp,
enum gesture_event event,
uint64_t time)
{
switch(event) {
case GESTURE_EVENT_RESET:
case GESTURE_EVENT_END:
case GESTURE_EVENT_CANCEL:
tp_gesture_stop_twofinger_scroll(tp, time);
libinput_timer_cancel(&tp->gesture.hold_timer);
tp->gesture.state = GESTURE_STATE_NONE;
break;
case GESTURE_EVENT_FINGER_SWITCH_TIMEOUT:
tp_gesture_cancel(tp, time);
break;
case GESTURE_EVENT_PINCH_START:
tp_gesture_init_pinch(tp);
tp_gesture_cancel(tp, time);
tp->gesture.state = GESTURE_STATE_PINCH_START;
break;
case GESTURE_EVENT_HOLD_AND_MOTION_START:
case GESTURE_EVENT_FINGER_DETECTED:
case GESTURE_EVENT_HOLD_TIMEOUT:
case GESTURE_EVENT_TAP_TIMEOUT:
case GESTURE_EVENT_POINTER_MOTION_START:
case GESTURE_EVENT_SCROLL_START:
case GESTURE_EVENT_SWIPE_START:
case GESTURE_EVENT_3FG_DRAG_START:
case GESTURE_EVENT_3FG_DRAG_RELEASE_TIMEOUT:
log_gesture_bug(tp, event);
break;
}
}
static void
tp_gesture_handle_event_on_state_pinch_start(struct tp_dispatch *tp,
enum gesture_event event,
uint64_t time)
{
switch(event) {
case GESTURE_EVENT_RESET:
case GESTURE_EVENT_END:
case GESTURE_EVENT_CANCEL:
libinput_timer_cancel(&tp->gesture.hold_timer);
break;
case GESTURE_EVENT_FINGER_SWITCH_TIMEOUT:
break;
case GESTURE_EVENT_HOLD_AND_MOTION_START:
case GESTURE_EVENT_FINGER_DETECTED:
case GESTURE_EVENT_HOLD_TIMEOUT:
case GESTURE_EVENT_TAP_TIMEOUT:
case GESTURE_EVENT_POINTER_MOTION_START:
case GESTURE_EVENT_SCROLL_START:
case GESTURE_EVENT_SWIPE_START:
case GESTURE_EVENT_PINCH_START:
case GESTURE_EVENT_3FG_DRAG_START:
case GESTURE_EVENT_3FG_DRAG_RELEASE_TIMEOUT:
log_gesture_bug(tp, event);
break;
}
}
static void
tp_gesture_handle_event_on_state_pinch(struct tp_dispatch *tp,
enum gesture_event event,
uint64_t time)
{
switch(event) {
case GESTURE_EVENT_RESET:
log_gesture_bug(tp, event);
break;
case GESTURE_EVENT_END:
case GESTURE_EVENT_CANCEL: {
bool cancelled = event == GESTURE_EVENT_CANCEL;
gesture_notify_pinch_end(&tp->device->base, time,
tp->gesture.finger_count,
tp->gesture.prev_scale,
cancelled);
libinput_timer_cancel(&tp->gesture.hold_timer);
tp->gesture.state = GESTURE_STATE_NONE;
break;
}
case GESTURE_EVENT_FINGER_SWITCH_TIMEOUT:
tp_gesture_cancel(tp, time);
break;
case GESTURE_EVENT_HOLD_AND_MOTION_START:
case GESTURE_EVENT_FINGER_DETECTED:
case GESTURE_EVENT_HOLD_TIMEOUT:
case GESTURE_EVENT_TAP_TIMEOUT:
case GESTURE_EVENT_POINTER_MOTION_START:
case GESTURE_EVENT_SCROLL_START:
case GESTURE_EVENT_SWIPE_START:
case GESTURE_EVENT_PINCH_START:
case GESTURE_EVENT_3FG_DRAG_START:
case GESTURE_EVENT_3FG_DRAG_RELEASE_TIMEOUT:
log_gesture_bug(tp, event);
break;
}
}
static void
tp_gesture_handle_event_on_state_swipe_start(struct tp_dispatch *tp,
enum gesture_event event,
uint64_t time)
{
switch(event) {
case GESTURE_EVENT_RESET:
case GESTURE_EVENT_END:
case GESTURE_EVENT_CANCEL:
libinput_timer_cancel(&tp->gesture.hold_timer);
tp->gesture.state = GESTURE_STATE_NONE;
break;
case GESTURE_EVENT_FINGER_SWITCH_TIMEOUT:
break;
case GESTURE_EVENT_HOLD_AND_MOTION_START:
case GESTURE_EVENT_FINGER_DETECTED:
case GESTURE_EVENT_HOLD_TIMEOUT:
case GESTURE_EVENT_TAP_TIMEOUT:
case GESTURE_EVENT_POINTER_MOTION_START:
case GESTURE_EVENT_SCROLL_START:
case GESTURE_EVENT_SWIPE_START:
case GESTURE_EVENT_PINCH_START:
case GESTURE_EVENT_3FG_DRAG_START:
case GESTURE_EVENT_3FG_DRAG_RELEASE_TIMEOUT:
log_gesture_bug(tp, event);
break;
}
}
static void
tp_gesture_handle_event_on_state_swipe(struct tp_dispatch *tp,
enum gesture_event event,
uint64_t time)
{
switch(event) {
case GESTURE_EVENT_RESET:
log_gesture_bug(tp, event);
break;
case GESTURE_EVENT_END:
case GESTURE_EVENT_CANCEL: {
bool cancelled = event == GESTURE_EVENT_CANCEL;
gesture_notify_swipe_end(&tp->device->base,
time,
tp->gesture.finger_count,
cancelled);
libinput_timer_cancel(&tp->gesture.hold_timer);
tp->gesture.state = GESTURE_STATE_NONE;
break;
}
case GESTURE_EVENT_FINGER_SWITCH_TIMEOUT:
tp_gesture_cancel(tp, time);
break;
case GESTURE_EVENT_HOLD_AND_MOTION_START:
case GESTURE_EVENT_FINGER_DETECTED:
case GESTURE_EVENT_HOLD_TIMEOUT:
case GESTURE_EVENT_TAP_TIMEOUT:
case GESTURE_EVENT_POINTER_MOTION_START:
case GESTURE_EVENT_SCROLL_START:
case GESTURE_EVENT_SWIPE_START:
case GESTURE_EVENT_PINCH_START:
case GESTURE_EVENT_3FG_DRAG_START:
case GESTURE_EVENT_3FG_DRAG_RELEASE_TIMEOUT:
log_gesture_bug(tp, event);
break;
}
}
static void
tp_gesture_handle_event_on_state_3fg_drag_start(struct tp_dispatch *tp,
enum gesture_event event,
uint64_t time)
{
switch(event) {
case GESTURE_EVENT_RESET:
case GESTURE_EVENT_END:
case GESTURE_EVENT_CANCEL:
libinput_timer_cancel(&tp->gesture.hold_timer);
tp->gesture.state = GESTURE_STATE_NONE;
break;
case GESTURE_EVENT_FINGER_SWITCH_TIMEOUT:
break;
case GESTURE_EVENT_HOLD_AND_MOTION_START:
case GESTURE_EVENT_FINGER_DETECTED:
case GESTURE_EVENT_TAP_TIMEOUT:
case GESTURE_EVENT_HOLD_TIMEOUT:
case GESTURE_EVENT_POINTER_MOTION_START:
case GESTURE_EVENT_SCROLL_START:
case GESTURE_EVENT_SWIPE_START:
case GESTURE_EVENT_PINCH_START:
case GESTURE_EVENT_3FG_DRAG_START:
case GESTURE_EVENT_3FG_DRAG_RELEASE_TIMEOUT:
log_gesture_bug(tp, event);
break;
}
}
static void
tp_gesture_set_3fg_drag_timer(struct tp_dispatch *tp, uint64_t time)
{
tp->gesture.drag_3fg_release_time = time;
libinput_timer_set(&tp->gesture.drag_3fg_timer, time + ms2us(700));
}
static void
tp_gesture_handle_event_on_state_3fg_drag(struct tp_dispatch *tp,
enum gesture_event event,
uint64_t time)
{
switch(event) {
case GESTURE_EVENT_RESET:
log_gesture_bug(tp, event);
break;
case GESTURE_EVENT_CANCEL:
/* If the gesture is cancelled we release the button immediately */
evdev_pointer_notify_button(tp->device,
tp->gesture.drag_3fg_release_time,
BTN_LEFT,
LIBINPUT_BUTTON_STATE_RELEASED);
tp->gesture.state = GESTURE_STATE_NONE;
break;
case GESTURE_EVENT_END:
/* If the gesture ends we start the timer so we
* can keep dragging */
tp_gesture_set_3fg_drag_timer(tp, time);
tp->gesture.state = GESTURE_STATE_3FG_DRAG_RELEASED;
break;
case GESTURE_EVENT_FINGER_SWITCH_TIMEOUT:
if (tp->gesture.finger_count_pending < 2) {
evdev_pointer_notify_button(tp->device,
tp->gesture.drag_3fg_release_time,
BTN_LEFT,
LIBINPUT_BUTTON_STATE_RELEASED);
tp->gesture.state = GESTURE_STATE_NONE;
}
break;
case GESTURE_EVENT_TAP_TIMEOUT:
break;
case GESTURE_EVENT_HOLD_AND_MOTION_START:
case GESTURE_EVENT_FINGER_DETECTED:
case GESTURE_EVENT_HOLD_TIMEOUT:
case GESTURE_EVENT_POINTER_MOTION_START:
case GESTURE_EVENT_SCROLL_START:
case GESTURE_EVENT_SWIPE_START:
case GESTURE_EVENT_PINCH_START:
case GESTURE_EVENT_3FG_DRAG_START:
case GESTURE_EVENT_3FG_DRAG_RELEASE_TIMEOUT:
log_gesture_bug(tp, event);
break;
}
}
static void
tp_gesture_handle_event_on_state_3fg_drag_released(struct tp_dispatch *tp,
enum gesture_event event,
uint64_t time)
{
switch(event) {
case GESTURE_EVENT_RESET:
log_gesture_bug(tp, event);
break;
case GESTURE_EVENT_END:
case GESTURE_EVENT_CANCEL:
case GESTURE_EVENT_3FG_DRAG_RELEASE_TIMEOUT:
tp_gesture_stop_3fg_drag(tp, time);
libinput_timer_cancel(&tp->gesture.drag_3fg_timer);
libinput_timer_cancel(&tp->gesture.finger_count_switch_timer);
evdev_pointer_notify_button(tp->device,
tp->gesture.drag_3fg_release_time,
BTN_LEFT,
LIBINPUT_BUTTON_STATE_RELEASED);
tp->gesture.state = GESTURE_STATE_NONE;
break;
case GESTURE_EVENT_FINGER_SWITCH_TIMEOUT:
case GESTURE_EVENT_TAP_TIMEOUT:
if (tp->gesture.finger_count_pending == tp->drag_3fg.nfingers) {
libinput_timer_cancel(&tp->gesture.drag_3fg_timer);
tp->gesture.state = GESTURE_STATE_3FG_DRAG;
}
break;
case GESTURE_EVENT_FINGER_DETECTED:
break;
case GESTURE_EVENT_POINTER_MOTION_START:
tp_gesture_stop_3fg_drag(tp, time);
libinput_timer_cancel(&tp->gesture.drag_3fg_timer);
evdev_pointer_notify_button(tp->device,
tp->gesture.drag_3fg_release_time,
BTN_LEFT,
LIBINPUT_BUTTON_STATE_RELEASED);
tp->gesture.state = GESTURE_STATE_POINTER_MOTION;
break;
case GESTURE_EVENT_HOLD_AND_MOTION_START:
case GESTURE_EVENT_HOLD_TIMEOUT:
log_gesture_bug(tp, event);
break;
/* Anything that's detected as gesture in this state
* will be continue the current 3fg drag gesture */
case GESTURE_EVENT_SCROLL_START:
libinput_timer_cancel(&tp->gesture.drag_3fg_timer);
evdev_pointer_notify_button(tp->device,
tp->gesture.drag_3fg_release_time,
BTN_LEFT,
LIBINPUT_BUTTON_STATE_RELEASED);
tp->gesture.state = GESTURE_STATE_SCROLL_START;
break;
case GESTURE_EVENT_SWIPE_START:
case GESTURE_EVENT_PINCH_START:
case GESTURE_EVENT_3FG_DRAG_START:
libinput_timer_cancel(&tp->gesture.drag_3fg_timer);
tp->gesture.state = GESTURE_STATE_3FG_DRAG;
break;
}
}
static void
tp_gesture_handle_event(struct tp_dispatch *tp,
enum gesture_event event,
uint64_t time)
{
enum tp_gesture_state oldstate;
oldstate = tp->gesture.state;
switch(tp->gesture.state) {
case GESTURE_STATE_NONE:
tp_gesture_handle_event_on_state_none(tp, event, time);
break;
case GESTURE_STATE_UNKNOWN:
tp_gesture_handle_event_on_state_unknown(tp, event, time);
break;
case GESTURE_STATE_HOLD:
tp_gesture_handle_event_on_state_hold(tp, event, time);
break;
case GESTURE_STATE_HOLD_AND_MOTION:
tp_gesture_handle_event_on_state_hold_and_motion(tp, event, time);
break;
case GESTURE_STATE_POINTER_MOTION:
tp_gesture_handle_event_on_state_pointer_motion(tp, event, time);
break;
case GESTURE_STATE_SCROLL_START:
tp_gesture_handle_event_on_state_scroll_start(tp, event, time);
break;
case GESTURE_STATE_SCROLL:
tp_gesture_handle_event_on_state_scroll(tp, event, time);
break;
case GESTURE_STATE_PINCH_START:
tp_gesture_handle_event_on_state_pinch_start(tp, event, time);
break;
case GESTURE_STATE_PINCH:
tp_gesture_handle_event_on_state_pinch(tp, event, time);
break;
case GESTURE_STATE_SWIPE_START:
tp_gesture_handle_event_on_state_swipe_start(tp, event, time);
break;
case GESTURE_STATE_SWIPE:
tp_gesture_handle_event_on_state_swipe(tp, event, time);
break;
case GESTURE_STATE_3FG_DRAG_START:
tp_gesture_handle_event_on_state_3fg_drag_start(tp, event, time);
break;
case GESTURE_STATE_3FG_DRAG:
tp_gesture_handle_event_on_state_3fg_drag(tp, event, time);
break;
case GESTURE_STATE_3FG_DRAG_RELEASED:
tp_gesture_handle_event_on_state_3fg_drag_released(tp, event, time);
break;
}
if (oldstate != tp->gesture.state) {
evdev_log_debug(tp->device,
"gesture: [%dfg] event %s → %s → %s\n",
tp->gesture.finger_count,
gesture_state_to_str(oldstate),
gesture_event_to_str(event),
gesture_state_to_str(tp->gesture.state));
}
}
static void
tp_gesture_hold_timeout(uint64_t now, void *data)
{
struct tp_dispatch *tp = data;
if (tp_tap_dragging_or_double_tapping(tp) || tp_tap_dragging(tp))
return;
tp_gesture_handle_event(tp, GESTURE_EVENT_HOLD_TIMEOUT, now);
}
void
tp_gesture_tap_timeout(struct tp_dispatch *tp, uint64_t time)
{
if (!tp->gesture.hold_enabled)
return;
if (!tp_gesture_is_quick_hold(tp))
tp_gesture_handle_event(tp, GESTURE_EVENT_TAP_TIMEOUT, time);
}
static void
tp_gesture_3fg_drag_timeout(uint64_t now, void *data)
{
struct tp_dispatch *tp = data;
tp_gesture_handle_event(tp, GESTURE_EVENT_3FG_DRAG_RELEASE_TIMEOUT, now);
}
static void
tp_gesture_detect_motion_gestures(struct tp_dispatch *tp, uint64_t time)
{
struct tp_touch *first = tp->gesture.touches[0],
*second = tp->gesture.touches[1],
*thumb;
uint32_t dir1, dir2;
struct device_coords delta;
struct phys_coords first_moved, second_moved, distance_mm;
double first_mm, second_mm; /* movement since gesture start in mm */
double min_move = 1.5; /* min movement threshold in mm - count this touch */
double max_move = 4.0; /* max movement threshold in mm - ignore other touch */
bool is_hold_and_motion;
first_moved = tp_gesture_mm_moved(tp, first);
first_mm = hypot(first_moved.x, first_moved.y);
if (tp->gesture.finger_count == 1) {
if (!tp_has_pending_pointer_motion(tp, time))
return;
is_hold_and_motion = (first_mm < HOLD_AND_MOTION_THRESHOLD);
if (tp->gesture.state == GESTURE_STATE_HOLD &&
is_hold_and_motion) {
tp_gesture_handle_event(tp,
GESTURE_EVENT_HOLD_AND_MOTION_START,
time);
return;
}
if (tp->gesture.state == GESTURE_STATE_HOLD_AND_MOTION &&
is_hold_and_motion)
return;
tp_gesture_handle_event(tp,
GESTURE_EVENT_POINTER_MOTION_START,
time);
return;
}
/* If we have more fingers than slots, we don't know where the
* fingers are. Default to swipe/3fg drag */
if (tp->gesture.enabled && tp->gesture.finger_count > 2 &&
tp->gesture.finger_count > tp->num_slots) {
if (tp->drag_3fg.nfingers == tp->gesture.finger_count)
tp_gesture_handle_event(tp, GESTURE_EVENT_3FG_DRAG_START, time);
else
tp_gesture_handle_event(tp, GESTURE_EVENT_SWIPE_START, time);
return;
}
/* Need more margin for error when there are more fingers */
max_move += 2.0 * (tp->gesture.finger_count - 2);
min_move += 0.5 * (tp->gesture.finger_count - 2);
second_moved = tp_gesture_mm_moved(tp, second);
second_mm = hypot(second_moved.x, second_moved.y);
delta.x = abs(first->point.x - second->point.x);
delta.y = abs(first->point.y - second->point.y);
distance_mm = evdev_device_unit_delta_to_mm(tp->device, &delta);
/* If both touches moved less than a mm, we cannot decide yet */
if (first_mm < 1 && second_mm < 1)
return;
/* If both touches are within 7mm vertically and 40mm horizontally
* past the timeout, assume scroll/swipe */
if ((!tp->gesture.enabled ||
(distance_mm.x < 40.0 && distance_mm.y < 7.0)) &&
time > (tp->gesture.initial_time + DEFAULT_GESTURE_SWIPE_TIMEOUT)) {
if (tp->gesture.finger_count == 2)
tp_gesture_handle_event(tp, GESTURE_EVENT_SCROLL_START, time);
else if (tp->drag_3fg.nfingers == tp->gesture.finger_count)
tp_gesture_handle_event(tp, GESTURE_EVENT_3FG_DRAG_START, time);
else
tp_gesture_handle_event(tp, GESTURE_EVENT_SWIPE_START, time);
return;
}
/* If 3fg dragging touches are within a 60x10mm box, start
* dragging immediately */
if (tp->gesture.finger_count == tp->drag_3fg.nfingers &&
distance_mm.x < 60.0 && distance_mm.y < 10.0) {
tp_gesture_handle_event(tp, GESTURE_EVENT_3FG_DRAG_START, time);
return;
}
/* If one touch exceeds the max_move threshold while the other has not
* yet passed the min_move threshold, there is either a resting thumb,
* or the user is doing "one-finger-scroll," where one touch stays in
* place while the other moves.
*/
if (first_mm >= max_move || second_mm >= max_move) {
double thumb_mm, finger_mm;
/* Pick the thumb as the lowest point on the touchpad */
if (first->point.y > second->point.y) {
thumb = first;
thumb_mm = first_mm;
finger_mm = second_mm;
} else {
thumb = second;
thumb_mm = second_mm;
finger_mm = first_mm;
}
/* If thumb detection is enabled, and thumb is still while
* finger moves, cancel gestures and mark lower as thumb.
* This applies to all gestures (2, 3, 4+ fingers), but allows
* more thumb motion on >2 finger gestures during detection.
*/
if (tp->thumb.detect_thumbs && thumb_mm < min_move) {
tp_thumb_suppress(tp, thumb);
tp_gesture_cancel(tp, time);
return;
}
/* If gestures detection is disabled, or if finger is still
* while thumb moves, assume this is "one-finger scrolling."
* This applies only to 2-finger gestures.
*/
if ((!tp->gesture.enabled || finger_mm < min_move) &&
tp->gesture.finger_count == 2) {
tp_gesture_handle_event(tp, GESTURE_EVENT_SCROLL_START, time);
return;
}
/* If more than 2 fingers are involved, and the thumb moves
* while the fingers stay still, assume a pinch if eligible.
*/
if (finger_mm < min_move &&
tp->gesture.finger_count > 2 &&
tp->gesture.enabled &&
tp->thumb.pinch_eligible) {
tp_gesture_handle_event(tp, GESTURE_EVENT_PINCH_START, time);
return;
}
}
/* If either touch is still below the min_move threshold, we can't
* tell what kind of gesture this is.
*/
if ((first_mm < min_move) || (second_mm < min_move))
return;
/* Both touches have exceeded the min_move threshold, so we have a
* valid gesture. Update gesture initial time and get directions so
* we know if it's a pinch or swipe/scroll.
*/
dir1 = tp_gesture_get_direction(tp, first);
dir2 = tp_gesture_get_direction(tp, second);
/* If we can't accurately detect pinches, or if the touches are moving
* the same way, this is a scroll or swipe.
*/
if (tp->gesture.finger_count > tp->num_slots ||
tp_gesture_same_directions(dir1, dir2)) {
if (tp->gesture.finger_count == 2) {
tp_gesture_handle_event(tp, GESTURE_EVENT_SCROLL_START, time);
return;
}
if (tp->drag_3fg.nfingers == tp->gesture.finger_count) {
tp_gesture_handle_event(tp, GESTURE_EVENT_3FG_DRAG_START, time);
return;
}
if (tp->gesture.enabled) {
tp_gesture_handle_event(tp, GESTURE_EVENT_SWIPE_START, time);
return;
}
}
/* If the touches are moving away from each other, this is a pinch */
tp_gesture_handle_event(tp, GESTURE_EVENT_PINCH_START, time);
}
static bool
tp_gesture_is_pinch(struct tp_dispatch *tp)
{
struct tp_touch *first = tp->gesture.touches[0],
*second = tp->gesture.touches[1];
uint32_t dir1, dir2;
struct phys_coords first_moved, second_moved;
double first_mm, second_mm;
dir1 = tp_gesture_get_direction(tp, first);
dir2 = tp_gesture_get_direction(tp, second);
if (tp_gesture_same_directions(dir1, dir2))
return false;
first_moved = tp_gesture_mm_moved(tp, first);
first_mm = hypot(first_moved.x, first_moved.y);
if (first_mm < PINCH_DISAMBIGUATION_MOVE_THRESHOLD)
return false;
second_moved = tp_gesture_mm_moved(tp, second);
second_mm = hypot(second_moved.x, second_moved.y);
if (second_mm < PINCH_DISAMBIGUATION_MOVE_THRESHOLD)
return false;
return true;
}
static void
tp_gesture_handle_state_none(struct tp_dispatch *tp, uint64_t time)
{
struct tp_touch *first, *second;
struct tp_touch *touches[4];
unsigned int ntouches;
unsigned int i;
ntouches = tp_gesture_get_active_touches(tp, touches, 4);
first = touches[0];
second = touches[1];
if (ntouches == 0)
return;
if (ntouches == 1) {
first->gesture.initial = first->point;
tp->gesture.touches[0] = first;
tp_gesture_handle_event(tp,
GESTURE_EVENT_FINGER_DETECTED,
time);
return;
}
if (!tp->gesture.enabled && !tp->tap.enabled && ntouches == 2) {
tp_gesture_handle_event(tp, GESTURE_EVENT_SCROLL_START, time);
return;
}
/* For 3+ finger gestures, we only really need to track two touches.
* The human hand's finger arrangement means that for a pinch, the
* bottom-most touch will always be the thumb, and the top-most touch
* will always be one of the fingers.
*
* For 3+ finger swipes, the fingers will likely (but not necessarily)
* be in a horizontal line. They all move together, regardless, so it
* doesn't really matter which two of those touches we track.
*
* Tracking top and bottom is a change from previous versions, where
* we tracked leftmost and rightmost. This change enables:
*
* - More accurate pinch detection if thumb is near the center
* - Better resting-thumb detection while two-finger scrolling
* - On capable hardware, allow 3- or 4-finger swipes with resting
* thumb or held-down clickpad
*/
if (ntouches > 2) {
second = touches[0];
for (i = 1; i < ntouches && i < tp->num_slots; i++) {
if (touches[i]->point.y < first->point.y)
first = touches[i];
else if (touches[i]->point.y >= second->point.y)
second = touches[i];
}
if (first == second)
return;
}
tp->gesture.initial_time = time;
first->gesture.initial = first->point;
second->gesture.initial = second->point;
tp->gesture.touches[0] = first;
tp->gesture.touches[1] = second;
tp_gesture_handle_event(tp, GESTURE_EVENT_FINGER_DETECTED, time);
}
static void
tp_gesture_handle_state_unknown(struct tp_dispatch *tp, uint64_t time,
bool ignore_motion)
{
if (!ignore_motion)
tp_gesture_detect_motion_gestures(tp, time);
}
static void
tp_gesture_handle_state_hold(struct tp_dispatch *tp, uint64_t time,
bool ignore_motion)
{
if (!ignore_motion)
tp_gesture_detect_motion_gestures(tp, time);
}
static void
tp_gesture_handle_state_hold_and_pointer_motion(struct tp_dispatch *tp, uint64_t time)
{
if (tp->queued & TOUCHPAD_EVENT_MOTION)
tp_gesture_post_pointer_motion(tp, time);
tp_gesture_detect_motion_gestures(tp, time);
}
static void
tp_gesture_handle_state_pointer_motion(struct tp_dispatch *tp, uint64_t time)
{
if (tp->queued & TOUCHPAD_EVENT_MOTION)
tp_gesture_post_pointer_motion(tp, time);
}
static void
tp_gesture_handle_state_scroll_start(struct tp_dispatch *tp, uint64_t time)
{
struct device_float_coords raw;
struct normalized_coords delta;
if (tp->scroll.method != LIBINPUT_CONFIG_SCROLL_2FG)
return;
/* We may confuse a pinch for a scroll initially,
* allow ourselves to correct our guess.
*/
if (time < (tp->gesture.initial_time + DEFAULT_GESTURE_PINCH_TIMEOUT) &&
tp_gesture_is_pinch(tp)) {
tp_gesture_handle_event(tp, GESTURE_EVENT_PINCH_START, time);
return;
}
raw = tp_get_average_touches_delta(tp);
/* scroll is not accelerated by default */
delta = tp_filter_scroll(tp, &raw, time);
if (normalized_is_zero(delta))
return;
tp_gesture_init_scroll(tp);
tp->gesture.state = GESTURE_STATE_SCROLL;
}
static void
tp_gesture_handle_state_scroll(struct tp_dispatch *tp, uint64_t time)
{
struct device_float_coords raw;
struct normalized_coords delta;
if (tp->scroll.method != LIBINPUT_CONFIG_SCROLL_2FG)
return;
/* We may confuse a pinch for a scroll initially,
* allow ourselves to correct our guess.
*/
if (time < (tp->gesture.initial_time + DEFAULT_GESTURE_PINCH_TIMEOUT) &&
tp_gesture_is_pinch(tp)) {
tp_gesture_handle_event(tp, GESTURE_EVENT_PINCH_START, time);
return;
}
raw = tp_get_average_touches_delta(tp);
/* scroll is not accelerated by default */
delta = tp_filter_scroll(tp, &raw, time);
if (normalized_is_zero(delta))
return;
tp_gesture_apply_scroll_constraints(tp, &raw, &delta, time);
evdev_post_scroll(tp->device,
time,
LIBINPUT_POINTER_AXIS_SOURCE_FINGER,
&delta);
}
static void
tp_gesture_handle_state_swipe_start(struct tp_dispatch *tp, uint64_t time)
{
struct device_float_coords raw;
struct normalized_coords delta;
raw = tp_get_average_touches_delta(tp);
delta = tp_filter_motion(tp, &raw, time);
if (!normalized_is_zero(delta) || !device_float_is_zero(raw)) {
const struct normalized_coords zero = { 0.0, 0.0 };
gesture_notify_swipe(&tp->device->base, time,
LIBINPUT_EVENT_GESTURE_SWIPE_BEGIN,
tp->gesture.finger_count,
&zero, &zero);
tp->gesture.state = GESTURE_STATE_SWIPE;
}
}
static void
tp_gesture_handle_state_swipe(struct tp_dispatch *tp, uint64_t time)
{
struct device_float_coords raw;
struct normalized_coords delta, unaccel;
raw = tp_get_average_touches_delta(tp);
delta = tp_filter_motion(tp, &raw, time);
if (!normalized_is_zero(delta) || !device_float_is_zero(raw)) {
unaccel = tp_filter_motion_unaccelerated(tp, &raw, time);
gesture_notify_swipe(&tp->device->base, time,
LIBINPUT_EVENT_GESTURE_SWIPE_UPDATE,
tp->gesture.finger_count,
&delta, &unaccel);
}
}
static void
tp_gesture_handle_state_pinch_start(struct tp_dispatch *tp, uint64_t time)
{
const struct normalized_coords zero = { 0.0, 0.0 };
double angle, angle_delta, distance, scale;
struct device_float_coords center, fdelta;
struct normalized_coords delta;
tp_gesture_get_pinch_info(tp, &distance, &angle, ¢er);
scale = distance / tp->gesture.initial_distance;
angle_delta = angle - tp->gesture.angle;
tp->gesture.angle = angle;
if (angle_delta > 180.0)
angle_delta -= 360.0;
else if (angle_delta < -180.0)
angle_delta += 360.0;
fdelta = device_float_delta(center, tp->gesture.center);
tp->gesture.center = center;
delta = tp_filter_motion(tp, &fdelta, time);
if (normalized_is_zero(delta) && device_float_is_zero(fdelta) &&
scale == tp->gesture.prev_scale && angle_delta == 0.0)
return;
gesture_notify_pinch(&tp->device->base, time,
LIBINPUT_EVENT_GESTURE_PINCH_BEGIN,
tp->gesture.finger_count,
&zero, &zero, 1.0, 0.0);
tp->gesture.prev_scale = scale;
tp->gesture.state = GESTURE_STATE_PINCH;
}
static void
tp_gesture_handle_state_pinch(struct tp_dispatch *tp, uint64_t time)
{
double angle, angle_delta, distance, scale;
struct device_float_coords center, fdelta;
struct normalized_coords delta, unaccel;
tp_gesture_get_pinch_info(tp, &distance, &angle, ¢er);
scale = distance / tp->gesture.initial_distance;
angle_delta = angle - tp->gesture.angle;
tp->gesture.angle = angle;
if (angle_delta > 180.0)
angle_delta -= 360.0;
else if (angle_delta < -180.0)
angle_delta += 360.0;
fdelta = device_float_delta(center, tp->gesture.center);
tp->gesture.center = center;
delta = tp_filter_motion(tp, &fdelta, time);
if (normalized_is_zero(delta) && device_float_is_zero(fdelta) &&
scale == tp->gesture.prev_scale && angle_delta == 0.0)
return;
unaccel = tp_filter_motion_unaccelerated(tp, &fdelta, time);
gesture_notify_pinch(&tp->device->base, time,
LIBINPUT_EVENT_GESTURE_PINCH_UPDATE,
tp->gesture.finger_count,
&delta, &unaccel, scale, angle_delta);
tp->gesture.prev_scale = scale;
}
static void
tp_gesture_handle_state_3fg_drag_start(struct tp_dispatch *tp, uint64_t time)
{
evdev_pointer_notify_button(tp->device,
time,
BTN_LEFT,
LIBINPUT_BUTTON_STATE_PRESSED);
/* FIXME: immediately send a motion event? */
tp->gesture.state = GESTURE_STATE_3FG_DRAG;
}
static void
tp_gesture_handle_state_3fg_drag(struct tp_dispatch *tp, uint64_t time)
{
if (!(tp->queued & TOUCHPAD_EVENT_MOTION))
return;
struct device_float_coords raw = tp_get_average_touches_delta(tp);
struct normalized_coords delta = tp_filter_motion(tp, &raw, time);
if (!normalized_is_zero(delta) || !device_float_is_zero(raw)) {
if (tp->queued & TOUCHPAD_EVENT_MOTION)
tp_gesture_post_pointer_motion(tp, time);
}
}
static void
tp_gesture_handle_state_3fg_drag_released(struct tp_dispatch *tp,
uint64_t time,
bool ignore_motion)
{
tp_gesture_detect_motion_gestures(tp, time);
}
static void
tp_gesture_handle_state(struct tp_dispatch *tp, uint64_t time,
bool ignore_motion)
{
enum tp_gesture_state oldstate = tp->gesture.state;
enum tp_gesture_state transitions[16] = {0};
enum tp_gesture_state *transition_state = transitions;
#define REMEMBER_TRANSITION(_ts, _state) { \
if (*(_ts) != (_state)) { \
++(_ts); \
assert((_ts) < transitions + ARRAY_LENGTH(transitions)); \
*(_ts) = _state; \
} \
}
*transition_state = tp->gesture.state;
if (tp->gesture.state == GESTURE_STATE_NONE) {
tp_gesture_handle_state_none(tp, time);
REMEMBER_TRANSITION(transition_state, tp->gesture.state);
}
if (tp->gesture.state == GESTURE_STATE_UNKNOWN) {
tp_gesture_handle_state_unknown(tp, time, ignore_motion);
REMEMBER_TRANSITION(transition_state, tp->gesture.state);
}
if (tp->gesture.state == GESTURE_STATE_HOLD) {
tp_gesture_handle_state_hold(tp, time, ignore_motion);
REMEMBER_TRANSITION(transition_state, tp->gesture.state);
}
if (tp->gesture.state == GESTURE_STATE_POINTER_MOTION) {
tp_gesture_handle_state_pointer_motion(tp, time);
REMEMBER_TRANSITION(transition_state, tp->gesture.state);
}
if (tp->gesture.state == GESTURE_STATE_HOLD_AND_MOTION) {
tp_gesture_handle_state_hold_and_pointer_motion(tp, time);
REMEMBER_TRANSITION(transition_state, tp->gesture.state);
}
if (tp->gesture.state == GESTURE_STATE_SCROLL) {
tp_gesture_handle_state_scroll(tp, time);
REMEMBER_TRANSITION(transition_state, tp->gesture.state);
}
if (tp->gesture.state == GESTURE_STATE_SCROLL_START) {
tp_gesture_handle_state_scroll_start(tp, time);
REMEMBER_TRANSITION(transition_state, tp->gesture.state);
}
if (tp->gesture.state == GESTURE_STATE_SWIPE) {
tp_gesture_handle_state_swipe(tp, time);
REMEMBER_TRANSITION(transition_state, tp->gesture.state);
}
if (tp->gesture.state == GESTURE_STATE_SWIPE_START) {
tp_gesture_handle_state_swipe_start(tp, time);
REMEMBER_TRANSITION(transition_state, tp->gesture.state);
}
if (tp->gesture.state == GESTURE_STATE_PINCH) {
tp_gesture_handle_state_pinch(tp, time);
REMEMBER_TRANSITION(transition_state, tp->gesture.state);
}
if (tp->gesture.state == GESTURE_STATE_PINCH_START) {
tp_gesture_handle_state_pinch_start(tp, time);
REMEMBER_TRANSITION(transition_state, tp->gesture.state);
}
if (tp->gesture.state == GESTURE_STATE_3FG_DRAG) {
tp_gesture_handle_state_3fg_drag(tp, time);
REMEMBER_TRANSITION(transition_state, tp->gesture.state);
}
if (tp->gesture.state == GESTURE_STATE_3FG_DRAG_START) {
tp_gesture_handle_state_3fg_drag_start(tp, time);
REMEMBER_TRANSITION(transition_state, tp->gesture.state);
}
if (tp->gesture.state == GESTURE_STATE_3FG_DRAG_RELEASED) {
tp_gesture_handle_state_3fg_drag_released(tp, time, ignore_motion);
REMEMBER_TRANSITION(transition_state, tp->gesture.state);
}
#undef REMEMBER_TRANSITION
if (oldstate != tp->gesture.state) {
char buf[1024] = {0};
size_t remaining = sizeof(buf);
size_t slen = 0;
for (enum tp_gesture_state *s = transitions + 1; s < transition_state; s++) {
int n = snprintf(&buf[slen], remaining, " → %s", gesture_state_to_str(*s));
slen += n;
remaining -= n;
}
evdev_log_debug(tp->device,
"gesture: [%dfg] state %s%s → %s\n",
tp->gesture.finger_count,
gesture_state_to_str(oldstate),
buf,
gesture_state_to_str(tp->gesture.state));
}
}
static bool
tp_gesture_thumb_moved(struct tp_dispatch *tp)
{
struct tp_touch *thumb;
struct phys_coords thumb_moved;
double thumb_mm;
thumb = tp_thumb_get_touch(tp);
if (!thumb)
return false;
if (!tp_touch_active_for_gesture(tp, thumb))
return false;
thumb_moved = tp_gesture_mm_moved(tp, thumb);
thumb_mm = hypot(thumb_moved.x, thumb_moved.y);
return thumb_mm >= PINCH_DISAMBIGUATION_MOVE_THRESHOLD;
}
void
tp_gesture_post_events(struct tp_dispatch *tp, uint64_t time,
bool ignore_motion)
{
if (tp->gesture.finger_count == 0)
return;
/* When tap-and-dragging, force 1fg mode. On clickpads, if the
* physical button is down, don't allow gestures unless the button
* is held down by a *thumb*, specifically.
*/
if (tp_tap_dragging(tp) ||
(tp->buttons.is_clickpad && tp->buttons.state &&
tp->thumb.state == THUMB_STATE_FINGER)) {
if (tp->gesture.state != GESTURE_STATE_POINTER_MOTION) {
tp_gesture_cancel(tp, time);
tp_gesture_handle_event(tp,
GESTURE_EVENT_POINTER_MOTION_START,
time);
}
tp->gesture.finger_count = 1;
tp->gesture.finger_count_pending = 0;
}
/* Don't send events when we're unsure in which mode we are */
if (tp->gesture.finger_count_pending)
return;
/* When pinching, the thumb tends to move slower than the finger,
* so we may suppress it too early. Give it some time to move.
*/
if (time < (tp->gesture.initial_time + DEFAULT_GESTURE_PINCH_TIMEOUT) &&
tp_gesture_thumb_moved(tp))
tp_thumb_reset(tp);
if (tp->gesture.finger_count <= 4)
tp_gesture_handle_state(tp, time, ignore_motion);
}
void
tp_gesture_stop_twofinger_scroll(struct tp_dispatch *tp, uint64_t time)
{
if (tp->scroll.method != LIBINPUT_CONFIG_SCROLL_2FG)
return;
evdev_stop_scroll(tp->device,
time,
LIBINPUT_POINTER_AXIS_SOURCE_FINGER);
}
static void
tp_gesture_end(struct tp_dispatch *tp, uint64_t time, enum gesture_cancelled cancelled)
{
switch (tp->gesture.state) {
case GESTURE_STATE_NONE:
case GESTURE_STATE_UNKNOWN:
case GESTURE_STATE_SCROLL_START:
case GESTURE_STATE_PINCH_START:
case GESTURE_STATE_SWIPE_START:
case GESTURE_STATE_3FG_DRAG_START:
tp_gesture_handle_event(tp, GESTURE_EVENT_RESET, time);
break;
case GESTURE_STATE_HOLD:
case GESTURE_STATE_HOLD_AND_MOTION:
case GESTURE_STATE_POINTER_MOTION:
case GESTURE_STATE_SCROLL:
case GESTURE_STATE_PINCH:
case GESTURE_STATE_SWIPE:
case GESTURE_STATE_3FG_DRAG:
case GESTURE_STATE_3FG_DRAG_RELEASED:
switch (cancelled) {
case CANCEL_GESTURE:
tp_gesture_handle_event(tp, GESTURE_EVENT_CANCEL, time);
break;
case END_GESTURE:
tp_gesture_handle_event(tp, GESTURE_EVENT_END, time);
break;
}
break;
}
}
void
tp_gesture_cancel(struct tp_dispatch *tp, uint64_t time)
{
tp_gesture_end(tp, time, CANCEL_GESTURE);
}
void
tp_gesture_cancel_motion_gestures(struct tp_dispatch *tp, uint64_t time)
{
switch (tp->gesture.state) {
case GESTURE_STATE_NONE:
case GESTURE_STATE_UNKNOWN:
case GESTURE_STATE_SCROLL_START:
case GESTURE_STATE_PINCH_START:
case GESTURE_STATE_SWIPE_START:
case GESTURE_STATE_3FG_DRAG_START:
break;
case GESTURE_STATE_HOLD:
break;
case GESTURE_STATE_HOLD_AND_MOTION:
case GESTURE_STATE_POINTER_MOTION:
case GESTURE_STATE_SCROLL:
case GESTURE_STATE_PINCH:
case GESTURE_STATE_SWIPE:
evdev_log_debug(tp->device, "Cancelling motion gestures\n");
tp_gesture_cancel(tp, time);
break;
case GESTURE_STATE_3FG_DRAG:
break;
case GESTURE_STATE_3FG_DRAG_RELEASED:
break;
}
}
void
tp_gesture_stop(struct tp_dispatch *tp, uint64_t time)
{
tp_gesture_end(tp, time, END_GESTURE);
}
static void
tp_gesture_finger_count_switch_timeout(uint64_t now, void *data)
{
struct tp_dispatch *tp = data;
if (!tp->gesture.finger_count_pending)
return;
tp_gesture_handle_event(tp, GESTURE_EVENT_FINGER_SWITCH_TIMEOUT, now);
tp->gesture.finger_count = tp->gesture.finger_count_pending;
tp->gesture.finger_count_pending = 0;
}
static bool
tp_gesture_debounce_finger_changes(struct tp_dispatch *tp)
{
switch (tp->gesture.state) {
case GESTURE_STATE_NONE:
case GESTURE_STATE_UNKNOWN:
case GESTURE_STATE_SCROLL_START:
case GESTURE_STATE_PINCH_START:
case GESTURE_STATE_SWIPE_START:
case GESTURE_STATE_POINTER_MOTION:
return false;
case GESTURE_STATE_HOLD:
case GESTURE_STATE_HOLD_AND_MOTION:
case GESTURE_STATE_SCROLL:
case GESTURE_STATE_PINCH:
case GESTURE_STATE_SWIPE:
case GESTURE_STATE_3FG_DRAG_START:
case GESTURE_STATE_3FG_DRAG_RELEASED:
case GESTURE_STATE_3FG_DRAG:
return true;
}
abort();
}
void
tp_gesture_update_finger_state(struct tp_dispatch *tp, uint64_t time)
{
unsigned int active_touches = 0;
struct tp_touch *t;
tp_for_each_touch(tp, t) {
if (tp_touch_active_for_gesture(tp, t))
active_touches++;
}
if (active_touches != tp->gesture.finger_count) {
/* If all fingers are lifted immediately end the gesture */
if (active_touches == 0) {
tp_gesture_stop(tp, time);
tp->gesture.finger_count = 0;
tp->gesture.finger_count_pending = 0;
/* Immediately switch to new mode to avoid initial latency */
} else if (!tp_gesture_debounce_finger_changes(tp)) {
tp->gesture.finger_count = active_touches;
tp->gesture.finger_count_pending = 0;
/* If in UNKNOWN or POINTER_MOTION state, go back to
* NONE to re-evaluate leftmost and rightmost touches
*/
if (tp->gesture.state == GESTURE_STATE_UNKNOWN ||
tp->gesture.state == GESTURE_STATE_POINTER_MOTION) {
tp_gesture_handle_event(tp,
GESTURE_EVENT_RESET,
time);
}
/* Else debounce finger changes */
} else if (active_touches != tp->gesture.finger_count_pending) {
tp->gesture.finger_count_pending = active_touches;
libinput_timer_set(&tp->gesture.finger_count_switch_timer,
time + DEFAULT_GESTURE_SWITCH_TIMEOUT);
}
} else {
tp->gesture.finger_count_pending = 0;
}
}
static bool
tp_gesture_are_gestures_enabled(struct tp_dispatch *tp)
{
return (!tp->semi_mt && tp->num_slots > 1);
}
static enum libinput_config_status
tp_gesture_set_hold_enabled(struct libinput_device *device,
enum libinput_config_hold_state enabled)
{
struct evdev_dispatch *dispatch = evdev_device(device)->dispatch;
struct tp_dispatch *tp = tp_dispatch(dispatch);
if (!tp_gesture_are_gestures_enabled(tp))
return LIBINPUT_CONFIG_STATUS_UNSUPPORTED;
tp->gesture.hold_enabled = (enabled == LIBINPUT_CONFIG_HOLD_ENABLED);
return LIBINPUT_CONFIG_STATUS_SUCCESS;
}
static enum libinput_config_hold_state
tp_gesture_is_hold_enabled(struct libinput_device *device)
{
struct evdev_dispatch *dispatch = evdev_device(device)->dispatch;
struct tp_dispatch *tp = tp_dispatch(dispatch);
return tp->gesture.hold_enabled ? LIBINPUT_CONFIG_HOLD_ENABLED :
LIBINPUT_CONFIG_HOLD_DISABLED;
}
static enum libinput_config_hold_state
tp_gesture_get_hold_default(struct libinput_device *device)
{
struct evdev_dispatch *dispatch = evdev_device(device)->dispatch;
struct tp_dispatch *tp = tp_dispatch(dispatch);
return tp_gesture_are_gestures_enabled(tp) ?
LIBINPUT_CONFIG_HOLD_ENABLED :
LIBINPUT_CONFIG_HOLD_DISABLED;
}
static int
tp_3fg_drag_count(struct libinput_device *device)
{
struct evdev_dispatch *dispatch = evdev_device(device)->dispatch;
struct tp_dispatch *tp = tp_dispatch(dispatch);
/* If we can't to gestures we can't do 3fg drag */
if (!tp_gesture_are_gestures_enabled(tp))
return 0;
/* For now return the number of MT slots until we need to figure out
* if we can implement this on a 2-finger BTN_TOOL_TRIPLETAP device */
return tp->num_slots;
}
static enum libinput_config_status
tp_3fg_drag_set_enabled(struct libinput_device *device,
enum libinput_config_3fg_drag_state enabled)
{
struct evdev_dispatch *dispatch = evdev_device(device)->dispatch;
struct tp_dispatch *tp = tp_dispatch(dispatch);
if (tp_3fg_drag_count(device) < 3)
return LIBINPUT_CONFIG_STATUS_UNSUPPORTED;
switch (enabled) {
case LIBINPUT_CONFIG_3FG_DRAG_DISABLED:
tp->drag_3fg.want_nfingers = 0;
break;
case LIBINPUT_CONFIG_3FG_DRAG_ENABLED_3FG:
tp->drag_3fg.want_nfingers = 3;
break;
case LIBINPUT_CONFIG_3FG_DRAG_ENABLED_4FG:
tp->drag_3fg.want_nfingers = 4;
break;
}
tp_3fg_drag_apply_config(evdev_device(device));
return LIBINPUT_CONFIG_STATUS_SUCCESS;
}
static enum libinput_config_3fg_drag_state
tp_3fg_drag_get_enabled(struct libinput_device *device)
{
struct evdev_dispatch *dispatch = evdev_device(device)->dispatch;
struct tp_dispatch *tp = tp_dispatch(dispatch);
switch (tp->drag_3fg.want_nfingers) {
case 3:
return LIBINPUT_CONFIG_3FG_DRAG_ENABLED_3FG;
case 4:
return LIBINPUT_CONFIG_3FG_DRAG_ENABLED_4FG;
}
return LIBINPUT_CONFIG_3FG_DRAG_DISABLED;
}
static enum libinput_config_3fg_drag_state
tp_3fg_drag_default(struct tp_dispatch *tp)
{
return LIBINPUT_CONFIG_3FG_DRAG_DISABLED;
}
static enum libinput_config_3fg_drag_state
tp_3fg_drag_get_default_enabled(struct libinput_device *device)
{
struct evdev_dispatch *dispatch = evdev_device(device)->dispatch;
struct tp_dispatch *tp = tp_dispatch(dispatch);
return tp_3fg_drag_default(tp);
}
void
tp_3fg_drag_apply_config(struct evdev_device *device)
{
struct tp_dispatch *tp = (struct tp_dispatch *)device->dispatch;
if (tp->drag_3fg.want_nfingers == tp->drag_3fg.nfingers)
return;
if (tp->nfingers_down)
return;
tp->drag_3fg.nfingers = tp->drag_3fg.want_nfingers;
evdev_log_debug(device, "touchpad-3fg-drag: drag is now for %zd fingers\n", tp->drag_3fg.nfingers);
}
void
tp_init_gesture(struct tp_dispatch *tp)
{
char timer_name[64];
tp->gesture.config.set_hold_enabled = tp_gesture_set_hold_enabled;
tp->gesture.config.get_hold_enabled = tp_gesture_is_hold_enabled;
tp->gesture.config.get_hold_default = tp_gesture_get_hold_default;
tp->device->base.config.gesture = &tp->gesture.config;
tp->drag_3fg.config.count = tp_3fg_drag_count;
tp->drag_3fg.config.set_enabled = tp_3fg_drag_set_enabled;
tp->drag_3fg.config.get_enabled = tp_3fg_drag_get_enabled;
tp->drag_3fg.config.get_default = tp_3fg_drag_get_default_enabled;
tp->device->base.config.drag_3fg = &tp->drag_3fg.config;
switch (tp_3fg_drag_default(tp)) {
case LIBINPUT_CONFIG_3FG_DRAG_DISABLED:
tp->drag_3fg.nfingers = 0;
break;
case LIBINPUT_CONFIG_3FG_DRAG_ENABLED_3FG:
tp->drag_3fg.nfingers = 3;
break;
case LIBINPUT_CONFIG_3FG_DRAG_ENABLED_4FG:
tp->drag_3fg.nfingers = 4;
break;
}
tp->drag_3fg.want_nfingers = tp->drag_3fg.nfingers;
/* two-finger scrolling is always enabled, this flag just
* decides whether we detect pinch. semi-mt devices are too
* unreliable to do pinch gestures. */
tp->gesture.enabled = tp_gesture_are_gestures_enabled(tp);
tp->gesture.state = GESTURE_STATE_NONE;
tp->gesture.hold_enabled = tp_gesture_are_gestures_enabled(tp);
snprintf(timer_name,
sizeof(timer_name),
"%s gestures",
evdev_device_get_sysname(tp->device));
libinput_timer_init(&tp->gesture.finger_count_switch_timer,
tp_libinput_context(tp),
timer_name,
tp_gesture_finger_count_switch_timeout, tp);
snprintf(timer_name,
sizeof(timer_name),
"%s hold",
evdev_device_get_sysname(tp->device));
libinput_timer_init(&tp->gesture.hold_timer,
tp_libinput_context(tp),
timer_name,
tp_gesture_hold_timeout, tp);
snprintf(timer_name,
sizeof(timer_name),
"%s drag_3fg",
evdev_device_get_sysname(tp->device));
libinput_timer_init(&tp->gesture.drag_3fg_timer,
tp_libinput_context(tp),
timer_name,
tp_gesture_3fg_drag_timeout, tp);
}
void
tp_remove_gesture(struct tp_dispatch *tp)
{
libinput_timer_cancel(&tp->gesture.finger_count_switch_timer);
libinput_timer_cancel(&tp->gesture.hold_timer);
libinput_timer_cancel(&tp->gesture.drag_3fg_timer);
}
libinput-1.28.1/src/evdev-mt-touchpad-tap.c000066400000000000000000001237161477265155700205370ustar00rootroot00000000000000/*
* Copyright © 2013-2015 Red Hat, Inc.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice (including the next
* paragraph) shall be included in all copies or substantial portions of the
* Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
*/
#include "config.h"
#include
#include
#include
#include "evdev-mt-touchpad.h"
#define DEFAULT_TAP_TIMEOUT_PERIOD ms2us(180)
#define DEFAULT_DRAG_TIMEOUT_PERIOD_BASE ms2us(160)
#define DEFAULT_DRAG_TIMEOUT_PERIOD_PERFINGER ms2us(20)
#define DEFAULT_DRAGLOCK_TIMEOUT_PERIOD ms2us(300)
#define DEFAULT_TAP_MOVE_THRESHOLD 1.3 /* mm */
enum tap_event {
TAP_EVENT_TOUCH = 12,
TAP_EVENT_MOTION,
TAP_EVENT_RELEASE,
TAP_EVENT_BUTTON,
TAP_EVENT_TIMEOUT,
TAP_EVENT_THUMB,
TAP_EVENT_PALM,
TAP_EVENT_PALM_UP,
};
/*****************************************
* DO NOT EDIT THIS FILE!
*
* Look at the state diagram in doc/touchpad-tap-state-machine.svg
* (generated with https://www.diagrams.net)
*
* Any changes in this file must be represented in the diagram.
*/
static inline const char*
tap_state_to_str(enum tp_tap_state state)
{
switch(state) {
CASE_RETURN_STRING(TAP_STATE_IDLE);
CASE_RETURN_STRING(TAP_STATE_HOLD);
CASE_RETURN_STRING(TAP_STATE_TOUCH);
CASE_RETURN_STRING(TAP_STATE_1FGTAP_TAPPED);
CASE_RETURN_STRING(TAP_STATE_2FGTAP_TAPPED);
CASE_RETURN_STRING(TAP_STATE_3FGTAP_TAPPED);
CASE_RETURN_STRING(TAP_STATE_TOUCH_2);
CASE_RETURN_STRING(TAP_STATE_TOUCH_2_HOLD);
CASE_RETURN_STRING(TAP_STATE_TOUCH_2_RELEASE);
CASE_RETURN_STRING(TAP_STATE_TOUCH_3);
CASE_RETURN_STRING(TAP_STATE_TOUCH_3_HOLD);
CASE_RETURN_STRING(TAP_STATE_TOUCH_3_RELEASE);
CASE_RETURN_STRING(TAP_STATE_TOUCH_3_RELEASE_2);
CASE_RETURN_STRING(TAP_STATE_1FGTAP_DRAGGING);
CASE_RETURN_STRING(TAP_STATE_2FGTAP_DRAGGING);
CASE_RETURN_STRING(TAP_STATE_3FGTAP_DRAGGING);
CASE_RETURN_STRING(TAP_STATE_1FGTAP_DRAGGING_WAIT);
CASE_RETURN_STRING(TAP_STATE_2FGTAP_DRAGGING_WAIT);
CASE_RETURN_STRING(TAP_STATE_3FGTAP_DRAGGING_WAIT);
CASE_RETURN_STRING(TAP_STATE_1FGTAP_DRAGGING_OR_DOUBLETAP);
CASE_RETURN_STRING(TAP_STATE_2FGTAP_DRAGGING_OR_DOUBLETAP);
CASE_RETURN_STRING(TAP_STATE_3FGTAP_DRAGGING_OR_DOUBLETAP);
CASE_RETURN_STRING(TAP_STATE_1FGTAP_DRAGGING_OR_TAP);
CASE_RETURN_STRING(TAP_STATE_2FGTAP_DRAGGING_OR_TAP);
CASE_RETURN_STRING(TAP_STATE_3FGTAP_DRAGGING_OR_TAP);
CASE_RETURN_STRING(TAP_STATE_1FGTAP_DRAGGING_2);
CASE_RETURN_STRING(TAP_STATE_2FGTAP_DRAGGING_2);
CASE_RETURN_STRING(TAP_STATE_3FGTAP_DRAGGING_2);
CASE_RETURN_STRING(TAP_STATE_DEAD);
}
return NULL;
}
static inline const char*
tap_event_to_str(enum tap_event event)
{
switch(event) {
CASE_RETURN_STRING(TAP_EVENT_TOUCH);
CASE_RETURN_STRING(TAP_EVENT_MOTION);
CASE_RETURN_STRING(TAP_EVENT_RELEASE);
CASE_RETURN_STRING(TAP_EVENT_TIMEOUT);
CASE_RETURN_STRING(TAP_EVENT_BUTTON);
CASE_RETURN_STRING(TAP_EVENT_THUMB);
CASE_RETURN_STRING(TAP_EVENT_PALM);
CASE_RETURN_STRING(TAP_EVENT_PALM_UP);
}
return NULL;
}
static inline void
log_tap_bug(struct tp_dispatch *tp, struct tp_touch *t, enum tap_event event)
{
evdev_log_bug_libinput(tp->device,
"%d: invalid tap event %s in state %s\n",
t->index,
tap_event_to_str(event),
tap_state_to_str(tp->tap.state));
}
static void
tp_tap_notify(struct tp_dispatch *tp,
uint64_t time,
int nfingers,
enum libinput_button_state state)
{
int32_t button;
int32_t button_map[2][3] = {
{ BTN_LEFT, BTN_RIGHT, BTN_MIDDLE },
{ BTN_LEFT, BTN_MIDDLE, BTN_RIGHT },
};
assert(tp->tap.map < ARRAY_LENGTH(button_map));
if (nfingers < 1 || nfingers > 3)
return;
tp_gesture_cancel(tp, time);
button = button_map[tp->tap.map][nfingers - 1];
if (state == LIBINPUT_BUTTON_STATE_PRESSED)
tp->tap.buttons_pressed |= bit(nfingers);
else
tp->tap.buttons_pressed &= ~bit(nfingers);
evdev_pointer_notify_button(tp->device,
time,
button,
state);
}
static void
tp_tap_set_timer(struct tp_dispatch *tp, uint64_t time)
{
libinput_timer_set(&tp->tap.timer, time + DEFAULT_TAP_TIMEOUT_PERIOD);
}
static void
tp_tap_set_drag_timer(struct tp_dispatch *tp, uint64_t time,
int nfingers_tapped)
{
libinput_timer_set(&tp->tap.timer,
time + DEFAULT_DRAG_TIMEOUT_PERIOD_BASE +
(nfingers_tapped *
DEFAULT_DRAG_TIMEOUT_PERIOD_PERFINGER));
}
static void
tp_tap_set_draglock_timer(struct tp_dispatch *tp, uint64_t time)
{
libinput_timer_set(&tp->tap.timer,
time + DEFAULT_DRAGLOCK_TIMEOUT_PERIOD);
}
static void
tp_tap_clear_timer(struct tp_dispatch *tp)
{
libinput_timer_cancel(&tp->tap.timer);
}
static void
tp_tap_move_to_dead(struct tp_dispatch *tp, struct tp_touch *t)
{
tp->tap.state = TAP_STATE_DEAD;
t->tap.state = TAP_TOUCH_STATE_DEAD;
tp_tap_clear_timer(tp);
}
static void
tp_tap_idle_handle_event(struct tp_dispatch *tp,
struct tp_touch *t,
enum tap_event event, uint64_t time)
{
switch (event) {
case TAP_EVENT_TOUCH:
tp->tap.state = TAP_STATE_TOUCH;
tp->tap.saved_press_time = time;
tp_tap_set_timer(tp, time);
break;
case TAP_EVENT_RELEASE:
break;
case TAP_EVENT_MOTION:
log_tap_bug(tp, t, event);
break;
case TAP_EVENT_TIMEOUT:
break;
case TAP_EVENT_BUTTON:
tp->tap.state = TAP_STATE_DEAD;
break;
case TAP_EVENT_THUMB:
log_tap_bug(tp, t, event);
break;
case TAP_EVENT_PALM:
tp->tap.state = TAP_STATE_IDLE;
break;
case TAP_EVENT_PALM_UP:
break;
}
}
static void
tp_tap_touch_handle_event(struct tp_dispatch *tp,
struct tp_touch *t,
enum tap_event event, uint64_t time)
{
switch (event) {
case TAP_EVENT_TOUCH:
tp->tap.state = TAP_STATE_TOUCH_2;
tp->tap.saved_press_time = time;
tp_tap_set_timer(tp, time);
break;
case TAP_EVENT_RELEASE:
tp_tap_notify(tp,
tp->tap.saved_press_time,
1,
LIBINPUT_BUTTON_STATE_PRESSED);
if (tp->tap.drag_enabled) {
tp->tap.state = TAP_STATE_1FGTAP_TAPPED;
tp->tap.saved_release_time = time;
tp_tap_set_drag_timer(tp, time, 1);
} else {
tp_tap_notify(tp,
time,
1,
LIBINPUT_BUTTON_STATE_RELEASED);
tp->tap.state = TAP_STATE_IDLE;
}
break;
case TAP_EVENT_MOTION:
tp_tap_move_to_dead(tp, t);
break;
case TAP_EVENT_TIMEOUT:
tp->tap.state = TAP_STATE_HOLD;
tp_tap_clear_timer(tp);
tp_gesture_tap_timeout(tp, time);
break;
case TAP_EVENT_BUTTON:
tp->tap.state = TAP_STATE_DEAD;
break;
case TAP_EVENT_THUMB:
tp->tap.state = TAP_STATE_IDLE;
t->tap.is_thumb = true;
tp->tap.nfingers_down--;
t->tap.state = TAP_TOUCH_STATE_DEAD;
tp_tap_clear_timer(tp);
break;
case TAP_EVENT_PALM:
tp->tap.state = TAP_STATE_IDLE;
tp_tap_clear_timer(tp);
break;
case TAP_EVENT_PALM_UP:
break;
}
}
static void
tp_tap_hold_handle_event(struct tp_dispatch *tp,
struct tp_touch *t,
enum tap_event event, uint64_t time)
{
switch (event) {
case TAP_EVENT_TOUCH:
tp->tap.state = TAP_STATE_TOUCH_2;
tp->tap.saved_press_time = time;
tp_tap_set_timer(tp, time);
break;
case TAP_EVENT_RELEASE:
tp->tap.state = TAP_STATE_IDLE;
break;
case TAP_EVENT_MOTION:
tp_tap_move_to_dead(tp, t);
break;
case TAP_EVENT_TIMEOUT:
break;
case TAP_EVENT_BUTTON:
tp->tap.state = TAP_STATE_DEAD;
break;
case TAP_EVENT_THUMB:
tp->tap.state = TAP_STATE_IDLE;
t->tap.is_thumb = true;
tp->tap.nfingers_down--;
t->tap.state = TAP_TOUCH_STATE_DEAD;
break;
case TAP_EVENT_PALM:
tp->tap.state = TAP_STATE_IDLE;
break;
case TAP_EVENT_PALM_UP:
break;
}
}
static void
tp_tap_tapped_handle_event(struct tp_dispatch *tp,
struct tp_touch *t,
enum tap_event event, uint64_t time,
int nfingers_tapped)
{
switch (event) {
case TAP_EVENT_MOTION:
case TAP_EVENT_RELEASE:
log_tap_bug(tp, t, event);
break;
case TAP_EVENT_TOUCH: {
enum tp_tap_state dest[3] = {
TAP_STATE_1FGTAP_DRAGGING_OR_DOUBLETAP,
TAP_STATE_2FGTAP_DRAGGING_OR_DOUBLETAP,
TAP_STATE_3FGTAP_DRAGGING_OR_DOUBLETAP,
};
assert(nfingers_tapped >= 1 && nfingers_tapped <= 3);
tp->tap.state = dest[nfingers_tapped - 1];
tp->tap.saved_press_time = time;
tp_tap_set_timer(tp, time);
break;
}
case TAP_EVENT_TIMEOUT:
tp->tap.state = TAP_STATE_IDLE;
tp_tap_notify(tp,
tp->tap.saved_release_time,
nfingers_tapped,
LIBINPUT_BUTTON_STATE_RELEASED);
break;
case TAP_EVENT_BUTTON:
tp->tap.state = TAP_STATE_DEAD;
tp_tap_notify(tp,
tp->tap.saved_release_time,
nfingers_tapped,
LIBINPUT_BUTTON_STATE_RELEASED);
break;
case TAP_EVENT_THUMB:
log_tap_bug(tp, t, event);
break;
case TAP_EVENT_PALM:
log_tap_bug(tp, t, event);
break;
case TAP_EVENT_PALM_UP:
break;
}
}
static void
tp_tap_touch2_handle_event(struct tp_dispatch *tp,
struct tp_touch *t,
enum tap_event event, uint64_t time)
{
switch (event) {
case TAP_EVENT_TOUCH:
tp->tap.state = TAP_STATE_TOUCH_3;
tp->tap.saved_press_time = time;
tp_tap_set_timer(tp, time);
break;
case TAP_EVENT_RELEASE:
tp->tap.state = TAP_STATE_TOUCH_2_RELEASE;
tp->tap.saved_release_time = time;
tp_tap_set_timer(tp, time);
break;
case TAP_EVENT_MOTION:
tp_tap_move_to_dead(tp, t);
break;
case TAP_EVENT_TIMEOUT:
tp->tap.state = TAP_STATE_TOUCH_2_HOLD;
tp_gesture_tap_timeout(tp, time);
break;
case TAP_EVENT_BUTTON:
tp->tap.state = TAP_STATE_DEAD;
break;
case TAP_EVENT_THUMB:
break;
case TAP_EVENT_PALM:
tp->tap.state = TAP_STATE_TOUCH;
break;
case TAP_EVENT_PALM_UP:
break;
}
}
static void
tp_tap_touch2_hold_handle_event(struct tp_dispatch *tp,
struct tp_touch *t,
enum tap_event event, uint64_t time)
{
switch (event) {
case TAP_EVENT_TOUCH:
tp->tap.state = TAP_STATE_TOUCH_3;
tp->tap.saved_press_time = time;
tp_tap_set_timer(tp, time);
break;
case TAP_EVENT_RELEASE:
tp->tap.state = TAP_STATE_HOLD;
break;
case TAP_EVENT_MOTION:
tp_tap_move_to_dead(tp, t);
break;
case TAP_EVENT_TIMEOUT:
tp->tap.state = TAP_STATE_TOUCH_2_HOLD;
break;
case TAP_EVENT_BUTTON:
tp->tap.state = TAP_STATE_DEAD;
break;
case TAP_EVENT_THUMB:
break;
case TAP_EVENT_PALM:
tp->tap.state = TAP_STATE_HOLD;
break;
case TAP_EVENT_PALM_UP:
break;
}
}
static void
tp_tap_touch2_release_handle_event(struct tp_dispatch *tp,
struct tp_touch *t,
enum tap_event event, uint64_t time)
{
switch (event) {
case TAP_EVENT_TOUCH:
tp->tap.state = TAP_STATE_TOUCH_2_HOLD;
t->tap.state = TAP_TOUCH_STATE_DEAD;
tp_tap_clear_timer(tp);
break;
case TAP_EVENT_RELEASE:
tp_tap_notify(tp,
tp->tap.saved_press_time,
2,
LIBINPUT_BUTTON_STATE_PRESSED);
if (tp->tap.drag_enabled) {
tp->tap.state = TAP_STATE_2FGTAP_TAPPED;
tp_tap_set_drag_timer(tp, time, 2);
} else {
tp_tap_notify(tp,
tp->tap.saved_release_time,
2,
LIBINPUT_BUTTON_STATE_RELEASED);
tp->tap.state = TAP_STATE_IDLE;
}
break;
case TAP_EVENT_MOTION:
tp_tap_move_to_dead(tp, t);
break;
case TAP_EVENT_TIMEOUT:
tp->tap.state = TAP_STATE_HOLD;
break;
case TAP_EVENT_BUTTON:
tp->tap.state = TAP_STATE_DEAD;
break;
case TAP_EVENT_THUMB:
break;
case TAP_EVENT_PALM:
/* There's only one saved press time and it's overwritten by
* the last touch down. So in the case of finger down, palm
* down, finger up, palm detected, we use the
* palm touch's press time here instead of the finger's press
* time. Let's wait and see if that's an issue.
*/
tp_tap_notify(tp,
tp->tap.saved_press_time,
1,
LIBINPUT_BUTTON_STATE_PRESSED);
if (tp->tap.drag_enabled) {
/* For a single-finger tap the timer delay is the same
* as for the release of the finger that became a palm,
* no reset necessary */
tp->tap.state = TAP_STATE_1FGTAP_TAPPED;
} else {
tp_tap_notify(tp,
tp->tap.saved_release_time,
1,
LIBINPUT_BUTTON_STATE_RELEASED);
tp->tap.state = TAP_STATE_IDLE;
}
break;
case TAP_EVENT_PALM_UP:
break;
}
}
static void
tp_tap_touch3_handle_event(struct tp_dispatch *tp,
struct tp_touch *t,
enum tap_event event, uint64_t time)
{
switch (event) {
case TAP_EVENT_TOUCH:
tp->tap.state = TAP_STATE_DEAD;
tp_tap_clear_timer(tp);
break;
case TAP_EVENT_MOTION:
tp_tap_move_to_dead(tp, t);
break;
case TAP_EVENT_TIMEOUT:
tp->tap.state = TAP_STATE_TOUCH_3_HOLD;
tp_tap_clear_timer(tp);
tp_gesture_tap_timeout(tp, time);
break;
case TAP_EVENT_RELEASE:
tp->tap.state = TAP_STATE_TOUCH_3_RELEASE;
tp->tap.saved_release_time = time;
tp_tap_set_timer(tp, time);
break;
case TAP_EVENT_BUTTON:
tp->tap.state = TAP_STATE_DEAD;
break;
case TAP_EVENT_THUMB:
break;
case TAP_EVENT_PALM:
tp->tap.state = TAP_STATE_TOUCH_2;
break;
case TAP_EVENT_PALM_UP:
break;
}
}
static void
tp_tap_touch3_hold_handle_event(struct tp_dispatch *tp,
struct tp_touch *t,
enum tap_event event, uint64_t time)
{
switch (event) {
case TAP_EVENT_TOUCH:
tp->tap.state = TAP_STATE_DEAD;
tp_tap_set_timer(tp, time);
break;
case TAP_EVENT_RELEASE:
tp->tap.state = TAP_STATE_TOUCH_2_HOLD;
break;
case TAP_EVENT_MOTION:
tp_tap_move_to_dead(tp, t);
break;
case TAP_EVENT_TIMEOUT:
break;
case TAP_EVENT_BUTTON:
tp->tap.state = TAP_STATE_DEAD;
break;
case TAP_EVENT_THUMB:
break;
case TAP_EVENT_PALM:
tp->tap.state = TAP_STATE_TOUCH_2_HOLD;
break;
case TAP_EVENT_PALM_UP:
break;
}
}
static void
tp_tap_touch3_release_handle_event(struct tp_dispatch *tp,
struct tp_touch *t,
enum tap_event event, uint64_t time)
{
switch (event) {
case TAP_EVENT_TOUCH:
tp_tap_notify(tp,
tp->tap.saved_press_time,
3,
LIBINPUT_BUTTON_STATE_PRESSED);
tp_tap_notify(tp,
tp->tap.saved_release_time,
3,
LIBINPUT_BUTTON_STATE_RELEASED);
tp->tap.state = TAP_STATE_TOUCH_3;
tp->tap.saved_press_time = time;
tp_tap_set_timer(tp, time);
break;
case TAP_EVENT_RELEASE:
tp->tap.state = TAP_STATE_TOUCH_3_RELEASE_2;
tp_tap_set_timer(tp, time);
break;
case TAP_EVENT_MOTION:
tp_tap_notify(tp,
tp->tap.saved_press_time,
3,
LIBINPUT_BUTTON_STATE_PRESSED);
tp_tap_notify(tp,
tp->tap.saved_release_time,
3,
LIBINPUT_BUTTON_STATE_RELEASED);
tp_tap_move_to_dead(tp, t);
break;
case TAP_EVENT_TIMEOUT:
tp_tap_notify(tp,
tp->tap.saved_press_time,
3,
LIBINPUT_BUTTON_STATE_PRESSED);
tp_tap_notify(tp,
tp->tap.saved_release_time,
3,
LIBINPUT_BUTTON_STATE_RELEASED);
tp->tap.state = TAP_STATE_TOUCH_2_HOLD;
break;
case TAP_EVENT_BUTTON:
tp_tap_notify(tp,
tp->tap.saved_press_time,
3,
LIBINPUT_BUTTON_STATE_PRESSED);
tp_tap_notify(tp,
tp->tap.saved_release_time,
3,
LIBINPUT_BUTTON_STATE_RELEASED);
tp->tap.state = TAP_STATE_DEAD;
break;
case TAP_EVENT_THUMB:
break;
case TAP_EVENT_PALM:
tp->tap.state = TAP_STATE_TOUCH_2_RELEASE;
break;
case TAP_EVENT_PALM_UP:
break;
}
}
static void
tp_tap_touch3_release2_handle_event(struct tp_dispatch *tp,
struct tp_touch *t,
enum tap_event event, uint64_t time)
{
switch (event) {
case TAP_EVENT_TOUCH:
tp_tap_notify(tp,
tp->tap.saved_press_time,
3,
LIBINPUT_BUTTON_STATE_PRESSED);
tp_tap_notify(tp,
tp->tap.saved_release_time,
3,
LIBINPUT_BUTTON_STATE_RELEASED);
tp->tap.state = TAP_STATE_TOUCH_2;
tp->tap.saved_press_time = time;
tp_tap_set_timer(tp, time);
break;
case TAP_EVENT_RELEASE:
tp_tap_notify(tp,
tp->tap.saved_press_time,
3,
LIBINPUT_BUTTON_STATE_PRESSED);
if (tp->tap.drag_enabled) {
tp->tap.state = TAP_STATE_3FGTAP_TAPPED;
tp_tap_set_drag_timer(tp, time, 3);
} else {
tp_tap_notify(tp,
tp->tap.saved_release_time,
3,
LIBINPUT_BUTTON_STATE_RELEASED);
tp->tap.state = TAP_STATE_IDLE;
}
break;
case TAP_EVENT_MOTION:
tp_tap_notify(tp,
tp->tap.saved_press_time,
3,
LIBINPUT_BUTTON_STATE_PRESSED);
tp_tap_notify(tp,
tp->tap.saved_release_time,
3,
LIBINPUT_BUTTON_STATE_RELEASED);
tp_tap_move_to_dead(tp, t);
break;
case TAP_EVENT_TIMEOUT:
tp_tap_notify(tp,
tp->tap.saved_press_time,
3,
LIBINPUT_BUTTON_STATE_PRESSED);
tp_tap_notify(tp,
tp->tap.saved_release_time,
3,
LIBINPUT_BUTTON_STATE_RELEASED);
tp->tap.state = TAP_STATE_HOLD;
break;
case TAP_EVENT_BUTTON:
tp_tap_notify(tp,
tp->tap.saved_press_time,
3,
LIBINPUT_BUTTON_STATE_PRESSED);
tp_tap_notify(tp,
tp->tap.saved_release_time,
3,
LIBINPUT_BUTTON_STATE_RELEASED);
tp->tap.state = TAP_STATE_DEAD;
break;
case TAP_EVENT_THUMB:
break;
case TAP_EVENT_PALM:
tp_tap_notify(tp,
tp->tap.saved_press_time,
2,
LIBINPUT_BUTTON_STATE_PRESSED);
if (tp->tap.drag_enabled) {
/* Resetting the timer to the appropriate delay
* for a two-finger tap would be ideal, but the
* timestamp of the last real finger release is lost,
* so the in-progress similar delay for release
* of the finger which became a palm instead
* will have to do */
tp->tap.state = TAP_STATE_2FGTAP_TAPPED;
} else {
tp_tap_notify(tp,
tp->tap.saved_release_time,
2,
LIBINPUT_BUTTON_STATE_RELEASED);
tp->tap.state = TAP_STATE_IDLE;
}
break;
case TAP_EVENT_PALM_UP:
break;
}
}
static void
tp_tap_dragging_or_doubletap_handle_event(struct tp_dispatch *tp,
struct tp_touch *t,
enum tap_event event, uint64_t time,
int nfingers_tapped)
{
switch (event) {
case TAP_EVENT_TOUCH: {
tp_tap_notify(tp,
tp->tap.saved_release_time,
nfingers_tapped,
LIBINPUT_BUTTON_STATE_RELEASED);
tp->tap.state = TAP_STATE_TOUCH_2;
tp->tap.saved_press_time = time;
tp_tap_set_timer(tp, time);
break;
}
case TAP_EVENT_RELEASE:
tp->tap.state = TAP_STATE_1FGTAP_TAPPED;
tp_tap_notify(tp,
tp->tap.saved_release_time,
nfingers_tapped,
LIBINPUT_BUTTON_STATE_RELEASED);
tp_tap_notify(tp,
tp->tap.saved_press_time,
1,
LIBINPUT_BUTTON_STATE_PRESSED);
tp->tap.saved_release_time = time;
tp_tap_set_timer(tp, time);
break;
case TAP_EVENT_MOTION:
case TAP_EVENT_TIMEOUT: {
enum tp_tap_state dest[3] = {
TAP_STATE_1FGTAP_DRAGGING,
TAP_STATE_2FGTAP_DRAGGING,
TAP_STATE_3FGTAP_DRAGGING,
};
assert(nfingers_tapped >= 1 && nfingers_tapped <= 3);
tp->tap.state = dest[nfingers_tapped - 1];
break;
}
case TAP_EVENT_BUTTON:
tp->tap.state = TAP_STATE_DEAD;
tp_tap_notify(tp,
tp->tap.saved_release_time,
nfingers_tapped,
LIBINPUT_BUTTON_STATE_RELEASED);
break;
case TAP_EVENT_THUMB:
break;
case TAP_EVENT_PALM: {
enum tp_tap_state dest[3] = {
TAP_STATE_1FGTAP_TAPPED,
TAP_STATE_2FGTAP_TAPPED,
TAP_STATE_3FGTAP_TAPPED,
};
assert(nfingers_tapped >= 1 && nfingers_tapped <= 3);
tp->tap.state = dest[nfingers_tapped - 1];
break;
}
case TAP_EVENT_PALM_UP:
break;
}
}
static void
tp_tap_dragging_handle_event(struct tp_dispatch *tp,
struct tp_touch *t,
enum tap_event event, uint64_t time,
int nfingers_tapped)
{
switch (event) {
case TAP_EVENT_TOUCH: {
enum tp_tap_state dest[3] = {
TAP_STATE_1FGTAP_DRAGGING_2,
TAP_STATE_2FGTAP_DRAGGING_2,
TAP_STATE_3FGTAP_DRAGGING_2,
};
assert(nfingers_tapped >= 1 && nfingers_tapped <= 3);
tp->tap.state = dest[nfingers_tapped - 1];
break;
}
case TAP_EVENT_RELEASE:
if (tp->tap.drag_lock != LIBINPUT_CONFIG_DRAG_LOCK_DISABLED) {
enum tp_tap_state dest[3] = {
TAP_STATE_1FGTAP_DRAGGING_WAIT,
TAP_STATE_2FGTAP_DRAGGING_WAIT,
TAP_STATE_3FGTAP_DRAGGING_WAIT,
};
assert(nfingers_tapped >= 1 && nfingers_tapped <= 3);
tp->tap.state = dest[nfingers_tapped - 1];
if (tp->tap.drag_lock == LIBINPUT_CONFIG_DRAG_LOCK_ENABLED_TIMEOUT)
tp_tap_set_draglock_timer(tp, time);
} else {
tp_tap_notify(tp,
time,
nfingers_tapped,
LIBINPUT_BUTTON_STATE_RELEASED);
tp->tap.state = TAP_STATE_IDLE;
}
break;
case TAP_EVENT_MOTION:
case TAP_EVENT_TIMEOUT:
/* noop */
break;
case TAP_EVENT_BUTTON:
tp->tap.state = TAP_STATE_DEAD;
tp_tap_notify(tp,
time,
nfingers_tapped,
LIBINPUT_BUTTON_STATE_RELEASED);
break;
case TAP_EVENT_THUMB:
break;
case TAP_EVENT_PALM:
tp_tap_notify(tp,
tp->tap.saved_release_time,
nfingers_tapped,
LIBINPUT_BUTTON_STATE_RELEASED);
tp->tap.state = TAP_STATE_IDLE;
break;
case TAP_EVENT_PALM_UP:
break;
}
}
static void
tp_tap_dragging_wait_handle_event(struct tp_dispatch *tp,
struct tp_touch *t,
enum tap_event event, uint64_t time,
int nfingers_tapped)
{
switch (event) {
case TAP_EVENT_TOUCH: {
enum tp_tap_state dest[3] = {
TAP_STATE_1FGTAP_DRAGGING_OR_TAP,
TAP_STATE_2FGTAP_DRAGGING_OR_TAP,
TAP_STATE_3FGTAP_DRAGGING_OR_TAP,
};
assert(nfingers_tapped >= 1 && nfingers_tapped <= 3);
tp->tap.state = dest[nfingers_tapped - 1];
tp_tap_set_timer(tp, time);
break;
}
case TAP_EVENT_RELEASE:
case TAP_EVENT_MOTION:
log_tap_bug(tp, t, event);
break;
case TAP_EVENT_TIMEOUT:
tp->tap.state = TAP_STATE_IDLE;
tp_tap_notify(tp,
time,
nfingers_tapped,
LIBINPUT_BUTTON_STATE_RELEASED);
break;
case TAP_EVENT_BUTTON:
tp->tap.state = TAP_STATE_DEAD;
tp_tap_notify(tp,
time,
nfingers_tapped,
LIBINPUT_BUTTON_STATE_RELEASED);
break;
case TAP_EVENT_THUMB:
case TAP_EVENT_PALM:
log_tap_bug(tp, t, event);
break;
case TAP_EVENT_PALM_UP:
break;
}
}
static void
tp_tap_dragging_tap_handle_event(struct tp_dispatch *tp,
struct tp_touch *t,
enum tap_event event, uint64_t time,
int nfingers_tapped)
{
switch (event) {
case TAP_EVENT_TOUCH: {
tp_tap_notify(tp,
time,
nfingers_tapped,
LIBINPUT_BUTTON_STATE_RELEASED);
tp_tap_clear_timer(tp);
tp_tap_move_to_dead(tp, t);
break;
}
case TAP_EVENT_RELEASE:
tp->tap.state = TAP_STATE_IDLE;
tp_tap_notify(tp,
time,
nfingers_tapped,
LIBINPUT_BUTTON_STATE_RELEASED);
break;
case TAP_EVENT_MOTION:
case TAP_EVENT_TIMEOUT: {
enum tp_tap_state dest[3] = {
TAP_STATE_1FGTAP_DRAGGING,
TAP_STATE_2FGTAP_DRAGGING,
TAP_STATE_3FGTAP_DRAGGING,
};
assert(nfingers_tapped >= 1 && nfingers_tapped <= 3);
tp->tap.state = dest[nfingers_tapped - 1];
break;
}
case TAP_EVENT_BUTTON:
tp->tap.state = TAP_STATE_DEAD;
tp_tap_notify(tp,
time,
nfingers_tapped,
LIBINPUT_BUTTON_STATE_RELEASED);
break;
case TAP_EVENT_THUMB:
break;
case TAP_EVENT_PALM: {
enum tp_tap_state dest[3] = {
TAP_STATE_1FGTAP_DRAGGING_WAIT,
TAP_STATE_2FGTAP_DRAGGING_WAIT,
TAP_STATE_3FGTAP_DRAGGING_WAIT,
};
assert(nfingers_tapped >= 1 && nfingers_tapped <= 3);
tp->tap.state = dest[nfingers_tapped - 1];
break;
}
case TAP_EVENT_PALM_UP:
break;
}
}
static void
tp_tap_dragging2_handle_event(struct tp_dispatch *tp,
struct tp_touch *t,
enum tap_event event, uint64_t time,
int nfingers_tapped)
{
switch (event) {
case TAP_EVENT_RELEASE: {
enum tp_tap_state dest[3] = {
TAP_STATE_1FGTAP_DRAGGING,
TAP_STATE_2FGTAP_DRAGGING,
TAP_STATE_3FGTAP_DRAGGING,
};
assert(nfingers_tapped >= 1 && nfingers_tapped <= 3);
tp->tap.state = dest[nfingers_tapped - 1];
break;
}
case TAP_EVENT_TOUCH:
tp->tap.state = TAP_STATE_DEAD;
tp_tap_notify(tp,
time,
nfingers_tapped,
LIBINPUT_BUTTON_STATE_RELEASED);
break;
case TAP_EVENT_MOTION:
case TAP_EVENT_TIMEOUT:
/* noop */
break;
case TAP_EVENT_BUTTON:
tp->tap.state = TAP_STATE_DEAD;
tp_tap_notify(tp,
time,
nfingers_tapped,
LIBINPUT_BUTTON_STATE_RELEASED);
break;
case TAP_EVENT_THUMB:
break;
case TAP_EVENT_PALM: {
enum tp_tap_state dest[3] = {
TAP_STATE_1FGTAP_DRAGGING,
TAP_STATE_2FGTAP_DRAGGING,
TAP_STATE_3FGTAP_DRAGGING,
};
assert(nfingers_tapped >= 1 && nfingers_tapped <= 3);
tp->tap.state = dest[nfingers_tapped - 1];
break;
}
case TAP_EVENT_PALM_UP:
break;
}
}
static void
tp_tap_dead_handle_event(struct tp_dispatch *tp,
struct tp_touch *t,
enum tap_event event,
uint64_t time)
{
switch (event) {
case TAP_EVENT_RELEASE:
if (tp->tap.nfingers_down == 0)
tp->tap.state = TAP_STATE_IDLE;
break;
case TAP_EVENT_TOUCH:
case TAP_EVENT_MOTION:
case TAP_EVENT_TIMEOUT:
case TAP_EVENT_BUTTON:
break;
case TAP_EVENT_THUMB:
break;
case TAP_EVENT_PALM:
case TAP_EVENT_PALM_UP:
if (tp->tap.nfingers_down == 0)
tp->tap.state = TAP_STATE_IDLE;
break;
}
}
static void
tp_tap_handle_event(struct tp_dispatch *tp,
struct tp_touch *t,
enum tap_event event,
uint64_t time)
{
enum tp_tap_state current;
current = tp->tap.state;
switch(tp->tap.state) {
case TAP_STATE_IDLE:
tp_tap_idle_handle_event(tp, t, event, time);
break;
case TAP_STATE_TOUCH:
tp_tap_touch_handle_event(tp, t, event, time);
break;
case TAP_STATE_HOLD:
tp_tap_hold_handle_event(tp, t, event, time);
break;
case TAP_STATE_1FGTAP_TAPPED:
tp_tap_tapped_handle_event(tp, t, event, time, 1);
break;
case TAP_STATE_2FGTAP_TAPPED:
tp_tap_tapped_handle_event(tp, t, event, time, 2);
break;
case TAP_STATE_3FGTAP_TAPPED:
tp_tap_tapped_handle_event(tp, t, event, time, 3);
break;
case TAP_STATE_TOUCH_2:
tp_tap_touch2_handle_event(tp, t, event, time);
break;
case TAP_STATE_TOUCH_2_HOLD:
tp_tap_touch2_hold_handle_event(tp, t, event, time);
break;
case TAP_STATE_TOUCH_2_RELEASE:
tp_tap_touch2_release_handle_event(tp, t, event, time);
break;
case TAP_STATE_TOUCH_3:
tp_tap_touch3_handle_event(tp, t, event, time);
break;
case TAP_STATE_TOUCH_3_HOLD:
tp_tap_touch3_hold_handle_event(tp, t, event, time);
break;
case TAP_STATE_TOUCH_3_RELEASE:
tp_tap_touch3_release_handle_event(tp, t, event, time);
break;
case TAP_STATE_TOUCH_3_RELEASE_2:
tp_tap_touch3_release2_handle_event(tp, t, event, time);
break;
case TAP_STATE_1FGTAP_DRAGGING_OR_DOUBLETAP:
tp_tap_dragging_or_doubletap_handle_event(tp, t, event, time,
1);
break;
case TAP_STATE_2FGTAP_DRAGGING_OR_DOUBLETAP:
tp_tap_dragging_or_doubletap_handle_event(tp, t, event, time,
2);
break;
case TAP_STATE_3FGTAP_DRAGGING_OR_DOUBLETAP:
tp_tap_dragging_or_doubletap_handle_event(tp, t, event, time,
3);
break;
case TAP_STATE_1FGTAP_DRAGGING:
tp_tap_dragging_handle_event(tp, t, event, time, 1);
break;
case TAP_STATE_2FGTAP_DRAGGING:
tp_tap_dragging_handle_event(tp, t, event, time, 2);
break;
case TAP_STATE_3FGTAP_DRAGGING:
tp_tap_dragging_handle_event(tp, t, event, time, 3);
break;
case TAP_STATE_1FGTAP_DRAGGING_WAIT:
tp_tap_dragging_wait_handle_event(tp, t, event, time, 1);
break;
case TAP_STATE_2FGTAP_DRAGGING_WAIT:
tp_tap_dragging_wait_handle_event(tp, t, event, time, 2);
break;
case TAP_STATE_3FGTAP_DRAGGING_WAIT:
tp_tap_dragging_wait_handle_event(tp, t, event, time, 3);
break;
case TAP_STATE_1FGTAP_DRAGGING_OR_TAP:
tp_tap_dragging_tap_handle_event(tp, t, event, time, 1);
break;
case TAP_STATE_2FGTAP_DRAGGING_OR_TAP:
tp_tap_dragging_tap_handle_event(tp, t, event, time, 2);
break;
case TAP_STATE_3FGTAP_DRAGGING_OR_TAP:
tp_tap_dragging_tap_handle_event(tp, t, event, time, 3);
break;
case TAP_STATE_1FGTAP_DRAGGING_2:
tp_tap_dragging2_handle_event(tp, t, event, time, 1);
break;
case TAP_STATE_2FGTAP_DRAGGING_2:
tp_tap_dragging2_handle_event(tp, t, event, time, 2);
break;
case TAP_STATE_3FGTAP_DRAGGING_2:
tp_tap_dragging2_handle_event(tp, t, event, time, 3);
break;
case TAP_STATE_DEAD:
tp_tap_dead_handle_event(tp, t, event, time);
break;
}
if (tp->tap.state == TAP_STATE_IDLE || tp->tap.state == TAP_STATE_DEAD)
tp_tap_clear_timer(tp);
if (current != tp->tap.state)
evdev_log_debug(tp->device,
"tap: touch %d (%s), tap state %s → %s → %s\n",
t ? (int)t->index : -1,
t ? touch_state_to_str(t->state) : "",
tap_state_to_str(current),
tap_event_to_str(event),
tap_state_to_str(tp->tap.state));
}
static bool
tp_tap_exceeds_motion_threshold(struct tp_dispatch *tp,
struct tp_touch *t)
{
struct phys_coords mm =
tp_phys_delta(tp, device_delta(t->point, t->tap.initial));
/* if we have more fingers down than slots, we know that synaptics
* touchpads are likely to give us pointer jumps.
* This triggers the movement threshold, making three-finger taps
* less reliable (#101435)
*
* This uses the real nfingers_down, not the one for taps.
*/
if (tp->device->model_flags & EVDEV_MODEL_SYNAPTICS_SERIAL_TOUCHPAD &&
(tp->nfingers_down > 2 || tp->old_nfingers_down > 2) &&
(tp->nfingers_down > tp->num_slots ||
tp->old_nfingers_down > tp->num_slots)) {
return false;
}
/* Semi-mt devices will give us large movements on finger release,
* depending which touch is released. Make sure we ignore any
* movement in the same frame as a finger change.
*/
if (tp->semi_mt && tp->nfingers_down != tp->old_nfingers_down)
return false;
return length_in_mm(mm) > DEFAULT_TAP_MOVE_THRESHOLD;
}
static bool
tp_tap_enabled(struct tp_dispatch *tp)
{
return tp->tap.enabled && !tp->tap.suspended;
}
int
tp_tap_handle_state(struct tp_dispatch *tp, uint64_t time)
{
struct tp_touch *t;
int filter_motion = 0;
if (!tp_tap_enabled(tp))
return 0;
/* Handle queued button pressed events from clickpads. For touchpads
* with separate physical buttons, ignore button pressed events so they
* don't interfere with tapping. */
if (tp->buttons.is_clickpad && tp->queued & TOUCHPAD_EVENT_BUTTON_PRESS)
tp_tap_handle_event(tp, NULL, TAP_EVENT_BUTTON, time);
tp_for_each_touch(tp, t) {
if (!t->dirty || t->state == TOUCH_NONE)
continue;
if (tp->buttons.is_clickpad &&
tp->queued & TOUCHPAD_EVENT_BUTTON_PRESS)
t->tap.state = TAP_TOUCH_STATE_DEAD;
/* If a touch was considered thumb for tapping once, we
* ignore it for the rest of lifetime */
if (t->tap.is_thumb)
continue;
/* A palm tap needs to be properly released because we might
* be who-knows-where in the state machine. Otherwise, we
* ignore any event from it.
*/
if (t->tap.is_palm) {
if (t->state == TOUCH_END)
tp_tap_handle_event(tp,
t,
TAP_EVENT_PALM_UP,
time);
continue;
}
if (t->state == TOUCH_HOVERING)
continue;
if (t->palm.state != PALM_NONE) {
assert(!t->tap.is_palm);
t->tap.is_palm = true;
t->tap.state = TAP_TOUCH_STATE_DEAD;
if (t->state != TOUCH_BEGIN) {
tp_tap_handle_event(tp, t, TAP_EVENT_PALM, time);
assert(tp->tap.nfingers_down > 0);
tp->tap.nfingers_down--;
}
} else if (t->state == TOUCH_BEGIN) {
/* The simple version: if a touch is a thumb on
* begin we ignore it. All other thumb touches
* follow the normal tap state for now */
if (tp_thumb_ignored_for_tap(tp, t)) {
t->tap.is_thumb = true;
continue;
}
t->tap.state = TAP_TOUCH_STATE_TOUCH;
t->tap.initial = t->point;
tp->tap.nfingers_down++;
tp_tap_handle_event(tp, t, TAP_EVENT_TOUCH, time);
} else if (t->state == TOUCH_END) {
if (t->was_down) {
assert(tp->tap.nfingers_down >= 1);
tp->tap.nfingers_down--;
tp_tap_handle_event(tp, t, TAP_EVENT_RELEASE, time);
}
t->tap.state = TAP_TOUCH_STATE_IDLE;
} else if (tp->tap.state != TAP_STATE_IDLE &&
tp_thumb_ignored(tp, t)) {
tp_tap_handle_event(tp, t, TAP_EVENT_THUMB, time);
} else if (tp->tap.state != TAP_STATE_IDLE &&
tp_tap_exceeds_motion_threshold(tp, t)) {
struct tp_touch *tmp;
/* Any touch exceeding the threshold turns all
* touches into DEAD */
tp_for_each_touch(tp, tmp) {
if (tmp->tap.state == TAP_TOUCH_STATE_TOUCH)
tmp->tap.state = TAP_TOUCH_STATE_DEAD;
}
tp_tap_handle_event(tp, t, TAP_EVENT_MOTION, time);
}
}
/**
* In any state where motion exceeding the move threshold would
* move to the next state, filter that motion until we actually
* exceed it. This prevents small motion events while we're waiting
* on a decision if a tap is a tap.
*/
switch (tp->tap.state) {
case TAP_STATE_TOUCH:
case TAP_STATE_1FGTAP_TAPPED:
case TAP_STATE_2FGTAP_TAPPED:
case TAP_STATE_3FGTAP_TAPPED:
case TAP_STATE_1FGTAP_DRAGGING_OR_DOUBLETAP:
case TAP_STATE_2FGTAP_DRAGGING_OR_DOUBLETAP:
case TAP_STATE_3FGTAP_DRAGGING_OR_DOUBLETAP:
case TAP_STATE_1FGTAP_DRAGGING_OR_TAP:
case TAP_STATE_2FGTAP_DRAGGING_OR_TAP:
case TAP_STATE_3FGTAP_DRAGGING_OR_TAP:
case TAP_STATE_TOUCH_2:
case TAP_STATE_TOUCH_3:
filter_motion = 1;
break;
default:
break;
}
assert(tp->tap.nfingers_down <= tp->nfingers_down);
if (tp->nfingers_down == 0)
assert(tp->tap.nfingers_down == 0);
return filter_motion;
}
static inline void
tp_tap_update_map(struct tp_dispatch *tp)
{
if (tp->tap.state != TAP_STATE_IDLE)
return;
if (tp->tap.map != tp->tap.want_map)
tp->tap.map = tp->tap.want_map;
}
void
tp_tap_post_process_state(struct tp_dispatch *tp)
{
tp_tap_update_map(tp);
}
static void
tp_tap_handle_timeout(uint64_t time, void *data)
{
struct tp_dispatch *tp = data;
struct tp_touch *t;
tp_tap_handle_event(tp, NULL, TAP_EVENT_TIMEOUT, time);
tp_for_each_touch(tp, t) {
if (t->state == TOUCH_NONE ||
t->tap.state == TAP_TOUCH_STATE_IDLE)
continue;
t->tap.state = TAP_TOUCH_STATE_DEAD;
}
}
static void
tp_tap_enabled_update(struct tp_dispatch *tp, bool suspended, bool enabled, uint64_t time)
{
bool was_enabled = tp_tap_enabled(tp);
tp->tap.suspended = suspended;
tp->tap.enabled = enabled;
if (tp_tap_enabled(tp) == was_enabled)
return;
if (tp_tap_enabled(tp)) {
struct tp_touch *t;
/* On resume, all touches are considered palms */
tp_for_each_touch(tp, t) {
if (t->state == TOUCH_NONE)
continue;
t->tap.is_palm = true;
t->tap.state = TAP_TOUCH_STATE_DEAD;
}
tp->tap.state = TAP_STATE_IDLE;
tp->tap.nfingers_down = 0;
} else {
tp_release_all_taps(tp, time);
}
}
static int
tp_tap_config_count(struct libinput_device *device)
{
struct evdev_dispatch *dispatch = evdev_device(device)->dispatch;
struct tp_dispatch *tp = tp_dispatch(dispatch);
return min(tp->ntouches, 3U); /* we only do up to 3 finger tap */
}
static enum libinput_config_status
tp_tap_config_set_enabled(struct libinput_device *device,
enum libinput_config_tap_state enabled)
{
struct evdev_dispatch *dispatch = evdev_device(device)->dispatch;
struct tp_dispatch *tp = tp_dispatch(dispatch);
tp_tap_enabled_update(tp, tp->tap.suspended,
(enabled == LIBINPUT_CONFIG_TAP_ENABLED),
libinput_now(device->seat->libinput));
return LIBINPUT_CONFIG_STATUS_SUCCESS;
}
static enum libinput_config_tap_state
tp_tap_config_is_enabled(struct libinput_device *device)
{
struct evdev_dispatch *dispatch = evdev_device(device)->dispatch;
struct tp_dispatch *tp = tp_dispatch(dispatch);
return tp->tap.enabled ? LIBINPUT_CONFIG_TAP_ENABLED :
LIBINPUT_CONFIG_TAP_DISABLED;
}
static enum libinput_config_tap_state
tp_tap_default(struct evdev_device *evdev)
{
/**
* If we don't have a left button we must have tapping enabled by
* default.
*/
if (!libevdev_has_event_code(evdev->evdev, EV_KEY, BTN_LEFT))
return LIBINPUT_CONFIG_TAP_ENABLED;
/**
* Tapping is disabled by default for two reasons:
* * if you don't know that tapping is a thing (or enabled by
* default), you get spurious mouse events that make the desktop
* feel buggy.
* * if you do know what tapping is and you want it, you
* usually know where to enable it, or at least you can search for
* it.
*/
return LIBINPUT_CONFIG_TAP_DISABLED;
}
static enum libinput_config_tap_state
tp_tap_config_get_default(struct libinput_device *device)
{
struct evdev_device *evdev = evdev_device(device);
return tp_tap_default(evdev);
}
static enum libinput_config_status
tp_tap_config_set_map(struct libinput_device *device,
enum libinput_config_tap_button_map map)
{
struct evdev_dispatch *dispatch = evdev_device(device)->dispatch;
struct tp_dispatch *tp = tp_dispatch(dispatch);
tp->tap.want_map = map;
tp_tap_update_map(tp);
return LIBINPUT_CONFIG_STATUS_SUCCESS;
}
static enum libinput_config_tap_button_map
tp_tap_config_get_map(struct libinput_device *device)
{
struct evdev_dispatch *dispatch = evdev_device(device)->dispatch;
struct tp_dispatch *tp = tp_dispatch(dispatch);
return tp->tap.want_map;
}
static enum libinput_config_tap_button_map
tp_tap_config_get_default_map(struct libinput_device *device)
{
return LIBINPUT_CONFIG_TAP_MAP_LRM;
}
static enum libinput_config_status
tp_tap_config_set_drag_enabled(struct libinput_device *device,
enum libinput_config_drag_state enabled)
{
struct evdev_dispatch *dispatch = evdev_device(device)->dispatch;
struct tp_dispatch *tp = tp_dispatch(dispatch);
tp->tap.drag_enabled = enabled;
return LIBINPUT_CONFIG_STATUS_SUCCESS;
}
static enum libinput_config_drag_state
tp_tap_config_get_drag_enabled(struct libinput_device *device)
{
struct evdev_dispatch *dispatch = evdev_device(device)->dispatch;
struct tp_dispatch *tp = tp_dispatch(dispatch);
return tp->tap.drag_enabled;
}
static inline enum libinput_config_drag_state
tp_drag_default(struct evdev_device *device)
{
return LIBINPUT_CONFIG_DRAG_ENABLED;
}
static enum libinput_config_drag_state
tp_tap_config_get_default_drag_enabled(struct libinput_device *device)
{
struct evdev_device *evdev = evdev_device(device);
return tp_drag_default(evdev);
}
static enum libinput_config_status
tp_tap_config_set_draglock_enabled(struct libinput_device *device,
enum libinput_config_drag_lock_state enabled)
{
struct evdev_dispatch *dispatch = evdev_device(device)->dispatch;
struct tp_dispatch *tp = tp_dispatch(dispatch);
tp->tap.drag_lock = enabled;
return LIBINPUT_CONFIG_STATUS_SUCCESS;
}
static enum libinput_config_drag_lock_state
tp_tap_config_get_draglock_enabled(struct libinput_device *device)
{
struct evdev_dispatch *dispatch = evdev_device(device)->dispatch;
struct tp_dispatch *tp = tp_dispatch(dispatch);
return tp->tap.drag_lock;
}
static inline enum libinput_config_drag_lock_state
tp_drag_lock_default(struct evdev_device *device)
{
return LIBINPUT_CONFIG_DRAG_LOCK_DISABLED;
}
static enum libinput_config_drag_lock_state
tp_tap_config_get_default_draglock_enabled(struct libinput_device *device)
{
struct evdev_device *evdev = evdev_device(device);
return tp_drag_lock_default(evdev);
}
void
tp_init_tap(struct tp_dispatch *tp)
{
char timer_name[64];
tp->tap.config.count = tp_tap_config_count;
tp->tap.config.set_enabled = tp_tap_config_set_enabled;
tp->tap.config.get_enabled = tp_tap_config_is_enabled;
tp->tap.config.get_default = tp_tap_config_get_default;
tp->tap.config.set_map = tp_tap_config_set_map;
tp->tap.config.get_map = tp_tap_config_get_map;
tp->tap.config.get_default_map = tp_tap_config_get_default_map;
tp->tap.config.set_drag_enabled = tp_tap_config_set_drag_enabled;
tp->tap.config.get_drag_enabled = tp_tap_config_get_drag_enabled;
tp->tap.config.get_default_drag_enabled = tp_tap_config_get_default_drag_enabled;
tp->tap.config.set_draglock_enabled = tp_tap_config_set_draglock_enabled;
tp->tap.config.get_draglock_enabled = tp_tap_config_get_draglock_enabled;
tp->tap.config.get_default_draglock_enabled = tp_tap_config_get_default_draglock_enabled;
tp->device->base.config.tap = &tp->tap.config;
tp->tap.state = TAP_STATE_IDLE;
tp->tap.enabled = tp_tap_default(tp->device);
tp->tap.map = LIBINPUT_CONFIG_TAP_MAP_LRM;
tp->tap.want_map = tp->tap.map;
tp->tap.drag_enabled = tp_drag_default(tp->device);
tp->tap.drag_lock = tp_drag_lock_default(tp->device);
snprintf(timer_name,
sizeof(timer_name),
"%s tap",
evdev_device_get_sysname(tp->device));
libinput_timer_init(&tp->tap.timer,
tp_libinput_context(tp),
timer_name,
tp_tap_handle_timeout, tp);
}
void
tp_remove_tap(struct tp_dispatch *tp)
{
libinput_timer_cancel(&tp->tap.timer);
}
void
tp_release_all_taps(struct tp_dispatch *tp, uint64_t now)
{
struct tp_touch *t;
int i;
for (i = 1; i <= 3; i++) {
if (tp->tap.buttons_pressed & bit(i))
tp_tap_notify(tp, now, i, LIBINPUT_BUTTON_STATE_RELEASED);
}
/* To neutralize all current touches, we make them all palms */
tp_for_each_touch(tp, t) {
if (t->state == TOUCH_NONE)
continue;
if (t->tap.is_palm)
continue;
t->tap.is_palm = true;
t->tap.state = TAP_TOUCH_STATE_DEAD;
}
tp->tap.state = TAP_STATE_IDLE;
tp->tap.nfingers_down = 0;
}
void
tp_tap_suspend(struct tp_dispatch *tp, uint64_t time)
{
tp_tap_enabled_update(tp, true, tp->tap.enabled, time);
}
void
tp_tap_resume(struct tp_dispatch *tp, uint64_t time)
{
tp_tap_enabled_update(tp, false, tp->tap.enabled, time);
}
bool
tp_tap_dragging(const struct tp_dispatch *tp)
{
switch (tp->tap.state) {
case TAP_STATE_1FGTAP_DRAGGING:
case TAP_STATE_2FGTAP_DRAGGING:
case TAP_STATE_3FGTAP_DRAGGING:
case TAP_STATE_1FGTAP_DRAGGING_2:
case TAP_STATE_2FGTAP_DRAGGING_2:
case TAP_STATE_3FGTAP_DRAGGING_2:
case TAP_STATE_1FGTAP_DRAGGING_WAIT:
case TAP_STATE_2FGTAP_DRAGGING_WAIT:
case TAP_STATE_3FGTAP_DRAGGING_WAIT:
case TAP_STATE_1FGTAP_DRAGGING_OR_TAP:
case TAP_STATE_2FGTAP_DRAGGING_OR_TAP:
case TAP_STATE_3FGTAP_DRAGGING_OR_TAP:
return true;
default:
return false;
}
}
bool
tp_tap_dragging_or_double_tapping(const struct tp_dispatch *tp)
{
switch (tp->tap.state) {
case TAP_STATE_1FGTAP_DRAGGING_OR_DOUBLETAP:
case TAP_STATE_2FGTAP_DRAGGING_OR_DOUBLETAP:
case TAP_STATE_3FGTAP_DRAGGING_OR_DOUBLETAP:
return true;
default:
return false;
}
}
libinput-1.28.1/src/evdev-mt-touchpad-thumb.c000066400000000000000000000304101477265155700210560ustar00rootroot00000000000000/*
* Copyright © 2019 Matt Mayfield
* Copyright © 2019 Red Hat, Inc.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice (including the next
* paragraph) shall be included in all copies or substantial portions of the
* Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
*/
#include "config.h"
#include "evdev-mt-touchpad.h"
/* distance between fingers to assume it is not a scroll */
#define SCROLL_MM_X 35
#define SCROLL_MM_Y 25
#define THUMB_TIMEOUT ms2us(100)
static inline const char*
thumb_state_to_str(enum tp_thumb_state state)
{
switch(state){
CASE_RETURN_STRING(THUMB_STATE_FINGER);
CASE_RETURN_STRING(THUMB_STATE_JAILED);
CASE_RETURN_STRING(THUMB_STATE_PINCH);
CASE_RETURN_STRING(THUMB_STATE_SUPPRESSED);
CASE_RETURN_STRING(THUMB_STATE_REVIVED);
CASE_RETURN_STRING(THUMB_STATE_REVIVED_JAILED);
CASE_RETURN_STRING(THUMB_STATE_DEAD);
}
return NULL;
}
static void
tp_thumb_set_state(struct tp_dispatch *tp,
struct tp_touch *t,
enum tp_thumb_state state)
{
unsigned int index = t ? t->index : UINT_MAX;
if (tp->thumb.state == state && tp->thumb.index == index)
return;
evdev_log_debug(tp->device,
"thumb: touch %d, %s → %s\n",
(int)index,
thumb_state_to_str(tp->thumb.state),
thumb_state_to_str(state));
tp->thumb.state = state;
tp->thumb.index = index;
}
void
tp_thumb_reset(struct tp_dispatch *tp)
{
tp->thumb.state = THUMB_STATE_FINGER;
tp->thumb.index = UINT_MAX;
tp->thumb.pinch_eligible = true;
}
static void
tp_thumb_lift(struct tp_dispatch *tp)
{
tp->thumb.state = THUMB_STATE_FINGER;
tp->thumb.index = UINT_MAX;
}
static bool
tp_thumb_in_exclusion_area(const struct tp_dispatch *tp,
const struct tp_touch *t)
{
return (t->point.y > tp->thumb.lower_thumb_line &&
tp->scroll.method != LIBINPUT_CONFIG_SCROLL_EDGE);
}
static bool
tp_thumb_detect_pressure_size(const struct tp_dispatch *tp,
const struct tp_touch *t)
{
bool is_thumb = false;
if (tp->thumb.use_pressure &&
t->pressure > tp->thumb.pressure_threshold &&
tp_thumb_in_exclusion_area(tp, t)) {
is_thumb = true;
}
if (tp->thumb.use_size &&
(t->major > tp->thumb.size_threshold) &&
(t->minor < (tp->thumb.size_threshold * 0.6))) {
is_thumb = true;
}
return is_thumb;
}
static bool
tp_thumb_needs_jail(const struct tp_dispatch *tp, const struct tp_touch *t)
{
if (t->point.y < tp->thumb.upper_thumb_line ||
tp->scroll.method == LIBINPUT_CONFIG_SCROLL_EDGE)
return false;
if (!tp_thumb_in_exclusion_area(tp, t) &&
(tp->thumb.use_size || tp->thumb.use_pressure) &&
!tp_thumb_detect_pressure_size(tp, t))
return false;
if (t->speed.exceeded_count >= 10)
return false;
return true;
}
bool
tp_thumb_ignored(const struct tp_dispatch *tp, const struct tp_touch *t)
{
return (tp->thumb.detect_thumbs &&
tp->thumb.index == t->index &&
(tp->thumb.state == THUMB_STATE_JAILED ||
tp->thumb.state == THUMB_STATE_PINCH ||
tp->thumb.state == THUMB_STATE_SUPPRESSED ||
tp->thumb.state == THUMB_STATE_REVIVED_JAILED ||
tp->thumb.state == THUMB_STATE_DEAD));
}
bool
tp_thumb_ignored_for_tap(const struct tp_dispatch *tp,
const struct tp_touch *t)
{
return (tp->thumb.detect_thumbs &&
tp->thumb.index == t->index &&
(tp->thumb.state == THUMB_STATE_PINCH ||
tp->thumb.state == THUMB_STATE_SUPPRESSED ||
tp->thumb.state == THUMB_STATE_DEAD));
}
bool
tp_thumb_ignored_for_gesture(const struct tp_dispatch *tp,
const struct tp_touch *t)
{
return (tp->thumb.detect_thumbs &&
tp->thumb.index == t->index &&
(tp->thumb.state == THUMB_STATE_JAILED ||
tp->thumb.state == THUMB_STATE_SUPPRESSED ||
tp->thumb.state == THUMB_STATE_REVIVED_JAILED ||
tp->thumb.state == THUMB_STATE_DEAD));
}
void
tp_thumb_suppress(struct tp_dispatch *tp, struct tp_touch *t)
{
if(tp->thumb.state == THUMB_STATE_FINGER ||
tp->thumb.state == THUMB_STATE_JAILED ||
tp->thumb.state == THUMB_STATE_PINCH ||
tp->thumb.index != t->index) {
tp_thumb_set_state(tp, t, THUMB_STATE_SUPPRESSED);
return;
}
tp_thumb_set_state(tp, t, THUMB_STATE_DEAD);
}
static void
tp_thumb_pinch(struct tp_dispatch *tp, struct tp_touch *t)
{
if(tp->thumb.state == THUMB_STATE_FINGER ||
tp->thumb.state == THUMB_STATE_JAILED ||
tp->thumb.index != t->index)
tp_thumb_set_state(tp, t, THUMB_STATE_PINCH);
else if (tp->thumb.state != THUMB_STATE_PINCH)
tp_thumb_suppress(tp, t);
}
static void
tp_thumb_revive(struct tp_dispatch *tp, struct tp_touch *t)
{
if((tp->thumb.state != THUMB_STATE_SUPPRESSED &&
tp->thumb.state != THUMB_STATE_PINCH) ||
(tp->thumb.index != t->index))
return;
if(tp_thumb_needs_jail(tp, t))
tp_thumb_set_state(tp, t, THUMB_STATE_REVIVED_JAILED);
else
tp_thumb_set_state(tp, t, THUMB_STATE_REVIVED);
}
void
tp_thumb_update_touch(struct tp_dispatch *tp,
struct tp_touch *t,
uint64_t time)
{
if (!tp->thumb.detect_thumbs)
return;
/* Once any active touch exceeds the speed threshold, don't
* try to detect pinches until all touches lift.
*/
if (t->speed.exceeded_count >= 10 &&
tp->thumb.pinch_eligible &&
tp->gesture.state == GESTURE_STATE_NONE) {
tp->thumb.pinch_eligible = false;
if(tp->thumb.state == THUMB_STATE_PINCH) {
struct tp_touch *thumb;
tp_for_each_touch(tp, thumb) {
if (thumb->index != tp->thumb.index)
continue;
tp_thumb_set_state(tp, thumb, THUMB_STATE_SUPPRESSED);
break;
}
}
}
/* Handle the thumb lifting off the touchpad */
if (t->state == TOUCH_END && t->index == tp->thumb.index) {
tp_thumb_lift(tp);
return;
}
/* If this touch is not the only one, thumb updates happen by context
* instead of here
*/
if (tp->nfingers_down > 1)
return;
/* If we arrived here by other fingers lifting off, revive current touch
* if appropriate
*/
tp_thumb_revive(tp, t);
/* First new touch below the lower_thumb_line, or below the upper_thumb_
* line if hardware can't verify it's a finger, starts as JAILED.
*/
if (t->state == TOUCH_BEGIN && tp_thumb_needs_jail(tp, t)) {
tp_thumb_set_state(tp, t, THUMB_STATE_JAILED);
return;
}
/* If a touch breaks the speed threshold, or leaves the thumb area
* (upper or lower, depending on HW detection), it "escapes" jail.
*/
if (tp->thumb.state == THUMB_STATE_JAILED &&
!(tp_thumb_needs_jail(tp, t)))
tp_thumb_set_state(tp, t, THUMB_STATE_FINGER);
if (tp->thumb.state == THUMB_STATE_REVIVED_JAILED &&
!(tp_thumb_needs_jail(tp, t)))
tp_thumb_set_state(tp, t, THUMB_STATE_REVIVED);
}
void
tp_thumb_update_multifinger(struct tp_dispatch *tp)
{
struct tp_touch *t;
struct tp_touch *first = NULL,
*second = NULL,
*newest = NULL,
*oldest = NULL;
struct device_coords distance;
struct phys_coords mm;
unsigned int speed_exceeded_count = 0;
/* Get the first and second bottom-most touches, the max speed exceeded
* count overall, and the newest and oldest touches.
*/
tp_for_each_touch(tp, t) {
if (t->state == TOUCH_NONE ||
t->state == TOUCH_HOVERING)
continue;
if (t->state == TOUCH_BEGIN)
newest = t;
speed_exceeded_count = max(speed_exceeded_count,
t->speed.exceeded_count);
if (!oldest || t->initial_time < oldest->initial_time) {
oldest = t;
}
if (!first) {
first = t;
continue;
}
if (t->point.y > first->point.y) {
second = first;
first = t;
continue;
}
if (!second || t->point.y > second->point.y ) {
second = t;
}
}
if (!first || !second)
return;
distance.x = abs(first->point.x - second->point.x);
distance.y = abs(first->point.y - second->point.y);
mm = evdev_device_unit_delta_to_mm(tp->device, &distance);
/* Speed-based thumb detection: if an existing finger is moving, and
* a new touch arrives, mark it as a thumb if it doesn't qualify as a
* 2-finger scroll. Also account for a thumb dropping onto the touchpad
* while scrolling or swiping.
*/
if (newest &&
tp->thumb.state == THUMB_STATE_FINGER &&
tp->nfingers_down >= 2 &&
speed_exceeded_count > 5 &&
(tp->scroll.method != LIBINPUT_CONFIG_SCROLL_2FG ||
(mm.x > SCROLL_MM_X || mm.y > SCROLL_MM_Y))) {
evdev_log_debug(tp->device,
"touch %d is speed-based thumb\n",
newest->index);
tp_thumb_suppress(tp, newest);
return;
}
/* Contextual thumb detection: When a new touch arrives, check the
* timing and position of the two lowest touches.
*
* If both touches are very close, regardless of timing, and no matter
* their absolute position on the touchpad, count them both as live
* to support responsive two-finger scrolling.
*/
if (mm.x < SCROLL_MM_X && mm.y < SCROLL_MM_Y) {
tp_thumb_lift(tp);
return;
}
/* If all the touches arrived within a very short time, and all of them
* are above the lower_thumb_line, assume the touches are all live to
* enable double, triple, and quadruple taps, clicks, and gestures. (If
* there is an actual resting thumb, it will be detected later based on
* the behavior of the other touches.)
*/
if (newest &&
(newest->initial_time - oldest->initial_time) < THUMB_TIMEOUT &&
first->point.y < tp->thumb.lower_thumb_line) {
tp_thumb_lift(tp);
return;
}
/* If we're past the THUMB_TIMEOUT, and the touches are relatively far
* apart, then the new touch is unlikely to be a tap or clickfinger.
* Proceed with pre-1.14.901 thumb detection.
*/
if (mm.y > SCROLL_MM_Y) {
if (tp->thumb.pinch_eligible)
tp_thumb_pinch(tp, first);
else
tp_thumb_suppress(tp, first);
} else {
tp_thumb_lift(tp);
}
}
void
tp_init_thumb(struct tp_dispatch *tp)
{
struct evdev_device *device = tp->device;
double w = 0.0, h = 0.0;
struct device_coords edges;
struct phys_coords mm = { 0.0, 0.0 };
uint32_t threshold;
struct quirks_context *quirks;
struct quirks *q;
tp->thumb.detect_thumbs = false;
if (!tp->buttons.is_clickpad)
return;
/* if the touchpad is less than 50mm high, skip thumb detection.
* it's too small to meaningfully interact with a thumb on the
* touchpad */
evdev_device_get_size(device, &w, &h);
if (h < 50)
return;
tp->thumb.detect_thumbs = true;
tp->thumb.use_pressure = false;
tp->thumb.pressure_threshold = INT_MAX;
tp->thumb.size_threshold = INT_MAX;
/* detect thumbs by pressure in the bottom 15mm, detect thumbs by
* lingering in the bottom 8mm */
mm.y = h * 0.85;
edges = evdev_device_mm_to_units(device, &mm);
tp->thumb.upper_thumb_line = edges.y;
mm.y = h * 0.92;
edges = evdev_device_mm_to_units(device, &mm);
tp->thumb.lower_thumb_line = edges.y;
quirks = evdev_libinput_context(device)->quirks;
q = quirks_fetch_for_device(quirks, device->udev_device);
if (libevdev_has_event_code(device->evdev, EV_ABS, ABS_MT_PRESSURE)) {
if (quirks_get_uint32(q,
QUIRK_ATTR_THUMB_PRESSURE_THRESHOLD,
&threshold)) {
tp->thumb.use_pressure = true;
tp->thumb.pressure_threshold = threshold;
}
}
if (libevdev_has_event_code(device->evdev, EV_ABS, ABS_MT_TOUCH_MAJOR)) {
if (quirks_get_uint32(q,
QUIRK_ATTR_THUMB_SIZE_THRESHOLD,
&threshold)) {
tp->thumb.use_size = true;
tp->thumb.size_threshold = threshold;
}
}
tp_thumb_reset(tp);
quirks_unref(q);
evdev_log_debug(device,
"thumb: enabled thumb detection (area%s%s)\n",
tp->thumb.use_pressure ? ", pressure" : "",
tp->thumb.use_size ? ", size" : "");
}
struct tp_touch*
tp_thumb_get_touch(struct tp_dispatch *tp)
{
struct tp_touch *thumb;
if (tp->thumb.index == UINT_MAX)
return NULL;
tp_for_each_touch(tp, thumb) {
if (thumb->index == tp->thumb.index)
return thumb;
}
return NULL;
}
libinput-1.28.1/src/evdev-mt-touchpad.c000066400000000000000000003143071477265155700177530ustar00rootroot00000000000000/*
* Copyright © 2014-2015 Red Hat, Inc.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice (including the next
* paragraph) shall be included in all copies or substantial portions of the
* Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
*/
#include "config.h"
#include
#include
#include
#include
#if HAVE_LIBWACOM
#include
#endif
#include "quirks.h"
#include "evdev-mt-touchpad.h"
#include "util-input-event.h"
#define DEFAULT_TRACKPOINT_ACTIVITY_TIMEOUT ms2us(300)
#define DEFAULT_TRACKPOINT_EVENT_TIMEOUT ms2us(40)
#define DEFAULT_KEYBOARD_ACTIVITY_TIMEOUT_1 ms2us(200)
#define DEFAULT_KEYBOARD_ACTIVITY_TIMEOUT_2 ms2us(500)
#define FAKE_FINGER_OVERFLOW bit(7)
#define THUMB_IGNORE_SPEED_THRESHOLD 20 /* mm/s */
enum notify {
DONT_NOTIFY,
DO_NOTIFY,
};
static inline struct tp_history_point*
tp_motion_history_offset(struct tp_touch *t, int offset)
{
int offset_index =
(t->history.index - offset + TOUCHPAD_HISTORY_LENGTH) %
TOUCHPAD_HISTORY_LENGTH;
return &t->history.samples[offset_index];
}
struct normalized_coords
tp_filter_motion(struct tp_dispatch *tp,
const struct device_float_coords *unaccelerated,
uint64_t time)
{
struct device_float_coords raw;
const struct normalized_coords zero = { 0.0, 0.0 };
if (device_float_is_zero(*unaccelerated))
return zero;
/* Convert to device units with x/y in the same resolution */
raw = tp_scale_to_xaxis(tp, *unaccelerated);
return filter_dispatch(tp->device->pointer.filter,
&raw, tp, time);
}
struct normalized_coords
tp_filter_motion_unaccelerated(struct tp_dispatch *tp,
const struct device_float_coords *unaccelerated,
uint64_t time)
{
struct device_float_coords raw;
const struct normalized_coords zero = { 0.0, 0.0 };
if (device_float_is_zero(*unaccelerated))
return zero;
/* Convert to device units with x/y in the same resolution */
raw = tp_scale_to_xaxis(tp, *unaccelerated);
return filter_dispatch_constant(tp->device->pointer.filter,
&raw, tp, time);
}
struct normalized_coords
tp_filter_scroll(struct tp_dispatch *tp,
const struct device_float_coords *unaccelerated,
uint64_t time)
{
struct device_float_coords raw;
const struct normalized_coords zero = { 0.0, 0.0 };
if (device_float_is_zero(*unaccelerated))
return zero;
/* Convert to device units with x/y in the same resolution */
raw = tp_scale_to_xaxis(tp, *unaccelerated);
return filter_dispatch_scroll(tp->device->pointer.filter,
&raw, tp, time);
}
static inline void
tp_calculate_motion_speed(struct tp_dispatch *tp,
struct tp_touch *t,
uint64_t time)
{
const struct tp_history_point *last;
struct device_coords delta;
struct phys_coords mm;
double distance;
double speed;
/* Don't do this on single-touch or semi-mt devices */
if (!tp->has_mt || tp->semi_mt)
return;
if (t->state != TOUCH_UPDATE)
return;
/* This doesn't kick in until we have at least 4 events in the
* motion history. As a side-effect, this automatically handles the
* 2fg scroll where a finger is down and moving fast before the
* other finger comes down for the scroll.
*
* We do *not* reset the speed to 0 here though. The motion history
* is reset whenever a new finger is down, so we'd be resetting the
* speed and failing.
*/
if (t->history.count < 4)
return;
/* TODO: we probably need a speed history here so we can average
* across a few events */
last = tp_motion_history_offset(t, 1);
delta.x = abs(t->point.x - last->point.x);
delta.y = abs(t->point.y - last->point.y);
mm = evdev_device_unit_delta_to_mm(tp->device, &delta);
distance = length_in_mm(mm);
speed = distance/(time - last->time); /* mm/us */
speed *= 1000000; /* mm/s */
t->speed.last_speed = speed;
}
static inline void
tp_motion_history_push(struct tp_touch *t, uint64_t time)
{
int motion_index = (t->history.index + 1) % TOUCHPAD_HISTORY_LENGTH;
if (t->history.count < TOUCHPAD_HISTORY_LENGTH)
t->history.count++;
t->history.samples[motion_index].point = t->point;
t->history.samples[motion_index].time = time;
t->history.index = motion_index;
}
/* Idea: if we got a tuple of *very* quick moves like {Left, Right,
* Left}, or {Right, Left, Right}, it means touchpad jitters since no
* human can move like that within thresholds.
*
* We encode left moves as zeroes, and right as ones. We also drop
* the array to all zeroes when constraints are not satisfied. Then we
* search for the pattern {1,0,1}. It can't match {Left, Right, Left},
* but it does match {Left, Right, Left, Right}, so it's okay.
*
* This only looks at x changes, y changes are ignored.
*/
static inline void
tp_detect_wobbling(struct tp_dispatch *tp,
struct tp_touch *t,
uint64_t time)
{
int dx, dy;
uint64_t dtime;
const struct device_coords* prev_point;
if (tp->nfingers_down != 1 ||
tp->nfingers_down != tp->old_nfingers_down)
return;
if (tp->hysteresis.enabled || t->history.count == 0)
return;
if (!(tp->queued & TOUCHPAD_EVENT_MOTION)) {
t->hysteresis.x_motion_history = 0;
return;
}
prev_point = &tp_motion_history_offset(t, 0)->point;
dx = prev_point->x - t->point.x;
dy = prev_point->y - t->point.y;
dtime = time - tp->hysteresis.last_motion_time;
tp->hysteresis.last_motion_time = time;
if ((dx == 0 && dy != 0) || dtime > ms2us(40)) {
t->hysteresis.x_motion_history = 0;
return;
}
t->hysteresis.x_motion_history >>= 1;
if (dx > 0) { /* right move */
static const char r_l_r = 0x5; /* {Right, Left, Right} */
t->hysteresis.x_motion_history |= bit(2);
if (t->hysteresis.x_motion_history == r_l_r) {
tp->hysteresis.enabled = true;
evdev_log_debug(tp->device,
"hysteresis enabled. "
"See %s/touchpad-jitter.html for details\n",
HTTP_DOC_LINK);
}
}
}
static inline void
tp_motion_hysteresis(struct tp_dispatch *tp,
struct tp_touch *t)
{
if (!tp->hysteresis.enabled)
return;
if (t->history.count > 0)
t->point = evdev_hysteresis(&t->point,
&t->hysteresis.center,
&tp->hysteresis.margin);
t->hysteresis.center = t->point;
}
static inline void
tp_motion_history_reset(struct tp_touch *t)
{
t->history.count = 0;
}
static inline struct tp_touch *
tp_current_touch(struct tp_dispatch *tp)
{
return &tp->touches[min(tp->slot, tp->ntouches - 1)];
}
static inline struct tp_touch *
tp_get_touch(struct tp_dispatch *tp, unsigned int slot)
{
assert(slot < tp->ntouches);
return &tp->touches[slot];
}
static inline unsigned int
tp_fake_finger_count(struct tp_dispatch *tp)
{
unsigned int fake_touches =
tp->fake_touches & ~(FAKE_FINGER_OVERFLOW|0x1);
/* Only one of BTN_TOOL_DOUBLETAP/TRIPLETAP/... may be set at any
* time */
if (fake_touches & (fake_touches - 1))
evdev_log_bug_kernel(tp->device,
"Invalid fake finger state %#x\n",
tp->fake_touches);
if (tp->fake_touches & FAKE_FINGER_OVERFLOW)
return FAKE_FINGER_OVERFLOW;
/* don't count BTN_TOUCH */
return ffs(tp->fake_touches >> 1);
}
static inline bool
tp_fake_finger_is_touching(struct tp_dispatch *tp)
{
return tp->fake_touches & 0x1;
}
static inline void
tp_fake_finger_set(struct tp_dispatch *tp,
unsigned int code,
bool is_press)
{
unsigned int shift;
switch (code) {
case BTN_TOUCH:
if (!is_press)
tp->fake_touches &= ~FAKE_FINGER_OVERFLOW;
shift = 0;
break;
case BTN_TOOL_FINGER:
shift = 1;
break;
case BTN_TOOL_DOUBLETAP:
case BTN_TOOL_TRIPLETAP:
case BTN_TOOL_QUADTAP:
shift = code - BTN_TOOL_DOUBLETAP + 2;
break;
/* when QUINTTAP is released we're either switching to 6 fingers
(flag stays in place until BTN_TOUCH is released) or
one of DOUBLE/TRIPLE/QUADTAP (will clear the flag on press) */
case BTN_TOOL_QUINTTAP:
if (is_press)
tp->fake_touches |= FAKE_FINGER_OVERFLOW;
return;
default:
return;
}
if (is_press) {
tp->fake_touches &= ~FAKE_FINGER_OVERFLOW;
tp->fake_touches |= bit(shift);
} else {
tp->fake_touches &= ~bit(shift);
}
}
static inline void
tp_new_touch(struct tp_dispatch *tp, struct tp_touch *t, uint64_t time)
{
if (t->state == TOUCH_BEGIN ||
t->state == TOUCH_UPDATE ||
t->state == TOUCH_HOVERING)
return;
/* Bug #161: touch ends in the same event frame where it restarts
again. That's a kernel bug, so let's complain. */
if (t->state == TOUCH_MAYBE_END) {
evdev_log_bug_kernel(tp->device,
"touch %d ended and began in in same frame.\n",
t->index);
tp->nfingers_down++;
t->state = TOUCH_UPDATE;
t->has_ended = false;
return;
}
/* we begin the touch as hovering because until BTN_TOUCH happens we
* don't know if it's a touch down or not. And BTN_TOUCH may happen
* after ABS_MT_TRACKING_ID */
tp_motion_history_reset(t);
t->dirty = true;
t->has_ended = false;
t->was_down = false;
t->palm.state = PALM_NONE;
t->state = TOUCH_HOVERING;
t->pinned.is_pinned = false;
t->speed.last_speed = 0;
t->speed.exceeded_count = 0;
t->hysteresis.x_motion_history = 0;
tp->queued |= TOUCHPAD_EVENT_MOTION;
}
static inline void
tp_begin_touch(struct tp_dispatch *tp, struct tp_touch *t, uint64_t time)
{
t->dirty = true;
t->state = TOUCH_BEGIN;
t->initial_time = time;
t->was_down = true;
tp->nfingers_down++;
t->palm.time = time;
t->tap.is_thumb = false;
t->tap.is_palm = false;
t->speed.exceeded_count = 0;
assert(tp->nfingers_down >= 1);
tp->hysteresis.last_motion_time = time;
}
/**
* Schedule a touch to be ended, based on either the events or some
* attributes of the touch (size, pressure). In some cases we need to
* resurrect a touch that has ended, so this doesn't actually end the touch
* yet. All the TOUCH_MAYBE_END touches get properly ended once the device
* state has been processed once and we know how many zombie touches we
* need.
*/
static inline void
tp_maybe_end_touch(struct tp_dispatch *tp,
struct tp_touch *t,
uint64_t time)
{
switch (t->state) {
case TOUCH_NONE:
case TOUCH_MAYBE_END:
return;
case TOUCH_END:
evdev_log_bug_libinput(tp->device,
"touch %d: already in TOUCH_END\n",
t->index);
return;
case TOUCH_HOVERING:
case TOUCH_BEGIN:
case TOUCH_UPDATE:
break;
}
if (t->state != TOUCH_HOVERING) {
assert(tp->nfingers_down >= 1);
tp->nfingers_down--;
t->state = TOUCH_MAYBE_END;
} else {
t->state = TOUCH_NONE;
}
t->dirty = true;
}
/**
* Inverse to tp_maybe_end_touch(), restores a touch back to its previous
* state.
*/
static inline void
tp_recover_ended_touch(struct tp_dispatch *tp,
struct tp_touch *t)
{
t->dirty = true;
t->state = TOUCH_UPDATE;
tp->nfingers_down++;
}
/**
* End a touch, even if the touch sequence is still active.
* Use tp_maybe_end_touch() instead.
*/
static inline void
tp_end_touch(struct tp_dispatch *tp, struct tp_touch *t, uint64_t time)
{
if (t->state != TOUCH_MAYBE_END) {
evdev_log_bug_libinput(tp->device,
"touch %d should be MAYBE_END, is %d\n",
t->index,
t->state);
return;
}
t->dirty = true;
t->palm.state = PALM_NONE;
t->state = TOUCH_END;
t->pinned.is_pinned = false;
t->palm.time = 0;
t->speed.exceeded_count = 0;
tp->queued |= TOUCHPAD_EVENT_MOTION;
}
/**
* End the touch sequence on ABS_MT_TRACKING_ID -1 or when the BTN_TOOL_* 0 is received.
*/
static inline void
tp_end_sequence(struct tp_dispatch *tp, struct tp_touch *t, uint64_t time)
{
t->has_ended = true;
tp_maybe_end_touch(tp, t, time);
}
static void
tp_stop_actions(struct tp_dispatch *tp, uint64_t time)
{
tp_edge_scroll_stop_events(tp, time);
tp_gesture_cancel(tp, time);
tp_tap_suspend(tp, time);
}
struct device_coords
tp_get_delta(struct tp_touch *t)
{
struct device_coords delta;
const struct device_coords zero = { 0.0, 0.0 };
if (t->history.count <= 1)
return zero;
delta.x = tp_motion_history_offset(t, 0)->point.x -
tp_motion_history_offset(t, 1)->point.x;
delta.y = tp_motion_history_offset(t, 0)->point.y -
tp_motion_history_offset(t, 1)->point.y;
return delta;
}
static inline int32_t
rotated(struct tp_dispatch *tp, unsigned int code, int value)
{
const struct input_absinfo *absinfo;
if (!tp->left_handed.rotate)
return value;
switch (code) {
case ABS_X:
case ABS_MT_POSITION_X:
absinfo = tp->device->abs.absinfo_x;
break;
case ABS_Y:
case ABS_MT_POSITION_Y:
absinfo = tp->device->abs.absinfo_y;
break;
default:
abort();
}
return absinfo->maximum - (value - absinfo->minimum);
}
static void
tp_process_absolute(struct tp_dispatch *tp,
const struct input_event *e,
uint64_t time)
{
struct tp_touch *t = tp_current_touch(tp);
switch(e->code) {
case ABS_MT_POSITION_X:
evdev_device_check_abs_axis_range(tp->device,
e->code,
e->value);
t->point.x = rotated(tp, e->code, e->value);
t->dirty = true;
tp->queued |= TOUCHPAD_EVENT_MOTION;
break;
case ABS_MT_POSITION_Y:
evdev_device_check_abs_axis_range(tp->device,
e->code,
e->value);
t->point.y = rotated(tp, e->code, e->value);
t->dirty = true;
tp->queued |= TOUCHPAD_EVENT_MOTION;
break;
case ABS_MT_SLOT:
tp->slot = e->value;
break;
case ABS_MT_TRACKING_ID:
if (e->value != -1) {
tp->nactive_slots += 1;
tp_new_touch(tp, t, time);
} else if (tp->nactive_slots >= 1) {
tp->nactive_slots -= 1;
tp_end_sequence(tp, t, time);
}
break;
case ABS_MT_PRESSURE:
t->pressure = e->value;
t->dirty = true;
tp->queued |= TOUCHPAD_EVENT_OTHERAXIS;
break;
case ABS_MT_TOOL_TYPE:
t->is_tool_palm = e->value == MT_TOOL_PALM;
t->dirty = true;
tp->queued |= TOUCHPAD_EVENT_OTHERAXIS;
break;
case ABS_MT_TOUCH_MAJOR:
t->major = e->value;
t->dirty = true;
tp->queued |= TOUCHPAD_EVENT_OTHERAXIS;
break;
case ABS_MT_TOUCH_MINOR:
t->minor = e->value;
t->dirty = true;
tp->queued |= TOUCHPAD_EVENT_OTHERAXIS;
break;
}
}
static void
tp_process_absolute_st(struct tp_dispatch *tp,
const struct input_event *e,
uint64_t time)
{
struct tp_touch *t = tp_current_touch(tp);
switch(e->code) {
case ABS_X:
evdev_device_check_abs_axis_range(tp->device,
e->code,
e->value);
t->point.x = rotated(tp, e->code, e->value);
t->dirty = true;
tp->queued |= TOUCHPAD_EVENT_MOTION;
break;
case ABS_Y:
evdev_device_check_abs_axis_range(tp->device,
e->code,
e->value);
t->point.y = rotated(tp, e->code, e->value);
t->dirty = true;
tp->queued |= TOUCHPAD_EVENT_MOTION;
break;
case ABS_PRESSURE:
t->pressure = e->value;
t->dirty = true;
tp->queued |= TOUCHPAD_EVENT_OTHERAXIS;
break;
}
}
static inline void
tp_restore_synaptics_touches(struct tp_dispatch *tp,
uint64_t time)
{
unsigned int i;
unsigned int nfake_touches;
nfake_touches = tp_fake_finger_count(tp);
if (nfake_touches < 3)
return;
if (tp->nfingers_down >= nfake_touches ||
(tp->nfingers_down == tp->num_slots && nfake_touches == tp->num_slots))
return;
/* Synaptics devices may end touch 2 on transition to/from
* BTN_TOOL_TRIPLETAP and start it again on the next frame with
* different coordinates (bz#91352, gitlab#434). We search the
* touches we have, if there is one that has just ended despite us
* being on tripletap, we move it back to update.
*
* Note: we only handle the transition from 2 to 3 touches, not the
* other way round (see gitlab#434)
*/
for (i = 0; i < tp->num_slots; i++) {
struct tp_touch *t = tp_get_touch(tp, i);
if (t->state != TOUCH_MAYBE_END)
continue;
/* new touch, move it through begin to update immediately */
tp_recover_ended_touch(tp, t);
}
}
static void
tp_process_fake_touches(struct tp_dispatch *tp,
uint64_t time)
{
struct tp_touch *t;
unsigned int nfake_touches;
unsigned int i, start;
nfake_touches = tp_fake_finger_count(tp);
if (nfake_touches == FAKE_FINGER_OVERFLOW)
return;
if (tp->device->model_flags &
EVDEV_MODEL_SYNAPTICS_SERIAL_TOUCHPAD)
tp_restore_synaptics_touches(tp, time);
/* ALPS serial touchpads always set 3 slots in the kernel, even
* where they support less than that. So we get BTN_TOOL_TRIPLETAP
* but never slot 2 because our slot count is wrong.
* This also means that the third touch falls through the cracks and
* is ignored.
*
* See https://gitlab.freedesktop.org/libinput/libinput/issues/408
*
* All touchpad devices have at least one slot so we only do this
* for 2 touches or higher.
*
* There's an bug in libevdev < 1.9.0 affecting slots after a
* SYN_DROPPED. Where a user release one or more touches during
* SYN_DROPPED and places new ones on the touchpad, we may end up
* with fake touches but no active slots.
* So let's check for nactive_slots > 0 to make sure we don't lose
* all fingers. That's a workaround only, this must be fixed in
* libevdev.
*
* For a long explanation of what happens, see
* https://gitlab.freedesktop.org/libevdev/libevdev/merge_requests/19
*/
if (tp->device->model_flags & EVDEV_MODEL_ALPS_SERIAL_TOUCHPAD &&
nfake_touches > 1 && tp->has_mt &&
tp->nactive_slots > 0 &&
nfake_touches > tp->nactive_slots &&
tp->nactive_slots < tp->num_slots) {
evdev_log_bug_kernel(tp->device,
"Wrong slot count (%d), reducing to %d\n",
tp->num_slots,
tp->nactive_slots);
/* This should be safe since we fill the slots from the
* first one so hiding the excessive slots shouldn't matter.
* There are sequences where we could accidentally lose an
* actual touch point but that requires specially crafted
* sequences and let's deal with that when it happens.
*/
tp->num_slots = tp->nactive_slots;
}
start = tp->has_mt ? tp->num_slots : 0;
for (i = start; i < tp->ntouches; i++) {
t = tp_get_touch(tp, i);
if (i < nfake_touches)
tp_new_touch(tp, t, time);
else
tp_end_sequence(tp, t, time);
}
}
static void
tp_process_trackpoint_button(struct tp_dispatch *tp,
const struct input_event *e,
uint64_t time)
{
struct evdev_dispatch *dispatch;
struct input_event event;
struct input_event syn_report = {
.input_event_sec = 0,
.input_event_usec = 0,
.type = EV_SYN,
.code = SYN_REPORT,
.value = 0
};
if (!tp->buttons.trackpoint)
return;
dispatch = tp->buttons.trackpoint->dispatch;
event = *e;
syn_report.input_event_sec = e->input_event_sec;
syn_report.input_event_usec = e->input_event_usec;
switch (event.code) {
case BTN_0:
event.code = BTN_LEFT;
break;
case BTN_1:
event.code = BTN_RIGHT;
break;
case BTN_2:
event.code = BTN_MIDDLE;
break;
default:
return;
}
dispatch->interface->process(dispatch,
tp->buttons.trackpoint,
&event, time);
dispatch->interface->process(dispatch,
tp->buttons.trackpoint,
&syn_report, time);
}
static void
tp_process_key(struct tp_dispatch *tp,
const struct input_event *e,
uint64_t time)
{
/* ignore kernel key repeat */
if (e->value == 2)
return;
switch (e->code) {
case BTN_LEFT:
case BTN_MIDDLE:
case BTN_RIGHT:
tp_process_button(tp, e, time);
break;
case BTN_TOUCH:
case BTN_TOOL_FINGER:
case BTN_TOOL_DOUBLETAP:
case BTN_TOOL_TRIPLETAP:
case BTN_TOOL_QUADTAP:
case BTN_TOOL_QUINTTAP:
tp_fake_finger_set(tp, e->code, !!e->value);
break;
case BTN_0:
case BTN_1:
case BTN_2:
tp_process_trackpoint_button(tp, e, time);
break;
}
}
static void
tp_process_msc(struct tp_dispatch *tp,
const struct input_event *e,
uint64_t time)
{
if (e->code != MSC_TIMESTAMP)
return;
tp->quirks.msc_timestamp.now = e->value;
tp->queued |= TOUCHPAD_EVENT_TIMESTAMP;
}
static void
tp_unpin_finger(const struct tp_dispatch *tp, struct tp_touch *t)
{
struct phys_coords mm;
struct device_coords delta;
if (!t->pinned.is_pinned)
return;
delta.x = abs(t->point.x - t->pinned.center.x);
delta.y = abs(t->point.y - t->pinned.center.y);
mm = evdev_device_unit_delta_to_mm(tp->device, &delta);
/* 1.5mm movement -> unpin */
if (hypot(mm.x, mm.y) >= 1.5) {
t->pinned.is_pinned = false;
return;
}
}
static void
tp_pin_fingers(struct tp_dispatch *tp)
{
struct tp_touch *t;
tp_for_each_touch(tp, t) {
t->pinned.is_pinned = true;
t->pinned.center = t->point;
}
}
bool
tp_touch_active(const struct tp_dispatch *tp, const struct tp_touch *t)
{
return (t->state == TOUCH_BEGIN || t->state == TOUCH_UPDATE) &&
t->palm.state == PALM_NONE &&
!t->pinned.is_pinned &&
!tp_thumb_ignored(tp, t) &&
tp_button_touch_active(tp, t) &&
tp_edge_scroll_touch_active(tp, t);
}
bool
tp_touch_active_for_gesture(const struct tp_dispatch *tp, const struct tp_touch *t)
{
return (t->state == TOUCH_BEGIN || t->state == TOUCH_UPDATE) &&
t->palm.state == PALM_NONE &&
!t->pinned.is_pinned &&
!tp_thumb_ignored_for_gesture(tp, t) &&
tp_button_touch_active(tp, t) &&
tp_edge_scroll_touch_active(tp, t);
}
static inline bool
tp_palm_was_in_side_edge(const struct tp_dispatch *tp, const struct tp_touch *t)
{
return t->palm.first.x < tp->palm.left_edge ||
t->palm.first.x > tp->palm.right_edge;
}
static inline bool
tp_palm_was_in_top_edge(const struct tp_dispatch *tp, const struct tp_touch *t)
{
return t->palm.first.y < tp->palm.upper_edge;
}
static inline bool
tp_palm_in_side_edge(const struct tp_dispatch *tp, const struct tp_touch *t)
{
return t->point.x < tp->palm.left_edge ||
t->point.x > tp->palm.right_edge;
}
static inline bool
tp_palm_in_top_edge(const struct tp_dispatch *tp, const struct tp_touch *t)
{
return t->point.y < tp->palm.upper_edge;
}
static inline bool
tp_palm_in_edge(const struct tp_dispatch *tp, const struct tp_touch *t)
{
return tp_palm_in_side_edge(tp, t) || tp_palm_in_top_edge(tp, t);
}
static bool
tp_palm_detect_dwt_triggered(struct tp_dispatch *tp,
struct tp_touch *t,
uint64_t time)
{
if (tp->dwt.dwt_enabled &&
tp->dwt.keyboard_active &&
t->state == TOUCH_BEGIN) {
t->palm.state = PALM_TYPING;
t->palm.first = t->point;
return true;
}
if (!tp->dwt.keyboard_active &&
t->state == TOUCH_UPDATE &&
t->palm.state == PALM_TYPING) {
/* If a touch has started before the first or after the last
key press, release it on timeout. Benefit: a palm rested
while typing on the touchpad will be ignored, but a touch
started once we stop typing will be able to control the
pointer (alas not tap, etc.).
*/
if (t->palm.time == 0 ||
t->palm.time > tp->dwt.keyboard_last_press_time) {
t->palm.state = PALM_NONE;
evdev_log_debug(tp->device,
"palm: touch %d released, timeout after typing\n",
t->index);
}
}
return false;
}
static bool
tp_palm_detect_trackpoint_triggered(struct tp_dispatch *tp,
struct tp_touch *t,
uint64_t time)
{
if (!tp->palm.monitor_trackpoint)
return false;
if (t->palm.state == PALM_NONE &&
t->state == TOUCH_BEGIN &&
tp->palm.trackpoint_active) {
t->palm.state = PALM_TRACKPOINT;
return true;
}
if (t->palm.state == PALM_TRACKPOINT &&
t->state == TOUCH_UPDATE &&
!tp->palm.trackpoint_active) {
if (t->palm.time == 0 ||
t->palm.time > tp->palm.trackpoint_last_event_time) {
t->palm.state = PALM_NONE;
evdev_log_debug(tp->device,
"palm: touch %d released, timeout after trackpoint\n", t->index);
}
}
return false;
}
static bool
tp_palm_detect_tool_triggered(struct tp_dispatch *tp,
struct tp_touch *t,
uint64_t time)
{
if (!tp->palm.use_mt_tool)
return false;
if (t->palm.state != PALM_NONE &&
t->palm.state != PALM_TOOL_PALM)
return false;
if (t->palm.state == PALM_NONE &&
t->is_tool_palm)
t->palm.state = PALM_TOOL_PALM;
else if (t->palm.state == PALM_TOOL_PALM &&
!t->is_tool_palm)
t->palm.state = PALM_NONE;
return t->palm.state == PALM_TOOL_PALM;
}
static inline bool
tp_palm_detect_move_out_of_edge(struct tp_dispatch *tp,
struct tp_touch *t,
uint64_t time)
{
const int PALM_TIMEOUT = ms2us(200);
int directions = 0;
struct device_float_coords delta;
int dirs;
if (time < t->palm.time + PALM_TIMEOUT && !tp_palm_in_edge(tp, t)) {
if (tp_palm_was_in_side_edge(tp, t))
directions = NE|E|SE|SW|W|NW;
else if (tp_palm_was_in_top_edge(tp, t))
directions = S|SE|SW;
if (directions) {
delta = device_delta(t->point, t->palm.first);
dirs = phys_get_direction(tp_phys_delta(tp, delta));
if ((dirs & directions) && !(dirs & ~directions))
return true;
}
}
return false;
}
static inline bool
tp_palm_detect_multifinger(struct tp_dispatch *tp, struct tp_touch *t, uint64_t time)
{
struct tp_touch *other;
if (tp->nfingers_down < 2)
return false;
/* If we have at least one other active non-palm touch make this
* touch non-palm too. This avoids palm detection during two-finger
* scrolling.
*
* Note: if both touches start in the palm zone within the same
* frame the second touch will still be PALM_NONE and thus detected
* here as non-palm touch. This is too niche to worry about for now.
*/
tp_for_each_touch(tp, other) {
if (other == t)
continue;
if (tp_touch_active(tp, other) &&
other->palm.state == PALM_NONE) {
return true;
}
}
return false;
}
static inline bool
tp_palm_detect_touch_size_triggered(struct tp_dispatch *tp,
struct tp_touch *t,
uint64_t time)
{
if (!tp->palm.use_size)
return false;
/* If a finger size is large enough for palm, we stick with that and
* force the user to release and reset the finger */
if (t->palm.state != PALM_NONE && t->palm.state != PALM_TOUCH_SIZE)
return false;
if (t->major > tp->palm.size_threshold ||
t->minor > tp->palm.size_threshold) {
if (t->palm.state != PALM_TOUCH_SIZE)
evdev_log_debug(tp->device,
"palm: touch %d size exceeded\n",
t->index);
t->palm.state = PALM_TOUCH_SIZE;
return true;
}
return false;
}
static inline bool
tp_palm_detect_edge(struct tp_dispatch *tp,
struct tp_touch *t,
uint64_t time)
{
if (t->palm.state == PALM_EDGE) {
if (tp_palm_detect_multifinger(tp, t, time)) {
t->palm.state = PALM_NONE;
evdev_log_debug(tp->device,
"palm: touch %d released, multiple fingers\n",
t->index);
/* If labelled a touch as palm, we unlabel as palm when
we move out of the palm edge zone within the timeout, provided
the direction is within 45 degrees of the horizontal.
*/
} else if (tp_palm_detect_move_out_of_edge(tp, t, time)) {
t->palm.state = PALM_NONE;
evdev_log_debug(tp->device,
"palm: touch %d released, out of edge zone\n",
t->index);
}
return false;
}
if (tp_palm_detect_multifinger(tp, t, time)) {
return false;
}
/* palm must start in exclusion zone, it's ok to move into
the zone without being a palm */
if (t->state != TOUCH_BEGIN || !tp_palm_in_edge(tp, t))
return false;
if (tp_touch_get_edge(tp, t) & EDGE_RIGHT)
return false;
t->palm.state = PALM_EDGE;
t->palm.time = time;
t->palm.first = t->point;
return true;
}
static bool
tp_palm_detect_pressure_triggered(struct tp_dispatch *tp,
struct tp_touch *t,
uint64_t time)
{
if (!tp->palm.use_pressure)
return false;
if (t->palm.state != PALM_NONE &&
t->palm.state != PALM_PRESSURE)
return false;
if (t->pressure > tp->palm.pressure_threshold)
t->palm.state = PALM_PRESSURE;
return t->palm.state == PALM_PRESSURE;
}
static bool
tp_palm_detect_arbitration_triggered(struct tp_dispatch *tp,
struct tp_touch *t,
uint64_t time)
{
if (tp->arbitration.state == ARBITRATION_NOT_ACTIVE)
return false;
t->palm.state = PALM_ARBITRATION;
return true;
}
static void
tp_palm_detect(struct tp_dispatch *tp, struct tp_touch *t, uint64_t time)
{
const char *palm_state;
enum touch_palm_state oldstate = t->palm.state;
if (tp_palm_detect_pressure_triggered(tp, t, time))
goto out;
if (tp_palm_detect_arbitration_triggered(tp, t, time))
goto out;
if (tp_palm_detect_dwt_triggered(tp, t, time))
goto out;
if (tp_palm_detect_trackpoint_triggered(tp, t, time))
goto out;
if (tp_palm_detect_tool_triggered(tp, t, time))
goto out;
if (tp_palm_detect_touch_size_triggered(tp, t, time))
goto out;
if (tp_palm_detect_edge(tp, t, time))
goto out;
/* Pressure is highest priority because it cannot be released and
* overrides all other checks. So we check once before anything else
* in case pressure triggers on a non-palm touch. And again after
* everything in case one of the others released but we have a
* pressure trigger now.
*/
if (tp_palm_detect_pressure_triggered(tp, t, time))
goto out;
return;
out:
if (oldstate == t->palm.state)
return;
switch (t->palm.state) {
case PALM_EDGE:
palm_state = "edge";
break;
case PALM_TYPING:
palm_state = "typing";
break;
case PALM_TRACKPOINT:
palm_state = "trackpoint";
break;
case PALM_TOOL_PALM:
palm_state = "tool-palm";
break;
case PALM_PRESSURE:
palm_state = "pressure";
break;
case PALM_TOUCH_SIZE:
palm_state = "touch size";
break;
case PALM_ARBITRATION:
palm_state = "arbitration";
break;
case PALM_NONE:
default:
abort();
break;
}
evdev_log_debug(tp->device,
"palm: touch %d (%s), palm detected (%s)\n",
t->index,
touch_state_to_str(t->state),
palm_state);
}
static void
tp_unhover_pressure(struct tp_dispatch *tp, uint64_t time)
{
struct tp_touch *t;
int i;
unsigned int nfake_touches;
unsigned int real_fingers_down = 0;
nfake_touches = tp_fake_finger_count(tp);
if (nfake_touches == FAKE_FINGER_OVERFLOW)
nfake_touches = 0;
for (i = 0; i < (int)tp->num_slots; i++) {
t = tp_get_touch(tp, i);
if (t->state == TOUCH_NONE)
continue;
if (t->dirty) {
if (t->state == TOUCH_HOVERING) {
if (t->pressure >= tp->pressure.high) {
evdev_log_debug(tp->device,
"pressure: begin touch %d\n",
t->index);
/* avoid jumps when landing a finger */
tp_motion_history_reset(t);
tp_begin_touch(tp, t, time);
}
/* don't unhover for pressure if we have too many
* fake fingers down, see comment below. Except
* for single-finger touches where the real touch
* decides for the rest.
*/
} else if (nfake_touches <= tp->num_slots ||
tp->num_slots == 1) {
if (t->pressure < tp->pressure.low) {
evdev_log_debug(tp->device,
"pressure: end touch %d\n",
t->index);
tp_maybe_end_touch(tp, t, time);
}
}
}
if (t->state == TOUCH_BEGIN ||
t->state == TOUCH_UPDATE)
real_fingers_down++;
}
if (nfake_touches <= tp->num_slots ||
tp->nfingers_down == 0)
return;
/* if we have more fake fingers down than slots, we assume
* _all_ fingers have enough pressure, even if some of the slotted
* ones don't. Anything else gets insane quickly.
*/
if (real_fingers_down > 0) {
tp_for_each_touch(tp, t) {
if (t->state == TOUCH_HOVERING) {
/* avoid jumps when landing a finger */
tp_motion_history_reset(t);
tp_begin_touch(tp, t, time);
if (tp->nfingers_down >= nfake_touches)
break;
}
}
}
if (tp->nfingers_down > nfake_touches ||
real_fingers_down == 0) {
for (i = tp->ntouches - 1; i >= 0; i--) {
t = tp_get_touch(tp, i);
if (t->state == TOUCH_HOVERING ||
t->state == TOUCH_NONE ||
t->state == TOUCH_MAYBE_END)
continue;
tp_maybe_end_touch(tp, t, time);
if (real_fingers_down > 0 &&
tp->nfingers_down == nfake_touches)
break;
}
}
}
static void
tp_unhover_size(struct tp_dispatch *tp, uint64_t time)
{
struct tp_touch *t;
int low = tp->touch_size.low,
high = tp->touch_size.high;
int i;
/* We require 5 slots for size handling, so we don't need to care
* about fake touches here */
for (i = 0; i < (int)tp->num_slots; i++) {
t = tp_get_touch(tp, i);
if (t->state == TOUCH_NONE)
continue;
if (!t->dirty)
continue;
if (t->state == TOUCH_HOVERING) {
if ((t->major > high && t->minor > low) ||
(t->major > low && t->minor > high)) {
evdev_log_debug(tp->device,
"touch-size: begin touch %d\n",
t->index);
/* avoid jumps when landing a finger */
tp_motion_history_reset(t);
tp_begin_touch(tp, t, time);
}
} else {
if (t->major < low || t->minor < low) {
evdev_log_debug(tp->device,
"touch-size: end touch %d\n",
t->index);
tp_maybe_end_touch(tp, t, time);
}
}
}
}
static void
tp_unhover_fake_touches(struct tp_dispatch *tp, uint64_t time)
{
struct tp_touch *t;
unsigned int nfake_touches;
int i;
if (!tp->fake_touches && !tp->nfingers_down)
return;
nfake_touches = tp_fake_finger_count(tp);
if (nfake_touches == FAKE_FINGER_OVERFLOW)
return;
if (tp->nfingers_down == nfake_touches &&
((tp->nfingers_down == 0 && !tp_fake_finger_is_touching(tp)) ||
(tp->nfingers_down > 0 && tp_fake_finger_is_touching(tp))))
return;
/* if BTN_TOUCH is set and we have less fingers down than fake
* touches, switch each hovering touch to BEGIN
* until nfingers_down matches nfake_touches
*/
if (tp_fake_finger_is_touching(tp) &&
tp->nfingers_down < nfake_touches) {
tp_for_each_touch(tp, t) {
if (t->state == TOUCH_HOVERING) {
tp_begin_touch(tp, t, time);
if (tp->nfingers_down >= nfake_touches)
break;
}
}
}
/* if BTN_TOUCH is unset end all touches, we're hovering now. If we
* have too many touches also end some of them. This is done in
* reverse order.
*/
if (tp->nfingers_down > nfake_touches ||
!tp_fake_finger_is_touching(tp)) {
for (i = tp->ntouches - 1; i >= 0; i--) {
t = tp_get_touch(tp, i);
if (t->state == TOUCH_HOVERING ||
t->state == TOUCH_NONE)
continue;
tp_maybe_end_touch(tp, t, time);
if (tp_fake_finger_is_touching(tp) &&
tp->nfingers_down == nfake_touches)
break;
}
}
}
static void
tp_unhover_touches(struct tp_dispatch *tp, uint64_t time)
{
if (tp->pressure.use_pressure)
tp_unhover_pressure(tp, time);
else if (tp->touch_size.use_touch_size)
tp_unhover_size(tp, time);
else
tp_unhover_fake_touches(tp, time);
}
static inline void
tp_position_fake_touches(struct tp_dispatch *tp)
{
struct tp_touch *t;
struct tp_touch *topmost = NULL;
unsigned int start, i;
if (tp_fake_finger_count(tp) <= tp->num_slots ||
tp->nfingers_down == 0)
return;
/* We have at least one fake touch down. Find the top-most real
* touch and copy its coordinates over to to all fake touches.
* This is more reliable than just taking the first touch.
*/
for (i = 0; i < tp->num_slots; i++) {
t = tp_get_touch(tp, i);
if (t->state == TOUCH_END ||
t->state == TOUCH_NONE)
continue;
if (topmost == NULL || t->point.y < topmost->point.y)
topmost = t;
}
if (!topmost) {
evdev_log_bug_libinput(tp->device,
"Unable to find topmost touch\n");
return;
}
start = tp->has_mt ? tp->num_slots : 1;
for (i = start; i < tp->ntouches; i++) {
t = tp_get_touch(tp, i);
if (t->state == TOUCH_NONE)
continue;
t->point = topmost->point;
t->pressure = topmost->pressure;
if (!t->dirty)
t->dirty = topmost->dirty;
}
}
static inline bool
tp_need_motion_history_reset(struct tp_dispatch *tp)
{
bool rc = false;
/* Changing the numbers of fingers can cause a jump in the
* coordinates, always reset the motion history for all touches when
* that happens.
*/
if (tp->nfingers_down != tp->old_nfingers_down)
return true;
/* Quirk: if we had multiple events without x/y axis
information, the next x/y event is going to be a jump. So we
reset that touch to non-dirty effectively swallowing that event
and restarting with the next event again.
*/
if (tp->device->model_flags & EVDEV_MODEL_LENOVO_T450_TOUCHPAD) {
if (tp->queued & TOUCHPAD_EVENT_MOTION) {
if (tp->quirks.nonmotion_event_count > 10) {
tp->queued &= ~TOUCHPAD_EVENT_MOTION;
rc = true;
}
tp->quirks.nonmotion_event_count = 0;
}
if ((tp->queued & (TOUCHPAD_EVENT_OTHERAXIS|TOUCHPAD_EVENT_MOTION)) ==
TOUCHPAD_EVENT_OTHERAXIS)
tp->quirks.nonmotion_event_count++;
}
return rc;
}
static bool
tp_detect_jumps(const struct tp_dispatch *tp,
struct tp_touch *t,
uint64_t time)
{
struct device_coords delta;
struct phys_coords mm;
struct tp_history_point *last;
double abs_distance, rel_distance;
bool is_jump = false;
uint64_t tdelta;
/* Reference interval from the touchpad the various thresholds
* were measured from */
unsigned int reference_interval = ms2us(12);
/* On some touchpads the firmware does funky stuff and we cannot
* have our own jump detection, e.g. Lenovo Carbon X1 Gen 6 (see
* issue #506)
*/
if (tp->jump.detection_disabled)
return false;
/* We haven't seen pointer jumps on Wacom tablets yet, so exclude
* those.
*/
if (tp->device->model_flags & EVDEV_MODEL_WACOM_TOUCHPAD)
return false;
if (t->history.count == 0) {
t->jumps.last_delta_mm = 0.0;
return false;
}
/* called before tp_motion_history_push, so offset 0 is the most
* recent coordinate */
last = tp_motion_history_offset(t, 0);
tdelta = time - last->time;
/* For test devices we always force the time delta to 12, at least
until the test suite actually does proper intervals. */
if (tp->device->model_flags & EVDEV_MODEL_TEST_DEVICE)
reference_interval = tdelta;
/* If the last frame is more than 30ms ago, we have irregular
* frames, who knows what's a pointer jump here and what's
* legitimate movement.... */
if (tdelta > 2.5 * reference_interval || tdelta == 0)
return false;
/* We historically expected ~12ms frame intervals, so the numbers
below are normalized to that (and that's also where the
measured data came from) */
delta.x = abs(t->point.x - last->point.x);
delta.y = abs(t->point.y - last->point.y);
mm = evdev_device_unit_delta_to_mm(tp->device, &delta);
abs_distance = hypot(mm.x, mm.y) * reference_interval/tdelta;
rel_distance = abs_distance - t->jumps.last_delta_mm;
/* Special case for the ALPS devices in the Lenovo ThinkPad E465,
* E550. These devices send occasional 4095/0 events on two fingers
* before snapping back to the correct position.
* https://gitlab.freedesktop.org/libinput/libinput/-/issues/492
* The specific values are hardcoded here, if this ever happens on
* any other device we can make it absmax/absmin instead.
*/
if (tp->device->model_flags & EVDEV_MODEL_ALPS_SERIAL_TOUCHPAD &&
t->point.x == 4095 && t->point.y == 0) {
t->point = last->point;
return true;
}
/* Cursor jump if:
* - current single-event delta is >20mm, or
* - we increased the delta by over 7mm within a 12ms frame.
* (12ms simply because that's what I measured)
*/
is_jump = abs_distance > 20.0 || rel_distance > 7;
t->jumps.last_delta_mm = abs_distance;
return is_jump;
}
/**
* Rewrite the motion history so that previous points' timestamps are the
* current point's timestamp minus whatever MSC_TIMESTAMP gives us.
*
* This must be called before tp_motion_history_push()
*
* @param t The touch point
* @param jumping_interval The large time interval in µs
* @param normal_interval Normal hw interval in µs
* @param time Current time in µs
*/
static inline void
tp_motion_history_fix_last(struct tp_dispatch *tp,
struct tp_touch *t,
unsigned int jumping_interval,
unsigned int normal_interval,
uint64_t time)
{
if (t->state != TOUCH_UPDATE)
return;
/* We know the coordinates are correct because the touchpad should
* get that bit right. But the timestamps we got from the kernel are
* messed up, so we go back in the history and fix them.
*
* This way the next delta is huge but it's over a large time, so
* the pointer accel code should do the right thing.
*/
for (int i = 0; i < (int)t->history.count; i++) {
struct tp_history_point *p;
p = tp_motion_history_offset(t, i);
p->time = time - jumping_interval - normal_interval * i;
}
}
static void
tp_process_msc_timestamp(struct tp_dispatch *tp, uint64_t time)
{
struct msc_timestamp *m = &tp->quirks.msc_timestamp;
/* Pointer jump detection based on MSC_TIMESTAMP.
MSC_TIMESTAMP gets reset after a kernel timeout (1s) and on some
devices (Dell XPS) the i2c controller sleeps after a timeout. On
wakeup, some events are swallowed, triggering a cursor jump. The
event sequence after a sleep is always:
initial finger down:
ABS_X/Y x/y
MSC_TIMESTAMP 0
SYN_REPORT +2500ms
second event:
ABS_X/Y x+n/y+n # normal movement
MSC_TIMESTAMP 7300 # the hw interval
SYN_REPORT +2ms
third event:
ABS_X/Y x+lots/y+lots # pointer jump!
MSC_TIMESTAMP 123456 # well above the hw interval
SYN_REPORT +2ms
fourth event:
ABS_X/Y x+lots+n/y+lots+n # all normal again
MSC_TIMESTAMP 123456 + 7300
SYN_REPORT +8ms
Our approach is to detect the 0 timestamp, check the interval on
the next event and then calculate the movement for one fictitious
event instead, swallowing all other movements. So if the time
delta is equivalent to 10 events and the movement is x, we
instead pretend there was movement of x/10.
*/
if (m->now == 0) {
m->state = JUMP_STATE_EXPECT_FIRST;
m->interval = 0;
return;
}
switch(m->state) {
case JUMP_STATE_EXPECT_FIRST:
if (m->now > ms2us(20)) {
m->state = JUMP_STATE_IGNORE;
} else {
m->state = JUMP_STATE_EXPECT_DELAY;
m->interval = m->now;
}
break;
case JUMP_STATE_EXPECT_DELAY:
if (m->now > m->interval * 2) {
uint32_t tdelta; /* µs */
struct tp_touch *t;
/* The current time is > 2 times the interval so we
* have a jump. Fix the motion history */
tdelta = m->now - m->interval;
tp_for_each_touch(tp, t) {
tp_motion_history_fix_last(tp,
t,
tdelta,
m->interval,
time);
}
m->state = JUMP_STATE_IGNORE;
/* We need to restart the acceleration filter to forget its history.
* The current point becomes the first point in the history there
* (including timestamp) and that accelerates correctly.
* This has a potential to be incorrect but since we only ever see
* those jumps over the first three events it doesn't matter.
*/
filter_restart(tp->device->pointer.filter, tp, time - tdelta);
}
break;
case JUMP_STATE_IGNORE:
break;
}
}
static void
tp_pre_process_state(struct tp_dispatch *tp, uint64_t time)
{
struct tp_touch *t;
if (tp->queued & TOUCHPAD_EVENT_TIMESTAMP)
tp_process_msc_timestamp(tp, time);
tp_process_fake_touches(tp, time);
tp_unhover_touches(tp, time);
tp_for_each_touch(tp, t) {
if (t->state == TOUCH_MAYBE_END)
tp_end_touch(tp, t, time);
/* Ignore motion when pressure/touch size fell below the
* threshold, thus ending the touch */
if (t->state == TOUCH_END && t->history.count > 0)
t->point = tp_motion_history_offset(t, 0)->point;
}
}
static void
tp_process_state(struct tp_dispatch *tp, uint64_t time)
{
struct tp_touch *t;
bool restart_filter = false;
bool want_motion_reset;
bool have_new_touch = false;
unsigned int speed_exceeded_count = 0;
tp_position_fake_touches(tp);
want_motion_reset = tp_need_motion_history_reset(tp);
tp_for_each_touch(tp, t) {
if (t->state == TOUCH_NONE)
continue;
if (want_motion_reset) {
tp_motion_history_reset(t);
t->quirks.reset_motion_history = true;
} else if (t->quirks.reset_motion_history) {
tp_motion_history_reset(t);
t->quirks.reset_motion_history = false;
}
if (!t->dirty) {
/* A non-dirty touch must be below the speed limit */
if (t->speed.exceeded_count > 0)
t->speed.exceeded_count--;
speed_exceeded_count = max(speed_exceeded_count,
t->speed.exceeded_count);
/* A touch that hasn't moved must be in the same
* position, so let's add this to the motion
* history.
*/
tp_motion_history_push(t, time);
continue;
}
if (tp_detect_jumps(tp, t, time)) {
if (!tp->semi_mt)
evdev_log_bug_kernel_ratelimit(tp->device,
&tp->jump.warning,
"Touch jump detected and discarded.\n"
"See %s/touchpad-jumping-cursors.html for details\n",
HTTP_DOC_LINK);
tp_motion_history_reset(t);
}
tp_thumb_update_touch(tp, t, time);
tp_palm_detect(tp, t, time);
tp_detect_wobbling(tp, t, time);
tp_motion_hysteresis(tp, t);
tp_motion_history_push(t, time);
/* Touch speed handling: if we'are above the threshold,
* count each event that we're over the threshold up to 10
* events. Count down when we are below the speed.
*
* Take the touch with the highest speed excess, if it is
* above a certain threshold (5, see below), assume a
* dropped finger is a thumb.
*
* Yes, this relies on the touchpad to keep sending us
* events even if the finger doesn't move, otherwise we
* never count down. Let's see how far we get with that.
*/
if (t->speed.last_speed > THUMB_IGNORE_SPEED_THRESHOLD) {
if (t->speed.exceeded_count < 15)
t->speed.exceeded_count++;
} else if (t->speed.exceeded_count > 0) {
t->speed.exceeded_count--;
}
speed_exceeded_count = max(speed_exceeded_count,
t->speed.exceeded_count);
tp_calculate_motion_speed(tp, t, time);
tp_unpin_finger(tp, t);
if (t->state == TOUCH_BEGIN) {
have_new_touch = true;
restart_filter = true;
}
}
if (tp->thumb.detect_thumbs &&
have_new_touch &&
tp->nfingers_down >= 2)
tp_thumb_update_multifinger(tp);
if (restart_filter)
filter_restart(tp->device->pointer.filter, tp, time);
tp_button_handle_state(tp, time);
tp_edge_scroll_handle_state(tp, time);
/*
* We have a physical button down event on a clickpad. To avoid
* spurious pointer moves by the clicking finger we pin all fingers.
* We unpin fingers when they move more then a certain threshold to
* to allow drag and drop.
*/
if ((tp->queued & TOUCHPAD_EVENT_BUTTON_PRESS) &&
tp->buttons.is_clickpad)
tp_pin_fingers(tp);
tp_gesture_update_finger_state(tp, time);
}
static void
tp_post_process_state(struct tp_dispatch *tp, uint64_t time)
{
struct tp_touch *t;
tp_for_each_touch(tp, t) {
if (!t->dirty)
continue;
if (t->state == TOUCH_END) {
if (t->has_ended)
t->state = TOUCH_NONE;
else
t->state = TOUCH_HOVERING;
} else if (t->state == TOUCH_BEGIN) {
t->state = TOUCH_UPDATE;
}
t->dirty = false;
}
tp->old_nfingers_down = tp->nfingers_down;
tp->buttons.old_state = tp->buttons.state;
tp->queued = TOUCHPAD_EVENT_NONE;
if (tp->nfingers_down == 0)
tp_thumb_reset(tp);
tp_tap_post_process_state(tp);
tp_button_post_process_state(tp);
}
static void
tp_post_events(struct tp_dispatch *tp, uint64_t time)
{
bool ignore_motion = false;
/* Only post (top) button events while suspended */
if (tp->device->is_suspended) {
tp_post_button_events(tp, time);
return;
}
ignore_motion |= tp_tap_handle_state(tp, time);
ignore_motion |= tp_post_button_events(tp, time);
if (tp->palm.trackpoint_active || tp->dwt.keyboard_active) {
tp_edge_scroll_stop_events(tp, time);
tp_gesture_cancel(tp, time);
return;
}
if (ignore_motion) {
tp_edge_scroll_stop_events(tp, time);
tp_gesture_cancel_motion_gestures(tp, time);
tp_gesture_post_events(tp, time, true);
return;
}
if (tp_edge_scroll_post_events(tp, time) != 0)
return;
tp_gesture_post_events(tp, time, false);
}
static void
tp_apply_rotation(struct evdev_device *device)
{
struct tp_dispatch *tp = (struct tp_dispatch *)device->dispatch;
if (tp->left_handed.want_rotate == tp->left_handed.rotate)
return;
if (tp->nfingers_down)
return;
tp->left_handed.rotate = tp->left_handed.want_rotate;
evdev_log_debug(device,
"touchpad-rotation: rotation is %s\n",
tp->left_handed.rotate ? "on" : "off");
}
static void
tp_handle_state(struct tp_dispatch *tp,
uint64_t time)
{
tp_pre_process_state(tp, time);
tp_process_state(tp, time);
tp_post_events(tp, time);
tp_post_process_state(tp, time);
tp_clickpad_middlebutton_apply_config(tp->device);
tp_apply_rotation(tp->device);
tp_3fg_drag_apply_config(tp->device);
}
LIBINPUT_UNUSED
static inline void
tp_debug_touch_state(struct tp_dispatch *tp,
struct evdev_device *device)
{
char buf[1024] = {0};
struct tp_touch *t;
size_t i = 0;
tp_for_each_touch(tp, t) {
if (i >= tp->nfingers_down)
break;
sprintf(&buf[strlen(buf)],
"slot %zd: %04d/%04d p%03d %s |",
i++,
t->point.x,
t->point.y,
t->pressure,
tp_touch_active(tp, t) ? "" : "inactive");
}
if (buf[0] != '\0')
evdev_log_debug(device, "touch state: %s\n", buf);
}
static void
tp_interface_process(struct evdev_dispatch *dispatch,
struct evdev_device *device,
struct input_event *e,
uint64_t time)
{
struct tp_dispatch *tp = tp_dispatch(dispatch);
switch (e->type) {
case EV_ABS:
if (tp->has_mt)
tp_process_absolute(tp, e, time);
else
tp_process_absolute_st(tp, e, time);
break;
case EV_KEY:
tp_process_key(tp, e, time);
break;
case EV_MSC:
tp_process_msc(tp, e, time);
break;
case EV_SYN:
tp_handle_state(tp, time);
#if 0
tp_debug_touch_state(tp, device);
#endif
break;
}
}
static void
tp_remove_sendevents(struct tp_dispatch *tp)
{
struct evdev_paired_keyboard *kbd;
libinput_timer_cancel(&tp->palm.trackpoint_timer);
libinput_timer_cancel(&tp->dwt.keyboard_timer);
if (tp->buttons.trackpoint &&
tp->palm.monitor_trackpoint)
libinput_device_remove_event_listener(
&tp->palm.trackpoint_listener);
list_for_each(kbd, &tp->dwt.paired_keyboard_list, link) {
libinput_device_remove_event_listener(&kbd->listener);
}
if (tp->lid_switch.lid_switch)
libinput_device_remove_event_listener(
&tp->lid_switch.listener);
if (tp->tablet_mode_switch.tablet_mode_switch)
libinput_device_remove_event_listener(
&tp->tablet_mode_switch.listener);
}
static void
tp_interface_remove(struct evdev_dispatch *dispatch)
{
struct tp_dispatch *tp = tp_dispatch(dispatch);
struct evdev_paired_keyboard *kbd;
libinput_timer_cancel(&tp->arbitration.arbitration_timer);
list_for_each_safe(kbd, &tp->dwt.paired_keyboard_list, link) {
evdev_paired_keyboard_destroy(kbd);
}
tp->dwt.keyboard_active = false;
tp_remove_tap(tp);
tp_remove_buttons(tp);
tp_remove_sendevents(tp);
tp_remove_edge_scroll(tp);
tp_remove_gesture(tp);
}
static void
tp_interface_destroy(struct evdev_dispatch *dispatch)
{
struct tp_dispatch *tp = tp_dispatch(dispatch);
libinput_timer_destroy(&tp->arbitration.arbitration_timer);
libinput_timer_destroy(&tp->palm.trackpoint_timer);
libinput_timer_destroy(&tp->dwt.keyboard_timer);
libinput_timer_destroy(&tp->tap.timer);
libinput_timer_destroy(&tp->gesture.finger_count_switch_timer);
libinput_timer_destroy(&tp->gesture.hold_timer);
libinput_timer_destroy(&tp->gesture.drag_3fg_timer);
free(tp->touches);
free(tp);
}
static void
tp_release_fake_touches(struct tp_dispatch *tp)
{
tp->fake_touches = 0;
}
static void
tp_clear_state(struct tp_dispatch *tp)
{
uint64_t now = libinput_now(tp_libinput_context(tp));
struct tp_touch *t;
/* Unroll the touchpad state.
* Release buttons first. If tp is a clickpad, the button event
* must come before the touch up. If it isn't, the order doesn't
* matter anyway
*
* Then cancel all timeouts on the taps, triggering the last set
* of events.
*
* Then lift all touches so the touchpad is in a neutral state.
*
* Then reset thumb state.
*
*/
tp_release_all_buttons(tp, now);
tp_release_all_taps(tp, now);
tp_for_each_touch(tp, t) {
tp_end_sequence(tp, t, now);
}
tp_release_fake_touches(tp);
tp_thumb_reset(tp);
tp_handle_state(tp, now);
}
static void
tp_suspend(struct tp_dispatch *tp,
struct evdev_device *device,
enum suspend_trigger trigger)
{
if (tp->suspend_reason & trigger)
return;
if (tp->suspend_reason != 0)
goto out;
tp_clear_state(tp);
/* On devices with top softwarebuttons we don't actually suspend the
* device, to keep the "trackpoint" buttons working. tp_post_events()
* will only send events for the trackpoint while suspended.
*/
if (tp->buttons.has_topbuttons) {
evdev_notify_suspended_device(device);
/* Enlarge topbutton area while suspended */
tp_init_top_softbuttons(tp, device, 3.0);
} else {
evdev_device_suspend(device);
}
out:
tp->suspend_reason |= trigger;
}
static void
tp_interface_suspend(struct evdev_dispatch *dispatch,
struct evdev_device *device)
{
struct tp_dispatch *tp = tp_dispatch(dispatch);
tp_clear_state(tp);
}
static inline void
tp_sync_touch(struct tp_dispatch *tp,
struct evdev_device *device,
struct tp_touch *t,
int slot)
{
struct libevdev *evdev = device->evdev;
int tracking_id;
if (!libevdev_fetch_slot_value(evdev,
slot,
ABS_MT_POSITION_X,
&t->point.x))
t->point.x = libevdev_get_event_value(evdev, EV_ABS, ABS_X);
if (!libevdev_fetch_slot_value(evdev,
slot,
ABS_MT_POSITION_Y,
&t->point.y))
t->point.y = libevdev_get_event_value(evdev, EV_ABS, ABS_Y);
if (!libevdev_fetch_slot_value(evdev,
slot,
ABS_MT_PRESSURE,
&t->pressure))
t->pressure = libevdev_get_event_value(evdev,
EV_ABS,
ABS_PRESSURE);
libevdev_fetch_slot_value(evdev,
slot,
ABS_MT_TOUCH_MAJOR,
&t->major);
libevdev_fetch_slot_value(evdev,
slot,
ABS_MT_TOUCH_MINOR,
&t->minor);
if (libevdev_fetch_slot_value(evdev,
slot,
ABS_MT_TRACKING_ID,
&tracking_id) &&
tracking_id != -1)
tp->nactive_slots++;
}
static void
tp_sync_slots(struct tp_dispatch *tp,
struct evdev_device *device)
{
/* Always sync the first touch so we get ABS_X/Y synced on
* single-touch touchpads */
tp_sync_touch(tp, device, &tp->touches[0], 0);
for (unsigned int i = 1; i < tp->num_slots; i++)
tp_sync_touch(tp, device, &tp->touches[i], i);
}
static void
tp_resume(struct tp_dispatch *tp,
struct evdev_device *device,
enum suspend_trigger trigger)
{
tp->suspend_reason &= ~trigger;
if (tp->suspend_reason != 0)
return;
if (tp->buttons.has_topbuttons) {
/* tap state-machine is offline while suspended, reset state */
tp_clear_state(tp);
/* restore original topbutton area size */
tp_init_top_softbuttons(tp, device, 1.0);
evdev_notify_resumed_device(device);
} else {
evdev_device_resume(device);
}
tp_sync_slots(tp, device);
}
static void
tp_trackpoint_timeout(uint64_t now, void *data)
{
struct tp_dispatch *tp = data;
if (tp->palm.trackpoint_active) {
tp_tap_resume(tp, now);
tp->palm.trackpoint_active = false;
}
tp->palm.trackpoint_event_count = 0;
}
static void
tp_trackpoint_event(uint64_t time, struct libinput_event *event, void *data)
{
struct tp_dispatch *tp = data;
if (!tp->palm.dwtp_enabled)
return;
/* Buttons do not count as trackpad activity, as people may use
the trackpoint buttons in combination with the touchpad. */
if (event->type == LIBINPUT_EVENT_POINTER_BUTTON)
return;
tp->palm.trackpoint_last_event_time = time;
tp->palm.trackpoint_event_count++;
/* Require at least three events before enabling palm detection */
if (tp->palm.trackpoint_event_count < 3) {
libinput_timer_set(&tp->palm.trackpoint_timer,
time + DEFAULT_TRACKPOINT_EVENT_TIMEOUT);
return;
}
if (!tp->palm.trackpoint_active) {
tp_stop_actions(tp, time);
tp->palm.trackpoint_active = true;
}
libinput_timer_set(&tp->palm.trackpoint_timer,
time + DEFAULT_TRACKPOINT_ACTIVITY_TIMEOUT);
}
static void
tp_keyboard_timeout(uint64_t now, void *data)
{
struct tp_dispatch *tp = data;
if (tp->dwt.dwt_enabled &&
long_any_bit_set(tp->dwt.key_mask,
ARRAY_LENGTH(tp->dwt.key_mask))) {
libinput_timer_set(&tp->dwt.keyboard_timer,
now + DEFAULT_KEYBOARD_ACTIVITY_TIMEOUT_2);
tp->dwt.keyboard_last_press_time = now;
evdev_log_debug(tp->device, "palm: keyboard timeout refresh\n");
return;
}
tp_tap_resume(tp, now);
tp->dwt.keyboard_active = false;
evdev_log_debug(tp->device, "palm: keyboard timeout\n");
}
static inline bool
tp_key_is_shift(unsigned int keycode)
{
return keycode == KEY_LEFTSHIFT || keycode == KEY_RIGHTSHIFT;
}
static inline bool
tp_key_is_modifier(unsigned int keycode)
{
switch (keycode) {
/* Ignore modifiers to be responsive to ctrl-click, alt-tab, etc. */
case KEY_LEFTCTRL:
case KEY_RIGHTCTRL:
case KEY_LEFTALT:
case KEY_RIGHTALT:
case KEY_LEFTSHIFT:
case KEY_RIGHTSHIFT:
case KEY_FN:
case KEY_CAPSLOCK:
case KEY_TAB:
case KEY_COMPOSE:
case KEY_RIGHTMETA:
case KEY_LEFTMETA:
return true;
default:
return false;
}
}
static inline bool
tp_key_ignore_for_dwt(unsigned int keycode)
{
/* Ignore keys not part of the "typewriter set", i.e. F-keys,
* multimedia keys, numpad, etc.
*/
if (tp_key_is_modifier(keycode))
return false;
switch (keycode) {
case KEY_ESC:
case KEY_KPASTERISK:
return true;
default:
return keycode >= KEY_F1;
}
}
static void
tp_keyboard_event(uint64_t time, struct libinput_event *event, void *data)
{
struct tp_dispatch *tp = data;
struct libinput_event_keyboard *kbdev;
unsigned int timeout;
unsigned int key;
bool is_modifier;
if (event->type != LIBINPUT_EVENT_KEYBOARD_KEY)
return;
kbdev = libinput_event_get_keyboard_event(event);
key = libinput_event_keyboard_get_key(kbdev);
/* Only trigger the timer on key down. */
if (libinput_event_keyboard_get_key_state(kbdev) !=
LIBINPUT_KEY_STATE_PRESSED) {
long_clear_bit(tp->dwt.key_mask, key);
long_clear_bit(tp->dwt.mod_mask, key);
return;
}
if (!tp->dwt.dwt_enabled)
return;
if (tp_key_ignore_for_dwt(key))
return;
/* modifier keys don't trigger disable-while-typing so things like
* ctrl+zoom or ctrl+click are possible.
* The exception is shift which we don't trigger DWT for on its own
* but we do trigger DWT for once we type some other key.
*/
is_modifier = tp_key_is_modifier(key);
if (is_modifier) {
if (!tp_key_is_shift(key))
long_set_bit(tp->dwt.mod_mask, key);
return;
}
if (!tp->dwt.keyboard_active) {
/* This is the first non-modifier key press. Check if the
* modifier mask is set. If any modifier is down we don't
* trigger dwt because it's likely to be combination like
* Ctrl+S or similar */
if (long_any_bit_set(tp->dwt.mod_mask,
ARRAY_LENGTH(tp->dwt.mod_mask)))
return;
tp_stop_actions(tp, time);
tp->dwt.keyboard_active = true;
timeout = DEFAULT_KEYBOARD_ACTIVITY_TIMEOUT_1;
} else {
timeout = DEFAULT_KEYBOARD_ACTIVITY_TIMEOUT_2;
}
tp->dwt.keyboard_last_press_time = time;
long_set_bit(tp->dwt.key_mask, key);
libinput_timer_set(&tp->dwt.keyboard_timer,
time + timeout);
}
static bool
tp_want_dwt(struct evdev_device *touchpad,
struct evdev_device *keyboard)
{
unsigned int vendor_tp = evdev_device_get_id_vendor(touchpad);
unsigned int vendor_kbd = evdev_device_get_id_vendor(keyboard);
unsigned int product_tp = evdev_device_get_id_product(touchpad);
unsigned int product_kbd = evdev_device_get_id_product(keyboard);
/* External touchpads with the same vid/pid as the keyboard are
considered a happy couple */
if (touchpad->tags & EVDEV_TAG_EXTERNAL_TOUCHPAD)
return vendor_tp == vendor_kbd && product_tp == product_kbd;
if (keyboard->tags & EVDEV_TAG_INTERNAL_KEYBOARD)
return true;
/* keyboard is not tagged as internal keyboard and it's not part of
* a combo */
return false;
}
static void
tp_dwt_pair_keyboard(struct evdev_device *touchpad,
struct evdev_device *keyboard)
{
struct tp_dispatch *tp = (struct tp_dispatch*)touchpad->dispatch;
struct evdev_paired_keyboard *kbd;
size_t count = 0;
if ((keyboard->tags & EVDEV_TAG_KEYBOARD) == 0)
return;
if (!tp_want_dwt(touchpad, keyboard))
return;
list_for_each(kbd, &tp->dwt.paired_keyboard_list, link) {
count++;
if (count > 3) {
evdev_log_info(touchpad,
"too many internal keyboards for dwt\n");
break;
}
}
kbd = zalloc(sizeof(*kbd));
kbd->device = keyboard;
libinput_device_add_event_listener(&keyboard->base,
&kbd->listener,
tp_keyboard_event, tp);
list_insert(&tp->dwt.paired_keyboard_list, &kbd->link);
evdev_log_debug(touchpad,
"palm: dwt activated with %s<->%s\n",
touchpad->devname,
keyboard->devname);
}
static void
tp_pair_trackpoint(struct evdev_device *touchpad,
struct evdev_device *trackpoint)
{
struct tp_dispatch *tp = (struct tp_dispatch*)touchpad->dispatch;
unsigned int bus_trp = libevdev_get_id_bustype(trackpoint->evdev);
bool tp_is_internal, trp_is_internal;
if ((trackpoint->tags & EVDEV_TAG_TRACKPOINT) == 0)
return;
tp_is_internal = !!(touchpad->tags & EVDEV_TAG_INTERNAL_TOUCHPAD);
trp_is_internal = bus_trp != BUS_USB && bus_trp != BUS_BLUETOOTH;
if (tp->buttons.trackpoint == NULL &&
tp_is_internal && trp_is_internal) {
/* Don't send any pending releases to the new trackpoint */
tp->buttons.active_is_topbutton = false;
tp->buttons.trackpoint = trackpoint;
if (tp->palm.monitor_trackpoint)
libinput_device_add_event_listener(&trackpoint->base,
&tp->palm.trackpoint_listener,
tp_trackpoint_event, tp);
}
}
static void
tp_lid_switch_event(uint64_t time, struct libinput_event *event, void *data)
{
struct tp_dispatch *tp = data;
struct libinput_event_switch *swev;
if (libinput_event_get_type(event) != LIBINPUT_EVENT_SWITCH_TOGGLE)
return;
swev = libinput_event_get_switch_event(event);
if (libinput_event_switch_get_switch(swev) != LIBINPUT_SWITCH_LID)
return;
switch (libinput_event_switch_get_switch_state(swev)) {
case LIBINPUT_SWITCH_STATE_OFF:
tp_resume(tp, tp->device, SUSPEND_LID);
evdev_log_debug(tp->device, "lid: resume touchpad\n");
break;
case LIBINPUT_SWITCH_STATE_ON:
tp_suspend(tp, tp->device, SUSPEND_LID);
evdev_log_debug(tp->device, "lid: suspending touchpad\n");
break;
}
}
static void
tp_tablet_mode_switch_event(uint64_t time,
struct libinput_event *event,
void *data)
{
struct tp_dispatch *tp = data;
struct libinput_event_switch *swev;
if (libinput_event_get_type(event) != LIBINPUT_EVENT_SWITCH_TOGGLE)
return;
swev = libinput_event_get_switch_event(event);
if (libinput_event_switch_get_switch(swev) !=
LIBINPUT_SWITCH_TABLET_MODE)
return;
switch (libinput_event_switch_get_switch_state(swev)) {
case LIBINPUT_SWITCH_STATE_OFF:
tp_resume(tp, tp->device, SUSPEND_TABLET_MODE);
evdev_log_debug(tp->device, "tablet-mode: resume touchpad\n");
break;
case LIBINPUT_SWITCH_STATE_ON:
tp_suspend(tp, tp->device, SUSPEND_TABLET_MODE);
evdev_log_debug(tp->device, "tablet-mode: suspending touchpad\n");
break;
}
}
static void
tp_pair_lid_switch(struct evdev_device *touchpad,
struct evdev_device *lid_switch)
{
struct tp_dispatch *tp = (struct tp_dispatch*)touchpad->dispatch;
if ((lid_switch->tags & EVDEV_TAG_LID_SWITCH) == 0)
return;
if (touchpad->tags & EVDEV_TAG_EXTERNAL_TOUCHPAD)
return;
if (tp->lid_switch.lid_switch == NULL) {
evdev_log_debug(touchpad,
"lid: activated for %s<->%s\n",
touchpad->devname,
lid_switch->devname);
libinput_device_add_event_listener(&lid_switch->base,
&tp->lid_switch.listener,
tp_lid_switch_event, tp);
tp->lid_switch.lid_switch = lid_switch;
}
}
static void
tp_pair_tablet_mode_switch(struct evdev_device *touchpad,
struct evdev_device *tablet_mode_switch)
{
struct tp_dispatch *tp = (struct tp_dispatch*)touchpad->dispatch;
if ((tablet_mode_switch->tags & EVDEV_TAG_TABLET_MODE_SWITCH) == 0)
return;
if (tp->tablet_mode_switch.tablet_mode_switch)
return;
if (touchpad->tags & EVDEV_TAG_EXTERNAL_TOUCHPAD)
return;
if (evdev_device_has_model_quirk(touchpad,
QUIRK_MODEL_TABLET_MODE_NO_SUSPEND))
return;
evdev_log_debug(touchpad,
"tablet-mode: activated for %s<->%s\n",
touchpad->devname,
tablet_mode_switch->devname);
libinput_device_add_event_listener(&tablet_mode_switch->base,
&tp->tablet_mode_switch.listener,
tp_tablet_mode_switch_event, tp);
tp->tablet_mode_switch.tablet_mode_switch = tablet_mode_switch;
if (evdev_device_switch_get_state(tablet_mode_switch,
LIBINPUT_SWITCH_TABLET_MODE)
== LIBINPUT_SWITCH_STATE_ON) {
tp_suspend(tp, touchpad, SUSPEND_TABLET_MODE);
}
}
static void
tp_change_rotation(struct evdev_device *device, enum notify notify)
{
struct tp_dispatch *tp = (struct tp_dispatch *)device->dispatch;
struct evdev_device *tablet_device = tp->left_handed.tablet_device;
bool tablet_is_left, touchpad_is_left;
if (!tp->left_handed.must_rotate)
return;
touchpad_is_left = device->left_handed.enabled;
tablet_is_left = tp->left_handed.tablet_left_handed_state;
tp->left_handed.want_rotate = touchpad_is_left || tablet_is_left;
tp_apply_rotation(device);
if (notify == DO_NOTIFY && tablet_device) {
struct evdev_dispatch *dispatch = tablet_device->dispatch;
if (dispatch->interface->left_handed_toggle)
dispatch->interface->left_handed_toggle(dispatch,
tablet_device,
tp->left_handed.want_rotate);
}
}
static void
tp_pair_tablet(struct evdev_device *touchpad,
struct evdev_device *tablet)
{
struct tp_dispatch *tp = (struct tp_dispatch*)touchpad->dispatch;
if (!tp->left_handed.must_rotate)
return;
if ((tablet->seat_caps & EVDEV_DEVICE_TABLET) == 0)
return;
if (libinput_device_get_device_group(&touchpad->base) !=
libinput_device_get_device_group(&tablet->base))
return;
tp->left_handed.tablet_device = tablet;
evdev_log_debug(touchpad,
"touchpad-rotation: %s will rotate %s\n",
touchpad->devname,
tablet->devname);
if (libinput_device_config_left_handed_get(&tablet->base)) {
tp->left_handed.want_rotate = true;
tp->left_handed.tablet_left_handed_state = true;
tp_change_rotation(touchpad, DONT_NOTIFY);
}
}
static void
tp_interface_device_added(struct evdev_device *device,
struct evdev_device *added_device)
{
struct tp_dispatch *tp = (struct tp_dispatch*)device->dispatch;
tp_pair_trackpoint(device, added_device);
tp_dwt_pair_keyboard(device, added_device);
tp_pair_lid_switch(device, added_device);
tp_pair_tablet_mode_switch(device, added_device);
tp_pair_tablet(device, added_device);
if (tp->sendevents.current_mode !=
LIBINPUT_CONFIG_SEND_EVENTS_DISABLED_ON_EXTERNAL_MOUSE)
return;
if (added_device->tags & EVDEV_TAG_EXTERNAL_MOUSE)
tp_suspend(tp, device, SUSPEND_EXTERNAL_MOUSE);
}
static void
tp_interface_device_removed(struct evdev_device *device,
struct evdev_device *removed_device)
{
struct tp_dispatch *tp = (struct tp_dispatch*)device->dispatch;
struct evdev_paired_keyboard *kbd;
if (removed_device == tp->buttons.trackpoint) {
/* Clear any pending releases for the trackpoint */
if (tp->buttons.active && tp->buttons.active_is_topbutton) {
tp->buttons.active = 0;
tp->buttons.active_is_topbutton = false;
}
if (tp->palm.monitor_trackpoint)
libinput_device_remove_event_listener(
&tp->palm.trackpoint_listener);
tp->buttons.trackpoint = NULL;
}
list_for_each_safe(kbd, &tp->dwt.paired_keyboard_list, link) {
if (kbd->device == removed_device) {
evdev_paired_keyboard_destroy(kbd);
tp->dwt.keyboard_active = false;
}
}
if (removed_device == tp->lid_switch.lid_switch) {
libinput_device_remove_event_listener(
&tp->lid_switch.listener);
tp->lid_switch.lid_switch = NULL;
tp_resume(tp, device, SUSPEND_LID);
}
if (removed_device == tp->tablet_mode_switch.tablet_mode_switch) {
libinput_device_remove_event_listener(
&tp->tablet_mode_switch.listener);
tp->tablet_mode_switch.tablet_mode_switch = NULL;
tp_resume(tp, device, SUSPEND_TABLET_MODE);
}
if (tp->sendevents.current_mode ==
LIBINPUT_CONFIG_SEND_EVENTS_DISABLED_ON_EXTERNAL_MOUSE) {
struct libinput_device *dev;
bool found = false;
list_for_each(dev, &device->base.seat->devices_list, link) {
struct evdev_device *d = evdev_device(dev);
if (d != removed_device &&
(d->tags & EVDEV_TAG_EXTERNAL_MOUSE)) {
found = true;
break;
}
}
if (!found)
tp_resume(tp, device, SUSPEND_EXTERNAL_MOUSE);
}
if (removed_device == tp->left_handed.tablet_device) {
tp->left_handed.tablet_device = NULL;
tp->left_handed.tablet_left_handed_state = false;
/* Slight awkwardness: removing the tablet causes the
* touchpad to rotate back to normal if only the tablet was
* set to left-handed. Niche case, nothing to worry about
*/
tp_change_rotation(device, DO_NOTIFY);
}
}
static inline void
evdev_tag_touchpad_internal(struct evdev_device *device)
{
device->tags |= EVDEV_TAG_INTERNAL_TOUCHPAD;
device->tags &= ~EVDEV_TAG_EXTERNAL_TOUCHPAD;
}
static inline void
evdev_tag_touchpad_external(struct evdev_device *device)
{
device->tags |= EVDEV_TAG_EXTERNAL_TOUCHPAD;
device->tags &= ~EVDEV_TAG_INTERNAL_TOUCHPAD;
}
static void
evdev_tag_touchpad(struct evdev_device *device,
struct udev_device *udev_device)
{
int bustype, vendor;
const char *prop;
prop = udev_device_get_property_value(udev_device,
"ID_INPUT_TOUCHPAD_INTEGRATION");
if (prop) {
if (streq(prop, "internal")) {
evdev_tag_touchpad_internal(device);
return;
}
if (streq(prop, "external")) {
evdev_tag_touchpad_external(device);
return;
}
evdev_log_info(device,
"tagged with unknown value %s\n",
prop);
}
/* The hwdb is the authority on integration, these heuristics are
* the fallback only (they precede the hwdb too).
*
* Simple approach:
* Bluetooth touchpads are considered external, anything else is
* internal. Except the ones from some vendors that only make external
* touchpads.
*/
bustype = libevdev_get_id_bustype(device->evdev);
vendor = libevdev_get_id_vendor(device->evdev);
switch (bustype) {
case BUS_BLUETOOTH:
evdev_tag_touchpad_external(device);
break;
default:
evdev_tag_touchpad_internal(device);
break;
}
switch (vendor) {
/* Logitech does not have internal touchpads */
case VENDOR_ID_LOGITECH:
evdev_tag_touchpad_external(device);
break;
}
/* Wacom makes touchpads, but not internal ones */
if (device->model_flags & EVDEV_MODEL_WACOM_TOUCHPAD)
evdev_tag_touchpad_external(device);
if ((device->tags &
(EVDEV_TAG_EXTERNAL_TOUCHPAD|EVDEV_TAG_INTERNAL_TOUCHPAD)) == 0) {
evdev_log_bug_libinput(device,
"Internal or external? Please file a bug.\n");
evdev_tag_touchpad_external(device);
}
}
static void
tp_arbitration_timeout(uint64_t now, void *data)
{
struct tp_dispatch *tp = data;
if (tp->arbitration.state != ARBITRATION_NOT_ACTIVE)
tp->arbitration.state = ARBITRATION_NOT_ACTIVE;
}
static void
tp_interface_toggle_touch(struct evdev_dispatch *dispatch,
struct evdev_device *device,
enum evdev_arbitration_state which,
const struct phys_rect *rect,
uint64_t time)
{
struct tp_dispatch *tp = tp_dispatch(dispatch);
if (which == tp->arbitration.state)
return;
switch (which) {
case ARBITRATION_IGNORE_ALL:
case ARBITRATION_IGNORE_RECT:
libinput_timer_cancel(&tp->arbitration.arbitration_timer);
tp_clear_state(tp);
tp->arbitration.state = which;
break;
case ARBITRATION_NOT_ACTIVE:
/* if in-kernel arbitration is in use and there is a touch
* and a pen in proximity, lifting the pen out of proximity
* causes a touch begin for the touch. On a hand-lift the
* proximity out precedes the touch up by a few ms, so we
* get what looks like a tap. Fix this by delaying
* arbitration by just a little bit so that any touch in
* event is caught as palm touch. */
libinput_timer_set(&tp->arbitration.arbitration_timer,
time + ms2us(90));
break;
}
}
/* Called when the tablet toggles to left-handed */
static void
touchpad_left_handed_toggled(struct evdev_dispatch *dispatch,
struct evdev_device *device,
bool left_handed_enabled)
{
struct tp_dispatch *tp = tp_dispatch(dispatch);
if (!tp->left_handed.tablet_device)
return;
evdev_log_debug(device,
"touchpad-rotation: tablet is %s\n",
left_handed_enabled ? "left-handed" : "right-handed");
/* Our left-handed config is independent even though rotation is
* locked. So we rotate when either device is left-handed. But it
* can only be actually changed when the device is in a neutral
* state, hence the want_rotate.
*/
tp->left_handed.tablet_left_handed_state = left_handed_enabled;
tp_change_rotation(device, DONT_NOTIFY);
}
static struct evdev_dispatch_interface tp_interface = {
.process = tp_interface_process,
.suspend = tp_interface_suspend,
.remove = tp_interface_remove,
.destroy = tp_interface_destroy,
.device_added = tp_interface_device_added,
.device_removed = tp_interface_device_removed,
.device_suspended = tp_interface_device_removed, /* treat as remove */
.device_resumed = tp_interface_device_added, /* treat as add */
.post_added = NULL,
.touch_arbitration_toggle = tp_interface_toggle_touch,
.touch_arbitration_update_rect = NULL,
.get_switch_state = NULL,
.left_handed_toggle = touchpad_left_handed_toggled,
};
static void
tp_init_touch(struct tp_dispatch *tp,
struct tp_touch *t,
unsigned int index)
{
t->tp = tp;
t->has_ended = true;
t->index = index;
}
static inline void
tp_disable_abs_mt(struct evdev_device *device)
{
struct libevdev *evdev = device->evdev;
unsigned int code;
for (code = ABS_MT_SLOT; code <= ABS_MAX; code++)
libevdev_disable_event_code(evdev, EV_ABS, code);
}
static bool
tp_init_slots(struct tp_dispatch *tp,
struct evdev_device *device)
{
const struct input_absinfo *absinfo;
struct map {
unsigned int code;
int ntouches;
} max_touches[] = {
{ BTN_TOOL_QUINTTAP, 5 },
{ BTN_TOOL_QUADTAP, 4 },
{ BTN_TOOL_TRIPLETAP, 3 },
{ BTN_TOOL_DOUBLETAP, 2 },
};
unsigned int i, n_btn_tool_touches = 1;
absinfo = libevdev_get_abs_info(device->evdev, ABS_MT_SLOT);
if (absinfo) {
tp->num_slots = absinfo->maximum + 1;
tp->slot = absinfo->value;
tp->has_mt = true;
} else {
tp->num_slots = 1;
tp->slot = 0;
tp->has_mt = false;
}
tp->semi_mt = libevdev_has_property(device->evdev, INPUT_PROP_SEMI_MT);
/* Semi-mt devices are not reliable for true multitouch data, so we
* simply pretend they're single touch touchpads with BTN_TOOL bits.
* Synaptics:
* Terrible resolution when two fingers are down,
* causing scroll jumps. The single-touch emulation ABS_X/Y is
* accurate but the ABS_MT_POSITION touchpoints report the bounding
* box and that causes jumps. See https://bugzilla.redhat.com/1235175
* Elantech:
* On three-finger taps/clicks, one slot doesn't get a coordinate
* assigned. See https://bugs.freedesktop.org/show_bug.cgi?id=93583
* Alps:
* If three fingers are set down in the same frame, one slot has the
* coordinates 0/0 and may not get updated for several frames.
* See https://bugzilla.redhat.com/show_bug.cgi?id=1295073
*
* The HP Pavilion DM4 touchpad has random jumps in slots, including
* for single-finger movement. See fdo bug 91135
*/
if (tp->semi_mt ||
evdev_device_has_model_quirk(tp->device,
QUIRK_MODEL_HP_PAVILION_DM4_TOUCHPAD)) {
tp->num_slots = 1;
tp->slot = 0;
tp->has_mt = false;
}
if (!tp->has_mt)
tp_disable_abs_mt(device);
ARRAY_FOR_EACH(max_touches, m) {
if (libevdev_has_event_code(device->evdev,
EV_KEY,
m->code)) {
n_btn_tool_touches = m->ntouches;
break;
}
}
tp->ntouches = max(tp->num_slots, n_btn_tool_touches);
tp->touches = zalloc(tp->ntouches * sizeof(struct tp_touch));
for (i = 0; i < tp->ntouches; i++)
tp_init_touch(tp, &tp->touches[i], i);
tp_sync_slots(tp, device);
/* Some touchpads don't reset BTN_TOOL_FINGER on touch up and only
* change to/from it when BTN_TOOL_DOUBLETAP is set. This causes us
* to ignore the first touches events until a two-finger gesture is
* performed.
*/
if (libevdev_get_event_value(device->evdev, EV_KEY, BTN_TOOL_FINGER))
tp_fake_finger_set(tp, BTN_TOOL_FINGER, 1);
return true;
}
static enum libinput_config_status
tp_accel_config_set_profile(struct libinput_device *libinput_device,
enum libinput_config_accel_profile profile);
static bool
tp_init_accel(struct tp_dispatch *tp, enum libinput_config_accel_profile which)
{
struct evdev_device *device = tp->device;
int res_x, res_y;
struct motion_filter *filter;
int dpi = device->dpi;
bool use_v_avg = device->use_velocity_averaging;
res_x = tp->device->abs.absinfo_x->resolution;
res_y = tp->device->abs.absinfo_y->resolution;
/*
* Not all touchpads report the same amount of units/mm (resolution).
* Normalize motion events to the default mouse DPI as base
* (unaccelerated) speed. This also evens out any differences in x
* and y resolution, so that a circle on the
* touchpad does not turn into an ellipse on the screen.
*/
tp->accel.x_scale_coeff = (DEFAULT_MOUSE_DPI/25.4) / res_x;
tp->accel.y_scale_coeff = (DEFAULT_MOUSE_DPI/25.4) / res_y;
tp->accel.xy_scale_coeff = 1.0 * res_x/res_y;
if (which == LIBINPUT_CONFIG_ACCEL_PROFILE_FLAT) {
filter = create_pointer_accelerator_filter_touchpad_flat(dpi);
} else if (which == LIBINPUT_CONFIG_ACCEL_PROFILE_CUSTOM) {
filter = create_custom_accelerator_filter();
} else if (evdev_device_has_model_quirk(device, QUIRK_MODEL_LENOVO_X230) ||
tp->device->model_flags & EVDEV_MODEL_LENOVO_X220_TOUCHPAD_FW81) {
filter = create_pointer_accelerator_filter_lenovo_x230(dpi, use_v_avg);
} else {
uint64_t eds_threshold = 0;
uint64_t eds_value = 0;
if (libevdev_get_id_bustype(device->evdev) == BUS_BLUETOOTH) {
eds_threshold = ms2us(50);
eds_value = ms2us(10);
}
filter = create_pointer_accelerator_filter_touchpad(dpi,
eds_threshold,
eds_value,
use_v_avg);
}
if (!filter)
return false;
evdev_device_init_pointer_acceleration(tp->device, filter);
device->pointer.config.set_profile = tp_accel_config_set_profile;
return true;
}
static enum libinput_config_status
tp_accel_config_set_speed(struct libinput_device *device, double speed)
{
struct evdev_device *dev = evdev_device(device);
if (!filter_set_speed(dev->pointer.filter, speed))
return LIBINPUT_CONFIG_STATUS_INVALID;
return LIBINPUT_CONFIG_STATUS_SUCCESS;
}
static enum libinput_config_status
tp_accel_config_set_profile(struct libinput_device *libinput_device,
enum libinput_config_accel_profile profile)
{
struct evdev_device *device = evdev_device(libinput_device);
struct tp_dispatch *tp = tp_dispatch(device->dispatch);
struct motion_filter *filter;
double speed;
filter = device->pointer.filter;
if (filter_get_type(filter) == profile)
return LIBINPUT_CONFIG_STATUS_SUCCESS;
speed = filter_get_speed(filter);
device->pointer.filter = NULL;
if (tp_init_accel(tp, profile)) {
tp_accel_config_set_speed(libinput_device, speed);
filter_destroy(filter);
} else {
device->pointer.filter = filter;
return LIBINPUT_CONFIG_STATUS_UNSUPPORTED;
}
return LIBINPUT_CONFIG_STATUS_SUCCESS;
}
static uint32_t
tp_scroll_get_methods(struct tp_dispatch *tp)
{
uint32_t methods = LIBINPUT_CONFIG_SCROLL_EDGE;
/* Any movement with more than one finger has random cursor
* jumps. Don't allow for 2fg scrolling on this device, see
* fdo bug 91135 */
if (evdev_device_has_model_quirk(tp->device,
QUIRK_MODEL_HP_PAVILION_DM4_TOUCHPAD))
return LIBINPUT_CONFIG_SCROLL_EDGE;
if (tp->ntouches >= 2)
methods |= LIBINPUT_CONFIG_SCROLL_2FG;
return methods;
}
static uint32_t
tp_scroll_config_scroll_method_get_methods(struct libinput_device *device)
{
struct evdev_device *evdev = evdev_device(device);
struct tp_dispatch *tp = (struct tp_dispatch*)evdev->dispatch;
return tp_scroll_get_methods(tp);
}
static enum libinput_config_status
tp_scroll_config_scroll_method_set_method(struct libinput_device *device,
enum libinput_config_scroll_method method)
{
struct evdev_device *evdev = evdev_device(device);
struct tp_dispatch *tp = (struct tp_dispatch*)evdev->dispatch;
uint64_t time = libinput_now(tp_libinput_context(tp));
if (method == tp->scroll.method)
return LIBINPUT_CONFIG_STATUS_SUCCESS;
tp_edge_scroll_stop_events(tp, time);
tp_gesture_stop_twofinger_scroll(tp, time);
tp->scroll.method = method;
return LIBINPUT_CONFIG_STATUS_SUCCESS;
}
static enum libinput_config_scroll_method
tp_scroll_config_scroll_method_get_method(struct libinput_device *device)
{
struct evdev_device *evdev = evdev_device(device);
struct tp_dispatch *tp = (struct tp_dispatch*)evdev->dispatch;
return tp->scroll.method;
}
static enum libinput_config_scroll_method
tp_scroll_get_default_method(struct tp_dispatch *tp)
{
uint32_t methods;
enum libinput_config_scroll_method method;
methods = tp_scroll_get_methods(tp);
if (methods & LIBINPUT_CONFIG_SCROLL_2FG)
method = LIBINPUT_CONFIG_SCROLL_2FG;
else
method = LIBINPUT_CONFIG_SCROLL_EDGE;
if ((methods & method) == 0)
evdev_log_bug_libinput(tp->device,
"invalid default scroll method %d\n",
method);
return method;
}
static enum libinput_config_scroll_method
tp_scroll_config_scroll_method_get_default_method(struct libinput_device *device)
{
struct evdev_device *evdev = evdev_device(device);
struct tp_dispatch *tp = (struct tp_dispatch*)evdev->dispatch;
return tp_scroll_get_default_method(tp);
}
static int
tp_scroll_config_natural_get_default(struct libinput_device *device)
{
struct evdev_device *dev = evdev_device(device);
return (evdev_device_has_model_quirk(dev, QUIRK_MODEL_APPLE_TOUCHPAD) ||
evdev_device_has_model_quirk(dev, QUIRK_MODEL_APPLE_TOUCHPAD_ONEBUTTON));
}
static void
tp_init_scroll(struct tp_dispatch *tp, struct evdev_device *device)
{
tp_edge_scroll_init(tp, device);
evdev_init_natural_scroll(device);
/* Override natural scroll config for Apple touchpads */
device->scroll.config_natural.get_default_enabled = tp_scroll_config_natural_get_default;
device->scroll.natural_scrolling_enabled = tp_scroll_config_natural_get_default(&device->base);
tp->scroll.config_method.get_methods = tp_scroll_config_scroll_method_get_methods;
tp->scroll.config_method.set_method = tp_scroll_config_scroll_method_set_method;
tp->scroll.config_method.get_method = tp_scroll_config_scroll_method_get_method;
tp->scroll.config_method.get_default_method = tp_scroll_config_scroll_method_get_default_method;
tp->scroll.method = tp_scroll_get_default_method(tp);
tp->device->base.config.scroll_method = &tp->scroll.config_method;
/* In mm for touchpads with valid resolution, see tp_init_accel() */
tp->device->scroll.threshold = 0.0;
tp->device->scroll.direction_lock_threshold = 5.0;
}
static int
tp_dwt_config_is_available(struct libinput_device *device)
{
return 1;
}
static enum libinput_config_status
tp_dwt_config_set(struct libinput_device *device,
enum libinput_config_dwt_state enable)
{
struct evdev_device *evdev = evdev_device(device);
struct tp_dispatch *tp = (struct tp_dispatch*)evdev->dispatch;
switch(enable) {
case LIBINPUT_CONFIG_DWT_ENABLED:
case LIBINPUT_CONFIG_DWT_DISABLED:
break;
default:
return LIBINPUT_CONFIG_STATUS_INVALID;
}
tp->dwt.dwt_enabled = (enable == LIBINPUT_CONFIG_DWT_ENABLED);
return LIBINPUT_CONFIG_STATUS_SUCCESS;
}
static enum libinput_config_dwt_state
tp_dwt_config_get(struct libinput_device *device)
{
struct evdev_device *evdev = evdev_device(device);
struct tp_dispatch *tp = (struct tp_dispatch*)evdev->dispatch;
return tp->dwt.dwt_enabled ?
LIBINPUT_CONFIG_DWT_ENABLED :
LIBINPUT_CONFIG_DWT_DISABLED;
}
static bool
tp_dwt_default_enabled(struct tp_dispatch *tp)
{
return true;
}
static enum libinput_config_dwt_state
tp_dwt_config_get_default(struct libinput_device *device)
{
struct evdev_device *evdev = evdev_device(device);
struct tp_dispatch *tp = (struct tp_dispatch*)evdev->dispatch;
return tp_dwt_default_enabled(tp) ?
LIBINPUT_CONFIG_DWT_ENABLED :
LIBINPUT_CONFIG_DWT_DISABLED;
}
static int
tp_dwtp_config_is_available(struct libinput_device *device)
{
return 1;
}
static enum libinput_config_status
tp_dwtp_config_set(struct libinput_device *device,
enum libinput_config_dwtp_state enable)
{
struct evdev_device *evdev = evdev_device(device);
struct tp_dispatch *tp = (struct tp_dispatch*)evdev->dispatch;
switch(enable) {
case LIBINPUT_CONFIG_DWTP_ENABLED:
case LIBINPUT_CONFIG_DWTP_DISABLED:
break;
default:
return LIBINPUT_CONFIG_STATUS_INVALID;
}
tp->palm.dwtp_enabled = (enable == LIBINPUT_CONFIG_DWTP_ENABLED);
return LIBINPUT_CONFIG_STATUS_SUCCESS;
}
static enum libinput_config_dwtp_state
tp_dwtp_config_get(struct libinput_device *device)
{
struct evdev_device *evdev = evdev_device(device);
struct tp_dispatch *tp = (struct tp_dispatch*)evdev->dispatch;
return tp->palm.dwtp_enabled ?
LIBINPUT_CONFIG_DWTP_ENABLED :
LIBINPUT_CONFIG_DWTP_DISABLED;
}
static bool
tp_dwtp_default_enabled(struct tp_dispatch *tp)
{
return true;
}
static enum libinput_config_dwtp_state
tp_dwtp_config_get_default(struct libinput_device *device)
{
struct evdev_device *evdev = evdev_device(device);
struct tp_dispatch *tp = (struct tp_dispatch*)evdev->dispatch;
return tp_dwtp_default_enabled(tp) ?
LIBINPUT_CONFIG_DWTP_ENABLED :
LIBINPUT_CONFIG_DWTP_DISABLED;
}
static inline bool
tp_is_tpkb_combo_below(struct evdev_device *device)
{
struct quirks_context *quirks;
struct quirks *q;
char *prop;
enum tpkbcombo_layout layout = TPKBCOMBO_LAYOUT_UNKNOWN;
int rc = false;
quirks = evdev_libinput_context(device)->quirks;
q = quirks_fetch_for_device(quirks, device->udev_device);
if (!q)
return false;
if (quirks_get_string(q, QUIRK_ATTR_TPKBCOMBO_LAYOUT, &prop)) {
rc = parse_tpkbcombo_layout_poperty(prop, &layout) &&
layout == TPKBCOMBO_LAYOUT_BELOW;
}
quirks_unref(q);
return rc;
}
static inline bool
tp_is_tablet(struct evdev_device *device)
{
return device->tags & EVDEV_TAG_TABLET_TOUCHPAD;
}
static void
tp_init_dwt(struct tp_dispatch *tp,
struct evdev_device *device)
{
if (device->tags & EVDEV_TAG_EXTERNAL_TOUCHPAD &&
!tp_is_tpkb_combo_below(device))
return;
tp->dwt.config.is_available = tp_dwt_config_is_available;
tp->dwt.config.set_enabled = tp_dwt_config_set;
tp->dwt.config.get_enabled = tp_dwt_config_get;
tp->dwt.config.get_default_enabled = tp_dwt_config_get_default;
tp->dwt.dwt_enabled = tp_dwt_default_enabled(tp);
device->base.config.dwt = &tp->dwt.config;
}
static void
tp_init_dwtp(struct tp_dispatch *tp,
struct evdev_device *device)
{
tp->palm.dwtp_enabled = tp_dwtp_default_enabled(tp);
if (device->tags & EVDEV_TAG_EXTERNAL_TOUCHPAD)
return;
tp->palm.config.is_available = tp_dwtp_config_is_available;
tp->palm.config.set_enabled = tp_dwtp_config_set;
tp->palm.config.get_enabled = tp_dwtp_config_get;
tp->palm.config.get_default_enabled = tp_dwtp_config_get_default;
device->base.config.dwtp = &tp->palm.config;
}
static inline void
tp_init_palmdetect_edge(struct tp_dispatch *tp,
struct evdev_device *device)
{
double width, height;
struct phys_coords mm = { 0.0, 0.0 };
struct device_coords edges;
if (device->tags & EVDEV_TAG_EXTERNAL_TOUCHPAD &&
!tp_is_tpkb_combo_below(device))
return;
/* Edge palm detection hurts more than it helps on Apple touchpads. */
if (evdev_device_has_model_quirk(device, QUIRK_MODEL_APPLE_TOUCHPAD))
return;
evdev_device_get_size(device, &width, &height);
/* Enable edge palm detection on touchpads >= 70 mm. Anything
smaller probably won't need it, until we find out it does */
if (width < 70.0)
return;
/* palm edges are 8% of the width on each side */
mm.x = min(8, width * 0.08);
edges = evdev_device_mm_to_units(device, &mm);
tp->palm.left_edge = edges.x;
mm.x = width - min(8, width * 0.08);
edges = evdev_device_mm_to_units(device, &mm);
tp->palm.right_edge = edges.x;
if (!tp->buttons.has_topbuttons && height > 55) {
/* top edge is 5% of the height */
mm.y = height * 0.05;
edges = evdev_device_mm_to_units(device, &mm);
tp->palm.upper_edge = edges.y;
}
}
static int
tp_read_palm_pressure_prop(struct tp_dispatch *tp,
const struct evdev_device *device)
{
const int default_palm_threshold = 130;
uint32_t threshold = default_palm_threshold;
struct quirks_context *quirks;
struct quirks *q;
quirks = evdev_libinput_context(device)->quirks;
q = quirks_fetch_for_device(quirks, device->udev_device);
if (!q)
return threshold;
quirks_get_uint32(q, QUIRK_ATTR_PALM_PRESSURE_THRESHOLD, &threshold);
quirks_unref(q);
return threshold;
}
static inline void
tp_init_palmdetect_pressure(struct tp_dispatch *tp,
struct evdev_device *device)
{
if (!libevdev_has_event_code(device->evdev, EV_ABS, ABS_MT_PRESSURE)) {
tp->palm.use_pressure = false;
return;
}
tp->palm.pressure_threshold = tp_read_palm_pressure_prop(tp, device);
if (tp->palm.pressure_threshold != 0) {
tp->palm.use_pressure = true;
evdev_log_debug(device,
"palm: pressure threshold is %d\n",
tp->palm.pressure_threshold);
}
}
static inline void
tp_init_palmdetect_size(struct tp_dispatch *tp,
struct evdev_device *device)
{
struct quirks_context *quirks;
struct quirks *q;
uint32_t threshold;
quirks = evdev_libinput_context(device)->quirks;
q = quirks_fetch_for_device(quirks, device->udev_device);
if (!q)
return;
if (quirks_get_uint32(q, QUIRK_ATTR_PALM_SIZE_THRESHOLD, &threshold)) {
if (threshold != 0) {
tp->palm.use_size = true;
tp->palm.size_threshold = threshold;
}
}
quirks_unref(q);
}
static inline void
tp_init_palmdetect_arbitration(struct tp_dispatch *tp,
struct evdev_device *device)
{
char timer_name[64];
snprintf(timer_name,
sizeof(timer_name),
"%s arbitration",
evdev_device_get_sysname(device));
libinput_timer_init(&tp->arbitration.arbitration_timer,
tp_libinput_context(tp),
timer_name,
tp_arbitration_timeout, tp);
tp->arbitration.state = ARBITRATION_NOT_ACTIVE;
}
static void
tp_init_palmdetect(struct tp_dispatch *tp,
struct evdev_device *device)
{
tp->palm.right_edge = INT_MAX;
tp->palm.left_edge = INT_MIN;
tp->palm.upper_edge = INT_MIN;
tp_init_palmdetect_arbitration(tp, device);
if (device->tags & EVDEV_TAG_EXTERNAL_TOUCHPAD &&
!tp_is_tpkb_combo_below(device) &&
!tp_is_tablet(device))
return;
if (!tp_is_tablet(device))
tp->palm.monitor_trackpoint = true;
if (libevdev_has_event_code(device->evdev,
EV_ABS,
ABS_MT_TOOL_TYPE))
tp->palm.use_mt_tool = true;
if (!tp_is_tablet(device))
tp_init_palmdetect_edge(tp, device);
tp_init_palmdetect_pressure(tp, device);
tp_init_palmdetect_size(tp, device);
}
static void
tp_init_sendevents(struct tp_dispatch *tp,
struct evdev_device *device)
{
char timer_name[64];
snprintf(timer_name,
sizeof(timer_name),
"%s trackpoint",
evdev_device_get_sysname(device));
libinput_timer_init(&tp->palm.trackpoint_timer,
tp_libinput_context(tp),
timer_name,
tp_trackpoint_timeout, tp);
snprintf(timer_name,
sizeof(timer_name),
"%s keyboard",
evdev_device_get_sysname(device));
libinput_timer_init(&tp->dwt.keyboard_timer,
tp_libinput_context(tp),
timer_name,
tp_keyboard_timeout, tp);
}
static bool
tp_pass_sanity_check(struct tp_dispatch *tp,
struct evdev_device *device)
{
struct libevdev *evdev = device->evdev;
if (!libevdev_has_event_code(evdev, EV_ABS, ABS_X))
goto error;
if (!libevdev_has_event_code(evdev, EV_KEY, BTN_TOUCH))
goto error;
if (!libevdev_has_event_code(evdev, EV_KEY, BTN_TOOL_FINGER))
goto error;
return true;
error:
evdev_log_bug_kernel(device,
"device failed touchpad sanity checks\n");
return false;
}
static void
tp_init_default_resolution(struct tp_dispatch *tp,
struct evdev_device *device)
{
const int touchpad_width_mm = 69, /* 1 under palm detection */
touchpad_height_mm = 50;
int xres, yres;
if (!device->abs.is_fake_resolution)
return;
/* we only get here if
* - the touchpad provides no resolution
* - the udev hwdb didn't override the resolution
* - no ATTR_SIZE_HINT is set
*
* The majority of touchpads that triggers all these conditions
* are old ones, so let's assume a small touchpad size and assume
* that.
*/
evdev_log_info(device,
"no resolution or size hints, assuming a size of %dx%dmm\n",
touchpad_width_mm,
touchpad_height_mm);
xres = device->abs.dimensions.x/touchpad_width_mm;
yres = device->abs.dimensions.y/touchpad_height_mm;
libevdev_set_abs_resolution(device->evdev, ABS_X, xres);
libevdev_set_abs_resolution(device->evdev, ABS_Y, yres);
libevdev_set_abs_resolution(device->evdev, ABS_MT_POSITION_X, xres);
libevdev_set_abs_resolution(device->evdev, ABS_MT_POSITION_Y, yres);
device->abs.is_fake_resolution = false;
}
static inline void
tp_init_hysteresis(struct tp_dispatch *tp)
{
int xmargin, ymargin;
const struct input_absinfo *ax = tp->device->abs.absinfo_x,
*ay = tp->device->abs.absinfo_y;
if (ax->fuzz)
xmargin = ax->fuzz;
else
xmargin = ax->resolution/4;
if (ay->fuzz)
ymargin = ay->fuzz;
else
ymargin = ay->resolution/4;
tp->hysteresis.margin.x = xmargin;
tp->hysteresis.margin.y = ymargin;
tp->hysteresis.enabled = (ax->fuzz || ay->fuzz);
if (tp->hysteresis.enabled)
evdev_log_debug(tp->device,
"hysteresis enabled. "
"See %s/touchpad-jitter.html for details\n",
HTTP_DOC_LINK);
}
static void
tp_init_pressure(struct tp_dispatch *tp,
struct evdev_device *device)
{
const struct input_absinfo *abs;
unsigned int code;
struct quirks_context *quirks;
struct quirks *q;
struct quirk_range r;
int hi, lo;
code = tp->has_mt ? ABS_MT_PRESSURE : ABS_PRESSURE;
if (!libevdev_has_event_code(device->evdev, EV_ABS, code)) {
tp->pressure.use_pressure = false;
return;
}
abs = libevdev_get_abs_info(device->evdev, code);
assert(abs);
quirks = evdev_libinput_context(device)->quirks;
q = quirks_fetch_for_device(quirks, device->udev_device);
if (q && quirks_get_range(q, QUIRK_ATTR_PRESSURE_RANGE, &r)) {
hi = r.upper;
lo = r.lower;
if (hi == 0 && lo == 0) {
evdev_log_info(device,
"pressure-based touch detection disabled\n");
goto out;
}
} else {
double range = absinfo_range(abs);
/* Approximately the synaptics defaults */
hi = abs->minimum + 0.12 * range;
lo = abs->minimum + 0.10 * range;
}
if (hi > abs->maximum || hi < abs->minimum ||
lo > abs->maximum || lo < abs->minimum) {
evdev_log_bug_libinput(device,
"discarding out-of-bounds pressure range %d:%d\n",
hi, lo);
goto out;
}
tp->pressure.use_pressure = true;
tp->pressure.high = hi;
tp->pressure.low = lo;
evdev_log_debug(device,
"using pressure-based touch detection (%d:%d)\n",
lo,
hi);
out:
quirks_unref(q);
}
static bool
tp_init_touch_size(struct tp_dispatch *tp,
struct evdev_device *device)
{
struct quirks_context *quirks;
struct quirks *q;
struct quirk_range r;
int lo, hi;
int rc = false;
if (!libevdev_has_event_code(device->evdev,
EV_ABS,
ABS_MT_TOUCH_MAJOR)) {
return false;
}
quirks = evdev_libinput_context(device)->quirks;
q = quirks_fetch_for_device(quirks, device->udev_device);
if (q && quirks_get_range(q, QUIRK_ATTR_TOUCH_SIZE_RANGE, &r)) {
hi = r.upper;
lo = r.lower;
} else {
goto out;
}
if (libevdev_get_num_slots(device->evdev) < 5) {
evdev_log_bug_libinput(device,
"Expected 5+ slots for touch size detection\n");
goto out;
}
if (hi == 0 && lo == 0) {
evdev_log_info(device,
"touch size based touch detection disabled\n");
goto out;
}
/* Thresholds apply for both major or minor */
tp->touch_size.low = lo;
tp->touch_size.high = hi;
tp->touch_size.use_touch_size = true;
evdev_log_debug(device,
"using size-based touch detection (%d:%d)\n",
hi, lo);
rc = true;
out:
quirks_unref(q);
return rc;
}
static void
tp_init_pressurepad(struct tp_dispatch *tp,
struct evdev_device *device)
{
/* On traditional touchpads, the pressure value equals contact
* size. On PressurePads, pressure is a real physical axis for the
* force down. So we disable it here because we don't do anything
* with it anyway and using it for touch size messes things up.
*
* The kernel/udev set the resolution to non-zero on those devices
* to indicate that the value is in a known axis space.
*
* See also #562
*/
if (libevdev_get_abs_resolution(device->evdev, ABS_MT_PRESSURE) != 0 ||
evdev_device_has_model_quirk(device, QUIRK_MODEL_PRESSURE_PAD)) {
libevdev_disable_event_code(device->evdev, EV_ABS, ABS_MT_PRESSURE);
libevdev_disable_event_code(device->evdev, EV_ABS, ABS_PRESSURE);
}
}
static int
tp_init(struct tp_dispatch *tp,
struct evdev_device *device)
{
bool use_touch_size = false;
tp->base.dispatch_type = DISPATCH_TOUCHPAD;
tp->base.interface = &tp_interface;
tp->device = device;
list_init(&tp->dwt.paired_keyboard_list);
if (!tp_pass_sanity_check(tp, device))
return false;
tp_init_default_resolution(tp, device);
tp_init_pressurepad(tp, device);
if (!tp_init_slots(tp, device))
return false;
evdev_device_init_abs_range_warnings(device);
use_touch_size = tp_init_touch_size(tp, device);
if (!use_touch_size)
tp_init_pressure(tp, device);
/* 5 warnings per 24 hours should be enough */
ratelimit_init(&tp->jump.warning, h2us(24), 5);
/* Set the dpi to that of the x axis, because that's what we normalize
to when needed*/
device->dpi = device->abs.absinfo_x->resolution * 25.4;
tp_init_hysteresis(tp);
if (!tp_init_accel(tp, LIBINPUT_CONFIG_ACCEL_PROFILE_ADAPTIVE))
return false;
tp_init_tap(tp);
tp_init_buttons(tp, device);
tp_init_dwt(tp, device);
tp_init_dwtp(tp, device);
tp_init_palmdetect(tp, device);
tp_init_sendevents(tp, device);
tp_init_scroll(tp, device);
tp_init_gesture(tp);
tp_init_thumb(tp);
/* Lenovo X1 Gen6 buffers the events in a weird way, making jump
* detection impossible. See
* https://gitlab.freedesktop.org/libinput/libinput/-/issues/506
*/
if (evdev_device_has_model_quirk(device,
QUIRK_MODEL_LENOVO_X1GEN6_TOUCHPAD))
tp->jump.detection_disabled = true;
device->seat_caps |= EVDEV_DEVICE_POINTER;
if (tp->gesture.enabled)
device->seat_caps |= EVDEV_DEVICE_GESTURE;
return true;
}
static uint32_t
tp_sendevents_get_modes(struct libinput_device *device)
{
struct evdev_device *evdev = evdev_device(device);
uint32_t modes = LIBINPUT_CONFIG_SEND_EVENTS_DISABLED;
if (evdev->tags & EVDEV_TAG_INTERNAL_TOUCHPAD)
modes |= LIBINPUT_CONFIG_SEND_EVENTS_DISABLED_ON_EXTERNAL_MOUSE;
return modes;
}
static void
tp_suspend_conditional(struct tp_dispatch *tp,
struct evdev_device *device)
{
struct libinput_device *dev;
list_for_each(dev, &device->base.seat->devices_list, link) {
struct evdev_device *d = evdev_device(dev);
if (d->tags & EVDEV_TAG_EXTERNAL_MOUSE) {
tp_suspend(tp, device, SUSPEND_EXTERNAL_MOUSE);
break;
}
}
}
static enum libinput_config_status
tp_sendevents_set_mode(struct libinput_device *device,
enum libinput_config_send_events_mode mode)
{
struct evdev_device *evdev = evdev_device(device);
struct tp_dispatch *tp = (struct tp_dispatch*)evdev->dispatch;
/* DISABLED overrides any DISABLED_ON_ */
if ((mode & LIBINPUT_CONFIG_SEND_EVENTS_DISABLED) &&
(mode & LIBINPUT_CONFIG_SEND_EVENTS_DISABLED_ON_EXTERNAL_MOUSE))
mode &= ~LIBINPUT_CONFIG_SEND_EVENTS_DISABLED_ON_EXTERNAL_MOUSE;
if (mode == tp->sendevents.current_mode)
return LIBINPUT_CONFIG_STATUS_SUCCESS;
switch(mode) {
case LIBINPUT_CONFIG_SEND_EVENTS_ENABLED:
tp_resume(tp, evdev, SUSPEND_SENDEVENTS);
tp_resume(tp, evdev, SUSPEND_EXTERNAL_MOUSE);
break;
case LIBINPUT_CONFIG_SEND_EVENTS_DISABLED:
tp_suspend(tp, evdev, SUSPEND_SENDEVENTS);
tp_resume(tp, evdev, SUSPEND_EXTERNAL_MOUSE);
break;
case LIBINPUT_CONFIG_SEND_EVENTS_DISABLED_ON_EXTERNAL_MOUSE:
tp_suspend_conditional(tp, evdev);
tp_resume(tp, evdev, SUSPEND_SENDEVENTS);
break;
default:
return LIBINPUT_CONFIG_STATUS_UNSUPPORTED;
}
tp->sendevents.current_mode = mode;
return LIBINPUT_CONFIG_STATUS_SUCCESS;
}
static enum libinput_config_send_events_mode
tp_sendevents_get_mode(struct libinput_device *device)
{
struct evdev_device *evdev = evdev_device(device);
struct tp_dispatch *dispatch = (struct tp_dispatch*)evdev->dispatch;
return dispatch->sendevents.current_mode;
}
static enum libinput_config_send_events_mode
tp_sendevents_get_default_mode(struct libinput_device *device)
{
return LIBINPUT_CONFIG_SEND_EVENTS_ENABLED;
}
static void
tp_change_to_left_handed(struct evdev_device *device)
{
struct tp_dispatch *tp = (struct tp_dispatch *)device->dispatch;
if (device->left_handed.want_enabled == device->left_handed.enabled)
return;
if (tp->buttons.state & 0x3) /* BTN_LEFT|BTN_RIGHT */
return;
/* tapping and clickfinger aren't affected by left-handed config,
* so checking physical buttons is enough */
device->left_handed.enabled = device->left_handed.want_enabled;
tp_change_rotation(device, DO_NOTIFY);
}
static bool
tp_requires_rotation(struct tp_dispatch *tp, struct evdev_device *device)
{
bool rotate = false;
#if HAVE_LIBWACOM
struct libinput *li = tp_libinput_context(tp);
WacomDeviceDatabase *db = NULL;
WacomDevice **devices = NULL,
**d;
WacomDevice *dev;
uint32_t vid = evdev_device_get_id_vendor(device),
pid = evdev_device_get_id_product(device);
if ((device->tags & EVDEV_TAG_TABLET_TOUCHPAD) == 0)
goto out;
db = libinput_libwacom_ref(li);
if (!db)
goto out;
/* Check if we have a device with the same vid/pid. If not,
we need to loop through all devices and check their paired
device. */
dev = libwacom_new_from_usbid(db, vid, pid, NULL);
if (dev) {
rotate = libwacom_is_reversible(dev);
libwacom_destroy(dev);
goto out;
}
devices = libwacom_list_devices_from_database(db, NULL);
if (!devices)
goto out;
d = devices;
while(*d) {
const WacomMatch *paired;
paired = libwacom_get_paired_device(*d);
if (paired &&
libwacom_match_get_vendor_id(paired) == vid &&
libwacom_match_get_product_id(paired) == pid) {
rotate = libwacom_is_reversible(dev);
break;
}
d++;
}
free(devices);
out:
/* We don't need to keep it around for the touchpad, we're done with
* it until the device dies. */
if (db)
libinput_libwacom_unref(li);
#endif
return rotate;
}
static void
tp_init_left_handed(struct tp_dispatch *tp,
struct evdev_device *device)
{
bool want_left_handed = true;
tp->left_handed.must_rotate = tp_requires_rotation(tp, device);
if (device->model_flags & EVDEV_MODEL_APPLE_TOUCHPAD_ONEBUTTON)
want_left_handed = false;
if (want_left_handed)
evdev_init_left_handed(device, tp_change_to_left_handed);
}
struct evdev_dispatch *
evdev_mt_touchpad_create(struct evdev_device *device)
{
struct tp_dispatch *tp;
evdev_tag_touchpad(device, device->udev_device);
tp = zalloc(sizeof *tp);
if (!tp_init(tp, device)) {
tp_interface_destroy(&tp->base);
return NULL;
}
device->base.config.sendevents = &tp->sendevents.config;
tp->sendevents.current_mode = LIBINPUT_CONFIG_SEND_EVENTS_ENABLED;
tp->sendevents.config.get_modes = tp_sendevents_get_modes;
tp->sendevents.config.set_mode = tp_sendevents_set_mode;
tp->sendevents.config.get_mode = tp_sendevents_get_mode;
tp->sendevents.config.get_default_mode = tp_sendevents_get_default_mode;
tp_init_left_handed(tp, device);
return &tp->base;
}
libinput-1.28.1/src/evdev-mt-touchpad.h000066400000000000000000000457661477265155700177720ustar00rootroot00000000000000/*
* Copyright © 2014-2015 Red Hat, Inc.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice (including the next
* paragraph) shall be included in all copies or substantial portions of the
* Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
*/
#ifndef EVDEV_MT_TOUCHPAD_H
#define EVDEV_MT_TOUCHPAD_H
#include
#include "evdev.h"
#include "timer.h"
#define TOUCHPAD_HISTORY_LENGTH 4
#define TOUCHPAD_MIN_SAMPLES 4
/* Convert mm to a distance normalized to DEFAULT_MOUSE_DPI */
#define TP_MM_TO_DPI_NORMALIZED(mm) (DEFAULT_MOUSE_DPI/25.4 * mm)
enum touchpad_event {
TOUCHPAD_EVENT_NONE = 0,
TOUCHPAD_EVENT_MOTION = bit(0),
TOUCHPAD_EVENT_BUTTON_PRESS = bit(1),
TOUCHPAD_EVENT_BUTTON_RELEASE = bit(2),
TOUCHPAD_EVENT_OTHERAXIS = bit(3),
TOUCHPAD_EVENT_TIMESTAMP = bit(4),
};
enum touch_state {
TOUCH_NONE = 0,
TOUCH_HOVERING = 1,
TOUCH_BEGIN = 2,
TOUCH_UPDATE = 3,
TOUCH_MAYBE_END = 4,
TOUCH_END = 5,
};
static inline const char *
touch_state_to_str(enum touch_state state)
{
switch(state) {
CASE_RETURN_STRING(TOUCH_NONE);
CASE_RETURN_STRING(TOUCH_HOVERING);
CASE_RETURN_STRING(TOUCH_BEGIN);
CASE_RETURN_STRING(TOUCH_UPDATE);
CASE_RETURN_STRING(TOUCH_MAYBE_END);
CASE_RETURN_STRING(TOUCH_END);
}
return NULL;
}
enum touch_palm_state {
PALM_NONE = 0,
PALM_EDGE,
PALM_TYPING,
PALM_TRACKPOINT,
PALM_TOOL_PALM,
PALM_PRESSURE,
PALM_TOUCH_SIZE,
PALM_ARBITRATION,
};
enum button_event {
BUTTON_EVENT_IN_BOTTOM_R = 30,
BUTTON_EVENT_IN_BOTTOM_M,
BUTTON_EVENT_IN_BOTTOM_L,
BUTTON_EVENT_IN_TOP_R,
BUTTON_EVENT_IN_TOP_M,
BUTTON_EVENT_IN_TOP_L,
BUTTON_EVENT_IN_AREA,
BUTTON_EVENT_UP,
BUTTON_EVENT_PRESS,
BUTTON_EVENT_RELEASE,
BUTTON_EVENT_TIMEOUT,
};
enum button_state {
BUTTON_STATE_NONE,
BUTTON_STATE_AREA,
BUTTON_STATE_BOTTOM,
BUTTON_STATE_TOP,
BUTTON_STATE_TOP_NEW,
BUTTON_STATE_TOP_TO_IGNORE,
BUTTON_STATE_IGNORE,
};
enum tp_tap_state {
TAP_STATE_IDLE = 4,
TAP_STATE_TOUCH,
TAP_STATE_HOLD,
TAP_STATE_1FGTAP_TAPPED,
TAP_STATE_2FGTAP_TAPPED,
TAP_STATE_3FGTAP_TAPPED,
TAP_STATE_TOUCH_2,
TAP_STATE_TOUCH_2_HOLD,
TAP_STATE_TOUCH_2_RELEASE,
TAP_STATE_TOUCH_3,
TAP_STATE_TOUCH_3_HOLD,
TAP_STATE_TOUCH_3_RELEASE,
TAP_STATE_TOUCH_3_RELEASE_2,
TAP_STATE_1FGTAP_DRAGGING_OR_DOUBLETAP,
TAP_STATE_2FGTAP_DRAGGING_OR_DOUBLETAP,
TAP_STATE_3FGTAP_DRAGGING_OR_DOUBLETAP,
TAP_STATE_1FGTAP_DRAGGING_OR_TAP,
TAP_STATE_2FGTAP_DRAGGING_OR_TAP,
TAP_STATE_3FGTAP_DRAGGING_OR_TAP,
TAP_STATE_1FGTAP_DRAGGING,
TAP_STATE_2FGTAP_DRAGGING,
TAP_STATE_3FGTAP_DRAGGING,
TAP_STATE_1FGTAP_DRAGGING_WAIT,
TAP_STATE_2FGTAP_DRAGGING_WAIT,
TAP_STATE_3FGTAP_DRAGGING_WAIT,
TAP_STATE_1FGTAP_DRAGGING_2,
TAP_STATE_2FGTAP_DRAGGING_2,
TAP_STATE_3FGTAP_DRAGGING_2,
TAP_STATE_DEAD, /**< finger count exceeded */
};
enum tp_tap_touch_state {
TAP_TOUCH_STATE_IDLE = 16, /**< not in touch */
TAP_TOUCH_STATE_TOUCH, /**< touching, may tap */
TAP_TOUCH_STATE_DEAD, /**< exceeded motion/timeout */
};
/* For edge scrolling, so we only care about right and bottom */
enum tp_edge {
EDGE_NONE = 0,
EDGE_RIGHT = bit(0),
EDGE_BOTTOM = bit(1),
};
enum tp_edge_scroll_touch_state {
EDGE_SCROLL_TOUCH_STATE_NONE,
EDGE_SCROLL_TOUCH_STATE_EDGE_NEW,
EDGE_SCROLL_TOUCH_STATE_EDGE,
EDGE_SCROLL_TOUCH_STATE_AREA,
};
enum tp_gesture_state {
GESTURE_STATE_NONE,
GESTURE_STATE_UNKNOWN,
GESTURE_STATE_HOLD,
GESTURE_STATE_HOLD_AND_MOTION,
GESTURE_STATE_POINTER_MOTION,
GESTURE_STATE_SCROLL_START,
GESTURE_STATE_SCROLL,
GESTURE_STATE_PINCH_START,
GESTURE_STATE_PINCH,
GESTURE_STATE_SWIPE_START,
GESTURE_STATE_SWIPE,
GESTURE_STATE_3FG_DRAG_START,
GESTURE_STATE_3FG_DRAG,
GESTURE_STATE_3FG_DRAG_RELEASED,
};
enum tp_thumb_state {
THUMB_STATE_FINGER,
THUMB_STATE_JAILED,
THUMB_STATE_PINCH,
THUMB_STATE_SUPPRESSED,
THUMB_STATE_REVIVED,
THUMB_STATE_REVIVED_JAILED,
THUMB_STATE_DEAD,
};
enum tp_jump_state {
JUMP_STATE_IGNORE = 0,
JUMP_STATE_EXPECT_FIRST,
JUMP_STATE_EXPECT_DELAY,
};
struct tp_touch {
struct tp_dispatch *tp;
unsigned int index;
enum touch_state state;
bool has_ended; /* TRACKING_ID == -1 */
bool dirty;
struct device_coords point;
uint64_t initial_time;
int pressure;
bool is_tool_palm; /* MT_TOOL_PALM */
int major, minor;
bool was_down; /* if distance == 0, false for pure hovering
touches */
struct {
/* A quirk mostly used on Synaptics touchpads. In a
transition to/from fake touches > num_slots, the current
event data is likely garbage and the subsequent event
is likely too. This marker tells us to reset the motion
history again -> this effectively swallows any motion */
bool reset_motion_history;
} quirks;
struct {
struct tp_history_point {
uint64_t time;
struct device_coords point;
} samples[TOUCHPAD_HISTORY_LENGTH];
unsigned int index;
unsigned int count;
} history;
struct {
double last_delta_mm;
} jumps;
struct {
struct device_coords center;
uint8_t x_motion_history;
} hysteresis;
/* A pinned touchpoint is the one that pressed the physical button
* on a clickpad. After the release, it won't move until the center
* moves more than a threshold away from the original coordinates
*/
struct {
bool is_pinned;
struct device_coords center;
} pinned;
/* Software-button state and timeout if applicable */
struct {
enum button_state state;
/* We use button_event here so we can use == on events */
enum button_event current;
struct libinput_timer timer;
struct device_coords initial;
bool has_moved; /* has moved more than threshold */
uint64_t initial_time;
} button;
struct {
enum tp_tap_touch_state state;
struct device_coords initial;
bool is_thumb;
bool is_palm;
} tap;
struct {
enum tp_edge_scroll_touch_state edge_state;
uint32_t edge;
int direction;
struct libinput_timer timer;
struct device_coords initial;
} scroll;
struct {
enum touch_palm_state state;
struct device_coords first; /* first coordinates if is_palm == true */
uint64_t time; /* first timestamp if is_palm == true */
} palm;
struct {
struct device_coords initial;
} gesture;
struct {
double last_speed; /* speed in mm/s at last sample */
unsigned int exceeded_count;
} speed;
};
enum suspend_trigger {
SUSPEND_NO_FLAG = 0x0,
SUSPEND_EXTERNAL_MOUSE = 0x1,
SUSPEND_SENDEVENTS = 0x2,
SUSPEND_LID = 0x4,
SUSPEND_TABLET_MODE = 0x8,
};
struct tp_dispatch {
struct evdev_dispatch base;
struct evdev_device *device;
unsigned int nfingers_down; /* number of fingers down */
unsigned int old_nfingers_down; /* previous no fingers down */
unsigned int slot; /* current slot */
bool has_mt;
bool semi_mt;
uint32_t suspend_reason;
/* pen/touch arbitration */
struct {
enum evdev_arbitration_state state;
struct libinput_timer arbitration_timer;
} arbitration;
unsigned int nactive_slots; /* number of active slots */
unsigned int num_slots; /* number of slots */
unsigned int ntouches; /* no slots inc. fakes */
struct tp_touch *touches; /* len == ntouches */
/* bit 0: BTN_TOUCH
* bit 1: BTN_TOOL_FINGER
* bit 2: BTN_TOOL_DOUBLETAP
* ...
*/
unsigned int fake_touches;
struct {
bool detection_disabled;
struct ratelimit warning;
} jump;
/* if pressure goes above high -> touch down,
if pressure then goes below low -> touch up */
struct {
bool use_pressure;
int high;
int low;
} pressure;
/* If touch size (either axis) goes above high -> touch down,
if touch size (either axis) goes below low -> touch up */
struct {
bool use_touch_size;
int high;
int low;
/* convert device units to angle */
double orientation_to_angle;
} touch_size;
struct {
bool enabled;
struct device_coords margin;
unsigned int other_event_count;
uint64_t last_motion_time;
} hysteresis;
struct {
double x_scale_coeff;
double y_scale_coeff;
double xy_scale_coeff;
} accel;
struct {
struct libinput_device_config_gesture config;
bool enabled;
unsigned int finger_count;
unsigned int finger_count_pending;
struct libinput_timer finger_count_switch_timer;
enum tp_gesture_state state;
struct tp_touch *touches[2];
uint64_t initial_time;
double initial_distance;
double prev_scale;
double angle;
struct device_float_coords center;
struct libinput_timer hold_timer;
bool hold_enabled;
struct libinput_timer drag_3fg_timer;
uint64_t drag_3fg_release_time;
} gesture;
struct {
bool is_clickpad; /* true for clickpads */
bool has_topbuttons;
bool use_clickfinger; /* number of fingers decides button number */
bool click_pending;
uint32_t state;
uint32_t old_state;
struct {
double x_scale_coeff;
double y_scale_coeff;
} motion_dist; /* for pinned touches */
unsigned int active; /* currently active button, for release event */
bool active_is_topbutton; /* is active a top button? */
/* Only used for clickpads. The software button areas are
* always 2 horizontal stripes across the touchpad.
* The buttons are split according to the edge settings.
*/
struct {
int32_t top_edge; /* in device coordinates */
int32_t rightbutton_left_edge; /* in device coordinates */
int32_t middlebutton_left_edge; /* in device coordinates */
} bottom_area;
struct {
int32_t bottom_edge; /* in device coordinates */
int32_t rightbutton_left_edge; /* in device coordinates */
int32_t leftbutton_right_edge; /* in device coordinates */
} top_area;
struct evdev_device *trackpoint;
enum libinput_config_click_method click_method;
struct libinput_device_config_click_method config_method;
enum libinput_config_clickfinger_button_map map;
enum libinput_config_clickfinger_button_map want_map;
} buttons;
struct {
struct libinput_device_config_scroll_method config_method;
enum libinput_config_scroll_method method;
int32_t right_edge; /* in device coordinates */
int32_t bottom_edge; /* in device coordinates */
struct {
bool h, v;
} active;
struct phys_coords vector;
uint64_t time_prev;
struct {
uint64_t h, v;
} duration;
} scroll;
enum touchpad_event queued;
struct {
struct libinput_device_config_tap config;
bool enabled;
bool suspended;
struct libinput_timer timer;
enum tp_tap_state state;
uint32_t buttons_pressed;
uint64_t saved_press_time,
saved_release_time;
enum libinput_config_tap_button_map map;
enum libinput_config_tap_button_map want_map;
bool drag_enabled;
enum libinput_config_drag_lock_state drag_lock;
unsigned int nfingers_down; /* number of fingers down for tapping (excl. thumb/palm) */
} tap;
struct {
struct libinput_device_config_3fg_drag config;
size_t nfingers;
size_t want_nfingers;
} drag_3fg;
struct {
struct libinput_device_config_dwtp config;
bool dwtp_enabled;
int32_t right_edge; /* in device coordinates */
int32_t left_edge; /* in device coordinates */
int32_t upper_edge; /* in device coordinates */
bool trackpoint_active;
struct libinput_event_listener trackpoint_listener;
struct libinput_timer trackpoint_timer;
uint64_t trackpoint_last_event_time;
uint32_t trackpoint_event_count;
bool monitor_trackpoint;
bool use_mt_tool;
bool use_pressure;
int pressure_threshold;
bool use_size;
int size_threshold;
} palm;
struct {
struct libinput_device_config_send_events config;
enum libinput_config_send_events_mode current_mode;
} sendevents;
struct {
struct libinput_device_config_dwt config;
bool dwt_enabled;
/* We have to allow for more than one device node to be the
* internal dwt keyboard (Razer Blade). But they're the same
* physical device, so we don't care about per-keyboard
* key/modifier masks.
*/
struct list paired_keyboard_list;
unsigned long key_mask[NLONGS(KEY_CNT)];
unsigned long mod_mask[NLONGS(KEY_CNT)];
bool keyboard_active;
struct libinput_timer keyboard_timer;
uint64_t keyboard_last_press_time;
} dwt;
struct {
bool detect_thumbs;
int upper_thumb_line;
int lower_thumb_line;
bool use_pressure;
int pressure_threshold;
bool use_size;
int size_threshold;
enum tp_thumb_state state;
unsigned int index;
bool pinch_eligible;
} thumb;
struct {
/* A quirk used on the T450 series Synaptics hardware.
* Slowly moving the finger causes multiple events with only
* ABS_MT_PRESSURE but no x/y information. When the x/y
* event comes, it will be a jump of ~20 units. We use the
* below to count non-motion events to discard that first
* event with the jump.
*/
unsigned int nonmotion_event_count;
struct msc_timestamp {
enum tp_jump_state state;
uint32_t interval;
uint32_t now;
} msc_timestamp;
} quirks;
struct {
struct libinput_event_listener listener;
struct evdev_device *lid_switch;
} lid_switch;
struct {
struct libinput_event_listener listener;
struct evdev_device *tablet_mode_switch;
} tablet_mode_switch;
struct {
bool rotate;
bool want_rotate;
bool must_rotate; /* true if we should rotate when applicable */
struct evdev_device *tablet_device;
bool tablet_left_handed_state;
} left_handed;
};
static inline struct tp_dispatch*
tp_dispatch(struct evdev_dispatch *dispatch)
{
evdev_verify_dispatch_type(dispatch, DISPATCH_TOUCHPAD);
return container_of(dispatch, struct tp_dispatch, base);
}
#define tp_for_each_touch(_tp, _t) \
for (unsigned int _i = 0; _i < (_tp)->ntouches && (_t = &(_tp)->touches[_i]); _i++)
static inline struct libinput*
tp_libinput_context(const struct tp_dispatch *tp)
{
return evdev_libinput_context(tp->device);
}
static inline struct normalized_coords
tp_normalize_delta(const struct tp_dispatch *tp,
struct device_float_coords delta)
{
struct normalized_coords normalized;
normalized.x = delta.x * tp->accel.x_scale_coeff;
normalized.y = delta.y * tp->accel.y_scale_coeff;
return normalized;
}
static inline struct phys_coords
tp_phys_delta(const struct tp_dispatch *tp,
struct device_float_coords delta)
{
struct phys_coords mm;
mm.x = delta.x / tp->device->abs.absinfo_x->resolution;
mm.y = delta.y / tp->device->abs.absinfo_y->resolution;
return mm;
}
/**
* Takes a set of device coordinates, returns that set of coordinates in the
* x-axis' resolution.
*/
static inline struct device_float_coords
tp_scale_to_xaxis(const struct tp_dispatch *tp,
struct device_float_coords delta)
{
struct device_float_coords raw;
raw.x = delta.x;
raw.y = delta.y * tp->accel.xy_scale_coeff;
return raw;
}
struct device_coords
tp_get_delta(struct tp_touch *t);
struct normalized_coords
tp_filter_motion(struct tp_dispatch *tp,
const struct device_float_coords *unaccelerated,
uint64_t time);
struct normalized_coords
tp_filter_motion_unaccelerated(struct tp_dispatch *tp,
const struct device_float_coords *unaccelerated,
uint64_t time);
struct normalized_coords
tp_filter_scroll(struct tp_dispatch *tp,
const struct device_float_coords *unaccelerated,
uint64_t time);
bool
tp_touch_active(const struct tp_dispatch *tp, const struct tp_touch *t);
bool
tp_touch_active_for_gesture(const struct tp_dispatch *tp,
const struct tp_touch *t);
int
tp_tap_handle_state(struct tp_dispatch *tp, uint64_t time);
void
tp_tap_post_process_state(struct tp_dispatch *tp);
void
tp_button_post_process_state(struct tp_dispatch *tp);
void
tp_init_tap(struct tp_dispatch *tp);
void
tp_remove_tap(struct tp_dispatch *tp);
void
tp_init_buttons(struct tp_dispatch *tp, struct evdev_device *device);
void
tp_init_top_softbuttons(struct tp_dispatch *tp,
struct evdev_device *device,
double topbutton_size_mult);
void
tp_remove_buttons(struct tp_dispatch *tp);
void
tp_process_button(struct tp_dispatch *tp,
const struct input_event *e,
uint64_t time);
void
tp_release_all_buttons(struct tp_dispatch *tp,
uint64_t time);
int
tp_post_button_events(struct tp_dispatch *tp, uint64_t time);
void
tp_button_handle_state(struct tp_dispatch *tp, uint64_t time);
bool
tp_button_touch_active(const struct tp_dispatch *tp,
const struct tp_touch *t);
bool
tp_button_is_inside_softbutton_area(const struct tp_dispatch *tp,
const struct tp_touch *t);
void
tp_release_all_taps(struct tp_dispatch *tp,
uint64_t now);
void
tp_tap_suspend(struct tp_dispatch *tp, uint64_t time);
void
tp_tap_resume(struct tp_dispatch *tp, uint64_t time);
bool
tp_tap_dragging(const struct tp_dispatch *tp);
bool
tp_tap_dragging_or_double_tapping(const struct tp_dispatch *tp);
void
tp_edge_scroll_init(struct tp_dispatch *tp, struct evdev_device *device);
void
tp_remove_edge_scroll(struct tp_dispatch *tp);
void
tp_edge_scroll_handle_state(struct tp_dispatch *tp, uint64_t time);
int
tp_edge_scroll_post_events(struct tp_dispatch *tp, uint64_t time);
void
tp_edge_scroll_stop_events(struct tp_dispatch *tp, uint64_t time);
int
tp_edge_scroll_touch_active(const struct tp_dispatch *tp,
const struct tp_touch *t);
uint32_t
tp_touch_get_edge(const struct tp_dispatch *tp, const struct tp_touch *t);
void
tp_init_gesture(struct tp_dispatch *tp);
void
tp_remove_gesture(struct tp_dispatch *tp);
void
tp_gesture_stop(struct tp_dispatch *tp, uint64_t time);
void
tp_gesture_cancel(struct tp_dispatch *tp, uint64_t time);
void
tp_gesture_cancel_motion_gestures(struct tp_dispatch *tp, uint64_t time);
void
tp_gesture_update_finger_state(struct tp_dispatch *tp, uint64_t time);
void
tp_gesture_post_events(struct tp_dispatch *tp, uint64_t time,
bool ignore_motion);
void
tp_gesture_stop_twofinger_scroll(struct tp_dispatch *tp, uint64_t time);
void
tp_gesture_tap_timeout(struct tp_dispatch *tp, uint64_t time);
void
tp_clickpad_middlebutton_apply_config(struct evdev_device *device);
bool
tp_thumb_ignored(const struct tp_dispatch *tp, const struct tp_touch *t);
void
tp_thumb_reset(struct tp_dispatch *tp);
bool
tp_thumb_ignored_for_gesture(const struct tp_dispatch *tp, const struct tp_touch *t);
bool
tp_thumb_ignored_for_tap(const struct tp_dispatch *tp,
const struct tp_touch *t);
void
tp_thumb_suppress(struct tp_dispatch *tp, struct tp_touch *t);
void
tp_thumb_update_touch(struct tp_dispatch *tp,
struct tp_touch *t,
uint64_t time);
void
tp_detect_thumb_while_moving(struct tp_dispatch *tp);
void
tp_thumb_update_multifinger(struct tp_dispatch *tp);
void
tp_init_thumb(struct tp_dispatch *tp);
struct tp_touch*
tp_thumb_get_touch(struct tp_dispatch *tp);
void
tp_3fg_drag_apply_config(struct evdev_device *device);
#endif
libinput-1.28.1/src/evdev-tablet-pad-leds.c000066400000000000000000000417341477265155700204710ustar00rootroot00000000000000/*
* Copyright © 2016 Red Hat, Inc.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice (including the next
* paragraph) shall be included in all copies or substantial portions of the
* Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
*/
#include "config.h"
#include
#include
#include "evdev-tablet-pad.h"
#if HAVE_LIBWACOM
#include
#endif
/* We only have 4 modes on current devices but
* anything other than MODE_NEXT is used as
* numeric value anyway so it doesn't matter if a value is
* missing here
*
* Once libwacom 2.15 is commonplace we can use the
* libwacom enum directly.
*/
enum pad_toggle_button_target_mode {
MODE_NEXT = -1,
MODE_0,
MODE_1,
MODE_2,
MODE_3,
};
struct pad_led_group {
struct libinput_tablet_pad_mode_group base;
struct list led_list;
struct list toggle_button_list;
};
struct pad_mode_toggle_button {
struct list link;
unsigned int button_index;
enum pad_toggle_button_target_mode target_mode;
};
struct pad_mode_led {
struct list link;
/* /sys/devices/..../input1235/input1235::wacom-led_0.1/brightness */
int brightness_fd;
int mode_idx;
};
static inline void
pad_mode_toggle_button_destroy(struct pad_mode_toggle_button* button)
{
list_remove(&button->link);
free(button);
}
static inline int
pad_led_group_get_mode(struct pad_led_group *group)
{
char buf[4] = {0};
int rc;
unsigned int brightness;
struct pad_mode_led *led;
list_for_each(led, &group->led_list, link) {
rc = lseek(led->brightness_fd, 0, SEEK_SET);
if (rc == -1)
return -errno;
rc = read(led->brightness_fd, buf, sizeof(buf) - 1);
if (rc == -1)
return -errno;
rc = sscanf(buf, "%u\n", &brightness);
if (rc != 1)
return -EINVAL;
/* Assumption: only one LED lit up at any time */
if (brightness != 0)
return led->mode_idx;
}
/* Wacom PTH-660 doesn't light up any LEDs
* until the button is pressed, so let's assume mode 0 */
return 0;
}
static inline void
pad_led_destroy(struct libinput *libinput,
struct pad_mode_led *led)
{
list_remove(&led->link);
if (led->brightness_fd != -1)
close_restricted(libinput, led->brightness_fd);
free(led);
}
#if HAVE_LIBWACOM
static inline struct pad_mode_led *
pad_led_new(struct libinput *libinput, const char *prefix, int group, int mode)
{
struct pad_mode_led *led;
char path[PATH_MAX];
int rc, fd, save_errno;
led = zalloc(sizeof *led);
led->brightness_fd = -1;
led->mode_idx = mode;
list_init(&led->link);
/* /sys/devices/..../input1235/input1235::wacom-0.1/brightness,
* where 0 and 1 are group and mode index. */
rc = snprintf(path,
sizeof(path),
"%s%d.%d/brightness",
prefix,
group,
mode);
if (rc == -1)
goto error;
fd = open_restricted(libinput, path, O_RDONLY | O_NONBLOCK | O_CLOEXEC);
if (fd < 0) {
errno = -fd;
goto error;
}
led->brightness_fd = fd;
return led;
error:
save_errno = errno;
pad_led_destroy(libinput, led);
errno = save_errno;
return NULL;
}
#endif /* HAVE_LIBWACOM */
static void
pad_led_group_destroy(struct libinput_tablet_pad_mode_group *g)
{
struct pad_led_group *group = (struct pad_led_group *)g;
struct pad_mode_toggle_button *button;
struct pad_mode_led *led;
list_for_each_safe(button, &group->toggle_button_list, link)
pad_mode_toggle_button_destroy(button);
list_for_each_safe(led, &group->led_list, link)
pad_led_destroy(g->device->seat->libinput, led);
free(group);
}
static struct pad_led_group *
pad_group_new(struct pad_dispatch *pad,
unsigned int group_index,
int num_modes)
{
struct pad_led_group *group;
group = zalloc(sizeof *group);
group->base.device = &pad->device->base;
group->base.refcount = 1;
group->base.index = group_index;
group->base.current_mode = 0;
group->base.num_modes = num_modes;
group->base.destroy = pad_led_group_destroy;
list_init(&group->toggle_button_list);
list_init(&group->led_list);
return group;
}
static inline struct libinput_tablet_pad_mode_group *
pad_get_mode_group(struct pad_dispatch *pad, unsigned int index)
{
struct libinput_tablet_pad_mode_group *group;
list_for_each(group, &pad->modes.mode_group_list, link) {
if (group->index == index)
return group;
}
return NULL;
}
#if HAVE_LIBWACOM
static inline bool
is_litest_device(struct evdev_device *device)
{
return !!udev_device_get_property_value(device->udev_device,
"LIBINPUT_TEST_DEVICE");
}
static inline struct pad_mode_toggle_button *
pad_mode_toggle_button_new(unsigned int button_index)
{
struct pad_mode_toggle_button *button;
button = zalloc(sizeof *button);
button->button_index = button_index;
button->target_mode = MODE_NEXT;
return button;
}
static int
pad_led_group_add_toggle_button(struct pad_led_group *group,
int button_index,
enum pad_toggle_button_target_mode mode)
{
struct pad_mode_toggle_button *button;
button = pad_mode_toggle_button_new(button_index);
if (!button)
return -ENOMEM;
button->target_mode = mode;
list_append(&group->toggle_button_list, &button->link);
group->base.toggle_button_mask |= bit(button_index);
group->base.button_mask |= bit(button_index);
return 0;
}
static inline bool
pad_led_get_sysfs_base_path(struct evdev_device *device,
char *path_out,
size_t path_out_sz)
{
struct udev_device *parent, *udev_device;
const char *test_path;
int rc;
udev_device = device->udev_device;
/* For testing purposes only allow for a base path set through a
* udev rule. We still expect the normal directory hierarchy inside */
test_path = udev_device_get_property_value(udev_device,
"LIBINPUT_TEST_TABLET_PAD_SYSFS_PATH");
if (test_path) {
rc = snprintf(path_out, path_out_sz, "%s", test_path);
return rc != -1;
}
parent = udev_device_get_parent_with_subsystem_devtype(udev_device,
"input",
NULL);
if (!parent)
return false;
rc = snprintf(path_out,
path_out_sz,
"%s/%s::wacom-",
udev_device_get_syspath(parent),
udev_device_get_sysname(parent));
return rc != -1;
}
static int
pad_add_mode_group(struct pad_dispatch *pad,
struct evdev_device *device,
unsigned int group_index,
int nmodes,
int button_index,
enum pad_toggle_button_target_mode mode,
uint32_t ring_mask,
uint32_t strip_mask,
uint32_t dial_mask,
bool create_leds)
{
struct libinput *li = pad_libinput_context(pad);
struct pad_led_group *group = NULL;
int rc = -ENOMEM;
char syspath[PATH_MAX];
/* syspath is /sys/class/leds/input1234/input12345::wacom-" and
only needs the group + mode appended */
if (!pad_led_get_sysfs_base_path(device, syspath, sizeof(syspath)))
return -ENOMEM;
group = pad_group_new(pad, group_index, nmodes);
if (!group)
goto out;
group->base.ring_mask = ring_mask;
group->base.strip_mask = strip_mask;
group->base.dial_mask = dial_mask;
group->base.button_mask |= bit(button_index);
rc = pad_led_group_add_toggle_button(group, button_index, mode);
if (rc < 0)
goto out;
for (int mode = 0; create_leds && mode < nmodes; mode++) {
struct pad_mode_led *led;
led = pad_led_new(li, syspath, group_index, mode);
if (!led) {
rc = -errno;
goto out;
}
list_append(&group->led_list, &led->link);
}
if (create_leds) {
rc = pad_led_group_get_mode(group);
if (rc < 0) {
goto out;
}
}
list_insert(&pad->modes.mode_group_list, &group->base.link);
rc = 0;
out:
if (rc)
pad_led_group_destroy(&group->base);
return rc;
}
static int
pad_fetch_group_index(struct pad_dispatch *pad,
WacomDevice *wacom,
int button_index)
{
char btn = 'A' + button_index;
WacomButtonFlags flags = libwacom_get_button_flag(wacom, btn);
int led_group = libwacom_get_button_led_group(wacom, btn);
if ((flags & WACOM_BUTTON_MODESWITCH) == 0) {
evdev_log_bug_libinput(pad->device,
"Cannot fetch group index for non-mode toggle button %c\n", btn);
return -1;
}
if (led_group >= 0)
return led_group;
/* Note on group_index: libwacom gives us the led_group
* but this is really just the index of the entry in
* the StatusLEDs line. This is effectively always
* 0 for the first ring or strip and 1 for the second
* ring or strip. The few devices that matter
* have either a pair of rings or strips, not mixed.
*
* Which means for devices where we don't have StatusLEDs
* we can hardcode this behavior, if we ever get a ring+strip
* devcice we need to update libwacom for that anyway.
*/
int group_index = -1;
switch (flags & WACOM_BUTTON_MODESWITCH) {
case WACOM_BUTTON_RING_MODESWITCH:
group_index = 0;
break;
case WACOM_BUTTON_RING2_MODESWITCH:
group_index = 1;
break;
case WACOM_BUTTON_TOUCHSTRIP_MODESWITCH:
group_index = 0;
break;
case WACOM_BUTTON_TOUCHSTRIP2_MODESWITCH:
group_index = 1;
break;
#ifdef HAVE_LIBWACOM_BUTTON_DIAL_MODESWITCH
case WACOM_BUTTON_DIAL_MODESWITCH:
group_index = 0;
break;
case WACOM_BUTTON_DIAL2_MODESWITCH:
group_index = 1;
break;
#endif
}
return group_index;
}
static inline int
pad_find_button_group(struct pad_dispatch *pad,
WacomDevice *wacom,
int button_index,
WacomButtonFlags button_flags)
{
int i;
WacomButtonFlags flags;
for (i = 0; i < libwacom_get_num_buttons(wacom); i++) {
if (i == button_index)
continue;
flags = libwacom_get_button_flag(wacom, 'A' + i);
if ((flags & WACOM_BUTTON_MODESWITCH) == 0)
continue;
if ((flags & WACOM_BUTTON_DIRECTION) ==
(button_flags & WACOM_BUTTON_DIRECTION))
return pad_fetch_group_index(pad, wacom, i);
}
return -1;
}
static enum pad_toggle_button_target_mode
pad_button_target_mode(WacomDevice *wacom, char button)
{
#ifdef HAVE_LIBWACOM_BUTTON_MODESWITCH_MODE
switch (libwacom_get_button_modeswitch_mode(wacom, button)) {
case WACOM_MODE_SWITCH_NEXT: return MODE_NEXT;
case WACOM_MODE_SWITCH_0: return MODE_0;
case WACOM_MODE_SWITCH_1: return MODE_1;
case WACOM_MODE_SWITCH_2: return MODE_2;
case WACOM_MODE_SWITCH_3: return MODE_3;
}
#endif
return MODE_NEXT;
}
static int
pad_init_leds_from_libwacom(struct pad_dispatch *pad,
struct evdev_device *device,
WacomDevice *wacom)
{
int rc = -EINVAL;
if (!wacom)
return -ENOENT;
for (int b = 0; b < libwacom_get_num_buttons(wacom); b++) {
char btn = 'A' + b;
WacomButtonFlags flags = libwacom_get_button_flag(wacom, btn);
int nmodes = 0;
uint32_t ring_mask = 0;
uint32_t strip_mask = 0;
uint32_t dial_mask = 0;
bool have_status_led = false;
if ((flags & WACOM_BUTTON_MODESWITCH) == 0)
continue;
enum pad_toggle_button_target_mode target_mode = pad_button_target_mode(wacom, btn);
int group_index = pad_fetch_group_index(pad, wacom, b);
switch (flags & WACOM_BUTTON_MODESWITCH) {
case WACOM_BUTTON_RING_MODESWITCH:
nmodes = libwacom_get_ring_num_modes(wacom);
ring_mask = 0x1;
break;
case WACOM_BUTTON_RING2_MODESWITCH:
nmodes = libwacom_get_ring2_num_modes(wacom);
ring_mask = 0x2;
break;
case WACOM_BUTTON_TOUCHSTRIP_MODESWITCH:
nmodes = libwacom_get_strips_num_modes(wacom);
strip_mask = 0x1;
break;
case WACOM_BUTTON_TOUCHSTRIP2_MODESWITCH:
/* there is no get_strips2_... */
nmodes = libwacom_get_strips_num_modes(wacom);
strip_mask = 0x2;
break;
#ifdef HAVE_LIBWACOM_BUTTON_DIAL_MODESWITCH
case WACOM_BUTTON_DIAL_MODESWITCH:
nmodes = libwacom_get_dial_num_modes(wacom);
dial_mask = 0x1;
break;
case WACOM_BUTTON_DIAL2_MODESWITCH:
nmodes = libwacom_get_dial2_num_modes(wacom);
dial_mask = 0x2;
break;
#endif
default:
evdev_log_error(pad->device,
"unable to init pad mode group: button %c has multiple modeswitch flags 0x%x\n",
btn, flags);
goto out;
}
have_status_led = libwacom_get_button_led_group(wacom, btn) >= 0;
if (nmodes > 1) {
struct libinput_tablet_pad_mode_group *group = pad_get_mode_group(pad, group_index);
if (!group) {
rc = pad_add_mode_group(pad, device, group_index, nmodes, b, target_mode,
ring_mask, strip_mask, dial_mask,
have_status_led);
} else {
struct pad_led_group *led_group = (struct pad_led_group *)group;
/* Multiple toggle buttons (Wacom MobileStudio Pro 16) */
rc = pad_led_group_add_toggle_button(led_group, b, target_mode);
if (rc < 0)
goto out;
}
}
}
if (list_empty(&pad->modes.mode_group_list)) {
rc = 1;
goto out;
}
/* Now loop again to match the other buttons with the existing
* mode groups */
for (int b = 0; b < libwacom_get_num_buttons(wacom); b++) {
char btn = 'A' + b;
WacomButtonFlags flags = libwacom_get_button_flag(wacom, btn);
if ((flags & WACOM_BUTTON_MODESWITCH))
continue;
int group_index = pad_find_button_group(pad, wacom, b, flags);
if (group_index == -1) {
evdev_log_bug_libinput(pad->device,
"unhandled position for button %i\n",
b);
rc = -EINVAL;
goto out;
}
struct libinput_tablet_pad_mode_group *group = pad_get_mode_group(pad, group_index);
if (!group) {
evdev_log_bug_libinput(pad->device,
"Failed to find group %d for button %i\n",
group_index,
b);
rc = -EINVAL;
goto out;
}
group->button_mask |= bit(b);
}
rc = 0;
out:
if (rc != 0) {
if (rc == -ENOENT && is_litest_device(pad->device)) {
evdev_log_error(pad->device,
"unable to init pad mode group: %s\n",
strerror(-rc));
}
pad_destroy_leds(pad);
}
return rc;
}
#endif /* HAVE_LIBWACOM */
static int
pad_init_fallback_group(struct pad_dispatch *pad)
{
struct pad_led_group *group;
group = pad_group_new(pad, 0, 1);
if (!group)
return 1;
/* If we only have one group, all buttons/strips/rings are part of
* that group. We rely on the other layers to filter out invalid
* indices */
group->base.button_mask = -1;
group->base.strip_mask = -1;
group->base.ring_mask = -1;
group->base.dial_mask = -1;
group->base.toggle_button_mask = 0;
list_insert(&pad->modes.mode_group_list, &group->base.link);
return 0;
}
int
pad_init_leds(struct pad_dispatch *pad,
struct evdev_device *device,
WacomDevice *wacom)
{
int rc = 1;
list_init(&pad->modes.mode_group_list);
if (pad->nbuttons > 32) {
evdev_log_bug_libinput(pad->device,
"Too many pad buttons for modes %d\n",
pad->nbuttons);
return rc;
}
/* If libwacom fails, we init one fallback group anyway */
#if HAVE_LIBWACOM
rc = pad_init_leds_from_libwacom(pad, device, wacom);
#endif
if (rc != 0)
rc = pad_init_fallback_group(pad);
return rc;
}
void
pad_destroy_leds(struct pad_dispatch *pad)
{
struct libinput_tablet_pad_mode_group *group;
list_for_each_safe(group, &pad->modes.mode_group_list, link)
libinput_tablet_pad_mode_group_unref(group);
}
void
pad_button_update_mode(struct libinput_tablet_pad_mode_group *g,
unsigned int button_index,
enum libinput_button_state state)
{
struct pad_led_group *group = (struct pad_led_group*)g;
int rc = -ENODEV;
if (state != LIBINPUT_BUTTON_STATE_PRESSED)
return;
if (!libinput_tablet_pad_mode_group_button_is_toggle(g, button_index))
return;
if (list_empty(&group->led_list)) {
struct pad_mode_toggle_button *button;
list_for_each(button, &group->toggle_button_list, link) {
if (button->button_index == button_index) {
if (button->target_mode == MODE_NEXT) {
unsigned int nmodes = group->base.num_modes;
rc = (group->base.current_mode + 1) % nmodes;
} else {
rc = button->target_mode;
}
break;
}
}
} else {
rc = pad_led_group_get_mode(group);
}
if (rc >= 0)
group->base.current_mode = rc;
}
int
evdev_device_tablet_pad_get_num_mode_groups(struct evdev_device *device)
{
struct pad_dispatch *pad = (struct pad_dispatch*)device->dispatch;
struct libinput_tablet_pad_mode_group *group;
int num_groups = 0;
if (!(device->seat_caps & EVDEV_DEVICE_TABLET_PAD))
return -1;
list_for_each(group, &pad->modes.mode_group_list, link)
num_groups++;
return num_groups;
}
struct libinput_tablet_pad_mode_group *
evdev_device_tablet_pad_get_mode_group(struct evdev_device *device,
unsigned int index)
{
struct pad_dispatch *pad = (struct pad_dispatch*)device->dispatch;
if (!(device->seat_caps & EVDEV_DEVICE_TABLET_PAD))
return NULL;
if (index >=
(unsigned int)evdev_device_tablet_pad_get_num_mode_groups(device))
return NULL;
return pad_get_mode_group(pad, index);
}
libinput-1.28.1/src/evdev-tablet-pad.c000066400000000000000000000576461477265155700175550ustar00rootroot00000000000000/*
* Copyright © 2016 Red Hat, Inc.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice (including the next
* paragraph) shall be included in all copies or substantial portions of the
* Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
*/
#include "config.h"
#include "evdev-tablet-pad.h"
#include "util-input-event.h"
#include
#include
#include
#if HAVE_LIBWACOM
#include
#endif
#define pad_set_status(pad_,s_) (pad_)->status |= (s_)
#define pad_unset_status(pad_,s_) (pad_)->status &= ~(s_)
#define pad_has_status(pad_,s_) (!!((pad_)->status & (s_)))
static void
pad_get_buttons_pressed(struct pad_dispatch *pad,
struct button_state *buttons)
{
struct button_state *state = &pad->button_state;
struct button_state *prev_state = &pad->prev_button_state;
unsigned int i;
for (i = 0; i < sizeof(buttons->bits); i++)
buttons->bits[i] = state->bits[i] & ~(prev_state->bits[i]);
}
static void
pad_get_buttons_released(struct pad_dispatch *pad,
struct button_state *buttons)
{
struct button_state *state = &pad->button_state;
struct button_state *prev_state = &pad->prev_button_state;
unsigned int i;
for (i = 0; i < sizeof(buttons->bits); i++)
buttons->bits[i] = prev_state->bits[i] & ~(state->bits[i]);
}
static inline bool
pad_button_is_down(const struct pad_dispatch *pad,
uint32_t button)
{
return bit_is_set(pad->button_state.bits, button);
}
static inline bool
pad_any_button_down(const struct pad_dispatch *pad)
{
const struct button_state *state = &pad->button_state;
unsigned int i;
for (i = 0; i < sizeof(state->bits); i++)
if (state->bits[i] != 0)
return true;
return false;
}
static inline void
pad_button_set_down(struct pad_dispatch *pad,
uint32_t button,
bool is_down)
{
struct button_state *state = &pad->button_state;
if (is_down) {
set_bit(state->bits, button);
pad_set_status(pad, PAD_BUTTONS_PRESSED);
} else {
clear_bit(state->bits, button);
pad_set_status(pad, PAD_BUTTONS_RELEASED);
}
}
static void
pad_process_relative(struct pad_dispatch *pad,
struct evdev_device *device,
struct input_event *e,
uint64_t time)
{
switch (e->code) {
case REL_DIAL:
pad->dials.dial1 = e->value * 120;
pad->changed_axes |= PAD_AXIS_DIAL1;
pad_set_status(pad, PAD_AXES_UPDATED);
break;
case REL_WHEEL:
if (!pad->dials.has_hires_dial) {
pad->dials.dial1 = -1 * e->value * 120;
pad->changed_axes |= PAD_AXIS_DIAL1;
pad_set_status(pad, PAD_AXES_UPDATED);
}
break;
case REL_HWHEEL:
if (!pad->dials.has_hires_dial) {
pad->dials.dial2 = e->value * 120;
pad->changed_axes |= PAD_AXIS_DIAL2;
pad_set_status(pad, PAD_AXES_UPDATED);
}
break;
case REL_WHEEL_HI_RES:
pad->dials.dial1 = -1 * e->value;
pad->changed_axes |= PAD_AXIS_DIAL1;
pad_set_status(pad, PAD_AXES_UPDATED);
break;
case REL_HWHEEL_HI_RES:
pad->dials.dial2 = e->value;
pad->changed_axes |= PAD_AXIS_DIAL2;
pad_set_status(pad, PAD_AXES_UPDATED);
break;
default:
evdev_log_info(device,
"Unhandled EV_REL event code %#x\n",
e->code);
break;
}
}
static void
pad_update_changed_axis(struct pad_dispatch *pad,
enum pad_axes axis,
const struct input_event *e)
{
if (pad->changed_axes & axis) {
evdev_log_bug_kernel_ratelimit(pad->device,
&pad->duplicate_abs_limit,
"Multiple EV_ABS %s events in the same SYN_REPORT\n",
libevdev_event_code_get_name(EV_ABS, e->code));
/* Special heuristics probably good enough:
* if we get multiple EV_ABS in the same SYN_REPORT
* and one of them is zero, assume they're all
* zero and unchanged. That's not perfectly
* correct but probably covers all cases */
if (e->value == 0) {
pad->changed_axes &= ~axis;
if (pad->changed_axes == 0)
pad_unset_status(pad, PAD_AXES_UPDATED);
return;
}
}
pad->changed_axes |= axis;
pad_set_status(pad, PAD_AXES_UPDATED);
}
static void
pad_process_absolute(struct pad_dispatch *pad,
struct evdev_device *device,
struct input_event *e,
uint64_t time)
{
enum pad_axes axis = PAD_AXIS_NONE;
switch (e->code) {
case ABS_WHEEL: axis = PAD_AXIS_RING1; break;
case ABS_THROTTLE: axis = PAD_AXIS_RING2; break;
case ABS_RX: axis = PAD_AXIS_STRIP1; break;
case ABS_RY: axis = PAD_AXIS_STRIP2; break;
case ABS_MISC:
/* The wacom driver always sends a 0 axis event on finger
up, but we also get an ABS_MISC 15 on touch down and
ABS_MISC 0 on touch up, on top of the actual event. This
is kernel behavior for xf86-input-wacom backwards
compatibility after the 3.17 wacom HID move.
We use that event to tell when we truly went a full
rotation around the wheel vs. a finger release.
FIXME: On the Intuos5 and later the kernel merges all
states into that event, so if any finger is down on any
button, the wheel release won't trigger the ABS_MISC 0
but still send a 0 event. We can't currently detect this.
*/
pad->have_abs_misc_terminator = true;
break;
default:
evdev_log_info(device,
"Unhandled EV_ABS event code %#x\n",
e->code);
break;
}
if (axis != PAD_AXIS_NONE) {
pad_update_changed_axis(pad, axis, e);
}
}
static inline double
normalize_wacom_ring(const struct input_absinfo *absinfo)
{
/* libinput has 0 as the ring's northernmost point in the device's
current logical rotation, increasing clockwise to 1. Wacom has
0 on the left-most wheel position.
*/
double range = absinfo_range(absinfo);
double value = (absinfo->value - absinfo->minimum) / range - 0.25;
if (value < 0.0)
value += 1.0;
return value;
}
static inline double
normalize_wacom_strip(const struct input_absinfo *absinfo)
{
/* strip axes don't use a proper value, they just shift the bit left
* for each position. 0 isn't a real value either, it's only sent on
* finger release */
double min = 0,
max = log2(absinfo->maximum);
double range = max - min;
double value = (log2(absinfo->value) - min) / range;
return value;
}
static inline double
normalize_strip(const struct input_absinfo *absinfo)
{
return absinfo_normalize_value(absinfo, absinfo->value);
}
static inline double
pad_handle_ring(struct pad_dispatch *pad,
struct evdev_device *device,
unsigned int code)
{
const struct input_absinfo *absinfo;
double degrees;
absinfo = libevdev_get_abs_info(device->evdev, code);
assert(absinfo);
degrees = normalize_wacom_ring(absinfo) * 360;
if (device->left_handed.enabled)
degrees = fmod(degrees + 180, 360);
return degrees;
}
static inline double
pad_handle_strip(struct pad_dispatch *pad,
struct evdev_device *device,
unsigned int code)
{
const struct input_absinfo *absinfo;
double pos;
absinfo = libevdev_get_abs_info(device->evdev, code);
assert(absinfo);
if (absinfo->value == 0)
return 0.0;
if (evdev_device_get_id_vendor(device) == VENDOR_ID_WACOM)
pos = normalize_wacom_strip(absinfo);
else
pos = normalize_strip(absinfo);
if (device->left_handed.enabled)
pos = 1.0 - pos;
return pos;
}
static inline struct libinput_tablet_pad_mode_group *
pad_dial_get_mode_group(struct pad_dispatch *pad,
unsigned int dial)
{
struct libinput_tablet_pad_mode_group *group;
list_for_each(group, &pad->modes.mode_group_list, link) {
if (libinput_tablet_pad_mode_group_has_dial(group, dial))
return group;
}
assert(!"Unable to find dial mode group");
return NULL;
}
static inline struct libinput_tablet_pad_mode_group *
pad_ring_get_mode_group(struct pad_dispatch *pad,
unsigned int ring)
{
struct libinput_tablet_pad_mode_group *group;
list_for_each(group, &pad->modes.mode_group_list, link) {
if (libinput_tablet_pad_mode_group_has_ring(group, ring))
return group;
}
assert(!"Unable to find ring mode group");
return NULL;
}
static inline struct libinput_tablet_pad_mode_group *
pad_strip_get_mode_group(struct pad_dispatch *pad,
unsigned int strip)
{
struct libinput_tablet_pad_mode_group *group;
list_for_each(group, &pad->modes.mode_group_list, link) {
if (libinput_tablet_pad_mode_group_has_strip(group, strip))
return group;
}
assert(!"Unable to find strip mode group");
return NULL;
}
static void
pad_check_notify_axes(struct pad_dispatch *pad,
struct evdev_device *device,
uint64_t time)
{
struct libinput_device *base = &device->base;
struct libinput_tablet_pad_mode_group *group;
double value;
bool send_finger_up = false;
/* Suppress the reset to 0 on finger up. See the
comment in pad_process_absolute */
if (pad->have_abs_misc_terminator &&
libevdev_get_event_value(device->evdev, EV_ABS, ABS_MISC) == 0)
send_finger_up = true;
/* Unlike the ring axis we don't get an event when we release
* so we can't set a source */
if (pad->changed_axes & PAD_AXIS_DIAL1) {
group = pad_dial_get_mode_group(pad, 0);
tablet_pad_notify_dial(base,
time,
0,
pad->dials.dial1,
group);
}
if (pad->changed_axes & PAD_AXIS_DIAL2) {
group = pad_dial_get_mode_group(pad, 1);
tablet_pad_notify_dial(base,
time,
1,
pad->dials.dial2,
group);
}
if (pad->changed_axes & PAD_AXIS_RING1) {
value = pad_handle_ring(pad, device, ABS_WHEEL);
if (send_finger_up)
value = -1.0;
group = pad_ring_get_mode_group(pad, 0);
tablet_pad_notify_ring(base,
time,
0,
value,
LIBINPUT_TABLET_PAD_RING_SOURCE_FINGER,
group);
}
if (pad->changed_axes & PAD_AXIS_RING2) {
value = pad_handle_ring(pad, device, ABS_THROTTLE);
if (send_finger_up)
value = -1.0;
group = pad_ring_get_mode_group(pad, 1);
tablet_pad_notify_ring(base,
time,
1,
value,
LIBINPUT_TABLET_PAD_RING_SOURCE_FINGER,
group);
}
if (pad->changed_axes & PAD_AXIS_STRIP1) {
value = pad_handle_strip(pad, device, ABS_RX);
if (send_finger_up)
value = -1.0;
group = pad_strip_get_mode_group(pad, 0);
tablet_pad_notify_strip(base,
time,
0,
value,
LIBINPUT_TABLET_PAD_STRIP_SOURCE_FINGER,
group);
}
if (pad->changed_axes & PAD_AXIS_STRIP2) {
value = pad_handle_strip(pad, device, ABS_RY);
if (send_finger_up)
value = -1.0;
group = pad_strip_get_mode_group(pad, 1);
tablet_pad_notify_strip(base,
time,
1,
value,
LIBINPUT_TABLET_PAD_STRIP_SOURCE_FINGER,
group);
}
pad->changed_axes = PAD_AXIS_NONE;
pad->have_abs_misc_terminator = false;
}
static void
pad_process_key(struct pad_dispatch *pad,
struct evdev_device *device,
struct input_event *e,
uint64_t time)
{
uint32_t button = e->code;
uint32_t is_press = e->value != 0;
/* ignore kernel key repeat */
if (e->value == 2)
return;
pad_button_set_down(pad, button, is_press);
}
static inline struct libinput_tablet_pad_mode_group *
pad_button_get_mode_group(struct pad_dispatch *pad,
unsigned int button)
{
struct libinput_tablet_pad_mode_group *group;
list_for_each(group, &pad->modes.mode_group_list, link) {
if (libinput_tablet_pad_mode_group_has_button(group, button))
return group;
}
assert(!"Unable to find button mode group\n");
return NULL;
}
static void
pad_notify_button_mask(struct pad_dispatch *pad,
struct evdev_device *device,
uint64_t time,
const struct button_state *buttons,
enum libinput_button_state state)
{
struct libinput_device *base = &device->base;
struct libinput_tablet_pad_mode_group *group;
int32_t code;
unsigned int i;
for (i = 0; i < sizeof(buttons->bits); i++) {
unsigned char buttons_slice = buttons->bits[i];
code = i * 8;
while (buttons_slice) {
int enabled;
key_or_button_map_t map;
code++;
enabled = (buttons_slice & 1);
buttons_slice >>= 1;
if (!enabled)
continue;
map = pad->button_map[code - 1];
if (map_is_unmapped(map))
continue;
if (map_is_button(map)) {
int32_t button = map_value(map);
group = pad_button_get_mode_group(pad, button);
pad_button_update_mode(group, button, state);
tablet_pad_notify_button(base,
time,
button,
state,
group);
} else if (map_is_key(map)) {
uint32_t key = map_value(map);
tablet_pad_notify_key(base,
time,
key,
(enum libinput_key_state)state);
} else {
abort();
}
}
}
}
static void
pad_notify_buttons(struct pad_dispatch *pad,
struct evdev_device *device,
uint64_t time,
enum libinput_button_state state)
{
struct button_state buttons;
if (state == LIBINPUT_BUTTON_STATE_PRESSED)
pad_get_buttons_pressed(pad, &buttons);
else
pad_get_buttons_released(pad, &buttons);
pad_notify_button_mask(pad, device, time, &buttons, state);
}
static void
pad_change_to_left_handed(struct evdev_device *device)
{
struct pad_dispatch *pad = (struct pad_dispatch*)device->dispatch;
if (device->left_handed.enabled == device->left_handed.want_enabled)
return;
if (pad_any_button_down(pad))
return;
device->left_handed.enabled = device->left_handed.want_enabled;
}
static void
pad_flush(struct pad_dispatch *pad,
struct evdev_device *device,
uint64_t time)
{
if (pad_has_status(pad, PAD_AXES_UPDATED)) {
pad_check_notify_axes(pad, device, time);
pad_unset_status(pad, PAD_AXES_UPDATED);
}
if (pad_has_status(pad, PAD_BUTTONS_RELEASED)) {
pad_notify_buttons(pad,
device,
time,
LIBINPUT_BUTTON_STATE_RELEASED);
pad_unset_status(pad, PAD_BUTTONS_RELEASED);
pad_change_to_left_handed(device);
}
if (pad_has_status(pad, PAD_BUTTONS_PRESSED)) {
pad_notify_buttons(pad,
device,
time,
LIBINPUT_BUTTON_STATE_PRESSED);
pad_unset_status(pad, PAD_BUTTONS_PRESSED);
}
/* Update state */
memcpy(&pad->prev_button_state,
&pad->button_state,
sizeof(pad->button_state));
pad->dials.dial1 = 0;
pad->dials.dial2 = 0;
}
static void
pad_process(struct evdev_dispatch *dispatch,
struct evdev_device *device,
struct input_event *e,
uint64_t time)
{
struct pad_dispatch *pad = pad_dispatch(dispatch);
switch (e->type) {
case EV_REL:
pad_process_relative(pad, device, e, time);
break;
case EV_ABS:
pad_process_absolute(pad, device, e, time);
break;
case EV_KEY:
pad_process_key(pad, device, e, time);
break;
case EV_SYN:
pad_flush(pad, device, time);
break;
case EV_MSC:
/* The EKR sends the serial as MSC_SERIAL, ignore this for
* now */
break;
default:
evdev_log_error(device,
"Unexpected event type %s (%#x)\n",
libevdev_event_type_get_name(e->type),
e->type);
break;
}
}
static void
pad_suspend(struct evdev_dispatch *dispatch,
struct evdev_device *device)
{
struct pad_dispatch *pad = pad_dispatch(dispatch);
struct libinput *libinput = pad_libinput_context(pad);
unsigned int code;
for (code = KEY_ESC; code < KEY_CNT; code++) {
if (pad_button_is_down(pad, code))
pad_button_set_down(pad, code, false);
}
pad_flush(pad, device, libinput_now(libinput));
}
static void
pad_destroy(struct evdev_dispatch *dispatch)
{
struct pad_dispatch *pad = pad_dispatch(dispatch);
pad_destroy_leds(pad);
free(pad);
}
static struct evdev_dispatch_interface pad_interface = {
.process = pad_process,
.suspend = pad_suspend,
.remove = NULL,
.destroy = pad_destroy,
.device_added = NULL,
.device_removed = NULL,
.device_suspended = NULL,
.device_resumed = NULL,
.post_added = NULL,
.touch_arbitration_toggle = NULL,
.touch_arbitration_update_rect = NULL,
.get_switch_state = NULL,
};
static bool
pad_init_buttons_from_libwacom(struct pad_dispatch *pad,
struct evdev_device *device,
WacomDevice *tablet)
{
bool rc = false;
#if HAVE_LIBWACOM
if (tablet) {
int num_buttons = libwacom_get_num_buttons(tablet);
int map = 0;
for (int i = 0; i < num_buttons; i++) {
unsigned int code;
code = libwacom_get_button_evdev_code(tablet, 'A' + i);
if (code == 0)
continue;
map_set_button_map(pad->button_map[code], map++);
}
pad->nbuttons = map;
rc = true;
}
#endif
return rc;
}
static void
pad_init_buttons_from_kernel(struct pad_dispatch *pad,
struct evdev_device *device)
{
unsigned int code;
int map = 0;
/* we match wacom_report_numbered_buttons() from the kernel */
for (code = BTN_0; code < BTN_0 + 10; code++) {
if (libevdev_has_event_code(device->evdev, EV_KEY, code))
map_set_button_map(pad->button_map[code], map++);
}
for (code = BTN_BASE; code < BTN_BASE + 2; code++) {
if (libevdev_has_event_code(device->evdev, EV_KEY, code))
map_set_button_map(pad->button_map[code], map++);
}
for (code = BTN_A; code < BTN_A + 6; code++) {
if (libevdev_has_event_code(device->evdev, EV_KEY, code))
map_set_button_map(pad->button_map[code], map++);
}
for (code = BTN_LEFT; code < BTN_LEFT + 7; code++) {
if (libevdev_has_event_code(device->evdev, EV_KEY, code))
map_set_button_map(pad->button_map[code], map++);
}
pad->nbuttons = map;
}
static void
pad_init_keys(struct pad_dispatch *pad, struct evdev_device *device)
{
unsigned int codes[] = {
KEY_BUTTONCONFIG,
KEY_ONSCREEN_KEYBOARD,
KEY_CONTROLPANEL,
};
/* Wacom's keys are the only ones we know anything about */
if (libevdev_get_id_vendor(device->evdev) != VENDOR_ID_WACOM)
return;
ARRAY_FOR_EACH(codes, code) {
if (libevdev_has_event_code(device->evdev, EV_KEY, *code))
map_set_key_map(pad->button_map[*code], *code);
}
}
static void
pad_init_buttons(struct pad_dispatch *pad,
struct evdev_device *device,
WacomDevice *wacom)
{
size_t i;
for (i = 0; i < ARRAY_LENGTH(pad->button_map); i++)
map_init(pad->button_map[i]);
if (!pad_init_buttons_from_libwacom(pad, device, wacom))
pad_init_buttons_from_kernel(pad, device);
pad_init_keys(pad, device);
}
static void
pad_init_left_handed(struct evdev_device *device,
WacomDevice *wacom)
{
bool has_left_handed = true;
#if HAVE_LIBWACOM
has_left_handed = !wacom || libwacom_is_reversible(wacom);
#endif
if (has_left_handed)
evdev_init_left_handed(device,
pad_change_to_left_handed);
}
static int
pad_init(struct pad_dispatch *pad, struct evdev_device *device)
{
int rc = 1;
struct libinput *li = evdev_libinput_context(device);
WacomDevice *wacom = NULL;
#if HAVE_LIBWACOM
WacomDeviceDatabase *db = libinput_libwacom_ref(li);
if (db) {
char event_path[64];
snprintf(event_path,
sizeof(event_path),
"/dev/input/%s",
evdev_device_get_sysname(device));
wacom = libwacom_new_from_path(db, event_path, WFALLBACK_NONE, NULL);
if (!wacom) {
wacom = libwacom_new_from_usbid(db,
evdev_device_get_id_vendor(device),
evdev_device_get_id_product(device),
NULL);
}
if (!wacom) {
evdev_log_info(device,
"device \"%s\" (%04x:%04x) is not known to libwacom\n",
evdev_device_get_name(device),
evdev_device_get_id_vendor(device),
evdev_device_get_id_product(device));
}
}
#endif
pad->base.dispatch_type = DISPATCH_TABLET_PAD;
pad->base.interface = &pad_interface;
pad->device = device;
pad->status = PAD_NONE;
pad->changed_axes = PAD_AXIS_NONE;
/* We expect the kernel to either give us both axes as hires or neither.
* Getting one is a kernel bug we don't need to care about */
pad->dials.has_hires_dial = libevdev_has_event_code(device->evdev, EV_REL, REL_WHEEL_HI_RES) ||
libevdev_has_event_code(device->evdev, EV_REL, REL_HWHEEL_HI_RES);
if (libevdev_has_event_code(device->evdev, EV_REL, REL_WHEEL) &&
libevdev_has_event_code(device->evdev, EV_REL, REL_DIAL)) {
log_bug_libinput(li, "Unsupported combination REL_DIAL and REL_WHEEL\n");
}
pad_init_buttons(pad, device, wacom);
pad_init_left_handed(device, wacom);
rc = pad_init_leds(pad, device, wacom);
/* at most 5 "Multiple EV_ABS events" log messages per hour */
ratelimit_init(&pad->duplicate_abs_limit, s2us(60 * 60), 5);
#if HAVE_LIBWACOM
if (wacom)
libwacom_destroy(wacom);
if (db)
libinput_libwacom_unref(li);
#endif
return rc;
}
static uint32_t
pad_sendevents_get_modes(struct libinput_device *device)
{
return LIBINPUT_CONFIG_SEND_EVENTS_DISABLED;
}
static enum libinput_config_status
pad_sendevents_set_mode(struct libinput_device *device,
enum libinput_config_send_events_mode mode)
{
struct evdev_device *evdev = evdev_device(device);
struct pad_dispatch *pad = (struct pad_dispatch*)evdev->dispatch;
if (mode == pad->sendevents.current_mode)
return LIBINPUT_CONFIG_STATUS_SUCCESS;
switch(mode) {
case LIBINPUT_CONFIG_SEND_EVENTS_ENABLED:
break;
case LIBINPUT_CONFIG_SEND_EVENTS_DISABLED:
pad_suspend(evdev->dispatch, evdev);
break;
default:
return LIBINPUT_CONFIG_STATUS_UNSUPPORTED;
}
pad->sendevents.current_mode = mode;
return LIBINPUT_CONFIG_STATUS_SUCCESS;
}
static enum libinput_config_send_events_mode
pad_sendevents_get_mode(struct libinput_device *device)
{
struct evdev_device *evdev = evdev_device(device);
struct pad_dispatch *dispatch = (struct pad_dispatch*)evdev->dispatch;
return dispatch->sendevents.current_mode;
}
static enum libinput_config_send_events_mode
pad_sendevents_get_default_mode(struct libinput_device *device)
{
return LIBINPUT_CONFIG_SEND_EVENTS_ENABLED;
}
struct evdev_dispatch *
evdev_tablet_pad_create(struct evdev_device *device)
{
struct pad_dispatch *pad;
pad = zalloc(sizeof *pad);
if (pad_init(pad, device) != 0) {
pad_destroy(&pad->base);
return NULL;
}
device->base.config.sendevents = &pad->sendevents.config;
pad->sendevents.current_mode = LIBINPUT_CONFIG_SEND_EVENTS_ENABLED;
pad->sendevents.config.get_modes = pad_sendevents_get_modes;
pad->sendevents.config.set_mode = pad_sendevents_set_mode;
pad->sendevents.config.get_mode = pad_sendevents_get_mode;
pad->sendevents.config.get_default_mode = pad_sendevents_get_default_mode;
return &pad->base;
}
int
evdev_device_tablet_pad_has_key(struct evdev_device *device, uint32_t code)
{
if (!(device->seat_caps & EVDEV_DEVICE_TABLET_PAD))
return -1;
return libevdev_has_event_code(device->evdev, EV_KEY, code);
}
int
evdev_device_tablet_pad_get_num_buttons(struct evdev_device *device)
{
struct pad_dispatch *pad = (struct pad_dispatch*)device->dispatch;
if (!(device->seat_caps & EVDEV_DEVICE_TABLET_PAD))
return -1;
return pad->nbuttons;
}
int
evdev_device_tablet_pad_get_num_dials(struct evdev_device *device)
{
int ndials = 0;
if (!(device->seat_caps & EVDEV_DEVICE_TABLET_PAD))
return -1;
if (libevdev_has_event_code(device->evdev, EV_REL, REL_WHEEL) ||
libevdev_has_event_code(device->evdev, EV_REL, REL_DIAL)) {
ndials++;
if (libevdev_has_event_code(device->evdev,
EV_REL,
REL_HWHEEL))
ndials++;
}
return ndials;
}
int
evdev_device_tablet_pad_get_num_rings(struct evdev_device *device)
{
int nrings = 0;
if (!(device->seat_caps & EVDEV_DEVICE_TABLET_PAD))
return -1;
if (libevdev_has_event_code(device->evdev, EV_ABS, ABS_WHEEL)) {
nrings++;
if (libevdev_has_event_code(device->evdev,
EV_ABS,
ABS_THROTTLE))
nrings++;
}
return nrings;
}
int
evdev_device_tablet_pad_get_num_strips(struct evdev_device *device)
{
int nstrips = 0;
if (!(device->seat_caps & EVDEV_DEVICE_TABLET_PAD))
return -1;
if (libevdev_has_event_code(device->evdev, EV_ABS, ABS_RX)) {
nstrips++;
if (libevdev_has_event_code(device->evdev,
EV_ABS,
ABS_RY))
nstrips++;
}
return nstrips;
}
libinput-1.28.1/src/evdev-tablet-pad.h000066400000000000000000000066061477265155700175500ustar00rootroot00000000000000/*
* Copyright © 2015 Red Hat, Inc.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice (including the next
* paragraph) shall be included in all copies or substantial portions of the
* Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
*/
#ifndef EVDEV_TABLET_PAD_H
#define EVDEV_TABLET_PAD_H
#include "evdev.h"
#if !HAVE_LIBWACOM
typedef void * WacomDevice;
#endif
#define LIBINPUT_BUTTONSET_AXIS_NONE 0
enum pad_status {
PAD_NONE = 0,
PAD_AXES_UPDATED = bit(0),
PAD_BUTTONS_PRESSED = bit(1),
PAD_BUTTONS_RELEASED = bit(2),
};
enum pad_axes {
PAD_AXIS_NONE = 0,
PAD_AXIS_RING1 = bit(0),
PAD_AXIS_RING2 = bit(1),
PAD_AXIS_STRIP1 = bit(2),
PAD_AXIS_STRIP2 = bit(3),
PAD_AXIS_DIAL1 = bit(4),
PAD_AXIS_DIAL2 = bit(5),
};
struct button_state {
unsigned char bits[NCHARS(KEY_CNT)];
};
typedef struct {
uint32_t value;
} key_or_button_map_t;
#define map_init(x_) ((x_).value = (uint32_t)-1)
#define map_is_unmapped(x_) ((x_).value == (uint32_t)-1)
#define map_is_button(x_) (((x_).value & 0xFF000000) == 0)
#define map_is_key(x_) (((x_).value & 0xFF000000) != 0)
#define map_set_button_map(field_, value_) ((field_).value = value_)
#define map_set_key_map(field_, value_) ((field_).value = value_ | 0xFF000000)
#define map_value(x_) ((x_).value & 0x00FFFFFF)
struct pad_dispatch {
struct evdev_dispatch base;
struct evdev_device *device;
unsigned char status;
uint32_t changed_axes;
struct button_state button_state;
struct button_state prev_button_state;
key_or_button_map_t button_map[KEY_CNT];
unsigned int nbuttons;
bool have_abs_misc_terminator;
struct {
bool has_hires_dial;
double dial1;
double dial2;
} dials;
struct {
struct libinput_device_config_send_events config;
enum libinput_config_send_events_mode current_mode;
} sendevents;
struct {
struct list mode_group_list;
} modes;
struct ratelimit duplicate_abs_limit;
};
static inline struct pad_dispatch*
pad_dispatch(struct evdev_dispatch *dispatch)
{
evdev_verify_dispatch_type(dispatch, DISPATCH_TABLET_PAD);
return container_of(dispatch, struct pad_dispatch, base);
}
static inline struct libinput *
pad_libinput_context(const struct pad_dispatch *pad)
{
return evdev_libinput_context(pad->device);
}
int
pad_init_leds(struct pad_dispatch *pad,
struct evdev_device *device,
WacomDevice *wacom);
void
pad_destroy_leds(struct pad_dispatch *pad);
void
pad_button_update_mode(struct libinput_tablet_pad_mode_group *g,
unsigned int button_index,
enum libinput_button_state state);
#endif
libinput-1.28.1/src/evdev-tablet.c000066400000000000000000002575651477265155700170150ustar00rootroot00000000000000/*
* Copyright © 2014 Red Hat, Inc.
* Copyright © 2014 Lyude Paul
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice (including the next
* paragraph) shall be included in all copies or substantial portions of the
* Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
*/
#include "config.h"
#include "evdev-tablet.h"
#include "util-input-event.h"
#include
#include
#include
#if HAVE_LIBWACOM
#include
#endif
enum notify {
DONT_NOTIFY,
DO_NOTIFY,
};
/* The tablet sends events every ~2ms , 50ms should be plenty enough to
detect out-of-range.
This value is higher during test suite runs */
static int FORCED_PROXOUT_TIMEOUT = 50 * 1000; /* µs */
#define tablet_set_status(tablet_,s_) (tablet_)->status |= (s_)
#define tablet_unset_status(tablet_,s_) (tablet_)->status &= ~(s_)
#define tablet_has_status(tablet_,s_) (!!((tablet_)->status & (s_)))
static inline void
tablet_get_pressed_buttons(struct tablet_dispatch *tablet,
struct button_state *buttons)
{
size_t i;
const struct button_state *state = &tablet->button_state,
*prev_state = &tablet->prev_button_state;
for (i = 0; i < sizeof(buttons->bits); i++)
buttons->bits[i] = state->bits[i] & ~(prev_state->bits[i]);
}
static inline void
tablet_get_released_buttons(struct tablet_dispatch *tablet,
struct button_state *buttons)
{
size_t i;
const struct button_state *state = &tablet->button_state,
*prev_state = &tablet->prev_button_state;
for (i = 0; i < sizeof(buttons->bits); i++)
buttons->bits[i] = prev_state->bits[i] &
~(state->bits[i]);
}
static struct libinput_tablet_tool_pressure_threshold*
tablet_tool_get_threshold(struct tablet_dispatch *tablet,
struct libinput_tablet_tool *tool)
{
ARRAY_FOR_EACH(tool->pressure.thresholds, threshold) {
if (threshold->tablet_id == tablet->tablet_id) {
return threshold;
}
}
/* If we ever get here, we failed detecting the proximity for this tablet
* (or we have too many tablets). Return the first one which will
* make things work incorrectly but we don't need to NULL-check
* everything for an extremely unlikely situtation */
evdev_log_bug_libinput(tablet->device,
"Failed to find tablet_id %d for pressure offsets\n",
tablet->tablet_id);
return &tool->pressure.thresholds[0];
}
/* Merge the previous state with the current one so all buttons look like
* they just got pressed in this frame */
static inline void
tablet_force_button_presses(struct tablet_dispatch *tablet)
{
struct button_state *state = &tablet->button_state,
*prev_state = &tablet->prev_button_state;
size_t i;
for (i = 0; i < sizeof(state->bits); i++) {
state->bits[i] = state->bits[i] | prev_state->bits[i];
prev_state->bits[i] = 0;
}
}
static inline size_t
tablet_history_size(const struct tablet_dispatch *tablet)
{
return tablet->history.size;
}
static inline void
tablet_history_reset(struct tablet_dispatch *tablet)
{
tablet->history.count = 0;
}
static inline void
tablet_history_push(struct tablet_dispatch *tablet,
const struct tablet_axes *axes)
{
unsigned int index = (tablet->history.index + 1) %
tablet_history_size(tablet);
tablet->history.samples[index] = *axes;
tablet->history.index = index;
tablet->history.count = min(tablet->history.count + 1,
tablet_history_size(tablet));
if (tablet->history.count < tablet_history_size(tablet))
tablet_history_push(tablet, axes);
}
/**
* Return a previous axis state, where index of 0 means "most recent", 1 is
* "one before most recent", etc.
*/
static inline const struct tablet_axes*
tablet_history_get(const struct tablet_dispatch *tablet, unsigned int index)
{
size_t sz = tablet_history_size(tablet);
assert(index < sz);
assert(index < tablet->history.count);
index = (tablet->history.index + sz - index) % sz;
return &tablet->history.samples[index];
}
static inline void
tablet_reset_changed_axes(struct tablet_dispatch *tablet)
{
memset(tablet->changed_axes, 0, sizeof(tablet->changed_axes));
}
static bool
tablet_device_has_axis(struct tablet_dispatch *tablet,
enum libinput_tablet_tool_axis axis)
{
struct libevdev *evdev = tablet->device->evdev;
bool has_axis = false;
unsigned int code;
if (axis == LIBINPUT_TABLET_TOOL_AXIS_ROTATION_Z) {
has_axis = (libevdev_has_event_code(evdev,
EV_KEY,
BTN_TOOL_MOUSE) &&
libevdev_has_event_code(evdev,
EV_ABS,
ABS_TILT_X) &&
libevdev_has_event_code(evdev,
EV_ABS,
ABS_TILT_Y));
code = axis_to_evcode(axis);
has_axis |= libevdev_has_event_code(evdev,
EV_ABS,
code);
} else if (axis == LIBINPUT_TABLET_TOOL_AXIS_REL_WHEEL) {
has_axis = libevdev_has_event_code(evdev,
EV_REL,
REL_WHEEL);
} else {
code = axis_to_evcode(axis);
has_axis = libevdev_has_event_code(evdev,
EV_ABS,
code);
}
return has_axis;
}
static inline bool
tablet_filter_axis_fuzz(const struct tablet_dispatch *tablet,
const struct evdev_device *device,
const struct input_event *e,
enum libinput_tablet_tool_axis axis)
{
int delta, fuzz;
int current, previous;
previous = tablet->prev_value[axis];
current = e->value;
delta = previous - current;
fuzz = libevdev_get_abs_fuzz(device->evdev, e->code);
/* ABS_DISTANCE doesn't have have fuzz set and causes continuous
* updates for the cursor/lens tools. Add a minimum fuzz of 2, same
* as the xf86-input-wacom driver
*/
switch (e->code) {
case ABS_DISTANCE:
fuzz = max(2, fuzz);
break;
default:
break;
}
return abs(delta) <= fuzz;
}
static void
tablet_process_absolute(struct tablet_dispatch *tablet,
struct evdev_device *device,
struct input_event *e,
uint64_t time)
{
enum libinput_tablet_tool_axis axis;
switch (e->code) {
case ABS_X:
case ABS_Y:
case ABS_Z:
case ABS_PRESSURE:
case ABS_TILT_X:
case ABS_TILT_Y:
case ABS_DISTANCE:
case ABS_WHEEL:
axis = evcode_to_axis(e->code);
if (axis == LIBINPUT_TABLET_TOOL_AXIS_NONE) {
evdev_log_bug_libinput(device,
"Invalid ABS event code %#x\n",
e->code);
break;
}
tablet->prev_value[axis] = tablet->current_value[axis];
if (tablet_filter_axis_fuzz(tablet, device, e, axis))
break;
tablet->current_value[axis] = e->value;
set_bit(tablet->changed_axes, axis);
tablet_set_status(tablet, TABLET_AXES_UPDATED);
break;
/* tool_id is the identifier for the tool we can use in libwacom
* to identify it (if we have one anyway) */
case ABS_MISC:
tablet->current_tool.id = e->value;
break;
/* Intuos 3 strip data. Should only happen on the Pad device, not on
the Pen device. */
case ABS_RX:
case ABS_RY:
/* Only on the 4D mouse (Intuos2), obsolete */
case ABS_RZ:
/* Only on the 4D mouse (Intuos2), obsolete.
The 24HD sends ABS_THROTTLE on the Pad device for the second
wheel but we shouldn't get here on kernel >= 3.17.
*/
case ABS_THROTTLE:
default:
evdev_log_info(device,
"Unhandled ABS event code %#x\n",
e->code);
break;
}
}
static inline int
axis_range_percentage(const struct input_absinfo *a, double percent)
{
return (a->maximum - a->minimum) * percent/100.0 + a->minimum;
}
static void
tablet_change_area(struct evdev_device *device)
{
struct tablet_dispatch *tablet = tablet_dispatch(device->dispatch);
if (memcmp(&tablet->area.rect, &tablet->area.want_rect, sizeof(tablet->area.rect)) == 0)
return;
if (!tablet_has_status(tablet, TABLET_TOOL_OUT_OF_PROXIMITY))
return;
tablet->area.rect = tablet->area.want_rect;
evdev_log_debug(device,
"tablet-area: area is %.2f/%.2f - %.2f/%.2f\n",
tablet->area.rect.x1,
tablet->area.rect.y1,
tablet->area.rect.x2,
tablet->area.rect.y2);
const struct input_absinfo *absx = device->abs.absinfo_x;
const struct input_absinfo *absy = device->abs.absinfo_y;
tablet->area.x.minimum = axis_range_percentage(absx, tablet->area.rect.x1 * 100);
tablet->area.x.maximum = axis_range_percentage(absx, tablet->area.rect.x2 * 100);
tablet->area.y.minimum = axis_range_percentage(absy, tablet->area.rect.y1 * 100);
tablet->area.y.maximum = axis_range_percentage(absy, tablet->area.rect.y2 * 100);
}
static void
tablet_apply_rotation(struct evdev_device *device)
{
struct tablet_dispatch *tablet = tablet_dispatch(device->dispatch);
if (tablet->rotation.rotate == tablet->rotation.want_rotate)
return;
if (!tablet_has_status(tablet, TABLET_TOOL_OUT_OF_PROXIMITY))
return;
tablet->rotation.rotate = tablet->rotation.want_rotate;
evdev_log_debug(device,
"tablet-rotation: rotation is %s\n",
tablet->rotation.rotate ? "on" : "off");
}
static void
tablet_change_rotation(struct evdev_device *device, enum notify notify)
{
struct tablet_dispatch *tablet = tablet_dispatch(device->dispatch);
struct evdev_device *touch_device = tablet->touch_device;
struct evdev_dispatch *dispatch;
bool tablet_is_left, touchpad_is_left;
tablet_is_left = tablet->device->left_handed.enabled;
touchpad_is_left = tablet->rotation.touch_device_left_handed_state;
tablet->rotation.want_rotate = tablet_is_left || touchpad_is_left;
tablet_apply_rotation(device);
if (notify == DO_NOTIFY && touch_device) {
bool enable = device->left_handed.want_enabled;
dispatch = touch_device->dispatch;
if (dispatch->interface->left_handed_toggle)
dispatch->interface->left_handed_toggle(dispatch,
touch_device,
enable);
}
}
static void
tablet_change_to_left_handed(struct evdev_device *device)
{
if (device->left_handed.enabled == device->left_handed.want_enabled)
return;
device->left_handed.enabled = device->left_handed.want_enabled;
tablet_change_rotation(device, DO_NOTIFY);
}
static void
tablet_update_tool(struct tablet_dispatch *tablet,
struct evdev_device *device,
enum libinput_tablet_tool_type tool,
bool enabled)
{
assert(tool != LIBINPUT_TOOL_NONE);
if (enabled) {
tablet->current_tool.type = tool;
tablet_set_status(tablet, TABLET_TOOL_ENTERING_PROXIMITY);
tablet_unset_status(tablet, TABLET_TOOL_OUT_OF_PROXIMITY);
}
else if (!tablet_has_status(tablet, TABLET_TOOL_OUT_OF_PROXIMITY)) {
tablet_set_status(tablet, TABLET_TOOL_LEAVING_PROXIMITY);
}
}
static inline double
normalize_slider(const struct input_absinfo *absinfo)
{
return absinfo_normalize(absinfo) * 2 - 1;
}
static inline double
normalize_distance(const struct input_absinfo *absinfo)
{
return absinfo_normalize(absinfo);
}
static inline double
normalize_pressure(struct libinput_tablet_tool_pressure_threshold *threshold,
int abs_value)
{
/**
* Note: the upper threshold takes the offset into account so that
* |- 4% -|
* min |------X------X-------------------------| max
* | |
* | + upper threshold / tip trigger
* +- offset and lower threshold
*
* The axis is scaled into the range [lower, max] so that the lower
* threshold is 0 pressure.
*/
struct input_absinfo abs = threshold->abs_pressure;
abs.minimum = threshold->threshold.lower;
return absinfo_normalize_value(&abs, abs_value);
}
static inline double
adjust_tilt(const struct input_absinfo *absinfo)
{
double value = absinfo_normalize(absinfo);
const int WACOM_MAX_DEGREES = 64;
/* If resolution is nonzero, it's in units/radian. But require
* a min/max less/greater than zero so we can assume 0 is the
* center */
if (absinfo->resolution != 0 &&
absinfo->maximum > 0 &&
absinfo->minimum < 0) {
value = rad2deg((double)absinfo->value/absinfo->resolution);
} else {
/* Wacom supports physical [-64, 64] degrees, so map to that by
* default. If other tablets have a different physical range or
* nonzero physical offsets, they need extra treatment
* here.
*/
/* Map to the (-1, 1) range */
value = (value * 2) - 1;
value *= WACOM_MAX_DEGREES;
}
return value;
}
static inline int32_t
invert_axis(const struct input_absinfo *absinfo)
{
return absinfo->maximum - (absinfo->value - absinfo->minimum);
}
static void
convert_tilt_to_rotation(struct tablet_dispatch *tablet)
{
const int offset = 5;
double x, y;
double angle = 0.0;
/* Wacom Intuos 4, 5, Pro mouse calculates rotation from the x/y tilt
values. The device has a 175 degree CCW hardware offset but since we use
atan2 the effective offset is just 5 degrees.
*/
x = tablet->axes.tilt.x;
y = tablet->axes.tilt.y;
/* atan2 is CCW, we want CW -> negate x */
if (x || y)
angle = rad2deg(atan2(-x, y));
angle = fmod(360 + angle - offset, 360);
tablet->axes.rotation = angle;
set_bit(tablet->changed_axes, LIBINPUT_TABLET_TOOL_AXIS_ROTATION_Z);
}
static double
convert_to_degrees(const struct input_absinfo *absinfo, double offset)
{
/* range is [0, 360[, i.e. range + 1 */
double value = (absinfo->value - absinfo->minimum) / absinfo_range(absinfo);
return fmod(value * 360.0 + offset, 360.0);
}
static inline double
normalize_wheel(struct tablet_dispatch *tablet,
int value)
{
struct evdev_device *device = tablet->device;
return value * device->scroll.wheel_click_angle.x;
}
static bool
is_inside_area(struct tablet_dispatch *tablet,
const struct device_coords *point,
double normalized_margin)
{
if (tablet->area.rect.x1 == 0.0 && tablet->area.rect.x2 == 1.0 &&
tablet->area.rect.y1 == 0.0 && tablet->area.rect.y2 == 1.0)
return true;
assert(normalized_margin > 0.0);
assert(normalized_margin <= 1.0);
int xmargin = (tablet->area.x.maximum - tablet->area.x.minimum) * normalized_margin;
int ymargin = (tablet->area.y.maximum - tablet->area.y.minimum) * normalized_margin;
return (point->x >= tablet->area.x.minimum - xmargin &&
point->x <= tablet->area.x.maximum + xmargin &&
point->y >= tablet->area.y.minimum - ymargin &&
point->y <= tablet->area.y.maximum + ymargin);
}
static void
apply_tablet_area(struct tablet_dispatch *tablet,
struct evdev_device *device,
struct device_coords *point)
{
if (tablet->area.rect.x1 == 0.0 && tablet->area.rect.x2 == 1.0 &&
tablet->area.rect.y1 == 0.0 && tablet->area.rect.y2 == 1.0)
return;
/* The point is somewhere on the tablet in device coordinates,
* but we need it relative to the x/y offset.
* So clip it first, then offset it to our area min/max.
*
* Right now we're just clipping, we don't completely
* ignore events. What we should do is ignore events outside
* altogether and generate prox in/out events when we actually
* enter the area.
*/
point->x = min(point->x, tablet->area.x.maximum);
point->y = min(point->y, tablet->area.y.maximum);
point->x = max(point->x, tablet->area.x.minimum);
point->y = max(point->y, tablet->area.y.minimum);
}
static inline void
tablet_update_xy(struct tablet_dispatch *tablet,
struct evdev_device *device)
{
const struct input_absinfo *absinfo;
int value;
if (!libevdev_has_event_code(device->evdev, EV_ABS, ABS_X) ||
!libevdev_has_event_code(device->evdev, EV_ABS, ABS_Y))
return;
if (bit_is_set(tablet->changed_axes, LIBINPUT_TABLET_TOOL_AXIS_X) ||
bit_is_set(tablet->changed_axes, LIBINPUT_TABLET_TOOL_AXIS_Y)) {
absinfo = device->abs.absinfo_x;
if (tablet->rotation.rotate)
value = invert_axis(absinfo);
else
value = absinfo->value;
tablet->axes.point.x = value;
absinfo = device->abs.absinfo_y;
if (tablet->rotation.rotate)
value = invert_axis(absinfo);
else
value = absinfo->value;
tablet->axes.point.y = value;
/* calibration and area are currently mutually exclusive so
* one of those is a noop */
evdev_transform_absolute(device, &tablet->axes.point);
apply_tablet_area(tablet, device, &tablet->axes.point);
}
}
static inline struct normalized_coords
tablet_tool_process_delta(struct tablet_dispatch *tablet,
struct libinput_tablet_tool *tool,
const struct evdev_device *device,
struct tablet_axes *axes,
uint64_t time)
{
const struct normalized_coords zero = { 0.0, 0.0 };
struct device_coords delta = { 0, 0 };
struct device_float_coords accel;
/* When tool contact changes, we probably got a cursor jump. Don't
try to calculate a delta for that event */
if (!tablet_has_status(tablet,
TABLET_TOOL_ENTERING_PROXIMITY) &&
!tablet_has_status(tablet, TABLET_TOOL_ENTERING_CONTACT) &&
!tablet_has_status(tablet, TABLET_TOOL_LEAVING_CONTACT) &&
(bit_is_set(tablet->changed_axes, LIBINPUT_TABLET_TOOL_AXIS_X) ||
bit_is_set(tablet->changed_axes, LIBINPUT_TABLET_TOOL_AXIS_Y))) {
delta.x = axes->point.x - tablet->last_smooth_point.x;
delta.y = axes->point.y - tablet->last_smooth_point.y;
}
if (axes->point.x != tablet->last_smooth_point.x)
set_bit(tablet->changed_axes, LIBINPUT_TABLET_TOOL_AXIS_X);
if (axes->point.y != tablet->last_smooth_point.y)
set_bit(tablet->changed_axes, LIBINPUT_TABLET_TOOL_AXIS_Y);
tablet->last_smooth_point = axes->point;
accel.x = 1.0 * delta.x;
accel.y = 1.0 * delta.y;
if (device_float_is_zero(accel))
return zero;
return filter_dispatch(device->pointer.filter,
&accel,
tool,
time);
}
static inline void
tablet_update_pressure(struct tablet_dispatch *tablet,
struct evdev_device *device,
struct libinput_tablet_tool *tool)
{
const struct input_absinfo *abs = libevdev_get_abs_info(device->evdev,
ABS_PRESSURE);
if (!abs)
return;
if (bit_is_set(tablet->changed_axes, LIBINPUT_TABLET_TOOL_AXIS_PRESSURE)) {
struct libinput_tablet_tool_pressure_threshold *threshold =
tablet_tool_get_threshold(tablet, tool);
tablet->axes.pressure = normalize_pressure(threshold, abs->value);
}
}
static inline void
tablet_update_distance(struct tablet_dispatch *tablet,
struct evdev_device *device)
{
const struct input_absinfo *absinfo;
if (!libevdev_has_event_code(device->evdev, EV_ABS, ABS_DISTANCE))
return;
if (bit_is_set(tablet->changed_axes,
LIBINPUT_TABLET_TOOL_AXIS_DISTANCE)) {
absinfo = libevdev_get_abs_info(device->evdev, ABS_DISTANCE);
tablet->axes.distance = normalize_distance(absinfo);
}
}
static inline void
tablet_update_slider(struct tablet_dispatch *tablet,
struct evdev_device *device)
{
const struct input_absinfo *absinfo;
if (!libevdev_has_event_code(device->evdev, EV_ABS, ABS_WHEEL))
return;
if (bit_is_set(tablet->changed_axes,
LIBINPUT_TABLET_TOOL_AXIS_SLIDER)) {
absinfo = libevdev_get_abs_info(device->evdev, ABS_WHEEL);
tablet->axes.slider = normalize_slider(absinfo);
}
}
static inline void
tablet_update_tilt(struct tablet_dispatch *tablet,
struct evdev_device *device)
{
const struct input_absinfo *absinfo;
if (!libevdev_has_event_code(device->evdev, EV_ABS, ABS_TILT_X) ||
!libevdev_has_event_code(device->evdev, EV_ABS, ABS_TILT_Y))
return;
/* mouse rotation resets tilt to 0 so always fetch both axes if
* either has changed */
if (bit_is_set(tablet->changed_axes,
LIBINPUT_TABLET_TOOL_AXIS_TILT_X) ||
bit_is_set(tablet->changed_axes,
LIBINPUT_TABLET_TOOL_AXIS_TILT_Y)) {
absinfo = libevdev_get_abs_info(device->evdev, ABS_TILT_X);
tablet->axes.tilt.x = adjust_tilt(absinfo);
absinfo = libevdev_get_abs_info(device->evdev, ABS_TILT_Y);
tablet->axes.tilt.y = adjust_tilt(absinfo);
if (device->left_handed.enabled) {
tablet->axes.tilt.x *= -1;
tablet->axes.tilt.y *= -1;
}
}
}
static inline void
tablet_update_artpen_rotation(struct tablet_dispatch *tablet,
struct evdev_device *device)
{
const struct input_absinfo *absinfo;
if (!libevdev_has_event_code(device->evdev, EV_ABS, ABS_Z))
return;
if (bit_is_set(tablet->changed_axes,
LIBINPUT_TABLET_TOOL_AXIS_ROTATION_Z)) {
absinfo = libevdev_get_abs_info(device->evdev,
ABS_Z);
/* artpen has 0 with buttons pointing east */
tablet->axes.rotation = convert_to_degrees(absinfo, 90);
}
}
static inline void
tablet_update_mouse_rotation(struct tablet_dispatch *tablet,
struct evdev_device *device)
{
if (bit_is_set(tablet->changed_axes,
LIBINPUT_TABLET_TOOL_AXIS_TILT_X) ||
bit_is_set(tablet->changed_axes,
LIBINPUT_TABLET_TOOL_AXIS_TILT_Y)) {
convert_tilt_to_rotation(tablet);
}
}
static inline void
tablet_update_rotation(struct tablet_dispatch *tablet,
struct evdev_device *device)
{
/* We must check ROTATION_Z after TILT_X/Y so that the tilt axes are
* already normalized and set if we have the mouse/lens tool */
if (tablet->current_tool.type == LIBINPUT_TABLET_TOOL_TYPE_MOUSE ||
tablet->current_tool.type == LIBINPUT_TABLET_TOOL_TYPE_LENS) {
tablet_update_mouse_rotation(tablet, device);
clear_bit(tablet->changed_axes, LIBINPUT_TABLET_TOOL_AXIS_TILT_X);
clear_bit(tablet->changed_axes, LIBINPUT_TABLET_TOOL_AXIS_TILT_Y);
tablet->axes.tilt.x = 0;
tablet->axes.tilt.y = 0;
/* tilt is already converted to left-handed, so mouse
* rotation is converted to left-handed automatically */
} else {
tablet_update_artpen_rotation(tablet, device);
if (device->left_handed.enabled) {
double r = tablet->axes.rotation;
tablet->axes.rotation = fmod(180 + r, 360);
}
}
}
static inline void
tablet_update_wheel(struct tablet_dispatch *tablet,
struct evdev_device *device)
{
int a;
a = LIBINPUT_TABLET_TOOL_AXIS_REL_WHEEL;
if (bit_is_set(tablet->changed_axes, a)) {
/* tablet->axes.wheel_discrete is already set */
tablet->axes.wheel = normalize_wheel(tablet,
tablet->axes.wheel_discrete);
} else {
tablet->axes.wheel = 0;
tablet->axes.wheel_discrete = 0;
}
}
static void
tablet_smoothen_axes(const struct tablet_dispatch *tablet,
struct tablet_axes *axes)
{
size_t i;
size_t count = tablet_history_size(tablet);
struct tablet_axes smooth = { 0 };
for (i = 0; i < count; i++) {
const struct tablet_axes *a = tablet_history_get(tablet, i);
smooth.point.x += a->point.x;
smooth.point.y += a->point.y;
smooth.tilt.x += a->tilt.x;
smooth.tilt.y += a->tilt.y;
}
axes->point.x = smooth.point.x/count;
axes->point.y = smooth.point.y/count;
axes->tilt.x = smooth.tilt.x/count;
axes->tilt.y = smooth.tilt.y/count;
}
static bool
tablet_check_notify_axes(struct tablet_dispatch *tablet,
struct evdev_device *device,
struct libinput_tablet_tool *tool,
struct tablet_axes *axes_out,
uint64_t time)
{
struct tablet_axes axes = {0};
const char tmp[sizeof(tablet->changed_axes)] = {0};
bool rc = false;
if (memcmp(tmp, tablet->changed_axes, sizeof(tmp)) == 0) {
axes = tablet->axes;
goto out;
}
tablet_update_xy(tablet, device);
tablet_update_pressure(tablet, device, tool);
tablet_update_distance(tablet, device);
tablet_update_slider(tablet, device);
tablet_update_tilt(tablet, device);
tablet_update_wheel(tablet, device);
/* We must check ROTATION_Z after TILT_X/Y so that the tilt axes are
* already normalized and set if we have the mouse/lens tool */
tablet_update_rotation(tablet, device);
axes.point = tablet->axes.point;
axes.pressure = tablet->axes.pressure;
axes.distance = tablet->axes.distance;
axes.slider = tablet->axes.slider;
axes.tilt = tablet->axes.tilt;
axes.wheel = tablet->axes.wheel;
axes.wheel_discrete = tablet->axes.wheel_discrete;
axes.rotation = tablet->axes.rotation;
rc = true;
out:
/* The tool position often jumps to a different spot when contact changes.
* If tool contact changes, clear the history to prevent axis smoothing
* from trying to average over the spatial discontinuity. */
if (tablet_has_status(tablet, TABLET_TOOL_ENTERING_CONTACT) ||
tablet_has_status(tablet, TABLET_TOOL_LEAVING_CONTACT)) {
tablet_history_reset(tablet);
}
tablet_history_push(tablet, &tablet->axes);
tablet_smoothen_axes(tablet, &axes);
/* The delta relies on the last *smooth* point, so we do it last */
axes.delta = tablet_tool_process_delta(tablet, tool, device, &axes, time);
*axes_out = axes;
return rc;
}
static void
tablet_update_button(struct tablet_dispatch *tablet,
uint32_t evcode,
uint32_t enable)
{
switch (evcode) {
case BTN_LEFT:
case BTN_RIGHT:
case BTN_MIDDLE:
case BTN_SIDE:
case BTN_EXTRA:
case BTN_FORWARD:
case BTN_BACK:
case BTN_TASK:
case BTN_STYLUS:
case BTN_STYLUS2:
case BTN_STYLUS3:
break;
default:
evdev_log_info(tablet->device,
"Unhandled button %s (%#x)\n",
libevdev_event_code_get_name(EV_KEY, evcode),
evcode);
return;
}
if (enable) {
set_bit(tablet->button_state.bits, evcode);
tablet_set_status(tablet, TABLET_BUTTONS_PRESSED);
} else {
clear_bit(tablet->button_state.bits, evcode);
tablet_set_status(tablet, TABLET_BUTTONS_RELEASED);
}
}
static inline enum libinput_tablet_tool_type
tablet_evcode_to_tool(int code)
{
enum libinput_tablet_tool_type type;
switch (code) {
case BTN_TOOL_PEN: type = LIBINPUT_TABLET_TOOL_TYPE_PEN; break;
case BTN_TOOL_RUBBER: type = LIBINPUT_TABLET_TOOL_TYPE_ERASER; break;
case BTN_TOOL_BRUSH: type = LIBINPUT_TABLET_TOOL_TYPE_BRUSH; break;
case BTN_TOOL_PENCIL: type = LIBINPUT_TABLET_TOOL_TYPE_PENCIL; break;
case BTN_TOOL_AIRBRUSH: type = LIBINPUT_TABLET_TOOL_TYPE_AIRBRUSH; break;
case BTN_TOOL_MOUSE: type = LIBINPUT_TABLET_TOOL_TYPE_MOUSE; break;
case BTN_TOOL_LENS: type = LIBINPUT_TABLET_TOOL_TYPE_LENS; break;
default:
abort();
}
return type;
}
static void
tablet_process_key(struct tablet_dispatch *tablet,
struct evdev_device *device,
struct input_event *e,
uint64_t time)
{
enum libinput_tablet_tool_type type;
/* ignore kernel key repeat */
if (e->value == 2)
return;
switch (e->code) {
case BTN_TOOL_FINGER:
evdev_log_bug_libinput(device,
"Invalid tool 'finger' on tablet interface\n");
break;
case BTN_TOOL_PEN:
case BTN_TOOL_RUBBER:
case BTN_TOOL_BRUSH:
case BTN_TOOL_PENCIL:
case BTN_TOOL_AIRBRUSH:
case BTN_TOOL_MOUSE:
case BTN_TOOL_LENS:
type = tablet_evcode_to_tool(e->code);
tablet_set_status(tablet, TABLET_TOOL_UPDATED);
if (e->value)
tablet->tool_state |= bit(type);
else
tablet->tool_state &= ~bit(type);
break;
case BTN_TOUCH:
if (!bit_is_set(tablet->axis_caps,
LIBINPUT_TABLET_TOOL_AXIS_PRESSURE)) {
if (e->value)
tablet_set_status(tablet,
TABLET_TOOL_ENTERING_CONTACT);
else
tablet_set_status(tablet,
TABLET_TOOL_LEAVING_CONTACT);
}
break;
default:
tablet_update_button(tablet, e->code, e->value);
break;
}
}
static void
tablet_process_relative(struct tablet_dispatch *tablet,
struct evdev_device *device,
struct input_event *e,
uint64_t time)
{
enum libinput_tablet_tool_axis axis;
switch (e->code) {
case REL_WHEEL:
axis = rel_evcode_to_axis(e->code);
if (axis == LIBINPUT_TABLET_TOOL_AXIS_NONE) {
evdev_log_bug_libinput(device,
"Invalid ABS event code %#x\n",
e->code);
break;
}
set_bit(tablet->changed_axes, axis);
tablet->axes.wheel_discrete = -1 * e->value;
tablet_set_status(tablet, TABLET_AXES_UPDATED);
break;
default:
evdev_log_info(device,
"Unhandled relative axis %s (%#x)\n",
libevdev_event_code_get_name(EV_REL, e->code),
e->code);
return;
}
}
static void
tablet_process_misc(struct tablet_dispatch *tablet,
struct evdev_device *device,
struct input_event *e,
uint64_t time)
{
switch (e->code) {
case MSC_SERIAL:
if (e->value != -1)
tablet->current_tool.serial = e->value;
break;
case MSC_SCAN:
break;
default:
evdev_log_info(device,
"Unhandled MSC event code %s (%#x)\n",
libevdev_event_code_get_name(EV_MSC, e->code),
e->code);
break;
}
}
static inline void
copy_axis_cap(const struct tablet_dispatch *tablet,
struct libinput_tablet_tool *tool,
enum libinput_tablet_tool_axis axis)
{
if (bit_is_set(tablet->axis_caps, axis))
set_bit(tool->axis_caps, axis);
}
static inline void
copy_button_cap(const struct tablet_dispatch *tablet,
struct libinput_tablet_tool *tool,
uint32_t button)
{
struct libevdev *evdev = tablet->device->evdev;
if (libevdev_has_event_code(evdev, EV_KEY, button))
set_bit(tool->buttons, button);
}
static inline bool
tool_set_bits_from_libwacom(const struct tablet_dispatch *tablet,
struct libinput_tablet_tool *tool)
{
bool rc = false;
#if HAVE_LIBWACOM
WacomDeviceDatabase *db;
const WacomStylus *s = NULL;
int code;
WacomStylusType type;
WacomAxisTypeFlags axes;
db = tablet_libinput_context(tablet)->libwacom.db;
if (!db)
return rc;
s = libwacom_stylus_get_for_id(db, tool->tool_id);
if (!s)
return rc;
type = libwacom_stylus_get_type(s);
if (type == WSTYLUS_PUCK) {
for (code = BTN_LEFT;
code < BTN_LEFT + libwacom_stylus_get_num_buttons(s);
code++)
copy_button_cap(tablet, tool, code);
} else {
if (libwacom_stylus_get_num_buttons(s) >= 3)
copy_button_cap(tablet, tool, BTN_STYLUS3);
if (libwacom_stylus_get_num_buttons(s) >= 2)
copy_button_cap(tablet, tool, BTN_STYLUS2);
if (libwacom_stylus_get_num_buttons(s) >= 1)
copy_button_cap(tablet, tool, BTN_STYLUS);
}
if (libwacom_stylus_has_wheel(s))
copy_axis_cap(tablet, tool, LIBINPUT_TABLET_TOOL_AXIS_REL_WHEEL);
axes = libwacom_stylus_get_axes(s);
if (axes & WACOM_AXIS_TYPE_TILT) {
/* tilt on the puck is converted to rotation */
if (type == WSTYLUS_PUCK) {
set_bit(tool->axis_caps,
LIBINPUT_TABLET_TOOL_AXIS_ROTATION_Z);
} else {
copy_axis_cap(tablet,
tool,
LIBINPUT_TABLET_TOOL_AXIS_TILT_X);
copy_axis_cap(tablet,
tool,
LIBINPUT_TABLET_TOOL_AXIS_TILT_Y);
}
}
if (axes & WACOM_AXIS_TYPE_ROTATION_Z)
copy_axis_cap(tablet, tool, LIBINPUT_TABLET_TOOL_AXIS_ROTATION_Z);
if (axes & WACOM_AXIS_TYPE_DISTANCE)
copy_axis_cap(tablet, tool, LIBINPUT_TABLET_TOOL_AXIS_DISTANCE);
if (axes & WACOM_AXIS_TYPE_SLIDER)
copy_axis_cap(tablet, tool, LIBINPUT_TABLET_TOOL_AXIS_SLIDER);
if (axes & WACOM_AXIS_TYPE_PRESSURE)
copy_axis_cap(tablet, tool, LIBINPUT_TABLET_TOOL_AXIS_PRESSURE);
rc = true;
#endif
return rc;
}
static void
tool_set_bits(const struct tablet_dispatch *tablet,
struct libinput_tablet_tool *tool)
{
enum libinput_tablet_tool_type type = tool->type;
copy_axis_cap(tablet, tool, LIBINPUT_TABLET_TOOL_AXIS_X);
copy_axis_cap(tablet, tool, LIBINPUT_TABLET_TOOL_AXIS_Y);
if (tool_set_bits_from_libwacom(tablet, tool))
return;
/* If we don't have libwacom, we simply copy any axis we have on the
tablet onto the tool. Except we know that mice only have rotation
anyway.
*/
switch (type) {
case LIBINPUT_TABLET_TOOL_TYPE_PEN:
case LIBINPUT_TABLET_TOOL_TYPE_ERASER:
case LIBINPUT_TABLET_TOOL_TYPE_PENCIL:
case LIBINPUT_TABLET_TOOL_TYPE_BRUSH:
case LIBINPUT_TABLET_TOOL_TYPE_AIRBRUSH:
copy_axis_cap(tablet, tool, LIBINPUT_TABLET_TOOL_AXIS_PRESSURE);
copy_axis_cap(tablet, tool, LIBINPUT_TABLET_TOOL_AXIS_DISTANCE);
copy_axis_cap(tablet, tool, LIBINPUT_TABLET_TOOL_AXIS_TILT_X);
copy_axis_cap(tablet, tool, LIBINPUT_TABLET_TOOL_AXIS_TILT_Y);
copy_axis_cap(tablet, tool, LIBINPUT_TABLET_TOOL_AXIS_SLIDER);
/* Rotation is special, it can be either ABS_Z or
* BTN_TOOL_MOUSE+ABS_TILT_X/Y. Aiptek tablets have
* mouse+tilt (and thus rotation), but they do not have
* ABS_Z. So let's not copy the axis bit if we don't have
* ABS_Z, otherwise we try to get the value from it later on
* proximity in and go boom because the absinfo isn't there.
*/
if (libevdev_has_event_code(tablet->device->evdev, EV_ABS,
ABS_Z))
copy_axis_cap(tablet, tool, LIBINPUT_TABLET_TOOL_AXIS_ROTATION_Z);
break;
case LIBINPUT_TABLET_TOOL_TYPE_MOUSE:
case LIBINPUT_TABLET_TOOL_TYPE_LENS:
copy_axis_cap(tablet, tool, LIBINPUT_TABLET_TOOL_AXIS_ROTATION_Z);
copy_axis_cap(tablet, tool, LIBINPUT_TABLET_TOOL_AXIS_REL_WHEEL);
break;
default:
break;
}
/* If we don't have libwacom, copy all pen-related buttons from the
tablet vs all mouse-related buttons */
switch (type) {
case LIBINPUT_TABLET_TOOL_TYPE_PEN:
case LIBINPUT_TABLET_TOOL_TYPE_BRUSH:
case LIBINPUT_TABLET_TOOL_TYPE_AIRBRUSH:
case LIBINPUT_TABLET_TOOL_TYPE_PENCIL:
case LIBINPUT_TABLET_TOOL_TYPE_ERASER:
copy_button_cap(tablet, tool, BTN_STYLUS);
copy_button_cap(tablet, tool, BTN_STYLUS2);
copy_button_cap(tablet, tool, BTN_STYLUS3);
break;
case LIBINPUT_TABLET_TOOL_TYPE_MOUSE:
case LIBINPUT_TABLET_TOOL_TYPE_LENS:
copy_button_cap(tablet, tool, BTN_LEFT);
copy_button_cap(tablet, tool, BTN_MIDDLE);
copy_button_cap(tablet, tool, BTN_RIGHT);
copy_button_cap(tablet, tool, BTN_SIDE);
copy_button_cap(tablet, tool, BTN_EXTRA);
break;
default:
break;
}
}
static bool
tablet_get_quirked_pressure_thresholds(struct tablet_dispatch *tablet,
int *hi,
int *lo)
{
struct evdev_device *device = tablet->device;
struct quirks_context *quirks = evdev_libinput_context(device)->quirks;
struct quirks *q = quirks_fetch_for_device(quirks, device->udev_device);
struct quirk_range r;
bool status = false;
/* Note: the quirk term "range" refers to the hi/lo settings, not the
* full available range for the pressure axis */
if (q && quirks_get_range(q, QUIRK_ATTR_PRESSURE_RANGE, &r)) {
if (r.lower < r.upper) {
*hi = r.lower;
*lo = r.upper;
status = true;
} else {
evdev_log_info(device, "Invalid pressure range, using defaults\n");
}
}
quirks_unref(q);
return status;
}
static void
apply_pressure_range_configuration(struct tablet_dispatch *tablet,
struct libinput_tablet_tool *tool,
bool force_update)
{
struct evdev_device *device = tablet->device;
if (!libevdev_has_event_code(device->evdev, EV_ABS, ABS_PRESSURE) ||
(!force_update &&
tool->pressure.range.min == tool->pressure.wanted_range.min &&
tool->pressure.range.max == tool->pressure.wanted_range.max))
return;
double min = tool->pressure.wanted_range.min;
double max = tool->pressure.wanted_range.max;
struct input_absinfo abs = *libevdev_get_abs_info(device->evdev, ABS_PRESSURE);
int minimum = axis_range_percentage(&abs, min * 100.0);
int maximum = axis_range_percentage(&abs, max * 100.0);
abs.minimum = minimum;
abs.maximum = maximum;
/* Only use the quirk pressure range if we don't have a custom range */
int hi, lo;
if (tool->pressure.wanted_range.min != 0.0 ||
tool->pressure.wanted_range.max != 1.0 ||
!tablet_get_quirked_pressure_thresholds(tablet, &hi, &lo)) {
/* 5 and 1% of the pressure range */
hi = axis_range_percentage(&abs, 5);
lo = axis_range_percentage(&abs, 1);
}
struct libinput_tablet_tool_pressure_threshold *threshold =
tablet_tool_get_threshold(tablet, tool);
threshold->abs_pressure = abs;
threshold->threshold.upper = hi;
threshold->threshold.lower = lo;
tool->pressure.range.min = tool->pressure.wanted_range.min;
tool->pressure.range.max = tool->pressure.wanted_range.max;
/* Disable any heuristics */
if (tool->pressure.has_configured_range) {
threshold->has_offset = true;
threshold->heuristic_state = PRESSURE_HEURISTIC_STATE_DONE;
}
}
static inline void
tool_init_pressure_thresholds(struct tablet_dispatch *tablet,
struct libinput_tablet_tool *tool,
struct libinput_tablet_tool_pressure_threshold *threshold)
{
struct evdev_device *device = tablet->device;
const struct input_absinfo *pressure, *distance;
threshold->tablet_id = tablet->tablet_id;
threshold->offset = 0;
threshold->has_offset = false;
threshold->threshold.upper = 1;
threshold->threshold.lower = 0;
pressure = libevdev_get_abs_info(device->evdev, ABS_PRESSURE);
if (!pressure)
return;
threshold->abs_pressure = *pressure;
distance = libevdev_get_abs_info(device->evdev, ABS_DISTANCE);
if (distance) {
threshold->offset = pressure->minimum;
threshold->heuristic_state = PRESSURE_HEURISTIC_STATE_DONE;
} else {
threshold->offset = pressure->maximum;
threshold->heuristic_state = PRESSURE_HEURISTIC_STATE_PROXIN1;
}
apply_pressure_range_configuration(tablet, tool, true);
}
static int
pressure_range_is_available(struct libinput_tablet_tool *tool)
{
return bit_is_set(tool->axis_caps, LIBINPUT_TABLET_TOOL_AXIS_PRESSURE);
}
static enum libinput_config_status
pressure_range_set(struct libinput_tablet_tool *tool, double min, double max)
{
if (min < 0.0 || min >= 1.0 || max <= 0.0 || max > 1.0 || max <= min)
return LIBINPUT_CONFIG_STATUS_INVALID;
tool->pressure.wanted_range.min = min;
tool->pressure.wanted_range.max = max;
tool->pressure.has_configured_range = true;
return LIBINPUT_CONFIG_STATUS_SUCCESS;
}
static void
pressure_range_get(struct libinput_tablet_tool *tool, double *min, double *max)
{
*min = tool->pressure.wanted_range.min;
*max = tool->pressure.wanted_range.max;
}
static void
pressure_range_get_default(struct libinput_tablet_tool *tool, double *min, double *max)
{
*min = 0.0;
*max = 1.0;
}
static struct libinput_tablet_tool *
tablet_new_tool(struct tablet_dispatch *tablet,
enum libinput_tablet_tool_type type,
uint32_t tool_id,
uint32_t serial)
{
struct libinput_tablet_tool *tool = zalloc(sizeof *tool);
*tool = (struct libinput_tablet_tool) {
.type = type,
.serial = serial,
.tool_id = tool_id,
.refcount = 1,
.pressure.range.min = 0.0,
.pressure.range.max = 0.0, /* to trigger configuration */
.pressure.wanted_range.min = 0.0,
.pressure.wanted_range.max = 1.0,
.config.pressure_range.is_available = pressure_range_is_available,
.config.pressure_range.set = pressure_range_set,
.config.pressure_range.get = pressure_range_get,
.config.pressure_range.get_default = pressure_range_get_default,
};
tool_init_pressure_thresholds(tablet, tool, &tool->pressure.thresholds[0]);
tool_set_bits(tablet, tool);
return tool;
}
static struct libinput_tablet_tool *
tablet_get_tool(struct tablet_dispatch *tablet,
enum libinput_tablet_tool_type type,
uint32_t tool_id,
uint32_t serial)
{
struct libinput *libinput = tablet_libinput_context(tablet);
struct libinput_tablet_tool *tool = NULL, *t;
struct list *tool_list;
if (serial) {
tool_list = &libinput->tool_list;
/* Check if we already have the tool in our list of tools */
list_for_each(t, tool_list, link) {
if (type == t->type && serial == t->serial) {
tool = t;
break;
}
}
}
/* If we get a tool with a delayed serial number, we already created
* a 0-serial number tool for it earlier. Re-use that, even though
* it means we can't distinguish this tool from others.
* https://bugs.freedesktop.org/show_bug.cgi?id=97526
*/
if (!tool) {
tool_list = &tablet->tool_list;
/* We can't guarantee that tools without serial numbers are
* unique, so we keep them local to the tablet that they come
* into proximity of instead of storing them in the global tool
* list
* Same as above, but don't bother checking the serial number
*/
list_for_each(t, tool_list, link) {
if (type == t->type) {
tool = t;
break;
}
}
/* Didn't find the tool but we have a serial. Switch
* tool_list back so we create in the correct list */
if (!tool && serial)
tool_list = &libinput->tool_list;
}
/* If we didn't already have the new_tool in our list of tools,
* add it */
if (!tool) {
tool = tablet_new_tool(tablet, type, tool_id, serial);
list_insert(tool_list, &tool->link);
} else {
ARRAY_FOR_EACH(tool->pressure.thresholds, t) {
if (t->tablet_id == tablet->tablet_id)
break;
if (t->tablet_id == 0) {
tool_init_pressure_thresholds(tablet, tool, t);
break;
}
}
}
return tool;
}
static void
tablet_notify_button_mask(struct tablet_dispatch *tablet,
struct evdev_device *device,
uint64_t time,
struct libinput_tablet_tool *tool,
const struct button_state *buttons,
enum libinput_button_state state)
{
struct libinput_device *base = &device->base;
size_t i;
size_t nbits = 8 * sizeof(buttons->bits);
enum libinput_tablet_tool_tip_state tip_state;
if (tablet_has_status(tablet, TABLET_TOOL_IN_CONTACT))
tip_state = LIBINPUT_TABLET_TOOL_TIP_DOWN;
else
tip_state = LIBINPUT_TABLET_TOOL_TIP_UP;
for (i = 0; i < nbits; i++) {
if (!bit_is_set(buttons->bits, i))
continue;
tablet_notify_button(base,
time,
tool,
tip_state,
&tablet->axes,
i,
state,
&tablet->area.x,
&tablet->area.y);
}
}
static void
tablet_notify_buttons(struct tablet_dispatch *tablet,
struct evdev_device *device,
uint64_t time,
struct libinput_tablet_tool *tool,
enum libinput_button_state state)
{
struct button_state buttons;
if (state == LIBINPUT_BUTTON_STATE_PRESSED)
tablet_get_pressed_buttons(tablet, &buttons);
else
tablet_get_released_buttons(tablet, &buttons);
tablet_notify_button_mask(tablet,
device,
time,
tool,
&buttons,
state);
}
static void
sanitize_pressure_distance(struct tablet_dispatch *tablet,
struct libinput_tablet_tool *tool)
{
bool tool_in_contact;
const struct input_absinfo *distance,
*pressure;
distance = libevdev_get_abs_info(tablet->device->evdev, ABS_DISTANCE);
/* Note: for pressure/distance sanitization we use the real pressure
axis, not our configured one */
pressure = libevdev_get_abs_info(tablet->device->evdev, ABS_PRESSURE);
if (!pressure || !distance)
return;
bool pressure_changed = bit_is_set(tablet->changed_axes, LIBINPUT_TABLET_TOOL_AXIS_PRESSURE);
bool distance_changed = bit_is_set(tablet->changed_axes, LIBINPUT_TABLET_TOOL_AXIS_DISTANCE);
if (!pressure_changed && !distance_changed)
return;
/* Note: this is an arbitrary "in contact" decision rather than "tip
* down". We use the lower threshold as minimum pressure value,
* anything less than that gets filtered away */
struct libinput_tablet_tool_pressure_threshold* threshold =
tablet_tool_get_threshold(tablet, tool);
tool_in_contact = (pressure->value > threshold->threshold.lower);
/* Keep distance and pressure mutually exclusive */
if (distance &&
distance->value > distance->minimum &&
pressure->value > pressure->minimum) {
if (tool_in_contact) {
clear_bit(tablet->changed_axes,
LIBINPUT_TABLET_TOOL_AXIS_DISTANCE);
tablet->axes.distance = 0;
} else {
clear_bit(tablet->changed_axes,
LIBINPUT_TABLET_TOOL_AXIS_PRESSURE);
tablet->axes.pressure = 0;
}
} else if (pressure_changed && !tool_in_contact) {
/* Make sure that the last axis value sent to the caller is a 0 */
if (tablet->axes.pressure == 0)
clear_bit(tablet->changed_axes,
LIBINPUT_TABLET_TOOL_AXIS_PRESSURE);
else
tablet->axes.pressure = 0;
}
}
static inline void
sanitize_mouse_lens_rotation(struct tablet_dispatch *tablet)
{
/* If we have a mouse/lens cursor and the tilt changed, the rotation
changed. Mark this, calculate the angle later */
if ((tablet->current_tool.type == LIBINPUT_TABLET_TOOL_TYPE_MOUSE ||
tablet->current_tool.type == LIBINPUT_TABLET_TOOL_TYPE_LENS) &&
(bit_is_set(tablet->changed_axes, LIBINPUT_TABLET_TOOL_AXIS_TILT_X) ||
bit_is_set(tablet->changed_axes, LIBINPUT_TABLET_TOOL_AXIS_TILT_Y)))
set_bit(tablet->changed_axes, LIBINPUT_TABLET_TOOL_AXIS_ROTATION_Z);
}
static void
sanitize_tablet_axes(struct tablet_dispatch *tablet,
struct libinput_tablet_tool *tool)
{
sanitize_pressure_distance(tablet, tool);
sanitize_mouse_lens_rotation(tablet);
}
static void
set_pressure_offset(struct libinput_tablet_tool_pressure_threshold *threshold, int offset)
{
threshold->offset = offset;
threshold->has_offset = true;
/* Adjust the tresholds accordingly - we use the same gap (4% in
* device coordinates) between upper and lower as before which isn't
* technically correct (our range shrunk) but it's easy to calculate.
*/
int gap = threshold->threshold.upper - threshold->threshold.lower;
threshold->threshold.lower = offset;
threshold->threshold.upper = offset + gap;
}
static void
update_pressure_offset(struct tablet_dispatch *tablet,
struct evdev_device *device,
struct libinput_tablet_tool *tool)
{
const struct input_absinfo *pressure =
libevdev_get_abs_info(device->evdev, ABS_PRESSURE);
if (!pressure || tool->pressure.has_configured_range ||
!bit_is_set(tablet->changed_axes, LIBINPUT_TABLET_TOOL_AXIS_PRESSURE))
return;
/* If we have an event that falls below the current offset, adjust
* the offset downwards. A fast contact can start with a
* higher-than-needed pressure offset and then we'd be tied into a
* high pressure offset for the rest of the session.
*
* If we are still pending the offset decision, only update the observed
* offset value, don't actually set it to have an offset.
*/
int offset = pressure->value;
struct libinput_tablet_tool_pressure_threshold *threshold =
tablet_tool_get_threshold(tablet, tool);
if (threshold->has_offset) {
if (offset < threshold->offset)
set_pressure_offset(threshold, offset);
} else if (threshold->heuristic_state != PRESSURE_HEURISTIC_STATE_DONE) {
threshold->offset = min(offset, threshold->offset);
}
}
static void
detect_pressure_offset(struct tablet_dispatch *tablet,
struct evdev_device *device,
struct libinput_tablet_tool *tool)
{
const struct input_absinfo *pressure, *distance;
int offset;
if (tool->pressure.has_configured_range ||
!bit_is_set(tablet->changed_axes, LIBINPUT_TABLET_TOOL_AXIS_PRESSURE))
return;
struct libinput_tablet_tool_pressure_threshold *threshold =
tablet_tool_get_threshold(tablet, tool);
if (threshold->has_offset)
return;
pressure = libevdev_get_abs_info(device->evdev, ABS_PRESSURE);
distance = libevdev_get_abs_info(device->evdev, ABS_DISTANCE);
if (!pressure)
return;
offset = pressure->value;
if (offset <= pressure->minimum)
return;
if (distance) {
/* If we're closer than 50% of the distance axis, skip pressure
* offset detection, too likely to be wrong */
if (distance->value < axis_range_percentage(distance, 50))
return;
} else {
/* A device without distance will always have some pressure on
* contact. Offset detection is delayed for a few proximity ins
* in the hope we'll find the minimum value until then. That
* offset is updated during motion events so by the time the
* deciding prox-in arrives we should know the minimum offset.
*/
if (offset > pressure->minimum)
threshold->offset = min(offset, threshold->offset);
switch (threshold->heuristic_state) {
case PRESSURE_HEURISTIC_STATE_PROXIN1:
case PRESSURE_HEURISTIC_STATE_PROXIN2:
threshold->heuristic_state++;
return;
case PRESSURE_HEURISTIC_STATE_DECIDE:
threshold->heuristic_state++;
offset = threshold->offset;
break;
case PRESSURE_HEURISTIC_STATE_DONE:
return;
}
}
if (offset <= pressure->minimum)
return;
if (offset > axis_range_percentage(pressure, 50)) {
evdev_log_error(device,
"Ignoring pressure offset greater than 50%% detected on tool %s (serial %#x). "
"See %s/tablet-support.html\n",
tablet_tool_type_to_string(tool->type),
tool->serial,
HTTP_DOC_LINK);
return;
}
evdev_log_info(device,
"Pressure offset detected on tool %s (serial %#x). "
"See %s/tablet-support.html\n",
tablet_tool_type_to_string(tool->type),
tool->serial,
HTTP_DOC_LINK);
set_pressure_offset(threshold, offset);
}
static void
detect_tool_contact(struct tablet_dispatch *tablet,
struct evdev_device *device,
struct libinput_tablet_tool *tool)
{
const struct input_absinfo *p;
int pressure;
if (!bit_is_set(tool->axis_caps, LIBINPUT_TABLET_TOOL_AXIS_PRESSURE))
return;
/* if we have pressure, always use that for contact, not BTN_TOUCH */
if (tablet_has_status(tablet, TABLET_TOOL_ENTERING_CONTACT))
evdev_log_bug_libinput(device,
"Invalid status: entering contact\n");
if (tablet_has_status(tablet, TABLET_TOOL_LEAVING_CONTACT) &&
!tablet_has_status(tablet, TABLET_TOOL_LEAVING_PROXIMITY))
evdev_log_bug_libinput(device,
"Invalid status: leaving contact\n");
p = libevdev_get_abs_info(tablet->device->evdev, ABS_PRESSURE);
if (!p) {
evdev_log_bug_libinput(device,
"Missing pressure axis\n");
return;
}
pressure = p->value;
struct libinput_tablet_tool_pressure_threshold *threshold =
tablet_tool_get_threshold(tablet, tool);
if (pressure <= threshold->threshold.lower &&
tablet_has_status(tablet, TABLET_TOOL_IN_CONTACT)) {
tablet_set_status(tablet, TABLET_TOOL_LEAVING_CONTACT);
} else if (pressure >= threshold->threshold.upper &&
!tablet_has_status(tablet, TABLET_TOOL_IN_CONTACT)) {
tablet_set_status(tablet, TABLET_TOOL_ENTERING_CONTACT);
}
}
static void
tablet_mark_all_axes_changed(struct tablet_dispatch *tablet,
struct libinput_tablet_tool *tool)
{
static_assert(sizeof(tablet->changed_axes) ==
sizeof(tool->axis_caps),
"Mismatching array sizes");
memcpy(tablet->changed_axes,
tool->axis_caps,
sizeof(tablet->changed_axes));
}
static void
tablet_update_proximity_state(struct tablet_dispatch *tablet,
struct evdev_device *device,
struct libinput_tablet_tool *tool)
{
const struct input_absinfo *distance;
int dist_max = tablet->cursor_proximity_threshold;
int dist;
distance = libevdev_get_abs_info(tablet->device->evdev, ABS_DISTANCE);
if (!distance)
return;
dist = distance->value;
if (dist == 0)
return;
/* Tool got into permitted range */
if (dist < dist_max &&
(tablet_has_status(tablet, TABLET_TOOL_OUT_OF_RANGE) ||
tablet_has_status(tablet, TABLET_TOOL_OUT_OF_PROXIMITY))) {
tablet_unset_status(tablet,
TABLET_TOOL_OUT_OF_RANGE);
tablet_unset_status(tablet,
TABLET_TOOL_OUT_OF_PROXIMITY);
tablet_set_status(tablet, TABLET_TOOL_ENTERING_PROXIMITY);
tablet_mark_all_axes_changed(tablet, tool);
tablet_set_status(tablet, TABLET_BUTTONS_PRESSED);
tablet_force_button_presses(tablet);
return;
}
if (dist < dist_max)
return;
/* Still out of range/proximity */
if (tablet_has_status(tablet, TABLET_TOOL_OUT_OF_RANGE) ||
tablet_has_status(tablet, TABLET_TOOL_OUT_OF_PROXIMITY))
return;
/* Tool entered prox but is outside of permitted range */
if (tablet_has_status(tablet,
TABLET_TOOL_ENTERING_PROXIMITY)) {
tablet_set_status(tablet,
TABLET_TOOL_OUT_OF_RANGE);
tablet_unset_status(tablet,
TABLET_TOOL_ENTERING_PROXIMITY);
return;
}
/* Tool was in prox and is now outside of range. Set leaving
* proximity, on the next event it will be OUT_OF_PROXIMITY and thus
* caught by the above conditions */
tablet_set_status(tablet, TABLET_TOOL_LEAVING_PROXIMITY);
}
static struct phys_rect
tablet_calculate_arbitration_rect(struct tablet_dispatch *tablet)
{
struct evdev_device *device = tablet->device;
struct phys_rect r = {0};
struct phys_coords mm;
mm = evdev_device_units_to_mm(device, &tablet->axes.point);
/* The rect we disable is 20mm left of the tip, 100mm north of the
* tip, and 200x250mm large.
* If the stylus is tilted left (tip further right than the eraser
* end) assume left-handed mode.
*
* Obviously if we'd run out of the boundaries, we clip the rect
* accordingly.
*/
if (tablet->axes.tilt.x > 0) {
r.x = mm.x - 20;
r.w = 200;
} else {
r.x = mm.x + 20;
r.w = 200;
r.x -= r.w;
}
if (r.x < 0) {
r.w += r.x;
r.x = 0;
}
r.y = mm.y - 100;
r.h = 250;
if (r.y < 0) {
r.h += r.y;
r.y = 0;
}
return r;
}
static inline void
tablet_update_touch_device_rect(struct tablet_dispatch *tablet,
const struct tablet_axes *axes,
uint64_t time)
{
struct evdev_dispatch *dispatch;
struct phys_rect rect = {0};
if (tablet->touch_device == NULL ||
tablet->arbitration != ARBITRATION_IGNORE_RECT)
return;
rect = tablet_calculate_arbitration_rect(tablet);
dispatch = tablet->touch_device->dispatch;
if (dispatch->interface->touch_arbitration_update_rect)
dispatch->interface->touch_arbitration_update_rect(dispatch,
tablet->touch_device,
&rect,
time);
}
static inline bool
tablet_send_proximity_in(struct tablet_dispatch *tablet,
struct libinput_tablet_tool *tool,
struct evdev_device *device,
struct tablet_axes *axes,
uint64_t time)
{
if (!tablet_has_status(tablet, TABLET_TOOL_ENTERING_PROXIMITY))
return false;
tablet_notify_proximity(&device->base,
time,
tool,
LIBINPUT_TABLET_TOOL_PROXIMITY_STATE_IN,
tablet->changed_axes,
axes,
&tablet->area.x,
&tablet->area.y);
tablet_unset_status(tablet, TABLET_TOOL_ENTERING_PROXIMITY);
tablet_unset_status(tablet, TABLET_AXES_UPDATED);
tablet_reset_changed_axes(tablet);
axes->delta.x = 0;
axes->delta.y = 0;
return true;
}
static inline void
tablet_send_proximity_out(struct tablet_dispatch *tablet,
struct libinput_tablet_tool *tool,
struct evdev_device *device,
struct tablet_axes *axes,
uint64_t time)
{
if (tablet_has_status(tablet, TABLET_TOOL_LEAVING_PROXIMITY) &&
!tablet_has_status(tablet, TABLET_TOOL_OUTSIDE_AREA)) {
tablet_notify_proximity(&device->base,
time,
tool,
LIBINPUT_TABLET_TOOL_PROXIMITY_STATE_OUT,
tablet->changed_axes,
axes,
&tablet->area.x,
&tablet->area.y);
}
}
static inline bool
tablet_send_tip(struct tablet_dispatch *tablet,
struct libinput_tablet_tool *tool,
struct evdev_device *device,
struct tablet_axes *axes,
uint64_t time)
{
if (tablet_has_status(tablet, TABLET_TOOL_ENTERING_CONTACT)) {
tablet_notify_tip(&device->base,
time,
tool,
LIBINPUT_TABLET_TOOL_TIP_DOWN,
tablet->changed_axes,
axes,
&tablet->area.x,
&tablet->area.y);
tablet_unset_status(tablet, TABLET_AXES_UPDATED);
tablet_unset_status(tablet, TABLET_TOOL_ENTERING_CONTACT);
tablet_set_status(tablet, TABLET_TOOL_IN_CONTACT);
tablet_reset_changed_axes(tablet);
axes->delta.x = 0;
axes->delta.y = 0;
return true;
}
if (tablet_has_status(tablet, TABLET_TOOL_LEAVING_CONTACT)) {
tablet_notify_tip(&device->base,
time,
tool,
LIBINPUT_TABLET_TOOL_TIP_UP,
tablet->changed_axes,
axes,
&tablet->area.x,
&tablet->area.y);
tablet_unset_status(tablet, TABLET_AXES_UPDATED);
tablet_unset_status(tablet, TABLET_TOOL_LEAVING_CONTACT);
tablet_unset_status(tablet, TABLET_TOOL_IN_CONTACT);
tablet_reset_changed_axes(tablet);
axes->delta.x = 0;
axes->delta.y = 0;
return true;
}
return false;
}
static inline void
tablet_send_axes(struct tablet_dispatch *tablet,
struct libinput_tablet_tool *tool,
struct evdev_device *device,
struct tablet_axes *axes,
uint64_t time)
{
enum libinput_tablet_tool_tip_state tip_state;
if (!tablet_has_status(tablet, TABLET_AXES_UPDATED))
return;
if (tablet_has_status(tablet,
TABLET_TOOL_IN_CONTACT))
tip_state = LIBINPUT_TABLET_TOOL_TIP_DOWN;
else
tip_state = LIBINPUT_TABLET_TOOL_TIP_UP;
tablet_notify_axis(&device->base,
time,
tool,
tip_state,
tablet->changed_axes,
axes,
&tablet->area.x,
&tablet->area.y);
tablet_unset_status(tablet, TABLET_AXES_UPDATED);
tablet_reset_changed_axes(tablet);
axes->delta.x = 0;
axes->delta.y = 0;
}
static inline void
tablet_send_buttons(struct tablet_dispatch *tablet,
struct libinput_tablet_tool *tool,
struct evdev_device *device,
uint64_t time)
{
if (tablet_has_status(tablet, TABLET_BUTTONS_RELEASED)) {
tablet_notify_buttons(tablet,
device,
time,
tool,
LIBINPUT_BUTTON_STATE_RELEASED);
tablet_unset_status(tablet, TABLET_BUTTONS_RELEASED);
}
if (tablet_has_status(tablet, TABLET_BUTTONS_PRESSED)) {
tablet_notify_buttons(tablet,
device,
time,
tool,
LIBINPUT_BUTTON_STATE_PRESSED);
tablet_unset_status(tablet, TABLET_BUTTONS_PRESSED);
}
}
static void
tablet_send_events(struct tablet_dispatch *tablet,
struct libinput_tablet_tool *tool,
struct evdev_device *device,
uint64_t time)
{
struct tablet_axes axes = {0};
if (tablet_has_status(tablet, TABLET_TOOL_LEAVING_PROXIMITY)) {
/* Tool is leaving proximity, we can't rely on the last axis
* information (it'll be mostly 0), so we just get the
* current state and skip over updating the axes.
*/
axes = tablet->axes;
/* Don't send an axis event, but we may have a tip event
* update */
tablet_unset_status(tablet, TABLET_AXES_UPDATED);
} else {
if (tablet_check_notify_axes(tablet, device, tool, &axes, time))
tablet_update_touch_device_rect(tablet, &axes, time);
}
assert(tablet->axes.delta.x == 0);
assert(tablet->axes.delta.y == 0);
tablet_send_proximity_in(tablet, tool, device, &axes, time);
if (!tablet_send_tip(tablet, tool, device, &axes, time))
tablet_send_axes(tablet, tool, device, &axes, time);
tablet_unset_status(tablet, TABLET_TOOL_ENTERING_CONTACT);
tablet_reset_changed_axes(tablet);
tablet_send_buttons(tablet, tool, device, time);
tablet_send_proximity_out(tablet, tool, device, &axes, time);
}
/**
* Handling for the proximity out workaround. Some tablets only send
* BTN_TOOL_PEN on the very first event, then leave it set even when the pen
* leaves the detectable range. To libinput this looks like we always have
* the pen in proximity.
*
* To avoid this, we set a timer on BTN_TOOL_PEN in. We expect the tablet to
* continuously send events, and while it's doing so we keep updating the
* timer. Once we go Xms without an event we assume proximity out and inject
* a BTN_TOOL_PEN event into the sequence through the timer func.
*
* We need to remember that we did that, on the first event after the
* timeout we need to emulate a BTN_TOOL_PEN event again to force proximity
* in.
*
* Other tools never send the BTN_TOOL_PEN event. For those tools, we
* piggyback along with the proximity out quirks by injecting
* the event during the first event frame.
*/
static inline void
tablet_proximity_out_quirk_set_timer(struct tablet_dispatch *tablet,
uint64_t time)
{
if (tablet->quirks.need_to_force_prox_out)
libinput_timer_set(&tablet->quirks.prox_out_timer,
time + FORCED_PROXOUT_TIMEOUT);
}
static bool
tablet_update_tool_state(struct tablet_dispatch *tablet,
struct evdev_device *device,
uint64_t time)
{
enum libinput_tablet_tool_type type;
uint32_t changed;
int state;
uint32_t doubled_up_new_tool_bit = 0;
/* we were already out of proximity but now got a tool update but
* our tool state is zero - i.e. we got a valid prox out from the
* device.
*/
if (tablet->quirks.proximity_out_forced &&
tablet_has_status(tablet, TABLET_TOOL_UPDATED) &&
!tablet->tool_state) {
tablet->quirks.need_to_force_prox_out = false;
tablet->quirks.proximity_out_forced = false;
}
/* We need to emulate a BTN_TOOL_PEN if we get an axis event (i.e.
* stylus is def. in proximity) and:
* - we forced a proximity out before, or
* - on the very first event after init, because if we didn't get a
* BTN_TOOL_PEN and the state for the tool was 0, this device will
* never send the event.
* We don't do this for pure button events because we discard those.
*
* But: on some devices the proximity out is delayed by the kernel,
* so we get it after our forced prox-out has triggered. In that
* case we need to just ignore the change.
*/
if (tablet_has_status(tablet, TABLET_AXES_UPDATED)) {
if (tablet->quirks.proximity_out_forced) {
if (!tablet_has_status(tablet, TABLET_TOOL_UPDATED) &&
!tablet->tool_state)
tablet->tool_state = bit(LIBINPUT_TABLET_TOOL_TYPE_PEN);
tablet->quirks.proximity_out_forced = false;
} else if (tablet->tool_state == 0 &&
tablet->current_tool.type == LIBINPUT_TOOL_NONE) {
tablet->tool_state = bit(LIBINPUT_TABLET_TOOL_TYPE_PEN);
tablet->quirks.proximity_out_forced = false;
}
}
if (tablet->tool_state == tablet->prev_tool_state)
return false;
/* Kernel tools are supposed to be mutually exclusive, but we may have
* two bits set due to firmware/kernel bugs.
* Two cases that have been seen in the wild:
* - BTN_TOOL_PEN on proximity in, followed by
* BTN_TOOL_RUBBER later, see #259
* -> We force a prox-out of the pen, trigger prox-in for eraser
* - BTN_TOOL_RUBBER on proximity in, but BTN_TOOL_PEN when
* the tip is down, see #702.
* -> We ignore BTN_TOOL_PEN
* In both cases the eraser is what we want, so we bias
* towards that.
*/
if (tablet->tool_state & (tablet->tool_state - 1)) {
doubled_up_new_tool_bit = tablet->tool_state ^ tablet->prev_tool_state;
/* The new tool is the pen. Ignore it */
if (doubled_up_new_tool_bit == bit(LIBINPUT_TABLET_TOOL_TYPE_PEN)) {
tablet->tool_state &= ~bit(LIBINPUT_TABLET_TOOL_TYPE_PEN);
return false;
}
/* The new tool is some tool other than pen (usually eraser).
* We set the current tool state to zero, thus setting
* everything up for a prox out on the tool. Once that is set
* up, we change the tool state to be the new one we just got.
* When we re-process this function we now get the new tool
* as prox in. Importantly, we basically rely on nothing else
* happening in the meantime.
*/
tablet->tool_state = 0;
}
changed = tablet->tool_state ^ tablet->prev_tool_state;
type = ffs(changed) - 1;
state = !!(tablet->tool_state & bit(type));
tablet_update_tool(tablet, device, type, state);
/* The proximity timeout is only needed for BTN_TOOL_PEN, devices
* that require it don't do erasers */
if (type == LIBINPUT_TABLET_TOOL_TYPE_PEN) {
if (state) {
tablet_proximity_out_quirk_set_timer(tablet, time);
} else {
/* If we get a BTN_TOOL_PEN 0 when *not* injecting
* events it means the tablet will give us the right
* events after all and we can disable our
* timer-based proximity out.
*/
if (!tablet->quirks.proximity_out_in_progress)
tablet->quirks.need_to_force_prox_out = false;
libinput_timer_cancel(&tablet->quirks.prox_out_timer);
}
}
tablet->prev_tool_state = tablet->tool_state;
if (doubled_up_new_tool_bit) {
tablet->tool_state = doubled_up_new_tool_bit;
return true; /* need to re-process */
}
return false;
}
static struct libinput_tablet_tool *
tablet_get_current_tool(struct tablet_dispatch *tablet)
{
if (tablet->current_tool.type == LIBINPUT_TOOL_NONE)
return NULL;
return tablet_get_tool(tablet,
tablet->current_tool.type,
tablet->current_tool.id,
tablet->current_tool.serial);
}
static void
tablet_flush(struct tablet_dispatch *tablet,
struct evdev_device *device,
uint64_t time)
{
struct libinput_tablet_tool *tool;
bool process_tool_twice;
reprocess:
process_tool_twice = tablet_update_tool_state(tablet, device, time);
tool = tablet_get_current_tool(tablet);
if (!tool)
return; /* OOM */
if (tool->type == LIBINPUT_TABLET_TOOL_TYPE_MOUSE ||
tool->type == LIBINPUT_TABLET_TOOL_TYPE_LENS)
tablet_update_proximity_state(tablet, device, tool);
if (tablet_has_status(tablet, TABLET_TOOL_OUT_OF_PROXIMITY) ||
tablet_has_status(tablet, TABLET_TOOL_OUT_OF_RANGE))
return;
if (tablet_has_status(tablet, TABLET_TOOL_LEAVING_PROXIMITY)) {
/* Release all stylus buttons */
memset(tablet->button_state.bits,
0,
sizeof(tablet->button_state.bits));
tablet_set_status(tablet, TABLET_BUTTONS_RELEASED);
if (tablet_has_status(tablet, TABLET_TOOL_IN_CONTACT))
tablet_set_status(tablet, TABLET_TOOL_LEAVING_CONTACT);
apply_pressure_range_configuration(tablet, tool, false);
} else if (!tablet_has_status(tablet, TABLET_TOOL_OUTSIDE_AREA)) {
if (tablet_has_status(tablet, TABLET_TOOL_ENTERING_PROXIMITY)) {
/* If we get into proximity outside the tablet area, we ignore
* that whole sequence of events even if we later move into
* the allowed area. This may be bad UX but it's complicated to
* implement so let's wait for someone to actually complain
* about it.
*
* We allow a margin of 3% (6mm on a 200mm tablet) to be "within"
* the area - there we clip to the area but do not ignore the
* sequence.
*/
const struct device_coords point = {
device->abs.absinfo_x->value,
device->abs.absinfo_y->value,
};
const double margin = 0.03;
if (is_inside_area(tablet, &point, margin)) {
tablet_mark_all_axes_changed(tablet, tool);
update_pressure_offset(tablet, device, tool);
detect_pressure_offset(tablet, device, tool);
detect_tool_contact(tablet, device, tool);
sanitize_tablet_axes(tablet, tool);
} else {
tablet_set_status(tablet, TABLET_TOOL_OUTSIDE_AREA);
tablet_unset_status(tablet, TABLET_TOOL_ENTERING_PROXIMITY);
}
} else if (tablet_has_status(tablet, TABLET_AXES_UPDATED)) {
update_pressure_offset(tablet, device, tool);
detect_tool_contact(tablet, device, tool);
sanitize_tablet_axes(tablet, tool);
}
}
if (!tablet_has_status(tablet, TABLET_TOOL_OUTSIDE_AREA))
tablet_send_events(tablet, tool, device, time);
if (tablet_has_status(tablet, TABLET_TOOL_LEAVING_PROXIMITY)) {
tablet_set_status(tablet, TABLET_TOOL_OUT_OF_PROXIMITY);
tablet_unset_status(tablet, TABLET_TOOL_LEAVING_PROXIMITY);
tablet_unset_status(tablet, TABLET_TOOL_OUTSIDE_AREA);
tablet_reset_changed_axes(tablet);
tablet_change_to_left_handed(device);
tablet_apply_rotation(device);
tablet_change_area(device);
tablet_history_reset(tablet);
}
if (process_tool_twice)
goto reprocess;
}
static inline void
tablet_set_touch_device_enabled(struct tablet_dispatch *tablet,
enum evdev_arbitration_state which,
const struct phys_rect *rect,
uint64_t time)
{
struct evdev_device *touch_device = tablet->touch_device;
struct evdev_dispatch *dispatch;
if (touch_device == NULL)
return;
tablet->arbitration = which;
dispatch = touch_device->dispatch;
if (dispatch->interface->touch_arbitration_toggle)
dispatch->interface->touch_arbitration_toggle(dispatch,
touch_device,
which,
rect,
time);
}
static inline void
tablet_toggle_touch_device(struct tablet_dispatch *tablet,
struct evdev_device *tablet_device,
uint64_t time)
{
enum evdev_arbitration_state which;
struct phys_rect r = {0};
struct phys_rect *rect = NULL;
if (tablet_has_status(tablet,
TABLET_TOOL_OUT_OF_RANGE) ||
tablet_has_status(tablet, TABLET_NONE) ||
tablet_has_status(tablet,
TABLET_TOOL_LEAVING_PROXIMITY) ||
tablet_has_status(tablet,
TABLET_TOOL_OUT_OF_PROXIMITY)) {
which = ARBITRATION_NOT_ACTIVE;
} else if (tablet->axes.tilt.x == 0) {
which = ARBITRATION_IGNORE_ALL;
} else if (tablet->arbitration != ARBITRATION_IGNORE_RECT) {
/* This enables rect-based arbitration, updates are sent
* elsewhere */
r = tablet_calculate_arbitration_rect(tablet);
rect = &r;
which = ARBITRATION_IGNORE_RECT;
} else {
return;
}
tablet_set_touch_device_enabled(tablet,
which,
rect,
time);
}
static inline void
tablet_reset_state(struct tablet_dispatch *tablet)
{
struct button_state zero = {0};
/* Update state */
memcpy(&tablet->prev_button_state,
&tablet->button_state,
sizeof(tablet->button_state));
tablet_unset_status(tablet, TABLET_TOOL_UPDATED);
if (memcmp(&tablet->button_state, &zero, sizeof(zero)) == 0)
tablet_unset_status(tablet, TABLET_BUTTONS_DOWN);
else
tablet_set_status(tablet, TABLET_BUTTONS_DOWN);
}
static void
tablet_proximity_out_quirk_timer_func(uint64_t now, void *data)
{
struct tablet_dispatch *tablet = data;
struct timeval tv = us2tv(now);
struct input_event events[2] = {
{ .input_event_sec = tv.tv_sec,
.input_event_usec = tv.tv_usec,
.type = EV_KEY,
.code = BTN_TOOL_PEN,
.value = 0 },
{ .input_event_sec = tv.tv_sec,
.input_event_usec = tv.tv_usec,
.type = EV_SYN,
.code = SYN_REPORT,
.value = 0 },
};
if (tablet_has_status(tablet, TABLET_TOOL_IN_CONTACT) ||
tablet_has_status(tablet, TABLET_BUTTONS_DOWN)) {
tablet_proximity_out_quirk_set_timer(tablet, now);
return;
}
if (tablet->quirks.last_event_time > now - FORCED_PROXOUT_TIMEOUT) {
tablet_proximity_out_quirk_set_timer(tablet,
tablet->quirks.last_event_time);
return;
}
evdev_log_debug(tablet->device, "tablet: forcing proximity after timeout\n");
tablet->quirks.proximity_out_in_progress = true;
ARRAY_FOR_EACH(events, e) {
tablet->base.interface->process(&tablet->base,
tablet->device,
e,
now);
}
tablet->quirks.proximity_out_in_progress = false;
tablet->quirks.proximity_out_forced = true;
}
static void
tablet_process(struct evdev_dispatch *dispatch,
struct evdev_device *device,
struct input_event *e,
uint64_t time)
{
struct tablet_dispatch *tablet = tablet_dispatch(dispatch);
switch (e->type) {
case EV_ABS:
tablet_process_absolute(tablet, device, e, time);
break;
case EV_REL:
tablet_process_relative(tablet, device, e, time);
break;
case EV_KEY:
tablet_process_key(tablet, device, e, time);
break;
case EV_MSC:
tablet_process_misc(tablet, device, e, time);
break;
case EV_SYN:
tablet_flush(tablet, device, time);
tablet_toggle_touch_device(tablet, device, time);
tablet_reset_state(tablet);
tablet->quirks.last_event_time = time;
break;
default:
evdev_log_error(device,
"Unexpected event type %s (%#x)\n",
libevdev_event_type_get_name(e->type),
e->type);
break;
}
}
static void
tablet_suspend(struct evdev_dispatch *dispatch,
struct evdev_device *device)
{
struct tablet_dispatch *tablet = tablet_dispatch(dispatch);
struct libinput *li = tablet_libinput_context(tablet);
uint64_t now = libinput_now(li);
tablet_set_touch_device_enabled(tablet,
ARBITRATION_NOT_ACTIVE,
NULL,
now);
if (!tablet_has_status(tablet, TABLET_TOOL_OUT_OF_PROXIMITY)) {
tablet_set_status(tablet, TABLET_TOOL_LEAVING_PROXIMITY);
tablet_flush(tablet, device, libinput_now(li));
}
}
static void
tablet_destroy(struct evdev_dispatch *dispatch)
{
struct tablet_dispatch *tablet = tablet_dispatch(dispatch);
struct libinput_tablet_tool *tool;
struct libinput *li = tablet_libinput_context(tablet);
libinput_timer_cancel(&tablet->quirks.prox_out_timer);
libinput_timer_destroy(&tablet->quirks.prox_out_timer);
list_for_each(tool, &li->tool_list, link) {
ARRAY_FOR_EACH(tool->pressure.thresholds, threshold) {
if (threshold->tablet_id == tablet->tablet_id) {
threshold->tablet_id = 0;
break;
}
}
}
list_for_each_safe(tool, &tablet->tool_list, link) {
libinput_tablet_tool_unref(tool);
}
libinput_libwacom_unref(li);
free(tablet);
}
static void
tablet_setup_touch_arbitration(struct evdev_device *device,
struct evdev_device *new_device)
{
struct tablet_dispatch *tablet = tablet_dispatch(device->dispatch);
/* We enable touch arbitration with the first touch screen/external
* touchpad we see. This may be wrong in some cases, so we have some
* heuristics in case we find a "better" device.
*/
if (tablet->touch_device != NULL) {
struct libinput_device_group *group1 = libinput_device_get_device_group(&device->base);
struct libinput_device_group *group2 = libinput_device_get_device_group(&new_device->base);
/* same phsical device? -> better, otherwise keep the one we have */
if (group1 != group2)
return;
/* We found a better device, let's swap it out */
struct libinput *li = tablet_libinput_context(tablet);
tablet_set_touch_device_enabled(tablet,
ARBITRATION_NOT_ACTIVE,
NULL,
libinput_now(li));
evdev_log_debug(device,
"touch-arbitration: removing pairing for %s<->%s\n",
device->devname,
tablet->touch_device->devname);
}
evdev_log_debug(device,
"touch-arbitration: activated for %s<->%s\n",
device->devname,
new_device->devname);
tablet->touch_device = new_device;
}
static void
tablet_setup_rotation(struct evdev_device *device,
struct evdev_device *new_device)
{
struct tablet_dispatch *tablet = tablet_dispatch(device->dispatch);
struct libinput_device_group *group1 = libinput_device_get_device_group(&device->base);
struct libinput_device_group *group2 = libinput_device_get_device_group(&new_device->base);
if (tablet->rotation.touch_device == NULL && (group1 == group2)) {
evdev_log_debug(device,
"tablet-rotation: %s will rotate %s\n",
device->devname,
new_device->devname);
tablet->rotation.touch_device = new_device;
if (libinput_device_config_left_handed_get(&new_device->base)) {
tablet->rotation.touch_device_left_handed_state = true;
tablet_change_rotation(device, DO_NOTIFY);
}
}
}
static void
tablet_device_added(struct evdev_device *device,
struct evdev_device *added_device)
{
bool is_touchscreen, is_ext_touchpad;
is_touchscreen = evdev_device_has_capability(added_device,
LIBINPUT_DEVICE_CAP_TOUCH);
is_ext_touchpad = evdev_device_has_capability(added_device,
LIBINPUT_DEVICE_CAP_POINTER) &&
(added_device->tags & EVDEV_TAG_EXTERNAL_TOUCHPAD);
if (is_touchscreen || is_ext_touchpad)
tablet_setup_touch_arbitration(device, added_device);
if (is_ext_touchpad)
tablet_setup_rotation(device, added_device);
}
static void
tablet_device_removed(struct evdev_device *device,
struct evdev_device *removed_device)
{
struct tablet_dispatch *tablet = tablet_dispatch(device->dispatch);
if (tablet->touch_device == removed_device)
tablet->touch_device = NULL;
if (tablet->rotation.touch_device == removed_device) {
tablet->rotation.touch_device = NULL;
tablet->rotation.touch_device_left_handed_state = false;
tablet_change_rotation(device, DO_NOTIFY);
}
}
static void
tablet_check_initial_proximity(struct evdev_device *device,
struct evdev_dispatch *dispatch)
{
struct tablet_dispatch *tablet = tablet_dispatch(dispatch);
struct libinput *li = tablet_libinput_context(tablet);
int code, state;
enum libinput_tablet_tool_type tool;
for (tool = LIBINPUT_TABLET_TOOL_TYPE_PEN;
tool <= LIBINPUT_TABLET_TOOL_TYPE_MAX;
tool++) {
code = tablet_tool_to_evcode(tool);
/* we only expect one tool to be in proximity at a time */
if (libevdev_fetch_event_value(device->evdev,
EV_KEY,
code,
&state) && state) {
tablet->tool_state = bit(tool);
tablet->prev_tool_state = bit(tool);
break;
}
}
if (!tablet->tool_state)
return;
tablet_update_tool(tablet, device, tool, state);
if (tablet->quirks.need_to_force_prox_out)
tablet_proximity_out_quirk_set_timer(tablet, libinput_now(li));
tablet->current_tool.id =
libevdev_get_event_value(device->evdev,
EV_ABS,
ABS_MISC);
/* we can't fetch MSC_SERIAL from the kernel, so we set the serial
* to 0 for now. On the first real event from the device we get the
* serial (if any) and that event will be converted into a proximity
* event */
tablet->current_tool.serial = 0;
}
/* Called when the touchpad toggles to left-handed */
static void
tablet_left_handed_toggled(struct evdev_dispatch *dispatch,
struct evdev_device *device,
bool left_handed_enabled)
{
struct tablet_dispatch *tablet = tablet_dispatch(dispatch);
if (!tablet->rotation.touch_device)
return;
evdev_log_debug(device,
"tablet-rotation: touchpad is %s\n",
left_handed_enabled ? "left-handed" : "right-handed");
/* Our left-handed config is independent even though rotation is
* locked. So we rotate when either device is left-handed. But it
* can only be actually changed when the device is in a neutral
* state, hence the want_rotate.
*/
tablet->rotation.touch_device_left_handed_state = left_handed_enabled;
tablet_change_rotation(device, DONT_NOTIFY);
}
static struct evdev_dispatch_interface tablet_interface = {
.process = tablet_process,
.suspend = tablet_suspend,
.remove = NULL,
.destroy = tablet_destroy,
.device_added = tablet_device_added,
.device_removed = tablet_device_removed,
.device_suspended = NULL,
.device_resumed = NULL,
.post_added = tablet_check_initial_proximity,
.touch_arbitration_toggle = NULL,
.touch_arbitration_update_rect = NULL,
.get_switch_state = NULL,
.left_handed_toggle = tablet_left_handed_toggled,
};
static void
tablet_init_calibration(struct tablet_dispatch *tablet,
struct evdev_device *device,
bool is_display_tablet)
{
if (is_display_tablet || libevdev_has_property(device->evdev, INPUT_PROP_DIRECT))
evdev_init_calibration(device, &tablet->calibration);
}
static int
tablet_area_has_rectangle(struct libinput_device *device)
{
return 1;
}
static enum libinput_config_status
tablet_area_set_rectangle(struct libinput_device *device,
const struct libinput_config_area_rectangle *rectangle)
{
struct evdev_device *evdev = evdev_device(device);
struct tablet_dispatch *tablet = tablet_dispatch(evdev->dispatch);
if (rectangle->x1 >= rectangle->x2 || rectangle->y1 >= rectangle->y2)
return LIBINPUT_CONFIG_STATUS_INVALID;
if (rectangle->x1 < 0.0 || rectangle->x2 > 1.0 ||
rectangle->y1 < 0.0 || rectangle->y2 > 1.0)
return LIBINPUT_CONFIG_STATUS_INVALID;
tablet->area.want_rect = *rectangle;
tablet_change_area(evdev);
return LIBINPUT_CONFIG_STATUS_SUCCESS;
}
static struct libinput_config_area_rectangle
tablet_area_get_rectangle(struct libinput_device *device)
{
struct evdev_device *evdev = evdev_device(device);
struct tablet_dispatch *tablet = tablet_dispatch(evdev->dispatch);
return tablet->area.rect;
}
static struct libinput_config_area_rectangle
tablet_area_get_default_rectangle(struct libinput_device *device)
{
struct libinput_config_area_rectangle rect = {
0.0, 0.0, 1.0, 1.0,
};
return rect;
}
static void
tablet_init_area(struct tablet_dispatch *tablet,
struct evdev_device *device)
{
tablet->area.rect = (struct libinput_config_area_rectangle) {
0.0, 0.0, 1.0, 1.0,
};
tablet->area.want_rect = tablet->area.rect;
tablet->area.x = *device->abs.absinfo_x;
tablet->area.y = *device->abs.absinfo_y;
if (!libevdev_has_property(device->evdev, INPUT_PROP_DIRECT)) {
device->base.config.area = &tablet->area.config;
tablet->area.config.has_rectangle = tablet_area_has_rectangle;
tablet->area.config.set_rectangle = tablet_area_set_rectangle;
tablet->area.config.get_rectangle = tablet_area_get_rectangle;
tablet->area.config.get_default_rectangle = tablet_area_get_default_rectangle;
}
}
static void
tablet_init_proximity_threshold(struct tablet_dispatch *tablet,
struct evdev_device *device)
{
/* This rules out most of the bamboos and other devices, we're
* pretty much down to
*/
if (!libevdev_has_event_code(device->evdev, EV_KEY, BTN_TOOL_MOUSE) &&
!libevdev_has_event_code(device->evdev, EV_KEY, BTN_TOOL_LENS))
return;
/* 42 is the default proximity threshold the xf86-input-wacom driver
* uses for Intuos/Cintiq models. Graphire models have a threshold
* of 10 but since they haven't been manufactured in ages and the
* intersection of users having a graphire, running libinput and
* wanting to use the mouse/lens cursor tool is small enough to not
* worry about it for now. If we need to, we can introduce a udev
* property later.
*
* Value is in device coordinates.
*/
tablet->cursor_proximity_threshold = 42;
}
static uint32_t
tablet_accel_config_get_profiles(struct libinput_device *libinput_device)
{
return LIBINPUT_CONFIG_ACCEL_PROFILE_NONE;
}
static enum libinput_config_status
tablet_accel_config_set_profile(struct libinput_device *libinput_device,
enum libinput_config_accel_profile profile)
{
return LIBINPUT_CONFIG_STATUS_UNSUPPORTED;
}
static enum libinput_config_accel_profile
tablet_accel_config_get_profile(struct libinput_device *libinput_device)
{
return LIBINPUT_CONFIG_ACCEL_PROFILE_NONE;
}
static enum libinput_config_accel_profile
tablet_accel_config_get_default_profile(struct libinput_device *libinput_device)
{
return LIBINPUT_CONFIG_ACCEL_PROFILE_NONE;
}
static int
tablet_init_accel(struct tablet_dispatch *tablet, struct evdev_device *device)
{
const struct input_absinfo *x, *y;
struct motion_filter *filter;
x = device->abs.absinfo_x;
y = device->abs.absinfo_y;
filter = create_pointer_accelerator_filter_tablet(x->resolution,
y->resolution);
if (!filter)
return -1;
evdev_device_init_pointer_acceleration(device, filter);
/* we override the profile hooks for accel configuration with hooks
* that don't allow selection of profiles */
device->pointer.config.get_profiles = tablet_accel_config_get_profiles;
device->pointer.config.set_profile = tablet_accel_config_set_profile;
device->pointer.config.get_profile = tablet_accel_config_get_profile;
device->pointer.config.get_default_profile = tablet_accel_config_get_default_profile;
return 0;
}
static void
tablet_init_left_handed(struct evdev_device *device,
WacomDevice *wacom)
{
bool has_left_handed = true;
#if HAVE_LIBWACOM
has_left_handed = !wacom || libwacom_is_reversible(wacom);
#endif
if (has_left_handed)
evdev_init_left_handed(device,
tablet_change_to_left_handed);
}
static inline bool
tablet_is_display_tablet(WacomDevice *wacom)
{
#if HAVE_LIBWACOM
return !wacom ||
(libwacom_get_integration_flags(wacom) & (WACOM_DEVICE_INTEGRATED_SYSTEM|WACOM_DEVICE_INTEGRATED_DISPLAY));
#else
return true;
#endif
}
static inline bool
tablet_is_aes(struct evdev_device *device, WacomDevice *wacom)
{
#if HAVE_LIBWACOM
int vid = evdev_device_get_id_vendor(device);
/* Wacom-specific check for whether smoothing is required:
* libwacom keeps all the AES pens in a single group, so any device
* that supports AES pens will list all AES pens. 0x11 is one of the
* lenovo pens so we use that as the flag of whether the tablet
* is an AES tablet
*/
if (wacom && vid == VENDOR_ID_WACOM) {
int nstyli;
const int *stylus_ids = libwacom_get_supported_styli(wacom, &nstyli);
for (int i = 0; i < nstyli; i++) {
if (stylus_ids[i] == 0x11) {
return true;
}
}
}
#endif
return false;
}
static void
tablet_init_smoothing(struct evdev_device *device,
struct tablet_dispatch *tablet,
bool is_aes)
{
size_t history_size = ARRAY_LENGTH(tablet->history.samples);
struct quirks_context *quirks = NULL;
struct quirks *q = NULL;
bool use_smoothing = true;
quirks = evdev_libinput_context(device)->quirks;
q = quirks_fetch_for_device(quirks, device->udev_device);
/* By default, always enable smoothing except on AES devices.
* AttrTabletSmoothing can override this, if necessary.
*/
if (!q || !quirks_get_bool(q, QUIRK_ATTR_TABLET_SMOOTHING, &use_smoothing))
use_smoothing = !is_aes;
/* Setting the history size to 1 means we never do any actual smoothing. */
if (!use_smoothing)
history_size = 1;
quirks_unref(q);
tablet->history.size = history_size;
}
static bool
tablet_reject_device(struct evdev_device *device)
{
struct libevdev *evdev = device->evdev;
double w, h;
bool has_xy, has_pen, has_btn_stylus, has_size;
has_xy = libevdev_has_event_code(evdev, EV_ABS, ABS_X) &&
libevdev_has_event_code(evdev, EV_ABS, ABS_Y);
has_pen = libevdev_has_event_code(evdev, EV_KEY, BTN_TOOL_PEN);
has_btn_stylus = libevdev_has_event_code(evdev, EV_KEY, BTN_STYLUS);
has_size = evdev_device_get_size(device, &w, &h) == 0;
if (has_xy && (has_pen || has_btn_stylus) && has_size)
return false;
evdev_log_bug_libinput(device,
"missing tablet capabilities:%s%s%s%s. "
"Ignoring this device.\n",
has_xy ? "" : " xy",
has_pen ? "" : " pen",
has_btn_stylus ? "" : " btn-stylus",
has_size ? "" : " resolution");
return true;
}
static void
tablet_fix_tilt(struct tablet_dispatch *tablet,
struct evdev_device *device)
{
struct libevdev *evdev = device->evdev;
if (libevdev_has_event_code(evdev, EV_ABS, ABS_TILT_X) !=
libevdev_has_event_code(evdev, EV_ABS, ABS_TILT_Y)) {
libevdev_disable_event_code(evdev, EV_ABS, ABS_TILT_X);
libevdev_disable_event_code(evdev, EV_ABS, ABS_TILT_Y);
return;
}
if (!libevdev_has_event_code(evdev, EV_ABS, ABS_TILT_X))
return;
/* Wacom has three types of devices:
* - symmetrical: [-90, 90], like the ISDv4 524c
* - asymmetrical: [-64, 63], like the Cintiq l3HDT
* - zero-based: [0, 127], like the Cintiq 12WX
*
* Note how the latter two cases have an even range and thus do
* not have a logical center value. But this is tilt and at
* least in the asymmetrical case we assume that hardware zero
* means vertical. So we cheat and adjust the range depending
* on whether it's odd, then use the center value.
*
* Since it's always the max that's one too low let's go with that and
* fix it if we run into a device where that isn't the case.
*/
for (unsigned int axis = ABS_TILT_X; axis <= ABS_TILT_Y; axis++) {
struct input_absinfo abs = *libevdev_get_abs_info(evdev, axis);
/* Don't touch axes reporting radians */
if (abs.resolution != 0)
continue;
if ((int)absinfo_range(&abs) % 2 == 1)
continue;
abs.maximum += 1;
libevdev_set_abs_info(evdev, axis, &abs);
evdev_log_debug(device,
"Adjusting %s range to [%d, %d]\n",
libevdev_event_code_get_name(EV_ABS, axis),
abs.minimum,
abs.maximum);
}
}
static int
tablet_init(struct tablet_dispatch *tablet,
struct evdev_device *device)
{
static unsigned int tablet_ids = 0;
struct libinput *li = evdev_libinput_context(device);
struct libevdev *evdev = device->evdev;
enum libinput_tablet_tool_axis axis;
int rc = -1;
WacomDevice *wacom = NULL;
#if HAVE_LIBWACOM
WacomDeviceDatabase *db = libinput_libwacom_ref(li);
if (db) {
char event_path[64];
snprintf(event_path,
sizeof(event_path),
"/dev/input/%s",
evdev_device_get_sysname(device));
wacom = libwacom_new_from_path(db, event_path, WFALLBACK_NONE, NULL);
if (!wacom) {
wacom = libwacom_new_from_usbid(db,
evdev_device_get_id_vendor(device),
evdev_device_get_id_product(device),
NULL);
}
if (!wacom) {
evdev_log_info(device,
"device \"%s\" (%04x:%04x) is not known to libwacom\n",
evdev_device_get_name(device),
evdev_device_get_id_vendor(device),
evdev_device_get_id_product(device));
}
}
#endif
tablet->tablet_id = ++tablet_ids;
tablet->base.dispatch_type = DISPATCH_TABLET;
tablet->base.interface = &tablet_interface;
tablet->device = device;
tablet->status = TABLET_NONE;
tablet->current_tool.type = LIBINPUT_TOOL_NONE;
list_init(&tablet->tool_list);
if (tablet_reject_device(device))
goto out;
bool is_aes = tablet_is_aes(device, wacom);
bool is_display_tablet = tablet_is_display_tablet(wacom);
if (!libevdev_has_event_code(evdev, EV_KEY, BTN_TOOL_PEN)) {
libevdev_enable_event_code(evdev, EV_KEY, BTN_TOOL_PEN, NULL);
tablet->quirks.proximity_out_forced = true;
}
/* Our rotation code only works with Wacoms, let's wait until
* someone shouts */
if (evdev_device_get_id_vendor(device) != VENDOR_ID_WACOM) {
libevdev_disable_event_code(evdev, EV_KEY, BTN_TOOL_MOUSE);
libevdev_disable_event_code(evdev, EV_KEY, BTN_TOOL_LENS);
}
tablet_fix_tilt(tablet, device);
tablet_init_calibration(tablet, device, is_display_tablet);
tablet_init_area(tablet, device);
tablet_init_proximity_threshold(tablet, device);
rc = tablet_init_accel(tablet, device);
if (rc != 0)
goto out;
evdev_init_sendevents(device, &tablet->base);
tablet_init_left_handed(device, wacom);
tablet_init_smoothing(device, tablet, is_aes);
for (axis = LIBINPUT_TABLET_TOOL_AXIS_X;
axis <= LIBINPUT_TABLET_TOOL_AXIS_MAX;
axis++) {
if (tablet_device_has_axis(tablet, axis))
set_bit(tablet->axis_caps, axis);
}
tablet_set_status(tablet, TABLET_TOOL_OUT_OF_PROXIMITY);
/* We always enable the proximity out quirk, but disable it once a
device gives us the right event sequence */
tablet->quirks.need_to_force_prox_out = true;
libinput_timer_init(&tablet->quirks.prox_out_timer,
li,
"proxout",
tablet_proximity_out_quirk_timer_func,
tablet);
rc = 0;
out:
#if HAVE_LIBWACOM
if (wacom)
libwacom_destroy(wacom);
if (db)
libinput_libwacom_unref(li);
#endif
return rc;
}
struct evdev_dispatch *
evdev_tablet_create(struct evdev_device *device)
{
struct tablet_dispatch *tablet;
struct libinput *li = evdev_libinput_context(device);
libinput_libwacom_ref(li);
/* Stop false positives caused by the forced proximity code */
if (getenv("LIBINPUT_RUNNING_TEST_SUITE"))
FORCED_PROXOUT_TIMEOUT = 150 * 1000; /* µs */
tablet = zalloc(sizeof *tablet);
if (tablet_init(tablet, device) != 0) {
tablet_destroy(&tablet->base);
return NULL;
}
return &tablet->base;
}
libinput-1.28.1/src/evdev-tablet.h000066400000000000000000000165711477265155700170100ustar00rootroot00000000000000/*
* Copyright © 2014 Red Hat, Inc.
* Copyright © 2014 Lyude Paul
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice (including the next
* paragraph) shall be included in all copies or substantial portions of the
* Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
*/
#ifndef EVDEV_TABLET_H
#define EVDEV_TABLET_H
#include "evdev.h"
#if !HAVE_LIBWACOM
typedef void * WacomDevice;
#endif
#define LIBINPUT_TABLET_TOOL_AXIS_NONE 0
#define LIBINPUT_TOOL_NONE 0
#define LIBINPUT_TABLET_TOOL_TYPE_MAX LIBINPUT_TABLET_TOOL_TYPE_LENS
#define TABLET_HISTORY_LENGTH 4
enum tablet_status {
TABLET_NONE = 0,
TABLET_AXES_UPDATED = bit(0),
TABLET_BUTTONS_PRESSED = bit(1),
TABLET_BUTTONS_DOWN = bit(2),
TABLET_BUTTONS_RELEASED = bit(3),
TABLET_TOOL_UPDATED = bit(4),
TABLET_TOOL_IN_CONTACT = bit(5),
TABLET_TOOL_LEAVING_PROXIMITY = bit(6),
TABLET_TOOL_OUT_OF_PROXIMITY = bit(7),
TABLET_TOOL_ENTERING_PROXIMITY = bit(8),
TABLET_TOOL_ENTERING_CONTACT = bit(9),
TABLET_TOOL_LEAVING_CONTACT = bit(10),
TABLET_TOOL_OUT_OF_RANGE = bit(11),
TABLET_TOOL_OUTSIDE_AREA = bit(12),
};
struct button_state {
unsigned char bits[NCHARS(KEY_CNT)];
};
struct tablet_dispatch {
struct evdev_dispatch base;
struct evdev_device *device;
unsigned int tablet_id; /* incremental ID */
unsigned int status;
unsigned char changed_axes[NCHARS(LIBINPUT_TABLET_TOOL_AXIS_MAX + 1)];
struct tablet_axes axes; /* for assembling the current state */
struct device_coords last_smooth_point;
struct {
unsigned int index;
unsigned int count;
struct tablet_axes samples[TABLET_HISTORY_LENGTH];
size_t size;
} history;
unsigned char axis_caps[NCHARS(LIBINPUT_TABLET_TOOL_AXIS_MAX + 1)];
int current_value[LIBINPUT_TABLET_TOOL_AXIS_MAX + 1];
int prev_value[LIBINPUT_TABLET_TOOL_AXIS_MAX + 1];
/* Only used for tablets that don't report serial numbers */
struct list tool_list;
struct button_state button_state;
struct button_state prev_button_state;
uint32_t tool_state;
uint32_t prev_tool_state;
struct {
enum libinput_tablet_tool_type type;
uint32_t id;
uint32_t serial;
} current_tool;
uint32_t cursor_proximity_threshold;
struct libinput_device_config_calibration calibration;
struct {
struct libinput_device_config_area config;
struct libinput_config_area_rectangle rect;
struct libinput_config_area_rectangle want_rect;
struct input_absinfo x;
struct input_absinfo y;
} area;
/* The paired touch device on devices with both pen & touch */
struct evdev_device *touch_device;
enum evdev_arbitration_state arbitration;
struct {
/* The device locked for rotation */
struct evdev_device *touch_device;
/* Last known left-handed state of the touchpad */
bool touch_device_left_handed_state;
bool rotate;
bool want_rotate;
} rotation;
struct {
bool need_to_force_prox_out;
struct libinput_timer prox_out_timer;
bool proximity_out_forced;
uint64_t last_event_time;
/* true while injecting BTN_TOOL_PEN events */
bool proximity_out_in_progress;
} quirks;
};
static inline struct tablet_dispatch*
tablet_dispatch(struct evdev_dispatch *dispatch)
{
evdev_verify_dispatch_type(dispatch, DISPATCH_TABLET);
return container_of(dispatch, struct tablet_dispatch, base);
}
static inline enum libinput_tablet_tool_axis
evcode_to_axis(const uint32_t evcode)
{
enum libinput_tablet_tool_axis axis;
switch (evcode) {
case ABS_X:
axis = LIBINPUT_TABLET_TOOL_AXIS_X;
break;
case ABS_Y:
axis = LIBINPUT_TABLET_TOOL_AXIS_Y;
break;
case ABS_Z:
axis = LIBINPUT_TABLET_TOOL_AXIS_ROTATION_Z;
break;
case ABS_DISTANCE:
axis = LIBINPUT_TABLET_TOOL_AXIS_DISTANCE;
break;
case ABS_PRESSURE:
axis = LIBINPUT_TABLET_TOOL_AXIS_PRESSURE;
break;
case ABS_TILT_X:
axis = LIBINPUT_TABLET_TOOL_AXIS_TILT_X;
break;
case ABS_TILT_Y:
axis = LIBINPUT_TABLET_TOOL_AXIS_TILT_Y;
break;
case ABS_WHEEL:
axis = LIBINPUT_TABLET_TOOL_AXIS_SLIDER;
break;
default:
axis = LIBINPUT_TABLET_TOOL_AXIS_NONE;
break;
}
return axis;
}
static inline enum libinput_tablet_tool_axis
rel_evcode_to_axis(const uint32_t evcode)
{
enum libinput_tablet_tool_axis axis;
switch (evcode) {
case REL_WHEEL:
axis = LIBINPUT_TABLET_TOOL_AXIS_REL_WHEEL;
break;
default:
axis = LIBINPUT_TABLET_TOOL_AXIS_NONE;
break;
}
return axis;
}
static inline uint32_t
axis_to_evcode(const enum libinput_tablet_tool_axis axis)
{
uint32_t evcode;
switch (axis) {
case LIBINPUT_TABLET_TOOL_AXIS_X:
evcode = ABS_X;
break;
case LIBINPUT_TABLET_TOOL_AXIS_Y:
evcode = ABS_Y;
break;
case LIBINPUT_TABLET_TOOL_AXIS_DISTANCE:
evcode = ABS_DISTANCE;
break;
case LIBINPUT_TABLET_TOOL_AXIS_PRESSURE:
evcode = ABS_PRESSURE;
break;
case LIBINPUT_TABLET_TOOL_AXIS_TILT_X:
evcode = ABS_TILT_X;
break;
case LIBINPUT_TABLET_TOOL_AXIS_TILT_Y:
evcode = ABS_TILT_Y;
break;
case LIBINPUT_TABLET_TOOL_AXIS_ROTATION_Z:
evcode = ABS_Z;
break;
case LIBINPUT_TABLET_TOOL_AXIS_SLIDER:
evcode = ABS_WHEEL;
break;
case LIBINPUT_TABLET_TOOL_AXIS_SIZE_MAJOR:
evcode = ABS_MT_TOUCH_MAJOR;
break;
case LIBINPUT_TABLET_TOOL_AXIS_SIZE_MINOR:
evcode = ABS_MT_TOUCH_MINOR;
break;
default:
abort();
}
return evcode;
}
static inline int
tablet_tool_to_evcode(enum libinput_tablet_tool_type type)
{
int code;
switch (type) {
case LIBINPUT_TABLET_TOOL_TYPE_PEN: code = BTN_TOOL_PEN; break;
case LIBINPUT_TABLET_TOOL_TYPE_ERASER: code = BTN_TOOL_RUBBER; break;
case LIBINPUT_TABLET_TOOL_TYPE_BRUSH: code = BTN_TOOL_BRUSH; break;
case LIBINPUT_TABLET_TOOL_TYPE_PENCIL: code = BTN_TOOL_PENCIL; break;
case LIBINPUT_TABLET_TOOL_TYPE_AIRBRUSH: code = BTN_TOOL_AIRBRUSH; break;
case LIBINPUT_TABLET_TOOL_TYPE_MOUSE: code = BTN_TOOL_MOUSE; break;
case LIBINPUT_TABLET_TOOL_TYPE_LENS: code = BTN_TOOL_LENS; break;
default:
abort();
}
return code;
}
static inline const char *
tablet_tool_type_to_string(enum libinput_tablet_tool_type type)
{
const char *str;
switch (type) {
case LIBINPUT_TABLET_TOOL_TYPE_PEN: str = "pen"; break;
case LIBINPUT_TABLET_TOOL_TYPE_ERASER: str = "eraser"; break;
case LIBINPUT_TABLET_TOOL_TYPE_BRUSH: str = "brush"; break;
case LIBINPUT_TABLET_TOOL_TYPE_PENCIL: str = "pencil"; break;
case LIBINPUT_TABLET_TOOL_TYPE_AIRBRUSH: str = "airbrush"; break;
case LIBINPUT_TABLET_TOOL_TYPE_MOUSE: str = "mouse"; break;
case LIBINPUT_TABLET_TOOL_TYPE_LENS: str = "lens"; break;
default:
abort();
}
return str;
}
static inline struct libinput *
tablet_libinput_context(const struct tablet_dispatch *tablet)
{
return evdev_libinput_context(tablet->device);
}
#endif
libinput-1.28.1/src/evdev-totem.c000066400000000000000000000556431477265155700166630ustar00rootroot00000000000000/*
* Copyright © 2018 Red Hat, Inc.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice (including the next
* paragraph) shall be included in all copies or substantial portions of the
* Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
*/
#include "config.h"
#include "evdev.h"
enum totem_slot_state {
SLOT_STATE_NONE,
SLOT_STATE_BEGIN,
SLOT_STATE_UPDATE,
SLOT_STATE_END,
};
struct totem_slot {
bool dirty;
unsigned int index;
enum totem_slot_state state;
struct libinput_tablet_tool *tool;
struct tablet_axes axes;
unsigned char changed_axes[NCHARS(LIBINPUT_TABLET_TOOL_AXIS_MAX + 1)];
struct device_coords last_point;
};
struct totem_dispatch {
struct evdev_dispatch base;
struct evdev_device *device;
int slot; /* current slot */
struct totem_slot *slots;
size_t nslots;
struct evdev_device *touch_device;
/* We only have one button */
bool button_state_now;
bool button_state_previous;
enum evdev_arbitration_state arbitration_state;
};
static inline struct totem_dispatch*
totem_dispatch(struct evdev_dispatch *totem)
{
evdev_verify_dispatch_type(totem, DISPATCH_TOTEM);
return container_of(totem, struct totem_dispatch, base);
}
static inline struct libinput *
totem_libinput_context(const struct totem_dispatch *totem)
{
return evdev_libinput_context(totem->device);
}
static struct libinput_tablet_tool *
totem_new_tool(struct totem_dispatch *totem)
{
struct libinput *libinput = totem_libinput_context(totem);
struct libinput_tablet_tool *tool;
tool = zalloc(sizeof *tool);
*tool = (struct libinput_tablet_tool) {
.type = LIBINPUT_TABLET_TOOL_TYPE_TOTEM,
.serial = 0,
.tool_id = 0,
.refcount = 1,
};
ARRAY_FOR_EACH(tool->pressure.thresholds, t) {
t->tablet_id = 0;
t->offset = 0;
t->has_offset = false;
t->threshold.lower = 0;
t->threshold.upper = 1;
}
set_bit(tool->axis_caps, LIBINPUT_TABLET_TOOL_AXIS_X);
set_bit(tool->axis_caps, LIBINPUT_TABLET_TOOL_AXIS_Y);
set_bit(tool->axis_caps, LIBINPUT_TABLET_TOOL_AXIS_ROTATION_Z);
set_bit(tool->axis_caps, LIBINPUT_TABLET_TOOL_AXIS_SIZE_MAJOR);
set_bit(tool->axis_caps, LIBINPUT_TABLET_TOOL_AXIS_SIZE_MINOR);
set_bit(tool->buttons, BTN_0);
list_insert(&libinput->tool_list, &tool->link);
return tool;
}
static inline void
totem_set_touch_device_enabled(struct totem_dispatch *totem,
bool enable_touch_device,
uint64_t time)
{
struct evdev_device *touch_device = totem->touch_device;
struct evdev_dispatch *dispatch;
struct phys_rect r, *rect = NULL;
enum evdev_arbitration_state state = ARBITRATION_NOT_ACTIVE;
if (touch_device == NULL)
return;
/* We just pick the coordinates of the first touch we find. The
* totem only does one tool right now despite being nominally an MT
* device, so let's not go too hard on ourselves*/
for (size_t i = 0; !enable_touch_device && i < totem->nslots; i++) {
struct totem_slot *slot = &totem->slots[i];
struct phys_coords mm;
if (slot->state == SLOT_STATE_NONE)
continue;
/* Totem size is ~70mm. We could calculate the real size but
until we need that, hardcoding it is enough */
mm = evdev_device_units_to_mm(totem->device, &slot->axes.point);
r.x = mm.x - 30;
r.y = mm.y - 30;
r.w = 100;
r.h = 100;
rect = &r;
state = ARBITRATION_IGNORE_RECT;
break;
}
dispatch = touch_device->dispatch;
if (enable_touch_device) {
if (dispatch->interface->touch_arbitration_toggle)
dispatch->interface->touch_arbitration_toggle(dispatch,
touch_device,
state,
rect,
time);
} else {
switch (totem->arbitration_state) {
case ARBITRATION_IGNORE_ALL:
abort();
case ARBITRATION_NOT_ACTIVE:
if (dispatch->interface->touch_arbitration_toggle)
dispatch->interface->touch_arbitration_toggle(dispatch,
touch_device,
state,
rect,
time);
break;
case ARBITRATION_IGNORE_RECT:
if (dispatch->interface->touch_arbitration_update_rect)
dispatch->interface->touch_arbitration_update_rect(dispatch,
touch_device,
rect,
time);
break;
}
}
totem->arbitration_state = state;
}
static void
totem_process_key(struct totem_dispatch *totem,
struct evdev_device *device,
struct input_event *e,
uint64_t time)
{
/* ignore kernel key repeat */
if (e->value == 2)
return;
switch(e->code) {
case BTN_0:
totem->button_state_now = !!e->value;
break;
default:
evdev_log_info(device,
"Unhandled KEY event code %#x\n",
e->code);
break;
}
}
static void
totem_process_abs(struct totem_dispatch *totem,
struct evdev_device *device,
struct input_event *e,
uint64_t time)
{
struct totem_slot *slot = &totem->slots[totem->slot];
switch(e->code) {
case ABS_MT_SLOT:
if ((size_t)e->value >= totem->nslots) {
evdev_log_bug_libinput(device,
"exceeded slot count (%d of max %zd)\n",
e->value,
totem->nslots);
e->value = totem->nslots - 1;
}
totem->slot = e->value;
return;
case ABS_MT_TRACKING_ID:
/* If the totem is already down on init, we currently
ignore it */
if (e->value >= 0)
slot->state = SLOT_STATE_BEGIN;
else if (slot->state != SLOT_STATE_NONE)
slot->state = SLOT_STATE_END;
break;
case ABS_MT_POSITION_X:
set_bit(slot->changed_axes, LIBINPUT_TABLET_TOOL_AXIS_X);
break;
case ABS_MT_POSITION_Y:
set_bit(slot->changed_axes, LIBINPUT_TABLET_TOOL_AXIS_Y);
break;
case ABS_MT_TOUCH_MAJOR:
set_bit(slot->changed_axes,
LIBINPUT_TABLET_TOOL_AXIS_SIZE_MAJOR);
break;
case ABS_MT_TOUCH_MINOR:
set_bit(slot->changed_axes,
LIBINPUT_TABLET_TOOL_AXIS_SIZE_MINOR);
break;
case ABS_MT_ORIENTATION:
set_bit(slot->changed_axes,
LIBINPUT_TABLET_TOOL_AXIS_ROTATION_Z);
break;
case ABS_MT_TOOL_TYPE:
if (e->value != MT_TOOL_DIAL) {
evdev_log_info(device,
"Unexpected tool type %#x, changing to dial\n",
e->code);
}
break;
default:
evdev_log_info(device,
"Unhandled ABS event code %#x\n",
e->code);
break;
}
}
static bool
totem_slot_fetch_axes(struct totem_dispatch *totem,
struct totem_slot *slot,
struct libinput_tablet_tool *tool,
struct tablet_axes *axes_out,
uint64_t time)
{
struct evdev_device *device = totem->device;
const char tmp[sizeof(slot->changed_axes)] = {0};
struct tablet_axes axes = {0};
struct device_float_coords delta;
bool rc = false;
if (memcmp(tmp, slot->changed_axes, sizeof(tmp)) == 0) {
axes = slot->axes;
goto out;
}
if (bit_is_set(slot->changed_axes, LIBINPUT_TABLET_TOOL_AXIS_X) ||
bit_is_set(slot->changed_axes, LIBINPUT_TABLET_TOOL_AXIS_Y)) {
slot->axes.point.x = libevdev_get_slot_value(device->evdev,
slot->index,
ABS_MT_POSITION_X);
slot->axes.point.y = libevdev_get_slot_value(device->evdev,
slot->index,
ABS_MT_POSITION_Y);
}
if (bit_is_set(slot->changed_axes,
LIBINPUT_TABLET_TOOL_AXIS_ROTATION_Z)) {
int angle = libevdev_get_slot_value(device->evdev,
slot->index,
ABS_MT_ORIENTATION);
/* The kernel gives us ±90 degrees off neutral */
slot->axes.rotation = (360 - angle) % 360;
}
if (bit_is_set(slot->changed_axes,
LIBINPUT_TABLET_TOOL_AXIS_SIZE_MAJOR) ||
bit_is_set(slot->changed_axes,
LIBINPUT_TABLET_TOOL_AXIS_SIZE_MINOR)) {
int major, minor;
unsigned int rmajor, rminor;
major = libevdev_get_slot_value(device->evdev,
slot->index,
ABS_MT_TOUCH_MAJOR);
minor = libevdev_get_slot_value(device->evdev,
slot->index,
ABS_MT_TOUCH_MINOR);
rmajor = libevdev_get_abs_resolution(device->evdev, ABS_MT_TOUCH_MAJOR);
rminor = libevdev_get_abs_resolution(device->evdev, ABS_MT_TOUCH_MINOR);
slot->axes.size.major = (double)major/rmajor;
slot->axes.size.minor = (double)minor/rminor;
}
axes.point = slot->axes.point;
axes.rotation = slot->axes.rotation;
axes.size = slot->axes.size;
delta.x = slot->axes.point.x - slot->last_point.x;
delta.y = slot->axes.point.y - slot->last_point.y;
axes.delta = filter_dispatch(device->pointer.filter, &delta, tool, time);
rc = true;
out:
*axes_out = axes;
return rc;
}
static void
totem_slot_mark_all_axes_changed(struct totem_dispatch *totem,
struct totem_slot *slot,
struct libinput_tablet_tool *tool)
{
static_assert(sizeof(slot->changed_axes) ==
sizeof(tool->axis_caps),
"Mismatching array sizes");
memcpy(slot->changed_axes,
tool->axis_caps,
sizeof(slot->changed_axes));
}
static inline void
totem_slot_reset_changed_axes(struct totem_dispatch *totem,
struct totem_slot *slot)
{
memset(slot->changed_axes, 0, sizeof(slot->changed_axes));
}
static inline void
slot_axes_initialize(struct totem_dispatch *totem,
struct totem_slot *slot)
{
struct evdev_device *device = totem->device;
slot->axes.point.x = libevdev_get_slot_value(device->evdev,
slot->index,
ABS_MT_POSITION_X);
slot->axes.point.y = libevdev_get_slot_value(device->evdev,
slot->index,
ABS_MT_POSITION_Y);
slot->last_point.x = slot->axes.point.x;
slot->last_point.y = slot->axes.point.y;
}
static enum totem_slot_state
totem_handle_slot_state(struct totem_dispatch *totem,
struct totem_slot *slot,
uint64_t time)
{
struct evdev_device *device = totem->device;
struct tablet_axes axes;
enum libinput_tablet_tool_tip_state tip_state;
bool updated;
switch (slot->state) {
case SLOT_STATE_BEGIN:
if (!slot->tool)
slot->tool = totem_new_tool(totem);
slot_axes_initialize(totem, slot);
totem_slot_mark_all_axes_changed(totem, slot, slot->tool);
break;
case SLOT_STATE_UPDATE:
case SLOT_STATE_END:
assert(slot->tool);
break;
case SLOT_STATE_NONE:
return SLOT_STATE_NONE;
}
tip_state = LIBINPUT_TABLET_TOOL_TIP_UP;
updated = totem_slot_fetch_axes(totem, slot, slot->tool, &axes, time);
switch (slot->state) {
case SLOT_STATE_BEGIN:
tip_state = LIBINPUT_TABLET_TOOL_TIP_DOWN;
tablet_notify_proximity(&device->base,
time,
slot->tool,
LIBINPUT_TABLET_TOOL_PROXIMITY_STATE_IN,
slot->changed_axes,
&axes,
device->abs.absinfo_x,
device->abs.absinfo_y);
totem_slot_reset_changed_axes(totem, slot);
tablet_notify_tip(&device->base,
time,
slot->tool,
tip_state,
slot->changed_axes,
&axes,
device->abs.absinfo_x,
device->abs.absinfo_y);
slot->state = SLOT_STATE_UPDATE;
break;
case SLOT_STATE_UPDATE:
tip_state = LIBINPUT_TABLET_TOOL_TIP_DOWN;
if (updated) {
tablet_notify_axis(&device->base,
time,
slot->tool,
tip_state,
slot->changed_axes,
&axes,
device->abs.absinfo_x,
device->abs.absinfo_y);
}
break;
case SLOT_STATE_END:
/* prox out is handled after button events */
break;
case SLOT_STATE_NONE:
abort();
break;
}
/* We only have one button but possibly multiple totems. It's not
* clear how the firmware will work, so for now we just handle the
* button state in the first slot.
*
* Due to the design of the totem we're also less fancy about
* button handling than the tablet code. Worst case, you might get
* tip up before button up but meh.
*/
if (totem->button_state_now != totem->button_state_previous) {
enum libinput_button_state btn_state;
if (totem->button_state_now)
btn_state = LIBINPUT_BUTTON_STATE_PRESSED;
else
btn_state = LIBINPUT_BUTTON_STATE_RELEASED;
tablet_notify_button(&device->base,
time,
slot->tool,
tip_state,
&axes,
BTN_0,
btn_state,
device->abs.absinfo_x,
device->abs.absinfo_y);
totem->button_state_previous = totem->button_state_now;
}
switch(slot->state) {
case SLOT_STATE_BEGIN:
case SLOT_STATE_UPDATE:
break;
case SLOT_STATE_END:
tip_state = LIBINPUT_TABLET_TOOL_TIP_UP;
tablet_notify_tip(&device->base,
time,
slot->tool,
tip_state,
slot->changed_axes,
&axes,
device->abs.absinfo_x,
device->abs.absinfo_y);
totem_slot_reset_changed_axes(totem, slot);
tablet_notify_proximity(&device->base,
time,
slot->tool,
LIBINPUT_TABLET_TOOL_PROXIMITY_STATE_OUT,
slot->changed_axes,
&axes,
device->abs.absinfo_x,
device->abs.absinfo_y);
slot->state = SLOT_STATE_NONE;
break;
case SLOT_STATE_NONE:
abort();
break;
}
slot->last_point = slot->axes.point;
totem_slot_reset_changed_axes(totem, slot);
return slot->state;
}
static enum totem_slot_state
totem_handle_state(struct totem_dispatch *totem,
uint64_t time)
{
enum totem_slot_state global_state = SLOT_STATE_NONE;
for (size_t i = 0; i < totem->nslots; i++) {
enum totem_slot_state s;
s = totem_handle_slot_state(totem,
&totem->slots[i],
time);
/* If one slot is active, the totem is active */
if (s != SLOT_STATE_NONE)
global_state = SLOT_STATE_UPDATE;
}
return global_state;
}
static void
totem_interface_process(struct evdev_dispatch *dispatch,
struct evdev_device *device,
struct input_event *e,
uint64_t time)
{
struct totem_dispatch *totem = totem_dispatch(dispatch);
enum totem_slot_state global_state;
bool enable_touch;
switch(e->type) {
case EV_ABS:
totem_process_abs(totem, device, e, time);
break;
case EV_KEY:
totem_process_key(totem, device, e, time);
break;
case EV_MSC:
/* timestamp, ignore */
break;
case EV_SYN:
global_state = totem_handle_state(totem, time);
enable_touch = (global_state == SLOT_STATE_NONE);
totem_set_touch_device_enabled(totem,
enable_touch,
time);
break;
default:
evdev_log_error(device,
"Unexpected event type %s (%#x)\n",
libevdev_event_type_get_name(e->type),
e->type);
break;
}
}
static void
totem_interface_suspend(struct evdev_dispatch *dispatch,
struct evdev_device *device)
{
struct totem_dispatch *totem = totem_dispatch(dispatch);
uint64_t now = libinput_now(evdev_libinput_context(device));
for (size_t i = 0; i < totem->nslots; i++) {
struct totem_slot *slot = &totem->slots[i];
struct tablet_axes axes;
enum libinput_tablet_tool_tip_state tip_state;
/* If we never initialized a tool, we can skip everything */
if (!slot->tool)
continue;
totem_slot_fetch_axes(totem, slot, slot->tool, &axes, now);
totem_slot_reset_changed_axes(totem, slot);
if (slot->state == SLOT_STATE_NONE)
tip_state = LIBINPUT_TABLET_TOOL_TIP_UP;
else
tip_state = LIBINPUT_TABLET_TOOL_TIP_DOWN;
if (totem->button_state_now) {
tablet_notify_button(&device->base,
now,
slot->tool,
tip_state,
&axes,
BTN_0,
LIBINPUT_BUTTON_STATE_RELEASED,
device->abs.absinfo_x,
device->abs.absinfo_y);
totem->button_state_now = false;
totem->button_state_previous = false;
}
if (slot->state != SLOT_STATE_NONE) {
tablet_notify_tip(&device->base,
now,
slot->tool,
LIBINPUT_TABLET_TOOL_TIP_UP,
slot->changed_axes,
&axes,
device->abs.absinfo_x,
device->abs.absinfo_y);
}
tablet_notify_proximity(&device->base,
now,
slot->tool,
LIBINPUT_TABLET_TOOL_PROXIMITY_STATE_OUT,
slot->changed_axes,
&axes,
device->abs.absinfo_x,
device->abs.absinfo_y);
}
totem_set_touch_device_enabled(totem, true, now);
}
static void
totem_interface_destroy(struct evdev_dispatch *dispatch)
{
struct totem_dispatch *totem = totem_dispatch(dispatch);
free(totem->slots);
free(totem);
}
static void
totem_interface_device_added(struct evdev_device *device,
struct evdev_device *added_device)
{
struct totem_dispatch *totem = totem_dispatch(device->dispatch);
struct libinput_device_group *g1, *g2;
if ((evdev_device_get_id_vendor(added_device) !=
evdev_device_get_id_vendor(device)) ||
(evdev_device_get_id_product(added_device) !=
evdev_device_get_id_product(device)))
return;
/* virtual devices don't have device groups, so check for that
libinput replay */
g1 = libinput_device_get_device_group(&device->base);
g2 = libinput_device_get_device_group(&added_device->base);
if (g1 && g2 && g1->identifier != g2->identifier)
return;
if (totem->touch_device != NULL) {
evdev_log_bug_libinput(device,
"already has a paired touch device, ignoring (%s)\n",
added_device->devname);
return;
}
totem->touch_device = added_device;
evdev_log_info(device, "%s: is the totem touch device\n", added_device->devname);
}
static void
totem_interface_device_removed(struct evdev_device *device,
struct evdev_device *removed_device)
{
struct totem_dispatch *totem = totem_dispatch(device->dispatch);
if (totem->touch_device != removed_device)
return;
totem_set_touch_device_enabled(totem, true,
libinput_now(evdev_libinput_context(device)));
totem->touch_device = NULL;
}
static void
totem_interface_initial_proximity(struct evdev_device *device,
struct evdev_dispatch *dispatch)
{
struct totem_dispatch *totem = totem_dispatch(dispatch);
uint64_t now = libinput_now(evdev_libinput_context(device));
bool enable_touch = true;
for (size_t i = 0; i < totem->nslots; i++) {
struct totem_slot *slot = &totem->slots[i];
struct tablet_axes axes;
int tracking_id;
tracking_id = libevdev_get_slot_value(device->evdev,
i,
ABS_MT_TRACKING_ID);
if (tracking_id == -1)
continue;
slot->tool = totem_new_tool(totem);
slot_axes_initialize(totem, slot);
totem_slot_mark_all_axes_changed(totem, slot, slot->tool);
totem_slot_fetch_axes(totem, slot, slot->tool, &axes, now);
tablet_notify_proximity(&device->base,
now,
slot->tool,
LIBINPUT_TABLET_TOOL_PROXIMITY_STATE_IN,
slot->changed_axes,
&axes,
device->abs.absinfo_x,
device->abs.absinfo_y);
totem_slot_reset_changed_axes(totem, slot);
tablet_notify_tip(&device->base,
now,
slot->tool,
LIBINPUT_TABLET_TOOL_TIP_DOWN,
slot->changed_axes,
&axes,
device->abs.absinfo_x,
device->abs.absinfo_y);
slot->state = SLOT_STATE_UPDATE;
enable_touch = false;
}
totem_set_touch_device_enabled(totem, enable_touch, now);
}
static struct evdev_dispatch_interface totem_interface = {
.process = totem_interface_process,
.suspend = totem_interface_suspend,
.remove = NULL,
.destroy = totem_interface_destroy,
.device_added = totem_interface_device_added,
.device_removed = totem_interface_device_removed,
.device_suspended = totem_interface_device_removed, /* treat as remove */
.device_resumed = totem_interface_device_added, /* treat as add */
.post_added = totem_interface_initial_proximity,
.touch_arbitration_toggle = NULL,
.touch_arbitration_update_rect = NULL,
.get_switch_state = NULL,
};
static bool
totem_reject_device(struct evdev_device *device)
{
struct libevdev *evdev = device->evdev;
bool has_xy, has_slot, has_tool_dial, has_size, has_touch_size;
double w, h;
has_xy = libevdev_has_event_code(evdev, EV_ABS, ABS_MT_POSITION_X) &&
libevdev_has_event_code(evdev, EV_ABS, ABS_MT_POSITION_Y);
has_slot = libevdev_has_event_code(evdev, EV_ABS, ABS_MT_SLOT);
has_tool_dial = libevdev_has_event_code(evdev, EV_ABS, ABS_MT_TOOL_TYPE) &&
libevdev_get_abs_maximum(evdev, ABS_MT_TOOL_TYPE) >= MT_TOOL_DIAL;
has_size = evdev_device_get_size(device, &w, &h) == 0;
has_touch_size =
libevdev_get_abs_resolution(device->evdev, ABS_MT_TOUCH_MAJOR) > 0 ||
libevdev_get_abs_resolution(device->evdev, ABS_MT_TOUCH_MINOR) > 0;
if (has_xy && has_slot && has_tool_dial && has_size && has_touch_size)
return false;
evdev_log_bug_libinput(device,
"missing totem capabilities:%s%s%s%s%s. "
"Ignoring this device.\n",
has_xy ? "" : " xy",
has_slot ? "" : " slot",
has_tool_dial ? "" : " dial",
has_size ? "" : " resolutions",
has_touch_size ? "" : " touch-size");
return true;
}
static uint32_t
totem_accel_config_get_profiles(struct libinput_device *libinput_device)
{
return LIBINPUT_CONFIG_ACCEL_PROFILE_NONE;
}
static enum libinput_config_status
totem_accel_config_set_profile(struct libinput_device *libinput_device,
enum libinput_config_accel_profile profile)
{
return LIBINPUT_CONFIG_STATUS_UNSUPPORTED;
}
static enum libinput_config_accel_profile
totem_accel_config_get_profile(struct libinput_device *libinput_device)
{
return LIBINPUT_CONFIG_ACCEL_PROFILE_NONE;
}
static enum libinput_config_accel_profile
totem_accel_config_get_default_profile(struct libinput_device *libinput_device)
{
return LIBINPUT_CONFIG_ACCEL_PROFILE_NONE;
}
static int
totem_init_accel(struct totem_dispatch *totem, struct evdev_device *device)
{
const struct input_absinfo *x, *y;
struct motion_filter *filter;
x = device->abs.absinfo_x;
y = device->abs.absinfo_y;
/* same filter as the tablet */
filter = create_pointer_accelerator_filter_tablet(x->resolution,
y->resolution);
if (!filter)
return -1;
evdev_device_init_pointer_acceleration(device, filter);
/* we override the profile hooks for accel configuration with hooks
* that don't allow selection of profiles */
device->pointer.config.get_profiles = totem_accel_config_get_profiles;
device->pointer.config.set_profile = totem_accel_config_set_profile;
device->pointer.config.get_profile = totem_accel_config_get_profile;
device->pointer.config.get_default_profile = totem_accel_config_get_default_profile;
return 0;
}
struct evdev_dispatch *
evdev_totem_create(struct evdev_device *device)
{
struct totem_dispatch *totem;
struct totem_slot *slots;
int num_slots;
if (totem_reject_device(device))
return NULL;
totem = zalloc(sizeof *totem);
totem->device = device;
totem->base.dispatch_type = DISPATCH_TOTEM;
totem->base.interface = &totem_interface;
num_slots = libevdev_get_num_slots(device->evdev);
if (num_slots <= 0)
goto error;
totem->slot = libevdev_get_current_slot(device->evdev);
slots = zalloc(num_slots * sizeof(*totem->slots));
for (int slot = 0; slot < num_slots; ++slot) {
slots[slot].index = slot;
}
totem->slots = slots;
totem->nslots = num_slots;
evdev_init_sendevents(device, &totem->base);
totem_init_accel(totem, device);
return &totem->base;
error:
totem_interface_destroy(&totem->base);
return NULL;
}
libinput-1.28.1/src/evdev-wheel.c000066400000000000000000000312241477265155700166240ustar00rootroot00000000000000/*
* Copyright © 2010 Intel Corporation
* Copyright © 2013 Jonas Ådahl
* Copyright © 2013-2017 Red Hat, Inc.
* Copyright © 2017 James Ye
* Copyright © 2021 José Expósito
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice (including the next
* paragraph) shall be included in all copies or substantial portions of the
* Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
*/
#include "config.h"
#include "evdev-fallback.h"
#include "util-input-event.h"
#define ACC_V120_THRESHOLD 60
#define WHEEL_SCROLL_TIMEOUT ms2us(500)
enum wheel_event {
WHEEL_EVENT_SCROLL_ACCUMULATED,
WHEEL_EVENT_SCROLL,
WHEEL_EVENT_SCROLL_TIMEOUT,
WHEEL_EVENT_SCROLL_DIR_CHANGED,
};
static inline const char *
wheel_state_to_str(enum wheel_state state)
{
switch(state) {
CASE_RETURN_STRING(WHEEL_STATE_NONE);
CASE_RETURN_STRING(WHEEL_STATE_ACCUMULATING_SCROLL);
CASE_RETURN_STRING(WHEEL_STATE_SCROLLING);
}
return NULL;
}
static inline const char*
wheel_event_to_str(enum wheel_event event)
{
switch(event) {
CASE_RETURN_STRING(WHEEL_EVENT_SCROLL_ACCUMULATED);
CASE_RETURN_STRING(WHEEL_EVENT_SCROLL);
CASE_RETURN_STRING(WHEEL_EVENT_SCROLL_TIMEOUT);
CASE_RETURN_STRING(WHEEL_EVENT_SCROLL_DIR_CHANGED);
}
return NULL;
}
static inline void
log_wheel_bug(struct fallback_dispatch *dispatch, enum wheel_event event)
{
evdev_log_bug_libinput(dispatch->device,
"invalid wheel event %s in state %s\n",
wheel_event_to_str(event),
wheel_state_to_str(dispatch->wheel.state));
}
static inline void
wheel_set_scroll_timer(struct fallback_dispatch *dispatch, uint64_t time)
{
libinput_timer_set(&dispatch->wheel.scroll_timer,
time + WHEEL_SCROLL_TIMEOUT);
}
static inline void
wheel_cancel_scroll_timer(struct fallback_dispatch *dispatch)
{
libinput_timer_cancel(&dispatch->wheel.scroll_timer);
}
static void
wheel_handle_event_on_state_none(struct fallback_dispatch *dispatch,
enum wheel_event event,
uint64_t time)
{
switch (event) {
case WHEEL_EVENT_SCROLL:
dispatch->wheel.state = WHEEL_STATE_ACCUMULATING_SCROLL;
break;
case WHEEL_EVENT_SCROLL_DIR_CHANGED:
break;
case WHEEL_EVENT_SCROLL_ACCUMULATED:
case WHEEL_EVENT_SCROLL_TIMEOUT:
log_wheel_bug(dispatch, event);
break;
}
}
static void
wheel_handle_event_on_state_accumulating_scroll(struct fallback_dispatch *dispatch,
enum wheel_event event,
uint64_t time)
{
switch (event) {
case WHEEL_EVENT_SCROLL_ACCUMULATED:
dispatch->wheel.state = WHEEL_STATE_SCROLLING;
wheel_set_scroll_timer(dispatch, time);
break;
case WHEEL_EVENT_SCROLL:
/* Ignore scroll while accumulating deltas */
break;
case WHEEL_EVENT_SCROLL_DIR_CHANGED:
dispatch->wheel.state = WHEEL_STATE_NONE;
break;
case WHEEL_EVENT_SCROLL_TIMEOUT:
log_wheel_bug(dispatch, event);
break;
}
}
static void
wheel_handle_event_on_state_scrolling(struct fallback_dispatch *dispatch,
enum wheel_event event,
uint64_t time)
{
switch (event) {
case WHEEL_EVENT_SCROLL:
wheel_cancel_scroll_timer(dispatch);
wheel_set_scroll_timer(dispatch, time);
break;
case WHEEL_EVENT_SCROLL_TIMEOUT:
dispatch->wheel.state = WHEEL_STATE_NONE;
break;
case WHEEL_EVENT_SCROLL_DIR_CHANGED:
wheel_cancel_scroll_timer(dispatch);
dispatch->wheel.state = WHEEL_STATE_NONE;
break;
case WHEEL_EVENT_SCROLL_ACCUMULATED:
log_wheel_bug(dispatch, event);
break;
}
}
static void
wheel_handle_event(struct fallback_dispatch *dispatch,
enum wheel_event event,
uint64_t time)
{
enum wheel_state oldstate = dispatch->wheel.state;
switch (oldstate) {
case WHEEL_STATE_NONE:
wheel_handle_event_on_state_none(dispatch, event, time);
break;
case WHEEL_STATE_ACCUMULATING_SCROLL:
wheel_handle_event_on_state_accumulating_scroll(dispatch,
event,
time);
break;
case WHEEL_STATE_SCROLLING:
wheel_handle_event_on_state_scrolling(dispatch, event, time);
break;
}
if (oldstate != dispatch->wheel.state) {
evdev_log_debug(dispatch->device,
"wheel state %s → %s → %s\n",
wheel_state_to_str(oldstate),
wheel_event_to_str(event),
wheel_state_to_str(dispatch->wheel.state));
}
}
static void
wheel_flush_scroll(struct fallback_dispatch *dispatch,
struct evdev_device *device,
uint64_t time)
{
struct normalized_coords wheel_degrees = { 0.0, 0.0 };
struct discrete_coords discrete = { 0.0, 0.0 };
struct wheel_v120 v120 = { 0.0, 0.0 };
/* This mouse has a trackstick instead of a mouse wheel and sends
* trackstick data via REL_WHEEL. Normalize it like normal x/y coordinates.
*/
if (device->model_flags & EVDEV_MODEL_LENOVO_SCROLLPOINT) {
const struct device_float_coords raw = {
.x = dispatch->wheel.lo_res.x,
.y = dispatch->wheel.lo_res.y * -1,
};
const struct normalized_coords normalized =
filter_dispatch_scroll(device->pointer.filter,
&raw,
device,
time);
evdev_post_scroll(device,
time,
LIBINPUT_POINTER_AXIS_SOURCE_CONTINUOUS,
&normalized);
dispatch->wheel.hi_res.x = 0;
dispatch->wheel.hi_res.y = 0;
dispatch->wheel.lo_res.x = 0;
dispatch->wheel.lo_res.y = 0;
return;
}
if (dispatch->wheel.hi_res.y != 0) {
int value = dispatch->wheel.hi_res.y;
v120.y = -1 * value;
wheel_degrees.y = -1 * value/120.0 * device->scroll.wheel_click_angle.y;
evdev_notify_axis_wheel(
device,
time,
bit(LIBINPUT_POINTER_AXIS_SCROLL_VERTICAL),
&wheel_degrees,
&v120);
dispatch->wheel.hi_res.y = 0;
}
if (dispatch->wheel.lo_res.y != 0) {
int value = dispatch->wheel.lo_res.y;
wheel_degrees.y = -1 * value * device->scroll.wheel_click_angle.y;
discrete.y = -1 * value;
evdev_notify_axis_legacy_wheel(
device,
time,
bit(LIBINPUT_POINTER_AXIS_SCROLL_VERTICAL),
&wheel_degrees,
&discrete);
dispatch->wheel.lo_res.y = 0;
}
if (dispatch->wheel.hi_res.x != 0) {
int value = dispatch->wheel.hi_res.x;
v120.x = value;
wheel_degrees.x = value/120.0 * device->scroll.wheel_click_angle.x;
evdev_notify_axis_wheel(
device,
time,
bit(LIBINPUT_POINTER_AXIS_SCROLL_HORIZONTAL),
&wheel_degrees,
&v120);
dispatch->wheel.hi_res.x = 0;
}
if (dispatch->wheel.lo_res.x != 0) {
int value = dispatch->wheel.lo_res.x;
wheel_degrees.x = value * device->scroll.wheel_click_angle.x;
discrete.x = value;
evdev_notify_axis_legacy_wheel(
device,
time,
bit(LIBINPUT_POINTER_AXIS_SCROLL_HORIZONTAL),
&wheel_degrees,
&discrete);
dispatch->wheel.lo_res.x = 0;
}
}
static void
wheel_handle_state_none(struct fallback_dispatch *dispatch,
struct evdev_device *device,
uint64_t time)
{
}
static void
wheel_handle_state_accumulating_scroll(struct fallback_dispatch *dispatch,
struct evdev_device *device,
uint64_t time)
{
if (abs(dispatch->wheel.hi_res.x) >= ACC_V120_THRESHOLD ||
abs(dispatch->wheel.hi_res.y) >= ACC_V120_THRESHOLD) {
wheel_handle_event(dispatch,
WHEEL_EVENT_SCROLL_ACCUMULATED,
time);
wheel_flush_scroll(dispatch, device, time);
}
}
static void
wheel_handle_state_scrolling(struct fallback_dispatch *dispatch,
struct evdev_device *device,
uint64_t time)
{
wheel_flush_scroll(dispatch, device, time);
}
static void
wheel_handle_direction_change(struct fallback_dispatch *dispatch,
struct input_event *e,
uint64_t time)
{
enum wheel_direction new_dir = WHEEL_DIR_UNKNOW;
switch (e->code) {
case REL_WHEEL_HI_RES:
new_dir = (e->value > 0) ? WHEEL_DIR_VPOS : WHEEL_DIR_VNEG;
break;
case REL_HWHEEL_HI_RES:
new_dir = (e->value > 0) ? WHEEL_DIR_HPOS : WHEEL_DIR_HNEG;
break;
}
if (new_dir != WHEEL_DIR_UNKNOW && new_dir != dispatch->wheel.dir) {
dispatch->wheel.dir = new_dir;
wheel_handle_event(dispatch,
WHEEL_EVENT_SCROLL_DIR_CHANGED,
time);
}
}
static void
fallback_rotate_wheel(struct fallback_dispatch *dispatch,
struct evdev_device *device,
struct input_event *e)
{
/* Special case: if we're upside down (-ish),
* swap the direction of the wheels so that user-down
* means scroll down. This isn't done for any other angle
* since it's not clear what the heuristics should be.*/
if (dispatch->rotation.angle >= 160.0 &&
dispatch->rotation.angle <= 220.0) {
e->value *= -1;
}
}
void
fallback_wheel_process_relative(struct fallback_dispatch *dispatch,
struct evdev_device *device,
struct input_event *e, uint64_t time)
{
switch (e->code) {
case REL_WHEEL:
fallback_rotate_wheel(dispatch, device, e);
dispatch->wheel.lo_res.y += e->value;
if (dispatch->wheel.emulate_hi_res_wheel)
dispatch->wheel.hi_res.y += e->value * 120;
dispatch->pending_event |= EVDEV_WHEEL;
wheel_handle_event(dispatch, WHEEL_EVENT_SCROLL, time);
break;
case REL_HWHEEL:
fallback_rotate_wheel(dispatch, device, e);
dispatch->wheel.lo_res.x += e->value;
if (dispatch->wheel.emulate_hi_res_wheel)
dispatch->wheel.hi_res.x += e->value * 120;
dispatch->pending_event |= EVDEV_WHEEL;
wheel_handle_event(dispatch, WHEEL_EVENT_SCROLL, time);
break;
case REL_WHEEL_HI_RES:
fallback_rotate_wheel(dispatch, device, e);
dispatch->wheel.hi_res.y += e->value;
dispatch->wheel.hi_res_event_received = true;
dispatch->pending_event |= EVDEV_WHEEL;
wheel_handle_direction_change(dispatch, e, time);
wheel_handle_event(dispatch, WHEEL_EVENT_SCROLL, time);
break;
case REL_HWHEEL_HI_RES:
fallback_rotate_wheel(dispatch, device, e);
dispatch->wheel.hi_res.x += e->value;
dispatch->wheel.hi_res_event_received = true;
dispatch->pending_event |= EVDEV_WHEEL;
wheel_handle_direction_change(dispatch, e, time);
wheel_handle_event(dispatch, WHEEL_EVENT_SCROLL, time);
break;
}
}
void
fallback_wheel_handle_state(struct fallback_dispatch *dispatch,
struct evdev_device *device,
uint64_t time)
{
if (!(device->seat_caps & EVDEV_DEVICE_POINTER))
return;
if (!dispatch->wheel.emulate_hi_res_wheel &&
!dispatch->wheel.hi_res_event_received &&
(dispatch->wheel.lo_res.x != 0 || dispatch->wheel.lo_res.y != 0)) {
evdev_log_bug_kernel(device,
"device supports high-resolution scroll but only low-resolution events have been received.\n"
"See %s/incorrectly-enabled-hires.html for details\n",
HTTP_DOC_LINK);
dispatch->wheel.emulate_hi_res_wheel = true;
dispatch->wheel.hi_res.x = dispatch->wheel.lo_res.x * 120;
dispatch->wheel.hi_res.y = dispatch->wheel.lo_res.y * 120;
}
switch (dispatch->wheel.state) {
case WHEEL_STATE_NONE:
wheel_handle_state_none(dispatch, device, time);
break;
case WHEEL_STATE_ACCUMULATING_SCROLL:
wheel_handle_state_accumulating_scroll(dispatch, device, time);
break;
case WHEEL_STATE_SCROLLING:
wheel_handle_state_scrolling(dispatch, device, time);
break;
}
}
static void
wheel_init_scroll_timer(uint64_t now, void *data)
{
struct evdev_device *device = data;
struct fallback_dispatch *dispatch =
fallback_dispatch(device->dispatch);
wheel_handle_event(dispatch, WHEEL_EVENT_SCROLL_TIMEOUT, now);
}
void
fallback_init_wheel(struct fallback_dispatch *dispatch,
struct evdev_device *device)
{
char timer_name[64];
dispatch->wheel.state = WHEEL_STATE_NONE;
dispatch->wheel.dir = WHEEL_DIR_UNKNOW;
/* On kernel < 5.0 we need to emulate high-resolution
wheel scroll events */
if ((libevdev_has_event_code(device->evdev,
EV_REL,
REL_WHEEL) &&
!libevdev_has_event_code(device->evdev,
EV_REL,
REL_WHEEL_HI_RES)) ||
(libevdev_has_event_code(device->evdev,
EV_REL,
REL_HWHEEL) &&
!libevdev_has_event_code(device->evdev,
EV_REL,
REL_HWHEEL_HI_RES)))
dispatch->wheel.emulate_hi_res_wheel = true;
snprintf(timer_name,
sizeof(timer_name),
"%s wheel scroll",
evdev_device_get_sysname(device));
libinput_timer_init(&dispatch->wheel.scroll_timer,
evdev_libinput_context(device),
timer_name,
wheel_init_scroll_timer,
device);
}
libinput-1.28.1/src/evdev.c000066400000000000000000002504001477265155700155210ustar00rootroot00000000000000/*
* Copyright © 2010 Intel Corporation
* Copyright © 2013 Jonas Ådahl
* Copyright © 2013-2017 Red Hat, Inc.
* Copyright © 2017 James Ye
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice (including the next
* paragraph) shall be included in all copies or substantial portions of the
* Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
*/
#include "config.h"
#include
#include
#include
#include
#include
#include "linux/input.h"
#include
#include
#include
#include
#include
#include "libinput.h"
#include "evdev.h"
#include "filter.h"
#include "libinput-private.h"
#include "quirks.h"
#include "util-input-event.h"
#if HAVE_LIBWACOM
#include
#endif
#define DEFAULT_WHEEL_CLICK_ANGLE 15
#define DEFAULT_BUTTON_SCROLL_TIMEOUT ms2us(200)
enum evdev_device_udev_tags {
EVDEV_UDEV_TAG_INPUT = bit(0),
EVDEV_UDEV_TAG_KEYBOARD = bit(1),
EVDEV_UDEV_TAG_MOUSE = bit(2),
EVDEV_UDEV_TAG_TOUCHPAD = bit(3),
EVDEV_UDEV_TAG_TOUCHSCREEN = bit(4),
EVDEV_UDEV_TAG_TABLET = bit(5),
EVDEV_UDEV_TAG_JOYSTICK = bit(6),
EVDEV_UDEV_TAG_ACCELEROMETER = bit(7),
EVDEV_UDEV_TAG_TABLET_PAD = bit(8),
EVDEV_UDEV_TAG_POINTINGSTICK = bit(9),
EVDEV_UDEV_TAG_TRACKBALL = bit(10),
EVDEV_UDEV_TAG_SWITCH = bit(11),
};
struct evdev_udev_tag_match {
const char *name;
enum evdev_device_udev_tags tag;
};
static const struct evdev_udev_tag_match evdev_udev_tag_matches[] = {
{"ID_INPUT", EVDEV_UDEV_TAG_INPUT},
{"ID_INPUT_KEYBOARD", EVDEV_UDEV_TAG_KEYBOARD},
{"ID_INPUT_KEY", EVDEV_UDEV_TAG_KEYBOARD},
{"ID_INPUT_MOUSE", EVDEV_UDEV_TAG_MOUSE},
{"ID_INPUT_TOUCHPAD", EVDEV_UDEV_TAG_TOUCHPAD},
{"ID_INPUT_TOUCHSCREEN", EVDEV_UDEV_TAG_TOUCHSCREEN},
{"ID_INPUT_TABLET", EVDEV_UDEV_TAG_TABLET},
{"ID_INPUT_TABLET_PAD", EVDEV_UDEV_TAG_TABLET_PAD},
{"ID_INPUT_JOYSTICK", EVDEV_UDEV_TAG_JOYSTICK},
{"ID_INPUT_ACCELEROMETER", EVDEV_UDEV_TAG_ACCELEROMETER},
{"ID_INPUT_POINTINGSTICK", EVDEV_UDEV_TAG_POINTINGSTICK},
{"ID_INPUT_TRACKBALL", EVDEV_UDEV_TAG_TRACKBALL},
{"ID_INPUT_SWITCH", EVDEV_UDEV_TAG_SWITCH},
};
static const unsigned int well_known_keyboard_keys[] = {
KEY_LEFTCTRL,
KEY_CAPSLOCK,
KEY_NUMLOCK,
KEY_INSERT,
KEY_MUTE,
KEY_CALC,
KEY_FILE,
KEY_MAIL,
KEY_PLAYPAUSE,
KEY_BRIGHTNESSDOWN,
};
static inline bool
parse_udev_flag(struct evdev_device *device,
struct udev_device *udev_device,
const char *property)
{
const char *val;
bool b;
val = udev_device_get_property_value(udev_device, property);
if (!val)
return false;
if (!parse_boolean_property(val, &b)) {
evdev_log_error(device,
"property %s has invalid value '%s'\n",
property,
val);
return false;
}
return b;
}
int
evdev_update_key_down_count(struct evdev_device *device,
int code,
int pressed)
{
int key_count = 0;
assert(code >= 0 && code < KEY_CNT);
if (pressed) {
key_count = ++device->key_count[code];
} else {
if (device->key_count[code] > 0) {
key_count = --device->key_count[code];
} else {
evdev_log_bug_libinput(device,
"releasing key %s with count %d\n",
libevdev_event_code_get_name(EV_KEY, code),
device->key_count[code]);
}
}
if (key_count > 32) {
evdev_log_bug_libinput(device,
"key count for %s reached abnormal values\n",
libevdev_event_code_get_name(EV_KEY, code));
}
return key_count;
}
enum libinput_switch_state
evdev_device_switch_get_state(struct evdev_device *device,
enum libinput_switch sw)
{
struct evdev_dispatch *dispatch = device->dispatch;
assert(dispatch->interface->get_switch_state);
return dispatch->interface->get_switch_state(dispatch, sw);
}
void
evdev_pointer_notify_physical_button(struct evdev_device *device,
uint64_t time,
int button,
enum libinput_button_state state)
{
if (evdev_middlebutton_filter_button(device,
time,
button,
state))
return;
evdev_pointer_notify_button(device,
time,
(unsigned int)button,
state);
}
static void
evdev_pointer_post_button(struct evdev_device *device,
uint64_t time,
unsigned int button,
enum libinput_button_state state)
{
int down_count;
down_count = evdev_update_key_down_count(device, button, state);
if ((state == LIBINPUT_BUTTON_STATE_PRESSED && down_count == 1) ||
(state == LIBINPUT_BUTTON_STATE_RELEASED && down_count == 0)) {
pointer_notify_button(&device->base, time, button, state);
if (state == LIBINPUT_BUTTON_STATE_RELEASED) {
if (device->left_handed.change_to_enabled)
device->left_handed.change_to_enabled(device);
if (device->scroll.change_scroll_method)
device->scroll.change_scroll_method(device);
}
}
}
static void
evdev_button_scroll_timeout(uint64_t time, void *data)
{
struct evdev_device *device = data;
device->scroll.button_scroll_state = BUTTONSCROLL_READY;
}
static void
evdev_button_scroll_button(struct evdev_device *device,
uint64_t time, int is_press)
{
/* Where the button lock is enabled, we wrap the buttons into
their own little state machine and filter out the events.
*/
switch (device->scroll.lock_state) {
case BUTTONSCROLL_LOCK_DISABLED:
break;
case BUTTONSCROLL_LOCK_IDLE:
assert(is_press);
device->scroll.lock_state = BUTTONSCROLL_LOCK_FIRSTDOWN;
evdev_log_debug(device, "scroll lock: first down\n");
break; /* handle event */
case BUTTONSCROLL_LOCK_FIRSTDOWN:
assert(!is_press);
device->scroll.lock_state = BUTTONSCROLL_LOCK_FIRSTUP;
evdev_log_debug(device, "scroll lock: first up\n");
return; /* filter release event */
case BUTTONSCROLL_LOCK_FIRSTUP:
assert(is_press);
device->scroll.lock_state = BUTTONSCROLL_LOCK_SECONDDOWN;
evdev_log_debug(device, "scroll lock: second down\n");
return; /* filter press event */
case BUTTONSCROLL_LOCK_SECONDDOWN:
assert(!is_press);
device->scroll.lock_state = BUTTONSCROLL_LOCK_IDLE;
evdev_log_debug(device, "scroll lock: idle\n");
break; /* handle event */
}
if (is_press) {
if (device->scroll.button < BTN_MOUSE + 5) {
/* For mouse buttons 1-5 (0x110 to 0x114) we apply a timeout before scrolling
* since the button could also be used for regular clicking. */
enum timer_flags flags = TIMER_FLAG_NONE;
device->scroll.button_scroll_state = BUTTONSCROLL_BUTTON_DOWN;
/* Special case: if middle button emulation is enabled and
* our scroll button is the left or right button, we only
* get here *after* the middle button timeout has expired
* for that button press. The time passed is the button-down
* time though (which is in the past), so we have to allow
* for a negative timer to be set.
*/
if (device->middlebutton.enabled &&
(device->scroll.button == BTN_LEFT ||
device->scroll.button == BTN_RIGHT)) {
flags = TIMER_FLAG_ALLOW_NEGATIVE;
}
libinput_timer_set_flags(&device->scroll.timer,
time + DEFAULT_BUTTON_SCROLL_TIMEOUT,
flags);
} else {
/* For extra mouse buttons numbered 6 or more (0x115+) we assume it is
* dedicated exclusively to scrolling, so we don't apply the timeout
* in order to provide immediate scrolling responsiveness. */
device->scroll.button_scroll_state = BUTTONSCROLL_READY;
}
device->scroll.button_down_time = time;
evdev_log_debug(device, "btnscroll: down\n");
} else {
libinput_timer_cancel(&device->scroll.timer);
switch(device->scroll.button_scroll_state) {
case BUTTONSCROLL_IDLE:
evdev_log_bug_libinput(device,
"invalid state IDLE for button up\n");
break;
case BUTTONSCROLL_BUTTON_DOWN:
case BUTTONSCROLL_READY:
evdev_log_debug(device, "btnscroll: cancel\n");
/* If the button is released quickly enough or
* without scroll events, emit the
* button press/release events. */
evdev_pointer_post_button(device,
device->scroll.button_down_time,
device->scroll.button,
LIBINPUT_BUTTON_STATE_PRESSED);
evdev_pointer_post_button(device, time,
device->scroll.button,
LIBINPUT_BUTTON_STATE_RELEASED);
break;
case BUTTONSCROLL_SCROLLING:
evdev_log_debug(device, "btnscroll: up\n");
evdev_stop_scroll(device, time,
LIBINPUT_POINTER_AXIS_SOURCE_CONTINUOUS);
break;
}
device->scroll.button_scroll_state = BUTTONSCROLL_IDLE;
}
}
void
evdev_pointer_notify_button(struct evdev_device *device,
uint64_t time,
unsigned int button,
enum libinput_button_state state)
{
if (device->scroll.method == LIBINPUT_CONFIG_SCROLL_ON_BUTTON_DOWN &&
button == device->scroll.button) {
evdev_button_scroll_button(device, time, state);
return;
}
evdev_pointer_post_button(device, time, button, state);
}
void
evdev_device_led_update(struct evdev_device *device, enum libinput_led leds)
{
static const struct {
enum libinput_led libinput;
int evdev;
} map[] = {
{ LIBINPUT_LED_NUM_LOCK, LED_NUML },
{ LIBINPUT_LED_CAPS_LOCK, LED_CAPSL },
{ LIBINPUT_LED_SCROLL_LOCK, LED_SCROLLL },
{ LIBINPUT_LED_COMPOSE, LED_COMPOSE },
{ LIBINPUT_LED_KANA, LED_KANA },
};
struct input_event ev[ARRAY_LENGTH(map) + 1];
unsigned int i;
if (!(device->seat_caps & EVDEV_DEVICE_KEYBOARD))
return;
memset(ev, 0, sizeof(ev));
for (i = 0; i < ARRAY_LENGTH(map); i++) {
ev[i].type = EV_LED;
ev[i].code = map[i].evdev;
ev[i].value = !!(leds & map[i].libinput);
}
ev[i].type = EV_SYN;
ev[i].code = SYN_REPORT;
i = write(device->fd, ev, sizeof ev);
(void)i; /* no, we really don't care about the return value */
}
void
evdev_transform_absolute(struct evdev_device *device,
struct device_coords *point)
{
if (!device->abs.apply_calibration)
return;
matrix_mult_vec(&device->abs.calibration, &point->x, &point->y);
}
void
evdev_transform_relative(struct evdev_device *device,
struct device_coords *point)
{
struct matrix rel_matrix;
if (!device->abs.apply_calibration)
return;
matrix_to_relative(&rel_matrix, &device->abs.calibration);
matrix_mult_vec(&rel_matrix, &point->x, &point->y);
}
double
evdev_device_transform_x(struct evdev_device *device,
double x,
uint32_t width)
{
return absinfo_scale_axis(device->abs.absinfo_x, x, width);
}
double
evdev_device_transform_y(struct evdev_device *device,
double y,
uint32_t height)
{
return absinfo_scale_axis(device->abs.absinfo_y, y, height);
}
void
evdev_notify_axis_legacy_wheel(struct evdev_device *device,
uint64_t time,
uint32_t axes,
const struct normalized_coords *delta_in,
const struct discrete_coords *discrete_in)
{
struct normalized_coords delta = *delta_in;
struct discrete_coords discrete = *discrete_in;
if (device->scroll.invert_horizontal_scrolling) {
delta.x *= -1;
discrete.x *= -1;
}
if (device->scroll.natural_scrolling_enabled) {
delta.x *= -1;
delta.y *= -1;
discrete.x *= -1;
discrete.y *= -1;
}
pointer_notify_axis_legacy_wheel(&device->base,
time,
axes,
&delta,
&discrete);
}
void
evdev_notify_axis_wheel(struct evdev_device *device,
uint64_t time,
uint32_t axes,
const struct normalized_coords *delta_in,
const struct wheel_v120 *v120_in)
{
struct normalized_coords delta = *delta_in;
struct wheel_v120 v120 = *v120_in;
if (device->scroll.invert_horizontal_scrolling) {
delta.x *= -1;
v120.x *= -1;
}
if (device->scroll.natural_scrolling_enabled) {
delta.x *= -1;
delta.y *= -1;
v120.x *= -1;
v120.y *= -1;
}
pointer_notify_axis_wheel(&device->base,
time,
axes,
&delta,
&v120);
}
void
evdev_notify_axis_finger(struct evdev_device *device,
uint64_t time,
uint32_t axes,
const struct normalized_coords *delta_in)
{
struct normalized_coords delta = *delta_in;
if (device->scroll.natural_scrolling_enabled) {
delta.x *= -1;
delta.y *= -1;
}
pointer_notify_axis_finger(&device->base,
time,
axes,
&delta);
}
void
evdev_notify_axis_continous(struct evdev_device *device,
uint64_t time,
uint32_t axes,
const struct normalized_coords *delta_in)
{
struct normalized_coords delta = *delta_in;
if (device->scroll.natural_scrolling_enabled) {
delta.x *= -1;
delta.y *= -1;
}
pointer_notify_axis_continuous(&device->base,
time,
axes,
&delta);
}
static void
evdev_tag_external_mouse(struct evdev_device *device,
struct udev_device *udev_device)
{
int bustype;
bustype = libevdev_get_id_bustype(device->evdev);
if (bustype == BUS_USB || bustype == BUS_BLUETOOTH)
device->tags |= EVDEV_TAG_EXTERNAL_MOUSE;
}
static void
evdev_tag_trackpoint(struct evdev_device *device,
struct udev_device *udev_device)
{
struct quirks_context *quirks;
struct quirks *q;
char *prop;
if (!libevdev_has_property(device->evdev,
INPUT_PROP_POINTING_STICK) &&
!parse_udev_flag(device, udev_device, "ID_INPUT_POINTINGSTICK"))
return;
device->tags |= EVDEV_TAG_TRACKPOINT;
quirks = evdev_libinput_context(device)->quirks;
q = quirks_fetch_for_device(quirks, device->udev_device);
if (q && quirks_get_string(q, QUIRK_ATTR_TRACKPOINT_INTEGRATION, &prop)) {
if (streq(prop, "internal")) {
/* noop, this is the default anyway */
} else if (streq(prop, "external")) {
device->tags |= EVDEV_TAG_EXTERNAL_MOUSE;
evdev_log_info(device,
"is an external pointing stick\n");
} else {
evdev_log_info(device,
"tagged with unknown value %s\n",
prop);
}
}
quirks_unref(q);
}
static inline void
evdev_tag_keyboard_internal(struct evdev_device *device)
{
device->tags |= EVDEV_TAG_INTERNAL_KEYBOARD;
device->tags &= ~EVDEV_TAG_EXTERNAL_KEYBOARD;
}
static inline void
evdev_tag_keyboard_external(struct evdev_device *device)
{
device->tags |= EVDEV_TAG_EXTERNAL_KEYBOARD;
device->tags &= ~EVDEV_TAG_INTERNAL_KEYBOARD;
}
static void
evdev_tag_keyboard(struct evdev_device *device,
struct udev_device *udev_device)
{
struct quirks_context *quirks;
struct quirks *q;
char *prop;
int code;
if (!libevdev_has_event_type(device->evdev, EV_KEY))
return;
for (code = KEY_Q; code <= KEY_P; code++) {
if (!libevdev_has_event_code(device->evdev,
EV_KEY,
code))
return;
}
quirks = evdev_libinput_context(device)->quirks;
q = quirks_fetch_for_device(quirks, device->udev_device);
if (q && quirks_get_string(q, QUIRK_ATTR_KEYBOARD_INTEGRATION, &prop)) {
if (streq(prop, "internal")) {
evdev_tag_keyboard_internal(device);
} else if (streq(prop, "external")) {
evdev_tag_keyboard_external(device);
} else {
evdev_log_info(device,
"tagged with unknown value %s\n",
prop);
}
}
quirks_unref(q);
device->tags |= EVDEV_TAG_KEYBOARD;
}
static void
evdev_tag_tablet_touchpad(struct evdev_device *device)
{
device->tags |= EVDEV_TAG_TABLET_TOUCHPAD;
}
static int
evdev_calibration_has_matrix(struct libinput_device *libinput_device)
{
struct evdev_device *device = evdev_device(libinput_device);
return device->abs.absinfo_x && device->abs.absinfo_y;
}
static enum libinput_config_status
evdev_calibration_set_matrix(struct libinput_device *libinput_device,
const float matrix[6])
{
struct evdev_device *device = evdev_device(libinput_device);
evdev_device_calibrate(device, matrix);
return LIBINPUT_CONFIG_STATUS_SUCCESS;
}
static int
evdev_calibration_get_matrix(struct libinput_device *libinput_device,
float matrix[6])
{
struct evdev_device *device = evdev_device(libinput_device);
matrix_to_farray6(&device->abs.usermatrix, matrix);
return !matrix_is_identity(&device->abs.usermatrix);
}
static int
evdev_calibration_get_default_matrix(struct libinput_device *libinput_device,
float matrix[6])
{
struct evdev_device *device = evdev_device(libinput_device);
matrix_to_farray6(&device->abs.default_calibration, matrix);
return !matrix_is_identity(&device->abs.default_calibration);
}
static uint32_t
evdev_sendevents_get_modes(struct libinput_device *device)
{
return LIBINPUT_CONFIG_SEND_EVENTS_DISABLED;
}
static enum libinput_config_status
evdev_sendevents_set_mode(struct libinput_device *device,
enum libinput_config_send_events_mode mode)
{
struct evdev_device *evdev = evdev_device(device);
struct evdev_dispatch *dispatch = evdev->dispatch;
if (mode == dispatch->sendevents.current_mode)
return LIBINPUT_CONFIG_STATUS_SUCCESS;
switch(mode) {
case LIBINPUT_CONFIG_SEND_EVENTS_ENABLED:
evdev_device_resume(evdev);
break;
case LIBINPUT_CONFIG_SEND_EVENTS_DISABLED:
evdev_device_suspend(evdev);
break;
default: /* no support for combined modes yet */
return LIBINPUT_CONFIG_STATUS_UNSUPPORTED;
}
dispatch->sendevents.current_mode = mode;
return LIBINPUT_CONFIG_STATUS_SUCCESS;
}
static enum libinput_config_send_events_mode
evdev_sendevents_get_mode(struct libinput_device *device)
{
struct evdev_device *evdev = evdev_device(device);
struct evdev_dispatch *dispatch = evdev->dispatch;
return dispatch->sendevents.current_mode;
}
static enum libinput_config_send_events_mode
evdev_sendevents_get_default_mode(struct libinput_device *device)
{
return LIBINPUT_CONFIG_SEND_EVENTS_ENABLED;
}
static int
evdev_left_handed_has(struct libinput_device *device)
{
/* This is only hooked up when we have left-handed configuration, so we
* can hardcode 1 here */
return 1;
}
static enum libinput_config_status
evdev_left_handed_set(struct libinput_device *device, int left_handed)
{
struct evdev_device *evdev = evdev_device(device);
evdev->left_handed.want_enabled = left_handed ? true : false;
evdev->left_handed.change_to_enabled(evdev);
return LIBINPUT_CONFIG_STATUS_SUCCESS;
}
static int
evdev_left_handed_get(struct libinput_device *device)
{
struct evdev_device *evdev = evdev_device(device);
/* return the wanted configuration, even if it hasn't taken
* effect yet! */
return evdev->left_handed.want_enabled;
}
static int
evdev_left_handed_get_default(struct libinput_device *device)
{
return 0;
}
void
evdev_init_left_handed(struct evdev_device *device,
void (*change_to_left_handed)(struct evdev_device *))
{
device->left_handed.config.has = evdev_left_handed_has;
device->left_handed.config.set = evdev_left_handed_set;
device->left_handed.config.get = evdev_left_handed_get;
device->left_handed.config.get_default = evdev_left_handed_get_default;
device->base.config.left_handed = &device->left_handed.config;
device->left_handed.enabled = false;
device->left_handed.want_enabled = false;
device->left_handed.change_to_enabled = change_to_left_handed;
}
static uint32_t
evdev_scroll_get_methods(struct libinput_device *device)
{
return LIBINPUT_CONFIG_SCROLL_ON_BUTTON_DOWN;
}
static enum libinput_config_status
evdev_scroll_set_method(struct libinput_device *device,
enum libinput_config_scroll_method method)
{
struct evdev_device *evdev = evdev_device(device);
evdev->scroll.want_method = method;
evdev->scroll.change_scroll_method(evdev);
return LIBINPUT_CONFIG_STATUS_SUCCESS;
}
static enum libinput_config_scroll_method
evdev_scroll_get_method(struct libinput_device *device)
{
struct evdev_device *evdev = evdev_device(device);
/* return the wanted configuration, even if it hasn't taken
* effect yet! */
return evdev->scroll.want_method;
}
static enum libinput_config_scroll_method
evdev_scroll_get_default_method(struct libinput_device *device)
{
struct evdev_device *evdev = evdev_device(device);
if (evdev->tags & EVDEV_TAG_TRACKPOINT)
return LIBINPUT_CONFIG_SCROLL_ON_BUTTON_DOWN;
/* Mice without a scroll wheel but with middle button have on-button
* scrolling by default */
if (!libevdev_has_event_code(evdev->evdev, EV_REL, REL_WHEEL) &&
!libevdev_has_event_code(evdev->evdev, EV_REL, REL_HWHEEL) &&
libevdev_has_event_code(evdev->evdev, EV_KEY, BTN_MIDDLE))
return LIBINPUT_CONFIG_SCROLL_ON_BUTTON_DOWN;
return LIBINPUT_CONFIG_SCROLL_NO_SCROLL;
}
static enum libinput_config_status
evdev_scroll_set_button(struct libinput_device *device,
uint32_t button)
{
struct evdev_device *evdev = evdev_device(device);
evdev->scroll.want_button = button;
evdev->scroll.change_scroll_method(evdev);
return LIBINPUT_CONFIG_STATUS_SUCCESS;
}
static uint32_t
evdev_scroll_get_button(struct libinput_device *device)
{
struct evdev_device *evdev = evdev_device(device);
/* return the wanted configuration, even if it hasn't taken
* effect yet! */
return evdev->scroll.want_button;
}
static uint32_t
evdev_scroll_get_default_button(struct libinput_device *device)
{
struct evdev_device *evdev = evdev_device(device);
unsigned int code;
if (libevdev_has_event_code(evdev->evdev, EV_KEY, BTN_MIDDLE))
return BTN_MIDDLE;
for (code = BTN_SIDE; code <= BTN_TASK; code++) {
if (libevdev_has_event_code(evdev->evdev, EV_KEY, code))
return code;
}
if (libevdev_has_event_code(evdev->evdev, EV_KEY, BTN_RIGHT))
return BTN_RIGHT;
return 0;
}
static enum libinput_config_status
evdev_scroll_set_button_lock(struct libinput_device *device,
enum libinput_config_scroll_button_lock_state state)
{
struct evdev_device *evdev = evdev_device(device);
switch (state) {
case LIBINPUT_CONFIG_SCROLL_BUTTON_LOCK_DISABLED:
evdev->scroll.want_lock_enabled = false;
break;
case LIBINPUT_CONFIG_SCROLL_BUTTON_LOCK_ENABLED:
evdev->scroll.want_lock_enabled = true;
break;
default:
return LIBINPUT_CONFIG_STATUS_INVALID;
}
evdev->scroll.change_scroll_method(evdev);
return LIBINPUT_CONFIG_STATUS_SUCCESS;
}
static enum libinput_config_scroll_button_lock_state
evdev_scroll_get_button_lock(struct libinput_device *device)
{
struct evdev_device *evdev = evdev_device(device);
if (evdev->scroll.lock_state == BUTTONSCROLL_LOCK_DISABLED)
return LIBINPUT_CONFIG_SCROLL_BUTTON_LOCK_DISABLED;
return LIBINPUT_CONFIG_SCROLL_BUTTON_LOCK_ENABLED;
}
static enum libinput_config_scroll_button_lock_state
evdev_scroll_get_default_button_lock(struct libinput_device *device)
{
return LIBINPUT_CONFIG_SCROLL_BUTTON_LOCK_DISABLED;
}
void
evdev_set_button_scroll_lock_enabled(struct evdev_device *device,
bool enabled)
{
if (enabled)
device->scroll.lock_state = BUTTONSCROLL_LOCK_IDLE;
else
device->scroll.lock_state = BUTTONSCROLL_LOCK_DISABLED;
}
void
evdev_init_button_scroll(struct evdev_device *device,
void (*change_scroll_method)(struct evdev_device *))
{
char timer_name[64];
snprintf(timer_name,
sizeof(timer_name),
"%s btnscroll",
evdev_device_get_sysname(device));
libinput_timer_init(&device->scroll.timer,
evdev_libinput_context(device),
timer_name,
evdev_button_scroll_timeout, device);
device->scroll.config.get_methods = evdev_scroll_get_methods;
device->scroll.config.set_method = evdev_scroll_set_method;
device->scroll.config.get_method = evdev_scroll_get_method;
device->scroll.config.get_default_method = evdev_scroll_get_default_method;
device->scroll.config.set_button = evdev_scroll_set_button;
device->scroll.config.get_button = evdev_scroll_get_button;
device->scroll.config.get_default_button = evdev_scroll_get_default_button;
device->scroll.config.set_button_lock = evdev_scroll_set_button_lock;
device->scroll.config.get_button_lock = evdev_scroll_get_button_lock;
device->scroll.config.get_default_button_lock = evdev_scroll_get_default_button_lock;
device->base.config.scroll_method = &device->scroll.config;
device->scroll.method = evdev_scroll_get_default_method((struct libinput_device *)device);
device->scroll.want_method = device->scroll.method;
device->scroll.button = evdev_scroll_get_default_button((struct libinput_device *)device);
device->scroll.want_button = device->scroll.button;
device->scroll.change_scroll_method = change_scroll_method;
}
void
evdev_init_calibration(struct evdev_device *device,
struct libinput_device_config_calibration *calibration)
{
device->base.config.calibration = calibration;
calibration->has_matrix = evdev_calibration_has_matrix;
calibration->set_matrix = evdev_calibration_set_matrix;
calibration->get_matrix = evdev_calibration_get_matrix;
calibration->get_default_matrix = evdev_calibration_get_default_matrix;
}
void
evdev_init_sendevents(struct evdev_device *device,
struct evdev_dispatch *dispatch)
{
device->base.config.sendevents = &dispatch->sendevents.config;
dispatch->sendevents.current_mode = LIBINPUT_CONFIG_SEND_EVENTS_ENABLED;
dispatch->sendevents.config.get_modes = evdev_sendevents_get_modes;
dispatch->sendevents.config.set_mode = evdev_sendevents_set_mode;
dispatch->sendevents.config.get_mode = evdev_sendevents_get_mode;
dispatch->sendevents.config.get_default_mode = evdev_sendevents_get_default_mode;
}
static int
evdev_scroll_config_natural_has(struct libinput_device *device)
{
return 1;
}
static enum libinput_config_status
evdev_scroll_config_natural_set(struct libinput_device *device,
int enabled)
{
struct evdev_device *dev = evdev_device(device);
dev->scroll.natural_scrolling_enabled = enabled ? true : false;
return LIBINPUT_CONFIG_STATUS_SUCCESS;
}
static int
evdev_scroll_config_natural_get(struct libinput_device *device)
{
struct evdev_device *dev = evdev_device(device);
return dev->scroll.natural_scrolling_enabled ? 1 : 0;
}
static int
evdev_scroll_config_natural_get_default(struct libinput_device *device)
{
/* Overridden in evdev-mt-touchpad.c for Apple touchpads. */
return 0;
}
void
evdev_init_natural_scroll(struct evdev_device *device)
{
device->scroll.config_natural.has = evdev_scroll_config_natural_has;
device->scroll.config_natural.set_enabled = evdev_scroll_config_natural_set;
device->scroll.config_natural.get_enabled = evdev_scroll_config_natural_get;
device->scroll.config_natural.get_default_enabled = evdev_scroll_config_natural_get_default;
device->scroll.natural_scrolling_enabled = false;
device->base.config.natural_scroll = &device->scroll.config_natural;
}
int
evdev_need_mtdev(struct evdev_device *device)
{
struct libevdev *evdev = device->evdev;
return (libevdev_has_event_code(evdev, EV_ABS, ABS_MT_POSITION_X) &&
libevdev_has_event_code(evdev, EV_ABS, ABS_MT_POSITION_Y) &&
!libevdev_has_event_code(evdev, EV_ABS, ABS_MT_SLOT));
}
/* Fake MT devices have the ABS_MT_SLOT bit set because of
the limited ABS_* range - they aren't MT devices, they
just have too many ABS_ axes */
bool
evdev_is_fake_mt_device(struct evdev_device *device)
{
struct libevdev *evdev = device->evdev;
return libevdev_has_event_code(evdev, EV_ABS, ABS_MT_SLOT) &&
libevdev_get_num_slots(evdev) == -1;
}
enum switch_reliability
evdev_read_switch_reliability_prop(struct evdev_device *device)
{
enum switch_reliability r;
struct quirks_context *quirks;
struct quirks *q;
char *prop;
quirks = evdev_libinput_context(device)->quirks;
q = quirks_fetch_for_device(quirks, device->udev_device);
if (!q || !quirks_get_string(q, QUIRK_ATTR_LID_SWITCH_RELIABILITY, &prop)) {
r = RELIABILITY_RELIABLE;
} else if (!parse_switch_reliability_property(prop, &r)) {
evdev_log_error(device,
"%s: switch reliability set to unknown value '%s'\n",
device->devname,
prop);
r = RELIABILITY_RELIABLE;
} else if (r == RELIABILITY_WRITE_OPEN) {
evdev_log_info(device, "will write switch open events\n");
}
quirks_unref(q);
return r;
}
LIBINPUT_UNUSED
static inline void
evdev_print_event(struct evdev_device *device,
const struct input_event *e)
{
static uint32_t offset = 0;
static uint32_t last_time = 0;
uint32_t time = us2ms(input_event_time(e));
if (offset == 0) {
offset = time;
last_time = time - offset;
}
time -= offset;
if (libevdev_event_is_code(e, EV_SYN, SYN_REPORT)) {
evdev_log_debug(device,
"%u.%03u ----------------- EV_SYN ----------------- +%ums\n",
time / 1000,
time % 1000,
time - last_time);
last_time = time;
} else {
evdev_log_debug(device,
"%u.%03u %-16s %-20s %4d\n",
time / 1000,
time % 1000,
libevdev_event_type_get_name(e->type),
libevdev_event_code_get_name(e->type, e->code),
e->value);
}
}
static inline void
evdev_process_event(struct evdev_device *device, struct input_event *e)
{
struct evdev_dispatch *dispatch = device->dispatch;
uint64_t time = input_event_time(e);
#if EVENT_DEBUGGING
evdev_print_event(device, e);
#endif
libinput_timer_flush(evdev_libinput_context(device), time);
dispatch->interface->process(dispatch, device, e, time);
}
static inline void
evdev_device_dispatch_one(struct evdev_device *device,
struct input_event *ev)
{
if (!device->mtdev) {
evdev_process_event(device, ev);
} else {
mtdev_put_event(device->mtdev, ev);
if (libevdev_event_is_code(ev, EV_SYN, SYN_REPORT)) {
while (!mtdev_empty(device->mtdev)) {
struct input_event e;
mtdev_get_event(device->mtdev, &e);
evdev_process_event(device, &e);
}
}
}
}
static int
evdev_sync_device(struct evdev_device *device)
{
struct input_event ev;
int rc;
do {
rc = libevdev_next_event(device->evdev,
LIBEVDEV_READ_FLAG_SYNC, &ev);
if (rc < 0)
break;
evdev_device_dispatch_one(device, &ev);
} while (rc == LIBEVDEV_READ_STATUS_SYNC);
return rc == -EAGAIN ? 0 : rc;
}
static inline void
evdev_note_time_delay(struct evdev_device *device,
const struct input_event *ev)
{
struct libinput *libinput = evdev_libinput_context(device);
uint32_t tdelta;
uint64_t eventtime = input_event_time(ev);
/* if we have a current libinput_dispatch() snapshot, compare our
* event time with the one from the snapshot. If we have more than
* 10ms delay, complain about it. This catches delays in processing
* where there is no steady event flow and thus SYN_DROPPED may not
* get hit by the kernel despite us being too slow.
*/
if (libinput->dispatch_time == 0 ||
eventtime > libinput->dispatch_time)
return;
tdelta = us2ms(libinput->dispatch_time - eventtime);
if (tdelta > 20) {
evdev_log_bug_client_ratelimit(device,
&device->delay_warning_limit,
"event processing lagging behind by %dms, your system is too slow\n",
tdelta);
}
}
static void
evdev_device_dispatch(void *data)
{
struct evdev_device *device = data;
struct libinput *libinput = evdev_libinput_context(device);
struct input_event ev;
int rc;
bool once = false;
/* If the compositor is repainting, this function is called only once
* per frame and we have to process all the events available on the
* fd, otherwise there will be input lag. */
do {
rc = libevdev_next_event(device->evdev,
LIBEVDEV_READ_FLAG_NORMAL, &ev);
if (rc == LIBEVDEV_READ_STATUS_SYNC) {
evdev_log_info_ratelimit(device,
&device->syn_drop_limit,
"SYN_DROPPED event - some input events have been lost.\n");
/* send one more sync event so we handle all
currently pending events before we sync up
to the current state */
ev.code = SYN_REPORT;
evdev_device_dispatch_one(device, &ev);
rc = evdev_sync_device(device);
if (rc == 0)
rc = LIBEVDEV_READ_STATUS_SUCCESS;
} else if (rc == LIBEVDEV_READ_STATUS_SUCCESS) {
if (!once) {
evdev_note_time_delay(device, &ev);
once = true;
}
evdev_device_dispatch_one(device, &ev);
} else if (rc == -ENODEV) {
evdev_device_remove(device);
return;
}
} while (rc == LIBEVDEV_READ_STATUS_SUCCESS);
if (rc != -EAGAIN && rc != -EINTR) {
libinput_remove_source(libinput, device->source);
device->source = NULL;
}
}
static inline bool
evdev_init_accel(struct evdev_device *device,
enum libinput_config_accel_profile which)
{
struct motion_filter *filter = NULL;
if (which == LIBINPUT_CONFIG_ACCEL_PROFILE_CUSTOM)
filter = create_custom_accelerator_filter();
else if (device->tags & EVDEV_TAG_TRACKPOINT) {
if (which == LIBINPUT_CONFIG_ACCEL_PROFILE_FLAT)
filter = create_pointer_accelerator_filter_trackpoint_flat(device->trackpoint_multiplier);
else
filter = create_pointer_accelerator_filter_trackpoint(device->trackpoint_multiplier,
device->use_velocity_averaging);
} else {
if (which == LIBINPUT_CONFIG_ACCEL_PROFILE_FLAT)
filter = create_pointer_accelerator_filter_flat(device->dpi);
else if (device->dpi < DEFAULT_MOUSE_DPI)
filter = create_pointer_accelerator_filter_linear_low_dpi(device->dpi,
device->use_velocity_averaging);
}
if (!filter)
filter = create_pointer_accelerator_filter_linear(device->dpi,
device->use_velocity_averaging);
if (!filter)
return false;
evdev_device_init_pointer_acceleration(device, filter);
return true;
}
static int
evdev_accel_config_available(struct libinput_device *device)
{
/* this function is only called if we set up ptraccel, so we can
reply with a resounding "Yes" */
return 1;
}
static enum libinput_config_status
evdev_accel_config_set_speed(struct libinput_device *device, double speed)
{
struct evdev_device *dev = evdev_device(device);
if (!filter_set_speed(dev->pointer.filter, speed))
return LIBINPUT_CONFIG_STATUS_INVALID;
return LIBINPUT_CONFIG_STATUS_SUCCESS;
}
static double
evdev_accel_config_get_speed(struct libinput_device *device)
{
struct evdev_device *dev = evdev_device(device);
return filter_get_speed(dev->pointer.filter);
}
static double
evdev_accel_config_get_default_speed(struct libinput_device *device)
{
return 0.0;
}
static uint32_t
evdev_accel_config_get_profiles(struct libinput_device *libinput_device)
{
struct evdev_device *device = evdev_device(libinput_device);
if (!device->pointer.filter)
return LIBINPUT_CONFIG_ACCEL_PROFILE_NONE;
return LIBINPUT_CONFIG_ACCEL_PROFILE_ADAPTIVE |
LIBINPUT_CONFIG_ACCEL_PROFILE_FLAT |
LIBINPUT_CONFIG_ACCEL_PROFILE_CUSTOM;
}
static enum libinput_config_status
evdev_accel_config_set_profile(struct libinput_device *libinput_device,
enum libinput_config_accel_profile profile)
{
struct evdev_device *device = evdev_device(libinput_device);
struct motion_filter *filter;
double speed;
filter = device->pointer.filter;
if (filter_get_type(filter) == profile)
return LIBINPUT_CONFIG_STATUS_SUCCESS;
speed = filter_get_speed(filter);
device->pointer.filter = NULL;
if (evdev_init_accel(device, profile)) {
evdev_accel_config_set_speed(libinput_device, speed);
filter_destroy(filter);
} else {
device->pointer.filter = filter;
return LIBINPUT_CONFIG_STATUS_UNSUPPORTED;
}
return LIBINPUT_CONFIG_STATUS_SUCCESS;
}
static enum libinput_config_accel_profile
evdev_accel_config_get_profile(struct libinput_device *libinput_device)
{
struct evdev_device *device = evdev_device(libinput_device);
return filter_get_type(device->pointer.filter);
}
static enum libinput_config_accel_profile
evdev_accel_config_get_default_profile(struct libinput_device *libinput_device)
{
struct evdev_device *device = evdev_device(libinput_device);
if (!device->pointer.filter)
return LIBINPUT_CONFIG_ACCEL_PROFILE_NONE;
/* No device has a flat profile as default */
return LIBINPUT_CONFIG_ACCEL_PROFILE_ADAPTIVE;
}
static enum libinput_config_status
evdev_set_accel_config(struct libinput_device *libinput_device,
struct libinput_config_accel *accel_config)
{
assert(evdev_accel_config_get_profile(libinput_device) == accel_config->profile);
struct evdev_device *dev = evdev_device(libinput_device);
if (!filter_set_accel_config(dev->pointer.filter, accel_config))
return LIBINPUT_CONFIG_STATUS_INVALID;
return LIBINPUT_CONFIG_STATUS_SUCCESS;
}
void
evdev_device_init_pointer_acceleration(struct evdev_device *device,
struct motion_filter *filter)
{
device->pointer.filter = filter;
if (device->base.config.accel == NULL) {
double default_speed;
device->pointer.config.available = evdev_accel_config_available;
device->pointer.config.set_speed = evdev_accel_config_set_speed;
device->pointer.config.get_speed = evdev_accel_config_get_speed;
device->pointer.config.get_default_speed = evdev_accel_config_get_default_speed;
device->pointer.config.get_profiles = evdev_accel_config_get_profiles;
device->pointer.config.set_profile = evdev_accel_config_set_profile;
device->pointer.config.get_profile = evdev_accel_config_get_profile;
device->pointer.config.get_default_profile = evdev_accel_config_get_default_profile;
device->pointer.config.set_accel_config = evdev_set_accel_config;
device->base.config.accel = &device->pointer.config;
default_speed = evdev_accel_config_get_default_speed(&device->base);
evdev_accel_config_set_speed(&device->base, default_speed);
}
}
static inline bool
evdev_read_wheel_click_prop(struct evdev_device *device,
const char *prop,
double *angle)
{
int val;
*angle = DEFAULT_WHEEL_CLICK_ANGLE;
prop = udev_device_get_property_value(device->udev_device, prop);
if (!prop)
return false;
val = parse_mouse_wheel_click_angle_property(prop);
if (val) {
*angle = val;
return true;
}
evdev_log_error(device,
"mouse wheel click angle is present but invalid, "
"using %d degrees instead\n",
DEFAULT_WHEEL_CLICK_ANGLE);
return false;
}
static inline bool
evdev_read_wheel_click_count_prop(struct evdev_device *device,
const char *prop,
double *angle)
{
int val;
prop = udev_device_get_property_value(device->udev_device, prop);
if (!prop)
return false;
val = parse_mouse_wheel_click_angle_property(prop);
if (val) {
*angle = 360.0/val;
return true;
}
evdev_log_error(device,
"mouse wheel click count is present but invalid, "
"using %d degrees for angle instead instead\n",
DEFAULT_WHEEL_CLICK_ANGLE);
*angle = DEFAULT_WHEEL_CLICK_ANGLE;
return false;
}
static inline struct wheel_angle
evdev_read_wheel_click_props(struct evdev_device *device)
{
struct wheel_angle angles;
const char *wheel_count = "MOUSE_WHEEL_CLICK_COUNT";
const char *wheel_angle = "MOUSE_WHEEL_CLICK_ANGLE";
const char *hwheel_count = "MOUSE_WHEEL_CLICK_COUNT_HORIZONTAL";
const char *hwheel_angle = "MOUSE_WHEEL_CLICK_ANGLE_HORIZONTAL";
/* CLICK_COUNT overrides CLICK_ANGLE */
if (evdev_read_wheel_click_count_prop(device, wheel_count, &angles.y) ||
evdev_read_wheel_click_prop(device, wheel_angle, &angles.y)) {
evdev_log_debug(device,
"wheel: vert click angle: %.2f\n", angles.y);
}
if (evdev_read_wheel_click_count_prop(device, hwheel_count, &angles.x) ||
evdev_read_wheel_click_prop(device, hwheel_angle, &angles.x)) {
evdev_log_debug(device,
"wheel: horizontal click angle: %.2f\n", angles.x);
} else {
angles.x = angles.y;
}
return angles;
}
static inline double
evdev_get_trackpoint_multiplier(struct evdev_device *device)
{
struct quirks_context *quirks;
struct quirks *q;
double multiplier = 1.0;
if (!(device->tags & EVDEV_TAG_TRACKPOINT))
return 1.0;
quirks = evdev_libinput_context(device)->quirks;
q = quirks_fetch_for_device(quirks, device->udev_device);
if (q) {
quirks_get_double(q, QUIRK_ATTR_TRACKPOINT_MULTIPLIER, &multiplier);
quirks_unref(q);
}
if (multiplier <= 0.0) {
evdev_log_bug_libinput(device,
"trackpoint multiplier %.2f is invalid\n",
multiplier);
multiplier = 1.0;
}
if (multiplier != 1.0)
evdev_log_info(device,
"trackpoint multiplier is %.2f\n",
multiplier);
return multiplier;
}
static inline bool
evdev_need_velocity_averaging(struct evdev_device *device)
{
struct quirks_context *quirks;
struct quirks *q;
bool use_velocity_averaging = false; /* default off unless we have quirk */
quirks = evdev_libinput_context(device)->quirks;
q = quirks_fetch_for_device(quirks, device->udev_device);
if (q) {
quirks_get_bool(q,
QUIRK_ATTR_USE_VELOCITY_AVERAGING,
&use_velocity_averaging);
quirks_unref(q);
}
if (use_velocity_averaging)
evdev_log_info(device,
"velocity averaging is turned on\n");
return use_velocity_averaging;
}
static inline int
evdev_read_dpi_prop(struct evdev_device *device)
{
const char *mouse_dpi;
int dpi = DEFAULT_MOUSE_DPI;
if (device->tags & EVDEV_TAG_TRACKPOINT)
return DEFAULT_MOUSE_DPI;
mouse_dpi = udev_device_get_property_value(device->udev_device,
"MOUSE_DPI");
if (mouse_dpi) {
dpi = parse_mouse_dpi_property(mouse_dpi);
if (!dpi) {
evdev_log_error(device,
"mouse DPI property is present but invalid, "
"using %d DPI instead\n",
DEFAULT_MOUSE_DPI);
dpi = DEFAULT_MOUSE_DPI;
}
evdev_log_info(device,
"device set to %d DPI\n",
dpi);
}
return dpi;
}
static inline uint32_t
evdev_read_model_flags(struct evdev_device *device)
{
const struct model_map {
enum quirk quirk;
enum evdev_device_model model;
} model_map[] = {
#define MODEL(name) { QUIRK_MODEL_##name, EVDEV_MODEL_##name }
MODEL(WACOM_TOUCHPAD),
MODEL(SYNAPTICS_SERIAL_TOUCHPAD),
MODEL(ALPS_SERIAL_TOUCHPAD),
MODEL(LENOVO_T450_TOUCHPAD),
MODEL(TRACKBALL),
MODEL(APPLE_TOUCHPAD_ONEBUTTON),
MODEL(LENOVO_SCROLLPOINT),
#undef MODEL
{ 0, 0 },
};
const struct model_map *m = model_map;
uint32_t model_flags = 0;
uint32_t all_model_flags = 0;
struct quirks_context *quirks;
struct quirks *q;
quirks = evdev_libinput_context(device)->quirks;
q = quirks_fetch_for_device(quirks, device->udev_device);
while (q && m->quirk) {
bool is_set;
/* Check for flag re-use */
assert((all_model_flags & m->model) == 0);
all_model_flags |= m->model;
if (quirks_get_bool(q, m->quirk, &is_set)) {
if (is_set) {
evdev_log_debug(device,
"tagged as %s\n",
quirk_get_name(m->quirk));
model_flags |= m->model;
} else {
evdev_log_debug(device,
"untagged as %s\n",
quirk_get_name(m->quirk));
model_flags &= ~m->model;
}
}
m++;
}
quirks_unref(q);
if (parse_udev_flag(device,
device->udev_device,
"ID_INPUT_TRACKBALL")) {
evdev_log_debug(device, "tagged as trackball\n");
model_flags |= EVDEV_MODEL_TRACKBALL;
}
/**
* Device is 6 years old at the time of writing this and this was
* one of the few udev properties that wasn't reserved for private
* usage, so we need to keep this for backwards compat.
*/
if (parse_udev_flag(device,
device->udev_device,
"LIBINPUT_MODEL_LENOVO_X220_TOUCHPAD_FW81")) {
evdev_log_debug(device, "tagged as trackball\n");
model_flags |= EVDEV_MODEL_LENOVO_X220_TOUCHPAD_FW81;
}
if (parse_udev_flag(device, device->udev_device,
"LIBINPUT_TEST_DEVICE")) {
evdev_log_debug(device, "is a test device\n");
model_flags |= EVDEV_MODEL_TEST_DEVICE;
}
return model_flags;
}
static inline bool
evdev_read_attr_res_prop(struct evdev_device *device,
size_t *xres,
size_t *yres)
{
struct quirks_context *quirks;
struct quirks *q;
struct quirk_dimensions dim;
bool rc = false;
quirks = evdev_libinput_context(device)->quirks;
q = quirks_fetch_for_device(quirks, device->udev_device);
if (!q)
return false;
rc = quirks_get_dimensions(q, QUIRK_ATTR_RESOLUTION_HINT, &dim);
if (rc) {
*xres = dim.x;
*yres = dim.y;
}
quirks_unref(q);
return rc;
}
static inline bool
evdev_read_attr_size_prop(struct evdev_device *device,
size_t *size_x,
size_t *size_y)
{
struct quirks_context *quirks;
struct quirks *q;
struct quirk_dimensions dim;
bool rc = false;
quirks = evdev_libinput_context(device)->quirks;
q = quirks_fetch_for_device(quirks, device->udev_device);
if (!q)
return false;
rc = quirks_get_dimensions(q, QUIRK_ATTR_SIZE_HINT, &dim);
if (rc) {
*size_x = dim.x;
*size_y = dim.y;
}
quirks_unref(q);
return rc;
}
/* Return 1 if the device is set to the fake resolution or 0 otherwise */
static inline int
evdev_fix_abs_resolution(struct evdev_device *device,
unsigned int xcode,
unsigned int ycode)
{
struct libevdev *evdev = device->evdev;
const struct input_absinfo *absx, *absy;
size_t widthmm = 0, heightmm = 0;
size_t xres = EVDEV_FAKE_RESOLUTION,
yres = EVDEV_FAKE_RESOLUTION;
if (!(xcode == ABS_X && ycode == ABS_Y) &&
!(xcode == ABS_MT_POSITION_X && ycode == ABS_MT_POSITION_Y)) {
evdev_log_bug_libinput(device,
"invalid x/y code combination %d/%d\n",
xcode,
ycode);
return 0;
}
absx = libevdev_get_abs_info(evdev, xcode);
absy = libevdev_get_abs_info(evdev, ycode);
if (absx->resolution != 0 || absy->resolution != 0)
return 0;
/* Note: we *do not* override resolutions if provided by the kernel.
* If a device needs this, add it to 60-evdev.hwdb. The libinput
* property is only for general size hints where we can make
* educated guesses but don't know better.
*/
if (!evdev_read_attr_res_prop(device, &xres, &yres) &&
evdev_read_attr_size_prop(device, &widthmm, &heightmm)) {
xres = absinfo_range(absx)/widthmm;
yres = absinfo_range(absy)/heightmm;
}
/* libevdev_set_abs_resolution() changes the absinfo we already
have a pointer to, no need to fetch it again */
libevdev_set_abs_resolution(evdev, xcode, xres);
libevdev_set_abs_resolution(evdev, ycode, yres);
return xres == EVDEV_FAKE_RESOLUTION;
}
static enum evdev_device_udev_tags
evdev_device_get_udev_tags(struct evdev_device *device,
struct udev_device *udev_device)
{
enum evdev_device_udev_tags tags = 0;
int i;
for (i = 0; i < 2 && udev_device; i++) {
unsigned j;
for (j = 0; j < ARRAY_LENGTH(evdev_udev_tag_matches); j++) {
const struct evdev_udev_tag_match match = evdev_udev_tag_matches[j];
if (parse_udev_flag(device,
udev_device,
match.name))
tags |= match.tag;
}
udev_device = udev_device_get_parent(udev_device);
}
return tags;
}
static inline void
evdev_fix_android_mt(struct evdev_device *device)
{
struct libevdev *evdev = device->evdev;
if (libevdev_has_event_code(evdev, EV_ABS, ABS_X) ||
libevdev_has_event_code(evdev, EV_ABS, ABS_Y))
return;
if (!libevdev_has_event_code(evdev, EV_ABS, ABS_MT_POSITION_X) ||
!libevdev_has_event_code(evdev, EV_ABS, ABS_MT_POSITION_Y) ||
evdev_is_fake_mt_device(device))
return;
libevdev_enable_event_code(evdev, EV_ABS, ABS_X,
libevdev_get_abs_info(evdev, ABS_MT_POSITION_X));
libevdev_enable_event_code(evdev, EV_ABS, ABS_Y,
libevdev_get_abs_info(evdev, ABS_MT_POSITION_Y));
}
static inline bool
evdev_check_min_max(struct evdev_device *device, unsigned int code)
{
struct libevdev *evdev = device->evdev;
const struct input_absinfo *absinfo;
if (!libevdev_has_event_code(evdev, EV_ABS, code))
return true;
absinfo = libevdev_get_abs_info(evdev, code);
if (absinfo->minimum == absinfo->maximum) {
/* Some devices have a sort-of legitimate min/max of 0 for
* ABS_MISC and above (e.g. Roccat Kone XTD). Don't ignore
* them, simply disable the axes so we won't get events,
* we don't know what to do with them anyway.
*/
if (absinfo->minimum == 0 &&
code >= ABS_MISC && code < ABS_MT_SLOT) {
evdev_log_info(device,
"disabling EV_ABS %#x on device (min == max == 0)\n",
code);
libevdev_disable_event_code(device->evdev,
EV_ABS,
code);
} else {
evdev_log_bug_kernel(device,
"device has min == max on %s\n",
libevdev_event_code_get_name(EV_ABS, code));
return false;
}
}
return true;
}
static bool
evdev_reject_device(struct evdev_device *device)
{
struct libevdev *evdev = device->evdev;
unsigned int code;
const struct input_absinfo *absx, *absy;
if (libevdev_has_event_code(evdev, EV_ABS, ABS_X) ^
libevdev_has_event_code(evdev, EV_ABS, ABS_Y))
return true;
if (libevdev_has_event_code(evdev, EV_REL, REL_X) ^
libevdev_has_event_code(evdev, EV_REL, REL_Y))
return true;
if (!evdev_is_fake_mt_device(device) &&
libevdev_has_event_code(evdev, EV_ABS, ABS_MT_POSITION_X) ^
libevdev_has_event_code(evdev, EV_ABS, ABS_MT_POSITION_Y))
return true;
if (libevdev_has_event_code(evdev, EV_ABS, ABS_X)) {
absx = libevdev_get_abs_info(evdev, ABS_X);
absy = libevdev_get_abs_info(evdev, ABS_Y);
if ((absx->resolution == 0 && absy->resolution != 0) ||
(absx->resolution != 0 && absy->resolution == 0)) {
evdev_log_bug_kernel(device,
"kernel has only x or y resolution, not both.\n");
return true;
}
}
if (!evdev_is_fake_mt_device(device) &&
libevdev_has_event_code(evdev, EV_ABS, ABS_MT_POSITION_X)) {
absx = libevdev_get_abs_info(evdev, ABS_MT_POSITION_X);
absy = libevdev_get_abs_info(evdev, ABS_MT_POSITION_Y);
if ((absx->resolution == 0 && absy->resolution != 0) ||
(absx->resolution != 0 && absy->resolution == 0)) {
evdev_log_bug_kernel(device,
"kernel has only x or y MT resolution, not both.\n");
return true;
}
}
for (code = 0; code < ABS_CNT; code++) {
switch (code) {
case ABS_MISC:
case ABS_MT_SLOT:
case ABS_MT_TOOL_TYPE:
break;
default:
if (!evdev_check_min_max(device, code))
return true;
}
}
return false;
}
static void
evdev_extract_abs_axes(struct evdev_device *device,
enum evdev_device_udev_tags udev_tags)
{
struct libevdev *evdev = device->evdev;
int fuzz;
if (!libevdev_has_event_code(evdev, EV_ABS, ABS_X) ||
!libevdev_has_event_code(evdev, EV_ABS, ABS_Y))
return;
if (evdev_fix_abs_resolution(device, ABS_X, ABS_Y))
device->abs.is_fake_resolution = true;
if (udev_tags & (EVDEV_UDEV_TAG_TOUCHPAD|EVDEV_UDEV_TAG_TOUCHSCREEN)) {
fuzz = evdev_read_fuzz_prop(device, ABS_X);
libevdev_set_abs_fuzz(evdev, ABS_X, fuzz);
fuzz = evdev_read_fuzz_prop(device, ABS_Y);
libevdev_set_abs_fuzz(evdev, ABS_Y, fuzz);
}
device->abs.absinfo_x = libevdev_get_abs_info(evdev, ABS_X);
device->abs.absinfo_y = libevdev_get_abs_info(evdev, ABS_Y);
device->abs.dimensions.x = abs((int)absinfo_range(device->abs.absinfo_x));
device->abs.dimensions.y = abs((int)absinfo_range(device->abs.absinfo_y));
if (evdev_is_fake_mt_device(device) ||
!libevdev_has_event_code(evdev, EV_ABS, ABS_MT_POSITION_X) ||
!libevdev_has_event_code(evdev, EV_ABS, ABS_MT_POSITION_Y))
return;
if (evdev_fix_abs_resolution(device,
ABS_MT_POSITION_X,
ABS_MT_POSITION_Y))
device->abs.is_fake_resolution = true;
if ((fuzz = evdev_read_fuzz_prop(device, ABS_MT_POSITION_X)))
libevdev_set_abs_fuzz(evdev, ABS_MT_POSITION_X, fuzz);
if ((fuzz = evdev_read_fuzz_prop(device, ABS_MT_POSITION_Y)))
libevdev_set_abs_fuzz(evdev, ABS_MT_POSITION_Y, fuzz);
device->abs.absinfo_x = libevdev_get_abs_info(evdev, ABS_MT_POSITION_X);
device->abs.absinfo_y = libevdev_get_abs_info(evdev, ABS_MT_POSITION_Y);
device->abs.dimensions.x = abs((int)absinfo_range(device->abs.absinfo_x));
device->abs.dimensions.y = abs((int)absinfo_range(device->abs.absinfo_y));
device->is_mt = 1;
}
static void
evdev_disable_accelerometer_axes(struct evdev_device *device)
{
struct libevdev *evdev = device->evdev;
libevdev_disable_event_code(evdev, EV_ABS, ABS_X);
libevdev_disable_event_code(evdev, EV_ABS, ABS_Y);
libevdev_disable_event_code(evdev, EV_ABS, ABS_Z);
libevdev_disable_event_code(evdev, EV_ABS, REL_X);
libevdev_disable_event_code(evdev, EV_ABS, REL_Y);
libevdev_disable_event_code(evdev, EV_ABS, REL_Z);
}
static bool
evdev_device_is_joystick_or_gamepad(struct evdev_device *device)
{
enum evdev_device_udev_tags udev_tags;
bool has_joystick_tags;
struct libevdev *evdev = device->evdev;
unsigned int code;
/* The EVDEV_UDEV_TAG_JOYSTICK is set when a joystick or gamepad button
* is found. However, it can not be used to identify joysticks or
* gamepads because there are keyboards that also have it. Even worse,
* many joysticks also map KEY_* and thus are tagged as keyboards.
*
* In order to be able to detect joysticks and gamepads and
* differentiate them from keyboards, apply the following rules:
*
* 1. The device is tagged as joystick but not as tablet
* 2. The device doesn't have 4 well-known keyboard keys
* 3. It has at least 2 joystick buttons
* 4. It doesn't have 10 keyboard keys */
udev_tags = evdev_device_get_udev_tags(device, device->udev_device);
has_joystick_tags = (udev_tags & EVDEV_UDEV_TAG_JOYSTICK) &&
!(udev_tags & EVDEV_UDEV_TAG_TABLET) &&
!(udev_tags & EVDEV_UDEV_TAG_TABLET_PAD);
if (!has_joystick_tags)
return false;
unsigned int num_well_known_keys = 0;
for (size_t i = 0; i < ARRAY_LENGTH(well_known_keyboard_keys); i++) {
code = well_known_keyboard_keys[i];
if (libevdev_has_event_code(evdev, EV_KEY, code))
num_well_known_keys++;
}
if (num_well_known_keys >= 4) /* should not have 4 well-known keys */
return false;
unsigned int num_joystick_btns = 0;
for (code = BTN_JOYSTICK; code < BTN_DIGI; code++) {
if (libevdev_has_event_code(evdev, EV_KEY, code))
num_joystick_btns++;
}
for (code = BTN_TRIGGER_HAPPY; code <= BTN_TRIGGER_HAPPY40; code++) {
if (libevdev_has_event_code(evdev, EV_KEY, code))
num_joystick_btns++;
}
if (num_joystick_btns < 2) /* require at least 2 joystick buttons */
return false;
unsigned int num_keys = 0;
for (code = KEY_ESC; code <= KEY_MICMUTE; code++) {
if (libevdev_has_event_code(evdev, EV_KEY, code) )
num_keys++;
}
for (code = KEY_OK; code <= KEY_LIGHTS_TOGGLE; code++) {
if (libevdev_has_event_code(evdev, EV_KEY, code) )
num_keys++;
}
for (code = KEY_ALS_TOGGLE; code < BTN_TRIGGER_HAPPY; code++) {
if (libevdev_has_event_code(evdev, EV_KEY, code) )
num_keys++;
}
if (num_keys >= 10) /* should not have 10 keyboard keys */
return false;
return true;
}
static struct evdev_dispatch *
evdev_configure_device(struct evdev_device *device)
{
struct libevdev *evdev = device->evdev;
enum evdev_device_udev_tags udev_tags;
unsigned int tablet_tags;
struct evdev_dispatch *dispatch;
udev_tags = evdev_device_get_udev_tags(device, device->udev_device);
if ((udev_tags & EVDEV_UDEV_TAG_INPUT) == 0 ||
(udev_tags & ~EVDEV_UDEV_TAG_INPUT) == 0) {
evdev_log_info(device,
"not tagged as supported input device\n");
return NULL;
}
evdev_log_info(device,
"is tagged by udev as:%s%s%s%s%s%s%s%s%s%s%s\n",
udev_tags & EVDEV_UDEV_TAG_KEYBOARD ? " Keyboard" : "",
udev_tags & EVDEV_UDEV_TAG_MOUSE ? " Mouse" : "",
udev_tags & EVDEV_UDEV_TAG_TOUCHPAD ? " Touchpad" : "",
udev_tags & EVDEV_UDEV_TAG_TOUCHSCREEN ? " Touchscreen" : "",
udev_tags & EVDEV_UDEV_TAG_TABLET ? " Tablet" : "",
udev_tags & EVDEV_UDEV_TAG_POINTINGSTICK ? " Pointingstick" : "",
udev_tags & EVDEV_UDEV_TAG_JOYSTICK ? " Joystick" : "",
udev_tags & EVDEV_UDEV_TAG_ACCELEROMETER ? " Accelerometer" : "",
udev_tags & EVDEV_UDEV_TAG_TABLET_PAD ? " TabletPad" : "",
udev_tags & EVDEV_UDEV_TAG_TRACKBALL ? " Trackball" : "",
udev_tags & EVDEV_UDEV_TAG_SWITCH ? " Switch" : "");
/* Ignore pure accelerometers, but accept devices that are
* accelerometers with other axes */
if (udev_tags == (EVDEV_UDEV_TAG_INPUT|EVDEV_UDEV_TAG_ACCELEROMETER)) {
evdev_log_info(device,
"device is an accelerometer, ignoring\n");
return NULL;
}
if (udev_tags & EVDEV_UDEV_TAG_ACCELEROMETER) {
evdev_disable_accelerometer_axes(device);
}
if (evdev_device_is_joystick_or_gamepad(device)) {
evdev_log_info(device,
"device is a joystick or a gamepad, ignoring\n");
return NULL;
}
if (evdev_reject_device(device)) {
evdev_log_info(device, "was rejected\n");
return NULL;
}
if (!evdev_is_fake_mt_device(device))
evdev_fix_android_mt(device);
if (libevdev_has_event_code(evdev, EV_ABS, ABS_X)) {
evdev_extract_abs_axes(device, udev_tags);
if (evdev_is_fake_mt_device(device))
udev_tags &= ~EVDEV_UDEV_TAG_TOUCHSCREEN;
}
if (evdev_device_has_model_quirk(device,
QUIRK_MODEL_DELL_CANVAS_TOTEM)) {
dispatch = evdev_totem_create(device);
device->seat_caps |= EVDEV_DEVICE_TABLET;
evdev_log_info(device, "device is a totem\n");
return dispatch;
}
/* libwacom assigns touchpad (or touchscreen) _and_ tablet to the
tablet touch bits, so make sure we don't initialize the tablet
interface for the touch device */
tablet_tags = EVDEV_UDEV_TAG_TABLET |
EVDEV_UDEV_TAG_TOUCHPAD |
EVDEV_UDEV_TAG_TOUCHSCREEN;
/* libwacom assigns tablet _and_ tablet_pad to the pad devices */
if (udev_tags & EVDEV_UDEV_TAG_TABLET_PAD) {
dispatch = evdev_tablet_pad_create(device);
device->seat_caps |= EVDEV_DEVICE_TABLET_PAD;
evdev_log_info(device, "device is a tablet pad\n");
return dispatch;
}
if ((udev_tags & tablet_tags) == EVDEV_UDEV_TAG_TABLET) {
dispatch = evdev_tablet_create(device);
device->seat_caps |= EVDEV_DEVICE_TABLET;
evdev_log_info(device, "device is a tablet\n");
return dispatch;
}
if (udev_tags & EVDEV_UDEV_TAG_TOUCHPAD) {
if (udev_tags & EVDEV_UDEV_TAG_TABLET)
evdev_tag_tablet_touchpad(device);
/* whether velocity should be averaged, false by default */
device->use_velocity_averaging = evdev_need_velocity_averaging(device);
dispatch = evdev_mt_touchpad_create(device);
evdev_log_info(device, "device is a touchpad\n");
return dispatch;
}
if (udev_tags & EVDEV_UDEV_TAG_MOUSE ||
udev_tags & EVDEV_UDEV_TAG_POINTINGSTICK) {
evdev_tag_external_mouse(device, device->udev_device);
evdev_tag_trackpoint(device, device->udev_device);
if (device->tags & EVDEV_TAG_TRACKPOINT)
device->trackpoint_multiplier = evdev_get_trackpoint_multiplier(device);
else
device->dpi = evdev_read_dpi_prop(device);
/* whether velocity should be averaged, false by default */
device->use_velocity_averaging = evdev_need_velocity_averaging(device);
device->seat_caps |= EVDEV_DEVICE_POINTER;
evdev_log_info(device, "device is a pointer\n");
/* want left-handed config option */
device->left_handed.want_enabled = true;
/* want natural-scroll config option */
device->scroll.natural_scrolling_enabled = true;
/* want button scrolling config option */
if (libevdev_has_event_code(evdev, EV_REL, REL_X) ||
libevdev_has_event_code(evdev, EV_REL, REL_Y))
device->scroll.want_button = 1;
}
if (udev_tags & EVDEV_UDEV_TAG_KEYBOARD) {
device->seat_caps |= EVDEV_DEVICE_KEYBOARD;
evdev_log_info(device, "device is a keyboard\n");
/* want natural-scroll config option */
if (libevdev_has_event_code(evdev, EV_REL, REL_WHEEL) ||
libevdev_has_event_code(evdev, EV_REL, REL_HWHEEL)) {
device->scroll.natural_scrolling_enabled = true;
device->seat_caps |= EVDEV_DEVICE_POINTER;
}
evdev_tag_keyboard(device, device->udev_device);
}
if (udev_tags & EVDEV_UDEV_TAG_TOUCHSCREEN) {
device->seat_caps |= EVDEV_DEVICE_TOUCH;
evdev_log_info(device, "device is a touch device\n");
}
if (udev_tags & EVDEV_UDEV_TAG_SWITCH) {
if (libevdev_has_event_code(evdev, EV_SW, SW_LID)) {
device->seat_caps |= EVDEV_DEVICE_SWITCH;
device->tags |= EVDEV_TAG_LID_SWITCH;
}
if (libevdev_has_event_code(evdev, EV_SW, SW_TABLET_MODE)) {
if (evdev_device_has_model_quirk(device,
QUIRK_MODEL_TABLET_MODE_SWITCH_UNRELIABLE)) {
evdev_log_info(device,
"device is an unreliable tablet mode switch, filtering events.\n");
libevdev_disable_event_code(device->evdev,
EV_SW,
SW_TABLET_MODE);
} else {
device->tags |= EVDEV_TAG_TABLET_MODE_SWITCH;
device->seat_caps |= EVDEV_DEVICE_SWITCH;
}
}
if (device->seat_caps & EVDEV_DEVICE_SWITCH)
evdev_log_info(device, "device is a switch device\n");
}
if (device->seat_caps & EVDEV_DEVICE_POINTER &&
libevdev_has_event_code(evdev, EV_REL, REL_X) &&
libevdev_has_event_code(evdev, EV_REL, REL_Y) &&
!evdev_init_accel(device, LIBINPUT_CONFIG_ACCEL_PROFILE_ADAPTIVE)) {
evdev_log_error(device,
"failed to initialize pointer acceleration\n");
return NULL;
}
if (evdev_device_has_model_quirk(device, QUIRK_MODEL_INVERT_HORIZONTAL_SCROLLING)) {
device->scroll.invert_horizontal_scrolling = true;
}
return fallback_dispatch_create(&device->base);
}
static void
evdev_notify_added_device(struct evdev_device *device)
{
struct libinput_device *dev;
list_for_each(dev, &device->base.seat->devices_list, link) {
struct evdev_device *d = evdev_device(dev);
if (dev == &device->base)
continue;
/* Notify existing device d about addition of device */
if (d->dispatch->interface->device_added)
d->dispatch->interface->device_added(d, device);
/* Notify new device about existing device d */
if (device->dispatch->interface->device_added)
device->dispatch->interface->device_added(device, d);
/* Notify new device if existing device d is suspended */
if (d->is_suspended &&
device->dispatch->interface->device_suspended)
device->dispatch->interface->device_suspended(device, d);
}
notify_added_device(&device->base);
if (device->dispatch->interface->post_added)
device->dispatch->interface->post_added(device,
device->dispatch);
}
static bool
evdev_device_have_same_syspath(struct udev_device *udev_device, int fd)
{
struct udev *udev = udev_device_get_udev(udev_device);
struct udev_device *udev_device_new = NULL;
struct stat st;
bool rc = false;
if (fstat(fd, &st) < 0)
goto out;
udev_device_new = udev_device_new_from_devnum(udev, 'c', st.st_rdev);
if (!udev_device_new)
goto out;
rc = streq(udev_device_get_syspath(udev_device_new),
udev_device_get_syspath(udev_device));
out:
if (udev_device_new)
udev_device_unref(udev_device_new);
return rc;
}
static bool
evdev_set_device_group(struct evdev_device *device,
struct udev_device *udev_device)
{
struct libinput *libinput = evdev_libinput_context(device);
struct libinput_device_group *group = NULL;
const char *udev_group;
udev_group = udev_device_get_property_value(udev_device,
"LIBINPUT_DEVICE_GROUP");
if (udev_group)
group = libinput_device_group_find_group(libinput, udev_group);
if (!group) {
group = libinput_device_group_create(libinput, udev_group);
if (!group)
return false;
libinput_device_set_device_group(&device->base, group);
libinput_device_group_unref(group);
} else {
libinput_device_set_device_group(&device->base, group);
}
return true;
}
static inline void
evdev_drain_fd(int fd)
{
struct input_event ev[24];
size_t sz = sizeof ev;
while (read(fd, &ev, sz) == (int)sz) {
/* discard all pending events */
}
}
static inline void
evdev_pre_configure_model_quirks(struct evdev_device *device)
{
struct quirks_context *quirks;
struct quirks *q;
const struct quirk_tuples *t;
char *prop;
/* Touchpad claims to have 4 slots but only ever sends 2
* https://bugs.freedesktop.org/show_bug.cgi?id=98100 */
if (evdev_device_has_model_quirk(device, QUIRK_MODEL_HP_ZBOOK_STUDIO_G3))
libevdev_set_abs_maximum(device->evdev, ABS_MT_SLOT, 1);
/* Generally we don't care about MSC_TIMESTAMP and it can cause
* unnecessary wakeups but on some devices we need to watch it for
* pointer jumps */
quirks = evdev_libinput_context(device)->quirks;
q = quirks_fetch_for_device(quirks, device->udev_device);
if (!q ||
!quirks_get_string(q, QUIRK_ATTR_MSC_TIMESTAMP, &prop) ||
!streq(prop, "watch")) {
libevdev_disable_event_code(device->evdev, EV_MSC, MSC_TIMESTAMP);
}
if (quirks_get_tuples(q, QUIRK_ATTR_EVENT_CODE, &t)) {
for (size_t i = 0; i < t->ntuples; i++) {
const struct input_absinfo absinfo = {
.minimum = 0,
.maximum = 1,
};
int type = t->tuples[i].first;
int code = t->tuples[i].second;
bool enable = t->tuples[i].third;
if (code == EVENT_CODE_UNDEFINED) {
if (enable)
libevdev_enable_event_type(device->evdev, type);
else
libevdev_disable_event_type(device->evdev, type);
} else {
if (enable)
libevdev_enable_event_code(device->evdev,
type,
code,
type == EV_ABS ? &absinfo : NULL);
else
libevdev_disable_event_code(device->evdev,
type,
code);
}
evdev_log_debug(device,
"quirks: %s %s %s (%#x %#x)\n",
enable ? "enabling" : "disabling",
libevdev_event_type_get_name(type),
libevdev_event_code_get_name(type, code),
type,
code);
}
}
if (quirks_get_tuples(q, QUIRK_ATTR_INPUT_PROP, &t)) {
for (size_t idx = 0; idx < t->ntuples; idx++) {
unsigned int p = t->tuples[idx].first;
bool enable = t->tuples[idx].second;
if (enable) {
libevdev_enable_property(device->evdev, p);
}
else {
#if HAVE_LIBEVDEV_DISABLE_PROPERTY
libevdev_disable_property(device->evdev, p);
#else
evdev_log_error(device,
"quirks: a quirk for this device requires newer libevdev than installed\n");
#endif
}
evdev_log_debug(device,
"quirks: %s %s (%#x)\n",
enable ? "enabling" : "disabling",
libevdev_property_get_name(p),
p);
}
}
quirks_unref(q);
}
static void
libevdev_log_func(const struct libevdev *evdev,
enum libevdev_log_priority priority,
void *data,
const char *file,
int line,
const char *func,
const char *format,
va_list args)
{
struct libinput *libinput = data;
enum libinput_log_priority pri = LIBINPUT_LOG_PRIORITY_ERROR;
const char prefix[] = "libevdev: ";
char fmt[strlen(format) + strlen(prefix) + 1];
switch (priority) {
case LIBEVDEV_LOG_ERROR:
pri = LIBINPUT_LOG_PRIORITY_ERROR;
break;
case LIBEVDEV_LOG_INFO:
pri = LIBINPUT_LOG_PRIORITY_INFO;
break;
case LIBEVDEV_LOG_DEBUG:
pri = LIBINPUT_LOG_PRIORITY_DEBUG;
break;
}
snprintf(fmt, sizeof(fmt), "%s%s", prefix, format);
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wformat-nonliteral"
log_msg_va(libinput, pri, fmt, args);
#pragma GCC diagnostic pop
}
static bool
udev_device_should_be_ignored(struct udev_device *udev_device)
{
const char *value;
value = udev_device_get_property_value(udev_device,
"LIBINPUT_IGNORE_DEVICE");
return value && !streq(value, "0");
}
struct evdev_device *
evdev_device_create(struct libinput_seat *seat,
struct udev_device *udev_device)
{
struct libinput *libinput = seat->libinput;
struct evdev_device *device = NULL;
int rc;
int fd = -1;
int unhandled_device = 0;
const char *devnode = udev_device_get_devnode(udev_device);
char *sysname = str_sanitize(udev_device_get_sysname(udev_device));
if (!devnode) {
log_info(libinput, "%s: no device node associated\n", sysname);
goto err;
}
if (udev_device_should_be_ignored(udev_device)) {
log_debug(libinput, "%s: device is ignored\n", sysname);
goto err;
}
/* Use non-blocking mode so that we can loop on read on
* evdev_device_data() until all events on the fd are
* read. mtdev_get() also expects this. */
fd = open_restricted(libinput, devnode,
O_RDWR | O_NONBLOCK | O_CLOEXEC);
if (fd < 0) {
log_info(libinput,
"%s: opening input device '%s' failed (%s).\n",
sysname,
devnode,
strerror(-fd));
goto err;
}
if (!evdev_device_have_same_syspath(udev_device, fd))
goto err;
device = zalloc(sizeof *device);
device->sysname = sysname;
sysname = NULL;
libinput_device_init(&device->base, seat);
libinput_seat_ref(seat);
evdev_drain_fd(fd);
rc = libevdev_new_from_fd(fd, &device->evdev);
if (rc != 0)
goto err;
libevdev_set_clock_id(device->evdev, CLOCK_MONOTONIC);
libevdev_set_device_log_function(device->evdev,
libevdev_log_func,
LIBEVDEV_LOG_ERROR,
libinput);
device->seat_caps = 0;
device->is_mt = 0;
device->mtdev = NULL;
device->udev_device = udev_device_ref(udev_device);
device->dispatch = NULL;
device->fd = fd;
device->devname = libevdev_get_name(device->evdev);
/* the log_prefix_name is used as part of a printf format string and
* must not contain % directives, see evdev_log_msg */
device->log_prefix_name = str_sanitize(device->devname);
device->scroll.threshold = 5.0; /* Default may be overridden */
device->scroll.direction_lock_threshold = 5.0; /* Default may be overridden */
device->scroll.direction = 0;
device->scroll.wheel_click_angle =
evdev_read_wheel_click_props(device);
device->model_flags = evdev_read_model_flags(device);
device->dpi = DEFAULT_MOUSE_DPI;
/* at most 5 SYN_DROPPED log-messages per 30s */
ratelimit_init(&device->syn_drop_limit, s2us(30), 5);
/* at most 5 "delayed processing" log messages per hour */
ratelimit_init(&device->delay_warning_limit, s2us(60 * 60), 5);
/* at most 5 log-messages per 5s */
ratelimit_init(&device->nonpointer_rel_limit, s2us(5), 5);
matrix_init_identity(&device->abs.calibration);
matrix_init_identity(&device->abs.usermatrix);
matrix_init_identity(&device->abs.default_calibration);
evdev_pre_configure_model_quirks(device);
device->dispatch = evdev_configure_device(device);
if (device->dispatch == NULL || device->seat_caps == 0)
goto err;
device->source =
libinput_add_fd(libinput, fd, evdev_device_dispatch, device);
if (!device->source)
goto err;
if (!evdev_set_device_group(device, udev_device))
goto err;
list_insert(seat->devices_list.prev, &device->base.link);
evdev_notify_added_device(device);
return device;
err:
if (fd >= 0) {
close_restricted(libinput, fd);
if (device) {
unhandled_device = device->seat_caps == 0;
evdev_device_destroy(device);
}
}
free(sysname);
return unhandled_device ? EVDEV_UNHANDLED_DEVICE : NULL;
}
const char *
evdev_device_get_output(struct evdev_device *device)
{
return device->output_name;
}
const char *
evdev_device_get_sysname(struct evdev_device *device)
{
return device->sysname;
}
const char *
evdev_device_get_name(struct evdev_device *device)
{
return device->devname;
}
unsigned int
evdev_device_get_id_bustype(struct evdev_device *device)
{
return libevdev_get_id_bustype(device->evdev);
}
unsigned int
evdev_device_get_id_product(struct evdev_device *device)
{
return libevdev_get_id_product(device->evdev);
}
unsigned int
evdev_device_get_id_vendor(struct evdev_device *device)
{
return libevdev_get_id_vendor(device->evdev);
}
struct udev_device *
evdev_device_get_udev_device(struct evdev_device *device)
{
return udev_device_ref(device->udev_device);
}
void
evdev_device_set_default_calibration(struct evdev_device *device,
const float calibration[6])
{
matrix_from_farray6(&device->abs.default_calibration, calibration);
evdev_device_calibrate(device, calibration);
}
void
evdev_device_calibrate(struct evdev_device *device,
const float calibration[6])
{
struct matrix scale,
translate,
transform;
double sx, sy;
matrix_from_farray6(&transform, calibration);
device->abs.apply_calibration = !matrix_is_identity(&transform);
/* back up the user matrix so we can return it on request */
matrix_from_farray6(&device->abs.usermatrix, calibration);
if (!device->abs.apply_calibration) {
matrix_init_identity(&device->abs.calibration);
return;
}
sx = absinfo_range(device->abs.absinfo_x);
sy = absinfo_range(device->abs.absinfo_y);
/* The transformation matrix is in the form:
* [ a b c ]
* [ d e f ]
* [ 0 0 1 ]
* Where a, e are the scale components, a, b, d, e are the rotation
* component (combined with scale) and c and f are the translation
* component. The translation component in the input matrix must be
* normalized to multiples of the device width and height,
* respectively. e.g. c == 1 shifts one device-width to the right.
*
* We pre-calculate a single matrix to apply to event coordinates:
* M = Un-Normalize * Calibration * Normalize
*
* Normalize: scales the device coordinates to [0,1]
* Calibration: user-supplied matrix
* Un-Normalize: scales back up to device coordinates
* Matrix maths requires the normalize/un-normalize in reverse
* order.
*/
/* Un-Normalize */
matrix_init_translate(&translate,
device->abs.absinfo_x->minimum,
device->abs.absinfo_y->minimum);
matrix_init_scale(&scale, sx, sy);
matrix_mult(&scale, &translate, &scale);
/* Calibration */
matrix_mult(&transform, &scale, &transform);
/* Normalize */
matrix_init_translate(&translate,
-device->abs.absinfo_x->minimum/sx,
-device->abs.absinfo_y->minimum/sy);
matrix_init_scale(&scale, 1.0/sx, 1.0/sy);
matrix_mult(&scale, &translate, &scale);
/* store final matrix in device */
matrix_mult(&device->abs.calibration, &transform, &scale);
}
void
evdev_read_calibration_prop(struct evdev_device *device)
{
const char *prop;
float calibration[6];
prop = udev_device_get_property_value(device->udev_device,
"LIBINPUT_CALIBRATION_MATRIX");
if (prop == NULL)
return;
if (!device->abs.absinfo_x || !device->abs.absinfo_y)
return;
if (!parse_calibration_property(prop, calibration))
return;
evdev_device_set_default_calibration(device, calibration);
evdev_log_info(device,
"applying calibration: %f %f %f %f %f %f\n",
calibration[0],
calibration[1],
calibration[2],
calibration[3],
calibration[4],
calibration[5]);
}
int
evdev_read_fuzz_prop(struct evdev_device *device, unsigned int code)
{
const char *prop;
char name[32];
int rc;
int fuzz = 0;
const struct input_absinfo *abs;
rc = snprintf(name, sizeof(name), "LIBINPUT_FUZZ_%02x", code);
if (rc == -1)
return 0;
prop = udev_device_get_property_value(device->udev_device, name);
if (prop && (safe_atoi(prop, &fuzz) == false || fuzz < 0)) {
evdev_log_bug_libinput(device,
"invalid LIBINPUT_FUZZ property value: %s\n",
prop);
return 0;
}
/* The udev callout should have set the kernel fuzz to zero.
* If the kernel fuzz is nonzero, something has gone wrong there, so
* let's complain but still use a fuzz of zero for our view of the
* device. Otherwise, the kernel will use the nonzero fuzz, we then
* use the same fuzz on top of the pre-fuzzed data and that leads to
* unresponsive behaviur.
*/
abs = libevdev_get_abs_info(device->evdev, code);
if (!abs || abs->fuzz == 0)
return fuzz;
if (prop) {
evdev_log_bug_libinput(device,
"kernel fuzz of %d even with LIBINPUT_FUZZ_%02x present\n",
abs->fuzz,
code);
} else {
evdev_log_bug_libinput(device,
"kernel fuzz of %d but LIBINPUT_FUZZ_%02x is missing\n",
abs->fuzz,
code);
}
return 0;
}
bool
evdev_device_has_capability(struct evdev_device *device,
enum libinput_device_capability capability)
{
switch (capability) {
case LIBINPUT_DEVICE_CAP_POINTER:
return !!(device->seat_caps & EVDEV_DEVICE_POINTER);
case LIBINPUT_DEVICE_CAP_KEYBOARD:
return !!(device->seat_caps & EVDEV_DEVICE_KEYBOARD);
case LIBINPUT_DEVICE_CAP_TOUCH:
return !!(device->seat_caps & EVDEV_DEVICE_TOUCH);
case LIBINPUT_DEVICE_CAP_GESTURE:
return !!(device->seat_caps & EVDEV_DEVICE_GESTURE);
case LIBINPUT_DEVICE_CAP_TABLET_TOOL:
return !!(device->seat_caps & EVDEV_DEVICE_TABLET);
case LIBINPUT_DEVICE_CAP_TABLET_PAD:
return !!(device->seat_caps & EVDEV_DEVICE_TABLET_PAD);
case LIBINPUT_DEVICE_CAP_SWITCH:
return !!(device->seat_caps & EVDEV_DEVICE_SWITCH);
default:
return false;
}
}
int
evdev_device_get_size(const struct evdev_device *device,
double *width,
double *height)
{
const struct input_absinfo *x, *y;
x = libevdev_get_abs_info(device->evdev, ABS_X);
y = libevdev_get_abs_info(device->evdev, ABS_Y);
if ((x && x->minimum == 0 && x->maximum == 1) ||
(y && y->minimum == 0 && y->maximum == 1))
return -1;
if (!x || !y || device->abs.is_fake_resolution ||
!x->resolution || !y->resolution)
return -1;
*width = absinfo_convert_to_mm(x, x->maximum);
*height = absinfo_convert_to_mm(y, y->maximum);
return 0;
}
int
evdev_device_has_button(struct evdev_device *device, uint32_t code)
{
if (!(device->seat_caps & EVDEV_DEVICE_POINTER))
return -1;
return libevdev_has_event_code(device->evdev, EV_KEY, code);
}
int
evdev_device_has_key(struct evdev_device *device, uint32_t code)
{
if (!(device->seat_caps & EVDEV_DEVICE_KEYBOARD))
return -1;
return libevdev_has_event_code(device->evdev, EV_KEY, code);
}
int
evdev_device_get_touch_count(struct evdev_device *device)
{
int ntouches;
if (!(device->seat_caps & EVDEV_DEVICE_TOUCH))
return -1;
ntouches = libevdev_get_num_slots(device->evdev);
if (ntouches == -1) {
/* mtdev devices have multitouch but we don't know
* how many. Otherwise, any touch device with num_slots of
* -1 is a single-touch device */
if (device->mtdev)
ntouches = 0;
else
ntouches = 1;
}
return ntouches;
}
int
evdev_device_has_switch(struct evdev_device *device,
enum libinput_switch sw)
{
unsigned int code;
if (!(device->seat_caps & EVDEV_DEVICE_SWITCH))
return -1;
switch (sw) {
case LIBINPUT_SWITCH_LID:
code = SW_LID;
break;
case LIBINPUT_SWITCH_TABLET_MODE:
code = SW_TABLET_MODE;
break;
default:
return -1;
}
return libevdev_has_event_code(device->evdev, EV_SW, code);
}
static inline bool
evdev_is_scrolling(const struct evdev_device *device,
enum libinput_pointer_axis axis)
{
assert(axis == LIBINPUT_POINTER_AXIS_SCROLL_HORIZONTAL ||
axis == LIBINPUT_POINTER_AXIS_SCROLL_VERTICAL);
return (device->scroll.direction & bit(axis)) != 0;
}
static inline void
evdev_start_scrolling(struct evdev_device *device,
enum libinput_pointer_axis axis)
{
assert(axis == LIBINPUT_POINTER_AXIS_SCROLL_HORIZONTAL ||
axis == LIBINPUT_POINTER_AXIS_SCROLL_VERTICAL);
device->scroll.direction |= bit(axis);
}
void
evdev_post_scroll(struct evdev_device *device,
uint64_t time,
enum libinput_pointer_axis_source source,
const struct normalized_coords *delta)
{
const struct normalized_coords *trigger;
struct normalized_coords event;
if (!evdev_is_scrolling(device,
LIBINPUT_POINTER_AXIS_SCROLL_VERTICAL))
device->scroll.buildup.y += delta->y;
if (!evdev_is_scrolling(device,
LIBINPUT_POINTER_AXIS_SCROLL_HORIZONTAL))
device->scroll.buildup.x += delta->x;
trigger = &device->scroll.buildup;
/* If we're not scrolling yet, use a distance trigger: moving
past a certain distance starts scrolling */
if (!evdev_is_scrolling(device,
LIBINPUT_POINTER_AXIS_SCROLL_HORIZONTAL) &&
!evdev_is_scrolling(device,
LIBINPUT_POINTER_AXIS_SCROLL_VERTICAL)) {
if (fabs(trigger->y) >= device->scroll.threshold)
evdev_start_scrolling(device,
LIBINPUT_POINTER_AXIS_SCROLL_VERTICAL);
if (fabs(trigger->x) >= device->scroll.threshold)
evdev_start_scrolling(device,
LIBINPUT_POINTER_AXIS_SCROLL_HORIZONTAL);
/* We're already scrolling in one direction. Require some
trigger speed to start scrolling in the other direction */
} else if (!evdev_is_scrolling(device,
LIBINPUT_POINTER_AXIS_SCROLL_VERTICAL)) {
if (fabs(delta->y) >= device->scroll.direction_lock_threshold)
evdev_start_scrolling(device,
LIBINPUT_POINTER_AXIS_SCROLL_VERTICAL);
} else if (!evdev_is_scrolling(device,
LIBINPUT_POINTER_AXIS_SCROLL_HORIZONTAL)) {
if (fabs(delta->x) >= device->scroll.direction_lock_threshold)
evdev_start_scrolling(device,
LIBINPUT_POINTER_AXIS_SCROLL_HORIZONTAL);
}
event = *delta;
/* We use the trigger to enable, but the delta from this event for
* the actual scroll movement. Otherwise we get a jump once
* scrolling engages */
if (!evdev_is_scrolling(device,
LIBINPUT_POINTER_AXIS_SCROLL_VERTICAL))
event.y = 0.0;
if (!evdev_is_scrolling(device,
LIBINPUT_POINTER_AXIS_SCROLL_HORIZONTAL))
event.x = 0.0;
if (!normalized_is_zero(event)) {
uint32_t axes = device->scroll.direction;
if (event.y == 0.0)
axes &= ~bit(LIBINPUT_POINTER_AXIS_SCROLL_VERTICAL);
if (event.x == 0.0)
axes &= ~bit(LIBINPUT_POINTER_AXIS_SCROLL_HORIZONTAL);
switch (source) {
case LIBINPUT_POINTER_AXIS_SOURCE_FINGER:
evdev_notify_axis_finger(device, time, axes, &event);
break;
case LIBINPUT_POINTER_AXIS_SOURCE_CONTINUOUS:
evdev_notify_axis_continous(device, time, axes, &event);
break;
default:
evdev_log_bug_libinput(device,
"Posting invalid scroll source %d\n",
source);
break;
}
}
}
void
evdev_stop_scroll(struct evdev_device *device,
uint64_t time,
enum libinput_pointer_axis_source source)
{
const struct normalized_coords zero = { 0.0, 0.0 };
/* terminate scrolling with a zero scroll event */
if (device->scroll.direction != 0) {
switch (source) {
case LIBINPUT_POINTER_AXIS_SOURCE_FINGER:
pointer_notify_axis_finger(&device->base,
time,
device->scroll.direction,
&zero);
break;
case LIBINPUT_POINTER_AXIS_SOURCE_CONTINUOUS:
pointer_notify_axis_continuous(&device->base,
time,
device->scroll.direction,
&zero);
break;
default:
evdev_log_bug_libinput(device,
"Stopping invalid scroll source %d\n",
source);
break;
}
}
device->scroll.buildup.x = 0;
device->scroll.buildup.y = 0;
device->scroll.direction = 0;
}
void
evdev_notify_suspended_device(struct evdev_device *device)
{
struct libinput_device *it;
if (device->is_suspended)
return;
list_for_each(it, &device->base.seat->devices_list, link) {
struct evdev_device *d = evdev_device(it);
if (it == &device->base)
continue;
if (d->dispatch->interface->device_suspended)
d->dispatch->interface->device_suspended(d, device);
}
device->is_suspended = true;
}
void
evdev_notify_resumed_device(struct evdev_device *device)
{
struct libinput_device *it;
if (!device->is_suspended)
return;
list_for_each(it, &device->base.seat->devices_list, link) {
struct evdev_device *d = evdev_device(it);
if (it == &device->base)
continue;
if (d->dispatch->interface->device_resumed)
d->dispatch->interface->device_resumed(d, device);
}
device->is_suspended = false;
}
void
evdev_device_suspend(struct evdev_device *device)
{
struct libinput *libinput = evdev_libinput_context(device);
evdev_notify_suspended_device(device);
if (device->dispatch->interface->suspend)
device->dispatch->interface->suspend(device->dispatch,
device);
if (device->source) {
libinput_remove_source(libinput, device->source);
device->source = NULL;
}
if (device->mtdev) {
mtdev_close_delete(device->mtdev);
device->mtdev = NULL;
}
if (device->fd != -1) {
close_restricted(libinput, device->fd);
device->fd = -1;
}
}
int
evdev_device_resume(struct evdev_device *device)
{
struct libinput *libinput = evdev_libinput_context(device);
int fd;
const char *devnode;
struct input_event ev;
enum libevdev_read_status status;
if (device->fd != -1)
return 0;
if (device->was_removed)
return -ENODEV;
devnode = udev_device_get_devnode(device->udev_device);
if (!devnode)
return -ENODEV;
fd = open_restricted(libinput, devnode,
O_RDWR | O_NONBLOCK | O_CLOEXEC);
if (fd < 0)
return -errno;
if (!evdev_device_have_same_syspath(device->udev_device, fd)) {
close_restricted(libinput, fd);
return -ENODEV;
}
evdev_drain_fd(fd);
device->fd = fd;
if (evdev_need_mtdev(device)) {
device->mtdev = mtdev_new_open(device->fd);
if (!device->mtdev)
return -ENODEV;
}
libevdev_change_fd(device->evdev, fd);
libevdev_set_clock_id(device->evdev, CLOCK_MONOTONIC);
/* re-sync libevdev's view of the device, but discard the actual
events. Our device is in a neutral state already */
libevdev_next_event(device->evdev,
LIBEVDEV_READ_FLAG_FORCE_SYNC,
&ev);
do {
status = libevdev_next_event(device->evdev,
LIBEVDEV_READ_FLAG_SYNC,
&ev);
} while (status == LIBEVDEV_READ_STATUS_SYNC);
device->source =
libinput_add_fd(libinput, fd, evdev_device_dispatch, device);
if (!device->source) {
mtdev_close_delete(device->mtdev);
return -ENOMEM;
}
evdev_notify_resumed_device(device);
return 0;
}
void
evdev_device_remove(struct evdev_device *device)
{
struct libinput_device *dev;
evdev_log_info(device, "device removed\n");
libinput_timer_cancel(&device->scroll.timer);
libinput_timer_cancel(&device->middlebutton.timer);
list_for_each(dev, &device->base.seat->devices_list, link) {
struct evdev_device *d = evdev_device(dev);
if (dev == &device->base)
continue;
if (d->dispatch->interface->device_removed)
d->dispatch->interface->device_removed(d, device);
}
evdev_device_suspend(device);
if (device->dispatch->interface->remove)
device->dispatch->interface->remove(device->dispatch);
/* A device may be removed while suspended, mark it to
* skip re-opening a different device with the same node */
device->was_removed = true;
list_remove(&device->base.link);
notify_removed_device(&device->base);
libinput_device_unref(&device->base);
}
void
evdev_device_destroy(struct evdev_device *device)
{
struct evdev_dispatch *dispatch;
dispatch = device->dispatch;
if (dispatch)
dispatch->interface->destroy(dispatch);
if (device->base.group)
libinput_device_group_unref(device->base.group);
free(device->log_prefix_name);
free(device->sysname);
free(device->output_name);
filter_destroy(device->pointer.filter);
libinput_timer_destroy(&device->scroll.timer);
libinput_timer_destroy(&device->middlebutton.timer);
libinput_seat_unref(device->base.seat);
libevdev_free(device->evdev);
udev_device_unref(device->udev_device);
free(device);
}
libinput-1.28.1/src/evdev.h000066400000000000000000000723261477265155700155370ustar00rootroot00000000000000/*
* Copyright © 2011, 2012 Intel Corporation
* Copyright © 2013 Jonas Ådahl
* Copyright © 2013-2015 Red Hat, Inc.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice (including the next
* paragraph) shall be included in all copies or substantial portions of the
* Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
*/
#ifndef EVDEV_H
#define EVDEV_H
#include "config.h"
#include
#include
#include "linux/input.h"
#include
#include "libinput-private.h"
#include "timer.h"
#include "filter.h"
#include "quirks.h"
#include "util-input-event.h"
/* The fake resolution value for abs devices without resolution */
#define EVDEV_FAKE_RESOLUTION 1
enum evdev_event_type {
EVDEV_NONE,
EVDEV_ABSOLUTE_TOUCH_DOWN = bit(0),
EVDEV_ABSOLUTE_MOTION = bit(1),
EVDEV_ABSOLUTE_TOUCH_UP = bit(2),
EVDEV_ABSOLUTE_MT = bit(3),
EVDEV_WHEEL = bit(4),
EVDEV_KEY = bit(5),
EVDEV_RELATIVE_MOTION = bit(6),
EVDEV_BUTTON = bit(7),
};
enum evdev_device_seat_capability {
EVDEV_DEVICE_POINTER = bit(0),
EVDEV_DEVICE_KEYBOARD = bit(1),
EVDEV_DEVICE_TOUCH = bit(2),
EVDEV_DEVICE_TABLET = bit(3),
EVDEV_DEVICE_TABLET_PAD = bit(4),
EVDEV_DEVICE_GESTURE = bit(5),
EVDEV_DEVICE_SWITCH = bit(6),
};
enum evdev_device_tags {
EVDEV_TAG_EXTERNAL_MOUSE = bit(0),
EVDEV_TAG_INTERNAL_TOUCHPAD = bit(1),
EVDEV_TAG_EXTERNAL_TOUCHPAD = bit(2),
EVDEV_TAG_TRACKPOINT = bit(3),
EVDEV_TAG_KEYBOARD = bit(4),
EVDEV_TAG_LID_SWITCH = bit(5),
EVDEV_TAG_INTERNAL_KEYBOARD = bit(6),
EVDEV_TAG_EXTERNAL_KEYBOARD = bit(7),
EVDEV_TAG_TABLET_MODE_SWITCH = bit(8),
EVDEV_TAG_TABLET_TOUCHPAD = bit(9),
};
enum evdev_middlebutton_state {
MIDDLEBUTTON_IDLE,
MIDDLEBUTTON_LEFT_DOWN,
MIDDLEBUTTON_RIGHT_DOWN,
MIDDLEBUTTON_MIDDLE,
MIDDLEBUTTON_LEFT_UP_PENDING,
MIDDLEBUTTON_RIGHT_UP_PENDING,
MIDDLEBUTTON_IGNORE_LR,
MIDDLEBUTTON_IGNORE_L,
MIDDLEBUTTON_IGNORE_R,
MIDDLEBUTTON_PASSTHROUGH,
};
enum evdev_middlebutton_event {
MIDDLEBUTTON_EVENT_L_DOWN,
MIDDLEBUTTON_EVENT_R_DOWN,
MIDDLEBUTTON_EVENT_OTHER,
MIDDLEBUTTON_EVENT_L_UP,
MIDDLEBUTTON_EVENT_R_UP,
MIDDLEBUTTON_EVENT_TIMEOUT,
MIDDLEBUTTON_EVENT_ALL_UP,
};
/**
* model flags are used as shortcut for quirks that need to be checked
* multiple times in timing-sensitive paths. For quirks that need to be
* checked only once, use the quirk directly.
*/
enum evdev_device_model {
EVDEV_MODEL_DEFAULT = 0,
EVDEV_MODEL_WACOM_TOUCHPAD = bit(1),
EVDEV_MODEL_SYNAPTICS_SERIAL_TOUCHPAD = bit(2),
EVDEV_MODEL_ALPS_SERIAL_TOUCHPAD = bit(3),
EVDEV_MODEL_LENOVO_T450_TOUCHPAD = bit(4),
EVDEV_MODEL_APPLE_TOUCHPAD_ONEBUTTON = bit(5),
EVDEV_MODEL_LENOVO_SCROLLPOINT = bit(6),
/* udev tags, not true quirks */
EVDEV_MODEL_TEST_DEVICE = bit(20),
EVDEV_MODEL_TRACKBALL = bit(21),
EVDEV_MODEL_LENOVO_X220_TOUCHPAD_FW81 = bit(22),
};
enum evdev_button_scroll_state {
BUTTONSCROLL_IDLE,
BUTTONSCROLL_BUTTON_DOWN, /* button is down */
BUTTONSCROLL_READY, /* ready for scroll events */
BUTTONSCROLL_SCROLLING, /* have sent scroll events */
};
enum evdev_button_scroll_lock_state {
BUTTONSCROLL_LOCK_DISABLED,
BUTTONSCROLL_LOCK_IDLE,
BUTTONSCROLL_LOCK_FIRSTDOWN,
BUTTONSCROLL_LOCK_FIRSTUP,
BUTTONSCROLL_LOCK_SECONDDOWN,
};
enum evdev_debounce_state {
/**
* Initial state, no debounce but monitoring events
*/
DEBOUNCE_INIT,
/**
* Bounce detected, future events need debouncing
*/
DEBOUNCE_NEEDED,
/**
* Debounce is enabled, but no event is currently being filtered
*/
DEBOUNCE_ON,
/**
* Debounce is enabled and we are currently filtering an event
*/
DEBOUNCE_ACTIVE,
};
enum evdev_arbitration_state {
ARBITRATION_NOT_ACTIVE,
ARBITRATION_IGNORE_ALL,
ARBITRATION_IGNORE_RECT,
};
struct evdev_device {
struct libinput_device base;
struct libinput_source *source;
struct evdev_dispatch *dispatch;
struct libevdev *evdev;
struct udev_device *udev_device;
char *output_name;
const char *devname;
char *log_prefix_name;
char *sysname;
bool was_removed;
int fd;
enum evdev_device_seat_capability seat_caps;
enum evdev_device_tags tags;
bool is_mt;
bool is_suspended;
int dpi; /* HW resolution */
double trackpoint_multiplier; /* trackpoint constant multiplier */
bool use_velocity_averaging; /* whether averaging should be applied on velocity calculation */
struct ratelimit syn_drop_limit; /* ratelimit for SYN_DROPPED logging */
struct ratelimit delay_warning_limit; /* ratelimit for delayd processing logging */
struct ratelimit nonpointer_rel_limit; /* ratelimit for REL_* events from non-pointer devices */
uint32_t model_flags;
struct mtdev *mtdev;
struct {
const struct input_absinfo *absinfo_x, *absinfo_y;
bool is_fake_resolution;
int apply_calibration;
struct matrix calibration;
struct matrix default_calibration; /* from LIBINPUT_CALIBRATION_MATRIX */
struct matrix usermatrix; /* as supplied by the caller */
struct device_coords dimensions;
struct {
struct device_coords min, max;
struct ratelimit range_warn_limit;
} warning_range;
} abs;
struct {
struct libinput_timer timer;
struct libinput_device_config_scroll_method config;
/* Currently enabled method, button */
enum libinput_config_scroll_method method;
uint32_t button;
uint64_t button_down_time;
/* set during device init, used at runtime to delay changes
* until all buttons are up */
enum libinput_config_scroll_method want_method;
uint32_t want_button;
/* Checks if buttons are down and commits the setting */
void (*change_scroll_method)(struct evdev_device *device);
enum evdev_button_scroll_state button_scroll_state;
double threshold;
double direction_lock_threshold;
uint32_t direction;
struct normalized_coords buildup;
struct libinput_device_config_natural_scroll config_natural;
/* set during device init if we want natural scrolling,
* used at runtime to enable/disable the feature */
bool natural_scrolling_enabled;
/* set during device init to invert direction of
* horizontal scrolling */
bool invert_horizontal_scrolling;
/* angle per REL_WHEEL click in degrees */
struct wheel_angle wheel_click_angle;
enum evdev_button_scroll_lock_state lock_state;
bool want_lock_enabled;
bool lock_enabled;
} scroll;
struct {
struct libinput_device_config_accel config;
struct motion_filter *filter;
} pointer;
/* Key counter used for multiplexing button events internally in
* libinput. */
uint8_t key_count[KEY_CNT];
struct {
struct libinput_device_config_left_handed config;
/* left-handed currently enabled */
bool enabled;
/* set during device init if we want left_handed config,
* used at runtime to delay the effect until buttons are up */
bool want_enabled;
/* Checks if buttons are down and commits the setting */
void (*change_to_enabled)(struct evdev_device *device);
} left_handed;
struct {
struct libinput_device_config_middle_emulation config;
/* middle-button emulation enabled */
bool enabled;
bool enabled_default;
bool want_enabled;
enum evdev_middlebutton_state state;
struct libinput_timer timer;
uint32_t button_mask;
uint64_t first_event_time;
} middlebutton;
};
static inline struct evdev_device *
evdev_device(struct libinput_device *device)
{
return container_of(device, struct evdev_device, base);
}
#define EVDEV_UNHANDLED_DEVICE ((struct evdev_device *) 1)
struct evdev_dispatch;
struct evdev_dispatch_interface {
/* Process an evdev input event. */
void (*process)(struct evdev_dispatch *dispatch,
struct evdev_device *device,
struct input_event *event,
uint64_t time);
/* Device is being suspended */
void (*suspend)(struct evdev_dispatch *dispatch,
struct evdev_device *device);
/* Device is being removed (may be NULL) */
void (*remove)(struct evdev_dispatch *dispatch);
/* Destroy an event dispatch handler and free all its resources. */
void (*destroy)(struct evdev_dispatch *dispatch);
/* A new device was added */
void (*device_added)(struct evdev_device *device,
struct evdev_device *added_device);
/* A device was removed */
void (*device_removed)(struct evdev_device *device,
struct evdev_device *removed_device);
/* A device was suspended */
void (*device_suspended)(struct evdev_device *device,
struct evdev_device *suspended_device);
/* A device was resumed */
void (*device_resumed)(struct evdev_device *device,
struct evdev_device *resumed_device);
/* Called immediately after the LIBINPUT_EVENT_DEVICE_ADDED event
* was sent */
void (*post_added)(struct evdev_device *device,
struct evdev_dispatch *dispatch);
/* For touch arbitration, called on the device that should
* enable/disable touch capabilities.
*/
void (*touch_arbitration_toggle)(struct evdev_dispatch *dispatch,
struct evdev_device *device,
enum evdev_arbitration_state which,
const struct phys_rect *rect, /* may be NULL */
uint64_t now);
/* Called when touch arbitration is on, updates the area where touch
* arbitration should apply.
*/
void (*touch_arbitration_update_rect)(struct evdev_dispatch *dispatch,
struct evdev_device *device,
const struct phys_rect *rect,
uint64_t now);
/* Return the state of the given switch */
enum libinput_switch_state
(*get_switch_state)(struct evdev_dispatch *dispatch,
enum libinput_switch which);
void (*left_handed_toggle)(struct evdev_dispatch *dispatch,
struct evdev_device *device,
bool left_handed_enabled);
};
enum evdev_dispatch_type {
DISPATCH_FALLBACK,
DISPATCH_TOUCHPAD,
DISPATCH_TABLET,
DISPATCH_TABLET_PAD,
DISPATCH_TOTEM,
};
struct evdev_dispatch {
enum evdev_dispatch_type dispatch_type;
struct evdev_dispatch_interface *interface;
struct {
struct libinput_device_config_send_events config;
enum libinput_config_send_events_mode current_mode;
} sendevents;
};
static inline void
evdev_verify_dispatch_type(struct evdev_dispatch *dispatch,
enum evdev_dispatch_type type)
{
if (dispatch->dispatch_type != type)
abort();
}
struct evdev_device *
evdev_device_create(struct libinput_seat *seat,
struct udev_device *device);
static inline struct libinput *
evdev_libinput_context(const struct evdev_device *device)
{
return device->base.seat->libinput;
}
static inline bool
evdev_device_has_model_quirk(struct evdev_device *device,
enum quirk model_quirk)
{
struct quirks_context *quirks;
struct quirks *q;
bool result = false;
assert(quirk_get_name(model_quirk) != NULL);
quirks = evdev_libinput_context(device)->quirks;
q = quirks_fetch_for_device(quirks, device->udev_device);
quirks_get_bool(q, model_quirk, &result);
quirks_unref(q);
return result;
}
void
evdev_transform_absolute(struct evdev_device *device,
struct device_coords *point);
void
evdev_transform_relative(struct evdev_device *device,
struct device_coords *point);
void
evdev_init_calibration(struct evdev_device *device,
struct libinput_device_config_calibration *calibration);
void
evdev_read_calibration_prop(struct evdev_device *device);
int
evdev_read_fuzz_prop(struct evdev_device *device, unsigned int code);
enum switch_reliability
evdev_read_switch_reliability_prop(struct evdev_device *device);
void
evdev_init_sendevents(struct evdev_device *device,
struct evdev_dispatch *dispatch);
void
evdev_device_init_pointer_acceleration(struct evdev_device *device,
struct motion_filter *filter);
struct evdev_dispatch *
evdev_touchpad_create(struct evdev_device *device);
struct evdev_dispatch *
evdev_mt_touchpad_create(struct evdev_device *device);
struct evdev_dispatch *
evdev_tablet_create(struct evdev_device *device);
struct evdev_dispatch *
evdev_tablet_pad_create(struct evdev_device *device);
struct evdev_dispatch *
evdev_lid_switch_dispatch_create(struct evdev_device *device);
struct evdev_dispatch *
fallback_dispatch_create(struct libinput_device *libinput_device);
struct evdev_dispatch *
evdev_totem_create(struct evdev_device *device);
bool
evdev_is_fake_mt_device(struct evdev_device *device);
int
evdev_need_mtdev(struct evdev_device *device);
void
evdev_device_led_update(struct evdev_device *device, enum libinput_led leds);
int
evdev_device_get_keys(struct evdev_device *device, char *keys, size_t size);
const char *
evdev_device_get_output(struct evdev_device *device);
const char *
evdev_device_get_sysname(struct evdev_device *device);
const char *
evdev_device_get_name(struct evdev_device *device);
unsigned int
evdev_device_get_id_bustype(struct evdev_device *device);
unsigned int
evdev_device_get_id_product(struct evdev_device *device);
unsigned int
evdev_device_get_id_vendor(struct evdev_device *device);
struct udev_device *
evdev_device_get_udev_device(struct evdev_device *device);
void
evdev_device_set_default_calibration(struct evdev_device *device,
const float calibration[6]);
void
evdev_device_calibrate(struct evdev_device *device,
const float calibration[6]);
bool
evdev_device_has_capability(struct evdev_device *device,
enum libinput_device_capability capability);
int
evdev_device_get_size(const struct evdev_device *device,
double *w,
double *h);
int
evdev_device_has_button(struct evdev_device *device, uint32_t code);
int
evdev_device_has_key(struct evdev_device *device, uint32_t code);
int
evdev_device_get_touch_count(struct evdev_device *device);
int
evdev_device_has_switch(struct evdev_device *device,
enum libinput_switch sw);
int
evdev_device_tablet_pad_has_key(struct evdev_device *device,
uint32_t code);
int
evdev_device_tablet_pad_get_num_buttons(struct evdev_device *device);
int
evdev_device_tablet_pad_get_num_dials(struct evdev_device *device);
int
evdev_device_tablet_pad_get_num_rings(struct evdev_device *device);
int
evdev_device_tablet_pad_get_num_strips(struct evdev_device *device);
int
evdev_device_tablet_pad_get_num_mode_groups(struct evdev_device *device);
struct libinput_tablet_pad_mode_group *
evdev_device_tablet_pad_get_mode_group(struct evdev_device *device,
unsigned int index);
enum libinput_switch_state
evdev_device_switch_get_state(struct evdev_device *device,
enum libinput_switch sw);
double
evdev_device_transform_x(struct evdev_device *device,
double x,
uint32_t width);
double
evdev_device_transform_y(struct evdev_device *device,
double y,
uint32_t height);
void
evdev_device_suspend(struct evdev_device *device);
int
evdev_device_resume(struct evdev_device *device);
void
evdev_notify_suspended_device(struct evdev_device *device);
void
evdev_notify_resumed_device(struct evdev_device *device);
void
evdev_pointer_notify_button(struct evdev_device *device,
uint64_t time,
unsigned int button,
enum libinput_button_state state);
void
evdev_pointer_notify_physical_button(struct evdev_device *device,
uint64_t time,
int button,
enum libinput_button_state state);
void
evdev_init_natural_scroll(struct evdev_device *device);
void
evdev_init_button_scroll(struct evdev_device *device,
void (*change_scroll_method)(struct evdev_device *));
void
evdev_set_button_scroll_lock_enabled(struct evdev_device *device,
bool enabled);
int
evdev_update_key_down_count(struct evdev_device *device,
int code,
int pressed);
void
evdev_notify_axis_legacy_wheel(struct evdev_device *device,
uint64_t time,
uint32_t axes,
const struct normalized_coords *delta_in,
const struct discrete_coords *discrete_in);
void
evdev_notify_axis_wheel(struct evdev_device *device,
uint64_t time,
uint32_t axes,
const struct normalized_coords *delta_in,
const struct wheel_v120 *v120_in);
void
evdev_notify_axis_finger(struct evdev_device *device,
uint64_t time,
uint32_t axes,
const struct normalized_coords *delta_in);
void
evdev_notify_axis_continous(struct evdev_device *device,
uint64_t time,
uint32_t axes,
const struct normalized_coords *delta_in);
void
evdev_post_scroll(struct evdev_device *device,
uint64_t time,
enum libinput_pointer_axis_source source,
const struct normalized_coords *delta);
void
evdev_stop_scroll(struct evdev_device *device,
uint64_t time,
enum libinput_pointer_axis_source source);
void
evdev_device_remove(struct evdev_device *device);
void
evdev_device_destroy(struct evdev_device *device);
bool
evdev_middlebutton_filter_button(struct evdev_device *device,
uint64_t time,
int button,
enum libinput_button_state state);
void
evdev_init_middlebutton(struct evdev_device *device,
bool enabled,
bool want_config);
enum libinput_config_middle_emulation_state
evdev_middlebutton_get(struct libinput_device *device);
int
evdev_middlebutton_is_available(struct libinput_device *device);
enum libinput_config_middle_emulation_state
evdev_middlebutton_get_default(struct libinput_device *device);
static inline struct phys_coords
evdev_convert_xy_to_mm(const struct evdev_device *device, int x, int y)
{
struct phys_coords mm;
mm.x = absinfo_convert_to_mm(device->abs.absinfo_x, x);
mm.y = absinfo_convert_to_mm(device->abs.absinfo_y, y);
return mm;
}
void
evdev_init_left_handed(struct evdev_device *device,
void (*change_to_left_handed)(struct evdev_device *));
static inline uint32_t
evdev_to_left_handed(struct evdev_device *device,
uint32_t button)
{
if (device->left_handed.enabled) {
if (button == BTN_LEFT)
return BTN_RIGHT;
else if (button == BTN_RIGHT)
return BTN_LEFT;
}
return button;
}
/**
* Apply a hysteresis filtering to the coordinate in, based on the current
* hysteresis center and the margin. If 'in' is within 'margin' of center,
* return the center (and thus filter the motion). If 'in' is outside,
* return a point on the edge of the new margin (which is an ellipse, usually
* a circle). So for a point x in the space outside c + margin we return r:
* ,---. ,---.
* | c | x → | r x
* `---' `---'
*
* The effect of this is that initial small motions are filtered. Once we
* move into one direction we lag the real coordinates by 'margin' but any
* movement that continues into that direction will always be just outside
* margin - we get responsive movement. Once we move back into the other
* direction, the first movements are filtered again.
*
* Returning the edge rather than the point avoids cursor jumps, as the
* first reachable coordinate is the point next to the center (center + 1).
* Otherwise, the center has a dead zone of size margin around it and the
* first reachable point is the margin edge.
*
* @param in The input coordinate
* @param center Current center of the hysteresis
* @param margin Hysteresis width (on each side)
*
* @return The new center of the hysteresis
*/
static inline struct device_coords
evdev_hysteresis(const struct device_coords *in,
const struct device_coords *center,
const struct device_coords *margin)
{
int dx = in->x - center->x;
int dy = in->y - center->y;
int dx2 = dx * dx;
int dy2 = dy * dy;
int a = margin->x;
int b = margin->y;
double normalized_finger_distance, finger_distance, margin_distance;
double lag_x, lag_y;
struct device_coords result;
if (!a || !b)
return *in;
/*
* Basic equation for an ellipse of radii a,b:
* x²/a² + y²/b² = 1
* But we start by making a scaled ellipse passing through the
* relative finger location (dx,dy). So the scale of this ellipse is
* the ratio of finger_distance to margin_distance:
* dx²/a² + dy²/b² = normalized_finger_distance²
*/
normalized_finger_distance = sqrt((double)dx2 / (a * a) +
(double)dy2 / (b * b));
/* Which means anything less than 1 is within the elliptical margin */
if (normalized_finger_distance < 1.0)
return *center;
finger_distance = sqrt(dx2 + dy2);
margin_distance = finger_distance / normalized_finger_distance;
/*
* Now calculate the x,y coordinates on the edge of the margin ellipse
* where it intersects the finger vector. Shortcut: We achieve this by
* finding the point with the same gradient as dy/dx.
*/
if (dx) {
double gradient = (double)dy / dx;
lag_x = margin_distance / sqrt(gradient * gradient + 1);
lag_y = sqrt((margin_distance + lag_x) *
(margin_distance - lag_x));
} else { /* Infinite gradient */
lag_x = 0.0;
lag_y = margin_distance;
}
/*
* 'result' is the centre of an ellipse (radii a,b) which has been
* dragged by the finger moving inside it to 'in'. The finger is now
* touching the margin ellipse at some point: (±lag_x,±lag_y)
*/
result.x = (dx >= 0) ? in->x - lag_x : in->x + lag_x;
result.y = (dy >= 0) ? in->y - lag_y : in->y + lag_y;
return result;
}
LIBINPUT_ATTRIBUTE_PRINTF(3, 4)
static inline void
evdev_log_msg(struct evdev_device *device,
enum libinput_log_priority priority,
const char *format,
...)
{
va_list args;
char buf[1024];
if (!is_logged(evdev_libinput_context(device), priority))
return;
/* Anything info and above is user-visible, use the device name */
snprintf(buf,
sizeof(buf),
"%-7s - %s%s%s",
evdev_device_get_sysname(device),
(priority > LIBINPUT_LOG_PRIORITY_DEBUG) ? device->log_prefix_name : "",
(priority > LIBINPUT_LOG_PRIORITY_DEBUG) ? ": " : "",
format);
va_start(args, format);
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wformat-nonliteral"
log_msg_va(evdev_libinput_context(device), priority, buf, args);
#pragma GCC diagnostic pop
va_end(args);
}
LIBINPUT_ATTRIBUTE_PRINTF(4, 5)
static inline void
evdev_log_msg_ratelimit(struct evdev_device *device,
struct ratelimit *ratelimit,
enum libinput_log_priority priority,
const char *format,
...)
{
va_list args;
char buf[1024];
enum ratelimit_state state;
if (!is_logged(evdev_libinput_context(device), priority))
return;
state = ratelimit_test(ratelimit);
if (state == RATELIMIT_EXCEEDED)
return;
/* Anything info and above is user-visible, use the device name */
snprintf(buf,
sizeof(buf),
"%-7s - %s%s%s",
evdev_device_get_sysname(device),
(priority > LIBINPUT_LOG_PRIORITY_DEBUG) ? device->log_prefix_name : "",
(priority > LIBINPUT_LOG_PRIORITY_DEBUG) ? ": " : "",
format);
va_start(args, format);
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wformat-nonliteral"
log_msg_va(evdev_libinput_context(device), priority, buf, args);
#pragma GCC diagnostic pop
va_end(args);
if (state == RATELIMIT_THRESHOLD) {
struct human_time ht = to_human_time(ratelimit->interval);
evdev_log_msg(device,
priority,
"WARNING: log rate limit exceeded (%d msgs per %d%s). "
"Discarding future messages.\n",
ratelimit->burst,
ht.value,
ht.unit);
}
}
#define evdev_log_debug(d_, ...) evdev_log_msg((d_), LIBINPUT_LOG_PRIORITY_DEBUG, __VA_ARGS__)
#define evdev_log_info(d_, ...) evdev_log_msg((d_), LIBINPUT_LOG_PRIORITY_INFO, __VA_ARGS__)
#define evdev_log_error(d_, ...) evdev_log_msg((d_), LIBINPUT_LOG_PRIORITY_ERROR, __VA_ARGS__)
#define evdev_log_bug_kernel(d_, ...) evdev_log_msg((d_), LIBINPUT_LOG_PRIORITY_ERROR, "kernel bug: " __VA_ARGS__)
#define evdev_log_bug_libinput(d_, ...) evdev_log_msg((d_), LIBINPUT_LOG_PRIORITY_ERROR, "libinput bug: " __VA_ARGS__)
#define evdev_log_bug_client(d_, ...) evdev_log_msg((d_), LIBINPUT_LOG_PRIORITY_ERROR, "client bug: " __VA_ARGS__)
#define evdev_log_debug_ratelimit(d_, r_, ...) \
evdev_log_msg_ratelimit((d_), (r_), LIBINPUT_LOG_PRIORITY_DEBUG, __VA_ARGS__)
#define evdev_log_info_ratelimit(d_, r_, ...) \
evdev_log_msg_ratelimit((d_), (r_), LIBINPUT_LOG_PRIORITY_INFO, __VA_ARGS__)
#define evdev_log_error_ratelimit(d_, r_, ...) \
evdev_log_msg_ratelimit((d_), (r_), LIBINPUT_LOG_PRIORITY_ERROR, __VA_ARGS__)
#define evdev_log_bug_kernel_ratelimit(d_, r_, ...) \
evdev_log_msg_ratelimit((d_), (r_), LIBINPUT_LOG_PRIORITY_ERROR, "kernel bug: " __VA_ARGS__)
#define evdev_log_bug_libinput_ratelimit(d_, r_, ...) \
evdev_log_msg_ratelimit((d_), (r_), LIBINPUT_LOG_PRIORITY_ERROR, "libinput bug: " __VA_ARGS__)
#define evdev_log_bug_client_ratelimit(d_, r_, ...) \
evdev_log_msg_ratelimit((d_), (r_), LIBINPUT_LOG_PRIORITY_ERROR, "client bug: " __VA_ARGS__)
/**
* Convert the pair of delta coordinates in device space to mm.
*/
static inline struct phys_coords
evdev_device_unit_delta_to_mm(const struct evdev_device* device,
const struct device_coords *units)
{
struct phys_coords mm = { 0, 0 };
const struct input_absinfo *absx, *absy;
if (device->abs.absinfo_x == NULL ||
device->abs.absinfo_y == NULL) {
log_bug_libinput(evdev_libinput_context(device),
"%s: is not an abs device\n",
device->devname);
return mm;
}
absx = device->abs.absinfo_x;
absy = device->abs.absinfo_y;
mm.x = 1.0 * units->x/absx->resolution;
mm.y = 1.0 * units->y/absy->resolution;
return mm;
}
/**
* Convert the pair of coordinates in device space to mm. This takes the
* axis min into account, i.e. a unit of min is equivalent to 0 mm.
*/
static inline struct phys_coords
evdev_device_units_to_mm(const struct evdev_device* device,
const struct device_coords *units)
{
struct phys_coords mm = { 0, 0 };
const struct input_absinfo *absx, *absy;
if (device->abs.absinfo_x == NULL ||
device->abs.absinfo_y == NULL) {
log_bug_libinput(evdev_libinput_context(device),
"%s: is not an abs device\n",
device->devname);
return mm;
}
absx = device->abs.absinfo_x;
absy = device->abs.absinfo_y;
mm.x = (units->x - absx->minimum)/absx->resolution;
mm.y = (units->y - absy->minimum)/absy->resolution;
return mm;
}
/**
* Convert the pair of coordinates in mm to device units. This takes the
* axis min into account, i.e. 0 mm is equivalent to the min.
*/
static inline struct device_coords
evdev_device_mm_to_units(const struct evdev_device *device,
const struct phys_coords *mm)
{
struct device_coords units = { 0, 0 };
const struct input_absinfo *absx, *absy;
if (device->abs.absinfo_x == NULL ||
device->abs.absinfo_y == NULL) {
log_bug_libinput(evdev_libinput_context(device),
"%s: is not an abs device\n",
device->devname);
return units;
}
absx = device->abs.absinfo_x;
absy = device->abs.absinfo_y;
units.x = mm->x * absx->resolution + absx->minimum;
units.y = mm->y * absy->resolution + absy->minimum;
return units;
}
static inline struct device_coord_rect
evdev_phys_rect_to_units(const struct evdev_device *device,
const struct phys_rect *mm)
{
struct device_coord_rect units = {0};
const struct input_absinfo *absx, *absy;
if (device->abs.absinfo_x == NULL ||
device->abs.absinfo_y == NULL) {
log_bug_libinput(evdev_libinput_context(device),
"%s: is not an abs device\n",
device->devname);
return units;
}
absx = device->abs.absinfo_x;
absy = device->abs.absinfo_y;
units.x = mm->x * absx->resolution + absx->minimum;
units.y = mm->y * absy->resolution + absy->minimum;
units.w = mm->w * absx->resolution;
units.h = mm->h * absy->resolution;
return units;
}
static inline void
evdev_device_init_abs_range_warnings(struct evdev_device *device)
{
const struct input_absinfo *x, *y;
int width, height;
x = device->abs.absinfo_x;
y = device->abs.absinfo_y;
width = device->abs.dimensions.x;
height = device->abs.dimensions.y;
device->abs.warning_range.min.x = x->minimum - 0.05 * width;
device->abs.warning_range.min.y = y->minimum - 0.05 * height;
device->abs.warning_range.max.x = x->maximum + 0.05 * width;
device->abs.warning_range.max.y = y->maximum + 0.05 * height;
/* One warning every 5 min is enough */
ratelimit_init(&device->abs.warning_range.range_warn_limit,
s2us(3000),
1);
}
static inline void
evdev_device_check_abs_axis_range(struct evdev_device *device,
unsigned int code,
int value)
{
int min, max;
switch(code) {
case ABS_X:
case ABS_MT_POSITION_X:
min = device->abs.warning_range.min.x;
max = device->abs.warning_range.max.x;
break;
case ABS_Y:
case ABS_MT_POSITION_Y:
min = device->abs.warning_range.min.y;
max = device->abs.warning_range.max.y;
break;
default:
return;
}
if (value < min || value > max) {
log_info_ratelimit(evdev_libinput_context(device),
&device->abs.warning_range.range_warn_limit,
"Axis %#x value %d is outside expected range [%d, %d]\n"
"See %s/absolute_coordinate_ranges.html for details\n",
code, value, min, max,
HTTP_DOC_LINK);
}
}
struct evdev_paired_keyboard {
struct list link;
struct evdev_device *device;
struct libinput_event_listener listener;
};
static inline void
evdev_paired_keyboard_destroy(struct evdev_paired_keyboard *kbd)
{
kbd->device = NULL;
libinput_device_remove_event_listener(&kbd->listener);
list_remove(&kbd->link);
free(kbd);
}
#endif /* EVDEV_H */
libinput-1.28.1/src/filter-custom.c000066400000000000000000000314051477265155700172070ustar00rootroot00000000000000/*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice (including the next
* paragraph) shall be included in all copies or substantial portions of the
* Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
*/
#include "config.h"
#include
#include
#include
#include
#include "filter.h"
#include "filter-private.h"
#define MOTION_TIMEOUT ms2us(1000)
#define FIRST_MOTION_TIME_INTERVAL ms2us(7) /* random but good enough interval for very first event */
struct custom_accel_function {
uint64_t last_time;
double step;
size_t npoints;
double points[];
};
static struct custom_accel_function *
create_custom_accel_function(double step, const double *points, size_t npoints)
{
if (npoints < LIBINPUT_ACCEL_NPOINTS_MIN ||
npoints > LIBINPUT_ACCEL_NPOINTS_MAX)
return NULL;
if (step <= 0 || step > LIBINPUT_ACCEL_STEP_MAX)
return NULL;
for (size_t idx = 0; idx < npoints; idx++) {
if (points[idx] < LIBINPUT_ACCEL_POINT_MIN_VALUE ||
points[idx] > LIBINPUT_ACCEL_POINT_MAX_VALUE)
return NULL;
}
struct custom_accel_function *cf = zalloc(sizeof(*cf) + npoints * sizeof(*points));
cf->last_time = 0;
cf->step = step;
cf->npoints = npoints;
memcpy(cf->points, points, sizeof(*points) * npoints);
return cf;
}
static void
custom_accel_function_destroy(struct custom_accel_function *cf)
{
if (cf == NULL)
return;
free(cf);
}
static double
custom_accel_function_calculate_speed(struct custom_accel_function *cf,
const struct device_float_coords *unaccelerated,
uint64_t time)
{
/* Although most devices have a constant polling rate, and for fast
* movements these distances do represent the actual speed,
* for slow movements it is not the case.
*
* Since all devices have a finite resolution, real world events
* for a slow smooth movement could look like:
* Event 1 - (0, 1) - time 0
* Event 2 - (0, 0) - time 7 - filtered (zero event)
* Event 3 - (1, 0) - time 14
* Event 4 - (0, 0) - time 21 - filtered (zero event)
* Event 5 - (0, 0) - time 28 - filtered (zero event)
* Event 6 - (0, 1) - time 35
*
* Not taking the time into account would mean interpreting those events as:
* Move 1 unit over 7 ms
* Pause for 7 ms
* Move 1 unit over 7 ms
* Pause for 14 ms
* Move 1 unit over 7ms
*
* Where in reality this was one smooth movement without pauses,
* so after normalizing for time we get:
* Move 1 unit over 7 ms
* Move 1 unit over 14 ms
* Move 1 unit over 21ms
*
* which should give us better speed estimation.
*/
/* calculate speed based on time passed since last event */
double distance = hypot(unaccelerated->x, unaccelerated->y);
/* handle first event in a motion */
if (time - cf->last_time > MOTION_TIMEOUT)
cf->last_time = time - FIRST_MOTION_TIME_INTERVAL;
double dt = us2ms_f(time - cf->last_time);
double speed = distance / dt; /* speed is in device-units per ms */
cf->last_time = time;
return speed;
}
static double
custom_accel_function_profile(struct custom_accel_function *cf,
double speed_in)
{
size_t npoints = cf->npoints;
double step = cf->step;
double *points = cf->points;
/* calculate the index of the first point used for interpolation */
size_t i = speed_in / step;
/* if speed is greater than custom curve's max speed,
use last 2 points for linear extrapolation
(same calculation as linear interpolation) */
i = min(i, npoints - 2);
/* the 2 points used for linear interpolation */
double x0 = step * i;
double x1 = step * (i + 1);
double y0 = points[i];
double y1 = points[i + 1];
/* linear interpolation */
double speed_out = (y0 * (x1 - speed_in) + y1 * (speed_in - x0)) / step;
/* We moved (dx, dy) device units within the last N ms. This gives us a
* given speed S in units/ms, that's our accel input. Our curve says map
* that speed S to some other speed S'.
*
* Our device delta is represented by the vector, that vector needs to
* be modified to represent our intended speed.
*
* Example: we moved a delta of 7 over the last 7ms. Our speed is
* thus 1 u/ms, our out speed is 2 u/ms because we want to double our
* speed (points: [0.0, 2.0]). Our delta must thus be 14 - factor of 2,
* or out-speed/in-speed.
*
* Example: we moved a delta of 1 over the last 7ms. Our input speed is
* 1/7 u/ms, our out speed is 1/7ms because we set up a flat accel
* curve (points: [0.0, 1.0]). Our delta must thus be 1 - factor of 1,
* or out-speed/in-speed.
*
* Example: we moved a delta of 1 over the last 21ms. Our input speed is
* 1/21 u/ms, our out speed is 1u/ms because we set up a fixed-speed
* curve (points: [1.0, 1.0]). Our delta must thus be 21 - factor of 21,
* or out-speed/in-speed.
*
* Example: we moved a delta of 21 over the last 7ms. Our input speed is
* 3 u/ms, our out speed is 1u/ms because we set up a fixed-speed
* curve (points: [1.0, 1.0]). Our delta must thus be 7 - factor of 1/3,
* or out-speed/in-speed.
*/
/* calculate the acceleration factor based on the user desired speed out */
double accel_factor = speed_out / speed_in;
return accel_factor;
}
static struct normalized_coords
custom_accel_function_filter(struct custom_accel_function *cf,
const struct device_float_coords *unaccelerated,
uint64_t time)
{
double speed = custom_accel_function_calculate_speed(cf, unaccelerated, time);
double accel_factor = custom_accel_function_profile(cf, speed);
struct normalized_coords accelerated = {
.x = unaccelerated->x * accel_factor,
.y = unaccelerated->y * accel_factor,
};
return accelerated;
}
struct custom_accelerator {
struct motion_filter base;
struct {
struct custom_accel_function *fallback;
struct custom_accel_function *motion;
struct custom_accel_function *scroll;
} funcs;
};
static struct custom_accel_function *
custom_accelerator_get_custom_function(struct custom_accelerator *f,
enum libinput_config_accel_type accel_type)
{
switch (accel_type) {
case LIBINPUT_ACCEL_TYPE_FALLBACK:
return f->funcs.fallback;
case LIBINPUT_ACCEL_TYPE_MOTION:
return f->funcs.motion ? f->funcs.motion : f->funcs.fallback;
case LIBINPUT_ACCEL_TYPE_SCROLL:
return f->funcs.scroll ? f->funcs.scroll : f->funcs.fallback;
}
return f->funcs.fallback;
}
static double
custom_accelerator_profile(enum libinput_config_accel_type accel_type,
struct motion_filter *filter,
double speed_in)
{
struct custom_accelerator *f = (struct custom_accelerator *)filter;
struct custom_accel_function *cf;
cf = custom_accelerator_get_custom_function(f, accel_type);
return custom_accel_function_profile(cf, speed_in);
}
static struct normalized_coords
custom_accelerator_filter(enum libinput_config_accel_type accel_type,
struct motion_filter *filter,
const struct device_float_coords *unaccelerated,
uint64_t time)
{
struct custom_accelerator *f = (struct custom_accelerator *)filter;
struct custom_accel_function *cf;
cf = custom_accelerator_get_custom_function(f, accel_type);
return custom_accel_function_filter(cf, unaccelerated, time);
}
static void
custom_accelerator_restart(struct motion_filter *filter,
void *data,
uint64_t time)
{
/* noop, this function has no effect in the custom interface */
}
static void
custom_accelerator_destroy(struct motion_filter *filter)
{
struct custom_accelerator *f =
(struct custom_accelerator *)filter;
/* destroy all custom movement functions */
custom_accel_function_destroy(f->funcs.fallback);
custom_accel_function_destroy(f->funcs.motion);
custom_accel_function_destroy(f->funcs.scroll);
free(f);
}
static bool
custom_accelerator_set_speed(struct motion_filter *filter,
double speed_adjustment)
{
assert(speed_adjustment >= -1.0 && speed_adjustment <= 1.0);
/* noop, this function has no effect in the custom interface */
return true;
}
static bool
custom_accelerator_set_accel_config(struct motion_filter *filter,
struct libinput_config_accel *config)
{
struct custom_accelerator *f =
(struct custom_accelerator *)filter;
struct custom_accel_function *fallback = NULL,
*motion = NULL,
*scroll = NULL;
if (config->custom.fallback) {
fallback = create_custom_accel_function(config->custom.fallback->step,
config->custom.fallback->points,
config->custom.fallback->npoints);
if (!fallback)
goto out;
}
if (config->custom.motion) {
motion = create_custom_accel_function(config->custom.motion->step,
config->custom.motion->points,
config->custom.motion->npoints);
if (!motion)
goto out;
}
if (config->custom.scroll) {
scroll = create_custom_accel_function(config->custom.scroll->step,
config->custom.scroll->points,
config->custom.scroll->npoints);
if (!scroll)
goto out;
}
custom_accel_function_destroy(f->funcs.fallback);
custom_accel_function_destroy(f->funcs.motion);
custom_accel_function_destroy(f->funcs.scroll);
f->funcs.fallback = fallback;
f->funcs.motion = motion;
f->funcs.scroll = scroll;
return true;
out:
custom_accel_function_destroy(fallback);
custom_accel_function_destroy(motion);
custom_accel_function_destroy(scroll);
return false;
}
/* custom profiles and filters for the different accel types: */
double
custom_accel_profile_fallback(struct motion_filter *filter,
void *data,
double speed_in,
uint64_t time)
{
return custom_accelerator_profile(LIBINPUT_ACCEL_TYPE_FALLBACK,
filter,
speed_in);
}
static struct normalized_coords
custom_accelerator_filter_fallback(struct motion_filter *filter,
const struct device_float_coords *unaccelerated,
void *data,
uint64_t time)
{
return custom_accelerator_filter(LIBINPUT_ACCEL_TYPE_FALLBACK,
filter,
unaccelerated,
time);
}
double
custom_accel_profile_motion(struct motion_filter *filter,
void *data,
double speed_in,
uint64_t time)
{
return custom_accelerator_profile(LIBINPUT_ACCEL_TYPE_MOTION,
filter,
speed_in);
}
static struct normalized_coords
custom_accelerator_filter_motion(struct motion_filter *filter,
const struct device_float_coords *unaccelerated,
void *data,
uint64_t time)
{
return custom_accelerator_filter(LIBINPUT_ACCEL_TYPE_MOTION,
filter,
unaccelerated,
time);
}
double
custom_accel_profile_scroll(struct motion_filter *filter,
void *data,
double speed_in,
uint64_t time)
{
return custom_accelerator_profile(LIBINPUT_ACCEL_TYPE_SCROLL,
filter,
speed_in);
}
static struct normalized_coords
custom_accelerator_filter_scroll(struct motion_filter *filter,
const struct device_float_coords *unaccelerated,
void *data,
uint64_t time)
{
return custom_accelerator_filter(LIBINPUT_ACCEL_TYPE_SCROLL,
filter,
unaccelerated,
time);
}
static struct motion_filter_interface custom_accelerator_interface = {
.type = LIBINPUT_CONFIG_ACCEL_PROFILE_CUSTOM,
.filter = custom_accelerator_filter_motion,
.filter_constant = custom_accelerator_filter_fallback,
.filter_scroll = custom_accelerator_filter_scroll,
.restart = custom_accelerator_restart,
.destroy = custom_accelerator_destroy,
.set_speed = custom_accelerator_set_speed,
.set_accel_config = custom_accelerator_set_accel_config,
};
struct motion_filter *
create_custom_accelerator_filter(void)
{
struct custom_accelerator *f = zalloc(sizeof(*f));
/* the unit function by default, speed in = speed out,
i.e. no acceleration */
const double default_step = 1.0;
const double default_points[2] = {0.0, 1.0};
/* initialize default acceleration, used as fallback */
f->funcs.fallback = create_custom_accel_function(default_step,
default_points,
ARRAY_LENGTH(default_points));
/* Don't initialize other acceleration functions. Those will be
initialized if the user sets their points, otherwise the fallback
acceleration function is used */
f->base.interface = &custom_accelerator_interface;
return &f->base;
}
libinput-1.28.1/src/filter-flat.c000066400000000000000000000101401477265155700166140ustar00rootroot00000000000000/*
* Copyright © 2006-2009 Simon Thum
* Copyright © 2012 Jonas Ådahl
* Copyright © 2014-2015 Red Hat, Inc.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice (including the next
* paragraph) shall be included in all copies or substantial portions of the
* Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
*/
#include "config.h"
#include
#include
#include
#include
#include "filter.h"
#include "libinput-util.h"
#include "filter-private.h"
struct pointer_accelerator_flat {
struct motion_filter base;
double factor;
int dpi;
};
static struct normalized_coords
accelerator_filter_flat(struct motion_filter *filter,
const struct device_float_coords *unaccelerated,
void *data, uint64_t time)
{
struct pointer_accelerator_flat *accel_filter =
(struct pointer_accelerator_flat *)filter;
double factor; /* unitless factor */
struct normalized_coords accelerated;
/* You want flat acceleration, you get flat acceleration for the
* device */
factor = accel_filter->factor;
accelerated.x = factor * unaccelerated->x;
accelerated.y = factor * unaccelerated->y;
return accelerated;
}
static struct normalized_coords
accelerator_filter_noop_flat(struct motion_filter *filter,
const struct device_float_coords *unaccelerated,
void *data, uint64_t time)
{
/* We map the unaccelerated flat filter to have the same behavior as
* the "accelerated" flat filter.
* The filter by definition is flat, i.e. it does not actually
* apply any acceleration (merely a constant factor) and we can assume
* that a user wants all mouse movement to have the same speed, mapped
* 1:1 to the input speed.
*
* Thus we apply the same factor to our non-accelerated motion - this way
* things like button scrolling end up having the same movement as
* pointer motion.
*/
return accelerator_filter_flat(filter, unaccelerated, data, time);
}
static bool
accelerator_set_speed_flat(struct motion_filter *filter,
double speed_adjustment)
{
struct pointer_accelerator_flat *accel_filter =
(struct pointer_accelerator_flat *)filter;
assert(speed_adjustment >= -1.0 && speed_adjustment <= 1.0);
/* Speed range is 0-200% of the nominal speed, with 0 mapping to the
* nominal speed. Anything above 200 is pointless, we're already
* skipping over ever second pixel at 200% speed.
*/
accel_filter->factor = max(0.005, 1 + speed_adjustment);
filter->speed_adjustment = speed_adjustment;
return true;
}
static void
accelerator_destroy_flat(struct motion_filter *filter)
{
struct pointer_accelerator_flat *accel =
(struct pointer_accelerator_flat *) filter;
free(accel);
}
static const struct motion_filter_interface accelerator_interface_flat = {
.type = LIBINPUT_CONFIG_ACCEL_PROFILE_FLAT,
.filter = accelerator_filter_flat,
.filter_constant = accelerator_filter_noop_flat,
.filter_scroll = accelerator_filter_noop_flat,
.restart = NULL,
.destroy = accelerator_destroy_flat,
.set_speed = accelerator_set_speed_flat,
};
struct motion_filter *
create_pointer_accelerator_filter_flat(int dpi)
{
struct pointer_accelerator_flat *filter;
filter = zalloc(sizeof *filter);
filter->base.interface = &accelerator_interface_flat;
filter->dpi = dpi;
return &filter->base;
}
libinput-1.28.1/src/filter-low-dpi.c000066400000000000000000000166311477265155700172540ustar00rootroot00000000000000/*
* Copyright © 2006-2009 Simon Thum
* Copyright © 2012 Jonas Ådahl
* Copyright © 2014-2015 Red Hat, Inc.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice (including the next
* paragraph) shall be included in all copies or substantial portions of the
* Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
*/
#include "config.h"
#include
#include
#include
#include
#include "filter.h"
#include "libinput-util.h"
#include "filter-private.h"
/*
* Default parameters for pointer acceleration profiles.
*/
#define DEFAULT_THRESHOLD v_ms2us(0.4) /* in units/us */
#define MINIMUM_THRESHOLD v_ms2us(0.2) /* in units/us */
#define DEFAULT_ACCELERATION 2.0 /* unitless factor */
#define DEFAULT_INCLINE 1.1 /* unitless factor */
struct pointer_accelerator_low_dpi {
struct motion_filter base;
accel_profile_func_t profile;
double velocity; /* units/us */
double last_velocity; /* units/us */
struct pointer_trackers trackers;
double threshold; /* units/us */
double accel; /* unitless factor */
double incline; /* incline of the function */
int dpi;
};
/**
* Custom acceleration function for mice < 1000dpi.
* At slow motion, a single device unit causes a one-pixel movement.
* The threshold/max accel depends on the DPI, the smaller the DPI the
* earlier we accelerate and the higher the maximum acceleration is. Result:
* at low speeds we get pixel-precision, at high speeds we get approx. the
* same movement as a high-dpi mouse.
*
* Note: data fed to this function is in device units, not normalized.
*/
double
pointer_accel_profile_linear_low_dpi(struct motion_filter *filter,
void *data,
double speed_in, /* in device units (units/us) */
uint64_t time)
{
struct pointer_accelerator_low_dpi *accel_filter =
(struct pointer_accelerator_low_dpi *)filter;
double max_accel = accel_filter->accel; /* unitless factor */
double threshold = accel_filter->threshold; /* units/us */
const double incline = accel_filter->incline;
double dpi_factor = accel_filter->dpi/(double)DEFAULT_MOUSE_DPI;
double factor; /* unitless */
/* dpi_factor is always < 1.0, increase max_accel, reduce
the threshold so it kicks in earlier */
max_accel /= dpi_factor;
threshold *= dpi_factor;
/* see pointer_accel_profile_linear for a long description */
if (v_us2ms(speed_in) < 0.07)
factor = 10 * v_us2ms(speed_in) + 0.3;
else if (speed_in < threshold)
factor = 1;
else
factor = incline * v_us2ms(speed_in - threshold) + 1;
factor = min(max_accel, factor);
return factor;
}
static inline double
calculate_acceleration_factor(struct pointer_accelerator_low_dpi *accel,
const struct device_float_coords *unaccelerated,
void *data,
uint64_t time)
{
double velocity; /* units/us in device-native dpi*/
double accel_factor;
trackers_feed(&accel->trackers, unaccelerated, time);
velocity = trackers_velocity(&accel->trackers, time);
accel_factor = calculate_acceleration_simpsons(&accel->base,
accel->profile,
data,
velocity,
accel->last_velocity,
time);
accel->last_velocity = velocity;
return accel_factor;
}
static struct normalized_coords
accelerator_filter_low_dpi(struct motion_filter *filter,
const struct device_float_coords *unaccelerated,
void *data, uint64_t time)
{
struct pointer_accelerator_low_dpi *accel =
(struct pointer_accelerator_low_dpi *) filter;
/* Accelerate for device units and return device units */
double accel_factor = calculate_acceleration_factor(accel,
unaccelerated,
data,
time);
const struct normalized_coords normalized = {
.x = accel_factor * unaccelerated->x,
.y = accel_factor * unaccelerated->y,
};
return normalized;
}
static struct normalized_coords
accelerator_filter_noop(struct motion_filter *filter,
const struct device_float_coords *unaccelerated,
void *data, uint64_t time)
{
const struct normalized_coords normalized = {
.x = unaccelerated->x,
.y = unaccelerated->y,
};
return normalized;
}
static void
accelerator_restart(struct motion_filter *filter,
void *data,
uint64_t time)
{
struct pointer_accelerator_low_dpi *accel =
(struct pointer_accelerator_low_dpi *) filter;
trackers_reset(&accel->trackers, time);
}
static void
accelerator_destroy(struct motion_filter *filter)
{
struct pointer_accelerator_low_dpi *accel =
(struct pointer_accelerator_low_dpi *) filter;
trackers_free(&accel->trackers);
free(accel);
}
static bool
accelerator_set_speed(struct motion_filter *filter,
double speed_adjustment)
{
struct pointer_accelerator_low_dpi *accel_filter =
(struct pointer_accelerator_low_dpi *)filter;
assert(speed_adjustment >= -1.0 && speed_adjustment <= 1.0);
/* Note: the numbers below are nothing but trial-and-error magic,
don't read more into them other than "they mostly worked ok" */
/* delay when accel kicks in */
accel_filter->threshold = DEFAULT_THRESHOLD -
v_ms2us(0.25) * speed_adjustment;
if (accel_filter->threshold < MINIMUM_THRESHOLD)
accel_filter->threshold = MINIMUM_THRESHOLD;
/* adjust max accel factor */
accel_filter->accel = DEFAULT_ACCELERATION + speed_adjustment * 1.5;
/* higher speed -> faster to reach max */
accel_filter->incline = DEFAULT_INCLINE + speed_adjustment * 0.75;
filter->speed_adjustment = speed_adjustment;
return true;
}
static const struct motion_filter_interface accelerator_interface_low_dpi = {
.type = LIBINPUT_CONFIG_ACCEL_PROFILE_ADAPTIVE,
.filter = accelerator_filter_low_dpi,
.filter_constant = accelerator_filter_noop,
.filter_scroll = accelerator_filter_noop,
.restart = accelerator_restart,
.destroy = accelerator_destroy,
.set_speed = accelerator_set_speed,
};
static struct pointer_accelerator_low_dpi *
create_default_filter(int dpi, bool use_velocity_averaging)
{
struct pointer_accelerator_low_dpi *filter;
filter = zalloc(sizeof *filter);
filter->last_velocity = 0.0;
trackers_init(&filter->trackers, use_velocity_averaging ? 16 : 2);
filter->threshold = DEFAULT_THRESHOLD;
filter->accel = DEFAULT_ACCELERATION;
filter->incline = DEFAULT_INCLINE;
filter->dpi = dpi;
return filter;
}
struct motion_filter *
create_pointer_accelerator_filter_linear_low_dpi(int dpi, bool use_velocity_averaging)
{
struct pointer_accelerator_low_dpi *filter;
filter = create_default_filter(dpi, use_velocity_averaging);
if (!filter)
return NULL;
filter->base.interface = &accelerator_interface_low_dpi;
filter->profile = pointer_accel_profile_linear_low_dpi;
return &filter->base;
}
libinput-1.28.1/src/filter-mouse.c000066400000000000000000000215311477265155700170240ustar00rootroot00000000000000/*
* Copyright © 2006-2009 Simon Thum
* Copyright © 2012 Jonas Ådahl
* Copyright © 2014-2015 Red Hat, Inc.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice (including the next
* paragraph) shall be included in all copies or substantial portions of the
* Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
*/
#include "config.h"
#include
#include
#include
#include
#include "filter.h"
#include "libinput-util.h"
#include "filter-private.h"
/*
* Default parameters for pointer acceleration profiles.
*/
#define DEFAULT_THRESHOLD v_ms2us(0.4) /* in 1000dpi units/us */
#define MINIMUM_THRESHOLD v_ms2us(0.2) /* in 1000dpi units/us */
#define DEFAULT_ACCELERATION 2.0 /* unitless factor */
#define DEFAULT_INCLINE 1.1 /* unitless factor */
struct pointer_accelerator {
struct motion_filter base;
accel_profile_func_t profile;
double velocity; /* units/us */
double last_velocity; /* units/us */
struct pointer_trackers trackers;
double threshold; /* 1000dpi units/us */
double accel; /* unitless factor */
double incline; /* incline of the function */
int dpi;
};
/**
* Calculate the acceleration factor for the given delta with the timestamp.
*
* @param accel The acceleration filter
* @param unaccelerated The raw delta in the device's dpi
* @param data Caller-specific data
* @param time Current time in µs
*
* @return A unitless acceleration factor, to be applied to the delta
*/
static inline double
calculate_acceleration_factor(struct pointer_accelerator *accel,
const struct normalized_coords *unaccelerated,
void *data,
uint64_t time)
{
double velocity; /* units/us in normalized 1000dpi units*/
double accel_factor;
/* The trackers API need device_float_coords, but note that we have
* normalized coordinates */
const struct device_float_coords unaccel = {
.x = unaccelerated->x,
.y = unaccelerated->y,
};
trackers_feed(&accel->trackers, &unaccel, time);
velocity = trackers_velocity(&accel->trackers, time);
/* This will call into our pointer_accel_profile_linear() profile func */
accel_factor = calculate_acceleration_simpsons(&accel->base,
accel->profile,
data,
velocity, /* normalized coords */
accel->last_velocity, /* normalized coords */
time);
accel->last_velocity = velocity;
return accel_factor;
}
static struct normalized_coords
accelerator_filter_linear(struct motion_filter *filter,
const struct device_float_coords *unaccelerated,
void *data, uint64_t time)
{
struct pointer_accelerator *accel =
(struct pointer_accelerator *) filter;
/* Accelerate for normalized units and return normalized units */
const struct normalized_coords normalized = normalize_for_dpi(unaccelerated,
accel->dpi);
double accel_factor = calculate_acceleration_factor(accel,
&normalized,
data,
time);
struct normalized_coords accelerated = {
.x = normalized.x * accel_factor,
.y = normalized.y * accel_factor,
};
return accelerated;
}
/**
* Generic filter that does nothing beyond converting from the device's
* native dpi into normalized coordinates.
*
* @param filter The acceleration filter
* @param unaccelerated The raw delta in the device's dpi
* @param data Caller-specific data
* @param time Current time in µs
*
* @return An accelerated tuple of coordinates representing normalized
* motion
*/
static struct normalized_coords
accelerator_filter_noop(struct motion_filter *filter,
const struct device_float_coords *unaccelerated,
void *data, uint64_t time)
{
struct pointer_accelerator *accel =
(struct pointer_accelerator *) filter;
return normalize_for_dpi(unaccelerated, accel->dpi);
}
static void
accelerator_restart(struct motion_filter *filter,
void *data,
uint64_t time)
{
struct pointer_accelerator *accel =
(struct pointer_accelerator *) filter;
trackers_reset(&accel->trackers, time);
}
static void
accelerator_destroy(struct motion_filter *filter)
{
struct pointer_accelerator *accel =
(struct pointer_accelerator *) filter;
trackers_free(&accel->trackers);
free(accel);
}
static bool
accelerator_set_speed(struct motion_filter *filter,
double speed_adjustment)
{
struct pointer_accelerator *accel_filter =
(struct pointer_accelerator *)filter;
assert(speed_adjustment >= -1.0 && speed_adjustment <= 1.0);
/* Note: the numbers below are nothing but trial-and-error magic,
don't read more into them other than "they mostly worked ok" */
/* delay when accel kicks in */
accel_filter->threshold = DEFAULT_THRESHOLD -
v_ms2us(0.25) * speed_adjustment;
if (accel_filter->threshold < MINIMUM_THRESHOLD)
accel_filter->threshold = MINIMUM_THRESHOLD;
/* adjust max accel factor */
accel_filter->accel = DEFAULT_ACCELERATION + speed_adjustment * 1.5;
/* higher speed -> faster to reach max */
accel_filter->incline = DEFAULT_INCLINE + speed_adjustment * 0.75;
filter->speed_adjustment = speed_adjustment;
return true;
}
double
pointer_accel_profile_linear(struct motion_filter *filter,
void *data,
double speed_in, /* in normalized units */
uint64_t time)
{
struct pointer_accelerator *accel_filter =
(struct pointer_accelerator *)filter;
const double max_accel = accel_filter->accel; /* unitless factor */
const double threshold = accel_filter->threshold; /* 1000dpi units/us */
const double incline = accel_filter->incline;
double factor; /* unitless */
/*
Our acceleration function calculates a factor to accelerate input
deltas with. The function is a double incline with a plateau,
with a rough shape like this:
accel
factor
^
| /
| _____/
| /
|/
+-------------> speed in
The two inclines are linear functions in the form
y = ax + b
where y is speed_out
x is speed_in
a is the incline of acceleration
b is minimum acceleration factor
for speeds up to 0.07 u/ms, we decelerate, down to 30% of input
speed.
hence 1 = a * 0.07 + 0.3
0.7 = a * 0.07 => a := 10
deceleration function is thus:
y = 10x + 0.3
Note:
* 0.07u/ms as threshold is a result of trial-and-error and
has no other intrinsic meaning.
* 0.3 is chosen simply because it is above the Nyquist frequency
for subpixel motion within a pixel.
*/
if (v_us2ms(speed_in) < 0.07) {
factor = 10 * v_us2ms(speed_in) + 0.3;
/* up to the threshold, we keep factor 1, i.e. 1:1 movement */
} else if (speed_in < threshold) {
factor = 1;
} else {
/* Acceleration function above the threshold:
y = ax' + b
where T is threshold
x is speed_in
x' is speed
and
y(T) == 1
hence 1 = ax' + 1
=> x' := (x - T)
*/
factor = incline * v_us2ms(speed_in - threshold) + 1;
}
/* Cap at the maximum acceleration factor */
factor = min(max_accel, factor);
return factor;
}
static const struct motion_filter_interface accelerator_interface = {
.type = LIBINPUT_CONFIG_ACCEL_PROFILE_ADAPTIVE,
.filter = accelerator_filter_linear,
.filter_constant = accelerator_filter_noop,
.filter_scroll = accelerator_filter_noop,
.restart = accelerator_restart,
.destroy = accelerator_destroy,
.set_speed = accelerator_set_speed,
};
static struct pointer_accelerator *
create_default_filter(int dpi, bool use_velocity_averaging)
{
struct pointer_accelerator *filter;
filter = zalloc(sizeof *filter);
filter->last_velocity = 0.0;
trackers_init(&filter->trackers, use_velocity_averaging ? 16 : 2);
filter->threshold = DEFAULT_THRESHOLD;
filter->accel = DEFAULT_ACCELERATION;
filter->incline = DEFAULT_INCLINE;
filter->dpi = dpi;
return filter;
}
struct motion_filter *
create_pointer_accelerator_filter_linear(int dpi, bool use_velocity_averaging)
{
struct pointer_accelerator *filter;
filter = create_default_filter(dpi, use_velocity_averaging);
if (!filter)
return NULL;
filter->base.interface = &accelerator_interface;
filter->profile = pointer_accel_profile_linear;
return &filter->base;
}
libinput-1.28.1/src/filter-private.h000066400000000000000000000105641477265155700173570ustar00rootroot00000000000000/*
* Copyright © 2012 Jonas Ådahl
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice (including the next
* paragraph) shall be included in all copies or substantial portions of the
* Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
*/
#ifndef FILTER_PRIVATE_H
#define FILTER_PRIVATE_H
#include "config.h"
#include "filter.h"
struct motion_filter_interface {
enum libinput_config_accel_profile type;
struct normalized_coords (*filter)(
struct motion_filter *filter,
const struct device_float_coords *unaccelerated,
void *data, uint64_t time);
struct normalized_coords (*filter_constant)(
struct motion_filter *filter,
const struct device_float_coords *unaccelerated,
void *data, uint64_t time);
struct normalized_coords (*filter_scroll)(
struct motion_filter *filter,
const struct device_float_coords *unaccelerated,
void *data, uint64_t time);
void (*restart)(struct motion_filter *filter,
void *data,
uint64_t time);
void (*destroy)(struct motion_filter *filter);
bool (*set_speed)(struct motion_filter *filter,
double speed_adjustment);
bool (*set_accel_config)(struct motion_filter *filter,
struct libinput_config_accel *accel_config);
};
struct motion_filter {
double speed_adjustment; /* normalized [-1, 1] */
const struct motion_filter_interface *interface;
};
struct pointer_tracker {
struct device_float_coords delta; /* delta to most recent event */
uint64_t time; /* us */
uint32_t dir;
};
/* For smoothing timestamps from devices with unreliable timing */
struct pointer_delta_smoothener {
uint64_t threshold;
uint64_t value;
};
static inline struct pointer_delta_smoothener *
pointer_delta_smoothener_create(uint64_t event_delta_smooth_threshold,
uint64_t event_delta_smooth_value)
{
struct pointer_delta_smoothener *s = zalloc(sizeof(*s));
s->threshold = event_delta_smooth_threshold;
s->value = event_delta_smooth_value;
return s;
}
static inline void
pointer_delta_smoothener_destroy(struct pointer_delta_smoothener *smoothener)
{
free(smoothener);
}
struct pointer_trackers {
struct pointer_tracker *trackers;
size_t ntrackers;
unsigned int cur_tracker;
struct pointer_delta_smoothener *smoothener;
};
void trackers_init(struct pointer_trackers *trackers, int ntrackers);
void trackers_free(struct pointer_trackers *trackers);
void
trackers_reset(struct pointer_trackers *trackers,
uint64_t time);
void
trackers_feed(struct pointer_trackers *trackers,
const struct device_float_coords *delta,
uint64_t time);
struct pointer_tracker *
trackers_by_offset(struct pointer_trackers *trackers, unsigned int offset);
double
trackers_velocity(struct pointer_trackers *trackers, uint64_t time);
double
calculate_acceleration_simpsons(struct motion_filter *filter,
accel_profile_func_t profile,
void *data,
double velocity,
double last_velocity,
uint64_t time);
/* Convert speed/velocity from units/us to units/ms */
static inline double
v_us2ms(double units_per_us)
{
return units_per_us * 1000.0;
}
static inline double
v_us2s(double units_per_us)
{
return units_per_us * 1000000.0;
}
/* Convert speed/velocity from units/ms to units/us */
static inline double
v_ms2us(double units_per_ms)
{
return units_per_ms/1000.0;
}
static inline struct normalized_coords
normalize_for_dpi(const struct device_float_coords *coords, int dpi)
{
struct normalized_coords norm;
norm.x = coords->x * DEFAULT_MOUSE_DPI/dpi;
norm.y = coords->y * DEFAULT_MOUSE_DPI/dpi;
return norm;
}
#endif
libinput-1.28.1/src/filter-tablet.c000066400000000000000000000125301477265155700171460ustar00rootroot00000000000000/*
* Copyright © 2006-2009 Simon Thum
* Copyright © 2012 Jonas Ådahl
* Copyright © 2014-2015 Red Hat, Inc.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice (including the next
* paragraph) shall be included in all copies or substantial portions of the
* Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
*/
#include "config.h"
#include
#include
#include
#include
#include "filter.h"
#include "libinput-util.h"
#include "filter-private.h"
struct tablet_accelerator_flat {
struct motion_filter base;
double factor;
int xres, yres;
double xres_scale, /* 1000dpi : tablet res */
yres_scale; /* 1000dpi : tablet res */
};
static inline struct normalized_coords
tablet_accelerator_filter_flat_mouse(struct tablet_accelerator_flat *filter,
const struct device_float_coords *units)
{
struct normalized_coords accelerated;
/*
Tablets are high res (Intuos 4 is 5080 dpi) and unmodified deltas
are way too high. Slow it down to the equivalent of a 1000dpi
mouse. The ratio of that is:
ratio = 1000/(resolution_per_mm * 25.4)
i.e. on the Intuos4 it's a ratio of ~1/5.
*/
accelerated.x = units->x * filter->xres_scale;
accelerated.y = units->y * filter->yres_scale;
accelerated.x *= filter->factor;
accelerated.y *= filter->factor;
return accelerated;
}
static struct normalized_coords
tablet_accelerator_filter_flat_pen(struct tablet_accelerator_flat *filter,
const struct device_float_coords *units)
{
struct normalized_coords accelerated;
/* Tablet input is in device units, output is supposed to be in
* logical pixels roughly equivalent to a mouse/touchpad.
*
* This is a magical constant found by trial and error. On a 96dpi
* screen 0.4mm of movement correspond to 1px logical pixel which
* is almost identical to the tablet mapped to screen in absolute
* mode. Tested on a Intuos5, other tablets may vary.
*/
const double DPI_CONVERSION = 96.0/25.4 * 2.5; /* unitless factor */
struct normalized_coords mm;
mm.x = 1.0 * units->x/filter->xres;
mm.y = 1.0 * units->y/filter->yres;
accelerated.x = mm.x * filter->factor * DPI_CONVERSION;
accelerated.y = mm.y * filter->factor * DPI_CONVERSION;
return accelerated;
}
static struct normalized_coords
tablet_accelerator_filter_flat(struct motion_filter *filter,
const struct device_float_coords *units,
void *data, uint64_t time)
{
struct tablet_accelerator_flat *accel_filter =
(struct tablet_accelerator_flat *)filter;
struct libinput_tablet_tool *tool = (struct libinput_tablet_tool*)data;
enum libinput_tablet_tool_type type;
struct normalized_coords accel;
type = libinput_tablet_tool_get_type(tool);
switch (type) {
case LIBINPUT_TABLET_TOOL_TYPE_MOUSE:
case LIBINPUT_TABLET_TOOL_TYPE_LENS:
accel = tablet_accelerator_filter_flat_mouse(accel_filter,
units);
break;
default:
accel = tablet_accelerator_filter_flat_pen(accel_filter,
units);
break;
}
return accel;
}
static bool
tablet_accelerator_set_speed(struct motion_filter *filter,
double speed_adjustment)
{
struct tablet_accelerator_flat *accel_filter =
(struct tablet_accelerator_flat *)filter;
assert(speed_adjustment >= -1.0 && speed_adjustment <= 1.0);
accel_filter->factor = speed_adjustment + 1.0;
return true;
}
static void
tablet_accelerator_destroy(struct motion_filter *filter)
{
struct tablet_accelerator_flat *accel_filter =
(struct tablet_accelerator_flat *)filter;
free(accel_filter);
}
static const struct motion_filter_interface accelerator_interface_tablet = {
.type = LIBINPUT_CONFIG_ACCEL_PROFILE_FLAT,
.filter = tablet_accelerator_filter_flat,
.filter_constant = NULL,
.filter_scroll = NULL,
.restart = NULL,
.destroy = tablet_accelerator_destroy,
.set_speed = tablet_accelerator_set_speed,
};
static struct tablet_accelerator_flat *
create_tablet_filter_flat(int xres, int yres)
{
struct tablet_accelerator_flat *filter;
filter = zalloc(sizeof *filter);
filter->factor = 1.0;
filter->xres = xres;
filter->yres = yres;
filter->xres_scale = DEFAULT_MOUSE_DPI/(25.4 * xres);
filter->yres_scale = DEFAULT_MOUSE_DPI/(25.4 * yres);
return filter;
}
struct motion_filter *
create_pointer_accelerator_filter_tablet(int xres, int yres)
{
struct tablet_accelerator_flat *filter;
filter = create_tablet_filter_flat(xres, yres);
if (!filter)
return NULL;
filter->base.interface = &accelerator_interface_tablet;
return &filter->base;
}
libinput-1.28.1/src/filter-touchpad-flat.c000066400000000000000000000102311477265155700204220ustar00rootroot00000000000000/*
* Copyright © 2006-2009 Simon Thum
* Copyright © 2012 Jonas Ådahl
* Copyright © 2014-2015 Red Hat, Inc.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice (including the next
* paragraph) shall be included in all copies or substantial portions of the
* Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
*/
#include "config.h"
#include
#include
#include
#include
#include "filter.h"
#include "libinput-util.h"
#include "filter-private.h"
#define TP_MAGIC_SLOWDOWN_FLAT 0.2968
struct touchpad_accelerator_flat {
struct motion_filter base;
double factor;
int dpi;
};
static struct normalized_coords
accelerator_filter_touchpad_flat(struct motion_filter *filter,
const struct device_float_coords *unaccelerated,
void *data, uint64_t time)
{
struct touchpad_accelerator_flat *accel =
(struct touchpad_accelerator_flat *)filter;
double factor; /* unitless factor */
struct normalized_coords normalized;
/* You want flat acceleration, you get flat acceleration for the
* device */
factor = accel->factor;
normalized = normalize_for_dpi(unaccelerated, accel->dpi);
normalized.x = TP_MAGIC_SLOWDOWN_FLAT * factor * normalized.x;
normalized.y = TP_MAGIC_SLOWDOWN_FLAT * factor * normalized.y;
return normalized;
}
static struct normalized_coords
accelerator_filter_noop_touchpad_flat(struct motion_filter *filter,
const struct device_float_coords *unaccelerated,
void *data, uint64_t time)
{
/* We map the unaccelerated flat filter to have the same behavior as
* the "accelerated" flat filter.
* The filter by definition is flat, i.e. it does not actually
* apply any acceleration (merely a constant factor) and we can assume
* that a user wants all mouse movement to have the same speed, mapped
* 1:1 to the input speed.
*
* Thus we apply the same factor to our non-accelerated motion - this way
* things like gestures end up having the same movement as
* pointer motion.
*/
return accelerator_filter_touchpad_flat(filter, unaccelerated, data, time);
}
static bool
accelerator_set_speed_touchpad_flat(struct motion_filter *filter,
double speed_adjustment)
{
struct touchpad_accelerator_flat *accel_filter =
(struct touchpad_accelerator_flat *)filter;
assert(speed_adjustment >= -1.0 && speed_adjustment <= 1.0);
accel_filter->factor = max(0.005, 1 + speed_adjustment);
filter->speed_adjustment = speed_adjustment;
return true;
}
static void
accelerator_destroy_touchpad_flat(struct motion_filter *filter)
{
struct touchpad_accelerator_flat *accel =
(struct touchpad_accelerator_flat *) filter;
free(accel);
}
static const struct motion_filter_interface accelerator_interface_touchpad_flat = {
.type = LIBINPUT_CONFIG_ACCEL_PROFILE_FLAT,
.filter = accelerator_filter_touchpad_flat,
.filter_constant = accelerator_filter_noop_touchpad_flat,
.filter_scroll = accelerator_filter_noop_touchpad_flat,
.restart = NULL,
.destroy = accelerator_destroy_touchpad_flat,
.set_speed = accelerator_set_speed_touchpad_flat,
};
struct motion_filter *
create_pointer_accelerator_filter_touchpad_flat(int dpi)
{
struct touchpad_accelerator_flat *filter;
filter = zalloc(sizeof *filter);
filter->base.interface = &accelerator_interface_touchpad_flat;
filter->dpi = dpi;
return &filter->base;
}
libinput-1.28.1/src/filter-touchpad-x230.c000066400000000000000000000244421477265155700202010ustar00rootroot00000000000000/*
* Copyright © 2006-2009 Simon Thum
* Copyright © 2012 Jonas Ådahl
* Copyright © 2014-2015 Red Hat, Inc.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice (including the next
* paragraph) shall be included in all copies or substantial portions of the
* Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
*/
#include "config.h"
#include
#include
#include
#include "filter.h"
#include "libinput-util.h"
#include "filter-private.h"
/* Trackpoint acceleration for the Lenovo x230. DO NOT TOUCH.
* This code is only invoked on the X230 and is quite flimsy,
* custom-designed to make this touchpad less terrible than the
* out-of-the-box experience. The x230 was released in 2013, it's
* not worth trying to optimize the code or de-duplicate the various
* copy-pastes.
*/
/*
* Default parameters for pointer acceleration profiles.
*/
#define DEFAULT_THRESHOLD v_ms2us(0.4) /* in units/us */
#define MINIMUM_THRESHOLD v_ms2us(0.2) /* in units/us */
#define DEFAULT_ACCELERATION 2.0 /* unitless factor */
#define DEFAULT_INCLINE 1.1 /* unitless factor */
/* for the Lenovo x230 custom accel. do not touch */
#define X230_THRESHOLD v_ms2us(0.4) /* in units/us */
#define X230_ACCELERATION 2.0 /* unitless factor */
#define X230_INCLINE 1.1 /* unitless factor */
#define X230_MAGIC_SLOWDOWN 0.4 /* unitless */
#define X230_TP_MAGIC_LOW_RES_FACTOR 4.0 /* unitless */
struct pointer_accelerator_x230 {
struct motion_filter base;
accel_profile_func_t profile;
double velocity; /* units/us */
double last_velocity; /* units/us */
struct pointer_trackers trackers;
double threshold; /* units/us */
double accel; /* unitless factor */
double incline; /* incline of the function */
int dpi;
};
/**
* Apply the acceleration profile to the given velocity.
*
* @param accel The acceleration filter
* @param data Caller-specific data
* @param velocity Velocity in device-units per µs
* @param time Current time in µs
*
* @return A unitless acceleration factor, to be applied to the delta
*/
static double
acceleration_profile(struct pointer_accelerator_x230 *accel,
void *data, double velocity, uint64_t time)
{
return accel->profile(&accel->base, data, velocity, time);
}
/**
* Calculate the acceleration factor for our current velocity, averaging
* between our current and the most recent velocity to smoothen out changes.
*
* @param accel The acceleration filter
* @param data Caller-specific data
* @param velocity Velocity in device-units per µs
* @param last_velocity Previous velocity in device-units per µs
* @param time Current time in µs
*
* @return A unitless acceleration factor, to be applied to the delta
*/
static double
calculate_acceleration(struct pointer_accelerator_x230 *accel,
void *data,
double velocity,
double last_velocity,
uint64_t time)
{
double factor;
/* Use Simpson's rule to calculate the average acceleration between
* the previous motion and the most recent. */
factor = acceleration_profile(accel, data, velocity, time);
factor += acceleration_profile(accel, data, last_velocity, time);
factor += 4.0 *
acceleration_profile(accel, data,
(last_velocity + velocity) / 2,
time);
factor = factor / 6.0;
return factor; /* unitless factor */
}
static struct normalized_coords
accelerator_filter_x230(struct motion_filter *filter,
const struct device_float_coords *raw,
void *data, uint64_t time)
{
struct pointer_accelerator_x230 *accel =
(struct pointer_accelerator_x230 *) filter;
double accel_factor; /* unitless factor */
struct normalized_coords accelerated;
struct device_float_coords delta_normalized;
struct normalized_coords unaccelerated;
double velocity; /* units/us */
/* This filter is a "do not touch me" filter. So the hack here is
* just to replicate the old behavior before filters switched to
* device-native dpi:
* 1) convert from device-native to 1000dpi normalized
* 2) run all calculation on 1000dpi-normalized data
* 3) apply accel factor no normalized data
*/
unaccelerated = normalize_for_dpi(raw, accel->dpi);
delta_normalized.x = unaccelerated.x;
delta_normalized.y = unaccelerated.y;
trackers_feed(&accel->trackers, &delta_normalized, time);
velocity = trackers_velocity(&accel->trackers, time);
accel_factor = calculate_acceleration(accel,
data,
velocity,
accel->last_velocity,
time);
accel->last_velocity = velocity;
accelerated.x = accel_factor * delta_normalized.x;
accelerated.y = accel_factor * delta_normalized.y;
return accelerated;
}
static struct normalized_coords
accelerator_filter_constant_x230(struct motion_filter *filter,
const struct device_float_coords *unaccelerated,
void *data, uint64_t time)
{
struct pointer_accelerator_x230 *accel =
(struct pointer_accelerator_x230 *) filter;
struct normalized_coords normalized;
const double factor =
X230_MAGIC_SLOWDOWN/X230_TP_MAGIC_LOW_RES_FACTOR;
normalized = normalize_for_dpi(unaccelerated, accel->dpi);
normalized.x = factor * normalized.x;
normalized.y = factor * normalized.y;
return normalized;
}
static void
accelerator_restart_x230(struct motion_filter *filter,
void *data,
uint64_t time)
{
struct pointer_accelerator_x230 *accel =
(struct pointer_accelerator_x230 *) filter;
unsigned int offset;
struct pointer_tracker *tracker;
for (offset = 1; offset < accel->trackers.ntrackers; offset++) {
tracker = trackers_by_offset(&accel->trackers, offset);
tracker->time = 0;
tracker->dir = 0;
tracker->delta.x = 0;
tracker->delta.y = 0;
}
tracker = trackers_by_offset(&accel->trackers, 0);
tracker->time = time;
tracker->dir = UNDEFINED_DIRECTION;
}
static void
accelerator_destroy_x230(struct motion_filter *filter)
{
struct pointer_accelerator_x230 *accel =
(struct pointer_accelerator_x230 *) filter;
free(accel->trackers.trackers);
free(accel);
}
static bool
accelerator_set_speed_x230(struct motion_filter *filter,
double speed_adjustment)
{
struct pointer_accelerator_x230 *accel_filter =
(struct pointer_accelerator_x230 *)filter;
assert(speed_adjustment >= -1.0 && speed_adjustment <= 1.0);
/* Note: the numbers below are nothing but trial-and-error magic,
don't read more into them other than "they mostly worked ok" */
/* delay when accel kicks in */
accel_filter->threshold = DEFAULT_THRESHOLD -
v_ms2us(0.25) * speed_adjustment;
if (accel_filter->threshold < MINIMUM_THRESHOLD)
accel_filter->threshold = MINIMUM_THRESHOLD;
/* adjust max accel factor */
accel_filter->accel = DEFAULT_ACCELERATION + speed_adjustment * 1.5;
/* higher speed -> faster to reach max */
accel_filter->incline = DEFAULT_INCLINE + speed_adjustment * 0.75;
filter->speed_adjustment = speed_adjustment;
return true;
}
double
touchpad_lenovo_x230_accel_profile(struct motion_filter *filter,
void *data,
double speed_in, /* 1000dpi-units/µs */
uint64_t time)
{
/* Those touchpads presents an actual lower resolution that what is
* advertised. We see some jumps from the cursor due to the big steps
* in X and Y when we are receiving data.
* Apply a factor to minimize those jumps at low speed, and try
* keeping the same feeling as regular touchpads at high speed.
* It still feels slower but it is usable at least */
double factor; /* unitless */
struct pointer_accelerator_x230 *accel_filter =
(struct pointer_accelerator_x230 *)filter;
double f1, f2; /* unitless */
const double max_accel = accel_filter->accel *
X230_TP_MAGIC_LOW_RES_FACTOR; /* unitless factor */
const double threshold = accel_filter->threshold /
X230_TP_MAGIC_LOW_RES_FACTOR; /* units/us */
const double incline = accel_filter->incline * X230_TP_MAGIC_LOW_RES_FACTOR;
/* Note: the magic values in this function are obtained by
* trial-and-error. No other meaning should be interpreted.
* The calculation is a compressed form of
* pointer_accel_profile_linear(), look at the git history of that
* function for an explanation of what the min/max/etc. does.
*/
speed_in *= X230_MAGIC_SLOWDOWN / X230_TP_MAGIC_LOW_RES_FACTOR;
f1 = min(1, v_us2ms(speed_in) * 5);
f2 = 1 + (v_us2ms(speed_in) - v_us2ms(threshold)) * incline;
factor = min(max_accel, f2 > 1 ? f2 : f1);
return factor * X230_MAGIC_SLOWDOWN / X230_TP_MAGIC_LOW_RES_FACTOR;
}
static const struct motion_filter_interface accelerator_interface_x230 = {
.type = LIBINPUT_CONFIG_ACCEL_PROFILE_ADAPTIVE,
.filter = accelerator_filter_x230,
.filter_constant = accelerator_filter_constant_x230,
.filter_scroll = accelerator_filter_constant_x230,
.restart = accelerator_restart_x230,
.destroy = accelerator_destroy_x230,
.set_speed = accelerator_set_speed_x230,
};
/* The Lenovo x230 has a bad touchpad. This accel method has been
* trial-and-error'd, any changes to it will require re-testing everything.
* Don't touch this.
*/
struct motion_filter *
create_pointer_accelerator_filter_lenovo_x230(int dpi, bool use_velocity_averaging)
{
struct pointer_accelerator_x230 *filter;
filter = zalloc(sizeof *filter);
filter->base.interface = &accelerator_interface_x230;
filter->profile = touchpad_lenovo_x230_accel_profile;
filter->last_velocity = 0.0;
trackers_init(&filter->trackers, use_velocity_averaging ? 16 : 2);
filter->threshold = X230_THRESHOLD;
filter->accel = X230_ACCELERATION; /* unitless factor */
filter->incline = X230_INCLINE; /* incline of the acceleration function */
filter->dpi = dpi;
return &filter->base;
}
libinput-1.28.1/src/filter-touchpad.c000066400000000000000000000224121477265155700175020ustar00rootroot00000000000000/*
* Copyright © 2006-2009 Simon Thum
* Copyright © 2012 Jonas Ådahl
* Copyright © 2014-2015 Red Hat, Inc.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice (including the next
* paragraph) shall be included in all copies or substantial portions of the
* Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
*/
#include "config.h"
#include
#include
#include
Axis 0x35 value 4000 is outside expected range [0, 3000]This error message indicates that the ABS_MT_POSITION_X axis (i.e. the x axis) generated an event outside the expected range of 0-3000. In this case the value was 4000. This discrepancy between the coordinate range the kernels advertises vs. what the touchpad sends can be the source of a number of perceived bugs in libinput. .. _absolute_coordinate_ranges_fix: ------------------------------------------------------------------------------ Measuring and fixing touchpad ranges ------------------------------------------------------------------------------ To fix the touchpad you need to: #. measure the physical size of your touchpad in mm #. run the ``libinput measure touchpad-size`` tool #. verify the hwdb entry provided by this tool #. test locally #. send a patch to the `systemd project