diff options
-rw-r--r-- | module-volume-change-notify.c | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/module-volume-change-notify.c b/module-volume-change-notify.c index b45e27e..255aa92 100644 --- a/module-volume-change-notify.c +++ b/module-volume-change-notify.c @@ -41,6 +41,34 @@ struct userdata { DBusConnection *dbus_connection; }; +dbus_bool_t add_volumes(DBusMessageIter *args, const pa_cvolume *vol) +{ + DBusMessageIter array; + char buf[] = { DBUS_TYPE_UINT16, 0}; + const pa_volume_t *values; + uint8_t channel; + + if (!dbus_message_iter_open_container (args, DBUS_TYPE_ARRAY, + buf, &array)) + return FALSE; + + for (channel = 0; channel < vol->channels; channel++) { + uint16_t volume = (vol->values[channel] * 100 + PA_VOLUME_NORM / 2) / + PA_VOLUME_NORM; + + if (!dbus_message_iter_append_basic(&array, DBUS_TYPE_UINT16, + &volume)) { + dbus_message_iter_abandon_container (args, &array); + return FALSE; + } + } + + if (!dbus_message_iter_close_container (args, &array)) + return FALSE; + + return TRUE; +} + void send_dbus_signal(const char *name, const pa_cvolume *vol, const struct userdata *u) { @@ -59,6 +87,9 @@ void send_dbus_signal(const char *name, const pa_cvolume *vol, if (!dbus_message_iter_append_basic(&args, DBUS_TYPE_STRING, &name)) goto fail; + if (!add_volumes(&args, vol)) + goto fail; + /* send the message and flush the connection */ if (!dbus_connection_send(u->dbus_connection, msg, NULL)) goto fail; |