Notes on DPI...

Some quick notes on setting DPI for High Density Displays and X11.

Background

On "normal" displays within X11 it is assumed that there are 96 pixels/dots per inch (DPI). This is fine for most cases. However, with "newer" displays, including on laptops, having double or more DPI this can make text really hard to see. Here are some tips that I've collected to help bring the fonts back in line.

Setting the correct DPI...

My daily window manager is cwm(1). within my ~/.xsession script I have the following.

DPI=`xdpyinfo | grep resolution | awk '{ print $2 }' | cut -f1 -dx`
DPI=${DPI:-96}
echo "DPI=${DPI}"
xrandr --dpi ${DPI}

~/.xsession snippet

This uses xdpyinfo(1) to fetch the DPI identified by X11. If not there or something goes wrong with the parse, assume 96 DPI and then output the setting (which is captured in ~/.xsession-errors) and use xrandr(1) to set the DPI.

Setting the pointer...

This will make the mouse pointers really small. To fix this I export the following settings (from the .xsession script).

export XCURSOR_PATH="~/.icons:/usr/local/lib/X11/icons:$XCURSOR_PATH"
export XCURSOR_SIZE="64"

~/.xsession snippet

The first export adds some new paths to look for new cursors. Use pkg_add(1) script to fine cursors that can be installed.

pkg_add -Q cursor

I also set the size to 64. (This should be multiples of 8). But on my display 64 seems to be a good size.

Setting the Xresources...

Updating the ~/.Xresources file will also help for programs that use this.

! set cursor size
Xcursor.theme: dmz-aa
Xcursor.size: 64

! default face name to use
*faceName: CodeNewRoman Nerd Font:style=Bold:size=20

~/.Xresources snippet

This also sets the cursor theme to use and size (duplicates the exports, but doesn't hurt). This also sets the default face name, style and size to use if not overridden by more specific settings.

Browsers...

Naturally the browsers don't seem to obey any of the X11 settings. Here are some specific settings that seem to help.

Firefox

Open about:config in the firefox multibar. Find layout.css.devPixelsPerPx and set to an appropriate number. Less than 1.0 makes things smaller and greater than 1.0 make thing larger. Updates take place immediately so it's nice that changes can be seen without restarting.

Chrome

Chrome is better/worse depending on your point of view. There doesn't seem to be any config setting to set. Instead a CLI option --force-device-scale-factor=x is used. As with firefox, number less than 1.0 will make things smaller and number larger than 1.0 will make thing bigger.

Since I usually launch chrome from cwm application menu, I have a simple shell script that add the CLI option.

#!/bin/sh

SF=${SCALE_FACTOR:-1.0}
ARGS="--force-device-scale-factor=${SF}"

/usr/local/bin/chrome ${ARGS} $@

start_chrome.sh

In the ~/.xsession script I set an environment variable of SCALE_FACTOR and then use that in this script to set the scale factor for chrome.

Conclusion

Other window managers / desktop environments like XFCE, Gnome, KDE seem to have their own ways of handling the display DPI discrepancy. They each have their plusses and minuses, but all require more dependencies. Choose what is right for you.

This doesn't take care of 100% of the applications, but covers the ones I use most.