init
This commit is contained in:
commit
53b2c66770
5 changed files with 165 additions and 0 deletions
78
main.go
Normal file
78
main.go
Normal file
|
|
@ -0,0 +1,78 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"log"
|
||||
"os"
|
||||
"os/exec"
|
||||
|
||||
"go.i3wm.org/i3"
|
||||
"gopkg.in/yaml.v3"
|
||||
)
|
||||
|
||||
type Config struct {
|
||||
Default string `yaml:"default"`
|
||||
Workspaces map[string]string `yaml:"workspaces"`
|
||||
}
|
||||
|
||||
func getWallpaper(workspace string, config Config) string {
|
||||
file := config.Default
|
||||
workspaceFile := config.Workspaces[workspace]
|
||||
|
||||
if workspaceFile != "" {
|
||||
file = workspaceFile
|
||||
}
|
||||
|
||||
return file
|
||||
}
|
||||
|
||||
func main() {
|
||||
recv := i3.Subscribe(i3.WorkspaceEventType)
|
||||
|
||||
if len(os.Args) != 2 {
|
||||
fmt.Errorf("Configuration required!")
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
data, err := os.ReadFile(os.Args[1])
|
||||
config := Config{}
|
||||
|
||||
if err != nil {
|
||||
log.Printf("[error] %s", err.Error())
|
||||
}
|
||||
|
||||
err = yaml.Unmarshal(data, &config)
|
||||
|
||||
if err != nil {
|
||||
log.Printf("[error] %s", err.Error())
|
||||
}
|
||||
|
||||
for recv.Next() {
|
||||
event := recv.Event().(*i3.WorkspaceEvent)
|
||||
|
||||
if event.Change != "focus" {
|
||||
continue
|
||||
}
|
||||
|
||||
outputs, err := i3.GetOutputs()
|
||||
args := []string{}
|
||||
|
||||
if err == nil {
|
||||
for _, output := range outputs {
|
||||
if output.CurrentWorkspace != "" {
|
||||
args = append(args, "--bg-fill", getWallpaper(output.CurrentWorkspace, config))
|
||||
}
|
||||
}
|
||||
|
||||
cmd := exec.Command("feh", args...)
|
||||
cmd.Env = os.Environ()
|
||||
log.Printf("[DEBUG] %s", cmd.String())
|
||||
|
||||
if err := cmd.Run(); err != nil {
|
||||
log.Printf("[ERROR] %s", err.Error())
|
||||
}
|
||||
} else {
|
||||
log.Printf("[ERROR] %s", err.Error())
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue