Commit graph

341 commits

Author SHA1 Message Date
Peter Hutterer
4b26eac8ad Fix (theoretical) use of uninitialized variable
This cannot ever be unset on any real device, but coverity is unhappy and
that's not making me happy.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2020-02-19 13:31:48 +10:00
Peter Hutterer
27aaba81d5 Don't try to send BTN_TOOL events for zero fingers
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2020-02-19 13:28:38 +10:00
Peter Hutterer
6ccee710bd Ignore slot sync for slots > 256
Clang doesn't support variable length arrays inside a struct so we could
either make our life complicated or just assume no-one is using more than 256
slots and hard-code that. Let's go for the easy solution until someone
notices.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2020-02-19 13:24:21 +10:00
Peter Hutterer
d6c2b3d0de Update the BTN_TOOL bits correctly during SYN_DROPPED handling
Where at least one touch ends during SYN_DROPPED, we send out two event
frames: one with all applicable touch sequences ending (tracking id -1) and
the second one with the whole device state *and* the applicable touch
sequences starting (tracking id != -1).

This requires us to also update the BTN_TOOL_ bits correctly so that they are
correct after the first frame. For that we count the number of previously
known touches and send a 0 event for the matching BTN_TOOL_ bit, together with
a 1 event for the currently known touches.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2020-02-19 11:09:31 +10:00
Peter Hutterer
41de1b0e1a Terminate all stopped/changed touches during SYN_DROPPED in the first frame
The previous event processing had subtle issues with touches stopping during
SYN_DROPPED. All of the device state was processed in the same frame, but if
any touch changed tracking ID during SYN_DROPPED, an inserted SYN_REPORT
resulted in a weird split of events:
- the first frame had all key/sw/abs updates including those slots that
  changed tracking ID, but not the ones that were fully terminated.
- the second frame had only the slots states for newly started touches **and**
  the slot state for touches terminated during SYN_DROPPED but not restarted.

In other words, where three fingers were on the touchpad and slot 0 was lifted
and put down again and slot 1 was lifted but *not* put down again, our frames
contained:
- frame 1: terminate slot 0, BTN_TOOL_TRIPLETAP 0, BTN_TOOL_DOUBLETAP 1
- frame 2: start slot 0, terminate slot 1

Where there was no touch changing tracking ID, only one frame was generated.
The BTN_TOOL updates were buggy, they may not match the number of fingers down
as seen on a frame-by-frame basis. This triggered libinput bug
https://gitlab.freedesktop.org/libinput/libinput/issues/422

This patch changes the above example to
- frame 1: terminate slot 0, terminate slot 1
- frame 2: start slot 0, BTN_TOOL_TRIPLETAP 0, BTN_TOOL_DOUBLETAP 1

Notably, the first frame no longer contains the BTN_TOOL bits. This patch is
one of two, the BTN_TOOL sync bits are part of a follow-up patch.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2020-02-19 11:06:28 +10:00
Peter Hutterer
2056da9517 Invert an if condition
Go from:
  if (a != b)
     continue;
  foo;

to:
  if (a == b) {
      foo;
  }

Basically just an indentation change after the condition inversion, makes the
follow-up patch easier to review.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2020-02-19 10:37:46 +10:00
Peter Hutterer
507bd1ee28 Push terminating the slots into a helper function
No functional changes.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2020-02-19 10:37:24 +10:00
Peter Hutterer
e38e3ae7c8 Split the MT state syncing and event generation into two functions
In the near future, we will need to handle slot termination *before* any other
state synchronization. So let's start splitting things up.

