...
1
2
3
4
5
6
7
8
9
10
11 package main
12
13 import (
14 "fmt"
15 "log"
16
17 "github.com/jezek/xgb"
18 "github.com/jezek/xgb/randr"
19 "github.com/jezek/xgb/xproto"
20 )
21
22 func main() {
23 X, _ := xgb.NewConn()
24
25
26 err := randr.Init(X)
27 if err != nil {
28 log.Fatal(err)
29 }
30
31
32 root := xproto.Setup(X).DefaultScreen(X).Root
33
34
35
36 resources, err := randr.GetScreenResources(X, root).Reply()
37 if err != nil {
38 log.Fatal(err)
39 }
40
41
42 for _, output := range resources.Outputs {
43 info, err := randr.GetOutputInfo(X, output, 0).Reply()
44 if err != nil {
45 log.Fatal(err)
46 }
47
48 if info.Connection == randr.ConnectionConnected {
49 bestMode := info.Modes[0]
50 for _, mode := range resources.Modes {
51 if mode.Id == uint32(bestMode) {
52 fmt.Printf("Width: %d, Height: %d\n",
53 mode.Width, mode.Height)
54 }
55 }
56 }
57 }
58
59 fmt.Println("\n")
60
61
62 for _, crtc := range resources.Crtcs {
63 info, err := randr.GetCrtcInfo(X, crtc, 0).Reply()
64 if err != nil {
65 log.Fatal(err)
66 }
67 fmt.Printf("X: %d, Y: %d, Width: %d, Height: %d\n",
68 info.X, info.Y, info.Width, info.Height)
69 }
70
71
72 err = randr.SelectInputChecked(X, root,
73 randr.NotifyMaskScreenChange|
74 randr.NotifyMaskCrtcChange|
75 randr.NotifyMaskOutputChange|
76 randr.NotifyMaskOutputProperty).Check()
77 if err != nil {
78 log.Fatal(err)
79 }
80
81
82
83
84
85 for {
86 ev, err := X.WaitForEvent()
87 if err != nil {
88 log.Fatal(err)
89 }
90 fmt.Println(ev)
91 }
92 }
93
View as plain text