linux: Attempt to apply Avalonia scaling factor via environment pre-launch. #656

Open
bangfire wants to merge 2 commits from bangfire/brute_scaling into master

View File

@ -20,4 +20,42 @@ if command -v gamemoderun > /dev/null 2>&1; then
COMMAND="$COMMAND gamemoderun"
fi
exec $COMMAND "$SCRIPT_DIR/$RYUJINX_BIN" "$@"
# Check if user already has a manual Avalonia scaling override or session type is x11.
if [[ -n "${AVALONIA_GLOBAL_SCALE_FACTOR-}" || "$(echo "$XDG_SESSION_TYPE")" == "x11" ]]; then
echo "Scaling: Performed by environment, skipping." >&2
AdamantGarth commented 2025-03-05 12:07:05 +00:00 (Migrated from github.com)
Review

The #!/bin/sh shebang indicates that this is a POSIX-compatible shell script, and POSIX sh doesn't specify the [[ syntax. The same goes for == which should be just =. As is, the script will fail on Debian-based systems (including Ubuntu) I think, as they use dash as /bin/sh which doesn't implement these syntax extensions. The same applies to all other ifs.

Also, echo here is redundant, but that's just a nit.

if [ -n "${AVALONIA_GLOBAL_SCALE_FACTOR-}" ] || [ "$XDG_SESSION_TYPE" = "x11" ]; then
The `#!/bin/sh` shebang indicates that this is a POSIX-compatible shell script, and POSIX `sh` doesn't specify the `[[` syntax. The same goes for `==` which should be just `=`. As is, the script will fail on Debian-based systems (including Ubuntu) I think, as they use `dash` as `/bin/sh` which doesn't implement these syntax extensions. The same applies to all other `if`s. Also, `echo` here is redundant, but that's just a nit. ```suggestion if [ -n "${AVALONIA_GLOBAL_SCALE_FACTOR-}" ] || [ "$XDG_SESSION_TYPE" = "x11" ]; then ```
else
# Query monitor config directly (GNOME), default display only.
if [[ "$(echo "$XDG_CURRENT_DESKTOP")" == "GNOME" && -f ~/.config/monitors.xml ]] then
echo -n 'Scaling: Monitor config located, querying scale...' >&2
SCALING="$(grep '<scale' ~/.config/monitors.xml -m 1 | cut -f2 -d">"|cut -f1 -d"<")"
SCALING="${SCALING##* }"
echo "found! Factor: ${SCALING}" >&2
# Fallback to X DPI query for others.
# Plasma handles this fine, GNOME will always round up e.g. 1.25 -> 2.00.
elif command -v xrdb >/dev/null; then
echo -n 'Scaling: Attempting to get scaling from X DPI value...' >&2
dpi="$(xrdb -get Xft.dpi)"
if [[ -n "${dpi}" ]]; then
SCALING=$(echo "scale=2; ${dpi}/96" | bc)
fi
AdamantGarth commented 2025-03-05 12:17:33 +00:00 (Migrated from github.com)
Review

bc can be replaced with awk which is more commonly installed by default.

            SCALING=$(awk -vdpi="$dpi" 'BEGIN{print dpi/96}')
`bc` can be replaced with `awk` which is more commonly installed by default. ```suggestion SCALING=$(awk -vdpi="$dpi" 'BEGIN{print dpi/96}') ```
echo "found! Factor: ${SCALING}"
# Query kscreen-doctor for Plasma as a fallback.
elif [[ "$(echo "$XDG_CURRENT_DESKTOP")" == "KDE" ]] && command -v kscreen-doctor >/dev/null; then
echo -n 'Scaling: Attempting to get Plasma desktop scaling factor...' >&2
SCALING="$(kscreen-doctor --outputs | grep "Scale" -m 1)"
SCALING="${SCALING##* }"
SCALING=$(echo $SCALING | sed 's/\x1B\[[0-9;]*m//g') # Trim ANSI chars from ksd output.
echo "found! Factor: ${SCALING}"
AdamantGarth commented 2025-03-05 14:05:12 +00:00 (Migrated from github.com)
Review

Can be replaced with a single awk call:

        # gsub strips ANSI color codes from ksd output
        SCALING=$(kscreen-doctor --outputs | awk '/Scale:/{gsub(/\x1b\[[0-9;]*m/,""); print $2; exit}')
Can be replaced with a single `awk` call: ```suggestion # gsub strips ANSI color codes from ksd output SCALING=$(kscreen-doctor --outputs | awk '/Scale:/{gsub(/\x1b\[[0-9;]*m/,""); print $2; exit}') ```
fi
if [[ -z "${SCALING-}" || "${SCALING-}" == "0" ]]; then
echo 'Unset invalid scaling value' >&2
SCALING="1"
fi
COMMAND="$COMMAND AVALONIA_GLOBAL_SCALE_FACTOR=$SCALING"
fi
exec $COMMAND "$SCRIPT_DIR/$RYUJINX_BIN" "$@"