func (ms Monitors) Init(e *Euclid, x XHandle) (bool, bool) { var rr, xn bool c := x.Conn() err := randr.Init(c) if err == nil && ms.Update(e, x, false, false, false) { rr = true randr.SelectInputChecked(c, x.Root(), randr.NotifyMaskScreenChange) } else { rr = false err = xinerama.Init(c) if err == nil { xia, err := xinerama.IsActive(c).Reply() if xia != nil && err == nil { xn = true xsq, _ := xinerama.QueryScreens(c).Reply() xsi := xsq.ScreenInfo for i := 0; i < len(xsi); i++ { info := xsi[i] rect := xproto.Rectangle{info.XOrg, info.YOrg, info.Width, info.Height} ms.Add(e, x, rect) } } else { s := x.Screen() rect := xproto.Rectangle{0, 0, s.WidthInPixels, s.HeightInPixels} ms.Add(e, x, rect) } } } return rr, xn }
func subscribeXEvents(ch chan<- Event, done <-chan struct{}) { X, err := xgb.NewConn() if err != nil { ch <- Event{Error: err} return } defer X.Close() if err = randr.Init(X); err != nil { ch <- Event{Error: err} return } root := xproto.Setup(X).DefaultScreen(X).Root eventMask := randr.NotifyMaskScreenChange | randr.NotifyMaskCrtcChange | randr.NotifyMaskOutputChange | randr.NotifyMaskOutputProperty err = randr.SelectInputChecked(X, root, uint16(eventMask)).Check() if err != nil { ch <- Event{Error: err} return } for { ev, err := X.WaitForEvent() select { case ch <- Event{Event: ev, Error: err}: case <-time.After(eventSendTimeout): continue case <-done: return } if err != nil { log.Fatal(err) } } }
func main() { X, _ := xgb.NewConn() // Every extension must be initialized before it can be used. err := randr.Init(X) if err != nil { log.Fatal(err) } // Get the root window on the default screen. root := xproto.Setup(X).DefaultScreen(X).Root // Gets the current screen resources. Screen resources contains a list // of names, crtcs, outputs and modes, among other things. resources, err := randr.GetScreenResources(X, root).Reply() if err != nil { log.Fatal(err) } // Iterate through all of the outputs and show some of their info. for _, output := range resources.Outputs { info, err := randr.GetOutputInfo(X, 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") // Iterate through all of the crtcs and show some of their info. for _, crtc := range resources.Crtcs { info, err := randr.GetCrtcInfo(X, 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) } // Tell RandR to send us events. (I think these are all of them, as of 1.3.) err = randr.SelectInputChecked(X, root, randr.NotifyMaskScreenChange| randr.NotifyMaskCrtcChange| randr.NotifyMaskOutputChange| randr.NotifyMaskOutputProperty).Check() if err != nil { log.Fatal(err) } // Listen to events and just dump them to standard out. // A more involved approach will have to read the 'U' field of // RandrNotifyEvent, which is a union (really a struct) of type // RanrNotifyDataUnion. for { ev, err := X.WaitForEvent() if err != nil { log.Fatal(err) } fmt.Println(ev) } }