From bf1053c4a7e716a6176095e1daec6746e8137af2 Mon Sep 17 00:00:00 2001 From: cybrneko Date: Sun, 5 Jul 2026 16:08:32 -0500 Subject: [PATCH] added automatic wallpaper setting --- configuration.nix | 7 +++- scripts/wallpaper-watch.sh | 79 +++++++++++++++++++++++++++++++++++++ users/cybrneko.nix | 4 ++ utilities/autowallpaper.nix | 29 ++++++++++++++ 4 files changed, 118 insertions(+), 1 deletion(-) create mode 100755 scripts/wallpaper-watch.sh create mode 100644 utilities/autowallpaper.nix diff --git a/configuration.nix b/configuration.nix index 167b62a..9a2be2c 100644 --- a/configuration.nix +++ b/configuration.nix @@ -25,7 +25,12 @@ # networking.proxy.noProxy = "127.0.0.1,localhost,internal.domain"; # Enable networking - networking.networkmanager.enable = true; + networking.networkmanager = { + enable = true; + plugins = with pkgs; [ + networkmanager-openvpn + ]; + }; # Set your time zone. time.timeZone = "America/Chicago"; diff --git a/scripts/wallpaper-watch.sh b/scripts/wallpaper-watch.sh new file mode 100755 index 0000000..6fdeb9a --- /dev/null +++ b/scripts/wallpaper-watch.sh @@ -0,0 +1,79 @@ +#!/usr/bin/env bash +set -euo pipefail + +WP_DIR="$HOME/Pictures/Wallpapers" +aspect_name() { + local w="$1" + local h="$2" + local a="$w" + local b="$h" + local t + local aspect + + while (( b != 0 )); do + t=$b + b=$(( a % b )) + a=$t + done + + aspect="$(( w / a ))x$(( h / a ))" + + case "$aspect" in + 64x27|43x18) + echo "21x9" + ;; + 8x5) + echo "16x10" + ;; + *) + echo "$aspect" + ;; + esac +} + +process_wallpapers() { + wallpapers=() + while read -r line; do + if [[ "$line" == *"+*"* ]]; then + role="primary" + else + role="secondary" + fi + + geom="$(awk '{print $3}' <<< "$line")" + + width="${geom%%/*}" + rest="${geom#*x}" + height="${rest%%/*}" + + aspect="$(aspect_name "$width" "$height")" + wallpapers+=("$WP_DIR/$aspect-$role.png") + done < <(xrandr --listmonitors | tail -n +2) + + count="${#wallpapers[@]}" + + modes=() + for (( i=0; i<${#wallpapers[@]}; i++ )); do + modes+=("zoom") + done + + echo "${wallpapers[@]}" + + hydrapaper --cli "${wallpapers[@]}" --mode "${modes[@]}" +} + +last_applied="" +pending="" + +while true; do + current="$(xrandr --query 2>/dev/null | grep ' connected' || true)" + + if [[ "$current" != "$pending" ]]; then + pending="$current" + elif [[ "$current" != "$last_applied" ]]; then + last_applied="$current" + process_wallpapers + fi + + sleep 1 +done diff --git a/users/cybrneko.nix b/users/cybrneko.nix index 6473632..21d177a 100644 --- a/users/cybrneko.nix +++ b/users/cybrneko.nix @@ -1,6 +1,10 @@ { config, lib, pkgs, ... }: { + imports = [ + ../utilities/autowallpaper.nix + ]; + home.activation.createAudioDirectories = lib.hm.dag.entryAfter [ "writeBoundary" ] '' mkdir -p \ diff --git a/utilities/autowallpaper.nix b/utilities/autowallpaper.nix new file mode 100644 index 0000000..c544206 --- /dev/null +++ b/utilities/autowallpaper.nix @@ -0,0 +1,29 @@ +{ config, pkgs, ... }: + +let + wallpaperWatch = pkgs.writeShellScriptBin "wallpaper-watch" + (builtins.readFile ../scripts/wallpaper-watch.sh); +in +{ + home.packages = [ + wallpaperWatch + ]; + + systemd.user.services.wallpaper-watcher = { + Unit = { + Description = "Dynamic wallpaper watcher"; + After = [ "graphical-session.target" ]; + PartOf = [ "graphical-session.target" ]; + }; + + Service = { + ExecStart = "${wallpaperWatch}/bin/wallpaper-watch"; + Restart = "always"; + RestartSec = 2; + }; + + Install = { + WantedBy = [ "graphical-session.target" ]; + }; + }; +}