-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
71 lines (63 loc) · 1.54 KB
/
main.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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
package main
import (
"fmt"
"log"
"os"
"os/signal"
"time"
"github.com/jezek/xgo"
)
func main() {
d, err := xgo.OpenDisplay("")
if err != nil {
log.Fatal(err)
return
}
//TODO listen in my own created window
fmt.Println("Display name:", d.Name())
fmt.Println("Number of screens:", d.NumberOfScreens())
fmt.Println("Number of desktops:", d.NumberOfDesktops())
fmt.Println("Default screen:", d.DefaultScreen().Id())
fmt.Println()
fmt.Println("Mouse info:")
s, err := d.Pointer().Status()
if err != nil {
fmt.Println("Can't obtain mouse status due to error:", err)
}
fmt.Printf("x: %d, y: %d, screen: %d, buttons: %v\n", s.RootX, s.RootY, s.Root.Screen().Id(), s.Button)
a := d.ActiveWindow()
ws, err := a.Pointer().Status()
if err != nil {
fmt.Printf("Can't obtain mouse status for window %s due to error: %v\n", a, err)
}
fmt.Println(s)
fmt.Println(ws)
signalChannel := make(chan os.Signal, 1)
signal.Notify(signalChannel, os.Interrupt)
stop := make(chan struct{})
mnch := a.Pointer().MotionNotify(stop)
fmt.Println("Listening to pointer motion notify in active window (hit CTRL-C to exit):")
fmt.Printf("x: %4d, y: %4d\n", s.RootX, s.RootY)
for mnch != nil {
select {
case <-signalChannel:
fmt.Println("ctrl-c")
close(stop)
stop = nil
signalChannel = nil
case mn, ok := <-mnch:
if !ok {
if stop != nil {
close(stop)
stop = nil
}
mnch = nil
break
}
fmt.Printf("x: %4d, y: %4d\n", mn.RootX, mn.RootY)
fmt.Println(mn)
}
}
fmt.Println("Done")
time.Sleep(time.Second)
}