added automatic wallpaper setting
This commit is contained in:
+6
-1
@@ -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";
|
||||
|
||||
Executable
+79
@@ -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
|
||||
@@ -1,6 +1,10 @@
|
||||
{ config, lib, pkgs, ... }:
|
||||
|
||||
{
|
||||
imports = [
|
||||
../utilities/autowallpaper.nix
|
||||
];
|
||||
|
||||
home.activation.createAudioDirectories =
|
||||
lib.hm.dag.entryAfter [ "writeBoundary" ] ''
|
||||
mkdir -p \
|
||||
|
||||
@@ -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" ];
|
||||
};
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user