From 272b81acf4371883f052962b563cb4cb914fb5b6 Mon Sep 17 00:00:00 2001 From: Henro Veijer Date: Thu, 26 Feb 2026 16:48:38 +0100 Subject: [PATCH] Added workspace_wallpaper --- henrovnix_ok/README.org | 124 ++++++++++++++++++ .../{background1.jpg => wallpaper1.jpg} | Bin .../{background2.jpg => wallpaper2.jpg} | Bin .../{background3.jpg => wallpaper3.jpg} | Bin .../{background4.jpg => wallpaper4.jpg} | Bin .../{background5.jpg => wallpaper5.jpg} | Bin .../{background.png => wallpaper6.png} | Bin 7 files changed, 124 insertions(+) rename henrovnix_ok/assets/conf/desktop/wallpaper/pictures/{background1.jpg => wallpaper1.jpg} (100%) rename henrovnix_ok/assets/conf/desktop/wallpaper/pictures/{background2.jpg => wallpaper2.jpg} (100%) rename henrovnix_ok/assets/conf/desktop/wallpaper/pictures/{background3.jpg => wallpaper3.jpg} (100%) rename henrovnix_ok/assets/conf/desktop/wallpaper/pictures/{background4.jpg => wallpaper4.jpg} (100%) rename henrovnix_ok/assets/conf/desktop/wallpaper/pictures/{background5.jpg => wallpaper5.jpg} (100%) rename henrovnix_ok/assets/conf/desktop/wallpaper/pictures/{background.png => wallpaper6.png} (100%) diff --git a/henrovnix_ok/README.org b/henrovnix_ok/README.org index 04dc00a6e..d5ec96213 100755 --- a/henrovnix_ok/README.org +++ b/henrovnix_ok/README.org @@ -1704,6 +1704,130 @@ in } #+end_src +** Workspace_Wallpaper +workspace_wallpaper installs wpaperd and deploys your wallpaper files from the repo (./assets/conf/desktop/wallpaper/pictures/) into ~/conf/desktop/wallpaper/pictures. It also deploys the default wallpaper configuration from assets/conf/desktop/wallpaper/wallpaper.conf into ~/conf/desktop/wallpaper/wallpaper.conf, which is the file you can edit as a user override. +#+begin_src nix :tangle home/desktop/workspace_wallpaper.nix :noweb tangle :mkdirp yes +{ config, pkgs, lib, flakeRoot, ... }: +let + repoWallpaperDir = flakeRoot + "/assets/conf/desktop/wallpaper"; + repoWallpaperConf = flakeRoot + "/assets/conf/desktop/wallpaper/wallpaper.conf"; + + userRelRoot = "nixos_conf/wallpaperstuff"; + userAbsRoot = "${config.home.homeDirectory}/${userRelRoot}"; + userConfPath = "${userAbsRoot}/wallpaper.conf"; + + userWsScriptPath = "${userAbsRoot}/wpaperd-workspace-1to9.sh"; + + # Exclude wallpaper.conf so HM does NOT manage it (avoids backup collisions) + repoWallpapersOnly = lib.cleanSourceWith { + src = repoWallpaperDir; + filter = path: type: + (builtins.baseNameOf path) != "wallpaper.conf"; + }; + + wsScript = '' + #!/usr/bin/env bash + set -euo pipefail + + ROOT_DIR="${1:?usage: wpaperd-workspace-1to9.sh /path/to/wallpaper-dir}" + + : "''${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; } + + set_for_ws() { + local ws_raw="$1" + # Hyprland workspace name may look like "1" or "1:foo" — take the numeric prefix + local ws="''${ws_raw%%:*}" + + [[ "$ws" =~ ^[1-9]$ ]] || return 0 + + local img="$ROOT_DIR/wallpaper$ws.jpg" + if [[ -f "$img" ]]; then + ${pkgs.wpaperd}/bin/wpaperctl set "$img" >/dev/null 2>&1 || true + fi + } + + # Apply once at start (best effort): ask hyprctl for active workspace name + if command -v ${pkgs.hyprland}/bin/hyprctl >/dev/null 2>&1; then + cur="$(${pkgs.hyprland}/bin/hyprctl activeworkspace -j 2>/dev/null | ${pkgs.jq}/bin/jq -r '.name // empty' || true)" + [[ -n "''${cur:-}" ]] && set_for_ws "$cur" || true + fi + + exec ${pkgs.socat}/bin/socat -u "UNIX-CONNECT:$SOCK" - | while IFS= read -r line; do + case "$line" in + workspace\>\>*) + ws="''${line#workspace>>}" + set_for_ws "$ws" + ;; + esac + done + ''; +in +{ + home.packages = [ + pkgs.wpaperd + pkgs.socat + pkgs.jq + pkgs.hyprland + ]; + + # Sync everything *except* wallpaper.conf into ~/nixos_conf/wallpaperstuff + # Put wallpaper1.jpg .. wallpaper9.jpg in your repo wallpaper dir and they’ll be copied here. + home.file."${userRelRoot}" = { + source = repoWallpapersOnly; + recursive = true; + }; + + # Now safely overwrite the config every activation (no HM collision) + home.activation.wallpaperConfForce = + lib.hm.dag.entryAfter [ "writeBoundary" ] '' + set -euo pipefail + mkdir -p "${userAbsRoot}" + install -m 0644 "${repoWallpaperConf}" "${userConfPath}" + ''; + + # Install the listener script + home.file."${userRelRoot}/wpaperd-workspace-1to9.sh" = { + text = wsScript; + executable = true; + }; + + # wpaperd daemon + systemd.user.services.wpaperd = { + Unit = { + Description = "wpaperd wallpaper daemon"; + After = [ "default.target" ]; + }; + Service = { + Type = "simple"; + ExecStart = "${pkgs.wpaperd}/bin/wpaperd --config ${userConfPath}"; + Restart = "on-failure"; + RestartSec = 1; + }; + Install.WantedBy = [ "default.target" ]; + }; + + # Workspace listener: switches wallpaper when workspace changes (1..9) + systemd.user.services.wpaperd-workspace-1to9 = { + Unit = { + Description = "Set wallpaper1..9.jpg per Hyprland workspace (wpaperctl)"; + After = [ "wpaperd.service" "graphical-session.target" ]; + PartOf = [ "graphical-session.target" ]; + }; + Service = { + Type = "simple"; + ExecStart = "${pkgs.bash}/bin/bash ${userWsScriptPath} ${userAbsRoot}"; + Restart = "on-failure"; + RestartSec = 1; + }; + Install.WantedBy = [ "default.target" ]; + }; +} +#+end_src + ** Animated Wallpaper userRelRoot = "nixos_conf/wallpaperstuff"; animated_wallpaper.nix installs mpvpaper and deploys your wallpaper files from the repo (./assets/conf/desktop/wallpaper) into ~/conf/desktop/wallpaper/pictures. diff --git a/henrovnix_ok/assets/conf/desktop/wallpaper/pictures/background1.jpg b/henrovnix_ok/assets/conf/desktop/wallpaper/pictures/wallpaper1.jpg similarity index 100% rename from henrovnix_ok/assets/conf/desktop/wallpaper/pictures/background1.jpg rename to henrovnix_ok/assets/conf/desktop/wallpaper/pictures/wallpaper1.jpg diff --git a/henrovnix_ok/assets/conf/desktop/wallpaper/pictures/background2.jpg b/henrovnix_ok/assets/conf/desktop/wallpaper/pictures/wallpaper2.jpg similarity index 100% rename from henrovnix_ok/assets/conf/desktop/wallpaper/pictures/background2.jpg rename to henrovnix_ok/assets/conf/desktop/wallpaper/pictures/wallpaper2.jpg diff --git a/henrovnix_ok/assets/conf/desktop/wallpaper/pictures/background3.jpg b/henrovnix_ok/assets/conf/desktop/wallpaper/pictures/wallpaper3.jpg similarity index 100% rename from henrovnix_ok/assets/conf/desktop/wallpaper/pictures/background3.jpg rename to henrovnix_ok/assets/conf/desktop/wallpaper/pictures/wallpaper3.jpg diff --git a/henrovnix_ok/assets/conf/desktop/wallpaper/pictures/background4.jpg b/henrovnix_ok/assets/conf/desktop/wallpaper/pictures/wallpaper4.jpg similarity index 100% rename from henrovnix_ok/assets/conf/desktop/wallpaper/pictures/background4.jpg rename to henrovnix_ok/assets/conf/desktop/wallpaper/pictures/wallpaper4.jpg diff --git a/henrovnix_ok/assets/conf/desktop/wallpaper/pictures/background5.jpg b/henrovnix_ok/assets/conf/desktop/wallpaper/pictures/wallpaper5.jpg similarity index 100% rename from henrovnix_ok/assets/conf/desktop/wallpaper/pictures/background5.jpg rename to henrovnix_ok/assets/conf/desktop/wallpaper/pictures/wallpaper5.jpg diff --git a/henrovnix_ok/assets/conf/desktop/wallpaper/pictures/background.png b/henrovnix_ok/assets/conf/desktop/wallpaper/pictures/wallpaper6.png similarity index 100% rename from henrovnix_ok/assets/conf/desktop/wallpaper/pictures/background.png rename to henrovnix_ok/assets/conf/desktop/wallpaper/pictures/wallpaper6.png