From 279ebae33dd7790293516ad8e4c4a179b83d5186 Mon Sep 17 00:00:00 2001 From: Conor Curran Date: Thu, 4 Feb 2010 18:01:13 -0800 Subject: updates for libdbus changes and new state machine pattern for the icon indicator --- src/indicator-sound.c | 72 +++++++++++++++++++++++++++++++++++++++++++++++---- src/pulse-manager.h | 2 +- src/sound-service.c | 2 +- 3 files changed, 69 insertions(+), 7 deletions(-) (limited to 'src') diff --git a/src/indicator-sound.c b/src/indicator-sound.c index 5ca4df7..89b64dd 100644 --- a/src/indicator-sound.c +++ b/src/indicator-sound.c @@ -79,17 +79,30 @@ static GtkImage * get_icon (IndicatorObject * io); static GtkMenu * get_menu (IndicatorObject * io); static GtkWidget *volume_slider = NULL; static gdouble input_value_from_across_the_dbus = 0.0; -static GtkImage *speaker_image = NULL; static gboolean new_slider_item (DbusmenuMenuitem * newitem, DbusmenuMenuitem * parent, DbusmenuClient * client); static void slider_prop_change_cb (DbusmenuMenuitem * mi, gchar * prop, GValue * value, GtkWidget *widget); static gboolean slider_value_changed_event_cb(GtkRange *range, GtkScrollType scroll, double value, gpointer user_data); static void change_speaker_image(gdouble volume_percent); +static void prepare_state_machine(); // DBUS communication static DBusGProxy *sound_dbus_proxy = NULL; static void connection_changed (IndicatorServiceManager * sm, gboolean connected, gpointer userdata); -static void catch_signal(DBusGProxy * proxy, gint sink_index, gboolean value, gpointer userdata); +static void catch_signal_sink_input_while_muted(DBusGProxy * proxy, gint sink_index, gboolean value, gpointer userdata); + +/****Volume States 'members' ***/ +static const gint STATE_MUTED = 0; +static const gint STATE_ZERO = 1; +static const gint STATE_LOW = 2; +static const gint STATE_MEDIUM = 3; +static const gint STATE_HIGH = 4; +static const gint STATE_MUTED_WHILE_INPUT = 5; +static const gint STATE_SINKS_NONE = 5; +static GHashTable *volume_states = NULL; +static GtkImage *speaker_image = NULL; +static gint current_state = STATE_MUTED; +static gint previous_state = STATE_MUTED; static void indicator_sound_class_init (IndicatorSoundClass *klass) @@ -119,9 +132,43 @@ static void indicator_sound_init (IndicatorSound *self) /* Now let's fire these guys up. */ self->service = indicator_service_manager_new_version(INDICATOR_SOUND_DBUS_NAME, INDICATOR_SOUND_DBUS_VERSION); g_signal_connect(G_OBJECT(self->service), INDICATOR_SERVICE_MANAGER_SIGNAL_CONNECTION_CHANGE, G_CALLBACK(connection_changed), self); + prepare_state_machine(); + return; } + +static void test_images_hash() +{ + gchar* name; + name = g_hash_table_lookup(volume_states, GINT_TO_POINTER(0)); + g_debug("image name = %s", name); +} + +/** +Prepare states Array. +**/ +static void prepare_state_machine() +{ + volume_states = g_hash_table_new_full(g_direct_hash, g_direct_equal, NULL, g_free); + g_hash_table_insert(volume_states, GINT_TO_POINTER(STATE_MUTED), "audio-volume-muted"); + g_hash_table_insert(volume_states, GINT_TO_POINTER(STATE_ZERO), "audio-volume-zero"); + g_hash_table_insert(volume_states, GINT_TO_POINTER(STATE_LOW), "audio-volume-low"); + g_hash_table_insert(volume_states, GINT_TO_POINTER(STATE_MEDIUM), "audio-volume-medium"); + g_hash_table_insert(volume_states, GINT_TO_POINTER(STATE_HIGH), "audio-volume-high"); + g_hash_table_insert(volume_states, GINT_TO_POINTER(STATE_MUTED_WHILE_INPUT), "audio-volume-muted-blocking"); + g_hash_table_insert(volume_states, GINT_TO_POINTER(STATE_SINKS_NONE), "audio-output-none"); + test_images_hash(); +} +/*static void destroy_volume_image_info(void *value)*/ +/*{*/ +/* gchar* name = (gchar*)value;*/ +/* g_free(name);*/ +/* g_free(sink->description); */ +/* g_free(sink->icon_name); */ +/* g_free(sink); */ +/*}*/ + static void connection_changed (IndicatorServiceManager * sm, gboolean connected, gpointer userdata) { @@ -143,7 +190,7 @@ connection_changed (IndicatorServiceManager * sm, gboolean connected, gpointer u } g_debug("about to connect to the signals"); dbus_g_proxy_add_signal(sound_dbus_proxy, SIGNAL_SINK_INPUT_WHILE_MUTED, G_TYPE_INT, G_TYPE_BOOLEAN, G_TYPE_INVALID); - dbus_g_proxy_connect_signal(sound_dbus_proxy, SIGNAL_SINK_INPUT_WHILE_MUTED, G_CALLBACK(catch_signal), NULL, NULL); + dbus_g_proxy_connect_signal(sound_dbus_proxy, SIGNAL_SINK_INPUT_WHILE_MUTED, G_CALLBACK(catch_signal_sink_input_while_muted), NULL, NULL); } } else { @@ -153,7 +200,6 @@ connection_changed (IndicatorServiceManager * sm, gboolean connected, gpointer u return; } - static void catch_signal_sink_input_while_muted(DBusGProxy * proxy, gint sink_index, gboolean value, gpointer userdata) { //gtk_image_set_from_icon_name(speaker_image, "audio-volume-muted-blocking-symbolic", GTK_ICON_SIZE_MENU); @@ -169,6 +215,7 @@ indicator_sound_dispose (GObject *object) g_object_unref(G_OBJECT(self->service)); self->service = NULL; } + g_hash_table_destroy(volume_states); G_OBJECT_CLASS (indicator_sound_parent_class)->dispose (object); return; } @@ -189,11 +236,26 @@ get_label (IndicatorObject * io) static GtkImage * get_icon (IndicatorObject * io) { - speaker_image = GTK_IMAGE(gtk_image_new_from_icon_name("audio-volume-high", GTK_ICON_SIZE_MENU)); + gchar* image_name = g_hash_table_lookup(volume_states, GINT_TO_POINTER(current_state)); + g_debug("At start-up attempting to set the image to %s", image_name); + speaker_image = GTK_IMAGE(gtk_image_new_from_icon_name(image_name, GTK_ICON_SIZE_MENU)); gtk_widget_show(GTK_WIDGET(speaker_image)); return speaker_image; } +static void update_state(const gint state) +{ + previous_state = current_state; + current_state = 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); +} + +static void determine_state(gdouble volume_percent) +{ + +} + static void change_speaker_image(gdouble volume_percent) { if (volume_percent < 30.0 && volume_percent > 0){ diff --git a/src/pulse-manager.h b/src/pulse-manager.h index 5271628..8fa32b3 100644 --- a/src/pulse-manager.h +++ b/src/pulse-manager.h @@ -21,6 +21,6 @@ pa_context* get_context(void); void establish_pulse_activities(SoundServiceDbus *service); void set_sink_volume(gdouble percent); void toggle_global_mute(gboolean mute_value); - +void close_pulse_activites(); diff --git a/src/sound-service.c b/src/sound-service.c index 7cf065c..101cd18 100644 --- a/src/sound-service.c +++ b/src/sound-service.c @@ -76,7 +76,7 @@ static void rebuild_sound_menu(DbusmenuMenuitem *root, SoundServiceDbus *service dbusmenu_menuitem_property_set(mute_all_menuitem, DBUSMENU_MENUITEM_PROP_LABEL, _(b_all_muted == FALSE ? "Mute All" : "Unmute")); g_signal_connect(G_OBJECT(mute_all_menuitem), DBUSMENU_MENUITEM_SIGNAL_ITEM_ACTIVATED, G_CALLBACK(set_global_mute), NULL); //TODO: If no valid sinks are found grey out the item(s) - dbusmenu_menuitem_property_set_bool(mute_all_menuitem, DBUSMENU_MENUITEM_PROP_SENSITIVE, b_sink_available); + dbusmenu_menuitem_property_set_bool(mute_all_menuitem, DBUSMENU_MENUITEM_PROP_ENABLED, b_sink_available); // Slider volume_slider_menuitem = slider_menu_item_new(b_sink_available, volume_percent); -- cgit v1.2.3 From 8dc16e23db505b8e216478f2589ef15382464c30 Mon Sep 17 00:00:00 2001 From: Conor Curran Date: Thu, 4 Feb 2010 18:08:19 -0800 Subject: and another dbus update break --- src/slider-menu-item.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src') diff --git a/src/slider-menu-item.c b/src/slider-menu-item.c index 02a5605..2620e6e 100644 --- a/src/slider-menu-item.c +++ b/src/slider-menu-item.c @@ -94,7 +94,7 @@ SliderMenuItem* slider_menu_item_new(gboolean sinks_available, gdouble start_vol //SliderMenuItemPrivate * priv = SLIDER_MENU_ITEM_GET_PRIVATE(self); dbusmenu_menuitem_property_set(DBUSMENU_MENUITEM(self), DBUSMENU_MENUITEM_PROP_TYPE, DBUSMENU_SLIDER_MENUITEM_TYPE); //TODO: If no valid sinks are found grey out the item(s) - dbusmenu_menuitem_property_set_bool(DBUSMENU_MENUITEM(self), DBUSMENU_MENUITEM_PROP_SENSITIVE, sinks_available); + dbusmenu_menuitem_property_set_bool(DBUSMENU_MENUITEM(self), DBUSMENU_MENUITEM_PROP_ENABLED, sinks_available); //g_debug("Sending the initial value of the slider over dbus = %f", start_volume * 100); return self; } -- cgit v1.2.3 From 470e751be8af2da3bbc69a1115d2ce19590cac5a Mon Sep 17 00:00:00 2001 From: Conor Curran Date: Fri, 5 Feb 2010 17:27:41 -0800 Subject: range bug fix --- src/indicator-sound.c | 143 ++++++++++++++++++++++++++------------------------ src/pulse-manager.c | 1 + 2 files changed, 74 insertions(+), 70 deletions(-) (limited to 'src') diff --git a/src/indicator-sound.c b/src/indicator-sound.c index 89b64dd..2b20c48 100644 --- a/src/indicator-sound.c +++ b/src/indicator-sound.c @@ -82,9 +82,9 @@ static gdouble input_value_from_across_the_dbus = 0.0; static gboolean new_slider_item (DbusmenuMenuitem * newitem, DbusmenuMenuitem * parent, DbusmenuClient * client); static void slider_prop_change_cb (DbusmenuMenuitem * mi, gchar * prop, GValue * value, GtkWidget *widget); -static gboolean slider_value_changed_event_cb(GtkRange *range, GtkScrollType scroll, double value, gpointer user_data); -static void change_speaker_image(gdouble volume_percent); -static void prepare_state_machine(); +static gboolean slider_value_changed_event_cb(GtkRange *range, gpointer user_data); +/*static void change_speaker_image(gdouble volume_percent);*/ +/*static void prepare_state_machine();*/ // DBUS communication static DBusGProxy *sound_dbus_proxy = NULL; @@ -101,8 +101,8 @@ static const gint STATE_MUTED_WHILE_INPUT = 5; static const gint STATE_SINKS_NONE = 5; static GHashTable *volume_states = NULL; static GtkImage *speaker_image = NULL; -static gint current_state = STATE_MUTED; -static gint previous_state = STATE_MUTED; +/*static gint current_state = 0;*/ +//static gint previous_state = 0; static void indicator_sound_class_init (IndicatorSoundClass *klass) @@ -132,34 +132,35 @@ static void indicator_sound_init (IndicatorSound *self) /* Now let's fire these guys up. */ self->service = indicator_service_manager_new_version(INDICATOR_SOUND_DBUS_NAME, INDICATOR_SOUND_DBUS_VERSION); g_signal_connect(G_OBJECT(self->service), INDICATOR_SERVICE_MANAGER_SIGNAL_CONNECTION_CHANGE, G_CALLBACK(connection_changed), self); - prepare_state_machine(); + //prepare_state_machine(); return; } -static void test_images_hash() -{ - gchar* name; - name = g_hash_table_lookup(volume_states, GINT_TO_POINTER(0)); - g_debug("image name = %s", name); -} +/*static void test_images_hash()*/ +/*{*/ +/* gchar* name;*/ +/* g_debug("about to test the images hash"); */ +/* name = g_hash_table_lookup(volume_states, GINT_TO_POINTER(0));*/ +/* g_debug("image name = %s", name); */ +/*}*/ -/** -Prepare states Array. -**/ -static void prepare_state_machine() -{ - volume_states = g_hash_table_new_full(g_direct_hash, g_direct_equal, NULL, g_free); - g_hash_table_insert(volume_states, GINT_TO_POINTER(STATE_MUTED), "audio-volume-muted"); - g_hash_table_insert(volume_states, GINT_TO_POINTER(STATE_ZERO), "audio-volume-zero"); - g_hash_table_insert(volume_states, GINT_TO_POINTER(STATE_LOW), "audio-volume-low"); - g_hash_table_insert(volume_states, GINT_TO_POINTER(STATE_MEDIUM), "audio-volume-medium"); - g_hash_table_insert(volume_states, GINT_TO_POINTER(STATE_HIGH), "audio-volume-high"); - g_hash_table_insert(volume_states, GINT_TO_POINTER(STATE_MUTED_WHILE_INPUT), "audio-volume-muted-blocking"); - g_hash_table_insert(volume_states, GINT_TO_POINTER(STATE_SINKS_NONE), "audio-output-none"); - test_images_hash(); -} +/*/***/ +/*Prepare states Array.*/ +/***/ +/*static void prepare_state_machine()*/ +/*{*/ +/* volume_states = g_hash_table_new_full(g_direct_hash, g_direct_equal, NULL, g_free);*/ +/* g_hash_table_insert(volume_states, GINT_TO_POINTER(STATE_MUTED), "audio-volume-muted");*/ +/* g_hash_table_insert(volume_states, GINT_TO_POINTER(STATE_ZERO), "audio-volume-zero");*/ +/* g_hash_table_insert(volume_states, GINT_TO_POINTER(STATE_LOW), "audio-volume-low");*/ +/* g_hash_table_insert(volume_states, GINT_TO_POINTER(STATE_MEDIUM), "audio-volume-medium");*/ +/* g_hash_table_insert(volume_states, GINT_TO_POINTER(STATE_HIGH), "audio-volume-high");*/ +/* g_hash_table_insert(volume_states, GINT_TO_POINTER(STATE_MUTED_WHILE_INPUT), "audio-volume-muted-blocking");*/ +/* g_hash_table_insert(volume_states, GINT_TO_POINTER(STATE_SINKS_NONE), "audio-output-none");*/ +/* test_images_hash();*/ +/*}*/ /*static void destroy_volume_image_info(void *value)*/ /*{*/ /* gchar* name = (gchar*)value;*/ @@ -236,41 +237,41 @@ get_label (IndicatorObject * io) static GtkImage * get_icon (IndicatorObject * io) { - gchar* image_name = g_hash_table_lookup(volume_states, GINT_TO_POINTER(current_state)); - g_debug("At start-up attempting to set the image to %s", image_name); - speaker_image = GTK_IMAGE(gtk_image_new_from_icon_name(image_name, GTK_ICON_SIZE_MENU)); + //gchar* image_name = g_hash_table_lookup(volume_states, GINT_TO_POINTER(current_state)); + //g_debug("At start-up attempting to set the image to %s", image_name); + speaker_image = GTK_IMAGE(gtk_image_new_from_icon_name("audio-volume-low", GTK_ICON_SIZE_MENU)); gtk_widget_show(GTK_WIDGET(speaker_image)); return speaker_image; } -static void update_state(const gint state) -{ - previous_state = current_state; - current_state = 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); -} +/*static void update_state(const gint state)*/ +/*{*/ +/* previous_state = current_state;*/ +/* current_state = 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);*/ +/*}*/ -static void determine_state(gdouble volume_percent) -{ - -} +/*static void determine_state(gdouble volume_percent)*/ +/*{*/ +/* */ +/*}*/ -static void change_speaker_image(gdouble volume_percent) -{ - if (volume_percent < 30.0 && volume_percent > 0){ - gtk_image_set_from_icon_name(speaker_image, "audio-volume-low", GTK_ICON_SIZE_MENU); - } - else if(volume_percent < 70.0 && volume_percent > 30.0){ - gtk_image_set_from_icon_name(speaker_image, "audio-volume-medium", GTK_ICON_SIZE_MENU); - } - else if(volume_percent > 70.0){ - gtk_image_set_from_icon_name(speaker_image, "audio-volume-high", GTK_ICON_SIZE_MENU); - } - else if(volume_percent <= 0.0){ - gtk_image_set_from_icon_name(speaker_image, "audio-volume-zero", GTK_ICON_SIZE_MENU); - } -} +/*static void change_speaker_image(gdouble volume_percent)*/ +/*{ */ +/* if (volume_percent < 30.0 && volume_percent > 0){*/ +/* gtk_image_set_from_icon_name(speaker_image, "audio-volume-low", GTK_ICON_SIZE_MENU);*/ +/* }*/ +/* else if(volume_percent < 70.0 && volume_percent > 30.0){*/ +/* gtk_image_set_from_icon_name(speaker_image, "audio-volume-medium", GTK_ICON_SIZE_MENU);*/ +/* }*/ +/* else if(volume_percent > 70.0){*/ +/* gtk_image_set_from_icon_name(speaker_image, "audio-volume-high", GTK_ICON_SIZE_MENU);*/ +/* }*/ +/* else if(volume_percent <= 0.0){*/ +/* gtk_image_set_from_icon_name(speaker_image, "audio-volume-zero", GTK_ICON_SIZE_MENU);*/ +/* }*/ +/*}*/ /* Indicator based function to get the menu for the whole applet. This starts up asking for the parts of the menu @@ -295,10 +296,10 @@ static gboolean new_slider_item(DbusmenuMenuitem * newitem, DbusmenuMenuitem * p GtkMenuItem *menu_volume_slider = GTK_MENU_ITEM(volume_slider); dbusmenu_gtkclient_newitem_base(DBUSMENU_GTKCLIENT(client), newitem, menu_volume_slider, parent); g_signal_connect(G_OBJECT(newitem), DBUSMENU_MENUITEM_SIGNAL_PROPERTY_CHANGED, G_CALLBACK(slider_prop_change_cb), volume_slider); - - GtkWidget* slider = ido_scale_menu_item_get_scale((IdoScaleMenuItem*)volume_slider); - GtkRange* range = (GtkRange*)slider; - g_signal_connect(G_OBJECT(range), "change-value", G_CALLBACK(slider_value_changed_event_cb), newitem); + + GtkWidget* slider = ido_scale_menu_item_get_scale((IdoScaleMenuItem*)volume_slider); + g_signal_connect(slider, "value-changed", G_CALLBACK(slider_value_changed_event_cb), newitem); + gtk_widget_show_all(volume_slider); return TRUE; } @@ -319,17 +320,19 @@ static void slider_prop_change_cb (DbusmenuMenuitem * mi, gchar * prop, GValue * return; } -static gboolean slider_value_changed_event_cb(GtkRange *range, GtkScrollType scroll, double slider_value, gpointer user_data) +static gboolean slider_value_changed_event_cb(GtkRange *range, gpointer user_data) { - if(slider_value != input_value_from_across_the_dbus) - { - DbusmenuMenuitem *item = (DbusmenuMenuitem*)user_data; - GValue value = {0}; - g_value_init(&value, G_TYPE_DOUBLE); - g_value_set_double(&value, slider_value); - dbusmenu_menuitem_handle_event (item, "slider_change", &value, 0); - change_speaker_image(slider_value); - } +/* #if(slider_value != input_value_from_across_the_dbus)*/ +/* #{ */ + DbusmenuMenuitem *item = (DbusmenuMenuitem*)user_data; + GValue value = {0}; + gdouble input = gtk_range_get_value(range); + g_debug("CALLBACK for the range - input received = %f", input); + g_value_init(&value, G_TYPE_DOUBLE); + g_value_set_double(&value, input); + dbusmenu_menuitem_handle_event (item, "slider_change", &value, 0); +/* change_speaker_image(slider_value);*/ +/* }*/ return FALSE; } diff --git a/src/pulse-manager.c b/src/pulse-manager.c index ce63b0d..dbf30a0 100644 --- a/src/pulse-manager.c +++ b/src/pulse-manager.c @@ -70,6 +70,7 @@ void close_pulse_activites() g_hash_table_destroy(sink_hash); pa_glib_mainloop_free(pa_main_loop); pa_main_loop = NULL; + g_debug("I just closed communication with Pulse"); } static void mute_each_sink(gpointer key, gpointer value, gpointer user_data) -- cgit v1.2.3 From f9ef87f71c488f6791e32b1cf7205fb65db81ce8 Mon Sep 17 00:00:00 2001 From: Conor Curran Date: Mon, 8 Feb 2010 14:42:30 +0000 Subject: automatic volume updates in progress --- src/common-defs.h | 2 +- src/indicator-sound.c | 9 ++++++++ src/pulse-manager.c | 59 +++++++++++++++++++++++++++++++++++++++++++++--- src/sound-service-dbus.c | 18 +++++++++++++++ src/sound-service-dbus.h | 2 ++ src/sound-service.xml | 3 +++ 6 files changed, 89 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/common-defs.h b/src/common-defs.h index 6cacb49..a06b1b3 100644 --- a/src/common-defs.h +++ b/src/common-defs.h @@ -1,6 +1,6 @@ /* constants used for signals on the dbus. This file is shared between client and server implementation */ #define SIGNAL_SINK_INPUT_WHILE_MUTED "SinkInputWhileMuted" -#define METHOD_SET_SINK_VOLUME "SetSinkVolume" +#define SIGNAL_UPDATE_SINK_VOLUME "UpdateSinkVolume" // DBUS items #define DBUSMENU_SLIDER_MENUITEM_TYPE "x-canonical-ido-slider-item" diff --git a/src/indicator-sound.c b/src/indicator-sound.c index 2b20c48..9ceebd1 100644 --- a/src/indicator-sound.c +++ b/src/indicator-sound.c @@ -90,6 +90,7 @@ static gboolean slider_value_changed_event_cb(GtkRange *range, gpointer user_da static DBusGProxy *sound_dbus_proxy = NULL; static void connection_changed (IndicatorServiceManager * sm, gboolean connected, gpointer userdata); static void catch_signal_sink_input_while_muted(DBusGProxy * proxy, gint sink_index, gboolean value, gpointer userdata); +void catch_signal_sink_volume_update(DBusGProxy * proxy, gint sink_volume, gpointer userdata); /****Volume States 'members' ***/ static const gint STATE_MUTED = 0; @@ -192,6 +193,9 @@ connection_changed (IndicatorServiceManager * sm, gboolean connected, gpointer u g_debug("about to connect to the signals"); dbus_g_proxy_add_signal(sound_dbus_proxy, SIGNAL_SINK_INPUT_WHILE_MUTED, G_TYPE_INT, G_TYPE_BOOLEAN, G_TYPE_INVALID); dbus_g_proxy_connect_signal(sound_dbus_proxy, SIGNAL_SINK_INPUT_WHILE_MUTED, G_CALLBACK(catch_signal_sink_input_while_muted), NULL, NULL); + dbus_g_proxy_add_signal(sound_dbus_proxy, SIGNAL_UPDATE_SINK_VOLUME, G_TYPE_INT, G_TYPE_INVALID); + dbus_g_proxy_connect_signal(sound_dbus_proxy, SIGNAL_UPDATE_SINK_VOLUME, G_CALLBACK(catch_signal_sink_volume_update), NULL, NULL); + } } else { @@ -207,6 +211,11 @@ static void catch_signal_sink_input_while_muted(DBusGProxy * proxy, gint sink_in g_debug("signal caught - I don't believe it ! with index %i and value %i", sink_index, value); } +void catch_signal_sink_volume_update(DBusGProxy * proxy, gint sink_volume, gpointer userdata) +{ + g_debug("signal caught - update sink volume with value : %i", sink_volume); +} + static void indicator_sound_dispose (GObject *object) { diff --git a/src/pulse-manager.c b/src/pulse-manager.c index dbf30a0..87f20ae 100644 --- a/src/pulse-manager.c +++ b/src/pulse-manager.c @@ -19,6 +19,7 @@ static void pulse_sink_info_callback(pa_context *c, const pa_sink_info *sink_inf static void context_success_callback(pa_context *c, int success, void *userdata); static void pulse_sink_input_info_callback(pa_context *c, const pa_sink_input_info *info, int eol, void *userdata); static void pulse_server_info_callback(pa_context *c, const pa_server_info *info, void *userdata); +static void update_sink_info(pa_context *c, const pa_sink_info *info, int eol, void *userdata); static void destroy_sink_info(void *value); /* @@ -204,7 +205,7 @@ static void pulse_sink_info_callback(pa_context *c, const pa_sink_info *sink, in } else{ - g_debug("About to add an item to our hash"); + g_debug("About to add an item to our hash"); sink_info *value; value = g_new0(sink_info, 1); value->index = value->device_index = sink->index; @@ -217,7 +218,7 @@ static void pulse_sink_info_callback(pa_context *c, const pa_sink_info *sink, in value->base_volume = sink->base_volume; value->channel_map = sink->channel_map; g_hash_table_insert(sink_hash, GINT_TO_POINTER(sink->index), value); - g_debug("After adding an item to our hash"); + g_debug("After adding an item to our hash"); } } @@ -254,7 +255,54 @@ static void pulse_sink_input_info_callback(pa_context *c, const pa_sink_input_in g_debug("\n SINK INPUT INFO sink index : %d \n", info->sink); check_sink_input_while_muted_event(info->sink); } -} +} + +static void update_sink_info(pa_context *c, const pa_sink_info *info, int eol, void *userdata) +{ + if (eol > 0) { + if (pa_context_errno(c) == PA_ERR_NOENTITY) + return; + g_warning("Sink INPUT info callback failure"); + return; + } + + GList *keys = g_hash_table_get_keys(sink_hash); + gint position = g_list_index(keys, GINT_TO_POINTER(info->index)); +/* gboolean update_ui_vol = FALSE;*/ + if(position >= 0) // => index is within the keys of the hash. + { + // TODO : update sinks hash with new details and if default send over dbus the update. in reverse order. + //gint sink_index = GPOINTER_TO_INT(g_list_nth_data(keys, position)); + 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); + 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); + s->mute = !!info->mute; +/* int equal = pa_cvolume_equal(&s->volume, &info->volume);*/ +/* update_ui_vol = (equal != 0); */ +/* g_debug("Are the volumes the same %i", equal); */ + s->volume = info->volume; + s->base_volume = info->base_volume; + s->channel_map = info->channel_map; + if(DEFAULT_SINK_INDEX == s->index/* && update_ui_vol == TRUE*/) + { + //update the UI + pa_volume_t vol = pa_cvolume_avg(&s->volume); + 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, vol * 100); + } + } + else + { + g_debug("attempting to add new sink with name %s", info->name); + //sink_info *s; + //s = g_new0(sink_info, 1); + //update the sinks hash with new sink. + } +} + static void pulse_server_info_callback(pa_context *c, const pa_server_info *info, void *userdata) { @@ -290,6 +338,11 @@ static void pulse_server_info_callback(pa_context *c, const pa_server_info *info static void subscribed_events_callback(pa_context *c, enum pa_subscription_event_type t, uint32_t index, void *userdata){ switch (t & PA_SUBSCRIPTION_EVENT_FACILITY_MASK) { case PA_SUBSCRIPTION_EVENT_SINK: + if ((t & PA_SUBSCRIPTION_EVENT_TYPE_MASK) == PA_SUBSCRIPTION_EVENT_REMOVE) { + //TODO handle the remove event + } else { + pa_operation_unref(pa_context_get_sink_info_by_index(c, index, update_sink_info, userdata)); + } //g_debug("Event sink for %i", index); break; case PA_SUBSCRIPTION_EVENT_SINK_INPUT: diff --git a/src/sound-service-dbus.c b/src/sound-service-dbus.c index 5e22dae..9a325fe 100644 --- a/src/sound-service-dbus.c +++ b/src/sound-service-dbus.c @@ -43,6 +43,7 @@ struct _SoundServiceDbusPrivate /* Signals */ enum { SINK_INPUT_WHILE_MUTED, + SINK_VOLUME_UPDATE, LAST_SIGNAL }; @@ -81,6 +82,14 @@ sound_service_dbus_class_init (SoundServiceDbusClass *klass) NULL, NULL, _sound_service_marshal_VOID__INT_BOOLEAN, G_TYPE_NONE, 2, G_TYPE_INT, G_TYPE_BOOLEAN); + + signals[SINK_VOLUME_UPDATE] = g_signal_new("sink-volume-update", + G_TYPE_FROM_CLASS (klass), + G_SIGNAL_RUN_LAST, + 0, + NULL, NULL, + g_cclosure_marshal_VOID__INT, + G_TYPE_NONE, 1, G_TYPE_INT); } /** @@ -116,6 +125,15 @@ void sound_service_dbus_sink_input_while_muted(SoundServiceDbus* obj, gint sink_ value); } +void sound_service_dbus_update_sink_volume(SoundServiceDbus* obj, gint sink_volume) +{ + g_debug("Emitting signal: UPDATE_SINK_VOLUME, with sink_volme %i", sink_volume); + g_signal_emit(obj, + signals[SINK_VOLUME_UPDATE], + 0, + sink_volume); +} + void set_pa_sinks_hash(SoundServiceDbus *self, GHashTable *sinks) { SoundServiceDbusPrivate *priv = SOUND_SERVICE_DBUS_GET_PRIVATE (self); diff --git a/src/sound-service-dbus.h b/src/sound-service-dbus.h index eea6d26..bb4fbe8 100644 --- a/src/sound-service-dbus.h +++ b/src/sound-service-dbus.h @@ -51,12 +51,14 @@ struct _SoundServiceDbusClass { GObjectClass parent_class; /* Signals -> outward messages to the DBUS and beyond*/ void (* sink_input_while_muted) (SoundServiceDbus *self, gint sink_index, gboolean is_muted, gpointer sound_data); + void (* sink_volume_update) (SoundServiceDbus *self, gint sink_volume); }; GType sound_service_dbus_get_type (void) G_GNUC_CONST; // Utility methods to get the messages across into the sound-service-dbus void sound_service_dbus_sink_input_while_muted (SoundServiceDbus* obj, gint sink_index, gboolean value); +void sound_service_dbus_update_sink_volume(SoundServiceDbus* obj, gint sink_volume); void set_pa_sinks_hash(SoundServiceDbus *self, GHashTable *sinks); // DBUS METHODS diff --git a/src/sound-service.xml b/src/sound-service.xml index 26d83e5..0a35690 100644 --- a/src/sound-service.xml +++ b/src/sound-service.xml @@ -13,6 +13,9 @@ Our respective UI element should listen to this and therefore will be updated wi + + + -- cgit v1.2.3 From ea417ae84133c26aed0b257376ab1d1c567a9779 Mon Sep 17 00:00:00 2001 From: Conor Curran Date: Mon, 8 Feb 2010 17:21:05 +0000 Subject: automatic slider volume updates working --- src/common-defs.h | 2 +- src/indicator-sound.c | 13 ++++++++----- src/pulse-manager.c | 5 ++++- src/sound-service-dbus.c | 9 +++++---- src/sound-service-dbus.h | 4 ++-- src/sound-service.xml | 2 +- 6 files changed, 21 insertions(+), 14 deletions(-) (limited to 'src') diff --git a/src/common-defs.h b/src/common-defs.h index a06b1b3..c969ddb 100644 --- a/src/common-defs.h +++ b/src/common-defs.h @@ -1,6 +1,6 @@ /* constants used for signals on the dbus. This file is shared between client and server implementation */ #define SIGNAL_SINK_INPUT_WHILE_MUTED "SinkInputWhileMuted" -#define SIGNAL_UPDATE_SINK_VOLUME "UpdateSinkVolume" +#define SIGNAL_SINK_VOLUME_UPDATE "SinkVolumeUpdate" // DBUS items #define DBUSMENU_SLIDER_MENUITEM_TYPE "x-canonical-ido-slider-item" diff --git a/src/indicator-sound.c b/src/indicator-sound.c index 9ceebd1..fe1b6fb 100644 --- a/src/indicator-sound.c +++ b/src/indicator-sound.c @@ -90,7 +90,7 @@ static gboolean slider_value_changed_event_cb(GtkRange *range, gpointer user_da static DBusGProxy *sound_dbus_proxy = NULL; static void connection_changed (IndicatorServiceManager * sm, gboolean connected, gpointer userdata); static void catch_signal_sink_input_while_muted(DBusGProxy * proxy, gint sink_index, gboolean value, gpointer userdata); -void catch_signal_sink_volume_update(DBusGProxy * proxy, gint sink_volume, gpointer userdata); +static void catch_signal_sink_volume_update(DBusGProxy * proxy, gdouble volume_percent, gpointer userdata); /****Volume States 'members' ***/ static const gint STATE_MUTED = 0; @@ -193,8 +193,8 @@ connection_changed (IndicatorServiceManager * sm, gboolean connected, gpointer u g_debug("about to connect to the signals"); dbus_g_proxy_add_signal(sound_dbus_proxy, SIGNAL_SINK_INPUT_WHILE_MUTED, G_TYPE_INT, G_TYPE_BOOLEAN, G_TYPE_INVALID); dbus_g_proxy_connect_signal(sound_dbus_proxy, SIGNAL_SINK_INPUT_WHILE_MUTED, G_CALLBACK(catch_signal_sink_input_while_muted), NULL, NULL); - dbus_g_proxy_add_signal(sound_dbus_proxy, SIGNAL_UPDATE_SINK_VOLUME, G_TYPE_INT, G_TYPE_INVALID); - dbus_g_proxy_connect_signal(sound_dbus_proxy, SIGNAL_UPDATE_SINK_VOLUME, G_CALLBACK(catch_signal_sink_volume_update), NULL, NULL); + dbus_g_proxy_add_signal(sound_dbus_proxy, SIGNAL_SINK_VOLUME_UPDATE, G_TYPE_DOUBLE, G_TYPE_INVALID); + dbus_g_proxy_connect_signal(sound_dbus_proxy, SIGNAL_SINK_VOLUME_UPDATE, G_CALLBACK(catch_signal_sink_volume_update), NULL, NULL); } @@ -211,9 +211,12 @@ static void catch_signal_sink_input_while_muted(DBusGProxy * proxy, gint sink_in g_debug("signal caught - I don't believe it ! with index %i and value %i", sink_index, value); } -void catch_signal_sink_volume_update(DBusGProxy * proxy, gint sink_volume, gpointer userdata) +static void catch_signal_sink_volume_update(DBusGProxy * proxy, gdouble volume_percent, gpointer userdata) { - g_debug("signal caught - update sink volume with value : %i", sink_volume); + g_debug("signal caught - update sink volume with value : %f", volume_percent); + GtkWidget* slider = ido_scale_menu_item_get_scale((IdoScaleMenuItem*)volume_slider); + GtkRange* range = (GtkRange*)slider; + gtk_range_set_value(range, volume_percent); } static void diff --git a/src/pulse-manager.c b/src/pulse-manager.c index 87f20ae..ff6f1bb 100644 --- a/src/pulse-manager.c +++ b/src/pulse-manager.c @@ -290,8 +290,11 @@ static void update_sink_info(pa_context *c, const pa_sink_info *info, int eol, v { //update the UI pa_volume_t vol = pa_cvolume_avg(&s->volume); + // Use the base of the device to ensure maximum acceptable levels on the hardware + gint volume_percent = (vol/s->base_volume); + g_debug("When using base volume => volume = %i", 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, vol * 100); + sound_service_dbus_update_sink_volume(dbus_service, pa_sw_volume_to_linear(vol) * 100); } } else diff --git a/src/sound-service-dbus.c b/src/sound-service-dbus.c index 9a325fe..635dfeb 100644 --- a/src/sound-service-dbus.c +++ b/src/sound-service-dbus.c @@ -88,8 +88,8 @@ sound_service_dbus_class_init (SoundServiceDbusClass *klass) G_SIGNAL_RUN_LAST, 0, NULL, NULL, - g_cclosure_marshal_VOID__INT, - G_TYPE_NONE, 1, G_TYPE_INT); + g_cclosure_marshal_VOID__DOUBLE, + G_TYPE_NONE, 1, G_TYPE_DOUBLE); } /** @@ -112,6 +112,7 @@ sound_service_dbus_get_sink_list (SoundServiceDbus *self) /** +SIGNALS Utility methods to emit signals from the service into the ether. **/ void sound_service_dbus_sink_input_while_muted(SoundServiceDbus* obj, gint sink_index, gboolean value) @@ -125,9 +126,9 @@ void sound_service_dbus_sink_input_while_muted(SoundServiceDbus* obj, gint sink_ value); } -void sound_service_dbus_update_sink_volume(SoundServiceDbus* obj, gint sink_volume) +void sound_service_dbus_update_sink_volume(SoundServiceDbus* obj, gdouble sink_volume) { - g_debug("Emitting signal: UPDATE_SINK_VOLUME, with sink_volme %i", sink_volume); + g_debug("Emitting signal: SINK_VOLUME_UPDATE, with sink_volme %f", sink_volume); g_signal_emit(obj, signals[SINK_VOLUME_UPDATE], 0, diff --git a/src/sound-service-dbus.h b/src/sound-service-dbus.h index bb4fbe8..dc52861 100644 --- a/src/sound-service-dbus.h +++ b/src/sound-service-dbus.h @@ -51,14 +51,14 @@ struct _SoundServiceDbusClass { GObjectClass parent_class; /* Signals -> outward messages to the DBUS and beyond*/ void (* sink_input_while_muted) (SoundServiceDbus *self, gint sink_index, gboolean is_muted, gpointer sound_data); - void (* sink_volume_update) (SoundServiceDbus *self, gint sink_volume); + void (* sink_volume_update) (SoundServiceDbus *self, gdouble sink_volume, gpointer sound_data); }; GType sound_service_dbus_get_type (void) G_GNUC_CONST; // Utility methods to get the messages across into the sound-service-dbus void sound_service_dbus_sink_input_while_muted (SoundServiceDbus* obj, gint sink_index, gboolean value); -void sound_service_dbus_update_sink_volume(SoundServiceDbus* obj, gint sink_volume); +void sound_service_dbus_update_sink_volume(SoundServiceDbus* obj, gdouble sink_volume); void set_pa_sinks_hash(SoundServiceDbus *self, GHashTable *sinks); // DBUS METHODS diff --git a/src/sound-service.xml b/src/sound-service.xml index 0a35690..e7f3e75 100644 --- a/src/sound-service.xml +++ b/src/sound-service.xml @@ -14,7 +14,7 @@ Our respective UI element should listen to this and therefore will be updated wi - + -- cgit v1.2.3 From d1e576becc28434d42e29640b8674342f8b6f521 Mon Sep 17 00:00:00 2001 From: Conor Curran Date: Mon, 8 Feb 2010 17:39:40 +0000 Subject: white space tidy up --- src/sound-service.xml | 1 + 1 file changed, 1 insertion(+) (limited to 'src') diff --git a/src/sound-service.xml b/src/sound-service.xml index e7f3e75..fffad00 100644 --- a/src/sound-service.xml +++ b/src/sound-service.xml @@ -13,6 +13,7 @@ Our respective UI element should listen to this and therefore will be updated wi + -- cgit v1.2.3 From bf02109517f8e770373e13fc78cdda3019d77f04 Mon Sep 17 00:00:00 2001 From: Conor Curran Date: Mon, 8 Feb 2010 19:19:07 +0000 Subject: mute ui updates from external intervention --- src/common-defs.h | 1 + src/indicator-sound.c | 15 ++++++++++++--- src/pulse-manager.c | 5 +++-- src/slider-menu-item.c | 3 --- src/slider-menu-item.h | 1 + src/sound-service-dbus.c | 21 ++++++++++++++++++++- src/sound-service.c | 16 +++++++++++----- src/sound-service.h | 4 +--- src/sound-service.xml | 4 ++++ 9 files changed, 53 insertions(+), 17 deletions(-) (limited to 'src') diff --git a/src/common-defs.h b/src/common-defs.h index c969ddb..4009773 100644 --- a/src/common-defs.h +++ b/src/common-defs.h @@ -1,6 +1,7 @@ /* constants used for signals on the dbus. This file is shared between client and server implementation */ #define SIGNAL_SINK_INPUT_WHILE_MUTED "SinkInputWhileMuted" #define SIGNAL_SINK_VOLUME_UPDATE "SinkVolumeUpdate" +//#define SIGNAL_SINK_MUTE_UPDATE "SinkMuteUpdate" // DBUS items #define DBUSMENU_SLIDER_MENUITEM_TYPE "x-canonical-ido-slider-item" diff --git a/src/indicator-sound.c b/src/indicator-sound.c index fe1b6fb..73a8a23 100644 --- a/src/indicator-sound.c +++ b/src/indicator-sound.c @@ -195,7 +195,8 @@ connection_changed (IndicatorServiceManager * sm, gboolean connected, gpointer u dbus_g_proxy_connect_signal(sound_dbus_proxy, SIGNAL_SINK_INPUT_WHILE_MUTED, G_CALLBACK(catch_signal_sink_input_while_muted), NULL, NULL); dbus_g_proxy_add_signal(sound_dbus_proxy, SIGNAL_SINK_VOLUME_UPDATE, G_TYPE_DOUBLE, G_TYPE_INVALID); dbus_g_proxy_connect_signal(sound_dbus_proxy, SIGNAL_SINK_VOLUME_UPDATE, G_CALLBACK(catch_signal_sink_volume_update), NULL, NULL); - +/* dbus_g_proxy_add_signal(sound_dbus_proxy, SIGNAL_SINK_MUTE_UPDATE, G_TYPE_BOOLEAN, G_TYPE_INVALID);*/ +/* dbus_g_proxy_connect_signal(sound_dbus_proxy, SIGNAL_SINK_MUTE_UPDATE, G_CALLBACK(catch_signal_sink_mute_update), NULL, NULL);*/ } } else { @@ -207,8 +208,7 @@ connection_changed (IndicatorServiceManager * sm, gboolean connected, gpointer u static void catch_signal_sink_input_while_muted(DBusGProxy * proxy, gint sink_index, gboolean value, gpointer userdata) { - //gtk_image_set_from_icon_name(speaker_image, "audio-volume-muted-blocking-symbolic", GTK_ICON_SIZE_MENU); - g_debug("signal caught - I don't believe it ! with index %i and value %i", sink_index, value); + g_debug("signal caught - sink input while muted with index %i and value %i", sink_index, value); } static void catch_signal_sink_volume_update(DBusGProxy * proxy, gdouble volume_percent, gpointer userdata) @@ -219,6 +219,15 @@ static void catch_signal_sink_volume_update(DBusGProxy * proxy, gdouble volume_p gtk_range_set_value(range, volume_percent); } +/*static void catch_signal_sink_mute_update(DBusGProxy * proxy, gdouble volume_percent, gpointer userdata)*/ +/*{*/ +/* g_debug("signal caught - update sink volume with value : %f", volume_percent);*/ +/* GtkWidget* slider = ido_scale_menu_item_get_scale((IdoScaleMenuItem*)volume_slider);*/ +/* GtkRange* range = (GtkRange*)slider; */ +/* gtk_range_set_value(range, volume_percent); */ +/*}*/ + + static void indicator_sound_dispose (GObject *object) { diff --git a/src/pulse-manager.c b/src/pulse-manager.c index ff6f1bb..0a35d92 100644 --- a/src/pulse-manager.c +++ b/src/pulse-manager.c @@ -291,10 +291,11 @@ static void update_sink_info(pa_context *c, const pa_sink_info *info, int eol, v //update the UI pa_volume_t vol = pa_cvolume_avg(&s->volume); // Use the base of the device to ensure maximum acceptable levels on the hardware - gint volume_percent = (vol/s->base_volume); - g_debug("When using base volume => volume = %i", volume_percent); + gdouble volume_percent = (vol/s->base_volume) * 100; + 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) * 100); + update_mute_ui(s->mute); } } else diff --git a/src/slider-menu-item.c b/src/slider-menu-item.c index 2620e6e..2e8321d 100644 --- a/src/slider-menu-item.c +++ b/src/slider-menu-item.c @@ -91,11 +91,8 @@ handle_event (DbusmenuMenuitem * mi, const gchar * name, const GValue * value, g SliderMenuItem* slider_menu_item_new(gboolean sinks_available, gdouble start_volume) { SliderMenuItem *self = g_object_new(SLIDER_MENU_ITEM_TYPE, NULL); - //SliderMenuItemPrivate * priv = SLIDER_MENU_ITEM_GET_PRIVATE(self); dbusmenu_menuitem_property_set(DBUSMENU_MENUITEM(self), DBUSMENU_MENUITEM_PROP_TYPE, DBUSMENU_SLIDER_MENUITEM_TYPE); - //TODO: If no valid sinks are found grey out the item(s) dbusmenu_menuitem_property_set_bool(DBUSMENU_MENUITEM(self), DBUSMENU_MENUITEM_PROP_ENABLED, sinks_available); - //g_debug("Sending the initial value of the slider over dbus = %f", start_volume * 100); return self; } diff --git a/src/slider-menu-item.h b/src/slider-menu-item.h index 48e71ff..c4423e3 100644 --- a/src/slider-menu-item.h +++ b/src/slider-menu-item.h @@ -46,6 +46,7 @@ struct _SliderMenuItem { }; GType slider_menu_item_get_type (void); +// TODO for now the volume percent param is not being used - remove once init mystery is solved SliderMenuItem* slider_menu_item_new(gboolean sinks_available, gdouble current_vol); G_END_DECLS diff --git a/src/sound-service-dbus.c b/src/sound-service-dbus.c index 635dfeb..bcc21f6 100644 --- a/src/sound-service-dbus.c +++ b/src/sound-service-dbus.c @@ -44,6 +44,7 @@ struct _SoundServiceDbusPrivate enum { SINK_INPUT_WHILE_MUTED, SINK_VOLUME_UPDATE, + SINK_MUTE_UPDATE, LAST_SIGNAL }; @@ -90,11 +91,18 @@ sound_service_dbus_class_init (SoundServiceDbusClass *klass) NULL, NULL, g_cclosure_marshal_VOID__DOUBLE, G_TYPE_NONE, 1, G_TYPE_DOUBLE); + +/* signals[SINK_MUTE_UPDATE] = g_signal_new("sink-mute-update",*/ +/* G_TYPE_FROM_CLASS (klass),*/ +/* G_SIGNAL_RUN_LAST,*/ +/* 0,*/ +/* NULL, NULL,*/ +/* g_cclosure_marshal_VOID__BOOLEAN,*/ +/* G_TYPE_NONE, 1, G_TYPE_BOOLEAN);*/ } /** DBUS Method Callbacks -TODO do not see the point in this returning a boolean and also needing a sink index since the service needs to be ultimately aware of what sink is chosen. **/ void sound_service_dbus_set_sink_volume(SoundServiceDbus* service, const guint volume_percent, GError** gerror) { @@ -102,6 +110,7 @@ void sound_service_dbus_set_sink_volume(SoundServiceDbus* service, const guint v set_sink_volume(volume_percent); } +//TODO needed ? GList * sound_service_dbus_get_sink_list (SoundServiceDbus *self) { @@ -135,6 +144,16 @@ void sound_service_dbus_update_sink_volume(SoundServiceDbus* obj, gdouble sink_v sink_volume); } +/*void sound_service_dbus_update_sink_mute(SoundServiceDbus* obj, gboolean sink_mute)*/ +/*{*/ +/* g_debug("Emitting signal: SINK_MUTE_UPDATE, with sink mute %i", sink_mute);*/ +/* g_signal_emit(obj,*/ +/* signals[SINK_MUTE_UPDATE],*/ +/* 0,*/ +/* sink_mute);*/ +/*}*/ + +// TODO needed? void set_pa_sinks_hash(SoundServiceDbus *self, GHashTable *sinks) { SoundServiceDbusPrivate *priv = SOUND_SERVICE_DBUS_GET_PRIVATE (self); diff --git a/src/sound-service.c b/src/sound-service.c index 101cd18..cc39e38 100644 --- a/src/sound-service.c +++ b/src/sound-service.c @@ -5,7 +5,6 @@ Copyright 2010 Canonical Ltd. Authors: Conor Curran Ted Gould - Christoph Korn Cody Russell This program is free software: you can redistribute it and/or modify it @@ -40,7 +39,7 @@ static gboolean b_all_muted = FALSE; static gboolean b_pulse_ready = FALSE; static gdouble volume_percent = 0.0; -static void set_global_mute(); +static void set_global_mute_from_ui(); static gboolean idle_routine (gpointer data); static void rebuild_sound_menu(DbusmenuMenuitem *root, SoundServiceDbus *service); @@ -74,7 +73,7 @@ static void rebuild_sound_menu(DbusmenuMenuitem *root, SoundServiceDbus *service // Mute button mute_all_menuitem = dbusmenu_menuitem_new(); dbusmenu_menuitem_property_set(mute_all_menuitem, DBUSMENU_MENUITEM_PROP_LABEL, _(b_all_muted == FALSE ? "Mute All" : "Unmute")); - g_signal_connect(G_OBJECT(mute_all_menuitem), DBUSMENU_MENUITEM_SIGNAL_ITEM_ACTIVATED, G_CALLBACK(set_global_mute), NULL); + g_signal_connect(G_OBJECT(mute_all_menuitem), DBUSMENU_MENUITEM_SIGNAL_ITEM_ACTIVATED, G_CALLBACK(set_global_mute_from_ui), NULL); //TODO: If no valid sinks are found grey out the item(s) dbusmenu_menuitem_property_set_bool(mute_all_menuitem, DBUSMENU_MENUITEM_PROP_ENABLED, b_sink_available); @@ -93,8 +92,14 @@ static void rebuild_sound_menu(DbusmenuMenuitem *root, SoundServiceDbus *service g_signal_connect(G_OBJECT(settings_mi), DBUSMENU_MENUITEM_SIGNAL_ITEM_ACTIVATED, G_CALLBACK(show_sound_settings_dialog), NULL); } +/* 'public' method allowing the server to update the mute UI*/ +void update_mute_ui(gboolean incoming_mute_value) +{ + b_all_muted = incoming_mute_value; + dbusmenu_menuitem_property_set(mute_all_menuitem, DBUSMENU_MENUITEM_PROP_LABEL, _(b_all_muted == FALSE ? "Mute All" : "Unmute")); +} -static void set_global_mute() +static void set_global_mute_from_ui() { b_all_muted = !b_all_muted; toggle_global_mute(b_all_muted); @@ -118,6 +123,7 @@ service_shutdown (IndicatorService *service, gpointer user_data) if (mainloop != NULL) { g_debug("Service shutdown - but commented out for right now"); + // TODO: uncomment for release /* close_pulse_activites()*/ /* g_main_loop_quit(mainloop);*/ } @@ -132,10 +138,10 @@ void update_pa_state(gboolean pa_state, gboolean sink_available, gboolean sink_m volume_percent = percent; g_debug("update pa state with state %i, availability of %i, mute value of %i and a volume percent is %f", pa_state, sink_available, sink_muted, volume_percent); rebuild_sound_menu(root_menuitem, dbus_interface); - g_debug("About to send over the volume slider"); GValue value = {0}; g_value_init(&value, G_TYPE_DOUBLE); g_value_set_double(&value, volume_percent * 100); + g_debug("About to send over the volume slider initial value %f", (volume_percent * 100)); dbusmenu_menuitem_property_set_value(DBUSMENU_MENUITEM(volume_slider_menuitem), DBUSMENU_SLIDER_MENUITEM_PROP_VOLUME, &value); } diff --git a/src/sound-service.h b/src/sound-service.h index fec52a3..d36ea41 100644 --- a/src/sound-service.h +++ b/src/sound-service.h @@ -8,7 +8,6 @@ Copyright 2010 Canonical Ltd. Authors: Conor Curran Ted Gould - Christoph Korn Cody Russell This program is free software: you can redistribute it and/or modify it @@ -39,11 +38,10 @@ with this program. If not, see . #include "dbus-shared-names.h" - // ENTRY AND EXIT POINTS void service_shutdown(IndicatorService * service, gpointer user_data); int main (int argc, char ** argv); void update_pa_state(gboolean pa_state, gboolean sink_available, gboolean sink_muted, gdouble current_vol); - +void update_mute_ui(gboolean incoming_mute_value); #endif diff --git a/src/sound-service.xml b/src/sound-service.xml index fffad00..8583fbc 100644 --- a/src/sound-service.xml +++ b/src/sound-service.xml @@ -17,6 +17,10 @@ Our respective UI element should listen to this and therefore will be updated wi + + + + -- cgit v1.2.3 From 1ae774f7367f91f40f94a845c525ddedf1ddbba5 Mon Sep 17 00:00:00 2001 From: Conor Curran Date: Mon, 8 Feb 2010 21:32:10 +0000 Subject: listener fixed --- src/indicator-sound.c | 12 ++++++------ src/pulse-manager.c | 18 +++++++++++------- 2 files changed, 17 insertions(+), 13 deletions(-) (limited to 'src') diff --git a/src/indicator-sound.c b/src/indicator-sound.c index 73a8a23..588b2d6 100644 --- a/src/indicator-sound.c +++ b/src/indicator-sound.c @@ -82,7 +82,7 @@ static gdouble input_value_from_across_the_dbus = 0.0; static gboolean new_slider_item (DbusmenuMenuitem * newitem, DbusmenuMenuitem * parent, DbusmenuClient * client); static void slider_prop_change_cb (DbusmenuMenuitem * mi, gchar * prop, GValue * value, GtkWidget *widget); -static gboolean slider_value_changed_event_cb(GtkRange *range, gpointer user_data); +static gboolean slider_value_changed_event_cb(GtkRange *range, GtkScrollType scroll_type, gdouble input_value, gpointer user_data); /*static void change_speaker_image(gdouble volume_percent);*/ /*static void prepare_state_machine();*/ @@ -319,7 +319,7 @@ static gboolean new_slider_item(DbusmenuMenuitem * newitem, DbusmenuMenuitem * p g_signal_connect(G_OBJECT(newitem), DBUSMENU_MENUITEM_SIGNAL_PROPERTY_CHANGED, G_CALLBACK(slider_prop_change_cb), volume_slider); GtkWidget* slider = ido_scale_menu_item_get_scale((IdoScaleMenuItem*)volume_slider); - g_signal_connect(slider, "value-changed", G_CALLBACK(slider_value_changed_event_cb), newitem); + g_signal_connect(slider, "change-value", G_CALLBACK(slider_value_changed_event_cb), newitem); gtk_widget_show_all(volume_slider); return TRUE; } @@ -341,16 +341,16 @@ static void slider_prop_change_cb (DbusmenuMenuitem * mi, gchar * prop, GValue * return; } -static gboolean slider_value_changed_event_cb(GtkRange *range, gpointer user_data) +static gboolean slider_value_changed_event_cb(GtkRange *range, GtkScrollType scroll_type, gdouble input_value, gpointer user_data) { /* #if(slider_value != input_value_from_across_the_dbus)*/ /* #{ */ DbusmenuMenuitem *item = (DbusmenuMenuitem*)user_data; + gdouble clamped_input = CLAMP(input_value, 0, 100); GValue value = {0}; - gdouble input = gtk_range_get_value(range); - g_debug("CALLBACK for the range - input received = %f", input); + g_debug("User input Event listener for the range - input received = %f", clamped_input); g_value_init(&value, G_TYPE_DOUBLE); - g_value_set_double(&value, input); + g_value_set_double(&value, clamped_input); dbusmenu_menuitem_handle_event (item, "slider_change", &value, 0); /* change_speaker_image(slider_value);*/ /* }*/ diff --git a/src/pulse-manager.c b/src/pulse-manager.c index 0a35d92..169c0df 100644 --- a/src/pulse-manager.c +++ b/src/pulse-manager.c @@ -44,7 +44,8 @@ void set_sink_volume(gdouble percent) g_debug("and an actual volume of %f", (gdouble)new_volume); pa_cvolume dev_vol; sink_info *s = g_hash_table_lookup(sink_hash, GINT_TO_POINTER(DEFAULT_SINK_INDEX)); - pa_cvolume_set(&dev_vol, s->volume.channels, new_volume); + pa_cvolume_set(&dev_vol, s->volume.channels, new_volume); + // TODO - really this needs to be set in the success callback - if call fails then the ui will not be updated indefinitely! pa_operation_unref(pa_context_set_sink_volume_by_index(pulse_context, DEFAULT_SINK_INDEX, &dev_vol, NULL, NULL)); } @@ -194,15 +195,13 @@ static void pulse_sink_info_callback(pa_context *c, const pa_sink_info *sink, in DEFAULT_SINK_INDEX = (DEFAULT_SINK_INDEX < 0) ? 0 : DEFAULT_SINK_INDEX; test_hash(); update_pa_state(TRUE, device_available, default_sink_is_muted(), get_default_sink_volume()); - g_debug("default sink index : %d", DEFAULT_SINK_INDEX); - + g_debug("default sink index : %d", DEFAULT_SINK_INDEX); } else{ //Update the indicator to show PA either is not ready or has no available sink g_warning("Cannot find a suitable default sink ..."); update_pa_state(FALSE, device_available, TRUE, 0); } - } else{ g_debug("About to add an item to our hash"); @@ -285,8 +284,8 @@ static void update_sink_info(pa_context *c, const pa_sink_info *info, int eol, v /* g_debug("Are the volumes the same %i", equal); */ s->volume = info->volume; s->base_volume = info->base_volume; - s->channel_map = info->channel_map; - if(DEFAULT_SINK_INDEX == s->index/* && update_ui_vol == TRUE*/) + s->channel_map = info->channel_map; + if(DEFAULT_SINK_INDEX == s->index) { //update the UI pa_volume_t vol = pa_cvolume_avg(&s->volume); @@ -297,6 +296,11 @@ static void update_sink_info(pa_context *c, const pa_sink_info *info, int eol, v sound_service_dbus_update_sink_volume(dbus_service, pa_sw_volume_to_linear(vol) * 100); update_mute_ui(s->mute); } + else{ + // Reset the ui flag + // TODO: there must be a nicer way to do this - I suspect this pattern could introduce race conditions !!! + g_debug("SKIPPED UPDATING UI BECAUSE THE UI_NEEDS_UPDATE WAS FALSE!"); + } } else { @@ -343,7 +347,7 @@ static void subscribed_events_callback(pa_context *c, enum pa_subscription_event switch (t & PA_SUBSCRIPTION_EVENT_FACILITY_MASK) { case PA_SUBSCRIPTION_EVENT_SINK: if ((t & PA_SUBSCRIPTION_EVENT_TYPE_MASK) == PA_SUBSCRIPTION_EVENT_REMOVE) { - //TODO handle the remove event + //TODO handle the remove event => if its our default sink - grey out the ui with update_pa_state } else { pa_operation_unref(pa_context_get_sink_info_by_index(c, index, update_sink_info, userdata)); } -- cgit v1.2.3 From 8046b1e98594e5be7a0c3392a0348577a18dce54 Mon Sep 17 00:00:00 2001 From: Conor Curran Date: Tue, 9 Feb 2010 18:13:58 +0000 Subject: slider init'd with the correct value - geesh --- src/indicator-sound.c | 102 ++++++++++++++++++--------------------- src/pulse-manager.c | 4 +- src/sound-service-dbus.c | 121 +++++++++++++++++++++++------------------------ src/sound-service-dbus.h | 4 -- src/sound-service.c | 16 ++++--- src/sound-service.xml | 7 +-- 6 files changed, 120 insertions(+), 134 deletions(-) (limited to 'src') diff --git a/src/indicator-sound.c b/src/indicator-sound.c index 588b2d6..3103aac 100644 --- a/src/indicator-sound.c +++ b/src/indicator-sound.c @@ -78,13 +78,12 @@ static GtkLabel * get_label (IndicatorObject * io); static GtkImage * get_icon (IndicatorObject * io); static GtkMenu * get_menu (IndicatorObject * io); static GtkWidget *volume_slider = NULL; -static gdouble input_value_from_across_the_dbus = 0.0; static gboolean new_slider_item (DbusmenuMenuitem * newitem, DbusmenuMenuitem * parent, DbusmenuClient * client); static void slider_prop_change_cb (DbusmenuMenuitem * mi, gchar * prop, GValue * value, GtkWidget *widget); static gboolean slider_value_changed_event_cb(GtkRange *range, GtkScrollType scroll_type, gdouble input_value, gpointer user_data); /*static void change_speaker_image(gdouble volume_percent);*/ -/*static void prepare_state_machine();*/ +static void prepare_state_machine(); // DBUS communication static DBusGProxy *sound_dbus_proxy = NULL; @@ -102,8 +101,9 @@ static const gint STATE_MUTED_WHILE_INPUT = 5; static const gint STATE_SINKS_NONE = 5; static GHashTable *volume_states = NULL; static GtkImage *speaker_image = NULL; -/*static gint current_state = 0;*/ -//static gint previous_state = 0; +static gint current_state = 0; +static gint previous_state = 0; +static gdouble initial_volume_percent = 0; static void indicator_sound_class_init (IndicatorSoundClass *klass) @@ -133,43 +133,36 @@ static void indicator_sound_init (IndicatorSound *self) /* Now let's fire these guys up. */ self->service = indicator_service_manager_new_version(INDICATOR_SOUND_DBUS_NAME, INDICATOR_SOUND_DBUS_VERSION); g_signal_connect(G_OBJECT(self->service), INDICATOR_SERVICE_MANAGER_SIGNAL_CONNECTION_CHANGE, G_CALLBACK(connection_changed), self); - //prepare_state_machine(); - + prepare_state_machine(); return; } -/*static void test_images_hash()*/ -/*{*/ -/* gchar* name;*/ -/* g_debug("about to test the images hash"); */ -/* name = g_hash_table_lookup(volume_states, GINT_TO_POINTER(0));*/ -/* g_debug("image name = %s", name); */ -/*}*/ +static void test_images_hash() +{ + g_debug("about to test the images hash"); + gchar* current_name = g_hash_table_lookup(volume_states, GINT_TO_POINTER(current_state)); + g_debug("start up current image name = %s", current_name); + gchar* previous_name = g_hash_table_lookup(volume_states, GINT_TO_POINTER(previous_state)); + g_debug("start up previous image name = %s", previous_name); +} + +/* +Prepare states Array. +*/ +static void prepare_state_machine() +{ + volume_states = g_hash_table_new_full(g_direct_hash, g_direct_equal, NULL, g_free); + g_hash_table_insert(volume_states, GINT_TO_POINTER(STATE_MUTED), g_strdup("audio-volume-muted")); + g_hash_table_insert(volume_states, GINT_TO_POINTER(STATE_ZERO), g_strdup("audio-volume-zero")); + g_hash_table_insert(volume_states, GINT_TO_POINTER(STATE_LOW), g_strdup("audio-volume-low")); + g_hash_table_insert(volume_states, GINT_TO_POINTER(STATE_MEDIUM), g_strdup("audio-volume-medium")); + g_hash_table_insert(volume_states, GINT_TO_POINTER(STATE_HIGH), g_strdup("audio-volume-high")); + g_hash_table_insert(volume_states, GINT_TO_POINTER(STATE_MUTED_WHILE_INPUT), g_strdup("audio-volume-muted-blocking")); + g_hash_table_insert(volume_states, GINT_TO_POINTER(STATE_SINKS_NONE), g_strdup("audio-output-none")); + test_images_hash(); +} -/*/***/ -/*Prepare states Array.*/ -/***/ -/*static void prepare_state_machine()*/ -/*{*/ -/* volume_states = g_hash_table_new_full(g_direct_hash, g_direct_equal, NULL, g_free);*/ -/* g_hash_table_insert(volume_states, GINT_TO_POINTER(STATE_MUTED), "audio-volume-muted");*/ -/* g_hash_table_insert(volume_states, GINT_TO_POINTER(STATE_ZERO), "audio-volume-zero");*/ -/* g_hash_table_insert(volume_states, GINT_TO_POINTER(STATE_LOW), "audio-volume-low");*/ -/* g_hash_table_insert(volume_states, GINT_TO_POINTER(STATE_MEDIUM), "audio-volume-medium");*/ -/* g_hash_table_insert(volume_states, GINT_TO_POINTER(STATE_HIGH), "audio-volume-high");*/ -/* g_hash_table_insert(volume_states, GINT_TO_POINTER(STATE_MUTED_WHILE_INPUT), "audio-volume-muted-blocking");*/ -/* g_hash_table_insert(volume_states, GINT_TO_POINTER(STATE_SINKS_NONE), "audio-output-none");*/ -/* test_images_hash();*/ -/*}*/ -/*static void destroy_volume_image_info(void *value)*/ -/*{*/ -/* gchar* name = (gchar*)value;*/ -/* g_free(name);*/ -/* g_free(sink->description); */ -/* g_free(sink->icon_name); */ -/* g_free(sink); */ -/*}*/ static void connection_changed (IndicatorServiceManager * sm, gboolean connected, gpointer userdata) @@ -195,8 +188,17 @@ connection_changed (IndicatorServiceManager * sm, gboolean connected, gpointer u dbus_g_proxy_connect_signal(sound_dbus_proxy, SIGNAL_SINK_INPUT_WHILE_MUTED, G_CALLBACK(catch_signal_sink_input_while_muted), NULL, NULL); dbus_g_proxy_add_signal(sound_dbus_proxy, SIGNAL_SINK_VOLUME_UPDATE, G_TYPE_DOUBLE, G_TYPE_INVALID); dbus_g_proxy_connect_signal(sound_dbus_proxy, SIGNAL_SINK_VOLUME_UPDATE, G_CALLBACK(catch_signal_sink_volume_update), NULL, NULL); -/* dbus_g_proxy_add_signal(sound_dbus_proxy, SIGNAL_SINK_MUTE_UPDATE, G_TYPE_BOOLEAN, G_TYPE_INVALID);*/ -/* dbus_g_proxy_connect_signal(sound_dbus_proxy, SIGNAL_SINK_MUTE_UPDATE, G_CALLBACK(catch_signal_sink_mute_update), NULL, NULL);*/ + gdouble *volume_percent_input; + volume_percent_input = g_new0(gdouble, 1); + org_ayatana_indicator_sound_get_sink_volume(sound_dbus_proxy, volume_percent_input, &error); + if (error != NULL) { + g_warning("Unable to fetch volume at indicator start up: %s", error->message); + g_error_free(error); + g_free(volume_percent_input); + return; + } + initial_volume_percent = *volume_percent_input * 100; + g_debug("at the indicator start up and the volume percent returned from dbus method is %f", initial_volume_percent); } } else { @@ -219,14 +221,6 @@ static void catch_signal_sink_volume_update(DBusGProxy * proxy, gdouble volume_p gtk_range_set_value(range, volume_percent); } -/*static void catch_signal_sink_mute_update(DBusGProxy * proxy, gdouble volume_percent, gpointer userdata)*/ -/*{*/ -/* g_debug("signal caught - update sink volume with value : %f", volume_percent);*/ -/* GtkWidget* slider = ido_scale_menu_item_get_scale((IdoScaleMenuItem*)volume_slider);*/ -/* GtkRange* range = (GtkRange*)slider; */ -/* gtk_range_set_value(range, volume_percent); */ -/*}*/ - static void indicator_sound_dispose (GObject *object) @@ -320,6 +314,9 @@ static gboolean new_slider_item(DbusmenuMenuitem * newitem, DbusmenuMenuitem * p GtkWidget* slider = ido_scale_menu_item_get_scale((IdoScaleMenuItem*)volume_slider); g_signal_connect(slider, "change-value", G_CALLBACK(slider_value_changed_event_cb), newitem); + GtkRange* range = (GtkRange*)slider; + gtk_range_set_value(range, initial_volume_percent); + gtk_widget_show_all(volume_slider); return TRUE; } @@ -328,27 +325,20 @@ static gboolean new_slider_item(DbusmenuMenuitem * newitem, DbusmenuMenuitem * p we need to be responsive to that. */ static void slider_prop_change_cb (DbusmenuMenuitem * mi, gchar * prop, GValue * value, GtkWidget *widget) { - g_debug("slider_prop_change_cb "); + g_debug("slider_prop_change_cb - dodgy updater "); g_debug("about to set the slider to %f", g_value_get_double(value)); GtkWidget* slider = ido_scale_menu_item_get_scale((IdoScaleMenuItem*)volume_slider); - GtkRange* range = (GtkRange*)slider; - gdouble level; - level = gtk_range_get_fill_level(range); - input_value_from_across_the_dbus = level; - g_debug("the current level is %f", level); - + GtkRange* range = (GtkRange*)slider; gtk_range_set_value(range, g_value_get_double(value)); return; } static gboolean slider_value_changed_event_cb(GtkRange *range, GtkScrollType scroll_type, gdouble input_value, gpointer user_data) { -/* #if(slider_value != input_value_from_across_the_dbus)*/ -/* #{ */ DbusmenuMenuitem *item = (DbusmenuMenuitem*)user_data; gdouble clamped_input = CLAMP(input_value, 0, 100); GValue value = {0}; - g_debug("User input Event listener for the range - input received = %f", clamped_input); + g_debug("User input on SLIDER - = %f", clamped_input); g_value_init(&value, G_TYPE_DOUBLE); g_value_set_double(&value, clamped_input); dbusmenu_menuitem_handle_event (item, "slider_change", &value, 0); diff --git a/src/pulse-manager.c b/src/pulse-manager.c index 169c0df..e7570c6 100644 --- a/src/pulse-manager.c +++ b/src/pulse-manager.c @@ -187,14 +187,14 @@ For now this callback it assumes it only used at startup. It may be necessary to static void pulse_sink_info_callback(pa_context *c, const pa_sink_info *sink, int eol, void *userdata) { if (eol > 0) { - gboolean device_available; - device_available = sink_available(); + gboolean device_available = sink_available(); if(device_available == TRUE) { // Hopefully the PA server has set the default device if not default to 0 DEFAULT_SINK_INDEX = (DEFAULT_SINK_INDEX < 0) ? 0 : DEFAULT_SINK_INDEX; test_hash(); update_pa_state(TRUE, device_available, default_sink_is_muted(), get_default_sink_volume()); + sound_service_dbus_update_sink_volume(dbus_service, get_default_sink_volume()); g_debug("default sink index : %d", DEFAULT_SINK_INDEX); } else{ diff --git a/src/sound-service-dbus.c b/src/sound-service-dbus.c index bcc21f6..ac92a06 100644 --- a/src/sound-service-dbus.c +++ b/src/sound-service-dbus.c @@ -25,18 +25,23 @@ #include #include "dbus-shared-names.h" #include "sound-service-dbus.h" -#include "sound-service-server.h" #include "common-defs.h" #include "sound-service-marshal.h" #include "pulse-manager.h" +// DBUS methods - +// TODO - other should be static and moved from the header to here +static gboolean sound_service_dbus_get_sink_volume(SoundServiceDbus* service, gdouble* volume_percent_input, GError** gerror); + +#include "sound-service-server.h" + typedef struct _SoundServiceDbusPrivate SoundServiceDbusPrivate; struct _SoundServiceDbusPrivate { DBusGConnection *system_bus; DBusGConnection *connection; - GHashTable *sinks_hash; + gdouble volume_percent; }; @@ -44,7 +49,6 @@ struct _SoundServiceDbusPrivate enum { SINK_INPUT_WHILE_MUTED, SINK_VOLUME_UPDATE, - SINK_MUTE_UPDATE, LAST_SIGNAL }; @@ -53,12 +57,12 @@ static guint signals[LAST_SIGNAL] = { 0 }; #define SOUND_SERVICE_DBUS_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), SOUND_SERVICE_DBUS_TYPE, SoundServiceDbusPrivate)) - static void sound_service_dbus_class_init (SoundServiceDbusClass *klass); static void sound_service_dbus_init (SoundServiceDbus *self); static void sound_service_dbus_dispose (GObject *object); static void sound_service_dbus_finalize (GObject *object); + /* GObject Boilerplate */ G_DEFINE_TYPE (SoundServiceDbus, sound_service_dbus, G_TYPE_OBJECT); @@ -92,15 +96,51 @@ sound_service_dbus_class_init (SoundServiceDbusClass *klass) g_cclosure_marshal_VOID__DOUBLE, G_TYPE_NONE, 1, G_TYPE_DOUBLE); -/* signals[SINK_MUTE_UPDATE] = g_signal_new("sink-mute-update",*/ -/* G_TYPE_FROM_CLASS (klass),*/ -/* G_SIGNAL_RUN_LAST,*/ -/* 0,*/ -/* NULL, NULL,*/ -/* g_cclosure_marshal_VOID__BOOLEAN,*/ -/* G_TYPE_NONE, 1, G_TYPE_BOOLEAN);*/ } +static void +sound_service_dbus_init (SoundServiceDbus *self) +{ + GError *error = NULL; + SoundServiceDbusPrivate * priv = SOUND_SERVICE_DBUS_GET_PRIVATE(self); + + priv->system_bus = NULL; + priv->connection = NULL; + priv->volume_percent = 0; + + /* Get the system bus */ + priv->system_bus = dbus_g_bus_get (DBUS_BUS_SYSTEM, &error); + /* Put the object on DBus */ + priv->connection = dbus_g_bus_get(DBUS_BUS_SESSION, &error); + + if (error != NULL) { + g_error("Unable to connect to the session bus when creating application indicator: %s", error->message); + g_error_free(error); + return; + } + dbus_g_connection_register_g_object(priv->connection, + "/org/ayatana/indicator/sound/service", + G_OBJECT(self)); + + return; +} + + +static void +sound_service_dbus_dispose (GObject *object) +{ + G_OBJECT_CLASS (sound_service_dbus_parent_class)->dispose (object); + return; +} + +static void +sound_service_dbus_finalize (GObject *object) +{ + G_OBJECT_CLASS (sound_service_dbus_parent_class)->finalize (object); + return; +} + + /** DBUS Method Callbacks **/ @@ -110,13 +150,12 @@ void sound_service_dbus_set_sink_volume(SoundServiceDbus* service, const guint v set_sink_volume(volume_percent); } -//TODO needed ? -GList * -sound_service_dbus_get_sink_list (SoundServiceDbus *self) +static gboolean sound_service_dbus_get_sink_volume (SoundServiceDbus *self, gdouble *volume_percent_input, GError** gerror) { - SoundServiceDbusPrivate *priv = SOUND_SERVICE_DBUS_GET_PRIVATE (self); - - return g_hash_table_get_keys (priv->sinks_hash); + SoundServiceDbusPrivate *priv = SOUND_SERVICE_DBUS_GET_PRIVATE (self); + g_debug("Get sink volume method in the sound service dbus!, about to send over volume percent of %f", priv->volume_percent); + *volume_percent_input = priv->volume_percent; + return TRUE; } @@ -137,6 +176,9 @@ void sound_service_dbus_sink_input_while_muted(SoundServiceDbus* obj, gint sink_ void sound_service_dbus_update_sink_volume(SoundServiceDbus* obj, gdouble sink_volume) { + SoundServiceDbusPrivate *priv = SOUND_SERVICE_DBUS_GET_PRIVATE (obj); + priv->volume_percent = sink_volume; + g_debug("Emitting signal: SINK_VOLUME_UPDATE, with sink_volme %f", sink_volume); g_signal_emit(obj, signals[SINK_VOLUME_UPDATE], @@ -153,50 +195,5 @@ void sound_service_dbus_update_sink_volume(SoundServiceDbus* obj, gdouble sink_v /* sink_mute);*/ /*}*/ -// TODO needed? -void set_pa_sinks_hash(SoundServiceDbus *self, GHashTable *sinks) -{ - SoundServiceDbusPrivate *priv = SOUND_SERVICE_DBUS_GET_PRIVATE (self); - priv->sinks_hash = sinks; -} -static void -sound_service_dbus_init (SoundServiceDbus *self) -{ - GError *error = NULL; - SoundServiceDbusPrivate * priv = SOUND_SERVICE_DBUS_GET_PRIVATE(self); - - priv->system_bus = NULL; - priv->connection = NULL; - - /* Get the system bus */ - priv->system_bus = dbus_g_bus_get (DBUS_BUS_SYSTEM, &error); - /* Put the object on DBus */ - priv->connection = dbus_g_bus_get(DBUS_BUS_SESSION, &error); - - if (error != NULL) { - g_error("Unable to connect to the session bus when creating application indicator: %s", error->message); - g_error_free(error); - return; - } - dbus_g_connection_register_g_object(priv->connection, - "/org/ayatana/indicator/sound/service", - G_OBJECT(self)); - - return; -} - -static void -sound_service_dbus_dispose (GObject *object) -{ - G_OBJECT_CLASS (sound_service_dbus_parent_class)->dispose (object); - return; -} - -static void -sound_service_dbus_finalize (GObject *object) -{ - G_OBJECT_CLASS (sound_service_dbus_parent_class)->finalize (object); - return; -} diff --git a/src/sound-service-dbus.h b/src/sound-service-dbus.h index dc52861..08d4bbd 100644 --- a/src/sound-service-dbus.h +++ b/src/sound-service-dbus.h @@ -53,18 +53,14 @@ struct _SoundServiceDbusClass { void (* sink_input_while_muted) (SoundServiceDbus *self, gint sink_index, gboolean is_muted, gpointer sound_data); void (* sink_volume_update) (SoundServiceDbus *self, gdouble sink_volume, gpointer sound_data); }; - GType sound_service_dbus_get_type (void) G_GNUC_CONST; // Utility methods to get the messages across into the sound-service-dbus void sound_service_dbus_sink_input_while_muted (SoundServiceDbus* obj, gint sink_index, gboolean value); void sound_service_dbus_update_sink_volume(SoundServiceDbus* obj, gdouble sink_volume); -void set_pa_sinks_hash(SoundServiceDbus *self, GHashTable *sinks); // DBUS METHODS void sound_service_dbus_set_sink_volume(SoundServiceDbus* service, const guint volume_percent, GError** gerror); -GList *sound_service_dbus_get_sink_list(SoundServiceDbus* service); - G_END_DECLS diff --git a/src/sound-service.c b/src/sound-service.c index cc39e38..503dc5a 100644 --- a/src/sound-service.c +++ b/src/sound-service.c @@ -107,8 +107,9 @@ static void set_global_mute_from_ui() /* GValue value = {0};*/ /* g_value_init(&value, G_TYPE_DOUBLE);*/ -/* g_value_set_double(&value, 100.0);*/ +/* g_value_set_double(&value, 99.0);*/ /* // Testing*/ +/* g_debug("BUGGY volume update");*/ /* dbusmenu_menuitem_property_set_value(DBUSMENU_MENUITEM(volume_slider_menuitem), DBUSMENU_SLIDER_MENUITEM_PROP_VOLUME, &value);*/ } @@ -121,7 +122,6 @@ service_shutdown (IndicatorService *service, gpointer user_data) { if (mainloop != NULL) { - g_debug("Service shutdown - but commented out for right now"); // TODO: uncomment for release /* close_pulse_activites()*/ @@ -138,11 +138,6 @@ void update_pa_state(gboolean pa_state, gboolean sink_available, gboolean sink_m volume_percent = percent; g_debug("update pa state with state %i, availability of %i, mute value of %i and a volume percent is %f", pa_state, sink_available, sink_muted, volume_percent); rebuild_sound_menu(root_menuitem, dbus_interface); - GValue value = {0}; - g_value_init(&value, G_TYPE_DOUBLE); - g_value_set_double(&value, volume_percent * 100); - g_debug("About to send over the volume slider initial value %f", (volume_percent * 100)); - dbusmenu_menuitem_property_set_value(DBUSMENU_MENUITEM(volume_slider_menuitem), DBUSMENU_SLIDER_MENUITEM_PROP_VOLUME, &value); } @@ -174,6 +169,13 @@ main (int argc, char ** argv) dbusmenu_server_set_root(server, root_menuitem); establish_pulse_activities(dbus_interface); +/* // THIS DOES NOT WORK FROM HERE*/ +/* GValue value = {0};*/ +/* g_value_init(&value, G_TYPE_DOUBLE);*/ +/* g_value_set_double(&value, volume_percent * 100);*/ +/* g_debug("About to send over the volume slider initial value %f", (volume_percent * 100));*/ +/* dbusmenu_menuitem_property_set_value(DBUSMENU_MENUITEM(volume_slider_menuitem), DBUSMENU_SLIDER_MENUITEM_PROP_VOLUME, &value);*/ + // Run the loop mainloop = g_main_loop_new(NULL, FALSE); g_main_loop_run(mainloop); diff --git a/src/sound-service.xml b/src/sound-service.xml index 8583fbc..4a88aab 100644 --- a/src/sound-service.xml +++ b/src/sound-service.xml @@ -5,6 +5,10 @@ + + + + @@ -17,9 +21,6 @@ Our respective UI element should listen to this and therefore will be updated wi - - - -- cgit v1.2.3 From 8d9276778375d9187a8f9839ff11e8aa5b186da0 Mon Sep 17 00:00:00 2001 From: Conor Curran Date: Tue, 9 Feb 2010 20:10:51 +0000 Subject: images changes dynamically now --- src/indicator-sound.c | 92 +++++++++++++++++++++++++++------------------------ 1 file changed, 48 insertions(+), 44 deletions(-) (limited to 'src') diff --git a/src/indicator-sound.c b/src/indicator-sound.c index 3103aac..10ce2ca 100644 --- a/src/indicator-sound.c +++ b/src/indicator-sound.c @@ -82,8 +82,11 @@ static GtkWidget *volume_slider = NULL; static gboolean new_slider_item (DbusmenuMenuitem * newitem, DbusmenuMenuitem * parent, DbusmenuClient * client); static void slider_prop_change_cb (DbusmenuMenuitem * mi, gchar * prop, GValue * value, GtkWidget *widget); static gboolean slider_value_changed_event_cb(GtkRange *range, GtkScrollType scroll_type, gdouble input_value, gpointer user_data); + /*static void change_speaker_image(gdouble volume_percent);*/ static void prepare_state_machine(); +static void determine_state_from_volume(gdouble volume_percent); +static void update_state(const gint state); // DBUS communication static DBusGProxy *sound_dbus_proxy = NULL; @@ -138,32 +141,32 @@ static void indicator_sound_init (IndicatorSound *self) } -static void test_images_hash() -{ - g_debug("about to test the images hash"); - gchar* current_name = g_hash_table_lookup(volume_states, GINT_TO_POINTER(current_state)); - g_debug("start up current image name = %s", current_name); - gchar* previous_name = g_hash_table_lookup(volume_states, GINT_TO_POINTER(previous_state)); - g_debug("start up previous image name = %s", previous_name); -} +/*static void test_images_hash()*/ +/*{*/ +/* g_debug("about to test the images hash"); */ +/* gchar* current_name = g_hash_table_lookup(volume_states, GINT_TO_POINTER(current_state));*/ +/* g_debug("start up current image name = %s", current_name); */ +/* gchar* previous_name = g_hash_table_lookup(volume_states, GINT_TO_POINTER(previous_state));*/ +/* g_debug("start up previous image name = %s", previous_name); */ +/*}*/ /* Prepare states Array. */ static void prepare_state_machine() { + // TODO we need three more images volume_states = g_hash_table_new_full(g_direct_hash, g_direct_equal, NULL, g_free); g_hash_table_insert(volume_states, GINT_TO_POINTER(STATE_MUTED), g_strdup("audio-volume-muted")); - g_hash_table_insert(volume_states, GINT_TO_POINTER(STATE_ZERO), g_strdup("audio-volume-zero")); + g_hash_table_insert(volume_states, GINT_TO_POINTER(STATE_ZERO), g_strdup(/*"audio-volume-zero"*/"audio-volume-muted")); g_hash_table_insert(volume_states, GINT_TO_POINTER(STATE_LOW), g_strdup("audio-volume-low")); g_hash_table_insert(volume_states, GINT_TO_POINTER(STATE_MEDIUM), g_strdup("audio-volume-medium")); g_hash_table_insert(volume_states, GINT_TO_POINTER(STATE_HIGH), g_strdup("audio-volume-high")); - g_hash_table_insert(volume_states, GINT_TO_POINTER(STATE_MUTED_WHILE_INPUT), g_strdup("audio-volume-muted-blocking")); - g_hash_table_insert(volume_states, GINT_TO_POINTER(STATE_SINKS_NONE), g_strdup("audio-output-none")); - test_images_hash(); + g_hash_table_insert(volume_states, GINT_TO_POINTER(STATE_MUTED_WHILE_INPUT), g_strdup(/*"audio-volume-muted-blocking"*/"audio-volume-muted")); + g_hash_table_insert(volume_states, GINT_TO_POINTER(STATE_SINKS_NONE), g_strdup(/*"audio-output-none"*/"audio-volume-muted")); + //test_images_hash(); } - static void connection_changed (IndicatorServiceManager * sm, gboolean connected, gpointer userdata) { @@ -197,7 +200,9 @@ connection_changed (IndicatorServiceManager * sm, gboolean connected, gpointer u g_free(volume_percent_input); return; } - initial_volume_percent = *volume_percent_input * 100; + initial_volume_percent = *volume_percent_input; + determine_state_from_volume(initial_volume_percent); + g_free(volume_percent_input); g_debug("at the indicator start up and the volume percent returned from dbus method is %f", initial_volume_percent); } @@ -218,7 +223,8 @@ static void catch_signal_sink_volume_update(DBusGProxy * proxy, gdouble volume_p g_debug("signal caught - update sink volume with value : %f", volume_percent); GtkWidget* slider = ido_scale_menu_item_get_scale((IdoScaleMenuItem*)volume_slider); GtkRange* range = (GtkRange*)slider; - gtk_range_set_value(range, volume_percent); + gtk_range_set_value(range, volume_percent); + determine_state_from_volume(volume_percent); } @@ -252,41 +258,39 @@ get_label (IndicatorObject * io) static GtkImage * get_icon (IndicatorObject * io) { - //gchar* image_name = g_hash_table_lookup(volume_states, GINT_TO_POINTER(current_state)); - //g_debug("At start-up attempting to set the image to %s", image_name); - speaker_image = GTK_IMAGE(gtk_image_new_from_icon_name("audio-volume-low", GTK_ICON_SIZE_MENU)); + gchar* current_name = g_hash_table_lookup(volume_states, GINT_TO_POINTER(current_state)); + g_debug("At start-up attempting to set the image to %s", current_name); + speaker_image = GTK_IMAGE(gtk_image_new_from_icon_name(current_name, GTK_ICON_SIZE_MENU)); gtk_widget_show(GTK_WIDGET(speaker_image)); return speaker_image; } -/*static void update_state(const gint state)*/ -/*{*/ -/* previous_state = current_state;*/ -/* current_state = 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);*/ -/*}*/ +static void update_state(const gint state) +{ + previous_state = current_state; + current_state = 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); +} -/*static void determine_state(gdouble volume_percent)*/ -/*{*/ -/* */ -/*}*/ +static void determine_state_from_volume(gdouble volume_percent) +{ + gint state = current_state; + if (volume_percent < 30.0 && volume_percent > 0){ + state = STATE_LOW; + } + else if(volume_percent < 70.0 && volume_percent > 30.0){ + state = STATE_MEDIUM; + } + else if(volume_percent > 70.0){ + state = STATE_HIGH; + } + else if(volume_percent == 0.0){ + state = STATE_ZERO; + } + update_state(state); +} -/*static void change_speaker_image(gdouble volume_percent)*/ -/*{ */ -/* if (volume_percent < 30.0 && volume_percent > 0){*/ -/* gtk_image_set_from_icon_name(speaker_image, "audio-volume-low", GTK_ICON_SIZE_MENU);*/ -/* }*/ -/* else if(volume_percent < 70.0 && volume_percent > 30.0){*/ -/* gtk_image_set_from_icon_name(speaker_image, "audio-volume-medium", GTK_ICON_SIZE_MENU);*/ -/* }*/ -/* else if(volume_percent > 70.0){*/ -/* gtk_image_set_from_icon_name(speaker_image, "audio-volume-high", GTK_ICON_SIZE_MENU);*/ -/* }*/ -/* else if(volume_percent <= 0.0){*/ -/* gtk_image_set_from_icon_name(speaker_image, "audio-volume-zero", GTK_ICON_SIZE_MENU);*/ -/* }*/ -/*}*/ /* Indicator based function to get the menu for the whole applet. This starts up asking for the parts of the menu -- cgit v1.2.3 From b117e1edcf717da7d0d0cd890a85cc86366df931 Mon Sep 17 00:00:00 2001 From: Conor Curran Date: Wed, 10 Feb 2010 00:46:07 +0000 Subject: silly/nasty scaling bug caught --- src/pulse-manager.c | 86 +++++++++++++++++++++++++++--------------------- src/sound-service-dbus.c | 31 ++++++++++------- src/sound-service-dbus.h | 3 +- src/sound-service.xml | 6 +++- 4 files changed, 75 insertions(+), 51 deletions(-) (limited to 'src') diff --git a/src/pulse-manager.c b/src/pulse-manager.c index e7570c6..858ae7b 100644 --- a/src/pulse-manager.c +++ b/src/pulse-manager.c @@ -22,33 +22,10 @@ static void pulse_server_info_callback(pa_context *c, const pa_server_info *info static void update_sink_info(pa_context *c, const pa_sink_info *info, int eol, void *userdata); static void destroy_sink_info(void *value); + /* -Refine the resolution of the slider or binary scale it to achieve a more subtle volume control. -Use the base volume stored in the sink struct to calculate actual linear volumes. +Entry point */ -void set_sink_volume(gdouble percent) -{ - g_debug("in the pulse manager:set_sink_volume with percent %f", percent); - if(DEFAULT_SINK_INDEX < 0) - { - g_warning("We have no default sink !!! - returning after not attempting to set any volume of any sink"); - return; - } - gdouble linear_input = (gdouble)(percent); - linear_input /= 100.0; - g_debug("linear double input = %f", linear_input); - pa_volume_t new_volume = pa_sw_volume_from_linear(linear_input); - // Use this to achieve more accurate scaling using the base volume (in the sink struct already!) - //pa_volume_t new_volume = (pa_volume_t) ((GPOINTER_TO_INT(linear_input) * s->base_volume) / 100); - g_debug("about to try to set the sw volume to a linear volume of %f", pa_sw_volume_to_linear(new_volume)); - g_debug("and an actual volume of %f", (gdouble)new_volume); - pa_cvolume dev_vol; - sink_info *s = g_hash_table_lookup(sink_hash, GINT_TO_POINTER(DEFAULT_SINK_INDEX)); - pa_cvolume_set(&dev_vol, s->volume.channels, new_volume); - // TODO - really this needs to be set in the success callback - if call fails then the ui will not be updated indefinitely! - pa_operation_unref(pa_context_set_sink_volume_by_index(pulse_context, DEFAULT_SINK_INDEX, &dev_vol, NULL, NULL)); -} - void establish_pulse_activities(SoundServiceDbus *service) { dbus_service = service; @@ -75,18 +52,6 @@ void close_pulse_activites() g_debug("I just closed communication with Pulse"); } -static void mute_each_sink(gpointer key, gpointer value, gpointer user_data) -{ - sink_info *info = (sink_info*)value; - pa_operation_unref(pa_context_set_sink_mute_by_index(pulse_context, info->index, GPOINTER_TO_INT(user_data), context_success_callback, NULL)); - g_debug("in the pulse manager: mute each sink %i", GPOINTER_TO_INT(user_data)); -} - -void toggle_global_mute(gboolean mute_value) -{ - g_hash_table_foreach(sink_hash, mute_each_sink, GINT_TO_POINTER(mute_value)); - g_debug("in the pulse manager: toggle global mute value %i", mute_value); -} static void destroy_sink_info(void *value) { @@ -107,6 +72,10 @@ static void test_hash(){ } +/* +Controllers & Utilities +*/ + static gboolean sink_available() { if (g_hash_table_size(sink_hash) < 1) @@ -150,6 +119,46 @@ static gdouble get_default_sink_volume() return value; } +static void mute_each_sink(gpointer key, gpointer value, gpointer user_data) +{ + sink_info *info = (sink_info*)value; + pa_operation_unref(pa_context_set_sink_mute_by_index(pulse_context, info->index, GPOINTER_TO_INT(user_data), context_success_callback, NULL)); + g_debug("in the pulse manager: mute each sink %i", GPOINTER_TO_INT(user_data)); +} + +void toggle_global_mute(gboolean mute_value) +{ + g_hash_table_foreach(sink_hash, mute_each_sink, GINT_TO_POINTER(mute_value)); + g_debug("in the pulse manager: toggle global mute value %i", mute_value); +} + + +/* +Refine the resolution of the slider or binary scale it to achieve a more subtle volume control. +Use the base volume stored in the sink struct to calculate actual linear volumes. +*/ +void set_sink_volume(gdouble percent) +{ + g_debug("in the pulse manager:set_sink_volume with percent %f", percent); + if(DEFAULT_SINK_INDEX < 0) + { + g_warning("We have no default sink !!! - returning after not attempting to set any volume of any sink"); + return; + } + gdouble linear_input = (gdouble)(percent); + linear_input /= 100.0; + g_debug("linear double input = %f", linear_input); + pa_volume_t new_volume = pa_sw_volume_from_linear(linear_input); + // Use this to achieve more accurate scaling using the base volume (in the sink struct already!) + //pa_volume_t new_volume = (pa_volume_t) ((GPOINTER_TO_INT(linear_input) * s->base_volume) / 100); + g_debug("about to try to set the sw volume to a linear volume of %f", pa_sw_volume_to_linear(new_volume)); + g_debug("and an actual volume of %f", (gdouble)new_volume); + pa_cvolume dev_vol; + sink_info *s = g_hash_table_lookup(sink_hash, GINT_TO_POINTER(DEFAULT_SINK_INDEX)); + pa_cvolume_set(&dev_vol, s->volume.channels, new_volume); + pa_operation_unref(pa_context_set_sink_volume_by_index(pulse_context, DEFAULT_SINK_INDEX, &dev_vol, NULL, NULL)); +} + /**********************************************************************************************************************/ // Pulse-Audio asychronous call-backs @@ -293,7 +302,8 @@ static void update_sink_info(pa_context *c, const pa_sink_info *info, int eol, v gdouble volume_percent = (vol/s->base_volume) * 100; 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) * 100); + sound_service_dbus_update_sink_volume(dbus_service, pa_sw_volume_to_linear(vol)); + update_mute_ui(s->mute); } else{ diff --git a/src/sound-service-dbus.c b/src/sound-service-dbus.c index ac92a06..00a2692 100644 --- a/src/sound-service-dbus.c +++ b/src/sound-service-dbus.c @@ -49,6 +49,7 @@ struct _SoundServiceDbusPrivate enum { SINK_INPUT_WHILE_MUTED, SINK_VOLUME_UPDATE, + SINK_MUTE_UPDATE, LAST_SIGNAL }; @@ -96,6 +97,14 @@ sound_service_dbus_class_init (SoundServiceDbusClass *klass) g_cclosure_marshal_VOID__DOUBLE, G_TYPE_NONE, 1, G_TYPE_DOUBLE); + signals[SINK_MUTE_UPDATE] = g_signal_new("sink-mute-update", + G_TYPE_FROM_CLASS (klass), + G_SIGNAL_RUN_LAST, + 0, + NULL, NULL, + g_cclosure_marshal_VOID__BOOLEAN, + G_TYPE_NONE, 1, G_TYPE_BOOLEAN); + } static void @@ -177,23 +186,23 @@ void sound_service_dbus_sink_input_while_muted(SoundServiceDbus* obj, gint sink_ void sound_service_dbus_update_sink_volume(SoundServiceDbus* obj, gdouble sink_volume) { SoundServiceDbusPrivate *priv = SOUND_SERVICE_DBUS_GET_PRIVATE (obj); - priv->volume_percent = sink_volume; + priv->volume_percent = sink_volume * 100; - g_debug("Emitting signal: SINK_VOLUME_UPDATE, with sink_volme %f", sink_volume); + g_debug("Emitting signal: SINK_VOLUME_UPDATE, with sink_volme %f", priv->volume_percent); g_signal_emit(obj, signals[SINK_VOLUME_UPDATE], 0, - sink_volume); + priv->volume_percent); } -/*void sound_service_dbus_update_sink_mute(SoundServiceDbus* obj, gboolean sink_mute)*/ -/*{*/ -/* g_debug("Emitting signal: SINK_MUTE_UPDATE, with sink mute %i", sink_mute);*/ -/* g_signal_emit(obj,*/ -/* signals[SINK_MUTE_UPDATE],*/ -/* 0,*/ -/* sink_mute);*/ -/*}*/ +void sound_service_dbus_update_sink_mute(SoundServiceDbus* obj, gboolean sink_mute) +{ + g_debug("Emitting signal: SINK_MUTE_UPDATE, with sink mute %i", sink_mute); + g_signal_emit(obj, + signals[SINK_MUTE_UPDATE], + 0, + sink_mute); +} diff --git a/src/sound-service-dbus.h b/src/sound-service-dbus.h index 08d4bbd..3103d98 100644 --- a/src/sound-service-dbus.h +++ b/src/sound-service-dbus.h @@ -52,12 +52,13 @@ struct _SoundServiceDbusClass { /* Signals -> outward messages to the DBUS and beyond*/ void (* sink_input_while_muted) (SoundServiceDbus *self, gint sink_index, gboolean is_muted, gpointer sound_data); void (* sink_volume_update) (SoundServiceDbus *self, gdouble sink_volume, gpointer sound_data); -}; +}; GType sound_service_dbus_get_type (void) G_GNUC_CONST; // Utility methods to get the messages across into the sound-service-dbus void sound_service_dbus_sink_input_while_muted (SoundServiceDbus* obj, gint sink_index, gboolean value); void sound_service_dbus_update_sink_volume(SoundServiceDbus* obj, gdouble sink_volume); +void sound_service_dbus_update_sink_mute(SoundServiceDbus* obj, gboolean sink_mute); // DBUS METHODS void sound_service_dbus_set_sink_volume(SoundServiceDbus* service, const guint volume_percent, GError** gerror); diff --git a/src/sound-service.xml b/src/sound-service.xml index 4a88aab..65d88ab 100644 --- a/src/sound-service.xml +++ b/src/sound-service.xml @@ -15,13 +15,17 @@ Our respective UI element should listen to this and therefore will be updated wi - + + + + + -- cgit v1.2.3 From 43bcb8cdaeed6260b0b707573e21fec554fd5991 Mon Sep 17 00:00:00 2001 From: Conor Curran Date: Wed, 10 Feb 2010 01:00:27 +0000 Subject: silly/nasty scaling bug caught --- src/common-defs.h | 2 +- src/indicator-sound.c | 15 ++++++++++++--- src/pulse-manager.c | 8 +------- 3 files changed, 14 insertions(+), 11 deletions(-) (limited to 'src') diff --git a/src/common-defs.h b/src/common-defs.h index 4009773..896caba 100644 --- a/src/common-defs.h +++ b/src/common-defs.h @@ -1,7 +1,7 @@ /* constants used for signals on the dbus. This file is shared between client and server implementation */ #define SIGNAL_SINK_INPUT_WHILE_MUTED "SinkInputWhileMuted" #define SIGNAL_SINK_VOLUME_UPDATE "SinkVolumeUpdate" -//#define SIGNAL_SINK_MUTE_UPDATE "SinkMuteUpdate" +#define SIGNAL_SINK_MUTE_UPDATE "SinkMuteUpdate" // DBUS items #define DBUSMENU_SLIDER_MENUITEM_TYPE "x-canonical-ido-slider-item" diff --git a/src/indicator-sound.c b/src/indicator-sound.c index 10ce2ca..7adaaef 100644 --- a/src/indicator-sound.c +++ b/src/indicator-sound.c @@ -93,6 +93,7 @@ static DBusGProxy *sound_dbus_proxy = NULL; static void connection_changed (IndicatorServiceManager * sm, gboolean connected, gpointer userdata); static void catch_signal_sink_input_while_muted(DBusGProxy * proxy, gint sink_index, gboolean value, gpointer userdata); static void catch_signal_sink_volume_update(DBusGProxy * proxy, gdouble volume_percent, gpointer userdata); +static void catch_signal_sink_mute_update(DBusGProxy *proxy, gboolean mute_value, gpointer userdata); /****Volume States 'members' ***/ static const gint STATE_MUTED = 0; @@ -191,6 +192,9 @@ connection_changed (IndicatorServiceManager * sm, gboolean connected, gpointer u dbus_g_proxy_connect_signal(sound_dbus_proxy, SIGNAL_SINK_INPUT_WHILE_MUTED, G_CALLBACK(catch_signal_sink_input_while_muted), NULL, NULL); dbus_g_proxy_add_signal(sound_dbus_proxy, SIGNAL_SINK_VOLUME_UPDATE, G_TYPE_DOUBLE, G_TYPE_INVALID); dbus_g_proxy_connect_signal(sound_dbus_proxy, SIGNAL_SINK_VOLUME_UPDATE, G_CALLBACK(catch_signal_sink_volume_update), NULL, NULL); + dbus_g_proxy_add_signal(sound_dbus_proxy, SIGNAL_SINK_MUTE_UPDATE, G_TYPE_BOOLEAN, G_TYPE_INVALID); + dbus_g_proxy_connect_signal(sound_dbus_proxy, SIGNAL_SINK_MUTE_UPDATE, G_CALLBACK(catch_signal_sink_mute_update), NULL, NULL); + gdouble *volume_percent_input; volume_percent_input = g_new0(gdouble, 1); org_ayatana_indicator_sound_get_sink_volume(sound_dbus_proxy, volume_percent_input, &error); @@ -218,15 +222,20 @@ static void catch_signal_sink_input_while_muted(DBusGProxy * proxy, gint sink_in g_debug("signal caught - sink input while muted with index %i and value %i", sink_index, value); } -static void catch_signal_sink_volume_update(DBusGProxy * proxy, gdouble volume_percent, gpointer userdata) +static void catch_signal_sink_volume_update(DBusGProxy *proxy, gdouble volume_percent, gpointer userdata) { g_debug("signal caught - update sink volume with value : %f", volume_percent); - GtkWidget* slider = ido_scale_menu_item_get_scale((IdoScaleMenuItem*)volume_slider); - GtkRange* range = (GtkRange*)slider; + GtkWidget *slider = ido_scale_menu_item_get_scale((IdoScaleMenuItem*)volume_slider); + GtkRange *range = (GtkRange*)slider; gtk_range_set_value(range, volume_percent); determine_state_from_volume(volume_percent); } +static void catch_signal_sink_mute_update(DBusGProxy *proxy, gboolean mute_value, gpointer userdata) +{ + g_debug("signal caught - sink mute update with mute_value %i", mute_value); +} + static void indicator_sound_dispose (GObject *object) diff --git a/src/pulse-manager.c b/src/pulse-manager.c index 858ae7b..11fd34f 100644 --- a/src/pulse-manager.c +++ b/src/pulse-manager.c @@ -276,11 +276,8 @@ static void update_sink_info(pa_context *c, const pa_sink_info *info, int eol, v GList *keys = g_hash_table_get_keys(sink_hash); gint position = g_list_index(keys, GINT_TO_POINTER(info->index)); -/* gboolean update_ui_vol = FALSE;*/ if(position >= 0) // => index is within the keys of the hash. { - // TODO : update sinks hash with new details and if default send over dbus the update. in reverse order. - //gint sink_index = GPOINTER_TO_INT(g_list_nth_data(keys, position)); 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); s->name = g_strdup(info->name); @@ -288,9 +285,6 @@ static void update_sink_info(pa_context *c, const pa_sink_info *info, int eol, v s->icon_name = g_strdup(pa_proplist_gets(info->proplist, PA_PROP_DEVICE_ICON_NAME)); s->active_port = (info->active_port != NULL); s->mute = !!info->mute; -/* int equal = pa_cvolume_equal(&s->volume, &info->volume);*/ -/* update_ui_vol = (equal != 0); */ -/* g_debug("Are the volumes the same %i", equal); */ s->volume = info->volume; s->base_volume = info->base_volume; s->channel_map = info->channel_map; @@ -303,7 +297,7 @@ 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); update_mute_ui(s->mute); } else{ -- cgit v1.2.3 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 From b51a53a2f2c6cbe23d4f6269360699e225bd30aa Mon Sep 17 00:00:00 2001 From: Conor Curran Date: Wed, 10 Feb 2010 11:33:36 +0000 Subject: mute init/revert now working properly plus dbus signal tidy up on the blocking message --- src/indicator-sound.c | 100 ++++++++++++++++++++++++++++++----------------- src/pulse-manager.c | 40 ++++++++++--------- src/sound-service-dbus.c | 27 +++++++++---- src/sound-service-dbus.h | 5 ++- src/sound-service.xml | 6 ++- 5 files changed, 113 insertions(+), 65 deletions(-) (limited to 'src') diff --git a/src/indicator-sound.c b/src/indicator-sound.c index 352e0ed..e2d3116 100644 --- a/src/indicator-sound.c +++ b/src/indicator-sound.c @@ -83,16 +83,17 @@ static gboolean new_slider_item (DbusmenuMenuitem * newitem, DbusmenuMenuitem * static void slider_prop_change_cb (DbusmenuMenuitem * mi, gchar * prop, GValue * value, GtkWidget *widget); static gboolean slider_value_changed_event_cb(GtkRange *range, GtkScrollType scroll_type, gdouble input_value, gpointer user_data); -/*static void change_speaker_image(gdouble volume_percent);*/ 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(); +static void fetch_volume_percent_from_dbus(); +static void fetch_mute_value_from_dbus(); +/*static void revert_state();*/ // DBUS communication static DBusGProxy *sound_dbus_proxy = NULL; static void connection_changed (IndicatorServiceManager * sm, gboolean connected, gpointer userdata); -static void catch_signal_sink_input_while_muted(DBusGProxy * proxy, gint sink_index, gboolean value, gpointer userdata); +static void catch_signal_sink_input_while_muted(DBusGProxy * proxy, gboolean value, gpointer userdata); static void catch_signal_sink_volume_update(DBusGProxy * proxy, gdouble volume_percent, gpointer userdata); static void catch_signal_sink_mute_update(DBusGProxy *proxy, gboolean mute_value, gpointer userdata); @@ -109,6 +110,7 @@ static GtkImage *speaker_image = NULL; static gint current_state = 0; static gint previous_state = 0; static gdouble initial_volume_percent = 0; +static gboolean initial_mute = FALSE; static void indicator_sound_class_init (IndicatorSoundClass *klass) @@ -189,26 +191,16 @@ connection_changed (IndicatorServiceManager * sm, gboolean connected, gpointer u g_error_free(error); } g_debug("about to connect to the signals"); - dbus_g_proxy_add_signal(sound_dbus_proxy, SIGNAL_SINK_INPUT_WHILE_MUTED, G_TYPE_INT, G_TYPE_BOOLEAN, G_TYPE_INVALID); + dbus_g_proxy_add_signal(sound_dbus_proxy, SIGNAL_SINK_INPUT_WHILE_MUTED, G_TYPE_BOOLEAN, G_TYPE_INVALID); dbus_g_proxy_connect_signal(sound_dbus_proxy, SIGNAL_SINK_INPUT_WHILE_MUTED, G_CALLBACK(catch_signal_sink_input_while_muted), NULL, NULL); dbus_g_proxy_add_signal(sound_dbus_proxy, SIGNAL_SINK_VOLUME_UPDATE, G_TYPE_DOUBLE, G_TYPE_INVALID); dbus_g_proxy_connect_signal(sound_dbus_proxy, SIGNAL_SINK_VOLUME_UPDATE, G_CALLBACK(catch_signal_sink_volume_update), NULL, NULL); dbus_g_proxy_add_signal(sound_dbus_proxy, SIGNAL_SINK_MUTE_UPDATE, G_TYPE_BOOLEAN, G_TYPE_INVALID); dbus_g_proxy_connect_signal(sound_dbus_proxy, SIGNAL_SINK_MUTE_UPDATE, G_CALLBACK(catch_signal_sink_mute_update), NULL, NULL); - gdouble *volume_percent_input; - volume_percent_input = g_new0(gdouble, 1); - org_ayatana_indicator_sound_get_sink_volume(sound_dbus_proxy, volume_percent_input, &error); - if (error != NULL) { - g_warning("Unable to fetch volume at indicator start up: %s", error->message); - g_error_free(error); - g_free(volume_percent_input); - return; - } - initial_volume_percent = *volume_percent_input; - determine_state_from_volume(initial_volume_percent); - g_free(volume_percent_input); - g_debug("at the indicator start up and the volume percent returned from dbus method is %f", initial_volume_percent); + // Ensure we are in a coherent state with the service at start up. + fetch_volume_percent_from_dbus(); + fetch_mute_value_from_dbus(); } } else { @@ -218,9 +210,46 @@ connection_changed (IndicatorServiceManager * sm, gboolean connected, gpointer u return; } -static void catch_signal_sink_input_while_muted(DBusGProxy * proxy, gint sink_index, gboolean value, gpointer userdata) +static void fetch_volume_percent_from_dbus() +{ + GError * error = NULL; + gdouble *volume_percent_input; + volume_percent_input = g_new0(gdouble, 1); + org_ayatana_indicator_sound_get_sink_volume(sound_dbus_proxy, volume_percent_input, &error); + if (error != NULL) { + g_warning("Unable to fetch VOLUME at indicator start up: %s", error->message); + g_error_free(error); + g_free(volume_percent_input); + return; + } + initial_volume_percent = *volume_percent_input; + determine_state_from_volume(initial_volume_percent); + g_free(volume_percent_input); + g_debug("at the indicator start up and the volume percent returned from dbus method is %f", initial_volume_percent); +} + +static void fetch_mute_value_from_dbus() +{ + GError * error = NULL; + gboolean *mute_input; + mute_input = g_new0(gboolean, 1); + org_ayatana_indicator_sound_get_sink_mute(sound_dbus_proxy, mute_input, &error); + if (error != NULL) { + g_warning("Unable to fetch MUTE at indicator start up: %s", error->message); + g_error_free(error); + g_free(mute_input); + return; + } + initial_mute = *mute_input; + if (initial_mute == TRUE) + update_state(STATE_MUTED); + g_free(mute_input); + g_debug("at the indicator start up and the MUTE returned from dbus method is %i", initial_mute); +} + +static void catch_signal_sink_input_while_muted(DBusGProxy * proxy, gboolean block_value, gpointer userdata) { - g_debug("signal caught - sink input while muted with index %i and value %i", sink_index, value); + g_debug("signal caught - sink input while muted with value %i", block_value); } static void catch_signal_sink_volume_update(DBusGProxy *proxy, gdouble volume_percent, gpointer userdata) @@ -235,16 +264,12 @@ 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 ! + //UNMUTE's force a volume update therefore icon is updated appropriately => no need for unmute handling here. if(mute_value == TRUE) { + g_debug("signal caught - sink mute update - MUTE"); 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); } @@ -287,24 +312,31 @@ get_icon (IndicatorObject * io) static void update_state(const gint state) { + g_debug("update state beginning - previous_state = %i", previous_state); + previous_state = current_state; + + g_debug("update state 3rd line - previous_state = %i", previous_state); + current_state = 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); } -static void revert_state() -{ +/*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); -} +/* g_debug("revert state beginning - previous_state = %i", previous_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 = 0; + g_debug("determine_state_from_volume - previous_state = %i", previous_state); + gint state = previous_state; if (volume_percent < 30.0 && volume_percent > 0){ state = STATE_LOW; } @@ -375,8 +407,6 @@ static gboolean slider_value_changed_event_cb(GtkRange *range, GtkScrollType scr g_value_init(&value, G_TYPE_DOUBLE); g_value_set_double(&value, clamped_input); dbusmenu_menuitem_handle_event (item, "slider_change", &value, 0); -/* change_speaker_image(slider_value);*/ -/* }*/ return FALSE; } diff --git a/src/pulse-manager.c b/src/pulse-manager.c index ae7961a..43a6f9f 100644 --- a/src/pulse-manager.c +++ b/src/pulse-manager.c @@ -62,15 +62,15 @@ static void destroy_sink_info(void *value) g_free(sink); } -static void test_hash(){ - guint size = 0; - size = g_hash_table_size(sink_hash); - g_debug("Size of hash = %i", size); - sink_info *s = g_hash_table_lookup(sink_hash, GINT_TO_POINTER(DEFAULT_SINK_INDEX)); - g_debug("The name of our sink is %s", s->name); - g_debug("and the max volume is %f", (gdouble)s->base_volume); +/*static void test_hash(){*/ +/* guint size = 0;*/ +/* size = g_hash_table_size(sink_hash);*/ +/* g_debug("Size of hash = %i", size);*/ +/* sink_info *s = g_hash_table_lookup(sink_hash, GINT_TO_POINTER(DEFAULT_SINK_INDEX)); */ +/* g_debug("The name of our sink is %s", s->name); */ +/* g_debug("and the max volume is %f", (gdouble)s->base_volume); */ -} +/*}*/ /* Controllers & Utilities @@ -103,9 +103,13 @@ static void check_sink_input_while_muted_event(gint sink_index) if (default_sink_is_muted(sink_index) == TRUE) { g_debug("SINKINPUTWHILEMUTED SIGNAL EVENT TO BE SENT FROM PA MANAGER"); - sound_service_dbus_sink_input_while_muted (dbus_service, sink_index, TRUE); + sound_service_dbus_sink_input_while_muted (dbus_service, TRUE); + } + else + { + // TODO is this overkill - signal will be sent alot + sound_service_dbus_sink_input_while_muted(dbus_service, FALSE); } - return; } static gdouble get_default_sink_volume() @@ -189,9 +193,8 @@ static void context_success_callback(pa_context *c, int success, void *userdata) /** On Service startup this callback will be called multiple times resulting our sinks_hash container to be filled with the available sinks. -key -> index -value -> sink_info -For now this callback it assumes it only used at startup. It may be necessary to use if sinks become available after startup +For now this callback it assumes it only used at startup. It may be necessary to use if sinks become available after startup. +Major candidate for refactoring. **/ static void pulse_sink_info_callback(pa_context *c, const pa_sink_info *sink, int eol, void *userdata) { @@ -201,9 +204,12 @@ static void pulse_sink_info_callback(pa_context *c, const pa_sink_info *sink, in { // Hopefully the PA server has set the default device if not default to 0 DEFAULT_SINK_INDEX = (DEFAULT_SINK_INDEX < 0) ? 0 : DEFAULT_SINK_INDEX; - test_hash(); + // TODO optimize + // Cache method returns! (unneccessary multiple utility calls) + // test_hash(); update_pa_state(TRUE, device_available, default_sink_is_muted(), get_default_sink_volume()); sound_service_dbus_update_sink_volume(dbus_service, get_default_sink_volume()); + sound_service_dbus_update_sink_mute(dbus_service, default_sink_is_muted()); g_debug("default sink index : %d", DEFAULT_SINK_INDEX); } else{ @@ -304,14 +310,10 @@ static void update_sink_info(pa_context *c, const pa_sink_info *info, int eol, v update_mute_ui(s->mute); } - else{ - // Reset the ui flag - // TODO: there must be a nicer way to do this - I suspect this pattern could introduce race conditions !!! - g_debug("SKIPPED UPDATING UI BECAUSE THE UI_NEEDS_UPDATE WAS FALSE!"); - } } else { + // TODO ADD new sink - part of big refactor g_debug("attempting to add new sink with name %s", info->name); //sink_info *s; //s = g_new0(sink_info, 1); diff --git a/src/sound-service-dbus.c b/src/sound-service-dbus.c index 00a2692..4a4a3c7 100644 --- a/src/sound-service-dbus.c +++ b/src/sound-service-dbus.c @@ -32,6 +32,7 @@ // DBUS methods - // TODO - other should be static and moved from the header to here static gboolean sound_service_dbus_get_sink_volume(SoundServiceDbus* service, gdouble* volume_percent_input, GError** gerror); +static gboolean sound_service_dbus_get_sink_mute(SoundServiceDbus* service, gboolean* mute_input, GError** gerror); #include "sound-service-server.h" @@ -42,6 +43,7 @@ struct _SoundServiceDbusPrivate DBusGConnection *system_bus; DBusGConnection *connection; gdouble volume_percent; + gboolean mute; }; @@ -86,8 +88,8 @@ sound_service_dbus_class_init (SoundServiceDbusClass *klass) G_SIGNAL_RUN_LAST, 0, NULL, NULL, - _sound_service_marshal_VOID__INT_BOOLEAN, - G_TYPE_NONE, 2, G_TYPE_INT, G_TYPE_BOOLEAN); + g_cclosure_marshal_VOID__BOOLEAN, + G_TYPE_NONE, 1, G_TYPE_BOOLEAN); signals[SINK_VOLUME_UPDATE] = g_signal_new("sink-volume-update", G_TYPE_FROM_CLASS (klass), @@ -167,20 +169,25 @@ static gboolean sound_service_dbus_get_sink_volume (SoundServiceDbus *self, gdou return TRUE; } +static gboolean sound_service_dbus_get_sink_mute (SoundServiceDbus *self, gboolean *mute_input, GError** gerror) +{ + SoundServiceDbusPrivate *priv = SOUND_SERVICE_DBUS_GET_PRIVATE (self); + g_debug("Get sink mute - sound service dbus!, about to send over mute_value of %i", priv->mute); + *mute_input = priv->mute; + return TRUE; +} /** SIGNALS Utility methods to emit signals from the service into the ether. **/ -void sound_service_dbus_sink_input_while_muted(SoundServiceDbus* obj, gint sink_index, gboolean value) +void sound_service_dbus_sink_input_while_muted(SoundServiceDbus* obj, gboolean block_value) { -/* g_assert((num < LAST_SIGNAL) && (num >= 0));*/ - g_debug("Emitting signal: SINK_INPUT_WHILE_MUTED, with sink_index %i and value %i", sink_index, value); + g_debug("Emitting signal: SINK_INPUT_WHILE_MUTED, with block_value: %i", block_value); g_signal_emit(obj, signals[SINK_INPUT_WHILE_MUTED], 0, - sink_index, - value); + block_value); } void sound_service_dbus_update_sink_volume(SoundServiceDbus* obj, gdouble sink_volume) @@ -198,10 +205,14 @@ void sound_service_dbus_update_sink_volume(SoundServiceDbus* obj, gdouble sink_v void sound_service_dbus_update_sink_mute(SoundServiceDbus* obj, gboolean sink_mute) { g_debug("Emitting signal: SINK_MUTE_UPDATE, with sink mute %i", sink_mute); + + SoundServiceDbusPrivate *priv = SOUND_SERVICE_DBUS_GET_PRIVATE (obj); + priv->mute = sink_mute; + g_signal_emit(obj, signals[SINK_MUTE_UPDATE], 0, - sink_mute); + priv->mute); } diff --git a/src/sound-service-dbus.h b/src/sound-service-dbus.h index 3103d98..223f766 100644 --- a/src/sound-service-dbus.h +++ b/src/sound-service-dbus.h @@ -50,13 +50,14 @@ struct _SoundServiceDbus { struct _SoundServiceDbusClass { GObjectClass parent_class; /* Signals -> outward messages to the DBUS and beyond*/ - void (* sink_input_while_muted) (SoundServiceDbus *self, gint sink_index, gboolean is_muted, gpointer sound_data); + // TODO - ARE THESE NECESSARY ? + void (* sink_input_while_muted) (SoundServiceDbus *self, gboolean block_value, gpointer sound_data); void (* sink_volume_update) (SoundServiceDbus *self, gdouble sink_volume, gpointer sound_data); }; GType sound_service_dbus_get_type (void) G_GNUC_CONST; // Utility methods to get the messages across into the sound-service-dbus -void sound_service_dbus_sink_input_while_muted (SoundServiceDbus* obj, gint sink_index, gboolean value); +void sound_service_dbus_sink_input_while_muted (SoundServiceDbus* obj, gboolean block_value); void sound_service_dbus_update_sink_volume(SoundServiceDbus* obj, gdouble sink_volume); void sound_service_dbus_update_sink_mute(SoundServiceDbus* obj, gboolean sink_mute); diff --git a/src/sound-service.xml b/src/sound-service.xml index 65d88ab..580f0e1 100644 --- a/src/sound-service.xml +++ b/src/sound-service.xml @@ -10,11 +10,15 @@ + + + + + - -- cgit v1.2.3 From 4b22b241e13fbc1ca6e6d1bec21beda2941c3ced Mon Sep 17 00:00:00 2001 From: Conor Curran Date: Wed, 10 Feb 2010 11:42:10 +0000 Subject: mute init/revert now working properly plus dbus signal tidy up on the blocking message --- src/indicator-sound.c | 1 + 1 file changed, 1 insertion(+) (limited to 'src') diff --git a/src/indicator-sound.c b/src/indicator-sound.c index e2d3116..eed1e6f 100644 --- a/src/indicator-sound.c +++ b/src/indicator-sound.c @@ -199,6 +199,7 @@ connection_changed (IndicatorServiceManager * sm, gboolean connected, gpointer u dbus_g_proxy_connect_signal(sound_dbus_proxy, SIGNAL_SINK_MUTE_UPDATE, G_CALLBACK(catch_signal_sink_mute_update), NULL, NULL); // Ensure we are in a coherent state with the service at start up. + // Preserve ordering! fetch_volume_percent_from_dbus(); fetch_mute_value_from_dbus(); } -- cgit v1.2.3 From ef8f7d725ef912219e1829d4c22db9abbc00df1a Mon Sep 17 00:00:00 2001 From: Conor Curran Date: Wed, 10 Feb 2010 12:45:23 +0000 Subject: tidy up plus unwanted feedback investigation --- src/indicator-sound.c | 6 ++++++ src/pulse-manager.c | 7 +++---- src/sound-service-dbus.c | 3 ++- src/sound-service-dbus.h | 9 +++------ 4 files changed, 14 insertions(+), 11 deletions(-) (limited to 'src') diff --git a/src/indicator-sound.c b/src/indicator-sound.c index eed1e6f..49fa4ed 100644 --- a/src/indicator-sound.c +++ b/src/indicator-sound.c @@ -257,6 +257,12 @@ static void catch_signal_sink_volume_update(DBusGProxy *proxy, gdouble volume_pe { g_debug("signal caught - update sink volume with value : %f", volume_percent); GtkWidget *slider = ido_scale_menu_item_get_scale((IdoScaleMenuItem*)volume_slider); + gboolean in_use = gtk_widget_has_grab(volume_slider); + if(in_use == TRUE) + { + g_debug("looks like the slider is the UI element in use therefore ignore this volume message => prevent circular semi feedback."); + return; + } GtkRange *range = (GtkRange*)slider; gtk_range_set_value(range, volume_percent); determine_state_from_volume(volume_percent); diff --git a/src/pulse-manager.c b/src/pulse-manager.c index 43a6f9f..8bf6cac 100644 --- a/src/pulse-manager.c +++ b/src/pulse-manager.c @@ -93,21 +93,20 @@ static gboolean default_sink_is_muted() return FALSE; if (g_hash_table_size(sink_hash) < 1) return FALSE; - // TODO ensure hash has a key with this value! sink_info *s = g_hash_table_lookup(sink_hash, GINT_TO_POINTER(DEFAULT_SINK_INDEX)); return s->mute; } static void check_sink_input_while_muted_event(gint sink_index) { + g_debug("SINKINPUTWHILEMUTED SIGNAL EVENT TO BE SENT FROM PA MANAGER - check trace for value"); + if (default_sink_is_muted(sink_index) == TRUE) { - g_debug("SINKINPUTWHILEMUTED SIGNAL EVENT TO BE SENT FROM PA MANAGER"); sound_service_dbus_sink_input_while_muted (dbus_service, TRUE); } else { - // TODO is this overkill - signal will be sent alot sound_service_dbus_sink_input_while_muted(dbus_service, FALSE); } } @@ -160,6 +159,7 @@ void set_sink_volume(gdouble percent) pa_cvolume dev_vol; sink_info *s = g_hash_table_lookup(sink_hash, GINT_TO_POINTER(DEFAULT_SINK_INDEX)); pa_cvolume_set(&dev_vol, s->volume.channels, new_volume); + pa_operation_unref(pa_context_set_sink_volume_by_index(pulse_context, DEFAULT_SINK_INDEX, &dev_vol, NULL, NULL)); } @@ -361,7 +361,6 @@ static void subscribed_events_callback(pa_context *c, enum pa_subscription_event } else { pa_operation_unref(pa_context_get_sink_info_by_index(c, index, update_sink_info, userdata)); } - //g_debug("Event sink for %i", index); break; case PA_SUBSCRIPTION_EVENT_SINK_INPUT: // This will be triggered when the sink receives input from a new stream diff --git a/src/sound-service-dbus.c b/src/sound-service-dbus.c index 4a4a3c7..a4c6eda 100644 --- a/src/sound-service-dbus.c +++ b/src/sound-service-dbus.c @@ -33,6 +33,7 @@ // TODO - other should be static and moved from the header to here static gboolean sound_service_dbus_get_sink_volume(SoundServiceDbus* service, gdouble* volume_percent_input, GError** gerror); static gboolean sound_service_dbus_get_sink_mute(SoundServiceDbus* service, gboolean* mute_input, GError** gerror); +static void sound_service_dbus_set_sink_volume(SoundServiceDbus* service, const guint volume_percent, GError** gerror); #include "sound-service-server.h" @@ -155,7 +156,7 @@ sound_service_dbus_finalize (GObject *object) /** DBUS Method Callbacks **/ -void sound_service_dbus_set_sink_volume(SoundServiceDbus* service, const guint volume_percent, GError** gerror) +static void sound_service_dbus_set_sink_volume(SoundServiceDbus* service, const guint volume_percent, GError** gerror) { g_debug("in the set sink volume method in the sound service dbus!, with volume_percent of %i", volume_percent); set_sink_volume(volume_percent); diff --git a/src/sound-service-dbus.h b/src/sound-service-dbus.h index 223f766..ef0d7dd 100644 --- a/src/sound-service-dbus.h +++ b/src/sound-service-dbus.h @@ -51,19 +51,16 @@ struct _SoundServiceDbusClass { GObjectClass parent_class; /* Signals -> outward messages to the DBUS and beyond*/ // TODO - ARE THESE NECESSARY ? - void (* sink_input_while_muted) (SoundServiceDbus *self, gboolean block_value, gpointer sound_data); - void (* sink_volume_update) (SoundServiceDbus *self, gdouble sink_volume, gpointer sound_data); + //void (* sink_input_while_muted) (SoundServiceDbus *self, gboolean block_value, gpointer sound_data); + //void (* sink_volume_update) (SoundServiceDbus *self, gdouble sink_volume, gpointer sound_data); }; GType sound_service_dbus_get_type (void) G_GNUC_CONST; -// Utility methods to get the messages across into the sound-service-dbus +// Utility methods to get the SIGNAL messages across into the sound-service-dbus void sound_service_dbus_sink_input_while_muted (SoundServiceDbus* obj, gboolean block_value); void sound_service_dbus_update_sink_volume(SoundServiceDbus* obj, gdouble sink_volume); void sound_service_dbus_update_sink_mute(SoundServiceDbus* obj, gboolean sink_mute); -// DBUS METHODS -void sound_service_dbus_set_sink_volume(SoundServiceDbus* service, const guint volume_percent, GError** gerror); - G_END_DECLS #endif -- cgit v1.2.3