github.com/robotn/xgb@v0.0.0-20190912153532-2cb92d044934/examples/xinerama/main.go (about) 1 // Example xinerama shows how to query the geometry of all active heads. 2 package main 3 4 import ( 5 "fmt" 6 "log" 7 8 "github.com/robotn/xgb" 9 "github.com/robotn/xgb/xinerama" 10 ) 11 12 func main() { 13 X, err := xgb.NewConn() 14 if err != nil { 15 log.Fatal(err) 16 } 17 18 // Initialize the Xinerama extension. 19 // The appropriate 'Init' function must be run for *every* 20 // extension before any of its requests can be used. 21 err = xinerama.Init(X) 22 if err != nil { 23 log.Fatal(err) 24 } 25 26 // Issue a request to get the screen information. 27 reply, err := xinerama.QueryScreens(X).Reply() 28 if err != nil { 29 log.Fatal(err) 30 } 31 32 // reply.Number is the number of active heads, while reply.ScreenInfo 33 // is a slice of XineramaScreenInfo containing the rectangle geometry 34 // of each head. 35 fmt.Printf("Number of heads: %d\n", reply.Number) 36 for i, screen := range reply.ScreenInfo { 37 fmt.Printf("%d :: X: %d, Y: %d, Width: %d, Height: %d\n", 38 i, screen.XOrg, screen.YOrg, screen.Width, screen.Height) 39 } 40 }