Back to Home

HiDPI on Linux

hidpi · linux · cinnamon · kde 5 · plasma 5 · gnome · mate · unity

HiDPI on Linux

    HiDPI
    Aqua mine

    Introduction

    After many years of dominance of displays with high pixel density on mobile devices, this trend has finally reached laptops with desktops. In my opinion, manufacturers did not install HiDPI matrices mainly due to poor DPI support other than 96 in Windows. Fortunately, the situation improved markedly with the release of Windows 8 with 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 appeared back in 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 that decide how to reflect the DPI change on the screen. If the text follows the set DPI value in 95% of cases (thanks xft!), Then the size of the elements depends on the desktop environment used and the toolkits on which the applications are written.

    GTK + 3 applications support both integer element scaling and fractional font scaling, as well as DPI changes on the fly, without restarting applications. The scaling of the elements is controlled by the environment variable GDK_SCALE, and the scaling of the fonts is controlled by GDK_DPI_SCALE.
    By default, fonts are scaled together with elements. Thus, with DPI 96 and GDK_SCALE=2, you get the font, as if it had DPI 192. To cancel the scaling of fonts, just set the environment variable GDK_DPI_SCALEto 0.5 (for GDK_SCALE=2).
    Qt4 does not know how to scale elements. Applying a new DPI value requires restarting the application.
    Qt5 , starting with version 5.4, supports integer scaling of elements through an environment variable 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 for each monitor separately.
    WxWidgets applications behave the same as GTK + 3, but do not support scaling elements.

    I tried to figure out which DEs can be used comfortably with HiDPI monitors. Testing was carried out 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



    Support for high pixel density 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, HiDPI support is implemented in much the same way as Gnome 3: double magnification of elements, fonts. Everything looks just as good, as in the case of Gnome 3. As you can see, the only application in the screenshot that looks small 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 enabling HiDPI mode is absent, but when you set the DPI value 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 main Kicker application launch menu, or the NetworkManager applet network selection dialog, was removed from Plasma 2. This introduces inconvenience 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 DPIs on different monitors is missing. Well, wait for Qt 5.6.
    In the screenshot you can see a wonderful bug of the DRI3 video subsystem, which is used by default in Fedora 22 - the KSnapshot screenshoter removed its own save dialog.

    Mate



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

    Unity



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

    Is there life with two monitors?

    Although not one of the toolkits and DE supports monitors with different pixel densities, and everything looks either too large or too small, it is possible to scale each monitor separately using X11. This allows you to display a picture that is not too demanding on the quality of display without special problems, for example, when the laptop is connected to the projector for a short time.
    To implement this 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 taking into account scaling.



    Conclusion

    If you use only one monitor with a double (192 DPI) or triple (288 DPI) pixel density, then you can use almost any modern DE and application without any problems. If you have some kind of DPI limit value for which integer scaling is not suitable (150, 240), or if you often use two monitors, only one of which is with a high pixel density, you will have to suffer and use scaling using X11, looking at 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.

    Usefulness

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

    Read Next