diff --git a/DBusInterface.md b/DBusInterface.md index c5df28dc..8dfd6791 100644 --- a/DBusInterface.md +++ b/DBusInterface.md @@ -14,6 +14,8 @@ Interfaces: The **org.freedesktop.ratbag1.Manager** interface provides: - Properties: - Devices -> array of object paths with interface Device + - Themes -> array of strings with theme names. The theme 'default' is + guaranteed to be available. - Signals: - DeviceNew -> new device available, carries object path - DeviceRemoved -> device removed, carries object path @@ -30,6 +32,12 @@ The **org.freedesktop.ratbag1.Device** interface provides: - Methods: - GetProfileByIndex(uint) -> returns the object path for the given index - Commit() -> commit the changes to the device + - GetSvg(string) -> returns the full path to the SVG for the given theme + or an empty string if none is available. The theme must be one of + org.freedesktop.ratbag1.Manager.Themes. The theme 'default' is + guaranteed to be available. ratbagd may return the path to a + file that doesn't exist. This is the case if the device has SVGs + available but not for the given theme. The **org.freedesktop.ratbag1.Profile** interface provides: - Properties: diff --git a/ratbagd/ratbagd-device.c b/ratbagd/ratbagd-device.c index ea5f758e..0eed4b77 100644 --- a/ratbagd/ratbagd-device.c +++ b/ratbagd/ratbagd-device.c @@ -187,6 +187,34 @@ out: return sd_bus_message_append(reply, "s", svg_path); } +static int ratbagd_device_get_theme_svg(sd_bus_message *m, + void *userdata, + sd_bus_error *error) +{ + struct ratbagd_device *device = userdata; + char svg_path[PATH_MAX] = {0}; + const char *theme; + const char *svg; + int r; + + r = sd_bus_message_read(m, "s", &theme); + if (r < 0) + return r; + + + 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/%s", LIBRATBAG_DATA_DIR, theme, svg); + +out: + return sd_bus_reply_method_return(m, "s", svg_path); +} + static int ratbagd_device_get_profiles(sd_bus *bus, const char *path, const char *interface, @@ -332,6 +360,7 @@ const sd_bus_vtable ratbagd_device_vtable[] = { 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), + SD_BUS_METHOD("GetSvg", "s", "s", ratbagd_device_get_theme_svg, SD_BUS_VTABLE_UNPRIVILEGED), SD_BUS_METHOD("Commit", "", "u", ratbagd_device_commit, SD_BUS_VTABLE_UNPRIVILEGED), SD_BUS_VTABLE_END, }; diff --git a/ratbagd/ratbagd.c b/ratbagd/ratbagd.c index ab0e1c27..d0f3f633 100644 --- a/ratbagd/ratbagd.c +++ b/ratbagd/ratbagd.c @@ -38,6 +38,12 @@ static bool verbose = false; +static const char *SVG_THEMES[] = { + "default", + "gnome", + NULL +}; + void log_verbose(const char *fmt, ...) { va_list args; @@ -146,9 +152,39 @@ static int ratbagd_get_devices(sd_bus *bus, return sd_bus_message_close_container(reply); } +static int ratbagd_get_themes(sd_bus *bus, + const char *path, + const char *interface, + const char *property, + sd_bus_message *reply, + void *userdata, + sd_bus_error *error) +{ + struct ratbagd *ctx = userdata; + const char **theme; + int r; + + r = sd_bus_message_open_container(reply, 'a', "s"); + if (r < 0) + return r; + + theme = ctx->themes; + while(*theme) { + r = sd_bus_message_append(reply, + "s", + *theme); + if (r < 0) + return r; + theme++; + } + + return sd_bus_message_close_container(reply); +} + static const sd_bus_vtable ratbagd_vtable[] = { SD_BUS_VTABLE_START(0), SD_BUS_PROPERTY("Devices", "ao", ratbagd_get_devices, 0, 0), + SD_BUS_PROPERTY("Themes", "as", ratbagd_get_themes, 0, 0), SD_BUS_SIGNAL("DeviceNew", "o", 0), SD_BUS_SIGNAL("DeviceRemoved", "o", 0), SD_BUS_VTABLE_END, @@ -323,6 +359,8 @@ static int ratbagd_new(struct ratbagd **out) if (!ctx) return -ENOMEM; + ctx->themes = SVG_THEMES; + r = sd_event_default(&ctx->event); if (r < 0) return r; diff --git a/ratbagd/ratbagd.h b/ratbagd/ratbagd.h index 23458239..1e1fd850 100644 --- a/ratbagd/ratbagd.h +++ b/ratbagd/ratbagd.h @@ -174,4 +174,6 @@ struct ratbagd { RBTree device_map; size_t n_devices; + + const char **themes; /* NULL-terminated */ };