aboutsummaryrefslogtreecommitdiff
path: root/nexgb/examples/randr.go
blob: 064856dc69d5eb27a3495fb4ac156b3abf1220ef (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
41
42
43
44
45
46
47
48
package main

import (
	"fmt"
	"log"

	"github.com/BurntSushi/xgb"
)

func main() {
	X, _ := xgb.NewConn()

	err := X.RegisterExtension("randr")
	if err != nil {
		log.Fatal(err)
	}

	resources, err := X.RandrGetScreenResources(X.DefaultScreen().Root).Reply()
	if err != nil {
		log.Fatal(err)
	}

	for _, output := range resources.Outputs {
		info, err := X.RandrGetOutputInfo(output, 0).Reply()
		if err != nil {
			log.Fatal(err)
		}

		bestMode := info.Modes[0]
		for _, mode := range resources.Modes {
			if mode.Id == uint32(bestMode) {
				fmt.Printf("Width: %d, Height: %d\n", mode.Width, mode.Height)
			}
		}
	}

	fmt.Println("\n")

	for _, crtc := range resources.Crtcs {
		info, err := X.RandrGetCrtcInfo(crtc, 0).Reply()
		if err != nil {
			log.Fatal(err)
		}
		fmt.Printf("X: %d, Y: %d, Width: %d, Height: %d\n",
			info.X, info.Y, info.Width, info.Height)
	}
}