Commit graph

1579 commits

Author SHA1 Message Date
Gabriel Laskar
20f5f2d962 util: harmonize container_of() definition with linux kernel one
commit 3925936 introduced changes to container_of, this is hopefully the
last part of it.

In the linux kernel, container_of() takes a type name, and not a
variable. Without this, in some cases it is needed to declare an unused
variable in order to call container_of().

example:

	return container_of(dispatch, struct fallback_dispatch, base);

instead of:

	struct fallback_dispatch *p;
	return container_of(dispatch, p, base);

This introduce also list_first_entry(), a simple wrapper around
container_of() to retrieve the first element of a non empty list. It
allows to simplify list_for_each() and list_for_each_safe().

Signed-off-by: Gabriel Laskar <gabriel@lse.epita.fr>
Reviewed-by: Peter Hutterer <peter.hutterer@who-t.net>
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2017-05-17 15:04:41 +10:00
Gabriel Laskar
3236ee0d90 util: use offsetof in container_of
gcc and clang supports offsetof (defined in stddef.h) as defined by C99
and POSIX.1-2001, use it in container_of.

Signed-off-by: Gabriel Laskar <gabriel@lse.epita.fr>
Reviewed-by: Peter Hutterer <peter.hutterer@who-t.net>
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2017-05-15 10:21:51 +10:00
Peter Hutterer
211bed2c25 touchpad: pull the tap exclusion zone down to the full edge zone
This was originally left outside of the button areas in case users tap in
those zones, but we're getting false tap events in that zone.

On a 100mm touchpad, the edge zone is merely 5mm, it's acceptable to ignore
taps in that area even in the software button. We can revisit this if we see
tap detection failures in the future.

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

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
Reviewed-by: Hans de Goede <hdegoede@redhat.com>
2017-05-11 10:30:04 +10:00
Eric Engestrom
368006ef40 evdev: replace null sentinel with ARRAY_SIZE
Signed-off-by: Eric Engestrom <eric.engestrom@imgtec.com>
Reviewed-by: Peter Hutterer <peter.hutterer@who-t.net>
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2017-05-11 10:29:50 +10:00
Peter Hutterer
07ed6d6f92 Ensure enums are size int
Because otherwise things go boom, but unless you passed -fshort-enums this
shouldn't happen anyway. And gcc's documentation says don't do that. So don't
do that, or we'll scream at you.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
Reviewed-by: Armin Krezović <krezovic.armin@gmail.com>
Tested-by: Armin Krezović <krezovic.armin@gmail.com>
Reviewed-by: Eric Engestrom <eric.engestrom@imgtec.com>
2017-05-10 12:52:20 +10:00
Peter Hutterer
02fca305ed Fix va_start compiler warning
../src/libinput.c:56:17: warning: passing an object that undergoes default
argument promotion to 'va_start' has undefined behavior [-Wvarargs]

The enum's size is compiler-defined, so the enum gets promoted to whatever the
compiler chose. That promotion is undefined, so let's use an int here.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
Reviewed-by: Armin Krezović <krezovic.armin@gmail.com>
Tested-by: Armin Krezović <krezovic.armin@gmail.com>
Reviewed-by: Eric Engestrom <eric.engestrom@imgtec.com>
2017-05-10 12:52:16 +10:00
Peter Hutterer
3925936969 util: fix container_of() macro
Fixes a bunch of warnings of the kind
../src/evdev.h:378:32: warning: variable 'f' is uninitialized when used here [-Wuninitialized]
        return container_of(dispatch, f, base);