This is functionally equivalent though dropping the need_tracking_id_changes
variable means we run through all slots now to check if we need to terminate
one of them. Given the normal number of slots on a device and that this should
only ever run very rarely anyway... meh.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2020-02-19 10:35:59 +10:00
Peter Hutterer
b64f94f9c4 Expand the touch state handling during SYN_DROPPED
Keep a better state of each touch before/after the SYN_DROPPED. Most of this
is currently unused, it's functionally the same as before but the new code
serves to increase readability and it can be passed around easier this way.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2020-02-19 10:31:53 +10:00
Peter Hutterer
b2ec3cb7d4 Make the code for handling before/after SYN_DROPPED slot values more readable
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2020-02-19 09:05:22 +10:00
Peter Hutterer
388644b22b Compress an if statement
No functional changes, just making the code slightly more compressed

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2020-02-16 22:02:44 +00:00
Peter Hutterer
50ebda0263 Localize two variables
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2020-02-16 22:02:44 +00:00
Peter Hutterer
6430694715 Uncomplicate the setting of axis during slot sync
A few bytes get wasted, but no magic handling of offsets etc are required.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2020-02-16 22:02:44 +00:00
Peter Hutterer
c04f5bcec0 Push the tracking id change bits on the stack
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2020-02-16 22:02:44 +00:00
Peter Hutterer
5501973320 Push the slot_update bits on the stack
Much simpler code this way

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2020-02-16 22:02:44 +00:00
Peter Hutterer
757f2d4900 Drop the mt_sync_state in our device struct
Replace it with a stack-allocated one. This saves us a bunch of confusing
allocations and size calculations.

And in the process use uint32_t/int32_t to ensure the struct is actually the
expected size.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2020-02-16 22:02:43 +00:00
Peter Hutterer
977891bd88 flake8 fixes for make-event-names.py
Mostly whitespace changes, two semicolon removals and one change to "foo is
None".

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2020-02-14 12:50:16 +10:00
Peter Hutterer
4d4873d101 Change the python script to generate event names to Python3
It's well past time. If you need this to run on python2, patch it out locally.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2020-02-14 12:50:16 +10:00
Peter Hutterer
939076efc9 uinput: drop an unused function argument
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2020-02-14 12:03:23 +10:00
Peter Hutterer
4c8a7a265d config.h is a local include path
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2020-02-14 12:03:23 +10:00
Peter Hutterer
25cddcecd3 Add queue_push_event as shortcut for the two-liner we use everywhere
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2020-02-12 21:41:15 +10:00
Peter Hutterer
0af21e0e74 Simplify some error handling by assuming a >=3.4 kernel
v3.4 was released in 2012, every kernel since has that ioctl. So instead of
assuming you're running new libevdev on an 8 year old kernel, let's assume
that any error from the ioctl() is an actual error and handle it accordingly.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2020-02-11 21:07:06 +10:00
Peter Hutterer
28dbb3399a doc: add markdown for monospace rendering of defines
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2020-02-11 20:46:14 +10:00
Michael Forney
1f1bd4e2ce Only use GCC pragma on GCC
Signed-off-by: Michael Forney <mforney@mforney.org>
2020-02-05 20:31:30 -08:00
Michael Forney
2f300eb6b5 Avoid initializer index range
This is a GNU C extension, and is not available in ISO C.

Instead, just explicitly initialize other indices to -1.

Signed-off-by: Michael Forney <mforney@mforney.org>
2020-02-05 20:31:30 -08:00
Michael Forney
06ef34c86b Add fallback min/max for compilers that don't have statement expressions
Statement expressions are a GNU C extension and are not available
in ISO C.

On compilers that don't have them, define these macros as plain
conditional expressions, since they are only ever used with expressions
that have no side-effects.

The statement-expression version is still retained as an added
safety measure on GNU-compatible compilers.

Signed-off-by: Michael Forney <mforney@mforney.org>
2020-02-05 20:30:39 -08:00
Peter Hutterer
9a5f44a605 make-event-names.py should take the files as argument
Don't rely on cat, just let our script read everything as required.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2019-10-23 03:13:50 +00:00
Alexander Dahl
2c6733fc67 doc: Fix function names in simple code example
That code did not compile because those functions were only renamed in
header and code back then, but not in the example.

