121 lines
3.4 KiB
Nix
121 lines
3.4 KiB
Nix
{ config, lib, pkgs, flakeRoot, ... }:
|
|
|
|
let
|
|
repoWallpaperDir = flakeRoot + "/assets/conf/desktop/wallpaper";
|
|
|
|
userRelRoot = "nixos_conf/wallpaperstuff";
|
|
userAbsRoot = "${config.home.homeDirectory}/${userRelRoot}";
|
|
picturesDir = "${userAbsRoot}/pictures";
|
|
|
|
repoWallpapersOnly = lib.cleanSourceWith {
|
|
src = repoWallpaperDir;
|
|
filter = path: type: true;
|
|
};
|
|
|
|
wsScriptRel = "hypr/scripts/hyprpaper-workspace-1to9.sh";
|
|
in
|
|
{
|
|
home.packages = [ pkgs.hyprpaper pkgs.socat pkgs.jq ];
|
|
|
|
home.file."${userRelRoot}" = {
|
|
source = repoWallpapersOnly;
|
|
recursive = true;
|
|
};
|
|
|
|
xdg.configFile."hypr/hyprpaper.conf".text = ''
|
|
ipc = true
|
|
splash = false
|
|
'';
|
|
|
|
xdg.configFile."${wsScriptRel}" = {
|
|
executable = true;
|
|
text = ''
|
|
#!/usr/bin/env bash
|
|
set -euo pipefail
|
|
|
|
: "''${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; }
|
|
|
|
# Allow overriding the pictures dir from argv; default to the Nix-provided one
|
|
PICTURES_DIR="''${1:-${picturesDir}}"
|
|
FIT_MODE="fill"
|
|
|
|
FOCUSED_MON=""
|
|
|
|
pick_wall_for_ws() {
|
|
local ws="''${1}"
|
|
local f
|
|
f="$(ls -1 "''${PICTURES_DIR}/''${ws}."* 2>/dev/null | head -n 1 || true)"
|
|
echo "''${f}"
|
|
}
|
|
|
|
apply_wallpaper() {
|
|
local mon="''${1}"
|
|
local ws="''${2}"
|
|
|
|
local file
|
|
file="$(pick_wall_for_ws "''${ws}")"
|
|
[[ -n "''${file}" ]] || return 0
|
|
|
|
hyprctl hyprpaper wallpaper "''${mon}, ''${file}, ''${FIT_MODE}" >/dev/null
|
|
}
|
|
|
|
FOCUSED_MON="$(hyprctl -j monitors | jq -r '.[] | select(.focused==true) | .name' | head -n 1 || true)"
|
|
CUR_WS="$(hyprctl -j activeworkspace | jq -r '.name' | head -n 1 || true)"
|
|
CUR_WS="''${CUR_WS%%:*}"
|
|
|
|
[[ -n "''${FOCUSED_MON}" && -n "''${CUR_WS}" ]] && apply_wallpaper "''${FOCUSED_MON}" "''${CUR_WS}"
|
|
|
|
handle() {
|
|
case "''${1}" in
|
|
focusedmon* )
|
|
local payload="''${1#*>>}"
|
|
FOCUSED_MON="''${payload%%,*}"
|
|
;;
|
|
workspace* )
|
|
local ws="''${1#*>>}"
|
|
ws="''${ws%%:*}"
|
|
ws="''${ws%% *}"
|
|
[[ -n "''${FOCUSED_MON}" && -n "''${ws}" ]] && apply_wallpaper "''${FOCUSED_MON}" "''${ws}"
|
|
;;
|
|
esac
|
|
}
|
|
|
|
socat -U - UNIX-CONNECT:"''${SOCK}" | while read -r line; do
|
|
handle "''${line}" || true
|
|
done
|
|
'';
|
|
};
|
|
|
|
systemd.user.services.hyprpaper = {
|
|
Unit = {
|
|
Description = "hyprpaper wallpaper daemon";
|
|
PartOf = [ "graphical-session.target" ];
|
|
After = [ "graphical-session.target" ];
|
|
};
|
|
Service = {
|
|
ExecStart = "${pkgs.hyprpaper}/bin/hyprpaper";
|
|
Restart = "on-failure";
|
|
RestartSec = 1;
|
|
};
|
|
Install = { WantedBy = [ "graphical-session.target" ]; };
|
|
};
|
|
|
|
systemd.user.services.hyprpaper-workspace-wallpapers = {
|
|
Unit = {
|
|
Description = "Hyprpaper workspace wallpapers (socket2 listener)";
|
|
PartOf = [ "graphical-session.target" ];
|
|
After = [ "graphical-session.target" "hyprpaper.service" ];
|
|
};
|
|
Service = {
|
|
ExecStart = "${pkgs.bash}/bin/bash ${config.xdg.configHome}/${wsScriptRel} ${picturesDir}";
|
|
Restart = "on-failure";
|
|
RestartSec = 1;
|
|
};
|
|
Install = { WantedBy = [ "graphical-session.target" ]; };
|
|
};
|
|
}
|