Compare commits

...

229 Commits

Author SHA1 Message Date
Peter Hutterer
ac862672e4 Add support for the libinput plugin system
This is hardcoded to be enabled from the default paths (/usr/share and
/etc) without any extra paths. If there is a need we can add xorg.conf
options later but for now it will do.

Part-of: <https://gitlab.freedesktop.org/xorg/driver/xf86-input-libinput/-/merge_requests/73>
2025-11-05 09:25:10 +10:00
Peter Hutterer
c169537717 CI: drop the merge request check
Effectively obsolete and now broken, see
https://gitlab.freedesktop.org/freedesktop/ci-templates/-/issues/81

Part-of: <https://gitlab.freedesktop.org/xorg/driver/xf86-input-libinput/-/merge_requests/75>
2025-10-24 14:54:57 +10:00
Peter Hutterer
79b62f322a CI: bump to latest ci-templates and latest Fedora
Part-of: <https://gitlab.freedesktop.org/xorg/driver/xf86-input-libinput/-/merge_requests/74>
2025-10-24 11:22:54 +10:00
Peter Hutterer
6612ab7e97 meson.build: add dep_libinput as dependency for the KANA check
So meson can find the libinput.h header if libinput is in a nonstandard
path.

Fixes: 0bcb60e744 ("Add support for LIBINPUT_LED_COMPOSE/LIBINPUT_LED_KANA")
Part-of: <https://gitlab.freedesktop.org/xorg/driver/xf86-input-libinput/-/merge_requests/72>
2025-10-23 09:31:45 +10:00
Peter Hutterer
709d0b0a9a meson.build: install the libinput-properties.h file
Patch provided by Brice De Bruyne

Closes #67

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
Part-of: <https://gitlab.freedesktop.org/xorg/driver/xf86-input-libinput/-/merge_requests/71>
2025-06-24 15:33:33 +10:00
Alan Coopersmith
9c64c0236c Improve man page formatting
More closely follow common style as described on
https://man7.org/linux/man-pages/man7/man-pages.7.html
and fix warnings raised by `mandoc -T lint` and `groff -rCHECKSTYLE=10`

Part-of: <https://gitlab.freedesktop.org/xorg/driver/xf86-input-libinput/-/merge_requests/70>
2025-06-01 09:32:20 -07:00
Enrico Weigelt, metux IT consult
c674db53d9 fix unused variable click_methods
This variable is only used under certain (build-time) conditions,
so need needs to be defined/assigned under those.

Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
Part-of: <https://gitlab.freedesktop.org/xorg/driver/xf86-input-libinput/-/merge_requests/65>
2025-04-16 23:16:53 +00:00
Enrico Weigelt, metux IT consult
8a63e97e0c ci: fix missing diffutils
> checking if gcc supports -fno-rtti -fno-exceptions... /builds/metux/xf86-input-libinput/_builddir/../configure: line 8891: diff: command not found

Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
Part-of: <https://gitlab.freedesktop.org/xorg/driver/xf86-input-libinput/-/merge_requests/67>
2025-04-16 15:41:43 +02:00
Peter Hutterer
c712930ef4 xf86-input-libinput 1.5.0
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2024-10-15 14:06:00 +10:00
Peter Hutterer
db7cfbe5c2 test: fix some scan-build warnings
e.g.
../../../test/test-draglock.c:262:2: warning: Value stored to 'rc' is never read [deadcode.DeadStores]
  262 |         rc = draglock_init_from_string(&dl, "10");
2024-10-15 13:58:18 +10:00
Peter Hutterer
cb80d7f82d Map some specific high keycodes into the FK20-23 range
These mappings have been part of xkeyboard-config for over a decade and
the likely reason they were introduced is that the corresponding evdev
keycode is > 255.

Let's forcibly remap those in the driver here so the rest of the system
can switch to the real keycodes instead of having to map them to the
whatever X expects.

See https://github.com/systemd/systemd/pull/34325/

Part-of: <https://gitlab.freedesktop.org/xorg/driver/xf86-input-libinput/-/merge_requests/62>
2024-10-09 23:25:17 +00:00
Peter Hutterer
7c5635cd6f Silence a compiler warning
../src/xf86libinput.c: In function ‘prop_draglock_set_pairs’:
../src/xf86libinput.c:5153:30: warning: comparison is always false due to limited range of data type [-Wtype-limits]
 5153 |                 if (pairs[i] > MAX_BUTTONS)

MAX_BUTTONS is defined by the server so let's use a temporary local
variable to silence the compiler.

Part-of: <https://gitlab.freedesktop.org/xorg/driver/xf86-input-libinput/-/merge_requests/61>
2024-10-09 14:02:44 +10:00
Peter Hutterer
b396ba3697 Prevent theoretical null-pointer dereference
Cannot happen since we don't enter this function if the atom isn't one
of the three checked above but the static analyzer doesn't know that.

Part-of: <https://gitlab.freedesktop.org/xorg/driver/xf86-input-libinput/-/merge_requests/60>
2024-09-13 03:06:20 +00:00
Martin Rys
0bcb60e744 Add support for LIBINPUT_LED_COMPOSE/LIBINPUT_LED_KANA
Added in libinput 1.26

Part-of: <https://gitlab.freedesktop.org/xorg/driver/xf86-input-libinput/-/merge_requests/58>
2024-09-12 09:31:01 +10:00
Peter Hutterer
3a33984cce Fix a bunch of whitespace issues
xf86libinput_kbd_ctrl() in particular was a copy/paste with 4-space
indentation, the rest is mostly space->tab replacement.

As pointed out in !58

Part-of: <https://gitlab.freedesktop.org/xorg/driver/xf86-input-libinput/-/merge_requests/59>
2024-09-06 10:14:31 +10:00
Peter Hutterer
bb41cc730c Add support for clickfinger button maps 2024-07-19 11:44:49 +10:00
Peter Hutterer
72c8eb25f8 Implement tablet tool pressure range support 2024-06-10 09:27:57 +00:00
Peter Hutterer
74335c6fd6 Revert "fix int type mismatches in printf()-like calls"
This now warns on 64-bit machines:
../src/xf86libinput.c:542:61: warning: format ‘%lu’ expects argument
of type ‘long unsigned int’, but argument 4 has type ‘CARD32’ {aka ‘unsigned int’} [-Wformat=]

Given they vastly outnumber 32-bit machines now, let's go back to the
old one that only warns on 32 bit until we fix the actual source types
to use uint32_t and similar.

