I presume the function is not returning the themed/scaled icon for the volume and I have to call gtk_icon_theme_get_default() + gtk_icon_theme_lookup_by_gicon_for_scale() to get the properly scaled theme “approved” icon.
If yes - how do I get the proper scale factor?
Or I don’t and the icon will already be scaled and theme appropriate?
Usually, we display GIcons with Gtk.Image , just set the pixel-size before setting the GIcon, and Gtk will manage to load at the most appropriate scale.
Why would it be explained there? It’s the GIO documentation: however you load an icon name from the theme is down to the icon theme.
This stuff is not documented into the icon getter because it’s part of the freedesktop platform.
You don’t: the toolkit knows the scaling factor, and is responsible for loading the correct asset given the scaling factor of the widget you’re using to display the icon.
GIcon is an abstract “icon” resource; how it is made concrete is up to the thing that loads the asset.
This can get a bit more involved if e.g. a user can drag a window between monitors with different scaling. As mentioned, offload that to the toolkit if you can.
Can you please explain what you’re trying to do with that icon?
Just display it, or save the image in a file?
The scale is determined by the monitor where the Window is displayed. If you’ve no Window, then no way to get it.
You can create a temporary Window (keep it hidden) for the sole purpose of getting the scale, but if the user has a multi-monitor setup with different scaling configured, then you’ve no way to know on which one the Window was created, so the scale value may not be the one you expect.
@gwillems,
All I want to do is to load the icon from the file.
Drawing will be in a different function and it could be in a different time.
This is why I’m confused.
Drawing something should be independent from loading something for drawing. Especially in GTK where realizing/drawing something is a requirements for getting the (proper) size.
So the program goes like this:
Get volume list on the initialization.
Get an icons of every volume during the initialization.
Main window appear.
User hit the button in the “toolbar”.
Child window appear which presents the volume list alone with the icons in a combo box.
However between 3, 4 and 5 the user can move trhe window between the monitors and by the time the drawing will happen - the scale factor can become invalid.
I can catch the appropriate signal of scale changing or window moving or whatever it is called, but that’s not a good solution.
OTOH, I’m not going to question the API that is thereto stay.
All I’m saying is that the choice is weird and ask if there is another way of getting the appropriate icons.
Or maybe there is an SVG file for that I can use or somehow acquire?