Ubuntu – How to find and change the screen DPI


I am trying to find and then change the screen DPI (dots per inch) setting in 12.04 and 12.10. However, I can't seem to find any app or config file that can do this. Is there any app or conf file for this?

Note that this is for 12.04+ so the following will not work:

Moreover, they are basically changing the font size, not the actual screen DPI.

Best Answer

  • This is an updated version of my previous answer which was related to Ubuntu 12.04. In 16.04 (Xenial) 3 steps are needed to set DPI correctly instead of 2.

    I'll explain on the example of the system with Ubuntu 12.04 with Gnome Classic and a monitor with resolution 1680x1050. My starting settings: xdpyinfo | grep dots reported 96x96 dots , xrdb -query | grep dpi reported Xft.dpi: 96 , grep DPI /var/log/Xorg.0.log reported some weird settings NOUVEAU(0): DPI set to (90, 88).

    In 16.04 the outputs of all these 3 commands were consistent and were equal to 96. Though such consensus is better than the disorder of 12.04, the reported value is hardcoded and far from the real DPI value.

    Let's calculate optimal DPI for my monitor. Actual size of the screen can be found with the command xrandr | grep -w connected (convert output to centimetres) or with a long ruler by hand. In my case: X = 47.4cm ; Y = 29.6cm. Divide them by 2.54 to get the size in inches: X ~ 18.66in ; Y ~ 11.65in. Lastly divide the actual dots amount (based on your resolution) by the size in inches: X = 1680/18.66 ~ 90dpi ; Y = 1050/11.65 ~ 90dpi. So my real dpi is 90.

    Be warned, the manual method of measuring may be more accurate, than the output of the command xrandr | grep -w connected because the newer versions of X server ignore the size reported by EDID and calculate the size using the screen resolution and a hardcoded value of DPI (more info here).
    Another method how to find the size of the monitor is to read its EDID directly. Install read-edid package and run the command sudo get-edid | parse-edid | grep DisplaySize in the terminal. Its output will give you the actual size of your monitor in millimetres. If not - use the ruler.

    Let's start fixing DPI:

    1) In 12.04 run gksudo gedit, open /etc/lightdm/lightdm.conf and add a parameter under [SeatDefaults] section:

    xserver-command=X -dpi 90

    There's no such file in 16.04 by default, so you must create lightdm.conf manually and put it into /etc/lightdm/lightdm.conf.d/. The contents of this file are the same:

    xserver-command=X -dpi 90

    Restart your computer or restart X. Now grep DPI /var/log/Xorg.0.log will show the desired setting.

    2) In my former answer I proposed to create a file in /etc/X11/Xsession.d/ containing string xrandr --dpi 90. This worked in 12.04, but in 16.04 this setting isn't persistent. In newer systems we can add the desired value on session start. Run "Startup Applications", press "Add" button, name it "Fix DPI" and set the command xrandr --dpi 90 in the field. Save the changes and re-login. Now xdpyinfo | grep dots will report 90x90 dots.

    If xdpyinfo still shows 96 then add a timeout before running xrandr. Edit the command in "Startup Applications" and change it to:

    bash -c "sleep 15; xrandr --dpi 90"


    Step 2 is optional for 12.04 because in older systems Step 1 fixes both Xorg.0.log and xdpyinfo values.

    3) In GNOME3 DPI setting is hardcoded to 96 and cannot be changed directly, but the text can be scaled instead. Calculate the desired multiplier: desired_DPI / 96 (in my case 90/96 = 0.9375). Now run the command (or use dconf if you prefer):

    gsettings set org.gnome.desktop.interface text-scaling-factor 0.9375

    Changes will be applied at once. xrdb -query | grep dpi will report the desired Xft.dpi: 90.

    P.S. There is another method to fix DPI setting which is much more difficult and it is described in this guide. I tried it also and the result was the same (at least in 12.04).

    Afterword: Only Ubuntu developers can say for certain whether values modified by Steps 1 & 2 really matter in modern Ubuntu or they are silently ignored. Only Step 3 produces the changes which are instantly noticeable. Those users who consider that certain apps may still rely on X server settings are encouraged to perform all 3 steps described above. For the rest Step 3 is sufficient - that's the sole way of customization adopted in modern Ubuntu distros.