libei: hook up the API for keymap assignments

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
This commit is contained in:
Peter Hutterer 2020-08-21 09:08:45 +10:00
parent 5749f3ec27
commit ab453cd1f4
3 changed files with 65 additions and 1 deletions

View file

@ -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)

View file

@ -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 {

View file

@ -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);