79 lines
2.7 KiB
Bash
Executable File
79 lines
2.7 KiB
Bash
Executable File
#!/bin/bash
|
|
|
|
# blob:summary=Launch the Blob screensaver in the default terminal on the system with the correct font configuration.
|
|
|
|
if ! blob-screensaver-effect >/dev/null; then
|
|
blob-notify-send -g ✋ "Screensaver needs ttfx or tte" "Install python-terminaltexteffects."
|
|
exit 1
|
|
fi
|
|
|
|
# Exit early if screensaver is already running
|
|
pgrep -f '[o]rg.blob.screensaver' && exit 0
|
|
|
|
# Allow screensaver to be turned off but also force started
|
|
if blob-toggle-enabled screensaver-off && [[ $1 != "force" ]]; then
|
|
exit 1
|
|
fi
|
|
|
|
focused=$(blob-hypr-monitor-focused)
|
|
terminal=$(xdg-terminal-exec --print-id)
|
|
|
|
case $terminal in
|
|
*Alacritty* | *ghostty* | *foot* | *kitty*) ;;
|
|
*)
|
|
blob-notify-send -g ✋ "Screensaver only runs in Alacritty, Foot, Ghostty, or Kitty"
|
|
exit 1
|
|
;;
|
|
esac
|
|
|
|
hypr_focus_monitor() {
|
|
hyprctl dispatch "hl.dsp.focus({ monitor = \"$1\" })" >/dev/null 2>&1 || hyprctl dispatch focusmonitor "$1" >/dev/null
|
|
}
|
|
|
|
hypr_exec() {
|
|
local command
|
|
printf -v command '%q ' "$@"
|
|
|
|
hyprctl dispatch "hl.dsp.exec_cmd([[$command]])" >/dev/null 2>&1 || hyprctl dispatch exec -- bash -lc "$command" >/dev/null
|
|
}
|
|
|
|
SOCKET="$XDG_RUNTIME_DIR/hypr/$HYPRLAND_INSTANCE_SIGNATURE/.socket2.sock"
|
|
|
|
# Open Hyprland's event stream before spawning anything, so a terminal that maps
|
|
# quickly can't emit its openwindow event before we are listening for it.
|
|
exec {events}< <(socat -U - "UNIX-CONNECT:$SOCKET")
|
|
|
|
# hypr_exec is async and a new window maps on whatever monitor is focused at that
|
|
# moment. Block until this monitor's screensaver actually opens before moving
|
|
# focus on -- otherwise slow-starting terminals all pile onto the last monitor.
|
|
# The deadline is a safety net in case the window never appears.
|
|
wait_for_screensaver_window() {
|
|
local line deadline=$((SECONDS + 5))
|
|
while ((SECONDS < deadline)) && IFS= read -r -t $((deadline - SECONDS)) -u "$events" line; do
|
|
[[ $line == openwindow\>\>*,org.blob.screensaver,* ]] && return 0
|
|
done
|
|
}
|
|
|
|
for m in $(hyprctl monitors -j | jq -r '.[] | .name'); do
|
|
hypr_focus_monitor "$m"
|
|
|
|
case $terminal in
|
|
*Alacritty*)
|
|
hypr_exec alacritty --class=org.blob.screensaver --config-file "$BLOB_PATH/default/alacritty/screensaver.toml" -e blob-screensaver
|
|
;;
|
|
*ghostty*)
|
|
hypr_exec ghostty --class=org.blob.screensaver --config-file="$BLOB_PATH/default/ghostty/screensaver" --font-size=18 -e blob-screensaver
|
|
;;
|
|
*foot*)
|
|
hypr_exec foot --app-id=org.blob.screensaver --config="$BLOB_PATH/default/foot/screensaver.ini" -e blob-screensaver
|
|
;;
|
|
*kitty*)
|
|
hypr_exec kitty --class=org.blob.screensaver --override font_size=18 --override window_padding_width=0 -e blob-screensaver
|
|
;;
|
|
esac
|
|
|
|
wait_for_screensaver_window
|
|
done
|
|
|
|
hypr_focus_monitor "$focused"
|