Janky GNOME workaround and added a fallback kscreen-doctor implementation if needed.

This commit is contained in:
Piplup 2025-03-13 17:52:57 +00:00
parent 13c4aca5ac
commit 4e61c3369b
No known key found for this signature in database
GPG key ID: AADE53FD75F1BEAD

View file

@ -20,29 +20,38 @@ if command -v gamemoderun > /dev/null 2>&1; then
COMMAND="$COMMAND gamemoderun" COMMAND="$COMMAND gamemoderun"
fi fi
# Check if user already has a manual Avalonia scaling override or session type is x11 # 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 if [[ -n "${AVALONIA_GLOBAL_SCALE_FACTOR-}" || "$(echo "$XDG_SESSION_TYPE")" == "x11" ]]; then
echo "Scaling: Performed by environment, skipping." >&2 echo "Scaling: Performed by environment, skipping." >&2
else else
# Attempt to get desktop scaling from environment (GNOME) # Query monitor config directly (GNOME), default display only.
if [[ "$(echo "$XDG_CURRENT_DESKTOP")" == "GNOME" ]] && command -v gsettings >/dev/null; then if [[ "$(echo "$XDG_CURRENT_DESKTOP")" == "GNOME" && -f ~/.config/monitors.xml ]] then
echo -n 'Scaling: GNOME desktop scaling query...' >&2 echo -n 'Scaling: Monitor config located, querying scale...' >&2
SCALING="$(gsettings get org.gnome.desktop.interface scaling-factor)" SCALING="$(grep '<scale' ~/.config/monitors.xml -m 1 | cut -f2 -d">"|cut -f1 -d"<")"
SCALING="${SCALING##* }" SCALING="${SCALING##* }"
echo "found! Factor: ${SCALING}" >&2 echo "found! Factor: ${SCALING}" >&2
# Attempt to get desktop scaling from X Query (Others) # Fallback to X DPI query for others.
elif command -v xrdb >/dev/null && command -v bc >/dev/null; then # Plasma handles this fine, GNOME will always round up e.g. 1.25 -> 2.00.
echo -n 'Scaling: X FreeType DPI scaling query...' >&2 elif command -v xrdb >/dev/null; then
echo -n 'Scaling: Attempting to get scaling from X DPI value...' >&2
dpi="$(xrdb -get Xft.dpi)" dpi="$(xrdb -get Xft.dpi)"
if [[ -n "${dpi}" ]]; then if [[ -n "${dpi}" ]]; then
SCALING=$(echo "scale=2; ${dpi}/96" | bc) SCALING=$(echo "scale=2; ${dpi}/96" | bc)
echo "found! Factor: ${SCALING}" >&2
fi fi
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}"
fi fi
if [[ -z "${SCALING-}" || "${SCALING-}" == "0" ]]; then if [[ -z "${SCALING-}" || "${SCALING-}" == "0" ]]; then
echo 'Scaling: Unset scaling value, using default scaling.' >&2 echo 'Unset invalid scaling value' >&2
SCALING="1" SCALING="1"
fi fi