diff --git a/README.md b/README.md index 77d9caa..d04fb6c 100644 --- a/README.md +++ b/README.md @@ -37,7 +37,7 @@ workspaces: "Name of the workspace 3": /home/alice/wallpapers/3.jpg ``` -Next, you simply need to run `i3-wallpaper-manager` while specify the path to the configuration file. +Next, you simply need to run `i3-wallpaper-manager` and specify the path to the configuration file. ```bash DISPLAY=:0 i3-wallpaper-manager /path/to/config.yaml @@ -48,3 +48,17 @@ To run it when i3 starts, add this to your i3 configuration: ```bash exec_always DISPLAY=:0 i3-wallpaper-manager /path/to/config.yaml ``` + +If you wish to use a program other than `feh`, set the `callback` parameter by specifying the path to your script. + +``` +#!/bin/sh + +SCREEN_1="$1" +WALLPAPER_1="$2" + +SCREEN_2="$3" +WALLPAPER_2="$4" + +# ... +``` diff --git a/callback.go b/callback.go new file mode 100644 index 0000000..63a9fc0 --- /dev/null +++ b/callback.go @@ -0,0 +1,19 @@ +package main + +import ( + "os" + "os/exec" +) + +func CallbackUpdateWallpapers(callback string, files, screens []string) (*exec.Cmd, error) { + args := []string{} + + for key, file := range files { + args = append(args, screens[key], file) + } + + cmd := exec.Command(callback, args...) + cmd.Env = os.Environ() + + return cmd, cmd.Run() +} diff --git a/config.go b/config.go index 9e657cf..e90166f 100644 --- a/config.go +++ b/config.go @@ -8,6 +8,7 @@ import ( type Config struct { Default string `yaml:"default"` + Callback string `yaml:"callback"` Workspaces map[string]string `yaml:"workspaces"` } diff --git a/config.yaml.example b/config.yaml.example index 5e50253..0cf69eb 100644 --- a/config.yaml.example +++ b/config.yaml.example @@ -3,3 +3,4 @@ workspaces: "Name of the workspace 1": /home/alice/wallpapers/1.jpg "Name of the workspace 2": /home/alice/wallpapers/2.jpg "Name of the workspace 3": /home/alice/wallpapers/3.jpg +# callback: /path/to/custom.sh diff --git a/wallpaper.go b/wallpaper.go index bbef976..016aa3a 100644 --- a/wallpaper.go +++ b/wallpaper.go @@ -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())