bazzite/system_files/deck/shared/usr/bin/bazzite-desktop-bootstrap
HikariKnight e8789c63a3
fix(deck): don't force scaling each time desktop loads (#2166)
It is now set once and not touched unless `~/.config/bazzite/fixups/scaling_fixup` is removed.
2025-01-21 07:53:51 -08:00

98 lines
4.4 KiB
Bash
Executable File

#!/bin/bash
# Modified from:
# https://gitlab.com/evlaV/steamdeck-kde-presets/-/blob/master/usr/bin/jupiter-plasma-bootstrap?ref_type=heads
set -eo pipefail
SYS_ID="$(/usr/libexec/hwsupport/sysid)"
IMAGE_INFO="/usr/share/ublue-os/image-info.json"
BASE_IMAGE_NAME=$(jq -r '."base-image-name"' < $IMAGE_INFO)
if [[ "${XDG_SESSION_TYPE}" = "wayland" ]]; then
mkdir -p "$HOME/.config/bazzite/fixups" 2>/dev/null
if [[ $BASE_IMAGE_NAME =~ "kinoite" ]]; then
if /usr/libexec/hwsupport/needs-left-rotation || /usr/libexec/hwsupport/needs-right-rotation; then
# Try to wait for kscreen to be ready. This was mostly a hack to try to make the below bug not happen, but I'm afraid
# to remove it because this weird bug has caused hours of grief.
i=0
while (( ++i < 5 )) && ! kscreen-console outputs; do
sleep 5
done
# Then try to fix the config
#
# There is some fun/insane bug where if kscreen hasn't evaluated connected displays yet, doing that at the same time as
# asking it to set the rotation causes it to racily either ignore you, or somehow do two modesets in such a way as to
# break the amdgpu driver and disable the screen for this X11 session. Really. Wayland seems fine.
#
# But if you ask for a nonsense rotation, it will guarantee it has evaluated the new display and added it to the config
# (before failing because foo isn't a rotation). Ha-ha, software!
kscreen-doctor output.eDP-1.rotation.foo || true
kscreen-doctor output.eDP.rotation.foo || true
# In wayland mode the display is named after some EDID identifier and not the output, but "1" works there, and hopefully
# is the internal screen oh boy.
# Try to wait for kscreen to be ready
i=0
while (( ++i < 5 )) && ! kscreen-console json; do
sleep 5
done
# Then try to fix the rotation
if /usr/libexec/hwsupport/needs-right-rotation; then
kscreen-doctor output.eDP.rotation.right \
|| kscreen-doctor output.eDP-1.rotation.right \
|| true
elif /usr/libexec/hwsupport/needs-left-rotation; then
kscreen-doctor output.eDP.rotation.left \
|| kscreen-doctor output.eDP-1.rotation.left \
|| true
fi
# Then try to fix the scaling
if [ ! -f "$HOME/.config/bazzite/fixups/scaling_fixup" ]; then
if /usr/libexec/hwsupport/needs-100-scale; then
kscreen-doctor output.eDP.scale.1 \
|| kscreen-doctor output.eDP-1.scale.1 \
|| true
elif /usr/libexec/hwsupport/needs-150-scale; then
kscreen-doctor output.eDP.scale.1.5 \
|| kscreen-doctor output.eDP-1.scale.1.5 \
|| true
elif /usr/libexec/hwsupport/needs-200-scale; then
kscreen-doctor output.eDP.scale.2 \
|| kscreen-doctor output.eDP-1.scale.2 \
|| true
fi
touch "$HOME/.config/bazzite/fixups/scaling_fixup"
fi
fi
# TEMP workaround for a bug causing the screen to not come back on input on handhelds
# if it was turned off from idling, this just disables the display idle in kde until
# we can figure out what causes the bug, as it does not happen on laptops/desktops.
# If this is valve hardware or a handheld that hhd supports (easiest way to just cover all handhelds)
# do not turn off the screen when idle (sleep still works normal)
if /usr/libexec/hwsupport/valve-hardware; then
perl -pi -e 's/TurnOffDisplayIdleTimeoutSec=\d{1,4}/TurnOffDisplayIdleTimeoutSec=-1\nTurnOffDisplayWhenIdle=false/g' ~/.config/powerdevilrc
elif /usr/libexec/hwsupport/hhd-supported-hardware; then
perl -pi -e 's/TurnOffDisplayIdleTimeoutSec=\d{1,4}/TurnOffDisplayIdleTimeoutSec=-1\nTurnOffDisplayWhenIdle=false/g' ~/.config/powerdevilrc
fi
elif [[ $BASE_IMAGE_NAME =~ "silverblue" ]]; then
# Set scale on GNOME desktops, rotation tends to work without issue.
if [ ! -f "$HOME/.config/bazzite/fixups/scaling_fixup" ]; then
if /usr/libexec/hwsupport/needs-100-scale; then
gnome-randr modify eDP --scale 1 \
|| gnome-randr modify eDP-1 --scale 1 \
|| true
elif /usr/libexec/hwsupport/needs-200-scale; then
gnome-randr modify eDP --scale 2 \
|| gnome-randr modify eDP-1 --scale 2 \
|| true
fi
touch "$HOME/.config/bazzite/fixups/scaling_fixup"
fi
fi
fi