1
0
forked from drath/libratbag

drivers: add a fallback for fetching the SVG name

In case the udev property is not present, we might want to query
the driver for the SVG name.
This is useful for driver-test as there is no udev device attached to
it, and for hidpp20 as we have auto-detection. We should then be able
to implement this in hidpp20 also so that the name gets automatically
created.

Signed-off-by: Benjamin Tissoires <benjamin.tissoires@gmail.com>
This commit is contained in:
Benjamin Tissoires
2017-07-12 06:44:40 +02:00
parent f55a314666
commit e522e0bb07
5 changed files with 27 additions and 2 deletions

View File

@@ -193,6 +193,7 @@ static struct ratbag_test_device ratbagd_test_device_descr = {
.num_resolutions = 3,
.num_buttons = 4,
.num_leds = 3,
.svg = "logitech-g500.svg",
.profiles = {
{
.buttons = {

View File

@@ -170,6 +170,13 @@ test_write_led(struct ratbag_led *led,
return 0;
}
static const char* test_get_svg_name(const struct ratbag_device *device)
{
struct ratbag_test_device *d = ratbag_get_drv_data(device);
return d->svg;
}
static int
test_fake_probe(struct ratbag_device *device)
{
@@ -211,6 +218,7 @@ struct ratbag_driver test_driver = {
.probe = test_fake_probe,
.test_probe = test_probe,
.remove = test_remove,
.get_svg_name = test_get_svg_name,
.read_profile = test_read_profile,
.write_profile = test_write_profile,
.set_active_profile = test_set_active_profile,

View File

@@ -144,6 +144,15 @@ struct ratbag_driver {
*/
int (*commit)(struct ratbag_device *device);
/**
* Callback called when the device doesn't have the udev property
* RATBAG_SVG.
*
* The returned value must not be free by the caller, the driver
* has to free it during .remove().
*/
const char *(*get_svg_name)(const struct ratbag_device *device);
/**
* Callback called when a read profile is requested by the
* caller of the library.
@@ -359,7 +368,7 @@ ratbag_set_drv_data(struct ratbag_device *device, void *drv_data)
}
static inline void *
ratbag_get_drv_data(struct ratbag_device *device)
ratbag_get_drv_data(const struct ratbag_device *device)
{
return device->drv_data;
}

View File

@@ -75,6 +75,7 @@ struct ratbag_test_device {
unsigned int num_resolutions;
unsigned int num_buttons;
unsigned int num_leds;
const char *svg;
struct ratbag_test_profile profiles[RATBAG_TEST_MAX_PROFILES];
void (*destroyed)(struct ratbag_device *device, void *data);
void *destroyed_data;

View File

@@ -484,7 +484,13 @@ ratbag_device_get_name(const struct ratbag_device* device)
LIBRATBAG_EXPORT const char *
ratbag_device_get_svg_name(const struct ratbag_device* device)
{
return udev_prop_value(device->udev_device, "RATBAG_SVG");
const char *name;
name = udev_prop_value(device->udev_device, "RATBAG_SVG");
if (!name && device->driver->get_svg_name)
name = device->driver->get_svg_name(device);
return name;
}
const char *