From 1f2ae31e9ac10c07fe5aa507552345ae45467afb Mon Sep 17 00:00:00 2001 From: Samuel Dionne-Riel Date: Fri, 1 Nov 2024 00:53:53 -0400 Subject: [PATCH 1/5] jovian-updater-logo-helper: Add support for BGRT --- .../jovian-updater-logo-helper.sh | 89 +++++++++++++++++-- 1 file changed, 81 insertions(+), 8 deletions(-) diff --git a/pkgs/jovian-updater-logo-helper/jovian-updater-logo-helper.sh b/pkgs/jovian-updater-logo-helper/jovian-updater-logo-helper.sh index 1d1135f0..92a87e94 100644 --- a/pkgs/jovian-updater-logo-helper/jovian-updater-logo-helper.sh +++ b/pkgs/jovian-updater-logo-helper/jovian-updater-logo-helper.sh @@ -49,17 +49,90 @@ MAGICK_INVOCATION=( # Create an empty image, with the panel-native resolution "canvas:black[${image_width}x${image_height}!]" -) -MAGICK_INVOCATION+=( - # Add the logo - "$logo" - # Centered - -gravity center - # (This means 'add') - -composite + # Switch default composition gravity to top-left + -gravity NorthWest ) +if [[ "$logo" == "--bgrt" ]]; then + # Status field described here: + # - https://uefi.org/htmlspecs/ACPI_Spec_6_4_html/05_ACPI_Software_Programming_Model/ACPI_Software_Programming_Model.html#boot-graphics-resource-table-bgrt + bgrt_rotation="$(( ($(cat /sys/firmware/acpi/bgrt/status) >> 1) & 2#11 ))" + bgrt_xoffset=$(cat /sys/firmware/acpi/bgrt/xoffset) + bgrt_yoffset=$(cat /sys/firmware/acpi/bgrt/yoffset) + bgrt_dimensions="$(magick identify /sys/firmware/acpi/bgrt/image | cut -d' ' -f3)" + bgrt_height=${bgrt_dimensions#*x} + bgrt_width=${bgrt_dimensions%x*} + + case "$bgrt_rotation" in + "$(( 2#00 ))") + bgrt_offset="+$(( + bgrt_xoffset + ))+$(( + bgrt_yoffset + ))" + bgrt_counter_rotation="0" + ;; + "$(( 2#01 ))") # 90 + bgrt_offset="+$(( + bgrt_yoffset + ))+$(( + image_width - bgrt_width - bgrt_xoffset + ))" + bgrt_counter_rotation="-90" + ;; + "$(( 2#10 ))") # 180 + bgrt_offset="+$(( + image_width - bgrt_width - bgrt_xoffset + ))+$(( + image_height - bgrt_height - bgrt_yoffset + ))" + bgrt_counter_rotation="180" + ;; + "$(( 2#11 ))") # -90 + bgrt_offset="+$(( + image_height - bgrt_height - bgrt_yoffset + ))+$(( + bgrt_xoffset + ))" + bgrt_counter_rotation="90" + ;; + esac + + MAGICK_INVOCATION+=( + # Put the canvas back into the panel native orientation. + -rotate $(( display_rotation )) + + # Add the BGRT (bmp image) + # Group operation so we don't operate on the canvas. + '(' + # Load the image + "/sys/firmware/acpi/bgrt/image" + + # Rotate the BGRT to its expected rotation for composition + -rotate $(( bgrt_counter_rotation )) + + # At its defined offset, again considering pre-composed rotation + -geometry "$bgrt_offset" + ')' + + # (This means 'add' for the previous image) + -composite + + # Undo the native orientation we added back. + -rotate -$(( display_rotation )) + ) +else + MAGICK_INVOCATION+=( + # Add the logo + "$logo" + # Centered + -gravity center + # (This means 'add') + -composite + ) +fi + # Final fixups to the image MAGICK_INVOCATION+=( # Ensures crop crops a single image with gravity From c801b49741be18ca6e47eecfcea5b3a27581e245 Mon Sep 17 00:00:00 2001 From: Samuel Dionne-Riel Date: Fri, 1 Nov 2024 00:54:02 -0400 Subject: [PATCH 2/5] modules/steam: Allow using the BGRT for the updater applet --- modules/steam/updater.nix | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/modules/steam/updater.nix b/modules/steam/updater.nix index 252e6a19..f0310e19 100644 --- a/modules/steam/updater.nix +++ b/modules/steam/updater.nix @@ -18,6 +18,7 @@ in type = types.enum [ "steamos" "jovian" + "bgrt" "vendor" ]; default = "steamos"; @@ -28,6 +29,8 @@ in When `jovian`, this will use the Jovian Experiments logo, scaled appropriately. + When `bgrt`, the BGRT (UEFI vendor logo) will be used. + When `vendor`, the vendor default will not be changed. This differs from `default` in that on systems other than the Steam Deck, the scaling may not be correct. @@ -68,6 +71,9 @@ in ${optionalString (cfg.updater.splash == "jovian") '' jovian_updater_logo="${../../artwork/logo/splash.png}" ''} + ${optionalString (cfg.updater.splash == "bgrt") '' + jovian_updater_logo="--bgrt" + ''} ${pkgs.jovian-updater-logo-helper}/bin/jovian-updater-logo-helper "$jovian_updater_logo" "/run/jovian/steam-splash.png" ''; From 2aa0d2cb9ae59a3fed9bcf2b9e136db3e24a18d0 Mon Sep 17 00:00:00 2001 From: Samuel Dionne-Riel Date: Fri, 1 Nov 2024 14:58:11 -0400 Subject: [PATCH 3/5] jovian-updater-logo-helper: Add tip for debugging --- .../jovian-updater-logo-helper.sh | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/pkgs/jovian-updater-logo-helper/jovian-updater-logo-helper.sh b/pkgs/jovian-updater-logo-helper/jovian-updater-logo-helper.sh index 92a87e94..8b82731b 100644 --- a/pkgs/jovian-updater-logo-helper/jovian-updater-logo-helper.sh +++ b/pkgs/jovian-updater-logo-helper/jovian-updater-logo-helper.sh @@ -1,5 +1,11 @@ #!/usr/bin/env bash +# +# Tips for debugging: +# +# - Pass `'canvas:red[128x64!]'` as the input image. +# + set -e set -u PS4=" $ " From 7d296ccdeaa9e3ecf00f569dfaf5a99265b35433 Mon Sep 17 00:00:00 2001 From: Samuel Dionne-Riel Date: Wed, 18 Dec 2024 20:38:30 -0500 Subject: [PATCH 4/5] jovian-updater-logo-helper: Harden resolution detection Fixes #443 We're forcing `-o pipefail` in the script since it'll be added within `writeShellApplication`... and this causes a surprising failure from the totally cromulent (if rude) pipe we build here. --- .../jovian-updater-logo-helper.sh | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/pkgs/jovian-updater-logo-helper/jovian-updater-logo-helper.sh b/pkgs/jovian-updater-logo-helper/jovian-updater-logo-helper.sh index 8b82731b..8ff943f8 100644 --- a/pkgs/jovian-updater-logo-helper/jovian-updater-logo-helper.sh +++ b/pkgs/jovian-updater-logo-helper/jovian-updater-logo-helper.sh @@ -6,6 +6,7 @@ # - Pass `'canvas:red[128x64!]'` as the input image. # +set -o pipefail set -e set -u PS4=" $ " @@ -38,7 +39,22 @@ display_rotation=$( ) # Gets the "preferred" display resolution -resolution=$(cat /sys/class/drm/card*-eDP-*/modes | head -n1) +resolution=$( + # This following pipe will more than likely SIGPIPE. + # So let's not fail... + set +o pipefail + # Prevent non-existent files from mucking up the output + shopt -s nullglob + ( + # Prefer eDP outputs, or else any DRM output + cat /sys/class/drm/card*-eDP-*/modes /sys/class/drm/card*-*-*/modes /dev/null + # pipe "nothing" in if `nullglob` fails to glob anything ^^^^^^^^^ + # otherwise `cat` will expect to consume `stdin` if given no parameters. + + # If for some reason this fails, fallback on a safe resolution. + echo "1920x1080" + ) | head -n1 # Save only the first match +) # The image dimension will be used as our canvas size. if [[ "$display_rotation" == "0" || "$display_rotation" == "180" ]]; then From 13ca34381abb17eb5d5c9ef38b4fe7dc9f9b7b80 Mon Sep 17 00:00:00 2001 From: Samuel Dionne-Riel Date: Wed, 18 Dec 2024 21:18:59 -0500 Subject: [PATCH 5/5] steam/updater: Ignore errors from jovian-updater-logo-helper In the most round-about way ever possible. I hate shell scripting. And those strong assumptions around it really doesn't help for this less-than-important script... --- modules/steam/updater.nix | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/modules/steam/updater.nix b/modules/steam/updater.nix index f0310e19..78206c7b 100644 --- a/modules/steam/updater.nix +++ b/modules/steam/updater.nix @@ -53,6 +53,12 @@ in RemainAfterExit = true; }; script = '' + # Ignore errors (`set -e` is added helpfully for us) + set +e + + # Except we want to fail early still... + ( + set -e mkdir -p /run/jovian ${optionalString (cfg.updater.splash == "steamos") '' @@ -76,6 +82,10 @@ in ''} ${pkgs.jovian-updater-logo-helper}/bin/jovian-updater-logo-helper "$jovian_updater_logo" "/run/jovian/steam-splash.png" + ) + + # Ensure this always terminates successfully, even if the logo thing failed + true ''; }; environment.etc."xdg/gamescope-session/environment" = {