Skip to content

Commit

Permalink
hyprland: rewrote wallpaper script in ruby
Browse files Browse the repository at this point in the history
  • Loading branch information
alyraffauf committed Jun 25, 2024
1 parent ab64b44 commit 47e212a
Showing 1 changed file with 30 additions and 23 deletions.
53 changes: 30 additions & 23 deletions homeManagerModules/desktop/hyprland/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -30,33 +30,40 @@
wallpaperd =
if config.alyraffauf.desktop.hyprland.randomWallpaper
then
pkgs.writeShellScript "hyprland-randomWallpaper" ''
OLD_PIDS=()
directory=${config.home.homeDirectory}/.local/share/backgrounds
pkgs.writers.writeRuby "hyprland-randomWallpaper" {} ''
require 'fileutils'
directory = "${config.xdg.dataHome}/backgrounds"
hyprctl = "${lib.getExe' config.wayland.windowManager.hyprland.package "hyprctl"}"
old_pids = []
sleep 1
if [ -d "$directory" ]; then
while true; do
NEW_PIDS=()
monitor=`${config.wayland.windowManager.hyprland.package}/bin/hyprctl monitors | grep Monitor | awk '{print $2}'`
for m in ''${monitor[@]}; do
random_background=$(ls $directory/*.{png,jpg} | shuf -n 1)
${lib.getExe pkgs.swaybg} -o $m -i $random_background -m fill &
NEW_PIDS+=($!)
done
if [[ ''${OLD_PIDS[@]} -gt 0 ]]; then
sleep 5
for pid in ''${OLD_PIDS[@]}; do
kill $pid
done
fi
OLD_PIDS=$NEW_PIDS
if Dir.exist?(directory)
loop do
new_pids = []
outputs = IO.popen([hyprctl, 'monitors']).read
monitors = outputs.each_line.map { |line| line.split[1] if line.include?('Monitor') }.compact
monitors.each do |monitor|
random_background = Dir.glob(File.join(directory, '*.{png,jpg}')).sample
pid = spawn("${lib.getExe pkgs.swaybg}", '-o', monitor, '-i', random_background, '-m', 'fill')
new_pids << pid
end
unless old_pids.empty?
sleep 5
old_pids.each do |pid|
Process.kill('TERM', pid)
end
old_pids = new_pids
sleep 895
done
fi
else
sleep 900
end
end
end
''
else "${lib.getExe pkgs.swaybg} -i ${config.alyraffauf.theme.wallpaper}";

Expand Down

0 comments on commit 47e212a

Please sign in to comment.