mirror of
https://github.com/alyraffauf/nixcfg.git
synced 2024-11-21 22:13:56 -05:00
home/hyprland: actively check for new monitors and asign them wallpapers (#46)
Some checks are pending
flakehub / flakehub-publish (push) Waiting to run
git-mirror / gitlab-sync (push) Waiting to run
nix-build / default-build (push) Waiting to run
nix-build / fallarbor-build (push) Waiting to run
nix-build / lavaridge-build (push) Waiting to run
nix-build / mauville-build (push) Waiting to run
nix-build / petalburg-build (push) Waiting to run
nix-build / rustboro-build (push) Waiting to run
nix-check / fmt-check (push) Waiting to run
nix-check / eval-check (push) Waiting to run
nix-drybuild / fallarbor-drybuild (push) Waiting to run
nix-drybuild / lavaridge-drybuild (push) Waiting to run
nix-drybuild / mauville-drybuild (push) Waiting to run
nix-drybuild / petalburg-drybuild (push) Waiting to run
nix-drybuild / rustboro-drybuild (push) Waiting to run
Some checks are pending
flakehub / flakehub-publish (push) Waiting to run
git-mirror / gitlab-sync (push) Waiting to run
nix-build / default-build (push) Waiting to run
nix-build / fallarbor-build (push) Waiting to run
nix-build / lavaridge-build (push) Waiting to run
nix-build / mauville-build (push) Waiting to run
nix-build / petalburg-build (push) Waiting to run
nix-build / rustboro-build (push) Waiting to run
nix-check / fmt-check (push) Waiting to run
nix-check / eval-check (push) Waiting to run
nix-drybuild / fallarbor-drybuild (push) Waiting to run
nix-drybuild / lavaridge-drybuild (push) Waiting to run
nix-drybuild / mauville-drybuild (push) Waiting to run
nix-drybuild / petalburg-drybuild (push) Waiting to run
nix-drybuild / rustboro-drybuild (push) Waiting to run
This commit is contained in:
parent
e7bb6fc676
commit
d2e51f8a32
|
@ -45,34 +45,52 @@ in {
|
|||
|
||||
directory = "${config.xdg.dataHome}/backgrounds/"
|
||||
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
|
||||
|
||||
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
|
||||
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
|
||||
pid = spawn("/nix/store/azvrjs0k5ap90dcqw280xrbqlm6nkibv-swaybg-1.2.1/bin/swaybg", '-o', monitor, '-i', random_background, '-m', 'fill')
|
||||
current_pids[monitor] = pid
|
||||
last_update_time[monitor] = Time.now
|
||||
known_monitors[monitor] = random_background
|
||||
end
|
||||
|
||||
# Remove wallpapers from removed monitors
|
||||
removed_monitors.each do |monitor|
|
||||
Process.kill('TERM', current_pids[monitor]) if current_pids[monitor]
|
||||
current_pids.delete(monitor)
|
||||
last_update_time.delete(monitor)
|
||||
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')
|
||||
new_pids << pid
|
||||
current_pids[monitor] = pid
|
||||
last_update_time[monitor] = Time.now
|
||||
known_monitors[monitor] = random_background
|
||||
end
|
||||
end
|
||||
|
||||
if old_pids.empty?
|
||||
sleep 900
|
||||
else
|
||||
sleep 5
|
||||
old_pids.each do |pid|
|
||||
Process.kill('TERM', pid)
|
||||
end
|
||||
sleep 895
|
||||
end
|
||||
|
||||
old_pids = new_pids
|
||||
sleep 5 # Check for monitor changes and update intervals every 5 seconds
|
||||
end
|
||||
end
|
||||
''
|
||||
|
|
Loading…
Reference in a new issue