gopaper/hyprpaper.go

56 lines
1.0 KiB
Go

package main
import (
"errors"
"log"
"os/exec"
)
func hyprpaperSet(path string) {
err := hyprpaperPreload(path)
if err != nil {
log.Fatal("preload failed!", err)
}
err = hyprpaperWallpaper(path)
if err != nil {
log.Fatal("set wallpaper failed!", err)
}
err = hyprpaperUnloadAll()
if err != nil {
log.Fatal("unload all failed!", err)
}
}
func hyprpaperPreload(path string) error {
out, err := exec.Command("hyprctl", "hyprpaper", "preload", path).Output()
if err != nil {
return err
}
return checkHyprctlError(out)
}
func hyprpaperWallpaper(path string) error {
out, err := exec.Command("hyprctl", "hyprpaper", "wallpaper", ",contain:"+path).Output()
if err != nil {
return err
}
return checkHyprctlError(out)
}
func hyprpaperUnloadAll() error {
out, err := exec.Command("hyprctl", "hyprpaper", "unload", "unused").Output()
if err != nil {
return err
}
return checkHyprctlError(out)
}
func checkHyprctlError(out []byte) error {
str := string(out)
if str != "ok\n" {
return errors.New(str)
}
return nil
}