mirror of
https://gitlab.freedesktop.org/libevdev/libevdev.git
synced 2026-01-05 10:10:11 +01:00
Expose phys/uniq to the caller
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
This commit is contained in:
parent
a98c9b3bee
commit
4318b73549
6 changed files with 106 additions and 0 deletions
|
|
@ -53,6 +53,8 @@ struct libevdev {
|
|||
libevdev_log_func_t log;
|
||||
|
||||
char name[MAX_NAME];
|
||||
char *phys;
|
||||
char *uniq;
|
||||
struct input_id ids;
|
||||
int driver_version;
|
||||
unsigned long bits[NLONGS(EV_CNT)];
|
||||
|
|
|
|||
|
|
@ -180,6 +180,8 @@ libevdev_new_from_fd(int fd, struct libevdev **dev)
|
|||
void
|
||||
libevdev_free(struct libevdev *dev)
|
||||
{
|
||||
free(dev->phys);
|
||||
free(dev->uniq);
|
||||
queue_free(dev);
|
||||
free(dev);
|
||||
}
|
||||
|
|
@ -204,6 +206,7 @@ libevdev_set_fd(struct libevdev* dev, int fd)
|
|||
{
|
||||
int rc;
|
||||
int i;
|
||||
char buf[256];
|
||||
|
||||
if (dev->fd != -1)
|
||||
return -EBADF;
|
||||
|
|
@ -216,6 +219,35 @@ libevdev_set_fd(struct libevdev* dev, int fd)
|
|||
if (rc < 0)
|
||||
goto out;
|
||||
|
||||
memset(buf, 0, sizeof(buf));
|
||||
rc = ioctl(fd, EVIOCGPHYS(sizeof(buf) - 1), buf);
|
||||
if (rc < 0) {
|
||||
/* uinput has no phys */
|
||||
if (errno != ENOENT)
|
||||
goto out;
|
||||
} else {
|
||||
dev->phys = calloc(strlen(buf) + 1, sizeof(char));
|
||||
if (!dev->phys) {
|
||||
errno = ENOSPC;
|
||||
goto out;
|
||||
}
|
||||
strcpy(dev->phys, buf);
|
||||
}
|
||||
|
||||
memset(buf, 0, sizeof(buf));
|
||||
rc = ioctl(fd, EVIOCGUNIQ(sizeof(buf) - 1), buf);
|
||||
if (rc < 0) {
|
||||
if (errno != ENOENT)
|
||||
goto out;
|
||||
} else {
|
||||
dev->uniq = calloc(strlen(buf) + 1, sizeof(char));
|
||||
if (!dev->uniq) {
|
||||
errno = ENOSPC;
|
||||
goto out;
|
||||
}
|
||||
strcpy(dev->uniq, buf);
|
||||
}
|
||||
|
||||
rc = ioctl(fd, EVIOCGID, &dev->ids);
|
||||
if (rc < 0)
|
||||
goto out;
|
||||
|
|
@ -588,6 +620,18 @@ libevdev_get_name(const struct libevdev *dev)
|
|||
return dev->name;
|
||||
}
|
||||
|
||||
const char *
|
||||
libevdev_get_phys(const struct libevdev *dev)
|
||||
{
|
||||
return dev->phys;
|
||||
}
|
||||
|
||||
const char *
|
||||
libevdev_get_uniq(const struct libevdev *dev)
|
||||
{
|
||||
return dev->uniq;
|
||||
}
|
||||
|
||||
int libevdev_get_product_id(const struct libevdev *dev)
|
||||
{
|
||||
return dev->ids.product;
|
||||
|
|
|
|||
|
|
@ -181,6 +181,22 @@ int libevdev_next_event(struct libevdev *dev, unsigned int flags, struct input_e
|
|||
*/
|
||||
const char* libevdev_get_name(const struct libevdev *dev);
|
||||
|
||||
/**
|
||||
* Virtual devices such as uinput devices have no phys location.
|
||||
*
|
||||
* @return The physical location of this device, or NULL if there is none
|
||||
*
|
||||
* @note This function is signal safe.
|
||||
*/
|
||||
const char * libevdev_get_phys(const struct libevdev *dev);
|
||||
|
||||
/**
|
||||
* @return The unique identifier for this device, or NULL if there is none
|
||||
*
|
||||
* @note This function is signal safe.
|
||||
*/
|
||||
const char * libevdev_get_uniq(const struct libevdev *dev);
|
||||
|
||||
/**
|
||||
* @return The device's product ID
|
||||
*
|
||||
|
|
|
|||
|
|
@ -9,6 +9,7 @@ man_src = \
|
|||
libevdev_get_abs_min.txt \
|
||||
libevdev_get_name.txt \
|
||||
libevdev_get_num_slots.txt \
|
||||
libevdev_get_phys.txt \
|
||||
libevdev_grab.txt \
|
||||
libevdev_has_event_type.txt \
|
||||
libevdev_new.txt \
|
||||
|
|
|
|||
41
man/libevdev_get_phys.txt
Normal file
41
man/libevdev_get_phys.txt
Normal file
|
|
@ -0,0 +1,41 @@
|
|||
libevdev_get_phys(3)
|
||||
====================
|
||||
|
||||
NAME
|
||||
----
|
||||
|
||||
libevdev_get_phys, libevdev_get_uniq - retreive the physical location and unique identifier for this device
|
||||
|
||||
SYNOPSIS
|
||||
--------
|
||||
|
||||
#include <libevdev/libevdev.h>
|
||||
|
||||
|
||||
DESCRIPTION
|
||||
-----------
|
||||
|
||||
*libevdev_get_phys* returns a pointer to a string representing the physical
|
||||
location of this device. For virtual devices such as those created by
|
||||
uinput, no physical location is available.
|
||||
|
||||
*libevdev_get_uniq* returns a pointer to a uniq identifier of this device.
|
||||
Not all devices have such an identifier.
|
||||
|
||||
PARAMETERS
|
||||
----------
|
||||
*dev*::
|
||||
Pointer to the libevdev device.
|
||||
|
||||
RETURN VALUE
|
||||
------------
|
||||
*libevdev_get_phys* returns a pointer to a string representing the physical
|
||||
location of this device, or NULL if none is defined.
|
||||
|
||||
*libevdev_get_uniq* returns a pointer to a uniq identifier of this device,
|
||||
or NULL if none is defined.
|
||||
|
||||
SEE ALSO
|
||||
--------
|
||||
|
||||
libevdev_get_name(3)
|
||||
|
|
@ -137,6 +137,8 @@ main(int argc, char **argv)
|
|||
libevdev_get_product_id(dev));
|
||||
printf("Evdev version: %x\n", libevdev_get_driver_version(dev));
|
||||
printf("Input device name: \"%s\"\n", libevdev_get_name(dev));
|
||||
printf("Phys location: %s\n", libevdev_get_phys(dev));
|
||||
printf("Uniq identifier: %s\n", libevdev_get_uniq(dev));
|
||||
print_bits(dev);
|
||||
print_props(dev);
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue