Xfce Wiki

Sub domains
 

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
projects:ui-scaling [2023/01/02 10:52] – [Basics] kelnosprojects:ui-scaling [2023/01/02 11:07] (current) – [Things that work] kelnos
Line 9: Line 9:
   * If you don't even have a window, you can use ''gdk_monitor_get_scale_factor()''.   * If you don't even have a window, you can use ''gdk_monitor_get_scale_factor()''.
   * Scale factors are (unfortunately) integer-only.  There's no such thing as a 1.5x scale, for example.   * Scale factors are (unfortunately) integer-only.  There's no such thing as a 1.5x scale, for example.
-  * You can connect to ''notify::scale-factor'' on a `GtkWidgetor `GdkMonitorinstance to know when you might need to reload icons at a new scale factor.+  * You can connect to ''notify::scale-factor'' on a ''GtkWidget'' or ''GdkMonitor'' instance to know when you might need to reload icons at a new scale factor.
 ===== Things that work ===== ===== Things that work =====
  
   * Any manually-loaded ''GdkPixbuf'' instances should be loaded at a width and height multiplied by the scale factor.  Then, "wrap" the pixbuf in a ''cairo_surface_t'' using ''gdk_cairo_surface_create_from_pixbuf()'', which takes the scale factor.  It can also take a ''GdkWindow'', but it's fine to pass ''NULL'' there.   * Any manually-loaded ''GdkPixbuf'' instances should be loaded at a width and height multiplied by the scale factor.  Then, "wrap" the pixbuf in a ''cairo_surface_t'' using ''gdk_cairo_surface_create_from_pixbuf()'', which takes the scale factor.  It can also take a ''GdkWindow'', but it's fine to pass ''NULL'' there.
-  * When loading themed icons, use the ''_for_scale()'' variants: ''gtk_icon_theme_lookup_icon_for_scale()'', ''gtk_icon_theme_load_icon_for_scale()'', and ''gtk_icon_theme_lookup_gicon_for_scale()'' Pass the unscaled size for the ''size'' parameter, and the UI scale factor for the ''scale'' parameter.  I also recommend passing ''GTK_ICON_LOOKUP_FORCE_SIZE''.+  * When loading themed icons, use the ''_for_scale()'' variants: ''gtk_icon_theme_lookup_icon_for_scale()'', ''gtk_icon_theme_load_icon_for_scale()'', and ''gtk_icon_theme_lookup_by_gicon_for_scale()'' Pass the unscaled size for the ''size'' parameter, and the UI scale factor for the ''scale'' parameter.  I also recommend passing ''GTK_ICON_LOOKUP_FORCE_SIZE''.
   * ''GIcon'' is a useful alternative in cases where it's awkward to pass around a scale factor (for example, in a ''GtkTreeModel'' implementation, the model shouldn't really know "view" details like the UI scale factor).  ''GIcon'' has quite a few implementation types, like ''GFileIcon'', ''GThemedIcon'', and ''GEmblemedIcon'' Even ''GdkPixbuf'' implements ''GIcon'' There's also ''GLoadableIcon'', which you can fairly easily implement if you need to do something custom.   * ''GIcon'' is a useful alternative in cases where it's awkward to pass around a scale factor (for example, in a ''GtkTreeModel'' implementation, the model shouldn't really know "view" details like the UI scale factor).  ''GIcon'' has quite a few implementation types, like ''GFileIcon'', ''GThemedIcon'', and ''GEmblemedIcon'' Even ''GdkPixbuf'' implements ''GIcon'' There's also ''GLoadableIcon'', which you can fairly easily implement if you need to do something custom.
   * If using ''GIcon'' with ''GtkImage'', you can get arbitrary sizing (that is, other sizes beyond what ''GTK_ICON_SIZE_'' offers) by using ''gtk_image_set_pixel_size()'' The code in ''GtkImage'' ignores the ''GTK_ICON_SIZE_'' sizes if the pixel size is specified.  For the pixel size, you want to specify the unscaled size.   * If using ''GIcon'' with ''GtkImage'', you can get arbitrary sizing (that is, other sizes beyond what ''GTK_ICON_SIZE_'' offers) by using ''gtk_image_set_pixel_size()'' The code in ''GtkImage'' ignores the ''GTK_ICON_SIZE_'' sizes if the pixel size is specified.  For the pixel size, you want to specify the unscaled size.