gopaper/hyprpaper.go

56 lines
1.0 KiB
Go
Raw Normal View History

2024-10-26 23:47:38 +00:00
package main
import (
"errors"
2024-10-27 17:15:14 +00:00
"log"
2024-10-26 23:47:38 +00:00
"os/exec"
)
2024-10-28 23:29:20 +00:00
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)
}
}
2024-10-26 23:47:38 +00:00
func hyprpaperPreload(path string) error {
2024-10-27 16:21:28 +00:00
out, err := exec.Command("hyprctl", "hyprpaper", "preload", path).Output()
2024-10-26 23:47:38 +00:00
if err != nil {
return err
}
2024-10-27 16:21:28 +00:00
return checkHyprctlError(out)
2024-10-26 23:47:38 +00:00
}
func hyprpaperWallpaper(path string) error {
2024-10-28 23:29:20 +00:00
out, err := exec.Command("hyprctl", "hyprpaper", "wallpaper", ",contain:"+path).Output()
2024-10-27 16:21:28 +00:00
if err != nil {
return err
}
return checkHyprctlError(out)
}
func hyprpaperUnloadAll() error {
2024-10-27 17:15:14 +00:00
out, err := exec.Command("hyprctl", "hyprpaper", "unload", "unused").Output()
2024-10-26 23:47:38 +00:00
if err != nil {
return err
}
2024-10-27 16:21:28 +00:00
return checkHyprctlError(out)
}
func checkHyprctlError(out []byte) error {
2024-10-26 23:47:38 +00:00
str := string(out)
if str != "ok\n" {
return errors.New(str)
}
return nil
}