38 lines
957 B
Bash
Executable File
38 lines
957 B
Bash
Executable File
#!/bin/sh
|
|
|
|
# Sets the correct DPI for your monitor instead of the generic '100'
|
|
# ! Make sure there is no DPI entry in your Xresources already!
|
|
|
|
FILE=$XDG_CONFIG_HOME/X11/xresources
|
|
|
|
grep 'Xft.dpi' "$FILE" && xrdb -merge "$FILE" && exit
|
|
|
|
INFO=/tmp/display_info
|
|
xrandr | grep ' connected' > $INFO
|
|
|
|
WIDTH_MM=$(awk '{print $NF}' $INFO)
|
|
WIDTH_IN=$(echo "${WIDTH_MM%mm}" | awk '{print $1 * 0.03937007874015748}')
|
|
|
|
HEIGHT_MM=$(awk '{print $(NF-2)}' $INFO)
|
|
HEIGHT_IN=$(echo "${HEIGHT_MM%mm}" | awk '{print $1 * 0.03937007874015748}')
|
|
|
|
DIAGONAL_IN=$(awk -v w="$WIDTH_IN" -v h="$HEIGHT_IN" \
|
|
'BEGIN{print sqrt(w^2 + h^2)}')
|
|
|
|
PX=$(cut -d ' ' -f 4 $INFO)
|
|
|
|
WIDTH_PX=${PX%x*}
|
|
|
|
TEMP_HEIGHT_PX=${PX#*x}
|
|
HEIGHT_PX=${TEMP_HEIGHT_PX%%+*}
|
|
|
|
DIAGONAL_PX=$(awk -v w="$WIDTH_PX" -v h="$HEIGHT_PX" \
|
|
'BEGIN{print sqrt(w^2 +h^2)}')
|
|
|
|
DPI=$(awk -v dp="$DIAGONAL_PX" -v di="$DIAGONAL_IN" \
|
|
'BEGIN{print dp / di}')
|
|
|
|
echo "Xft.dpi: $DPI" >> "$FILE"
|
|
xrdb -merge "$FILE"
|
|
rm $INFO
|