diff --git a/bin/omarchy-launch-screensaver b/bin/omarchy-launch-screensaver index 78cf757116ae..3f678599365f 100755 --- a/bin/omarchy-launch-screensaver +++ b/bin/omarchy-launch-screensaver @@ -50,28 +50,42 @@ wait_for_screensaver_window() { done } -while read -r m special; do +art=~/.config/omarchy/branding/screensaver.txt +art_columns=$(LC_ALL=C.UTF-8 wc -L 2>/dev/null <"$art" || echo 0) +art_rows=$(wc -l 2>/dev/null <"$art" || echo 0) + +# Size the font per monitor, between 6 and 18, so the art fits its logical size instead of being cropped at the edges, +# as the 81-column logo is on a 1080p panel at scale 2. A monospace cell at N points is about 0.8N by 1.75N pixels. +monitors_with_font_size() { + hyprctl monitors -j | jq -r --argjson columns "$art_columns" --argjson rows "$art_rows" ' + .[] | .scale as $scale + | (if .transform % 2 == 1 then [.height, .width] else [.width, .height] end | map(. / $scale)) as [$width, $height] + | ([18, $width / (($columns + 2) * 0.8), $height / (($rows + 2) * 1.75)] | min | floor | [., 6] | max) as $font_size + | "\(.name) \($font_size) \(.specialWorkspace.name)"' +} + +while read -r m font_size special; do hypr_focus_monitor "$m" # Share a special workspace that is already showing, like the scratchpad, so it is still open afterwards. workspace=${special:-special:screensaver-$m} case $terminal in *Alacritty*) - hypr_exec alacritty --class=org.omarchy.screensaver --config-file "$OMARCHY_PATH/default/alacritty/screensaver.toml" -e omarchy-screensaver + hypr_exec alacritty --class=org.omarchy.screensaver --config-file "$OMARCHY_PATH/default/alacritty/screensaver.toml" -o "font.size=$font_size" -e omarchy-screensaver ;; *ghostty*) - hypr_exec ghostty --class=org.omarchy.screensaver --config-file="$OMARCHY_PATH/default/ghostty/screensaver" --font-size=18 -e omarchy-screensaver + hypr_exec ghostty --class=org.omarchy.screensaver --config-file="$OMARCHY_PATH/default/ghostty/screensaver" --font-size="$font_size" -e omarchy-screensaver ;; *foot*) - hypr_exec foot --app-id=org.omarchy.screensaver --config="$OMARCHY_PATH/default/foot/screensaver.ini" -e omarchy-screensaver + hypr_exec foot --app-id=org.omarchy.screensaver --config="$OMARCHY_PATH/default/foot/screensaver.ini" --font="JetBrainsMono Nerd Font:size=$font_size" -e omarchy-screensaver ;; *kitty*) - hypr_exec kitty --class=org.omarchy.screensaver --override font_size=18 --override window_padding_width=0 -e omarchy-screensaver + hypr_exec kitty --class=org.omarchy.screensaver --override font_size="$font_size" --override window_padding_width=0 -e omarchy-screensaver ;; esac wait_for_screensaver_window -done < <(hyprctl monitors -j | jq -r '.[] | "\(.name) \(.specialWorkspace.name)"') +done < <(monitors_with_font_size) hypr_focus_monitor "$focused" diff --git a/default/alacritty/screensaver.toml b/default/alacritty/screensaver.toml index 7db389ed9201..19d01cfb8161 100644 --- a/default/alacritty/screensaver.toml +++ b/default/alacritty/screensaver.toml @@ -4,8 +4,5 @@ background = "0x000000" [colors.cursor] cursor = "0x000000" -[font] -size = 18.0 - [window] opacity = 1.0 diff --git a/default/foot/screensaver.ini b/default/foot/screensaver.ini index 7130d0694949..037c04caffd7 100644 --- a/default/foot/screensaver.ini +++ b/default/foot/screensaver.ini @@ -1,5 +1,4 @@ [main] -font=JetBrainsMono Nerd Font:size=18 pad=0x0 [colors-dark] diff --git a/test/shell.d/screensaver-workspace-test.sh b/test/shell.d/screensaver-workspace-test.sh index 9583535dfc5e..9b877d93ff67 100644 --- a/test/shell.d/screensaver-workspace-test.sh +++ b/test/shell.d/screensaver-workspace-test.sh @@ -23,7 +23,7 @@ cat >"$tmpdir/bin/hyprctl" <<'SH' printf '%s\n' "$*" >>"$TEST_DIR/calls" case "$*" in 'monitors -j') - printf '[{"name":"DP-1","specialWorkspace":{"name":""}},{"name":"DP-2","specialWorkspace":{"name":"special:scratchpad"}}]\n' + printf '[{"name":"DP-1","width":2560,"height":1440,"scale":1,"transform":0,"specialWorkspace":{"name":""}},{"name":"DP-2","width":1920,"height":1080,"scale":2,"transform":0,"specialWorkspace":{"name":"special:scratchpad"}}]\n' ;; 'clients -j') cat "$TEST_DIR/clients.json" @@ -48,9 +48,11 @@ chmod +x "$tmpdir/bin/"* : >"$tmpdir/calls" : >"$tmpdir/spawned" +mkdir -p "$tmpdir/.config/omarchy/branding" +cp "$ROOT/logo.txt" "$tmpdir/.config/omarchy/branding/screensaver.txt" printf '[{"class":"org.omarchy.screensaver","mapped":true}]\n' >"$tmpdir/clients.json" -PATH="$tmpdir/bin:$PATH" TEST_DIR="$tmpdir" XDG_RUNTIME_DIR="$tmpdir" HYPRLAND_INSTANCE_SIGNATURE=test \ +HOME="$tmpdir" PATH="$tmpdir/bin:$PATH" TEST_DIR="$tmpdir" XDG_RUNTIME_DIR="$tmpdir" HYPRLAND_INSTANCE_SIGNATURE=test \ timeout 10 "$ROOT/bin/omarchy-launch-screensaver" force mapfile -t spawns < <(grep exec_cmd "$tmpdir/calls") @@ -61,6 +63,11 @@ pass "the screensaver opens on its own special workspace, leaving a fullscreen w [[ ${spawns[1]} == *"[workspace special:scratchpad]"* ]] || fail "the screensaver shares a special workspace that is already showing" "${spawns[1]}" pass "the screensaver shares a special workspace that is already showing" +[[ ${spawns[0]} == *"size=18 "* ]] || fail "the logo is drawn at full size where it fits" "${spawns[0]}" +pass "the logo is drawn at full size where it fits" +[[ ${spawns[1]} == *"size=14 "* ]] || + fail "the font shrinks so the logo fits a 1080p monitor at scale 2 instead of being cropped" "${spawns[1]}" +pass "the font shrinks so the logo fits a 1080p monitor at scale 2 instead of being cropped" # Emptying a special workspace focuses its monitor; the last screensaver to close must not keep focus. : >"$tmpdir/calls" @@ -82,7 +89,8 @@ pass "focus returns to the monitor that had it once the screensaver closes" kill "$(<"$tmpdir/socat.pid")" : >"$tmpdir/calls" : >"$tmpdir/spawned" -PATH="$tmpdir/bin:$PATH" TEST_DIR="$tmpdir" XDG_RUNTIME_DIR="$tmpdir" HYPRLAND_INSTANCE_SIGNATURE=test \ +printf '%2000s\n' x >"$tmpdir/.config/omarchy/branding/screensaver.txt" +HOME="$tmpdir" PATH="$tmpdir/bin:$PATH" TEST_DIR="$tmpdir" XDG_RUNTIME_DIR="$tmpdir" HYPRLAND_INSTANCE_SIGNATURE=test \ timeout 10 "$ROOT/bin/omarchy-launch-screensaver" force for (( attempt = 0; attempt < 100; attempt++ )); do (( $(grep -c 'hl.dsp.focus({ monitor = "DP-1" })' "$tmpdir/calls") == 3 )) && break @@ -91,6 +99,10 @@ done (( $(grep -c 'hl.dsp.focus({ monitor = "DP-1" })' "$tmpdir/calls") == 3 )) || fail "focus returns without waiting for a close that has already happened" "$(<"$tmpdir/calls")" pass "focus returns without waiting for a close that has already happened" +mapfile -t spawns < <(grep exec_cmd "$tmpdir/calls") +(( ${#spawns[@]} == 2 )) && [[ ${spawns[0]} == *"size=6 "* && ${spawns[1]} == *"size=6 "* ]] || + fail "art too wide to fit still gets a usable font size" "$(<"$tmpdir/calls")" +pass "art too wide to fit still gets a usable font size" # The launcher's workspace only holds for the first map. A terminal mapped again as it closes falls back to # the class rule, which must keep it off the regular workspaces where its fullscreen rule would take over.