Name-space the scroll event types

To provide a generic naming system of type_direction. That will become more
important once we add new axes as part of the ongoing work to support graphics
tablets.

[edit: and switch to the new defines]

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
Reviewed-by: Hans de Goede <hdegoede@redhat.com>
tools: add a tool for GUI-based debugging

Looking at debugging output is nice but not useful when testing for the feel
of a device. Add a tool that presents a canvas and draws the various events
onto it.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
Rename KEYBOARD_KEY_STATE to KEY_STATE

e912d620d0f20f415b4d3dde967648e4b9c317b9 changed from POINTER_BUTTON_STATE to
simply BUTTON_STATE, replicate that for key events too.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
test: move the interface declaration up

No functional changes, just some prep work.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
udev: split libinput_udev context init into two functions

This is preparation work for context-specific log handlers.

Callers are now encouraged to first initialize the context with
libinput_udev_create_context() and then set the seat for this context with
libinput_udev_assign_seat().

In the upcoming patch to support context-specific log handlers this enables a
caller to set the log handler for a context before any devices are
initialized. Otherwise, a log message generated by a new device may pass a
libinput context that the caller is not yet aware of.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
Reviewed-by: Hans de Goede <hdegoede@redhat.com>
Change the logging system to be per-context

Rather than a single global logging function, make the logging dependent on
the individual context. This way we won't stomp on each other's feet in the
(admittedly unusual) case of having multiple libinput contexts.

The userdata argument to the log handler was dropped. The caller has a ref to
the libinput context now, any userdata can be attached to that context
instead.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
Reviewed-by: Hans de Goede <hdegoede@redhat.com>
event-gui: Don't drop fraction of pointer motion events

Signed-off-by: Jonas Ådahl <jadahl@gmail.com>
Make ref count unref/ref() functions return resulting object pointer

In order to know if an unref() destroyed an object and to allow more
convenient use of ref(), make both functions return a pointer to the
object it was passed, or NULL if that object was destroyed.

Signed-off-by: Jonas Ådahl <jadahl@gmail.com>
Reviewed-by: Peter Hutterer <peter.hutterer@who-t.net>
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
Make context reference counted

Instead of only allowing one owner keeping a libinput context alive,
make context reference counted, replacing libinput_destroy() with
libinput_unref() while adding another function libinput_ref().

Even though there might not be any current use cases, it doesn't mean we
should hard code this usage model in the API. The old behaviour can be
emulated by never calling libinput_ref() while replacing
libinput_destroy() with libinput_unref().

Signed-off-by: Jonas Ådahl <jadahl@gmail.com>
Reviewed-by: Peter Hutterer <peter.hutterer@who-t.net>
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
test: Add context reference counting test

This test relies on valgrind detecting the leak and use-after-free.

Signed-off-by: Jonas Ådahl <jadahl@gmail.com>
Reviewed-by: Peter Hutterer <peter.hutterer@who-t.net>
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
Merge branch 'ref-counting-context'

Conflicts:
	src/udev-seat.c
	test/log.c
Add msleep() helper function

For those whose eyes struggle to focus on 5 zeros in a row, or those just sick
of forgetting one zero and wondering why things don't work.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
Reviewed-by: Hans de Goede <hdegoede@redhat.com>
test: add one more test for two-finger tapping

Inverted order of release from the other test

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
Reviewed-by: Hans de Goede <hdegoede@redhat.com>
test: Add touchpad 2 finger scroll test

Signed-off-by: Hans de Goede <hdegoede@redhat.com>
Reviewed-by: Peter Hutterer <peter.hutterer@who-t.net>
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
touchpad: Avoid spurious motion event for scroll movement below threshold

If the user puts down to fingers to scroll, then changes his mind and
lifts them, without having them moved past the initial scroll threshold in
either direction, then any movement which he has done will cause a spurious
scroll event when the second finger down is lifted first.

The problem is that t->is_pointer was not being set to false in this case,
since that is done in tp_post_twofinger_scroll after checking scroll.state
which never gets set in this scenario.

Instead of changing the order, simply completely remove scroll.state completely
it is a boolean, and everywhere we check for it we also check for the axis bits
in state.direction, so it is not necessary.

Also add a check to ensure there are no spurious motion events.

Signed-off-by: Hans de Goede <hdegoede@redhat.com>
Reviewed-by: Peter Hutterer <peter.hutterer@who-t.net>
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
tp_post_twofinger_scroll: Move setting of t->is_pointer = false up a bit

There is no need to loop over the touch points twice.

Signed-off-by: Hans de Goede <hdegoede@redhat.com>
Reviewed-by: Peter Hutterer <peter.hutterer@who-t.net>
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
test: Prefix litest created device names with litest

And add an example xorg.conf.d .conf file for ignoring these devices under
xorg.

Signed-off-by: Hans de Goede <hdegoede@redhat.com>
Reviewed-by: Peter Hutterer <peter.hutterer@who-t.net>
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
timer: Complain if a timer is set more than 5 seconds from now

Signed-off-by: Hans de Goede <hdegoede@redhat.com>
Reviewed-by: Peter Hutterer <peter.hutterer@who-t.net>
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
Drop the deprecated LIBINPUT_POINTER_*_SCROLL enums

We have enough API breakage in this release that it's not worth keeping
these around. Every caller must be fixed for all the other stuff anyway,
so drop this too.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
Fix a few comments referring to udev_create_for_seat()

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>