Problem with icons when updating a gnome-shell extension to version 44

I have an extension which uses changing custom icons (from bundled PNGs) in the top bar. I had previously used Gtk.IconTheme to allow this to be potentially overridden with an icon theme. My upload for this extension was rejected because I should now be using St.IconTheme, but I can find no help beyond the initial hint that I add my extension’s icon path to the search path.

In particular, I have hung my extension off a button using an St.Icon. Having created a new St.IconTheme and appended my icon path to its search path, how can I fetch a new icon and apply it to the St.Icon. The only attempt that does not err was mysticon.set_icon_name(newname) but that just gives me a blank icon, so there must be one or more extra steps required to use that.

Does anyone know how to make this work? I could just revert to not supporting themed icons and only use Gio.FileIcon.new(path) and set_gicon() as I currently do as a fallback, but that seems a step backwards.

The “default” St.IconTheme is currently a private member of the default St.TextureCache. I’m not sure, but it may be possible to use a method like St.TextureCache.load_gicon() to preload icons by passing it a series of GFileIcon’s.

At the moment accessing the default St.IconTheme isn’t possible, so you’d have make calls to St.IconTheme.load_icon() on your dedicated instance and apply the result to the actor in question if you want to do it that way.

Thanks; however, load_gicon() gives me a GdkPixbuf.Pixbuf and I still can’t figure out how that could be applied to a Gio.Icon or St.Icon; I seem to have “generic icon wrapper” classes on the left and near raw-bytes on the right, and I just can’t see how to connect the dots.

I’m not at all fussed how I do it, all I’m trying to [re]achieve is being able to change the icon in my extensions button (which is currently an St.Icon that I try to change via set_gicon()). I’d previously get the icon path from Gtk.IconTheme.get_default() or fall back to my extension’s path, and then use Gio.FileIcon.new() to get a Gio.Icon to use.

I just can’t see how to get anything out of St.IconTheme that I can then apply to an St.Icon.

.

Ah, well Gio.Icon is actually an interface and GdkPixbuf.Pixbuf implements that interface, so you can just pass it to St.Icon:gicon.

I’m not 100% about how St.TextureCache works in tandem with St.IconTheme, but it seems like St.TextureCache.load_gicon()should result in it being cached and passing the Gio.Icon to St.Icon afterwards should skip the loading.

For St.IconTheme, you can call St.IconTheme.lookup_by_gicon(), which returns a St.IconInfo you can call St.IconInfo.load_icon() on to get the rendered Gio.Icon in the form of a GdkPixbuf.Pixbuf.

Ok thanks, I’ll have a play with that info tomorrow.

Q though: what is St.Icon:gicon, that’s not a syntax I recognise?

Oh, that’s a “standard” documentation format, or way of saying:

“the gicon property of the Icon class in the St library”

Another one for signals is GObject.Object::notify.

This topic was automatically closed 45 days after the last reply. New replies are no longer allowed.