GTK UNIT SCALE: tweak density and scaling of GTK UIs
2025-11-01 22:00:00 JST
GTK's widget spacing and padding can sometimes seem excessive, but it is particularly problematic on mid-DPI displays. These screens fall into that awkward range where 1x scaling makes elements too small while 2x scaling creates excessive spacing.
gtk-unit-scale is a quick'n'dirty workaround. It introduces a new environment variable, GTK_UNIT_SCALE, to offer more flexible scaling control. This patch allows you to adjust widget dimensions without touching text scaling.
Move your mouse over the image to see the impact of GTK_UNIT_SCALE=0.8:
How It Works
The GTK_UNIT_SCALE variable allows you to scale all dimension units in GTK applications while maintaining the original text sizes (assuming proper CSS styling). This provides a more balanced approach to scaling than text-only solutions.
export GTK_UNIT_SCALE=0.9
To apply the change system-wide, set the variable in /etc/environment:
GTK_UNIT_SCALE=0.9
In practice, this factor is applied to all pixel lengths when computing a dimension from CSS styles. This is a cheap way to achieve an effect similar to CSS' "display" or "device independent" pixels.
Because text is not affected, it complements nicely the text-scaling-factor offered by GTK, which should be set to a value close to GTK_UNIT_SCALE:
- via "Gnome Tweaks", change the "Scaling Factor" in the "Fonts" tab
- via "gsettings", changing the key
org.gnome.desktop.interface.text-scaling-factor:sh gsettings get/set org.gnome.desktop.interface text-scaling-factor
This approach offers several advantages:
- More compact widget layouts without affecting text readability
- Better utilization of screen space
- A potential alternative to fractional scaling with its associated artifacts
- Preservation of text size ratios while adjusting widget dimensions
I've tested it on two different display configurations:
- A 15-inch MacBook Air (224 PPI) where it significantly improved usability
- A 27-inch 4K display (163 PPI) where it provided noticeable benefits
Implementation
The patch is available for both GTK 3 and GTK 4:
For convenience, the repository packages both versions for Arch and Fedora: https://github.com/let-def/gtk-unit-scale
Usage Instructions
Clone the repository and build GTK with the patch applied:
git clone --single-branch --branch=packaging https://github.com/let-def/gtk-unit-scale
cd gtk-unit-scale
# For Archlinux
make archlinux-gtk3 archlinux-gtk4
# For Fedora
make fedora-gtk3
# Manually install the generated packages
make fedora-gtk4
# Manually install the generated packages
Launch GTK applications with the GTK_UNIT_SCALE environment variable set to a value between 0.8 and 1.0.
Considerations
While this solution has worked well in my testing, it is worth noting that:
- Values below 0.75 may cause visual artifacts
- This is not an official GTK feature and comes without guarantees
- The patch is maintained based on personal usage needs
Conclusion
This unit scaling approach provides a practical solution for improving GTK application usability, especially on mid-DPI displays. While not a perfect solution, it offers a viable alternative to fractional scaling. I hope this can help you too if you encountered these problems.