63 lines
1.2 KiB
Go
63 lines
1.2 KiB
Go
package main
|
|
|
|
import (
|
|
"log"
|
|
"os/exec"
|
|
|
|
"go.i3wm.org/i3"
|
|
)
|
|
|
|
func GetWorkspaceWallpaper(workspace string, config Config) string {
|
|
file := config.Default
|
|
workspaceFile := config.Workspaces[workspace]
|
|
|
|
if workspaceFile != "" {
|
|
file = workspaceFile
|
|
}
|
|
|
|
return file
|
|
}
|
|
|
|
func GetOutputsWallpapers(config Config) ([]string, []string, error) {
|
|
files := []string{}
|
|
screens := []string{}
|
|
outputs, err := i3.GetOutputs()
|
|
if err != nil {
|
|
return files, screens, err
|
|
}
|
|
|
|
for _, output := range outputs {
|
|
if output.CurrentWorkspace != "" {
|
|
file := GetWorkspaceWallpaper(output.CurrentWorkspace, config)
|
|
|
|
if file != "" {
|
|
files = append(files, file)
|
|
screens = append(screens, output.Name)
|
|
}
|
|
}
|
|
}
|
|
|
|
return files, screens, nil
|
|
}
|
|
|
|
func UpdateWallapers(config Config) {
|
|
files, screens, err := GetOutputsWallpapers(config)
|
|
if err != nil {
|
|
log.Printf("[ERROR] %s", err.Error())
|
|
return
|
|
}
|
|
|
|
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())
|
|
} else {
|
|
log.Printf("[SUCCESS] cmd=%s", cmd.String())
|
|
}
|
|
}
|