This reverts commit a7d2994256.
2024-06-07 11:14:17 +10:00
Enrico Weigelt, metux IT consult
b791b30b1f update .gitignore
"test/test-bezier" was yet missing

Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
2024-02-21 13:21:09 +01:00
Enrico Weigelt, metux IT consult
a7d2994256 fix int type mismatches in printf()-like calls
Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
2024-02-21 13:21:09 +01:00
Enrico Weigelt, metux IT consult
c6b4d2732f replace BUG_() macros by xf86IDrvMsg() calls
Latest master moved the BUG_() macros out of os.h, and it's more appropriate
to use xf86IDrvMsg() in those cases (like we're already doing in other places)
anyways.

Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
2024-02-21 13:19:47 +01:00
Peter Hutterer
6ed6814489 gitlab CI: update to latest templates and current fedora 2024-02-20 08:24:15 +10:00
Peter Hutterer
a24f467576 Add editorconfig file 2024-02-20 08:22:16 +10:00
Peter Hutterer
b254d491e2 Add a property for the tablet tool serial and hw ID
The driver encodes the serial in the device name but that's not reliable
enough. Expose both serial and tool id (optional) as a property so
clients can read them and adjust their behavior accordingly.

Fixes #16
2023-11-10 08:17:46 +10:00
Peter Hutterer
0dc42f0e4e Sort the read-only properties 2023-11-10 08:16:59 +10:00
Peter Hutterer
46af622e9d xf86-input-libinput 1.4.0
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2023-08-25 13:51:18 +10:00
Peter Hutterer
5e20d16dd4 Don't try to enable a NULL device
If there is no other libinput device in our list (and next is thus NULL),
skip the xf86AddEnabledDevice() call.

Fixes #60
2023-07-10 09:05:19 +10:00
Peter Hutterer
310db4206f Don't run past the last element in the list
If there is no (other) libinput device in the current device list, we'd
eventually end up with next == NULL, causing a segfault.

Fixes #60
2023-07-03 13:33:19 +10:00
Peter Hutterer
94a52a8488 tablet: map BTN_STYLUS3 to button 8
Buttons 4-7 are out of bounds for hysterical historical reasons.
Previously this button fell through to the default statement and
resulted in 8 + BTN_STYLUS3 - BTN_SIDE == 65 which is rather obviously
wrong.

Instead, map it explicitly to what the fourth button would be mapped to
on other devices. This will now overlap with BTN_SIDE on devices that
both BTN_STYLUS3 *and* BTN_SIDE but those devices don't appear to exist
in the real world.

Fixes #50

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2023-06-15 15:09:31 +10:00
Peter Hutterer
a4dfadee2f Initialize the left-handed property for tablet tools
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2023-06-08 14:14:37 +10:00
Peter Hutterer
141aa867a6 Change the capabilities to an enum
Slightly nicer for debugging.
2023-06-08 14:14:37 +10:00
Yinon Burgansky
57b049d376 Improve documentation of the custom acceleration profile 2023-04-26 01:33:46 +03:00
Peter Hutterer
8cf533df3a xf86-input-libinput 1.3.0
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2023-04-04 14:56:40 +10:00
Yinon Burgansky
484b6a7f3f Add support for the scroll movement type of the custom acceleration profile
Adds new properties and xorg.conf entries for setting the scroll acceleration
function's points and step.
The new xorg.conf entries are AccelPointsScroll, AccelStepScroll.
2023-02-18 21:22:15 +02:00
Shin-myoung-serp
e87c7bfcc2 Correct the coordinate transform parameters for an absolute pointer
Fixes #53
2023-02-01 18:33:31 +09:00
Peter Hutterer
f94a8edb0e Add support for custom pointer acceleration
Adds new properties and xorg.conf entries for setting the acceleration
function's points and step.

`AccelProfile` option can now accept `custom` value.

Add 4 new options which only apply when `AccelProfile` is `custom`:

- Add `AccelPointsFallback` option for setting the points of the
  Fallback acceleration function. Points values are represented by a
  space-separated list, e.g. "0.0 1.0 2.4 2.5".

- Add `AccelStepFallback` option for setting the step of the Fallback
  acceleration function. When a step of 0.0 is provided,
  libinput default Fallback acceleration function is used.

- Add `AccelPointsMotion` and `AccelStepMotion` options, which are
  equivalent to `AccelPointsFallback` and `AccelStepFallback` options,
  but apply to the Motion acceleration function.

See libinput documentation for a detailed explanation of custom
pointer acceleration.
2023-01-09 15:53:38 +02:00
Peter Hutterer
ca02afd8d2 configure.ac: inputproto 2.4 is optional
Missing else condition in PKG_CHECK_MODULES caused configure to bail out
where 2.4 wasn't available.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2022-12-09 09:15:09 +10:00
Alan Coopersmith
252bc4ba0d gitlab CI: enable gitlab's builtin static analysis
Signed-off-by: Alan Coopersmith <alan.coopersmith@oracle.com>
2022-07-23 16:58:19 -07:00
Alan Coopersmith
925903018f gitlab CI: enable commit & merge request checks
Uses ci-fairy from freedesktop/ci-templates

Signed-off-by: Alan Coopersmith <alan.coopersmith@oracle.com>
2022-07-23 16:58:19 -07:00
Hong Xu
dfc5e20426 Better explain HorizontalScrolling. 2022-04-27 11:33:46 +00:00
Peter Hutterer
2ee183a6cd Add meson build system
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2022-01-25 12:21:09 +10:00
Peter Hutterer
efa999e377 man: use @VERSION@ for the driver version
Makes use of meson easier which requires @ as pre/suffix for variables.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2022-01-25 12:16:04 +10:00
Peter Hutterer
7b4a870b23 man: replace the various suffixes with their actual numbers
These don't change, iirc they exist because of some unixes having
different man pages but at this point really on Solaris is left and that
uses the same suffixes as everyone else.

And the __xservername__ is a leftover from the Xfree86 vs Xorg days - if
you're still running Xfree86, you're not using this driver.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2022-01-25 12:16:04 +10:00
Peter Hutterer
30500626fe Drop HAVE_CONFIG_H, we always have it defined
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2022-01-25 09:56:13 +10:00
Peter Hutterer
62f267a952 xf86-input-libinput 1.2.1
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2022-01-24 15:00:09 +10:00
Peter Hutterer
c1f07edafa Fix a compiler warning
xf86libinput.c:2457:89: warning: passing argument 1 of
‘libinput_event_pointer_get_axis_source’ from incompatible
pointer type [-Wincompatible-pointer-types]

No function changes due to the binary layout of libinput events but
let's not rely on that.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2022-01-24 11:38:53 +10:00
Alan Coopersmith
a3d38b0f40 Build xz tarballs instead of bzip2
Signed-off-by: Alan Coopersmith <alan.coopersmith@oracle.com>
2022-01-16 21:32:35 +00:00
Alan Coopersmith
e3a75f34f8 Fix spelling/wording issues
Found by using:
    codespell --builtin clear,rare,usage,informal,code,names

Signed-off-by: Alan Coopersmith <alan.coopersmith@oracle.com>
2022-01-16 11:50:26 -08:00
Luna Nova
830f7c3b1b Fix copy-paste error in LibinputInitAccelProperty checking available profiles against adaptive/flat 2021-12-18 04:55:14 +00:00
Peter Hutterer
4ab7873366 Quietly check for the _source option
xf86CheckStrOption returns the same value but doesn't mark it as used in
the server and, more importantly, doesn't spam the log with
  (**) Option "_source" "server/udev"
messages.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2021-11-24 01:14:05 +00:00
José Expósito
b3e65904db Make XIPropertyValuePtr verification consistent
Signed-off-by: José Expósito <jose.exposito89@gmail.com>
2021-11-17 07:57:28 +01:00
José Expósito
75cc87518b Add an option to disable high-resolution wheel scroll
Starting on libinput 1.19 pointer axis events have been deprecated in
favor of their scroll equivalents, including support for high-resolution
wheel scroll.

While it is recommended to handle the new events, some applications
and/or frameworks might not be ready at the moment.

Provide an option to discard high-resolution wheel scroll events.

Fix #41

Signed-off-by: José Expósito <jose.exposito89@gmail.com>
2021-11-14 22:52:47 +00:00
José Expósito
3951ce739d man: fix horizontal scroll property name
Signed-off-by: José Expósito <jose.exposito89@gmail.com>
2021-11-10 18:12:46 +01:00
Povilas Kanapickas
cbdd9efaab xf86-input-libinput 1.2.0
Signed-off-by: Povilas Kanapickas <povilas@radix.lt>
2021-09-19 19:55:46 +03:00
Peter Hutterer
4c54f4d0d2 Rename HAS_GESTURES to HAVE_GESTURES
HAVE_FOO is generally used everywhere (see HAVE_CONFIG_H) so let's keep
this consistent.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2021-09-16 11:23:53 +10:00
Povilas Kanapickas
8331214771 gitlab-ci: Configure xorgproto build from source
We need newer xorgproto than what's in fedora as we depend on inputproto
2.3.99.1 or newer.
2021-09-16 11:23:53 +10:00
Povilas Kanapickas
8588a19f63 Require inputproto 2.4 to build the gesture support
Signed-off-by: Povilas Kanapickas <povilas@radix.lt>
2021-09-16 11:23:33 +10:00
Peter Hutterer
beb94333e1 Use the new v120 API from libinput if available
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2021-08-06 08:45:01 +02:00
José Expósito
ca9042c7f0 Get scroll source in the event handler
Where libinput supports high-resolution scroll events, the scroll source
is encoded in the event type.

Get the scroll source in xf86libinput_handle_event to facilitate the
migration.

Refactor, no functional changes.

Signed-off-by: José Expósito <jose.exposito89@gmail.com>
2021-08-04 17:51:26 +02:00
Peter Hutterer
bf8dc2e2ed Upgrade the default scroll distance to 120
This is just a number, to be used as divider and shouldn't have any effect in
correctly written clients. With the high-res scrolling coming up however, we
have a few devices where the dist cannot be expressed as an integer fraction
of 15, so let's up it to 120 because we know all hardware wheels have to be an
integer fraction of that that, thanks to Microsoft's API requirements.

For non-wheel scrolls we need to now map into the new range. Previously we
just passed the scroll events on from the touchpad/button scrolling, meaning a
vdist of 15 meant 15 "libinput pixels" of scrolling resulted in a logical
wheel click. Now that we have 120 as vdist, we need to times the input data by
8 to keep the same proportions.

See 39b0bb4585 for the previous revert.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2021-08-04 12:09:54 +02:00
Povilas Kanapickas
ecd845c307 Implement support for touchpad gestures 2021-07-05 13:35:02 +00:00
Peter Hutterer
0d9184cb76 xf86-input-libinput 1.1.0
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2021-06-24 08:26:19 +10:00
Peter Hutterer
9bb9e635df Implement a touchpad scroll distance property
To be used for touchpads and continuous (i.e. button-based scrolling).

libinput provides us with pixel data for finger-based and button-based
scrolling but the X server does support this - XI2.1 smooth scrolling is
merely centered around a logical scroll click (defined as "increment"), with
smooth scrolling being a fraction of that increment. For example, in the old
synaptics driver that value was in device-specific units and thus different
for every device.

The increment is a constant value set in the ScrollClass and cannot be changed
at device runtime. So we simply initialize with a random default (15, because
that works well for wheels) and then scale our pixel delta in to that range.

With the default value, a 15 pixel movement would result in a logical scroll
click, if the distance is set to 30 the users has to move 30 pixels to trigger
that scroll click. Pixel here being defined as the deltas that libinput
provides to us.

From the client's perspective nothing changes, the increment is still the
same.

Range checks are quite restrictive, this option is supposed to improve
usability, not as a workaround around other bugs.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2021-05-05 13:34:36 +10:00
Peter Hutterer
cc10918bdc Fix a spacing issue
yay for copy/paste proliferation

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2021-05-05 13:18:19 +10:00
Peter Hutterer
69888cef81 xf86-input-libinput 1.0.1
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2021-04-16 12:18:24 +10:00
Peter Hutterer
6c1c53d296 Make sure the device is valid when setting the tap button map
Fixes #34

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2021-04-09 10:33:15 +10:00
Peter Hutterer
34f14fdf12 xf86-input-libinput 1.0.0
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2021-04-06 15:55:45 +10:00
Peter Hutterer
92047e5d99 gitlab CI: bump to use Fedora 33
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2021-04-06 15:55:45 +10:00
Peter Hutterer
b8d3c29f59 Remove trailing whitespaces
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2021-04-06 15:51:35 +10:00
Peter Hutterer
2bbc4727a1 Switch to the real MIT license
Due to a copy/paste error, the COPYING file and subsequently created files
with the same content referred to the "Historical Permission Notice and
Disclaimer - sell variant", not the proper MIT license.

Replace with the proper MIT (Expat) license and add the use SPDX license
identifiers.

Acks below are from contributors with substantial changes, collected in MR !19
or via private email correspondence.

https://gitlab.freedesktop.org/xorg/driver/xf86-input-libinput/-/merge_requests/19

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
Acked-by: Dorian Stoll <dorian.stoll@tmsp.io>
Acked-by: Jonas Ådahl <jadahl@gmail.com>
Acked-by: Benjamin Tissoires <benjamin.tissoires@gmail.com>
Acked-by: Evangelos Foutras <evangelos@foutrelis.com>
Acked-by: Niklas Haas <git@haasn.xyz>
Acked-by: Olivier Fourdan <ofourdan@redhat.com>
Acked-by: David Rosca <nowrep@gmail.com>
Acked-by: Lyude Paul <lyude@redhat.com>
Acked-by: Keith Packard <keithp@keithp.com>
Acked-by: Alan Coopersmith <alan.coopersmith@oracle.com>
Acked-by: Michel Dänzer <michel@daenzer.net>
Acked-by: Tim Writer <tim.writer@amd.com>
Acked-by: Friedrich Schöller <code@schoeller.se>
Acked-by: Mikhail Konev <k.mvc@ya.ru>
Acked-by: Martin Pieuchot <mpi@openbsd.org>
2021-03-24 13:28:56 +10:00
Dorian Stoll
39be944991 Lift canceled touch inputs
If a touch input gets turned into a palm (by setting ABS_MT_TOOL_TYPE to
MT_TOOL_PALM), libinput will emit a cancel event instead of the normal
up event. The xorg wrapper needs to be able to handle a canceled touch
and lift it, otherwise these inputs will never get lifted and will stick
around forever.

Signed-off-by: Dorian Stoll <dorian.stoll@tmsp.io>
2020-11-04 23:53:01 +01:00
Povilas Kanapickas
bd2aaa246d Remove extraneous semicolon 2020-10-19 21:09:49 +03:00
Povilas Kanapickas
99773d7bda Remove unused btnmap variables 2020-10-19 21:07:47 +03:00
Peter Hutterer
3afb6244e3 Bump the server requirement to 1.19 to get rid of a bunch of ifdefs
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2020-05-19 16:34:18 +10:00
Peter Hutterer
f279108ffd Bump the libinput requirement to 1.11
Released June 2018, that should be recent enough.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2020-05-19 16:30:35 +10:00
Peter Hutterer
583ed5acdc xf86-input-libinput 0.30.0
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2020-05-19 15:58:13 +10:00
Peter Hutterer
e8e5d1a6b5 gitlab CI: update to latest CI templates
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2020-05-19 15:58:13 +10:00
Peter Hutterer
639b21d78a gitlab CI: bump to Fedora 32
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2020-05-19 15:47:11 +10:00
Peter Hutterer
e52daf203b Implement support for scroll button locks
Add a boolean option/property to enable/disable the scroll button lock. Where
enabled, the button can be clicked and released as opposed to having to be
held down.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2019-10-11 11:18:52 +10:00
Peter Hutterer
400bf493d1 xf86-input-libinput 0.29.0
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2019-08-12 12:35:51 +10:00
Peter Hutterer
27a88897be Add basic Gitlab CI for testing the build
This merely tests against the devel package in Fedora, not against the xserver
from git. Should be enough, the driver here doesn't change enough to need the
git builds.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2019-08-12 11:44:56 +10:00
Peter Hutterer
d5867e5db6 Fix compiler warning about unhandled switch events
This bumps the required libinput version to 1.7 - which has been out for over
two years now. That's conservative enough.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2019-08-12 10:36:08 +10:00
Peter Hutterer
1ef2ed874e Check for the tool type too when creating subdevices
Fixed #25

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2019-07-31 00:32:44 +00:00
Peter Hutterer
3c9052d886 Fix wrong enum type
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2019-07-31 00:32:44 +00:00
Peter Hutterer
39b0bb4585 Revert "Upgrade the default scroll distance to 120"
This was part of the high-resolution wheel work that was factored out ahead of
time. Problem is: this breaks scroll button emulation in the server as we
use the distance to determine when we click buttons 4-7.

Before: movement of 15 normalized pixel units on a touchpad - one click. Now:
120 of those units. So that's a bit less than ideal.

The change to 120 can be done, but needs the corresponding handling in the
axis distance calculations.

Fixes #24

This reverts commit 055481187d.
2019-07-30 11:51:12 +10:00
David Rosca
8923d18d25 Also use type to match tablet tool with device
On devices with tools having both serial and id 0,
it would fail to create separate subdevices.

Thinkpad X220T (Wacom ISDv4 E6) now correctly registers
Pen and Eraser xinput devices.
2019-02-25 18:43:42 +01:00
Peter Hutterer
055481187d Upgrade the default scroll distance to 120
This is just a number, to be used as divider and shouldn't have any effect in
correctly written clients. With the high-res scrolling coming up however, we
have a few devices where the dist cannot be expressed as an integer fraction
of 15, so let's up it to 120 because we know all hardware wheels have to be an
integer fraction of that that, thanks to Microsoft's API requirements.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2019-02-12 15:40:53 +10:00
Peter Hutterer
5a925eaa84 xf86-input-libinput 0.28.2
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2019-02-04 13:14:11 +10:00
Peter Hutterer
e7eafa199e Handle scroll wheel events with a discrete of 0
The driver currently assumes that any wheel event has a non-zero discrete
value of 1. This is incorrect, it just hasn't triggered yet with any device.

With the hi-res scroll patches in place in the kernel and libinput, we may get
wheel events with a discrete value of 0. We assume that if this ever happens,
the device has some sensible click angle set so all we need to do is ignore
the discrete 0 events and wait for the first discrete event to come.

Also add an explanatory comment too to make it clear the calculation is only
done once.

Fixes #19

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2019-01-25 14:31:11 +10:00
Peter Hutterer
d13ab268bd Return the wheel scroll value instead of just the fraction
This is prep work for the hi-res work but right now, no real functional
changes. It does however fix a bug where we used the vertial scroll dist for
the horizontal wheel as well.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2019-01-24 08:29:48 +10:00
Peter Hutterer
347c78387e Split the scroll axis details up for easier extension
If we need more per-axis fields, it's easier to add this way.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2019-01-21 13:08:30 +10:00
Peter Hutterer
b63f7994dc conf: add an example snippet for how to assign options
Users still like to copy the whole file, potentially messing things up.
Let's put a warning into the file directly that this is less than ideal.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2019-01-07 16:29:51 +10:00
Alan Coopersmith
04f42d6e0f Update configure.ac bug URL for gitlab migration
Signed-off-by: Alan Coopersmith <alan.coopersmith@oracle.com>
2018-11-25 12:47:32 -08:00
Alan Coopersmith
5d341d1d6c Update README for gitlab migration
Signed-off-by: Alan Coopersmith <alan.coopersmith@oracle.com>
2018-11-18 11:48:07 -08:00
Peter Hutterer
4985de5ef3 Remove two dead assignments
Value stored but never read.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2018-10-15 15:30:55 +10:00
Peter Hutterer
e26fc3c66c xf86-input-libinput 0.28.1
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2018-10-15 09:36:36 +10:00
Peter Hutterer
a759610292 Use the seat slot, not the device slot for touch events
The device slot is per-device, so if we have more than one device we may get a
touch down event for a slot already in use.

Fixes https://gitlab.freedesktop.org/libinput/libinput/issues/153

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2018-10-04 11:47:46 +10:00
Peter Hutterer
21ff2ca7d1 Remove unused assignment
dev is our list iterator below, this is a dead assignment

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2018-07-19 15:58:06 +10:00
Peter Hutterer
c67f191d5b xf86-input-libinput 0.28.0
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2018-07-11 11:06:59 +10:00
Peter Hutterer
1978a2555b Minor whitespace fix
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2018-07-11 10:59:20 +10:00
Peter Hutterer
0909a1a765 draglock: fix memory overwrite during draglock parsing
Passing in the size of the array but using it as "number of elements" inside
the function. Rename a bunch of arguments to avoid this.

https://bugs.freedesktop.org/show_bug.cgi?id=107166

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2018-07-10 11:17:50 +10:00
Peter Hutterer
20bb8d6b9f Revert "Implement the custom acceleration curve options"
Custom pointer acceleration curves were reverted in libinput, so no point
having this code here.

This reverts commit d84e0035d1.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2018-05-23 08:14:23 +10:00
Peter Hutterer
1e88664d95 Use the libinput touch count to init the right number of touches
Initial version by Johannes Pointner <h4nn35.work@gmail.com>
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2018-05-02 13:59:00 +10:00
Peter Hutterer
d84e0035d1 Implement the custom acceleration curve options
One new property, and the existing accel profile gets extended to keep one
extra value. The new property libinput Accel Curve Points is a list of pairs
of points to be added to the acceleration curve.

libinput only supports adding points to the curve so we simply declare the
behavior as undefined when the curve is set multiple times. Also helps to
identify those that bother to read the man page before playing with random
driver values.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2018-04-20 14:04:25 +10:00
Peter Hutterer
6c75acfcdf Use xf86SetStrOption to check for string options
This one shows up in the log and marks it as used.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2018-04-20 13:34:23 +10:00
Peter Hutterer
eaf847be16 man: whitespace fixes in man page
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2018-04-17 15:11:12 +10:00
Peter Hutterer
d319092d55 man: fix formatting issue caused by invalid tag
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2018-04-17 13:52:33 +10:00
Peter Hutterer
18cc042e68 xf86-input-libinput 0.27.1
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2018-04-10 09:19:52 +10:00
Evangelos Foutras
0db82219bb Fix "left handed" property not set on all pointers
Remove conditional that prevents the LIBINPUT_PROP_LEFT_HANDED{,DEFAULT}
properties from being set on all pointer devices (only the first got it).
This appears to be a debugging left-over accidentally merged in
6d3bd4544a.

https://bugs.freedesktop.org/show_bug.cgi?id=105667

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2018-03-22 10:59:01 +10:00
Peter Hutterer
f93bc148d4 xf86-input-libinput 0.27.0
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2018-03-20 11:23:57 +10:00
Peter Hutterer
0d4b50fd6e man: note that we don't do /dev/input/by-id or /dev/input/by-path
For logind-setups we need to match the path libinput wants to open with the
Option Device path that the device has so we know when to return the
server-fd. This doesn't work for by-id or by-path because libinput resolves
those (through udev) to the actual eventX node so our paths look different
when they are the same device.

This could be fixed but since this is easy enough to work around with a
InputClass section and rather a niche case, it's not really worth the effort.

https://bugs.freedesktop.org/show_bug.cgi?id=105562

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
Reviewed-by: Adam Jackson <ajax@redhat.com>
2018-03-20 10:48:04 +10:00
Peter Hutterer
9d9f59fd4c Apply the capabilities checks on subdevices when applying the config
Properties are initialized on the correct devices only but on resume we'd just
blindly apply the config from our device. Depending on the resume order, this
would mean we'd apply a previously set config with a default config.

Example:
* pointer device with keyboard subdevice
* pointer device exports natural scrolling, keyboard device does not and
  remains at default (off)
* client enables natural scrolling on the pointer device
* VT switch away, VT switch back
* pointer device gets enabled first, enables natural scrolling on the
  libinput device
* keyboard device gets enabled second, resets to the default value

Reported-by: Yuxuan Shui <yshuiv7@gmail.com>
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
Tested-by: Yuxuan Shui <yshuiv7@gmail.com>
2018-02-21 09:53:12 +10:00
Peter Hutterer
7353481490 Split LibinputDeviceApplyConfig into helper functions
No functional changes
2018-02-02 14:25:44 +10:00
Peter Hutterer
6d3bd4544a Move the subdevice capabilities check into the properties
87f9fe3a6fafe60134c6's intention was to not create properties that a subdevice
doesn't have configuration options for (i.e. if you have a pointer+keyboard
device, don't expose tapping configuration on the keyboard subdevice).

The result was messy, the checker function had a confusing triple-negation and
some properties weren't checked - e.g. left-handed was allowed for touch/tablet
but not for pointer, dwt was allowed for any device.

Fix this by moving the check into the property init function directly and
inverting the helper function to be easier to read.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2018-02-02 14:25:31 +10:00
Peter Hutterer
2be6487de4 xf86-input-libinput 0.26.0
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2017-09-15 11:26:54 +10:00
Peter Hutterer
6ce3d0249d Post a motion event before a tablet button down
Not all clients update the pointer position correctly from the button events
(for historical reasons) so we need to send a motion event before the button
event that represents a tip state change.

https://bugs.freedesktop.org/show_bug.cgi?id=101588

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2017-08-17 15:20:29 +10:00
Peter Hutterer
87f9fe3a6f Only initialize properties that match capabilities on a subdevice
If a device is split into multiple subdevices, usually pointer+keyboard, we
initialized properties matching the libinput device on both devices. This
results in the keyboard having e.g. a Accel Speed or Left Handed settings even
though it cannot send any events of that type.

Filter by capabilities on the subdevice so we only get those properties that
match the subdevice's capabilities.

https://bugs.freedesktop.org/show_bug.cgi?id=100900

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2017-05-29 08:15:20 +10:00
Peter Hutterer
0c657e0dcf Update copyright years
because why not

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2017-05-18 14:03:06 +10:00
Niklas Haas
ac3574958f man: add missing documentation for Accel Profile
This seems to have been simply missing from 0163482e.

cf. https://bugs.freedesktop.org/show_bug.cgi?id=101017

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2017-05-15 11:41:46 +10:00
Martin Kepplinger
8772a593b4 Fix config comment description to match the config
Since the config matches on tablets too, update the describing comment
accordingly.

Signed-off-by: Martin Kepplinger <martin.kepplinger@ginzinger.com>
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2017-05-08 10:33:58 +10:00
Peter Hutterer
a80773a488 xf86-input-libinput 0.25.1
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2017-05-05 13:43:23 +10:00
Peter Hutterer
8bc694595d Post a motion event after proximity events
This patch splits the meat of xf86libinput_handle_tablet_axis into a helper
function xf86libinput_post_tablet_motion(), to be called right after we send
the proximity in event.

Clients that don't handle proximity (e.g. all XI2 clients) don't see the
coordinates we send along with the proximity events. And, for historical
reasons, they may not look at the coordinates in button events. So a device
that comes into proximity and immediately sends a tip down button event
doesn't send a motion event, causing the client to think the tip down was at
whatever the last known position was (before previous prox-out).

The practical effect is that when a user tries to draw a few dots, they end up
being connected to each other.

https://bugzilla.redhat.com/show_bug.cgi?id=1433755

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2017-03-22 11:14:15 +10:00
Peter Hutterer
153a7fc62f xf86-input-libinput 0.25.0
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2017-03-09 15:58:39 +10:00
Peter Hutterer
72fb6d304e test: fix a test failure on ppc64(le) and aarch64
Caused by different results in -O0 vs -O2. The resulting array differs only
slightly but the initial sequence has one extra zero. That triggers our
assert, no other compiler flag seem to be affecting this.

Compiled with -O0:
Breakpoint 1, test_nonzero_x_linear () at test-bezier.c:157
157			assert(bezier[x] > bezier[x-1]);
(gdb) p bezier
$6 = {0 <repeats 409 times>, 1, 2, 4, 5, 7, 9, 10, 12, 14, 15, 17, 19, 21, 22,

Compiled with -O2:
(gdb) p bezier
$1 = {0 <repeats 410 times>, 1, 3, 5, 7, 9, 10, 12, 14, 15, 17, 19, 20, 22,

Printing of the temporary numbers in the decasteljau function shows that a few
of them are off by one, e.g.
    408.530612/0.836735 with O0, but
    409.510204/0.836735 with O2
Note: these are not rounding errors caused by the code, the cast to int
happens afterwards.

Hack around this by allowing for one extra zero before we check that the rest
of the curve is ascending again.

https://bugs.freedesktop.org/show_bug.cgi?id=99992

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2017-02-28 15:27:33 +10:00
Peter Hutterer
aae2c8ad9a Open sysfs files directly instead of going through the server
Only use-case here are pad mode LEDs that now live in /sys/class/leds. Asking
the server to open them is pointless, the server only knows how to open Option
"Device". And since the LEDs are in sysfs we should have access to them
anyway, so no need for jumping through or hula-ing hoops.

xf86CloseSerial() works as intended as it's a slim wrapper around close(), so
we only have to worry about the open() path here.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2017-02-27 09:34:36 +10:00
Peter Hutterer
dafc296f2d Add streq() macro, replace strcmp instances with it
And why isn't this a thing in glibc yet

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
Reviewed-by: Eric Engestrom <eric.engestrom@imgtec.com>
2017-02-27 09:34:36 +10:00
Peter Hutterer
7c90f06d56 Update pad modes in a workproc, not during the input thread
Updating the property directly causes us to send events from the input thread
which has some "interesting" side effects like messing up the reply order or
just crashing the server.

Schedule a work proc instead and update it whenever the server is back in the
main thread.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2017-02-27 09:34:36 +10:00
Peter Hutterer
2eb5a2f0c0 xf86-input-libinput 0.24.0
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2017-02-09 16:16:34 +10:00
Peter Hutterer
19ceef972e Drop unnecessary function declaration
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2017-01-27 12:14:29 +10:00
Mihail Konev
07f30ea049 autogen: add default patch prefix
Signed-off-by: Mihail Konev <k.mvc@ya.ru>
2017-01-26 14:00:21 +10:00
Emil Velikov
6187ed0450 autogen.sh: use quoted string variables
Place quotes around the $srcdir, $ORIGDIR and $0 variables to prevent
fall-outs, when they contain space.

Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
Reviewed-by: Peter Hutterer <peter.hutterer@who-t.net>
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2017-01-26 11:26:20 +10:00
Peter Hutterer
974ab6b62b Add tablet tool area ratio property
By default, the X server maps the tablet axes to the available screen area.
When a tablet is mapped to the screen but has a different aspect ratio than
the screen, input data is skewed. Expose an area ratio property to map the
a subsection of the available tablet area into the desired ratio.

Differences to the wacom driver: there the x/y min/max values must be
specified manually and in device coordinates. For this driver we merely
provide the area ratio (e.g. 4:3) and let the driver work out the rest.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
Reviewed-by: Jason Gerecke <jason.gerecke@wacom.com>
2017-01-12 14:53:41 +10:00
Peter Hutterer
5d04707381 Implement stylus pressure curve support
Takes a 4-point cubic bezier curve as input and maps the pressure coordinates
to the values outlined by this curve. This is an extension of the current
implementation in the xf86-input-wacom driver which only allows the two center
control points to be modified.

Over the years a few users have noted that the wacom driver's pressure curve
makes it impossible to cap the pressure at a given value. Given our bezier
implementation here, it's effectively a freebie to add configurability of the
first and last control points. We do require all control points' x coordinates
to be in ascending order.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2017-01-04 09:57:57 +10:00
Peter Hutterer
f65a5c5022 Add a bezier curve implementation
Needed for the wacom stylus pressure curve

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2017-01-03 17:31:42 +10:00
Peter Hutterer
0dad7408fa Calculate the required scroll distance based on the angle
For a mouse with a click angle of 15 degrees things are unchanged. For devices
with angles less than 10, the current code scrolled way too fast. Because the
angle wasn't used anywhere, each tick would count as full scroll wheel event,
a slight movement of the wheel would thus scroll as much as a large movement
on a normal mouse.

Fix this by taking the actual click angle of the device into account. We
calculate some multiple of the angle that's close enough to the default 15
degrees of the wheel and then require that many click events to hit the full
scroll distance. For example, a mouse with a click angle of 3 degrees now
requires 5 clicks to trigger a full legacy scroll button event.

XI2.1 clients get the intermediate events (i.e. in this case five times
one-fifth of the scroll distance) and can thus scroll smoothly, or more
specifically in smaller events than usual.

https://bugs.freedesktop.org/show_bug.cgi?id=92772

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
Reviewed-by: Hans de Goede <hdegoede@redhat.com>
2017-01-03 15:16:21 +10:00
Peter Hutterer
ea02578a4e Move axis value calculation into a helper function
The only difference here is the axis number.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
Reviewed-by: Hans de Goede <hdegoede@redhat.com>
2017-01-03 15:16:21 +10:00
Peter Hutterer
2ceb2e1b18 Add a comment regarding scroll dist default values
Changed this during development because I forgot that the value actually
matters (for touchpads anyway).

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
Reviewed-by: Hans de Goede <hdegoede@redhat.com>
2017-01-03 15:16:21 +10:00
Peter Hutterer
f47f78eb0b Ignore LED updates for disabled devices
If an XKB AccessX timeout is set and a VT switch is triggered, the
AccessXTimeoutExpire function may be called after the device has already been
disabled. This can cause a null-pointer dereference as our shared libinput
device may have been released by then.

In the legacy drivers this would've simply caused a write to an invalid fd
(-1), not a crash. Here we need to be more careful.

https://bugs.freedesktop.org/show_bug.cgi?id=98464

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
Reviewed-by: Hans de Goede <hdegoede@redhat.com>
2016-12-21 07:58:26 +10:00
Peter Hutterer
1c3ce3ce3c xf86-input-libinput 0.23.0
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2016-12-12 14:54:00 +10:00
Peter Hutterer
4d481ea7c8 Fix default scroll button number
Was exposing the evdev code rather than the xorg code.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
Reviewed-by: Hans de Goede <hdegoede@redhat.com>
2016-12-06 06:59:39 +10:00
Peter Hutterer
72bac84df9 If the parent libinput_device is unavailable, create a new one
The parent device ref's the libinput device during pre_init and unref's it
during DEVICE_INIT, so the copy is lost. During DEVICE_ON, the libinput device
is re-added and ref'd, this one stays around now. But the takeaway is: unless
the device is enabled, no libinput device reference is available.

If a device is a mixed pointer + keyboard device, a subdevice is created
during a WorkProc. The subdevice relied on the parent's libinput_device being
available and didn't even check for it. This WorkProc usually runs after
the parent's DEVICE_ON, so in most cases all is well.

But when running without logind and the server is vt-switched away, the parent
device only runs PreInit and DEVICE_INIT but never DEVICE_ON, causing the
subdevice to burn, crash, and generally fail horribly when it dereferences the
parent's libinput device.

Fix this because we have global warming already and don't need to burn more
things and also because it's considered bad user experience to have the
server crash. The simple fix is to check the parent device first and if it is
unavailable, create a new one because it will end up disabled as well anyway,
so the ref goes away as well. The use-case where the parent somehow gets
disabled but the subdevice doesn't is a bit too niche to worry about.

This doesn't happen with logind because in that case we don't get a usable fd
while VT-switched away, so we can't even run PreInit and never get this far
(see the paused fd handling in the xfree86 code for that). It can be
reproduced by setting AutoEnableDevices off, but why would you do that,
seriously.

https://bugs.freedesktop.org/show_bug.cgi?id=97117

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
Reviewed-by: Hans de Goede <hdegoede@redhat.com>
2016-11-19 16:24:23 +10:00
Peter Hutterer
0b073d90e6 Link the left-handed property between the tools
The property is tablet-wide, not just per tool. So when one tool is updated,
run through all other devices that share the same underlying device.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
Reviewed-by: Hans de Goede <hdegoede@redhat.com>
2016-11-14 13:29:30 +10:00
Peter Hutterer
669fbb0985 Drop indentation for matrix handling
Exit early if the string is NULL to reduce indentation. No functional changes.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2016-11-01 10:42:19 +10:00
Peter Hutterer
c4f0a9bcb8 conf: match against tablets too
Now that we sort below the xf86-input-wacom driver anyway, there's no good
reason to ignore tablets anymore.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2016-11-01 10:30:14 +10:00
Peter Hutterer
a61e156326 man: sort the options and properties alphabetically
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2016-10-27 14:25:09 +10:00
Peter Hutterer
552cbaf466 Don't init the AccelSpeed/LeftHanded properties on the base tablet device
This device never sends events, no point in exposing these options

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
Reviewed-by: Eric Engestrom <eric.engestrom@imgtec.com>
2016-10-27 10:28:08 +10:00
Peter Hutterer
bc91d337d7 Fix potential NULL pointer dereferencing
Found by coverity.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2016-10-21 07:51:51 +10:00
Peter Hutterer
c8d2293873 Remove superfluous check for next being NULL
is_libinput_device(next) causes a dereference of next anyway, so this cannot
ever be NULL.

Besides, if next ends up as NULL that means we have lost count of how many
remaining devices use libinput, so we have other issues.

Found by coverity.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2016-10-20 08:38:24 +10:00
Peter Hutterer
a7014aa8c6 Remove two unused variables
They were never used anyway

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2016-10-20 08:28:26 +10:00
Peter Hutterer
bf7fffde52 Don't init the horiz scroll property on non-pointer devices
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2016-10-19 11:42:57 +10:00
Peter Hutterer
7282177756 xf86-input-libinput 0.22.0
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2016-10-19 10:55:12 +10:00
Peter Hutterer
1dd61abf7e Wrap the input_lock calls into ifdefs
Missing from a790ff35f9

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2016-10-19 10:46:22 +10:00
Peter Hutterer
c80954386d xf86-input-libinput 0.21.0
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2016-10-19 09:24:37 +10:00
Peter Hutterer
a790ff35f9 Swap the registered input device on DEVICE_OFF when needed
If we don't swap out the pInfo previously passed to xf86AddEnabledDevice(),
the thread eventually calls read_input on a struct that has been deleted.
Avoid this by swapping out the to-be-destroyed pInfo with the first one we
find.

Reproducer: sudo udevadm trigger --type=devices --action=add

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
Reviewed-by: Hans de Goede <hdegoede@redhat.com>
2016-10-19 07:56:46 +10:00
Peter Hutterer
6318ac420b Fix tap button map option handling
Copy/paste error

https://bugs.freedesktop.org/show_bug.cgi?id=97989

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2016-10-14 13:34:56 +10:00
Peter Hutterer
cd02040a5d xf86-input-libinput 0.20.0
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2016-09-30 17:01:33 +10:00
Michel Dänzer
0cfe9ec6c2 Fix --with-xorg-conf-dir default value
If --prefix isn't specified on the command line, $prefix contains "NONE"
at this point, not the default prefix value. So make install would
attempt to install the xorg.conf.d snippet to
${DESTDIR}NONE/share/X11/xorg.conf.d/.

Avoid this by leaving ${prefix} verbatim in the default value, to be
resolved by make.

Signed-off-by: Michel Dänzer <michel.daenzer@amd.com>
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2016-09-21 16:29:01 +10:00
Keith Packard
b87d2530db Initializing strip association with wrong index
This looks like a cut&paste coding error to me, and it generated a
compiler warning about possibly uninitialized value.

Signed-off-by: Keith Packard <keithp@keithp.com>
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2016-09-19 09:51:00 +10:00
Peter Hutterer
2f1df46ba9 Correct the horizontal scroll property name
Clear typo. Not bothering to be backwards compatible here, anything that uses
the #define will update on rebuild, anyone using the string directly should've
told me about the typo...

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
Reviewed-by: Hans de Goede <hdegoede@redhat.com>
2016-09-13 16:49:33 +10:00
Peter Hutterer
fa69bb1bc2 Always delay hotplugging subdevices
Avoid creating new devices from within the input thread which was the case for
tablet tools. It requires a lot more care about locking and has a potential to
mess up things.

Instead, schedule a WorkProc and buffer all events until we have the device
created. Once that's done, replay the event sequence so far. If the device
comes into proximity and out again before we manage to create the new device
we just ditch the whole sequence and wait for the next proximity in.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2016-09-09 16:34:05 +10:00
Peter Hutterer
af4fa36884 Add support for configurable tap button mapping
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
Reviewed-by: Hans de Goede <hdegoede@redhat.com>
2016-09-07 14:41:59 +10:00
Peter Hutterer
a5b3c209fc Add support for the rotation configuration
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2016-08-31 11:11:37 +10:00
Peter Hutterer
0f7c5ed02d conf: drop libinput to below the other drivers
This is the continuation of 3f569ec493, dropping libinput below the remaining
drivers. Wacom and synaptics already sort higher anyway (see wacom commit
0da5cd54 and synaptics commit 59e5db025). evdev remains the catchall
basic fallback driver and is overwritten by libinput. The two drivers affected
by this patch are joystick and vmmouse.

joystick is a niche driver and drives devices libinput doesn't handle anyway
so there is no need to override. If a user installs it, presumably it is to
use it.

vmmouse is a niche driver and does not assign itself anymore for newer kernel
drivers (see vmmouse commit 576e8123 from Oct 2014). So if vmmouse is
installed it can safely sort higher than libinput.

Note: this is upstream behavior, distributions have to work out the wanted
behavior themselves by renaming the config snippets accordingly.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
Reviewed-by: Hans de Goede <hdegoede@redhat.com>
2016-08-31 08:33:19 +10:00
Peter Hutterer
0168716fa1 Whitespace fix
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2016-08-19 11:35:08 +10:00
Peter Hutterer
b508c54fa0 Comment two read-only properties as such
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2016-08-16 09:35:27 +10:00
Peter Hutterer
d43e514430 Expose tablet pad modes as properties
There is not good wire protocol for pad modes so instead we just export the
information via properties. One property to tell us how many groups and how
many modes each group has. One property for the current mode of each group.
And three properties to tell us which group each button, ring and strip is in.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2016-08-16 07:49:49 +10:00
Peter Hutterer
5f2fff3c24 Ensure parent devices are actual parent devices
The list returned by xf86FirstLocalDevice() includes our own device. If the
parent device is removed before the hotplug callback is invoked, the first
match with the same shared-device ID is our own device (or potentially another
subdevice on the same already-removed parent). Avoid this by making sure the
matched device is actually a parent device.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
Reviewed-by: Hans de Goede <hdegoede@redhat.com>
Tested-by: Keith Packard <keithp@keithp.com>
2016-08-16 07:49:49 +10:00
Peter Hutterer
116cddba69 Bail out of PreInit if the parent driver data is NULL
If the parent device is removed before the WorkProc is called, the private
data is NULL.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
Reviewed-by: Hans de Goede <hdegoede@redhat.com>
2016-08-12 11:34:35 +10:00
Peter Hutterer
fb4847d243 Block input events while creating the virtual subdevices
If an event comes in halfway through the new device creation we read it from
libinput's epollfd but depending on the setup stage the new device may not be
ready yet.

https://bugs.freedesktop.org/show_bug.cgi?id=97117

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
Reviewed-by: Hans de Goede <hdegoede@redhat.com>
2016-08-12 11:34:35 +10:00
Peter Hutterer
ce85b11e4c Fix button offset for tablet pad buttons
4-7 is reserved for scroll buttons, as usual

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2016-07-08 13:02:32 +10:00
Eric Engestrom
77a47a795c man: fix a couple typos
Signed-off-by: Eric Engestrom <eric@engestrom.ch>
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2016-07-04 07:33:34 +10:00
Peter Hutterer
ae4f0a8d72 Init touch x/y axis labels as MT axis labels
https://bugs.freedesktop.org/show_bug.cgi?id=96481

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
Reviewed-by: Hans de Goede <hdegoede@redhat.com>
2016-06-14 12:15:48 +10:00
Keith Packard
289de5be15 Use xf86AddEnabledDevice instead of AddEnabledDevice when threaded [v3]
libinput can't run at SIGIO time, so it has been using
AddEnabledDevice to run in non-signal context.

Threaded input runs all input in non-signal context, so we want to use
xf86AddEnabledDevice at last.

v2: use XINPUT ABI version check instead of testing for presence of
    AddEnabledDevice, which can't get removed from the server until
    a few more patches past the threaded input change are merged.

v3: remove reference to XI86_SIGNAL_IO, which was presumably
    a planned change to the xf86AddEnabledDevice path to make that
    not use SIGIO.

Signed-off-by: Keith Packard <keithp@keithp.com>
Tested-by: Michel Dänzer <michel.daenzer@amd.com>
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2016-05-30 18:21:33 +10:00
Peter Hutterer
ceea2bb8ba Change some fixed floats to decimal notation
Just to make it more obvious we're using floats/doubles here.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2016-05-30 15:28:47 +10:00
Peter Hutterer
d8aef83834 Fix proximity events
Two bugs caused proximity events to be discarded. First, on proximity out
posting through pDev would be discarded because pDev is the parent device that
we use as a base for hotplugging the real devices for each tool from. That
device never sends events though, doing so will see the event discarded in the
server.

Second, if the tool already exists don't just exit, send the proximity event
first. To unify the three paths where we do send the events simply move them
down to the exit phase of the function.

https://bugs.freedesktop.org/show_bug.cgi?id=95484

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2016-05-23 14:15:22 +10:00
Peter Hutterer
34b6ed980f Add tablet pad support
Modelled to be mostly compatible to the xf86-input-wacom driver behavior. The
pad gets 7 axes, the first three of which are mute and the others are always
available but obviously only send events when the axis is there.

The strip axes are incompatible, the wacom driver merely forwards the device
events (which are a bitshifted value), libinput normalizes it and we just
expand this back into an integer range. Let's see how we go with this.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2016-05-09 12:06:24 +10:00
Peter Hutterer
ce85432f41 Discard buttons >= 256
https://bugs.freedesktop.org/show_bug.cgi?id=95295

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2016-05-09 08:15:43 +10:00
Peter Hutterer
181ea654dd Fix potential use of uninitialized values
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2016-04-28 14:41:43 +10:00
Peter Hutterer
f9b6fa21df xf86-input-libinput 0.19.0
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2016-04-28 13:43:49 +10:00
Peter Hutterer
3f569ec493 conf: rename to 60-libinput.conf
60 sorts higher than the other drivers (evdev has 10, synaptics, wacom and
others have 50) so we keep the same order.

This is part of a two-step solution, the other half is renaming the
xf86-input-wacom's config snippet to sort higher than libinput's.

Currently libinput picks up devices that are (for now) destined to the wacom
driver. Since the wacom driver is more of a leaf package than libinput, the
best option here is to make the wacom driver sort higher and let users
uninstall it when not needed. To avoid crowding the 90-* space where users
usually have custom config snippets, drop libinput down to 60 and bump wacom
up.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
Acked-by: Jason Gerecke <jason.gerecke@wacom.com>
2016-04-28 12:29:20 +10:00
Stanislav Ochotnicky
602bb8eefa Fix implicit declaration of function 'xf86Msg' in xf86libinput.c
Addition of xf86.h header fixes compilation issues in some cases.

See: https://bugs.gentoo.org/show_bug.cgi?id=560970

Signed-off-by: Stanislav Ochotnicky <sochotnicky@redhat.com>
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2016-04-08 15:37:04 +10:00
Peter Hutterer
13726f404f xf86-input-libinput 0.18.0
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2016-04-07 13:31:28 +10:00
Peter Hutterer
5e7ee73fe2 Support art pen rotation
The art pen is a normal pen, but it does provide a rotation axis.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2016-02-29 14:34:43 +10:00
Peter Hutterer
4564a92d59 Support the mouse/lens tool
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2016-02-29 14:34:43 +10:00
Peter Hutterer
0c2bcd0358 Add support for the airbrush tool axes
Same axes as the pen, but axis number 6 is the wheel (which really is a
slider)

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2016-02-29 14:34:43 +10:00
Peter Hutterer
b4541e4dff Add support for tablet tools
Use two new internal capabilities, CAP_TABLET and CAP_TABLET_TOOL. If a
libinput tablet device is added, add an X device without any classes. This
device will not send events, but once we have pad support in libinput we
may be able to this the pad device.

When a tool comes into proximity, create a new X device for that serial number
and start sending events through it. Since the X device only represents a
single serial number/type combination, some of the wacom-specific
configuration options fall away. This only matters in the case of multiple
tools, in which case a per-tool configuration is preferable anyway, so we
don't lose anything here.

Gesture support only applied to the touch parts on the device, we don't
deal with this here specifically - that event node is handled by libinput as
touchscreen or touchpad.

This already works with GIMP and clients that don't rely on any
wacom-driver-specific properties. Configuration clients like
gnome-settings-daemon will need to change to handle new properties, to be
added as we go along.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2016-02-29 14:34:43 +10:00
Peter Hutterer
8136113139 xf86-input-libinput 0.17.0
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2016-02-26 15:57:48 +10:00
Peter Hutterer
202eb68dc0 Fix compiler warnings about missing tablet event cases
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2016-01-28 15:02:54 +10:00
Peter Hutterer
e8f5394b07 Add property/option for enabling/disabling tap-n-drag
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
Reviewed-by: Hans de Goede <hdegoede@redhat.com>
2016-01-28 15:01:39 +10:00
Peter Hutterer
20f5269a29 Fix default tapping drack lock property value
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2016-01-27 11:13:07 +10:00
Peter Hutterer
3dacb28b20 Allow hotplugging a device immediately
This splits the hotplugging code up so we can use it through a callback but
also as an immediate call that gives us back the device just hotplugged. Also
added is the ability to add extra options to the device.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2016-01-05 11:16:19 +10:00
Peter Hutterer
db8e73141c Change creating subdevices to something more generic
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2016-01-05 11:16:19 +10:00
Peter Hutterer
0d1851a000 xf86-input-libinput 0.16.0
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2015-12-23 13:53:38 +10:00
Peter Hutterer
ad8483b913 Drain the fd after opening
Make sure we don't send any events that may have been enqueued before we
initialized ourselves. Specifically, if we're using systemd-logind the fd
remains open when we disable/enable the device, allowing events to queue up on
the fd. These events are then replayed once the device is re-opened.

This is not the case when VT-switching, in that case logind closes the fd for
us.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
Reviewed-by: Keith Packard <keithp@keithp.com>
2015-12-17 11:23:28 +10:00
Peter Hutterer
1f43f3921f Split mixed pointer/keyboard devices into two separate X devices
The server struggles with devices that are both, the protocol (especially XI2)
requires a fairly strict separation of pointer vs keyboard devices. Though the
server has a couple of hacks to route events correctly, mixed
devices still experience bugs like [1].

Instead of advertising the device as a single mixed device, split the device
into two X devices, one with only a pointer/touch component, one with only a
keyboard component. This ensures that the device is effectively attached to
both the VCP and the VCK, something the XI2 protocol doesn't really allow.

This patch drops the keyboard capability on a mixed device, duplicates the
input options and attributes and queues a NewInputDeviceRequest call. The new
device only has the keyboard capability but is otherwise unchanged. The
wacom driver has used this approach for years.

The WorkProc is necessary to avoid inconsistent state, the server doesn't
handle a NewInputDeviceRequest during PreInit well.

The approach:
During pre-init we create a struct xf86libinput_device with the
libinput_device and a unique ID. The child device has that ID added to the
options and will look for the other device during its pre-init. The two
devices then share the xf86libinput_device struct.

We only have a single epollfd for all devices  and the server calls read_input
on the first device in the list with the epollfd as pInfo->fd. That shared
struct is used as the userdata on the libinput_device we get back from the
event, and each device is in the xorg_list device_list of that shared struct.
We loop through those to find the ones with the right capabilities and
post the event through that device.

Since devices can be enabled and disabled independently, the rest of the code
makes sure that we only ever add the device to libinput when the first shared
device is enabled, and remove it accordingly.

The server uses pInfo->major/minor to detect if another device is using the
same path for a logind-controlled fd. If so, it reuses that device's
pInfo->fd and sets the "fd" option to that value. That pInfo->fd is the
libinput epollfd though, not the actual device fd.

This doesn't matter for us, since we manage the fds largely ourselves and the
pInfo->fd we use is the epollfd anyway. On unplug however, the udev code
triggers a device removal for all devices, including the duplicated ones. When
we disable device, we restore the pInfo->fd from the "fd" option so that the
server can request logind to close the fd.

That only works if the "fd" option is correct, otherwise the server asks
logind to close the epollfd and everyone is unhappy.

[1] https://bugs.freedesktop.org/show_bug.cgi?id=49950

https://bugs.freedesktop.org/show_bug.cgi?id=92896

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
Reviewed-by: Hans de Goede <hdegoede@redhat.com>
2015-11-23 07:26:46 +10:00
Peter Hutterer
83dfd31ec8 Revert "Split mixed pointer/keyboard devices into two separate X devices"
When using logind, this causes the server to hang when a split device is
unplugged. The reason is mostly in the server, when open the device by
requesting the logind fd, the server loops through the device list to check if
any other device has the same major/minor (see systemd_logind_take_fd()) and
returns the pInfo->fd for that device instead of requesting the fd again from
logind.

For libinput devices, the pInfo->fd is the epollfd, not the actual device, so
our second device gets the epollfd assigned. When the devices are removed, we
keep the device fd open and release the epollfd through logind.

This reverts commit c943739a2b.
2015-11-20 10:51:38 +10:00
Peter Hutterer
c943739a2b Split mixed pointer/keyboard devices into two separate X devices
The server struggles with devices that are both, the protocol (especially XI2)
requires a fairly strict separation of pointer vs keyboard devices. Though the
server has a couple of hacks to route events correctly, mixed
devices still experience bugs like [1].

Instead of advertising the device as a single mixed device, split the device
into two X devices, one with only a pointer/touch component, one with only a
keyboard component. This ensures that the device is effectively attached to
both the VCP and the VCK, something the XI2 protocol doesn't really allow.

This patch drops the keyboard capability on a mixed device, duplicates the
input options and attributes and queues a NewInputDeviceRequest call. The new
device only has the keyboard capability but is otherwise unchanged. The
wacom driver has used this approach for years.

The WorkProc is necessary to avoid inconsistent state, the server doesn't
handle a NewInputDeviceRequest during PreInit well.

The approach:
During pre-init we create a struct xf86libinput_device with the
libinput_device and a unique ID. The child device has that ID added to the
options and will look for the other device during its pre-init. The two
devices then share the xf86libinput_device struct.

We only have a single epollfd for all devices  and the server calls read_input
on the first device in the list with the epollfd as pInfo->fd. That shared
struct is used as the userdata on the libinput_device we get back from the
event, and each device is in the xorg_list device_list of that shared struct.
We loop through those to find the ones with the right capabilities and
post the event through that device.

Since devices can be enabled and disabled independently, the rest of the code
makes sure that we only ever add the device to libinput when the first shared
device is enabled, and remove it accordingly.

[1] https://bugs.freedesktop.org/show_bug.cgi?id=49950

https://bugs.freedesktop.org/show_bug.cgi?id=92896

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
Reviewed-by: Hans de Goede <hdegoede@redhat.com>
2015-11-20 08:45:40 +10:00
Peter Hutterer
a72e96538a Add a helper function for the driver context initialization
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
Reviewed-by: Hans de Goede <hdegoede@redhat.com>
2015-11-18 07:00:29 +10:00
Peter Hutterer
b1a9bea607 Copy the device capabilities to the X driver struct
And use those copied caps instead of the direct device capability calls.

No functional changes at this point, this is preparation work for selectively
disabling capabilities on a device.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
Reviewed-by: Hans de Goede <hdegoede@redhat.com>
2015-11-18 07:00:29 +10:00
Peter Hutterer
a6aad69a97 Split type_name detection out into a helper function
No functional changes

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
Reviewed-by: Hans de Goede <hdegoede@redhat.com>
2015-11-18 07:00:29 +10:00
Peter Hutterer
6fa5f30129 Unref the libinput context on pre_init failure
A device that fails pre_init has a ref to the libinput context but may not
have a pInfo->private. For those devices we never call libinput_unref() and
the libinput struct never gets freed.

Thus if at least one device didn't pass pre_init, we never cleaned up after
ourselves.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
Reviewed-by: Hans de Goede <hdegoede@redhat.com>
2015-11-18 07:00:01 +10:00
Peter Hutterer
c53dde1a50 Don't fail DEVICE_CLOSE
We're not doing anything here, so no reason to fail.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2015-11-13 14:33:02 +10:00
Peter Hutterer
d7331f6e34 Remove unused server_fds list
Obsolete as of 353c52f2be

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2015-11-13 14:32:31 +10:00
Peter Hutterer
fb56f6d7a5 Set the device to NULL after unref
No real effect in the current code, but it adds a bit of safety.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2015-11-13 10:02:16 +10:00
Peter Hutterer
c8861d2a2f Plug two memory leaks
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2015-11-12 10:17:39 +10:00
Peter Hutterer
44f4b2ed70 xf86-input-libinput 0.15.0
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2015-10-27 17:08:59 +10:00
Peter Hutterer
0163482e22 Add property support for the accel profiles
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2015-10-26 10:00:57 +10:00
Peter Hutterer
80c356f58f conf: install the libinput xorg.conf.d snippet
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2015-09-18 00:29:20 +10:00
Peter Hutterer
1645a79c34 conf: don't hook onto tablets and joysticks
If we install the config file by default, we shouldn't use libinput for
devices we know we can't handle.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2015-09-18 00:29:17 +10:00
Peter Hutterer
b7f8db12a3 conf: rename 99-libinput.conf to 90-libinput.conf
This way it still sorts after the usual subjects, but it's easier to stack
extra config in afterwards.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2015-09-18 00:27:43 +10:00
Peter Hutterer
6abd341279 Fix invalid pointer passed to the properties
Takes a void*, not a void**

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2015-09-03 17:42:20 +10:00
Peter Hutterer
19b42f242d Move the read-only properties into the same condition
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2015-09-03 17:33:40 +10:00
Peter Hutterer
f48b64c8cd xf86-input-libinput 0.14.0
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2015-08-31 13:27:09 +10:00
Yomi0
b55239ef25 Fix typo in libinput.man
Correct typo. Draging to dragging.
2015-08-30 23:14:25 -04:00
Peter Hutterer
9563334dda Use xf86OpenSerial instead of a direct open() call
This will transparently handle server-side fds for us.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
Reviewed-by: Hans de Goede <hdegoede@redhat.com>
Reviewed-by: Martin Pieuchot <mpi@openbsd.org>
2015-08-17 09:18:01 +10:00
Peter Hutterer
353c52f2be Revamp server fd opening
The server already stores the server-fd in the options, so we only need to run
through the list of current devices, find a match and extract that fd from the
options. Less magic in our driver and it gives us a pInfo handle in
open_restricted which we'll can use for xf86OpenSerial().

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
Reviewed-by: Hans de Goede <hdegoede@redhat.com>
Reviewed-by: Martin Pieuchot <mpi@openbsd.org>
2015-08-17 09:16:42 +10:00
Peter Hutterer
f139f14249 Add an option to disable horizontal scrolling
libinput always has horizontal scrolling enabled and punts the decision when
to scroll horizontally to the toolkit/widget. This is the better approach, but
while we have a stack that's not ready for that, and in the X case likely
never will be fully ready provide an option to disable horizontal scrolling.

This option doesn't really disable horizontal scrolling, it merely discards
any horizontal scroll delta. libinput will still think it's scrolling.

https://bugs.freedesktop.org/show_bug.cgi?id=91589

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
Reviewed-by: Hans de Goede <hdegoede@redhat.com>
2015-08-13 07:53:19 +10:00
Peter Hutterer
e3a888c3ab Add drag lock support
First, why is this here and not in libinput: drag lock should be implemented
in the compositor (not in libinput) so it can provide feedback when it
activates and grouped in with other accessibility features. That will work for
Wayland but in X the compositor cannot filter button events - only the server
and the drivers can.

This patch adds mostly the same functionality that evdev provides with two
options on how it works:
* a single button number configures the given button to lock the next button
  pressed in a logically down state until a press+ release of that same button
  again
* a set of button number pairs configures each button with the to-be-locked
  logical button, i.e. a pair of "1 3" will hold 3 logically down after a
  button 1 press

The property and the xorg.conf options take the same configuration as the
evdev driver (though the property has a different prefix, libinput instead of
Evdev).

The behavior difference to evdev is in how releases are handled, evdev sends
the release on the second button press event, this implementation sends the
release on the second release event.

https://bugs.freedesktop.org/show_bug.cgi?id=85577

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
Reviewed-by: Hans de Goede <hdegoede@redhat.com>
2015-08-13 07:52:48 +10:00
Martin Pieuchot
cd61ddb040 Remove unneeded header, epoll(7) interface is not directly used.
Signed-off-by: Martin Pieuchot <mpi@openbsd.org>
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2015-08-12 10:16:11 +10:00
Martin Pieuchot
a199880057 Rename a local variable to not shadow the BSD strmode(3) function.
Signed-off-by: Martin Pieuchot <mpi@openbsd.org>
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2015-08-12 10:16:01 +10:00
Peter Hutterer
cc57eecd72 gitignore: add patterns for automake test suite and misc other bits
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2015-08-11 15:06:43 +10:00
Peter Hutterer
fe58cff48b Rename main source file to x86libinput.c
To avoid conflict and confusion with libinput's sources. This was originally
triggered by needing a header file for the driver which cannot be named
libinput.h. That need went away after other refacturing, but we might as well
rename it now, sooner or later we'll need a xf86libinput.h file.

Can't do much about the libinput-properties header though, not worth breaking
other projects and it's namespaced into /usr/include/xorg anyway.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2015-08-11 15:05:29 +10:00
Peter Hutterer
4b2bed6912 xf86-input-libinput 0.13.0
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2015-08-04 17:08:22 +10:00
Stephen Chandler Paul
223be9f62b Add a property for Disable While Typing
Signed-off-by: Stephen Chandler Paul <cpaul@redhat.com>
Reviewed-by: Peter Hutterer <peter.hutterer@who-t.net>
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2015-08-04 14:14:48 +10:00
Peter Hutterer
d3ee745a24 man: minor man page improvements
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2015-07-21 11:21:47 +10:00
Peter Hutterer
b550b70a00 Fix compiler warnings about touchpad gestures
We don't do anything with them though.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2015-07-21 11:16:06 +10:00
Peter Hutterer
254b1f27a0 xf86-input-libinput 0.12.0
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2015-07-14 16:18:38 +10:00
Peter Hutterer
bfedf7dbac Add a property for tap drag lock
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
Reviewed-by: Hans de Goede <hdegoede@redhat.com>
2015-07-09 11:08:23 +10:00
Peter Hutterer
9c5cf97143 Support buttons > BTN_BACK on mice
https://bugzilla.redhat.com/show_bug.cgi?id=1230945

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2015-06-15 10:20:18 +10:00
30 changed files with 10139 additions and 2590 deletions

17
.editorconfig Normal file
View File

@@ -0,0 +1,17 @@
# https://editorconfig.org/
root = true
[*]
charset = utf-8
end_of_line = lf
trim_trailing_whitespace = true
insert_final_newline = true
[*.{c,h}]
indent_size = 8
indent_style = tab
[{meson.build,meson_options.txt}]
indent_size = 8
indent_style = tab

13
.gitignore vendored
View File

@@ -71,8 +71,17 @@ core
*.tar.bz2
*.tar.gz
#
# Add & Override patterns for xf86-input-libinput
# Add & Override patterns for xf86-input-libinput
#
# Edit the following section as needed
# For example, !report.pc overrides *.pc. See 'man gitignore'
#
#
*.log
*.trs
*.swp
*.announce
*.sig
test-driver
tags
.vimdir
test/test-bezier

83
.gitlab-ci.yml Normal file
View File

@@ -0,0 +1,83 @@
# vim: set expandtab shiftwidth=2 tabstop=8 textwidth=0 filetype=yaml:
#
# This CI uses the freedesktop.org ci-templates.
# Please see the ci-templates documentation for details:
# https://freedesktop.pages.freedesktop.org/ci-templates/
.templates_sha: &template_sha fb9d50ccb3cbbb4c6dc5f9ef53a0ad3cb0d8a177
include:
- project: 'freedesktop/ci-templates'
ref: *template_sha
file: '/templates/fedora.yml'
- project: 'freedesktop/ci-templates'
ref: *template_sha
file: '/templates/ci-fairy.yml'
- template: Security/SAST.gitlab-ci.yml
variables:
FDO_UPSTREAM_REPO: xorg/driver/xf86-input-libinput
stages:
- containers
- build
- test
.fedora:
variables:
FDO_DISTRIBUTION_VERSION: 43
FDO_DISTRIBUTION_PACKAGES: 'git autoconf automake libtool make xorg-x11-server-devel libudev-devel libevdev-devel libinput-devel xorg-x11-util-macros diffutils'
FDO_DISTRIBUTION_EXEC: 'env FDO_CI_CONCURRENT=${FDO_CI_CONCURRENT} bash .gitlab-ci/fedora-install.sh'
FDO_DISTRIBUTION_TAG: '2025-10-24.0'
fedora@container_build:
extends:
- .fedora
- .fdo.container-build@fedora
stage: containers
variables:
GIT_STRATEGY: none
.default_build:
stage: build
script:
- mkdir _builddir _inst
- pushd _builddir > /dev/null
- ../autogen.sh --prefix=$(realpath ../_inst) --disable-silent-rules
- make && make check
- make install
- popd > /dev/null
artifacts:
name: "automake-logs-$CI_JOB_NAME"
when: always
expire_in: 1 week
paths:
- _builddir/config.log
fedora@default-build:
extends:
- .fedora
- .fdo.distribution-image@fedora
- .default_build
#
# Verify that commit messages are as expected
#
check-commits:
extends:
- .fdo.ci-fairy
stage: test
script:
- ci-fairy check-commits --junit-xml=results.xml
except:
- master@xorg/driver/xf86-input-libinput
variables:
GIT_DEPTH: 100
artifacts:
reports:
junit: results.xml
allow_failure: true

9
.gitlab-ci/fedora-install.sh Executable file
View File

@@ -0,0 +1,9 @@
#!/bin/bash
# we require at least inputproto >= 2.3.99.1 which has been released in xorgproto 2021.5
git clone https://gitlab.freedesktop.org/xorg/proto/xorgproto.git --depth 1 --branch=xorgproto-2021.5
pushd xorgproto
./autogen.sh
make -j${FDO_CI_CONCURRENT:-4} install
popd
rm -rf xorgproto

36
COPYING
View File

@@ -1,20 +1,20 @@
Copyright © 2014 Red Hat, Inc.
SPDX-License-Identifier: MIT
Permission to use, copy, modify, distribute, and sell this software
and its documentation for any purpose is hereby granted without
fee, provided that the above copyright notice appear in all copies
and that both that copyright notice and this permission notice
appear in supporting documentation, and that the name of the authors
not be used in advertising or publicity pertaining to distribution of the
software without specific, written prior permission. The authors make no
representations about the suitability of this software for any
purpose. It is provided "as is" without express or implied
warranty.
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 AUTHORS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN
NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY SPECIAL, INDIRECT OR
CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS
OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
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.

View File

@@ -21,12 +21,14 @@
DISTCHECK_CONFIGURE_FLAGS = --with-sdkdir='$${includedir}/xorg'
SUBDIRS = src include man
SUBDIRS = src include man test
MAINTAINERCLEANFILES = ChangeLog INSTALL
pkgconfigdir = $(libdir)/pkgconfig
pkgconfig_DATA = xorg-libinput.pc
dist_xorgconf_DATA = conf/40-libinput.conf
.PHONY: ChangeLog INSTALL
INSTALL:
@@ -37,4 +39,4 @@ ChangeLog:
dist-hook: ChangeLog INSTALL
EXTRA_DIST = conf/99-libinput.conf README.md
EXTRA_DIST = README.md

View File

@@ -2,7 +2,7 @@ xf86-input-libinput - a libinput-based X driver
===============================================
The official repository for this driver is
http://cgit.freedesktop.org/xorg/driver/xf86-input-libinput/
https://gitlab.freedesktop.org/xorg/driver/xf86-input-libinput
This is an X driver based on libinput. It is a thin wrapper around libinput,
so while it does provide all features that libinput supports it does little
@@ -20,10 +20,10 @@ xorg-x11-server-devel package or similar) and libinput (check your
distribution for libinput-devel or similar).
To get libinput from source, see:
http://www.freedesktop.org/wiki/Software/libinput/
https://www.freedesktop.org/wiki/Software/libinput/
To build the X server from source:
http://www.x.org/wiki/Building_the_X_Window_System/
https://www.x.org/wiki/Building_the_X_Window_System/
Building
--------
@@ -48,8 +48,8 @@ This will assign this driver to *all* devices. Use with caution.
Bugs
----
Bugs in libinput go to the "libinput" component of wayland:
https://bugs.freedesktop.org/enter_bug.cgi?product=Wayland
Bugs in libinput go to the Issues section of the libinput gitlab project:
https://gitlab.freedesktop.org/libinput/libinput/issues
Bugs in this driver go to the "Input/libinput" component of xorg:
https://bugs.freedesktop.org/enter_bug.cgi?product=xorg
Bugs in this driver go to the Issues section of its gitlab project:
https://gitlab.freedesktop.org/xorg/driver/xf86-input-libinput/issues

View File

@@ -1,14 +1,17 @@
#! /bin/sh
srcdir=`dirname $0`
srcdir=`dirname "$0"`
test -z "$srcdir" && srcdir=.
ORIGDIR=`pwd`
cd $srcdir
cd "$srcdir"
autoreconf -v --install || exit 1
cd $ORIGDIR || exit $?
cd "$ORIGDIR" || exit $?
git config --local --get format.subjectPrefix >/dev/null 2>&1 ||
git config --local format.subjectPrefix "PATCH xf86-input-libinput"
if test -z "$NOCONFIGURE"; then
exec $srcdir/configure "$@"
exec "$srcdir"/configure "$@"
fi

52
conf/40-libinput.conf Normal file
View File

@@ -0,0 +1,52 @@
# Match on all types of devices but joysticks
#
# If you want to configure your devices, do not copy this file.
# Instead, use a config snippet that contains something like this:
#
# Section "InputClass"
# Identifier "something or other"
# MatchDriver "libinput"
#
# MatchIsTouchpad "on"
# ... other Match directives ...
# Option "someoption" "value"
# EndSection
#
# This applies the option any libinput device also matched by the other
# directives. See the xorg.conf(5) man page for more info on
# matching devices.
Section "InputClass"
Identifier "libinput pointer catchall"
MatchIsPointer "on"
MatchDevicePath "/dev/input/event*"
Driver "libinput"
EndSection
Section "InputClass"
Identifier "libinput keyboard catchall"
MatchIsKeyboard "on"
MatchDevicePath "/dev/input/event*"
Driver "libinput"
EndSection
Section "InputClass"
Identifier "libinput touchpad catchall"
MatchIsTouchpad "on"
MatchDevicePath "/dev/input/event*"
Driver "libinput"
EndSection
Section "InputClass"
Identifier "libinput touchscreen catchall"
MatchIsTouchscreen "on"
MatchDevicePath "/dev/input/event*"
Driver "libinput"
EndSection
Section "InputClass"
Identifier "libinput tablet catchall"
MatchIsTablet "on"
MatchDevicePath "/dev/input/event*"
Driver "libinput"
EndSection

View File

@@ -1,6 +0,0 @@
# Use the libinput driver for all event devices
Section "InputClass"
Identifier "libinput"
Driver "libinput"
MatchDevicePath "/dev/input/event*"
EndSection

View File

@@ -23,29 +23,107 @@
# Initialize Autoconf
AC_PREREQ([2.60])
AC_INIT([xf86-input-libinput],
[0.11.0],
[https://bugs.freedesktop.org/enter_bug.cgi?product=xorg],
[1.5.0],
[https://gitlab.freedesktop.org/xorg/driver/xf86-input-libinput/issues],
[xf86-input-libinput])
AC_CONFIG_SRCDIR([Makefile.am])
AC_CONFIG_HEADERS([config.h])
AC_CONFIG_AUX_DIR(.)
# Initialize Automake
AM_INIT_AUTOMAKE([foreign dist-bzip2])
AM_INIT_AUTOMAKE([foreign dist-xz])
# Initialize libtool
AC_DISABLE_STATIC
LT_INIT
# Initialize X.Org macros 1.8 or later for MAN_SUBSTS set by XORG_MANPAGE_SECTIONS
m4_ifndef([XORG_MACROS_VERSION],
m4_ifndef([XORG_MACROS_VERSION],
[m4_fatal([must install xorg-macros 1.8 or later before running autoconf/autogen])])
XORG_MACROS_VERSION(1.8)
XORG_DEFAULT_OPTIONS
# Obtain compiler/linker options from server and required extensions
PKG_CHECK_MODULES(XORG, [xorg-server >= 1.10] xproto [inputproto >= 2.2])
PKG_CHECK_MODULES(LIBINPUT, [libinput >= 0.14.0])
PKG_CHECK_MODULES(XORG, [xorg-server >= 1.19] xproto [inputproto >= 2.2])
PKG_CHECK_MODULES(LIBINPUT, [libinput >= 1.11.0])
PKG_CHECK_MODULES(INPUTPROTO24, [inputproto >= 2.3.99.1],
[AC_DEFINE(HAVE_INPUTPROTO24, [1], [inputproto 2.4 is available])],
[:])
OLD_LIBS=$LIBS
OLD_CFLAGS=$CFLAGS
LIBS="$LIBS $LIBINPUT_LIBS"
CFLAGS="$CFLAGS $LIBINPUT_CFLAGS"
AC_MSG_CHECKING([if libinput_device_config_scroll_get_button_lock is available])
AC_LINK_IFELSE(
[AC_LANG_PROGRAM([[#include <libinput.h>]],
[[libinput_device_config_scroll_get_button_lock(NULL)]])],
[AC_MSG_RESULT([yes])
AC_DEFINE(HAVE_LIBINPUT_SCROLL_BUTTON_LOCK, [1],
[libinput_device_config_scroll_get_button_lock() is available])
[libinput_have_scroll_button_lock=yes]],
[AC_MSG_RESULT([no])
[libinput_have_scroll_button_lock=no]])
AC_MSG_CHECKING([if libinput_event_pointer_get_scroll_value_v120 is available])
AC_LINK_IFELSE(
[AC_LANG_PROGRAM([[#include <libinput.h>]],
[[libinput_event_pointer_get_scroll_value_v120(NULL, 0)]])],
[AC_MSG_RESULT([yes])
AC_DEFINE(HAVE_LIBINPUT_AXIS_VALUE_V120, [1],
[libinput_event_pointer_get_scroll_value_v120() is available])
[libinput_have_axis_value_v120=yes]],
[AC_MSG_RESULT([no])
[libinput_have_axis_value_v120=no]])
AC_MSG_CHECKING([if libinput_config_accel_create is available])
AC_LINK_IFELSE(
[AC_LANG_PROGRAM([[#include <libinput.h>]],
[[libinput_config_accel_create(0)]])],
[AC_MSG_RESULT([yes])
AC_DEFINE(HAVE_LIBINPUT_CUSTOM_ACCEL, [1],
[libinput_config_accel_create() is available])
[libinput_have_custom_accel=yes]],
[AC_MSG_RESULT([no])
[libinput_have_custom_accel=no]])
AC_MSG_CHECKING([if libinput_tablet_tool_config_pressure_range_set is available])
AC_LINK_IFELSE(
[AC_LANG_PROGRAM([[#include <libinput.h>]],
[[libinput_tablet_tool_config_pressure_range_set(0)]])],
[AC_MSG_RESULT([yes])
AC_DEFINE(HAVE_LIBINPUT_PRESURE_RANGE, [1],
[libinput_tablet_tool_config_pressure_range_set() is available])
[libinput_have_pressure_range=yes]],
[AC_MSG_RESULT([no])
[libinput_have_pressure_range=no]])
AC_MSG_CHECKING([if libinput_device_config_click_set_clickfinger_button_map is available])
AC_LINK_IFELSE(
[AC_LANG_PROGRAM([[#include <libinput.h>]],
[[libinput_device_config_click_set_clickfinger_button_map(NULL, 0)]])],
[AC_MSG_RESULT([yes])
AC_DEFINE(HAVE_LIBINPUT_CLICKFINGER_BUTTON_MAP, [1],
[libinput_device_config_click_set_clickfinger_button_map() is available])
[libinput_have_clickfinger_button_map=yes]],
[AC_MSG_RESULT([no])
[libinput_have_clickfinger_button_map=no]])
AC_MSG_CHECKING([if libinput_plugin_system_load is available])
AC_LINK_IFELSE(
[AC_LANG_PROGRAM([[#include <libinput.h>]],
[[libinput_plugin_system_load_plugins(NULL, 0)]])],
[AC_MSG_RESULT([yes])
AC_DEFINE(HAVE_LIBINPUT_PLUGINS, [1],
[libinput_plugin_system_load_plugins() is available])
[libinput_have_plugin_system=yes]],
[AC_MSG_RESULT([no])
[libinput_have_plugin_system=no]])
LIBS=$OLD_LIBS
CFLAGS=$OLD_CFLAGS
# Define a configure option for an alternate input module directory
AC_ARG_WITH(xorg-module-dir,
@@ -56,6 +134,13 @@ AC_ARG_WITH(xorg-module-dir,
inputdir=${moduledir}/input
AC_SUBST(inputdir)
AC_ARG_WITH(xorg-conf-dir,
AC_HELP_STRING([--with-xorg-conf-dir=DIR],
[Default xorg.conf.d directory [[default=${prefix}/share/X11/xorg.conf.d]]]),
[xorgconfdir="$withval"],
[xorgconfdir='${prefix}/share/X11/xorg.conf.d'])
AC_SUBST(xorgconfdir)
# X Server SDK location is required to install header files
sdkdir=`$PKG_CONFIG --variable=sdkdir xorg-server`
@@ -71,5 +156,6 @@ AC_CONFIG_FILES([Makefile
include/Makefile
src/Makefile
man/Makefile
test/Makefile
xorg-libinput.pc])
AC_OUTPUT

View File

@@ -1,24 +1,26 @@
/*
* SPDX-License-Identifier: MIT
*
* Copyright © 2015 Red Hat, Inc.
*
* Permission to use, copy, modify, distribute, and sell this software
* and its documentation for any purpose is hereby granted without
* fee, provided that the above copyright notice appear in all copies
* and that both that copyright notice and this permission notice
* appear in supporting documentation, and that the name of Red Hat
* not be used in advertising or publicity pertaining to distribution
* of the software without specific, written prior permission. Red
* Hat makes no representations about the suitability of this software
* for any purpose. It is provided "as is" without express or implied
* warranty.
* 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 AUTHORS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
* INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN
* NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY SPECIAL, INDIRECT OR
* CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS
* OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
* NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
* CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
* 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 _LIBINPUT_PROPERTIES_H_
@@ -30,6 +32,32 @@
/* Tapping default enabled/disabled: BOOL, 1 value, read-only */
#define LIBINPUT_PROP_TAP_DEFAULT "libinput Tapping Enabled Default"
/* Tap drag enabled/disabled: BOOL, 1 value */
#define LIBINPUT_PROP_TAP_DRAG "libinput Tapping Drag Enabled"
/* Tap drag default enabled/disabled: BOOL, 1 value, read-only */
#define LIBINPUT_PROP_TAP_DRAG_DEFAULT "libinput Tapping Drag Enabled Default"
/* Tap drag lock enabled/disabled: BOOL, 1 value */
#define LIBINPUT_PROP_TAP_DRAG_LOCK "libinput Tapping Drag Lock Enabled"
/* Tap drag lock default enabled/disabled: BOOL, 1 value, read-only */
#define LIBINPUT_PROP_TAP_DRAG_LOCK_DEFAULT "libinput Tapping Drag Lock Enabled Default"
/* Tap button order: BOOL, 2 values in order LRM, LMR, only one may be set
at any time */
#define LIBINPUT_PROP_TAP_BUTTONMAP "libinput Tapping Button Mapping Enabled"
/* Tap button default order: BOOL, 2 values in order LRM, LMR, read-only */
#define LIBINPUT_PROP_TAP_BUTTONMAP_DEFAULT "libinput Tapping Button Mapping Default"
/* Clickfinger button order: BOOL, 2 values in order LRM, LMR, only one may be set
at any time */
#define LIBINPUT_PROP_CLICKFINGER_BUTTONMAP "libinput Clickfinger Button Mapping Enabled"
/* Clickfinger button default order: BOOL, 2 values in order LRM, LMR, read-only */
#define LIBINPUT_PROP_CLICKFINGER_BUTTONMAP_DEFAULT "libinput Clickfinger Button Mapping Default"
/* Calibration matrix: FLOAT, 9 values of a 3x3 matrix, in rows */
#define LIBINPUT_PROP_CALIBRATION "libinput Calibration Matrix"
@@ -42,6 +70,36 @@
/* Pointer accel speed: FLOAT, 1 value, 32 bit, read-only*/
#define LIBINPUT_PROP_ACCEL_DEFAULT "libinput Accel Speed Default"
/* Pointer accel profile: BOOL, 3 values in order adaptive, flat, custom
* only one is enabled at a time at max, read-only */
#define LIBINPUT_PROP_ACCEL_PROFILES_AVAILABLE "libinput Accel Profiles Available"
/* Pointer accel profile: BOOL, 3 values in order adaptive, flat, custom
only one is enabled at a time at max, read-only */
#define LIBINPUT_PROP_ACCEL_PROFILE_ENABLED_DEFAULT "libinput Accel Profile Enabled Default"
/* Pointer accel profile: BOOL, 3 values in order adaptive, flat, custom
only one is enabled at a time at max */
#define LIBINPUT_PROP_ACCEL_PROFILE_ENABLED "libinput Accel Profile Enabled"
/* Points for the custom accel profile: FLOAT, N values */
#define LIBINPUT_PROP_ACCEL_CUSTOM_POINTS_FALLBACK "libinput Accel Custom Fallback Points"
/* Steps for the custom accel profile: FLOAT, 1 value */
#define LIBINPUT_PROP_ACCEL_CUSTOM_STEP_FALLBACK "libinput Accel Custom Fallback Step"
/* Points for the custom accel profile: FLOAT, N values */
#define LIBINPUT_PROP_ACCEL_CUSTOM_POINTS_MOTION "libinput Accel Custom Motion Points"
/* Steps for the custom accel profile: FLOAT, 1 value */
#define LIBINPUT_PROP_ACCEL_CUSTOM_STEP_MOTION "libinput Accel Custom Motion Step"
/* Points for the custom accel profile: FLOAT, N values */
#define LIBINPUT_PROP_ACCEL_CUSTOM_POINTS_SCROLL "libinput Accel Custom Scroll Points"
/* Steps for the custom accel profile: FLOAT, 1 value */
#define LIBINPUT_PROP_ACCEL_CUSTOM_STEP_SCROLL "libinput Accel Custom Scroll Step"
/* Natural scrolling: BOOL, 1 value */
#define LIBINPUT_PROP_NATURAL_SCROLL "libinput Natural Scrolling Enabled"
@@ -84,6 +142,18 @@
/* Scroll button for button scrolling: 32-bit int, 1 value, read-only */
#define LIBINPUT_PROP_SCROLL_BUTTON_DEFAULT "libinput Button Scrolling Button Default"
/* Scroll button lock: BOOL, 1 value, TRUE for enabled, FALSE otherwise */
#define LIBINPUT_PROP_SCROLL_BUTTON_LOCK "libinput Button Scrolling Button Lock Enabled"
/* Scroll button lock: BOOL, 1 value, TRUE for enabled, FALSE otherwise, read-only*/
#define LIBINPUT_PROP_SCROLL_BUTTON_LOCK_DEFAULT "libinput Button Scrolling Button Lock Enabled Default"
/* Scroll pixel distance: CARD32, 1 value (with implementation-defined limits) */
#define LIBINPUT_PROP_SCROLL_PIXEL_DISTANCE "libinput Scrolling Pixel Distance"
/* Scroll pixel distance: CARD32, 1 value, read-only */
#define LIBINPUT_PROP_SCROLL_PIXEL_DISTANCE_DEFAULT "libinput Scrolling Pixel Distance Default"
/* Click method: BOOL read-only, 2 values in order buttonareas, clickfinger
shows available click methods */
#define LIBINPUT_PROP_CLICK_METHODS_AVAILABLE "libinput Click Methods Available"
@@ -102,4 +172,92 @@
/* Middle button emulation: BOOL, 1 value, read-only */
#define LIBINPUT_PROP_MIDDLE_EMULATION_ENABLED_DEFAULT "libinput Middle Emulation Enabled Default"
/* Disable while typing: BOOL, 1 value */
#define LIBINPUT_PROP_DISABLE_WHILE_TYPING "libinput Disable While Typing Enabled"
/* Disable while typing: BOOL, 1 value, read-only */
#define LIBINPUT_PROP_DISABLE_WHILE_TYPING_DEFAULT "libinput Disable While Typing Enabled Default"
/* Drag lock buttons, either:
CARD8, one value, the meta lock button, or
CARD8, n * 2 values, the drag lock pairs with n being the button and n+1
the target button number */
#define LIBINPUT_PROP_DRAG_LOCK_BUTTONS "libinput Drag Lock Buttons"
/* Horizontal scroll events enabled: BOOL, 1 value (0 or 1).
* If disabled, horizontal scroll events are discarded */
#define LIBINPUT_PROP_HORIZ_SCROLL_ENABLED "libinput Horizontal Scroll Enabled"
/* Number of modes each pad mode group has available: CARD8, one for each
* pad mode group, read-only.
*/
#define LIBINPUT_PROP_TABLET_PAD_MODE_GROUPS_AVAILABLE "libinput Pad Mode Groups Modes Available"
/* Mode each pad mode group is currently in: CARD8, one for each pad mode
* group, read-only.
*/
#define LIBINPUT_PROP_TABLET_PAD_MODE_GROUPS "libinput Pad Mode Groups Modes"
/* The association of each logical button with the pad mode group: INT8,
* one for each logical button. If set to -1 the button cannot be associated
* with a mode group. read-only
*/
#define LIBINPUT_PROP_TABLET_PAD_MODE_GROUP_BUTTONS "libinput Pad Mode Group Buttons"
/* The association of each logical strip with the pad mode group: INT8,
* one for each logical strip. If set to -1 the strip cannot be associated
* with a mode group. read-only
*/
#define LIBINPUT_PROP_TABLET_PAD_MODE_GROUP_STRIPS "libinput Pad Mode Group Strips"
/* The association of each logical ring with the pad mode group: INT8,
* one for each logical ring. If set to -1 the ring cannot be associated
* with a mode group. read-only
*/
#define LIBINPUT_PROP_TABLET_PAD_MODE_GROUP_RINGS "libinput Pad Mode Group Rings"
/* Device rotation: FLOAT, 1 value, 32 bit */
#define LIBINPUT_PROP_ROTATION_ANGLE "libinput Rotation Angle"
/* Device rotation: FLOAT, 1 value, 32 bit, read-only */
#define LIBINPUT_PROP_ROTATION_ANGLE_DEFAULT "libinput Rotation Angle Default"
/* Tablet tool pressure curve: float, 8 values, 32 bit
* Value range is [0.0, 1.0], the values specify the x/y of the four
* control points for a cubic bezier curve.
* Default value: 0.0 0.0 0.0 0.0 1.0 1.0 1.0 1.0
*/
#define LIBINPUT_PROP_TABLET_TOOL_PRESSURECURVE "libinput Tablet Tool Pressurecurve"
/* Tablet tool pressure range: float, 2 values, 32 bit
* Value range is [0.0, 1.0] for min and max physical pressure to map to the logical range
* Default value: 0.0 1.0
*/
#define LIBINPUT_PROP_TABLET_TOOL_PRESSURE_RANGE "libinput Tablet Tool Pressure Range"
/* Tablet tool pressure range: float, 2 values, 32 bit, read-only */
#define LIBINPUT_PROP_TABLET_TOOL_PRESSURE_RANGE_DEFAULT "libinput Tablet Tool Pressure Range Default"
/* Tablet tool area ratio: CARD32, 2 values, w and h */
#define LIBINPUT_PROP_TABLET_TOOL_AREA_RATIO "libinput Tablet Tool Area Ratio"
/* High-resolution wheel scroll events enabled: BOOL, 1 value (0 or 1).
* If disabled, high-resolution wheel scroll events are discarded */
#define LIBINPUT_PROP_HIRES_WHEEL_SCROLL_ENABLED "libinput High Resolution Wheel Scroll Enabled"
/* The tablet tool unique serial number: CARD32, 1 value, constant for the
* lifetime of the device.
*
* If this property exists and is zero, the tool does not have a unique serial
* number.
*/
#define LIBINPUT_PROP_TABLET_TOOL_SERIAL "libinput Tablet Tool Serial"
/* The tablet tool hardware ID: CARD32, 1 value, constant for the lifetime of the device.
*
* This property only exists if the device has a known tool ID.
* See libinput_tablet_tool_get_tool_id() in the libinput documentation for details.
*/
#define LIBINPUT_PROP_TABLET_TOOL_ID "libinput Tablet Tool ID"
#endif /* _LIBINPUT_PROPERTIES_H_ */

View File

@@ -18,7 +18,7 @@
# 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.
#
#
drivermandir = $(DRIVER_MAN_DIR)
@@ -32,6 +32,9 @@ CLEANFILES = $(driverman_DATA)
SUFFIXES = .$(DRIVER_MAN_SUFFIX) .man
MAN_SUBSTS += \
-e 's|\@VERSION\@|$(PACKAGE_NAME) $(PACKAGE_VERSION)|g'
# String replacements in MAN_SUBSTS now come from xorg-macros.m4 via configure
.man.$(DRIVER_MAN_SUFFIX):
$(AM_V_GEN)$(SED) $(MAN_SUBSTS) < $< > $@

View File

@@ -1,6 +1,7 @@
'\" t
.\" shorthand for double quote that works everywhere.
.ds q \N'34'
.TH LIBINPUT __drivermansuffix__ __vendorversion__
.TH LIBINPUT 4 2025-06-01 "@VERSION@"
.SH NAME
libinput \- libinput-based X.Org input driver
.SH SYNOPSIS
@@ -14,177 +15,438 @@ libinput \- libinput-based X.Org input driver
.fi
.SH NOTE
This is the man page for the X input driver. If you are looking for the
library documentation, go to
.BI http://wayland.freedesktop.org/libinput/doc/
This is the man page for the X input driver.
If you are looking for the library documentation, go to
.B http://wayland.freedesktop.org/libinput/doc/
.SH DESCRIPTION
.B libinput
is an __xservername__ input driver based on libinput. It
therefore supports all input devices that libinput can handle, including
.B libinput
is an Xorg input driver based on libinput.
It therefore supports all input devices that libinput can handle, including
most mice, keyboards, tablets and touchscreens.
.PP
It is recommended that
.B libinput
devices are configured through the
.B InputClass
directive (refer to __xconfigfile__(__filemansuffix__)) instead of manual
per-device configuration. Devices configured in the
__xconfigfile__(__filemansuffix__) are not hot-plug capable.
directive (refer to
.BR xorg.conf (5))
instead of manual per-device configuration.
Devices configured using the
.B InputDevice
directive in the
.BR xorg.conf (5)
file are not hot-plug capable.
.SH CONFIGURATION DETAILS
Please refer to __xconfigfile__(__filemansuffix__) for general configuration
details and for options that can be used with all input drivers. This
section only covers configuration details specific to this driver.
Please refer to
.BR xorg.conf (5)
for general configuration details
and for options that can be used with all input drivers.
This section only covers configuration details specific to this driver.
.PP
The following driver
The following driver
.B Options
are supported:
.TP 7
.BI "Option \*qDevice\*q \*q" string \*q
Specifies the device through which the device can be accessed. This will
generally be of the form \*q/dev/input/eventX\*q, where X is some integer.
The mapping from device node to hardware is system-dependent. Property:
"Device Node" (read-only).
.BI "Option \*qAccelProfile\*q \*q" string \*q
Sets the pointer acceleration profile to the given profile.
Permitted values are
.BR adaptive ,
.BR flat ,
.BR custom .
Not all devices support this option or all profiles.
If a profile is unsupported, the default profile for this device is used.
For a description on the profiles and their behavior,
see the libinput documentation.
.TP 7
.BI "Option \*qAccelSpeed\*q \*q" float \*q
Sets the pointer acceleration speed within the range [-1, 1]
Sets the pointer acceleration speed within the range [-1, 1].
This only applies to the flat or adaptive profile.
.TP 7
.BI "Option \*qAccelPointsFallback\*q \*q" string \*q
.TQ
.BI "Option \*qAccelPointsMotion\*q \*q" string \*q
.TQ
.BI "Option \*qAccelPointsScroll\*q \*q" string \*q
Sets the points of the Fallback/Motion/Scroll acceleration functions.
The string must be a space-separated list of
floating point non-negative numbers, e.g.,
"0.0 1.0 2.4 2.5".
This only applies to the custom profile.
See section
.B CUSTOM ACCELERATION PROFILE
.TP 7
.BI "Option \*qAccelStepFallback\*q \*q" float \*q
.TQ
.BI "Option \*qAccelStepMotion\*q \*q" float \*q
.TQ
.BI "Option \*qAccelStepScroll\*q \*q" float \*q
Sets the step between the points of the Fallback/Motion/Scroll
acceleration functions.
When a step of 0.0 is provided,
libinput's Fallback acceleration function is used.
This only applies to the custom profile.
See section
.B CUSTOM ACCELERATION PROFILE
.TP 7
.BI "Option \*qButtonMapping\*q \*q" string \*q
Sets the logical button mapping for this device, see
XSetPointerMapping(__libmansuffix__). The string must be a
space-separated list of button mappings in the order of the
.BR XSetPointerMapping (3).
The string must be a space-separated list of button mappings in the order of the
logical buttons on the device, starting with button 1.
The default mapping is "1 2 3 ... 32". A mapping of 0
deactivates the button. Multiple buttons can have the same mapping.
The default mapping is "1 2 3 ... 32".
A mapping of 0 deactivates the button.
Multiple buttons can have the same mapping.
Invalid mapping strings are discarded and the default mapping
is used for all buttons. Buttons not specified in the user's mapping use the
default mapping. See section
is used for all buttons.
Buttons not specified in the user's mapping use the default mapping.
See section
.B BUTTON MAPPING
for more details.
.TP 7
.BI "Option \*qCalibrationMatrix\*q \*q" string \*q
A string of 9 space-separated floating point numbers.
A string of 9 space-separated floating point numbers, in the order
\*qa b c d e f g h i\*q.
Sets the calibration matrix to the 3x3 matrix where the first row is (abc),
the second row is (def) and the third row is (ghi).
.TP 7
.BI "Option \*qClickMethod\*q \*q" string \*q
Enables a click method. Permitted values are
.BI none,
.BI buttonareas,
.BI clickfinger.
Not all devices support all methods, if an option is unsupported, the
default click method for this device is used.
Enables a click method.
Permitted values are
.BR none ,
.BR buttonareas ,
.BR clickfinger .
Not all devices support all methods.
If an option is unsupported, the default click method for this device is used.
.TP 7
.BI "Option \*qDisableWhileTyping\*q \*q" bool \*q
Indicates if the touchpad should be disabled while typing on the keyboard
(this does not apply to modifier keys such as Ctrl or Alt).
.TP 7
.BI "Option \*qDevice\*q \*q" string \*q
Specifies the device through which the device can be accessed.
This will generally be of the form \*q/dev/input/eventX\*q,
where X is some integer.
When using
.B InputClass
directives, this option is set by the server.
The mapping from device node to hardware is system-dependent.
Property: "Device Node" (read-only).
.TP 7
.BI "Option \*qDragLockButtons\*q \*q" "L1 B1 L2 B2 ..." \*q
Sets "drag lock buttons" that simulate a button logically down even when it has
been physically released.
To logically release a locked button,
a second click of the same button is required.
.IP
If the option is a single button number, that button acts as the
"meta" locking button for the next button number.
See section
.B BUTTON DRAG LOCK
for details.
.IP
If the option is a list of button number pairs, the first number of each
number pair is the lock button, the second number the logical button number
to be locked.
See section
.B BUTTON DRAG LOCK
for details.
.IP
For both meta and button pair configuration,
the button numbers are device button numbers, i.e. the
.B ButtonMapping
applies after drag lock.
.TP 7
.BI "Option \*qHighResolutionWheelScrolling\*q \*q" bool \*q
Disables high-resolution wheel scroll events, enabled by default. When enabled,
the driver forwards only high-resolution wheel scroll events from libinput.
When disabled, the driver forwards legacy wheel scroll events instead.
.TP 7
.BI "Option \*qHorizontalScrolling\*q \*q" bool \*q
Enables or disables horizontal scrolling.
When disabled,
this driver will discard any horizontal scroll events from libinput.
This does not disable horizontal scroll events from libinput;
it merely discards the horizontal axis from any scroll events.
Default is enabled.
.TP 7
.BI "Option \*qLeftHanded\*q \*q" bool \*q
Enables left-handed button orientation, i.e. swapping left and right buttons.
.TP 7
.BI "Option \*qMiddleEmulation\*q \*q" bool \*q
Enables middle button emulation. When enabled, pressing the left and right
Enables middle button emulation.
When enabled, pressing the left and right
buttons simultaneously produces a middle mouse button click.
.TP 7
.BI "Option \*qNaturalScrolling\*q \*q" bool \*q
Enables or disables natural scrolling behavior.
.TP 7
.BI "Option \*qRotationAngle\*q \*q" float \*q
Sets the rotation angle of the device to the given angle, in degrees clockwise.
The angle must be between 0.0 (inclusive) and 360.0 (exclusive).
.TP 7
.BI "Option \*qScrollButton\*q \*q" int \*q
Designates a button as scroll button. If the
.BI ScrollMethod
Designates a button as scroll button.
If the
.B ScrollMethod
is
.BI button
and the button is logically held down, x/y axis movement is converted into
.B button
and the button is logically down, x/y axis movement is converted into
scroll events.
.TP 7
.BI "Option \*qScrollButtonLock\*q \*q" bool \*q
Enables or disables the scroll button lock.
If enabled, the
.B ScrollButton
is considered logically down after the first click and remains down until
the second click of that button.
If disabled (the default), the
.B ScrollButton
button is considered logically down while held down and up once physically
released.
.TP 7
.BI "Option \*qScrollMethod\*q \*q" string \*q
Enables a scroll method. Permitted values are
.BI none,
.BI twofinger,
.BI edge,
.BI button.
Not all devices support all options, if an option is unsupported, the
default scroll option for this device is used.
.BR none ,
.BR twofinger ,
.BR edge ,
.BR button .
Not all devices support all options.
If an option is unsupported, the default scroll option for this device is used.
.TP 7
.BI "Option \*qScrollPixelDistance\*q \*q" int \*q
Sets the movement distance, in "pixels", required to trigger one logical
wheel click.
This option only applies to the scroll methods
.BR twofinger ,
.BR edge ,
.BR button .
See section
.B SCROLL PIXEL DISTANCE
for more details.
.TP 7
.BI "Option \*qSendEventsMode\*q \*q" (disabled|enabled|disabled-on-external-mouse) \*q
Sets the send events mode to disabled, enabled, or "disable when an external
mouse is connected".
Sets the send events mode to disabled, enabled,
or "disable when an external mouse is connected".
.TP 7
.BI "Option \*qTabletToolPressureCurve\*q \*q" "x0/y0 x1/y1 x2/y2 x3/y3" \*q
Set the pressure curve for a tablet stylus to the bezier formed by the four
points.
The respective x/y coordinate must be in the [0.0, 1.0] range.
For more information see section
.B TABLET TOOL PRESSURE CURVE.
.TP 7
.BI "Option \*qTabletToolPressureRange\*q \*q" "min max" \*q
Set the pressure range for a tablet stylus to the given subset of the physical
range.
The min/max values must be in the [0.0, 1.0] range.
For example, a min of 0.3 means the tablet will send 0 pressure for anything
equal or below 30% of the physical pressure range and a max of 0.7 means
the tablet sends its maximum pressure value for any pressure equal or higher to
70% of the physical pressure range.
.TP 7
.BI "Option \*qTabletToolAreaRatio\*q \*q" "w:h" \*q
Sets the area ratio for a tablet tool.
The area always starts at the origin (0/0) and
expands to the largest available area with the specified aspect ratio.
Events outside this area are cropped to the area.
The special value "default" is used for the default mapping
(i.e. the device-native mapping).
For more information see section
.B TABLET TOOL AREA RATIO.
.TP 7
.BI "Option \*qTapping\*q \*q" bool \*q
Enables or disables tap-to-click behavior.
.TP 7
.BI "Option \*qTappingButtonMap\*q \*q" (lrm|lmr) \*q
Set the button mapping for 1/2/3-finger taps to left/right/middle or
left/middle/right, respectively.
.TP 7
.BI "Option \*qTappingDrag\*q \*q" bool \*q
Enables or disables drag during tapping behavior ("tap-and-drag").
When enabled, a tap followed by a finger held down causes a single button down
only, all motions of that finger thus translate into dragging motion.
Tap-and-drag requires option
.B Tapping
to be enabled.
.TP 7
.BI "Option \*qTappingDragLock\*q \*q" bool \*q
Enables or disables drag lock during tapping behavior.
When enabled,
a finger up during tap-and-drag will not immediately release the button.
If the finger is set down again within the timeout,
the dragging process continues.
.PP
For all options, the options are only parsed if the device supports that
configuration option. For all options, the default value is the one used by
libinput. On configuration failure, the default value is applied.
configuration option.
For all options, the default value is the one used by libinput.
On configuration failure, the default value is applied.
.SH SUPPORTED PROPERTIES
.B libinput
exports runtime-configurable options as properties. If a property listed
below is not available, the matching configuration option is not available
on the device. This however does not imply that the feature is not available
on the device. The following properties are provided by the
exports runtime-configurable options as properties.
If a property listed below is not available,
the matching configuration option is not available on the device.
This however does not imply that the feature is not available on the device.
The following properties are provided by the
.B libinput
driver.
.TP 7
.BI "libinput Tapping Enabled"
1 boolean value (8 bit, 0 or 1). 1 enables tapping
.B "libinput Accel Profiles Available"
3 boolean values (8 bit, 0 or 1), in order "adaptive", "flat", "custom".
Indicates which acceleration profiles are available on this device.
.TP 7
.BI "libinput Calibration Matrix"
.B "libinput Accel Profile Enabled"
3 boolean values (8 bit, 0 or 1), in order "adaptive", "flat", "custom".
Indicates which acceleration profile is currently enabled on this device.
.TP 7
.B "libinput Accel Speed"
1 32-bit float value, defines the pointer speed.
Value range -1, 1.
This only applies to the flat or adaptive profile.
.TP 7
.B "libinput Accel Custom Fallback Points"
.TQ
.B "libinput Accel Custom Motion Points"
.TQ
.B "libinput Accel Custom Scroll Points"
A space-separated list of 32-bit floating point non-negative numbers, e.g.
"0.0 1.0 2.4 2.5".
Sets the points of the Fallback/Motion/Scroll acceleration functions.
This only applies to the custom profile.
See section
.B CUSTOM ACCELERATION PROFILE
.TP 7
.B "libinput Accel Custom Fallback Step"
.TQ
.B "libinput Accel Custom Motion Step"
.TQ
.B "libinput Accel Custom Scroll Step"
1 32-bit float value, sets the step between the points of the
Fallback/Motion/Scroll acceleration functions.
When a step of 0.0 is provided, libinput's Fallback acceleration
function is used.
This only applies to the custom profile.
See section
.B CUSTOM ACCELERATION PROFILE
.TP 7
.B "libinput Button Scrolling Button"
1 32-bit value. Sets the button number to use for button scrolling.
This setting is independent of the scroll method, to enable button scrolling the
method must be set to button-scrolling and a valid button must be set.
.TP 7
.B "libinput Button Scrolling Button Lock Enabled"
1 boolean value. If true, the scroll button lock is enabled.
This setting is independent of the scroll method or the scroll button, to enable
button scrolling the method must be set to button-scrolling and a valid
button must be set.
.TP 7
.B "libinput Calibration Matrix"
9 32-bit float values, representing a 3x3 calibration matrix, order is row
1, row 2, row 3
.TP 7
.BI "libinput Accel Speed"
1 32-bit float value, defines the pointer speed. Value range -1, 1
.TP 7
.BI "libinput Natural Scrolling Enabled"
1 boolean value (8 bit, 0 or 1). 1 enables natural scrolling
.TP 7
.BI "libinput Send Events Modes Available"
2 boolean values (8 bit, 0 or 1), in order "disabled" and
"disabled-on-external-mouse". Indicates which send-event modes are available
on this device.
.TP 7
.BI "libinput Send Events Mode Enabled"
2 boolean values (8 bit, 0 or 1), in order "disabled" and
"disabled-on-external-mouse". Indicates which send-event modes is currently
enabled on this device.
.TP 7
.BI "libinput Left Handed Enabled"
1 boolean value (8 bit, 0 or 1). Indicates if left-handed mode is enabled or
disabled.
.TP 7
.BI "libinput Scroll Methods Available"
3 boolean values (8 bit, 0 or 1), in order "two-finger", "edge", "button".
Indicates which scroll methods are available on this device.
.TP 7
.BI "libinput Scroll Method Enabled"
3 boolean values (8 bit, 0 or 1), in order "two-finger", "edge", "button".
Indicates which scroll method is currently enabled on this device.
.TP 7
.BI "libinput Button Scrolling Button"
1 32-bit value. Sets the button number to use for button scrolling. This
setting is independent of the scroll method, to enable button scrolling the
method must be set to button-scrolling and a valid button must be set.
.TP 7
.BI "libinput Click Methods Available"
.B "libinput Click Methods Available"
2 boolean values (8 bit, 0 or 1), in order "buttonareas", "clickfinger".
Indicates which click methods are available on this device.
.TP 7
.BI "libinput Click Methods Enabled"
.B "libinput Click Methods Enabled"
2 boolean values (8 bit, 0 or 1), in order "buttonareas", "clickfinger".
Indicates which click methods are enabled on this device.
.TP 7
.BI "libinput Middle Emulation Enabled"
1 boolean value (8 bit, 0 or 1). Indicates if middle emulation is enabled or
disabled.
.TP7
.B "libinput Drag Lock Buttons"
Either one 8-bit value specifying the meta drag lock button, or a list of
button pairs.
See section
.B BUTTON DRAG LOCK
for details.
.TP 7
.B "libinput High Resolution Wheel Scroll Enabled"
1 boolean value (8 bit, 0 or 1).
Indicates whether high-resolution wheel scroll events are enabled or not.
.TP 7
.B "libinput Horizontal Scroll Enabled"
1 boolean value (8 bit, 0 or 1).
Indicates whether horizontal scrolling events are enabled or not.
.TP 7
.B "libinput Left Handed Enabled"
1 boolean value (8 bit, 0 or 1).
Indicates if left-handed mode is enabled or disabled.
.TP 7
.B "libinput Middle Emulation Enabled"
1 boolean value (8 bit, 0 or 1).
Indicates if middle emulation is enabled or disabled.
.TP 7
.B "libinput Natural Scrolling Enabled"
1 boolean value (8 bit, 0 or 1).
1 enables natural scrolling.
.TP 7
.B "libinput Rotation Angle"
1 32-bit float value [0.0 to 360.0).
Sets the rotation angle of the device,
clockwise of its natural neutral position.
.TP 7
.B "libinput Scroll Methods Available"
3 boolean values (8 bit, 0 or 1), in order "two-finger", "edge", "button".
Indicates which scroll methods are available on this device.
.TP 7
.B "libinput Scroll Method Enabled"
3 boolean values (8 bit, 0 or 1), in order "two-finger", "edge", "button".
Indicates which scroll method is currently enabled on this device.
.TP 7
.B "libinput Scroll Pixel Distance"
1 32-bit value (nonzero, with additional implementation-defined range checks).
Changes the movement distance required to trigger one logical wheel click.
.TP 7
.B "libinput Send Events Modes Available"
2 boolean values (8 bit, 0 or 1), in order "disabled" and
"disabled-on-external-mouse".
Indicates which send-event modes are available on this device.
.TP 7
.B "libinput Send Events Mode Enabled"
2 boolean values (8 bit, 0 or 1), in order "disabled" and
"disabled-on-external-mouse".
Indicates which send-event mode is currently enabled on this device.
.TP 7
.B "libinput Tablet Tool Pressurecurve"
4 32-bit float values [0.0 to 1.0].
See section
.B TABLET TOOL PRESSURE CURVE
.TP 7
.B "libinput Tablet Tool Area Ratio"
2 32-bit values, corresponding to width and height.
Special value 0, 0 resets to the default ratio.
See section
.B TABLET TOOL AREA RATIO
for more information.
.TP 7
.B "libinput Tapping Enabled"
1 boolean value (8 bit, 0 or 1).
1 enables tapping.
.TP 7.
.B "libinput Tapping Button Mapping Enabled"
2 boolean value (8 bit, 0 or 1), in order "lrm" and "lmr".
Indicates which button mapping is currently enabled on this device.
.TP 7
.B "libinput Tapping Drag Lock Enabled"
1 boolean value (8 bit, 0 or 1).
1 enables drag lock during tapping.
.TP 7
.B "libinput Disable While Typing Enabled"
1 boolean value (8 bit, 0 or 1).
Indicates if disable while typing is enabled or disabled.
.PP
The above properties have a
.BI "libinput <property name> Default"
Most properties have a
.B "libinput <property name> Default"
equivalent that indicates the default value for this setting on this device.
.SH BUTTON MAPPING
X clients receive events with logical button numbers, where 1, 2, 3
are usually interpreted as left, middle, right and logical buttons 4, 5, 6,
7 are usually interpreted as scroll up, down, left, right. The fourth and
fifth physical buttons on a device will thus send logical buttons 8 and 9.
X clients receive events with logical button numbers,
where 1, 2, 3 are usually interpreted as left, middle, right;
and logical buttons 4, 5, 6, 7 are usually interpreted
as scroll up, down, left, right.
The fourth and fifth physical buttons on a device
will thus send logical buttons 8 and 9.
The
.B ButtonMapping
option adjusts the logical button mapping, it does not affect how a physical
@@ -195,17 +457,136 @@ button mapping of
.B "\*q3 2 1 ...\*q"
On systems using the
.B libinput
__xservername__ input driver it is recommended to use the
Xorg input driver it is recommended to use the
.B LeftHanded
option instead.
.PP
The
.B libinput
__xservername__ input driver does not use the button mapping after setup.
Use XSetPointerMapping(__libmansuffix__) to modify the button mapping at
runtime.
Xorg input driver does not use the button mapping after setup.
Use
.BR XSetPointerMapping (3)
to modify the button mapping at runtime.
.SH BUTTON DRAG LOCK
Button drag lock holds a button logically down even when the button itself
has been physically released since.
Button drag lock comes in two modes.
.PP
If in "meta" mode, a meta button click activates drag lock for the next
button press of any other button.
A button click in the future will keep that button held logically down
until a subsequent click of that same button.
The meta button events themselves are discarded.
A separate meta button click is required each time a drag lock should be
activated for a button in the future.
.PP
If in "pairs" mode, each button can be assigned a target locking button.
On button click, the target lock button is held logically down until the
next click of the same button.
The button events themselves are discarded
and only the target button events are sent.
.PP
This feature is provided by this driver, not by libinput.
.SH TABLET TOOL PRESSURE CURVE
The pressure curve affects how stylus pressure is reported.
By default, the hardware pressure is reported as-is.
By setting a pressure curve, the feel of the stylus can be adjusted
to be more like e.g. a pencil or a brush.
.PP
The pressure curve is a cubic Bezier curve, drawn within a normalized range
of 0.0 to 1.0 between the four points provided.
This normalized range is applied to the tablet's pressure input
so that the highest pressure maps to 1.0.
The points must have increasing x coordinates, if x0 is larger than 0.0
all pressure values lower than x0 are equivalent to y0.
If x3 is less than 1.0,
all pressure values higher than x3 are equivalent to y3.
.PP
The input for a linear curve (default) is "0.0/0.0 0.0/0.0 1.0/1.0 1.0/1.0";
a slightly depressed curve (firmer) might be
"0.0/0.0 0.05/0.0 1.0/0.95 1.0/1.0";
a slightly raised curve (softer) might be "0.0/0.0 0.0/0.05 0.95/1.0 1.0/1.0".
.PP
This feature is provided by this driver, not by libinput.
.SH TABLET TOOL AREA RATIO
By default, a tablet tool can access the whole sensor area and the tablet
area is mapped to the available screen area.
For external tablets like the Wacom Intuos series,
the height:width ratio of the tablet may be different to that of the monitor,
causing the skew of input data.
.PP
To avoid this skew of input data, an area ratio may be set to match the
ratio of the screen device.
For example, a ratio of 4:3 will reduce the available area of the tablet
to the largest available area with a ratio of 4:3.
Events within this area will scale to the tablet's announced axis range,
the area ratio is thus transparent to the X server.
Any events outside this area will send events equal to the maximum value of
that axis.
The area always starts at the device's origin in it's current rotation, i.e.,
it takes left-handed-ness into account.
.PP
This feature is provided by this driver, not by libinput.
.SH SCROLL PIXEL DISTANCE
The X server does not support per-pixel scrolling but it does support
smooth scrolling.
All scroll events however are based around a logical unit of scrolling
(traditionally corresponding to a wheel click).
It is thus not possible to scroll by 10 pixels, but it is possible for a
driver to scroll by 1/10th of a logical wheel click.
.PP
libinput provides scroll data in pixels.
The \fBScrollPixelDistance\fR option defines the amount of movement equivalent
to one wheel click.
For example, a value of 50 means the user has to move a finger by 50 pixels to
generate one logical click event and each pixel is 1/50th of a wheel click.
.SH CUSTOM ACCELERATION PROFILE
The custom pointer acceleration profile gives users full control over the
acceleration behavior at different speeds.
libinput exposes an acceleration function \fIf(x)\fP
where the x-axis is the device speed in device units per millisecond
and the y-axis is the pointer speed.
.PP
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.
Thus the points defining the custom function are:
.EX
(0 * step, f[0]), (1 * step, f[1]), ..., ((n-1) * step, f[n-1])
.EE
When a velocity value does not lie exactly on those points,
a linear interpolation/extrapolation of the two closest points
will be calculated.
.PP
There are 3 custom acceleration functions,
which are used for different movement types:
.TS
tab(;) allbox;
l l l.
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
.TE
.PP
See libinput library documentation for more details:
https://wayland.freedesktop.org/libinput/doc/latest/pointer-acceleration.html#the-custom-acceleration-profile
.SH BUGS
This driver does not work with \fBOption \*qDevice\*q\fR set to an event
node in \fI/dev/input/by-id\fR and \fI/dev/input/by-path\fR.
This can be usually be worked by using \fBSection \*qInputClass\*q\fR with an
appropriate \fBMatch*\fR statement in the
.BR xorg.conf (5).
.SH AUTHORS
Peter Hutterer
.SH "SEE ALSO"
__xservername__(__appmansuffix__), __xconfigfile__(__filemansuffix__), Xserver(__appmansuffix__), X(__miscmansuffix__)
.BR Xorg (1),
.BR xorg.conf (5),
.BR Xserver (1),
.BR X (7)

158
meson.build Normal file
View File

@@ -0,0 +1,158 @@
project('xf86-input-libinput', 'c',
version: '1.5.0', # bump version in configure.ac
default_options: ['warning_level=2'],
meson_version: '>= 0.50.0')
driver_version = meson.project_version().split('.')
dir_pkgconf = get_option('prefix') / get_option('libdir') / 'pkgconfig'
dir_man4 = get_option('prefix') / get_option('mandir') / 'man4'
cc = meson.get_compiler('c')
cflags = [
'-Wno-unused-parameter',
'-Wno-sign-compare', # lots of work to get rid of this
'-Wmissing-prototypes',
'-Wstrict-prototypes',
'-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')
pkgconfig = import('pkgconfig')
dep_xserver = dependency('xorg-server', version: '>= 1.19')
dep_xproto = dependency('xproto')
dep_inputproto = dependency('inputproto', version: '>= 2.2')
dep_libinput = dependency('libinput', version: '>= 1.11.0')
config_h = configuration_data()
config_h.set('PACKAGE_VERSION_MAJOR', driver_version[0])
config_h.set('PACKAGE_VERSION_MINOR', driver_version[1])
config_h.set('PACKAGE_VERSION_PATCHLEVEL', driver_version[2])
if dep_inputproto.version().version_compare('>= 2.3.99.1')
config_h.set('HAVE_INPUTPROTO24', 1)
endif
if cc.has_function('libinput_device_config_scroll_get_button_lock',
dependencies: dep_libinput)
config_h.set('HAVE_LIBINPUT_SCROLL_BUTTON_LOCK', 1)
endif
if cc.has_function('libinput_event_pointer_get_scroll_value_v120',
dependencies: dep_libinput)
config_h.set('HAVE_LIBINPUT_AXIS_VALUE_V120', 1)
endif
if cc.has_function('libinput_config_accel_create',
dependencies: dep_libinput)
config_h.set('HAVE_LIBINPUT_CUSTOM_ACCEL', 1)
endif
if cc.has_function('libinput_tablet_tool_config_pressure_range_set',
dependencies: dep_libinput)
config_h.set('HAVE_LIBINPUT_PRESSURE_RANGE', 1)
endif
if cc.has_function('libinput_device_config_click_set_clickfinger_button_map',
dependencies: dep_libinput)
config_h.set('HAVE_LIBINPUT_CLICKFINGER_BUTTON_MAP', 1)
endif
if cc.has_header_symbol('libinput.h', 'LIBINPUT_LED_COMPOSE',
dependencies: dep_libinput)
config_h.set('HAVE_LIBINPUT_COMPOSE_AND_KANA', 1)
endif
if cc.has_function('libinput_plugin_system_load_plugins', dependencies: dep_libinput)
config_h.set('HAVE_LIBINPUT_PLUGINS', 1)
endif
dir_headers = get_option('sdkdir')
if dir_headers == ''
dir_headers = dep_xserver.get_pkgconfig_variable('sdkdir')
endif
dir_xorg_module = get_option('xorg-module-dir')
if dir_xorg_module == ''
dir_xorg_module = dep_xserver.get_pkgconfig_variable('moduledir') / 'input'
endif
dir_xorg_conf = get_option('xorg-conf-dir')
if dir_xorg_conf == ''
dir_xorg_conf = dep_xserver.get_pkgconfig_variable('sysconfigdir')
endif
libbezier = static_library('bezier', ['src/bezier.c', 'src/bezier.h'])
dep_libbezier = declare_dependency(link_with: libbezier)
libdraglock = static_library('draglock', ['src/draglock.c', 'src/draglock.h'])
dep_libdraglock = declare_dependency(link_with: libdraglock)
dep_drivers = [
dep_xserver,
dep_xproto,
dep_inputproto,
dep_libinput,
dep_libbezier,
dep_libdraglock,
]
driver_src = ['src/xf86libinput.c', 'src/util-strings.c']
driver_lib = shared_module(
'libinput_drv',
driver_src,
name_prefix: '', # we want libinput_drv.so, not liblibinput_drv.so
include_directories: include_directories('include'),
dependencies: dep_drivers,
install: true,
install_dir: dir_xorg_module,
)
test_bezier = executable('test-bezier',
['test/test-bezier.c'],
dependencies: dep_libbezier,
include_directories: include_directories('src'),
install: false)
test('test-bezier', test_bezier)
test_draglock = executable('test-draglock',
['test/test-draglock.c'],
dependencies: dep_libdraglock,
include_directories: include_directories('src'),
install: false)
test('test-draglock', test_draglock)
conf_pkgconf = configuration_data()
conf_pkgconf.set('PACKAGE_VERSION', meson.project_version())
conf_pkgconf.set('sdkdir', dir_headers)
configure_file(
input: 'xorg-libinput.pc.in',
output: 'xorg-libinput.pc',
configuration: conf_pkgconf,
install_dir: dir_pkgconf,
)
config_man = configuration_data()
config_man.set('VERSION', '@0@ @1@'.format(meson.project_name(), meson.project_version()))
configure_file(
input: 'man/libinput.man',
output: 'libinput.4',
configuration: config_man,
install_dir: dir_man4
)
install_headers('include/libinput-properties.h', install_dir: dir_headers)
install_data('conf/40-libinput.conf', install_dir: dir_xorg_conf)
# Now generate config.h
configure_file(output: 'config.h', configuration: config_h)

15
meson_options.txt Normal file
View File

@@ -0,0 +1,15 @@
option('sdkdir',
type: 'string',
value: '',
description: 'Directory to install header files in [default=from xorg-server pkgconf]',
)
option('xorg-module-dir',
type : 'string',
value : '',
description : 'Default xorg module directory [default=from xorg-server pkgconf]',
)
option('xorg-conf-dir',
type : 'string',
value : '',
description : 'Default xorg.conf.d directory [default=from xorg-server pkgconfig]'
)

View File

@@ -30,8 +30,16 @@ AM_CPPFLAGS =-I$(top_srcdir)/include $(LIBINPUT_CFLAGS)
@DRIVER_NAME@_drv_la_LTLIBRARIES = @DRIVER_NAME@_drv.la
@DRIVER_NAME@_drv_la_LDFLAGS = -module -avoid-version
@DRIVER_NAME@_drv_la_LIBADD = $(LIBINPUT_LIBS)
@DRIVER_NAME@_drv_la_LIBADD = $(LIBINPUT_LIBS) libdraglock.la libbezier.la -lm
@DRIVER_NAME@_drv_ladir = @inputdir@
@DRIVER_NAME@_drv_la_SOURCES = @DRIVER_NAME@.c
@DRIVER_NAME@_drv_la_SOURCES = \
xf86libinput.c \
util-macros.h \
util-strings.h \
util-strings.c \
$(NULL)
noinst_LTLIBRARIES = libdraglock.la libbezier.la
libdraglock_la_SOURCES = draglock.c draglock.h
libbezier_la_SOURCES = bezier.c bezier.h

179
src/bezier.c Normal file
View File

@@ -0,0 +1,179 @@
/*
* SPDX-License-Identifier: MIT
*
* 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.
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include <assert.h>
#include <math.h>
#include <stdio.h>
#include "bezier.h"
const struct bezier_control_point bezier_defaults[4] = {
{ 0.0, 0.0 },
{ 0.0, 0.0 },
{ 1.0, 1.0 },
{ 1.0, 1.0 },
};
struct point {
int x, y;
};
/**
* de Casteljau's algorithm. See this page here
* https://pomax.github.io/bezierinfo/#extended
*
* To play with bezier curve shapes, I used
* http://cubic-bezier.com/
*/
static struct point
decasteljau(const struct point *controls,
size_t ncontrols,
double t)
{
struct point new_controls[ncontrols];
if (ncontrols == 1)
return controls[0];
for (int i = 0; i < ncontrols - 1; i++) {
new_controls[i].x = (1.0 - t) * controls[i].x + t * controls[i + 1].x;
new_controls[i].y = (1.0 - t) * controls[i].y + t * controls[i + 1].y;
}
return decasteljau(new_controls, ncontrols - 1, t);
}
/**
* Given a Bézier curve defined by the control points, reduce the curve to
* one with ncurve_points.
*/
static void
flatten_curve(const struct point *controls,
size_t ncontrols,
struct point *curve,
size_t ncurve_points)
{
ncurve_points--; /* make sure we end up with 100/100 as last point */
for (int i = 0; i <= ncurve_points; i++) {
double t = 1.0 * i/ncurve_points;
struct point p;
p = decasteljau(controls, ncontrols, t);
curve[i] = p;
}
}
/**
* Calculate line through a and b, set curve[x] for each x between
* [a.x, b.x].
*
* Note: pcurve must be at least b.x size.
*/
static void
line_between(struct point a, struct point b,
struct point *curve, size_t curve_sz)
{
double slope;
double offset;
assert(b.x < curve_sz);
if (a.x == b.x) {
curve[a.x].x = a.x;
curve[a.x].y = a.y;
return;
}
slope = (double)(b.y - a.y)/(b.x - a.x);
offset = a.y - slope * a.x;
for (int x = a.x; x <= b.x; x++) {
struct point p;
p.x = x;
p.y = slope * x + offset;
curve[x] = p;
}
}
bool
cubic_bezier(const struct bezier_control_point controls[4],
int *bezier_out,
size_t bezier_sz)
{
const int nsegments = 50;
const int range = bezier_sz - 1;
struct point curve[nsegments];
struct point bezier[bezier_sz];
struct point zero = { 0, 0 },
max = { range, range};
/* Scale control points into the [0, bezier_sz) range */
struct point ctrls[4];
for (int i = 0; i < 4; i++) {
if (controls[i].x < 0.0 || controls[i].x > 1.0 ||
controls[i].y < 0.0 || controls[i].y > 1.0)
return false;
ctrls[i].x = controls[i].x * range;
ctrls[i].y = controls[i].y * range;
}
for (int i = 0; i < 3; i++) {
if (ctrls[i].x > ctrls[i+1].x)
return false;
}
/* Reduce curve to nsegments, because this isn't a drawing program */
flatten_curve(ctrls, 4, curve, nsegments);
/* we now have nsegments points in curve that represent the bezier
curve (already in the [0, bezier_sz) range). Run through the
points and draw a straight line between each point and voila, we
have our curve.
If the first control points (x0/y0) is not at x == 0 or the last
control point (x3/y3) is not at the max value, draw a line
between from 0/0 to x0/y0 and from x3/y3 to xmax/y3.
*/
line_between(zero, curve[0], bezier, bezier_sz);
for (int i = 0; i < nsegments - 1; i++)
line_between(curve[i], curve[i+1], bezier, bezier_sz);
if (curve[nsegments - 1].x < max.x)
line_between(curve[nsegments - 1], max, bezier, bezier_sz);
for (int i = 0; i < bezier_sz; i++)
bezier_out[i] = bezier[i].y;
return true;
}

71
src/bezier.h Normal file
View File

@@ -0,0 +1,71 @@
/*
* SPDX-License-Identifier: MIT
*
* 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.
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#ifndef BEZIER_H
#define BEZIER_H
#include <stdlib.h>
#include <stdbool.h>
struct bezier_control_point {
double x, y;
};
extern const struct bezier_control_point bezier_defaults[4];
/**
* Given four control points in the range [(0.0/0.0), (1.0/1.0)]
* construct a Bézier curve.
*
* ^
*1.0 | c2 ______ c3
* | _/
* | /
* |c1 /
* | /
* | /
* |/_________________>
* c0 1.0
*
* This function requires that c[i].x <= c[i+1].x
*
* The curve is mapped into a canvas size [0, bezier_sz)². For each x
* coordinate in [0, bezier_sz), the matching y coordinate is thus
* bezier[x].
*
* In other words, if you have a range [0,2048) input possible values,
* the output is a list of 2048 points in a [0, 2048) range.
*
* @return true on success, false otherwise
*/
bool
cubic_bezier(const struct bezier_control_point controls[4],
int *bezier,
size_t bezier_sz);
#endif

284
src/draglock.c Normal file
View File

@@ -0,0 +1,284 @@
/*
* SPDX-License-Identifier: MIT
*
* 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.
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include "draglock.h"
#include <string.h>
#include <stdlib.h>
#define ARRAY_SIZE(a) (sizeof(a)/sizeof((a)[0]))
static int
draglock_parse_config(struct draglock *dl, const char *config)
{
int button = 0, target = 0;
const char *str = NULL;
char *end_str = NULL;
int pairs[DRAGLOCK_MAX_BUTTONS] = {0};
if (!config)
return 0;
/* empty string disables drag lock */
if (*config == '\0') {
dl->mode = DRAGLOCK_DISABLED;
return 0;
}
/* check for a single-number string first, config is "<int>" */
button = strtol(config, &end_str, 10);
if (*end_str == '\0') {
if (button < 0 || button >= DRAGLOCK_MAX_BUTTONS)
return 1;
/* we allow for button 0 so stacked xorg.conf.d snippets can
* disable the config again */
if (button == 0) {
dl->mode = DRAGLOCK_DISABLED;
return 0;
}
return draglock_set_meta(dl, button);
}
dl->mode = DRAGLOCK_DISABLED;
/* check for a set of button pairs, config is
* "<int> <int> <int> <int>..." */
str = config;
while (*str != '\0') {
button = strtol(str, &end_str, 10);
if (*end_str == '\0')
return 1;
str = end_str;
target = strtol(str, &end_str, 10);
if (end_str == str)
return 1;
if (button <= 0 || button >= DRAGLOCK_MAX_BUTTONS || target >= DRAGLOCK_MAX_BUTTONS)
return 1;
pairs[button] = target;
str = end_str;
}
return draglock_set_pairs(dl, pairs, ARRAY_SIZE(pairs));
}
int
draglock_init_from_string(struct draglock *dl, const char *config)
{
dl->mode = DRAGLOCK_DISABLED;
dl->meta_button = 0;
dl->meta_state = false;
memset(dl->lock_pair, 0, sizeof(dl->lock_pair));
memset(dl->lock_state, 0, sizeof(dl->lock_state));
return draglock_parse_config(dl, config);
}
enum draglock_mode
draglock_get_mode(const struct draglock *dl)
{
return dl->mode;
}
int
draglock_get_meta(const struct draglock *dl)
{
if (dl->mode == DRAGLOCK_META)
return dl->meta_button;
return 0;
}
size_t
draglock_get_pairs(const struct draglock *dl, int *array, size_t nelem)
{
unsigned int i;
size_t last = 0;
if (dl->mode != DRAGLOCK_PAIRS)
return 0;
/* size 1 array with the meta button */
if (dl->meta_button) {
*array = dl->meta_button;
return 1;
}
/* size N array with a[0] == 0, the rest ordered by button number */
memset(array, 0, nelem * sizeof(array[0]));
for (i = 0; i < nelem && i < ARRAY_SIZE(dl->lock_pair); i++) {
array[i] = dl->lock_pair[i];
if (array[i] != 0 && i > last)
last = i;
}
return last;
}
int
draglock_set_meta(struct draglock *dl, int meta_button)
{
if (meta_button < 0 || meta_button >= DRAGLOCK_MAX_BUTTONS)
return 1;
dl->meta_button = meta_button;
dl->mode = meta_button ? DRAGLOCK_META : DRAGLOCK_DISABLED;
return 0;
}
int
draglock_set_pairs(struct draglock *dl, const int *array, size_t nelem)
{
unsigned int i;
if (nelem == 0 || array[0] != 0)
return 1;
for (i = 0; i < nelem; i++) {
if (array[i] < 0 || array[i] >= DRAGLOCK_MAX_BUTTONS)
return 1;
}
dl->mode = DRAGLOCK_DISABLED;
for (i = 0; i < nelem; i++) {
dl->lock_pair[i] = array[i];
if (dl->lock_pair[i])
dl->mode = DRAGLOCK_PAIRS;
}
return 0;
}
static int
draglock_filter_meta(struct draglock *dl, int *button, int *press)
{
int b = *button,
is_press = *press;
if (b == dl->meta_button) {
if (is_press)
dl->meta_state = true;
*button = 0;
return 0;
}
switch (dl->lock_state[b]) {
case DRAGLOCK_BUTTON_STATE_NONE:
if (dl->meta_state && is_press) {
dl->lock_state[b] = DRAGLOCK_BUTTON_STATE_DOWN_1;
dl->meta_state = false;
}
break;
case DRAGLOCK_BUTTON_STATE_DOWN_1:
if (!is_press) {
dl->lock_state[b] = DRAGLOCK_BUTTON_STATE_UP_1;
b = 0;
}
break;
case DRAGLOCK_BUTTON_STATE_UP_1:
if (is_press) {
dl->lock_state[b] = DRAGLOCK_BUTTON_STATE_DOWN_2;
b = 0;
}
break;
case DRAGLOCK_BUTTON_STATE_DOWN_2:
if (!is_press) {
dl->lock_state[b] = DRAGLOCK_BUTTON_STATE_NONE;
}
break;
}
*button = b;
return 0;
}
static int
draglock_filter_pair(struct draglock *dl, int *button, int *press)
{
int b = *button,
is_press = *press;
if (dl->lock_pair[b] == 0)
return 0;
switch (dl->lock_state[b]) {
case DRAGLOCK_BUTTON_STATE_NONE:
if (is_press) {
dl->lock_state[b] = DRAGLOCK_BUTTON_STATE_DOWN_1;
b = dl->lock_pair[b];
}
break;
case DRAGLOCK_BUTTON_STATE_DOWN_1:
if (!is_press) {
dl->lock_state[b] = DRAGLOCK_BUTTON_STATE_UP_1;
b = 0;
}
break;
case DRAGLOCK_BUTTON_STATE_UP_1:
if (is_press) {
dl->lock_state[b] = DRAGLOCK_BUTTON_STATE_DOWN_2;
b = 0;
}
break;
case DRAGLOCK_BUTTON_STATE_DOWN_2:
if (!is_press) {
dl->lock_state[b] = DRAGLOCK_BUTTON_STATE_NONE;
b = dl->lock_pair[b];
}
break;
}
*button = b;
return 0;
}
int
draglock_filter_button(struct draglock *dl, int *button, int *is_press)
{
if (*button == 0)
return 0;
switch(dl->mode) {
case DRAGLOCK_DISABLED:
return 0;
case DRAGLOCK_META:
return draglock_filter_meta(dl, button, is_press);
case DRAGLOCK_PAIRS:
return draglock_filter_pair(dl, button, is_press);
default:
abort();
break;
}
return 0;
}

161
src/draglock.h Normal file
View File

@@ -0,0 +1,161 @@
/*
* SPDX-License-Identifier: MIT
*
* 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.
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#ifndef DRAGLOCK_H
#define DRAGLOCK_H 1
#include <stdbool.h>
#include <stdlib.h>
/* 32 buttons are enough for everybody™
* Note that this is the limit of physical buttons as well as the highest
* allowed target button.
*/
#define DRAGLOCK_MAX_BUTTONS 32
enum draglock_mode
{
DRAGLOCK_DISABLED,
DRAGLOCK_META,
DRAGLOCK_PAIRS
};
enum draglock_button_state
{
DRAGLOCK_BUTTON_STATE_NONE,
DRAGLOCK_BUTTON_STATE_DOWN_1,
DRAGLOCK_BUTTON_STATE_UP_1,
DRAGLOCK_BUTTON_STATE_DOWN_2,
};
struct draglock
{
enum draglock_mode mode;
int meta_button; /* meta key to lock any button */
bool meta_state; /* meta_button state */
unsigned int lock_pair[DRAGLOCK_MAX_BUTTONS + 1];/* specify a meta/lock pair */
enum draglock_button_state lock_state[DRAGLOCK_MAX_BUTTONS + 1]; /* state of any locked buttons */
};
/**
* Initialize the draglock struct based on the config string. The string is
* either a single number to configure DRAGLOCK_META mode or a list of
* number pairs, with pair[0] as button and pair[1] as target lock number to
* configure DRAGLOCK_PAIRS mode.
*
* If config is NULL, the empty string, "0" or an even-numbered list of 0,
* the drag lock mode is DRAGLOCK_DISABLED.
*
* @return 0 on success or nonzero on error
*/
int
draglock_init_from_string(struct draglock *dl, const char *config);
/**
* Get the current drag lock mode.
*
* If the mode is DRAGLOCK_META, a meta button click will cause the next
* subsequent button click to be held logically down until the release of
* the second button click of that same button. Events from the meta button
* are always discarded.
*
* If the mode is DRAGLOCK_PAIRS, any button may be configured with a
* 'target' button number. A click of that button causes the target button
* to be held logically down until the release of the second button click.
*/
enum draglock_mode
draglock_get_mode(const struct draglock *dl);
/**
* @return the meta button number or 0 if the current mode is not
* DRAGLOCK_META.
*/
int
draglock_get_meta(const struct draglock *dl);
/**
* Get the drag lock button mapping pairs. The array is filled with the
* button number as index and the mapped target button number as value, i.e.
* array[3] == 8 means button 3 will draglock button 8.
*
* A value of 0 indicates draglock is disabled for that button.
*
* @note Button numbers start at 1, array[0] is always 0.
*
* @param[in|out] array Caller-allocated array to hold the button mappings.
* @param[in] nelem Maximum number of elements in array
*
* @return The number of valid elements in array or 0 if the current mode is
* not DRAGLOCK_PAIRS
*/
size_t
draglock_get_pairs(const struct draglock *dl, int *array, size_t nelem);
/**
* Set the drag lock config to the DRAGLOCK_META mode, with the given
* button as meta button.
*
* If the button is 0 the mode becomes DRAGLOCK_DISABLED.
*
* @return 0 on success, nonzero otherwise
*/
int
draglock_set_meta(struct draglock *dl, int meta_button);
/**
* Set the drag lock config to the DRAGLOCK_PAIRS mode. The array
* must be filled with the button number as index and the mapped target
* button number as value, i.e.
* array[3] == 8 means button 3 will draglock button 8.
*
* A value of 0 indicates draglock is disabled for that button. If all
* buttons are 0, the mode becomes DRAGLOCK_DISABLED.
*
* @note Button numbers start at 1, array[0] is always 0.
*
* @return 0 on successor nonzero otherwise
*/
int
draglock_set_pairs(struct draglock *dl, const int *array, size_t nelem);
/**
* Process the given button event through the drag lock state machine.
* If the event is to be discarded by the caller, button is set to 0.
* Otherwise, button is set to the button event to process and is_press is
* set to the button state to process.
*
* @param[in|out] button The button number to process
* @param[in|out] is_press nonzero for press, zero for release
*
* @return 0 on success or 1 on error
*/
int
draglock_filter_button(struct draglock *dl, int *button, int *is_press);
#endif /* DRAGLOCK_H */

File diff suppressed because it is too large Load Diff

65
src/util-macros.h Normal file
View File

@@ -0,0 +1,65 @@
/*
* Copyright © 2008-2011 Kristian Høgsberg
* Copyright © 2011 Intel Corporation
* 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.
*/
#pragma once
#include "config.h"
#define ARRAY_LENGTH(a) (sizeof (a) / sizeof (a)[0])
/**
* Iterate through the array _arr, assigning the variable elem to each
* element. elem only exists within the loop.
*/
#define ARRAY_FOR_EACH(_arr, _elem) \
for (__typeof__((_arr)[0]) *_elem = _arr; \
_elem < (_arr) + ARRAY_LENGTH(_arr); \
_elem++)
#define min(a, b) (((a) < (b)) ? (a) : (b))
#define max(a, b) (((a) > (b)) ? (a) : (b))
#define ANSI_HIGHLIGHT "\x1B[0;1;39m"
#define ANSI_RED "\x1B[0;31m"
#define ANSI_GREEN "\x1B[0;32m"
#define ANSI_YELLOW "\x1B[0;33m"
#define ANSI_BLUE "\x1B[0;34m"
#define ANSI_MAGENTA "\x1B[0;35m"
#define ANSI_CYAN "\x1B[0;36m"
#define ANSI_BRIGHT_RED "\x1B[0;31;1m"
#define ANSI_BRIGHT_GREEN "\x1B[0;32;1m"
#define ANSI_BRIGHT_YELLOW "\x1B[0;33;1m"
#define ANSI_BRIGHT_BLUE "\x1B[0;34;1m"
#define ANSI_BRIGHT_MAGENTA "\x1B[0;35;1m"
#define ANSI_BRIGHT_CYAN "\x1B[0;36;1m"
#define ANSI_NORMAL "\x1B[0m"
#define ANSI_UP "\x1B[%dA"
#define ANSI_DOWN "\x1B[%dB"
#define ANSI_RIGHT "\x1B[%dC"
#define ANSI_LEFT "\x1B[%dD"
#define CASE_RETURN_STRING(a) case a: return #a
#define _fallthrough_ __attribute__((fallthrough))

243
src/util-strings.c Normal file
View File

@@ -0,0 +1,243 @@
/*
* Copyright © 2008 Kristian Høgsberg
* 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 "util-strings.h"
/**
* Return the next word in a string pointed to by state before the first
* separator character. Call repeatedly to tokenize a whole string.
*
* @param state Current state
* @param len String length of the word returned
* @param separators List of separator characters
*
* @return The first word in *state, NOT null-terminated
*/
static const char *
next_word(const char **state, size_t *len, const char *separators)
{
const char *next = *state;
size_t l;
if (!*next)
return NULL;
next += strspn(next, separators);
if (!*next) {
*state = next;
return NULL;
}
l = strcspn(next, separators);
*state = next + l;
*len = l;
return next;
}
/**
* Return a null-terminated string array with the contents of argv
* duplicated.
*
* Use strv_free() to free the array.
*
* @return A null-terminated string array or NULL on errors
*/
char**
strv_from_argv(int argc, char **argv)
{
char **strv = NULL;
assert(argc >= 0);
if (argc == 0)
return NULL;
strv = zalloc((argc + 1) * sizeof *strv);
for (int i = 0; i < argc; i++) {
char *copy = safe_strdup(argv[i]);
if (!copy) {
strv_free(strv);
return NULL;
}
strv[i] = copy;
}
return strv;
}
/**
* Return a null-terminated string array with the tokens in the input
* string, e.g. "one two\tthree" with a separator list of " \t" will return
* an array [ "one", "two", "three", NULL ] and num elements 3.
*
* Use strv_free() to free the array.
*
* Another example:
* result = strv_from_string("+1-2++3--4++-+5-+-", "+-", &nelem)
* result == [ "1", "2", "3", "4", "5", NULL ] and nelem == 5
*
* @param in Input string
* @param separators List of separator characters
* @param num_elements Number of elements found in the input string
*
* @return A null-terminated string array or NULL on errors
*/
char **
strv_from_string(const char *in, const char *separators, size_t *num_elements)
{
assert(in != NULL);
const char *s = in;
size_t l, nelems = 0;
while (next_word(&s, &l, separators) != NULL)
nelems++;
if (nelems == 0) {
*num_elements = 0;
return NULL;
}
size_t strv_len = nelems + 1; /* NULL-terminated */
char **strv = zalloc(strv_len * sizeof *strv);
size_t idx = 0;
const char *word;
s = in;
while ((word = next_word(&s, &l, separators)) != NULL) {
char *copy = strndup(word, l);
if (!copy) {
strv_free(strv);
*num_elements = 0;
return NULL;
}
strv[idx++] = copy;
}
*num_elements = nelems;
return strv;
}
/**
* Return a newly allocated string with all elements joined by the
* joiner, same as Python's string.join() basically.
* A strv of ["one", "two", "three", NULL] with a joiner of ", " results
* in "one, two, three".
*
* An empty strv ([NULL]) returns NULL, same for passing NULL as either
* argument.
*
* @param strv Input string array
* @param joiner Joiner between the elements in the final string
*
* @return A null-terminated string joining all elements
*/
char *
strv_join(char **strv, const char *joiner)
{
char **s;
char *str;
size_t slen = 0;
size_t count = 0;
if (!strv || !joiner)
return NULL;
if (strv[0] == NULL)
return NULL;
for (s = strv, count = 0; *s; s++, count++) {
slen += strlen(*s);
}
assert(slen < 1000);
assert(strlen(joiner) < 1000);
assert(count > 0);
assert(count < 100);
slen += (count - 1) * strlen(joiner);
str = zalloc(slen + 1); /* trailing \0 */
for (s = strv; *s; s++) {
strcat(str, *s);
--count;
if (count > 0)
strcat(str, joiner);
}
return str;
}
/**
* Return a pointer to the basename within filename.
* If the filename the empty string or a directory (i.e. the last char of
* filename is '/') NULL is returned.
*/
const char *
safe_basename(const char *filename)
{
const char *basename;
if (*filename == '\0')
return NULL;
basename = strrchr(filename, '/');
if (basename == NULL)
return filename;
if (*(basename + 1) == '\0')
return NULL;
return basename + 1;
}
/**
* Similar to basename() but returns the trunk only without the (last)
* trailing suffix, so that:
*
* - foo.c returns foo
* - foo.a.b returns foo.a
* - foo returns foo
* - foo/ returns ""
*
* @return an allocated string representing the trunk name of the file
*/
char *
trunkname(const char *filename)
{
const char *base = safe_basename(filename);
char *suffix;
if (base == NULL)
return safe_strdup("");
suffix = rindex(base, '.');
if (suffix == NULL)
return safe_strdup(base);
else
return strndup(base, suffix-base);
}

464
src/util-strings.h Normal file
View File

@@ -0,0 +1,464 @@
/*
* Copyright © 2008 Kristian Høgsberg
* 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.
*/
#pragma once
#include "config.h"
#define _GNU_SOURCE
#include <assert.h>
#include <ctype.h>
#include <errno.h>
#include <limits.h>
#include <math.h>
#include <string.h>
#include <stdio.h>
#include <stdbool.h>
#include <stdlib.h>
#include <stdarg.h>
#ifdef HAVE_LOCALE_H
#include <locale.h>
#endif
#ifdef HAVE_XLOCALE_H
#include <xlocale.h>
#endif
#include "util-macros.h"
static inline bool
streq(const char *str1, const char *str2)
{
/* one NULL, one not NULL is always false */
if (str1 && str2)
return strcmp(str1, str2) == 0;
return str1 == str2;
}
static inline bool
strneq(const char *str1, const char *str2, int n)
{
/* one NULL, one not NULL is always false */
if (str1 && str2)
return strncmp(str1, str2, n) == 0;
return str1 == str2;
}
static inline void *
zalloc(size_t size)
{
void *p;
/* We never need to alloc anything more than 1,5 MB so we can assume
* if we ever get above that something's going wrong */
if (size > 1536 * 1024)
assert(!"bug: internal malloc size limit exceeded");
p = calloc(1, size);
if (!p)
abort();
return p;
}
/**
* strdup guaranteed to succeed. If the input string is NULL, the output
* string is NULL. If the input string is a string pointer, we strdup or
* abort on failure.
*/
static inline char*
safe_strdup(const char *str)
{
char *s;
if (!str)
return NULL;
s = strdup(str);
if (!s)
abort();
return s;
}
/**
* Simple wrapper for asprintf that ensures the passed in-pointer is set
* to NULL upon error.
* The standard asprintf() call does not guarantee the passed in pointer
* will be NULL'ed upon failure, whereas this wrapper does.
*
* @param strp pointer to set to newly allocated string.
* This pointer should be passed to free() to release when done.
* @param fmt the format string to use for printing.
* @return The number of bytes printed (excluding the null byte terminator)
* upon success or -1 upon failure. In the case of failure the pointer is set
* to NULL.
*/
__attribute__ ((format (printf, 2, 3)))
static inline int
xasprintf(char **strp, const char *fmt, ...)
{
int rc = 0;
va_list args;
va_start(args, fmt);
rc = vasprintf(strp, fmt, args);
va_end(args);
if ((rc == -1) && strp)
*strp = NULL;
return rc;
}
__attribute__ ((format (printf, 2, 0)))
static inline int
xvasprintf(char **strp, const char *fmt, va_list args)
{
int rc = 0;
rc = vasprintf(strp, fmt, args);
if ((rc == -1) && strp)
*strp = NULL;
return rc;
}
static inline bool
safe_atoi_base(const char *str, int *val, int base)
{
char *endptr;
long v;
assert(base == 10 || base == 16 || base == 8);
errno = 0;
v = strtol(str, &endptr, base);
if (errno > 0)
return false;
if (str == endptr)
return false;
if (*str != '\0' && *endptr != '\0')
return false;
if (v > INT_MAX || v < INT_MIN)
return false;
*val = v;
return true;
}
static inline bool
safe_atoi(const char *str, int *val)
{
return safe_atoi_base(str, val, 10);
}
static inline bool
safe_atou_base(const char *str, unsigned int *val, int base)
{
char *endptr;
unsigned long v;
assert(base == 10 || base == 16 || base == 8);
errno = 0;
v = strtoul(str, &endptr, base);
if (errno > 0)
return false;
if (str == endptr)
return false;
if (*str != '\0' && *endptr != '\0')
return false;
if ((long)v < 0)
return false;
*val = v;
return true;
}
static inline bool
safe_atou(const char *str, unsigned int *val)
{
return safe_atou_base(str, val, 10);
}
static inline bool
safe_atod(const char *str, double *val)
{
char *endptr;
double v;
#ifdef HAVE_LOCALE_H
locale_t c_locale;
#endif
size_t slen = strlen(str);
/* We don't have a use-case where we want to accept hex for a double
* or any of the other values strtod can parse */
for (size_t i = 0; i < slen; i++) {
char c = str[i];
if (isdigit(c))
continue;
switch(c) {
case '+':
case '-':
case '.':
break;
default:
return false;
}
}
#ifdef HAVE_LOCALE_H
/* Create a "C" locale to force strtod to use '.' as separator */
c_locale = newlocale(LC_NUMERIC_MASK, "C", (locale_t)0);
if (c_locale == (locale_t)0)
return false;
errno = 0;
v = strtod_l(str, &endptr, c_locale);
freelocale(c_locale);
#else
/* No locale support in provided libc, assume it already uses '.' */
errno = 0;
v = strtod(str, &endptr);
#endif
if (errno > 0)
return false;
if (str == endptr)
return false;
if (*str != '\0' && *endptr != '\0')
return false;
if (v != 0.0 && !isnormal(v))
return false;
*val = v;
return true;
}
char **strv_from_argv(int argc, char **argv);
char **strv_from_string(const char *in, const char *separator, size_t *num_elements);
char *strv_join(char **strv, const char *joiner);
static inline void
strv_free(char **strv) {
char **s = strv;
if (!strv)
return;
while (*s != NULL) {
free(*s);
*s = (char*)0x1; /* detect use-after-free */
s++;
}
free (strv);
}
/**
* parse a string containing a list of doubles into a double array.
*
* @param in string to parse
* @param separator string used to separate double in list e.g. ","
* @param result double array
* @param length length of double array
* @return true when parsed successfully otherwise false
*/
static inline double *
double_array_from_string(const char *in,
const char *separator,
size_t *length)
{
double *result = NULL;
*length = 0;
size_t nelem;
char **strv = strv_from_string(in, separator, &nelem);
if(!strv)
return result;
double *numv = zalloc(sizeof(double) * nelem);
for (size_t idx = 0; idx < nelem; idx++) {
double val;
if (!safe_atod(strv[idx], &val))
goto out;
numv[idx] = val;
}
result = numv;
numv = NULL;
*length = nelem;
out:
strv_free(strv);
free(numv);
return result;
}
struct key_value_str{
char *key;
char *value;
};
struct key_value_double {
double key;
double value;
};
static inline ssize_t
kv_double_from_string(const char *string,
const char *pair_separator,
const char *kv_separator,
struct key_value_double **result_out)
{
struct key_value_double *result = NULL;
if (!pair_separator || pair_separator[0] == '\0' ||
!kv_separator || kv_separator[0] == '\0')
return -1;
size_t npairs;
char **pairs = strv_from_string(string, pair_separator, &npairs);
if (!pairs || npairs == 0)
goto error;
result = zalloc(npairs * sizeof *result);
for (size_t idx = 0; idx < npairs; idx++) {
char *pair = pairs[idx];
size_t nelem;
char **kv = strv_from_string(pair, kv_separator, &nelem);
double k, v;
if (!kv || nelem != 2 ||
!safe_atod(kv[0], &k) ||
!safe_atod(kv[1], &v)) {
strv_free(kv);
goto error;
}
result[idx].key = k;
result[idx].value = v;
strv_free(kv);
}
strv_free(pairs);
*result_out = result;
return npairs;
error:
strv_free(pairs);
free(result);
return -1;
}
/**
* Strip any of the characters in what from the beginning and end of the
* input string.
*
* @return a newly allocated string with none of "what" at the beginning or
* end of string
*/
static inline char *
strstrip(const char *input, const char *what)
{
char *str, *last;
str = safe_strdup(&input[strspn(input, what)]);
last = str;
for (char *c = str; *c != '\0'; c++) {
if (!strchr(what, *c))
last = c + 1;
}
*last = '\0';
return str;
}
/**
* Return true if str ends in suffix, false otherwise. If the suffix is the
* empty string, strendswith() always returns false.
*/
static inline bool
strendswith(const char *str, const char *suffix)
{
size_t slen = strlen(str);
size_t suffixlen = strlen(suffix);
size_t offset;
if (slen == 0 || suffixlen == 0 || suffixlen > slen)
return false;
offset = slen - suffixlen;
return strneq(&str[offset], suffix, suffixlen);
}
static inline bool
strstartswith(const char *str, const char *prefix)
{
size_t prefixlen = strlen(prefix);
return prefixlen > 0 ? strneq(str, prefix, strlen(prefix)) : false;
}
const char *
safe_basename(const char *filename);
char *
trunkname(const char *filename);
/**
* Return a copy of str with all % converted to %% to make the string
* acceptable as printf format.
*/
static inline char *
str_sanitize(const char *str)
{
if (!str)
return NULL;
if (!strchr(str, '%'))
return strdup(str);
size_t slen = min(strlen(str), 512);
char *sanitized = zalloc(2 * slen + 1);
const char *src = str;
char *dst = sanitized;
for (size_t i = 0; i < slen; i++) {
if (*src == '%')
*dst++ = '%';
*dst++ = *src++;
}
*dst = '\0';
return sanitized;
}

6751
src/xf86libinput.c Normal file

File diff suppressed because it is too large Load Diff

1
test/.gitignore vendored Normal file
View File

@@ -0,0 +1 @@
test-draglock

16
test/Makefile.am Normal file
View File

@@ -0,0 +1,16 @@
AM_CPPFLAGS = $(XORG_CFLAGS) \
$(CWARNFLAGS) \
-I$(top_srcdir)/include \
-I$(top_srcdir)/src
tests = test-draglock test-bezier
noinst_PROGRAMS = $(tests)
test_draglock_SOURCES = test-draglock.c
test_draglock_LDADD = ../src/libdraglock.la
test_bezier_SOURCES = test-bezier.c
test_bezier_LDADD = ../src/libbezier.la -lm
TESTS = $(tests)

208
test/test-bezier.c Normal file
View File

@@ -0,0 +1,208 @@
/*
* SPDX-License-Identifier: MIT
*
* 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 "bezier.h"
#include <assert.h>
#include <string.h>
#include <stdio.h>
static inline void
print_curve(int *bezier, size_t size)
{
/* look at it with gnuplot, "plot 'output-file.txt'" */
for (int i = 0; i < size; i++)
printf("%d %d\n", i, bezier[i]);
}
static void
test_linear(void)
{
const int size = 2048;
int bezier[size];
struct bezier_control_point controls[] = {
{ 0.0, 0.0 },
{ 0.0, 0.0 },
{ 1.0, 1.0 },
{ 1.0, 1.0 }
};
cubic_bezier(controls, bezier, size);
assert(bezier[0] == 0);
assert(bezier[size - 1] == size - 1);
for (int x = 1; x < size; x++)
assert(bezier[x] == x);
}
/* Center point pulled down towards X axis */
static void
test_flattened(void)
{
const int size = 2048;
int bezier[size];
struct bezier_control_point controls[] = {
{ 0.0, 0.0 },
{ 0.1, 0.0 },
{ 1.0, 0.9 },
{ 1.0, 1.0 }
};
cubic_bezier(controls, bezier, size);
assert(bezier[0] == 0);
assert(bezier[size - 1] == size - 1);
for (int x = 1; x < size - 1; x++) {
assert(bezier[x] < x);
}
}
/* Center point pulled up from X axis */
static void
test_raised(void)
{
const int size = 2048;
int bezier[size];
struct bezier_control_point controls[] = {
{ 0.0, 0.0 },
{ 0.1, 0.4 },
{ 0.4, 1.0 },
{ 1.0, 1.0 }
};
cubic_bezier(controls, bezier, size);
assert(bezier[0] == 0);
assert(bezier[size - 1] == size - 1);
for (int x = 1; x < size; x++)
assert(bezier[x] >= x);
for (int x = 10; x < size - 10; x++)
assert(bezier[x] > x);
}
static void
test_windy(void)
{
const int size = 2048;
int bezier[size];
struct bezier_control_point controls[] = {
{ 0.0, 0.0 },
{ 0.0, 0.3 },
{ 1.0, 0.7 },
{ 1.0, 1.0 }
};
cubic_bezier(controls, bezier, size);
assert(bezier[0] == 0);
assert(bezier[size - 1] == size - 1);
for (int x = 1; x < size/2 - 20; x++)
assert(bezier[x] > x);
for (int x = size/2 + 20; x < size - 1; x++)
assert(bezier[x] < x);
}
static void
test_nonzero_x_linear(void)
{
const int size = 2048;
int bezier[size];
int x;
struct bezier_control_point controls[] = {
{ 0.2, 0.0 },
{ 0.2, 0.0 },
{ 0.8, 1.0 },
{ 0.8, 1.0 }
};
cubic_bezier(controls, bezier, size);
x = 0;
do {
assert(bezier[x] == 0);
} while (++x < size * 0.2 - 1);
/* ppc64le, ppc64, aarch64 have different math results at -O2,
resulting in one extra zero at the beginning of the array.
some other numbers are different too but within the error
margin (#99992) */
if (bezier[x] == 0)
x++;
do {
assert(bezier[x] > bezier[x-1]);
} while (++x < size * 0.8 - 1);
do {
assert(bezier[x] == size - 1);
} while (++x < size);
}
static void
test_nonzero_y_linear(void)
{
const int size = 2048;
int bezier[size];
struct bezier_control_point controls[] = {
{ 0.0, 0.2 },
{ 0.0, 0.2 },
{ 1.0, 0.8 },
{ 1.0, 0.8 }
};
cubic_bezier(controls, bezier, size);
assert(bezier[0] == (int)(size * 0.2));
for (int x = 1; x < size; x++) {
assert(bezier[x - 1] <= bezier[x]);
assert(bezier[x] >= (int)(size * 0.2));
}
}
int
main(int argc, char **argv)
{
test_linear();
test_flattened();
test_raised();
test_windy();
test_nonzero_x_linear();
test_nonzero_y_linear();
return 0;
}

548
test/test-draglock.c Normal file
View File

@@ -0,0 +1,548 @@
/*
* SPDX-License-Identifier: MIT
*
* 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 "draglock.h"
#include <assert.h>
#include <string.h>
static void
test_config_empty(void)
{
struct draglock dl;
int rc;
rc = draglock_init_from_string(&dl, NULL);
assert(dl.mode == DRAGLOCK_DISABLED);
assert(rc == 0);
}
static void
test_config_invalid(void)
{
struct draglock dl;
int rc;
/* no trailing space */
rc = draglock_init_from_string(&dl, "1 ");
assert(rc != 0);
assert(dl.mode == DRAGLOCK_DISABLED);
rc = draglock_init_from_string(&dl, "256");
assert(rc != 0);
assert(dl.mode == DRAGLOCK_DISABLED);
rc = draglock_init_from_string(&dl, "-1");
assert(rc != 0);
assert(dl.mode == DRAGLOCK_DISABLED);
rc = draglock_init_from_string(&dl, "1 2 3");
assert(rc != 0);
assert(dl.mode == DRAGLOCK_DISABLED);
rc = draglock_init_from_string(&dl, "0 2");
assert(rc != 0);
assert(dl.mode == DRAGLOCK_DISABLED);
rc = draglock_init_from_string(&dl, "0 0");
assert(rc != 0);
assert(dl.mode == DRAGLOCK_DISABLED);
}
static void
test_config_disable(void)
{
struct draglock dl;
int rc;
rc = draglock_init_from_string(&dl, "");
assert(rc == 0);
assert(dl.mode == DRAGLOCK_DISABLED);
rc = draglock_init_from_string(&dl, "0");
assert(rc == 0);
assert(dl.mode == DRAGLOCK_DISABLED);
}
static void
test_config_meta_button(void)
{
struct draglock dl;
int rc;
rc = draglock_init_from_string(&dl, "1");
assert(rc == 0);
assert(dl.mode == DRAGLOCK_META);
assert(dl.meta_button == 1);
rc = draglock_init_from_string(&dl, "2");
assert(rc == 0);
assert(dl.mode == DRAGLOCK_META);
assert(dl.meta_button == 2);
rc = draglock_init_from_string(&dl, "10");
assert(rc == 0);
assert(dl.mode == DRAGLOCK_META);
assert(dl.meta_button == 10);
}
static void
test_config_button_pairs(void)
{
struct draglock dl;
int rc;
rc = draglock_init_from_string(&dl, "1 1");
assert(rc == 0);
assert(dl.mode == DRAGLOCK_PAIRS);
rc = draglock_init_from_string(&dl, "1 2 3 4 5 6 7 8");
assert(rc == 0);
assert(dl.mode == DRAGLOCK_PAIRS);
rc = draglock_init_from_string(&dl, "1 2 3 4 5 0 7 8");
assert(rc == 0);
assert(dl.mode == DRAGLOCK_PAIRS);
/* all disabled */
rc = draglock_init_from_string(&dl, "1 0 3 0 5 0 7 0");
assert(rc == 0);
assert(dl.mode == DRAGLOCK_DISABLED);
}
static void
test_config_get(void)
{
struct draglock dl;
int rc;
const int sz = 32;
int map[sz];
draglock_init_from_string(&dl, "");
rc = draglock_get_meta(&dl);
assert(rc == 0);
rc = draglock_get_pairs(&dl, map, sz);
assert(rc == 0);
draglock_init_from_string(&dl, "8");
rc = draglock_get_meta(&dl);
assert(rc == 8);
rc = draglock_get_pairs(&dl, map, sz);
assert(rc == 0);
draglock_init_from_string(&dl, "1 2 3 4 5 6");
rc = draglock_get_meta(&dl);
assert(rc == 0);
rc = draglock_get_pairs(&dl, map, sz);
assert(rc == 5);
assert(map[0] == 0);
assert(map[1] == 2);
assert(map[2] == 0);
assert(map[3] == 4);
assert(map[4] == 0);
assert(map[5] == 6);
}
static void
test_set_meta(void)
{
struct draglock dl;
int rc;
draglock_init_from_string(&dl, "");
rc = draglock_set_meta(&dl, 0);
assert(rc == 0);
assert(dl.mode == DRAGLOCK_DISABLED);
rc = draglock_set_meta(&dl, 1);
assert(rc == 0);
assert(dl.mode == DRAGLOCK_META);
rc = draglock_set_meta(&dl, -1);
assert(rc == 1);
rc = draglock_set_meta(&dl, 32);
assert(rc == 1);
}
static void
test_set_pairs(void)
{
struct draglock dl;
int rc;
const int sz = 32;
int map[sz];
draglock_init_from_string(&dl, "");
memset(map, 0, sizeof(map));
rc = draglock_set_pairs(&dl, map, sz);
assert(rc == 0);
assert(dl.mode == DRAGLOCK_DISABLED);
rc = draglock_set_pairs(&dl, map, 1);
assert(rc == 0);
assert(dl.mode == DRAGLOCK_DISABLED);
map[0] = 1;
rc = draglock_set_pairs(&dl, map, 1);
assert(rc == 1);
map[0] = 0;
map[1] = 2;
rc = draglock_set_pairs(&dl, map, sz);
assert(rc == 0);
assert(dl.mode == DRAGLOCK_PAIRS);
map[0] = 0;
map[1] = 0;
map[10] = 8;
rc = draglock_set_pairs(&dl, map, sz);
assert(rc == 0);
assert(dl.mode == DRAGLOCK_PAIRS);
}
static void
test_filter_meta_passthrough(void)
{
struct draglock dl;
int rc;
int button, press;
int i;
rc = draglock_init_from_string(&dl, "10");
assert(rc == 0);
for (i = 0; i < 10; i++) {
button = i;
press = 1;
rc = draglock_filter_button(&dl, &button, &press);
assert(rc == 0);
assert(button == i);
assert(press == 1);
press = 1;
rc = draglock_filter_button(&dl, &button, &press);
assert(rc == 0);
assert(button == i);
assert(press == 1);
}
}
static void
test_filter_meta_click_meta_only(void)
{
struct draglock dl;
int rc;
int button, press;
rc = draglock_init_from_string(&dl, "10");
assert(rc == 0);
button = 10;
press = 1;
rc = draglock_filter_button(&dl, &button, &press);
assert(rc == 0);
assert(button == 0);
button = 10;
press = 0;
rc = draglock_filter_button(&dl, &button, &press);
assert(rc == 0);
assert(button == 0);
}
static void
test_filter_meta(void)
{
struct draglock dl;
int rc;
int button, press;
int i;
rc = draglock_init_from_string(&dl, "10");
assert(rc == 0);
for (i = 1; i < 10; i++) {
/* meta down */
button = 10;
press = 1;
rc = draglock_filter_button(&dl, &button, &press);
assert(rc == 0);
assert(button == 0);
/* meta up */
button = 10;
press = 0;
rc = draglock_filter_button(&dl, &button, &press);
assert(rc == 0);
assert(button == 0);
/* button down -> passthrough */
button = i;
press = 1;
rc = draglock_filter_button(&dl, &button, &press);
assert(rc == 0);
assert(button == i);
/* button up -> eaten */
button = i;
press = 0;
rc = draglock_filter_button(&dl, &button, &press);
assert(rc == 0);
assert(button == 0);
/* button down -> eaten */
button = i;
press = 1;
rc = draglock_filter_button(&dl, &button, &press);
assert(rc == 0);
assert(button == 0);
/* button up -> passthrough */
button = i;
press = 0;
rc = draglock_filter_button(&dl, &button, &press);
assert(rc == 0);
assert(button == i);
assert(press == 0);
}
}
static void
test_filter_meta_extra_click(void)
{
struct draglock dl;
int rc;
int button, press;
int i;
rc = draglock_init_from_string(&dl, "10");
assert(rc == 0);
for (i = 1; i < 10; i++) {
/* meta down */
button = 10;
press = 1;
rc = draglock_filter_button(&dl, &button, &press);
assert(rc == 0);
assert(button == 0);
/* meta up */
button = 10;
press = 0;
rc = draglock_filter_button(&dl, &button, &press);
assert(rc == 0);
assert(button == 0);
/* button down -> passthrough */
button = i;
press = 1;
rc = draglock_filter_button(&dl, &button, &press);
assert(rc == 0);
assert(button == i);
/* button up -> eaten */
button = i;
press = 0;
rc = draglock_filter_button(&dl, &button, &press);
assert(rc == 0);
assert(button == 0);
/* meta down */
button = 10;
press = 1;
rc = draglock_filter_button(&dl, &button, &press);
assert(rc == 0);
assert(button == 0);
/* meta up */
button = 10;
press = 0;
rc = draglock_filter_button(&dl, &button, &press);
assert(rc == 0);
assert(button == 0);
/* button down -> eaten */
button = i;
press = 1;
rc = draglock_filter_button(&dl, &button, &press);
assert(rc == 0);
assert(button == 0);
/* button up -> passthrough */
button = i;
press = 0;
rc = draglock_filter_button(&dl, &button, &press);
assert(rc == 0);
assert(button == i);
assert(press == 0);
}
}
static void
test_filter_meta_interleaved(void)
{
struct draglock dl;
int rc;
int button, press;
int i;
rc = draglock_init_from_string(&dl, "10");
assert(rc == 0);
for (i = 1; i < 10; i++) {
/* meta down */
button = 10;
press = 1;
rc = draglock_filter_button(&dl, &button, &press);
assert(rc == 0);
assert(button == 0);
/* meta up */
button = 10;
press = 0;
rc = draglock_filter_button(&dl, &button, &press);
assert(rc == 0);
assert(button == 0);
/* button down -> passthrough */
button = i;
press = 1;
rc = draglock_filter_button(&dl, &button, &press);
assert(rc == 0);
assert(button == i);
/* button up -> eaten */
button = i;
press = 0;
rc = draglock_filter_button(&dl, &button, &press);
assert(rc == 0);
assert(button == 0);
}
for (i = 0; i < 10; i++) {
/* button down -> eaten */
button = i;
press = 1;
rc = draglock_filter_button(&dl, &button, &press);
assert(rc == 0);
assert(button == 0);
/* button up -> passthrough */
button = i;
press = 0;
rc = draglock_filter_button(&dl, &button, &press);
assert(rc == 0);
assert(button == i);
assert(press == 0);
}
}
static void
test_filter_pairs(void)
{
struct draglock dl;
int rc;
int button, press;
int i;
rc = draglock_init_from_string(&dl, "1 11 2 0 3 13 4 0 5 15 6 0 7 17 8 0 9 19");
assert(rc == 0);
for (i = 1; i < 10; i++) {
button = i;
press = 1;
rc = draglock_filter_button(&dl, &button, &press);
assert(rc == 0);
if (i % 2)
assert(button == i + 10);
else
assert(button == i);
assert(press == 1);
button = i;
press = 0;
rc = draglock_filter_button(&dl, &button, &press);
assert(rc == 0);
if (i % 2) {
assert(button == 0);
} else {
assert(button == i);
assert(press == 0);
}
}
for (i = 1; i < 10; i++) {
button = i;
press = 1;
rc = draglock_filter_button(&dl, &button, &press);
assert(rc == 0);
if (i % 2) {
assert(button == 0);
} else {
assert(button == i);
assert(press == 1);
}
button = i;
press = 0;
rc = draglock_filter_button(&dl, &button, &press);
assert(rc == 0);
if (i % 2)
assert(button == i + 10);
else
assert(button == i);
assert(press == 0);
}
}
int
main(int argc, char **argv)
{
test_config_empty();
test_config_invalid();
test_config_disable();
test_config_meta_button();
test_config_button_pairs();
test_config_get();
test_set_meta();
test_set_pairs();
test_filter_meta_passthrough();
test_filter_meta_click_meta_only();
test_filter_meta();
test_filter_meta_extra_click();
test_filter_meta_interleaved();
test_filter_pairs();
return 0;
}