// getBuffersReply reads a byte slice into a GetBuffersReply value. func getBuffersReply(buf []byte) *GetBuffersReply { v := new(GetBuffersReply) b := 1 // skip reply determinant b += 1 // padding v.Sequence = xgb.Get16(buf[b:]) b += 2 v.Length = xgb.Get32(buf[b:]) // 4-byte units b += 4 v.Width = xgb.Get32(buf[b:]) b += 4 v.Height = xgb.Get32(buf[b:]) b += 4 v.Count = xgb.Get32(buf[b:]) b += 4 b += 12 // padding v.Buffers = make([]DRI2Buffer, v.Count) b += DRI2BufferReadList(buf[b:], v.Buffers) return v }
// getContextReply reads a byte slice into a GetContextReply value. func getContextReply(buf []byte) *GetContextReply { v := new(GetContextReply) b := 1 // skip reply determinant if buf[b] == 1 { v.Enabled = true } else { v.Enabled = false } b += 1 v.Sequence = xgb.Get16(buf[b:]) b += 2 v.Length = xgb.Get32(buf[b:]) // 4-byte units b += 4 v.ElementHeader = ElementHeader(buf[b]) b += 1 b += 3 // padding v.NumInterceptedClients = xgb.Get32(buf[b:]) b += 4 b += 16 // padding v.InterceptedClients = make([]ClientInfo, v.NumInterceptedClients) b += ClientInfoReadList(buf[b:], v.InterceptedClients) return v }
// getParamReply reads a byte slice into a GetParamReply value. func getParamReply(buf []byte) *GetParamReply { v := new(GetParamReply) b := 1 // skip reply determinant if buf[b] == 1 { v.IsParamRecognized = true } else { v.IsParamRecognized = false } b += 1 v.Sequence = xgb.Get16(buf[b:]) b += 2 v.Length = xgb.Get32(buf[b:]) // 4-byte units b += 4 v.ValueHi = xgb.Get32(buf[b:]) b += 4 v.ValueLo = xgb.Get32(buf[b:]) b += 4 return v }
// CompletionEventNew constructs a CompletionEvent value that implements xgb.Event from a byte slice. func CompletionEventNew(buf []byte) xgb.Event { v := CompletionEvent{} b := 1 // don't read event number b += 1 // padding v.Sequence = xgb.Get16(buf[b:]) b += 2 v.Drawable = xproto.Drawable(xgb.Get32(buf[b:])) b += 4 v.MinorEvent = xgb.Get16(buf[b:]) b += 2 v.MajorEvent = buf[b] b += 1 b += 1 // padding v.Shmseg = Seg(xgb.Get32(buf[b:])) b += 4 v.Offset = xgb.Get32(buf[b:]) b += 4 return v }
// AttachFormatRead reads a byte slice into a AttachFormat value. func AttachFormatRead(buf []byte, v *AttachFormat) int { b := 0 v.Attachment = xgb.Get32(buf[b:]) b += 4 v.Format = xgb.Get32(buf[b:]) b += 4 return b }
// ClientInfoRead reads a byte slice into a ClientInfo value. func ClientInfoRead(buf []byte, v *ClientInfo) int { b := 0 v.ClientResource = ClientSpec(xgb.Get32(buf[b:])) b += 4 v.NumRanges = xgb.Get32(buf[b:]) b += 4 v.Ranges = make([]Range, v.NumRanges) b += RangeReadList(buf[b:], v.Ranges) return b }
// authenticateReply reads a byte slice into a AuthenticateReply value. func authenticateReply(buf []byte) *AuthenticateReply { v := new(AuthenticateReply) b := 1 // skip reply determinant b += 1 // padding v.Sequence = xgb.Get16(buf[b:]) b += 2 v.Length = xgb.Get32(buf[b:]) // 4-byte units b += 4 v.Authenticated = xgb.Get32(buf[b:]) b += 4 return v }
// waitSBCReply reads a byte slice into a WaitSBCReply value. func waitSBCReply(buf []byte) *WaitSBCReply { v := new(WaitSBCReply) b := 1 // skip reply determinant b += 1 // padding v.Sequence = xgb.Get16(buf[b:]) b += 2 v.Length = xgb.Get32(buf[b:]) // 4-byte units b += 4 v.UstHi = xgb.Get32(buf[b:]) b += 4 v.UstLo = xgb.Get32(buf[b:]) b += 4 v.MscHi = xgb.Get32(buf[b:]) b += 4 v.MscLo = xgb.Get32(buf[b:]) b += 4 v.SbcHi = xgb.Get32(buf[b:]) b += 4 v.SbcLo = xgb.Get32(buf[b:]) b += 4 return v }
// PropValNum64 transforms a GetPropertyReply struct into a 64 bit // integer. Useful when the property value is a single integer. func PropValNum64(reply *xproto.GetPropertyReply, err error) (int64, error) { if err != nil { return 0, err } if reply.Format != 32 { return 0, fmt.Errorf("PropValNum: Expected format 32 but got %d", reply.Format) } return int64(xgb.Get32(reply.Value)), nil }
// getOverlayWindowReply reads a byte slice into a GetOverlayWindowReply value. func getOverlayWindowReply(buf []byte) *GetOverlayWindowReply { v := new(GetOverlayWindowReply) b := 1 // skip reply determinant b += 1 // padding v.Sequence = xgb.Get16(buf[b:]) b += 2 v.Length = xgb.Get32(buf[b:]) // 4-byte units b += 4 v.OverlayWin = xproto.Window(xgb.Get32(buf[b:])) b += 4 b += 20 // padding return v }
// enableContextReply reads a byte slice into a EnableContextReply value. func enableContextReply(buf []byte) *EnableContextReply { v := new(EnableContextReply) b := 1 // skip reply determinant v.Category = buf[b] b += 1 v.Sequence = xgb.Get16(buf[b:]) b += 2 v.Length = xgb.Get32(buf[b:]) // 4-byte units b += 4 v.ElementHeader = ElementHeader(buf[b]) b += 1 if buf[b] == 1 { v.ClientSwapped = true } else { v.ClientSwapped = false } b += 1 b += 2 // padding v.XidBase = xgb.Get32(buf[b:]) b += 4 v.ServerTime = xgb.Get32(buf[b:]) b += 4 v.RecSequenceNum = xgb.Get32(buf[b:]) b += 4 b += 8 // padding v.Data = make([]byte, (int(v.Length) * 4)) copy(v.Data[:(int(v.Length)*4)], buf[b:]) b += xgb.Pad(int((int(v.Length) * 4))) return v }
// queryExtentsReply reads a byte slice into a QueryExtentsReply value. func queryExtentsReply(buf []byte) *QueryExtentsReply { v := new(QueryExtentsReply) b := 1 // skip reply determinant b += 1 // padding v.Sequence = xgb.Get16(buf[b:]) b += 2 v.Length = xgb.Get32(buf[b:]) // 4-byte units b += 4 if buf[b] == 1 { v.BoundingShaped = true } else { v.BoundingShaped = false } b += 1 if buf[b] == 1 { v.ClipShaped = true } else { v.ClipShaped = false } b += 1 b += 2 // padding v.BoundingShapeExtentsX = int16(xgb.Get16(buf[b:])) b += 2 v.BoundingShapeExtentsY = int16(xgb.Get16(buf[b:])) b += 2 v.BoundingShapeExtentsWidth = xgb.Get16(buf[b:]) b += 2 v.BoundingShapeExtentsHeight = xgb.Get16(buf[b:]) b += 2 v.ClipShapeExtentsX = int16(xgb.Get16(buf[b:])) b += 2 v.ClipShapeExtentsY = int16(xgb.Get16(buf[b:])) b += 2 v.ClipShapeExtentsWidth = xgb.Get16(buf[b:]) b += 2 v.ClipShapeExtentsHeight = xgb.Get16(buf[b:]) b += 2 return v }
// queryVersionReply reads a byte slice into a QueryVersionReply value. func queryVersionReply(buf []byte) *QueryVersionReply { v := new(QueryVersionReply) b := 1 // skip reply determinant b += 1 // padding v.Sequence = xgb.Get16(buf[b:]) b += 2 v.Length = xgb.Get32(buf[b:]) // 4-byte units b += 4 v.MajorVersion = xgb.Get32(buf[b:]) b += 4 v.MinorVersion = xgb.Get32(buf[b:]) b += 4 return v }
// swapBuffersReply reads a byte slice into a SwapBuffersReply value. func swapBuffersReply(buf []byte) *SwapBuffersReply { v := new(SwapBuffersReply) b := 1 // skip reply determinant b += 1 // padding v.Sequence = xgb.Get16(buf[b:]) b += 2 v.Length = xgb.Get32(buf[b:]) // 4-byte units b += 4 v.SwapHi = xgb.Get32(buf[b:]) b += 4 v.SwapLo = xgb.Get32(buf[b:]) b += 4 return v }
// DRI2BufferRead reads a byte slice into a DRI2Buffer value. func DRI2BufferRead(buf []byte, v *DRI2Buffer) int { b := 0 v.Attachment = xgb.Get32(buf[b:]) b += 4 v.Name = xgb.Get32(buf[b:]) b += 4 v.Pitch = xgb.Get32(buf[b:]) b += 4 v.Cpp = xgb.Get32(buf[b:]) b += 4 v.Flags = xgb.Get32(buf[b:]) b += 4 return b }
func main() { X, err := xgb.NewConn() if err != nil { log.Fatal(err) } // Get the window id of the root window. setup := xproto.Setup(X) root := setup.DefaultScreen(X).Root // Get the atom id (i.e., intern an atom) of "_NET_ACTIVE_WINDOW". aname := "_NET_ACTIVE_WINDOW" query1, buf := xproto.InternAtom(X, nil, true, uint16(len(aname)), aname) activeAtom, err := query1.Reply() if err != nil { log.Fatal(err) } // Get the atom id (i.e., intern an atom) of "_NET_WM_NAME". aname = "_NET_WM_NAME" query2, buf := xproto.InternAtom(X, buf, true, uint16(len(aname)), aname) nameAtom, err := query2.Reply() if err != nil { log.Fatal(err) } // Get the actual value of _NET_ACTIVE_WINDOW. // Note that 'reply.Value' is just a slice of bytes, so we use an // XGB helper function, 'Get32', to pull an unsigned 32-bit integer out // of the byte slice. We then convert it to an X resource id so it can // be used to get the name of the window in the next GetProperty request. query3, buf := xproto.GetProperty(X, buf, false, root, activeAtom.Atom, xproto.GetPropertyTypeAny, 0, (1<<32)-1) reply, err := query3.Reply() if err != nil { log.Fatal(err) } windowId := xproto.Window(xgb.Get32(reply.Value)) fmt.Printf("Active window id: %X\n", windowId) // Now get the value of _NET_WM_NAME for the active window. // Note that this time, we simply convert the resulting byte slice, // reply.Value, to a string. query4, buf := xproto.GetProperty(X, buf, false, windowId, nameAtom.Atom, xproto.GetPropertyTypeAny, 0, (1<<32)-1) reply, err = query4.Reply() if err != nil { log.Fatal(err) } fmt.Printf("Active window name: %s\n", string(reply.Value)) }
// getImageReply reads a byte slice into a GetImageReply value. func getImageReply(buf []byte) *GetImageReply { v := new(GetImageReply) b := 1 // skip reply determinant v.Depth = buf[b] b += 1 v.Sequence = xgb.Get16(buf[b:]) b += 2 v.Length = xgb.Get32(buf[b:]) // 4-byte units b += 4 v.Visual = xproto.Visualid(xgb.Get32(buf[b:])) b += 4 v.Size = xgb.Get32(buf[b:]) b += 4 return v }
// PropValWindow transforms a GetPropertyReply struct into an X resource // window identifier. // The property reply must be in 32 bit format. func PropValWindow(reply *xproto.GetPropertyReply, err error) (xproto.Window, error) { if err != nil { return 0, err } if reply.Format != 32 { return 0, fmt.Errorf("PropValId: Expected format 32 but got %d", reply.Format) } return xproto.Window(xgb.Get32(reply.Value)), nil }
// BufferSwapCompleteEventNew constructs a BufferSwapCompleteEvent value that implements xgb.Event from a byte slice. func BufferSwapCompleteEventNew(buf []byte) xgb.Event { v := BufferSwapCompleteEvent{} b := 1 // don't read event number b += 1 // padding v.Sequence = xgb.Get16(buf[b:]) b += 2 v.EventType = xgb.Get16(buf[b:]) b += 2 b += 2 // padding v.Drawable = xproto.Drawable(xgb.Get32(buf[b:])) b += 4 v.UstHi = xgb.Get32(buf[b:]) b += 4 v.UstLo = xgb.Get32(buf[b:]) b += 4 v.MscHi = xgb.Get32(buf[b:]) b += 4 v.MscLo = xgb.Get32(buf[b:]) b += 4 v.Sbc = xgb.Get32(buf[b:]) b += 4 return v }
// connectReply reads a byte slice into a ConnectReply value. func connectReply(buf []byte) *ConnectReply { v := new(ConnectReply) b := 1 // skip reply determinant b += 1 // padding v.Sequence = xgb.Get16(buf[b:]) b += 2 v.Length = xgb.Get32(buf[b:]) // 4-byte units b += 4 v.DriverNameLength = xgb.Get32(buf[b:]) b += 4 v.DeviceNameLength = xgb.Get32(buf[b:]) b += 4 b += 16 // padding { byteString := make([]byte, v.DriverNameLength) copy(byteString[:v.DriverNameLength], buf[b:]) v.DriverName = string(byteString) b += xgb.Pad(int(v.DriverNameLength)) } v.AlignmentPad = make([]byte, (((int(v.DriverNameLength) + 3) & -4) - int(v.DriverNameLength))) copy(v.AlignmentPad[:(((int(v.DriverNameLength)+3)&-4)-int(v.DriverNameLength))], buf[b:]) b += xgb.Pad(int((((int(v.DriverNameLength) + 3) & -4) - int(v.DriverNameLength)))) { byteString := make([]byte, v.DeviceNameLength) copy(byteString[:v.DeviceNameLength], buf[b:]) v.DeviceName = string(byteString) b += xgb.Pad(int(v.DeviceNameLength)) } return v }
// NotifyEventNew constructs a NotifyEvent value that implements xgb.Event from a byte slice. func NotifyEventNew(buf []byte) xgb.Event { v := NotifyEvent{} b := 1 // don't read event number v.ShapeKind = Kind(buf[b]) b += 1 v.Sequence = xgb.Get16(buf[b:]) b += 2 v.AffectedWindow = xproto.Window(xgb.Get32(buf[b:])) b += 4 v.ExtentsX = int16(xgb.Get16(buf[b:])) b += 2 v.ExtentsY = int16(xgb.Get16(buf[b:])) b += 2 v.ExtentsWidth = xgb.Get16(buf[b:]) b += 2 v.ExtentsHeight = xgb.Get16(buf[b:]) b += 2 v.ServerTime = xproto.Timestamp(xgb.Get32(buf[b:])) b += 4 if buf[b] == 1 { v.Shaped = true } else { v.Shaped = false } b += 1 b += 11 // padding return v }
// PropValAtom transforms a GetPropertyReply struct into an ATOM name. // The property reply must be in 32 bit format. func PropValAtom(xu *xgbutil.XUtil, reply *xproto.GetPropertyReply, err error) (string, error) { if err != nil { return "", err } if reply.Format != 32 { return "", fmt.Errorf("PropValAtom: Expected format 32 but got %d", reply.Format) } return AtomName(xu, xproto.Atom(xgb.Get32(reply.Value))) }
// getRectanglesReply reads a byte slice into a GetRectanglesReply value. func getRectanglesReply(buf []byte) *GetRectanglesReply { v := new(GetRectanglesReply) b := 1 // skip reply determinant v.Ordering = buf[b] b += 1 v.Sequence = xgb.Get16(buf[b:]) b += 2 v.Length = xgb.Get32(buf[b:]) // 4-byte units b += 4 v.RectanglesLen = xgb.Get32(buf[b:]) b += 4 b += 20 // padding v.Rectangles = make([]xproto.Rectangle, v.RectanglesLen) b += xproto.RectangleReadList(buf[b:], v.Rectangles) return v }
// InvalidateBuffersEventNew constructs a InvalidateBuffersEvent value that implements xgb.Event from a byte slice. func InvalidateBuffersEventNew(buf []byte) xgb.Event { v := InvalidateBuffersEvent{} b := 1 // don't read event number b += 1 // padding v.Sequence = xgb.Get16(buf[b:]) b += 2 v.Drawable = xproto.Drawable(xgb.Get32(buf[b:])) b += 4 return v }
// copyRegionReply reads a byte slice into a CopyRegionReply value. func copyRegionReply(buf []byte) *CopyRegionReply { v := new(CopyRegionReply) b := 1 // skip reply determinant b += 1 // padding v.Sequence = xgb.Get16(buf[b:]) b += 2 v.Length = xgb.Get32(buf[b:]) // 4-byte units b += 4 return v }
// BadContextErrorNew constructs a BadContextError value that implements xgb.Error from a byte slice. func BadContextErrorNew(buf []byte) xgb.Error { v := BadContextError{} v.NiceName = "BadContext" b := 1 // skip error determinant b += 1 // don't read error number v.Sequence = xgb.Get16(buf[b:]) b += 2 v.InvalidRecord = xgb.Get32(buf[b:]) b += 4 return v }
// PropValNums is the same as PropValNum, except that it returns a slice // of integers. Also must be 32 bit format. func PropValNums(reply *xproto.GetPropertyReply, err error) ([]uint, error) { if err != nil { return nil, err } if reply.Format != 32 { return nil, fmt.Errorf("PropValIds: Expected format 32 but got %d", reply.Format) } nums := make([]uint, reply.ValueLen) vals := reply.Value for i := 0; len(vals) >= 4; i++ { nums[i] = uint(xgb.Get32(vals)) vals = vals[4:] } return nums, nil }
// inputSelectedReply reads a byte slice into a InputSelectedReply value. func inputSelectedReply(buf []byte) *InputSelectedReply { v := new(InputSelectedReply) b := 1 // skip reply determinant if buf[b] == 1 { v.Enabled = true } else { v.Enabled = false } b += 1 v.Sequence = xgb.Get16(buf[b:]) b += 2 v.Length = xgb.Get32(buf[b:]) // 4-byte units b += 4 return v }
// PropValWindows is the same as PropValWindow, except that it returns a slice // of identifiers. Also must be 32 bit format. func PropValWindows(reply *xproto.GetPropertyReply, err error) ([]xproto.Window, error) { if err != nil { return nil, err } if reply.Format != 32 { return nil, fmt.Errorf("PropValIds: Expected format 32 but got %d", reply.Format) } ids := make([]xproto.Window, reply.ValueLen) vals := reply.Value for i := 0; len(vals) >= 4; i++ { ids[i] = xproto.Window(xgb.Get32(vals)) vals = vals[4:] } return ids, nil }
// PropValAtoms is the same as PropValAtom, except that it returns a slice // of atom names. Also must be 32 bit format. // This is a method of an XUtil struct, unlike the other 'PropVal...' functions. func PropValAtoms(xu *xgbutil.XUtil, reply *xproto.GetPropertyReply, err error) ([]string, error) { if err != nil { return nil, err } if reply.Format != 32 { return nil, fmt.Errorf("PropValAtoms: Expected format 32 but got %d", reply.Format) } ids := make([]string, reply.ValueLen) vals := reply.Value for i := 0; len(vals) >= 4; i++ { ids[i], err = AtomName(xu, xproto.Atom(xgb.Get32(vals))) if err != nil { return nil, err } vals = vals[4:] } return ids, nil }