Hyprland: automatic background change

This commit is contained in:
Filippo Berto 2023-11-20 11:26:58 +01:00
parent 91fb78e143
commit 19e12e6605
No known key found for this signature in database
GPG key ID: FE98AE5EC52B1056
4 changed files with 43 additions and 1 deletions

View file

@ -147,6 +147,7 @@
../../modules/hm/update_background.nix
../../modules/hm/vim.nix
../../modules/hm/webapp.nix
../../modules/hm/wl_update_background.nix
../../modules/hm/xidlehook.nix
../../modules/hm/xresources.nix
../../modules/hm/zathura.nix

View file

@ -138,6 +138,7 @@
../../modules/hm/update_background.nix
../../modules/hm/vim.nix
../../modules/hm/webapp.nix
../../modules/hm/wl_update_background.nix
../../modules/hm/xidlehook.nix
../../modules/hm/xresources.nix
../../modules/hm/zathura.nix

View file

@ -55,7 +55,7 @@
# See https://wiki.hyprland.org/Configuring/Keywords/ for more
# Execute your favorite apps at launch
exec-once = waybar & swww init & blueman-applet & nm-applet # & firefox
exec-once = waybar & swww init & blueman-applet & nm-applet & systemctl --user restart swayidle # & firefox
# Source a file (multi-file configs)
# source = ~/.config/hypr/myColors.conf

View file

@ -0,0 +1,40 @@
{ pkgs, ... }:
let
update_time = "10m";
backgrounds_directory = "$HOME/Immagini/Sfondi/1080+/1440+";
update_script = pkgs.writeShellScriptBin "wl-update-background" ''
set -e
if [ $# -eq 0 ]; then
image=`${pkgs.findutils}/bin/find ${backgrounds_directory} -type f | ${pkgs.gnugrep}/bin/grep -v "/\." | ${pkgs.coreutils}/bin/shuf -n 1`
else
image="$1"
fi
echo "image: $image"
${pkgs.swww}/bin/swww img "$image"
'';
in
{
home.packages = [ update_script ];
systemd.user.services."wl-update-background" = {
Unit = {
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" ]; };
Service = {
Type = "oneshot";
IOSchedulingClass = "idle";
ExecStart = "${update_script}/bin/wl-update-background";
};
};
systemd.user.timers."wl-update-background" = {
Unit = { Description = "Set random desktop background using swww"; };
Timer = { OnUnitActiveSec = update_time; };
Install = { WantedBy = [ "timers.target" ]; };
};
}