mirror of
https://github.com/libratbag/libratbag.git
synced 2026-11-07 23:23:52 +01:00
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:
@@ -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,
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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 *
|
||||
|
||||
Reference in New Issue
Block a user