From c93f726dd6943a42052d6e8242de1d726ae77bdb Mon Sep 17 00:00:00 2001 From: Daylin Morgan Date: Mon, 21 Oct 2024 00:12:17 -0500 Subject: [PATCH] add infra to trigger swww --- src/hyprland.nim | 5 +++-- src/hyprman.nim | 2 +- src/swww.nim | 14 ++++++++++++-- 3 files changed, 16 insertions(+), 5 deletions(-) diff --git a/src/hyprland.nim b/src/hyprland.nim index e4ef3a1..0ce09fc 100644 --- a/src/hyprland.nim +++ b/src/hyprland.nim @@ -1,5 +1,5 @@ import std/[os, strformat, strutils, streams, tables, net, sugar] -import ./lib +import ./[lib, swww] export tables import yaml, jsony @@ -124,9 +124,10 @@ proc handleHyprEvent(event: string) = s = event.split(">>", 1) event = s[0] - if event == "monitoraddedv2": + if event in ["monitoraddedv2", "monitorremoved"]: # TODO: open as many bars as necessary depending on num monitors notify("monitor added") + oneShotSwww() if event in redrawEvents: writeEwwClasses() diff --git a/src/hyprman.nim b/src/hyprman.nim index beea9dd..de06a6d 100644 --- a/src/hyprman.nim +++ b/src/hyprman.nim @@ -25,7 +25,7 @@ proc watch() = proc swww() = ## set swww to cycle through wallpapers - runSwww() + persistentSwww() when isMainModule: const diff --git a/src/swww.nim b/src/swww.nim index 6984128..2a97729 100644 --- a/src/swww.nim +++ b/src/swww.nim @@ -1,6 +1,8 @@ import std/[os, osproc, strformat, strutils, random] import ./lib +const oneMinute = 1000 * 60 + proc loadGallery(): seq[string] = for path in walkDirRec( config.wallpapers, yieldFilter = {pcFile, pcLinkToFile} @@ -20,9 +22,17 @@ proc setImg(path: string, output: string) = execCmd(fmt"swww img --transition-type fade --outputs {output} {path}") if code != 0: notify "swww failed" -const oneMinute = 1000 * 60 +proc oneShotSwww*() = + if config.wallpapers == "": return + if not dirExists(config.wallpapers): + notify(fmt"{config.wallpapers} directory does not exist") + quit(1) + let gallery = loadGallery() + for monitor in swwwMonitors(): + setImg(gallery.sample(), monitor) -proc runSwww*() = + +proc persistentSwww*() = if config.wallpapers == "": quit(0) if not dirExists(config.wallpapers): notify(fmt"{config.wallpapers} directory does not exist")