Now we support more monitors
This commit is contained in:
+336
-343
File diff suppressed because it is too large
Load Diff
+33
-40
@@ -1719,10 +1719,9 @@ let
|
||||
picturesDir = "${userAbsRoot}/pictures";
|
||||
currentDir = "${userAbsRoot}/current";
|
||||
|
||||
# where the listener script will live
|
||||
scriptRel = "hypr/scripts/wpaperd-workspace-1to9.sh";
|
||||
# wpaperd reads this by default (XDG_CONFIG_HOME/wpaperd/config.toml)
|
||||
wpaperdConfRel = "wpaperd/config.toml";
|
||||
wpaperdConfAbs = "${config.xdg.configHome}/${wpaperdConfRel}";
|
||||
in
|
||||
{
|
||||
home.packages = [
|
||||
@@ -1738,7 +1737,27 @@ in
|
||||
recursive = true;
|
||||
};
|
||||
|
||||
# Workspace/monitor listener: creates per-monitor symlink and reloads wpaperd
|
||||
# Create a correct wpaperd config.
|
||||
# - [default] sets stretch globally
|
||||
# - [any] acts as fallback for outputs not explicitly listed (wpaperd-output(5))
|
||||
# - Per-output sections point at CURRENT/<MON>.jpg (symlinks the script updates)
|
||||
#
|
||||
# NOTE: This is safe even if you add/remove monitors: [any] keeps things working.
|
||||
xdg.configFile."${wpaperdConfRel}".text = ''
|
||||
[default]
|
||||
mode = "stretch"
|
||||
|
||||
[any]
|
||||
path = "${picturesDir}/wallpaper1.jpg"
|
||||
|
||||
[eDP-1]
|
||||
path = "${currentDir}/eDP-1.jpg"
|
||||
|
||||
[DP-1]
|
||||
path = "${currentDir}/DP-1.jpg"
|
||||
'';
|
||||
|
||||
# Listener: on focused monitor change, update CURRENT/<MON>.jpg -> pictures/wallpaperN.jpg
|
||||
xdg.configFile."${scriptRel}" = {
|
||||
executable = true;
|
||||
text = ''
|
||||
@@ -1747,10 +1766,9 @@ in
|
||||
|
||||
log() { echo "[wpaperd-ws] $*" >&2; }
|
||||
|
||||
ROOT="${userAbsRoot}"
|
||||
PICTURES="${picturesDir}"
|
||||
CURRENT="${currentDir}"
|
||||
CONF="${config.xdg.configHome}/${wpaperdConfRel}"
|
||||
CONF="${wpaperdConfAbs}"
|
||||
|
||||
: "''${XDG_RUNTIME_DIR:?XDG_RUNTIME_DIR not set}"
|
||||
: "''${HYPRLAND_INSTANCE_SIGNATURE:?HYPRLAND_INSTANCE_SIGNATURE not set}"
|
||||
@@ -1758,7 +1776,7 @@ in
|
||||
|
||||
mkdir -p "$CURRENT" "$(dirname "$CONF")"
|
||||
|
||||
# wait for hyprland socket so the service doesn't exit "successfully" too early
|
||||
# Wait for Hyprland socket so the service doesn't exit too early
|
||||
for i in $(seq 1 120); do
|
||||
[[ -S "$SOCK" ]] && break
|
||||
sleep 0.1
|
||||
@@ -1779,28 +1797,7 @@ in
|
||||
esac
|
||||
}
|
||||
|
||||
# Create/refresh config.toml with one section per output, pointing at CURRENT/<mon>.jpg
|
||||
write_config_from_monitors() {
|
||||
local mons
|
||||
mons="$(${pkgs.hyprland}/bin/hyprctl -j monitors | ${pkgs.jq}/bin/jq -r '.[].name')"
|
||||
|
||||
# Truncate + rebuild
|
||||
: >"$CONF"
|
||||
|
||||
# Each output gets its own section (wpaperd-output(5)); force stretch mode
|
||||
# (If you want different mode later: "fit", "crop", etc.)
|
||||
while IFS= read -r mon; do
|
||||
[[ -n "$mon" ]] || continue
|
||||
cat >>"$CONF" <<EOF
|
||||
["$mon"]
|
||||
path = "$CURRENT/$mon.jpg"
|
||||
mode = "stretch"
|
||||
|
||||
EOF
|
||||
done <<<"$mons"
|
||||
}
|
||||
|
||||
ensure_symlink_for() {
|
||||
ensure_link_for() {
|
||||
local mon="$1"
|
||||
local ws="$2"
|
||||
|
||||
@@ -1817,14 +1814,8 @@ EOF
|
||||
log "Link: $CURRENT/$mon.jpg -> $img"
|
||||
}
|
||||
|
||||
apply_for() {
|
||||
local mon="$1"
|
||||
local ws="$2"
|
||||
|
||||
ensure_symlink_for "$mon" "$ws"
|
||||
write_config_from_monitors
|
||||
|
||||
# wpaperctl supports reload-wallpaper on 1.2.1
|
||||
reload() {
|
||||
# wpaperctl reload-wallpaper exists on v1.2.1
|
||||
${pkgs.wpaperd}/bin/wpaperctl reload-wallpaper >/dev/null 2>&1 || true
|
||||
}
|
||||
|
||||
@@ -1833,8 +1824,9 @@ EOF
|
||||
| ${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" || true
|
||||
ensure_link_for "$mon" "$ws" || true
|
||||
done
|
||||
reload
|
||||
}
|
||||
|
||||
handle_line() {
|
||||
@@ -1845,7 +1837,8 @@ EOF
|
||||
local mon="''${payload%%,*}"
|
||||
local ws="''${payload#*,}"
|
||||
[[ -n "$mon" && -n "$ws" ]] || return 0
|
||||
apply_for "$mon" "$ws"
|
||||
ensure_link_for "$mon" "$ws" || true
|
||||
reload
|
||||
;;
|
||||
esac
|
||||
}
|
||||
@@ -1859,7 +1852,7 @@ EOF
|
||||
'';
|
||||
};
|
||||
|
||||
# Start wpaperd (uses ~/.config/wpaperd/config.toml by default)
|
||||
# Start wpaperd (reads XDG_CONFIG_HOME/wpaperd/config.toml by default)
|
||||
systemd.user.services.wpaperd = {
|
||||
Unit = {
|
||||
Description = "wpaperd wallpaper daemon";
|
||||
@@ -1874,7 +1867,7 @@ EOF
|
||||
Install.WantedBy = [ "graphical-session.target" ];
|
||||
};
|
||||
|
||||
# Listener that updates per-monitor symlink based on workspace and triggers reload
|
||||
# Listener service
|
||||
systemd.user.services.wpaperd-workspace-wallpapers = {
|
||||
Unit = {
|
||||
Description = "Set wallpaper per monitor based on workspace number (1..9)";
|
||||
|
||||
@@ -8,10 +8,9 @@ let
|
||||
picturesDir = "${userAbsRoot}/pictures";
|
||||
currentDir = "${userAbsRoot}/current";
|
||||
|
||||
# where the listener script will live
|
||||
scriptRel = "hypr/scripts/wpaperd-workspace-1to9.sh";
|
||||
# wpaperd reads this by default (XDG_CONFIG_HOME/wpaperd/config.toml)
|
||||
wpaperdConfRel = "wpaperd/config.toml";
|
||||
wpaperdConfAbs = "${config.xdg.configHome}/${wpaperdConfRel}";
|
||||
in
|
||||
{
|
||||
home.packages = [
|
||||
@@ -27,7 +26,27 @@ in
|
||||
recursive = true;
|
||||
};
|
||||
|
||||
# Workspace/monitor listener: creates per-monitor symlink and reloads wpaperd
|
||||
# Create a correct wpaperd config.
|
||||
# - [default] sets stretch globally
|
||||
# - [any] acts as fallback for outputs not explicitly listed (wpaperd-output(5))
|
||||
# - Per-output sections point at CURRENT/<MON>.jpg (symlinks the script updates)
|
||||
#
|
||||
# NOTE: This is safe even if you add/remove monitors: [any] keeps things working.
|
||||
xdg.configFile."${wpaperdConfRel}".text = ''
|
||||
[default]
|
||||
mode = "stretch"
|
||||
|
||||
[any]
|
||||
path = "${picturesDir}/wallpaper1.jpg"
|
||||
|
||||
[eDP-1]
|
||||
path = "${currentDir}/eDP-1.jpg"
|
||||
|
||||
[DP-1]
|
||||
path = "${currentDir}/DP-1.jpg"
|
||||
'';
|
||||
|
||||
# Listener: on focused monitor change, update CURRENT/<MON>.jpg -> pictures/wallpaperN.jpg
|
||||
xdg.configFile."${scriptRel}" = {
|
||||
executable = true;
|
||||
text = ''
|
||||
@@ -36,10 +55,9 @@ in
|
||||
|
||||
log() { echo "[wpaperd-ws] $*" >&2; }
|
||||
|
||||
ROOT="${userAbsRoot}"
|
||||
PICTURES="${picturesDir}"
|
||||
CURRENT="${currentDir}"
|
||||
CONF="${config.xdg.configHome}/${wpaperdConfRel}"
|
||||
CONF="${wpaperdConfAbs}"
|
||||
|
||||
: "''${XDG_RUNTIME_DIR:?XDG_RUNTIME_DIR not set}"
|
||||
: "''${HYPRLAND_INSTANCE_SIGNATURE:?HYPRLAND_INSTANCE_SIGNATURE not set}"
|
||||
@@ -47,7 +65,7 @@ in
|
||||
|
||||
mkdir -p "$CURRENT" "$(dirname "$CONF")"
|
||||
|
||||
# wait for hyprland socket so the service doesn't exit "successfully" too early
|
||||
# Wait for Hyprland socket so the service doesn't exit too early
|
||||
for i in $(seq 1 120); do
|
||||
[[ -S "$SOCK" ]] && break
|
||||
sleep 0.1
|
||||
@@ -68,28 +86,7 @@ in
|
||||
esac
|
||||
}
|
||||
|
||||
# Create/refresh config.toml with one section per output, pointing at CURRENT/<mon>.jpg
|
||||
write_config_from_monitors() {
|
||||
local mons
|
||||
mons="$(${pkgs.hyprland}/bin/hyprctl -j monitors | ${pkgs.jq}/bin/jq -r '.[].name')"
|
||||
|
||||
# Truncate + rebuild
|
||||
: >"$CONF"
|
||||
|
||||
# Each output gets its own section (wpaperd-output(5)); force stretch mode
|
||||
# (If you want different mode later: "fit", "crop", etc.)
|
||||
while IFS= read -r mon; do
|
||||
[[ -n "$mon" ]] || continue
|
||||
cat >>"$CONF" <<EOF
|
||||
["$mon"]
|
||||
path = "$CURRENT/$mon.jpg"
|
||||
mode = "stretch"
|
||||
|
||||
EOF
|
||||
done <<<"$mons"
|
||||
}
|
||||
|
||||
ensure_symlink_for() {
|
||||
ensure_link_for() {
|
||||
local mon="$1"
|
||||
local ws="$2"
|
||||
|
||||
@@ -106,14 +103,8 @@ EOF
|
||||
log "Link: $CURRENT/$mon.jpg -> $img"
|
||||
}
|
||||
|
||||
apply_for() {
|
||||
local mon="$1"
|
||||
local ws="$2"
|
||||
|
||||
ensure_symlink_for "$mon" "$ws"
|
||||
write_config_from_monitors
|
||||
|
||||
# wpaperctl supports reload-wallpaper on 1.2.1
|
||||
reload() {
|
||||
# wpaperctl reload-wallpaper exists on v1.2.1
|
||||
${pkgs.wpaperd}/bin/wpaperctl reload-wallpaper >/dev/null 2>&1 || true
|
||||
}
|
||||
|
||||
@@ -122,8 +113,9 @@ EOF
|
||||
| ${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" || true
|
||||
ensure_link_for "$mon" "$ws" || true
|
||||
done
|
||||
reload
|
||||
}
|
||||
|
||||
handle_line() {
|
||||
@@ -134,7 +126,8 @@ EOF
|
||||
local mon="''${payload%%,*}"
|
||||
local ws="''${payload#*,}"
|
||||
[[ -n "$mon" && -n "$ws" ]] || return 0
|
||||
apply_for "$mon" "$ws"
|
||||
ensure_link_for "$mon" "$ws" || true
|
||||
reload
|
||||
;;
|
||||
esac
|
||||
}
|
||||
@@ -148,7 +141,7 @@ EOF
|
||||
'';
|
||||
};
|
||||
|
||||
# Start wpaperd (uses ~/.config/wpaperd/config.toml by default)
|
||||
# Start wpaperd (reads XDG_CONFIG_HOME/wpaperd/config.toml by default)
|
||||
systemd.user.services.wpaperd = {
|
||||
Unit = {
|
||||
Description = "wpaperd wallpaper daemon";
|
||||
@@ -163,7 +156,7 @@ EOF
|
||||
Install.WantedBy = [ "graphical-session.target" ];
|
||||
};
|
||||
|
||||
# Listener that updates per-monitor symlink based on workspace and triggers reload
|
||||
# Listener service
|
||||
systemd.user.services.wpaperd-workspace-wallpapers = {
|
||||
Unit = {
|
||||
Description = "Set wallpaper per monitor based on workspace number (1..9)";
|
||||
|
||||
Reference in New Issue
Block a user