Fixes: ab2f20bfd6 ("Revamp the API once again")
Signed-off-by: Alexander Dahl <ada@thorsis.com>
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2019-09-13 15:30:57 +10:00
Nayan Deshmukh
a2bb53262f doc: add a note regarding truncation of id_* fields
The id_* fields are 16 bits in linux/input.h and we mirror
the kernel API here. Even though we accept an int for this
fields in ABI the value is truncated at 16 bits.

Signed-off-by: Nayan Deshmukh <nayan26deshmukh@gmail.com>
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2019-08-05 08:26:15 +10:00
Peter Hutterer
da67db5f59 Initialize the slots correctly when enabling ABS_MT_SLOT
Previously, enabling or disabling ABS_MT_SLOT would not change the actual
slots, it was treated as a normal bitflag. This means we couldn't initialize a
libevdev context from scratch and have it behave like a correct MT context.

Fixes #4

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2019-06-18 09:31:41 +10:00
Peter Hutterer
4d745caab4 doc: fix a typo
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2019-06-12 08:55:42 +10:00
Peter Hutterer
49206a2aba doc: minor documentation updates
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2019-06-05 10:56:45 +10:00
Peter Hutterer
a68e91b172 doc: change @retval documentation to help doxygen with rendering
This causes some weird rendering, let's split it into a list (which also
happens to be more readable).

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2019-06-03 17:48:28 +10:00
Peter Hutterer
c8be2b3260 doc: fix some doxygen layout
The linewrapped 1 caused doxygen to start a list

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2019-06-03 17:48:11 +10:00
Peter Hutterer
cf645672dc doc: fix some doxygen warnings
warning: explicit link request to 'defines' could not be resolved

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2019-06-03 17:47:41 +10:00
Peter Hutterer
9fe185dd3d Add a code-based name lookup function
Two new function pairs:
	libevdev_event_code_from_code_name()
	libevdev_event_type_from_code_name()

	libevdev_event_code_from_code_name_n()
	libevdev_event_type_from_code_name_n()

These functions look up event codes/types by the name of the event code only,
removing the need to figure out what event type an event code has. So if all
you have is "BTN_TOUCH", you can now look up the type and code for that,
without having to check the prefix yourself to guess at the type.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2019-03-21 00:55:32 +00:00
Peter Hutterer
76662deeff Don't read events unless required
With the previous approach, every libevdev_next_event() invocation triggered a
read() on the device fd. This is not efficient, the kernel provides whole
event frames at a time so we're guaranteed to have more events waiting unless
the current event is a SYN_REPORT.

Assuming a fast-enough client and e.g. a touchpad device with multiple axes
per frame, we'd thus trigger several unnecessary read() calls per event frame.

Drop this behavior, instead only trigger the read when our internal queue is
empty and we need more events.

Fallout:
- we don't have any warning about a too-slow sync, i.e. if a SYN_DROPPED
  arrives while we're syncing, we don't get a warning in the log anymore.
  the test for this was removed.
- the tests that required the specific behavior were rewritten accordingly
- a revoke on a kernel device doesn't return ENODEV until already-received
  events have been processed

The above shouldn't be an issue for existing real-world clients.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2019-03-19 01:02:52 +00:00
Peter Hutterer
6852dadbca Replace ABS_MT_SLOT - 1 with the v4.20 ABS_RESERVED define
ABS_RESERVED was added to 4.20 for that reason, to keep that event code
reserved so we can't use it for anything else (and thus mess up the fake MT
detection).

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2019-01-16 13:17:33 +10:00
Peter Hutterer
41e47b7043 include: sync event codes with kernel 4.19
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2018-10-22 18:55:57 +10:00
Peter Hutterer
1e605f6282 Add libevdev_event_value_get_name() to resolve ABS_MT_TOOL_TYPE values
ABS_MT_TOOL_TYPE values are an enum, not a numerical value like all other
axes. So let's allow converting those values to string.

