Merge branch 'feature/callback' into develop
This commit is contained in:
commit
8c0bc5c710
5 changed files with 50 additions and 6 deletions
16
README.md
16
README.md
|
|
@ -37,7 +37,7 @@ workspaces:
|
||||||
"Name of the workspace 3": /home/alice/wallpapers/3.jpg
|
"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
|
```bash
|
||||||
DISPLAY=:0 i3-wallpaper-manager /path/to/config.yaml
|
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
|
```bash
|
||||||
exec_always DISPLAY=:0 i3-wallpaper-manager /path/to/config.yaml
|
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
19
callback.go
Normal 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()
|
||||||
|
}
|
||||||
|
|
@ -8,6 +8,7 @@ import (
|
||||||
|
|
||||||
type Config struct {
|
type Config struct {
|
||||||
Default string `yaml:"default"`
|
Default string `yaml:"default"`
|
||||||
|
Callback string `yaml:"callback"`
|
||||||
Workspaces map[string]string `yaml:"workspaces"`
|
Workspaces map[string]string `yaml:"workspaces"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -3,3 +3,4 @@ workspaces:
|
||||||
"Name of the workspace 1": /home/alice/wallpapers/1.jpg
|
"Name of the workspace 1": /home/alice/wallpapers/1.jpg
|
||||||
"Name of the workspace 2": /home/alice/wallpapers/2.jpg
|
"Name of the workspace 2": /home/alice/wallpapers/2.jpg
|
||||||
"Name of the workspace 3": /home/alice/wallpapers/3.jpg
|
"Name of the workspace 3": /home/alice/wallpapers/3.jpg
|
||||||
|
# callback: /path/to/custom.sh
|
||||||
|
|
|
||||||
19
wallpaper.go
19
wallpaper.go
|
|
@ -2,6 +2,7 @@ package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"log"
|
"log"
|
||||||
|
"os/exec"
|
||||||
|
|
||||||
"go.i3wm.org/i3"
|
"go.i3wm.org/i3"
|
||||||
)
|
)
|
||||||
|
|
@ -17,11 +18,12 @@ func GetWorkspaceWallpaper(workspace string, config Config) string {
|
||||||
return file
|
return file
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetOutputsWallpapers(config Config) ([]string, error) {
|
func GetOutputsWallpapers(config Config) ([]string, []string, error) {
|
||||||
files := []string{}
|
files := []string{}
|
||||||
|
screens := []string{}
|
||||||
outputs, err := i3.GetOutputs()
|
outputs, err := i3.GetOutputs()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return files, err
|
return files, screens, err
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, output := range outputs {
|
for _, output := range outputs {
|
||||||
|
|
@ -30,21 +32,28 @@ func GetOutputsWallpapers(config Config) ([]string, error) {
|
||||||
|
|
||||||
if file != "" {
|
if file != "" {
|
||||||
files = append(files, file)
|
files = append(files, file)
|
||||||
|
screens = append(screens, output.Name)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return files, nil
|
return files, screens, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func UpdateWallapers(config Config) {
|
func UpdateWallapers(config Config) {
|
||||||
files, err := GetOutputsWallpapers(config)
|
files, screens, err := GetOutputsWallpapers(config)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("[ERROR] %s", err.Error())
|
log.Printf("[ERROR] %s", err.Error())
|
||||||
return
|
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 {
|
if err != nil {
|
||||||
log.Printf("[ERROR] cmd=%s error=%s", cmd.String(), err.Error())
|
log.Printf("[ERROR] cmd=%s error=%s", cmd.String(), err.Error())
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue