Loaned script from the internet
This commit is contained in:
+440
-340
File diff suppressed because it is too large
Load Diff
+154
-30
@@ -1765,82 +1765,205 @@ in
|
|||||||
** Workspace Wallpaper
|
** Workspace Wallpaper
|
||||||
#+begin_src nix :tangle home/desktop/workspace_wallpaper.nix :noweb tangle :mkdirp yes
|
#+begin_src nix :tangle home/desktop/workspace_wallpaper.nix :noweb tangle :mkdirp yes
|
||||||
{ config, lib, pkgs, flakeRoot, ... }:
|
{ config, lib, pkgs, flakeRoot, ... }:
|
||||||
|
|
||||||
let
|
let
|
||||||
repoWallpaperDir = flakeRoot + "/assets/conf/desktop/wallpaper";
|
# Where your numbered wallpapers live (1.*, 2.*, ... 9.*)
|
||||||
userRelRoot = "nixos_conf/wallpaperstuff";
|
userRelRoot = "nixos_conf/wallpaperstuff";
|
||||||
userAbsRoot = "${config.home.homeDirectory}/${userRelRoot}";
|
userAbsRoot = "${config.home.homeDirectory}/${userRelRoot}";
|
||||||
picturesDir = "${userAbsRoot}/pictures";
|
picturesDir = "${userAbsRoot}/pictures";
|
||||||
|
|
||||||
|
# (Optional) still sync your repo wallpapers/scripts into ~/nixos_conf/wallpaperstuff
|
||||||
|
repoWallpaperDir = flakeRoot + "/assets/conf/desktop/wallpaper";
|
||||||
repoWallpapersOnly = lib.cleanSourceWith {
|
repoWallpapersOnly = lib.cleanSourceWith {
|
||||||
src = repoWallpaperDir;
|
src = repoWallpaperDir;
|
||||||
filter = path: type: true;
|
filter = path: type: true;
|
||||||
};
|
};
|
||||||
wsScriptRel = "hypr/scripts/hyprpaper-workspace-1to9.sh";
|
|
||||||
|
daemonRel = "hypr/scripts/hyprpaper-ws-daemon.sh";
|
||||||
|
setRel = "hypr/scripts/set-wallpaper.sh";
|
||||||
in
|
in
|
||||||
{
|
{
|
||||||
home.packages = [ pkgs.hyprpaper pkgs.socat pkgs.jq ];
|
home.packages = [
|
||||||
|
pkgs.hyprpaper
|
||||||
|
pkgs.socat
|
||||||
|
pkgs.jq
|
||||||
|
pkgs.findutils
|
||||||
|
pkgs.coreutils
|
||||||
|
pkgs.gnused
|
||||||
|
pkgs.gawk
|
||||||
|
];
|
||||||
|
|
||||||
|
# Keep your existing "sync wallpapers into a writable dir" pattern
|
||||||
home.file."${userRelRoot}" = {
|
home.file."${userRelRoot}" = {
|
||||||
source = repoWallpapersOnly;
|
source = repoWallpapersOnly;
|
||||||
recursive = true;
|
recursive = true;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
# Hyprpaper config (hyprpaper reads this; it does NOT need to write it)
|
||||||
|
# `ipc = true` enables `hyprctl hyprpaper ...` commands. :contentReference[oaicite:0]{index=0}
|
||||||
xdg.configFile."hypr/hyprpaper.conf".text = ''
|
xdg.configFile."hypr/hyprpaper.conf".text = ''
|
||||||
ipc = true
|
ipc = true
|
||||||
splash = false
|
splash = false
|
||||||
'';
|
'';
|
||||||
xdg.configFile."${wsScriptRel}" = {
|
|
||||||
|
# Workspace wallpaper daemon: listens to socket2, applies w-<id>=... mapping
|
||||||
|
# Uses workspacev2 to get numeric workspace id. :contentReference[oaicite:1]{index=1}
|
||||||
|
xdg.configFile."${daemonRel}" = {
|
||||||
executable = true;
|
executable = true;
|
||||||
text = ''
|
text = ''
|
||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
set -euo pipefail
|
set -euo pipefail
|
||||||
|
|
||||||
: "''${XDG_RUNTIME_DIR:?XDG_RUNTIME_DIR not set}"
|
: "''${XDG_RUNTIME_DIR:?XDG_RUNTIME_DIR not set}"
|
||||||
: "''${HYPRLAND_INSTANCE_SIGNATURE:?HYPRLAND_INSTANCE_SIGNATURE not set}"
|
: "''${HYPRLAND_INSTANCE_SIGNATURE:?HYPRLAND_INSTANCE_SIGNATURE not set}"
|
||||||
|
|
||||||
SOCK="''${XDG_RUNTIME_DIR}/hypr/''${HYPRLAND_INSTANCE_SIGNATURE}/.socket2.sock"
|
SOCK="''${XDG_RUNTIME_DIR}/hypr/''${HYPRLAND_INSTANCE_SIGNATURE}/.socket2.sock"
|
||||||
[[ -S "$SOCK" ]] || { echo "Hyprland socket not found: $SOCK" >&2; exit 1; }
|
[[ -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}}"
|
PICTURES_DIR="''${1:-${picturesDir}}"
|
||||||
FIT_MODE="fill"
|
FIT_MODE="fill" # hyprpaper fit_mode: contain|cover|tile|fill :contentReference[oaicite:2]{index=2}
|
||||||
FOCUSED_MON=""
|
|
||||||
pick_wall_for_ws() {
|
HYPR_DIR="''${XDG_CONFIG_HOME:-$HOME/.config}/hypr"
|
||||||
local ws="''${1}"
|
MAP_ROOT="''${HYPR_DIR}/hyprpaper/config"
|
||||||
|
|
||||||
|
focused_monitor() {
|
||||||
|
hyprctl -j monitors | jq -r '.[] | select(.focused==true) | .name' | head -n 1
|
||||||
|
}
|
||||||
|
|
||||||
|
map_file_for_monitor() {
|
||||||
|
local mon="''${1}"
|
||||||
|
echo "''${MAP_ROOT}/''${mon}/defaults.conf"
|
||||||
|
}
|
||||||
|
|
||||||
|
ensure_map_file() {
|
||||||
|
local mon="''${1}"
|
||||||
local f
|
local f
|
||||||
f="$(ls -1 "''${PICTURES_DIR}/''${ws}."* 2>/dev/null | head -n 1 || true)"
|
f="$(map_file_for_monitor "''${mon}")"
|
||||||
|
mkdir -p "$(dirname "''${f}")"
|
||||||
|
if [[ ! -f "''${f}" ]]; then
|
||||||
|
# Seed with 1..9 from picturesDir if present, else empty entries
|
||||||
|
{
|
||||||
|
for i in 1 2 3 4 5 6 7 8 9; do
|
||||||
|
seed="$(ls -1 "''${PICTURES_DIR}/''${i}."* 2>/dev/null | head -n 1 || true)"
|
||||||
|
echo "w-''${i}= ''${seed}"
|
||||||
|
done
|
||||||
|
} > "''${f}"
|
||||||
|
fi
|
||||||
echo "''${f}"
|
echo "''${f}"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
get_wall_for_ws() {
|
||||||
|
local mon="''${1}"
|
||||||
|
local wsid="''${2}"
|
||||||
|
local f key val
|
||||||
|
f="$(ensure_map_file "''${mon}")"
|
||||||
|
key="w-''${wsid}"
|
||||||
|
# accept "w-1=/path" or "w-1= /path"
|
||||||
|
val="$(awk -F= -v k="''${key}" '$1==k {sub(/^[[:space:]]+/, "", $2); print $2; exit}' "''${f}" || true)"
|
||||||
|
echo "''${val}"
|
||||||
|
}
|
||||||
|
|
||||||
apply_wallpaper() {
|
apply_wallpaper() {
|
||||||
local mon="''${1}"
|
local mon="''${1}"
|
||||||
local ws="''${2}"
|
local wsid="''${2}"
|
||||||
local file
|
local file
|
||||||
file="$(pick_wall_for_ws "''${ws}")"
|
|
||||||
|
file="$(get_wall_for_ws "''${mon}" "''${wsid}")"
|
||||||
[[ -n "''${file}" ]] || return 0
|
[[ -n "''${file}" ]] || return 0
|
||||||
|
[[ -f "''${file}" ]] || return 0
|
||||||
|
|
||||||
|
# Apply via IPC
|
||||||
|
# hyprpaper “wallpaper { monitor path fit_mode }” model is per monitor. :contentReference[oaicite:3]{index=3}
|
||||||
hyprctl hyprpaper wallpaper "''${mon}, ''${file}, ''${FIT_MODE}" >/dev/null
|
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)"
|
# Initial apply on startup
|
||||||
CUR_WS="''${CUR_WS%%:*}"
|
mon="$(focused_monitor || true)"
|
||||||
[[ -n "''${FOCUSED_MON}" && -n "''${CUR_WS}" ]] && apply_wallpaper "''${FOCUSED_MON}" "''${CUR_WS}"
|
wsid="$(hyprctl -j activeworkspace | jq -r '.id' | head -n 1 || true)"
|
||||||
|
[[ -n "''${mon}" && -n "''${wsid}" ]] && apply_wallpaper "''${mon}" "''${wsid}"
|
||||||
|
|
||||||
handle() {
|
handle() {
|
||||||
case "''${1}" in
|
local line="''${1}"
|
||||||
focusedmon* )
|
case "''${line}" in
|
||||||
local payload="''${1#*>>}"
|
workspacev2* )
|
||||||
FOCUSED_MON="''${payload%%,*}"
|
# workspacev2>>ID,NAME :contentReference[oaicite:4]{index=4}
|
||||||
|
local payload wsid
|
||||||
|
payload="''${line#*>>}"
|
||||||
|
wsid="''${payload%%,*}"
|
||||||
|
mon="$(focused_monitor || true)"
|
||||||
|
[[ -n "''${mon}" && -n "''${wsid}" ]] && apply_wallpaper "''${mon}" "''${wsid}"
|
||||||
;;
|
;;
|
||||||
workspace* )
|
focusedmon* )
|
||||||
local ws="''${1#*>>}"
|
# focusedmon>>MON,WORKSPACENAME :contentReference[oaicite:5]{index=5}
|
||||||
ws="''${ws%%:*}"
|
# When monitor focus changes, re-apply for the active workspace id.
|
||||||
ws="''${ws%% *}"
|
mon="$(focused_monitor || true)"
|
||||||
[[ -n "''${FOCUSED_MON}" && -n "''${ws}" ]] && apply_wallpaper "''${FOCUSED_MON}" "''${ws}"
|
wsid="$(hyprctl -j activeworkspace | jq -r '.id' | head -n 1 || true)"
|
||||||
|
[[ -n "''${mon}" && -n "''${wsid}" ]] && apply_wallpaper "''${mon}" "''${wsid}"
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
}
|
}
|
||||||
|
|
||||||
socat -U - UNIX-CONNECT:"''${SOCK}" | while read -r line; do
|
socat -U - UNIX-CONNECT:"''${SOCK}" | while read -r line; do
|
||||||
handle "''${line}" || true
|
handle "''${line}" || true
|
||||||
done
|
done
|
||||||
'';
|
'';
|
||||||
};
|
};
|
||||||
|
|
||||||
|
# CLI setter in the style of your inspiration script.
|
||||||
|
# Usage: set-wallpaper.sh <workspace_id> <monitor> [wallpaper]
|
||||||
|
xdg.configFile."${setRel}" = {
|
||||||
|
executable = true;
|
||||||
|
text = ''
|
||||||
|
#!/usr/bin/env bash
|
||||||
|
set -euo pipefail
|
||||||
|
|
||||||
|
HYPR_DIR="''${XDG_CONFIG_HOME:-$HOME/.config}/hypr"
|
||||||
|
MAP_ROOT="''${HYPR_DIR}/hyprpaper/config"
|
||||||
|
|
||||||
|
usage() {
|
||||||
|
echo "Usage: set-wallpaper.sh <workspace_id> <monitor> [wallpaper_path]"
|
||||||
|
}
|
||||||
|
|
||||||
|
wsid="''${1:-}"
|
||||||
|
mon="''${2:-}"
|
||||||
|
wp="''${3:-}"
|
||||||
|
|
||||||
|
[[ -n "''${wsid}" ]] || { usage; exit 1; }
|
||||||
|
[[ -n "''${mon}" ]] || { usage; exit 1; }
|
||||||
|
|
||||||
|
cfg="''${MAP_ROOT}/''${mon}/defaults.conf"
|
||||||
|
mkdir -p "$(dirname "''${cfg}")"
|
||||||
|
[[ -f "''${cfg}" ]] || touch "''${cfg}"
|
||||||
|
|
||||||
|
if [[ -z "''${wp}" ]]; then
|
||||||
|
# Random pick from your defaults folder if you want; adjust path if needed:
|
||||||
|
wp="$(find "$HOME/.config/wallpapers/defaults" -type f 2>/dev/null | shuf -n 1 || true)"
|
||||||
|
[[ -n "''${wp}" ]] || { echo "No wallpaper found (random). Provide a path as arg 3."; exit 1; }
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Ensure key exists; if not, append it
|
||||||
|
key="w-''${wsid}"
|
||||||
|
if ! grep -q "^''${key}=" "''${cfg}"; then
|
||||||
|
echo "''${key}=" >> "''${cfg}"
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Set mapping
|
||||||
|
${pkgs.gnused}/bin/sed -i "s|^''${key}=.*|''${key}= ''${wp}|g" "''${cfg}"
|
||||||
|
|
||||||
|
# If this monitor is currently showing that workspace id, apply immediately
|
||||||
|
curws="$(hyprctl -j monitors | jq -r --arg m "''${mon}" '.[] | select(.name==$m) | .activeWorkspace.id' | head -n 1 || true)"
|
||||||
|
if [[ "''${curws}" == "''${wsid}" ]]; then
|
||||||
|
hyprctl hyprpaper wallpaper "''${mon}, ''${wp}, fill" >/dev/null
|
||||||
|
fi
|
||||||
|
'';
|
||||||
|
};
|
||||||
|
|
||||||
|
# Services
|
||||||
systemd.user.services.hyprpaper = {
|
systemd.user.services.hyprpaper = {
|
||||||
Unit = {
|
Unit = {
|
||||||
Description = "hyprpaper wallpaper daemon";
|
Description = "hyprpaper wallpaper daemon";
|
||||||
PartOf = [ "graphical-session.target" ];
|
PartOf = [ "graphical-session.target" ];
|
||||||
After = [ "graphical-session.target" ];
|
After = [ "graphical-session.target" ];
|
||||||
};
|
};
|
||||||
Service = {
|
Service = {
|
||||||
ExecStart = "${pkgs.hyprpaper}/bin/hyprpaper";
|
ExecStart = "${pkgs.hyprpaper}/bin/hyprpaper";
|
||||||
@@ -1849,14 +1972,15 @@ in
|
|||||||
};
|
};
|
||||||
Install = { WantedBy = [ "graphical-session.target" ]; };
|
Install = { WantedBy = [ "graphical-session.target" ]; };
|
||||||
};
|
};
|
||||||
systemd.user.services.hyprpaper-workspace-wallpapers = {
|
|
||||||
|
systemd.user.services.hyprpaper-ws-daemon = {
|
||||||
Unit = {
|
Unit = {
|
||||||
Description = "Hyprpaper workspace wallpapers (socket2 listener)";
|
Description = "Workspace->wallpaper mapping daemon (hyprpaper + socket2)";
|
||||||
PartOf = [ "graphical-session.target" ];
|
PartOf = [ "graphical-session.target" ];
|
||||||
After = [ "graphical-session.target" "hyprpaper.service" ];
|
After = [ "graphical-session.target" "hyprpaper.service" ];
|
||||||
};
|
};
|
||||||
Service = {
|
Service = {
|
||||||
ExecStart = "${pkgs.bash}/bin/bash ${config.xdg.configHome}/${wsScriptRel} ${picturesDir}";
|
ExecStart = "${pkgs.bash}/bin/bash ${config.xdg.configHome}/${daemonRel} ${picturesDir}";
|
||||||
Restart = "on-failure";
|
Restart = "on-failure";
|
||||||
RestartSec = 1;
|
RestartSec = 1;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -4,20 +4,17 @@ let
|
|||||||
in
|
in
|
||||||
{
|
{
|
||||||
programs.waybar.enable = true;
|
programs.waybar.enable = true;
|
||||||
|
|
||||||
# Ensure config matches repo (HM-managed symlink, not user-editable)
|
# Ensure config matches repo (HM-managed symlink, not user-editable)
|
||||||
xdg.configFile."waybar/config" = {
|
xdg.configFile."waybar/config" = {
|
||||||
source = repoWaybarDir + "/config.jsonc";
|
source = repoWaybarDir + "/config.jsonc";
|
||||||
force = true;
|
force = true;
|
||||||
};
|
};
|
||||||
|
|
||||||
# Override HM's internally-generated waybar-style.css derivation
|
# Override HM's internally-generated waybar-style.css derivation
|
||||||
# and use your repo file instead.
|
# and use your repo file instead.
|
||||||
xdg.configFile."waybar/style.css" = {
|
xdg.configFile."waybar/style.css" = {
|
||||||
source = lib.mkForce (repoWaybarDir + "/style.css");
|
source = lib.mkForce (repoWaybarDir + "/style.css");
|
||||||
force = true;
|
force = true;
|
||||||
};
|
};
|
||||||
|
|
||||||
# Prevent HM from also trying to generate style content via programs.waybar.style
|
# Prevent HM from also trying to generate style content via programs.waybar.style
|
||||||
# (not strictly required once mkForce is in place, but keeps intent clear)
|
# (not strictly required once mkForce is in place, but keeps intent clear)
|
||||||
programs.waybar.style = "";
|
programs.waybar.style = "";
|
||||||
|
|||||||
@@ -1,33 +1,48 @@
|
|||||||
{ config, lib, pkgs, flakeRoot, ... }:
|
{ config, lib, pkgs, flakeRoot, ... }:
|
||||||
|
|
||||||
let
|
let
|
||||||
repoWallpaperDir = flakeRoot + "/assets/conf/desktop/wallpaper";
|
# Where your numbered wallpapers live (1.*, 2.*, ... 9.*)
|
||||||
|
|
||||||
userRelRoot = "nixos_conf/wallpaperstuff";
|
userRelRoot = "nixos_conf/wallpaperstuff";
|
||||||
userAbsRoot = "${config.home.homeDirectory}/${userRelRoot}";
|
userAbsRoot = "${config.home.homeDirectory}/${userRelRoot}";
|
||||||
picturesDir = "${userAbsRoot}/pictures";
|
picturesDir = "${userAbsRoot}/pictures";
|
||||||
|
|
||||||
|
# (Optional) still sync your repo wallpapers/scripts into ~/nixos_conf/wallpaperstuff
|
||||||
|
repoWallpaperDir = flakeRoot + "/assets/conf/desktop/wallpaper";
|
||||||
repoWallpapersOnly = lib.cleanSourceWith {
|
repoWallpapersOnly = lib.cleanSourceWith {
|
||||||
src = repoWallpaperDir;
|
src = repoWallpaperDir;
|
||||||
filter = path: type: true;
|
filter = path: type: true;
|
||||||
};
|
};
|
||||||
|
|
||||||
wsScriptRel = "hypr/scripts/hyprpaper-workspace-1to9.sh";
|
daemonRel = "hypr/scripts/hyprpaper-ws-daemon.sh";
|
||||||
|
setRel = "hypr/scripts/set-wallpaper.sh";
|
||||||
in
|
in
|
||||||
{
|
{
|
||||||
home.packages = [ pkgs.hyprpaper pkgs.socat pkgs.jq ];
|
home.packages = [
|
||||||
|
pkgs.hyprpaper
|
||||||
|
pkgs.socat
|
||||||
|
pkgs.jq
|
||||||
|
pkgs.findutils
|
||||||
|
pkgs.coreutils
|
||||||
|
pkgs.gnused
|
||||||
|
pkgs.gawk
|
||||||
|
];
|
||||||
|
|
||||||
|
# Keep your existing "sync wallpapers into a writable dir" pattern
|
||||||
home.file."${userRelRoot}" = {
|
home.file."${userRelRoot}" = {
|
||||||
source = repoWallpapersOnly;
|
source = repoWallpapersOnly;
|
||||||
recursive = true;
|
recursive = true;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
# Hyprpaper config (hyprpaper reads this; it does NOT need to write it)
|
||||||
|
# `ipc = true` enables `hyprctl hyprpaper ...` commands. :contentReference[oaicite:0]{index=0}
|
||||||
xdg.configFile."hypr/hyprpaper.conf".text = ''
|
xdg.configFile."hypr/hyprpaper.conf".text = ''
|
||||||
ipc = true
|
ipc = true
|
||||||
splash = false
|
splash = false
|
||||||
'';
|
'';
|
||||||
|
|
||||||
xdg.configFile."${wsScriptRel}" = {
|
# Workspace wallpaper daemon: listens to socket2, applies w-<id>=... mapping
|
||||||
|
# Uses workspacev2 to get numeric workspace id. :contentReference[oaicite:1]{index=1}
|
||||||
|
xdg.configFile."${daemonRel}" = {
|
||||||
executable = true;
|
executable = true;
|
||||||
text = ''
|
text = ''
|
||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
@@ -39,47 +54,85 @@ in
|
|||||||
SOCK="''${XDG_RUNTIME_DIR}/hypr/''${HYPRLAND_INSTANCE_SIGNATURE}/.socket2.sock"
|
SOCK="''${XDG_RUNTIME_DIR}/hypr/''${HYPRLAND_INSTANCE_SIGNATURE}/.socket2.sock"
|
||||||
[[ -S "$SOCK" ]] || { echo "Hyprland socket not found: $SOCK" >&2; exit 1; }
|
[[ -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}}"
|
PICTURES_DIR="''${1:-${picturesDir}}"
|
||||||
FIT_MODE="fill"
|
FIT_MODE="fill" # hyprpaper fit_mode: contain|cover|tile|fill :contentReference[oaicite:2]{index=2}
|
||||||
|
|
||||||
FOCUSED_MON=""
|
HYPR_DIR="''${XDG_CONFIG_HOME:-$HOME/.config}/hypr"
|
||||||
|
MAP_ROOT="''${HYPR_DIR}/hyprpaper/config"
|
||||||
|
|
||||||
pick_wall_for_ws() {
|
focused_monitor() {
|
||||||
local ws="''${1}"
|
hyprctl -j monitors | jq -r '.[] | select(.focused==true) | .name' | head -n 1
|
||||||
|
}
|
||||||
|
|
||||||
|
map_file_for_monitor() {
|
||||||
|
local mon="''${1}"
|
||||||
|
echo "''${MAP_ROOT}/''${mon}/defaults.conf"
|
||||||
|
}
|
||||||
|
|
||||||
|
ensure_map_file() {
|
||||||
|
local mon="''${1}"
|
||||||
local f
|
local f
|
||||||
f="$(ls -1 "''${PICTURES_DIR}/''${ws}."* 2>/dev/null | head -n 1 || true)"
|
f="$(map_file_for_monitor "''${mon}")"
|
||||||
|
mkdir -p "$(dirname "''${f}")"
|
||||||
|
if [[ ! -f "''${f}" ]]; then
|
||||||
|
# Seed with 1..9 from picturesDir if present, else empty entries
|
||||||
|
{
|
||||||
|
for i in 1 2 3 4 5 6 7 8 9; do
|
||||||
|
seed="$(ls -1 "''${PICTURES_DIR}/''${i}."* 2>/dev/null | head -n 1 || true)"
|
||||||
|
echo "w-''${i}= ''${seed}"
|
||||||
|
done
|
||||||
|
} > "''${f}"
|
||||||
|
fi
|
||||||
echo "''${f}"
|
echo "''${f}"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
get_wall_for_ws() {
|
||||||
|
local mon="''${1}"
|
||||||
|
local wsid="''${2}"
|
||||||
|
local f key val
|
||||||
|
f="$(ensure_map_file "''${mon}")"
|
||||||
|
key="w-''${wsid}"
|
||||||
|
# accept "w-1=/path" or "w-1= /path"
|
||||||
|
val="$(awk -F= -v k="''${key}" '$1==k {sub(/^[[:space:]]+/, "", $2); print $2; exit}' "''${f}" || true)"
|
||||||
|
echo "''${val}"
|
||||||
|
}
|
||||||
|
|
||||||
apply_wallpaper() {
|
apply_wallpaper() {
|
||||||
local mon="''${1}"
|
local mon="''${1}"
|
||||||
local ws="''${2}"
|
local wsid="''${2}"
|
||||||
|
|
||||||
local file
|
local file
|
||||||
file="$(pick_wall_for_ws "''${ws}")"
|
|
||||||
[[ -n "''${file}" ]] || return 0
|
|
||||||
|
|
||||||
|
file="$(get_wall_for_ws "''${mon}" "''${wsid}")"
|
||||||
|
[[ -n "''${file}" ]] || return 0
|
||||||
|
[[ -f "''${file}" ]] || return 0
|
||||||
|
|
||||||
|
# Apply via IPC
|
||||||
|
# hyprpaper “wallpaper { monitor path fit_mode }” model is per monitor. :contentReference[oaicite:3]{index=3}
|
||||||
hyprctl hyprpaper wallpaper "''${mon}, ''${file}, ''${FIT_MODE}" >/dev/null
|
hyprctl hyprpaper wallpaper "''${mon}, ''${file}, ''${FIT_MODE}" >/dev/null
|
||||||
}
|
}
|
||||||
|
|
||||||
FOCUSED_MON="$(hyprctl -j monitors | jq -r '.[] | select(.focused==true) | .name' | head -n 1 || true)"
|
# Initial apply on startup
|
||||||
CUR_WS="$(hyprctl -j activeworkspace | jq -r '.name' | head -n 1 || true)"
|
mon="$(focused_monitor || true)"
|
||||||
CUR_WS="''${CUR_WS%%:*}"
|
wsid="$(hyprctl -j activeworkspace | jq -r '.id' | head -n 1 || true)"
|
||||||
|
[[ -n "''${mon}" && -n "''${wsid}" ]] && apply_wallpaper "''${mon}" "''${wsid}"
|
||||||
[[ -n "''${FOCUSED_MON}" && -n "''${CUR_WS}" ]] && apply_wallpaper "''${FOCUSED_MON}" "''${CUR_WS}"
|
|
||||||
|
|
||||||
handle() {
|
handle() {
|
||||||
case "''${1}" in
|
local line="''${1}"
|
||||||
focusedmon* )
|
case "''${line}" in
|
||||||
local payload="''${1#*>>}"
|
workspacev2* )
|
||||||
FOCUSED_MON="''${payload%%,*}"
|
# workspacev2>>ID,NAME :contentReference[oaicite:4]{index=4}
|
||||||
|
local payload wsid
|
||||||
|
payload="''${line#*>>}"
|
||||||
|
wsid="''${payload%%,*}"
|
||||||
|
mon="$(focused_monitor || true)"
|
||||||
|
[[ -n "''${mon}" && -n "''${wsid}" ]] && apply_wallpaper "''${mon}" "''${wsid}"
|
||||||
;;
|
;;
|
||||||
workspace* )
|
focusedmon* )
|
||||||
local ws="''${1#*>>}"
|
# focusedmon>>MON,WORKSPACENAME :contentReference[oaicite:5]{index=5}
|
||||||
ws="''${ws%%:*}"
|
# When monitor focus changes, re-apply for the active workspace id.
|
||||||
ws="''${ws%% *}"
|
mon="$(focused_monitor || true)"
|
||||||
[[ -n "''${FOCUSED_MON}" && -n "''${ws}" ]] && apply_wallpaper "''${FOCUSED_MON}" "''${ws}"
|
wsid="$(hyprctl -j activeworkspace | jq -r '.id' | head -n 1 || true)"
|
||||||
|
[[ -n "''${mon}" && -n "''${wsid}" ]] && apply_wallpaper "''${mon}" "''${wsid}"
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
}
|
}
|
||||||
@@ -90,11 +143,61 @@ in
|
|||||||
'';
|
'';
|
||||||
};
|
};
|
||||||
|
|
||||||
|
# CLI setter in the style of your inspiration script.
|
||||||
|
# Usage: set-wallpaper.sh <workspace_id> <monitor> [wallpaper]
|
||||||
|
xdg.configFile."${setRel}" = {
|
||||||
|
executable = true;
|
||||||
|
text = ''
|
||||||
|
#!/usr/bin/env bash
|
||||||
|
set -euo pipefail
|
||||||
|
|
||||||
|
HYPR_DIR="''${XDG_CONFIG_HOME:-$HOME/.config}/hypr"
|
||||||
|
MAP_ROOT="''${HYPR_DIR}/hyprpaper/config"
|
||||||
|
|
||||||
|
usage() {
|
||||||
|
echo "Usage: set-wallpaper.sh <workspace_id> <monitor> [wallpaper_path]"
|
||||||
|
}
|
||||||
|
|
||||||
|
wsid="''${1:-}"
|
||||||
|
mon="''${2:-}"
|
||||||
|
wp="''${3:-}"
|
||||||
|
|
||||||
|
[[ -n "''${wsid}" ]] || { usage; exit 1; }
|
||||||
|
[[ -n "''${mon}" ]] || { usage; exit 1; }
|
||||||
|
|
||||||
|
cfg="''${MAP_ROOT}/''${mon}/defaults.conf"
|
||||||
|
mkdir -p "$(dirname "''${cfg}")"
|
||||||
|
[[ -f "''${cfg}" ]] || touch "''${cfg}"
|
||||||
|
|
||||||
|
if [[ -z "''${wp}" ]]; then
|
||||||
|
# Random pick from your defaults folder if you want; adjust path if needed:
|
||||||
|
wp="$(find "$HOME/.config/wallpapers/defaults" -type f 2>/dev/null | shuf -n 1 || true)"
|
||||||
|
[[ -n "''${wp}" ]] || { echo "No wallpaper found (random). Provide a path as arg 3."; exit 1; }
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Ensure key exists; if not, append it
|
||||||
|
key="w-''${wsid}"
|
||||||
|
if ! grep -q "^''${key}=" "''${cfg}"; then
|
||||||
|
echo "''${key}=" >> "''${cfg}"
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Set mapping
|
||||||
|
${pkgs.gnused}/bin/sed -i "s|^''${key}=.*|''${key}= ''${wp}|g" "''${cfg}"
|
||||||
|
|
||||||
|
# If this monitor is currently showing that workspace id, apply immediately
|
||||||
|
curws="$(hyprctl -j monitors | jq -r --arg m "''${mon}" '.[] | select(.name==$m) | .activeWorkspace.id' | head -n 1 || true)"
|
||||||
|
if [[ "''${curws}" == "''${wsid}" ]]; then
|
||||||
|
hyprctl hyprpaper wallpaper "''${mon}, ''${wp}, fill" >/dev/null
|
||||||
|
fi
|
||||||
|
'';
|
||||||
|
};
|
||||||
|
|
||||||
|
# Services
|
||||||
systemd.user.services.hyprpaper = {
|
systemd.user.services.hyprpaper = {
|
||||||
Unit = {
|
Unit = {
|
||||||
Description = "hyprpaper wallpaper daemon";
|
Description = "hyprpaper wallpaper daemon";
|
||||||
PartOf = [ "graphical-session.target" ];
|
PartOf = [ "graphical-session.target" ];
|
||||||
After = [ "graphical-session.target" ];
|
After = [ "graphical-session.target" ];
|
||||||
};
|
};
|
||||||
Service = {
|
Service = {
|
||||||
ExecStart = "${pkgs.hyprpaper}/bin/hyprpaper";
|
ExecStart = "${pkgs.hyprpaper}/bin/hyprpaper";
|
||||||
@@ -104,14 +207,14 @@ in
|
|||||||
Install = { WantedBy = [ "graphical-session.target" ]; };
|
Install = { WantedBy = [ "graphical-session.target" ]; };
|
||||||
};
|
};
|
||||||
|
|
||||||
systemd.user.services.hyprpaper-workspace-wallpapers = {
|
systemd.user.services.hyprpaper-ws-daemon = {
|
||||||
Unit = {
|
Unit = {
|
||||||
Description = "Hyprpaper workspace wallpapers (socket2 listener)";
|
Description = "Workspace->wallpaper mapping daemon (hyprpaper + socket2)";
|
||||||
PartOf = [ "graphical-session.target" ];
|
PartOf = [ "graphical-session.target" ];
|
||||||
After = [ "graphical-session.target" "hyprpaper.service" ];
|
After = [ "graphical-session.target" "hyprpaper.service" ];
|
||||||
};
|
};
|
||||||
Service = {
|
Service = {
|
||||||
ExecStart = "${pkgs.bash}/bin/bash ${config.xdg.configHome}/${wsScriptRel} ${picturesDir}";
|
ExecStart = "${pkgs.bash}/bin/bash ${config.xdg.configHome}/${daemonRel} ${picturesDir}";
|
||||||
Restart = "on-failure";
|
Restart = "on-failure";
|
||||||
RestartSec = 1;
|
RestartSec = 1;
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user