📜 ⬆️ ⬇️

HiDPI in Linux, in particular in KDE

Monitors in 4K resolution are no longer considered the lot of the bourgeoisie and are gradually entering the life of the common people. As well as other high-resolution monitors. A couple of years ago, I said about the support of such monitors in Linux that “no, rather than yes.” There was some kind of support, but the number of glitches with it made the whole process meaningless, and really wanted to switch the monitor to a smaller resolution. What some 4K monitors do not allow to do in Linux so far. The fact is that NVidia drivers, when connected via DisplayPort, naively believe in the monitor's EDID, and if only one maximum resolution is registered there, they are not allowed to install any other. You must either roll back to the Nouveau, or configure HiDPI. We will customize! (The article is intended for a person who knows the basics of Linux and what is the X server).

About DPI in general and HiDPI in particular


DPI (dots per inch) is a value that says how many pixels of a screen is the physical centimeter of its area. If the monitor works in non-native resolution, then we are talking about virtual pixels of resolution. From ancient times to quite recently, the value in 96 DPI was the standard - that is, if ordinary monitors differed from it, then so much so that it could be neglected. 120 DPI was once the maximum value that was usually tested.

Not surprisingly, for so many years, program developers have taken this value as an unshakable constant. Suddenly monitors came with 160-192 DPI and started. All programs that at least some size in the interface were set in pixels, received panels hitting each other, signatures, cropped to the first letter, and buttons, for the successful pressing of which you need to give a cash prize.

The word HiDPI refers to the situation on monitors with DPI> 160. The DPI of the operating system is not necessarily the DPI of the screen. On the contrary, the DPI of the system can be rotated in order to make the interface larger and smaller. Moreover, the systems distinguish DPI total, DPI fonts and DPI, given to full-screen applications.
')

What about the others?


Makos rescued her authoritarian rule. Since almost all programs create their own interface through the same API, it was simply corrected, and it worked out right away. Separate indestructible shoals only emphasize how generally all is well.

Android was born on systems with a wide scatter of DPI, so he knew everything from the cradle, and the textbooks for programmers took it all into account.

Windows allowed to rotate DPI fonts always. That's just the DPI graphics from this has not changed. Individual elements were resized because they were tied to the size of the font, or the screen. But the dimensions specified in pixels did not move. In Win 10, finally, there was normal support for HiDPI, but only for programs written for Win 10. For the rest, a crutch was written, making just a graphic increase in the program window with translation of the position of clicks. Zooming out makes the window blurry, and the translation is crooked. Worse, this magnification tries to run for fullscreen applications, too, so to play it, you need to turn it off, and to work, turn it on.

What about Linux?


And in Linux, as always, orgy. We have two major GUI dial-ups (Qt and GTK), each of which relatively recently experienced rewriting from scratch, so the old and new versions are still in use. Plus a few smaller sets (EFL, wxWidgets). Plus, there are several languages ​​that use their own tools, for example, Java. Plus, there are several ancient libraries, on which nobody already writes, but the necessary software on them still happens. (GTK 1, Motif) Even if the X server and the window manager correctly handle the DPI, it’s not a fact that the whole zoo will accept this information and work fine.

There is a lot to dislike Ubuntu with Unity, but one thing I have to say. I do not know how to configure HiDPI in Unity because everything always worked out of the box. All other DE: Cinnamon, KDE, XFCE, also have a corresponding flag. This flag configures DE itself, applications written in its main library (only the new version) and a couple of flags for Qt / GTK. And the rest is all sideways. As a result, for example, in the players, the Play button remains tiny. And the tray icons are small, but not all. A year after such a system - and a person in Overwatch only plays for McCrack, because a person has pixel pixel accuracy on a mouse and he hates everyone.

I will tell you how to configure KDE. Not as according to the instructions, but so that everything worked. Deadbeef, Yakuake, Blender. I checked it mostly in Archa. In other distributions, it may be that something of what I describe is already done or done differently. Think with your head or write in the comments - let's figure it out.

X Setup


The first thing you need to check, and if I know X, that we have HiDPI? To do this, we need a xdpyinfo xdpyinfo - it is in turnips. Set, if not set, the native resolution of the monitor, (and restart X). Launch in the console inside X (that is, not Ctrl-Alt-F *).

 xdpyinfo | grep -B 2 resolution screen #0: dimensions: 3840x2160 pixels (621x341 millimeters) resolution: 157x161 dots per inch 

