diff options
-rw-r--r-- | module-volume-change-notify.c | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/module-volume-change-notify.c b/module-volume-change-notify.c index 6032d17..b45e27e 100644 --- a/module-volume-change-notify.c +++ b/module-volume-change-notify.c @@ -41,6 +41,35 @@ struct userdata { DBusConnection *dbus_connection; }; +void send_dbus_signal(const char *name, const pa_cvolume *vol, + const struct userdata *u) +{ + DBusMessage* msg; + DBusMessageIter args; + + /* create a signal and check for errors */ + msg = dbus_message_new_signal("/org/PulseAudio/VolumeNotification", + "org.PulseAudio.VolumeNotification", + "VolumeChange"); + if (!msg) + return; + + /* append arguments onto signal */ + dbus_message_iter_init_append(msg, &args); + if (!dbus_message_iter_append_basic(&args, DBUS_TYPE_STRING, &name)) + goto fail; + + /* send the message and flush the connection */ + if (!dbus_connection_send(u->dbus_connection, msg, NULL)) + goto fail; + + dbus_connection_flush(u->dbus_connection); + +fail: + /* free the message */ + dbus_message_unref(msg); +} + void sink_change_event_cb(pa_core *c, pa_subscription_event_type_t t, uint32_t idx, void *userdata) { @@ -49,10 +78,14 @@ void sink_change_event_cb(pa_core *c, pa_subscription_event_type_t t, if (PA_SUBSCRIPTION_EVENT_CHANGE & t == 0) return; + if (!userdata) + return; + s = pa_idxset_get_by_index(c->sinks, idx); if (!s) return; + send_dbus_signal(s->name, &s->reference_volume, userdata); } void pa__done(pa_module *m) |