init
This commit is contained in:
commit
0900b04c7c
3 changed files with 77 additions and 0 deletions
8
go.mod
Normal file
8
go.mod
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
module gitnet.fr/deblan/smart-screensaver
|
||||
|
||||
go 1.23.0
|
||||
|
||||
require (
|
||||
github.com/vitali-fedulov/hyper v1.0.1 // indirect
|
||||
github.com/vitali-fedulov/images3 v1.0.16 // indirect
|
||||
)
|
||||
4
go.sum
Normal file
4
go.sum
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
github.com/vitali-fedulov/hyper v1.0.1 h1:juW5AgxqAVbAAlakTcc1IeO/iqT8R+KdIyia8tz29zE=
|
||||
github.com/vitali-fedulov/hyper v1.0.1/go.mod h1:nQqkBaCL7ETNg7c90cbfFeJWoKchMrPejZYr+kiuSQI=
|
||||
github.com/vitali-fedulov/images3 v1.0.16 h1:FBFR9v/MpA5H6VcoEMrpfX3epPxWhWZKhvA9R/VzssU=
|
||||
github.com/vitali-fedulov/images3 v1.0.16/go.mod h1:E53TQh4WO/byLuozZvfgJ/JIsSKsfbhnjaOnMAb4ZjM=
|
||||
65
main.go
Normal file
65
main.go
Normal file
|
|
@ -0,0 +1,65 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"flag"
|
||||
"fmt"
|
||||
"log"
|
||||
"os"
|
||||
"os/exec"
|
||||
"time"
|
||||
|
||||
"github.com/vitali-fedulov/images3"
|
||||
)
|
||||
|
||||
var display string
|
||||
var imagesStore string
|
||||
var delay int
|
||||
|
||||
func main() {
|
||||
flag.StringVar(&display, "d", "", "Display")
|
||||
flag.StringVar(&imagesStore, "s", "", "Images directory")
|
||||
flag.IntVar(&delay, "t", 60, "Delay between checks")
|
||||
flag.Parse()
|
||||
|
||||
directory, _ := os.MkdirTemp("", "smart-screensaver")
|
||||
images := []string{}
|
||||
i := 0
|
||||
|
||||
for {
|
||||
image := fmt.Sprintf("%s/%d.jpg", directory, i)
|
||||
_, err := exec.Command("import", "-display", display, "-window", "root", image).Output()
|
||||
|
||||
i++
|
||||
|
||||
if err == nil {
|
||||
images = append(images, image)
|
||||
}
|
||||
|
||||
log.Println("Checking...")
|
||||
|
||||
if len(images) == 2 {
|
||||
img1, _ := images3.Open(images[0])
|
||||
img2, _ := images3.Open(images[1])
|
||||
|
||||
icon1 := images3.Icon(img1, images[0])
|
||||
icon2 := images3.Icon(img2, images[1])
|
||||
|
||||
if images3.Similar(icon1, icon2) {
|
||||
log.Println("Starting screensaver...")
|
||||
cmd := exec.Command("feh", "-F", "-r", "--on-last-slide", "resume", "-z", "-D", "2", imagesStore)
|
||||
cmd.Env = []string{fmt.Sprintf("DISPLAY=%s", display)}
|
||||
_, err := cmd.Output()
|
||||
|
||||
if err != nil {
|
||||
log.Println(err.Error())
|
||||
}
|
||||
}
|
||||
|
||||
os.Remove(images[0])
|
||||
|
||||
images = []string{images[1]}
|
||||
}
|
||||
|
||||
time.Sleep(time.Duration(delay) * time.Second)
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue