diff --git a/doc/dbus.rst b/doc/dbus.rst index dfcd256e..8320b601 100644 --- a/doc/dbus.rst +++ b/doc/dbus.rst @@ -158,6 +158,15 @@ known to ratbagd. The device's name, suitable for presentation to the user. +.. attribute:: FirmwareVersion + + :type: s + :flags: read-only, constant + + A device-specific string with the firmware version, or the empty + string. For devices with a major/minor or purely numeric firmware + version, the conversion into a string is implementation-defined. + .. attribute:: Profiles :type: ao diff --git a/ratbagd/ratbagd-device.c b/ratbagd/ratbagd-device.c index b58cb4bf..7a2f4d67 100644 --- a/ratbagd/ratbagd-device.c +++ b/ratbagd/ratbagd-device.c @@ -220,10 +220,27 @@ ratbag_device_get_model(sd_bus *bus, return sd_bus_message_append(reply, "s", model); } +static int +ratbagd_device_get_firmware_version(sd_bus *bus, + const char *path, + const char *interface, + const char *property, + sd_bus_message *reply, + void *userdata, + sd_bus_error *error) +{ + struct ratbagd_device *device = userdata; + struct ratbag_device *lib_device = device->lib_device; + const char* version = ratbag_device_get_firmware_version(lib_device); + + return sd_bus_message_append(reply, "s", version); +} + const sd_bus_vtable ratbagd_device_vtable[] = { SD_BUS_VTABLE_START(0), SD_BUS_PROPERTY("Model", "s", ratbag_device_get_model, 0, SD_BUS_VTABLE_PROPERTY_CONST), SD_BUS_PROPERTY("Name", "s", ratbagd_device_get_device_name, 0, SD_BUS_VTABLE_PROPERTY_CONST), + SD_BUS_PROPERTY("FirmwareVersion", "s", ratbagd_device_get_firmware_version, 0, SD_BUS_VTABLE_PROPERTY_CONST), SD_BUS_PROPERTY("Profiles", "ao", ratbagd_device_get_profiles, 0, SD_BUS_VTABLE_PROPERTY_CONST), SD_BUS_METHOD("Commit", "", "u", ratbagd_device_commit, SD_BUS_VTABLE_UNPRIVILEGED), SD_BUS_SIGNAL("Resync", "", 0), diff --git a/src/libratbag-private.h b/src/libratbag-private.h index bf86efb6..3ec301ec 100644 --- a/src/libratbag-private.h +++ b/src/libratbag-private.h @@ -147,6 +147,8 @@ struct ratbag_device { unsigned num_buttons; unsigned num_leds; + char* firmware_version; + void *drv_data; struct list link; diff --git a/src/libratbag.c b/src/libratbag.c index 1046ca75..ea94879f 100644 --- a/src/libratbag.c +++ b/src/libratbag.c @@ -228,6 +228,7 @@ ratbag_device_destroy(struct ratbag_device *device) ratbag_unref(device->ratbag); ratbag_device_data_unref(device->data); free(device->name); + free(device->firmware_version); free(device); } @@ -1622,6 +1623,19 @@ ratbag_device_get_user_data(const struct ratbag_device *ratbag_device) return ratbag_device->userdata; } +LIBRATBAG_EXPORT const char* +ratbag_device_get_firmware_version(const struct ratbag_device *ratbag_device) +{ + return ratbag_device->firmware_version; +} + +LIBRATBAG_EXPORT void +ratbag_device_set_firmware_version(struct ratbag_device *device, const char* fw) +{ + free(device->firmware_version); + device->firmware_version = strdup_safe(fw); +} + LIBRATBAG_EXPORT void* ratbag_profile_get_user_data(const struct ratbag_profile *ratbag_profile) { diff --git a/src/libratbag.h b/src/libratbag.h index 9982acb4..2c44c39a 100644 --- a/src/libratbag.h +++ b/src/libratbag.h @@ -421,6 +421,26 @@ ratbag_device_set_user_data(struct ratbag_device *device, void *userdata); void* ratbag_device_get_user_data(const struct ratbag_device *device); +/** + * @ingroup device + * + * Set the firmware version of the device. + * + * @param device A previously initialized ratbag device + * @param fw The firmware version of the device. + */ +void +ratbag_device_set_firmware_version(struct ratbag_device *device, const char* fw); + +/** + * @ingroup device + * + * @param device A previously initialized ratbag device + * @return The firmware version of the device. + */ +const char* +ratbag_device_get_firmware_version(const struct ratbag_device *device); + /** * @ingroup device * diff --git a/tools/ratbagc.py.in b/tools/ratbagc.py.in index 716c3aa3..eda24f57 100644 --- a/tools/ratbagc.py.in +++ b/tools/ratbagc.py.in @@ -262,6 +262,11 @@ class RatbagdDevice(metaclass=MetaRatbag): """The device name, usually provided by the kernel.""" return libratbag.ratbag_device_get_name(self._device) + @property + def firmware_version(self): + """The firmware version of the device.""" + return libratbag.ratbag_device_get_firmware_version(self._device) + @property def profiles(self): """A list of RatbagdProfile objects provided by this device.""" diff --git a/tools/ratbagctl.in.in b/tools/ratbagctl.in.in index e66bace4..1d5bfdc4 100755 --- a/tools/ratbagctl.in.in +++ b/tools/ratbagctl.in.in @@ -229,6 +229,8 @@ def print_device(d, level): print(" " * level + "{} - {}".format(d.id, d.name)) print(" " * level + " Model: {}".format(d.model)) + if d.firmware_version: + print(" " * level + " Firmware version: {}".format(d.firmware_version)) print(" " * level + " Number of Buttons: {}".format(len(p.buttons))) print(" " * level + " Number of Leds: {}".format(len(p.leds))) print(" " * level + "Number of Profiles: {}".format(len(d.profiles))) diff --git a/tools/ratbagd.py b/tools/ratbagd.py index 24dd1b9c..308a8611 100644 --- a/tools/ratbagd.py +++ b/tools/ratbagd.py @@ -347,6 +347,11 @@ class RatbagdDevice(_RatbagdDBus): """The device name, usually provided by the kernel.""" return self._get_dbus_property("Name") + @GObject.Property + def firmware_version(self): + """The firmware version of the device.""" + return self._get_dbus_property("FirmwareVersion") + @GObject.Property def profiles(self): """A list of RatbagdProfile objects provided by this device."""