vincentbernat.i3wm-configur.../bin/xsettingsd-setup
Vincent Bernat db5f5743b9 xsettingsd: improve automatic DPI detection
For laptops, we don't want the same as for regular screens.
2020-01-29 23:47:03 +01:00

46 lines
1.5 KiB
Bash
Executable file

#!/bin/sh
DISPLAY=${DISPLAY%.0}
# For information
xrandr --current \
| sed -n 's/^\([^ ]\{1,\}\)* connected.* \([0-9]\{1,\}\)x.* \([0-9]\{1,\}\)mm x .*/\1 \2 \3/p' \
| while read output pixels mm; do
dpi=$(($pixels * 254 / 10 / $mm))
# For laptop screens, we need to apply a correction factor
case $output in
eDP-1|eDP1) corrected=$(($dpi * 96/144)) ;;
*) corrected=$dpi
esac
# Authorized factors: 1, 1.5, 2, 3, 4, ...
rounded=$(((corrected + 24) / 48 * 48))
[ $rounded -gt 192 ] && rounded=$(((corrected + 48) / 96 * 96))
[ $rounded -lt 96 ] && rounded=96
echo "$output: ${dpi}dpi (corrected to ${corrected}dpi, rounded to ${rounded}dpi)" >&2
done
# Don't try to guess DPI. For a laptop, we don't want the same DPI as
# for an external screen. Just hardcode stuff...
case $(hostname),$(autorandr --current) in
zoro,default) dpi=144 ;;
guybrush,default) dpi=144 ;;
neo,*) dpi=192 ;;
*,*) dpi=96 ;;
esac
xrandr --dpi $dpi
# Build xsettingsd.local
{
cat ~/.config/awesome/xsettingsd
echo Xft/DPI $(( $1*1024 ))
echo Xft/RGBA \"$( [ $1 -gt 144 ] && echo none || echo rgb )\"
echo Gdk/WindowScalingFactor $(( $1/96 ))
echo Gdk/UnscaledDPI $(( $1*1024/($1/96) ))
} > ~/.xsettingsd
# Signal xsettingsd
systemctl --user reload xsettingsd@$(systemd-escape -- "$DISPLAY").service
# Also use xrdb for very old stuff (you know, LibreOffice)
echo Xft.dpi: $dpi | xrdb -merge