foudfou/FireTray — Issue #16: Tray icon not themable
Author: ssokolow
Created: 2012-02-14 11:48:30+00:00
State: open

On my system, I've set up an icon theme which results in all of my tray icons looking like carved depressions in the panel which only show color when attention is desired. (eg. Dropbox only showing color when syncing, Pidgin only showing color when a message is waiting, etc.)

However, FireTray seems to have hard-coded the colorful thunderbird icon, so I can't readily replace it with the "no new mail" icon I want.

The proper way to handle tray icons on Linux is to let `GtkStatusIcon` do the work. I'm not familiar with Firefox's GTK+ API wrapper and I don't know how to test any modification I'd make to your code, but I can give you an example of how to do it in PyGTK:

import gtk, gio

icon_theme = gtk.icon_theme_get_default()
icon_theme.append_search_path("/the/resolved/path/to/your/fallback/icons")

ICON_DEFAULT = gio.ThemedIcon(["indicator-messages", "applications-email-panel", "thunderbird"])
ICON_NEWMAIL = gio.ThemedIcon(["indicator-messages-new", "mail-message-new"])

statusicon = gtk.status_icon_new_from_gicon(ICON_DEFAULT)

if True: # Replace with the test for new messages
statusicon.set_from_gicon(ICON_NEWMAIL)
else:
statusicon.set_from_gicon(ICON_DEFAULT)

gtk.main() # Yes, this snippet will actually run

Here are some of the reasons you want to let `GtkStatusIcon` do as much of the work as possible:

* The active icon theme and required icon size might change when you least expect it. If given a `GtkThemedIcon` or set using an icon name, `GtkStatusIcon` will handle loading new icon files as appropriate.
* That concise example does all the necessary error handling. If it can't find any matching icons, it'll use the system's "missing icon" image.
* When using `GtkThemedIcon` or an icon name, GTK+ will figure out the file extension for you and will support every image format `GdkPixbuf` was compiled with. (Which typically means, at least, SVG, PNG, GIF, and XPM)

As for the fallback icon them you'd distribute in your XPI, you're technically supposed to reproduce the directory structure from `/usr/share/icons` inside the folder you feed to `icon_theme.append_search_path` but I couldn't get it to work with the standard "hicolor" fallback theme, so I'm relying on an old GTK+ compatibility feature where it will also check for matching icons directly inside the path you feed it.