-
Notifications
You must be signed in to change notification settings - Fork 7
/
lock.go
56 lines (48 loc) · 1.59 KB
/
lock.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
package main
import (
"github.com/vova616/screenshot"
"github.com/BurntSushi/xgb"
"github.com/BurntSushi/xgb/xinerama"
"github.com/disintegration/gift"
"image/png"
"image"
"os"
"strconv"
"bytes"
"os/exec"
)
func main() {
// read lock icon file
iconChan := make(chan image.Image)
go func() {
fdLock, _ := os.Open(os.Args[1])
defer fdLock.Close()
pngLock, _ := png.Decode(fdLock)
iconChan <- image.Image(pngLock)
}()
// get primary monitor's position and resolution
primaryChan := make(chan xinerama.ScreenInfo)
go func() {
c, _ := xgb.NewConn()
xinerama.Init(c)
reply, _ := xinerama.QueryScreens(c).Reply()
c.Close()
primaryChan <- reply.ScreenInfo[0]
}()
// take screenshot and pixelate
raw_root, _ := screenshot.CaptureScreen()
gift.New(gift.Pixelate(10)).Draw(raw_root, raw_root)
// wait for lock icon and primary display info
primary := <-primaryChan
icon := <-iconChan
// paste lock onto screenshot
posX := int(primary.XOrg) + int(primary.Width/2) - (icon.Bounds().Max.X/2)
posY := int(primary.YOrg) + int(primary.Height/2) - (icon.Bounds().Max.Y/2)
gift.New().DrawAt(raw_root, icon, image.Pt(posX, posY), gift.OverOperator)
// run i3lock with raw byte buffer as stdin
format := strconv.Itoa(raw_root.Bounds().Dx()) + "x" +
strconv.Itoa(raw_root.Bounds().Dy()) + ":rgbx"
i3 := exec.Command( "i3lock", "--raw", format, "-i", "/dev/stdin")
i3.Stdin = bytes.NewBuffer([]byte(raw_root.Pix))
i3.Run()
}