The DPI value of a screen indicates how many dots per inch or pixels per inch it supports. As the resolution increases, the display density also increases. You may know what resolution your display has but you may have no idea what your screen's DPI is. It is important to find the proper DPI value in Linux. Setting it to an incorrect value will make controls and icons look blurry or small. In this article, we will see how to find the right value for your screen.
In modern distros, the X server can automatically detect the right value. If the value is incorrect, you can calculate it manually and change it in your Linux desktop environment and for the X server globally.
Note: Not all Linux software looks okay in high-resolution mode yet. For example, LibreOffice supports HiDPI well, but does not come with a single icon theme which suits high-resolutions. The scaling factor of Mozilla Firefox also needs to be adjusted manually. Only the Cinnamon desktop environment has perfect DPI scaling support out-of-the-box.
Let's see how to find your DPI value in Linux.
Find the DPI value for your screen
To find the current DPI value of the screen used by Xserver, do the following.
- Open your favorite terminal emulator.
- Type or copy-paste the following command:
xdpyinfo | grep -B 2 resolution
The output will be something like this:
The line "resolution" shows the actual value.
If this value is not correct, you can calculate it yourself. Here is how.
How to calculate the right DPI value
To calculate the proper DPI value, do the following.
- Open your favorite terminal emulator
- Get your screen size in millimeters by running the command:
xrandr | grep -w connected
The output contains the physical display size in millimeters. In my case, it is 340mm x 190mm.
- Convert it to centimeters. My values are 34 x 19.
- Convert centimeters to inches. Divide the values by 2.54. In my case, the values are as follows: 13.39in x 7.48in.
- Finally, divide your screen resolution values by inch values. In my case, the values are as follows:
1920/13.39 = 143,390589993=~144.
1080/7.48 = 144,385026738=~144.
That's it. For my screen, I need to use 144 as my DPI value. Let's see how to change it.
How to change the DPI value
Depending on the graphical desktop environment you are using, the procedure can be different. I'll review some common cases which will give you an idea of what to do.
No desktop environment/barebones window manager
If you are running a window manager without a full featured DE (for example, Fluxbox), you must create or modify the /home/your user name/.Xresources file and add the following line:
Here and in all examples below, substitute the 144 portion with your actual DPI value.
If your .Xresources file is not processed, add the following line to your startup file (e.g. .xinitrc or some window manager-specific file)
xrdb -merge ~/.Xresources
Alternatively, you can try with the following line:
xrandr --dpi 144
However, xrandr may have issues with certain display drivers. Try and see if this works or not. In my case, this doesn't work.
Open a new terminal window and execute the command:
gsettings set org.gnome.desktop.interface scaling-factor 2
The scaling-factor parameter allows only whole numbers to be set. 1 = 100%, 2 = 200% and so on.
The DPI can be set to what you want under Settings - Appearance - Font.
For further reading, I recommend you to refer to this page. It is dedicated to Arch Linux, but the tips are common between all modern distros or can be easily adapted.