From e522e0bb071971b39bcdde2d962f9069539fdca2 Mon Sep 17 00:00:00 2001 From: Benjamin Tissoires Date: Wed, 12 Jul 2017 06:44:40 +0200 Subject: [PATCH] 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 --- ratbagd/ratbagd.c | 1 + src/driver-test.c | 8 ++++++++ src/libratbag-private.h | 11 ++++++++++- src/libratbag-test.h | 1 + src/libratbag.c | 8 +++++++- 5 files changed, 27 insertions(+), 2 deletions(-) diff --git a/ratbagd/ratbagd.c b/ratbagd/ratbagd.c index 1280e642..84f0da9f 100644 --- a/ratbagd/ratbagd.c +++ b/ratbagd/ratbagd.c @@ -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 = { diff --git a/src/driver-test.c b/src/driver-test.c index 40f2dc60..29944318 100644 --- a/src/driver-test.c +++ b/src/driver-test.c @@ -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, diff --git a/src/libratbag-private.h b/src/libratbag-private.h index a8625d8f..3674d14e 100644 --- a/src/libratbag-private.h +++ b/src/libratbag-private.h @@ -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; } diff --git a/src/libratbag-test.h b/src/libratbag-test.h index 305a3099..38500890 100644 --- a/src/libratbag-test.h +++ b/src/libratbag-test.h @@ -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; diff --git a/src/libratbag.c b/src/libratbag.c index 330ff011..858d9d15 100644 --- a/src/libratbag.c +++ b/src/libratbag.c @@ -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 *