Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 19 additions & 4 deletions linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
package wallpaper

import (
"os"
"os/exec"
"os/user"
"path/filepath"
Expand Down Expand Up @@ -53,10 +54,24 @@ func SetFromFile(file string) error {
case "Deepin":
return exec.Command("dconf", "write", "/com/deepin/wrap/gnome/desktop/background/picture-uri", strconv.Quote("file://"+file)).Run()
default:
err := exec.Command("swaybg", "-i", file).Start()
// if the command completed successfully, return
if err == nil {
return nil
// Make sure we're on wayland at all, otherwise fall back to feh
if os.Getenv("WAYLAND_DISPLAY") != "" {

// Search for existing swww sockets which might indicate the user prefers it to swaybg
swwSock := os.Getenv("XDG_RUNTIME_DIR") + "/swww-" + os.Getenv("WAYLAND_DISPLAY") + ".socket"

if _, err := os.Stat(swwSock); err == nil {
err := exec.Command("swww", "img", file).Start()
if err == nil {
return nil
}
}

err := exec.Command("swaybg", "-i", file).Start()
// if the command completed successfully, return
if err == nil {
return nil
}
}

return exec.Command("feh", "-bg-fill", file).Run()
Expand Down