We see three pairs of values ​​- screen resolution, real screen sizes, and DPI (separately vertically and horizontally). If all three pairs look like truth, then turn away from the monitor and give praise to the highest entity of your choice; for if xdpyinfo returns nonsense and DPI = 96, then your higher nature sends you ordeal.

The most common causes of irregular DPI are EDID curves and branded video card firewood. I will not say anything about ATi video cards, since I’m avoiding them. Not that they are bad, but ATi + Linux = superfluous problems. With Intel, everything should work by itself. NVidia, until recently, stubbornly defiled DPI. First, turn off G-sync in nvidia-settings , anyway, no composite manager is friends with it. If it does not help, enable KMS. Kernel Mode Setting is the method by which the screen resolution is managed by the Linux kernel, and not by X. In addition to the direct appointment, it allows you to bypass a lot of the buggy code 20 years ago in the Xs. Unfortunately, the procedure for enabling KMS on Nvidia’s proprietary drivers is distributionally dependent, so I’ll only describe in general terms. You need to add the modules nvidia, nvidia_modeset, nvidia_uvm, nvidia_drm to the initramfs, rebuild it, and then add the kernel parameter nvidia-drm.modeset=1 . Google

If you didn’t understand anything in the previous paragraph, then you can simply give up NVidia brand firewood and use Nouveau for now - there is a KMS out of the box. In Kubunt, this is done through a program that manages the drivers.

If all of the above did not help and xdpyinfo still writes garbage, then maybe not the video drivers, but the monitor's EDID curves are to blame. First run xrandr --dpi 192 in the same console. And run some program. If it has become more, then the method works. Paste this command into .xprofile and restart .xprofile In the future I will talk a lot about .xprofile . This is a file in the home folder of each user who customizes the work of graphic applications. If not, just create it: touch ~/.xprofile . If everything worked - Hooray! If not, first verify that your distribution does not have .xprofile cut out from KDE. For which, add something like touch ~/net_ne_vyrezali and reload again.

Still not working? Let's write DPI in Iksa manually. Create, if not already, the file /etc/X11/xorg.conf.d/90-monitor.conf and write to it:

 Section "Monitor" Identifier "Prikolny monitor" DisplaySize 286 179 #   EndSection 

And for branded firewood Nvidia

 Section "Monitor" Identifier "Prikolny monitor" Option "DPI" "192 x 192" EndSection 

Please note that everywhere I put the forced DPI value at 192, more precisely at any value multiple of 96. It works more precisely than the real DPI, because gladiolus. Here the designer's paradox works:


I wrote the stupid name of the monitor so that in all graphical utilities it was clear that our setting is readable and tries to be applied.

Save, restart X and rejoice. Or we drink bitter and wait for Wayland to finish.

Setup in KDE


So finally, we configure HiDPI in KDE correctly. In the menu → System Settings → Display and Monitor at the very bottom there is a large Scale Display button. By pressing it, a window with a single Scale slider comes out. Now attention! If you did not manage to adjust the DPI in X, close this article, set the slider value to taste, and rejoice in what works. And what does not work - reconcile (This is usually Chrome, Skype, QtCreator, Yakuake, GTK).

If you have the correct DPI in X, then do not touch this slider! Ideally, even, do not twist it back and forth, because it seems that he is writing something somewhere. Close this window nafig. According to an article in the blog of the creator of this slider (salt in the comments), it overrides the system DPI and sets a few more variables. The problem is that not all programs see this redefinition, and it turns out to be porridge. Therefore, we will not touch the slider, and adjust everything manually.

In general, at this stage, if the DPI is correct, then everything should be quite large. We pass in System Settings → Fonts . By default, there is a font size of 11. If you need 10-14 to achieve harmony - put it, the applications will be pulled. If more or less - it makes sense to try podshamanit system DPI as it is stated above. Below is the Force Font DPI field. You can tweak it, if you want, but note that not all applications read this value. Not even that. Some applications do not read this value with all their parts. So if you try to fix the system DPI here at 96, there will be porridge. But you can raise the DPI 167 monitor to the ideal 192.

Close the Fonts window. In general, now is the time to restart X and see what happened. It should work and have a convenient KDE size, all its settings and applications. The plasma panel, by the way, does not grow by itself. But it is a vector, and you can always stretch it - click the sandwich on the left and the buttons will appear. The same size in Dolphin must be set manually. If somewhere else in KDE applications the buttons and panels are too small, you need to shuffle the sizes of the icons in System Settings → Icons.

