mirror of
https://github.com/alyraffauf/nixcfg.git
synced 2024-11-21 20:33:55 -05:00
home/hyprland: actively check for new monitors and asign them wallpapers
This commit is contained in:
parent
e7bb6fc676
commit
da794d991f
|
@ -45,34 +45,52 @@ in {
|
||||||
|
|
||||||
directory = "${config.xdg.dataHome}/backgrounds/"
|
directory = "${config.xdg.dataHome}/backgrounds/"
|
||||||
hyprctl = "${lib.getExe' config.wayland.windowManager.hyprland.package "hyprctl"}"
|
hyprctl = "${lib.getExe' config.wayland.windowManager.hyprland.package "hyprctl"}"
|
||||||
old_pids = []
|
current_pids = {}
|
||||||
|
known_monitors = {}
|
||||||
|
last_update_time = {}
|
||||||
|
|
||||||
|
update_interval = 900 # 15 minutes in seconds
|
||||||
|
|
||||||
sleep 1
|
sleep 1
|
||||||
|
|
||||||
if Dir.exist?(directory)
|
if Dir.exist?(directory)
|
||||||
loop do
|
loop do
|
||||||
new_pids = []
|
|
||||||
|
|
||||||
outputs = IO.popen([hyprctl, 'monitors']).read
|
outputs = IO.popen([hyprctl, 'monitors']).read
|
||||||
monitors = outputs.each_line.map { |line| line.split[1] if line.include?('Monitor') }.compact
|
active_monitors = outputs.each_line.map { |line| line.split[1] if line.include?('Monitor') }.compact
|
||||||
|
|
||||||
monitors.each do |monitor|
|
added_monitors = active_monitors - known_monitors.keys
|
||||||
|
removed_monitors = known_monitors.keys - active_monitors
|
||||||
|
|
||||||
|
# Handle newly added monitors
|
||||||
|
added_monitors.each do |monitor|
|
||||||
random_background = Dir.glob(File.join(directory, '*.{png,jpg}')).sample
|
random_background = Dir.glob(File.join(directory, '*.{png,jpg}')).sample
|
||||||
pid = spawn("${lib.getExe pkgs.swaybg}", '-o', monitor, '-i', random_background, '-m', 'fill')
|
pid = spawn("/nix/store/azvrjs0k5ap90dcqw280xrbqlm6nkibv-swaybg-1.2.1/bin/swaybg", '-o', monitor, '-i', random_background, '-m', 'fill')
|
||||||
new_pids << pid
|
current_pids[monitor] = pid
|
||||||
|
last_update_time[monitor] = Time.now
|
||||||
|
known_monitors[monitor] = random_background
|
||||||
end
|
end
|
||||||
|
|
||||||
if old_pids.empty?
|
# Remove wallpapers from removed monitors
|
||||||
sleep 900
|
removed_monitors.each do |monitor|
|
||||||
else
|
Process.kill('TERM', current_pids[monitor]) if current_pids[monitor]
|
||||||
sleep 5
|
current_pids.delete(monitor)
|
||||||
old_pids.each do |pid|
|
last_update_time.delete(monitor)
|
||||||
Process.kill('TERM', pid)
|
known_monitors.delete(monitor)
|
||||||
|
end
|
||||||
|
|
||||||
|
# Update wallpapers after the set interval
|
||||||
|
active_monitors.each do |monitor|
|
||||||
|
if Time.now - last_update_time[monitor] >= update_interval
|
||||||
|
Process.kill('TERM', current_pids[monitor]) if current_pids[monitor]
|
||||||
|
random_background = Dir.glob(File.join(directory, '*.{png,jpg}')).sample
|
||||||
|
pid = spawn("${lib.getExe pkgs.swaybg}", '-o', monitor, '-i', random_background, '-m', 'fill')
|
||||||
|
current_pids[monitor] = pid
|
||||||
|
last_update_time[monitor] = Time.now
|
||||||
|
known_monitors[monitor] = random_background
|
||||||
end
|
end
|
||||||
sleep 895
|
|
||||||
end
|
end
|
||||||
|
|
||||||
old_pids = new_pids
|
sleep 5 # Check for monitor changes and update intervals every 5 seconds
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
''
|
''
|
||||||
|
|
Loading…
Reference in a new issue