1
0
forked from drath/libratbag

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 <peter.hutterer@who-t.net>
This commit is contained in:
Peter Hutterer
2016-03-04 08:30:10 +10:00
parent 18a0be561f
commit 212ab08c15
3 changed files with 38 additions and 0 deletions

View File

@@ -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],

View File

@@ -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):
"""

View File

@@ -25,6 +25,7 @@
#include <assert.h>
#include <errno.h>
#include <limits.h>
#include <libratbag.h>
#include <stdbool.h>
#include <stdio.h>
@@ -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),