diff options
-rw-r--r-- | nexgb/glx/glx.go | 113 | ||||
-rw-r--r-- | nexgb/randr/randr.go | 487 | ||||
-rw-r--r-- | nexgb/record/record.go | 20 | ||||
-rw-r--r-- | nexgb/render/render.go | 58 | ||||
-rw-r--r-- | nexgb/screensaver/screensaver.go | 3 | ||||
-rw-r--r-- | nexgb/xf86dri/xf86dri.go | 5 | ||||
-rw-r--r-- | nexgb/xf86vidmode/xf86vidmode.go | 27 | ||||
-rw-r--r-- | nexgb/xfixes/xfixes.go | 17 | ||||
-rw-r--r-- | nexgb/xgbgen/field.go | 15 | ||||
-rw-r--r-- | nexgb/xprint/xprint.go | 57 | ||||
-rw-r--r-- | nexgb/xproto/xproto.go | 69 | ||||
-rw-r--r-- | nexgb/xselinux/xselinux.go | 16 | ||||
-rw-r--r-- | nexgb/xv/xv.go | 44 |
13 files changed, 667 insertions, 264 deletions
diff --git a/nexgb/glx/glx.go b/nexgb/glx/glx.go index cf72d9a..0ecc3b5 100644 --- a/nexgb/glx/glx.go +++ b/nexgb/glx/glx.go @@ -3165,14 +3165,14 @@ func getClipPlaneReply(buf []byte) *GetClipPlaneReply { v := new(GetClipPlaneReply) 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 + b += 1 // padding + b += 24 // padding v.Data = make([]Float64, (int(v.Length) / 2)) @@ -4096,14 +4096,14 @@ func getDoublevReply(buf []byte) *GetDoublevReply { v := new(GetDoublevReply) 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 + b += 1 // padding + b += 4 // padding v.N = xgb.Get32(buf[b:]) @@ -5340,14 +5340,14 @@ func getMapdvReply(buf []byte) *GetMapdvReply { v := new(GetMapdvReply) 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 + b += 1 // padding + b += 4 // padding v.N = xgb.Get32(buf[b:]) @@ -7548,14 +7548,14 @@ func getTexGendvReply(buf []byte) *GetTexGendvReply { v := new(GetTexGendvReply) 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 + b += 1 // padding + b += 4 // padding v.N = xgb.Get32(buf[b:]) @@ -8654,6 +8654,103 @@ func isDirectRequest(c *xgb.Conn, Context Context) []byte { return buf } +// IsEnabledCookie is a cookie used only for IsEnabled requests. +type IsEnabledCookie struct { + *xgb.Cookie +} + +// IsEnabled sends a checked request. +// If an error occurs, it will be returned with the reply by calling IsEnabledCookie.Reply() +func IsEnabled(c *xgb.Conn, ContextTag ContextTag, Capability uint32) IsEnabledCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["GLX"]; !ok { + panic("Cannot issue request 'IsEnabled' using the uninitialized extension 'GLX'. glx.Init(connObj) must be called first.") + } + cookie := c.NewCookie(true, true) + c.NewRequest(isEnabledRequest(c, ContextTag, Capability), cookie) + return IsEnabledCookie{cookie} +} + +// IsEnabledUnchecked sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func IsEnabledUnchecked(c *xgb.Conn, ContextTag ContextTag, Capability uint32) IsEnabledCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["GLX"]; !ok { + panic("Cannot issue request 'IsEnabled' using the uninitialized extension 'GLX'. glx.Init(connObj) must be called first.") + } + cookie := c.NewCookie(false, true) + c.NewRequest(isEnabledRequest(c, ContextTag, Capability), cookie) + return IsEnabledCookie{cookie} +} + +// IsEnabledReply represents the data returned from a IsEnabled request. +type IsEnabledReply struct { + Sequence uint16 // sequence number of the request for this reply + Length uint32 // number of bytes in this reply + // padding: 1 bytes + RetVal Bool32 +} + +// Reply blocks and returns the reply data for a IsEnabled request. +func (cook IsEnabledCookie) Reply() (*IsEnabledReply, error) { + buf, err := cook.Cookie.Reply() + if err != nil { + return nil, err + } + if buf == nil { + return nil, nil + } + return isEnabledReply(buf), nil +} + +// isEnabledReply reads a byte slice into a IsEnabledReply value. +func isEnabledReply(buf []byte) *IsEnabledReply { + v := new(IsEnabledReply) + 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.RetVal = Bool32(xgb.Get32(buf[b:])) + b += 4 + + return v +} + +// Write request to wire for IsEnabled +// isEnabledRequest writes a IsEnabled request to a byte slice. +func isEnabledRequest(c *xgb.Conn, ContextTag ContextTag, Capability uint32) []byte { + size := 12 + b := 0 + buf := make([]byte, size) + + c.ExtLock.RLock() + buf[b] = c.Extensions["GLX"] + c.ExtLock.RUnlock() + b += 1 + + buf[b] = 140 // request opcode + b += 1 + + xgb.Put16(buf[b:], uint16(size/4)) // write request size in 4-byte units + b += 2 + + xgb.Put32(buf[b:], uint32(ContextTag)) + b += 4 + + xgb.Put32(buf[b:], Capability) + b += 4 + + return buf +} + // IsListCookie is a cookie used only for IsList requests. type IsListCookie struct { *xgb.Cookie diff --git a/nexgb/randr/randr.go b/nexgb/randr/randr.go index 021c011..d280e95 100644 --- a/nexgb/randr/randr.go +++ b/nexgb/randr/randr.go @@ -503,6 +503,153 @@ func ModeInfoListBytes(buf []byte, list []ModeInfo) int { return xgb.Pad(b) } +type MonitorInfo struct { + Name xproto.Atom + Primary bool + Automatic bool + NOutput uint16 + X int16 + Y int16 + Width uint16 + Height uint16 + WidthInMillimeters uint32 + HeightInMillimeters uint32 + Outputs []Output // size: xgb.Pad((int(NOutput) * 4)) +} + +// MonitorInfoRead reads a byte slice into a MonitorInfo value. +func MonitorInfoRead(buf []byte, v *MonitorInfo) int { + b := 0 + + v.Name = xproto.Atom(xgb.Get32(buf[b:])) + b += 4 + + if buf[b] == 1 { + v.Primary = true + } else { + v.Primary = false + } + b += 1 + + if buf[b] == 1 { + v.Automatic = true + } else { + v.Automatic = false + } + b += 1 + + v.NOutput = xgb.Get16(buf[b:]) + b += 2 + + v.X = int16(xgb.Get16(buf[b:])) + b += 2 + + v.Y = int16(xgb.Get16(buf[b:])) + b += 2 + + v.Width = xgb.Get16(buf[b:]) + b += 2 + + v.Height = xgb.Get16(buf[b:]) + b += 2 + + v.WidthInMillimeters = xgb.Get32(buf[b:]) + b += 4 + + v.HeightInMillimeters = xgb.Get32(buf[b:]) + b += 4 + + v.Outputs = make([]Output, v.NOutput) + for i := 0; i < int(v.NOutput); i++ { + v.Outputs[i] = Output(xgb.Get32(buf[b:])) + b += 4 + } + + return b +} + +// MonitorInfoReadList reads a byte slice into a list of MonitorInfo values. +func MonitorInfoReadList(buf []byte, dest []MonitorInfo) int { + b := 0 + for i := 0; i < len(dest); i++ { + dest[i] = MonitorInfo{} + b += MonitorInfoRead(buf[b:], &dest[i]) + } + return xgb.Pad(b) +} + +// Bytes writes a MonitorInfo value to a byte slice. +func (v MonitorInfo) Bytes() []byte { + buf := make([]byte, (24 + xgb.Pad((int(v.NOutput) * 4)))) + b := 0 + + xgb.Put32(buf[b:], uint32(v.Name)) + b += 4 + + if v.Primary { + buf[b] = 1 + } else { + buf[b] = 0 + } + b += 1 + + if v.Automatic { + buf[b] = 1 + } else { + buf[b] = 0 + } + b += 1 + + xgb.Put16(buf[b:], v.NOutput) + b += 2 + + xgb.Put16(buf[b:], uint16(v.X)) + b += 2 + + xgb.Put16(buf[b:], uint16(v.Y)) + b += 2 + + xgb.Put16(buf[b:], v.Width) + b += 2 + + xgb.Put16(buf[b:], v.Height) + b += 2 + + xgb.Put32(buf[b:], v.WidthInMillimeters) + b += 4 + + xgb.Put32(buf[b:], v.HeightInMillimeters) + b += 4 + + for i := 0; i < int(v.NOutput); i++ { + xgb.Put32(buf[b:], uint32(v.Outputs[i])) + b += 4 + } + + return buf[:b] +} + +// MonitorInfoListBytes writes a list of MonitorInfo values to a byte slice. +func MonitorInfoListBytes(buf []byte, list []MonitorInfo) int { + b := 0 + var structBytes []byte + for _, item := range list { + structBytes = item.Bytes() + copy(buf[b:], structBytes) + b += len(structBytes) + } + return xgb.Pad(b) +} + +// MonitorInfoListSize computes the size (bytes) of a list of MonitorInfo values. +func MonitorInfoListSize(list []MonitorInfo) int { + size := 0 + for _, item := range list { + size += (24 + xgb.Pad((int(item.NOutput) * 4))) + } + return size +} + const ( NotifyCrtcChange = 0 NotifyOutputChange = 1 @@ -2173,6 +2320,70 @@ func createModeRequest(c *xgb.Conn, Window xproto.Window, ModeInfo ModeInfo, Nam return buf } +// DeleteMonitorCookie is a cookie used only for DeleteMonitor requests. +type DeleteMonitorCookie struct { + *xgb.Cookie +} + +// DeleteMonitor sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func DeleteMonitor(c *xgb.Conn, Window xproto.Window, Name xproto.Atom) DeleteMonitorCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["RANDR"]; !ok { + panic("Cannot issue request 'DeleteMonitor' using the uninitialized extension 'RANDR'. randr.Init(connObj) must be called first.") + } + cookie := c.NewCookie(false, false) + c.NewRequest(deleteMonitorRequest(c, Window, Name), cookie) + return DeleteMonitorCookie{cookie} +} + +// DeleteMonitorChecked sends a checked request. +// If an error occurs, it can be retrieved using DeleteMonitorCookie.Check() +func DeleteMonitorChecked(c *xgb.Conn, Window xproto.Window, Name xproto.Atom) DeleteMonitorCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["RANDR"]; !ok { + panic("Cannot issue request 'DeleteMonitor' using the uninitialized extension 'RANDR'. randr.Init(connObj) must be called first.") + } + cookie := c.NewCookie(true, false) + c.NewRequest(deleteMonitorRequest(c, Window, Name), cookie) + return DeleteMonitorCookie{cookie} +} + +// Check returns an error if one occurred for checked requests that are not expecting a reply. +// This cannot be called for requests expecting a reply, nor for unchecked requests. +func (cook DeleteMonitorCookie) Check() error { + return cook.Cookie.Check() +} + +// Write request to wire for DeleteMonitor +// deleteMonitorRequest writes a DeleteMonitor request to a byte slice. +func deleteMonitorRequest(c *xgb.Conn, Window xproto.Window, Name xproto.Atom) []byte { + size := 12 + b := 0 + buf := make([]byte, size) + + c.ExtLock.RLock() + buf[b] = c.Extensions["RANDR"] + c.ExtLock.RUnlock() + b += 1 + + buf[b] = 44 // request opcode + b += 1 + + xgb.Put16(buf[b:], uint16(size/4)) // write request size in 4-byte units + b += 2 + + xgb.Put32(buf[b:], uint32(Window)) + b += 4 + + xgb.Put32(buf[b:], uint32(Name)) + b += 4 + + return buf +} + // DeleteOutputModeCookie is a cookie used only for DeleteOutputMode requests. type DeleteOutputModeCookie struct { *xgb.Cookie @@ -2464,11 +2675,9 @@ type GetCrtcGammaReply struct { // padding: 1 bytes Size uint16 // padding: 22 bytes - Red []uint16 // size: xgb.Pad((int(Size) * 2)) - // alignment gap to multiple of 2 + Red []uint16 // size: xgb.Pad((int(Size) * 2)) Green []uint16 // size: xgb.Pad((int(Size) * 2)) - // alignment gap to multiple of 2 - Blue []uint16 // size: xgb.Pad((int(Size) * 2)) + Blue []uint16 // size: xgb.Pad((int(Size) * 2)) } // Reply blocks and returns the reply data for a GetCrtcGamma request. @@ -2507,16 +2716,12 @@ func getCrtcGammaReply(buf []byte) *GetCrtcGammaReply { b += 2 } - b = (b + 1) & ^1 // alignment gap - v.Green = make([]uint16, v.Size) for i := 0; i < int(v.Size); i++ { v.Green[i] = xgb.Get16(buf[b:]) b += 2 } - b = (b + 1) & ^1 // alignment gap - v.Blue = make([]uint16, v.Size) for i := 0; i < int(v.Size); i++ { v.Blue[i] = xgb.Get16(buf[b:]) @@ -2694,8 +2899,7 @@ type GetCrtcInfoReply struct { NumOutputs uint16 NumPossibleOutputs uint16 Outputs []Output // size: xgb.Pad((int(NumOutputs) * 4)) - // alignment gap to multiple of 4 - Possible []Output // size: xgb.Pad((int(NumPossibleOutputs) * 4)) + Possible []Output // size: xgb.Pad((int(NumPossibleOutputs) * 4)) } // Reply blocks and returns the reply data for a GetCrtcInfo request. @@ -2760,8 +2964,6 @@ func getCrtcInfoReply(buf []byte) *GetCrtcInfoReply { b += 4 } - b = (b + 3) & ^3 // alignment gap - v.Possible = make([]Output, v.NumPossibleOutputs) for i := 0; i < int(v.NumPossibleOutputs); i++ { v.Possible[i] = Output(xgb.Get32(buf[b:])) @@ -2962,6 +3164,122 @@ func getCrtcTransformRequest(c *xgb.Conn, Crtc Crtc) []byte { return buf } +// GetMonitorsCookie is a cookie used only for GetMonitors requests. +type GetMonitorsCookie struct { + *xgb.Cookie +} + +// GetMonitors sends a checked request. +// If an error occurs, it will be returned with the reply by calling GetMonitorsCookie.Reply() +func GetMonitors(c *xgb.Conn, Window xproto.Window, GetActive bool) GetMonitorsCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["RANDR"]; !ok { + panic("Cannot issue request 'GetMonitors' using the uninitialized extension 'RANDR'. randr.Init(connObj) must be called first.") + } + cookie := c.NewCookie(true, true) + c.NewRequest(getMonitorsRequest(c, Window, GetActive), cookie) + return GetMonitorsCookie{cookie} +} + +// GetMonitorsUnchecked sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func GetMonitorsUnchecked(c *xgb.Conn, Window xproto.Window, GetActive bool) GetMonitorsCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["RANDR"]; !ok { + panic("Cannot issue request 'GetMonitors' using the uninitialized extension 'RANDR'. randr.Init(connObj) must be called first.") + } + cookie := c.NewCookie(false, true) + c.NewRequest(getMonitorsRequest(c, Window, GetActive), cookie) + return GetMonitorsCookie{cookie} +} + +// GetMonitorsReply represents the data returned from a GetMonitors request. +type GetMonitorsReply struct { + Sequence uint16 // sequence number of the request for this reply + Length uint32 // number of bytes in this reply + // padding: 1 bytes + Timestamp xproto.Timestamp + NMonitors uint32 + NOutputs uint32 + // padding: 12 bytes + Monitors []MonitorInfo // size: MonitorInfoListSize(Monitors) +} + +// Reply blocks and returns the reply data for a GetMonitors request. +func (cook GetMonitorsCookie) Reply() (*GetMonitorsReply, error) { + buf, err := cook.Cookie.Reply() + if err != nil { + return nil, err + } + if buf == nil { + return nil, nil + } + return getMonitorsReply(buf), nil +} + +// getMonitorsReply reads a byte slice into a GetMonitorsReply value. +func getMonitorsReply(buf []byte) *GetMonitorsReply { + v := new(GetMonitorsReply) + 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.Timestamp = xproto.Timestamp(xgb.Get32(buf[b:])) + b += 4 + + v.NMonitors = xgb.Get32(buf[b:]) + b += 4 + + v.NOutputs = xgb.Get32(buf[b:]) + b += 4 + + b += 12 // padding + + v.Monitors = make([]MonitorInfo, v.NMonitors) + b += MonitorInfoReadList(buf[b:], v.Monitors) + + return v +} + +// Write request to wire for GetMonitors +// getMonitorsRequest writes a GetMonitors request to a byte slice. +func getMonitorsRequest(c *xgb.Conn, Window xproto.Window, GetActive bool) []byte { + size := 12 + b := 0 + buf := make([]byte, size) + + c.ExtLock.RLock() + buf[b] = c.Extensions["RANDR"] + c.ExtLock.RUnlock() + b += 1 + + buf[b] = 42 // request opcode + b += 1 + + xgb.Put16(buf[b:], uint16(size/4)) // write request size in 4-byte units + b += 2 + + xgb.Put32(buf[b:], uint32(Window)) + b += 4 + + if GetActive { + buf[b] = 1 + } else { + buf[b] = 0 + } + b += 1 + + return buf +} + // GetOutputInfoCookie is a cookie used only for GetOutputInfo requests. type GetOutputInfoCookie struct { *xgb.Cookie @@ -3009,12 +3327,10 @@ type GetOutputInfoReply struct { NumPreferred uint16 NumClones uint16 NameLen uint16 - Crtcs []Crtc // size: xgb.Pad((int(NumCrtcs) * 4)) - // alignment gap to multiple of 4 - Modes []Mode // size: xgb.Pad((int(NumModes) * 4)) - // alignment gap to multiple of 4 - Clones []Output // size: xgb.Pad((int(NumClones) * 4)) - Name []byte // size: xgb.Pad((int(NameLen) * 1)) + Crtcs []Crtc // size: xgb.Pad((int(NumCrtcs) * 4)) + Modes []Mode // size: xgb.Pad((int(NumModes) * 4)) + Clones []Output // size: xgb.Pad((int(NumClones) * 4)) + Name []byte // size: xgb.Pad((int(NameLen) * 1)) } // Reply blocks and returns the reply data for a GetOutputInfo request. @@ -3082,16 +3398,12 @@ func getOutputInfoReply(buf []byte) *GetOutputInfoReply { b += 4 } - b = (b + 3) & ^3 // alignment gap - v.Modes = make([]Mode, v.NumModes) for i := 0; i < int(v.NumModes); i++ { v.Modes[i] = Mode(xgb.Get32(buf[b:])) b += 4 } - b = (b + 3) & ^3 // alignment gap - v.Clones = make([]Output, v.NumClones) for i := 0; i < int(v.NumClones); i++ { v.Clones[i] = Output(xgb.Get32(buf[b:])) @@ -3551,14 +3863,11 @@ type GetProviderInfoReply struct { NumAssociatedProviders uint16 NameLen uint16 // padding: 8 bytes - Crtcs []Crtc // size: xgb.Pad((int(NumCrtcs) * 4)) - // alignment gap to multiple of 4 - Outputs []Output // size: xgb.Pad((int(NumOutputs) * 4)) - // alignment gap to multiple of 4 - AssociatedProviders []Provider // size: xgb.Pad((int(NumAssociatedProviders) * 4)) - // alignment gap to multiple of 4 - AssociatedCapability []uint32 // size: xgb.Pad((int(NumAssociatedProviders) * 4)) - Name string // size: xgb.Pad((int(NameLen) * 1)) + Crtcs []Crtc // size: xgb.Pad((int(NumCrtcs) * 4)) + Outputs []Output // size: xgb.Pad((int(NumOutputs) * 4)) + AssociatedProviders []Provider // size: xgb.Pad((int(NumAssociatedProviders) * 4)) + AssociatedCapability []uint32 // size: xgb.Pad((int(NumAssociatedProviders) * 4)) + Name string // size: xgb.Pad((int(NameLen) * 1)) } // Reply blocks and returns the reply data for a GetProviderInfo request. @@ -3613,24 +3922,18 @@ func getProviderInfoReply(buf []byte) *GetProviderInfoReply { b += 4 } - b = (b + 3) & ^3 // alignment gap - v.Outputs = make([]Output, v.NumOutputs) for i := 0; i < int(v.NumOutputs); i++ { v.Outputs[i] = Output(xgb.Get32(buf[b:])) b += 4 } - b = (b + 3) & ^3 // alignment gap - v.AssociatedProviders = make([]Provider, v.NumAssociatedProviders) for i := 0; i < int(v.NumAssociatedProviders); i++ { v.AssociatedProviders[i] = Provider(xgb.Get32(buf[b:])) b += 4 } - b = (b + 3) & ^3 // alignment gap - v.AssociatedCapability = make([]uint32, v.NumAssociatedProviders) for i := 0; i < int(v.NumAssociatedProviders); i++ { v.AssociatedCapability[i] = xgb.Get32(buf[b:]) @@ -3966,8 +4269,7 @@ type GetScreenInfoReply struct { Rate uint16 NInfo uint16 // padding: 2 bytes - Sizes []ScreenSize // size: xgb.Pad((int(NSizes) * 8)) - // alignment gap to multiple of 2 + Sizes []ScreenSize // size: xgb.Pad((int(NSizes) * 8)) Rates []RefreshRates // size: RefreshRatesListSize(Rates) } @@ -4026,8 +4328,6 @@ func getScreenInfoReply(buf []byte) *GetScreenInfoReply { v.Sizes = make([]ScreenSize, v.NSizes) b += ScreenSizeReadList(buf[b:], v.Sizes) - b = (b + 1) & ^1 // alignment gap - v.Rates = make([]RefreshRates, (int(v.NInfo) - int(v.NSizes))) b += RefreshRatesReadList(buf[b:], v.Rates) @@ -4101,12 +4401,10 @@ type GetScreenResourcesReply struct { NumModes uint16 NamesLen uint16 // padding: 8 bytes - Crtcs []Crtc // size: xgb.Pad((int(NumCrtcs) * 4)) - // alignment gap to multiple of 4 - Outputs []Output // size: xgb.Pad((int(NumOutputs) * 4)) - // alignment gap to multiple of 4 - Modes []ModeInfo // size: xgb.Pad((int(NumModes) * 32)) - Names []byte // size: xgb.Pad((int(NamesLen) * 1)) + Crtcs []Crtc // size: xgb.Pad((int(NumCrtcs) * 4)) + Outputs []Output // size: xgb.Pad((int(NumOutputs) * 4)) + Modes []ModeInfo // size: xgb.Pad((int(NumModes) * 32)) + Names []byte // size: xgb.Pad((int(NamesLen) * 1)) } // Reply blocks and returns the reply data for a GetScreenResources request. @@ -4160,16 +4458,12 @@ func getScreenResourcesReply(buf []byte) *GetScreenResourcesReply { b += 4 } - b = (b + 3) & ^3 // alignment gap - v.Outputs = make([]Output, v.NumOutputs) for i := 0; i < int(v.NumOutputs); i++ { v.Outputs[i] = Output(xgb.Get32(buf[b:])) b += 4 } - b = (b + 3) & ^3 // alignment gap - v.Modes = make([]ModeInfo, v.NumModes) b += ModeInfoReadList(buf[b:], v.Modes) @@ -4247,12 +4541,10 @@ type GetScreenResourcesCurrentReply struct { NumModes uint16 NamesLen uint16 // padding: 8 bytes - Crtcs []Crtc // size: xgb.Pad((int(NumCrtcs) * 4)) - // alignment gap to multiple of 4 - Outputs []Output // size: xgb.Pad((int(NumOutputs) * 4)) - // alignment gap to multiple of 4 - Modes []ModeInfo // size: xgb.Pad((int(NumModes) * 32)) - Names []byte // size: xgb.Pad((int(NamesLen) * 1)) + Crtcs []Crtc // size: xgb.Pad((int(NumCrtcs) * 4)) + Outputs []Output // size: xgb.Pad((int(NumOutputs) * 4)) + Modes []ModeInfo // size: xgb.Pad((int(NumModes) * 32)) + Names []byte // size: xgb.Pad((int(NamesLen) * 1)) } // Reply blocks and returns the reply data for a GetScreenResourcesCurrent request. @@ -4306,16 +4598,12 @@ func getScreenResourcesCurrentReply(buf []byte) *GetScreenResourcesCurrentReply b += 4 } - b = (b + 3) & ^3 // alignment gap - v.Outputs = make([]Output, v.NumOutputs) for i := 0; i < int(v.NumOutputs); i++ { v.Outputs[i] = Output(xgb.Get32(buf[b:])) b += 4 } - b = (b + 3) & ^3 // alignment gap - v.Modes = make([]ModeInfo, v.NumModes) b += ModeInfoReadList(buf[b:], v.Modes) @@ -5254,7 +5542,7 @@ func (cook SetCrtcGammaCookie) Check() error { // Write request to wire for SetCrtcGamma // setCrtcGammaRequest writes a SetCrtcGamma request to a byte slice. func setCrtcGammaRequest(c *xgb.Conn, Crtc Crtc, Size uint16, Red []uint16, Green []uint16, Blue []uint16) []byte { - size := xgb.Pad((((((12 + xgb.Pad((int(Size) * 2))) + 2) + xgb.Pad((int(Size) * 2))) + 2) + xgb.Pad((int(Size) * 2)))) + size := xgb.Pad((((12 + xgb.Pad((int(Size) * 2))) + xgb.Pad((int(Size) * 2))) + xgb.Pad((int(Size) * 2)))) b := 0 buf := make([]byte, size) @@ -5266,7 +5554,7 @@ func setCrtcGammaRequest(c *xgb.Conn, Crtc Crtc, Size uint16, Red []uint16, Gree buf[b] = 24 // request opcode b += 1 - blen := b + xgb.Put16(buf[b:], uint16(size/4)) // write request size in 4-byte units b += 2 xgb.Put32(buf[b:], uint32(Crtc)) @@ -5282,23 +5570,17 @@ func setCrtcGammaRequest(c *xgb.Conn, Crtc Crtc, Size uint16, Red []uint16, Gree b += 2 } - b = (b + 1) & ^1 // alignment gap - for i := 0; i < int(Size); i++ { xgb.Put16(buf[b:], Green[i]) b += 2 } - b = (b + 1) & ^1 // alignment gap - for i := 0; i < int(Size); i++ { xgb.Put16(buf[b:], Blue[i]) b += 2 } - b = xgb.Pad(b) - xgb.Put16(buf[blen:], uint16(b/4)) // write request size in 4-byte units - return buf[:b] + return buf } // SetCrtcTransformCookie is a cookie used only for SetCrtcTransform requests. @@ -5385,6 +5667,73 @@ func setCrtcTransformRequest(c *xgb.Conn, Crtc Crtc, Transform render.Transform, return buf[:b] } +// SetMonitorCookie is a cookie used only for SetMonitor requests. +type SetMonitorCookie struct { + *xgb.Cookie +} + +// SetMonitor sends an unchecked request. +// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. +func SetMonitor(c *xgb.Conn, Window xproto.Window, Monitorinfo MonitorInfo) SetMonitorCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["RANDR"]; !ok { + panic("Cannot issue request 'SetMonitor' using the uninitialized extension 'RANDR'. randr.Init(connObj) must be called first.") + } + cookie := c.NewCookie(false, false) + c.NewRequest(setMonitorRequest(c, Window, Monitorinfo), cookie) + return SetMonitorCookie{cookie} +} + +// SetMonitorChecked sends a checked request. +// If an error occurs, it can be retrieved using SetMonitorCookie.Check() +func SetMonitorChecked(c *xgb.Conn, Window xproto.Window, Monitorinfo MonitorInfo) SetMonitorCookie { + c.ExtLock.RLock() + defer c.ExtLock.RUnlock() + if _, ok := c.Extensions["RANDR"]; !ok { + panic("Cannot issue request 'SetMonitor' using the uninitialized extension 'RANDR'. randr.Init(connObj) must be called first.") + } + cookie := c.NewCookie(true, false) + c.NewRequest(setMonitorRequest(c, Window, Monitorinfo), cookie) + return SetMonitorCookie{cookie} +} + +// Check returns an error if one occurred for checked requests that are not expecting a reply. +// This cannot be called for requests expecting a reply, nor for unchecked requests. +func (cook SetMonitorCookie) Check() error { + return cook.Cookie.Check() +} + +// Write request to wire for SetMonitor +// setMonitorRequest writes a SetMonitor request to a byte slice. +func setMonitorRequest(c *xgb.Conn, Window xproto.Window, Monitorinfo MonitorInfo) []byte { + size := xgb.Pad((8 + (24 + xgb.Pad((int(Monitorinfo.NOutput) * 4))))) + b := 0 + buf := make([]byte, size) + + c.ExtLock.RLock() + buf[b] = c.Extensions["RANDR"] + c.ExtLock.RUnlock() + b += 1 + + buf[b] = 43 // request opcode + b += 1 + + xgb.Put16(buf[b:], uint16(size/4)) // write request size in 4-byte units + b += 2 + + xgb.Put32(buf[b:], uint32(Window)) + b += 4 + + { + structBytes := Monitorinfo.Bytes() + copy(buf[b:], structBytes) + b += len(structBytes) + } + + return buf +} + // SetOutputPrimaryCookie is a cookie used only for SetOutputPrimary requests. type SetOutputPrimaryCookie struct { *xgb.Cookie diff --git a/nexgb/record/record.go b/nexgb/record/record.go index 5469170..1cb022b 100644 --- a/nexgb/record/record.go +++ b/nexgb/record/record.go @@ -554,7 +554,7 @@ func (cook CreateContextCookie) Check() error { // Write request to wire for CreateContext // createContextRequest writes a CreateContext request to a byte slice. func createContextRequest(c *xgb.Conn, Context Context, ElementHeader ElementHeader, NumClientSpecs uint32, NumRanges uint32, ClientSpecs []ClientSpec, Ranges []Range) []byte { - size := xgb.Pad((((20 + xgb.Pad((int(NumClientSpecs) * 4))) + 4) + xgb.Pad((int(NumRanges) * 24)))) + size := xgb.Pad(((20 + xgb.Pad((int(NumClientSpecs) * 4))) + xgb.Pad((int(NumRanges) * 24)))) b := 0 buf := make([]byte, size) @@ -566,7 +566,7 @@ func createContextRequest(c *xgb.Conn, Context Context, ElementHeader ElementHea buf[b] = 1 // request opcode b += 1 - blen := b + xgb.Put16(buf[b:], uint16(size/4)) // write request size in 4-byte units b += 2 xgb.Put32(buf[b:], uint32(Context)) @@ -588,13 +588,9 @@ func createContextRequest(c *xgb.Conn, Context Context, ElementHeader ElementHea b += 4 } - b = (b + 3) & ^3 // alignment gap - b += RangeListBytes(buf[b:], Ranges) - b = xgb.Pad(b) - xgb.Put16(buf[blen:], uint16(b/4)) // write request size in 4-byte units - return buf[:b] + return buf } // DisableContextCookie is a cookie used only for DisableContext requests. @@ -1099,7 +1095,7 @@ func (cook RegisterClientsCookie) Check() error { // Write request to wire for RegisterClients // registerClientsRequest writes a RegisterClients request to a byte slice. func registerClientsRequest(c *xgb.Conn, Context Context, ElementHeader ElementHeader, NumClientSpecs uint32, NumRanges uint32, ClientSpecs []ClientSpec, Ranges []Range) []byte { - size := xgb.Pad((((20 + xgb.Pad((int(NumClientSpecs) * 4))) + 4) + xgb.Pad((int(NumRanges) * 24)))) + size := xgb.Pad(((20 + xgb.Pad((int(NumClientSpecs) * 4))) + xgb.Pad((int(NumRanges) * 24)))) b := 0 buf := make([]byte, size) @@ -1111,7 +1107,7 @@ func registerClientsRequest(c *xgb.Conn, Context Context, ElementHeader ElementH buf[b] = 2 // request opcode b += 1 - blen := b + xgb.Put16(buf[b:], uint16(size/4)) // write request size in 4-byte units b += 2 xgb.Put32(buf[b:], uint32(Context)) @@ -1133,13 +1129,9 @@ func registerClientsRequest(c *xgb.Conn, Context Context, ElementHeader ElementH b += 4 } - b = (b + 3) & ^3 // alignment gap - b += RangeListBytes(buf[b:], Ranges) - b = xgb.Pad(b) - xgb.Put16(buf[blen:], uint16(b/4)) // write request size in 4-byte units - return buf[:b] + return buf } // UnregisterClientsCookie is a cookie used only for UnregisterClients requests. diff --git a/nexgb/render/render.go b/nexgb/render/render.go index e15bd67..01ea481 100644 --- a/nexgb/render/render.go +++ b/nexgb/render/render.go @@ -1613,7 +1613,7 @@ func (cook AddGlyphsCookie) Check() error { // Write request to wire for AddGlyphs // addGlyphsRequest writes a AddGlyphs request to a byte slice. func addGlyphsRequest(c *xgb.Conn, Glyphset Glyphset, GlyphsLen uint32, Glyphids []uint32, Glyphs []Glyphinfo, Data []byte) []byte { - size := xgb.Pad(((((12 + xgb.Pad((int(GlyphsLen) * 4))) + 4) + xgb.Pad((int(GlyphsLen) * 12))) + xgb.Pad((len(Data) * 1)))) + size := xgb.Pad((((12 + xgb.Pad((int(GlyphsLen) * 4))) + xgb.Pad((int(GlyphsLen) * 12))) + xgb.Pad((len(Data) * 1)))) b := 0 buf := make([]byte, size) @@ -1625,7 +1625,7 @@ func addGlyphsRequest(c *xgb.Conn, Glyphset Glyphset, GlyphsLen uint32, Glyphids buf[b] = 20 // request opcode b += 1 - blen := b + xgb.Put16(buf[b:], uint16(size/4)) // write request size in 4-byte units b += 2 xgb.Put32(buf[b:], uint32(Glyphset)) @@ -1639,16 +1639,12 @@ func addGlyphsRequest(c *xgb.Conn, Glyphset Glyphset, GlyphsLen uint32, Glyphids b += 4 } - b = (b + 3) & ^3 // alignment gap - b += GlyphinfoListBytes(buf[b:], Glyphs) copy(buf[b:], Data[:len(Data)]) b += int(len(Data)) - b = xgb.Pad(b) - xgb.Put16(buf[blen:], uint16(b/4)) // write request size in 4-byte units - return buf[:b] + return buf } // AddTrapsCookie is a cookie used only for AddTraps requests. @@ -1760,7 +1756,7 @@ func (cook ChangePictureCookie) Check() error { // Write request to wire for ChangePicture // changePictureRequest writes a ChangePicture request to a byte slice. func changePictureRequest(c *xgb.Conn, Picture Picture, ValueMask uint32, ValueList []uint32) []byte { - size := xgb.Pad((8 + (4 + xgb.Pad((4 * xgb.PopCount(int(ValueMask))))))) + size := xgb.Pad((12 + xgb.Pad((4 * xgb.PopCount(int(ValueMask)))))) b := 0 buf := make([]byte, size) @@ -1780,6 +1776,7 @@ func changePictureRequest(c *xgb.Conn, Picture Picture, ValueMask uint32, ValueL xgb.Put32(buf[b:], ValueMask) b += 4 + for i := 0; i < xgb.PopCount(int(ValueMask)); i++ { xgb.Put32(buf[b:], ValueList[i]) b += 4 @@ -2240,7 +2237,7 @@ func (cook CreateConicalGradientCookie) Check() error { // Write request to wire for CreateConicalGradient // createConicalGradientRequest writes a CreateConicalGradient request to a byte slice. func createConicalGradientRequest(c *xgb.Conn, Picture Picture, Center Pointfix, Angle Fixed, NumStops uint32, Stops []Fixed, Colors []Color) []byte { - size := xgb.Pad((((24 + xgb.Pad((int(NumStops) * 4))) + 4) + xgb.Pad((int(NumStops) * 8)))) + size := xgb.Pad(((24 + xgb.Pad((int(NumStops) * 4))) + xgb.Pad((int(NumStops) * 8)))) b := 0 buf := make([]byte, size) @@ -2252,7 +2249,7 @@ func createConicalGradientRequest(c *xgb.Conn, Picture Picture, Center Pointfix, buf[b] = 36 // request opcode b += 1 - blen := b + xgb.Put16(buf[b:], uint16(size/4)) // write request size in 4-byte units b += 2 xgb.Put32(buf[b:], uint32(Picture)) @@ -2275,13 +2272,9 @@ func createConicalGradientRequest(c *xgb.Conn, Picture Picture, Center Pointfix, b += 4 } - b = (b + 3) & ^3 // alignment gap - b += ColorListBytes(buf[b:], Colors) - b = xgb.Pad(b) - xgb.Put16(buf[blen:], uint16(b/4)) // write request size in 4-byte units - return buf[:b] + return buf } // CreateCursorCookie is a cookie used only for CreateCursor requests. @@ -2458,7 +2451,7 @@ func (cook CreateLinearGradientCookie) Check() error { // Write request to wire for CreateLinearGradient // createLinearGradientRequest writes a CreateLinearGradient request to a byte slice. func createLinearGradientRequest(c *xgb.Conn, Picture Picture, P1 Pointfix, P2 Pointfix, NumStops uint32, Stops []Fixed, Colors []Color) []byte { - size := xgb.Pad((((28 + xgb.Pad((int(NumStops) * 4))) + 4) + xgb.Pad((int(NumStops) * 8)))) + size := xgb.Pad(((28 + xgb.Pad((int(NumStops) * 4))) + xgb.Pad((int(NumStops) * 8)))) b := 0 buf := make([]byte, size) @@ -2470,7 +2463,7 @@ func createLinearGradientRequest(c *xgb.Conn, Picture Picture, P1 Pointfix, P2 P buf[b] = 34 // request opcode b += 1 - blen := b + xgb.Put16(buf[b:], uint16(size/4)) // write request size in 4-byte units b += 2 xgb.Put32(buf[b:], uint32(Picture)) @@ -2496,13 +2489,9 @@ func createLinearGradientRequest(c *xgb.Conn, Picture Picture, P1 Pointfix, P2 P b += 4 } - b = (b + 3) & ^3 // alignment gap - b += ColorListBytes(buf[b:], Colors) - b = xgb.Pad(b) - xgb.Put16(buf[blen:], uint16(b/4)) // write request size in 4-byte units - return buf[:b] + return buf } // CreatePictureCookie is a cookie used only for CreatePicture requests. @@ -2545,7 +2534,7 @@ func (cook CreatePictureCookie) Check() error { // Write request to wire for CreatePicture // createPictureRequest writes a CreatePicture request to a byte slice. func createPictureRequest(c *xgb.Conn, Pid Picture, Drawable xproto.Drawable, Format Pictformat, ValueMask uint32, ValueList []uint32) []byte { - size := xgb.Pad((16 + (4 + xgb.Pad((4 * xgb.PopCount(int(ValueMask))))))) + size := xgb.Pad((20 + xgb.Pad((4 * xgb.PopCount(int(ValueMask)))))) b := 0 buf := make([]byte, size) @@ -2571,6 +2560,7 @@ func createPictureRequest(c *xgb.Conn, Pid Picture, Drawable xproto.Drawable, Fo xgb.Put32(buf[b:], ValueMask) b += 4 + for i := 0; i < xgb.PopCount(int(ValueMask)); i++ { xgb.Put32(buf[b:], ValueList[i]) b += 4 @@ -2620,7 +2610,7 @@ func (cook CreateRadialGradientCookie) Check() error { // Write request to wire for CreateRadialGradient // createRadialGradientRequest writes a CreateRadialGradient request to a byte slice. func createRadialGradientRequest(c *xgb.Conn, Picture Picture, Inner Pointfix, Outer Pointfix, InnerRadius Fixed, OuterRadius Fixed, NumStops uint32, Stops []Fixed, Colors []Color) []byte { - size := xgb.Pad((((36 + xgb.Pad((int(NumStops) * 4))) + 4) + xgb.Pad((int(NumStops) * 8)))) + size := xgb.Pad(((36 + xgb.Pad((int(NumStops) * 4))) + xgb.Pad((int(NumStops) * 8)))) b := 0 buf := make([]byte, size) @@ -2632,7 +2622,7 @@ func createRadialGradientRequest(c *xgb.Conn, Picture Picture, Inner Pointfix, O buf[b] = 35 // request opcode b += 1 - blen := b + xgb.Put16(buf[b:], uint16(size/4)) // write request size in 4-byte units b += 2 xgb.Put32(buf[b:], uint32(Picture)) @@ -2664,13 +2654,9 @@ func createRadialGradientRequest(c *xgb.Conn, Picture Picture, Inner Pointfix, O b += 4 } - b = (b + 3) & ^3 // alignment gap - b += ColorListBytes(buf[b:], Colors) - b = xgb.Pad(b) - xgb.Put16(buf[blen:], uint16(b/4)) // write request size in 4-byte units - return buf[:b] + return buf } // CreateSolidFillCookie is a cookie used only for CreateSolidFill requests. @@ -3156,11 +3142,9 @@ type QueryPictFormatsReply struct { NumVisuals uint32 NumSubpixel uint32 // padding: 4 bytes - Formats []Pictforminfo // size: xgb.Pad((int(NumFormats) * 28)) - // alignment gap to multiple of 4 - Screens []Pictscreen // size: PictscreenListSize(Screens) - // alignment gap to multiple of 4 - Subpixels []uint32 // size: xgb.Pad((int(NumSubpixel) * 4)) + Formats []Pictforminfo // size: xgb.Pad((int(NumFormats) * 28)) + Screens []Pictscreen // size: PictscreenListSize(Screens) + Subpixels []uint32 // size: xgb.Pad((int(NumSubpixel) * 4)) } // Reply blocks and returns the reply data for a QueryPictFormats request. @@ -3208,13 +3192,9 @@ func queryPictFormatsReply(buf []byte) *QueryPictFormatsReply { v.Formats = make([]Pictforminfo, v.NumFormats) b += PictforminfoReadList(buf[b:], v.Formats) - b = (b + 3) & ^3 // alignment gap - v.Screens = make([]Pictscreen, v.NumScreens) b += PictscreenReadList(buf[b:], v.Screens) - b = (b + 3) & ^3 // alignment gap - v.Subpixels = make([]uint32, v.NumSubpixel) for i := 0; i < int(v.NumSubpixel); i++ { v.Subpixels[i] = xgb.Get32(buf[b:]) diff --git a/nexgb/screensaver/screensaver.go b/nexgb/screensaver/screensaver.go index 418576c..0e9511f 100644 --- a/nexgb/screensaver/screensaver.go +++ b/nexgb/screensaver/screensaver.go @@ -513,7 +513,7 @@ func (cook SetAttributesCookie) Check() error { // Write request to wire for SetAttributes // setAttributesRequest writes a SetAttributes request to a byte slice. func setAttributesRequest(c *xgb.Conn, Drawable xproto.Drawable, X int16, Y int16, Width uint16, Height uint16, BorderWidth uint16, Class byte, Depth byte, Visual xproto.Visualid, ValueMask uint32, ValueList []uint32) []byte { - size := xgb.Pad((24 + (4 + xgb.Pad((4 * xgb.PopCount(int(ValueMask))))))) + size := xgb.Pad((28 + xgb.Pad((4 * xgb.PopCount(int(ValueMask)))))) b := 0 buf := make([]byte, size) @@ -557,6 +557,7 @@ func setAttributesRequest(c *xgb.Conn, Drawable xproto.Drawable, X int16, Y int1 xgb.Put32(buf[b:], ValueMask) b += 4 + for i := 0; i < xgb.PopCount(int(ValueMask)); i++ { xgb.Put32(buf[b:], ValueList[i]) b += 4 diff --git a/nexgb/xf86dri/xf86dri.go b/nexgb/xf86dri/xf86dri.go index 51c9322..06f49a0 100644 --- a/nexgb/xf86dri/xf86dri.go +++ b/nexgb/xf86dri/xf86dri.go @@ -896,8 +896,7 @@ type GetDrawableInfoReply struct { BackY int16 NumBackClipRects uint32 ClipRects []DrmClipRect // size: xgb.Pad((int(NumClipRects) * 8)) - // alignment gap to multiple of 4 - BackClipRects []DrmClipRect // size: xgb.Pad((int(NumBackClipRects) * 8)) + BackClipRects []DrmClipRect // size: xgb.Pad((int(NumBackClipRects) * 8)) } // Reply blocks and returns the reply data for a GetDrawableInfo request. @@ -958,8 +957,6 @@ func getDrawableInfoReply(buf []byte) *GetDrawableInfoReply { v.ClipRects = make([]DrmClipRect, v.NumClipRects) b += DrmClipRectReadList(buf[b:], v.ClipRects) - b = (b + 3) & ^3 // alignment gap - v.BackClipRects = make([]DrmClipRect, v.NumBackClipRects) b += DrmClipRectReadList(buf[b:], v.BackClipRects) diff --git a/nexgb/xf86vidmode/xf86vidmode.go b/nexgb/xf86vidmode/xf86vidmode.go index 2829fd6..22e236f 100644 --- a/nexgb/xf86vidmode/xf86vidmode.go +++ b/nexgb/xf86vidmode/xf86vidmode.go @@ -1152,11 +1152,9 @@ type GetGammaRampReply struct { // padding: 1 bytes Size uint16 // padding: 22 bytes - Red []uint16 // size: xgb.Pad((((int(Size) + 1) & -2) * 2)) - // alignment gap to multiple of 2 + Red []uint16 // size: xgb.Pad((((int(Size) + 1) & -2) * 2)) Green []uint16 // size: xgb.Pad((((int(Size) + 1) & -2) * 2)) - // alignment gap to multiple of 2 - Blue []uint16 // size: xgb.Pad((((int(Size) + 1) & -2) * 2)) + Blue []uint16 // size: xgb.Pad((((int(Size) + 1) & -2) * 2)) } // Reply blocks and returns the reply data for a GetGammaRamp request. @@ -1195,16 +1193,12 @@ func getGammaRampReply(buf []byte) *GetGammaRampReply { b += 2 } - b = (b + 1) & ^1 // alignment gap - v.Green = make([]uint16, ((int(v.Size) + 1) & -2)) for i := 0; i < int(((int(v.Size) + 1) & -2)); i++ { v.Green[i] = xgb.Get16(buf[b:]) b += 2 } - b = (b + 1) & ^1 // alignment gap - v.Blue = make([]uint16, ((int(v.Size) + 1) & -2)) for i := 0; i < int(((int(v.Size) + 1) & -2)); i++ { v.Blue[i] = xgb.Get16(buf[b:]) @@ -1532,8 +1526,7 @@ type GetMonitorReply struct { NumHsync byte NumVsync byte // padding: 20 bytes - Hsync []Syncrange // size: xgb.Pad((int(NumHsync) * 4)) - // alignment gap to multiple of 4 + Hsync []Syncrange // size: xgb.Pad((int(NumHsync) * 4)) Vsync []Syncrange // size: xgb.Pad((int(NumVsync) * 4)) Vendor string // size: xgb.Pad((int(VendorLength) * 1)) AlignmentPad []byte // size: xgb.Pad(((((int(VendorLength) + 3) & -4) - int(VendorLength)) * 1)) @@ -1585,8 +1578,6 @@ func getMonitorReply(buf []byte) *GetMonitorReply { b += 4 } - b = (b + 3) & ^3 // alignment gap - v.Vsync = make([]Syncrange, v.NumVsync) for i := 0; i < int(v.NumVsync); i++ { v.Vsync[i] = Syncrange(xgb.Get32(buf[b:])) @@ -2280,7 +2271,7 @@ func (cook SetGammaRampCookie) Check() error { // Write request to wire for SetGammaRamp // setGammaRampRequest writes a SetGammaRamp request to a byte slice. func setGammaRampRequest(c *xgb.Conn, Screen uint16, Size uint16, Red []uint16, Green []uint16, Blue []uint16) []byte { - size := xgb.Pad((((((8 + xgb.Pad((((int(Size) + 1) & -2) * 2))) + 2) + xgb.Pad((((int(Size) + 1) & -2) * 2))) + 2) + xgb.Pad((((int(Size) + 1) & -2) * 2)))) + size := xgb.Pad((((8 + xgb.Pad((((int(Size) + 1) & -2) * 2))) + xgb.Pad((((int(Size) + 1) & -2) * 2))) + xgb.Pad((((int(Size) + 1) & -2) * 2)))) b := 0 buf := make([]byte, size) @@ -2292,7 +2283,7 @@ func setGammaRampRequest(c *xgb.Conn, Screen uint16, Size uint16, Red []uint16, buf[b] = 18 // request opcode b += 1 - blen := b + xgb.Put16(buf[b:], uint16(size/4)) // write request size in 4-byte units b += 2 xgb.Put16(buf[b:], Screen) @@ -2306,23 +2297,17 @@ func setGammaRampRequest(c *xgb.Conn, Screen uint16, Size uint16, Red []uint16, b += 2 } - b = (b + 1) & ^1 // alignment gap - for i := 0; i < int(((int(Size) + 1) & -2)); i++ { xgb.Put16(buf[b:], Green[i]) b += 2 } - b = (b + 1) & ^1 // alignment gap - for i := 0; i < int(((int(Size) + 1) & -2)); i++ { xgb.Put16(buf[b:], Blue[i]) b += 2 } - b = xgb.Pad(b) - xgb.Put16(buf[blen:], uint16(b/4)) // write request size in 4-byte units - return buf[:b] + return buf } // SetViewPortCookie is a cookie used only for SetViewPort requests. diff --git a/nexgb/xfixes/xfixes.go b/nexgb/xfixes/xfixes.go index 0f9e4b0..440c3fd 100644 --- a/nexgb/xfixes/xfixes.go +++ b/nexgb/xfixes/xfixes.go @@ -1524,9 +1524,8 @@ type GetCursorImageAndNameReply struct { CursorAtom xproto.Atom Nbytes uint16 // padding: 2 bytes - Name string // size: xgb.Pad((int(Nbytes) * 1)) - // alignment gap to multiple of 4 CursorImage []uint32 // size: xgb.Pad(((int(Width) * int(Height)) * 4)) + Name string // size: xgb.Pad((int(Nbytes) * 1)) } // Reply blocks and returns the reply data for a GetCursorImageAndName request. @@ -1583,6 +1582,12 @@ func getCursorImageAndNameReply(buf []byte) *GetCursorImageAndNameReply { b += 2 // padding + v.CursorImage = make([]uint32, (int(v.Width) * int(v.Height))) + for i := 0; i < int((int(v.Width) * int(v.Height))); i++ { + v.CursorImage[i] = xgb.Get32(buf[b:]) + b += 4 + } + { byteString := make([]byte, v.Nbytes) copy(byteString[:v.Nbytes], buf[b:]) @@ -1590,14 +1595,6 @@ func getCursorImageAndNameReply(buf []byte) *GetCursorImageAndNameReply { b += int(v.Nbytes) } - b = (b + 3) & ^3 // alignment gap - - v.CursorImage = make([]uint32, (int(v.Width) * int(v.Height))) - for i := 0; i < int((int(v.Width) * int(v.Height))); i++ { - v.CursorImage[i] = xgb.Get32(buf[b:]) - b += 4 - } - return v } diff --git a/nexgb/xgbgen/field.go b/nexgb/xgbgen/field.go index 58f54c8..d6957b7 100644 --- a/nexgb/xgbgen/field.go +++ b/nexgb/xgbgen/field.go @@ -76,7 +76,7 @@ func (p *PadField) Size() Size { type RequiredStartAlign struct { } -func (f *RequiredStartAlign) Initialize(p *Protocol) { } +func (f *RequiredStartAlign) Initialize(p *Protocol) {} func (f *RequiredStartAlign) SrcName() string { panic("illegal to take source name of a required_start_align field") @@ -94,10 +94,10 @@ func (f *RequiredStartAlign) Size() Size { return newFixedSize(0, true) } -func (f *RequiredStartAlign) Define(c *Context) { } +func (f *RequiredStartAlign) Define(c *Context) {} -func (f *RequiredStartAlign) Read(c *Context, prefix string) { } -func (f *RequiredStartAlign) Write(c *Context, prefix string) { } +func (f *RequiredStartAlign) Read(c *Context, prefix string) {} +func (f *RequiredStartAlign) Write(c *Context, prefix string) {} // SingleField represents most of the fields in an XML protocol description. // It corresponds to any single value. @@ -317,9 +317,9 @@ func (f *ValueField) Initialize(p *Protocol) { // SwitchField represents a 'switch' element in the XML protocol description // file. // Currently we translate this to a slice of uint32 and let the user sort -// through it. +// through it. type SwitchField struct { - xmlName string + xmlName string Name string MaskName string Expr Expression @@ -342,6 +342,7 @@ func (f *SwitchField) Size() Size { // TODO: size expression used here is not correct unless every element of // the switch is 32 bit long. This assumption holds for xproto but may not // hold for other protocols (xkb?) + listSize := newExpressionSize(&Function{ Name: "xgb.Pad", Expr: &BinaryOp{ @@ -357,7 +358,7 @@ func (f *SwitchField) Size() Size { }, }, }, true) - + return listSize } diff --git a/nexgb/xprint/xprint.go b/nexgb/xprint/xprint.go index d692aed..330003d 100644 --- a/nexgb/xprint/xprint.go +++ b/nexgb/xprint/xprint.go @@ -317,10 +317,12 @@ func NewPcontextId(c *xgb.Conn) (Pcontext, error) { } type Printer struct { - NameLen uint32 - Name []String8 // size: xgb.Pad((int(NameLen) * 1)) + NameLen uint32 + Name []String8 // size: xgb.Pad((int(NameLen) * 1)) + // alignment gap to multiple of 4 DescLen uint32 Description []String8 // size: xgb.Pad((int(DescLen) * 1)) + // alignment gap to multiple of 4 } // PrinterRead reads a byte slice into a Printer value. @@ -336,6 +338,8 @@ func PrinterRead(buf []byte, v *Printer) int { b += 1 } + b = (b + 3) & ^3 // alignment gap + v.DescLen = xgb.Get32(buf[b:]) b += 4 @@ -345,6 +349,8 @@ func PrinterRead(buf []byte, v *Printer) int { b += 1 } + b = (b + 3) & ^3 // alignment gap + return b } @@ -360,7 +366,7 @@ func PrinterReadList(buf []byte, dest []Printer) int { // Bytes writes a Printer value to a byte slice. func (v Printer) Bytes() []byte { - buf := make([]byte, (((4 + xgb.Pad((int(v.NameLen) * 1))) + 4) + xgb.Pad((int(v.DescLen) * 1)))) + buf := make([]byte, (((((4 + xgb.Pad((int(v.NameLen) * 1))) + 4) + 4) + xgb.Pad((int(v.DescLen) * 1))) + 4)) b := 0 xgb.Put32(buf[b:], v.NameLen) @@ -371,6 +377,8 @@ func (v Printer) Bytes() []byte { b += 1 } + b = (b + 3) & ^3 // alignment gap + xgb.Put32(buf[b:], v.DescLen) b += 4 @@ -379,6 +387,8 @@ func (v Printer) Bytes() []byte { b += 1 } + b = (b + 3) & ^3 // alignment gap + return buf[:b] } @@ -398,7 +408,7 @@ func PrinterListBytes(buf []byte, list []Printer) int { func PrinterListSize(list []Printer) int { size := 0 for _, item := range list { - size += (((4 + xgb.Pad((int(item.NameLen) * 1))) + 4) + xgb.Pad((int(item.DescLen) * 1))) + size += (((((4 + xgb.Pad((int(item.NameLen) * 1))) + 4) + 4) + xgb.Pad((int(item.DescLen) * 1))) + 4) } return size } @@ -1644,9 +1654,7 @@ type PrintInputSelectedReply struct { Length uint32 // number of bytes in this reply // padding: 1 bytes EventMask uint32 - EventList []uint32 AllEventsMask uint32 - AllEventsList []uint32 } // Reply blocks and returns the reply data for a PrintInputSelected request. @@ -1677,23 +1685,9 @@ func printInputSelectedReply(buf []byte) *PrintInputSelectedReply { v.EventMask = xgb.Get32(buf[b:]) b += 4 - v.EventList = make([]uint32, xgb.PopCount(int(v.EventMask))) - for i := 0; i < xgb.PopCount(int(v.EventMask)); i++ { - v.EventList[i] = xgb.Get32(buf[b:]) - b += 4 - } - b = xgb.Pad(b) - v.AllEventsMask = xgb.Get32(buf[b:]) b += 4 - v.AllEventsList = make([]uint32, xgb.PopCount(int(v.AllEventsMask))) - for i := 0; i < xgb.PopCount(int(v.AllEventsMask)); i++ { - v.AllEventsList[i] = xgb.Get32(buf[b:]) - b += 4 - } - b = xgb.Pad(b) - return v } @@ -1761,7 +1755,7 @@ func (cook PrintPutDocumentDataCookie) Check() error { // Write request to wire for PrintPutDocumentData // printPutDocumentDataRequest writes a PrintPutDocumentData request to a byte slice. func printPutDocumentDataRequest(c *xgb.Conn, Drawable xproto.Drawable, LenData uint32, LenFmt uint16, LenOptions uint16, Data []byte, DocFormat []String8, Options []String8) []byte { - size := xgb.Pad((((16 + xgb.Pad((int(LenData) * 1))) + xgb.Pad((len(DocFormat) * 1))) + xgb.Pad((len(Options) * 1)))) + size := xgb.Pad((((16 + xgb.Pad((int(LenData) * 1))) + xgb.Pad((int(LenFmt) * 1))) + xgb.Pad((int(LenOptions) * 1)))) b := 0 buf := make([]byte, size) @@ -1791,12 +1785,12 @@ func printPutDocumentDataRequest(c *xgb.Conn, Drawable xproto.Drawable, LenData copy(buf[b:], Data[:LenData]) b += int(LenData) - for i := 0; i < int(len(DocFormat)); i++ { + for i := 0; i < int(LenFmt); i++ { buf[b] = byte(DocFormat[i]) b += 1 } - for i := 0; i < int(len(Options)); i++ { + for i := 0; i < int(LenOptions); i++ { buf[b] = byte(Options[i]) b += 1 } @@ -2065,27 +2059,27 @@ type PrintSelectInputCookie struct { // PrintSelectInput sends an unchecked request. // If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. -func PrintSelectInput(c *xgb.Conn, Context Pcontext, EventMask uint32, EventList []uint32) PrintSelectInputCookie { +func PrintSelectInput(c *xgb.Conn, Context Pcontext, EventMask uint32) PrintSelectInputCookie { c.ExtLock.RLock() defer c.ExtLock.RUnlock() if _, ok := c.Extensions["XpExtension"]; !ok { panic("Cannot issue request 'PrintSelectInput' using the uninitialized extension 'XpExtension'. xprint.Init(connObj) must be called first.") } cookie := c.NewCookie(false, false) - c.NewRequest(printSelectInputRequest(c, Context, EventMask, EventList), cookie) + c.NewRequest(printSelectInputRequest(c, Context, EventMask), cookie) return PrintSelectInputCookie{cookie} } // PrintSelectInputChecked sends a checked request. // If an error occurs, it can be retrieved using PrintSelectInputCookie.Check() -func PrintSelectInputChecked(c *xgb.Conn, Context Pcontext, EventMask uint32, EventList []uint32) PrintSelectInputCookie { +func PrintSelectInputChecked(c *xgb.Conn, Context Pcontext, EventMask uint32) PrintSelectInputCookie { c.ExtLock.RLock() defer c.ExtLock.RUnlock() if _, ok := c.Extensions["XpExtension"]; !ok { panic("Cannot issue request 'PrintSelectInput' using the uninitialized extension 'XpExtension'. xprint.Init(connObj) must be called first.") } cookie := c.NewCookie(true, false) - c.NewRequest(printSelectInputRequest(c, Context, EventMask, EventList), cookie) + c.NewRequest(printSelectInputRequest(c, Context, EventMask), cookie) return PrintSelectInputCookie{cookie} } @@ -2097,8 +2091,8 @@ func (cook PrintSelectInputCookie) Check() error { // Write request to wire for PrintSelectInput // printSelectInputRequest writes a PrintSelectInput request to a byte slice. -func printSelectInputRequest(c *xgb.Conn, Context Pcontext, EventMask uint32, EventList []uint32) []byte { - size := xgb.Pad((8 + (4 + xgb.Pad((4 * xgb.PopCount(int(EventMask))))))) +func printSelectInputRequest(c *xgb.Conn, Context Pcontext, EventMask uint32) []byte { + size := 12 b := 0 buf := make([]byte, size) @@ -2118,11 +2112,6 @@ func printSelectInputRequest(c *xgb.Conn, Context Pcontext, EventMask uint32, Ev xgb.Put32(buf[b:], EventMask) b += 4 - for i := 0; i < xgb.PopCount(int(EventMask)); i++ { - xgb.Put32(buf[b:], EventList[i]) - b += 4 - } - b = xgb.Pad(b) return buf } diff --git a/nexgb/xproto/xproto.go b/nexgb/xproto/xproto.go index 716c49b..237f3cb 100644 --- a/nexgb/xproto/xproto.go +++ b/nexgb/xproto/xproto.go @@ -343,6 +343,8 @@ const ( BlankingDefault = 2 ) +type Bool32 uint32 + type Button byte const ( @@ -1204,6 +1206,10 @@ func NewColormapId(c *xgb.Conn) (Colormap, error) { return Colormap(id), nil } +const ( + ColormapNone = 0 +) + // BadColormap is the error number for a BadColormap. const BadColormap = 12 @@ -1243,10 +1249,6 @@ func init() { } const ( - ColormapNone = 0 -) - -const ( ColormapAllocNone = 0 ColormapAllocAll = 1 ) @@ -2474,6 +2476,10 @@ func NewFontId(c *xgb.Conn) (Font, error) { return Font(id), nil } +const ( + FontNone = 0 +) + // BadFont is the error number for a BadFont. const BadFont = 7 @@ -2513,10 +2519,6 @@ func init() { } const ( - FontNone = 0 -) - -const ( FontDrawLeftToRight = 0 FontDrawRightToLeft = 1 ) @@ -3046,6 +3048,7 @@ type Host struct { // padding: 1 bytes AddressLen uint16 Address []byte // size: xgb.Pad((int(AddressLen) * 1)) + // alignment gap to multiple of 4 } // HostRead reads a byte slice into a Host value. @@ -3064,6 +3067,8 @@ func HostRead(buf []byte, v *Host) int { copy(v.Address[:v.AddressLen], buf[b:]) b += int(v.AddressLen) + b = (b + 3) & ^3 // alignment gap + return b } @@ -3079,7 +3084,7 @@ func HostReadList(buf []byte, dest []Host) int { // Bytes writes a Host value to a byte slice. func (v Host) Bytes() []byte { - buf := make([]byte, (4 + xgb.Pad((int(v.AddressLen) * 1)))) + buf := make([]byte, ((4 + xgb.Pad((int(v.AddressLen) * 1))) + 4)) b := 0 buf[b] = v.Family @@ -3093,6 +3098,8 @@ func (v Host) Bytes() []byte { copy(buf[b:], v.Address[:v.AddressLen]) b += int(v.AddressLen) + b = (b + 3) & ^3 // alignment gap + return buf[:b] } @@ -3112,7 +3119,7 @@ func HostListBytes(buf []byte, list []Host) int { func HostListSize(list []Host) int { size := 0 for _, item := range list { - size += (4 + xgb.Pad((int(item.AddressLen) * 1))) + size += ((4 + xgb.Pad((int(item.AddressLen) * 1))) + 4) } return size } @@ -3445,6 +3452,8 @@ func init() { type Keycode byte +type Keycode32 uint32 + // KeymapNotify is the event number for a KeymapNotifyEvent. const KeymapNotify = 11 @@ -5568,9 +5577,8 @@ type SetupInfo struct { // padding: 4 bytes Vendor string // size: xgb.Pad((int(VendorLen) * 1)) // alignment gap to multiple of 4 - PixmapFormats []Format // size: xgb.Pad((int(PixmapFormatsLen) * 8)) - // alignment gap to multiple of 4 - Roots []ScreenInfo // size: ScreenInfoListSize(Roots) + PixmapFormats []Format // size: xgb.Pad((int(PixmapFormatsLen) * 8)) + Roots []ScreenInfo // size: ScreenInfoListSize(Roots) } // SetupInfoRead reads a byte slice into a SetupInfo value. @@ -5647,8 +5655,6 @@ func SetupInfoRead(buf []byte, v *SetupInfo) int { v.PixmapFormats = make([]Format, v.PixmapFormatsLen) b += FormatReadList(buf[b:], v.PixmapFormats) - b = (b + 3) & ^3 // alignment gap - v.Roots = make([]ScreenInfo, v.RootsLen) b += ScreenInfoReadList(buf[b:], v.Roots) @@ -5667,7 +5673,7 @@ func SetupInfoReadList(buf []byte, dest []SetupInfo) int { // Bytes writes a SetupInfo value to a byte slice. func (v SetupInfo) Bytes() []byte { - buf := make([]byte, (((((40 + xgb.Pad((int(v.VendorLen) * 1))) + 4) + xgb.Pad((int(v.PixmapFormatsLen) * 8))) + 4) + ScreenInfoListSize(v.Roots))) + buf := make([]byte, ((((40 + xgb.Pad((int(v.VendorLen) * 1))) + 4) + xgb.Pad((int(v.PixmapFormatsLen) * 8))) + ScreenInfoListSize(v.Roots))) b := 0 buf[b] = v.Status @@ -5735,8 +5741,6 @@ func (v SetupInfo) Bytes() []byte { b += FormatListBytes(buf[b:], v.PixmapFormats) - b = (b + 3) & ^3 // alignment gap - b += ScreenInfoListBytes(buf[b:], v.Roots) return buf[:b] @@ -5758,7 +5762,7 @@ func SetupInfoListBytes(buf []byte, list []SetupInfo) int { func SetupInfoListSize(list []SetupInfo) int { size := 0 for _, item := range list { - size += (((((40 + xgb.Pad((int(item.VendorLen) * 1))) + 4) + xgb.Pad((int(item.PixmapFormatsLen) * 8))) + 4) + ScreenInfoListSize(item.Roots)) + size += ((((40 + xgb.Pad((int(item.VendorLen) * 1))) + 4) + xgb.Pad((int(item.PixmapFormatsLen) * 8))) + ScreenInfoListSize(item.Roots)) } return size } @@ -6588,8 +6592,7 @@ type AllocColorCellsReply struct { MasksLen uint16 // padding: 20 bytes Pixels []uint32 // size: xgb.Pad((int(PixelsLen) * 4)) - // alignment gap to multiple of 4 - Masks []uint32 // size: xgb.Pad((int(MasksLen) * 4)) + Masks []uint32 // size: xgb.Pad((int(MasksLen) * 4)) } // Reply blocks and returns the reply data for a AllocColorCells request. @@ -6631,8 +6634,6 @@ func allocColorCellsReply(buf []byte) *AllocColorCellsReply { b += 4 } - b = (b + 3) & ^3 // alignment gap - v.Masks = make([]uint32, v.MasksLen) for i := 0; i < int(v.MasksLen); i++ { v.Masks[i] = xgb.Get32(buf[b:]) @@ -7091,7 +7092,7 @@ func (cook ChangeGCCookie) Check() error { // Write request to wire for ChangeGC // changeGCRequest writes a ChangeGC request to a byte slice. func changeGCRequest(c *xgb.Conn, Gc Gcontext, ValueMask uint32, ValueList []uint32) []byte { - size := xgb.Pad((8 + (4 + xgb.Pad((4 * xgb.PopCount(int(ValueMask))))))) + size := xgb.Pad((12 + xgb.Pad((4 * xgb.PopCount(int(ValueMask)))))) b := 0 buf := make([]byte, size) @@ -7108,6 +7109,7 @@ func changeGCRequest(c *xgb.Conn, Gc Gcontext, ValueMask uint32, ValueList []uin xgb.Put32(buf[b:], ValueMask) b += 4 + for i := 0; i < xgb.PopCount(int(ValueMask)); i++ { xgb.Put32(buf[b:], ValueList[i]) b += 4 @@ -7204,7 +7206,7 @@ func (cook ChangeKeyboardControlCookie) Check() error { // Write request to wire for ChangeKeyboardControl // changeKeyboardControlRequest writes a ChangeKeyboardControl request to a byte slice. func changeKeyboardControlRequest(c *xgb.Conn, ValueMask uint32, ValueList []uint32) []byte { - size := xgb.Pad((4 + (4 + xgb.Pad((4 * xgb.PopCount(int(ValueMask))))))) + size := xgb.Pad((8 + xgb.Pad((4 * xgb.PopCount(int(ValueMask)))))) b := 0 buf := make([]byte, size) @@ -7218,6 +7220,7 @@ func changeKeyboardControlRequest(c *xgb.Conn, ValueMask uint32, ValueList []uin xgb.Put32(buf[b:], ValueMask) b += 4 + for i := 0; i < xgb.PopCount(int(ValueMask)); i++ { xgb.Put32(buf[b:], ValueList[i]) b += 4 @@ -7499,7 +7502,7 @@ func (cook ChangeWindowAttributesCookie) Check() error { // Write request to wire for ChangeWindowAttributes // changeWindowAttributesRequest writes a ChangeWindowAttributes request to a byte slice. func changeWindowAttributesRequest(c *xgb.Conn, Window Window, ValueMask uint32, ValueList []uint32) []byte { - size := xgb.Pad((8 + (4 + xgb.Pad((4 * xgb.PopCount(int(ValueMask))))))) + size := xgb.Pad((12 + xgb.Pad((4 * xgb.PopCount(int(ValueMask)))))) b := 0 buf := make([]byte, size) @@ -7516,6 +7519,7 @@ func changeWindowAttributesRequest(c *xgb.Conn, Window Window, ValueMask uint32, xgb.Put32(buf[b:], ValueMask) b += 4 + for i := 0; i < xgb.PopCount(int(ValueMask)); i++ { xgb.Put32(buf[b:], ValueList[i]) b += 4 @@ -7717,7 +7721,7 @@ func (cook ConfigureWindowCookie) Check() error { // Write request to wire for ConfigureWindow // configureWindowRequest writes a ConfigureWindow request to a byte slice. func configureWindowRequest(c *xgb.Conn, Window Window, ValueMask uint16, ValueList []uint32) []byte { - size := xgb.Pad((10 + (2 + xgb.Pad((4 * xgb.PopCount(int(ValueMask))))))) + size := xgb.Pad((12 + xgb.Pad((4 * xgb.PopCount(int(ValueMask)))))) b := 0 buf := make([]byte, size) @@ -8221,7 +8225,7 @@ func (cook CreateGCCookie) Check() error { // Write request to wire for CreateGC // createGCRequest writes a CreateGC request to a byte slice. func createGCRequest(c *xgb.Conn, Cid Gcontext, Drawable Drawable, ValueMask uint32, ValueList []uint32) []byte { - size := xgb.Pad((12 + (4 + xgb.Pad((4 * xgb.PopCount(int(ValueMask))))))) + size := xgb.Pad((16 + xgb.Pad((4 * xgb.PopCount(int(ValueMask)))))) b := 0 buf := make([]byte, size) @@ -8241,6 +8245,7 @@ func createGCRequest(c *xgb.Conn, Cid Gcontext, Drawable Drawable, ValueMask uin xgb.Put32(buf[b:], ValueMask) b += 4 + for i := 0; i < xgb.PopCount(int(ValueMask)); i++ { xgb.Put32(buf[b:], ValueList[i]) b += 4 @@ -8416,7 +8421,7 @@ func (cook CreateWindowCookie) Check() error { // Write request to wire for CreateWindow // createWindowRequest writes a CreateWindow request to a byte slice. func createWindowRequest(c *xgb.Conn, Depth byte, Wid Window, Parent Window, X int16, Y int16, Width uint16, Height uint16, BorderWidth uint16, Class uint16, Visual Visualid, ValueMask uint32, ValueList []uint32) []byte { - size := xgb.Pad((28 + (4 + xgb.Pad((4 * xgb.PopCount(int(ValueMask))))))) + size := xgb.Pad((32 + xgb.Pad((4 * xgb.PopCount(int(ValueMask)))))) b := 0 buf := make([]byte, size) @@ -8458,6 +8463,7 @@ func createWindowRequest(c *xgb.Conn, Depth byte, Wid Window, Parent Window, X i xgb.Put32(buf[b:], ValueMask) b += 4 + for i := 0; i < xgb.PopCount(int(ValueMask)); i++ { xgb.Put32(buf[b:], ValueList[i]) b += 4 @@ -12904,8 +12910,7 @@ type QueryFontReply struct { FontDescent int16 CharInfosLen uint32 Properties []Fontprop // size: xgb.Pad((int(PropertiesLen) * 8)) - // alignment gap to multiple of 4 - CharInfos []Charinfo // size: xgb.Pad((int(CharInfosLen) * 12)) + CharInfos []Charinfo // size: xgb.Pad((int(CharInfosLen) * 12)) } // Reply blocks and returns the reply data for a QueryFont request. @@ -12983,8 +12988,6 @@ func queryFontReply(buf []byte) *QueryFontReply { v.Properties = make([]Fontprop, v.PropertiesLen) b += FontpropReadList(buf[b:], v.Properties) - b = (b + 3) & ^3 // alignment gap - v.CharInfos = make([]Charinfo, v.CharInfosLen) b += CharinfoReadList(buf[b:], v.CharInfos) diff --git a/nexgb/xselinux/xselinux.go b/nexgb/xselinux/xselinux.go index 1afcc10..c237857 100644 --- a/nexgb/xselinux/xselinux.go +++ b/nexgb/xselinux/xselinux.go @@ -41,7 +41,9 @@ type ListItem struct { ObjectContextLen uint32 DataContextLen uint32 ObjectContext string // size: xgb.Pad((int(ObjectContextLen) * 1)) - DataContext string // size: xgb.Pad((int(DataContextLen) * 1)) + // alignment gap to multiple of 4 + DataContext string // size: xgb.Pad((int(DataContextLen) * 1)) + // alignment gap to multiple of 4 } // ListItemRead reads a byte slice into a ListItem value. @@ -64,6 +66,8 @@ func ListItemRead(buf []byte, v *ListItem) int { b += int(v.ObjectContextLen) } + b = (b + 3) & ^3 // alignment gap + { byteString := make([]byte, v.DataContextLen) copy(byteString[:v.DataContextLen], buf[b:]) @@ -71,6 +75,8 @@ func ListItemRead(buf []byte, v *ListItem) int { b += int(v.DataContextLen) } + b = (b + 3) & ^3 // alignment gap + return b } @@ -86,7 +92,7 @@ func ListItemReadList(buf []byte, dest []ListItem) int { // Bytes writes a ListItem value to a byte slice. func (v ListItem) Bytes() []byte { - buf := make([]byte, ((12 + xgb.Pad((int(v.ObjectContextLen) * 1))) + xgb.Pad((int(v.DataContextLen) * 1)))) + buf := make([]byte, ((((12 + xgb.Pad((int(v.ObjectContextLen) * 1))) + 4) + xgb.Pad((int(v.DataContextLen) * 1))) + 4)) b := 0 xgb.Put32(buf[b:], uint32(v.Name)) @@ -101,9 +107,13 @@ func (v ListItem) Bytes() []byte { copy(buf[b:], v.ObjectContext[:v.ObjectContextLen]) b += int(v.ObjectContextLen) + b = (b + 3) & ^3 // alignment gap + copy(buf[b:], v.DataContext[:v.DataContextLen]) b += int(v.DataContextLen) + b = (b + 3) & ^3 // alignment gap + return buf[:b] } @@ -123,7 +133,7 @@ func ListItemListBytes(buf []byte, list []ListItem) int { func ListItemListSize(list []ListItem) int { size := 0 for _, item := range list { - size += ((12 + xgb.Pad((int(item.ObjectContextLen) * 1))) + xgb.Pad((int(item.DataContextLen) * 1))) + size += ((((12 + xgb.Pad((int(item.ObjectContextLen) * 1))) + 4) + xgb.Pad((int(item.DataContextLen) * 1))) + 4) } return size } diff --git a/nexgb/xv/xv.go b/nexgb/xv/xv.go index f0d3f3a..69a0549 100644 --- a/nexgb/xv/xv.go +++ b/nexgb/xv/xv.go @@ -45,7 +45,7 @@ type AdaptorInfo struct { Type byte // padding: 1 bytes Name string // size: xgb.Pad((int(NameSize) * 1)) - // padding: 0 bytes + // alignment gap to multiple of 4 Formats []Format // size: xgb.Pad((int(NumFormats) * 8)) } @@ -77,7 +77,7 @@ func AdaptorInfoRead(buf []byte, v *AdaptorInfo) int { b += int(v.NameSize) } - b += 0 // padding + b = (b + 3) & ^3 // alignment gap v.Formats = make([]Format, v.NumFormats) b += FormatReadList(buf[b:], v.Formats) @@ -97,7 +97,7 @@ func AdaptorInfoReadList(buf []byte, dest []AdaptorInfo) int { // Bytes writes a AdaptorInfo value to a byte slice. func (v AdaptorInfo) Bytes() []byte { - buf := make([]byte, (((12 + xgb.Pad((int(v.NameSize) * 1))) + 0) + xgb.Pad((int(v.NumFormats) * 8)))) + buf := make([]byte, (((12 + xgb.Pad((int(v.NameSize) * 1))) + 4) + xgb.Pad((int(v.NumFormats) * 8)))) b := 0 xgb.Put32(buf[b:], uint32(v.BaseId)) @@ -120,7 +120,7 @@ func (v AdaptorInfo) Bytes() []byte { copy(buf[b:], v.Name[:v.NameSize]) b += int(v.NameSize) - b += 0 // padding + b = (b + 3) & ^3 // alignment gap b += FormatListBytes(buf[b:], v.Formats) @@ -143,7 +143,7 @@ func AdaptorInfoListBytes(buf []byte, list []AdaptorInfo) int { func AdaptorInfoListSize(list []AdaptorInfo) int { size := 0 for _, item := range list { - size += (((12 + xgb.Pad((int(item.NameSize) * 1))) + 0) + xgb.Pad((int(item.NumFormats) * 8))) + size += (((12 + xgb.Pad((int(item.NameSize) * 1))) + 4) + xgb.Pad((int(item.NumFormats) * 8))) } return size } @@ -159,6 +159,7 @@ type AttributeInfo struct { Max int32 Size uint32 Name string // size: xgb.Pad((int(Size) * 1)) + // alignment gap to multiple of 4 } // AttributeInfoRead reads a byte slice into a AttributeInfo value. @@ -184,6 +185,8 @@ func AttributeInfoRead(buf []byte, v *AttributeInfo) int { b += int(v.Size) } + b = (b + 3) & ^3 // alignment gap + return b } @@ -199,7 +202,7 @@ func AttributeInfoReadList(buf []byte, dest []AttributeInfo) int { // Bytes writes a AttributeInfo value to a byte slice. func (v AttributeInfo) Bytes() []byte { - buf := make([]byte, (16 + xgb.Pad((int(v.Size) * 1)))) + buf := make([]byte, ((16 + xgb.Pad((int(v.Size) * 1))) + 4)) b := 0 xgb.Put32(buf[b:], v.Flags) @@ -217,6 +220,8 @@ func (v AttributeInfo) Bytes() []byte { copy(buf[b:], v.Name[:v.Size]) b += int(v.Size) + b = (b + 3) & ^3 // alignment gap + return buf[:b] } @@ -236,7 +241,7 @@ func AttributeInfoListBytes(buf []byte, list []AttributeInfo) int { func AttributeInfoListSize(list []AttributeInfo) int { size := 0 for _, item := range list { - size += (16 + xgb.Pad((int(item.Size) * 1))) + size += ((16 + xgb.Pad((int(item.Size) * 1))) + 4) } return size } @@ -397,6 +402,7 @@ type EncodingInfo struct { // padding: 2 bytes Rate Rational Name string // size: xgb.Pad((int(NameSize) * 1)) + // alignment gap to multiple of 4 } // EncodingInfoRead reads a byte slice into a EncodingInfo value. @@ -427,6 +433,8 @@ func EncodingInfoRead(buf []byte, v *EncodingInfo) int { b += int(v.NameSize) } + b = (b + 3) & ^3 // alignment gap + return b } @@ -442,7 +450,7 @@ func EncodingInfoReadList(buf []byte, dest []EncodingInfo) int { // Bytes writes a EncodingInfo value to a byte slice. func (v EncodingInfo) Bytes() []byte { - buf := make([]byte, (20 + xgb.Pad((int(v.NameSize) * 1)))) + buf := make([]byte, ((20 + xgb.Pad((int(v.NameSize) * 1))) + 4)) b := 0 xgb.Put32(buf[b:], uint32(v.Encoding)) @@ -468,6 +476,8 @@ func (v EncodingInfo) Bytes() []byte { copy(buf[b:], v.Name[:v.NameSize]) b += int(v.NameSize) + b = (b + 3) & ^3 // alignment gap + return buf[:b] } @@ -487,7 +497,7 @@ func EncodingInfoListBytes(buf []byte, list []EncodingInfo) int { func EncodingInfoListSize(list []EncodingInfo) int { size := 0 for _, item := range list { - size += (20 + xgb.Pad((int(item.NameSize) * 1))) + size += ((20 + xgb.Pad((int(item.NameSize) * 1))) + 4) } return size } @@ -567,9 +577,8 @@ type Image struct { DataSize uint32 NumPlanes uint32 Pitches []uint32 // size: xgb.Pad((int(NumPlanes) * 4)) - // alignment gap to multiple of 4 - Offsets []uint32 // size: xgb.Pad((int(NumPlanes) * 4)) - Data []byte // size: xgb.Pad((int(DataSize) * 1)) + Offsets []uint32 // size: xgb.Pad((int(NumPlanes) * 4)) + Data []byte // size: xgb.Pad((int(DataSize) * 1)) } // ImageRead reads a byte slice into a Image value. @@ -597,8 +606,6 @@ func ImageRead(buf []byte, v *Image) int { b += 4 } - b = (b + 3) & ^3 // alignment gap - v.Offsets = make([]uint32, v.NumPlanes) for i := 0; i < int(v.NumPlanes); i++ { v.Offsets[i] = xgb.Get32(buf[b:]) @@ -624,7 +631,7 @@ func ImageReadList(buf []byte, dest []Image) int { // Bytes writes a Image value to a byte slice. func (v Image) Bytes() []byte { - buf := make([]byte, ((((16 + xgb.Pad((int(v.NumPlanes) * 4))) + 4) + xgb.Pad((int(v.NumPlanes) * 4))) + xgb.Pad((int(v.DataSize) * 1)))) + buf := make([]byte, (((16 + xgb.Pad((int(v.NumPlanes) * 4))) + xgb.Pad((int(v.NumPlanes) * 4))) + xgb.Pad((int(v.DataSize) * 1)))) b := 0 xgb.Put32(buf[b:], v.Id) @@ -647,8 +654,6 @@ func (v Image) Bytes() []byte { b += 4 } - b = (b + 3) & ^3 // alignment gap - for i := 0; i < int(v.NumPlanes); i++ { xgb.Put32(buf[b:], v.Offsets[i]) b += 4 @@ -676,7 +681,7 @@ func ImageListBytes(buf []byte, list []Image) int { func ImageListSize(list []Image) int { size := 0 for _, item := range list { - size += ((((16 + xgb.Pad((int(item.NumPlanes) * 4))) + 4) + xgb.Pad((int(item.NumPlanes) * 4))) + xgb.Pad((int(item.DataSize) * 1))) + size += (((16 + xgb.Pad((int(item.NumPlanes) * 4))) + xgb.Pad((int(item.NumPlanes) * 4))) + xgb.Pad((int(item.DataSize) * 1))) } return size } @@ -2416,7 +2421,6 @@ type QueryImageAttributesReply struct { Height uint16 // padding: 12 bytes Pitches []uint32 // size: xgb.Pad((int(NumPlanes) * 4)) - // alignment gap to multiple of 4 Offsets []uint32 // size: xgb.Pad((int(NumPlanes) * 4)) } @@ -2465,8 +2469,6 @@ func queryImageAttributesReply(buf []byte) *QueryImageAttributesReply { b += 4 } - b = (b + 3) & ^3 // alignment gap - v.Offsets = make([]uint32, v.NumPlanes) for i := 0; i < int(v.NumPlanes); i++ { v.Offsets[i] = xgb.Get32(buf[b:]) |