Skip to content

Commit

Permalink
statusnotifier: Add tweak SnForceIcons
Browse files Browse the repository at this point in the history
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
  • Loading branch information
jjk-jacky committed Oct 15, 2018
1 parent 7e1bf75 commit a4ac961
Show file tree
Hide file tree
Showing 5 changed files with 82 additions and 0 deletions.
19 changes: 19 additions & 0 deletions doc/kalu.pod
Original file line number Diff line number Diff line change
Expand Up @@ -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<SnForceIcons = 1>

I<Only if kalu was compiled with --enable-status-notifier>

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
Expand Down Expand Up @@ -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<SnForceIcons> in
L<B<CONFIGURATION TWEAKS>|/CONFIGURATION TWEAKS> above.

=head2 References

[1] http://blog.martin-graesslin.com/blog/2014/03/system-tray-in-plasma-next/
Expand Down
20 changes: 20 additions & 0 deletions src/kalu/conf.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down
3 changes: 3 additions & 0 deletions src/kalu/kalu.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
32 changes: 32 additions & 0 deletions src/kalu/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -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"))
Expand All @@ -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"))
Expand All @@ -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);
Expand All @@ -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");
Expand Down
8 changes: 8 additions & 0 deletions src/kalu/preferences.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit a4ac961

Please sign in to comment.