mirror of
https://github.com/alyraffauf/nixcfg.git
synced 2024-11-22 07:13:55 -05:00
hyprland: rewrote wallpaper script in ruby
This commit is contained in:
parent
ab64b44497
commit
ca4c453a96
|
@ -30,33 +30,41 @@
|
||||||
wallpaperd =
|
wallpaperd =
|
||||||
if config.alyraffauf.desktop.hyprland.randomWallpaper
|
if config.alyraffauf.desktop.hyprland.randomWallpaper
|
||||||
then
|
then
|
||||||
pkgs.writeShellScript "hyprland-randomWallpaper" ''
|
pkgs.writers.writeRuby "hyprland-randomWallpaper" {} ''
|
||||||
OLD_PIDS=()
|
require 'fileutils'
|
||||||
directory=${config.home.homeDirectory}/.local/share/backgrounds
|
|
||||||
|
directory = "${config.xdg.dataHome}/backgrounds"
|
||||||
|
hyprctl = "${lib.getExe' config.wayland.windowManager.hyprland.package "hyprctl"}"
|
||||||
|
old_pids = []
|
||||||
|
|
||||||
sleep 1
|
sleep 1
|
||||||
|
|
||||||
if [ -d "$directory" ]; then
|
if Dir.exist?(directory)
|
||||||
while true; do
|
loop do
|
||||||
NEW_PIDS=()
|
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
|
outputs = IO.popen([hyprctl, 'monitors']).read
|
||||||
sleep 5
|
monitors = outputs.each_line.map { |line| line.split[1] if line.include?('Monitor') }.compact
|
||||||
for pid in ''${OLD_PIDS[@]}; do
|
|
||||||
kill $pid
|
|
||||||
done
|
|
||||||
fi
|
|
||||||
|
|
||||||
OLD_PIDS=$NEW_PIDS
|
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
|
||||||
|
|
||||||
|
if old_pids.empty?
|
||||||
|
sleep 900
|
||||||
|
else
|
||||||
|
sleep 5
|
||||||
|
old_pids.each do |pid|
|
||||||
|
Process.kill('TERM', pid)
|
||||||
|
end
|
||||||
sleep 895
|
sleep 895
|
||||||
done
|
end
|
||||||
fi
|
|
||||||
|
old_pids = new_pids
|
||||||
|
end
|
||||||
|
end
|
||||||
''
|
''
|
||||||
else "${lib.getExe pkgs.swaybg} -i ${config.alyraffauf.theme.wallpaper}";
|
else "${lib.getExe pkgs.swaybg} -i ${config.alyraffauf.theme.wallpaper}";
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue