From 91f87397b0491976f88bff412b12dc8293378c54 Mon Sep 17 00:00:00 2001 From: andrzej Date: Thu, 31 Oct 2024 15:18:04 +0100 Subject: [PATCH] background fill (introduces race condition!) --- slideshow.go | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/slideshow.go b/slideshow.go index 337466d..76223ad 100644 --- a/slideshow.go +++ b/slideshow.go @@ -9,19 +9,33 @@ import ( func slideshow(ch <-chan string) { dir := <-ch - ticker := time.NewTicker(time.Duration(config.Duration) * time.Second) + ticker := time.NewTicker(time.Duration(config.Duration) * time.Minute) + //set a flat background color based on config defaults - // err = exec.Command("swaybg", "-i", img, "--mode", "fit").Run() + fillReady := make(chan bool) + go func() { + fillCmd := exec.Command("swaybg", "-c", "#232136") + err := fillCmd.Start() + if err != nil { + fmt.Println("could not set background color", err) + } + fmt.Println("bg color set!") + fillReady <- true + fillCmd.Wait() + }() + var cmd *exec.Cmd go func() { for { + <-fillReady + newCmd := setRandomWallpaper(dir) if cmd != nil { err := cmd.Process.Kill() if err != nil { log.Fatal("could not kill process", err) } } - cmd = setRandomWallpaper(dir) + cmd = newCmd select { case dir = <-ch: log.Println("directory set!") @@ -38,9 +52,9 @@ func setRandomWallpaper(dir string) *exec.Cmd { if err != nil { panic(err) } - fmt.Printf("setting wallpaper: %v\n", img) cmd := exec.Command("swaybg", "-i", img, "--mode", "fit") + fmt.Printf("setting wallpaper: %v\n", img) err = cmd.Start() if err != nil { log.Fatal("failed to set wallpaper!", err)