(How) can I get GTK applications to scale their UI while running under a non-GNOME Wayland session? Under X11, I set GDK_SCALE and GDK_DPI_SCALE as per Gtk – 3.0: Using GTK on the X11 Window System . However, these are specific to X11 and there seems to be no equivalent for Wayland: Gtk – 3.0: Using GTK with Wayland .
You should configure your Wayland compositor to scale the output according to your needs. It will then tell GTK about the scale, and GTK will scale accordingly. This is all built into the Wayland windowing system - there is no custom GNOME protocol that makes this possible, and it should work the same on every compositor.
Scaling output can mean more than one thing. I don’t want the display to be rendered at 1920x1080 and be scaled up to 3840x2160, I want the display to be rendered at 3840x2160 and applications increase their font/UI element sizes. Are you talking about the former or the latter?
My understanding is that GDK_SCALE and GDK_DPI_SCALE causes the font/UI element sizes to be adjusted, is that right?
Could you possibly provide more information? Which Wayland protocol is used for this?
Scaling output can mean more than one thing. I don’t want the display to be rendered at 1920x1080 and be scaled up to 3840x2160, I want the display to be rendered at 3840x2160 and applications increase their font/UI element sizes. Are you talking about the former or the latter?
We are talking about the latter.
My understanding is that GDK_SCALE and GDK_DPI_SCALE causes the font/UI element sizes to be adjusted, is that right?
The GDK_SCALE variable is only for X11. It’s just for debugging/testing – when running in GNOME X11, Gtk dynamically picks up the scaling factor from XSETTINGS or GSettings. This variable is ignored on Wayland, since HiDPI was supported from the start at the protocol level.
Could you possibly provide more information? Which Wayland protocol is used for this?
You will need to read the documentation for the Wayland compositor that you’re using to find out how to configure the scale factor.
Support for HiDPI with integer scale factors is part of the Wayland core protocol. Support for fractional (non-integer) scale factors was added in the wp_fractional_scale_v1 extension.
The way the core protocol works is that the Wayland compositor sends a wl_surface::preferred_buffer_scale message to the application. Using that information, the application can decide whether it wants to render at higher resolution on a HiDPI display. If the application decides it would like to, it calls wl_surface::set_buffer_scale to let the compositor know, and allocates a higher resolution buffer according to the scale.
Note that Gtk does not support fractional scaling (yet). GNOME Shell tells apps that don’t support fractional scaling to use the next highest integer scale (e.g. 2× when the display scale is set to 175%), then the result is downscaled by the compositor.