New rotating_wallpaper.nix
This commit is contained in:
+391
-344
File diff suppressed because it is too large
Load Diff
+88
-41
@@ -1710,67 +1710,114 @@ in
|
||||
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";
|
||||
|
||||
userRelRoot = "nixos_conf/wallpaperstuff";
|
||||
userAbsRoot = "${config.home.homeDirectory}/${userRelRoot}";
|
||||
scriptRel = "hypr/scripts/wpaperd-workspace-1to9.sh";
|
||||
in
|
||||
{
|
||||
#################################
|
||||
# Install wallpaper daemon
|
||||
#################################
|
||||
|
||||
home.packages = [ pkgs.wpaperd ];
|
||||
|
||||
#################################
|
||||
# Copy wallpapers from repo
|
||||
#################################
|
||||
|
||||
home.packages = [
|
||||
pkgs.wpaperd
|
||||
pkgs.socat
|
||||
pkgs.jq
|
||||
];
|
||||
# Copy wallpapers from repo → ~/nixos_conf/wallpaperstuff
|
||||
home.file."${userRelRoot}" = {
|
||||
source = repoWallpaperDir;
|
||||
recursive = true;
|
||||
};
|
||||
|
||||
#################################
|
||||
# Start wpaperd (no config file)
|
||||
#################################
|
||||
|
||||
# Workspace listener script (no wpaperd config needed)
|
||||
xdg.configFile."${scriptRel}".text = ''
|
||||
#!/usr/bin/env bash
|
||||
set -euo pipefail
|
||||
ROOT="${userAbsRoot}"
|
||||
: "''${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" ]] || exit 0
|
||||
# Extract numeric workspace prefix from "1" or "1:foo"
|
||||
ws_num() {
|
||||
local w="''${1%%:*}"
|
||||
[[ "$w" =~ ^[0-9]+$ ]] || return 1
|
||||
printf '%s\n' "$w"
|
||||
}
|
||||
img_for_ws() {
|
||||
local n="$1"
|
||||
case "$n" in
|
||||
1|2|3|4|5|6|7|8|9) printf '%s/wallpaper%s.jpg\n' "$ROOT" "$n" ;;
|
||||
*) return 1 ;;
|
||||
esac
|
||||
}
|
||||
apply_for() {
|
||||
local mon="$1"
|
||||
local ws="$2"
|
||||
local n
|
||||
n="$(ws_num "$ws")" || return 0
|
||||
local img
|
||||
img="$(img_for_ws "$n")" || return 0
|
||||
[[ -f "$img" ]] || return 0
|
||||
# Set wallpaper for specific monitor (supported by wpaperctl)
|
||||
${pkgs.wpaperd}/bin/wpaperctl set "$img" "$mon" >/dev/null 2>&1 || true
|
||||
}
|
||||
apply_initial() {
|
||||
# For each monitor, read its activeWorkspace.name and apply once at startup
|
||||
${pkgs.hyprland}/bin/hyprctl -j monitors \
|
||||
| ${pkgs.jq}/bin/jq -r '.[] | "\(.name)\t\(.activeWorkspace.name)"' \
|
||||
| while IFS=$'\t' read -r mon ws; do
|
||||
[[ -n "$mon" && -n "$ws" ]] || continue
|
||||
apply_for "$mon" "$ws"
|
||||
done
|
||||
}
|
||||
handle_line() {
|
||||
case "$1" in
|
||||
focusedmon\>\>*)
|
||||
# focusedmon>>MONNAME,WORKSPACENAME
|
||||
local payload="''${1#focusedmon>>}"
|
||||
local mon="''${payload%%,*}"
|
||||
local ws="''${payload#*,}"
|
||||
apply_for "$mon" "$ws"
|
||||
;;
|
||||
workspace\>\>*)
|
||||
# workspace>>WORKSPACENAME (no monitor info) — ignore
|
||||
;;
|
||||
workspacev2\>\>*)
|
||||
# workspacev2>>ID,NAME (no monitor info) — ignore
|
||||
;;
|
||||
esac
|
||||
}
|
||||
apply_initial
|
||||
exec ${pkgs.socat}/bin/socat -U - "UNIX-CONNECT:$SOCK" \
|
||||
| while IFS= read -r line; do
|
||||
handle_line "$line" || true
|
||||
done
|
||||
'';
|
||||
xdg.configFile."${scriptRel}".executable = true;
|
||||
# Start wpaperd
|
||||
systemd.user.services.wpaperd = {
|
||||
Unit = {
|
||||
Description = "wpaperd wallpaper daemon";
|
||||
After = [ "graphical-session.target" ];
|
||||
PartOf = [ "graphical-session.target" ];
|
||||
};
|
||||
|
||||
Service = {
|
||||
ExecStart = "${pkgs.wpaperd}/bin/wpaperd";
|
||||
Restart = "on-failure";
|
||||
};
|
||||
|
||||
Install.WantedBy = [ "default.target" ];
|
||||
Install.WantedBy = [ "graphical-session.target" ];
|
||||
};
|
||||
|
||||
#################################
|
||||
# Hyprland workspace → wallpaper
|
||||
#################################
|
||||
|
||||
wayland.windowManager.hyprland = {
|
||||
enable = true;
|
||||
|
||||
extraConfig = ''
|
||||
# Workspace wallpaper bindings
|
||||
|
||||
# bind = $mainMod, 1, exec, hyprctl dispatch workspace 1 && wpaperctl set ${userAbsRoot}/wallpaper1.jpg
|
||||
# bind = $mainMod, 2, exec, hyprctl dispatch workspace 2 && wpaperctl set ${userAbsRoot}/wallpaper2.jpg
|
||||
# bind = $mainMod, 3, exec, hyprctl dispatch workspace 3 && wpaperctl set ${userAbsRoot}/wallpaper3.jpg
|
||||
# bind = $mainMod, 4, exec, hyprctl dispatch workspace 4 && wpaperctl set ${userAbsRoot}/wallpaper4.jpg
|
||||
# bind = $mainMod, 5, exec, hyprctl dispatch workspace 5 && wpaperctl set ${userAbsRoot}/wallpaper5.jpg
|
||||
# bind = $mainMod, 6, exec, hyprctl dispatch workspace 6 && wpaperctl set ${userAbsRoot}/wallpaper6.jpg
|
||||
# bind = $mainMod, 7, exec, hyprctl dispatch workspace 7 && wpaperctl set ${userAbsRoot}/wallpaper7.jpg
|
||||
# bind = $mainMod, 8, exec, hyprctl dispatch workspace 8 && wpaperctl set ${userAbsRoot}/wallpaper8.jpg
|
||||
# bind = $mainMod, 9, exec, hyprctl dispatch workspace 9 && wpaperctl set ${userAbsRoot}/wallpaper9.jpg
|
||||
'';
|
||||
# Listen to Hyprland workspace/monitor focus and set wallpapers accordingly
|
||||
systemd.user.services.wpaperd-workspace-wallpapers = {
|
||||
Unit = {
|
||||
Description = "Set wallpaper based on workspace number (1..9)";
|
||||
After = [ "graphical-session.target" "wpaperd.service" ];
|
||||
PartOf = [ "graphical-session.target" ];
|
||||
};
|
||||
Service = {
|
||||
ExecStart = "${pkgs.bash}/bin/bash ${config.xdg.configHome}/${scriptRel}";
|
||||
Restart = "on-failure";
|
||||
};
|
||||
Install.WantedBy = [ "graphical-session.target" ];
|
||||
};
|
||||
}
|
||||
#+end_src
|
||||
|
||||
@@ -1,64 +1,111 @@
|
||||
{ config, pkgs, lib, flakeRoot, ... }:
|
||||
|
||||
let
|
||||
repoWallpaperDir = flakeRoot + "/assets/conf/desktop/wallpaper";
|
||||
|
||||
userRelRoot = "nixos_conf/wallpaperstuff";
|
||||
userAbsRoot = "${config.home.homeDirectory}/${userRelRoot}";
|
||||
scriptRel = "hypr/scripts/wpaperd-workspace-1to9.sh";
|
||||
in
|
||||
{
|
||||
#################################
|
||||
# Install wallpaper daemon
|
||||
#################################
|
||||
|
||||
home.packages = [ pkgs.wpaperd ];
|
||||
|
||||
#################################
|
||||
# Copy wallpapers from repo
|
||||
#################################
|
||||
|
||||
home.packages = [
|
||||
pkgs.wpaperd
|
||||
pkgs.socat
|
||||
pkgs.jq
|
||||
];
|
||||
# Copy wallpapers from repo → ~/nixos_conf/wallpaperstuff
|
||||
home.file."${userRelRoot}" = {
|
||||
source = repoWallpaperDir;
|
||||
recursive = true;
|
||||
};
|
||||
|
||||
#################################
|
||||
# Start wpaperd (no config file)
|
||||
#################################
|
||||
|
||||
# Workspace listener script (no wpaperd config needed)
|
||||
xdg.configFile."${scriptRel}".text = ''
|
||||
#!/usr/bin/env bash
|
||||
set -euo pipefail
|
||||
ROOT="${userAbsRoot}"
|
||||
: "''${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" ]] || exit 0
|
||||
# Extract numeric workspace prefix from "1" or "1:foo"
|
||||
ws_num() {
|
||||
local w="''${1%%:*}"
|
||||
[[ "$w" =~ ^[0-9]+$ ]] || return 1
|
||||
printf '%s\n' "$w"
|
||||
}
|
||||
img_for_ws() {
|
||||
local n="$1"
|
||||
case "$n" in
|
||||
1|2|3|4|5|6|7|8|9) printf '%s/wallpaper%s.jpg\n' "$ROOT" "$n" ;;
|
||||
*) return 1 ;;
|
||||
esac
|
||||
}
|
||||
apply_for() {
|
||||
local mon="$1"
|
||||
local ws="$2"
|
||||
local n
|
||||
n="$(ws_num "$ws")" || return 0
|
||||
local img
|
||||
img="$(img_for_ws "$n")" || return 0
|
||||
[[ -f "$img" ]] || return 0
|
||||
# Set wallpaper for specific monitor (supported by wpaperctl)
|
||||
${pkgs.wpaperd}/bin/wpaperctl set "$img" "$mon" >/dev/null 2>&1 || true
|
||||
}
|
||||
apply_initial() {
|
||||
# For each monitor, read its activeWorkspace.name and apply once at startup
|
||||
${pkgs.hyprland}/bin/hyprctl -j monitors \
|
||||
| ${pkgs.jq}/bin/jq -r '.[] | "\(.name)\t\(.activeWorkspace.name)"' \
|
||||
| while IFS=$'\t' read -r mon ws; do
|
||||
[[ -n "$mon" && -n "$ws" ]] || continue
|
||||
apply_for "$mon" "$ws"
|
||||
done
|
||||
}
|
||||
handle_line() {
|
||||
case "$1" in
|
||||
focusedmon\>\>*)
|
||||
# focusedmon>>MONNAME,WORKSPACENAME
|
||||
local payload="''${1#focusedmon>>}"
|
||||
local mon="''${payload%%,*}"
|
||||
local ws="''${payload#*,}"
|
||||
apply_for "$mon" "$ws"
|
||||
;;
|
||||
workspace\>\>*)
|
||||
# workspace>>WORKSPACENAME (no monitor info) — ignore
|
||||
;;
|
||||
workspacev2\>\>*)
|
||||
# workspacev2>>ID,NAME (no monitor info) — ignore
|
||||
;;
|
||||
esac
|
||||
}
|
||||
apply_initial
|
||||
exec ${pkgs.socat}/bin/socat -U - "UNIX-CONNECT:$SOCK" \
|
||||
| while IFS= read -r line; do
|
||||
handle_line "$line" || true
|
||||
done
|
||||
'';
|
||||
xdg.configFile."${scriptRel}".executable = true;
|
||||
# Start wpaperd
|
||||
systemd.user.services.wpaperd = {
|
||||
Unit = {
|
||||
Description = "wpaperd wallpaper daemon";
|
||||
After = [ "graphical-session.target" ];
|
||||
PartOf = [ "graphical-session.target" ];
|
||||
};
|
||||
|
||||
Service = {
|
||||
ExecStart = "${pkgs.wpaperd}/bin/wpaperd";
|
||||
Restart = "on-failure";
|
||||
};
|
||||
|
||||
Install.WantedBy = [ "default.target" ];
|
||||
Install.WantedBy = [ "graphical-session.target" ];
|
||||
};
|
||||
|
||||
#################################
|
||||
# Hyprland workspace → wallpaper
|
||||
#################################
|
||||
|
||||
wayland.windowManager.hyprland = {
|
||||
enable = true;
|
||||
|
||||
extraConfig = ''
|
||||
# Workspace wallpaper bindings
|
||||
|
||||
# bind = $mainMod, 1, exec, hyprctl dispatch workspace 1 && wpaperctl set ${userAbsRoot}/wallpaper1.jpg
|
||||
# bind = $mainMod, 2, exec, hyprctl dispatch workspace 2 && wpaperctl set ${userAbsRoot}/wallpaper2.jpg
|
||||
# bind = $mainMod, 3, exec, hyprctl dispatch workspace 3 && wpaperctl set ${userAbsRoot}/wallpaper3.jpg
|
||||
# bind = $mainMod, 4, exec, hyprctl dispatch workspace 4 && wpaperctl set ${userAbsRoot}/wallpaper4.jpg
|
||||
# bind = $mainMod, 5, exec, hyprctl dispatch workspace 5 && wpaperctl set ${userAbsRoot}/wallpaper5.jpg
|
||||
# bind = $mainMod, 6, exec, hyprctl dispatch workspace 6 && wpaperctl set ${userAbsRoot}/wallpaper6.jpg
|
||||
# bind = $mainMod, 7, exec, hyprctl dispatch workspace 7 && wpaperctl set ${userAbsRoot}/wallpaper7.jpg
|
||||
# bind = $mainMod, 8, exec, hyprctl dispatch workspace 8 && wpaperctl set ${userAbsRoot}/wallpaper8.jpg
|
||||
# bind = $mainMod, 9, exec, hyprctl dispatch workspace 9 && wpaperctl set ${userAbsRoot}/wallpaper9.jpg
|
||||
'';
|
||||
# Listen to Hyprland workspace/monitor focus and set wallpapers accordingly
|
||||
systemd.user.services.wpaperd-workspace-wallpapers = {
|
||||
Unit = {
|
||||
Description = "Set wallpaper based on workspace number (1..9)";
|
||||
After = [ "graphical-session.target" "wpaperd.service" ];
|
||||
PartOf = [ "graphical-session.target" ];
|
||||
};
|
||||
Service = {
|
||||
ExecStart = "${pkgs.bash}/bin/bash ${config.xdg.configHome}/${scriptRel}";
|
||||
Restart = "on-failure";
|
||||
};
|
||||
Install.WantedBy = [ "graphical-session.target" ];
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user