From c879c510dbef95deea70687d59c2013005bf946d Mon Sep 17 00:00:00 2001 From: Conor Curran Date: Wed, 24 Feb 2010 14:19:01 +0000 Subject: unit tests for the indicator side added --- src/indicator-sound.c | 282 ++++++++++++++++++++++++++------------------------ 1 file changed, 144 insertions(+), 138 deletions(-) (limited to 'src/indicator-sound.c') diff --git a/src/indicator-sound.c b/src/indicator-sound.c index acacddc..ffe7acb 100644 --- a/src/indicator-sound.c +++ b/src/indicator-sound.c @@ -100,13 +100,15 @@ static void fetch_mute_value_from_dbus(); static void prepare_state_machine(); static void determine_state_from_volume(gdouble volume_percent); static void update_state(const gint state); + 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 const gint STATE_SINKS_NONE = 6; + static GHashTable *volume_states = NULL; static GtkImage *speaker_image = NULL; static GtkWidget* primary_image = NULL; @@ -115,6 +117,7 @@ static gint previous_state = 0; static gdouble initial_volume_percent = 0; static gboolean initial_mute = FALSE; +// Construction static void indicator_sound_class_init (IndicatorSoundClass *klass) { @@ -147,21 +150,91 @@ static void indicator_sound_init (IndicatorSound *self) return; } +static void +indicator_sound_dispose (GObject *object) +{ + IndicatorSound * self = INDICATOR_SOUND(object); -/* -Prepare states Array. -*/ -static void prepare_state_machine() + if (self->service != NULL) { + 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; +} + +static void +indicator_sound_finalize (GObject *object) { - // 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-panel")); - g_hash_table_insert(volume_states, GINT_TO_POINTER(STATE_ZERO), g_strdup("audio-volume-zero-panel")); - g_hash_table_insert(volume_states, GINT_TO_POINTER(STATE_LOW), g_strdup("audio-volume-low-panel")); - g_hash_table_insert(volume_states, GINT_TO_POINTER(STATE_MEDIUM), g_strdup("audio-volume-medium-panel")); - g_hash_table_insert(volume_states, GINT_TO_POINTER(STATE_HIGH), g_strdup("audio-volume-high-panel")); - g_hash_table_insert(volume_states, GINT_TO_POINTER(STATE_MUTED_WHILE_INPUT), g_strdup("audio-volume-muted-blocking-panel")); - g_hash_table_insert(volume_states, GINT_TO_POINTER(STATE_SINKS_NONE), g_strdup("audio-output-none-panel")); + G_OBJECT_CLASS (indicator_sound_parent_class)->finalize (object); + return; +} + +static GtkLabel * +get_label (IndicatorObject * io) +{ + return NULL; +} + +static GtkImage * +get_icon (IndicatorObject * io) +{ + 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; +} + +/* Indicator based function to get the menu for the whole + applet. This starts up asking for the parts of the menu + from the various services. */ +static GtkMenu * +get_menu (IndicatorObject * io) +{ + DbusmenuGtkMenu *menu = dbusmenu_gtkmenu_new(INDICATOR_SOUND_DBUS_NAME, INDICATOR_SOUND_DBUS_OBJECT); + DbusmenuGtkClient *client = dbusmenu_gtkmenu_get_client(menu); + dbusmenu_client_add_type_handler(DBUSMENU_CLIENT(client), DBUSMENU_SLIDER_MENUITEM_TYPE, new_slider_item); + + // register Key-press listening on the menu widget as the slider does not allow this. + g_signal_connect(menu, "key-press-event", G_CALLBACK(key_press_cb), NULL); + + return GTK_MENU(menu); +} + +/** +new_slider_item: +Create a new dBusMenu Slider item. +**/ +static gboolean new_slider_item(DbusmenuMenuitem * newitem, DbusmenuMenuitem * parent, DbusmenuClient * client) +{ + g_return_val_if_fail(DBUSMENU_IS_MENUITEM(newitem), FALSE); + g_return_val_if_fail(DBUSMENU_IS_GTKCLIENT(client), FALSE); + + volume_slider = ido_scale_menu_item_new_with_range ("Volume", initial_volume_percent, 0, 100, 0.5); + g_object_set(volume_slider, "reverse-scroll-events", TRUE, NULL); + + 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); + + // register slider changes listening on the range + GtkWidget* slider = ido_scale_menu_item_get_scale((IdoScaleMenuItem*)volume_slider); + g_signal_connect(slider, "value-changed", G_CALLBACK(value_changed_event_cb), newitem); + // alternative callback mechanism which i could use again at some point. +/* g_signal_connect(slider, "change-value", G_CALLBACK(user_change_value_event_cb), newitem); */ + + // Set images on the ido + primary_image = ido_scale_menu_item_get_primary_image((IdoScaleMenuItem*)volume_slider); + gtk_image_set_from_icon_name(GTK_IMAGE(primary_image), g_hash_table_lookup(volume_states, GINT_TO_POINTER(STATE_ZERO)), GTK_ICON_SIZE_MENU); + GtkWidget* secondary_image = ido_scale_menu_item_get_secondary_image((IdoScaleMenuItem*)volume_slider); + gtk_image_set_from_icon_name(GTK_IMAGE(secondary_image), g_hash_table_lookup(volume_states, GINT_TO_POINTER(STATE_HIGH)), GTK_ICON_SIZE_MENU); + + gtk_widget_show_all(volume_slider); + + return TRUE; } static void @@ -205,6 +278,63 @@ connection_changed (IndicatorServiceManager * sm, gboolean connected, gpointer u return; } + + + +/* +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-panel")); + g_hash_table_insert(volume_states, GINT_TO_POINTER(STATE_ZERO), g_strdup("audio-volume-low-zero-panel")); + g_hash_table_insert(volume_states, GINT_TO_POINTER(STATE_LOW), g_strdup("audio-volume-low-panel")); + g_hash_table_insert(volume_states, GINT_TO_POINTER(STATE_MEDIUM), g_strdup("audio-volume-medium-panel")); + g_hash_table_insert(volume_states, GINT_TO_POINTER(STATE_HIGH), g_strdup("audio-volume-high-panel")); + g_hash_table_insert(volume_states, GINT_TO_POINTER(STATE_MUTED_WHILE_INPUT), g_strdup("audio-volume-muted-blocking-panel")); + g_hash_table_insert(volume_states, GINT_TO_POINTER(STATE_SINKS_NONE), g_strdup("audio-output-none-panel")); +} + + + +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 determine_state_from_volume(gdouble volume_percent) +{ +/* 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; + } + 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 fetch_volume_percent_from_dbus() { GError * error = NULL; @@ -270,130 +400,6 @@ static void catch_signal_sink_mute_update(DBusGProxy *proxy, gboolean mute_value g_debug("signal caught - sink mute update with mute value: %i", mute_value); gtk_widget_set_sensitive(volume_slider, !mute_value); } - - -static void -indicator_sound_dispose (GObject *object) -{ - IndicatorSound * self = INDICATOR_SOUND(object); - - if (self->service != NULL) { - 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; -} - -static void -indicator_sound_finalize (GObject *object) -{ - G_OBJECT_CLASS (indicator_sound_parent_class)->finalize (object); - return; -} - -static GtkLabel * -get_label (IndicatorObject * io) -{ - return NULL; -} - -static GtkImage * -get_icon (IndicatorObject * io) -{ - 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) -{ -/* 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 determine_state_from_volume(gdouble volume_percent) -{ -/* 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; - } - 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); -} - - -/* Indicator based function to get the menu for the whole - applet. This starts up asking for the parts of the menu - from the various services. */ -static GtkMenu * -get_menu (IndicatorObject * io) -{ - DbusmenuGtkMenu *menu = dbusmenu_gtkmenu_new(INDICATOR_SOUND_DBUS_NAME, INDICATOR_SOUND_DBUS_OBJECT); - DbusmenuGtkClient *client = dbusmenu_gtkmenu_get_client(menu); - dbusmenu_client_add_type_handler(DBUSMENU_CLIENT(client), DBUSMENU_SLIDER_MENUITEM_TYPE, new_slider_item); - - // register Key-press listening on the menu widget as the slider does not allow this. - g_signal_connect(menu, "key-press-event", G_CALLBACK(key_press_cb), NULL); - - return GTK_MENU(menu); -} - -/** -new_slider_item: -Create a new dBusMenu Slider item, register the -**/ -static gboolean new_slider_item(DbusmenuMenuitem * newitem, DbusmenuMenuitem * parent, DbusmenuClient * client) -{ - g_return_val_if_fail(DBUSMENU_IS_MENUITEM(newitem), FALSE); - g_return_val_if_fail(DBUSMENU_IS_GTKCLIENT(client), FALSE); - - volume_slider = ido_scale_menu_item_new_with_range ("Volume", initial_volume_percent, 0, 100, 0.5); - g_object_set(volume_slider, "reverse-scroll-events", TRUE, NULL); - - 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); - - // register slider changes listening on the range - GtkWidget* slider = ido_scale_menu_item_get_scale((IdoScaleMenuItem*)volume_slider); - g_signal_connect(slider, "value-changed", G_CALLBACK(value_changed_event_cb), newitem); - // alternative callback mechanism which i could use again at some point. -/* g_signal_connect(slider, "change-value", G_CALLBACK(user_change_value_event_cb), newitem); */ - - // Set images on the ido - primary_image = ido_scale_menu_item_get_primary_image((IdoScaleMenuItem*)volume_slider); - gtk_image_set_from_icon_name(GTK_IMAGE(primary_image), g_hash_table_lookup(volume_states, GINT_TO_POINTER(STATE_ZERO)), GTK_ICON_SIZE_MENU); - GtkWidget* secondary_image = ido_scale_menu_item_get_secondary_image((IdoScaleMenuItem*)volume_slider); - gtk_image_set_from_icon_name(GTK_IMAGE(secondary_image), g_hash_table_lookup(volume_states, GINT_TO_POINTER(STATE_HIGH)), GTK_ICON_SIZE_MENU); - - gtk_widget_show_all(volume_slider); - - return TRUE; -} - /** slider_prop_change_cb: Whenever we have a property change on a DbusmenuMenuitem this will be called. -- cgit v1.2.3 From be2b2e73044d5ba0c656431f0d19723af6b55946 Mon Sep 17 00:00:00 2001 From: Conor Curran Date: Tue, 2 Mar 2010 10:20:25 +0000 Subject: refactored the indicator tests so as no c file needs to be included --- src/indicator-sound.c | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'src/indicator-sound.c') diff --git a/src/indicator-sound.c b/src/indicator-sound.c index 546f404..3aca517 100644 --- a/src/indicator-sound.c +++ b/src/indicator-sound.c @@ -300,11 +300,22 @@ gint get_state() return current_state; } +gchar* get_state_image_name(gint state) +{ + return g_hash_table_lookup(volume_states, GINT_TO_POINTER(state)); +} + void prepare_for_tests(IndicatorObject *io) { + prepare_state_machine(); get_icon(io); } +void tidy_up_hash() +{ + g_hash_table_destroy(volume_states); +} + static void update_state(const gint state) { /* g_debug("update state beginning - previous_state = %i", previous_state);*/ -- cgit v1.2.3 From 259f58ec21be89f22f478243f4c8acf9a44231f9 Mon Sep 17 00:00:00 2001 From: Conor Curran Date: Wed, 3 Mar 2010 15:05:08 +0000 Subject: tests compiling --- src/indicator-sound.c | 1 + 1 file changed, 1 insertion(+) (limited to 'src/indicator-sound.c') diff --git a/src/indicator-sound.c b/src/indicator-sound.c index 3aca517..4bdfbb7 100644 --- a/src/indicator-sound.c +++ b/src/indicator-sound.c @@ -238,6 +238,7 @@ static gboolean new_slider_item(DbusmenuMenuitem * newitem, DbusmenuMenuitem * p static void connection_changed (IndicatorServiceManager * sm, gboolean connected, gpointer userdata) { + // TODO: This could be safer. if (connected) { if (sound_dbus_proxy == NULL) { GError * error = NULL; -- cgit v1.2.3 From 6b706a64c5bdcc4b33adfa94b5fa71dbda928399 Mon Sep 17 00:00:00 2001 From: Conor Curran Date: Thu, 4 Mar 2010 18:02:45 +0000 Subject: slider stretching in place --- src/indicator-sound.c | 47 +++++++++++++++++++++-------------------------- 1 file changed, 21 insertions(+), 26 deletions(-) (limited to 'src/indicator-sound.c') diff --git a/src/indicator-sound.c b/src/indicator-sound.c index 3a6ae30..098b24f 100644 --- a/src/indicator-sound.c +++ b/src/indicator-sound.c @@ -78,14 +78,14 @@ G_DEFINE_TYPE (IndicatorSound, indicator_sound, INDICATOR_OBJECT_TYPE); static GtkLabel * get_label (IndicatorObject * io); static GtkImage * get_icon (IndicatorObject * io); static GtkMenu * get_menu (IndicatorObject * io); + //Slider related 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); -// Alternative callback mechanism, may use this again once ido is updated. -/*static gboolean user_change_value_event_cb(GtkRange *range, GtkScrollType scroll_type, gdouble input_value, gpointer user_data);*/ static gboolean value_changed_event_cb(GtkRange *range, gpointer user_data); static gboolean key_press_cb(GtkWidget* widget, GdkEventKey* event, gpointer data); +static void slider_size_allocate(GtkWidget *widget, GtkAllocation *allocation, gpointer user_data); // DBUS communication static DBusGProxy *sound_dbus_proxy = NULL; @@ -96,6 +96,7 @@ static void catch_signal_sink_mute_update(DBusGProxy *proxy, gboolean mute_value static void fetch_volume_percent_from_dbus(); static void fetch_mute_value_from_dbus(); + /****Volume States 'members' ***/ static void update_state(const gint state); @@ -201,6 +202,7 @@ get_menu (IndicatorObject * io) return GTK_MENU(menu); } + /** new_slider_item: Create a new dBusMenu Slider item. @@ -220,10 +222,9 @@ static gboolean new_slider_item(DbusmenuMenuitem * newitem, DbusmenuMenuitem * p // register slider changes listening on the range GtkWidget* slider = ido_scale_menu_item_get_scale((IdoScaleMenuItem*)volume_slider); + g_signal_connect(slider, "value-changed", G_CALLBACK(value_changed_event_cb), newitem); - // alternative callback mechanism which i could use again at some point. -/* g_signal_connect(slider, "change-value", G_CALLBACK(user_change_value_event_cb), newitem); */ - + g_signal_connect(slider, "size-allocate", G_CALLBACK(slider_size_allocate), NULL); // Set images on the ido primary_image = ido_scale_menu_item_get_primary_image((IdoScaleMenuItem*)volume_slider); gtk_image_set_from_icon_name(GTK_IMAGE(primary_image), g_hash_table_lookup(volume_states, GINT_TO_POINTER(STATE_ZERO)), GTK_ICON_SIZE_MENU); @@ -277,9 +278,6 @@ connection_changed (IndicatorServiceManager * sm, gboolean connected, gpointer u return; } - - - /* Prepare states Array. */ @@ -451,6 +449,21 @@ static gboolean value_changed_event_cb(GtkRange *range, gpointer user_data) return FALSE; } +/** +slider_size_allocate: +Callback on the size-allocate event on the slider item. +**/ +static void slider_size_allocate(GtkWidget *widget, + GtkAllocation *allocation, + gpointer user_data) +{ + g_print("size allocate on slider (%dx%d)\n", allocation->width, allocation->height); + if(allocation->width < 200) + { + gtk_widget_set_size_request(widget, 200, -1); + } +} + /** key_press_cb: **/ @@ -514,22 +527,4 @@ static gboolean key_press_cb(GtkWidget* widget, GdkEventKey* event, gpointer dat return digested; } -/** -This callback should only be called when the user actually drags the slider. -Turned off for now in favour of the non descriminating value-changed call back. -Once the grabbing listener is implemented on the slider may revert to using this. -Its another tool for filtering unwanted volume change updates. -**/ -/*static gboolean user_change_value_event_cb(GtkRange *range, GtkScrollType scroll_type, gdouble input_value, gpointer user_data)*/ -/*{*/ -/* DbusmenuMenuitem *item = (DbusmenuMenuitem*)user_data;*/ -/* gdouble clamped_input = CLAMP(input_value, 0, 100);*/ -/* GValue value = {0};*/ -/* 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);*/ -/* return FALSE; */ -/*} */ - -- cgit v1.2.3 From 378c3c3f79aae564090593af6c6ce6abdb3c541a Mon Sep 17 00:00:00 2001 From: Conor Curran Date: Thu, 4 Mar 2010 18:34:15 +0000 Subject: correct size now being used for the icons - design_team_size --- src/indicator-sound.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) (limited to 'src/indicator-sound.c') diff --git a/src/indicator-sound.c b/src/indicator-sound.c index 098b24f..28f85b8 100644 --- a/src/indicator-sound.c +++ b/src/indicator-sound.c @@ -116,6 +116,9 @@ static gint previous_state = 0; static gdouble initial_volume_percent = 0; static gboolean initial_mute = FALSE; +#define DESIGN_TEAM_SIZE design_team_size +static GtkIconSize design_team_size; + // Construction static void indicator_sound_class_init (IndicatorSoundClass *klass) @@ -129,6 +132,8 @@ indicator_sound_class_init (IndicatorSoundClass *klass) io_class->get_label = get_label; io_class->get_image = get_icon; io_class->get_menu = get_menu; + + design_team_size = gtk_icon_size_register("design-team-size", 22, 22); /* dbus_g_object_register_marshaller (_sound_service_marshal_VOID__INT_BOOLEAN,*/ /* G_TYPE_NONE,*/ @@ -181,7 +186,7 @@ get_icon (IndicatorObject * io) { 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)); + speaker_image = GTK_IMAGE(gtk_image_new_from_icon_name(current_name, DESIGN_TEAM_SIZE)); gtk_widget_show(GTK_WIDGET(speaker_image)); return speaker_image; } @@ -227,9 +232,9 @@ static gboolean new_slider_item(DbusmenuMenuitem * newitem, DbusmenuMenuitem * p g_signal_connect(slider, "size-allocate", G_CALLBACK(slider_size_allocate), NULL); // Set images on the ido primary_image = ido_scale_menu_item_get_primary_image((IdoScaleMenuItem*)volume_slider); - gtk_image_set_from_icon_name(GTK_IMAGE(primary_image), g_hash_table_lookup(volume_states, GINT_TO_POINTER(STATE_ZERO)), GTK_ICON_SIZE_MENU); + gtk_image_set_from_icon_name(GTK_IMAGE(primary_image), g_hash_table_lookup(volume_states, GINT_TO_POINTER(STATE_ZERO)), DESIGN_TEAM_SIZE); GtkWidget* secondary_image = ido_scale_menu_item_get_secondary_image((IdoScaleMenuItem*)volume_slider); - gtk_image_set_from_icon_name(GTK_IMAGE(secondary_image), g_hash_table_lookup(volume_states, GINT_TO_POINTER(STATE_HIGH)), GTK_ICON_SIZE_MENU); + gtk_image_set_from_icon_name(GTK_IMAGE(secondary_image), g_hash_table_lookup(volume_states, GINT_TO_POINTER(STATE_HIGH)), DESIGN_TEAM_SIZE); gtk_widget_show_all(volume_slider); @@ -325,7 +330,7 @@ static void update_state(const gint 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); + gtk_image_set_from_icon_name(speaker_image, image_name, DESIGN_TEAM_SIZE); } -- cgit v1.2.3 From 8d392c8f315f18c1ebc52850141b103897e2eea2 Mon Sep 17 00:00:00 2001 From: Conor Curran Date: Fri, 5 Mar 2010 10:38:57 +0000 Subject: blocking event now being registered, removed unneccessary marshaller --- src/indicator-sound.c | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) (limited to 'src/indicator-sound.c') diff --git a/src/indicator-sound.c b/src/indicator-sound.c index 28f85b8..1fb8090 100644 --- a/src/indicator-sound.c +++ b/src/indicator-sound.c @@ -90,7 +90,7 @@ static void slider_size_allocate(GtkWidget *widget, GtkAllocation *allocation, // 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, 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); static void fetch_volume_percent_from_dbus(); @@ -135,11 +135,6 @@ indicator_sound_class_init (IndicatorSoundClass *klass) design_team_size = gtk_icon_size_register("design-team-size", 22, 22); -/* dbus_g_object_register_marshaller (_sound_service_marshal_VOID__INT_BOOLEAN,*/ -/* G_TYPE_NONE,*/ -/* G_TYPE_INT,*/ -/* G_TYPE_BOOLEAN,*/ -/* G_TYPE_INVALID);*/ return; } @@ -264,7 +259,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_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_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); @@ -393,10 +388,10 @@ static void fetch_mute_value_from_dbus() 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 value %i", block_value);*/ -/*}*/ +static void catch_signal_sink_input_while_muted(DBusGProxy * proxy, gboolean block_value, gpointer userdata) +{ + 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) { -- cgit v1.2.3 From c462eb03f66d00a39562d00238f5dce35f371df6 Mon Sep 17 00:00:00 2001 From: Conor Curran Date: Mon, 8 Mar 2010 19:12:18 +0000 Subject: no sink available dynamically being handled --- src/indicator-sound.c | 75 +++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 73 insertions(+), 2 deletions(-) (limited to 'src/indicator-sound.c') diff --git a/src/indicator-sound.c b/src/indicator-sound.c index 1fb8090..c10b549 100644 --- a/src/indicator-sound.c +++ b/src/indicator-sound.c @@ -93,8 +93,10 @@ static void connection_changed (IndicatorServiceManager * sm, gboolean connected 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); +static void catch_signal_sink_availability_update(DBusGProxy *proxy, gboolean available_value, gpointer userdata); static void fetch_volume_percent_from_dbus(); static void fetch_mute_value_from_dbus(); +static void fetch_sink_availability_from_dbus(); /****Volume States 'members' ***/ @@ -110,11 +112,13 @@ static const gint STATE_SINKS_NONE = 6; static GHashTable *volume_states = NULL; static GtkImage *speaker_image = NULL; +static GtkImage *blocking_image = NULL; static GtkWidget* primary_image = NULL; static gint current_state = 0; static gint previous_state = 0; static gdouble initial_volume_percent = 0; static gboolean initial_mute = FALSE; +static gboolean device_available = TRUE; #define DESIGN_TEAM_SIZE design_team_size static GtkIconSize design_team_size; @@ -182,6 +186,8 @@ get_icon (IndicatorObject * io) 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, DESIGN_TEAM_SIZE)); + gchar* blocking_name = g_hash_table_lookup(volume_states, GINT_TO_POINTER(STATE_MUTED_WHILE_INPUT)); + blocking_image = GTK_IMAGE(gtk_image_new_from_icon_name(blocking_name, DESIGN_TEAM_SIZE)); gtk_widget_show(GTK_WIDGET(speaker_image)); return speaker_image; } @@ -264,11 +270,14 @@ connection_changed (IndicatorServiceManager * sm, gboolean connected, gpointer u 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); + dbus_g_proxy_add_signal(sound_dbus_proxy, SIGNAL_SINK_AVAILABLE_UPDATE, G_TYPE_BOOLEAN, G_TYPE_INVALID); + dbus_g_proxy_connect_signal(sound_dbus_proxy, SIGNAL_SINK_AVAILABLE_UPDATE, G_CALLBACK(catch_signal_sink_availability_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(); + fetch_sink_availability_from_dbus(); } } else { @@ -332,7 +341,8 @@ static void update_state(const gint state) void determine_state_from_volume(gdouble volume_percent) { /* g_debug("determine_state_from_volume - previous_state = %i", previous_state);*/ - + if (device_available == FALSE) + return; gint state = previous_state; if (volume_percent < 30.0 && volume_percent > 0){ state = STATE_LOW; @@ -350,6 +360,25 @@ void determine_state_from_volume(gdouble volume_percent) } +static void fetch_sink_availability_from_dbus() +{ + GError * error = NULL; + gboolean *available_input; + available_input = g_new0(gboolean, 1); + org_ayatana_indicator_sound_get_sink_availability(sound_dbus_proxy, available_input, &error); + if (error != NULL) { + g_warning("Unable to fetch AVAILABILITY at indicator start up: %s", error->message); + g_error_free(error); + g_free(available_input); + return; + } + device_available = *available_input; + if (device_available == FALSE) + update_state(STATE_SINKS_NONE); + g_free(available_input); + g_debug("IndicatorSound::fetch_sink_availability_from_dbus -> AVAILABILTY returned from dbus method is %i", device_available); + +} static void fetch_volume_percent_from_dbus() { @@ -391,6 +420,38 @@ static void fetch_mute_value_from_dbus() static void catch_signal_sink_input_while_muted(DBusGProxy * proxy, gboolean block_value, gpointer userdata) { g_debug("signal caught - sink input while muted with value %i", block_value); + if (block_value == 1) { + GError* error= NULL; + // We can assume we are in the muted state ! + GtkIconTheme* theme = gtk_icon_theme_get_default(); + GdkPixbuf* mute_buf = gtk_icon_theme_load_icon(theme, + g_hash_table_lookup(volume_states, GINT_TO_POINTER(STATE_MUTED_WHILE_INPUT)), + 22, + GTK_ICON_LOOKUP_GENERIC_FALLBACK, + &error); + if(error != NULL){ + g_error("indicator-sound : catch_signal_sink_input_while_muted - %s", error->message); + g_error_free(error); + return; + } + gchar* blocked_name = g_hash_table_lookup(volume_states, GINT_TO_POINTER(STATE_MUTED_WHILE_INPUT)); + GdkPixbuf* blocked_buf = gtk_icon_theme_load_icon(theme, blocked_name, + 22, + GTK_ICON_LOOKUP_GENERIC_FALLBACK, + &error); + if(error != NULL){ + g_error("indicator-sound : catch_signal_sink_input_while_muted - %s", error->message); + g_error_free(error); + return; + } + g_debug("gdk_pixbuf_get_width returns %i", gdk_pixbuf_get_width(blocked_buf)); + gdk_pixbuf_composite(mute_buf, blocked_buf, 0, 0, + gdk_pixbuf_get_width(blocked_buf), + gdk_pixbuf_get_height(blocked_buf), + 0, 0, 1, 1, GDK_INTERP_BILINEAR, 128); + //gtk_image_set_from_icon_name(speaker_image, blocked_name, DESIGN_TEAM_SIZE); + //gtk_image_set_from_pixbuf(speaker_image, blocked_buf); + } } static void catch_signal_sink_volume_update(DBusGProxy *proxy, gdouble volume_percent, gpointer userdata) @@ -409,13 +470,23 @@ static void catch_signal_sink_mute_update(DBusGProxy *proxy, gboolean mute_value { //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) + if(mute_value == TRUE && device_available != FALSE) { update_state(STATE_MUTED); } g_debug("signal caught - sink mute update with mute value: %i", mute_value); gtk_widget_set_sensitive(volume_slider, !mute_value); } + +static void catch_signal_sink_availability_update(DBusGProxy *proxy, gboolean available_value, gpointer userdata) +{ + device_available = available_value; + if (device_available == FALSE){ + update_state(STATE_SINKS_NONE); + } + g_debug("signal caught - sink availability update with value: %i", available_value); +} + /** slider_prop_change_cb: Whenever we have a property change on a DbusmenuMenuitem this will be called. -- cgit v1.2.3 From ea8064d34d73a1b242cc571fbfd9f0f39128178a Mon Sep 17 00:00:00 2001 From: Conor Curran Date: Tue, 9 Mar 2010 18:10:09 +0000 Subject: smoother slider actions due ido grabbing update and pixbuf icon loading problems --- src/indicator-sound.c | 124 +++++++++++++++++++++++++++++++------------------- 1 file changed, 78 insertions(+), 46 deletions(-) (limited to 'src/indicator-sound.c') diff --git a/src/indicator-sound.c b/src/indicator-sound.c index c10b549..5fd68b2 100644 --- a/src/indicator-sound.c +++ b/src/indicator-sound.c @@ -5,7 +5,7 @@ into the gnome-panel using it's applet interface. Copyright 2010 Canonical Ltd. Authors: - Conor Curran + Conor Curran Ted Gould This program is free software: you can redistribute it and/or modify it @@ -82,10 +82,12 @@ static GtkMenu * get_menu (IndicatorObject * io); //Slider related 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 void slider_prop_change_cb (DbusmenuMenuitem * mi, gchar * prop, GValue * value, GtkWidget *widget);*/ static gboolean value_changed_event_cb(GtkRange *range, gpointer user_data); static gboolean key_press_cb(GtkWidget* widget, GdkEventKey* event, gpointer data); static void slider_size_allocate(GtkWidget *widget, GtkAllocation *allocation, gpointer user_data); +static void slider_grabbed(GtkWidget *widget, gpointer user_data); +static void slider_released(GtkWidget *widget, gpointer user_data); // DBUS communication static DBusGProxy *sound_dbus_proxy = NULL; @@ -98,7 +100,6 @@ static void fetch_volume_percent_from_dbus(); static void fetch_mute_value_from_dbus(); static void fetch_sink_availability_from_dbus(); - /****Volume States 'members' ***/ static void update_state(const gint state); @@ -112,13 +113,13 @@ static const gint STATE_SINKS_NONE = 6; static GHashTable *volume_states = NULL; static GtkImage *speaker_image = NULL; -static GtkImage *blocking_image = NULL; -static GtkWidget* primary_image = NULL; static gint current_state = 0; static gint previous_state = 0; + static gdouble initial_volume_percent = 0; static gboolean initial_mute = FALSE; static gboolean device_available = TRUE; +static gboolean slider_in_direct_use = FALSE; #define DESIGN_TEAM_SIZE design_team_size static GtkIconSize design_team_size; @@ -184,10 +185,8 @@ static GtkImage * get_icon (IndicatorObject * io) { 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); + 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, DESIGN_TEAM_SIZE)); - gchar* blocking_name = g_hash_table_lookup(volume_states, GINT_TO_POINTER(STATE_MUTED_WHILE_INPUT)); - blocking_image = GTK_IMAGE(gtk_image_new_from_icon_name(blocking_name, DESIGN_TEAM_SIZE)); gtk_widget_show(GTK_WIDGET(speaker_image)); return speaker_image; } @@ -204,7 +203,6 @@ get_menu (IndicatorObject * io) // register Key-press listening on the menu widget as the slider does not allow this. g_signal_connect(menu, "key-press-event", G_CALLBACK(key_press_cb), NULL); - return GTK_MENU(menu); } @@ -224,15 +222,16 @@ 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); +/* g_signal_connect(G_OBJECT(newitem), DBUSMENU_MENUITEM_SIGNAL_PROPERTY_CHANGED, G_CALLBACK(slider_prop_change_cb), volume_slider);*/ // register slider changes listening on the range GtkWidget* slider = ido_scale_menu_item_get_scale((IdoScaleMenuItem*)volume_slider); - - g_signal_connect(slider, "value-changed", G_CALLBACK(value_changed_event_cb), newitem); - g_signal_connect(slider, "size-allocate", G_CALLBACK(slider_size_allocate), NULL); + g_signal_connect(slider, "value-changed", G_CALLBACK(value_changed_event_cb), newitem); + g_signal_connect(volume_slider, "slider-grabbed", G_CALLBACK(slider_grabbed), NULL); + g_signal_connect(volume_slider, "slider-released", G_CALLBACK(slider_released), NULL); + g_signal_connect(slider, "size-allocate", G_CALLBACK(slider_size_allocate), NULL); // Set images on the ido - primary_image = ido_scale_menu_item_get_primary_image((IdoScaleMenuItem*)volume_slider); + GtkWidget* primary_image = ido_scale_menu_item_get_primary_image((IdoScaleMenuItem*)volume_slider); gtk_image_set_from_icon_name(GTK_IMAGE(primary_image), g_hash_table_lookup(volume_states, GINT_TO_POINTER(STATE_ZERO)), DESIGN_TEAM_SIZE); GtkWidget* secondary_image = ido_scale_menu_item_get_secondary_image((IdoScaleMenuItem*)volume_slider); gtk_image_set_from_icon_name(GTK_IMAGE(secondary_image), g_hash_table_lookup(volume_states, GINT_TO_POINTER(STATE_HIGH)), DESIGN_TEAM_SIZE); @@ -413,6 +412,9 @@ static void fetch_mute_value_from_dbus() initial_mute = *mute_input; if (initial_mute == TRUE) update_state(STATE_MUTED); +// TODO bug down below - VIRTUALLY IMPOSSIBLE TO SETUP SLIDER WITH ANY ALTERNATIVE STARTUP STATE +/* GtkWidget* slider = ido_scale_menu_item_get_scale((IdoScaleMenuItem*)volume_slider);*/ +/* gtk_widget_set_sensitive(slider, !initial_mute);*/ g_free(mute_input); g_debug("at the indicator start up and the MUTE returned from dbus method is %i", initial_mute); } @@ -423,18 +425,25 @@ static void catch_signal_sink_input_while_muted(DBusGProxy * proxy, gboolean blo if (block_value == 1) { GError* error= NULL; // We can assume we are in the muted state ! + gchar* blocked_name = g_hash_table_lookup(volume_states, GINT_TO_POINTER(STATE_MUTED_WHILE_INPUT)); GtkIconTheme* theme = gtk_icon_theme_get_default(); - GdkPixbuf* mute_buf = gtk_icon_theme_load_icon(theme, - g_hash_table_lookup(volume_states, GINT_TO_POINTER(STATE_MUTED_WHILE_INPUT)), - 22, - GTK_ICON_LOOKUP_GENERIC_FALLBACK, - &error); + g_debug("DOES the ICON THEME Have the Blocked image = %i", gtk_icon_theme_has_icon(theme, blocked_name)); +/* GdkPixbuf* mute_buf = gtk_icon_theme_load_icon(theme, */ +/* blocked_name,*/ +/* 22,*/ +/* GTK_ICON_LOOKUP_GENERIC_FALLBACK,*/ +/* &error);*/ if(error != NULL){ g_error("indicator-sound : catch_signal_sink_input_while_muted - %s", error->message); g_error_free(error); return; } - gchar* blocked_name = g_hash_table_lookup(volume_states, GINT_TO_POINTER(STATE_MUTED_WHILE_INPUT)); + + GtkIconInfo* buffer_icon_info = gtk_icon_theme_lookup_icon(theme, blocked_name, + 22, + GTK_ICON_LOOKUP_GENERIC_FALLBACK); + g_debug("The icon name of the buffer icon %s", gtk_icon_info_get_filename(buffer_icon_info)); + GdkPixbuf* blocked_buf = gtk_icon_theme_load_icon(theme, blocked_name, 22, GTK_ICON_LOOKUP_GENERIC_FALLBACK, @@ -445,25 +454,34 @@ static void catch_signal_sink_input_while_muted(DBusGProxy * proxy, gboolean blo return; } g_debug("gdk_pixbuf_get_width returns %i", gdk_pixbuf_get_width(blocked_buf)); - gdk_pixbuf_composite(mute_buf, blocked_buf, 0, 0, - gdk_pixbuf_get_width(blocked_buf), - gdk_pixbuf_get_height(blocked_buf), - 0, 0, 1, 1, GDK_INTERP_BILINEAR, 128); +/* gdk_pixbuf_composite(mute_buf, blocked_buf, 0, 0,*/ +/* gdk_pixbuf_get_width(blocked_buf),*/ +/* gdk_pixbuf_get_height(blocked_buf), */ +/* 0, 0, 1, 1, GDK_INTERP_BILINEAR, 128);*/ //gtk_image_set_from_icon_name(speaker_image, blocked_name, DESIGN_TEAM_SIZE); - //gtk_image_set_from_pixbuf(speaker_image, blocked_buf); + + g_debug("DOES the ICON THEME Have the Blocked image = %i", gtk_icon_theme_has_icon(theme, blocked_name)); + gchar ** theme_path; + gint nelements = 1; + + gtk_icon_theme_get_search_path(theme, &theme_path, &nelements); + g_debug("icon theme path is %s ", *theme_path); + gtk_image_set_from_pixbuf(speaker_image, blocked_buf); } } static void catch_signal_sink_volume_update(DBusGProxy *proxy, gdouble volume_percent, gpointer userdata) { - GtkWidget *slider = ido_scale_menu_item_get_scale((IdoScaleMenuItem*)volume_slider); - GtkRange *range = (GtkRange*)slider; - - // DEBUG - gdouble current_value = gtk_range_get_value(range); - g_debug("SIGNAL- update sink volume - current_value : %f and new value : %f", current_value, volume_percent); - gtk_range_set_value(range, volume_percent); - determine_state_from_volume(volume_percent); + if (slider_in_direct_use != TRUE){ + GtkWidget *slider = ido_scale_menu_item_get_scale((IdoScaleMenuItem*)volume_slider); + GtkRange *range = (GtkRange*)slider; + + // DEBUG + gdouble current_value = gtk_range_get_value(range); + g_debug("SIGNAL- update sink volume - current_value : %f and new value : %f", current_value, volume_percent); + 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) @@ -491,15 +509,15 @@ static void catch_signal_sink_availability_update(DBusGProxy *proxy, gboolean av slider_prop_change_cb: Whenever we have a property change on a DbusmenuMenuitem this will be called. **/ -static void slider_prop_change_cb (DbusmenuMenuitem * mi, gchar * prop, GValue * value, GtkWidget *widget) -{ - 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; - gtk_range_set_value(range, g_value_get_double(value)); - return; -} +/*static void slider_prop_change_cb (DbusmenuMenuitem * mi, gchar * prop, GValue * value, GtkWidget *widget)*/ +/*{*/ +/* 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; */ +/* gtk_range_set_value(range, g_value_get_double(value)); */ +/* return;*/ +/*}*/ /** value_changed_event_cb: @@ -520,6 +538,20 @@ static gboolean value_changed_event_cb(GtkRange *range, gpointer user_data) return FALSE; } + +static void slider_grabbed (GtkWidget *widget, gpointer user_data) +{ + slider_in_direct_use = TRUE; + g_debug ("!!!!!! grabbed\n"); +} + +static void slider_released (GtkWidget *widget, gpointer user_data) +{ + slider_in_direct_use = FALSE; + g_debug ("!!!!!! released\n"); +} + + /** slider_size_allocate: Callback on the size-allocate event on the slider item. @@ -528,10 +560,10 @@ static void slider_size_allocate(GtkWidget *widget, GtkAllocation *allocation, gpointer user_data) { - g_print("size allocate on slider (%dx%d)\n", allocation->width, allocation->height); - if(allocation->width < 200) - { - gtk_widget_set_size_request(widget, 200, -1); + g_print("Size allocate on slider (%dx%d)\n", allocation->width, allocation->height); + if(allocation->width < 200){ + g_print("Attempting to resize the slider"); + gtk_widget_set_size_request(widget, 200, -1); } } -- cgit v1.2.3 From 16021586200c0e7746ce787e43a8721dfe23ae48 Mon Sep 17 00:00:00 2001 From: Conor Curran Date: Wed, 10 Mar 2010 10:53:23 +0000 Subject: fixed that annoying startup in mute state allowing slider to move - race conditions on start up are pretty hairy --- src/indicator-sound.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'src/indicator-sound.c') diff --git a/src/indicator-sound.c b/src/indicator-sound.c index 5fd68b2..1876e69 100644 --- a/src/indicator-sound.c +++ b/src/indicator-sound.c @@ -235,6 +235,9 @@ static gboolean new_slider_item(DbusmenuMenuitem * newitem, DbusmenuMenuitem * p gtk_image_set_from_icon_name(GTK_IMAGE(primary_image), g_hash_table_lookup(volume_states, GINT_TO_POINTER(STATE_ZERO)), DESIGN_TEAM_SIZE); GtkWidget* secondary_image = ido_scale_menu_item_get_secondary_image((IdoScaleMenuItem*)volume_slider); gtk_image_set_from_icon_name(GTK_IMAGE(secondary_image), g_hash_table_lookup(volume_states, GINT_TO_POINTER(STATE_HIGH)), DESIGN_TEAM_SIZE); + + // the race conditions at start up are like a west waterford greyhound dart. god knows who wins, who breaks a leg. + gtk_widget_set_sensitive(volume_slider, !initial_mute); gtk_widget_show_all(volume_slider); @@ -412,9 +415,6 @@ static void fetch_mute_value_from_dbus() initial_mute = *mute_input; if (initial_mute == TRUE) update_state(STATE_MUTED); -// TODO bug down below - VIRTUALLY IMPOSSIBLE TO SETUP SLIDER WITH ANY ALTERNATIVE STARTUP STATE -/* GtkWidget* slider = ido_scale_menu_item_get_scale((IdoScaleMenuItem*)volume_slider);*/ -/* gtk_widget_set_sensitive(slider, !initial_mute);*/ g_free(mute_input); g_debug("at the indicator start up and the MUTE returned from dbus method is %i", initial_mute); } -- cgit v1.2.3 From 59eb14451f0635c286d482e8b35cad622882aa35 Mon Sep 17 00:00:00 2001 From: Conor Curran Date: Wed, 10 Mar 2010 18:10:40 +0000 Subject: fade animation in place --- src/indicator-sound.c | 181 +++++++++++++++++++++++++++++++++++++------------- 1 file changed, 136 insertions(+), 45 deletions(-) (limited to 'src/indicator-sound.c') diff --git a/src/indicator-sound.c b/src/indicator-sound.c index 1876e69..ebd4306 100644 --- a/src/indicator-sound.c +++ b/src/indicator-sound.c @@ -123,6 +123,13 @@ static gboolean slider_in_direct_use = FALSE; #define DESIGN_TEAM_SIZE design_team_size static GtkIconSize design_team_size; +static gint timeout_id; +static gint animation_id; +static GList * blocked_animation_list = NULL; +static GList * blocked_iter = NULL; +static void prepare_blocked_animation(); +static gboolean fade_back_to_mute_image(); +static gboolean commence_animation(); // Construction static void @@ -151,6 +158,9 @@ static void indicator_sound_init (IndicatorSound *self) 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_blocked_animation(); + timeout_id = 0; + animation_id = 0; return; } @@ -164,6 +174,8 @@ indicator_sound_dispose (GObject *object) self->service = NULL; } g_hash_table_destroy(volume_states); + // TODO delete all pointers in the list; + g_list_free(blocked_animation_list); G_OBJECT_CLASS (indicator_sound_parent_class)->dispose (object); return; } @@ -305,6 +317,51 @@ void prepare_state_machine() g_hash_table_insert(volume_states, GINT_TO_POINTER(STATE_SINKS_NONE), g_strdup("audio-output-none-panel")); } +/* +prepare_blocked_animation: +Prepares the array of images to be used in the blocked animation. +Only called at startup. +*/ +static void prepare_blocked_animation() +{ + GError* error= NULL; + int i; + + gchar* blocked_name = g_hash_table_lookup(volume_states, GINT_TO_POINTER(STATE_MUTED_WHILE_INPUT)); + gchar* muted_name = g_hash_table_lookup(volume_states, GINT_TO_POINTER(STATE_MUTED)); + GtkIconTheme* theme = gtk_icon_theme_get_default(); + GdkPixbuf* mute_buf = gtk_icon_theme_load_icon(theme, + muted_name, + 22, + GTK_ICON_LOOKUP_GENERIC_FALLBACK, + &error); + if(error != NULL){ + g_error("indicator-sound : prepare_blocked_animation - %s", error->message); + g_error_free(error); + return; + } + + GdkPixbuf* blocked_buf = gtk_icon_theme_load_icon(theme, blocked_name, + 22, + GTK_ICON_LOOKUP_GENERIC_FALLBACK, + &error); + if(error != NULL){ + g_error("indicator-sound : prepare_blocked_animation - %s", error->message); + g_error_free(error); + return; + } + + for(i = 0; i < 256; i++) + { + gdk_pixbuf_composite(mute_buf, blocked_buf, 0, 0, + gdk_pixbuf_get_width(mute_buf), + gdk_pixbuf_get_height(mute_buf), + 0, 0, 1, 1, GDK_INTERP_BILINEAR, i); + g_debug("creating animation - alpha value = %i", i); + blocked_animation_list = g_list_append(blocked_animation_list, gdk_pixbuf_copy(blocked_buf)); + } +} + gint get_state() { return current_state; @@ -365,7 +422,7 @@ void determine_state_from_volume(gdouble volume_percent) static void fetch_sink_availability_from_dbus() { GError * error = NULL; - gboolean *available_input; + gboolean * available_input; available_input = g_new0(gboolean, 1); org_ayatana_indicator_sound_get_sink_availability(sound_dbus_proxy, available_input, &error); if (error != NULL) { @@ -422,53 +479,75 @@ static void fetch_mute_value_from_dbus() static void catch_signal_sink_input_while_muted(DBusGProxy * proxy, gboolean block_value, gpointer userdata) { g_debug("signal caught - sink input while muted with value %i", block_value); - if (block_value == 1) { - GError* error= NULL; + if (block_value == 1 && timeout_id == 0 ) { // We can assume we are in the muted state ! - gchar* blocked_name = g_hash_table_lookup(volume_states, GINT_TO_POINTER(STATE_MUTED_WHILE_INPUT)); - GtkIconTheme* theme = gtk_icon_theme_get_default(); - g_debug("DOES the ICON THEME Have the Blocked image = %i", gtk_icon_theme_has_icon(theme, blocked_name)); -/* GdkPixbuf* mute_buf = gtk_icon_theme_load_icon(theme, */ -/* blocked_name,*/ -/* 22,*/ -/* GTK_ICON_LOOKUP_GENERIC_FALLBACK,*/ -/* &error);*/ - if(error != NULL){ - g_error("indicator-sound : catch_signal_sink_input_while_muted - %s", error->message); - g_error_free(error); - return; - } - - GtkIconInfo* buffer_icon_info = gtk_icon_theme_lookup_icon(theme, blocked_name, - 22, - GTK_ICON_LOOKUP_GENERIC_FALLBACK); - g_debug("The icon name of the buffer icon %s", gtk_icon_info_get_filename(buffer_icon_info)); - - GdkPixbuf* blocked_buf = gtk_icon_theme_load_icon(theme, blocked_name, - 22, - GTK_ICON_LOOKUP_GENERIC_FALLBACK, - &error); - if(error != NULL){ - g_error("indicator-sound : catch_signal_sink_input_while_muted - %s", error->message); - g_error_free(error); - return; - } - g_debug("gdk_pixbuf_get_width returns %i", gdk_pixbuf_get_width(blocked_buf)); -/* gdk_pixbuf_composite(mute_buf, blocked_buf, 0, 0,*/ -/* gdk_pixbuf_get_width(blocked_buf),*/ -/* gdk_pixbuf_get_height(blocked_buf), */ -/* 0, 0, 1, 1, GDK_INTERP_BILINEAR, 128);*/ - //gtk_image_set_from_icon_name(speaker_image, blocked_name, DESIGN_TEAM_SIZE); - - g_debug("DOES the ICON THEME Have the Blocked image = %i", gtk_icon_theme_has_icon(theme, blocked_name)); - gchar ** theme_path; - gint nelements = 1; + gtk_image_set_from_icon_name(speaker_image, + g_hash_table_lookup(volume_states, GINT_TO_POINTER(STATE_MUTED_WHILE_INPUT)), + DESIGN_TEAM_SIZE); + blocked_iter = blocked_animation_list; + timeout_id = g_timeout_add_seconds(3, commence_animation, NULL); + } +} - gtk_icon_theme_get_search_path(theme, &theme_path, &nelements); - g_debug("icon theme path is %s ", *theme_path); - gtk_image_set_from_pixbuf(speaker_image, blocked_buf); - } +static gboolean commence_animation() +{ + animation_id = g_timeout_add_seconds(1, fade_back_to_mute_image, NULL); + timeout_id = 0; + g_debug("out of there\n"); + return FALSE; +} + +static gboolean fade_back_to_mute_image() +{ + g_debug("fade me entry\n"); + if(blocked_iter != NULL) + { + g_debug("in there\n"); + gtk_image_set_from_pixbuf(speaker_image, blocked_iter->data); + blocked_iter = blocked_iter->next; + return TRUE; + } + else{ + animation_id = 0; + g_debug("out of there\n"); + return FALSE; + } } +/* int i;*/ +/* GList * anim_iter;*/ +/* anim_iter = blocked_animation_list;*/ +/* for(i=0; i < 2560000; i++)*/ +/* { */ +/* if(i % 100000 == 0)*/ +/* {*/ +/* if (anim_iter != NULL)*/ +/* {*/ +/* gtk_image_set_from_pixbuf(speaker_image, anim_iter->data); */ +/* anim_iter = anim_iter->next; */ +/* g_debug("should now be setting each image");*/ +/* }*/ +/* }*/ +/* }*/ +/* gtk_image_set_from_icon_name(speaker_image,*/ +/* g_hash_table_lookup(volume_states, GINT_TO_POINTER(STATE_MUTED)),*/ +/* DESIGN_TEAM_SIZE);*/ + //fade_id = g_timeout_add_seconds(0.2, fade_each_frame, NULL); + + + + +/* g_debug("DOES the ICON THEME Have the Blocked image = %i", gtk_icon_theme_has_icon(theme, blocked_name));*/ +/* GtkIconInfo* buffer_icon_info = gtk_icon_theme_lookup_icon(theme, blocked_name,*/ +/* 22,*/ +/* GTK_ICON_LOOKUP_GENERIC_FALLBACK);*/ +/* g_debug("The icon name of the buffer icon %s", gtk_icon_info_get_filename(buffer_icon_info));*/ +/* g_debug("gdk_pixbuf_get_width returns %i", gdk_pixbuf_get_width(blocked_buf));*/ +/* g_debug("DOES the ICON THEME Have the Blocked image = %i", gtk_icon_theme_has_icon(theme, blocked_name));*/ +/* gchar ** theme_path; */ +/* gint nelements = 1;*/ +/* gtk_icon_theme_get_search_path(theme, &theme_path, &nelements);*/ +/* gtk_image_set_from_icon_name(speaker_image, blocked_name, DESIGN_TEAM_SIZE);*/ +/* g_debug("icon theme path is %s ", *theme_path);*/ static void catch_signal_sink_volume_update(DBusGProxy *proxy, gdouble volume_percent, gpointer userdata) { @@ -492,6 +571,18 @@ static void catch_signal_sink_mute_update(DBusGProxy *proxy, gboolean mute_value { update_state(STATE_MUTED); } + else{ + if(timeout_id != 0){ + g_debug("about to remove the timeout_id callback from the mainloop!!**"); + g_source_remove(timeout_id); + timeout_id = 0; + } + if(animation_id != 0){ + g_debug("about to remove the animation_id callback from the mainloop!!**"); + g_source_remove(animation_id); + animation_id = 0; + } + } g_debug("signal caught - sink mute update with mute value: %i", mute_value); gtk_widget_set_sensitive(volume_slider, !mute_value); } -- cgit v1.2.3 From c67c7ac2effb7ee425370ee33e6b5449e04b98c6 Mon Sep 17 00:00:00 2001 From: Conor Curran Date: Thu, 11 Mar 2010 00:23:59 +0000 Subject: animation working much better now --- src/indicator-sound.c | 85 +++++---------------------------------------------- 1 file changed, 8 insertions(+), 77 deletions(-) (limited to 'src/indicator-sound.c') diff --git a/src/indicator-sound.c b/src/indicator-sound.c index ebd4306..d9c5aa6 100644 --- a/src/indicator-sound.c +++ b/src/indicator-sound.c @@ -123,13 +123,11 @@ static gboolean slider_in_direct_use = FALSE; #define DESIGN_TEAM_SIZE design_team_size static GtkIconSize design_team_size; -static gint timeout_id; static gint animation_id; static GList * blocked_animation_list = NULL; static GList * blocked_iter = NULL; static void prepare_blocked_animation(); static gboolean fade_back_to_mute_image(); -static gboolean commence_animation(); // Construction static void @@ -152,14 +150,11 @@ indicator_sound_class_init (IndicatorSoundClass *klass) static void indicator_sound_init (IndicatorSound *self) { - /* Set good defaults */ self->service = NULL; - /* 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_blocked_animation(); - timeout_id = 0; animation_id = 0; return; } @@ -234,7 +229,6 @@ 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);*/ // register slider changes listening on the range GtkWidget* slider = ido_scale_menu_item_get_scale((IdoScaleMenuItem*)volume_slider); @@ -306,7 +300,6 @@ Prepare states Array. */ 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-panel")); g_hash_table_insert(volume_states, GINT_TO_POINTER(STATE_ZERO), g_strdup("audio-volume-low-zero-panel")); @@ -350,14 +343,14 @@ static void prepare_blocked_animation() g_error_free(error); return; } - - for(i = 0; i < 256; i++) + // sample 22 snapshots - range : 0-256 + for(i = 0; i < 23; i++) { gdk_pixbuf_composite(mute_buf, blocked_buf, 0, 0, gdk_pixbuf_get_width(mute_buf), gdk_pixbuf_get_height(mute_buf), - 0, 0, 1, 1, GDK_INTERP_BILINEAR, i); - g_debug("creating animation - alpha value = %i", i); + 0, 0, 1, 1, GDK_INTERP_BILINEAR, MIN(255, i * 11)); + g_debug("creating blocking animation - alpha value = %i", MIN(255, i * 11)); blocked_animation_list = g_list_append(blocked_animation_list, gdk_pixbuf_copy(blocked_buf)); } } @@ -479,75 +472,31 @@ static void fetch_mute_value_from_dbus() static void catch_signal_sink_input_while_muted(DBusGProxy * proxy, gboolean block_value, gpointer userdata) { g_debug("signal caught - sink input while muted with value %i", block_value); - if (block_value == 1 && timeout_id == 0 ) { + if (block_value == 1 && animation_id == 0 ) { // We can assume we are in the muted state ! gtk_image_set_from_icon_name(speaker_image, g_hash_table_lookup(volume_states, GINT_TO_POINTER(STATE_MUTED_WHILE_INPUT)), DESIGN_TEAM_SIZE); blocked_iter = blocked_animation_list; - timeout_id = g_timeout_add_seconds(3, commence_animation, NULL); + animation_id = g_timeout_add_seconds(1, fade_back_to_mute_image, NULL); } } - -static gboolean commence_animation() -{ - animation_id = g_timeout_add_seconds(1, fade_back_to_mute_image, NULL); - timeout_id = 0; - g_debug("out of there\n"); - return FALSE; -} static gboolean fade_back_to_mute_image() { - g_debug("fade me entry\n"); if(blocked_iter != NULL) { - g_debug("in there\n"); + g_debug("in animation 'loop'\n"); gtk_image_set_from_pixbuf(speaker_image, blocked_iter->data); blocked_iter = blocked_iter->next; return TRUE; } else{ animation_id = 0; - g_debug("out of there\n"); + g_debug("exit from animation\n"); return FALSE; } } -/* int i;*/ -/* GList * anim_iter;*/ -/* anim_iter = blocked_animation_list;*/ -/* for(i=0; i < 2560000; i++)*/ -/* { */ -/* if(i % 100000 == 0)*/ -/* {*/ -/* if (anim_iter != NULL)*/ -/* {*/ -/* gtk_image_set_from_pixbuf(speaker_image, anim_iter->data); */ -/* anim_iter = anim_iter->next; */ -/* g_debug("should now be setting each image");*/ -/* }*/ -/* }*/ -/* }*/ -/* gtk_image_set_from_icon_name(speaker_image,*/ -/* g_hash_table_lookup(volume_states, GINT_TO_POINTER(STATE_MUTED)),*/ -/* DESIGN_TEAM_SIZE);*/ - //fade_id = g_timeout_add_seconds(0.2, fade_each_frame, NULL); - - - - -/* g_debug("DOES the ICON THEME Have the Blocked image = %i", gtk_icon_theme_has_icon(theme, blocked_name));*/ -/* GtkIconInfo* buffer_icon_info = gtk_icon_theme_lookup_icon(theme, blocked_name,*/ -/* 22,*/ -/* GTK_ICON_LOOKUP_GENERIC_FALLBACK);*/ -/* g_debug("The icon name of the buffer icon %s", gtk_icon_info_get_filename(buffer_icon_info));*/ -/* g_debug("gdk_pixbuf_get_width returns %i", gdk_pixbuf_get_width(blocked_buf));*/ -/* g_debug("DOES the ICON THEME Have the Blocked image = %i", gtk_icon_theme_has_icon(theme, blocked_name));*/ -/* gchar ** theme_path; */ -/* gint nelements = 1;*/ -/* gtk_icon_theme_get_search_path(theme, &theme_path, &nelements);*/ -/* gtk_image_set_from_icon_name(speaker_image, blocked_name, DESIGN_TEAM_SIZE);*/ -/* g_debug("icon theme path is %s ", *theme_path);*/ static void catch_signal_sink_volume_update(DBusGProxy *proxy, gdouble volume_percent, gpointer userdata) { @@ -572,11 +521,6 @@ static void catch_signal_sink_mute_update(DBusGProxy *proxy, gboolean mute_value update_state(STATE_MUTED); } else{ - if(timeout_id != 0){ - g_debug("about to remove the timeout_id callback from the mainloop!!**"); - g_source_remove(timeout_id); - timeout_id = 0; - } if(animation_id != 0){ g_debug("about to remove the animation_id callback from the mainloop!!**"); g_source_remove(animation_id); @@ -596,19 +540,6 @@ static void catch_signal_sink_availability_update(DBusGProxy *proxy, gboolean av g_debug("signal caught - sink availability update with value: %i", available_value); } -/** -slider_prop_change_cb: -Whenever we have a property change on a DbusmenuMenuitem this will be called. -**/ -/*static void slider_prop_change_cb (DbusmenuMenuitem * mi, gchar * prop, GValue * value, GtkWidget *widget)*/ -/*{*/ -/* 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; */ -/* gtk_range_set_value(range, g_value_get_double(value)); */ -/* return;*/ -/*}*/ /** value_changed_event_cb: -- cgit v1.2.3 From 69c96d7e7fa903569073bd87069b2d9f6aeb3fa4 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Wed, 10 Mar 2010 22:59:35 -0600 Subject: Update to use new icon helper from libindicator --- src/indicator-sound.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'src/indicator-sound.c') diff --git a/src/indicator-sound.c b/src/indicator-sound.c index 3a6ae30..0b92af8 100644 --- a/src/indicator-sound.c +++ b/src/indicator-sound.c @@ -34,6 +34,7 @@ with this program. If not, see . #include #include #include +#include #include "indicator-sound.h" #include "dbus-shared-names.h" @@ -180,7 +181,7 @@ get_icon (IndicatorObject * io) { 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)); + speaker_image = indicator_image_helper(current_name); gtk_widget_show(GTK_WIDGET(speaker_image)); return speaker_image; } @@ -327,7 +328,9 @@ static void update_state(const gint 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); + GtkImage * tempimage = indicator_image_helper(image_name); + gtk_image_set_from_pixbuf(speaker_image, gtk_image_get_pixbuf(tempimage)); + g_object_ref_sink(tempimage); } -- cgit v1.2.3 From 21d52b5ed3206791d5a0b4adc907be75a9e5f668 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Wed, 10 Mar 2010 23:07:22 -0600 Subject: Using GIcon for setting the icons on the IDO slider. --- src/indicator-sound.c | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) (limited to 'src/indicator-sound.c') diff --git a/src/indicator-sound.c b/src/indicator-sound.c index 0b92af8..2dc6bf3 100644 --- a/src/indicator-sound.c +++ b/src/indicator-sound.c @@ -225,12 +225,23 @@ static gboolean new_slider_item(DbusmenuMenuitem * newitem, DbusmenuMenuitem * p // alternative callback mechanism which i could use again at some point. /* g_signal_connect(slider, "change-value", G_CALLBACK(user_change_value_event_cb), newitem); */ - // Set images on the ido + /* Get the primary Image */ primary_image = ido_scale_menu_item_get_primary_image((IdoScaleMenuItem*)volume_slider); - gtk_image_set_from_icon_name(GTK_IMAGE(primary_image), g_hash_table_lookup(volume_states, GINT_TO_POINTER(STATE_ZERO)), GTK_ICON_SIZE_MENU); + + /* Build a GIcon for the theme fallbacks */ + GIcon * primary_gicon = g_themed_icon_new_with_default_fallbacks(g_hash_table_lookup(volume_states, GINT_TO_POINTER(STATE_ZERO))); + gtk_image_set_from_gicon(GTK_IMAGE(primary_image), primary_gicon, GTK_ICON_SIZE_MENU); + g_object_unref(primary_gicon); + + /* Get the secondary image */ GtkWidget* secondary_image = ido_scale_menu_item_get_secondary_image((IdoScaleMenuItem*)volume_slider); - gtk_image_set_from_icon_name(GTK_IMAGE(secondary_image), g_hash_table_lookup(volume_states, GINT_TO_POINTER(STATE_HIGH)), GTK_ICON_SIZE_MENU); + /* Build a GIcon for fallbacks */ + GIcon * secondary_gicon = g_themed_icon_new_with_default_fallbacks(g_hash_table_lookup(volume_states, GINT_TO_POINTER(STATE_HIGH))); + gtk_image_set_from_gicon(GTK_IMAGE(secondary_image), secondary_gicon, GTK_ICON_SIZE_MENU); + g_object_unref(secondary_gicon); + + /* Make the widget visible to users */ gtk_widget_show_all(volume_slider); return TRUE; -- cgit v1.2.3