Skip to content

Commit

Permalink
scarab: Apply scaling factor in Wayland
Browse files Browse the repository at this point in the history
Sets `AVALONIA_GLOBAL_SCALE_FACTOR` to the GNOME desktop scaling factor
based on
<AvaloniaUI/Avalonia#9390 (comment)>,
falling back to the X FreeType DPI setting if the former is not
available.
  • Loading branch information
l0b0 committed Oct 14, 2024
1 parent b1ea4a3 commit 636f5c6
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
7 changes: 7 additions & 0 deletions pkgs/tools/games/scarab/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,15 @@
lib,
buildDotnetModule,
fetchFromGitHub,
bc,
glib,
glibc,
zlib,
gtk3,
copyDesktopItems,
icoutils,
wrapGAppsHook3,
writeText,
makeDesktopItem,
}:

Expand All @@ -34,6 +37,8 @@ buildDotnetModule rec {
'';

runtimeDeps = [
bc
glib
glibc
zlib
gtk3
Expand All @@ -60,6 +65,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 = [
Expand Down
17 changes: 17 additions & 0 deletions pkgs/tools/games/scarab/scaling-settings.bash
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Keep existing value if it is already non-empty
if [[ -z "${AVALONIA_GLOBAL_SCALE_FACTOR-}" ]]; then
# Attempt to get GNOME desktop interface scaling factor
AVALONIA_GLOBAL_SCALE_FACTOR="$(gsettings get org.gnome.desktop.interface scaling-factor | cut --delimiter=' ' --fields=2)"
fi

if [[ -z "${AVALONIA_GLOBAL_SCALE_FACTOR-}" ]]; then
# Attempt to get scaling factor from X FreeType DPI setting
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
export AVALONIA_GLOBAL_SCALE_FACTOR
fi

0 comments on commit 636f5c6

Please sign in to comment.