From 7b09facd05ebcc8b915c7cc920dfd0133c2664b3 Mon Sep 17 00:00:00 2001 From: Victor Engmark Date: Mon, 14 Oct 2024 17:21:04 +1300 Subject: [PATCH] scarab: Apply scaling factor in Wayland Sets `AVALONIA_GLOBAL_SCALE_FACTOR` to the GNOME desktop scaling factor based on , 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. --- pkgs/tools/games/scarab/default.nix | 7 ++++++ pkgs/tools/games/scarab/scaling-settings.bash | 24 +++++++++++++++++++ 2 files changed, 31 insertions(+) create mode 100644 pkgs/tools/games/scarab/scaling-settings.bash diff --git a/pkgs/tools/games/scarab/default.nix b/pkgs/tools/games/scarab/default.nix index 26de0b1f9a2937..844d38ed006342 100644 --- a/pkgs/tools/games/scarab/default.nix +++ b/pkgs/tools/games/scarab/default.nix @@ -1,5 +1,6 @@ { lib, + bc, buildDotnetModule, fetchFromGitHub, copyDesktopItems, @@ -29,6 +30,10 @@ buildDotnetModule rec { -n nuget.org --configfile NuGet.Config ''; + runtimeDeps = [ + bc + ]; + nativeBuildInputs = [ copyDesktopItems icoutils @@ -45,6 +50,8 @@ buildDotnetModule rec { size=''${sizes[$i]}x''${sizes[$i]} install -D omegamaggotprime_''$((i+1))_''${size}x32.png $out/share/icons/hicolor/$size/apps/scarab.png done + + wrapProgram "$out/bin/Scarab" --run '. ${./scaling-settings.bash}' ''; desktopItems = [ diff --git a/pkgs/tools/games/scarab/scaling-settings.bash b/pkgs/tools/games/scarab/scaling-settings.bash new file mode 100644 index 00000000000000..8bec5c898ef6ec --- /dev/null +++ b/pkgs/tools/games/scarab/scaling-settings.bash @@ -0,0 +1,24 @@ +# Keep existing value if it is already non-empty +if [[ -z "${AVALONIA_GLOBAL_SCALE_FACTOR-}" ]] && type 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 [[ -z "${AVALONIA_GLOBAL_SCALE_FACTOR-}" ]] && type 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 [[ "${AVALONIA_GLOBAL_SCALE_FACTOR-}" == "0" ]]; then + echo 'Unset invalid scaling value' >&2 + unset AVALONIA_GLOBAL_SCALE_FACTOR +fi + +if [[ -n "${AVALONIA_GLOBAL_SCALE_FACTOR-}" ]]; then + echo "Applying scale factor: ${AVALONIA_GLOBAL_SCALE_FACTOR}" >&2 + export AVALONIA_GLOBAL_SCALE_FACTOR +fi