func newHeads(X *xgb.Conn) heads { var primaryHead *head var primaryOutput randr.Output root := xproto.Setup(X).DefaultScreen(X).Root resources, err := randr.GetScreenResourcesCurrent(X, root).Reply() if err != nil { log.Fatalf("Could not get screen resources: %s.", err) } primaryOutputReply, _ := randr.GetOutputPrimary(X, root).Reply() if primaryOutputReply != nil { primaryOutput = primaryOutputReply.Output } hds := make([]head, 0, len(resources.Outputs)) off := make([]string, 0) disconnected := make([]string, 0) for i, output := range resources.Outputs { oinfo, err := randr.GetOutputInfo(X, output, 0).Reply() if err != nil { log.Fatalf("Could not get output info for screen %d: %s.", i, err) } outputName := string(oinfo.Name) if oinfo.Connection != randr.ConnectionConnected { disconnected = append(disconnected, outputName) continue } if oinfo.Crtc == 0 { off = append(off, outputName) continue } crtcinfo, err := randr.GetCrtcInfo(X, oinfo.Crtc, 0).Reply() if err != nil { log.Fatalf("Could not get crtc info for screen (%d, %s): %s.", i, outputName, err) } head := newHead(output, outputName, crtcinfo) if output == primaryOutput { primaryHead = &head } hds = append(hds, head) } if primaryHead == nil && len(hds) > 0 { tmp := hds[0] primaryHead = &tmp } hdsPrim := heads{ primary: primaryHead, heads: hds, off: off, disconnected: disconnected, } sort.Sort(hdsPrim) return hdsPrim }
func (ms Monitors) Update(e *Euclid, x XHandle, mergeOverlapping, removeUnplugged, removeDisabled bool) bool { c := x.Conn() sres, err := randr.GetScreenResources(c, x.Root()).Reply() if err != nil { return false } var r []*randr.GetOutputInfoReply for _, o := range sres.Outputs { rp, _ := randr.GetOutputInfo(c, o, xproto.TimeCurrentTime).Reply() r = append(r, rp) } for _, m := range ms { m.wired = false } for i, info := range r { if info != nil { if info.Crtc != 0 { ir, _ := randr.GetCrtcInfo(c, info.Crtc, xproto.TimeCurrentTime).Reply() if ir != nil { rect := xproto.Rectangle{ir.X, ir.Y, ir.Width, ir.Height} m := ms.fromId(sres.Outputs[i]) if m != nil { m.rectangle = rect m.UpdateRoot() for _, d := range m.desktops { for _, _ = range d.clients { //mm.Translate(mm, n.Client) } } //mm.Arrange() m.wired = true } else { m := ms.Add(e, x, rect) m.name = string(info.Name) m.id = sres.Outputs[i] } } } else if !removeDisabled && info.Connection != randr.ConnectionDisconnected { m := ms.fromId(sres.Outputs[i]) if m != nil { m.wired = true } } } } gpo, _ := randr.GetOutputPrimary(c, x.Root()).Reply() if gpo != nil { primary := ms.fromId(gpo.Output) if primary != nil { primary.primary = true if ms.Focused() != primary { primary.focused = true } //ewmh_update_current_desktop(); } } if mergeOverlapping { ms.mergeOverlapping() } if removeUnplugged { ms.removeUnplugged() } //update_motion_recorder(); return ms.Number() > 0 }