mirror of
https://github.com/alyraffauf/nixcfg.git
synced 2024-11-22 08:33:55 -05:00
randomWallpaper: check if wm is alive
Some checks are pending
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
Some checks are pending
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
This commit is contained in:
parent
4c833eec04
commit
6e85d68743
|
@ -14,56 +14,74 @@
|
||||||
|
|
||||||
update_interval = 900 # 15 minutes in seconds
|
update_interval = 900 # 15 minutes in seconds
|
||||||
|
|
||||||
|
xdg_runtime_dir = ENV['XDG_RUNTIME_DIR']
|
||||||
|
hyprland_instance_signature = ENV['HYPRLAND_INSTANCE_SIGNATURE']
|
||||||
|
sway_sock = ENV['SWAYSOCK']
|
||||||
|
|
||||||
|
hyprland_lock_path = nil
|
||||||
|
|
||||||
|
unless hyprland_instance_signature.nil?
|
||||||
|
hyprland_lock_path = File.join(xdg_runtime_dir, 'hypr', hyprland_instance_signature, 'hyprland.lock')
|
||||||
|
end
|
||||||
|
|
||||||
|
def wm_dead? (hyprland_lock_path, sway_sock)
|
||||||
|
sway_running = system("pidof sway > /dev/null")
|
||||||
|
hypr_running = system("pidof Hyprland > /dev/null")
|
||||||
|
(hyprland_lock_path.nil? || !File.exist?(hyprland_lock_path) || !hypr_running) && (sway_sock.nil? || !File.exist?(sway_sock) || !sway_running)
|
||||||
|
end
|
||||||
|
|
||||||
def get_outputs
|
def get_outputs
|
||||||
hyprctl = IO.popen(["${lib.getExe' config.wayland.windowManager.hyprland.package "hyprctl"}", 'monitors']).read
|
hyprctl = IO.popen(["${lib.getExe' config.wayland.windowManager.hyprland.package "hyprctl"}", 'monitors']).read
|
||||||
swaymsg = IO.popen(["${lib.getExe' config.wayland.windowManager.sway.package "swaymsg"}", '-t', 'get_outputs', '-p']).readlines
|
swaymsg = IO.popen(["${lib.getExe' config.wayland.windowManager.sway.package "swaymsg"}", '-t', 'get_outputs', '-p']).readlines
|
||||||
|
|
||||||
hypr_outputs = hyprctl.each_line.map { |line| line.split[1] if line.include?('Monitor') }.compact
|
hypr_outputs = hyprctl.each_line.map { |line| line.split[1] if line.include?('Monitor') }.compact
|
||||||
sway_outputs = swaymsg.select { |line| line.include?('Output') }.map { |line| line.split[1] }
|
sway_outputs = swaymsg.select { |line| line.include?('Output') }.map { |line| line.split[1] }
|
||||||
return sway_outputs | hypr_outputs
|
|
||||||
|
return (sway_outputs | hypr_outputs)
|
||||||
end
|
end
|
||||||
|
|
||||||
sleep 1
|
sleep 1
|
||||||
|
|
||||||
if Dir.exist?(directory)
|
loop do
|
||||||
loop do
|
active_monitors = get_outputs
|
||||||
active_monitors = get_outputs
|
|
||||||
next if active_monitors.empty?
|
|
||||||
|
|
||||||
added_monitors = active_monitors - known_monitors.keys
|
break if wm_dead? hyprland_lock_path, sway_sock
|
||||||
removed_monitors = known_monitors.keys - active_monitors
|
next if active_monitors.empty?
|
||||||
|
|
||||||
# Handle newly added monitors
|
added_monitors = active_monitors - known_monitors.keys
|
||||||
added_monitors.each do |monitor|
|
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("${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
|
||||||
|
|
||||||
|
# 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
|
||||||
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("${lib.getExe pkgs.swaybg}", '-o', monitor, '-i', random_background, '-m', 'fill')
|
||||||
|
sleep 1
|
||||||
|
Process.kill('TERM', current_pids[monitor]) if current_pids[monitor]
|
||||||
current_pids[monitor] = pid
|
current_pids[monitor] = pid
|
||||||
last_update_time[monitor] = Time.now
|
last_update_time[monitor] = Time.now
|
||||||
known_monitors[monitor] = random_background
|
known_monitors[monitor] = random_background
|
||||||
end
|
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
|
|
||||||
random_background = Dir.glob(File.join(directory, '*.{png,jpg}')).sample
|
|
||||||
pid = spawn("${lib.getExe pkgs.swaybg}", '-o', monitor, '-i', random_background, '-m', 'fill')
|
|
||||||
sleep 1
|
|
||||||
Process.kill('TERM', current_pids[monitor]) if current_pids[monitor]
|
|
||||||
current_pids[monitor] = pid
|
|
||||||
last_update_time[monitor] = Time.now
|
|
||||||
known_monitors[monitor] = random_background
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
sleep 3
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
sleep 3
|
||||||
end
|
end
|
||||||
'';
|
'';
|
||||||
in {
|
in {
|
||||||
|
|
Loading…
Reference in a new issue