Merge branch 'feature/callback' into develop
Some checks are pending
ci/woodpecker/push/build Pipeline is pending approval
ci/woodpecker/push/test Pipeline is pending approval

This commit is contained in:
Simon Vieille 2024-08-01 22:48:05 +02:00
commit 8c0bc5c710
5 changed files with 50 additions and 6 deletions

View file

@ -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"
# ...
```

19
callback.go Normal file
View file

@ -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()
}

View file

@ -8,6 +8,7 @@ import (
type Config struct {
Default string `yaml:"default"`
Callback string `yaml:"callback"`
Workspaces map[string]string `yaml:"workspaces"`
}

View file

@ -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

View file

@ -2,6 +2,7 @@ package main
import (
"log"
"os/exec"
"go.i3wm.org/i3"
)
@ -17,11 +18,12 @@ 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 +32,28 @@ 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())