📜 ⬆️ ⬇️

HiDPI in Linux

HiDPI
Aqua mine

Introduction

After years of domination of displays with a high pixel density on mobile devices, this trend has finally reached desktop laptops. In my opinion, manufacturers did not install HiDPI-matrixes mainly due to poor support for DPI, other than 96, in Windows. Fortunately, the situation has improved markedly with the release of Windows 8 with the Modern UI, although in desktop mode it is still far from ideal - people still complain about 3200 × 1800 at 13.3 "in laptops and doubt about buying a 4K UHD 23.8" monitor.

DPI and Linux

The ability to set an arbitrary DPI value dates back to the days of Xfree86, but it should be understood that this is just a value that does nothing by itself. It is read and used by programs and components, which decide how to reflect the change in DPI on the screen. If the text follows the set DPI value in 95% of cases (thanks to xft!), Then the size of the elements depends on the desktop environment and toolkits on which the applications are written.
')
GTK + 3 applications support both integer scaling of elements and fractional scaling of fonts, as well as DPI change on the fly, without restarting applications. The element scaling is controlled by the GDK_SCALE environment GDK_SCALE , and the font scaling is GDK_DPI_SCALE .
By default, fonts are scaled along with the elements. Thus, with DPI 96 and GDK_SCALE=2 , you will get the font as if it were with DPI 192. To cancel the scaling of fonts, it is enough to set the environment variable GDK_DPI_SCALE to 0.5 (for GDK_SCALE=2 ).
Qt4 does not know how to scale elements. To apply a new DPI value, a restart of the application is required.
Qt5 , starting with version 5.4, supports integer scaling of elements through the QT_DEVICE_PIXEL_RATIO environment QT_DEVICE_PIXEL_RATIO . DPI cannot be changed on the fly, as in Qt4, but work in this direction is underway and will be available with the release of Qt 5.6, as well as scaling to each monitor separately.
WxWidgets applications behave the same as GTK + 3, only they do not support scaling elements.

I tried to find out which DE can be comfortably used with HiDPI monitors. Testing was conducted on a laptop with 12.5 "1366 × 768 (125 DPI) with an external 23.8" monitor connected with a resolution of 3840 × 2160 (185 DPI).

Gnome 3



High pixel density support in Gnome 3 is implemented by double scaling of all elements and fonts, i.e. technically, the DPI is set to 192. You can explicitly set another DPI with the following command:
 gsettings set org.gnome.settings-daemon.plugins.xsettings overrides "{ 'Gdk/WindowScalingFactor':<2>, 'Gdk/UnscaledDPI':<189440> }" 

Where 189440 = 185 * 1024. And do not forget about GDK_DPI_SCALE !
All elements of the DE interface look great, standard applications too. There is no separate scaling support for each monitor.

Cinnamon



Since Cinnamon is written using GTK + 3, it has HiDPI support in much the same way as Gnome 3: double enlarging of elements, fonts. Everything looks just as good in the case of Gnome 3. As you can see, the only application on the screenshot that looks fine is VLC, it is written in Qt4. Scaling support for each monitor is also missing.

KDE 5



Most KDE applications written in QtQuick can work with any DPI. As such, the button for turning on the HiDPI mode is absent, but when the DPI value is set to 185, not only the fonts, but also the elements automatically increase. For some reason, the ability to resize many pop-up menus, for example, the Kicker main application launch menu, or the NetworkManager applet network selection dialog was removed from Plasma 2. This is inconvenient and somewhat spoils the impression of DE, but, fortunately, there are workarounds . Some applications, such as the Dolphin file manager, are still not fully ported to Qt5, so they look worse than they could when using Qt5.
The ability to use different DPI on different monitors is missing. Well, we are waiting for Qt 5.6.
In the screenshot you can see a wonderful bug in the DRI3 video subsystem, which is enabled in Fedora 22 by default - the KSnapshot screenshot shoots its own save dialog.

Mate



Mate supports setting an arbitrary DPI value. There is no scaling as such, but many applications support working with an arbitrary DPI, although they are running in some places. Icons do not scale. A good choice for owners of monitors with a DPI bound value when integer scaling is not suitable. There is no separate scaling for each monitor.

Unity



Unity is the only desktop environment that supports scaling to each monitor separately. Unfortunately, only the elements of the DE itself (only the left and the top panel, the main menu) are scaled, but not the applications, which practically does not provide any real benefit. Instead of specifying the DPI, Unity suggests choosing a scaling factor based on the base DPI value of 96. I set the slider to 1.75, thus setting the DPI to 168.
In general, the situation resembles Gnome 3, which is not surprising, since Unity is also written in GTK + 3.

Is there life with two monitors?

Although none of the toolkits and DE support monitors with different pixel densities, and everything looks either too large or too small, there is the possibility of scaling each monitor separately using X11 tools. This allows you to easily display a picture that is not too demanding on the display quality, for example, when a laptop is connected to the projector for a short time.
To implement such scaling, we need to set a virtual increased resolution on the display with a lower DPI and reduce it to the original resolution using X11:

 xrandr --output LVDS1 --pos 0x0 --scale 2x2 --fb 6572x2160 xrandr --output DP1 --scale 1x1 --pos 2732x0 

where 2x2 is the horizontal and vertical scaling coefficient, and 6572 = 1366 * 2 + 3840 is the sum of the horizontal resolution of both monitors with scaling taken into account.



Conclusion

If you use only one monitor, with double (192 DPI) or triple (288 DPI) pixel density, you can use almost any modern DE and applications without any problems. If you have a certain DPI value for which integer scaling (150, 240) is not suitable, or if you often use two monitors, only one of which has a high pixel density, then you will have to suffer and use scaling with X11, looking at the blurry fonts. It remains to be hoped that with the advent of Qt 5.6, the situation will change for the better, and there GTK + 3 will be tightened.

Utility

xsettingsd - applying DPI without restarting GTK + 3 applications from non-Gnome environments
We use high resolutions on video cards that do not support them

Source: https://habr.com/ru/post/259495/


All Articles