Configure other applications


Chrome, Atom and others


These applications read DPI directly from where it will turn out and follow it as a knight to the code. If they read something wrong, then they will look somehow wrong. Usually they ignore the settings in the System Settings and follow the DPI that xdpyinfo returns. If there is 96, then for Chrome you can use the argument --force-device-scale-factor=2 , for the Atom there is a curve hidpi plugin in the official turnips, for other programs there are crutches.

QtCreator, Yakuake, and other Qt5 apps


In general, they should work . But QtCreator doesn’t scale the toolbar, and Yakuake has a tab bar. The reason is in the bug and in the QT_AUTO_SCREEN_SCALE_FACTOR environment QT_AUTO_SCREEN_SCALE_FACTOR . When it is 1 , Qt5 tries to find the DPI value itself, and when 0 waits for it to be given in other variables. The bug is that KDE passes garbage.

In short, these applications need to set the variable QT_AUTO_SCREEN_SCALE_FACTOR=1 and everything will work. This can be done either selectively or globally. Optionally - in the Menu Editor. Just do not forget to add the application to the panel and in the autorun. This is necessary because .desktop records are copied, not linked. The second option is to set this variable all-system, in .xprofile or even / etc / environment , or where variables are written in your distribution. There are two nuances. First, KDE forcibly resets this variable to 0 in the / usr / bin / startkde script . You will have to open and edit it by #export QT_AUTO_SCREEN_SCALE_FACTOR=0 line #export QT_AUTO_SCREEN_SCALE_FACTOR=0 . After that, you need to remember to repeat this fix every time KDE is updated. The second caveat is that the KDE developers warn in the comments: setting this variable globally can lead to some Qt5 applications being increased twice. But this is not happening to me. Further, if the system DPI is incorrect, you need to set the variable QT_SCALE_FACTOR=2 in .xprofile .

Remember that the QT_DEVICE_PIXEL_RATIO variable QT_DEVICE_PIXEL_RATIO deprecated. If you put it somewhere, you need to remove it.

Qt4 Applications


These applications, in general, poorly able to HiDPI. But all is not lost. Qt4 creates a very flexible interface. Run qtconfig-qt4 . First, see the font and set a convenient size. Then, on the Interface tab, find a crutch called “ Global strut ” (in translation - global crutch.) This setting means that QWidget instances and its descendants cannot be smaller than this size in pixels, so that they are not used. With the help of Minimum Width, you can set the width of the scrollbars, and with the help of Minimum Height - the height of the toolbars.

GTK3 applications


Everything is simple here. You need to set two variables in .xprofile :

GDK_SCALE=2 Commands GTK to increase everything 2 times. The value must be integer. GDK_DPI_SCALE adjusts the font increase. If after GDK_SCALE fonts are huge, you need to set GDK_DPI_SCALE=0.5

GTK2 Applications


Everything is complicated here. GTK2 cannot do HiDPI at all. But there is a hack. Software called Oomox is a GTK theme (skins) generator. Including, with its help, you can collect such a topic under GTK2, which will imitate HiDPI. Or find a theme ready .

Applications on Qt3, Gtk1, Motif


Everything is quite complicated here. There are two possible hacks. First, you can take advantage of Kwin's ability to enlarge the entire screen. System Settings → Desktop Effects → Desktop Effects → Zoom . The middle button on the left is the settings, including the keys for turning it on and off. The second way is to run the application in the remote desktop server and connect to it locally. I will simply insert a link to the script , because setting it up is a matter of a separate article.

Java applications


More cool and commercial Java programs behave like Chrome: they read DPI from X and follow it. -Dsun.java2d.uiScale=2 programs can be fixed with one of two arguments: -Dsun.java2d.uiScale=2 increases the interface 2 times, and -Dswing.defaultlaf=com.sun.java.swing.plaf.gtk.GTKLookAndFeel tells it to use for drawing sizes from GTK . Let me remind you that in .xprofile you can create the variable export _JAVA_OPTIONS='-Dawt.useSystemAAFontSettings=on -Dswing.aatext=true -Dswing.defaultlaf=com.sun.java.swing.plaf.gtk.GTKLookAndFeel' . The above example includes anti-aliasing in fonts and GTK.

Well, so somehow.

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


All Articles