From c16afeb71e0d51a036ca840b83ccd3bdb44e288b Mon Sep 17 00:00:00 2001 From: Kyle Gospodnetich Date: Thu, 18 Apr 2024 15:57:31 -0700 Subject: [PATCH] fix(deck): Use new rotation system based on Valve's bootstrap. --- .../kinoite/usr/bin/bazzite-plasma-bootstrap | 49 +++++++++++++++++++ .../bazzite-plasma-bootstrap.desktop | 16 ++++++ .../kinoite/usr/libexec/bazzite-rotation-fix | 46 ----------------- .../usr/libexec/hardware/needs-left-rotation | 12 +++++ .../usr/libexec/hardware/needs-right-rotation | 8 +++ .../shared/usr/libexec/bazzite-user-setup | 12 ++--- .../libexec/hardware/hhd-supported-hardware | 4 +- .../libexec/hardware/rotation-fix-hardware | 8 --- .../simpledeckytdp-supported-hardware | 4 +- .../usr/libexec/hardware/valve-hardware | 4 +- 10 files changed, 94 insertions(+), 69 deletions(-) create mode 100755 system_files/deck/kinoite/usr/bin/bazzite-plasma-bootstrap create mode 100644 system_files/deck/kinoite/usr/etc/xdg/autostart/bazzite-plasma-bootstrap.desktop delete mode 100755 system_files/deck/kinoite/usr/libexec/bazzite-rotation-fix create mode 100755 system_files/deck/kinoite/usr/libexec/hardware/needs-left-rotation create mode 100755 system_files/deck/kinoite/usr/libexec/hardware/needs-right-rotation delete mode 100755 system_files/desktop/shared/usr/libexec/hardware/rotation-fix-hardware diff --git a/system_files/deck/kinoite/usr/bin/bazzite-plasma-bootstrap b/system_files/deck/kinoite/usr/bin/bazzite-plasma-bootstrap new file mode 100755 index 0000000000..c98c7fa0f3 --- /dev/null +++ b/system_files/deck/kinoite/usr/bin/bazzite-plasma-bootstrap @@ -0,0 +1,49 @@ +#!/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="$(cat /sys/devices/virtual/dmi/id/product_name)" + +if [[ "${XDG_SESSION_TYPE}" = "wayland" ]]; then + if /usr/libexec/hardware/needs-left-rotation || /usr/libexec/hardware/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 config + if /usr/libexec/hardware/needs-right-rotation; then + kscreen-doctor output.eDP.rotation.right \ + || kscreen-doctor output.eDP-1.rotation.right \ + || true + elif /usr/libexec/hardware/needs-left-rotation; then + kscreen-doctor output.eDP.rotation.left \ + || kscreen-doctor output.eDP-1.rotation.left \ + || true + fi + fi +fi diff --git a/system_files/deck/kinoite/usr/etc/xdg/autostart/bazzite-plasma-bootstrap.desktop b/system_files/deck/kinoite/usr/etc/xdg/autostart/bazzite-plasma-bootstrap.desktop new file mode 100644 index 0000000000..16df7c39c3 --- /dev/null +++ b/system_files/deck/kinoite/usr/etc/xdg/autostart/bazzite-plasma-bootstrap.desktop @@ -0,0 +1,16 @@ +[Desktop Entry] +Exec=/usr/bin/bazzite-plasma-bootstrap +GenericName[en_US]=Desktop Bootstrap +GenericName=Desktop Bootstrap +Icon=system-run +MimeType= +Name[en_US]=Desktop Bootstrap +Name=Desktop Bootstrap +Path= +StartupNotify=true +Terminal=false +Type=Application +X-DBUS-ServiceName= +X-DBUS-StartupType= +X-KDE-SubstituteUID=false +X-KDE-Username= diff --git a/system_files/deck/kinoite/usr/libexec/bazzite-rotation-fix b/system_files/deck/kinoite/usr/libexec/bazzite-rotation-fix deleted file mode 100755 index b9a91ea893..0000000000 --- a/system_files/deck/kinoite/usr/libexec/bazzite-rotation-fix +++ /dev/null @@ -1,46 +0,0 @@ -#!/usr/bin/bash - -# This script fixes the screen orientation in the Desktop Mode in Bazzite-Deck KDE -# Author: d3Xt3r - -SYS_ID="$(cat /sys/devices/virtual/dmi/id/product_name)" - -STEAM_PID=$(cat $HOME/.steam/steam.pid) -STEAM_CMDLINE_PATH=/proc/$STEAM_PID/cmdline -STEAM_CMDLINE=$(cat $STEAM_CMDLINE_PATH) - -IS_GAMEMODE=$(echo $STEAM_CMDLINE | grep gamepadui*) - - -sleep 1 -echo $(date '+%Y-%m-%d %H:%M:%S') Starting Bazzite Desktop Orientation Fix script...| tee -a /tmp/bazrotfix.log - -# This bit is needed to allow enough time for the desktop to load, otherwise the fix won't work -# Since Steam launches automatically in the Desktop mode in Bazzite-Deck, we can use it -# to determine whether or not the desktop has loaded. -while ! pgrep -x "steam" > /dev/null; do - echo $(date '+%Y-%m-%d %H:%M:%S') Waiting for Steam to start.. | tee -a /tmp/bazrotfix.log - sleep 0.5 -done - -sleep 1 - -# Debug: Get current outputs -kscreen-doctor --outputs 2>&1 | tee -a /tmp/bazrotfix.log - -# Fix desktop orientation -# Rotation options: right, normal, left, inverted -echo $(date '+%Y-%m-%d %H:%M:%S') Fixing desktop orientation... | tee -a /tmp/bazrotfix.log -if /usr/libexec/hardware/valve-hardware; then - # Fix default scale on for Steam Deck hardware - kscreen-doctor output.1.scale.1.00 2>&1 | tee -a /tmp/bazrotfix.log -elif [[ ! -z "$IS_GAMEMODE" ]]; then - kscreen-doctor output.1.rotation.normal 2>&1 | tee -a /tmp/bazrotfix.log -elif [[ ":83E1:Loki Max:AIR Plus:" =~ ":$SYS_ID:" ]]; then - kscreen-doctor output.1.rotation.left 2>&1 | tee -a /tmp/bazrotfix.log -else - kscreen-doctor output.1.rotation.normal 2>&1 | tee -a /tmp/bazrotfix.log -fi - -echo $(date '+%Y-%m-%d %H:%M:%S') Ending Bazzite Desktop Orientation Fix script >> /tmp/bazrotfix.log -echo -e '\n' >> /tmp/bazrotfix.log diff --git a/system_files/deck/kinoite/usr/libexec/hardware/needs-left-rotation b/system_files/deck/kinoite/usr/libexec/hardware/needs-left-rotation new file mode 100755 index 0000000000..d93f7de089 --- /dev/null +++ b/system_files/deck/kinoite/usr/libexec/hardware/needs-left-rotation @@ -0,0 +1,12 @@ +#!/usr/bin/bash + +SYS_ID="$(cat /sys/devices/virtual/dmi/id/product_name)" + +# Legion Go +# Loki Max +# AYANEO Air Plus +if [[ ":83E1:Loki Max:AIR Plus:" =~ ":$SYS_ID:" ]]; then + exit 0 +fi + +exit 1 \ No newline at end of file diff --git a/system_files/deck/kinoite/usr/libexec/hardware/needs-right-rotation b/system_files/deck/kinoite/usr/libexec/hardware/needs-right-rotation new file mode 100755 index 0000000000..c31bcec8a5 --- /dev/null +++ b/system_files/deck/kinoite/usr/libexec/hardware/needs-right-rotation @@ -0,0 +1,8 @@ +#!/usr/bin/bash + +# Steam Deck +if /usr/libexec/hardware/valve-hardware; then + exit 0 +fi + +exit 1 \ No newline at end of file diff --git a/system_files/desktop/shared/usr/libexec/bazzite-user-setup b/system_files/desktop/shared/usr/libexec/bazzite-user-setup index 156d686f55..891cce9999 100755 --- a/system_files/desktop/shared/usr/libexec/bazzite-user-setup +++ b/system_files/desktop/shared/usr/libexec/bazzite-user-setup @@ -15,7 +15,7 @@ BAZZITE_CONFIG_DIR="${XDG_DATA_HOME:-$HOME/.local/share}/bazzite" mkdir -p "$BAZZITE_CONFIG_DIR" # SCRIPT VERSION -USER_SETUP_VER=30 +USER_SETUP_VER=31 USER_SETUP_VER_FILE="$BAZZITE_CONFIG_DIR/version" USER_SETUP_FEDORA_VER_FILE="$BAZZITE_CONFIG_DIR/fedora_version" USER_SETUP_IMAGE_VER_FILE=$BAZZITE_CONFIG_DIR/image_name"" @@ -148,14 +148,8 @@ if [[ $IMAGE_NAME =~ "deck" || $IMAGE_NAME =~ "ally" || $IMAGE_NAME =~ "framegam rm -f "$AUTOSTART_FOLDER/autostart/bazzite-handle-legion-go-rotation.desktop" fi - if /usr/libexec/hardware/rotation-fix-hardware && [[ $BASE_IMAGE_NAME =~ "kinoite" ]]; then - if [[ ! -f "$AUTOSTART_FOLDER/autostart/bazzite-rotation-fix.desktop" ]]; then - echo 'Adding rotation fix' - mkdir -p "$AUTOSTART_FOLDER/autostart" - printf "[Desktop Entry]\nExec=/usr/libexec/bazzite-rotation-fix\nIcon=dialog-scripts\nName=bazzite-rotation-fix\nType=Application\nX-KDE-AutostartScript=true\n" > "$AUTOSTART_FOLDER/autostart/bazzite-rotation-fix.desktop" - fi - elif [[ -f "$AUTOSTART_FOLDER/autostart/bazzite-rotation-fix.desktop" ]]; then - echo 'Non-supported or GNOME detected, removing rotaion fix' + # Remove old rotation fix + if [[ -f "$AUTOSTART_FOLDER/autostart/bazzite-rotation-fix.desktop" ]]; then rm -f "$AUTOSTART_FOLDER/autostart/bazzite-rotation-fix.desktop" fi fi diff --git a/system_files/desktop/shared/usr/libexec/hardware/hhd-supported-hardware b/system_files/desktop/shared/usr/libexec/hardware/hhd-supported-hardware index f010ee05bf..8b92ea9f14 100755 --- a/system_files/desktop/shared/usr/libexec/hardware/hhd-supported-hardware +++ b/system_files/desktop/shared/usr/libexec/hardware/hhd-supported-hardware @@ -3,6 +3,6 @@ SYS_ID="$(cat /sys/devices/virtual/dmi/id/product_name)" if [[ ":ROG Ally RC71L_RC71L:ROG Ally RC71L:83E1:G1618-04:G1617-01:G1619-05:AIR Plus:AIR:AYANEO GEEK:AYANEO 2:AYANEO 2S:AOKZOE A1 AR07:G1619-04:Win600:Loki Max:Loki Zero:Loki MiniPro:" =~ ":$SYS_ID:" ]]; then exit 0 -else - exit 1 fi + +exit 1 diff --git a/system_files/desktop/shared/usr/libexec/hardware/rotation-fix-hardware b/system_files/desktop/shared/usr/libexec/hardware/rotation-fix-hardware deleted file mode 100755 index 7fb4dfb440..0000000000 --- a/system_files/desktop/shared/usr/libexec/hardware/rotation-fix-hardware +++ /dev/null @@ -1,8 +0,0 @@ -#!/usr/bin/bash -# Returns true for hardware that needs a rotation fix in KDE -SYS_ID="$(cat /sys/devices/virtual/dmi/id/product_name)" -if [[ ":ROG Ally RC71L_RC71L:ROG Ally RC71L:83E1:Loki Max:G1618-04:G1619-04:21A0007TUK:HP ENVY x360 Convertible 13-ay0xxx:" =~ ":$SYS_ID:" ]]; then - exit 0 -else - exit 1 -fi diff --git a/system_files/desktop/shared/usr/libexec/hardware/simpledeckytdp-supported-hardware b/system_files/desktop/shared/usr/libexec/hardware/simpledeckytdp-supported-hardware index ad300f4d73..72ac71c81c 100755 --- a/system_files/desktop/shared/usr/libexec/hardware/simpledeckytdp-supported-hardware +++ b/system_files/desktop/shared/usr/libexec/hardware/simpledeckytdp-supported-hardware @@ -3,6 +3,6 @@ SYS_ID="$(cat /sys/devices/virtual/dmi/id/product_name)" if [[ ":ROG Ally RC71L_RC71L:ROG Ally RC71L:83E1:G1618-04:G1619-04:G1617-01:G1619-05:AIR Plus:AIR:SLIDE:" =~ ":$SYS_ID:" ]]; then exit 0 -else - exit 1 fi + +exit 1 diff --git a/system_files/desktop/shared/usr/libexec/hardware/valve-hardware b/system_files/desktop/shared/usr/libexec/hardware/valve-hardware index eeb8f73332..72e5b184e7 100755 --- a/system_files/desktop/shared/usr/libexec/hardware/valve-hardware +++ b/system_files/desktop/shared/usr/libexec/hardware/valve-hardware @@ -3,6 +3,6 @@ SYS_ID="$(cat /sys/devices/virtual/dmi/id/product_name)" if [[ ":Jupiter:Galileo:" =~ ":$SYS_ID:" ]]; then exit 0 -else - exit 1 fi + +exit 1