aboutsummaryrefslogtreecommitdiff
path: root/prototypes/xgb-monitors.go
blob: 5ce5af9eaca83595f2ed47428c0bbc58f6931ddf (plain)
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
package main

import (
	"github.com/BurntSushi/xgb"
	"github.com/BurntSushi/xgb/xproto"
	"log"

	// Needs a patched local version with xcb-proto 1.12 and this fix:
	// -size := xgb.Pad((8 + (24 + xgb.Pad((int(NOutput) * 4)))))
	// +size := xgb.Pad((8 + (24 + xgb.Pad((int(Monitorinfo.NOutput) * 4)))))
	"github.com/BurntSushi/xgb/randr"
)

func main() {
	X, err := xgb.NewConn()
	if err != nil {
		log.Fatalln(err)
	}

	if err := randr.Init(X); err != nil {
		log.Fatalln(err)
	}

	setup := xproto.Setup(X)
	screen := setup.DefaultScreen(X)

	ms, err := randr.GetMonitors(X, screen.Root, true /* GetActive */).Reply()
	if err != nil {
		log.Fatalln(err)
	}

	for _, m := range ms.Monitors {
		reply, err := xproto.GetAtomName(X, m.Name).Reply()
		if err != nil {
			log.Fatalln(err)
		}

		log.Printf("Monitor %s %+v\n", reply.Name, m)
	}
}