add swww implementation for random wallpapers

This commit is contained in:
Daylin Morgan 2024-10-20 09:36:46 -05:00
parent 1561acdb5f
commit 33e47efe43
Signed by: daylin
GPG key ID: 950D13E9719334AD
4 changed files with 62 additions and 5 deletions

View file

@ -17,6 +17,7 @@ type
id*: int id*: int
Monitor = object Monitor = object
activeWorkspace*: ActiveWorkspace activeWorkspace*: ActiveWorkspace
name: string
id*: int id*: int

View file

@ -1,8 +1,13 @@
## hyprman, the hyprland companion ## hyprman, the hyprland companion
import std/[osproc, strformat] import std/[os, osproc, strformat]
import hwylterm/cligen, cligen import hwylterm/cligen, cligen
import ./[mako,hyprland, lib]# state] import ./[
hyprland,
lib,
mako,
swww
]
hwylCli(clCfg) hwylCli(clCfg)
@ -18,6 +23,10 @@ proc watch() =
## watch hyprland events for eww class changes ## watch hyprland events for eww class changes
watchHyprland() watchHyprland()
proc swww() =
## set swww to cycle through wallpapers
runSwww()
when isMainModule: when isMainModule:
const const
config = //{"config": "path/to/config"} config = //{"config": "path/to/config"}
@ -27,7 +36,19 @@ when isMainModule:
"reverse": "swap notification order" "reverse": "swap notification order"
} }
dispatchMulti( dispatchMulti(
[makoCmd, cmdName = "mako", usage = clCfg.use, help = makoHelp], [makoCmd, usage = clCfg.use, help = makoHelp, cmdName = "mako",],
[start, usage = clCfg.use], [start , usage = clCfg.use],
[watch, usage = clCfg.use] [watch , usage = clCfg.use],
[swww , usage = clCfg.use],
) )
#!/usr/bin/env bash
#[
DIR=./woodblock-cherry-blossom/
while : ; do
for file in $(find $DIR -type f -name '*.png');do
swww img "$file" --transition-type wave
sleep 3600
done
done
]#

View file

@ -10,6 +10,7 @@ proc notify*(message: string) =
type type
Icons = Table[string, string] Icons = Table[string, string]
Config = object # config vs icons? Config = object # config vs icons?
wallpapers* {.defaultVal: ""}: string
classes*: Icons classes*: Icons
`no-client`*: string `no-client`*: string
`default-icon`*: string `default-icon`*: string
@ -19,6 +20,7 @@ proc loadConfig*(): Config =
if fileExists(configPath): if fileExists(configPath):
var s = newFileStream(configPath) var s = newFileStream(configPath)
load(s, result) load(s, result)
result.wallpapers = expandTilde(result.wallpapers)
func pickIcon*( func pickIcon*(
c: Config, c: Config,

33
src/swww.nim Normal file
View file

@ -0,0 +1,33 @@
import std/[os, osproc, strformat, strutils, random]
import ./lib
proc loadGallery(): seq[string] =
for path in walkDirRec(
config.wallpapers, yieldFilter = {pcFile, pcLinkToFile}
):
let (_,_, ext) = splitFile(path)
if ext in [".png", ".jpeg"]:
result.add path
proc swwwMonitors(): seq[string] =
let (output, code) = execCmdEx("swww query")
if code != 0: notify "swww failed"
for line in output.strip().splitLines():
result.add line.split(':', 1)[0]
proc setImg(path: string, output: string) =
let code =
execCmd(fmt"swww img --transition-type fade --outputs {output} {path}")
if code != 0: notify "swww failed"
proc runSwww*() =
if config.wallpapers == "": quit(0)
if not dirExists(config.wallpapers):
notify(fmt"{config.wallpapers} directory does not exist")
quit(1)
let gallery = loadGallery()
while true:
for monitor in swwwMonitors():
setImg(gallery.sample(), monitor)
sleep 1000 * 60 * 30