add infra to trigger swww

This commit is contained in:
Daylin Morgan 2024-10-21 00:12:17 -05:00
parent 8fa101f0e2
commit c93f726dd6
Signed by: daylin
GPG key ID: 950D13E9719334AD
3 changed files with 16 additions and 5 deletions

View file

@ -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()

View file

@ -25,7 +25,7 @@ proc watch() =
proc swww() =
## set swww to cycle through wallpapers
runSwww()
persistentSwww()
when isMainModule:
const

View file

@ -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")