how to force DPI settings in Xenial?

Is it possible at all to force a specific DPI settings in Ubuntu Xenial?

Recipes mentioned in Can I pass a dpi flag to lightdm to set the proper DPI for X? don't work anymore:

  • I can successfully pass -dpi... option to X server,
  • I do see in Xorg.0.log that X server uses that option (actually without this option it successfully calculated proper DPI from monitor physical dimensions),
  • but even on the login screen DPI settings are set back to 96, according to xdpyinfo (I've checked this with an xterm, launched from a text console with proper $DISPLAY and $XAUTHORITY manually set).

So the question is: is changing DPI possible at all? Or should I simply dump off anything related to GNOME (due to this "WONTFIX") until more sane developers come to the GNOME team?


Solution 1:

I can't test on Xenial at the moment, but here's a fix that worked for my DPI-related problem on Trusty when none of the others did.

Problem: When I rebooted after having to swap out one of my 19" 1280x1024 monitors for a 17" 1280x1024 monitor, my fonts were small and looked "wrong" (I lack the vocabulary to say more but I assume it had to do with how the anti-aliasing interacted with a bad DPI setting).

Worse, GTK+ 2.x apps gave the confusing impression that they were ignoring the font size settings. (If I changed the font face or style, applications would update, but not even restarting applications would cause a change from 11pt. to 12pt. or 14pt. to have any visible effect. I didn't test that symptom against GTK+ 3.x though.)

Solution: The Xft.dpi X11 resource.

Confirmed effective for: GTK+ 2.x, GTK+ 3.x, and Qt 4 apps

For your case, try running this on your system and then restarting your applications:

echo Xft.dpi: 75 | xrdb -merge

Note: You may need to wait and/or restart them twice. When I tested GTK+ 3.x with file-roller and a DPI of 144, it remained on the 144 scale the first time I tested it after setting my DPI back to 96, but quitting and restarting it a second time returned it to the expected scale.

If that solves the problem, persist it by adding Xft.dpi: 75 on a line of its own in ~/.Xresources.

If it doesn't solve it, try again with other values to make sure you understand what the system is doing with the value you give it. I had to set the DPI to 96 to get the desired scale and that didn't occur to my sleep-fogged mind until I tried 72 DPI and the font shrunk rather than growing.

(Replacing the failed left-most 19" monitor with a 17" monitor was an online replacement and I have KDE's display settings daemon disabled, so what I expected was all three monitors operating on a fixed DPI setting calculated from a 19" 1280x1024 display.)

If the ~/.Xresources version has no effect, your desktop is probably missing the customary call to xrdb to apply them. I typically add xrdb -merge ~/.Xresources as one of the last things to run on login so it doesn't conflict with whatever else the desktop may be trying to accomplish.