mirror of
https://gitlab.freedesktop.org/libinput/libinput.git
synced 2026-01-18 18:10:28 +01:00
tablet: use libwacom to identify tablets for left-handedness
A tablet hotplug event is rare and not a time-critical event, so we load the database on tablet init and throw it away again. Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net> Reviewed-by: Stephen Chandler Paul <thatslyude@gmail.com>
This commit is contained in:
parent
1e912b460a
commit
9c62daf1d8
5 changed files with 87 additions and 2 deletions
11
configure.ac
11
configure.ac
|
|
@ -165,6 +165,16 @@ if test "x$build_tests" = "xyes"; then
|
|||
AC_PATH_PROG(VALGRIND, [valgrind])
|
||||
fi
|
||||
|
||||
AC_ARG_ENABLE(libwacom,
|
||||
AS_HELP_STRING([--enable-libwacom],
|
||||
[Use libwacom for tablet identification (default=enabled)]),
|
||||
[use_libwacom="$enableval"],
|
||||
[use_libwacom="yes"])
|
||||
if test "x$use_libwacom" = "xyes"; then
|
||||
PKG_CHECK_MODULES(LIBWACOM, [libwacom], [HAVE_LIBWACOM="yes"])
|
||||
AC_DEFINE(HAVE_LIBWACOM, 1, [Build with libwacom])
|
||||
fi
|
||||
|
||||
AM_CONDITIONAL(HAVE_VALGRIND, [test "x$VALGRIND" != "x"])
|
||||
AM_CONDITIONAL(BUILD_TESTS, [test "x$build_tests" = "xyes"])
|
||||
AM_CONDITIONAL(BUILD_DOCS, [test "x$build_documentation" = "xyes"])
|
||||
|
|
@ -186,6 +196,7 @@ AC_MSG_RESULT([
|
|||
Prefix ${prefix}
|
||||
udev base dir ${UDEV_DIR}
|
||||
|
||||
libwacom enabled ${use_libwacom}
|
||||
Build documentation ${build_documentation}
|
||||
Build tests ${build_tests}
|
||||
Tests use valgrind ${VALGRIND}
|
||||
|
|
|
|||
|
|
@ -31,12 +31,14 @@ libinput_la_SOURCES = \
|
|||
libinput_la_LIBADD = $(MTDEV_LIBS) \
|
||||
$(LIBUDEV_LIBS) \
|
||||
$(LIBEVDEV_LIBS) \
|
||||
$(LIBWACOM_LIBS) \
|
||||
libinput-util.la
|
||||
|
||||
libinput_la_CFLAGS = -I$(top_srcdir)/include \
|
||||
$(MTDEV_CFLAGS) \
|
||||
$(LIBUDEV_CFLAGS) \
|
||||
$(LIBEVDEV_CFLAGS) \
|
||||
$(LIBWACOM_CFLAGS) \
|
||||
$(GCC_CFLAGS)
|
||||
EXTRA_libinput_la_DEPENDENCIES = $(srcdir)/libinput.sym
|
||||
|
||||
|
|
|
|||
|
|
@ -27,6 +27,10 @@
|
|||
#include <stdbool.h>
|
||||
#include <string.h>
|
||||
|
||||
#if HAVE_LIBWACOM
|
||||
#include <libwacom/libwacom.h>
|
||||
#endif
|
||||
|
||||
#define tablet_set_status(tablet_,s_) (tablet_)->status |= (s_)
|
||||
#define tablet_unset_status(tablet_,s_) (tablet_)->status &= ~(s_)
|
||||
#define tablet_has_status(tablet_,s_) (!!((tablet_)->status & (s_)))
|
||||
|
|
@ -645,6 +649,45 @@ tablet_init(struct tablet_dispatch *tablet,
|
|||
return 0;
|
||||
}
|
||||
|
||||
static void
|
||||
tablet_init_left_handed(struct evdev_device *device)
|
||||
{
|
||||
#if HAVE_LIBWACOM
|
||||
struct libinput *libinput = device->base.seat->libinput;
|
||||
WacomDeviceDatabase *db;
|
||||
WacomDevice *d = NULL;
|
||||
WacomError *error;
|
||||
int vid, pid;
|
||||
|
||||
vid = evdev_device_get_id_vendor(device);
|
||||
pid = evdev_device_get_id_product(device);
|
||||
|
||||
db = libwacom_database_new();
|
||||
if (!db)
|
||||
return;
|
||||
error = libwacom_error_new();
|
||||
d = libwacom_new_from_usbid(db, vid, pid, error);
|
||||
|
||||
if (d) {
|
||||
if (libwacom_is_reversible(d))
|
||||
evdev_init_left_handed(device,
|
||||
tablet_change_to_left_handed);
|
||||
} else if (libwacom_error_get_code(error) == WERROR_UNKNOWN_MODEL) {
|
||||
log_info(libinput, "Tablet unknown to libwacom\n");
|
||||
} else {
|
||||
log_error(libinput,
|
||||
"libwacom error: %s\n",
|
||||
libwacom_error_get_message(error));
|
||||
}
|
||||
|
||||
if (error)
|
||||
libwacom_error_free(&error);
|
||||
if (d)
|
||||
libwacom_destroy(d);
|
||||
libwacom_database_destroy(db);
|
||||
#endif
|
||||
}
|
||||
|
||||
struct evdev_dispatch *
|
||||
evdev_tablet_create(struct evdev_device *device)
|
||||
{
|
||||
|
|
@ -659,7 +702,7 @@ evdev_tablet_create(struct evdev_device *device)
|
|||
return NULL;
|
||||
}
|
||||
|
||||
evdev_init_left_handed(device, tablet_change_to_left_handed);
|
||||
tablet_init_left_handed(device);
|
||||
|
||||
return &tablet->base;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -383,6 +383,7 @@ END_TEST
|
|||
|
||||
START_TEST(left_handed)
|
||||
{
|
||||
#if HAVE_LIBWACOM
|
||||
struct litest_device *dev = litest_current_device();
|
||||
struct libinput *li = dev->libinput;
|
||||
struct libinput_event *event;
|
||||
|
|
@ -491,6 +492,15 @@ START_TEST(left_handed)
|
|||
|
||||
libinput_event_destroy(event);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
END_TEST
|
||||
|
||||
START_TEST(no_left_handed)
|
||||
{
|
||||
struct litest_device *dev = litest_current_device();
|
||||
|
||||
ck_assert(!libinput_device_config_left_handed_is_available(dev->libinput_device));
|
||||
}
|
||||
END_TEST
|
||||
|
||||
|
|
@ -1109,7 +1119,8 @@ main(int argc, char **argv)
|
|||
litest_add("tablet:proximity", bad_distance_events, LITEST_TABLET | LITEST_DISTANCE, LITEST_ANY);
|
||||
litest_add("tablet:motion", motion, LITEST_TABLET, LITEST_ANY);
|
||||
litest_add("tablet:motion", motion_event_state, LITEST_TABLET, LITEST_ANY);
|
||||
litest_add("tablet:left_handed", left_handed, LITEST_TABLET, LITEST_ANY);
|
||||
litest_add_for_device("tablet:left_handed", left_handed, LITEST_WACOM_INTUOS);
|
||||
litest_add_for_device("tablet:left_handed", no_left_handed, LITEST_WACOM_CINTIQ);
|
||||
litest_add("tablet:normalization", normalization, LITEST_TABLET, LITEST_ANY);
|
||||
litest_add("tablet:pad", pad_buttons_ignored, LITEST_TABLET, LITEST_ANY);
|
||||
|
||||
|
|
|
|||
|
|
@ -7,3 +7,21 @@
|
|||
fun:litest_run
|
||||
fun:main
|
||||
}
|
||||
{
|
||||
<g_type_register_static>
|
||||
Memcheck:Leak
|
||||
...
|
||||
fun:g_type_register_static
|
||||
}
|
||||
{
|
||||
<g_type_register_static>
|
||||
Memcheck:Leak
|
||||
...
|
||||
fun:g_type_register_fundamental
|
||||
}
|
||||
{
|
||||
<g_type_register_static>
|
||||
Memcheck:Leak
|
||||
...
|
||||
fun:g_malloc0
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue