From b531c560bb046c359598a07a08cfaeaa973090c2 Mon Sep 17 00:00:00 2001 From: Krzysztof Klimonda Date: Sat, 20 Mar 2010 00:55:03 +0100 Subject: Fix the missing icon on theme change if old icon has different name Some applications (like Transmission) use different icon name for Notification Area to display monochrome icon. To make sure that the icon we display exists after user changes theme use indicator_image_helper () from libindicator to keep track of the icon. --- src/libappindicator/app-indicator.c | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/src/libappindicator/app-indicator.c b/src/libappindicator/app-indicator.c index 1dce0a0..2e6d8d1 100644 --- a/src/libappindicator/app-indicator.c +++ b/src/libappindicator/app-indicator.c @@ -35,6 +35,8 @@ License version 3 and version 2.1 along with this program. If not, see #include #include +#include + #include "libappindicator/app-indicator.h" #include "libappindicator/app-indicator-enum-types.h" @@ -812,6 +814,13 @@ fallback_timer_expire (gpointer data) return FALSE; } +/* emit a NEW_ICON signal in response for the theme change */ +static void +theme_changed_cb (GtkIconTheme * theme, gpointer user_data) +{ + g_signal_emit (user_data, signals[NEW_ICON], 0, TRUE); +} + /* Creates a StatusIcon that can be used when the application indicator area isn't available. */ static GtkStatusIcon * @@ -827,6 +836,8 @@ fallback (AppIndicator * self) G_CALLBACK(status_icon_changes), icon); g_signal_connect(G_OBJECT(self), APP_INDICATOR_SIGNAL_NEW_ATTENTION_ICON, G_CALLBACK(status_icon_changes), icon); + g_signal_connect(G_OBJECT(gtk_icon_theme_get_default()), + "changed", G_CALLBACK(theme_changed_cb), self); status_icon_changes(self, icon); @@ -849,22 +860,26 @@ static void status_icon_changes (AppIndicator * self, gpointer data) { GtkStatusIcon * icon = GTK_STATUS_ICON(data); + GtkImage *image = indicator_image_helper (self->priv->icon_name); switch (app_indicator_get_status(self)) { case APP_INDICATOR_STATUS_PASSIVE: gtk_status_icon_set_visible(icon, FALSE); - gtk_status_icon_set_from_icon_name(icon, app_indicator_get_icon(self)); + gtk_status_icon_set_from_pixbuf(icon, gtk_image_get_pixbuf (image)); break; case APP_INDICATOR_STATUS_ACTIVE: - gtk_status_icon_set_from_icon_name(icon, app_indicator_get_icon(self)); + gtk_status_icon_set_from_pixbuf(icon, gtk_image_get_pixbuf (image)); gtk_status_icon_set_visible(icon, TRUE); break; case APP_INDICATOR_STATUS_ATTENTION: - gtk_status_icon_set_from_icon_name(icon, app_indicator_get_attention_icon(self)); + gtk_status_icon_set_from_pixbuf(icon, gtk_image_get_pixbuf (image)); gtk_status_icon_set_visible(icon, TRUE); break; }; + g_object_ref_sink (image); + g_object_unref (image); + return; } -- cgit v1.2.3 From 16a9a730a4001585e87dc3c680081fd8b205b9a2 Mon Sep 17 00:00:00 2001 From: Krzysztof Klimonda Date: Mon, 22 Mar 2010 17:41:35 +0100 Subject: don't use indicator_image_helper () Remove indicator_image_helper () call and use g_themed_icon_new_with_default_fallbacks () directly. We don't need the logic embedded in indicator_image_helper () for the GtkStatusIcon as it takes care of changing icon size for us. --- src/libappindicator/app-indicator.c | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/src/libappindicator/app-indicator.c b/src/libappindicator/app-indicator.c index 2e6d8d1..dc99936 100644 --- a/src/libappindicator/app-indicator.c +++ b/src/libappindicator/app-indicator.c @@ -35,8 +35,6 @@ License version 3 and version 2.1 along with this program. If not, see #include #include -#include - #include "libappindicator/app-indicator.h" #include "libappindicator/app-indicator-enum-types.h" @@ -860,25 +858,26 @@ static void status_icon_changes (AppIndicator * self, gpointer data) { GtkStatusIcon * icon = GTK_STATUS_ICON(data); - GtkImage *image = indicator_image_helper (self->priv->icon_name); + GIcon *themed_icon = + g_themed_icon_new_with_default_fallbacks (self->priv->icon_name); switch (app_indicator_get_status(self)) { case APP_INDICATOR_STATUS_PASSIVE: gtk_status_icon_set_visible(icon, FALSE); - gtk_status_icon_set_from_pixbuf(icon, gtk_image_get_pixbuf (image)); + gtk_status_icon_set_from_gicon(icon, G_ICON (themed_icon)); break; case APP_INDICATOR_STATUS_ACTIVE: - gtk_status_icon_set_from_pixbuf(icon, gtk_image_get_pixbuf (image)); + gtk_status_icon_set_from_gicon(icon, G_ICON (themed_icon)); gtk_status_icon_set_visible(icon, TRUE); break; case APP_INDICATOR_STATUS_ATTENTION: - gtk_status_icon_set_from_pixbuf(icon, gtk_image_get_pixbuf (image)); + gtk_status_icon_set_from_gicon(icon, G_ICON (themed_icon)); gtk_status_icon_set_visible(icon, TRUE); break; }; - g_object_ref_sink (image); - g_object_unref (image); + g_object_ref_sink (themed_icon); + g_object_unref (themed_icon); return; } -- cgit v1.2.3 From c80fe4d00d01c4498771c79419aa3c54567a1eec Mon Sep 17 00:00:00 2001 From: Krzysztof Klimonda Date: Mon, 22 Mar 2010 17:53:02 +0100 Subject: Move g_signal_connect for the theme-changed signal to app_indicator_init () --- src/libappindicator/app-indicator.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/libappindicator/app-indicator.c b/src/libappindicator/app-indicator.c index dc99936..43475fb 100644 --- a/src/libappindicator/app-indicator.c +++ b/src/libappindicator/app-indicator.c @@ -144,6 +144,8 @@ static void watcher_proxy_destroyed (GObject * object, gpointer data); static void client_menu_changed (GtkWidget *widget, GtkWidget *child, AppIndicator *indicator); static void submenu_changed (GtkWidget *widget, GtkWidget *child, gpointer data); +static void theme_changed_cb (GtkIconTheme * theme, gpointer user_data); + /* GObject type */ G_DEFINE_TYPE (AppIndicator, app_indicator, G_TYPE_OBJECT); @@ -335,6 +337,9 @@ app_indicator_init (AppIndicator *self) } dbus_g_connection_ref(priv->connection); + g_signal_connect(G_OBJECT(gtk_icon_theme_get_default()), + "changed", G_CALLBACK(theme_changed_cb), self); + self->priv = priv; return; @@ -834,8 +839,6 @@ fallback (AppIndicator * self) G_CALLBACK(status_icon_changes), icon); g_signal_connect(G_OBJECT(self), APP_INDICATOR_SIGNAL_NEW_ATTENTION_ICON, G_CALLBACK(status_icon_changes), icon); - g_signal_connect(G_OBJECT(gtk_icon_theme_get_default()), - "changed", G_CALLBACK(theme_changed_cb), self); status_icon_changes(self, icon); -- cgit v1.2.3 From 85400dc1f4b95227f9160b96e30841e1e90ee60a Mon Sep 17 00:00:00 2001 From: Krzysztof Klimonda Date: Mon, 22 Mar 2010 18:07:32 +0100 Subject: Use app_indicator_get_icon/app_indicator_get_attention_icon methods to get the right icon. --- src/libappindicator/app-indicator.c | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/src/libappindicator/app-indicator.c b/src/libappindicator/app-indicator.c index 43475fb..38f095f 100644 --- a/src/libappindicator/app-indicator.c +++ b/src/libappindicator/app-indicator.c @@ -861,26 +861,33 @@ static void status_icon_changes (AppIndicator * self, gpointer data) { GtkStatusIcon * icon = GTK_STATUS_ICON(data); - GIcon *themed_icon = - g_themed_icon_new_with_default_fallbacks (self->priv->icon_name); + GIcon *themed_icon = NULL; switch (app_indicator_get_status(self)) { case APP_INDICATOR_STATUS_PASSIVE: + themed_icon = + g_themed_icon_new_with_default_fallbacks (app_indicator_get_icon (self)); gtk_status_icon_set_visible(icon, FALSE); - gtk_status_icon_set_from_gicon(icon, G_ICON (themed_icon)); + gtk_status_icon_set_from_gicon(icon, themed_icon); break; case APP_INDICATOR_STATUS_ACTIVE: - gtk_status_icon_set_from_gicon(icon, G_ICON (themed_icon)); + themed_icon = + g_themed_icon_new_with_default_fallbacks (app_indicator_get_icon (self)); + gtk_status_icon_set_from_gicon(icon, themed_icon); gtk_status_icon_set_visible(icon, TRUE); break; case APP_INDICATOR_STATUS_ATTENTION: - gtk_status_icon_set_from_gicon(icon, G_ICON (themed_icon)); + themed_icon = + g_themed_icon_new_with_default_fallbacks (app_indicator_get_attention_icon (self)); + gtk_status_icon_set_from_gicon(icon, themed_icon); gtk_status_icon_set_visible(icon, TRUE); break; }; - g_object_ref_sink (themed_icon); - g_object_unref (themed_icon); + if (themed_icon) { + g_object_ref_sink (themed_icon); + g_object_unref (themed_icon); + } return; } -- cgit v1.2.3 From 26a1f2691a9086347b76002edb4304728f481f0c Mon Sep 17 00:00:00 2001 From: Krzysztof Klimonda Date: Thu, 25 Mar 2010 16:29:28 +0100 Subject: remove g_object_ref_sink call from status_icon_changes --- src/libappindicator/app-indicator.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/libappindicator/app-indicator.c b/src/libappindicator/app-indicator.c index 38f095f..ffab463 100644 --- a/src/libappindicator/app-indicator.c +++ b/src/libappindicator/app-indicator.c @@ -884,10 +884,8 @@ status_icon_changes (AppIndicator * self, gpointer data) break; }; - if (themed_icon) { - g_object_ref_sink (themed_icon); + if (themed_icon) g_object_unref (themed_icon); - } return; } -- cgit v1.2.3