Question
I'm trying to retrieve the (string) icon name(s) corresponding to a given (string) Gtk stock ID.
Example
Gtk stock id 'gtk-go-forward' has two corresponding icon names, 'gtk-go-forward-ltr' and 'gtk-go-forward-rtl'. I'd like to retrieve either:
- both icon names 'gtk-go-forward-ltr' and 'gtk-go-forward-rtl' given the ID 'gtk-go-forward'; OR
- just the icon name 'gtk-go-forward-ltr' (the "appropriate" one for my text direction).
Potential restrictions
I'm using the gobject introspection API, not the base C one.
Rationale (optional to read)
I'm trying to make a St.Icon
for the icon specified by the stock ID, but at a largish size (96 px).
I can use gtk_icon_set_render_icon
with the stock ID 'gtk-go-forward' directly like so (it picks the LTR version) (the syntax is GNOME javscript but this is irrelevant to the quesiton; I'm using the GObject introspection API):
let style = Gtk.Widget.get_default_style();
let iconset = style.lookup_icon_set('gtk-go-forward');
let icon = new St.Icon({
gicon: iconset.render_icon(gtkStyle, Gtk.TextDirection.LTR,
Gtk.StateType.NORMAL, Gtk.IconSize.DIALOG,
null, null),
icon_type: St.IconType.FULLCOLOR,
icon_size: 96
});
This will give me an icon for stock ID 'gtk-go-forward' (it picks 'gtk-go-forward-ltr'), but the icon is very fuzzy.
Alternatively if I feed in the icon name 'gtk-go-forward-ltr' directly, the icon is not fuzzy:
let icon = new St.Icon({
gicon: Gio.ThemedIcon.new_with_default_fallbacks('gtk-go-forward-ltr'),
icon_type: St.IconType.FULLCOLOR,
icon_size: 96
});
So in summary, I think that my best bet at getting a large, non-fuzzy icon is to find the icon name for the stock ID, rather than using the stock ID (feeding gtk-go-forward
to the second method above produces the "missing icon" icon as it is not a valid icon name).
In the picture above the top icon uses the first method (stock ID with render_icon) and the bottom icon uses the second method (use the icon name directly). Big difference in clarity.