forked from drath/libratbag
Add ratbag_get_name to retrieve the name of the device
Signed-off-by: Benjamin Tissoires <benjamin.tissoires@gmail.com> # Conflicts: # src/libratbag-private.h # src/libratbag.c
This commit is contained in:
@@ -40,6 +40,7 @@
|
||||
struct ratbag_driver;
|
||||
|
||||
struct ratbag {
|
||||
char *name;
|
||||
int evdev_fd;
|
||||
int refcount;
|
||||
struct ratbag_driver *driver;
|
||||
|
||||
@@ -127,6 +127,7 @@ ratbag_new_from_fd(struct libratbag *libratbag, int fd)
|
||||
struct input_id ids;
|
||||
struct ratbag *ratbag = NULL;
|
||||
struct ratbag_driver *driver;
|
||||
char buf[256];
|
||||
|
||||
if (!libratbag) {
|
||||
fprintf(stderr, "libratbag is NULL\n");
|
||||
@@ -141,6 +142,18 @@ ratbag_new_from_fd(struct libratbag *libratbag, int fd)
|
||||
if (rc < 0)
|
||||
goto out_err;
|
||||
|
||||
memset(buf, 0, sizeof(buf));
|
||||
rc = ioctl(fd, EVIOCGNAME(sizeof(buf) - 1), buf);
|
||||
if (rc < 0)
|
||||
goto out_err;
|
||||
|
||||
free(ratbag->name);
|
||||
ratbag->name = strdup(buf);
|
||||
if (!ratbag->name) {
|
||||
errno = ENOMEM;
|
||||
goto out_err;
|
||||
}
|
||||
|
||||
ratbag_device_init(ratbag, fd);
|
||||
|
||||
driver = ratbag_find_driver(libratbag, &ids);
|
||||
@@ -154,6 +167,8 @@ ratbag_new_from_fd(struct libratbag *libratbag, int fd)
|
||||
return ratbag;
|
||||
|
||||
out_err:
|
||||
if (ratbag)
|
||||
free(ratbag->name);
|
||||
free(ratbag);
|
||||
return NULL;
|
||||
}
|
||||
@@ -169,10 +184,17 @@ ratbag_unref(struct ratbag *ratbag)
|
||||
if (ratbag->refcount > 0)
|
||||
return ratbag;
|
||||
|
||||
free(ratbag->name);
|
||||
free(ratbag);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
LIBRATBAG_EXPORT const char *
|
||||
ratbag_get_name(const struct ratbag* ratbag)
|
||||
{
|
||||
return ratbag->name;
|
||||
}
|
||||
|
||||
static void
|
||||
ratbag_register_driver(struct libratbag *libratbag, struct ratbag_driver *driver)
|
||||
{
|
||||
|
||||
@@ -175,6 +175,15 @@ libratbag_unref(struct libratbag *libratbag);
|
||||
struct ratbag*
|
||||
ratbag_new_from_fd(struct libratbag *libratbag, int fd);
|
||||
|
||||
/**
|
||||
* @ingroup base
|
||||
*
|
||||
* @param ratbag A previously initialized ratbag context
|
||||
* @return The name of the device associated with the given ratbag.
|
||||
*/
|
||||
const char *
|
||||
ratbag_get_name(const struct ratbag* ratbag);
|
||||
|
||||
/**
|
||||
* @ingroup device
|
||||
*/
|
||||
|
||||
@@ -5,6 +5,7 @@ global:
|
||||
libratbag_create_context;
|
||||
libratbag_ref;
|
||||
libratbag_unref;
|
||||
ratbag_get_name;
|
||||
ratbag_new_from_fd;
|
||||
ratbag_unref;
|
||||
local:
|
||||
|
||||
Reference in New Issue
Block a user