nixpkgs/pkgs/tools/games/scarab/scaling-settings.bash
Victor Engmark 59ed3fa2c4
scarab: Apply scaling factor in Wayland
Sets `AVALONIA_GLOBAL_SCALE_FACTOR` to the GNOME desktop scaling factor
based on
<https://github.com/AvaloniaUI/Avalonia/issues/9390#issuecomment-2382126451>,
falling back to the X FreeType DPI setting if the former is not
available.

Does not include `gsettings` and `xrdb` in build inputs, since these
should be available on the relevant platforms.

Bash does not support decimal/floating point arithmetic, so this *does*
include `bc` in the runtime dependencies.
2024-11-10 14:56:44 +13:00

25 lines
991 B
Bash

# Keep existing value if it is already non-empty
if [[ -z "${AVALONIA_GLOBAL_SCALE_FACTOR-}" ]] && command -v gsettings >/dev/null; then
echo 'Attempting to get GNOME desktop interface scaling factor' >&2
AVALONIA_GLOBAL_SCALE_FACTOR="$(gsettings get org.gnome.desktop.interface scaling-factor)"
AVALONIA_GLOBAL_SCALE_FACTOR="${AVALONIA_GLOBAL_SCALE_FACTOR##* }"
fi
if [[ "${AVALONIA_GLOBAL_SCALE_FACTOR-}" == "0" ]]; then
echo 'Unset invalid scaling value' >&2
unset AVALONIA_GLOBAL_SCALE_FACTOR
fi
if [[ -z "${AVALONIA_GLOBAL_SCALE_FACTOR-}" ]] && command -v xrdb >/dev/null; then
echo 'Attempting to get scaling factor from X FreeType DPI setting' >&2
dpi="$(xrdb -get Xft.dpi)"
if [[ -n "${dpi}" ]]; then
AVALONIA_GLOBAL_SCALE_FACTOR=$(echo "scale=2; ${dpi}/96" | bc)
fi
fi
if [[ -n "${AVALONIA_GLOBAL_SCALE_FACTOR-}" ]]; then
echo "Applying scale factor: ${AVALONIA_GLOBAL_SCALE_FACTOR}" >&2
export AVALONIA_GLOBAL_SCALE_FACTOR
fi