Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 20 additions & 6 deletions bin/omarchy-launch-screensaver
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down
3 changes: 0 additions & 3 deletions default/alacritty/screensaver.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,5 @@ background = "0x000000"
[colors.cursor]
cursor = "0x000000"

[font]
size = 18.0

[window]
opacity = 1.0
1 change: 0 additions & 1 deletion default/foot/screensaver.ini
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
[main]
font=JetBrainsMono Nerd Font:size=18
pad=0x0

[colors-dark]
Expand Down
18 changes: 15 additions & 3 deletions test/shell.d/screensaver-workspace-test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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'

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 New sizing paths lack tests

The new tests only check landscape monitors through foot. They never exercise rotated monitors, art tall enough to limit the font size, or the new arguments for Alacritty, Ghostty, and Kitty. Mistakes in those paths could pass these checks and leave users with cropped art or a screensaver that does not open. Add cases for those paths.

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

;;
'clients -j')
cat "$TEST_DIR/clients.json"
Expand All @@ -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")
Expand All @@ -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"
Expand All @@ -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
Expand All @@ -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.
Expand Down