Fix hyprland background

This commit is contained in:
Filippo Berto 2026-01-16 14:13:58 +01:00
parent c6cae00eba
commit 02d9349a03
No known key found for this signature in database
GPG key ID: F1D17F9BCEC62FBC
3 changed files with 24 additions and 29 deletions

View file

@ -229,7 +229,7 @@ in
"SUPER, J, togglesplit, # dwindle"
"SUPER ALT, E, exec, wofi-emoji"
"SUPER ALT, P, exec, wl-clipedit"
"SUPER ALT, B, exec, wl-update-background"
"SUPER ALT, B, exec, systemctl --user reload-or-restart wl-update-background"
",Print, exec, grimblast copy"
"SHIFT, Print, exec, grimblast copy area"

View file

@ -1,4 +1,9 @@
{ pkgs, ... }: {
{ pkgs, nixosConfig, ... }:
let
inherit (nixosConfig.networking) hostName;
backgrounds_directory = if hostName == "sif" then "$HOME/Pictures/Wallpapers/2160+" else "$HOME/Immagini/Sfondi/2160+";
in
{
home.packages = [ pkgs.wl-update-background ];
systemd.user.services."wl-update-background" = {
@ -6,7 +11,6 @@
Description = "Set random desktop background using swww";
After = [ "graphical-session.pre.target" ];
PartOf = [ "graphical-session.target" ];
RequiresMountsFor = [ "/home/bertof/Immagini" ];
};
Install = {
WantedBy = [ "graphical-session.target" ];
@ -14,7 +18,8 @@
Service = {
Type = "oneshot";
IOSchedulingClass = "idle";
ExecStart = "${pkgs.wl-update-background}/bin/wl-update-background";
StartLimitBurst = 0;
ExecStart = "${pkgs.wl-update-background.override {inherit backgrounds_directory;}}/bin/wl-update-background";
};
};

View file

@ -1,29 +1,19 @@
{ findutils
, coreutils
, writeShellScriptBin
{ coreutils
, findutils
, hyprland
, lib
, writeShellScriptBin
, backgrounds_directory ? "$HOME/Immagini/Sfondi/"
}: writeShellScriptBin "wl-update-background"
# ''
# set -e
# if [ $# -eq 0 ]; then
# image=`${findutils}/bin/find ${backgrounds_directory} -type f | ${gnugrep}/bin/grep -v "/\." | ${coreutils}/bin/shuf -n 1`
# else
# image="$1"
# fi
# echo "image: $image"
# ${swww}/bin/swww img "$image"
# ''
''
}: writeShellScriptBin "wl-update-background" ''
set -euo pipefail
PATH=$PATH:${lib.makeBinPath [findutils coreutils hyprland]}
WALLPAPER_DIR=${backgrounds_directory}
CURRENT_WALL=$(hyprctl hyprpaper listloaded)
CURRENT_WALL=$(basename "$CURRENT_WALL")
# Get a random wallpaper that is not the current one
WALLPAPER=$(${findutils}/bin/find "$WALLPAPER_DIR" -type f ! -name "$(${coreutils}/bin/basename "$CURRENT_WALL")" | ${coreutils}/bin/shuf -n 1)
NEW_WALLPAPER=$(find "$WALLPAPER_DIR" -type f ! -name "$CURRENT_WALL" | shuf -n 1)
# Apply the selected wallpaper
${hyprland}/bin/hyprctl hyprpaper reload ,"$WALLPAPER"
hyprctl hyprpaper reload ,"$NEW_WALLPAPER"
''