From 212ab08c15d6256f8533998f10d2b3442dd70ec8 Mon Sep 17 00:00:00 2001 From: Peter Hutterer Date: Fri, 4 Mar 2016 08:30:10 +1000 Subject: [PATCH] device: export the full path to the SVG as well Exporting just the filename requires the caller to know where that file sits. That's useful for things like e.g. icons where callers may several sets to chose from but here most callers will just use the default svg provided by libratbag. Export that, so that we don't have build-time dependencies in the callers just for that single path. Signed-off-by: Peter Hutterer --- configure.ac | 3 +++ python/ratbagd/__init__.py | 9 +++++++++ src/ratbagd-device.c | 26 ++++++++++++++++++++++++++ 3 files changed, 38 insertions(+) diff --git a/configure.ac b/configure.ac index 25efbfad..a3147d95 100644 --- a/configure.ac +++ b/configure.ac @@ -132,6 +132,9 @@ PKG_CHECK_MODULES([LIBUDEV], [libudev]) PKG_CHECK_MODULES([LIBSYSTEMD], [libsystemd >= 227]) PKG_CHECK_MODULES([LIBRATBAG], [libratbag >= 0.2]) +libratbag_data_dir=`$PKG_CONFIG --variable pkgdatadir libratbag` +AC_DEFINE_UNQUOTED([LIBRATBAG_DATA_DIR], ["$libratbag_data_dir"], [Directory for libratbag's SVG files]) + # ------------------------------------------------------------------------------ # options AC_ARG_WITH([systemd-unit-dir], diff --git a/python/ratbagd/__init__.py b/python/ratbagd/__init__.py index 23dd72e4..a3c6271b 100644 --- a/python/ratbagd/__init__.py +++ b/python/ratbagd/__init__.py @@ -84,6 +84,7 @@ class RatbagdDevice(_RatbagdDBus): self._devnode = self.dbus_property("Id") self._description = self.dbus_property("Description") self._svg = self.dbus_property("Svg") + self._svg_path = self.dbus_property("SvgPath") self._profiles = [] self._active_profile = -1 @@ -125,6 +126,14 @@ class RatbagdDevice(_RatbagdDBus): """ return self._svg + @property + def svg_path(self): + """ + The absolute SVG path. This function returns the full path to the + svg file. + """ + return self._svg_path + @property def id(self): """ diff --git a/src/ratbagd-device.c b/src/ratbagd-device.c index 2f4dc3af..3fee6209 100644 --- a/src/ratbagd-device.c +++ b/src/ratbagd-device.c @@ -25,6 +25,7 @@ #include #include +#include #include #include #include @@ -167,6 +168,30 @@ static int ratbagd_device_get_svg(sd_bus *bus, return sd_bus_message_append(reply, "s", svg); } +static int ratbagd_device_get_svg_path(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; + char svg_path[PATH_MAX] = {0}; + const char *svg; + + svg = ratbag_device_get_svg_name(device->lib_device); + if (!svg) { + log_error("Unable to fetch SVG for %s\n", + ratbagd_device_get_name(device)); + goto out; + } + + sprintf(svg_path, "%s/%s", LIBRATBAG_DATA_DIR, svg); + +out: + return sd_bus_message_append(reply, "s", svg_path); +} static int ratbagd_device_get_profiles(sd_bus *bus, const char *path, @@ -267,6 +292,7 @@ const sd_bus_vtable ratbagd_device_vtable[] = { SD_BUS_VTABLE_PROPERTY_CONST), SD_BUS_PROPERTY("Description", "s", ratbagd_device_get_description, 0, SD_BUS_VTABLE_PROPERTY_CONST), SD_BUS_PROPERTY("Svg", "s", ratbagd_device_get_svg, 0, SD_BUS_VTABLE_PROPERTY_CONST), + SD_BUS_PROPERTY("SvgPath", "s", ratbagd_device_get_svg_path, 0, SD_BUS_VTABLE_PROPERTY_CONST), SD_BUS_PROPERTY("Profiles", "ao", ratbagd_device_get_profiles, 0, SD_BUS_VTABLE_PROPERTY_CONST), SD_BUS_PROPERTY("ActiveProfile", "u", ratbagd_device_get_active_profile, 0, 0), SD_BUS_METHOD("GetProfileByIndex", "u", "o", ratbagd_device_get_profile_by_index, SD_BUS_VTABLE_UNPRIVILEGED),