How are icon names translated in gtk?

I’m trying to understand how icon names are translated in gtk, and not having much luck. Can anybody point me to an explanation? Tutorial, blog, book whatever? Or even the code itself?

I mean if I write

gtk_button_new_from_icon_name ("icon-name", size);

How is the string “icon-name” translated into an actual filename (and then into an object). I understand about /usr/share/icons and the Icon Theme Specification but the filenames under the directory often have additional components such as -symbolic and so don’t match the exact name in the spec. How are they matched up and how is the choice made when there are multiple possibilities?

Named icons follow the XDG icon theme specification.

If you specify icon-name as the name, then the icon will be matched to the current icon theme name, and to the size specified when looking up the icon—using gtk_icon_theme_lookup_icon(). In absence of an explicit size, like gtk_image_set_pixel_size() the size is computed by the style.

The -symbolic bit is a separate GTK extension that hasn’t been codified in the specification; it’s a suffix, so if you select icon-name-symbolic you’ll get the symbolic icon if it exists, and if it doesn’t you’ll get icon-name.

1 Like

Thanks for the fast reply. It’ll take me a while to digest!

Sorry, I wasn’t clear. I’m interested in the answer for GTK3 but I think your answer is specific to GTK4?

The behaviour is the same in both GTK3 and GTK4: icon name resolution hasn’t changed across major versions.

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