From a4ac9617f412b6456497be0c16bf53a725b2db1a Mon Sep 17 00:00:00 2001 From: Olivier Brunel Date: Sun, 7 Oct 2018 17:40:39 +0200 Subject: [PATCH] statusnotifier: Add tweak SnForceIcons It seems there that the icons used via StatusNotifierItem might not always work (as expected) when asking the host to load an icon from the icon theme (via its name, e.g. "kalu-gray"). So, setting SnForceIcons=1 will have kalu load icons from the theme itself, then send them to the host instead of just names. Thanks to Tank-Missile; Closes #68 --- doc/kalu.pod | 19 +++++++++++++++++++ src/kalu/conf.c | 20 ++++++++++++++++++++ src/kalu/kalu.h | 3 +++ src/kalu/main.c | 32 ++++++++++++++++++++++++++++++++ src/kalu/preferences.c | 8 ++++++++ 5 files changed, 82 insertions(+) diff --git a/doc/kalu.pod b/doc/kalu.pod index 611f201..a1c2b48 100644 --- a/doc/kalu.pod +++ b/doc/kalu.pod @@ -945,6 +945,21 @@ This can be used so that the log in kalu's updater is visible by default; Else the pane is only opened when an important message is added (error, warning or info) or upon manual trigger. +=item B + +I + +This can be used so kalu will load all icons from the theme, creating the ones +missing as always, and then cache them up in memory. Then, whenever an icon +needs to be used via the StatusNotifier interface, the full icon will be sent +(else only the name would be sent if the icon was found to exist in the theme, +leaving it up to the StatusNotifierHost application to load - and optionally +resize - the icon to use). + +This might be useful when icons otherwise don't show up as expected, likely due +to differences in how applications (kalu vs StatusNotifierHost) load/resize +icons from the theme. + =back =head1 KDE STATUSNOTIFIERITEM SUPPORT @@ -978,6 +993,10 @@ StatusNotifierHost and not kalu) but also its content, since kalu doesn't know when it is shown (so it can only include the date/time of last check, not how long ago it was). +Lastly, if icons don't appear to work/show as expected, notably when trying to +use custom ones, you might wanna see B in +L|/CONFIGURATION TWEAKS> above. + =head2 References [1] http://blog.martin-graesslin.com/blog/2014/03/system-tray-in-plasma-next/ diff --git a/src/kalu/conf.c b/src/kalu/conf.c index 17844bd..1d1d1c5 100644 --- a/src/kalu/conf.c +++ b/src/kalu/conf.c @@ -1246,6 +1246,26 @@ parse_config_file (const char *file, continue; } } +#endif +#ifdef ENABLE_STATUS_NOTIFIER + else if (streq (key, "SnForceIcons")) + { + if (value[0] == '0' && value[1] == '\0') + { + config->sn_force_icons = FALSE; + debug ("config: disable forcing icons for StatusNotifier"); + } + else if (value[0] == '1' && value[1] == '\0') + { + config->sn_force_icons = TRUE; + debug ("config: enable forcing icons for StatusNotifier"); + } + else + { + add_error ("unknown value for %s: %s", key, value); + continue; + } + } #endif else { diff --git a/src/kalu/kalu.h b/src/kalu/kalu.h index 428aea1..c05ccdb 100644 --- a/src/kalu/kalu.h +++ b/src/kalu/kalu.h @@ -227,6 +227,9 @@ typedef struct _config_t { char *color_error; gboolean auto_show_log; #endif +#ifdef ENABLE_STATUS_NOTIFIER + gboolean sn_force_icons; +#endif } config_t; typedef struct _watched_package_t { diff --git a/src/kalu/main.c b/src/kalu/main.c index d67f386..765418c 100644 --- a/src/kalu/main.c +++ b/src/kalu/main.c @@ -1507,6 +1507,14 @@ main (int argc, char *argv[]) gtk_icon_theme_add_builtin_icon ("kalu", 48, pixbuf_kalu); G_GNUC_END_IGNORE_DEPRECATIONS } +#ifdef ENABLE_STATUS_NOTIFIER + else if (config->sn_force_icons) + { + debug ("Force loading icon \"kalu\" from theme for StatusNotifier"); + pixbuf_kalu = gtk_icon_theme_load_icon (icon_theme, "kalu", 48, GTK_ICON_LOOKUP_FORCE_SIZE, NULL); + sn_icon[SN_ICON_KALU] = g_object_ref (pixbuf_kalu); + } +#endif /* kalu-paused */ if (!gtk_icon_theme_has_icon (icon_theme, "kalu-paused")) @@ -1524,6 +1532,14 @@ main (int argc, char *argv[]) #endif g_object_unref (pixbuf); } +#ifdef ENABLE_STATUS_NOTIFIER + else if (config->sn_force_icons) + { + debug ("Force loading icon \"kalu-paused\" from theme for StatusNotifier"); + pixbuf = gtk_icon_theme_load_icon (icon_theme, "kalu-paused", 48, GTK_ICON_LOOKUP_FORCE_SIZE, NULL); + sn_icon[SN_ICON_KALU_PAUSED] = pixbuf; + } +#endif /* kalu-gray */ if (!gtk_icon_theme_has_icon (icon_theme, "kalu-gray")) @@ -1541,6 +1557,14 @@ main (int argc, char *argv[]) #endif g_object_unref (pixbuf); } +#ifdef ENABLE_STATUS_NOTIFIER + else if (config->sn_force_icons) + { + debug ("Force loading icon \"kalu-gray\" from theme for StatusNotifier"); + pixbuf = gtk_icon_theme_load_icon (icon_theme, "kalu-gray", 48, GTK_ICON_LOOKUP_FORCE_SIZE, NULL); + sn_icon[SN_ICON_KALU_GRAY] = pixbuf; + } +#endif if (pixbuf_kalu) g_object_unref (pixbuf_kalu); @@ -1561,6 +1585,14 @@ main (int argc, char *argv[]) g_object_unref (pixbuf); g_object_unref (pixbuf_kalu); } +#ifdef ENABLE_STATUS_NOTIFIER + else if (config->sn_force_icons) + { + debug ("Force loading icon \"kalu-gray-paused\" from theme for StatusNotifier"); + pixbuf = gtk_icon_theme_load_icon (icon_theme, "kalu-gray-paused", 48, GTK_ICON_LOOKUP_FORCE_SIZE, NULL); + sn_icon[SN_ICON_KALU_GRAY_PAUSED] = pixbuf; + } +#endif #ifdef ENABLE_STATUS_NOTIFIER debug ("create StatusNotifier"); diff --git a/src/kalu/preferences.c b/src/kalu/preferences.c index 61285ba..ba753fc 100644 --- a/src/kalu/preferences.c +++ b/src/kalu/preferences.c @@ -838,6 +838,14 @@ btn_save_cb (GtkButton *button _UNUSED_, gpointer data _UNUSED_) } #endif +#ifdef ENABLE_STATUS_NOTIFIER + /* force icons for Statusnotifier (no GUI) */ + if (new_config.sn_force_icons) + { + add_to_conf ("SnForceIcons = 1\n"); + } +#endif + /* General */ s = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (filechooser)); if (NULL == s)