2022-05-17 05:14:19 +02:00
|
|
|
#!/bin/sh
|
|
|
|
# env
|
2023-10-24 21:51:20 +02:00
|
|
|
# Written in 2022-2023 by Lucas
|
2022-05-17 05:14:19 +02:00
|
|
|
# CC0 1.0 Universal/Public domain - No rights reserved
|
|
|
|
#
|
|
|
|
# To the extent possible under law, the author(s) have dedicated all
|
|
|
|
# copyright and related and neighboring rights to this software to the
|
|
|
|
# public domain worldwide. This software is distributed without any
|
|
|
|
# warranty. You should have received a copy of the CC0 Public Domain
|
|
|
|
# Dedication along with this software. If not, see
|
|
|
|
# <http://creativecommons.org/publicdomain/zero/1.0/>.
|
|
|
|
|
2022-06-22 03:01:59 +02:00
|
|
|
usage()
|
|
|
|
{
|
2023-10-24 21:51:20 +02:00
|
|
|
printf "Usage: %s [-n] [targetdpi]\n" "${0##*/}" >&2
|
2022-06-22 03:01:59 +02:00
|
|
|
exit 1
|
|
|
|
}
|
|
|
|
|
2023-10-24 21:51:20 +02:00
|
|
|
err()
|
|
|
|
{
|
|
|
|
printf "%s: %s\n" "${0##*/}" "$*" >&2
|
|
|
|
exit 1
|
|
|
|
}
|
|
|
|
|
|
|
|
show=false
|
|
|
|
while getopts n flag; do
|
|
|
|
case $flag in
|
|
|
|
n) show=true ;;
|
|
|
|
*) usage ;;
|
|
|
|
esac
|
|
|
|
done
|
|
|
|
shift $((OPTIND - 1))
|
2022-06-22 03:01:59 +02:00
|
|
|
if [ $# -gt 1 ]; then
|
|
|
|
usage
|
|
|
|
fi
|
|
|
|
|
2023-10-24 21:51:20 +02:00
|
|
|
FACESIZES="8.0 4.0 6.0 7.0 8.0 9.0 10.0 12.0"
|
|
|
|
|
|
|
|
basedpi=$(xdpyinfo | grep '^ resolution:' | {
|
|
|
|
min=
|
|
|
|
while read -r line; do
|
|
|
|
set -- $line
|
|
|
|
dpi_x=${2%%x*}
|
|
|
|
dpi_y=${2##*x}
|
|
|
|
dpi_sum=$(( $dpi_x + $dpi_y ))
|
|
|
|
if [ -z "$min" ]; then
|
|
|
|
min=$dpi_sum
|
|
|
|
else
|
|
|
|
min=$(( $dpi_sum < $min ? $dpi_sum : $dpi ))
|
2022-05-17 05:14:19 +02:00
|
|
|
fi
|
2023-10-24 21:51:20 +02:00
|
|
|
done
|
|
|
|
|
|
|
|
if [ -n "$min" ]; then
|
|
|
|
echo "$min / 2" | bc -l
|
|
|
|
fi
|
|
|
|
})
|
|
|
|
|
|
|
|
if [ -z "$basedpi" ]; then
|
|
|
|
err "Can't find DPI"
|
2022-05-17 05:14:19 +02:00
|
|
|
fi
|
2023-10-24 21:51:20 +02:00
|
|
|
|
|
|
|
targetdpi=${1:-96}
|
2022-05-17 05:14:19 +02:00
|
|
|
|
|
|
|
for facesize in $FACESIZES; do
|
2023-10-24 21:51:20 +02:00
|
|
|
echo "$basedpi * $facesize / $targetdpi"
|
2022-05-17 05:14:19 +02:00
|
|
|
done | bc -l | {
|
|
|
|
i=0
|
|
|
|
printf "Xft.dpi:\t%.1f\n" "$targetdpi"
|
|
|
|
while read -r v; do
|
|
|
|
if [ $i -eq 0 ]; then
|
2023-10-24 21:51:20 +02:00
|
|
|
printf "XTerm.VT100.faceSize:\t%f\n" "$v"
|
2022-05-17 05:14:19 +02:00
|
|
|
else
|
2023-10-24 21:51:20 +02:00
|
|
|
printf "XTerm.VT100.faceSize%d:\t%f\n" $i "$v"
|
2022-05-17 05:14:19 +02:00
|
|
|
fi
|
|
|
|
i=$(($i + 1))
|
|
|
|
done
|
2023-10-24 21:51:20 +02:00
|
|
|
} | if $show; then
|
|
|
|
cat
|
|
|
|
else
|
|
|
|
xrdb -merge
|
|
|
|
fi
|