From 33e47efe433a2869227e699e3c929bbacd892ba7 Mon Sep 17 00:00:00 2001 From: Daylin Morgan Date: Sun, 20 Oct 2024 09:36:46 -0500 Subject: [PATCH] add swww implementation for random wallpapers --- src/hyprland.nim | 1 + src/hyprman.nim | 31 ++++++++++++++++++++++++++----- src/lib.nim | 2 ++ src/swww.nim | 33 +++++++++++++++++++++++++++++++++ 4 files changed, 62 insertions(+), 5 deletions(-) create mode 100644 src/swww.nim diff --git a/src/hyprland.nim b/src/hyprland.nim index ed96501..c89549c 100644 --- a/src/hyprland.nim +++ b/src/hyprland.nim @@ -17,6 +17,7 @@ type id*: int Monitor = object activeWorkspace*: ActiveWorkspace + name: string id*: int diff --git a/src/hyprman.nim b/src/hyprman.nim index 333bfde..0dcc87a 100644 --- a/src/hyprman.nim +++ b/src/hyprman.nim @@ -1,8 +1,13 @@ ## hyprman, the hyprland companion -import std/[osproc, strformat] +import std/[os, osproc, strformat] import hwylterm/cligen, cligen -import ./[mako,hyprland, lib]# state] +import ./[ + hyprland, + lib, + mako, + swww +] hwylCli(clCfg) @@ -18,6 +23,10 @@ proc watch() = ## watch hyprland events for eww class changes watchHyprland() +proc swww() = + ## set swww to cycle through wallpapers + runSwww() + when isMainModule: const config = //{"config": "path/to/config"} @@ -27,7 +36,19 @@ when isMainModule: "reverse": "swap notification order" } dispatchMulti( - [makoCmd, cmdName = "mako", usage = clCfg.use, help = makoHelp], - [start, usage = clCfg.use], - [watch, usage = clCfg.use] + [makoCmd, usage = clCfg.use, help = makoHelp, cmdName = "mako",], + [start , 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 +]# diff --git a/src/lib.nim b/src/lib.nim index 2d9b7d1..3da952d 100644 --- a/src/lib.nim +++ b/src/lib.nim @@ -10,6 +10,7 @@ proc notify*(message: string) = type Icons = Table[string, string] Config = object # config vs icons? + wallpapers* {.defaultVal: ""}: string classes*: Icons `no-client`*: string `default-icon`*: string @@ -19,6 +20,7 @@ proc loadConfig*(): Config = if fileExists(configPath): var s = newFileStream(configPath) load(s, result) + result.wallpapers = expandTilde(result.wallpapers) func pickIcon*( c: Config, diff --git a/src/swww.nim b/src/swww.nim new file mode 100644 index 0000000..3b4e307 --- /dev/null +++ b/src/swww.nim @@ -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 +