Just typecasting NULL means we can ignore sample but for the type.

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

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
Reviewed-by: Armin Krezović <krezovic.armin@gmail.com>
Tested-by: Armin Krezović <krezovic.armin@gmail.com>
Reviewed-by: Eric Engestrom <eric.engestrom@imgtec.com>
2017-05-10 12:33:10 +10:00
Peter Hutterer
89490d2b34 util: drop GCC specifics for container_of
clang supports __typeof__ which was the only real difference. Not sure any
other compilers matter (that don't support __typeof__)

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
Reviewed-by: Armin Krezović <krezovic.armin@gmail.com>
Tested-by: Armin Krezović <krezovic.armin@gmail.com>
Reviewed-by: Eric Engestrom <eric.engestrom@imgtec.com>
2017-05-10 12:30:50 +10:00
Peter Hutterer
8dcd71b395 lid: remove the keyboard listener on remove and re-init the listener
If the event listener is added, then removed again on a lid switch on/off
event, the list is set to null. This can trigger two crashes:
* when the keyboard is removed first, the call to
  libinput_device_remove_event_listener() dereferences the null pointer
* when the switch is removed first, the call to device_destroy will find a
  remaining event listener and assert

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

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2017-05-05 12:50:57 +10:00
Peter Hutterer
9d1fdb0c6d touchpad: remove the lid switch listener on device_removed
Sequence triggered by the xorg driver, but basically: if the touchpad is
destroyed before the lid switch, the event listener wasn't removed and an
assertion was triggered.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2017-05-05 12:50:04 +10:00
Peter Hutterer
87b04a0cb2 util: add asserts with useful error messages to catch uninitialized lists
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2017-05-04 15:28:58 +10:00
Peter Hutterer
fc470291f1 Merge branch 'wip/touchpad-tap-timestamps' 2017-05-04 11:51:36 +10:00
Peter Hutterer
61452d80c6 lid: fix some indentation
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2017-05-03 21:08:14 +10:00
Marcos Paulo de Souza
8584c044da touchpad: make use of use tp_for_each_touch
Instead of reimplementing a for loop every time.

Signed-off-by: Marcos Paulo de Souza <marcos.souza.org@gmail.com>
Reviewed-by: Peter Hutterer <peter.hutterer@who-t.net>
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2017-05-03 12:38:15 +10:00
Peter Hutterer
b4f9d7a6b5 doc: fix doxygen group for libinput_event_tablet_pad_get_time
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2017-05-02 15:35:52 +10:00
Peter Hutterer
2d032019b6 doc: document the event timestamps
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2017-05-02 15:32:19 +10:00
Paul Kocialkowski
6af9f8e5fb udev: Remove unused Elantech touchpad model binding
The Elantech touchpad model binding in udev is currently unused, since
pressure values were moved to a udev binding of their own.

This gets rid of the deprecated model binding.

Signed-off-by: Paul Kocialkowski <contact@paulk.fr>
Reviewed-by: Peter Hutterer <peter.hutterer@who-t.net>
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2017-05-02 10:37:44 +10:00
Peter Hutterer
2b867feab7 Put a check in to make sure our events have correct timestamps
This is for debugging purposes only, we cannot guarantee that event timestamps
always go up - at least not across devices. Example: tapping on a touchpad may
delay an event until a timeout expires, but that event is then sent with the
original touch timestamps (i.e. in the past). If any other device produces
events during that timeout period, our timestamps are out-of-order.

This isn't really a bug because we are forced to do that, but for bug-fixing
it can be useful to detect.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2017-04-28 16:47:38 +10:00
Peter Hutterer
ea4332a6cf touchpad: add touch state debugging helper
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2017-04-28 15:37:00 +10:00
Peter Hutterer
691aea6d06 touchpad: for 2/3-finger tap, use the last finger down as press time
This makes the tapping times shorter and hopefully more obvious. It also fixes
a bug where repeated tripletap (by tapping with one finger while leaving the
other two down) could cause incorrect timestamps.

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

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2017-04-28 15:37:00 +10:00
Peter Hutterer
4c0b8ba4c2 touchpad: send multitap button events with the correct timestamps
For multitap, we're one tap behind with the button clicks, i.e. we send the
first full click button on the second tap, etc. Remember the timestamps of the
touches so we can send the events with the right timestamps. This makes
tapping more accurate because the time between taps and various timeouts
matter less for double-click detection.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2017-04-28 15:37:00 +10:00
Peter Hutterer
e461f21c52 touchpad: fix the button timestamps for double/tripletap
Both events had the same timestamp but we have the timestamp from the original
event - use it.

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

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2017-04-28 15:11:30 +10:00
Peter Hutterer
3ecdab130a Merge branch 'wip/touchpad-custom-pressure-values' 2017-04-26 12:38:28 +10:00
Peter Hutterer
fe4e2aef04 touchpad: drop the unused touchpad_model enum
A leftover from synaptics where we do this detection in the driver. libinput
pushes this to the hwdb and sets the model flags accordingly.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2017-04-26 12:38:15 +10:00
Peter Hutterer
8d5f4decb4 touchpad: move the pressure range to a hwdb entry
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2017-04-26 12:38:15 +10:00
Peter Hutterer
97d3ddb070 Merge branch 'wip/touchpad-mt-tool-palm' 2017-04-26 12:23:24 +10:00
Peter Hutterer
7b9aa96d02 Add doc to discourage use of libinput_device_get_output_name()
This is a leftover from when libinput was part of weston and we could
interpret properties correctly. Realistically, the only way this could work
with libinput as external library is if we define precisely what the
definition of an output is. Practically, it's a lot easier to just throw up
our hands and leave it all to the caller.

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

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
Reviewed-by: Pekka Paalanen <pekka.paalanen@collabora.co.uk>
2017-04-25 10:56:48 +10:00
Peter Hutterer
555ee1a989 evdev: improve default scroll button detection
Try to guess the default scroll buttons a bit better. Right now we default to
scroll button 0 (disabled) whenever a device doesn't have a middle button but
we might as well cast a wider net here as setting a scroll button only has a
direct effect when button scrolling is enabled.

Use the first extra button we find or fall back onto the right button if we
don't have any extra buttons.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2017-04-24 10:27:32 +10:00
Peter Hutterer
9495713b05 touchpad: add MT_TOOL-based palm detection
If the touchpad driver tells us something is a palm, go with that.

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

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2017-04-21 10:03:58 +10:00
Peter Hutterer
7d1a047b7c touchpad: add helper function for stopping current actions
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2017-04-21 10:03:16 +10:00
Peter Hutterer
76fce6cddd touchpad: move edge palm init to separate helper
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2017-04-21 10:03:16 +10:00
Peter Hutterer
160d60eb85 touchpad: always enable trackpoint palm detection
Trackpoints are situated so that a user is pretty much guaranteed to trigger
some palm interaction, even if on a small touchpad. Always enable trackpoint
monitoring on touchpads where required.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2017-04-21 10:03:16 +10:00
Peter Hutterer
5a63c82822 touchpad: make palm detection logging a bit easier
Nested trinary conditions are fun, but...

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2017-04-21 10:03:16 +10:00
Peter Hutterer
ddcf1f61bf touchpad: move edge palm detection into a helper too
Just code cleanup, no changes.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2017-04-21 10:03:16 +10:00
Peter Hutterer
a49ebfe593 tablet: remove useless self-assignment
Introduced in 230af3f9fc

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2017-04-01 15:37:24 +10:00
Peter Hutterer
b4bb28caeb touchpad: don't try to unhover touches in NONE state
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2017-03-29 11:13:23 +10:00
Peter Hutterer
24445374b2 test: highlight the various state machines with colors
Makes visual identification easier

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2017-03-28 18:56:38 +10:00
Peter Hutterer
0bd36f2542 test: add color to litest verbose output
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2017-03-28 18:56:38 +10:00
Peter Hutterer
58b89fbf2e evdev: fix typo in log message
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2017-03-28 18:56:38 +10:00
Peter Hutterer
078d5cb332 Merge branch 'wip/tablet-wobbly-lines-v2' 2017-03-23 10:18:19 +10:00
Peter Hutterer
411a3a4766 tablet: add axis smoothing
Taking the tablet events as-is produces the occasional wobble in what should
be a straight line. Bug 99961 has a jpg attachment to illustrate that.
Emulate the wacom driver behavior and average x/y across the last 4 values to
smoothen out these dents.

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

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
Acked-by: Ping Cheng <pingc@wacom.com>
2017-03-23 10:18:09 +10:00
Peter Hutterer
ae11eaa265 tablet: reset delta and changed axes as soon as we send them
We don't have frame events for tablets so we must take care to send the
axis change notifications only once and leave the others as-is. Most of the
axes are absolute so it doesn't really matter, but we need to reset the delta
to make sure clients don't receive the same delta twice.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
Acked-by: Ping Cheng <pingc@wacom.com>
2017-03-23 10:18:09 +10:00
Peter Hutterer
a19d18f9c6 tablet: add assert that deltas are always 0
The tablet axis struct has a delta field that's only useful for the events,
not for our internal axis handling. Make sure we never set it to anything
nonzero.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
Acked-by: Ping Cheng <pingc@wacom.com>
2017-03-23 10:18:09 +10:00
Peter Hutterer
88876e66fa tablet: split point vs delta handling up
Handle the delta in the end once we've updated the device state for all axes.
This requires us to use the device history rather than the current state
delta, and it also requires us to update both x and y whenever an axis change
comes in.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
Acked-by: Ping Cheng <pingc@wacom.com>
2017-03-23 10:18:09 +10:00
Peter Hutterer
230af3f9fc table: move custom rotation handling into a helper function
This is a bit hard to follow:
- tilt is handled first and if either tilt axis is set we fetch *both* tilt axes
  into tablet->axes.tilt
- rotation is handled second but it only triggers if either tilt axis is
  flagged. as we now guarantee to have both axes in tablet->axes.tilt, we
  can continue with the rotation conversion without needing some other state

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
Acked-by: Ping Cheng <pingc@wacom.com>
2017-03-23 10:18:09 +10:00
Peter Hutterer
401bbf52d8 tablet: reshuffle device axis updates
This is prep work for axis smoothing. Modify the various helper functions to
just update the state in the tablet and then grab the state later for better
grouping.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
Acked-by: Ping Cheng <pingc@wacom.com>
2017-03-23 10:18:09 +10:00
Peter Hutterer
1e113f6283 tablet: move the axis transforms to the end
No functional changes, part of the grouping of tablet axis manipulation vs.
processing of that manipulated state.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
Acked-by: Ping Cheng <pingc@wacom.com>
2017-03-23 10:18:09 +10:00
Peter Hutterer
f8aa49b619 tablet: move delta processing down
No functional changes, this is just to group the calls that modify tablet axis
state together and move the bits that rely on this state (but don't modify it)
to the bottom.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
Acked-by: Ping Cheng <pingc@wacom.com>
2017-03-23 10:18:09 +10:00
Peter Hutterer
0d757a94f9 tablet: add a motion history
Stores the processed axes values in a history 4 events deep. Currently unused
but will be used to smoothen out axis values to avoid transducer-caused axis
wobbles.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
Acked-by: Ping Cheng <pingc@wacom.com>
2017-03-23 10:18:09 +10:00
Peter Hutterer
f5d8552cc3 tablet: move definition of tablet_axes down
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
Acked-by: Ping Cheng <pingc@wacom.com>
2017-03-23 10:18:09 +10:00