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

This commit is contained in:
Aly Raffauf 2024-08-05 00:42:11 -04:00
parent 4c833eec04
commit 6e85d68743

View file

@ -14,19 +14,38 @@
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
break if wm_dead? hyprland_lock_path, sway_sock
next if active_monitors.empty? next if active_monitors.empty?
added_monitors = active_monitors - known_monitors.keys added_monitors = active_monitors - known_monitors.keys
@ -64,7 +83,6 @@
sleep 3 sleep 3
end end
end
''; '';
in { in {
config = lib.mkIf config.ar.home.services.randomWallpaper.enable { config = lib.mkIf config.ar.home.services.randomWallpaper.enable {