add callback option

This commit is contained in:
Simon Vieille 2024-08-01 22:47:26 +02:00
commit d11d8c7f87
Signed by: deblan
GPG key ID: 579388D585F70417
5 changed files with 52 additions and 6 deletions

View file

@ -2,6 +2,7 @@ package main
import (
"log"
"os/exec"
"go.i3wm.org/i3"
)
@ -17,11 +18,13 @@ func GetWorkspaceWallpaper(workspace string, config Config) string {
return file
}
func GetOutputsWallpapers(config Config) ([]string, error) {
func GetOutputsWallpapers(config Config) ([]string, []string, error) {
files := []string{}
screens := []string{}
outputs, err := i3.GetOutputs()
if err != nil {
return files, err
return files, screens, err
}
for _, output := range outputs {
@ -30,21 +33,29 @@ func GetOutputsWallpapers(config Config) ([]string, error) {
if file != "" {
files = append(files, file)
screens = append(screens, output.Name)
}
}
}
return files, nil
return files, screens, nil
}
func UpdateWallapers(config Config) {
files, err := GetOutputsWallpapers(config)
files, screens, err := GetOutputsWallpapers(config)
if err != nil {
log.Printf("[ERROR] %s", err.Error())
return
}
cmd, err := FehUpdateWallpapers(files)
var cmd *exec.Cmd
if config.Callback == "" {
cmd, err = FehUpdateWallpapers(files)
} else {
cmd, err = CallbackUpdateWallpapers(config.Callback, files, screens)
}
if err != nil {
log.Printf("[ERROR] cmd=%s error=%s", cmd.String(), err.Error())