vincentbernat.i3wm-configur.../bin/xsettingsd-setup
Vincent Bernat d85a504c53 Initial i3 configuration
This is derived from my Awesome configuration. Still a lot to do from
a WM perspective. The organization is a bit different and I am giving
it up on the per-display systemd units as it does not really work due
to the fact we only have one user DBus and one environment.
2021-07-04 08:38:39 +02:00

44 lines
1.3 KiB
Bash
Executable file

#!/bin/sh
DISPLAY=${DISPLAY%.0}
# Compute DPI of each screens
dpis=""
for info in $(xrandr --current \
| sed -n 's/^\([^ ]\{1,\}\)* connected.* \([0-9]\{1,\}\)x.* \([0-9]\{1,\}\)mm x .*/\1,\2,\3/p'); do
output=${info%%,*}
pixels=${info#*,}
pixels=${pixels%%,*}
mm=${info##*,}
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
dpis="$dpis$rounded "
echo "$output: ${dpi}dpi (corrected to ${corrected}dpi, rounded to ${rounded}dpi)" >&2
done
# Use first screen DPI
dpi=${dpis%% *}
dpi=${dpi:-96}
echo "using ${dpi}dpi" >&2
xrandr --dpi $dpi
# Build xsettingsd
{
cat ~/.config/i3/xsettingsd
echo Xft/DPI $(( $dpi*1024 ))
echo Xft/RGBA \"$( [ $dpi -gt 144 ] && echo none || echo rgb )\"
echo Gdk/WindowScalingFactor $(( $dpi/96 ))
echo Gdk/UnscaledDPI $(( $dpi*1024/($dpi/96) ))
} > ~/.xsettingsd
# Also use xrdb for very old stuff (you know, LibreOffice)
echo Xft.dpi: $dpi | xrdb -merge