diff options
author | kotontrion <[email protected]> | 2024-08-21 10:56:13 +0200 |
---|---|---|
committer | kotontrion <[email protected]> | 2024-08-21 10:56:13 +0200 |
commit | 6a5fdcb8f7b8463d5a8b3d533b82ebd35d282e92 (patch) | |
tree | fc7958a22f6fc43050163c8c3dcbc9e9ce27628e | |
parent | 5db80aa88a215030ffb90239870afdf62eebaf2e (diff) |
add gicon property for easier icon usage
-rw-r--r-- | src/trayItem.vala | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/src/trayItem.vala b/src/trayItem.vala index d954f8f..bcbf8a7 100644 --- a/src/trayItem.vala +++ b/src/trayItem.vala @@ -120,6 +120,8 @@ public class TrayItem : Object { public Gdk.Pixbuf icon_pixbuf { owned get { return _get_icon_pixbuf(); } } + public GLib.Icon gicon { get; private set; } + public string item_id { get; private set; } public signal void changed(); @@ -149,6 +151,8 @@ public class TrayItem : Object { SignalHandler.disconnect(proxy, id); } }); + + update_gicon(); ready(); } catch (Error err) { @@ -165,6 +169,33 @@ public class TrayItem : Object { changed(); } + private void update_gicon() { + if(icon_name != null && icon_name != "") { + if(icon_theme_path != null && icon_theme_path != "") { + + Gtk.IconTheme icon_theme = new Gtk.IconTheme(); + string[] paths = {icon_theme_path}; + icon_theme.set_search_path(paths); + + int size = icon_theme.get_icon_sizes(icon_name)[0]; + Gtk.IconInfo icon_info = icon_theme.lookup_icon( + icon_name, size, Gtk.IconLookupFlags.FORCE_SIZE); + + if (icon_info != null) + gicon = new GLib.FileIcon(GLib.File.new_for_path(icon_info.get_filename())); + } else { + gicon = new GLib.ThemedIcon(icon_name); + } + } + else { + Pixmap[] pixmaps = proxy.Status == Status.NEEDS_ATTENTION + ? proxy.AttentionIconPixmap + : proxy.IconPixmap; + gicon = pixmap_to_pixbuf(pixmaps); + } + } + + private void refresh_all_properties() { proxy.g_connection.call.begin( proxy.g_name, @@ -189,6 +220,8 @@ public class TrayItem : Object { proxy.set_cached_property(prop_key, prop_value); } + update_gicon(); + _notify(); } catch(Error e) { //silently ignore |