Search code examples
gtkgtkmm3

Where are stockId gtk image stored?


Where are stockId gtk image stored ?

I use gtkmm 3.24.5.

In gtkmm I display them as :

// Note: This code is deprecated Gtk::Image image(Gtk:Stock::Yes.id, ICON_SIZE_BUTTON);

I want to kown where image is stored on disk.


Solution

  • This depends on the icon theme that is currently applied.

    On systems that conform to the Freedesktop.org Cross-Desktop Group (XDG) specification (Unix-like systems) they can be in a theme's subfolder that is located in any of the following paths (order is by precedence):

    • $HOME/.icons
    • $XDG_DATA_DIRS/icons
    • /usr/share/pixmaps

    Where $HOME is the user's home directory, and $XDG_DATA_DIRS is any path where data files are stored.

    If you'd like to find this information out programmatically, you can do something like this:

    Glib::RefPtr<Gdk::Display> display = Gtk::Widget::get_display();
    Glib::RefPtr<Gtk::IconTheme> icon_theme = Gtk::IconTheme::get_for_display(display);
    Glib::RefPtr<Gtk::IconPaintable> icon = icon_theme->lookup_icon("gtk-yes", 48);
    Glib::RefPtr<Gio::File> icon_file = icon->get_file();
    string icon_path = icon_file.get_path();
    

    Be aware that if there is no icon found that uses that name and size, the lookup_icon method will simply return an IconPaintable that renders the "missing icon".

    Since you are aware that stock icons are deprecated at this point, I recommend that you port your code to use newer techniques since you are likely to get weird results on newer systems. Someone would have to correct me, but I don't think stock icons are even included as a fallback in GNOME anymore.