Fixes https://gitlab.freedesktop.org/libevdev/libevdev/issues/1

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
Reviewed-by: Benjamin Tissoires <benjamin.tissoires@gmail.com>
2018-07-09 11:57:57 +10:00
Peter Hutterer
d9cfd143d0 Resolve the names "SW_MAX" and friends
Some of the *_MAX names are duplicates and have a real define. These were not
resolved until now.

Fixes https://gitlab.freedesktop.org/libevdev/libevdev/issues/3

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
Reviewed-by: Benjamin Tissoires <benjamin.tissoires@gmail.com>
2018-07-09 11:57:57 +10:00
Peter Hutterer
812fc7096d make-event-names: minor cleanups for readability
Two variable renames for less ambiguity
Two changes from an long if condition to a "if foo in [...]"

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
Reviewed-by: Benjamin Tissoires <benjamin.tissoires@gmail.com>
2018-07-09 11:57:57 +10:00
Peter Hutterer
c3953e1bb8 Change all URLs to gitlab.fdo
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2018-06-06 18:20:11 +10:00
Deepa Dinamani
3c6766c862 Update struct input_event
The struct input_event is not y2038 safe.
Update the struct according to the kernel patch:
https://lkml.org/lkml/2018/1/6/324

Signed-off-by: Deepa Dinamani <deepa.kernel@gmail.com>
Reviewed-by: Peter Hutterer <peter.hutterer@who-t.net>
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2018-04-12 15:23:22 +10:00
Peter Hutterer
6ff816163e Blacklist SW_MAX so it doesn't shadow SW_PEN_INSERTED
They have the same value, so the _MAX code would shadow the real code, causing
issues in any client that needs to get all event names from libevdev.
Specifically, the loop of:
  for each code in 0 to max-for-type:
      print(name)
would not show up the code (but the _MAX) code instead. This causes issues
with clients that rely on name resolution that works. And the _MAX values are
special values anyway.

Blacklist it in the script here, causing it to resolve from name to code, but
not from code to name (like other duplicated codes).

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
Reviewed-by: Benjamin Tissoires <benjamin.tissoires@gmail.com>
2018-02-26 17:12:08 +10:00
Peter Hutterer
a67d1964ff Blacklist REP_MAX so it doesn't shadow REP_PERIOD
They have the same value, so the _MAX code would shadow the real code, causing
issues in any client that needs to get all event names from libevdev.
Specifically, the loop of:
  for each code in 0 to max-for-type:
      print(name)
would not show up the code (but the _MAX) code instead. This causes issues
with clients that rely on name resolution that works. And the _MAX values are
special values anyway.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
Reviewed-by: Benjamin Tissoires <benjamin.tissoires@gmail.com>
2018-02-26 17:12:08 +10:00
Peter Hutterer
3799acd49e Drop the python map printing
leftover from when this was part of evemu

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
Reviewed-by: Benjamin Tissoires <benjamin.tissoires@gmail.com>
2018-02-26 16:53:55 +10:00
Peter Hutterer
0637d0237a When changing the fd, reset our grab state to ungrabbed
Previously, calling grabbing a device after changing the fd was a no-op
because libevdev's grab state didn't match the fd:

libevdev_grab(LIBEVDEV_GRAB);
  .. fd is grabbed
  .. internal state is 'grabbed'
libevdev_change_fd();
  .. new fd is ungrabbed
  .. internal state is 'grabbed'
libevdev_grab(LIBEVDEV_GRAB);
  .. argument matches internal state and we exit without grabbing the device

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2017-12-13 10:01:58 +10:00
Peter Hutterer
c6e11a0a80 uinput: make a note that the syspath we return is the input node
And not the syspath for the /dev/input/eventX node

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2017-07-03 09:55:29 +10:00
Peter Hutterer
abfb307e18 Fix an indentation issues
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2017-04-25 09:27:16 +10:00