Uninstalled icon theme icons in tests

With my quests to repair my screenshots I also like to get my icons back.

In my builddir I have:

tree icons/
icons/
├── gnome
│   ├── 16x16
│   │   └── ...
│   ├── 22x22
│   │   └── ...
│   ├── 24x24
│   │   └── ...
│   ├── 32x32
│   │   └── ...
│   ├── 48x48
│   │   └── ...
│   ├── 64x64
│   │   └── ...
│   └── scalable
│       └── ...
└── hicolor
    ├── 16x16
    │   └── ...
    ├── 24x24
    │   └── ...
    ├── 256x256
    │   └── ...
    ├── 48x48
    │   └── ...
    └── scalable
        └── ...

Those get installed when installing (and then also show up in the UI), but I’d like to access them from the tests already. For that so far I was just setting:

	XDG_CACHE_HOME=$(abs_top_builddir)
	XDG_DATA_HOME=$(abs_top_builddir)

and it was good. This does not work anymore :/. I added some debug logging:

theme is "Adwaita", icon-theme is "Adwaita", "(null)"
...
dk_pixbuf_new_from_theme: Couldn't load buzztrax_menu_source_machine 16x16 icon: Icon 'buzztrax_menu_source_machine' not present in theme Adwaita

but

find icons/ -name "buzztrax_menu_source_machine*"
icons/gnome/24x24/buzztrax_menu_source_machine.png
icons/gnome/16x16/buzztrax_menu_source_machine.png
icons/hicolor/24x24/buzztrax_menu_source_machine.png
icons/hicolor/16x16/buzztrax_menu_source_machine.png

I’ve tried a bunch of things:

    if ((display_manager = gdk_display_manager_get ())) {
      GdkScreen *default_screen;
      GtkSettings *default_settings;
      gchar *theme_name, *icon_theme_name, *fallback_icon_theme_name;

      default_display = gdk_display_manager_get_default_display (display_manager);
      if ((default_screen = gdk_display_get_default_screen (default_display))) {

        if ((default_settings = gtk_settings_get_for_screen (default_screen))) {
          g_object_get (default_settings, "gtk-theme-name", &theme_name,
              "gtk-icon-theme-name", &icon_theme_name,
              "gtk-fallback-icon-theme", &fallback_icon_theme_name, NULL);
          LOG_INFO ("theme is \"%s\", icon-theme is \"%s\", \"%s\"", theme_name,
              icon_theme_name, fallback_icon_theme_name);

          g_object_set (default_settings, "gtk-icon-theme-name", "gnome",
              "gtk-fallback-icon-theme", "hicolor",  NULL);
         ....

Setting the icon-theme or fallback-icon-theme has no effect. When loading the icon it still claims that ‘Adwaita’ is the icon-theme. What changed that this is not honored in gtk-3 anymore and whats the new way to achieve this?

I also looked at gtk_icon_theme_prepend_search_path and the docs for gtk_icon_theme_set_search_path() hint that it looks for an index.theme file.
So this is not what I cam looking for (I need a path for the icons and not for the icon-theme).

When I run with GTK_DEBUG=“icontheme” and redirect output to a log and then:

> grep /home/ensonic/ /tmp/gtk.log
Gtk-Message: 12:19:56.312: look for icon cache in /home/ensonic/projects/buzztrax/buzztrax/icons
Gtk-Message: 12:19:58.476: look for icon cache in /home/ensonic/projects/buzztrax/buzztrax/icons
Gtk-Message: 12:20:00.791: look for icon cache in /home/ensonic/projects/buzztrax/buzztrax/icons
Gtk-Message: 12:20:03.304: look for icon cache in /home/ensonic/projects/buzztrax/buzztrax/icons
Gtk-Message: 12:20:06.756: look for icon cache in /home/ensonic/projects/buzztrax/buzztrax/icons

Then I see that it checks the icon-dir I mentioned at the start of my post. There is no cache, but a cache is optional, right?

Also if I create a cache there (gtk-update-icon-cache -f -t icons/) it finds it, but still does not consider the icons.

Shouldn’t they be in a subdirectory below the size dir?

Usually app icons are in ${datadir}/icons/${theme}/${size}/apps, then icons used inside apps would go in ${datadir}/icons/${theme}/${size}/actions, ${datadir}/icons/${theme}/${size}/status, etc…

You might be able to get away without the subdirectory, if you create a theme index for your icon directory.

Looking at /usr/share/icons/hicolor/index.theme, it contains:

[Icon Theme]
Name=Hicolor
Comment=Fallback icon theme
Hidden=true
Directories=16x16/actions,16x16@2/actions,16x16/animations,16x16@2/animations,16x16/apps,16x16@2/apps,16x16/categories,[...]

[16x16/actions]
Size=16
Context=Actions
Type=Threshold

[16x16/animations]
Size=16
Context=Animations
Type=Threshold

etc.

What if you create your own? With:

[Icon Theme]
Name=test
Comment=Test icon theme
Hidden=true
Directories=gnome/16x16,gnome/24x24,hicolor/16x16,hicolor/24x24,[...]

[gnome/16x16]
Size=16
Context=Applications
Type=Threshold

[gnome/24x24]
Size=24
Context=Applications
Type=Threshold

[hicolor/16x16]
Size=16
Context=Applications
Type=Threshold

[hicolor/24x24]
Size=24
Context=Applications
Type=Threshold

Not sure if having multiple entries for the same size + same context is legal, though.

Thanks, I added an extra ‘apps’ folder to the local directory layout and it works again. Not sure what changed in gtk in the way icons are searched.

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