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
bangfire commented 2025-02-12 21:40:49 +00:00 (Migrated from github.com)

Inspired by https://github.com/NixOS/nixpkgs/pull/348427 as it seems to work well at least on my system (Plasma 6.3).
A little ugly but probably better than nothing. Tried to get a KDE route working via kscreen-doctor but for whatever reason the environment variable refuses to set with the output of that... not sure why as when I copied the exact string that was being executed into the terminal directly it did work. Either way I gave up, probably some unicode weirdness that I don't want to get into.

Needs bc to be installed which I think is widely packaged with most distros but it's hard to know.

Needs GNOME testing.
Edit: GNOME is also useless, the gsettings scaling value doesn't even seem to be used and there doesn't seem to be any other method to query display scaling without parsing the XML manually.

Fixes #643 in theory.

Inspired by https://github.com/NixOS/nixpkgs/pull/348427 as it seems to work well at least on my system (Plasma 6.3). A little ugly but probably better than nothing. Tried to get a KDE route working via `kscreen-doctor` but for whatever reason the environment variable refuses to set with the output of that... not sure why as when I copied the exact string that was being executed into the terminal directly it did work. Either way I gave up, probably some unicode weirdness that I don't want to get into. Needs `bc` to be installed which I think is widely packaged with most distros but it's hard to know. Needs GNOME testing. Edit: GNOME is also useless, the `gsettings` scaling value doesn't even seem to be used and there doesn't seem to be any other method to query display scaling without parsing the XML manually. Fixes #643 in theory.
github-actions[bot] commented 2025-02-12 21:49:16 +00:00 (Migrated from github.com)
Download the artifacts for this pull request: * [ryujinx-Release-1.2.0+ec30b13-linux_arm64](https://nightly.link/Ryubing/Ryujinx/actions/artifacts/2595266504.zip) * [ryujinx-Release-1.2.0+ec30b13-linux_arm64-AppImage](https://nightly.link/Ryubing/Ryujinx/actions/artifacts/2595266686.zip) * [ryujinx-Release-1.2.0+ec30b13-linux_x64](https://nightly.link/Ryubing/Ryujinx/actions/artifacts/2595272092.zip) * [ryujinx-Release-1.2.0+ec30b13-macos_universal](https://nightly.link/Ryubing/Ryujinx/actions/artifacts/2595272170.zip) * [ryujinx-Release-1.2.0+ec30b13-linux_x64-AppImage](https://nightly.link/Ryubing/Ryujinx/actions/artifacts/2595272205.zip) * [ryujinx-Release-1.2.0+ec30b13-win_x64](https://nightly.link/Ryubing/Ryujinx/actions/artifacts/2595284996.zip) <details><summary>Only for Developers</summary> * [ryujinx-Debug-1.2.0+ec30b13-linux_arm64](https://nightly.link/Ryubing/Ryujinx/actions/artifacts/2595266783.zip) * [ryujinx-Debug-1.2.0+ec30b13-linux_arm64-AppImage](https://nightly.link/Ryubing/Ryujinx/actions/artifacts/2595266884.zip) * [ryujinx-Debug-1.2.0+ec30b13-macos_universal](https://nightly.link/Ryubing/Ryujinx/actions/artifacts/2595273053.zip) * [ryujinx-Debug-1.2.0+ec30b13-linux_x64](https://nightly.link/Ryubing/Ryujinx/actions/artifacts/2595274320.zip) * [ryujinx-Debug-1.2.0+ec30b13-linux_x64-AppImage](https://nightly.link/Ryubing/Ryujinx/actions/artifacts/2595274419.zip) * [ryujinx-Debug-1.2.0+ec30b13-win_x64](https://nightly.link/Ryubing/Ryujinx/actions/artifacts/2595289179.zip) </details>
AdamantGarth (Migrated from github.com) reviewed 2025-03-05 15:50:43 +00:00
AdamantGarth (Migrated from github.com) left a comment

Hi, I would suggest running shellcheck on the script and fixing the warnings. Also left a couple of more specific suggestions.

This will complicate the parsing, but maybe it's worth setting AVALONIA_SCREEN_SCALE_FACTORS instead (for the methods that provide this info, like kscreen-doctor and monitors.xml) to support multiple monitors. See: https://github.com/AvaloniaUI/Avalonia/wiki/Configuring-X11-per-monitor-DPI. For the kscreen-doctor method it may look like:

AVALONIA_SCREEN_SCALE_FACTORS=$(kscreen-doctor --outputs | awk '{gsub(/\x1b\[[0-9;]*m/,"")} /Output:/{printf "%s%s=", s, $3; s=";"} /Scale:/{printf "%s", $2}')

I frequently run Ryujinx on an external monitor (but not always), would be nice to have it automatically adapt scaling to the monitor it's currently on.

Hi, I would suggest running [shellcheck](https://www.shellcheck.net/) on the script and fixing the warnings. Also left a couple of more specific suggestions. This will complicate the parsing, but maybe it's worth setting `AVALONIA_SCREEN_SCALE_FACTORS` instead (for the methods that provide this info, like `kscreen-doctor` and `monitors.xml`) to support multiple monitors. See: https://github.com/AvaloniaUI/Avalonia/wiki/Configuring-X11-per-monitor-DPI. For the `kscreen-doctor` method it may look like: ```sh AVALONIA_SCREEN_SCALE_FACTORS=$(kscreen-doctor --outputs | awk '{gsub(/\x1b\[[0-9;]*m/,"")} /Output:/{printf "%s%s=", s, $3; s=";"} /Scale:/{printf "%s", $2}') ``` I frequently run Ryujinx on an external monitor (but not always), would be nice to have it automatically adapt scaling to the monitor it's currently on.
@ -23,1 +23,3 @@
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 (Migrated from github.com) commented 2025-03-05 12:07:05 +00:00

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 ```
@ -24,0 +38,4 @@
dpi="$(xrdb -get Xft.dpi)"
if [[ -n "${dpi}" ]]; then
SCALING=$(echo "scale=2; ${dpi}/96" | bc)
fi
AdamantGarth (Migrated from github.com) commented 2025-03-05 12:17:33 +00:00

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}') ```
@ -24,0 +47,4 @@
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 (Migrated from github.com) commented 2025-03-05 14:05:12 +00:00

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}') ```
This pull request can be merged automatically.
You are not authorized to merge this pull request.

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin bangfire/brute_scaling:bangfire/brute_scaling
git checkout bangfire/brute_scaling
Sign in to join this conversation.
No description provided.