Skip to content

Commit

Permalink
Merge pull request #282 from Jovian-Experiments/feature/updater-logo-…
Browse files Browse the repository at this point in the history
…fixes

Add support for using the BGRT in the updater applet
  • Loading branch information
K900 authored Dec 19, 2024
2 parents cb76297 + 13ca343 commit ce2abe4
Show file tree
Hide file tree
Showing 2 changed files with 120 additions and 9 deletions.
16 changes: 16 additions & 0 deletions modules/steam/updater.nix
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ in
type = types.enum [
"steamos"
"jovian"
"bgrt"
"vendor"
];
default = "steamos";
Expand All @@ -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.
Expand All @@ -50,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") ''
Expand All @@ -68,8 +77,15 @@ 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"
)
# Ensure this always terminates successfully, even if the logo thing failed
true
'';
};
environment.etc."xdg/gamescope-session/environment" = {
Expand Down
113 changes: 104 additions & 9 deletions pkgs/jovian-updater-logo-helper/jovian-updater-logo-helper.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
#!/usr/bin/env bash

#
# Tips for debugging:
#
# - Pass `'canvas:red[128x64!]'` as the input image.
#

set -o pipefail
set -e
set -u
PS4=" $ "
Expand Down Expand Up @@ -32,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
Expand All @@ -49,17 +71,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
Expand Down

0 comments on commit ce2abe4

Please sign in to comment.