Files
nixos/henrovnix_ok/home/desktop/rotating_wallpaper.nix
T
2026-02-26 19:45:26 +01:00

115 lines
2.6 KiB
Nix

{ config, lib, pkgs, ... }:
let
scriptPath = "hypr/scripts/wp-workspace-1to9.sh";
wpScript = ''
#!/usr/bin/env bash
set -euo pipefail
WALL_DIR="''${1:-$HOME/nixos_conf/wallpaperstuff/pictures}"
: "''${XDG_RUNTIME_DIR:?XDG_RUNTIME_DIR not set}"
: "''${HYPRLAND_INSTANCE_SIGNATURE:?HYPRLAND_INSTANCE_SIGNATURE not set}"
SOCK="''${XDG_RUNTIME_DIR}/hypr/''${HYPRLAND_INSTANCE_SIGNATURE}/.socket2.sock"
[[ -S "$SOCK" ]] || { echo "Hyprland socket not found: $SOCK" >&2; exit 1; }
need() { command -v "$1" >/dev/null 2>&1 || { echo "Missing dependency: $1" >&2; exit 1; }; }
need hyprctl
need wpaperctl
need socat
get_active_ws_id() {
if command -v jq >/dev/null 2>&1; then
hyprctl activeworkspace -j | jq -r '.id'
else
hyprctl activeworkspace | awk '/workspace ID/ {print $3; exit}'
fi
}
get_active_monitor() {
if command -v jq >/dev/null 2>&1; then
hyprctl activeworkspace -j | jq -r '.monitor'
else
hyprctl activeworkspace | sed -n 's/.* on monitor \([^:]*\):.*/\1/p' | head -n1
fi
}
set_for_ws() {
local ws_raw="$1"
local ws="''${ws_raw%%:*}"
[[ "$ws" =~ ^[1-9]$ ]] || return 0
local img="''${WALL_DIR}/wallpaper''${ws}.jpg"
[[ -f "$img" ]] || return 0
local mon
mon="$(get_active_monitor)"
if [[ -n "''${mon:-}" ]]; then
wpaperctl set "$img" "$mon"
else
wpaperctl set "$img"
fi
}
preseed_1_to_9() {
local orig
orig="$(get_active_ws_id)"
for ws in {1..9}; do
hyprctl dispatch workspace "$ws" >/dev/null
sleep 0.05
set_for_ws "$ws"
done
hyprctl dispatch workspace "$orig" >/dev/null
}
# Start daemon if not already running
if ! pgrep -x wpaperd >/dev/null; then
wpaperd -d &
sleep 0.5
fi
preseed_1_to_9
set_for_ws "$(get_active_ws_id)"
while IFS= read -r line; do
case "$line" in
workspace\>\>*)
set_for_ws "''${line#workspace>>}"
;;
workspacev2\>\>*)
payload="''${line#workspacev2>>}"
ws_id="''${payload%%,*}"
set_for_ws "$ws_id"
;;
esac
done < <(socat -U - "UNIX-CONNECT:''${SOCK}")
'';
in
{
home.packages = with pkgs; [
wpaperd
socat
jq
];
# Write script
xdg.configFile."${scriptPath}" = {
text = wpScript;
executable = true;
};
# Ensure Hyprland starts it
wayland.windowManager.hyprland = {
enable = true;
extraConfig = ''
exec-once = ${config.xdg.configHome}/${scriptPath}
'';
};
}