From ab453cd1f41f4a5ca34aa126dd2bcbc053346de7 Mon Sep 17 00:00:00 2001 From: Peter Hutterer Date: Fri, 21 Aug 2020 09:08:45 +1000 Subject: [PATCH] libei: hook up the API for keymap assignments Signed-off-by: Peter Hutterer --- src/libei-device.c | 49 +++++++++++++++++++++++++++++++++++++++++++++ src/libei-private.h | 6 ++++++ src/libei.h | 11 +++++++++- 3 files changed, 65 insertions(+), 1 deletion(-) diff --git a/src/libei-device.c b/src/libei-device.c index cd38c6d..47fbf13 100644 --- a/src/libei-device.c +++ b/src/libei-device.c @@ -28,6 +28,7 @@ #include "util-bits.h" #include "util-macros.h" #include "util-mem.h" +#include "util-io.h" #include "util-strings.h" #include "libei-private.h" @@ -36,6 +37,7 @@ static void ei_device_destroy(struct ei_device *device) { free(device->name); + xclose(device->keymap.fd); } _public_ @@ -74,6 +76,9 @@ ei_device_new(struct ei *ei) device->id = ++deviceid; device->state = EI_DEVICE_STATE_NEW; device->name = xaprintf("unnamed device %d", device->id); + device->keymap.fd = -1; + device->keymap.source = EI_KEYMAP_SOURCE_SERVER; + device->keymap.type = EI_KEYMAP_TYPE_NONE; return device; } @@ -139,6 +144,32 @@ ei_device_configure_touch_range(struct ei_device *device, device->touch.dim.height = height; } +_public_ void +ei_device_configure_keymap(struct ei_device *device, + enum ei_keymap_type type, + int fd) +{ + if (device->state != EI_DEVICE_STATE_NEW || + !flag_is_set(device->capabilities, EI_DEVICE_CAP_TOUCH)) + return; + + if (fd < 0) + return; + + /* + * This can be a quiet error because it should never happen + * anyway and if it does, the device will just have a -1 keymap + * after being accepted by the server. + */ + int newfd = dup(fd); + if (newfd < 0) + return; + + device->keymap.source = EI_KEYMAP_SOURCE_CLIENT; + device->keymap.type = type; + device->keymap.fd = newfd; +} + _public_ void ei_device_add(struct ei_device *device) { @@ -219,6 +250,24 @@ ei_device_get_touch_height(struct ei_device *device) return device->touch.dim.height; } +_public_ enum ei_keymap_source +ei_device_get_keymap_source(struct ei_device *device) +{ + return device->keymap.source; +} + +_public_ enum ei_keymap_type +ei_device_get_keymap_type(struct ei_device *device) +{ + return device->keymap.type; +} + +_public_ int +ei_device_get_keymap(struct ei_device *device) +{ + return device->keymap.fd; +} + _public_ void ei_device_pointer_motion(struct ei_device *device, double x, double y) diff --git a/src/libei-private.h b/src/libei-private.h index f6b785d..ed18edf 100644 --- a/src/libei-private.h +++ b/src/libei-private.h @@ -87,6 +87,12 @@ struct ei_device { struct { struct dimensions dim; } touch; + + struct { + enum ei_keymap_source source; + enum ei_keymap_type type; + int fd; + } keymap; }; struct ei_event { diff --git a/src/libei.h b/src/libei.h index cb53949..1740335 100644 --- a/src/libei.h +++ b/src/libei.h @@ -496,7 +496,8 @@ ei_device_get_touch_height(struct ei_device *device); * assigned to this device individually. * * If this function returns -1, this device does not have - * an individual keymap assigned. + * an individual keymap assigned and the ei_device_get_keymap_type() is @ref + * EI_KEYMAP_TYPE_NONE. * * FIXME: the current API makes it impossible to know when the keymap has * been consumed so the file stays open forever. @@ -504,6 +505,14 @@ ei_device_get_touch_height(struct ei_device *device); int ei_device_get_keymap(struct ei_device *device); +/** + * Returns the type for this keymap. If the type is @ref + * EI_KEYMAP_TYPE_NONE this device does not have a custom keymap assigned to + * it and ei_device_get_keymap() returns -1. + * + * Otherwise, the type specifies how to interpret the data at the file + * descriptor returned by ei_device_get_keymap(). + */ enum ei_keymap_type ei_device_get_keymap_type(struct ei_device *device);