From d15e61753ff8d715f60d074eb280bdb89d8f00ee Mon Sep 17 00:00:00 2001 From: Conor Curran Date: Wed, 10 Feb 2010 01:35:19 +0000 Subject: mute signal state toggle almost working --- src/indicator-sound.c | 22 +++++++++++++++++++++- src/pulse-manager.c | 8 ++++++-- 2 files changed, 27 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/indicator-sound.c b/src/indicator-sound.c index 7adaaef..352e0ed 100644 --- a/src/indicator-sound.c +++ b/src/indicator-sound.c @@ -87,6 +87,7 @@ static gboolean slider_value_changed_event_cb(GtkRange *range, GtkScrollType scr static void prepare_state_machine(); static void determine_state_from_volume(gdouble volume_percent); static void update_state(const gint state); +static void revert_state(); // DBUS communication static DBusGProxy *sound_dbus_proxy = NULL; @@ -233,6 +234,16 @@ static void catch_signal_sink_volume_update(DBusGProxy *proxy, gdouble volume_pe static void catch_signal_sink_mute_update(DBusGProxy *proxy, gboolean mute_value, gpointer userdata) { + //We can be sure the service won't send a mute signal unless it has changed ! + if(mute_value == TRUE) + { + update_state(STATE_MUTED); + } + else + { + g_debug("signal caught - sink mute update - about to mute state"); + revert_state(); + } g_debug("signal caught - sink mute update with mute_value %i", mute_value); } @@ -282,9 +293,18 @@ static void update_state(const gint state) gtk_image_set_from_icon_name(speaker_image, image_name, GTK_ICON_SIZE_MENU); } +static void revert_state() +{ + + current_state = previous_state; + gchar* image_name = g_hash_table_lookup(volume_states, GINT_TO_POINTER(current_state)); + gtk_image_set_from_icon_name(speaker_image, image_name, GTK_ICON_SIZE_MENU); + g_debug("after reverting back to previous state of %i", current_state); +} + static void determine_state_from_volume(gdouble volume_percent) { - gint state = current_state; + gint state = 0; if (volume_percent < 30.0 && volume_percent > 0){ state = STATE_LOW; } diff --git a/src/pulse-manager.c b/src/pulse-manager.c index 11fd34f..ae7961a 100644 --- a/src/pulse-manager.c +++ b/src/pulse-manager.c @@ -279,11 +279,13 @@ static void update_sink_info(pa_context *c, const pa_sink_info *info, int eol, v if(position >= 0) // => index is within the keys of the hash. { sink_info *s = g_hash_table_lookup(sink_hash, GINT_TO_POINTER(info->index)); - g_debug("attempting to update sink with name %s", s->name); + //g_debug("attempting to update sink with name %s", s->name); s->name = g_strdup(info->name); s->description = g_strdup(info->description); s->icon_name = g_strdup(pa_proplist_gets(info->proplist, PA_PROP_DEVICE_ICON_NAME)); s->active_port = (info->active_port != NULL); + // NASTY!! + gboolean mute_changed = s->mute != !!info->mute; s->mute = !!info->mute; s->volume = info->volume; s->base_volume = info->base_volume; @@ -297,7 +299,9 @@ static void update_sink_info(pa_context *c, const pa_sink_info *info, int eol, v g_debug("When using base volume => volume = %f", volume_percent); g_debug("about to update ui with linear volume of %f", pa_sw_volume_to_linear(vol)); sound_service_dbus_update_sink_volume(dbus_service, pa_sw_volume_to_linear(vol)); - sound_service_dbus_update_sink_mute(dbus_service, s->mute); + if (mute_changed == TRUE) + sound_service_dbus_update_sink_mute(dbus_service, s->mute); + update_mute_ui(s->mute); } else{ -- cgit v1.2.3