From 4a7b05be36b96134b4dae3ca385e9bfbb797d531 Mon Sep 17 00:00:00 2001 From: "Andrew Gallant (Ocelot)" Date: Sat, 5 May 2012 02:56:15 -0400 Subject: [PATCH] oh momma. a lot of modifications and it appears to be working. w00t. --- nexgb/cookie.go | 111 ++ nexgb/xgb.go | 498 ++--- nexgb/xproto.go | 4620 +++++++++++++++++++++++++++++++++-------------- 3 files changed, 3620 insertions(+), 1609 deletions(-) create mode 100644 nexgb/cookie.go diff --git a/nexgb/cookie.go b/nexgb/cookie.go new file mode 100644 index 0000000..502ccbf --- /dev/null +++ b/nexgb/cookie.go @@ -0,0 +1,111 @@ +package xgb + +import ( + "errors" +) + +type cookie struct { + Sequence uint16 + replyChan chan []byte + errorChan chan error + pingChan chan bool +} + +func (c *Conn) newCookie(checked, reply bool) cookie { + cookie := cookie{ + Sequence: c.newSequenceId(), + replyChan: nil, + errorChan: nil, + pingChan: nil, + } + + // There are four different kinds of cookies: + // Checked requests with replies get a reply channel and an error channel. + // Unchecked requests with replies get a reply channel and a ping channel. + // Checked requests w/o replies get a ping channel and an error channel. + // Unchecked requests w/o replies get no channels. + // The reply channel is used to send reply data. + // The error channel is used to send error data. + // The ping channel is used when one of the 'reply' or 'error' channels + // is missing but the other is present. The ping channel is way to force + // the blocking to stop and basically say "the error has been received + // in the main event loop" (when the ping channel is coupled with a reply + // channel) or "the request you made that has no reply was successful" + // (when the ping channel is coupled with an error channel). + if checked { + cookie.errorChan = make(chan error, 1) + if !reply { + cookie.pingChan = make(chan bool, 1) + } + } + if reply { + cookie.replyChan = make(chan []byte, 1) + if !checked { + cookie.pingChan = make(chan bool, 1) + } + } + + return cookie +} + +func (c cookie) reply() ([]byte, error) { + // checked + if c.errorChan != nil { + return c.replyChecked() + } + return c.replyUnchecked() +} + +func (c cookie) replyChecked() ([]byte, error) { + if c.replyChan == nil { + return nil, errors.New("Cannot call 'replyChecked' on a cookie that " + + "is not expecting a *reply* or an error.") + } + if c.errorChan == nil { + return nil, errors.New("Cannot call 'replyChecked' on a cookie that " + + "is not expecting a reply or an *error*.") + } + + select { + case reply := <-c.replyChan: + return reply, nil + case err := <-c.errorChan: + return nil, err + } + panic("unreachable") +} + +func (c cookie) replyUnchecked() ([]byte, error) { + if c.replyChan == nil { + return nil, errors.New("Cannot call 'replyUnchecked' on a cookie " + + "that is not expecting a *reply*.") + } + + select { + case reply := <-c.replyChan: + return reply, nil + case <-c.pingChan: + return nil, nil + } + panic("unreachable") +} + +func (c cookie) Check() error { + if c.replyChan != nil { + return errors.New("Cannot call 'Check' on a cookie that is " + + "expecting a *reply*. Use 'Reply' instead.") + } + if c.errorChan == nil { + return errors.New("Cannot call 'Check' on a cookie that is " + + "not expecting a possible *error*.") + } + + select { + case err := <-c.errorChan: + return err + case <-c.pingChan: + return nil + } + panic("unreachable") +} + diff --git a/nexgb/xgb.go b/nexgb/xgb.go index 1a4ada1..b453427 100644 --- a/nexgb/xgb.go +++ b/nexgb/xgb.go @@ -25,27 +25,18 @@ const ( type Conn struct { host string conn net.Conn - nextCookie uint16 - cookies map[uint16]*Cookie - events queue err error display string defaultScreen int - scratch [32]byte Setup SetupInfo extensions map[string]byte - requestChan chan *Request - requestCookieChan chan *Cookie - replyChan chan bool - eventChan chan bool - errorChan chan bool - + eventChan chan eventOrError + cookieChan chan cookie xidChan chan xid - newIdLock sync.Mutex - writeLock sync.Mutex - dequeueLock sync.Mutex - cookieLock sync.Mutex + seqChan chan uint16 + reqChan chan *request + extLock sync.Mutex } @@ -75,16 +66,18 @@ func NewConnDisplay(display string) (*Conn, error) { return nil, err } - conn.xidChan = make(chan xid, 5) - go conn.generateXids() - - conn.nextCookie = 1 - conn.cookies = make(map[uint16]*Cookie) - conn.events = queue{make([][]byte, 100), 0, 0} conn.extensions = make(map[string]byte) - conn.newReadChannels() - conn.newRequestChannels() + conn.cookieChan = make(chan cookie, 100) + conn.xidChan = make(chan xid, 5) + conn.seqChan = make(chan uint16, 20) + conn.reqChan = make(chan *request, 100) + conn.eventChan = make(chan eventOrError, 100) + + go conn.generateXIds() + go conn.generateSeqIds() + go conn.sendRequests() + go conn.readResponses() return conn, nil } @@ -97,43 +90,11 @@ func (c *Conn) Close() { // Id is used for all X identifiers, such as windows, pixmaps, and GCs. type Id uint32 -// Request is used to abstract the difference between a request -// that expects a reply and a request that doesn't expect a reply. -type Request struct { - buf []byte - cookieChan chan *Cookie -} - -func newRequest(buf []byte, needsReply bool) *Request { - req := &Request{ - buf: buf, - cookieChan: nil, - } - if needsReply { - req.cookieChan = make(chan *Cookie) - } - return req -} - -// Cookies are the sequence numbers used to pair replies up with their requests -type Cookie struct { - id uint16 - replyChan chan []byte - errorChan chan error -} - -func newCookie(id uint16) *Cookie { - return &Cookie{ - id: id, - replyChan: make(chan []byte, 1), - errorChan: make(chan error, 1), - } -} - // Event is an interface that can contain any of the events returned by the // server. Use a type assertion switch to extract the Event structs. type Event interface { ImplementsEvent() + Bytes() []byte } // newEventFuncs is a map from event numbers to functions that create @@ -153,6 +114,10 @@ type Error interface { // the corresponding error. var newErrorFuncs = map[int]func(buf []byte) Error{} +// eventOrError corresponds to values that can be either an event or an +// error. +type eventOrError interface{} + // NewID generates a new unused ID for use with requests like CreateWindow. // If no new ids can be generated, the id returned is 0 and error is non-nil. func (c *Conn) NewId() (Id, error) { @@ -164,7 +129,7 @@ func (c *Conn) NewId() (Id, error) { } // xid encapsulates a resource identifier being sent over the Conn.xidChan -// channel. If no new resource id can be generated, id is set to -1 and a +// channel. If no new resource id can be generated, id is set to 0 and a // non-nil error is set in xid.err. type xid struct { id Id @@ -174,7 +139,24 @@ type xid struct { // generateXids sends new Ids down the channel for NewId to use. // This needs to be updated to use the XC Misc extension once we run out of // new ids. -func (conn *Conn) generateXids() { +// Thanks to libxcb/src/xcb_xid.c. This code is greatly inspired by it. +func (conn *Conn) generateXIds() { + // This requires some explanation. From the horse's mouth: + // "The resource-id-mask contains a single contiguous set of bits (at least + // 18). The client allocates resource IDs for types WINDOW, PIXMAP, + // CURSOR, FONT, GCONTEXT, and COLORMAP by choosing a value with only some + // subset of these bits set and ORing it with resource-id-base. Only values + // constructed in this way can be used to name newly created resources over + // this connection." + // So for example (using 8 bit integers), the mask might look like: + // 00111000 + // So that valid values would be 00101000, 00110000, 00001000, and so on. + // Thus, the idea is to increment it by the place of the last least + // significant '1'. In this case, that value would be 00001000. To get + // that value, we can AND the original mask with its two's complement: + // 00111000 & 11001000 = 00001000. + // And we use that value to increment the last resource id to get a new one. + // (And then, of course, we OR it with resource-id-base.) inc := conn.Setup.ResourceIdMask & -conn.Setup.ResourceIdMask max := conn.Setup.ResourceIdMask last := uint32(0) @@ -196,11 +178,224 @@ func (conn *Conn) generateXids() { } } +// newSeqId fetches the next sequence id from the Conn.seqChan channel. +func (c *Conn) newSequenceId() uint16 { + return <-c.seqChan +} + +// generateSeqIds returns new sequence ids. +// A sequence id is generated for *every* request. It's the identifier used +// to match up replies with requests. +// Since sequence ids can only be 16 bit integers we start over at zero when it +// comes time to wrap. +// FIXME: 65,536 requests without replies cannot be made in a single sequence. +func (c *Conn) generateSeqIds() { + seqid := uint16(1) + for { + c.seqChan <- seqid + if seqid == uint16((1 << 16) - 1) { + seqid = 0 + } else { + seqid++ + } + } +} + +// request encapsulates a buffer of raw bytes (containing the request data) +// and a cookie, which when combined represents a single request. +// The cookie is used to match up the reply/error. +type request struct { + buf []byte + cookie cookie +} + +// newRequest takes the bytes an a cookie, constructs a request type, +// and sends it over the Conn.reqChan channel. It then returns the cookie +// (for convenience). +func (c *Conn) newRequest(buf []byte, cookie cookie) { + c.reqChan <- &request{buf: buf, cookie: cookie} +} + +// sendRequests is run as a single goroutine that takes requests and writes +// the bytes to the wire and adds the cookie to the cookie queue. +func (c *Conn) sendRequests() { + for req := range c.reqChan { + c.cookieChan <- req.cookie + if _, err := c.conn.Write(req.buf); err != nil { + fmt.Fprintf(os.Stderr, "x protocol write error: %s\n", err) + close(c.reqChan) + return + } + } +} + +// readResponses is a goroutine that reads events, errors and +// replies off the wire. +// When an event is read, it is always added to the event channel. +// When an error is read, if it corresponds to an existing checked cookie, +// it is sent to that cookie's error channel. Otherwise it is added to the +// event channel. +// When a reply is read, it is added to the corresponding cookie's reply +// channel. (It is an error if no such cookie exists in this case.) +// Finally, cookies that came "before" this reply are always cleaned up. +func (c *Conn) readResponses() { + var ( + err Error + event Event + seq uint16 + replyBytes []byte + ) + + buf := make([]byte, 32) + for { + err, event, seq = nil, nil, 0 + + if _, err := io.ReadFull(c.conn, buf); err != nil { + fmt.Fprintf(os.Stderr, "x protocol read error: %s\n", err) + close(c.eventChan) + break + } + + switch buf[0] { + case 0: // This is an error + // Use the constructor function for this error (that is auto + // generated) by looking it up by the error number. + err = newErrorFuncs[int(buf[1])](buf) + seq = err.SequenceId() + + // This error is either sent to the event channel or a specific + // cookie's error channel below. + case 1: // This is a reply + seq = Get16(buf[2:]) + + // check to see if this reply has more bytes to be read + size := Get32(buf[4:]) + if size > 0 { + byteCount := 32 + size * 4 + biggerBuf := make([]byte, byteCount) + copy(biggerBuf[:32], buf) + if _, err := io.ReadFull(c.conn, biggerBuf[32:]); err != nil { + fmt.Fprintf(os.Stderr, "x protocol read error: %s\n", err) + close(c.eventChan) + break + } + replyBytes = biggerBuf + } else { + replyBytes = buf + } + + // This reply is sent to its corresponding cookie below. + default: // This is an event + // Use the constructor function for this event (like for errors, + // and is also auto generated) by looking it up by the event number. + // Note that we AND the event number with 127 so that we ignore + // the most significant bit (which is set when it was sent from + // a SendEvent request). + event = newEventFuncs[int(buf[0] & 127)](buf) + // seq = event.SequenceId() // 0 for KeymapNotify + + // Put the event into the queue. + c.eventChan <- event + + // No more processing for events. + continue + + // If this was a KeymapNotify event, then we don't do any more + // processing since we don't have any sequence id. + // if event != nil { + // if _, ok := event.(KeymapNotifyEvent); ok { + // continue + // } + // } + } + + // At this point, we have a sequence number and we're either + // processing an error or a reply, which are both responses to + // requests. So all we have to do is find the cookie corresponding + // to this error/reply, and send the appropriate data to it. + // In doing so, we make sure that any cookies that came before it + // are marked as successful if they are void and checked. + // If there's a cookie that requires a reply that is before this + // reply, then something is wrong. + for cookie := range c.cookieChan { + // This is the cookie we're looking for. Process and break. + if cookie.Sequence == seq { + if err != nil { // this is an error to a request + // synchronous processing + if cookie.errorChan != nil { + cookie.errorChan <- err + } else { // asynchronous processing + c.eventChan <- err + } + } else { // this is a reply + if cookie.replyChan == nil { + fmt.Fprintf(os.Stderr, + "Reply with sequence id %d does not have a " + + "cookie with a valid reply channel.\n", seq) + } else { + cookie.replyChan <- replyBytes + } + } + break + } + + switch { + // Checked requests with replies + case cookie.replyChan != nil && cookie.errorChan != nil: + fmt.Fprintf(os.Stderr, + "Found cookie with sequence id %d that is expecting a " + + "reply but will never get it.\n", cookie.Sequence) + // Unchecked requests with replies + case cookie.replyChan != nil && cookie.pingChan != nil: + cookie.pingChan <- true + // Checked requests without replies + case cookie.pingChan != nil && cookie.errorChan != nil: + cookie.pingChan <- true + // Unchecked requests without replies don't have any channels, + // so we can't do anything with them except let them pass by. + } + } + } +} + +// processEventOrError takes an eventOrError, type switches on it, +// and returns it in Go idiomatic style. +func processEventOrError(everr eventOrError) (Event, Error) { + switch ee := everr.(type) { + case Event: + return ee, nil + case Error: + return nil, ee + default: + fmt.Fprintf(os.Stderr, "Invalid event/error type: %T\n", everr) + } + panic("unreachable") +} + +// WaitForEvent returns the next event from the server. +// It will block until an event is available. +func (c *Conn) WaitForEvent() (Event, Error) { + return processEventOrError(<-c.eventChan) +} + +// PollForEvent returns the next event from the server if one is available in +// the internal queue. +// It will not block. +func (c *Conn) PollForEvent() (Event, Error) { + select { + case everr := <-c.eventChan: + return processEventOrError(everr) + default: + return nil, nil + } + panic("unreachable") +} + // RegisterExtension adds the respective extension's major op code to // the extensions map. func (c *Conn) RegisterExtension(name string) error { nameUpper := strings.ToUpper(name) - reply, err := c.QueryExtension(uint16(len(nameUpper)), nameUpper) + reply, err := c.QueryExtension(uint16(len(nameUpper)), nameUpper).Reply() switch { case err != nil: @@ -216,190 +411,3 @@ func (c *Conn) RegisterExtension(name string) error { return nil } - -// A simple queue used to stow away events. -type queue struct { - data [][]byte - a, b int -} - -func (q *queue) queue(item []byte) { - if q.b == len(q.data) { - if q.a > 0 { - copy(q.data, q.data[q.a:q.b]) - q.a, q.b = 0, q.b-q.a - } else { - newData := make([][]byte, (len(q.data)*3)/2) - copy(newData, q.data) - q.data = newData - } - } - q.data[q.b] = item - q.b++ -} - -func (q *queue) dequeue(c *Conn) []byte { - c.dequeueLock.Lock() - defer c.dequeueLock.Unlock() - - if q.a < q.b { - item := q.data[q.a] - q.a++ - return item - } - return nil -} - -// newWriteChan creates the channel required for writing to the net.Conn. -func (c *Conn) newRequestChannels() { - c.requestChan = make(chan *Request, writeBuffer) - c.requestCookieChan = make(chan *Cookie, 1) - - go func() { - for request := range c.requestChan { - cookieNum := c.nextCookie - c.nextCookie++ - - if request.cookieChan != nil { - cookie := newCookie(cookieNum) - c.cookies[cookieNum] = cookie - request.cookieChan <- cookie - } - if _, err := c.conn.Write(request.buf); err != nil { - fmt.Fprintf(os.Stderr, "x protocol write error: %s\n", err) - close(c.requestChan) - return - } - } - }() -} - -// request is a buffered write to net.Conn. -func (c *Conn) request(buf []byte, needsReply bool) *Cookie { - req := newRequest(buf, needsReply) - c.requestChan <- req - - if req.cookieChan != nil { - cookie := <-req.cookieChan - close(req.cookieChan) - return cookie - } - return nil -} - -func (c *Conn) sendRequest(needsReply bool, bufs ...[]byte) *Cookie { - if len(bufs) == 1 { - return c.request(bufs[0], needsReply) - } - - total := make([]byte, 0) - for _, buf := range bufs { - total = append(total, buf...) - } - return c.request(total, needsReply) -} - -func (c *Conn) newReadChannels() { - c.eventChan = make(chan bool, readBuffer) - - onError := func() { - panic("read error") - } - - go func() { - for { - buf := make([]byte, 32) - if _, err := io.ReadFull(c.conn, buf); err != nil { - fmt.Fprintf(os.Stderr, "x protocol read error: %s\n", err) - onError() - return - } - - switch buf[0] { - case 0: - // err := &Error{ - // Detail: buf[1], - // Cookie: uint16(get16(buf[2:])), - // Id: Id(get32(buf[4:])), - // Minor: get16(buf[8:]), - // Major: buf[10], - // } - err := newErrorFuncs[int(buf[1])](buf) - if cookie, ok := c.cookies[err.SequenceId()]; ok { - cookie.errorChan <- err - } else { - fmt.Fprintf(os.Stderr, "x protocol error: %s\n", err) - } - case 1: - seq := uint16(Get16(buf[2:])) - if _, ok := c.cookies[seq]; !ok { - continue - } - - size := Get32(buf[4:]) - if size > 0 { - bigbuf := make([]byte, 32+size*4, 32+size*4) - copy(bigbuf[0:32], buf) - if _, err := io.ReadFull(c.conn, bigbuf[32:]); err != nil { - fmt.Fprintf(os.Stderr, - "x protocol read error: %s\n", err) - onError() - return - } - c.cookies[seq].replyChan <- bigbuf - } else { - c.cookies[seq].replyChan <- buf - } - default: - c.events.queue(buf) - select { - case c.eventChan <- true: - default: - } - } - } - }() -} - -func (c *Conn) waitForReply(cookie *Cookie) ([]byte, error) { - if cookie == nil { - panic("nil cookie") - } - if _, ok := c.cookies[cookie.id]; !ok { - panic("waiting for a cookie that will never come") - } - select { - case reply := <-cookie.replyChan: - return reply, nil - case err := <-cookie.errorChan: - return nil, err - } - panic("unreachable") -} - -// WaitForEvent returns the next event from the server. -// It will block until an event is available. -func (c *Conn) WaitForEvent() (Event, error) { - for { - if reply := c.events.dequeue(c); reply != nil { - evCode := reply[0] & 0x7f - return newEventFuncs[int(evCode)](reply), nil - } - if !<-c.eventChan { - return nil, errors.New("Event channel has been closed.") - } - } - panic("unreachable") -} - -// PollForEvent returns the next event from the server if one is available in the internal queue. -// It will not read from the connection, so you must call WaitForEvent to receive new events. -// Only use this function to empty the queue without blocking. -func (c *Conn) PollForEvent() (Event, error) { - if reply := c.events.dequeue(c); reply != nil { - evCode := reply[0] & 0x7f - return newEventFuncs[int(evCode)](reply), nil - } - return nil, nil -} - diff --git a/nexgb/xproto.go b/nexgb/xproto.go index 3317b51..d56f0a1 100644 --- a/nexgb/xproto.go +++ b/nexgb/xproto.go @@ -1,10 +1,22 @@ package xgb /* - This file was generated by xproto.xml on May 3 2012 12:48:47am EDT. + This file was generated by xproto.xml on May 5 2012 2:50:11am EDT. This file is automatically generated. Edit at your peril! */ +// Skipping definition for base type 'Int8' + +// Skipping definition for base type 'Card16' + +// Skipping definition for base type 'Char' + +// Skipping definition for base type 'Card32' + +// Skipping definition for base type 'Double' + +// Skipping definition for base type 'Bool' + // Skipping definition for base type 'Float' // Skipping definition for base type 'Id' @@ -19,18 +31,6 @@ package xgb // Skipping definition for base type 'Byte' -// Skipping definition for base type 'Int8' - -// Skipping definition for base type 'Card16' - -// Skipping definition for base type 'Char' - -// Skipping definition for base type 'Card32' - -// Skipping definition for base type 'Double' - -// Skipping definition for base type 'Bool' - const ( VisualClassStaticGray = 0 VisualClassGrayScale = 1 @@ -2727,6 +2727,10 @@ func (v KeyPressEvent) Bytes() []byte { func (v KeyPressEvent) ImplementsEvent() {} +func (v KeyPressEvent) SequenceId() uint16 { + return v.Sequence +} + func init() { newEventFuncs[2] = NewKeyPressEvent } @@ -2857,6 +2861,10 @@ func (v ButtonPressEvent) Bytes() []byte { func (v ButtonPressEvent) ImplementsEvent() {} +func (v ButtonPressEvent) SequenceId() uint16 { + return v.Sequence +} + func init() { newEventFuncs[4] = NewButtonPressEvent } @@ -2987,6 +2995,10 @@ func (v MotionNotifyEvent) Bytes() []byte { func (v MotionNotifyEvent) ImplementsEvent() {} +func (v MotionNotifyEvent) SequenceId() uint16 { + return v.Sequence +} + func init() { newEventFuncs[6] = NewMotionNotifyEvent } @@ -3111,6 +3123,10 @@ func (v EnterNotifyEvent) Bytes() []byte { func (v EnterNotifyEvent) ImplementsEvent() {} +func (v EnterNotifyEvent) SequenceId() uint16 { + return v.Sequence +} + func init() { newEventFuncs[7] = NewEnterNotifyEvent } @@ -3177,6 +3193,10 @@ func (v FocusInEvent) Bytes() []byte { func (v FocusInEvent) ImplementsEvent() {} +func (v FocusInEvent) SequenceId() uint16 { + return v.Sequence +} + func init() { newEventFuncs[9] = NewFocusInEvent } @@ -3219,6 +3239,10 @@ func (v KeymapNotifyEvent) Bytes() []byte { func (v KeymapNotifyEvent) ImplementsEvent() {} +func (v KeymapNotifyEvent) SequenceId() uint16 { + return uint16(0) +} + func init() { newEventFuncs[11] = NewKeymapNotifyEvent } @@ -3311,6 +3335,10 @@ func (v ExposeEvent) Bytes() []byte { func (v ExposeEvent) ImplementsEvent() {} +func (v ExposeEvent) SequenceId() uint16 { + return v.Sequence +} + func init() { newEventFuncs[12] = NewExposeEvent } @@ -3417,6 +3445,10 @@ func (v GraphicsExposureEvent) Bytes() []byte { func (v GraphicsExposureEvent) ImplementsEvent() {} +func (v GraphicsExposureEvent) SequenceId() uint16 { + return v.Sequence +} + func init() { newEventFuncs[13] = NewGraphicsExposureEvent } @@ -3488,6 +3520,10 @@ func (v NoExposureEvent) Bytes() []byte { func (v NoExposureEvent) ImplementsEvent() {} +func (v NoExposureEvent) SequenceId() uint16 { + return v.Sequence +} + func init() { newEventFuncs[14] = NewNoExposureEvent } @@ -3552,6 +3588,10 @@ func (v VisibilityNotifyEvent) Bytes() []byte { func (v VisibilityNotifyEvent) ImplementsEvent() {} +func (v VisibilityNotifyEvent) SequenceId() uint16 { + return v.Sequence +} + func init() { newEventFuncs[15] = NewVisibilityNotifyEvent } @@ -3666,6 +3706,10 @@ func (v CreateNotifyEvent) Bytes() []byte { func (v CreateNotifyEvent) ImplementsEvent() {} +func (v CreateNotifyEvent) SequenceId() uint16 { + return v.Sequence +} + func init() { newEventFuncs[16] = NewCreateNotifyEvent } @@ -3725,6 +3769,10 @@ func (v DestroyNotifyEvent) Bytes() []byte { func (v DestroyNotifyEvent) ImplementsEvent() {} +func (v DestroyNotifyEvent) SequenceId() uint16 { + return v.Sequence +} + func init() { newEventFuncs[17] = NewDestroyNotifyEvent } @@ -3804,6 +3852,10 @@ func (v UnmapNotifyEvent) Bytes() []byte { func (v UnmapNotifyEvent) ImplementsEvent() {} +func (v UnmapNotifyEvent) SequenceId() uint16 { + return v.Sequence +} + func init() { newEventFuncs[18] = NewUnmapNotifyEvent } @@ -3883,6 +3935,10 @@ func (v MapNotifyEvent) Bytes() []byte { func (v MapNotifyEvent) ImplementsEvent() {} +func (v MapNotifyEvent) SequenceId() uint16 { + return v.Sequence +} + func init() { newEventFuncs[19] = NewMapNotifyEvent } @@ -3942,6 +3998,10 @@ func (v MapRequestEvent) Bytes() []byte { func (v MapRequestEvent) ImplementsEvent() {} +func (v MapRequestEvent) SequenceId() uint16 { + return v.Sequence +} + func init() { newEventFuncs[20] = NewMapRequestEvent } @@ -4042,6 +4102,10 @@ func (v ReparentNotifyEvent) Bytes() []byte { func (v ReparentNotifyEvent) ImplementsEvent() {} +func (v ReparentNotifyEvent) SequenceId() uint16 { + return v.Sequence +} + func init() { newEventFuncs[21] = NewReparentNotifyEvent } @@ -4163,6 +4227,10 @@ func (v ConfigureNotifyEvent) Bytes() []byte { func (v ConfigureNotifyEvent) ImplementsEvent() {} +func (v ConfigureNotifyEvent) SequenceId() uint16 { + return v.Sequence +} + func init() { newEventFuncs[22] = NewConfigureNotifyEvent } @@ -4273,6 +4341,10 @@ func (v ConfigureRequestEvent) Bytes() []byte { func (v ConfigureRequestEvent) ImplementsEvent() {} +func (v ConfigureRequestEvent) SequenceId() uint16 { + return v.Sequence +} + func init() { newEventFuncs[23] = NewConfigureRequestEvent } @@ -4346,6 +4418,10 @@ func (v GravityNotifyEvent) Bytes() []byte { func (v GravityNotifyEvent) ImplementsEvent() {} +func (v GravityNotifyEvent) SequenceId() uint16 { + return v.Sequence +} + func init() { newEventFuncs[24] = NewGravityNotifyEvent } @@ -4412,6 +4488,10 @@ func (v ResizeRequestEvent) Bytes() []byte { func (v ResizeRequestEvent) ImplementsEvent() {} +func (v ResizeRequestEvent) SequenceId() uint16 { + return v.Sequence +} + func init() { newEventFuncs[25] = NewResizeRequestEvent } @@ -4488,6 +4568,10 @@ func (v CirculateNotifyEvent) Bytes() []byte { func (v CirculateNotifyEvent) ImplementsEvent() {} +func (v CirculateNotifyEvent) SequenceId() uint16 { + return v.Sequence +} + func init() { newEventFuncs[26] = NewCirculateNotifyEvent } @@ -4566,6 +4650,10 @@ func (v PropertyNotifyEvent) Bytes() []byte { func (v PropertyNotifyEvent) ImplementsEvent() {} +func (v PropertyNotifyEvent) SequenceId() uint16 { + return v.Sequence +} + func init() { newEventFuncs[28] = NewPropertyNotifyEvent } @@ -4632,6 +4720,10 @@ func (v SelectionClearEvent) Bytes() []byte { func (v SelectionClearEvent) ImplementsEvent() {} +func (v SelectionClearEvent) SequenceId() uint16 { + return v.Sequence +} + func init() { newEventFuncs[29] = NewSelectionClearEvent } @@ -4719,6 +4811,10 @@ func (v SelectionRequestEvent) Bytes() []byte { func (v SelectionRequestEvent) ImplementsEvent() {} +func (v SelectionRequestEvent) SequenceId() uint16 { + return v.Sequence +} + func init() { newEventFuncs[30] = NewSelectionRequestEvent } @@ -4799,6 +4895,10 @@ func (v SelectionNotifyEvent) Bytes() []byte { func (v SelectionNotifyEvent) ImplementsEvent() {} +func (v SelectionNotifyEvent) SequenceId() uint16 { + return v.Sequence +} + func init() { newEventFuncs[31] = NewSelectionNotifyEvent } @@ -4885,6 +4985,10 @@ func (v ColormapNotifyEvent) Bytes() []byte { func (v ColormapNotifyEvent) ImplementsEvent() {} +func (v ColormapNotifyEvent) SequenceId() uint16 { + return v.Sequence +} + func init() { newEventFuncs[32] = NewColormapNotifyEvent } @@ -4956,6 +5060,10 @@ func (v ClientMessageEvent) Bytes() []byte { func (v ClientMessageEvent) ImplementsEvent() {} +func (v ClientMessageEvent) SequenceId() uint16 { + return v.Sequence +} + func init() { newEventFuncs[33] = NewClientMessageEvent } @@ -5027,6 +5135,10 @@ func (v MappingNotifyEvent) Bytes() []byte { func (v MappingNotifyEvent) ImplementsEvent() {} +func (v MappingNotifyEvent) SequenceId() uint16 { + return v.Sequence +} + func init() { newEventFuncs[34] = NewMappingNotifyEvent } @@ -5047,6 +5159,10 @@ func (v KeyReleaseEvent) Bytes() []byte { func (v KeyReleaseEvent) ImplementsEvent() {} +func (v KeyReleaseEvent) SequenceId() uint16 { + return v.Sequence +} + func init() { newEventFuncs[3] = NewKeyReleaseEvent } @@ -5067,6 +5183,10 @@ func (v ButtonReleaseEvent) Bytes() []byte { func (v ButtonReleaseEvent) ImplementsEvent() {} +func (v ButtonReleaseEvent) SequenceId() uint16 { + return v.Sequence +} + func init() { newEventFuncs[5] = NewButtonReleaseEvent } @@ -5087,6 +5207,10 @@ func (v LeaveNotifyEvent) Bytes() []byte { func (v LeaveNotifyEvent) ImplementsEvent() {} +func (v LeaveNotifyEvent) SequenceId() uint16 { + return v.Sequence +} + func init() { newEventFuncs[8] = NewLeaveNotifyEvent } @@ -5107,6 +5231,10 @@ func (v FocusOutEvent) Bytes() []byte { func (v FocusOutEvent) ImplementsEvent() {} +func (v FocusOutEvent) SequenceId() uint16 { + return v.Sequence +} + func init() { newEventFuncs[10] = NewFocusOutEvent } @@ -5127,6 +5255,10 @@ func (v CirculateRequestEvent) Bytes() []byte { func (v CirculateRequestEvent) ImplementsEvent() {} +func (v CirculateRequestEvent) SequenceId() uint16 { + return v.Sequence +} + func init() { newEventFuncs[27] = NewCirculateRequestEvent } @@ -5798,10 +5930,25 @@ func init() { } // Request CreateWindow -// size: (28 + (4 + pad((4 * popCount(int(ValueMask)))))) +// size: pad((28 + (4 + pad((4 * popCount(int(ValueMask))))))) +type CreateWindowCookie cookie + // Write request to wire for CreateWindow -func (c *Conn) CreateWindow(Depth byte, Wid Id, Parent Id, X int16, Y int16, Width uint16, Height uint16, BorderWidth uint16, Class uint16, Visual Visualid, ValueMask uint32, ValueList []uint32) { - size := (28 + (4 + pad((4 * popCount(int(ValueMask)))))) +func (c *Conn) CreateWindow(Depth byte, Wid Id, Parent Id, X int16, Y int16, Width uint16, Height uint16, BorderWidth uint16, Class uint16, Visual Visualid, ValueMask uint32, ValueList []uint32) CreateWindowCookie { + cookie := c.newCookie(false, false) + c.newRequest(createWindowRequest(Depth, Wid, Parent, X, Y, Width, Height, BorderWidth, Class, Visual, ValueMask, ValueList), cookie) + return CreateWindowCookie(cookie) +} + +func (c *Conn) CreateWindowChecked(Depth byte, Wid Id, Parent Id, X int16, Y int16, Width uint16, Height uint16, BorderWidth uint16, Class uint16, Visual Visualid, ValueMask uint32, ValueList []uint32) CreateWindowCookie { + cookie := c.newCookie(true, false) + c.newRequest(createWindowRequest(Depth, Wid, Parent, X, Y, Width, Height, BorderWidth, Class, Visual, ValueMask, ValueList), cookie) + return CreateWindowCookie(cookie) +} + +// Write request to wire for CreateWindow +func createWindowRequest(Depth byte, Wid Id, Parent Id, X int16, Y int16, Width uint16, Height uint16, BorderWidth uint16, Class uint16, Visual Visualid, ValueMask uint32, ValueList []uint32) []byte { + size := pad((28 + (4 + pad((4 * popCount(int(ValueMask))))))) b := 0 buf := make([]byte, size) @@ -5849,14 +5996,29 @@ func (c *Conn) CreateWindow(Depth byte, Wid Id, Parent Id, X int16, Y int16, Wid } b = pad(b) - c.sendRequest(false, buf) + return buf } // Request ChangeWindowAttributes -// size: (8 + (4 + pad((4 * popCount(int(ValueMask)))))) +// size: pad((8 + (4 + pad((4 * popCount(int(ValueMask))))))) +type ChangeWindowAttributesCookie cookie + // Write request to wire for ChangeWindowAttributes -func (c *Conn) ChangeWindowAttributes(Window Id, ValueMask uint32, ValueList []uint32) { - size := (8 + (4 + pad((4 * popCount(int(ValueMask)))))) +func (c *Conn) ChangeWindowAttributes(Window Id, ValueMask uint32, ValueList []uint32) ChangeWindowAttributesCookie { + cookie := c.newCookie(false, false) + c.newRequest(changeWindowAttributesRequest(Window, ValueMask, ValueList), cookie) + return ChangeWindowAttributesCookie(cookie) +} + +func (c *Conn) ChangeWindowAttributesChecked(Window Id, ValueMask uint32, ValueList []uint32) ChangeWindowAttributesCookie { + cookie := c.newCookie(true, false) + c.newRequest(changeWindowAttributesRequest(Window, ValueMask, ValueList), cookie) + return ChangeWindowAttributesCookie(cookie) +} + +// Write request to wire for ChangeWindowAttributes +func changeWindowAttributesRequest(Window Id, ValueMask uint32, ValueList []uint32) []byte { + size := pad((8 + (4 + pad((4 * popCount(int(ValueMask))))))) b := 0 buf := make([]byte, size) @@ -5879,33 +6041,23 @@ func (c *Conn) ChangeWindowAttributes(Window Id, ValueMask uint32, ValueList []u } b = pad(b) - c.sendRequest(false, buf) + return buf } // Request GetWindowAttributes // size: 8 -func (c *Conn) GetWindowAttributes(Window Id) (*GetWindowAttributesReply, error) { - return c.GetWindowAttributesReply(c.GetWindowAttributesRequest(Window)) +type GetWindowAttributesCookie cookie + +func (c *Conn) GetWindowAttributes(Window Id) GetWindowAttributesCookie { + cookie := c.newCookie(true, true) + c.newRequest(getWindowAttributesRequest(Window), cookie) + return GetWindowAttributesCookie(cookie) } -// Write request to wire for GetWindowAttributes -func (c *Conn) GetWindowAttributesRequest(Window Id) *Cookie { - size := 8 - b := 0 - buf := make([]byte, size) - - buf[b] = 3 // request opcode - b += 1 - - b += 1 // padding - - Put16(buf[b:], uint16(size/4)) // write request size in 4-byte units - b += 2 - - Put32(buf[b:], uint32(Window)) - b += 4 - - return c.sendRequest(true, buf) +func (c *Conn) GetWindowAttributesUnchecked(Window Id) GetWindowAttributesCookie { + cookie := c.newCookie(false, true) + c.newRequest(getWindowAttributesRequest(Window), cookie) + return GetWindowAttributesCookie(cookie) } // Request reply for GetWindowAttributes @@ -5931,13 +6083,17 @@ type GetWindowAttributesReply struct { // padding: 2 bytes } -// Read reply GetWindowAttributes -func (c *Conn) GetWindowAttributesReply(cook *Cookie) (*GetWindowAttributesReply, error) { - buf, err := c.waitForReply(cook) +// Waits and reads reply data from request GetWindowAttributes +func (cook GetWindowAttributesCookie) Reply() (*GetWindowAttributesReply, error) { + buf, err := cookie(cook).reply() if err != nil { return nil, err } + return getWindowAttributesReply(buf), nil +} +// Read reply into structure from buffer for GetWindowAttributes +func getWindowAttributesReply(buf []byte) *GetWindowAttributesReply { v := new(GetWindowAttributesReply) b := 1 // skip reply determinant @@ -6006,13 +6162,48 @@ func (c *Conn) GetWindowAttributesReply(cook *Cookie) (*GetWindowAttributesReply b += 2 // padding - return v, nil + return v +} + +// Write request to wire for GetWindowAttributes +func getWindowAttributesRequest(Window Id) []byte { + size := 8 + b := 0 + buf := make([]byte, size) + + buf[b] = 3 // request opcode + b += 1 + + b += 1 // padding + + Put16(buf[b:], uint16(size/4)) // write request size in 4-byte units + b += 2 + + Put32(buf[b:], uint32(Window)) + b += 4 + + return buf } // Request DestroyWindow // size: 8 +type DestroyWindowCookie cookie + // Write request to wire for DestroyWindow -func (c *Conn) DestroyWindow(Window Id) { +func (c *Conn) DestroyWindow(Window Id) DestroyWindowCookie { + cookie := c.newCookie(false, false) + c.newRequest(destroyWindowRequest(Window), cookie) + return DestroyWindowCookie(cookie) +} + +func (c *Conn) DestroyWindowChecked(Window Id) DestroyWindowCookie { + cookie := c.newCookie(true, false) + c.newRequest(destroyWindowRequest(Window), cookie) + return DestroyWindowCookie(cookie) +} + +// Write request to wire for DestroyWindow +func destroyWindowRequest(Window Id) []byte { size := 8 b := 0 buf := make([]byte, size) @@ -6028,13 +6219,28 @@ func (c *Conn) DestroyWindow(Window Id) { Put32(buf[b:], uint32(Window)) b += 4 - c.sendRequest(false, buf) + return buf } // Request DestroySubwindows // size: 8 +type DestroySubwindowsCookie cookie + // Write request to wire for DestroySubwindows -func (c *Conn) DestroySubwindows(Window Id) { +func (c *Conn) DestroySubwindows(Window Id) DestroySubwindowsCookie { + cookie := c.newCookie(false, false) + c.newRequest(destroySubwindowsRequest(Window), cookie) + return DestroySubwindowsCookie(cookie) +} + +func (c *Conn) DestroySubwindowsChecked(Window Id) DestroySubwindowsCookie { + cookie := c.newCookie(true, false) + c.newRequest(destroySubwindowsRequest(Window), cookie) + return DestroySubwindowsCookie(cookie) +} + +// Write request to wire for DestroySubwindows +func destroySubwindowsRequest(Window Id) []byte { size := 8 b := 0 buf := make([]byte, size) @@ -6050,13 +6256,28 @@ func (c *Conn) DestroySubwindows(Window Id) { Put32(buf[b:], uint32(Window)) b += 4 - c.sendRequest(false, buf) + return buf } // Request ChangeSaveSet // size: 8 +type ChangeSaveSetCookie cookie + // Write request to wire for ChangeSaveSet -func (c *Conn) ChangeSaveSet(Mode byte, Window Id) { +func (c *Conn) ChangeSaveSet(Mode byte, Window Id) ChangeSaveSetCookie { + cookie := c.newCookie(false, false) + c.newRequest(changeSaveSetRequest(Mode, Window), cookie) + return ChangeSaveSetCookie(cookie) +} + +func (c *Conn) ChangeSaveSetChecked(Mode byte, Window Id) ChangeSaveSetCookie { + cookie := c.newCookie(true, false) + c.newRequest(changeSaveSetRequest(Mode, Window), cookie) + return ChangeSaveSetCookie(cookie) +} + +// Write request to wire for ChangeSaveSet +func changeSaveSetRequest(Mode byte, Window Id) []byte { size := 8 b := 0 buf := make([]byte, size) @@ -6073,13 +6294,28 @@ func (c *Conn) ChangeSaveSet(Mode byte, Window Id) { Put32(buf[b:], uint32(Window)) b += 4 - c.sendRequest(false, buf) + return buf } // Request ReparentWindow // size: 16 +type ReparentWindowCookie cookie + // Write request to wire for ReparentWindow -func (c *Conn) ReparentWindow(Window Id, Parent Id, X int16, Y int16) { +func (c *Conn) ReparentWindow(Window Id, Parent Id, X int16, Y int16) ReparentWindowCookie { + cookie := c.newCookie(false, false) + c.newRequest(reparentWindowRequest(Window, Parent, X, Y), cookie) + return ReparentWindowCookie(cookie) +} + +func (c *Conn) ReparentWindowChecked(Window Id, Parent Id, X int16, Y int16) ReparentWindowCookie { + cookie := c.newCookie(true, false) + c.newRequest(reparentWindowRequest(Window, Parent, X, Y), cookie) + return ReparentWindowCookie(cookie) +} + +// Write request to wire for ReparentWindow +func reparentWindowRequest(Window Id, Parent Id, X int16, Y int16) []byte { size := 16 b := 0 buf := make([]byte, size) @@ -6104,13 +6340,28 @@ func (c *Conn) ReparentWindow(Window Id, Parent Id, X int16, Y int16) { Put16(buf[b:], uint16(Y)) b += 2 - c.sendRequest(false, buf) + return buf } // Request MapWindow // size: 8 +type MapWindowCookie cookie + // Write request to wire for MapWindow -func (c *Conn) MapWindow(Window Id) { +func (c *Conn) MapWindow(Window Id) MapWindowCookie { + cookie := c.newCookie(false, false) + c.newRequest(mapWindowRequest(Window), cookie) + return MapWindowCookie(cookie) +} + +func (c *Conn) MapWindowChecked(Window Id) MapWindowCookie { + cookie := c.newCookie(true, false) + c.newRequest(mapWindowRequest(Window), cookie) + return MapWindowCookie(cookie) +} + +// Write request to wire for MapWindow +func mapWindowRequest(Window Id) []byte { size := 8 b := 0 buf := make([]byte, size) @@ -6126,13 +6377,28 @@ func (c *Conn) MapWindow(Window Id) { Put32(buf[b:], uint32(Window)) b += 4 - c.sendRequest(false, buf) + return buf } // Request MapSubwindows // size: 8 +type MapSubwindowsCookie cookie + // Write request to wire for MapSubwindows -func (c *Conn) MapSubwindows(Window Id) { +func (c *Conn) MapSubwindows(Window Id) MapSubwindowsCookie { + cookie := c.newCookie(false, false) + c.newRequest(mapSubwindowsRequest(Window), cookie) + return MapSubwindowsCookie(cookie) +} + +func (c *Conn) MapSubwindowsChecked(Window Id) MapSubwindowsCookie { + cookie := c.newCookie(true, false) + c.newRequest(mapSubwindowsRequest(Window), cookie) + return MapSubwindowsCookie(cookie) +} + +// Write request to wire for MapSubwindows +func mapSubwindowsRequest(Window Id) []byte { size := 8 b := 0 buf := make([]byte, size) @@ -6148,13 +6414,28 @@ func (c *Conn) MapSubwindows(Window Id) { Put32(buf[b:], uint32(Window)) b += 4 - c.sendRequest(false, buf) + return buf } // Request UnmapWindow // size: 8 +type UnmapWindowCookie cookie + // Write request to wire for UnmapWindow -func (c *Conn) UnmapWindow(Window Id) { +func (c *Conn) UnmapWindow(Window Id) UnmapWindowCookie { + cookie := c.newCookie(false, false) + c.newRequest(unmapWindowRequest(Window), cookie) + return UnmapWindowCookie(cookie) +} + +func (c *Conn) UnmapWindowChecked(Window Id) UnmapWindowCookie { + cookie := c.newCookie(true, false) + c.newRequest(unmapWindowRequest(Window), cookie) + return UnmapWindowCookie(cookie) +} + +// Write request to wire for UnmapWindow +func unmapWindowRequest(Window Id) []byte { size := 8 b := 0 buf := make([]byte, size) @@ -6170,13 +6451,28 @@ func (c *Conn) UnmapWindow(Window Id) { Put32(buf[b:], uint32(Window)) b += 4 - c.sendRequest(false, buf) + return buf } // Request UnmapSubwindows // size: 8 +type UnmapSubwindowsCookie cookie + // Write request to wire for UnmapSubwindows -func (c *Conn) UnmapSubwindows(Window Id) { +func (c *Conn) UnmapSubwindows(Window Id) UnmapSubwindowsCookie { + cookie := c.newCookie(false, false) + c.newRequest(unmapSubwindowsRequest(Window), cookie) + return UnmapSubwindowsCookie(cookie) +} + +func (c *Conn) UnmapSubwindowsChecked(Window Id) UnmapSubwindowsCookie { + cookie := c.newCookie(true, false) + c.newRequest(unmapSubwindowsRequest(Window), cookie) + return UnmapSubwindowsCookie(cookie) +} + +// Write request to wire for UnmapSubwindows +func unmapSubwindowsRequest(Window Id) []byte { size := 8 b := 0 buf := make([]byte, size) @@ -6192,14 +6488,29 @@ func (c *Conn) UnmapSubwindows(Window Id) { Put32(buf[b:], uint32(Window)) b += 4 - c.sendRequest(false, buf) + return buf } // Request ConfigureWindow -// size: (10 + (2 + pad((4 * popCount(int(ValueMask)))))) +// size: pad((10 + (2 + pad((4 * popCount(int(ValueMask))))))) +type ConfigureWindowCookie cookie + // Write request to wire for ConfigureWindow -func (c *Conn) ConfigureWindow(Window Id, ValueMask uint16, ValueList []uint32) { - size := (10 + (2 + pad((4 * popCount(int(ValueMask)))))) +func (c *Conn) ConfigureWindow(Window Id, ValueMask uint16, ValueList []uint32) ConfigureWindowCookie { + cookie := c.newCookie(false, false) + c.newRequest(configureWindowRequest(Window, ValueMask, ValueList), cookie) + return ConfigureWindowCookie(cookie) +} + +func (c *Conn) ConfigureWindowChecked(Window Id, ValueMask uint16, ValueList []uint32) ConfigureWindowCookie { + cookie := c.newCookie(true, false) + c.newRequest(configureWindowRequest(Window, ValueMask, ValueList), cookie) + return ConfigureWindowCookie(cookie) +} + +// Write request to wire for ConfigureWindow +func configureWindowRequest(Window Id, ValueMask uint16, ValueList []uint32) []byte { + size := pad((10 + (2 + pad((4 * popCount(int(ValueMask))))))) b := 0 buf := make([]byte, size) @@ -6225,13 +6536,28 @@ func (c *Conn) ConfigureWindow(Window Id, ValueMask uint16, ValueList []uint32) } b = pad(b) - c.sendRequest(false, buf) + return buf } // Request CirculateWindow // size: 8 +type CirculateWindowCookie cookie + // Write request to wire for CirculateWindow -func (c *Conn) CirculateWindow(Direction byte, Window Id) { +func (c *Conn) CirculateWindow(Direction byte, Window Id) CirculateWindowCookie { + cookie := c.newCookie(false, false) + c.newRequest(circulateWindowRequest(Direction, Window), cookie) + return CirculateWindowCookie(cookie) +} + +func (c *Conn) CirculateWindowChecked(Direction byte, Window Id) CirculateWindowCookie { + cookie := c.newCookie(true, false) + c.newRequest(circulateWindowRequest(Direction, Window), cookie) + return CirculateWindowCookie(cookie) +} + +// Write request to wire for CirculateWindow +func circulateWindowRequest(Direction byte, Window Id) []byte { size := 8 b := 0 buf := make([]byte, size) @@ -6248,33 +6574,23 @@ func (c *Conn) CirculateWindow(Direction byte, Window Id) { Put32(buf[b:], uint32(Window)) b += 4 - c.sendRequest(false, buf) + return buf } // Request GetGeometry // size: 8 -func (c *Conn) GetGeometry(Drawable Id) (*GetGeometryReply, error) { - return c.GetGeometryReply(c.GetGeometryRequest(Drawable)) +type GetGeometryCookie cookie + +func (c *Conn) GetGeometry(Drawable Id) GetGeometryCookie { + cookie := c.newCookie(true, true) + c.newRequest(getGeometryRequest(Drawable), cookie) + return GetGeometryCookie(cookie) } -// Write request to wire for GetGeometry -func (c *Conn) GetGeometryRequest(Drawable Id) *Cookie { - size := 8 - b := 0 - buf := make([]byte, size) - - buf[b] = 14 // request opcode - b += 1 - - b += 1 // padding - - Put16(buf[b:], uint16(size/4)) // write request size in 4-byte units - b += 2 - - Put32(buf[b:], uint32(Drawable)) - b += 4 - - return c.sendRequest(true, buf) +func (c *Conn) GetGeometryUnchecked(Drawable Id) GetGeometryCookie { + cookie := c.newCookie(false, true) + c.newRequest(getGeometryRequest(Drawable), cookie) + return GetGeometryCookie(cookie) } // Request reply for GetGeometry @@ -6292,13 +6608,17 @@ type GetGeometryReply struct { // padding: 2 bytes } -// Read reply GetGeometry -func (c *Conn) GetGeometryReply(cook *Cookie) (*GetGeometryReply, error) { - buf, err := c.waitForReply(cook) +// Waits and reads reply data from request GetGeometry +func (cook GetGeometryCookie) Reply() (*GetGeometryReply, error) { + buf, err := cookie(cook).reply() if err != nil { return nil, err } + return getGeometryReply(buf), nil +} +// Read reply into structure from buffer for GetGeometry +func getGeometryReply(buf []byte) *GetGeometryReply { v := new(GetGeometryReply) b := 1 // skip reply determinant @@ -6331,22 +6651,16 @@ func (c *Conn) GetGeometryReply(cook *Cookie) (*GetGeometryReply, error) { b += 2 // padding - return v, nil + return v } -// Request QueryTree -// size: 8 -func (c *Conn) QueryTree(Window Id) (*QueryTreeReply, error) { - return c.QueryTreeReply(c.QueryTreeRequest(Window)) -} - -// Write request to wire for QueryTree -func (c *Conn) QueryTreeRequest(Window Id) *Cookie { +// Write request to wire for GetGeometry +func getGeometryRequest(Drawable Id) []byte { size := 8 b := 0 buf := make([]byte, size) - buf[b] = 15 // request opcode + buf[b] = 14 // request opcode b += 1 b += 1 // padding @@ -6354,10 +6668,26 @@ func (c *Conn) QueryTreeRequest(Window Id) *Cookie { Put16(buf[b:], uint16(size/4)) // write request size in 4-byte units b += 2 - Put32(buf[b:], uint32(Window)) + Put32(buf[b:], uint32(Drawable)) b += 4 - return c.sendRequest(true, buf) + return buf +} + +// Request QueryTree +// size: 8 +type QueryTreeCookie cookie + +func (c *Conn) QueryTree(Window Id) QueryTreeCookie { + cookie := c.newCookie(true, true) + c.newRequest(queryTreeRequest(Window), cookie) + return QueryTreeCookie(cookie) +} + +func (c *Conn) QueryTreeUnchecked(Window Id) QueryTreeCookie { + cookie := c.newCookie(false, true) + c.newRequest(queryTreeRequest(Window), cookie) + return QueryTreeCookie(cookie) } // Request reply for QueryTree @@ -6373,13 +6703,17 @@ type QueryTreeReply struct { Children []Id // size: pad((int(ChildrenLen) * 4)) } -// Read reply QueryTree -func (c *Conn) QueryTreeReply(cook *Cookie) (*QueryTreeReply, error) { - buf, err := c.waitForReply(cook) +// Waits and reads reply data from request QueryTree +func (cook QueryTreeCookie) Reply() (*QueryTreeReply, error) { + buf, err := cookie(cook).reply() if err != nil { return nil, err } + return queryTreeReply(buf), nil +} +// Read reply into structure from buffer for QueryTree +func queryTreeReply(buf []byte) *QueryTreeReply { v := new(QueryTreeReply) b := 1 // skip reply determinant @@ -6409,18 +6743,85 @@ func (c *Conn) QueryTreeReply(cook *Cookie) (*QueryTreeReply, error) { } b = pad(b) - return v, nil + return v +} + +// Write request to wire for QueryTree +func queryTreeRequest(Window Id) []byte { + size := 8 + b := 0 + buf := make([]byte, size) + + buf[b] = 15 // request opcode + b += 1 + + b += 1 // padding + + Put16(buf[b:], uint16(size/4)) // write request size in 4-byte units + b += 2 + + Put32(buf[b:], uint32(Window)) + b += 4 + + return buf } // Request InternAtom -// size: (8 + pad((int(NameLen) * 1))) -func (c *Conn) InternAtom(OnlyIfExists bool, NameLen uint16, Name string) (*InternAtomReply, error) { - return c.InternAtomReply(c.InternAtomRequest(OnlyIfExists, NameLen, Name)) +// size: pad((8 + pad((int(NameLen) * 1)))) +type InternAtomCookie cookie + +func (c *Conn) InternAtom(OnlyIfExists bool, NameLen uint16, Name string) InternAtomCookie { + cookie := c.newCookie(true, true) + c.newRequest(internAtomRequest(OnlyIfExists, NameLen, Name), cookie) + return InternAtomCookie(cookie) +} + +func (c *Conn) InternAtomUnchecked(OnlyIfExists bool, NameLen uint16, Name string) InternAtomCookie { + cookie := c.newCookie(false, true) + c.newRequest(internAtomRequest(OnlyIfExists, NameLen, Name), cookie) + return InternAtomCookie(cookie) +} + +// Request reply for InternAtom +// size: 12 +type InternAtomReply struct { + Sequence uint16 + Length uint32 + // padding: 1 bytes + Atom Id +} + +// Waits and reads reply data from request InternAtom +func (cook InternAtomCookie) Reply() (*InternAtomReply, error) { + buf, err := cookie(cook).reply() + if err != nil { + return nil, err + } + return internAtomReply(buf), nil +} + +// Read reply into structure from buffer for InternAtom +func internAtomReply(buf []byte) *InternAtomReply { + v := new(InternAtomReply) + b := 1 // skip reply determinant + + b += 1 // padding + + v.Sequence = Get16(buf[b:]) + b += 2 + + v.Length = Get32(buf[b:]) // 4-byte units + b += 4 + + v.Atom = Id(Get32(buf[b:])) + b += 4 + + return v } // Write request to wire for InternAtom -func (c *Conn) InternAtomRequest(OnlyIfExists bool, NameLen uint16, Name string) *Cookie { - size := (8 + pad((int(NameLen) * 1))) +func internAtomRequest(OnlyIfExists bool, NameLen uint16, Name string) []byte { + size := pad((8 + pad((int(NameLen) * 1)))) b := 0 buf := make([]byte, size) @@ -6445,66 +6846,23 @@ func (c *Conn) InternAtomRequest(OnlyIfExists bool, NameLen uint16, Name string) copy(buf[b:], Name[:NameLen]) b += pad(int(NameLen)) - return c.sendRequest(true, buf) -} - -// Request reply for InternAtom -// size: 12 -type InternAtomReply struct { - Sequence uint16 - Length uint32 - // padding: 1 bytes - Atom Id -} - -// Read reply InternAtom -func (c *Conn) InternAtomReply(cook *Cookie) (*InternAtomReply, error) { - buf, err := c.waitForReply(cook) - if err != nil { - return nil, err - } - - v := new(InternAtomReply) - b := 1 // skip reply determinant - - b += 1 // padding - - v.Sequence = Get16(buf[b:]) - b += 2 - - v.Length = Get32(buf[b:]) // 4-byte units - b += 4 - - v.Atom = Id(Get32(buf[b:])) - b += 4 - - return v, nil + return buf } // Request GetAtomName // size: 8 -func (c *Conn) GetAtomName(Atom Id) (*GetAtomNameReply, error) { - return c.GetAtomNameReply(c.GetAtomNameRequest(Atom)) +type GetAtomNameCookie cookie + +func (c *Conn) GetAtomName(Atom Id) GetAtomNameCookie { + cookie := c.newCookie(true, true) + c.newRequest(getAtomNameRequest(Atom), cookie) + return GetAtomNameCookie(cookie) } -// Write request to wire for GetAtomName -func (c *Conn) GetAtomNameRequest(Atom Id) *Cookie { - size := 8 - b := 0 - buf := make([]byte, size) - - buf[b] = 17 // request opcode - b += 1 - - b += 1 // padding - - Put16(buf[b:], uint16(size/4)) // write request size in 4-byte units - b += 2 - - Put32(buf[b:], uint32(Atom)) - b += 4 - - return c.sendRequest(true, buf) +func (c *Conn) GetAtomNameUnchecked(Atom Id) GetAtomNameCookie { + cookie := c.newCookie(false, true) + c.newRequest(getAtomNameRequest(Atom), cookie) + return GetAtomNameCookie(cookie) } // Request reply for GetAtomName @@ -6518,13 +6876,17 @@ type GetAtomNameReply struct { Name string // size: pad((int(NameLen) * 1)) } -// Read reply GetAtomName -func (c *Conn) GetAtomNameReply(cook *Cookie) (*GetAtomNameReply, error) { - buf, err := c.waitForReply(cook) +// Waits and reads reply data from request GetAtomName +func (cook GetAtomNameCookie) Reply() (*GetAtomNameReply, error) { + buf, err := cookie(cook).reply() if err != nil { return nil, err } + return getAtomNameReply(buf), nil +} +// Read reply into structure from buffer for GetAtomName +func getAtomNameReply(buf []byte) *GetAtomNameReply { v := new(GetAtomNameReply) b := 1 // skip reply determinant @@ -6548,14 +6910,49 @@ func (c *Conn) GetAtomNameReply(cook *Cookie) (*GetAtomNameReply, error) { b += pad(int(v.NameLen)) } - return v, nil + return v +} + +// Write request to wire for GetAtomName +func getAtomNameRequest(Atom Id) []byte { + size := 8 + b := 0 + buf := make([]byte, size) + + buf[b] = 17 // request opcode + b += 1 + + b += 1 // padding + + Put16(buf[b:], uint16(size/4)) // write request size in 4-byte units + b += 2 + + Put32(buf[b:], uint32(Atom)) + b += 4 + + return buf } // Request ChangeProperty -// size: (24 + pad((((int(DataLen) * int(Format)) / 8) * 1))) +// size: pad((24 + pad((((int(DataLen) * int(Format)) / 8) * 1)))) +type ChangePropertyCookie cookie + // Write request to wire for ChangeProperty -func (c *Conn) ChangeProperty(Mode byte, Window Id, Property Id, Type Id, Format byte, DataLen uint32, Data []byte) { - size := (24 + pad((((int(DataLen) * int(Format)) / 8) * 1))) +func (c *Conn) ChangeProperty(Mode byte, Window Id, Property Id, Type Id, Format byte, DataLen uint32, Data []byte) ChangePropertyCookie { + cookie := c.newCookie(false, false) + c.newRequest(changePropertyRequest(Mode, Window, Property, Type, Format, DataLen, Data), cookie) + return ChangePropertyCookie(cookie) +} + +func (c *Conn) ChangePropertyChecked(Mode byte, Window Id, Property Id, Type Id, Format byte, DataLen uint32, Data []byte) ChangePropertyCookie { + cookie := c.newCookie(true, false) + c.newRequest(changePropertyRequest(Mode, Window, Property, Type, Format, DataLen, Data), cookie) + return ChangePropertyCookie(cookie) +} + +// Write request to wire for ChangeProperty +func changePropertyRequest(Mode byte, Window Id, Property Id, Type Id, Format byte, DataLen uint32, Data []byte) []byte { + size := pad((24 + pad((((int(DataLen) * int(Format)) / 8) * 1)))) b := 0 buf := make([]byte, size) @@ -6588,13 +6985,28 @@ func (c *Conn) ChangeProperty(Mode byte, Window Id, Property Id, Type Id, Format copy(buf[b:], Data[:((int(DataLen)*int(Format))/8)]) b += pad(int(((int(DataLen) * int(Format)) / 8))) - c.sendRequest(false, buf) + return buf } // Request DeleteProperty // size: 12 +type DeletePropertyCookie cookie + // Write request to wire for DeleteProperty -func (c *Conn) DeleteProperty(Window Id, Property Id) { +func (c *Conn) DeleteProperty(Window Id, Property Id) DeletePropertyCookie { + cookie := c.newCookie(false, false) + c.newRequest(deletePropertyRequest(Window, Property), cookie) + return DeletePropertyCookie(cookie) +} + +func (c *Conn) DeletePropertyChecked(Window Id, Property Id) DeletePropertyCookie { + cookie := c.newCookie(true, false) + c.newRequest(deletePropertyRequest(Window, Property), cookie) + return DeletePropertyCookie(cookie) +} + +// Write request to wire for DeleteProperty +func deletePropertyRequest(Window Id, Property Id) []byte { size := 12 b := 0 buf := make([]byte, size) @@ -6613,17 +7025,81 @@ func (c *Conn) DeleteProperty(Window Id, Property Id) { Put32(buf[b:], uint32(Property)) b += 4 - c.sendRequest(false, buf) + return buf } // Request GetProperty // size: 24 -func (c *Conn) GetProperty(Delete bool, Window Id, Property Id, Type Id, LongOffset uint32, LongLength uint32) (*GetPropertyReply, error) { - return c.GetPropertyReply(c.GetPropertyRequest(Delete, Window, Property, Type, LongOffset, LongLength)) +type GetPropertyCookie cookie + +func (c *Conn) GetProperty(Delete bool, Window Id, Property Id, Type Id, LongOffset uint32, LongLength uint32) GetPropertyCookie { + cookie := c.newCookie(true, true) + c.newRequest(getPropertyRequest(Delete, Window, Property, Type, LongOffset, LongLength), cookie) + return GetPropertyCookie(cookie) +} + +func (c *Conn) GetPropertyUnchecked(Delete bool, Window Id, Property Id, Type Id, LongOffset uint32, LongLength uint32) GetPropertyCookie { + cookie := c.newCookie(false, true) + c.newRequest(getPropertyRequest(Delete, Window, Property, Type, LongOffset, LongLength), cookie) + return GetPropertyCookie(cookie) +} + +// Request reply for GetProperty +// size: (32 + pad(((int(ValueLen) * (int(Format) / 8)) * 1))) +type GetPropertyReply struct { + Sequence uint16 + Length uint32 + Format byte + Type Id + BytesAfter uint32 + ValueLen uint32 + // padding: 12 bytes + Value []byte // size: pad(((int(ValueLen) * (int(Format) / 8)) * 1)) +} + +// Waits and reads reply data from request GetProperty +func (cook GetPropertyCookie) Reply() (*GetPropertyReply, error) { + buf, err := cookie(cook).reply() + if err != nil { + return nil, err + } + return getPropertyReply(buf), nil +} + +// Read reply into structure from buffer for GetProperty +func getPropertyReply(buf []byte) *GetPropertyReply { + v := new(GetPropertyReply) + b := 1 // skip reply determinant + + v.Format = buf[b] + b += 1 + + v.Sequence = Get16(buf[b:]) + b += 2 + + v.Length = Get32(buf[b:]) // 4-byte units + b += 4 + + v.Type = Id(Get32(buf[b:])) + b += 4 + + v.BytesAfter = Get32(buf[b:]) + b += 4 + + v.ValueLen = Get32(buf[b:]) + b += 4 + + b += 12 // padding + + v.Value = make([]byte, (int(v.ValueLen) * (int(v.Format) / 8))) + copy(v.Value[:(int(v.ValueLen)*(int(v.Format)/8))], buf[b:]) + b += pad(int((int(v.ValueLen) * (int(v.Format) / 8)))) + + return v } // Write request to wire for GetProperty -func (c *Conn) GetPropertyRequest(Delete bool, Window Id, Property Id, Type Id, LongOffset uint32, LongLength uint32) *Cookie { +func getPropertyRequest(Delete bool, Window Id, Property Id, Type Id, LongOffset uint32, LongLength uint32) []byte { size := 24 b := 0 buf := make([]byte, size) @@ -6656,83 +7132,23 @@ func (c *Conn) GetPropertyRequest(Delete bool, Window Id, Property Id, Type Id, Put32(buf[b:], LongLength) b += 4 - return c.sendRequest(true, buf) -} - -// Request reply for GetProperty -// size: (32 + pad(((int(ValueLen) * (int(Format) / 8)) * 1))) -type GetPropertyReply struct { - Sequence uint16 - Length uint32 - Format byte - Type Id - BytesAfter uint32 - ValueLen uint32 - // padding: 12 bytes - Value []byte // size: pad(((int(ValueLen) * (int(Format) / 8)) * 1)) -} - -// Read reply GetProperty -func (c *Conn) GetPropertyReply(cook *Cookie) (*GetPropertyReply, error) { - buf, err := c.waitForReply(cook) - if err != nil { - return nil, err - } - - v := new(GetPropertyReply) - b := 1 // skip reply determinant - - v.Format = buf[b] - b += 1 - - v.Sequence = Get16(buf[b:]) - b += 2 - - v.Length = Get32(buf[b:]) // 4-byte units - b += 4 - - v.Type = Id(Get32(buf[b:])) - b += 4 - - v.BytesAfter = Get32(buf[b:]) - b += 4 - - v.ValueLen = Get32(buf[b:]) - b += 4 - - b += 12 // padding - - v.Value = make([]byte, (int(v.ValueLen) * (int(v.Format) / 8))) - copy(v.Value[:(int(v.ValueLen)*(int(v.Format)/8))], buf[b:]) - b += pad(int((int(v.ValueLen) * (int(v.Format) / 8)))) - - return v, nil + return buf } // Request ListProperties // size: 8 -func (c *Conn) ListProperties(Window Id) (*ListPropertiesReply, error) { - return c.ListPropertiesReply(c.ListPropertiesRequest(Window)) +type ListPropertiesCookie cookie + +func (c *Conn) ListProperties(Window Id) ListPropertiesCookie { + cookie := c.newCookie(true, true) + c.newRequest(listPropertiesRequest(Window), cookie) + return ListPropertiesCookie(cookie) } -// Write request to wire for ListProperties -func (c *Conn) ListPropertiesRequest(Window Id) *Cookie { - size := 8 - b := 0 - buf := make([]byte, size) - - buf[b] = 21 // request opcode - b += 1 - - b += 1 // padding - - Put16(buf[b:], uint16(size/4)) // write request size in 4-byte units - b += 2 - - Put32(buf[b:], uint32(Window)) - b += 4 - - return c.sendRequest(true, buf) +func (c *Conn) ListPropertiesUnchecked(Window Id) ListPropertiesCookie { + cookie := c.newCookie(false, true) + c.newRequest(listPropertiesRequest(Window), cookie) + return ListPropertiesCookie(cookie) } // Request reply for ListProperties @@ -6746,13 +7162,17 @@ type ListPropertiesReply struct { Atoms []Id // size: pad((int(AtomsLen) * 4)) } -// Read reply ListProperties -func (c *Conn) ListPropertiesReply(cook *Cookie) (*ListPropertiesReply, error) { - buf, err := c.waitForReply(cook) +// Waits and reads reply data from request ListProperties +func (cook ListPropertiesCookie) Reply() (*ListPropertiesReply, error) { + buf, err := cookie(cook).reply() if err != nil { return nil, err } + return listPropertiesReply(buf), nil +} +// Read reply into structure from buffer for ListProperties +func listPropertiesReply(buf []byte) *ListPropertiesReply { v := new(ListPropertiesReply) b := 1 // skip reply determinant @@ -6776,13 +7196,48 @@ func (c *Conn) ListPropertiesReply(cook *Cookie) (*ListPropertiesReply, error) { } b = pad(b) - return v, nil + return v +} + +// Write request to wire for ListProperties +func listPropertiesRequest(Window Id) []byte { + size := 8 + b := 0 + buf := make([]byte, size) + + buf[b] = 21 // request opcode + b += 1 + + b += 1 // padding + + Put16(buf[b:], uint16(size/4)) // write request size in 4-byte units + b += 2 + + Put32(buf[b:], uint32(Window)) + b += 4 + + return buf } // Request SetSelectionOwner // size: 16 +type SetSelectionOwnerCookie cookie + // Write request to wire for SetSelectionOwner -func (c *Conn) SetSelectionOwner(Owner Id, Selection Id, Time Timestamp) { +func (c *Conn) SetSelectionOwner(Owner Id, Selection Id, Time Timestamp) SetSelectionOwnerCookie { + cookie := c.newCookie(false, false) + c.newRequest(setSelectionOwnerRequest(Owner, Selection, Time), cookie) + return SetSelectionOwnerCookie(cookie) +} + +func (c *Conn) SetSelectionOwnerChecked(Owner Id, Selection Id, Time Timestamp) SetSelectionOwnerCookie { + cookie := c.newCookie(true, false) + c.newRequest(setSelectionOwnerRequest(Owner, Selection, Time), cookie) + return SetSelectionOwnerCookie(cookie) +} + +// Write request to wire for SetSelectionOwner +func setSelectionOwnerRequest(Owner Id, Selection Id, Time Timestamp) []byte { size := 16 b := 0 buf := make([]byte, size) @@ -6804,17 +7259,64 @@ func (c *Conn) SetSelectionOwner(Owner Id, Selection Id, Time Timestamp) { Put32(buf[b:], uint32(Time)) b += 4 - c.sendRequest(false, buf) + return buf } // Request GetSelectionOwner // size: 8 -func (c *Conn) GetSelectionOwner(Selection Id) (*GetSelectionOwnerReply, error) { - return c.GetSelectionOwnerReply(c.GetSelectionOwnerRequest(Selection)) +type GetSelectionOwnerCookie cookie + +func (c *Conn) GetSelectionOwner(Selection Id) GetSelectionOwnerCookie { + cookie := c.newCookie(true, true) + c.newRequest(getSelectionOwnerRequest(Selection), cookie) + return GetSelectionOwnerCookie(cookie) +} + +func (c *Conn) GetSelectionOwnerUnchecked(Selection Id) GetSelectionOwnerCookie { + cookie := c.newCookie(false, true) + c.newRequest(getSelectionOwnerRequest(Selection), cookie) + return GetSelectionOwnerCookie(cookie) +} + +// Request reply for GetSelectionOwner +// size: 12 +type GetSelectionOwnerReply struct { + Sequence uint16 + Length uint32 + // padding: 1 bytes + Owner Id +} + +// Waits and reads reply data from request GetSelectionOwner +func (cook GetSelectionOwnerCookie) Reply() (*GetSelectionOwnerReply, error) { + buf, err := cookie(cook).reply() + if err != nil { + return nil, err + } + return getSelectionOwnerReply(buf), nil +} + +// Read reply into structure from buffer for GetSelectionOwner +func getSelectionOwnerReply(buf []byte) *GetSelectionOwnerReply { + v := new(GetSelectionOwnerReply) + b := 1 // skip reply determinant + + b += 1 // padding + + v.Sequence = Get16(buf[b:]) + b += 2 + + v.Length = Get32(buf[b:]) // 4-byte units + b += 4 + + v.Owner = Id(Get32(buf[b:])) + b += 4 + + return v } // Write request to wire for GetSelectionOwner -func (c *Conn) GetSelectionOwnerRequest(Selection Id) *Cookie { +func getSelectionOwnerRequest(Selection Id) []byte { size := 8 b := 0 buf := make([]byte, size) @@ -6830,46 +7332,28 @@ func (c *Conn) GetSelectionOwnerRequest(Selection Id) *Cookie { Put32(buf[b:], uint32(Selection)) b += 4 - return c.sendRequest(true, buf) -} - -// Request reply for GetSelectionOwner -// size: 12 -type GetSelectionOwnerReply struct { - Sequence uint16 - Length uint32 - // padding: 1 bytes - Owner Id -} - -// Read reply GetSelectionOwner -func (c *Conn) GetSelectionOwnerReply(cook *Cookie) (*GetSelectionOwnerReply, error) { - buf, err := c.waitForReply(cook) - if err != nil { - return nil, err - } - - v := new(GetSelectionOwnerReply) - b := 1 // skip reply determinant - - b += 1 // padding - - v.Sequence = Get16(buf[b:]) - b += 2 - - v.Length = Get32(buf[b:]) // 4-byte units - b += 4 - - v.Owner = Id(Get32(buf[b:])) - b += 4 - - return v, nil + return buf } // Request ConvertSelection // size: 24 +type ConvertSelectionCookie cookie + // Write request to wire for ConvertSelection -func (c *Conn) ConvertSelection(Requestor Id, Selection Id, Target Id, Property Id, Time Timestamp) { +func (c *Conn) ConvertSelection(Requestor Id, Selection Id, Target Id, Property Id, Time Timestamp) ConvertSelectionCookie { + cookie := c.newCookie(false, false) + c.newRequest(convertSelectionRequest(Requestor, Selection, Target, Property, Time), cookie) + return ConvertSelectionCookie(cookie) +} + +func (c *Conn) ConvertSelectionChecked(Requestor Id, Selection Id, Target Id, Property Id, Time Timestamp) ConvertSelectionCookie { + cookie := c.newCookie(true, false) + c.newRequest(convertSelectionRequest(Requestor, Selection, Target, Property, Time), cookie) + return ConvertSelectionCookie(cookie) +} + +// Write request to wire for ConvertSelection +func convertSelectionRequest(Requestor Id, Selection Id, Target Id, Property Id, Time Timestamp) []byte { size := 24 b := 0 buf := make([]byte, size) @@ -6897,14 +7381,29 @@ func (c *Conn) ConvertSelection(Requestor Id, Selection Id, Target Id, Property Put32(buf[b:], uint32(Time)) b += 4 - c.sendRequest(false, buf) + return buf } // Request SendEvent -// size: (12 + pad(32)) +// size: pad((12 + pad(32))) +type SendEventCookie cookie + // Write request to wire for SendEvent -func (c *Conn) SendEvent(Propagate bool, Destination Id, EventMask uint32, Event string) { - size := (12 + pad(32)) +func (c *Conn) SendEvent(Propagate bool, Destination Id, EventMask uint32, Event string) SendEventCookie { + cookie := c.newCookie(false, false) + c.newRequest(sendEventRequest(Propagate, Destination, EventMask, Event), cookie) + return SendEventCookie(cookie) +} + +func (c *Conn) SendEventChecked(Propagate bool, Destination Id, EventMask uint32, Event string) SendEventCookie { + cookie := c.newCookie(true, false) + c.newRequest(sendEventRequest(Propagate, Destination, EventMask, Event), cookie) + return SendEventCookie(cookie) +} + +// Write request to wire for SendEvent +func sendEventRequest(Propagate bool, Destination Id, EventMask uint32, Event string) []byte { + size := pad((12 + pad(32))) b := 0 buf := make([]byte, size) @@ -6930,17 +7429,55 @@ func (c *Conn) SendEvent(Propagate bool, Destination Id, EventMask uint32, Event copy(buf[b:], Event[:32]) b += pad(int(32)) - c.sendRequest(false, buf) + return buf } // Request GrabPointer // size: 24 -func (c *Conn) GrabPointer(OwnerEvents bool, GrabWindow Id, EventMask uint16, PointerMode byte, KeyboardMode byte, ConfineTo Id, Cursor Id, Time Timestamp) (*GrabPointerReply, error) { - return c.GrabPointerReply(c.GrabPointerRequest(OwnerEvents, GrabWindow, EventMask, PointerMode, KeyboardMode, ConfineTo, Cursor, Time)) +type GrabPointerCookie cookie + +func (c *Conn) GrabPointer(OwnerEvents bool, GrabWindow Id, EventMask uint16, PointerMode byte, KeyboardMode byte, ConfineTo Id, Cursor Id, Time Timestamp) GrabPointerCookie { + cookie := c.newCookie(true, true) + c.newRequest(grabPointerRequest(OwnerEvents, GrabWindow, EventMask, PointerMode, KeyboardMode, ConfineTo, Cursor, Time), cookie) + return GrabPointerCookie(cookie) +} + +func (c *Conn) GrabPointerUnchecked(OwnerEvents bool, GrabWindow Id, EventMask uint16, PointerMode byte, KeyboardMode byte, ConfineTo Id, Cursor Id, Time Timestamp) GrabPointerCookie { + cookie := c.newCookie(false, true) + c.newRequest(grabPointerRequest(OwnerEvents, GrabWindow, EventMask, PointerMode, KeyboardMode, ConfineTo, Cursor, Time), cookie) + return GrabPointerCookie(cookie) +} + +// Request reply for GrabPointer +// size: 8 +type GrabPointerReply struct { + Sequence uint16 + Length uint32 + Status byte +} + +// Waits and reads reply data from request GrabPointer +func (cook GrabPointerCookie) Reply() (*GrabPointerReply, error) { + buf, err := cookie(cook).reply() + if err != nil { + return nil, err + } + return grabPointerReply(buf), nil +} + +// Read reply into structure from buffer for GrabPointer +func grabPointerReply(buf []byte) *GrabPointerReply { + v := new(GrabPointerReply) + b := 1 // skip reply determinant + + v.Status = buf[b] + b += 1 + + return v } // Write request to wire for GrabPointer -func (c *Conn) GrabPointerRequest(OwnerEvents bool, GrabWindow Id, EventMask uint16, PointerMode byte, KeyboardMode byte, ConfineTo Id, Cursor Id, Time Timestamp) *Cookie { +func grabPointerRequest(OwnerEvents bool, GrabWindow Id, EventMask uint16, PointerMode byte, KeyboardMode byte, ConfineTo Id, Cursor Id, Time Timestamp) []byte { size := 24 b := 0 buf := make([]byte, size) @@ -6979,37 +7516,28 @@ func (c *Conn) GrabPointerRequest(OwnerEvents bool, GrabWindow Id, EventMask uin Put32(buf[b:], uint32(Time)) b += 4 - return c.sendRequest(true, buf) -} - -// Request reply for GrabPointer -// size: 8 -type GrabPointerReply struct { - Sequence uint16 - Length uint32 - Status byte -} - -// Read reply GrabPointer -func (c *Conn) GrabPointerReply(cook *Cookie) (*GrabPointerReply, error) { - buf, err := c.waitForReply(cook) - if err != nil { - return nil, err - } - - v := new(GrabPointerReply) - b := 1 // skip reply determinant - - v.Status = buf[b] - b += 1 - - return v, nil + return buf } // Request UngrabPointer // size: 8 +type UngrabPointerCookie cookie + // Write request to wire for UngrabPointer -func (c *Conn) UngrabPointer(Time Timestamp) { +func (c *Conn) UngrabPointer(Time Timestamp) UngrabPointerCookie { + cookie := c.newCookie(false, false) + c.newRequest(ungrabPointerRequest(Time), cookie) + return UngrabPointerCookie(cookie) +} + +func (c *Conn) UngrabPointerChecked(Time Timestamp) UngrabPointerCookie { + cookie := c.newCookie(true, false) + c.newRequest(ungrabPointerRequest(Time), cookie) + return UngrabPointerCookie(cookie) +} + +// Write request to wire for UngrabPointer +func ungrabPointerRequest(Time Timestamp) []byte { size := 8 b := 0 buf := make([]byte, size) @@ -7025,13 +7553,28 @@ func (c *Conn) UngrabPointer(Time Timestamp) { Put32(buf[b:], uint32(Time)) b += 4 - c.sendRequest(false, buf) + return buf } // Request GrabButton // size: 24 +type GrabButtonCookie cookie + // Write request to wire for GrabButton -func (c *Conn) GrabButton(OwnerEvents bool, GrabWindow Id, EventMask uint16, PointerMode byte, KeyboardMode byte, ConfineTo Id, Cursor Id, Button byte, Modifiers uint16) { +func (c *Conn) GrabButton(OwnerEvents bool, GrabWindow Id, EventMask uint16, PointerMode byte, KeyboardMode byte, ConfineTo Id, Cursor Id, Button byte, Modifiers uint16) GrabButtonCookie { + cookie := c.newCookie(false, false) + c.newRequest(grabButtonRequest(OwnerEvents, GrabWindow, EventMask, PointerMode, KeyboardMode, ConfineTo, Cursor, Button, Modifiers), cookie) + return GrabButtonCookie(cookie) +} + +func (c *Conn) GrabButtonChecked(OwnerEvents bool, GrabWindow Id, EventMask uint16, PointerMode byte, KeyboardMode byte, ConfineTo Id, Cursor Id, Button byte, Modifiers uint16) GrabButtonCookie { + cookie := c.newCookie(true, false) + c.newRequest(grabButtonRequest(OwnerEvents, GrabWindow, EventMask, PointerMode, KeyboardMode, ConfineTo, Cursor, Button, Modifiers), cookie) + return GrabButtonCookie(cookie) +} + +// Write request to wire for GrabButton +func grabButtonRequest(OwnerEvents bool, GrabWindow Id, EventMask uint16, PointerMode byte, KeyboardMode byte, ConfineTo Id, Cursor Id, Button byte, Modifiers uint16) []byte { size := 24 b := 0 buf := make([]byte, size) @@ -7075,13 +7618,28 @@ func (c *Conn) GrabButton(OwnerEvents bool, GrabWindow Id, EventMask uint16, Poi Put16(buf[b:], Modifiers) b += 2 - c.sendRequest(false, buf) + return buf } // Request UngrabButton // size: 12 +type UngrabButtonCookie cookie + // Write request to wire for UngrabButton -func (c *Conn) UngrabButton(Button byte, GrabWindow Id, Modifiers uint16) { +func (c *Conn) UngrabButton(Button byte, GrabWindow Id, Modifiers uint16) UngrabButtonCookie { + cookie := c.newCookie(false, false) + c.newRequest(ungrabButtonRequest(Button, GrabWindow, Modifiers), cookie) + return UngrabButtonCookie(cookie) +} + +func (c *Conn) UngrabButtonChecked(Button byte, GrabWindow Id, Modifiers uint16) UngrabButtonCookie { + cookie := c.newCookie(true, false) + c.newRequest(ungrabButtonRequest(Button, GrabWindow, Modifiers), cookie) + return UngrabButtonCookie(cookie) +} + +// Write request to wire for UngrabButton +func ungrabButtonRequest(Button byte, GrabWindow Id, Modifiers uint16) []byte { size := 12 b := 0 buf := make([]byte, size) @@ -7103,13 +7661,28 @@ func (c *Conn) UngrabButton(Button byte, GrabWindow Id, Modifiers uint16) { b += 2 // padding - c.sendRequest(false, buf) + return buf } // Request ChangeActivePointerGrab // size: 16 +type ChangeActivePointerGrabCookie cookie + // Write request to wire for ChangeActivePointerGrab -func (c *Conn) ChangeActivePointerGrab(Cursor Id, Time Timestamp, EventMask uint16) { +func (c *Conn) ChangeActivePointerGrab(Cursor Id, Time Timestamp, EventMask uint16) ChangeActivePointerGrabCookie { + cookie := c.newCookie(false, false) + c.newRequest(changeActivePointerGrabRequest(Cursor, Time, EventMask), cookie) + return ChangeActivePointerGrabCookie(cookie) +} + +func (c *Conn) ChangeActivePointerGrabChecked(Cursor Id, Time Timestamp, EventMask uint16) ChangeActivePointerGrabCookie { + cookie := c.newCookie(true, false) + c.newRequest(changeActivePointerGrabRequest(Cursor, Time, EventMask), cookie) + return ChangeActivePointerGrabCookie(cookie) +} + +// Write request to wire for ChangeActivePointerGrab +func changeActivePointerGrabRequest(Cursor Id, Time Timestamp, EventMask uint16) []byte { size := 16 b := 0 buf := make([]byte, size) @@ -7133,17 +7706,55 @@ func (c *Conn) ChangeActivePointerGrab(Cursor Id, Time Timestamp, EventMask uint b += 2 // padding - c.sendRequest(false, buf) + return buf } // Request GrabKeyboard // size: 16 -func (c *Conn) GrabKeyboard(OwnerEvents bool, GrabWindow Id, Time Timestamp, PointerMode byte, KeyboardMode byte) (*GrabKeyboardReply, error) { - return c.GrabKeyboardReply(c.GrabKeyboardRequest(OwnerEvents, GrabWindow, Time, PointerMode, KeyboardMode)) +type GrabKeyboardCookie cookie + +func (c *Conn) GrabKeyboard(OwnerEvents bool, GrabWindow Id, Time Timestamp, PointerMode byte, KeyboardMode byte) GrabKeyboardCookie { + cookie := c.newCookie(true, true) + c.newRequest(grabKeyboardRequest(OwnerEvents, GrabWindow, Time, PointerMode, KeyboardMode), cookie) + return GrabKeyboardCookie(cookie) +} + +func (c *Conn) GrabKeyboardUnchecked(OwnerEvents bool, GrabWindow Id, Time Timestamp, PointerMode byte, KeyboardMode byte) GrabKeyboardCookie { + cookie := c.newCookie(false, true) + c.newRequest(grabKeyboardRequest(OwnerEvents, GrabWindow, Time, PointerMode, KeyboardMode), cookie) + return GrabKeyboardCookie(cookie) +} + +// Request reply for GrabKeyboard +// size: 8 +type GrabKeyboardReply struct { + Sequence uint16 + Length uint32 + Status byte +} + +// Waits and reads reply data from request GrabKeyboard +func (cook GrabKeyboardCookie) Reply() (*GrabKeyboardReply, error) { + buf, err := cookie(cook).reply() + if err != nil { + return nil, err + } + return grabKeyboardReply(buf), nil +} + +// Read reply into structure from buffer for GrabKeyboard +func grabKeyboardReply(buf []byte) *GrabKeyboardReply { + v := new(GrabKeyboardReply) + b := 1 // skip reply determinant + + v.Status = buf[b] + b += 1 + + return v } // Write request to wire for GrabKeyboard -func (c *Conn) GrabKeyboardRequest(OwnerEvents bool, GrabWindow Id, Time Timestamp, PointerMode byte, KeyboardMode byte) *Cookie { +func grabKeyboardRequest(OwnerEvents bool, GrabWindow Id, Time Timestamp, PointerMode byte, KeyboardMode byte) []byte { size := 16 b := 0 buf := make([]byte, size) @@ -7175,37 +7786,28 @@ func (c *Conn) GrabKeyboardRequest(OwnerEvents bool, GrabWindow Id, Time Timesta b += 2 // padding - return c.sendRequest(true, buf) -} - -// Request reply for GrabKeyboard -// size: 8 -type GrabKeyboardReply struct { - Sequence uint16 - Length uint32 - Status byte -} - -// Read reply GrabKeyboard -func (c *Conn) GrabKeyboardReply(cook *Cookie) (*GrabKeyboardReply, error) { - buf, err := c.waitForReply(cook) - if err != nil { - return nil, err - } - - v := new(GrabKeyboardReply) - b := 1 // skip reply determinant - - v.Status = buf[b] - b += 1 - - return v, nil + return buf } // Request UngrabKeyboard // size: 8 +type UngrabKeyboardCookie cookie + // Write request to wire for UngrabKeyboard -func (c *Conn) UngrabKeyboard(Time Timestamp) { +func (c *Conn) UngrabKeyboard(Time Timestamp) UngrabKeyboardCookie { + cookie := c.newCookie(false, false) + c.newRequest(ungrabKeyboardRequest(Time), cookie) + return UngrabKeyboardCookie(cookie) +} + +func (c *Conn) UngrabKeyboardChecked(Time Timestamp) UngrabKeyboardCookie { + cookie := c.newCookie(true, false) + c.newRequest(ungrabKeyboardRequest(Time), cookie) + return UngrabKeyboardCookie(cookie) +} + +// Write request to wire for UngrabKeyboard +func ungrabKeyboardRequest(Time Timestamp) []byte { size := 8 b := 0 buf := make([]byte, size) @@ -7221,13 +7823,28 @@ func (c *Conn) UngrabKeyboard(Time Timestamp) { Put32(buf[b:], uint32(Time)) b += 4 - c.sendRequest(false, buf) + return buf } // Request GrabKey // size: 16 +type GrabKeyCookie cookie + // Write request to wire for GrabKey -func (c *Conn) GrabKey(OwnerEvents bool, GrabWindow Id, Modifiers uint16, Key Keycode, PointerMode byte, KeyboardMode byte) { +func (c *Conn) GrabKey(OwnerEvents bool, GrabWindow Id, Modifiers uint16, Key Keycode, PointerMode byte, KeyboardMode byte) GrabKeyCookie { + cookie := c.newCookie(false, false) + c.newRequest(grabKeyRequest(OwnerEvents, GrabWindow, Modifiers, Key, PointerMode, KeyboardMode), cookie) + return GrabKeyCookie(cookie) +} + +func (c *Conn) GrabKeyChecked(OwnerEvents bool, GrabWindow Id, Modifiers uint16, Key Keycode, PointerMode byte, KeyboardMode byte) GrabKeyCookie { + cookie := c.newCookie(true, false) + c.newRequest(grabKeyRequest(OwnerEvents, GrabWindow, Modifiers, Key, PointerMode, KeyboardMode), cookie) + return GrabKeyCookie(cookie) +} + +// Write request to wire for GrabKey +func grabKeyRequest(OwnerEvents bool, GrabWindow Id, Modifiers uint16, Key Keycode, PointerMode byte, KeyboardMode byte) []byte { size := 16 b := 0 buf := make([]byte, size) @@ -7262,13 +7879,28 @@ func (c *Conn) GrabKey(OwnerEvents bool, GrabWindow Id, Modifiers uint16, Key Ke b += 3 // padding - c.sendRequest(false, buf) + return buf } // Request UngrabKey // size: 12 +type UngrabKeyCookie cookie + // Write request to wire for UngrabKey -func (c *Conn) UngrabKey(Key Keycode, GrabWindow Id, Modifiers uint16) { +func (c *Conn) UngrabKey(Key Keycode, GrabWindow Id, Modifiers uint16) UngrabKeyCookie { + cookie := c.newCookie(false, false) + c.newRequest(ungrabKeyRequest(Key, GrabWindow, Modifiers), cookie) + return UngrabKeyCookie(cookie) +} + +func (c *Conn) UngrabKeyChecked(Key Keycode, GrabWindow Id, Modifiers uint16) UngrabKeyCookie { + cookie := c.newCookie(true, false) + c.newRequest(ungrabKeyRequest(Key, GrabWindow, Modifiers), cookie) + return UngrabKeyCookie(cookie) +} + +// Write request to wire for UngrabKey +func ungrabKeyRequest(Key Keycode, GrabWindow Id, Modifiers uint16) []byte { size := 12 b := 0 buf := make([]byte, size) @@ -7290,13 +7922,28 @@ func (c *Conn) UngrabKey(Key Keycode, GrabWindow Id, Modifiers uint16) { b += 2 // padding - c.sendRequest(false, buf) + return buf } // Request AllowEvents // size: 8 +type AllowEventsCookie cookie + // Write request to wire for AllowEvents -func (c *Conn) AllowEvents(Mode byte, Time Timestamp) { +func (c *Conn) AllowEvents(Mode byte, Time Timestamp) AllowEventsCookie { + cookie := c.newCookie(false, false) + c.newRequest(allowEventsRequest(Mode, Time), cookie) + return AllowEventsCookie(cookie) +} + +func (c *Conn) AllowEventsChecked(Mode byte, Time Timestamp) AllowEventsCookie { + cookie := c.newCookie(true, false) + c.newRequest(allowEventsRequest(Mode, Time), cookie) + return AllowEventsCookie(cookie) +} + +// Write request to wire for AllowEvents +func allowEventsRequest(Mode byte, Time Timestamp) []byte { size := 8 b := 0 buf := make([]byte, size) @@ -7313,61 +7960,81 @@ func (c *Conn) AllowEvents(Mode byte, Time Timestamp) { Put32(buf[b:], uint32(Time)) b += 4 - c.sendRequest(false, buf) + return buf } // Request GrabServer -// size: 3 +// size: 4 +type GrabServerCookie cookie + // Write request to wire for GrabServer -func (c *Conn) GrabServer() { - size := 3 +func (c *Conn) GrabServer() GrabServerCookie { + cookie := c.newCookie(false, false) + c.newRequest(grabServerRequest(), cookie) + return GrabServerCookie(cookie) +} + +func (c *Conn) GrabServerChecked() GrabServerCookie { + cookie := c.newCookie(true, false) + c.newRequest(grabServerRequest(), cookie) + return GrabServerCookie(cookie) +} + +// Write request to wire for GrabServer +func grabServerRequest() []byte { + size := 4 b := 0 buf := make([]byte, size) buf[b] = 36 // request opcode b += 1 - c.sendRequest(false, buf) + return buf } // Request UngrabServer -// size: 3 +// size: 4 +type UngrabServerCookie cookie + // Write request to wire for UngrabServer -func (c *Conn) UngrabServer() { - size := 3 +func (c *Conn) UngrabServer() UngrabServerCookie { + cookie := c.newCookie(false, false) + c.newRequest(ungrabServerRequest(), cookie) + return UngrabServerCookie(cookie) +} + +func (c *Conn) UngrabServerChecked() UngrabServerCookie { + cookie := c.newCookie(true, false) + c.newRequest(ungrabServerRequest(), cookie) + return UngrabServerCookie(cookie) +} + +// Write request to wire for UngrabServer +func ungrabServerRequest() []byte { + size := 4 b := 0 buf := make([]byte, size) buf[b] = 37 // request opcode b += 1 - c.sendRequest(false, buf) + return buf } // Request QueryPointer // size: 8 -func (c *Conn) QueryPointer(Window Id) (*QueryPointerReply, error) { - return c.QueryPointerReply(c.QueryPointerRequest(Window)) +type QueryPointerCookie cookie + +func (c *Conn) QueryPointer(Window Id) QueryPointerCookie { + cookie := c.newCookie(true, true) + c.newRequest(queryPointerRequest(Window), cookie) + return QueryPointerCookie(cookie) } -// Write request to wire for QueryPointer -func (c *Conn) QueryPointerRequest(Window Id) *Cookie { - size := 8 - b := 0 - buf := make([]byte, size) - - buf[b] = 38 // request opcode - b += 1 - - b += 1 // padding - - Put16(buf[b:], uint16(size/4)) // write request size in 4-byte units - b += 2 - - Put32(buf[b:], uint32(Window)) - b += 4 - - return c.sendRequest(true, buf) +func (c *Conn) QueryPointerUnchecked(Window Id) QueryPointerCookie { + cookie := c.newCookie(false, true) + c.newRequest(queryPointerRequest(Window), cookie) + return QueryPointerCookie(cookie) } // Request reply for QueryPointer @@ -7386,13 +8053,17 @@ type QueryPointerReply struct { // padding: 2 bytes } -// Read reply QueryPointer -func (c *Conn) QueryPointerReply(cook *Cookie) (*QueryPointerReply, error) { - buf, err := c.waitForReply(cook) +// Waits and reads reply data from request QueryPointer +func (cook QueryPointerCookie) Reply() (*QueryPointerReply, error) { + buf, err := cookie(cook).reply() if err != nil { return nil, err } + return queryPointerReply(buf), nil +} +// Read reply into structure from buffer for QueryPointer +func queryPointerReply(buf []byte) *QueryPointerReply { v := new(QueryPointerReply) b := 1 // skip reply determinant @@ -7432,17 +8103,91 @@ func (c *Conn) QueryPointerReply(cook *Cookie) (*QueryPointerReply, error) { b += 2 // padding - return v, nil + return v +} + +// Write request to wire for QueryPointer +func queryPointerRequest(Window Id) []byte { + size := 8 + b := 0 + buf := make([]byte, size) + + buf[b] = 38 // request opcode + b += 1 + + b += 1 // padding + + Put16(buf[b:], uint16(size/4)) // write request size in 4-byte units + b += 2 + + Put32(buf[b:], uint32(Window)) + b += 4 + + return buf } // Request GetMotionEvents // size: 16 -func (c *Conn) GetMotionEvents(Window Id, Start Timestamp, Stop Timestamp) (*GetMotionEventsReply, error) { - return c.GetMotionEventsReply(c.GetMotionEventsRequest(Window, Start, Stop)) +type GetMotionEventsCookie cookie + +func (c *Conn) GetMotionEvents(Window Id, Start Timestamp, Stop Timestamp) GetMotionEventsCookie { + cookie := c.newCookie(true, true) + c.newRequest(getMotionEventsRequest(Window, Start, Stop), cookie) + return GetMotionEventsCookie(cookie) +} + +func (c *Conn) GetMotionEventsUnchecked(Window Id, Start Timestamp, Stop Timestamp) GetMotionEventsCookie { + cookie := c.newCookie(false, true) + c.newRequest(getMotionEventsRequest(Window, Start, Stop), cookie) + return GetMotionEventsCookie(cookie) +} + +// Request reply for GetMotionEvents +// size: (32 + pad((int(EventsLen) * 8))) +type GetMotionEventsReply struct { + Sequence uint16 + Length uint32 + // padding: 1 bytes + EventsLen uint32 + // padding: 20 bytes + Events []Timecoord // size: pad((int(EventsLen) * 8)) +} + +// Waits and reads reply data from request GetMotionEvents +func (cook GetMotionEventsCookie) Reply() (*GetMotionEventsReply, error) { + buf, err := cookie(cook).reply() + if err != nil { + return nil, err + } + return getMotionEventsReply(buf), nil +} + +// Read reply into structure from buffer for GetMotionEvents +func getMotionEventsReply(buf []byte) *GetMotionEventsReply { + v := new(GetMotionEventsReply) + b := 1 // skip reply determinant + + b += 1 // padding + + v.Sequence = Get16(buf[b:]) + b += 2 + + v.Length = Get32(buf[b:]) // 4-byte units + b += 4 + + v.EventsLen = Get32(buf[b:]) + b += 4 + + b += 20 // padding + + v.Events = make([]Timecoord, v.EventsLen) + b += ReadTimecoordList(buf[b:], v.Events) + + return v } // Write request to wire for GetMotionEvents -func (c *Conn) GetMotionEventsRequest(Window Id, Start Timestamp, Stop Timestamp) *Cookie { +func getMotionEventsRequest(Window Id, Start Timestamp, Stop Timestamp) []byte { size := 16 b := 0 buf := make([]byte, size) @@ -7464,82 +8209,23 @@ func (c *Conn) GetMotionEventsRequest(Window Id, Start Timestamp, Stop Timestamp Put32(buf[b:], uint32(Stop)) b += 4 - return c.sendRequest(true, buf) -} - -// Request reply for GetMotionEvents -// size: (32 + pad((int(EventsLen) * 8))) -type GetMotionEventsReply struct { - Sequence uint16 - Length uint32 - // padding: 1 bytes - EventsLen uint32 - // padding: 20 bytes - Events []Timecoord // size: pad((int(EventsLen) * 8)) -} - -// Read reply GetMotionEvents -func (c *Conn) GetMotionEventsReply(cook *Cookie) (*GetMotionEventsReply, error) { - buf, err := c.waitForReply(cook) - if err != nil { - return nil, err - } - - v := new(GetMotionEventsReply) - b := 1 // skip reply determinant - - b += 1 // padding - - v.Sequence = Get16(buf[b:]) - b += 2 - - v.Length = Get32(buf[b:]) // 4-byte units - b += 4 - - v.EventsLen = Get32(buf[b:]) - b += 4 - - b += 20 // padding - - v.Events = make([]Timecoord, v.EventsLen) - b += ReadTimecoordList(buf[b:], v.Events) - - return v, nil + return buf } // Request TranslateCoordinates // size: 16 -func (c *Conn) TranslateCoordinates(SrcWindow Id, DstWindow Id, SrcX int16, SrcY int16) (*TranslateCoordinatesReply, error) { - return c.TranslateCoordinatesReply(c.TranslateCoordinatesRequest(SrcWindow, DstWindow, SrcX, SrcY)) +type TranslateCoordinatesCookie cookie + +func (c *Conn) TranslateCoordinates(SrcWindow Id, DstWindow Id, SrcX int16, SrcY int16) TranslateCoordinatesCookie { + cookie := c.newCookie(true, true) + c.newRequest(translateCoordinatesRequest(SrcWindow, DstWindow, SrcX, SrcY), cookie) + return TranslateCoordinatesCookie(cookie) } -// Write request to wire for TranslateCoordinates -func (c *Conn) TranslateCoordinatesRequest(SrcWindow Id, DstWindow Id, SrcX int16, SrcY int16) *Cookie { - size := 16 - b := 0 - buf := make([]byte, size) - - buf[b] = 40 // request opcode - b += 1 - - b += 1 // padding - - Put16(buf[b:], uint16(size/4)) // write request size in 4-byte units - b += 2 - - Put32(buf[b:], uint32(SrcWindow)) - b += 4 - - Put32(buf[b:], uint32(DstWindow)) - b += 4 - - Put16(buf[b:], uint16(SrcX)) - b += 2 - - Put16(buf[b:], uint16(SrcY)) - b += 2 - - return c.sendRequest(true, buf) +func (c *Conn) TranslateCoordinatesUnchecked(SrcWindow Id, DstWindow Id, SrcX int16, SrcY int16) TranslateCoordinatesCookie { + cookie := c.newCookie(false, true) + c.newRequest(translateCoordinatesRequest(SrcWindow, DstWindow, SrcX, SrcY), cookie) + return TranslateCoordinatesCookie(cookie) } // Request reply for TranslateCoordinates @@ -7553,13 +8239,17 @@ type TranslateCoordinatesReply struct { DstY int16 } -// Read reply TranslateCoordinates -func (c *Conn) TranslateCoordinatesReply(cook *Cookie) (*TranslateCoordinatesReply, error) { - buf, err := c.waitForReply(cook) +// Waits and reads reply data from request TranslateCoordinates +func (cook TranslateCoordinatesCookie) Reply() (*TranslateCoordinatesReply, error) { + buf, err := cookie(cook).reply() if err != nil { return nil, err } + return translateCoordinatesReply(buf), nil +} +// Read reply into structure from buffer for TranslateCoordinates +func translateCoordinatesReply(buf []byte) *TranslateCoordinatesReply { v := new(TranslateCoordinatesReply) b := 1 // skip reply determinant @@ -7585,13 +8275,57 @@ func (c *Conn) TranslateCoordinatesReply(cook *Cookie) (*TranslateCoordinatesRep v.DstY = int16(Get16(buf[b:])) b += 2 - return v, nil + return v +} + +// Write request to wire for TranslateCoordinates +func translateCoordinatesRequest(SrcWindow Id, DstWindow Id, SrcX int16, SrcY int16) []byte { + size := 16 + b := 0 + buf := make([]byte, size) + + buf[b] = 40 // request opcode + b += 1 + + b += 1 // padding + + Put16(buf[b:], uint16(size/4)) // write request size in 4-byte units + b += 2 + + Put32(buf[b:], uint32(SrcWindow)) + b += 4 + + Put32(buf[b:], uint32(DstWindow)) + b += 4 + + Put16(buf[b:], uint16(SrcX)) + b += 2 + + Put16(buf[b:], uint16(SrcY)) + b += 2 + + return buf } // Request WarpPointer // size: 24 +type WarpPointerCookie cookie + // Write request to wire for WarpPointer -func (c *Conn) WarpPointer(SrcWindow Id, DstWindow Id, SrcX int16, SrcY int16, SrcWidth uint16, SrcHeight uint16, DstX int16, DstY int16) { +func (c *Conn) WarpPointer(SrcWindow Id, DstWindow Id, SrcX int16, SrcY int16, SrcWidth uint16, SrcHeight uint16, DstX int16, DstY int16) WarpPointerCookie { + cookie := c.newCookie(false, false) + c.newRequest(warpPointerRequest(SrcWindow, DstWindow, SrcX, SrcY, SrcWidth, SrcHeight, DstX, DstY), cookie) + return WarpPointerCookie(cookie) +} + +func (c *Conn) WarpPointerChecked(SrcWindow Id, DstWindow Id, SrcX int16, SrcY int16, SrcWidth uint16, SrcHeight uint16, DstX int16, DstY int16) WarpPointerCookie { + cookie := c.newCookie(true, false) + c.newRequest(warpPointerRequest(SrcWindow, DstWindow, SrcX, SrcY, SrcWidth, SrcHeight, DstX, DstY), cookie) + return WarpPointerCookie(cookie) +} + +// Write request to wire for WarpPointer +func warpPointerRequest(SrcWindow Id, DstWindow Id, SrcX int16, SrcY int16, SrcWidth uint16, SrcHeight uint16, DstX int16, DstY int16) []byte { size := 24 b := 0 buf := make([]byte, size) @@ -7628,13 +8362,28 @@ func (c *Conn) WarpPointer(SrcWindow Id, DstWindow Id, SrcX int16, SrcY int16, S Put16(buf[b:], uint16(DstY)) b += 2 - c.sendRequest(false, buf) + return buf } // Request SetInputFocus // size: 12 +type SetInputFocusCookie cookie + // Write request to wire for SetInputFocus -func (c *Conn) SetInputFocus(RevertTo byte, Focus Id, Time Timestamp) { +func (c *Conn) SetInputFocus(RevertTo byte, Focus Id, Time Timestamp) SetInputFocusCookie { + cookie := c.newCookie(false, false) + c.newRequest(setInputFocusRequest(RevertTo, Focus, Time), cookie) + return SetInputFocusCookie(cookie) +} + +func (c *Conn) SetInputFocusChecked(RevertTo byte, Focus Id, Time Timestamp) SetInputFocusCookie { + cookie := c.newCookie(true, false) + c.newRequest(setInputFocusRequest(RevertTo, Focus, Time), cookie) + return SetInputFocusCookie(cookie) +} + +// Write request to wire for SetInputFocus +func setInputFocusRequest(RevertTo byte, Focus Id, Time Timestamp) []byte { size := 12 b := 0 buf := make([]byte, size) @@ -7654,25 +8403,23 @@ func (c *Conn) SetInputFocus(RevertTo byte, Focus Id, Time Timestamp) { Put32(buf[b:], uint32(Time)) b += 4 - c.sendRequest(false, buf) + return buf } // Request GetInputFocus -// size: 3 -func (c *Conn) GetInputFocus() (*GetInputFocusReply, error) { - return c.GetInputFocusReply(c.GetInputFocusRequest()) +// size: 4 +type GetInputFocusCookie cookie + +func (c *Conn) GetInputFocus() GetInputFocusCookie { + cookie := c.newCookie(true, true) + c.newRequest(getInputFocusRequest(), cookie) + return GetInputFocusCookie(cookie) } -// Write request to wire for GetInputFocus -func (c *Conn) GetInputFocusRequest() *Cookie { - size := 3 - b := 0 - buf := make([]byte, size) - - buf[b] = 43 // request opcode - b += 1 - - return c.sendRequest(true, buf) +func (c *Conn) GetInputFocusUnchecked() GetInputFocusCookie { + cookie := c.newCookie(false, true) + c.newRequest(getInputFocusRequest(), cookie) + return GetInputFocusCookie(cookie) } // Request reply for GetInputFocus @@ -7684,13 +8431,17 @@ type GetInputFocusReply struct { Focus Id } -// Read reply GetInputFocus -func (c *Conn) GetInputFocusReply(cook *Cookie) (*GetInputFocusReply, error) { - buf, err := c.waitForReply(cook) +// Waits and reads reply data from request GetInputFocus +func (cook GetInputFocusCookie) Reply() (*GetInputFocusReply, error) { + buf, err := cookie(cook).reply() if err != nil { return nil, err } + return getInputFocusReply(buf), nil +} +// Read reply into structure from buffer for GetInputFocus +func getInputFocusReply(buf []byte) *GetInputFocusReply { v := new(GetInputFocusReply) b := 1 // skip reply determinant @@ -7706,25 +8457,35 @@ func (c *Conn) GetInputFocusReply(cook *Cookie) (*GetInputFocusReply, error) { v.Focus = Id(Get32(buf[b:])) b += 4 - return v, nil + return v } -// Request QueryKeymap -// size: 3 -func (c *Conn) QueryKeymap() (*QueryKeymapReply, error) { - return c.QueryKeymapReply(c.QueryKeymapRequest()) -} - -// Write request to wire for QueryKeymap -func (c *Conn) QueryKeymapRequest() *Cookie { - size := 3 +// Write request to wire for GetInputFocus +func getInputFocusRequest() []byte { + size := 4 b := 0 buf := make([]byte, size) - buf[b] = 44 // request opcode + buf[b] = 43 // request opcode b += 1 - return c.sendRequest(true, buf) + return buf +} + +// Request QueryKeymap +// size: 4 +type QueryKeymapCookie cookie + +func (c *Conn) QueryKeymap() QueryKeymapCookie { + cookie := c.newCookie(true, true) + c.newRequest(queryKeymapRequest(), cookie) + return QueryKeymapCookie(cookie) +} + +func (c *Conn) QueryKeymapUnchecked() QueryKeymapCookie { + cookie := c.newCookie(false, true) + c.newRequest(queryKeymapRequest(), cookie) + return QueryKeymapCookie(cookie) } // Request reply for QueryKeymap @@ -7736,13 +8497,17 @@ type QueryKeymapReply struct { Keys []byte // size: pad(32) } -// Read reply QueryKeymap -func (c *Conn) QueryKeymapReply(cook *Cookie) (*QueryKeymapReply, error) { - buf, err := c.waitForReply(cook) +// Waits and reads reply data from request QueryKeymap +func (cook QueryKeymapCookie) Reply() (*QueryKeymapReply, error) { + buf, err := cookie(cook).reply() if err != nil { return nil, err } + return queryKeymapReply(buf), nil +} +// Read reply into structure from buffer for QueryKeymap +func queryKeymapReply(buf []byte) *QueryKeymapReply { v := new(QueryKeymapReply) b := 1 // skip reply determinant @@ -7758,14 +8523,41 @@ func (c *Conn) QueryKeymapReply(cook *Cookie) (*QueryKeymapReply, error) { copy(v.Keys[:32], buf[b:]) b += pad(int(32)) - return v, nil + return v +} + +// Write request to wire for QueryKeymap +func queryKeymapRequest() []byte { + size := 4 + b := 0 + buf := make([]byte, size) + + buf[b] = 44 // request opcode + b += 1 + + return buf } // Request OpenFont -// size: (12 + pad((int(NameLen) * 1))) +// size: pad((12 + pad((int(NameLen) * 1)))) +type OpenFontCookie cookie + // Write request to wire for OpenFont -func (c *Conn) OpenFont(Fid Id, NameLen uint16, Name string) { - size := (12 + pad((int(NameLen) * 1))) +func (c *Conn) OpenFont(Fid Id, NameLen uint16, Name string) OpenFontCookie { + cookie := c.newCookie(false, false) + c.newRequest(openFontRequest(Fid, NameLen, Name), cookie) + return OpenFontCookie(cookie) +} + +func (c *Conn) OpenFontChecked(Fid Id, NameLen uint16, Name string) OpenFontCookie { + cookie := c.newCookie(true, false) + c.newRequest(openFontRequest(Fid, NameLen, Name), cookie) + return OpenFontCookie(cookie) +} + +// Write request to wire for OpenFont +func openFontRequest(Fid Id, NameLen uint16, Name string) []byte { + size := pad((12 + pad((int(NameLen) * 1)))) b := 0 buf := make([]byte, size) @@ -7788,13 +8580,28 @@ func (c *Conn) OpenFont(Fid Id, NameLen uint16, Name string) { copy(buf[b:], Name[:NameLen]) b += pad(int(NameLen)) - c.sendRequest(false, buf) + return buf } // Request CloseFont // size: 8 +type CloseFontCookie cookie + // Write request to wire for CloseFont -func (c *Conn) CloseFont(Font Id) { +func (c *Conn) CloseFont(Font Id) CloseFontCookie { + cookie := c.newCookie(false, false) + c.newRequest(closeFontRequest(Font), cookie) + return CloseFontCookie(cookie) +} + +func (c *Conn) CloseFontChecked(Font Id) CloseFontCookie { + cookie := c.newCookie(true, false) + c.newRequest(closeFontRequest(Font), cookie) + return CloseFontCookie(cookie) +} + +// Write request to wire for CloseFont +func closeFontRequest(Font Id) []byte { size := 8 b := 0 buf := make([]byte, size) @@ -7810,33 +8617,23 @@ func (c *Conn) CloseFont(Font Id) { Put32(buf[b:], uint32(Font)) b += 4 - c.sendRequest(false, buf) + return buf } // Request QueryFont // size: 8 -func (c *Conn) QueryFont(Font Id) (*QueryFontReply, error) { - return c.QueryFontReply(c.QueryFontRequest(Font)) +type QueryFontCookie cookie + +func (c *Conn) QueryFont(Font Id) QueryFontCookie { + cookie := c.newCookie(true, true) + c.newRequest(queryFontRequest(Font), cookie) + return QueryFontCookie(cookie) } -// Write request to wire for QueryFont -func (c *Conn) QueryFontRequest(Font Id) *Cookie { - size := 8 - b := 0 - buf := make([]byte, size) - - buf[b] = 47 // request opcode - b += 1 - - b += 1 // padding - - Put16(buf[b:], uint16(size/4)) // write request size in 4-byte units - b += 2 - - Put32(buf[b:], uint32(Font)) - b += 4 - - return c.sendRequest(true, buf) +func (c *Conn) QueryFontUnchecked(Font Id) QueryFontCookie { + cookie := c.newCookie(false, true) + c.newRequest(queryFontRequest(Font), cookie) + return QueryFontCookie(cookie) } // Request reply for QueryFont @@ -7864,13 +8661,17 @@ type QueryFontReply struct { CharInfos []Charinfo // size: pad((int(CharInfosLen) * 12)) } -// Read reply QueryFont -func (c *Conn) QueryFontReply(cook *Cookie) (*QueryFontReply, error) { - buf, err := c.waitForReply(cook) +// Waits and reads reply data from request QueryFont +func (cook QueryFontCookie) Reply() (*QueryFontReply, error) { + buf, err := cookie(cook).reply() if err != nil { return nil, err } + return queryFontReply(buf), nil +} +// Read reply into structure from buffer for QueryFont +func queryFontReply(buf []byte) *QueryFontReply { v := new(QueryFontReply) b := 1 // skip reply determinant @@ -7935,26 +8736,19 @@ func (c *Conn) QueryFontReply(cook *Cookie) (*QueryFontReply, error) { v.CharInfos = make([]Charinfo, v.CharInfosLen) b += ReadCharinfoList(buf[b:], v.CharInfos) - return v, nil + return v } -// Request QueryTextExtents -// size: (8 + pad((len(String) * 2))) -func (c *Conn) QueryTextExtents(Font Id, String []Char2b, StringLen uint16) (*QueryTextExtentsReply, error) { - return c.QueryTextExtentsReply(c.QueryTextExtentsRequest(Font, String, StringLen)) -} - -// Write request to wire for QueryTextExtents -func (c *Conn) QueryTextExtentsRequest(Font Id, String []Char2b, StringLen uint16) *Cookie { - size := (8 + pad((len(String) * 2))) +// Write request to wire for QueryFont +func queryFontRequest(Font Id) []byte { + size := 8 b := 0 buf := make([]byte, size) - buf[b] = 48 // request opcode + buf[b] = 47 // request opcode b += 1 - buf[b] = byte((int(StringLen) & 1)) - b += 1 + b += 1 // padding Put16(buf[b:], uint16(size/4)) // write request size in 4-byte units b += 2 @@ -7962,11 +8756,23 @@ func (c *Conn) QueryTextExtentsRequest(Font Id, String []Char2b, StringLen uint1 Put32(buf[b:], uint32(Font)) b += 4 - b += Char2bListBytes(buf[b:], String) + return buf +} - // skip writing local field: StringLen (2) :: uint16 +// Request QueryTextExtents +// size: pad((8 + pad((len(String) * 2)))) +type QueryTextExtentsCookie cookie - return c.sendRequest(true, buf) +func (c *Conn) QueryTextExtents(Font Id, String []Char2b, StringLen uint16) QueryTextExtentsCookie { + cookie := c.newCookie(true, true) + c.newRequest(queryTextExtentsRequest(Font, String, StringLen), cookie) + return QueryTextExtentsCookie(cookie) +} + +func (c *Conn) QueryTextExtentsUnchecked(Font Id, String []Char2b, StringLen uint16) QueryTextExtentsCookie { + cookie := c.newCookie(false, true) + c.newRequest(queryTextExtentsRequest(Font, String, StringLen), cookie) + return QueryTextExtentsCookie(cookie) } // Request reply for QueryTextExtents @@ -7984,13 +8790,17 @@ type QueryTextExtentsReply struct { OverallRight int32 } -// Read reply QueryTextExtents -func (c *Conn) QueryTextExtentsReply(cook *Cookie) (*QueryTextExtentsReply, error) { - buf, err := c.waitForReply(cook) +// Waits and reads reply data from request QueryTextExtents +func (cook QueryTextExtentsCookie) Reply() (*QueryTextExtentsReply, error) { + buf, err := cookie(cook).reply() if err != nil { return nil, err } + return queryTextExtentsReply(buf), nil +} +// Read reply into structure from buffer for QueryTextExtents +func queryTextExtentsReply(buf []byte) *QueryTextExtentsReply { v := new(QueryTextExtentsReply) b := 1 // skip reply determinant @@ -8024,18 +8834,97 @@ func (c *Conn) QueryTextExtentsReply(cook *Cookie) (*QueryTextExtentsReply, erro v.OverallRight = int32(Get32(buf[b:])) b += 4 - return v, nil + return v +} + +// Write request to wire for QueryTextExtents +func queryTextExtentsRequest(Font Id, String []Char2b, StringLen uint16) []byte { + size := pad((8 + pad((len(String) * 2)))) + b := 0 + buf := make([]byte, size) + + buf[b] = 48 // request opcode + b += 1 + + buf[b] = byte((int(StringLen) & 1)) + b += 1 + + Put16(buf[b:], uint16(size/4)) // write request size in 4-byte units + b += 2 + + Put32(buf[b:], uint32(Font)) + b += 4 + + b += Char2bListBytes(buf[b:], String) + + // skip writing local field: StringLen (2) :: uint16 + + return buf } // Request ListFonts -// size: (8 + pad((int(PatternLen) * 1))) -func (c *Conn) ListFonts(MaxNames uint16, PatternLen uint16, Pattern string) (*ListFontsReply, error) { - return c.ListFontsReply(c.ListFontsRequest(MaxNames, PatternLen, Pattern)) +// size: pad((8 + pad((int(PatternLen) * 1)))) +type ListFontsCookie cookie + +func (c *Conn) ListFonts(MaxNames uint16, PatternLen uint16, Pattern string) ListFontsCookie { + cookie := c.newCookie(true, true) + c.newRequest(listFontsRequest(MaxNames, PatternLen, Pattern), cookie) + return ListFontsCookie(cookie) +} + +func (c *Conn) ListFontsUnchecked(MaxNames uint16, PatternLen uint16, Pattern string) ListFontsCookie { + cookie := c.newCookie(false, true) + c.newRequest(listFontsRequest(MaxNames, PatternLen, Pattern), cookie) + return ListFontsCookie(cookie) +} + +// Request reply for ListFonts +// size: (32 + StrListSize(Names)) +type ListFontsReply struct { + Sequence uint16 + Length uint32 + // padding: 1 bytes + NamesLen uint16 + // padding: 22 bytes + Names []Str // size: StrListSize(Names) +} + +// Waits and reads reply data from request ListFonts +func (cook ListFontsCookie) Reply() (*ListFontsReply, error) { + buf, err := cookie(cook).reply() + if err != nil { + return nil, err + } + return listFontsReply(buf), nil +} + +// Read reply into structure from buffer for ListFonts +func listFontsReply(buf []byte) *ListFontsReply { + v := new(ListFontsReply) + b := 1 // skip reply determinant + + b += 1 // padding + + v.Sequence = Get16(buf[b:]) + b += 2 + + v.Length = Get32(buf[b:]) // 4-byte units + b += 4 + + v.NamesLen = Get16(buf[b:]) + b += 2 + + b += 22 // padding + + v.Names = make([]Str, v.NamesLen) + b += ReadStrList(buf[b:], v.Names) + + return v } // Write request to wire for ListFonts -func (c *Conn) ListFontsRequest(MaxNames uint16, PatternLen uint16, Pattern string) *Cookie { - size := (8 + pad((int(PatternLen) * 1))) +func listFontsRequest(MaxNames uint16, PatternLen uint16, Pattern string) []byte { + size := pad((8 + pad((int(PatternLen) * 1)))) b := 0 buf := make([]byte, size) @@ -8056,79 +8945,23 @@ func (c *Conn) ListFontsRequest(MaxNames uint16, PatternLen uint16, Pattern stri copy(buf[b:], Pattern[:PatternLen]) b += pad(int(PatternLen)) - return c.sendRequest(true, buf) -} - -// Request reply for ListFonts -// size: (32 + StrListSize(Names)) -type ListFontsReply struct { - Sequence uint16 - Length uint32 - // padding: 1 bytes - NamesLen uint16 - // padding: 22 bytes - Names []Str // size: StrListSize(Names) -} - -// Read reply ListFonts -func (c *Conn) ListFontsReply(cook *Cookie) (*ListFontsReply, error) { - buf, err := c.waitForReply(cook) - if err != nil { - return nil, err - } - - v := new(ListFontsReply) - b := 1 // skip reply determinant - - b += 1 // padding - - v.Sequence = Get16(buf[b:]) - b += 2 - - v.Length = Get32(buf[b:]) // 4-byte units - b += 4 - - v.NamesLen = Get16(buf[b:]) - b += 2 - - b += 22 // padding - - v.Names = make([]Str, v.NamesLen) - b += ReadStrList(buf[b:], v.Names) - - return v, nil + return buf } // Request ListFontsWithInfo -// size: (8 + pad((int(PatternLen) * 1))) -func (c *Conn) ListFontsWithInfo(MaxNames uint16, PatternLen uint16, Pattern string) (*ListFontsWithInfoReply, error) { - return c.ListFontsWithInfoReply(c.ListFontsWithInfoRequest(MaxNames, PatternLen, Pattern)) +// size: pad((8 + pad((int(PatternLen) * 1)))) +type ListFontsWithInfoCookie cookie + +func (c *Conn) ListFontsWithInfo(MaxNames uint16, PatternLen uint16, Pattern string) ListFontsWithInfoCookie { + cookie := c.newCookie(true, true) + c.newRequest(listFontsWithInfoRequest(MaxNames, PatternLen, Pattern), cookie) + return ListFontsWithInfoCookie(cookie) } -// Write request to wire for ListFontsWithInfo -func (c *Conn) ListFontsWithInfoRequest(MaxNames uint16, PatternLen uint16, Pattern string) *Cookie { - size := (8 + pad((int(PatternLen) * 1))) - b := 0 - buf := make([]byte, size) - - buf[b] = 50 // request opcode - b += 1 - - b += 1 // padding - - Put16(buf[b:], uint16(size/4)) // write request size in 4-byte units - b += 2 - - Put16(buf[b:], MaxNames) - b += 2 - - Put16(buf[b:], PatternLen) - b += 2 - - copy(buf[b:], Pattern[:PatternLen]) - b += pad(int(PatternLen)) - - return c.sendRequest(true, buf) +func (c *Conn) ListFontsWithInfoUnchecked(MaxNames uint16, PatternLen uint16, Pattern string) ListFontsWithInfoCookie { + cookie := c.newCookie(false, true) + c.newRequest(listFontsWithInfoRequest(MaxNames, PatternLen, Pattern), cookie) + return ListFontsWithInfoCookie(cookie) } // Request reply for ListFontsWithInfo @@ -8156,13 +8989,17 @@ type ListFontsWithInfoReply struct { Name string // size: pad((int(NameLen) * 1)) } -// Read reply ListFontsWithInfo -func (c *Conn) ListFontsWithInfoReply(cook *Cookie) (*ListFontsWithInfoReply, error) { - buf, err := c.waitForReply(cook) +// Waits and reads reply data from request ListFontsWithInfo +func (cook ListFontsWithInfoCookie) Reply() (*ListFontsWithInfoReply, error) { + buf, err := cookie(cook).reply() if err != nil { return nil, err } + return listFontsWithInfoReply(buf), nil +} +// Read reply into structure from buffer for ListFontsWithInfo +func listFontsWithInfoReply(buf []byte) *ListFontsWithInfoReply { v := new(ListFontsWithInfoReply) b := 1 // skip reply determinant @@ -8232,14 +9069,55 @@ func (c *Conn) ListFontsWithInfoReply(cook *Cookie) (*ListFontsWithInfoReply, er b += pad(int(v.NameLen)) } - return v, nil + return v +} + +// Write request to wire for ListFontsWithInfo +func listFontsWithInfoRequest(MaxNames uint16, PatternLen uint16, Pattern string) []byte { + size := pad((8 + pad((int(PatternLen) * 1)))) + b := 0 + buf := make([]byte, size) + + buf[b] = 50 // request opcode + b += 1 + + b += 1 // padding + + Put16(buf[b:], uint16(size/4)) // write request size in 4-byte units + b += 2 + + Put16(buf[b:], MaxNames) + b += 2 + + Put16(buf[b:], PatternLen) + b += 2 + + copy(buf[b:], Pattern[:PatternLen]) + b += pad(int(PatternLen)) + + return buf } // Request SetFontPath -// size: (8 + StrListSize(Font)) +// size: pad((8 + StrListSize(Font))) +type SetFontPathCookie cookie + // Write request to wire for SetFontPath -func (c *Conn) SetFontPath(FontQty uint16, Font []Str) { - size := (8 + StrListSize(Font)) +func (c *Conn) SetFontPath(FontQty uint16, Font []Str) SetFontPathCookie { + cookie := c.newCookie(false, false) + c.newRequest(setFontPathRequest(FontQty, Font), cookie) + return SetFontPathCookie(cookie) +} + +func (c *Conn) SetFontPathChecked(FontQty uint16, Font []Str) SetFontPathCookie { + cookie := c.newCookie(true, false) + c.newRequest(setFontPathRequest(FontQty, Font), cookie) + return SetFontPathCookie(cookie) +} + +// Write request to wire for SetFontPath +func setFontPathRequest(FontQty uint16, Font []Str) []byte { + size := pad((8 + StrListSize(Font))) b := 0 buf := make([]byte, size) @@ -8258,25 +9136,23 @@ func (c *Conn) SetFontPath(FontQty uint16, Font []Str) { b += StrListBytes(buf[b:], Font) - c.sendRequest(false, buf) + return buf } // Request GetFontPath -// size: 3 -func (c *Conn) GetFontPath() (*GetFontPathReply, error) { - return c.GetFontPathReply(c.GetFontPathRequest()) +// size: 4 +type GetFontPathCookie cookie + +func (c *Conn) GetFontPath() GetFontPathCookie { + cookie := c.newCookie(true, true) + c.newRequest(getFontPathRequest(), cookie) + return GetFontPathCookie(cookie) } -// Write request to wire for GetFontPath -func (c *Conn) GetFontPathRequest() *Cookie { - size := 3 - b := 0 - buf := make([]byte, size) - - buf[b] = 52 // request opcode - b += 1 - - return c.sendRequest(true, buf) +func (c *Conn) GetFontPathUnchecked() GetFontPathCookie { + cookie := c.newCookie(false, true) + c.newRequest(getFontPathRequest(), cookie) + return GetFontPathCookie(cookie) } // Request reply for GetFontPath @@ -8290,13 +9166,17 @@ type GetFontPathReply struct { Path []Str // size: StrListSize(Path) } -// Read reply GetFontPath -func (c *Conn) GetFontPathReply(cook *Cookie) (*GetFontPathReply, error) { - buf, err := c.waitForReply(cook) +// Waits and reads reply data from request GetFontPath +func (cook GetFontPathCookie) Reply() (*GetFontPathReply, error) { + buf, err := cookie(cook).reply() if err != nil { return nil, err } + return getFontPathReply(buf), nil +} +// Read reply into structure from buffer for GetFontPath +func getFontPathReply(buf []byte) *GetFontPathReply { v := new(GetFontPathReply) b := 1 // skip reply determinant @@ -8316,13 +9196,40 @@ func (c *Conn) GetFontPathReply(cook *Cookie) (*GetFontPathReply, error) { v.Path = make([]Str, v.PathLen) b += ReadStrList(buf[b:], v.Path) - return v, nil + return v +} + +// Write request to wire for GetFontPath +func getFontPathRequest() []byte { + size := 4 + b := 0 + buf := make([]byte, size) + + buf[b] = 52 // request opcode + b += 1 + + return buf } // Request CreatePixmap // size: 16 +type CreatePixmapCookie cookie + // Write request to wire for CreatePixmap -func (c *Conn) CreatePixmap(Depth byte, Pid Id, Drawable Id, Width uint16, Height uint16) { +func (c *Conn) CreatePixmap(Depth byte, Pid Id, Drawable Id, Width uint16, Height uint16) CreatePixmapCookie { + cookie := c.newCookie(false, false) + c.newRequest(createPixmapRequest(Depth, Pid, Drawable, Width, Height), cookie) + return CreatePixmapCookie(cookie) +} + +func (c *Conn) CreatePixmapChecked(Depth byte, Pid Id, Drawable Id, Width uint16, Height uint16) CreatePixmapCookie { + cookie := c.newCookie(true, false) + c.newRequest(createPixmapRequest(Depth, Pid, Drawable, Width, Height), cookie) + return CreatePixmapCookie(cookie) +} + +// Write request to wire for CreatePixmap +func createPixmapRequest(Depth byte, Pid Id, Drawable Id, Width uint16, Height uint16) []byte { size := 16 b := 0 buf := make([]byte, size) @@ -8348,13 +9255,28 @@ func (c *Conn) CreatePixmap(Depth byte, Pid Id, Drawable Id, Width uint16, Heigh Put16(buf[b:], Height) b += 2 - c.sendRequest(false, buf) + return buf } // Request FreePixmap // size: 8 +type FreePixmapCookie cookie + // Write request to wire for FreePixmap -func (c *Conn) FreePixmap(Pixmap Id) { +func (c *Conn) FreePixmap(Pixmap Id) FreePixmapCookie { + cookie := c.newCookie(false, false) + c.newRequest(freePixmapRequest(Pixmap), cookie) + return FreePixmapCookie(cookie) +} + +func (c *Conn) FreePixmapChecked(Pixmap Id) FreePixmapCookie { + cookie := c.newCookie(true, false) + c.newRequest(freePixmapRequest(Pixmap), cookie) + return FreePixmapCookie(cookie) +} + +// Write request to wire for FreePixmap +func freePixmapRequest(Pixmap Id) []byte { size := 8 b := 0 buf := make([]byte, size) @@ -8370,14 +9292,29 @@ func (c *Conn) FreePixmap(Pixmap Id) { Put32(buf[b:], uint32(Pixmap)) b += 4 - c.sendRequest(false, buf) + return buf } // Request CreateGC -// size: (12 + (4 + pad((4 * popCount(int(ValueMask)))))) +// size: pad((12 + (4 + pad((4 * popCount(int(ValueMask))))))) +type CreateGCCookie cookie + // Write request to wire for CreateGC -func (c *Conn) CreateGC(Cid Id, Drawable Id, ValueMask uint32, ValueList []uint32) { - size := (12 + (4 + pad((4 * popCount(int(ValueMask)))))) +func (c *Conn) CreateGC(Cid Id, Drawable Id, ValueMask uint32, ValueList []uint32) CreateGCCookie { + cookie := c.newCookie(false, false) + c.newRequest(createGCRequest(Cid, Drawable, ValueMask, ValueList), cookie) + return CreateGCCookie(cookie) +} + +func (c *Conn) CreateGCChecked(Cid Id, Drawable Id, ValueMask uint32, ValueList []uint32) CreateGCCookie { + cookie := c.newCookie(true, false) + c.newRequest(createGCRequest(Cid, Drawable, ValueMask, ValueList), cookie) + return CreateGCCookie(cookie) +} + +// Write request to wire for CreateGC +func createGCRequest(Cid Id, Drawable Id, ValueMask uint32, ValueList []uint32) []byte { + size := pad((12 + (4 + pad((4 * popCount(int(ValueMask))))))) b := 0 buf := make([]byte, size) @@ -8403,14 +9340,29 @@ func (c *Conn) CreateGC(Cid Id, Drawable Id, ValueMask uint32, ValueList []uint3 } b = pad(b) - c.sendRequest(false, buf) + return buf } // Request ChangeGC -// size: (8 + (4 + pad((4 * popCount(int(ValueMask)))))) +// size: pad((8 + (4 + pad((4 * popCount(int(ValueMask))))))) +type ChangeGCCookie cookie + // Write request to wire for ChangeGC -func (c *Conn) ChangeGC(Gc Id, ValueMask uint32, ValueList []uint32) { - size := (8 + (4 + pad((4 * popCount(int(ValueMask)))))) +func (c *Conn) ChangeGC(Gc Id, ValueMask uint32, ValueList []uint32) ChangeGCCookie { + cookie := c.newCookie(false, false) + c.newRequest(changeGCRequest(Gc, ValueMask, ValueList), cookie) + return ChangeGCCookie(cookie) +} + +func (c *Conn) ChangeGCChecked(Gc Id, ValueMask uint32, ValueList []uint32) ChangeGCCookie { + cookie := c.newCookie(true, false) + c.newRequest(changeGCRequest(Gc, ValueMask, ValueList), cookie) + return ChangeGCCookie(cookie) +} + +// Write request to wire for ChangeGC +func changeGCRequest(Gc Id, ValueMask uint32, ValueList []uint32) []byte { + size := pad((8 + (4 + pad((4 * popCount(int(ValueMask))))))) b := 0 buf := make([]byte, size) @@ -8433,13 +9385,28 @@ func (c *Conn) ChangeGC(Gc Id, ValueMask uint32, ValueList []uint32) { } b = pad(b) - c.sendRequest(false, buf) + return buf } // Request CopyGC // size: 16 +type CopyGCCookie cookie + // Write request to wire for CopyGC -func (c *Conn) CopyGC(SrcGc Id, DstGc Id, ValueMask uint32) { +func (c *Conn) CopyGC(SrcGc Id, DstGc Id, ValueMask uint32) CopyGCCookie { + cookie := c.newCookie(false, false) + c.newRequest(copyGCRequest(SrcGc, DstGc, ValueMask), cookie) + return CopyGCCookie(cookie) +} + +func (c *Conn) CopyGCChecked(SrcGc Id, DstGc Id, ValueMask uint32) CopyGCCookie { + cookie := c.newCookie(true, false) + c.newRequest(copyGCRequest(SrcGc, DstGc, ValueMask), cookie) + return CopyGCCookie(cookie) +} + +// Write request to wire for CopyGC +func copyGCRequest(SrcGc Id, DstGc Id, ValueMask uint32) []byte { size := 16 b := 0 buf := make([]byte, size) @@ -8461,14 +9428,29 @@ func (c *Conn) CopyGC(SrcGc Id, DstGc Id, ValueMask uint32) { Put32(buf[b:], ValueMask) b += 4 - c.sendRequest(false, buf) + return buf } // Request SetDashes -// size: (12 + pad((int(DashesLen) * 1))) +// size: pad((12 + pad((int(DashesLen) * 1)))) +type SetDashesCookie cookie + // Write request to wire for SetDashes -func (c *Conn) SetDashes(Gc Id, DashOffset uint16, DashesLen uint16, Dashes []byte) { - size := (12 + pad((int(DashesLen) * 1))) +func (c *Conn) SetDashes(Gc Id, DashOffset uint16, DashesLen uint16, Dashes []byte) SetDashesCookie { + cookie := c.newCookie(false, false) + c.newRequest(setDashesRequest(Gc, DashOffset, DashesLen, Dashes), cookie) + return SetDashesCookie(cookie) +} + +func (c *Conn) SetDashesChecked(Gc Id, DashOffset uint16, DashesLen uint16, Dashes []byte) SetDashesCookie { + cookie := c.newCookie(true, false) + c.newRequest(setDashesRequest(Gc, DashOffset, DashesLen, Dashes), cookie) + return SetDashesCookie(cookie) +} + +// Write request to wire for SetDashes +func setDashesRequest(Gc Id, DashOffset uint16, DashesLen uint16, Dashes []byte) []byte { + size := pad((12 + pad((int(DashesLen) * 1)))) b := 0 buf := make([]byte, size) @@ -8492,14 +9474,29 @@ func (c *Conn) SetDashes(Gc Id, DashOffset uint16, DashesLen uint16, Dashes []by copy(buf[b:], Dashes[:DashesLen]) b += pad(int(DashesLen)) - c.sendRequest(false, buf) + return buf } // Request SetClipRectangles -// size: (12 + pad((len(Rectangles) * 8))) +// size: pad((12 + pad((len(Rectangles) * 8)))) +type SetClipRectanglesCookie cookie + // Write request to wire for SetClipRectangles -func (c *Conn) SetClipRectangles(Ordering byte, Gc Id, ClipXOrigin int16, ClipYOrigin int16, Rectangles []Rectangle) { - size := (12 + pad((len(Rectangles) * 8))) +func (c *Conn) SetClipRectangles(Ordering byte, Gc Id, ClipXOrigin int16, ClipYOrigin int16, Rectangles []Rectangle) SetClipRectanglesCookie { + cookie := c.newCookie(false, false) + c.newRequest(setClipRectanglesRequest(Ordering, Gc, ClipXOrigin, ClipYOrigin, Rectangles), cookie) + return SetClipRectanglesCookie(cookie) +} + +func (c *Conn) SetClipRectanglesChecked(Ordering byte, Gc Id, ClipXOrigin int16, ClipYOrigin int16, Rectangles []Rectangle) SetClipRectanglesCookie { + cookie := c.newCookie(true, false) + c.newRequest(setClipRectanglesRequest(Ordering, Gc, ClipXOrigin, ClipYOrigin, Rectangles), cookie) + return SetClipRectanglesCookie(cookie) +} + +// Write request to wire for SetClipRectangles +func setClipRectanglesRequest(Ordering byte, Gc Id, ClipXOrigin int16, ClipYOrigin int16, Rectangles []Rectangle) []byte { + size := pad((12 + pad((len(Rectangles) * 8)))) b := 0 buf := make([]byte, size) @@ -8523,13 +9520,28 @@ func (c *Conn) SetClipRectangles(Ordering byte, Gc Id, ClipXOrigin int16, ClipYO b += RectangleListBytes(buf[b:], Rectangles) - c.sendRequest(false, buf) + return buf } // Request FreeGC // size: 8 +type FreeGCCookie cookie + // Write request to wire for FreeGC -func (c *Conn) FreeGC(Gc Id) { +func (c *Conn) FreeGC(Gc Id) FreeGCCookie { + cookie := c.newCookie(false, false) + c.newRequest(freeGCRequest(Gc), cookie) + return FreeGCCookie(cookie) +} + +func (c *Conn) FreeGCChecked(Gc Id) FreeGCCookie { + cookie := c.newCookie(true, false) + c.newRequest(freeGCRequest(Gc), cookie) + return FreeGCCookie(cookie) +} + +// Write request to wire for FreeGC +func freeGCRequest(Gc Id) []byte { size := 8 b := 0 buf := make([]byte, size) @@ -8545,13 +9557,28 @@ func (c *Conn) FreeGC(Gc Id) { Put32(buf[b:], uint32(Gc)) b += 4 - c.sendRequest(false, buf) + return buf } // Request ClearArea // size: 16 +type ClearAreaCookie cookie + // Write request to wire for ClearArea -func (c *Conn) ClearArea(Exposures bool, Window Id, X int16, Y int16, Width uint16, Height uint16) { +func (c *Conn) ClearArea(Exposures bool, Window Id, X int16, Y int16, Width uint16, Height uint16) ClearAreaCookie { + cookie := c.newCookie(false, false) + c.newRequest(clearAreaRequest(Exposures, Window, X, Y, Width, Height), cookie) + return ClearAreaCookie(cookie) +} + +func (c *Conn) ClearAreaChecked(Exposures bool, Window Id, X int16, Y int16, Width uint16, Height uint16) ClearAreaCookie { + cookie := c.newCookie(true, false) + c.newRequest(clearAreaRequest(Exposures, Window, X, Y, Width, Height), cookie) + return ClearAreaCookie(cookie) +} + +// Write request to wire for ClearArea +func clearAreaRequest(Exposures bool, Window Id, X int16, Y int16, Width uint16, Height uint16) []byte { size := 16 b := 0 buf := make([]byte, size) @@ -8584,13 +9611,28 @@ func (c *Conn) ClearArea(Exposures bool, Window Id, X int16, Y int16, Width uint Put16(buf[b:], Height) b += 2 - c.sendRequest(false, buf) + return buf } // Request CopyArea // size: 28 +type CopyAreaCookie cookie + // Write request to wire for CopyArea -func (c *Conn) CopyArea(SrcDrawable Id, DstDrawable Id, Gc Id, SrcX int16, SrcY int16, DstX int16, DstY int16, Width uint16, Height uint16) { +func (c *Conn) CopyArea(SrcDrawable Id, DstDrawable Id, Gc Id, SrcX int16, SrcY int16, DstX int16, DstY int16, Width uint16, Height uint16) CopyAreaCookie { + cookie := c.newCookie(false, false) + c.newRequest(copyAreaRequest(SrcDrawable, DstDrawable, Gc, SrcX, SrcY, DstX, DstY, Width, Height), cookie) + return CopyAreaCookie(cookie) +} + +func (c *Conn) CopyAreaChecked(SrcDrawable Id, DstDrawable Id, Gc Id, SrcX int16, SrcY int16, DstX int16, DstY int16, Width uint16, Height uint16) CopyAreaCookie { + cookie := c.newCookie(true, false) + c.newRequest(copyAreaRequest(SrcDrawable, DstDrawable, Gc, SrcX, SrcY, DstX, DstY, Width, Height), cookie) + return CopyAreaCookie(cookie) +} + +// Write request to wire for CopyArea +func copyAreaRequest(SrcDrawable Id, DstDrawable Id, Gc Id, SrcX int16, SrcY int16, DstX int16, DstY int16, Width uint16, Height uint16) []byte { size := 28 b := 0 buf := make([]byte, size) @@ -8630,13 +9672,28 @@ func (c *Conn) CopyArea(SrcDrawable Id, DstDrawable Id, Gc Id, SrcX int16, SrcY Put16(buf[b:], Height) b += 2 - c.sendRequest(false, buf) + return buf } // Request CopyPlane // size: 32 +type CopyPlaneCookie cookie + // Write request to wire for CopyPlane -func (c *Conn) CopyPlane(SrcDrawable Id, DstDrawable Id, Gc Id, SrcX int16, SrcY int16, DstX int16, DstY int16, Width uint16, Height uint16, BitPlane uint32) { +func (c *Conn) CopyPlane(SrcDrawable Id, DstDrawable Id, Gc Id, SrcX int16, SrcY int16, DstX int16, DstY int16, Width uint16, Height uint16, BitPlane uint32) CopyPlaneCookie { + cookie := c.newCookie(false, false) + c.newRequest(copyPlaneRequest(SrcDrawable, DstDrawable, Gc, SrcX, SrcY, DstX, DstY, Width, Height, BitPlane), cookie) + return CopyPlaneCookie(cookie) +} + +func (c *Conn) CopyPlaneChecked(SrcDrawable Id, DstDrawable Id, Gc Id, SrcX int16, SrcY int16, DstX int16, DstY int16, Width uint16, Height uint16, BitPlane uint32) CopyPlaneCookie { + cookie := c.newCookie(true, false) + c.newRequest(copyPlaneRequest(SrcDrawable, DstDrawable, Gc, SrcX, SrcY, DstX, DstY, Width, Height, BitPlane), cookie) + return CopyPlaneCookie(cookie) +} + +// Write request to wire for CopyPlane +func copyPlaneRequest(SrcDrawable Id, DstDrawable Id, Gc Id, SrcX int16, SrcY int16, DstX int16, DstY int16, Width uint16, Height uint16, BitPlane uint32) []byte { size := 32 b := 0 buf := make([]byte, size) @@ -8679,14 +9736,29 @@ func (c *Conn) CopyPlane(SrcDrawable Id, DstDrawable Id, Gc Id, SrcX int16, SrcY Put32(buf[b:], BitPlane) b += 4 - c.sendRequest(false, buf) + return buf } // Request PolyPoint -// size: (12 + pad((len(Points) * 4))) +// size: pad((12 + pad((len(Points) * 4)))) +type PolyPointCookie cookie + // Write request to wire for PolyPoint -func (c *Conn) PolyPoint(CoordinateMode byte, Drawable Id, Gc Id, Points []Point) { - size := (12 + pad((len(Points) * 4))) +func (c *Conn) PolyPoint(CoordinateMode byte, Drawable Id, Gc Id, Points []Point) PolyPointCookie { + cookie := c.newCookie(false, false) + c.newRequest(polyPointRequest(CoordinateMode, Drawable, Gc, Points), cookie) + return PolyPointCookie(cookie) +} + +func (c *Conn) PolyPointChecked(CoordinateMode byte, Drawable Id, Gc Id, Points []Point) PolyPointCookie { + cookie := c.newCookie(true, false) + c.newRequest(polyPointRequest(CoordinateMode, Drawable, Gc, Points), cookie) + return PolyPointCookie(cookie) +} + +// Write request to wire for PolyPoint +func polyPointRequest(CoordinateMode byte, Drawable Id, Gc Id, Points []Point) []byte { + size := pad((12 + pad((len(Points) * 4)))) b := 0 buf := make([]byte, size) @@ -8707,14 +9779,29 @@ func (c *Conn) PolyPoint(CoordinateMode byte, Drawable Id, Gc Id, Points []Point b += PointListBytes(buf[b:], Points) - c.sendRequest(false, buf) + return buf } // Request PolyLine -// size: (12 + pad((len(Points) * 4))) +// size: pad((12 + pad((len(Points) * 4)))) +type PolyLineCookie cookie + // Write request to wire for PolyLine -func (c *Conn) PolyLine(CoordinateMode byte, Drawable Id, Gc Id, Points []Point) { - size := (12 + pad((len(Points) * 4))) +func (c *Conn) PolyLine(CoordinateMode byte, Drawable Id, Gc Id, Points []Point) PolyLineCookie { + cookie := c.newCookie(false, false) + c.newRequest(polyLineRequest(CoordinateMode, Drawable, Gc, Points), cookie) + return PolyLineCookie(cookie) +} + +func (c *Conn) PolyLineChecked(CoordinateMode byte, Drawable Id, Gc Id, Points []Point) PolyLineCookie { + cookie := c.newCookie(true, false) + c.newRequest(polyLineRequest(CoordinateMode, Drawable, Gc, Points), cookie) + return PolyLineCookie(cookie) +} + +// Write request to wire for PolyLine +func polyLineRequest(CoordinateMode byte, Drawable Id, Gc Id, Points []Point) []byte { + size := pad((12 + pad((len(Points) * 4)))) b := 0 buf := make([]byte, size) @@ -8735,14 +9822,29 @@ func (c *Conn) PolyLine(CoordinateMode byte, Drawable Id, Gc Id, Points []Point) b += PointListBytes(buf[b:], Points) - c.sendRequest(false, buf) + return buf } // Request PolySegment -// size: (12 + pad((len(Segments) * 8))) +// size: pad((12 + pad((len(Segments) * 8)))) +type PolySegmentCookie cookie + // Write request to wire for PolySegment -func (c *Conn) PolySegment(Drawable Id, Gc Id, Segments []Segment) { - size := (12 + pad((len(Segments) * 8))) +func (c *Conn) PolySegment(Drawable Id, Gc Id, Segments []Segment) PolySegmentCookie { + cookie := c.newCookie(false, false) + c.newRequest(polySegmentRequest(Drawable, Gc, Segments), cookie) + return PolySegmentCookie(cookie) +} + +func (c *Conn) PolySegmentChecked(Drawable Id, Gc Id, Segments []Segment) PolySegmentCookie { + cookie := c.newCookie(true, false) + c.newRequest(polySegmentRequest(Drawable, Gc, Segments), cookie) + return PolySegmentCookie(cookie) +} + +// Write request to wire for PolySegment +func polySegmentRequest(Drawable Id, Gc Id, Segments []Segment) []byte { + size := pad((12 + pad((len(Segments) * 8)))) b := 0 buf := make([]byte, size) @@ -8762,14 +9864,29 @@ func (c *Conn) PolySegment(Drawable Id, Gc Id, Segments []Segment) { b += SegmentListBytes(buf[b:], Segments) - c.sendRequest(false, buf) + return buf } // Request PolyRectangle -// size: (12 + pad((len(Rectangles) * 8))) +// size: pad((12 + pad((len(Rectangles) * 8)))) +type PolyRectangleCookie cookie + // Write request to wire for PolyRectangle -func (c *Conn) PolyRectangle(Drawable Id, Gc Id, Rectangles []Rectangle) { - size := (12 + pad((len(Rectangles) * 8))) +func (c *Conn) PolyRectangle(Drawable Id, Gc Id, Rectangles []Rectangle) PolyRectangleCookie { + cookie := c.newCookie(false, false) + c.newRequest(polyRectangleRequest(Drawable, Gc, Rectangles), cookie) + return PolyRectangleCookie(cookie) +} + +func (c *Conn) PolyRectangleChecked(Drawable Id, Gc Id, Rectangles []Rectangle) PolyRectangleCookie { + cookie := c.newCookie(true, false) + c.newRequest(polyRectangleRequest(Drawable, Gc, Rectangles), cookie) + return PolyRectangleCookie(cookie) +} + +// Write request to wire for PolyRectangle +func polyRectangleRequest(Drawable Id, Gc Id, Rectangles []Rectangle) []byte { + size := pad((12 + pad((len(Rectangles) * 8)))) b := 0 buf := make([]byte, size) @@ -8789,14 +9906,29 @@ func (c *Conn) PolyRectangle(Drawable Id, Gc Id, Rectangles []Rectangle) { b += RectangleListBytes(buf[b:], Rectangles) - c.sendRequest(false, buf) + return buf } // Request PolyArc -// size: (12 + pad((len(Arcs) * 12))) +// size: pad((12 + pad((len(Arcs) * 12)))) +type PolyArcCookie cookie + // Write request to wire for PolyArc -func (c *Conn) PolyArc(Drawable Id, Gc Id, Arcs []Arc) { - size := (12 + pad((len(Arcs) * 12))) +func (c *Conn) PolyArc(Drawable Id, Gc Id, Arcs []Arc) PolyArcCookie { + cookie := c.newCookie(false, false) + c.newRequest(polyArcRequest(Drawable, Gc, Arcs), cookie) + return PolyArcCookie(cookie) +} + +func (c *Conn) PolyArcChecked(Drawable Id, Gc Id, Arcs []Arc) PolyArcCookie { + cookie := c.newCookie(true, false) + c.newRequest(polyArcRequest(Drawable, Gc, Arcs), cookie) + return PolyArcCookie(cookie) +} + +// Write request to wire for PolyArc +func polyArcRequest(Drawable Id, Gc Id, Arcs []Arc) []byte { + size := pad((12 + pad((len(Arcs) * 12)))) b := 0 buf := make([]byte, size) @@ -8816,14 +9948,29 @@ func (c *Conn) PolyArc(Drawable Id, Gc Id, Arcs []Arc) { b += ArcListBytes(buf[b:], Arcs) - c.sendRequest(false, buf) + return buf } // Request FillPoly -// size: (16 + pad((len(Points) * 4))) +// size: pad((16 + pad((len(Points) * 4)))) +type FillPolyCookie cookie + // Write request to wire for FillPoly -func (c *Conn) FillPoly(Drawable Id, Gc Id, Shape byte, CoordinateMode byte, Points []Point) { - size := (16 + pad((len(Points) * 4))) +func (c *Conn) FillPoly(Drawable Id, Gc Id, Shape byte, CoordinateMode byte, Points []Point) FillPolyCookie { + cookie := c.newCookie(false, false) + c.newRequest(fillPolyRequest(Drawable, Gc, Shape, CoordinateMode, Points), cookie) + return FillPolyCookie(cookie) +} + +func (c *Conn) FillPolyChecked(Drawable Id, Gc Id, Shape byte, CoordinateMode byte, Points []Point) FillPolyCookie { + cookie := c.newCookie(true, false) + c.newRequest(fillPolyRequest(Drawable, Gc, Shape, CoordinateMode, Points), cookie) + return FillPolyCookie(cookie) +} + +// Write request to wire for FillPoly +func fillPolyRequest(Drawable Id, Gc Id, Shape byte, CoordinateMode byte, Points []Point) []byte { + size := pad((16 + pad((len(Points) * 4)))) b := 0 buf := make([]byte, size) @@ -8851,14 +9998,29 @@ func (c *Conn) FillPoly(Drawable Id, Gc Id, Shape byte, CoordinateMode byte, Poi b += PointListBytes(buf[b:], Points) - c.sendRequest(false, buf) + return buf } // Request PolyFillRectangle -// size: (12 + pad((len(Rectangles) * 8))) +// size: pad((12 + pad((len(Rectangles) * 8)))) +type PolyFillRectangleCookie cookie + // Write request to wire for PolyFillRectangle -func (c *Conn) PolyFillRectangle(Drawable Id, Gc Id, Rectangles []Rectangle) { - size := (12 + pad((len(Rectangles) * 8))) +func (c *Conn) PolyFillRectangle(Drawable Id, Gc Id, Rectangles []Rectangle) PolyFillRectangleCookie { + cookie := c.newCookie(false, false) + c.newRequest(polyFillRectangleRequest(Drawable, Gc, Rectangles), cookie) + return PolyFillRectangleCookie(cookie) +} + +func (c *Conn) PolyFillRectangleChecked(Drawable Id, Gc Id, Rectangles []Rectangle) PolyFillRectangleCookie { + cookie := c.newCookie(true, false) + c.newRequest(polyFillRectangleRequest(Drawable, Gc, Rectangles), cookie) + return PolyFillRectangleCookie(cookie) +} + +// Write request to wire for PolyFillRectangle +func polyFillRectangleRequest(Drawable Id, Gc Id, Rectangles []Rectangle) []byte { + size := pad((12 + pad((len(Rectangles) * 8)))) b := 0 buf := make([]byte, size) @@ -8878,14 +10040,29 @@ func (c *Conn) PolyFillRectangle(Drawable Id, Gc Id, Rectangles []Rectangle) { b += RectangleListBytes(buf[b:], Rectangles) - c.sendRequest(false, buf) + return buf } // Request PolyFillArc -// size: (12 + pad((len(Arcs) * 12))) +// size: pad((12 + pad((len(Arcs) * 12)))) +type PolyFillArcCookie cookie + // Write request to wire for PolyFillArc -func (c *Conn) PolyFillArc(Drawable Id, Gc Id, Arcs []Arc) { - size := (12 + pad((len(Arcs) * 12))) +func (c *Conn) PolyFillArc(Drawable Id, Gc Id, Arcs []Arc) PolyFillArcCookie { + cookie := c.newCookie(false, false) + c.newRequest(polyFillArcRequest(Drawable, Gc, Arcs), cookie) + return PolyFillArcCookie(cookie) +} + +func (c *Conn) PolyFillArcChecked(Drawable Id, Gc Id, Arcs []Arc) PolyFillArcCookie { + cookie := c.newCookie(true, false) + c.newRequest(polyFillArcRequest(Drawable, Gc, Arcs), cookie) + return PolyFillArcCookie(cookie) +} + +// Write request to wire for PolyFillArc +func polyFillArcRequest(Drawable Id, Gc Id, Arcs []Arc) []byte { + size := pad((12 + pad((len(Arcs) * 12)))) b := 0 buf := make([]byte, size) @@ -8905,14 +10082,29 @@ func (c *Conn) PolyFillArc(Drawable Id, Gc Id, Arcs []Arc) { b += ArcListBytes(buf[b:], Arcs) - c.sendRequest(false, buf) + return buf } // Request PutImage -// size: (24 + pad((len(Data) * 1))) +// size: pad((24 + pad((len(Data) * 1)))) +type PutImageCookie cookie + // Write request to wire for PutImage -func (c *Conn) PutImage(Format byte, Drawable Id, Gc Id, Width uint16, Height uint16, DstX int16, DstY int16, LeftPad byte, Depth byte, Data []byte) { - size := (24 + pad((len(Data) * 1))) +func (c *Conn) PutImage(Format byte, Drawable Id, Gc Id, Width uint16, Height uint16, DstX int16, DstY int16, LeftPad byte, Depth byte, Data []byte) PutImageCookie { + cookie := c.newCookie(false, false) + c.newRequest(putImageRequest(Format, Drawable, Gc, Width, Height, DstX, DstY, LeftPad, Depth, Data), cookie) + return PutImageCookie(cookie) +} + +func (c *Conn) PutImageChecked(Format byte, Drawable Id, Gc Id, Width uint16, Height uint16, DstX int16, DstY int16, LeftPad byte, Depth byte, Data []byte) PutImageCookie { + cookie := c.newCookie(true, false) + c.newRequest(putImageRequest(Format, Drawable, Gc, Width, Height, DstX, DstY, LeftPad, Depth, Data), cookie) + return PutImageCookie(cookie) +} + +// Write request to wire for PutImage +func putImageRequest(Format byte, Drawable Id, Gc Id, Width uint16, Height uint16, DstX int16, DstY int16, LeftPad byte, Depth byte, Data []byte) []byte { + size := pad((24 + pad((len(Data) * 1)))) b := 0 buf := make([]byte, size) @@ -8954,17 +10146,73 @@ func (c *Conn) PutImage(Format byte, Drawable Id, Gc Id, Width uint16, Height ui copy(buf[b:], Data[:len(Data)]) b += pad(int(len(Data))) - c.sendRequest(false, buf) + return buf } // Request GetImage // size: 20 -func (c *Conn) GetImage(Format byte, Drawable Id, X int16, Y int16, Width uint16, Height uint16, PlaneMask uint32) (*GetImageReply, error) { - return c.GetImageReply(c.GetImageRequest(Format, Drawable, X, Y, Width, Height, PlaneMask)) +type GetImageCookie cookie + +func (c *Conn) GetImage(Format byte, Drawable Id, X int16, Y int16, Width uint16, Height uint16, PlaneMask uint32) GetImageCookie { + cookie := c.newCookie(true, true) + c.newRequest(getImageRequest(Format, Drawable, X, Y, Width, Height, PlaneMask), cookie) + return GetImageCookie(cookie) +} + +func (c *Conn) GetImageUnchecked(Format byte, Drawable Id, X int16, Y int16, Width uint16, Height uint16, PlaneMask uint32) GetImageCookie { + cookie := c.newCookie(false, true) + c.newRequest(getImageRequest(Format, Drawable, X, Y, Width, Height, PlaneMask), cookie) + return GetImageCookie(cookie) +} + +// Request reply for GetImage +// size: (32 + pad(((int(Length) * 4) * 1))) +type GetImageReply struct { + Sequence uint16 + Length uint32 + Depth byte + Visual Visualid + // padding: 20 bytes + Data []byte // size: pad(((int(Length) * 4) * 1)) +} + +// Waits and reads reply data from request GetImage +func (cook GetImageCookie) Reply() (*GetImageReply, error) { + buf, err := cookie(cook).reply() + if err != nil { + return nil, err + } + return getImageReply(buf), nil +} + +// Read reply into structure from buffer for GetImage +func getImageReply(buf []byte) *GetImageReply { + v := new(GetImageReply) + b := 1 // skip reply determinant + + v.Depth = buf[b] + b += 1 + + v.Sequence = Get16(buf[b:]) + b += 2 + + v.Length = Get32(buf[b:]) // 4-byte units + b += 4 + + v.Visual = Visualid(Get32(buf[b:])) + b += 4 + + b += 20 // padding + + v.Data = make([]byte, (int(v.Length) * 4)) + copy(v.Data[:(int(v.Length)*4)], buf[b:]) + b += pad(int((int(v.Length) * 4))) + + return v } // Write request to wire for GetImage -func (c *Conn) GetImageRequest(Format byte, Drawable Id, X int16, Y int16, Width uint16, Height uint16, PlaneMask uint32) *Cookie { +func getImageRequest(Format byte, Drawable Id, X int16, Y int16, Width uint16, Height uint16, PlaneMask uint32) []byte { size := 20 b := 0 buf := make([]byte, size) @@ -8996,56 +10244,29 @@ func (c *Conn) GetImageRequest(Format byte, Drawable Id, X int16, Y int16, Width Put32(buf[b:], PlaneMask) b += 4 - return c.sendRequest(true, buf) -} - -// Request reply for GetImage -// size: (32 + pad(((int(Length) * 4) * 1))) -type GetImageReply struct { - Sequence uint16 - Length uint32 - Depth byte - Visual Visualid - // padding: 20 bytes - Data []byte // size: pad(((int(Length) * 4) * 1)) -} - -// Read reply GetImage -func (c *Conn) GetImageReply(cook *Cookie) (*GetImageReply, error) { - buf, err := c.waitForReply(cook) - if err != nil { - return nil, err - } - - v := new(GetImageReply) - b := 1 // skip reply determinant - - v.Depth = buf[b] - b += 1 - - v.Sequence = Get16(buf[b:]) - b += 2 - - v.Length = Get32(buf[b:]) // 4-byte units - b += 4 - - v.Visual = Visualid(Get32(buf[b:])) - b += 4 - - b += 20 // padding - - v.Data = make([]byte, (int(v.Length) * 4)) - copy(v.Data[:(int(v.Length)*4)], buf[b:]) - b += pad(int((int(v.Length) * 4))) - - return v, nil + return buf } // Request PolyText8 -// size: (16 + pad((len(Items) * 1))) +// size: pad((16 + pad((len(Items) * 1)))) +type PolyText8Cookie cookie + // Write request to wire for PolyText8 -func (c *Conn) PolyText8(Drawable Id, Gc Id, X int16, Y int16, Items []byte) { - size := (16 + pad((len(Items) * 1))) +func (c *Conn) PolyText8(Drawable Id, Gc Id, X int16, Y int16, Items []byte) PolyText8Cookie { + cookie := c.newCookie(false, false) + c.newRequest(polyText8Request(Drawable, Gc, X, Y, Items), cookie) + return PolyText8Cookie(cookie) +} + +func (c *Conn) PolyText8Checked(Drawable Id, Gc Id, X int16, Y int16, Items []byte) PolyText8Cookie { + cookie := c.newCookie(true, false) + c.newRequest(polyText8Request(Drawable, Gc, X, Y, Items), cookie) + return PolyText8Cookie(cookie) +} + +// Write request to wire for PolyText8 +func polyText8Request(Drawable Id, Gc Id, X int16, Y int16, Items []byte) []byte { + size := pad((16 + pad((len(Items) * 1)))) b := 0 buf := make([]byte, size) @@ -9072,14 +10293,29 @@ func (c *Conn) PolyText8(Drawable Id, Gc Id, X int16, Y int16, Items []byte) { copy(buf[b:], Items[:len(Items)]) b += pad(int(len(Items))) - c.sendRequest(false, buf) + return buf } // Request PolyText16 -// size: (16 + pad((len(Items) * 1))) +// size: pad((16 + pad((len(Items) * 1)))) +type PolyText16Cookie cookie + // Write request to wire for PolyText16 -func (c *Conn) PolyText16(Drawable Id, Gc Id, X int16, Y int16, Items []byte) { - size := (16 + pad((len(Items) * 1))) +func (c *Conn) PolyText16(Drawable Id, Gc Id, X int16, Y int16, Items []byte) PolyText16Cookie { + cookie := c.newCookie(false, false) + c.newRequest(polyText16Request(Drawable, Gc, X, Y, Items), cookie) + return PolyText16Cookie(cookie) +} + +func (c *Conn) PolyText16Checked(Drawable Id, Gc Id, X int16, Y int16, Items []byte) PolyText16Cookie { + cookie := c.newCookie(true, false) + c.newRequest(polyText16Request(Drawable, Gc, X, Y, Items), cookie) + return PolyText16Cookie(cookie) +} + +// Write request to wire for PolyText16 +func polyText16Request(Drawable Id, Gc Id, X int16, Y int16, Items []byte) []byte { + size := pad((16 + pad((len(Items) * 1)))) b := 0 buf := make([]byte, size) @@ -9106,14 +10342,29 @@ func (c *Conn) PolyText16(Drawable Id, Gc Id, X int16, Y int16, Items []byte) { copy(buf[b:], Items[:len(Items)]) b += pad(int(len(Items))) - c.sendRequest(false, buf) + return buf } // Request ImageText8 -// size: (16 + pad((int(StringLen) * 1))) +// size: pad((16 + pad((int(StringLen) * 1)))) +type ImageText8Cookie cookie + // Write request to wire for ImageText8 -func (c *Conn) ImageText8(StringLen byte, Drawable Id, Gc Id, X int16, Y int16, String string) { - size := (16 + pad((int(StringLen) * 1))) +func (c *Conn) ImageText8(StringLen byte, Drawable Id, Gc Id, X int16, Y int16, String string) ImageText8Cookie { + cookie := c.newCookie(false, false) + c.newRequest(imageText8Request(StringLen, Drawable, Gc, X, Y, String), cookie) + return ImageText8Cookie(cookie) +} + +func (c *Conn) ImageText8Checked(StringLen byte, Drawable Id, Gc Id, X int16, Y int16, String string) ImageText8Cookie { + cookie := c.newCookie(true, false) + c.newRequest(imageText8Request(StringLen, Drawable, Gc, X, Y, String), cookie) + return ImageText8Cookie(cookie) +} + +// Write request to wire for ImageText8 +func imageText8Request(StringLen byte, Drawable Id, Gc Id, X int16, Y int16, String string) []byte { + size := pad((16 + pad((int(StringLen) * 1)))) b := 0 buf := make([]byte, size) @@ -9141,14 +10392,29 @@ func (c *Conn) ImageText8(StringLen byte, Drawable Id, Gc Id, X int16, Y int16, copy(buf[b:], String[:StringLen]) b += pad(int(StringLen)) - c.sendRequest(false, buf) + return buf } // Request ImageText16 -// size: (16 + pad((int(StringLen) * 2))) +// size: pad((16 + pad((int(StringLen) * 2)))) +type ImageText16Cookie cookie + // Write request to wire for ImageText16 -func (c *Conn) ImageText16(StringLen byte, Drawable Id, Gc Id, X int16, Y int16, String []Char2b) { - size := (16 + pad((int(StringLen) * 2))) +func (c *Conn) ImageText16(StringLen byte, Drawable Id, Gc Id, X int16, Y int16, String []Char2b) ImageText16Cookie { + cookie := c.newCookie(false, false) + c.newRequest(imageText16Request(StringLen, Drawable, Gc, X, Y, String), cookie) + return ImageText16Cookie(cookie) +} + +func (c *Conn) ImageText16Checked(StringLen byte, Drawable Id, Gc Id, X int16, Y int16, String []Char2b) ImageText16Cookie { + cookie := c.newCookie(true, false) + c.newRequest(imageText16Request(StringLen, Drawable, Gc, X, Y, String), cookie) + return ImageText16Cookie(cookie) +} + +// Write request to wire for ImageText16 +func imageText16Request(StringLen byte, Drawable Id, Gc Id, X int16, Y int16, String []Char2b) []byte { + size := pad((16 + pad((int(StringLen) * 2)))) b := 0 buf := make([]byte, size) @@ -9175,13 +10441,28 @@ func (c *Conn) ImageText16(StringLen byte, Drawable Id, Gc Id, X int16, Y int16, b += Char2bListBytes(buf[b:], String) - c.sendRequest(false, buf) + return buf } // Request CreateColormap // size: 16 +type CreateColormapCookie cookie + // Write request to wire for CreateColormap -func (c *Conn) CreateColormap(Alloc byte, Mid Id, Window Id, Visual Visualid) { +func (c *Conn) CreateColormap(Alloc byte, Mid Id, Window Id, Visual Visualid) CreateColormapCookie { + cookie := c.newCookie(false, false) + c.newRequest(createColormapRequest(Alloc, Mid, Window, Visual), cookie) + return CreateColormapCookie(cookie) +} + +func (c *Conn) CreateColormapChecked(Alloc byte, Mid Id, Window Id, Visual Visualid) CreateColormapCookie { + cookie := c.newCookie(true, false) + c.newRequest(createColormapRequest(Alloc, Mid, Window, Visual), cookie) + return CreateColormapCookie(cookie) +} + +// Write request to wire for CreateColormap +func createColormapRequest(Alloc byte, Mid Id, Window Id, Visual Visualid) []byte { size := 16 b := 0 buf := make([]byte, size) @@ -9204,13 +10485,28 @@ func (c *Conn) CreateColormap(Alloc byte, Mid Id, Window Id, Visual Visualid) { Put32(buf[b:], uint32(Visual)) b += 4 - c.sendRequest(false, buf) + return buf } // Request FreeColormap // size: 8 +type FreeColormapCookie cookie + // Write request to wire for FreeColormap -func (c *Conn) FreeColormap(Cmap Id) { +func (c *Conn) FreeColormap(Cmap Id) FreeColormapCookie { + cookie := c.newCookie(false, false) + c.newRequest(freeColormapRequest(Cmap), cookie) + return FreeColormapCookie(cookie) +} + +func (c *Conn) FreeColormapChecked(Cmap Id) FreeColormapCookie { + cookie := c.newCookie(true, false) + c.newRequest(freeColormapRequest(Cmap), cookie) + return FreeColormapCookie(cookie) +} + +// Write request to wire for FreeColormap +func freeColormapRequest(Cmap Id) []byte { size := 8 b := 0 buf := make([]byte, size) @@ -9226,13 +10522,28 @@ func (c *Conn) FreeColormap(Cmap Id) { Put32(buf[b:], uint32(Cmap)) b += 4 - c.sendRequest(false, buf) + return buf } // Request CopyColormapAndFree // size: 12 +type CopyColormapAndFreeCookie cookie + // Write request to wire for CopyColormapAndFree -func (c *Conn) CopyColormapAndFree(Mid Id, SrcCmap Id) { +func (c *Conn) CopyColormapAndFree(Mid Id, SrcCmap Id) CopyColormapAndFreeCookie { + cookie := c.newCookie(false, false) + c.newRequest(copyColormapAndFreeRequest(Mid, SrcCmap), cookie) + return CopyColormapAndFreeCookie(cookie) +} + +func (c *Conn) CopyColormapAndFreeChecked(Mid Id, SrcCmap Id) CopyColormapAndFreeCookie { + cookie := c.newCookie(true, false) + c.newRequest(copyColormapAndFreeRequest(Mid, SrcCmap), cookie) + return CopyColormapAndFreeCookie(cookie) +} + +// Write request to wire for CopyColormapAndFree +func copyColormapAndFreeRequest(Mid Id, SrcCmap Id) []byte { size := 12 b := 0 buf := make([]byte, size) @@ -9251,13 +10562,28 @@ func (c *Conn) CopyColormapAndFree(Mid Id, SrcCmap Id) { Put32(buf[b:], uint32(SrcCmap)) b += 4 - c.sendRequest(false, buf) + return buf } // Request InstallColormap // size: 8 +type InstallColormapCookie cookie + // Write request to wire for InstallColormap -func (c *Conn) InstallColormap(Cmap Id) { +func (c *Conn) InstallColormap(Cmap Id) InstallColormapCookie { + cookie := c.newCookie(false, false) + c.newRequest(installColormapRequest(Cmap), cookie) + return InstallColormapCookie(cookie) +} + +func (c *Conn) InstallColormapChecked(Cmap Id) InstallColormapCookie { + cookie := c.newCookie(true, false) + c.newRequest(installColormapRequest(Cmap), cookie) + return InstallColormapCookie(cookie) +} + +// Write request to wire for InstallColormap +func installColormapRequest(Cmap Id) []byte { size := 8 b := 0 buf := make([]byte, size) @@ -9273,13 +10599,28 @@ func (c *Conn) InstallColormap(Cmap Id) { Put32(buf[b:], uint32(Cmap)) b += 4 - c.sendRequest(false, buf) + return buf } // Request UninstallColormap // size: 8 +type UninstallColormapCookie cookie + // Write request to wire for UninstallColormap -func (c *Conn) UninstallColormap(Cmap Id) { +func (c *Conn) UninstallColormap(Cmap Id) UninstallColormapCookie { + cookie := c.newCookie(false, false) + c.newRequest(uninstallColormapRequest(Cmap), cookie) + return UninstallColormapCookie(cookie) +} + +func (c *Conn) UninstallColormapChecked(Cmap Id) UninstallColormapCookie { + cookie := c.newCookie(true, false) + c.newRequest(uninstallColormapRequest(Cmap), cookie) + return UninstallColormapCookie(cookie) +} + +// Write request to wire for UninstallColormap +func uninstallColormapRequest(Cmap Id) []byte { size := 8 b := 0 buf := make([]byte, size) @@ -9295,33 +10636,23 @@ func (c *Conn) UninstallColormap(Cmap Id) { Put32(buf[b:], uint32(Cmap)) b += 4 - c.sendRequest(false, buf) + return buf } // Request ListInstalledColormaps // size: 8 -func (c *Conn) ListInstalledColormaps(Window Id) (*ListInstalledColormapsReply, error) { - return c.ListInstalledColormapsReply(c.ListInstalledColormapsRequest(Window)) +type ListInstalledColormapsCookie cookie + +func (c *Conn) ListInstalledColormaps(Window Id) ListInstalledColormapsCookie { + cookie := c.newCookie(true, true) + c.newRequest(listInstalledColormapsRequest(Window), cookie) + return ListInstalledColormapsCookie(cookie) } -// Write request to wire for ListInstalledColormaps -func (c *Conn) ListInstalledColormapsRequest(Window Id) *Cookie { - size := 8 - b := 0 - buf := make([]byte, size) - - buf[b] = 83 // request opcode - b += 1 - - b += 1 // padding - - Put16(buf[b:], uint16(size/4)) // write request size in 4-byte units - b += 2 - - Put32(buf[b:], uint32(Window)) - b += 4 - - return c.sendRequest(true, buf) +func (c *Conn) ListInstalledColormapsUnchecked(Window Id) ListInstalledColormapsCookie { + cookie := c.newCookie(false, true) + c.newRequest(listInstalledColormapsRequest(Window), cookie) + return ListInstalledColormapsCookie(cookie) } // Request reply for ListInstalledColormaps @@ -9335,13 +10666,17 @@ type ListInstalledColormapsReply struct { Cmaps []Id // size: pad((int(CmapsLen) * 4)) } -// Read reply ListInstalledColormaps -func (c *Conn) ListInstalledColormapsReply(cook *Cookie) (*ListInstalledColormapsReply, error) { - buf, err := c.waitForReply(cook) +// Waits and reads reply data from request ListInstalledColormaps +func (cook ListInstalledColormapsCookie) Reply() (*ListInstalledColormapsReply, error) { + buf, err := cookie(cook).reply() if err != nil { return nil, err } + return listInstalledColormapsReply(buf), nil +} +// Read reply into structure from buffer for ListInstalledColormaps +func listInstalledColormapsReply(buf []byte) *ListInstalledColormapsReply { v := new(ListInstalledColormapsReply) b := 1 // skip reply determinant @@ -9365,17 +10700,99 @@ func (c *Conn) ListInstalledColormapsReply(cook *Cookie) (*ListInstalledColormap } b = pad(b) - return v, nil + return v +} + +// Write request to wire for ListInstalledColormaps +func listInstalledColormapsRequest(Window Id) []byte { + size := 8 + b := 0 + buf := make([]byte, size) + + buf[b] = 83 // request opcode + b += 1 + + b += 1 // padding + + Put16(buf[b:], uint16(size/4)) // write request size in 4-byte units + b += 2 + + Put32(buf[b:], uint32(Window)) + b += 4 + + return buf } // Request AllocColor // size: 16 -func (c *Conn) AllocColor(Cmap Id, Red uint16, Green uint16, Blue uint16) (*AllocColorReply, error) { - return c.AllocColorReply(c.AllocColorRequest(Cmap, Red, Green, Blue)) +type AllocColorCookie cookie + +func (c *Conn) AllocColor(Cmap Id, Red uint16, Green uint16, Blue uint16) AllocColorCookie { + cookie := c.newCookie(true, true) + c.newRequest(allocColorRequest(Cmap, Red, Green, Blue), cookie) + return AllocColorCookie(cookie) +} + +func (c *Conn) AllocColorUnchecked(Cmap Id, Red uint16, Green uint16, Blue uint16) AllocColorCookie { + cookie := c.newCookie(false, true) + c.newRequest(allocColorRequest(Cmap, Red, Green, Blue), cookie) + return AllocColorCookie(cookie) +} + +// Request reply for AllocColor +// size: 20 +type AllocColorReply struct { + Sequence uint16 + Length uint32 + // padding: 1 bytes + Red uint16 + Green uint16 + Blue uint16 + // padding: 2 bytes + Pixel uint32 +} + +// Waits and reads reply data from request AllocColor +func (cook AllocColorCookie) Reply() (*AllocColorReply, error) { + buf, err := cookie(cook).reply() + if err != nil { + return nil, err + } + return allocColorReply(buf), nil +} + +// Read reply into structure from buffer for AllocColor +func allocColorReply(buf []byte) *AllocColorReply { + v := new(AllocColorReply) + b := 1 // skip reply determinant + + b += 1 // padding + + v.Sequence = Get16(buf[b:]) + b += 2 + + v.Length = Get32(buf[b:]) // 4-byte units + b += 4 + + v.Red = Get16(buf[b:]) + b += 2 + + v.Green = Get16(buf[b:]) + b += 2 + + v.Blue = Get16(buf[b:]) + b += 2 + + b += 2 // padding + + v.Pixel = Get32(buf[b:]) + b += 4 + + return v } // Write request to wire for AllocColor -func (c *Conn) AllocColorRequest(Cmap Id, Red uint16, Green uint16, Blue uint16) *Cookie { +func allocColorRequest(Cmap Id, Red uint16, Green uint16, Blue uint16) []byte { size := 16 b := 0 buf := make([]byte, size) @@ -9402,89 +10819,23 @@ func (c *Conn) AllocColorRequest(Cmap Id, Red uint16, Green uint16, Blue uint16) b += 2 // padding - return c.sendRequest(true, buf) -} - -// Request reply for AllocColor -// size: 20 -type AllocColorReply struct { - Sequence uint16 - Length uint32 - // padding: 1 bytes - Red uint16 - Green uint16 - Blue uint16 - // padding: 2 bytes - Pixel uint32 -} - -// Read reply AllocColor -func (c *Conn) AllocColorReply(cook *Cookie) (*AllocColorReply, error) { - buf, err := c.waitForReply(cook) - if err != nil { - return nil, err - } - - v := new(AllocColorReply) - b := 1 // skip reply determinant - - b += 1 // padding - - v.Sequence = Get16(buf[b:]) - b += 2 - - v.Length = Get32(buf[b:]) // 4-byte units - b += 4 - - v.Red = Get16(buf[b:]) - b += 2 - - v.Green = Get16(buf[b:]) - b += 2 - - v.Blue = Get16(buf[b:]) - b += 2 - - b += 2 // padding - - v.Pixel = Get32(buf[b:]) - b += 4 - - return v, nil + return buf } // Request AllocNamedColor -// size: (12 + pad((int(NameLen) * 1))) -func (c *Conn) AllocNamedColor(Cmap Id, NameLen uint16, Name string) (*AllocNamedColorReply, error) { - return c.AllocNamedColorReply(c.AllocNamedColorRequest(Cmap, NameLen, Name)) +// size: pad((12 + pad((int(NameLen) * 1)))) +type AllocNamedColorCookie cookie + +func (c *Conn) AllocNamedColor(Cmap Id, NameLen uint16, Name string) AllocNamedColorCookie { + cookie := c.newCookie(true, true) + c.newRequest(allocNamedColorRequest(Cmap, NameLen, Name), cookie) + return AllocNamedColorCookie(cookie) } -// Write request to wire for AllocNamedColor -func (c *Conn) AllocNamedColorRequest(Cmap Id, NameLen uint16, Name string) *Cookie { - size := (12 + pad((int(NameLen) * 1))) - b := 0 - buf := make([]byte, size) - - buf[b] = 85 // request opcode - b += 1 - - b += 1 // padding - - Put16(buf[b:], uint16(size/4)) // write request size in 4-byte units - b += 2 - - Put32(buf[b:], uint32(Cmap)) - b += 4 - - Put16(buf[b:], NameLen) - b += 2 - - b += 2 // padding - - copy(buf[b:], Name[:NameLen]) - b += pad(int(NameLen)) - - return c.sendRequest(true, buf) +func (c *Conn) AllocNamedColorUnchecked(Cmap Id, NameLen uint16, Name string) AllocNamedColorCookie { + cookie := c.newCookie(false, true) + c.newRequest(allocNamedColorRequest(Cmap, NameLen, Name), cookie) + return AllocNamedColorCookie(cookie) } // Request reply for AllocNamedColor @@ -9502,13 +10853,17 @@ type AllocNamedColorReply struct { VisualBlue uint16 } -// Read reply AllocNamedColor -func (c *Conn) AllocNamedColorReply(cook *Cookie) (*AllocNamedColorReply, error) { - buf, err := c.waitForReply(cook) +// Waits and reads reply data from request AllocNamedColor +func (cook AllocNamedColorCookie) Reply() (*AllocNamedColorReply, error) { + buf, err := cookie(cook).reply() if err != nil { return nil, err } + return allocNamedColorReply(buf), nil +} +// Read reply into structure from buffer for AllocNamedColor +func allocNamedColorReply(buf []byte) *AllocNamedColorReply { v := new(AllocNamedColorReply) b := 1 // skip reply determinant @@ -9541,30 +10896,19 @@ func (c *Conn) AllocNamedColorReply(cook *Cookie) (*AllocNamedColorReply, error) v.VisualBlue = Get16(buf[b:]) b += 2 - return v, nil + return v } -// Request AllocColorCells -// size: 12 -func (c *Conn) AllocColorCells(Contiguous bool, Cmap Id, Colors uint16, Planes uint16) (*AllocColorCellsReply, error) { - return c.AllocColorCellsReply(c.AllocColorCellsRequest(Contiguous, Cmap, Colors, Planes)) -} - -// Write request to wire for AllocColorCells -func (c *Conn) AllocColorCellsRequest(Contiguous bool, Cmap Id, Colors uint16, Planes uint16) *Cookie { - size := 12 +// Write request to wire for AllocNamedColor +func allocNamedColorRequest(Cmap Id, NameLen uint16, Name string) []byte { + size := pad((12 + pad((int(NameLen) * 1)))) b := 0 buf := make([]byte, size) - buf[b] = 86 // request opcode + buf[b] = 85 // request opcode b += 1 - if Contiguous { - buf[b] = 1 - } else { - buf[b] = 0 - } - b += 1 + b += 1 // padding Put16(buf[b:], uint16(size/4)) // write request size in 4-byte units b += 2 @@ -9572,13 +10916,31 @@ func (c *Conn) AllocColorCellsRequest(Contiguous bool, Cmap Id, Colors uint16, P Put32(buf[b:], uint32(Cmap)) b += 4 - Put16(buf[b:], Colors) + Put16(buf[b:], NameLen) b += 2 - Put16(buf[b:], Planes) - b += 2 + b += 2 // padding - return c.sendRequest(true, buf) + copy(buf[b:], Name[:NameLen]) + b += pad(int(NameLen)) + + return buf +} + +// Request AllocColorCells +// size: 12 +type AllocColorCellsCookie cookie + +func (c *Conn) AllocColorCells(Contiguous bool, Cmap Id, Colors uint16, Planes uint16) AllocColorCellsCookie { + cookie := c.newCookie(true, true) + c.newRequest(allocColorCellsRequest(Contiguous, Cmap, Colors, Planes), cookie) + return AllocColorCellsCookie(cookie) +} + +func (c *Conn) AllocColorCellsUnchecked(Contiguous bool, Cmap Id, Colors uint16, Planes uint16) AllocColorCellsCookie { + cookie := c.newCookie(false, true) + c.newRequest(allocColorCellsRequest(Contiguous, Cmap, Colors, Planes), cookie) + return AllocColorCellsCookie(cookie) } // Request reply for AllocColorCells @@ -9594,13 +10956,17 @@ type AllocColorCellsReply struct { Masks []uint32 // size: pad((int(MasksLen) * 4)) } -// Read reply AllocColorCells -func (c *Conn) AllocColorCellsReply(cook *Cookie) (*AllocColorCellsReply, error) { - buf, err := c.waitForReply(cook) +// Waits and reads reply data from request AllocColorCells +func (cook AllocColorCellsCookie) Reply() (*AllocColorCellsReply, error) { + buf, err := cookie(cook).reply() if err != nil { return nil, err } + return allocColorCellsReply(buf), nil +} +// Read reply into structure from buffer for AllocColorCells +func allocColorCellsReply(buf []byte) *AllocColorCellsReply { v := new(AllocColorCellsReply) b := 1 // skip reply determinant @@ -9634,22 +11000,16 @@ func (c *Conn) AllocColorCellsReply(cook *Cookie) (*AllocColorCellsReply, error) } b = pad(b) - return v, nil + return v } -// Request AllocColorPlanes -// size: 16 -func (c *Conn) AllocColorPlanes(Contiguous bool, Cmap Id, Colors uint16, Reds uint16, Greens uint16, Blues uint16) (*AllocColorPlanesReply, error) { - return c.AllocColorPlanesReply(c.AllocColorPlanesRequest(Contiguous, Cmap, Colors, Reds, Greens, Blues)) -} - -// Write request to wire for AllocColorPlanes -func (c *Conn) AllocColorPlanesRequest(Contiguous bool, Cmap Id, Colors uint16, Reds uint16, Greens uint16, Blues uint16) *Cookie { - size := 16 +// Write request to wire for AllocColorCells +func allocColorCellsRequest(Contiguous bool, Cmap Id, Colors uint16, Planes uint16) []byte { + size := 12 b := 0 buf := make([]byte, size) - buf[b] = 87 // request opcode + buf[b] = 86 // request opcode b += 1 if Contiguous { @@ -9668,16 +11028,26 @@ func (c *Conn) AllocColorPlanesRequest(Contiguous bool, Cmap Id, Colors uint16, Put16(buf[b:], Colors) b += 2 - Put16(buf[b:], Reds) + Put16(buf[b:], Planes) b += 2 - Put16(buf[b:], Greens) - b += 2 + return buf +} - Put16(buf[b:], Blues) - b += 2 +// Request AllocColorPlanes +// size: 16 +type AllocColorPlanesCookie cookie - return c.sendRequest(true, buf) +func (c *Conn) AllocColorPlanes(Contiguous bool, Cmap Id, Colors uint16, Reds uint16, Greens uint16, Blues uint16) AllocColorPlanesCookie { + cookie := c.newCookie(true, true) + c.newRequest(allocColorPlanesRequest(Contiguous, Cmap, Colors, Reds, Greens, Blues), cookie) + return AllocColorPlanesCookie(cookie) +} + +func (c *Conn) AllocColorPlanesUnchecked(Contiguous bool, Cmap Id, Colors uint16, Reds uint16, Greens uint16, Blues uint16) AllocColorPlanesCookie { + cookie := c.newCookie(false, true) + c.newRequest(allocColorPlanesRequest(Contiguous, Cmap, Colors, Reds, Greens, Blues), cookie) + return AllocColorPlanesCookie(cookie) } // Request reply for AllocColorPlanes @@ -9695,13 +11065,17 @@ type AllocColorPlanesReply struct { Pixels []uint32 // size: pad((int(PixelsLen) * 4)) } -// Read reply AllocColorPlanes -func (c *Conn) AllocColorPlanesReply(cook *Cookie) (*AllocColorPlanesReply, error) { - buf, err := c.waitForReply(cook) +// Waits and reads reply data from request AllocColorPlanes +func (cook AllocColorPlanesCookie) Reply() (*AllocColorPlanesReply, error) { + buf, err := cookie(cook).reply() if err != nil { return nil, err } + return allocColorPlanesReply(buf), nil +} +// Read reply into structure from buffer for AllocColorPlanes +func allocColorPlanesReply(buf []byte) *AllocColorPlanesReply { v := new(AllocColorPlanesReply) b := 1 // skip reply determinant @@ -9736,14 +11110,66 @@ func (c *Conn) AllocColorPlanesReply(cook *Cookie) (*AllocColorPlanesReply, erro } b = pad(b) - return v, nil + return v +} + +// Write request to wire for AllocColorPlanes +func allocColorPlanesRequest(Contiguous bool, Cmap Id, Colors uint16, Reds uint16, Greens uint16, Blues uint16) []byte { + size := 16 + b := 0 + buf := make([]byte, size) + + buf[b] = 87 // request opcode + b += 1 + + if Contiguous { + buf[b] = 1 + } else { + buf[b] = 0 + } + b += 1 + + Put16(buf[b:], uint16(size/4)) // write request size in 4-byte units + b += 2 + + Put32(buf[b:], uint32(Cmap)) + b += 4 + + Put16(buf[b:], Colors) + b += 2 + + Put16(buf[b:], Reds) + b += 2 + + Put16(buf[b:], Greens) + b += 2 + + Put16(buf[b:], Blues) + b += 2 + + return buf } // Request FreeColors -// size: (12 + pad((len(Pixels) * 4))) +// size: pad((12 + pad((len(Pixels) * 4)))) +type FreeColorsCookie cookie + // Write request to wire for FreeColors -func (c *Conn) FreeColors(Cmap Id, PlaneMask uint32, Pixels []uint32) { - size := (12 + pad((len(Pixels) * 4))) +func (c *Conn) FreeColors(Cmap Id, PlaneMask uint32, Pixels []uint32) FreeColorsCookie { + cookie := c.newCookie(false, false) + c.newRequest(freeColorsRequest(Cmap, PlaneMask, Pixels), cookie) + return FreeColorsCookie(cookie) +} + +func (c *Conn) FreeColorsChecked(Cmap Id, PlaneMask uint32, Pixels []uint32) FreeColorsCookie { + cookie := c.newCookie(true, false) + c.newRequest(freeColorsRequest(Cmap, PlaneMask, Pixels), cookie) + return FreeColorsCookie(cookie) +} + +// Write request to wire for FreeColors +func freeColorsRequest(Cmap Id, PlaneMask uint32, Pixels []uint32) []byte { + size := pad((12 + pad((len(Pixels) * 4)))) b := 0 buf := make([]byte, size) @@ -9767,14 +11193,29 @@ func (c *Conn) FreeColors(Cmap Id, PlaneMask uint32, Pixels []uint32) { } b = pad(b) - c.sendRequest(false, buf) + return buf } // Request StoreColors -// size: (8 + pad((len(Items) * 12))) +// size: pad((8 + pad((len(Items) * 12)))) +type StoreColorsCookie cookie + // Write request to wire for StoreColors -func (c *Conn) StoreColors(Cmap Id, Items []Coloritem) { - size := (8 + pad((len(Items) * 12))) +func (c *Conn) StoreColors(Cmap Id, Items []Coloritem) StoreColorsCookie { + cookie := c.newCookie(false, false) + c.newRequest(storeColorsRequest(Cmap, Items), cookie) + return StoreColorsCookie(cookie) +} + +func (c *Conn) StoreColorsChecked(Cmap Id, Items []Coloritem) StoreColorsCookie { + cookie := c.newCookie(true, false) + c.newRequest(storeColorsRequest(Cmap, Items), cookie) + return StoreColorsCookie(cookie) +} + +// Write request to wire for StoreColors +func storeColorsRequest(Cmap Id, Items []Coloritem) []byte { + size := pad((8 + pad((len(Items) * 12)))) b := 0 buf := make([]byte, size) @@ -9791,14 +11232,29 @@ func (c *Conn) StoreColors(Cmap Id, Items []Coloritem) { b += ColoritemListBytes(buf[b:], Items) - c.sendRequest(false, buf) + return buf } // Request StoreNamedColor -// size: (16 + pad((int(NameLen) * 1))) +// size: pad((16 + pad((int(NameLen) * 1)))) +type StoreNamedColorCookie cookie + // Write request to wire for StoreNamedColor -func (c *Conn) StoreNamedColor(Flags byte, Cmap Id, Pixel uint32, NameLen uint16, Name string) { - size := (16 + pad((int(NameLen) * 1))) +func (c *Conn) StoreNamedColor(Flags byte, Cmap Id, Pixel uint32, NameLen uint16, Name string) StoreNamedColorCookie { + cookie := c.newCookie(false, false) + c.newRequest(storeNamedColorRequest(Flags, Cmap, Pixel, NameLen, Name), cookie) + return StoreNamedColorCookie(cookie) +} + +func (c *Conn) StoreNamedColorChecked(Flags byte, Cmap Id, Pixel uint32, NameLen uint16, Name string) StoreNamedColorCookie { + cookie := c.newCookie(true, false) + c.newRequest(storeNamedColorRequest(Flags, Cmap, Pixel, NameLen, Name), cookie) + return StoreNamedColorCookie(cookie) +} + +// Write request to wire for StoreNamedColor +func storeNamedColorRequest(Flags byte, Cmap Id, Pixel uint32, NameLen uint16, Name string) []byte { + size := pad((16 + pad((int(NameLen) * 1)))) b := 0 buf := make([]byte, size) @@ -9825,18 +11281,72 @@ func (c *Conn) StoreNamedColor(Flags byte, Cmap Id, Pixel uint32, NameLen uint16 copy(buf[b:], Name[:NameLen]) b += pad(int(NameLen)) - c.sendRequest(false, buf) + return buf } // Request QueryColors -// size: (8 + pad((len(Pixels) * 4))) -func (c *Conn) QueryColors(Cmap Id, Pixels []uint32) (*QueryColorsReply, error) { - return c.QueryColorsReply(c.QueryColorsRequest(Cmap, Pixels)) +// size: pad((8 + pad((len(Pixels) * 4)))) +type QueryColorsCookie cookie + +func (c *Conn) QueryColors(Cmap Id, Pixels []uint32) QueryColorsCookie { + cookie := c.newCookie(true, true) + c.newRequest(queryColorsRequest(Cmap, Pixels), cookie) + return QueryColorsCookie(cookie) +} + +func (c *Conn) QueryColorsUnchecked(Cmap Id, Pixels []uint32) QueryColorsCookie { + cookie := c.newCookie(false, true) + c.newRequest(queryColorsRequest(Cmap, Pixels), cookie) + return QueryColorsCookie(cookie) +} + +// Request reply for QueryColors +// size: (32 + pad((int(ColorsLen) * 8))) +type QueryColorsReply struct { + Sequence uint16 + Length uint32 + // padding: 1 bytes + ColorsLen uint16 + // padding: 22 bytes + Colors []Rgb // size: pad((int(ColorsLen) * 8)) +} + +// Waits and reads reply data from request QueryColors +func (cook QueryColorsCookie) Reply() (*QueryColorsReply, error) { + buf, err := cookie(cook).reply() + if err != nil { + return nil, err + } + return queryColorsReply(buf), nil +} + +// Read reply into structure from buffer for QueryColors +func queryColorsReply(buf []byte) *QueryColorsReply { + v := new(QueryColorsReply) + b := 1 // skip reply determinant + + b += 1 // padding + + v.Sequence = Get16(buf[b:]) + b += 2 + + v.Length = Get32(buf[b:]) // 4-byte units + b += 4 + + v.ColorsLen = Get16(buf[b:]) + b += 2 + + b += 22 // padding + + v.Colors = make([]Rgb, v.ColorsLen) + b += ReadRgbList(buf[b:], v.Colors) + + return v } // Write request to wire for QueryColors -func (c *Conn) QueryColorsRequest(Cmap Id, Pixels []uint32) *Cookie { - size := (8 + pad((len(Pixels) * 4))) +func queryColorsRequest(Cmap Id, Pixels []uint32) []byte { + size := pad((8 + pad((len(Pixels) * 4)))) b := 0 buf := make([]byte, size) @@ -9857,81 +11367,23 @@ func (c *Conn) QueryColorsRequest(Cmap Id, Pixels []uint32) *Cookie { } b = pad(b) - return c.sendRequest(true, buf) -} - -// Request reply for QueryColors -// size: (32 + pad((int(ColorsLen) * 8))) -type QueryColorsReply struct { - Sequence uint16 - Length uint32 - // padding: 1 bytes - ColorsLen uint16 - // padding: 22 bytes - Colors []Rgb // size: pad((int(ColorsLen) * 8)) -} - -// Read reply QueryColors -func (c *Conn) QueryColorsReply(cook *Cookie) (*QueryColorsReply, error) { - buf, err := c.waitForReply(cook) - if err != nil { - return nil, err - } - - v := new(QueryColorsReply) - b := 1 // skip reply determinant - - b += 1 // padding - - v.Sequence = Get16(buf[b:]) - b += 2 - - v.Length = Get32(buf[b:]) // 4-byte units - b += 4 - - v.ColorsLen = Get16(buf[b:]) - b += 2 - - b += 22 // padding - - v.Colors = make([]Rgb, v.ColorsLen) - b += ReadRgbList(buf[b:], v.Colors) - - return v, nil + return buf } // Request LookupColor -// size: (12 + pad((int(NameLen) * 1))) -func (c *Conn) LookupColor(Cmap Id, NameLen uint16, Name string) (*LookupColorReply, error) { - return c.LookupColorReply(c.LookupColorRequest(Cmap, NameLen, Name)) +// size: pad((12 + pad((int(NameLen) * 1)))) +type LookupColorCookie cookie + +func (c *Conn) LookupColor(Cmap Id, NameLen uint16, Name string) LookupColorCookie { + cookie := c.newCookie(true, true) + c.newRequest(lookupColorRequest(Cmap, NameLen, Name), cookie) + return LookupColorCookie(cookie) } -// Write request to wire for LookupColor -func (c *Conn) LookupColorRequest(Cmap Id, NameLen uint16, Name string) *Cookie { - size := (12 + pad((int(NameLen) * 1))) - b := 0 - buf := make([]byte, size) - - buf[b] = 92 // request opcode - b += 1 - - b += 1 // padding - - Put16(buf[b:], uint16(size/4)) // write request size in 4-byte units - b += 2 - - Put32(buf[b:], uint32(Cmap)) - b += 4 - - Put16(buf[b:], NameLen) - b += 2 - - b += 2 // padding - - copy(buf[b:], Name[:NameLen]) - b += pad(int(NameLen)) - - return c.sendRequest(true, buf) +func (c *Conn) LookupColorUnchecked(Cmap Id, NameLen uint16, Name string) LookupColorCookie { + cookie := c.newCookie(false, true) + c.newRequest(lookupColorRequest(Cmap, NameLen, Name), cookie) + return LookupColorCookie(cookie) } // Request reply for LookupColor @@ -9948,13 +11400,17 @@ type LookupColorReply struct { VisualBlue uint16 } -// Read reply LookupColor -func (c *Conn) LookupColorReply(cook *Cookie) (*LookupColorReply, error) { - buf, err := c.waitForReply(cook) +// Waits and reads reply data from request LookupColor +func (cook LookupColorCookie) Reply() (*LookupColorReply, error) { + buf, err := cookie(cook).reply() if err != nil { return nil, err } + return lookupColorReply(buf), nil +} +// Read reply into structure from buffer for LookupColor +func lookupColorReply(buf []byte) *LookupColorReply { v := new(LookupColorReply) b := 1 // skip reply determinant @@ -9984,13 +11440,56 @@ func (c *Conn) LookupColorReply(cook *Cookie) (*LookupColorReply, error) { v.VisualBlue = Get16(buf[b:]) b += 2 - return v, nil + return v +} + +// Write request to wire for LookupColor +func lookupColorRequest(Cmap Id, NameLen uint16, Name string) []byte { + size := pad((12 + pad((int(NameLen) * 1)))) + b := 0 + buf := make([]byte, size) + + buf[b] = 92 // request opcode + b += 1 + + b += 1 // padding + + Put16(buf[b:], uint16(size/4)) // write request size in 4-byte units + b += 2 + + Put32(buf[b:], uint32(Cmap)) + b += 4 + + Put16(buf[b:], NameLen) + b += 2 + + b += 2 // padding + + copy(buf[b:], Name[:NameLen]) + b += pad(int(NameLen)) + + return buf } // Request CreateCursor // size: 32 +type CreateCursorCookie cookie + // Write request to wire for CreateCursor -func (c *Conn) CreateCursor(Cid Id, Source Id, Mask Id, ForeRed uint16, ForeGreen uint16, ForeBlue uint16, BackRed uint16, BackGreen uint16, BackBlue uint16, X uint16, Y uint16) { +func (c *Conn) CreateCursor(Cid Id, Source Id, Mask Id, ForeRed uint16, ForeGreen uint16, ForeBlue uint16, BackRed uint16, BackGreen uint16, BackBlue uint16, X uint16, Y uint16) CreateCursorCookie { + cookie := c.newCookie(false, false) + c.newRequest(createCursorRequest(Cid, Source, Mask, ForeRed, ForeGreen, ForeBlue, BackRed, BackGreen, BackBlue, X, Y), cookie) + return CreateCursorCookie(cookie) +} + +func (c *Conn) CreateCursorChecked(Cid Id, Source Id, Mask Id, ForeRed uint16, ForeGreen uint16, ForeBlue uint16, BackRed uint16, BackGreen uint16, BackBlue uint16, X uint16, Y uint16) CreateCursorCookie { + cookie := c.newCookie(true, false) + c.newRequest(createCursorRequest(Cid, Source, Mask, ForeRed, ForeGreen, ForeBlue, BackRed, BackGreen, BackBlue, X, Y), cookie) + return CreateCursorCookie(cookie) +} + +// Write request to wire for CreateCursor +func createCursorRequest(Cid Id, Source Id, Mask Id, ForeRed uint16, ForeGreen uint16, ForeBlue uint16, BackRed uint16, BackGreen uint16, BackBlue uint16, X uint16, Y uint16) []byte { size := 32 b := 0 buf := make([]byte, size) @@ -10036,13 +11535,28 @@ func (c *Conn) CreateCursor(Cid Id, Source Id, Mask Id, ForeRed uint16, ForeGree Put16(buf[b:], Y) b += 2 - c.sendRequest(false, buf) + return buf } // Request CreateGlyphCursor // size: 32 +type CreateGlyphCursorCookie cookie + // Write request to wire for CreateGlyphCursor -func (c *Conn) CreateGlyphCursor(Cid Id, SourceFont Id, MaskFont Id, SourceChar uint16, MaskChar uint16, ForeRed uint16, ForeGreen uint16, ForeBlue uint16, BackRed uint16, BackGreen uint16, BackBlue uint16) { +func (c *Conn) CreateGlyphCursor(Cid Id, SourceFont Id, MaskFont Id, SourceChar uint16, MaskChar uint16, ForeRed uint16, ForeGreen uint16, ForeBlue uint16, BackRed uint16, BackGreen uint16, BackBlue uint16) CreateGlyphCursorCookie { + cookie := c.newCookie(false, false) + c.newRequest(createGlyphCursorRequest(Cid, SourceFont, MaskFont, SourceChar, MaskChar, ForeRed, ForeGreen, ForeBlue, BackRed, BackGreen, BackBlue), cookie) + return CreateGlyphCursorCookie(cookie) +} + +func (c *Conn) CreateGlyphCursorChecked(Cid Id, SourceFont Id, MaskFont Id, SourceChar uint16, MaskChar uint16, ForeRed uint16, ForeGreen uint16, ForeBlue uint16, BackRed uint16, BackGreen uint16, BackBlue uint16) CreateGlyphCursorCookie { + cookie := c.newCookie(true, false) + c.newRequest(createGlyphCursorRequest(Cid, SourceFont, MaskFont, SourceChar, MaskChar, ForeRed, ForeGreen, ForeBlue, BackRed, BackGreen, BackBlue), cookie) + return CreateGlyphCursorCookie(cookie) +} + +// Write request to wire for CreateGlyphCursor +func createGlyphCursorRequest(Cid Id, SourceFont Id, MaskFont Id, SourceChar uint16, MaskChar uint16, ForeRed uint16, ForeGreen uint16, ForeBlue uint16, BackRed uint16, BackGreen uint16, BackBlue uint16) []byte { size := 32 b := 0 buf := make([]byte, size) @@ -10088,13 +11602,28 @@ func (c *Conn) CreateGlyphCursor(Cid Id, SourceFont Id, MaskFont Id, SourceChar Put16(buf[b:], BackBlue) b += 2 - c.sendRequest(false, buf) + return buf } // Request FreeCursor // size: 8 +type FreeCursorCookie cookie + // Write request to wire for FreeCursor -func (c *Conn) FreeCursor(Cursor Id) { +func (c *Conn) FreeCursor(Cursor Id) FreeCursorCookie { + cookie := c.newCookie(false, false) + c.newRequest(freeCursorRequest(Cursor), cookie) + return FreeCursorCookie(cookie) +} + +func (c *Conn) FreeCursorChecked(Cursor Id) FreeCursorCookie { + cookie := c.newCookie(true, false) + c.newRequest(freeCursorRequest(Cursor), cookie) + return FreeCursorCookie(cookie) +} + +// Write request to wire for FreeCursor +func freeCursorRequest(Cursor Id) []byte { size := 8 b := 0 buf := make([]byte, size) @@ -10110,13 +11639,28 @@ func (c *Conn) FreeCursor(Cursor Id) { Put32(buf[b:], uint32(Cursor)) b += 4 - c.sendRequest(false, buf) + return buf } // Request RecolorCursor // size: 20 +type RecolorCursorCookie cookie + // Write request to wire for RecolorCursor -func (c *Conn) RecolorCursor(Cursor Id, ForeRed uint16, ForeGreen uint16, ForeBlue uint16, BackRed uint16, BackGreen uint16, BackBlue uint16) { +func (c *Conn) RecolorCursor(Cursor Id, ForeRed uint16, ForeGreen uint16, ForeBlue uint16, BackRed uint16, BackGreen uint16, BackBlue uint16) RecolorCursorCookie { + cookie := c.newCookie(false, false) + c.newRequest(recolorCursorRequest(Cursor, ForeRed, ForeGreen, ForeBlue, BackRed, BackGreen, BackBlue), cookie) + return RecolorCursorCookie(cookie) +} + +func (c *Conn) RecolorCursorChecked(Cursor Id, ForeRed uint16, ForeGreen uint16, ForeBlue uint16, BackRed uint16, BackGreen uint16, BackBlue uint16) RecolorCursorCookie { + cookie := c.newCookie(true, false) + c.newRequest(recolorCursorRequest(Cursor, ForeRed, ForeGreen, ForeBlue, BackRed, BackGreen, BackBlue), cookie) + return RecolorCursorCookie(cookie) +} + +// Write request to wire for RecolorCursor +func recolorCursorRequest(Cursor Id, ForeRed uint16, ForeGreen uint16, ForeBlue uint16, BackRed uint16, BackGreen uint16, BackBlue uint16) []byte { size := 20 b := 0 buf := make([]byte, size) @@ -10150,17 +11694,68 @@ func (c *Conn) RecolorCursor(Cursor Id, ForeRed uint16, ForeGreen uint16, ForeBl Put16(buf[b:], BackBlue) b += 2 - c.sendRequest(false, buf) + return buf } // Request QueryBestSize // size: 12 -func (c *Conn) QueryBestSize(Class byte, Drawable Id, Width uint16, Height uint16) (*QueryBestSizeReply, error) { - return c.QueryBestSizeReply(c.QueryBestSizeRequest(Class, Drawable, Width, Height)) +type QueryBestSizeCookie cookie + +func (c *Conn) QueryBestSize(Class byte, Drawable Id, Width uint16, Height uint16) QueryBestSizeCookie { + cookie := c.newCookie(true, true) + c.newRequest(queryBestSizeRequest(Class, Drawable, Width, Height), cookie) + return QueryBestSizeCookie(cookie) +} + +func (c *Conn) QueryBestSizeUnchecked(Class byte, Drawable Id, Width uint16, Height uint16) QueryBestSizeCookie { + cookie := c.newCookie(false, true) + c.newRequest(queryBestSizeRequest(Class, Drawable, Width, Height), cookie) + return QueryBestSizeCookie(cookie) +} + +// Request reply for QueryBestSize +// size: 12 +type QueryBestSizeReply struct { + Sequence uint16 + Length uint32 + // padding: 1 bytes + Width uint16 + Height uint16 +} + +// Waits and reads reply data from request QueryBestSize +func (cook QueryBestSizeCookie) Reply() (*QueryBestSizeReply, error) { + buf, err := cookie(cook).reply() + if err != nil { + return nil, err + } + return queryBestSizeReply(buf), nil +} + +// Read reply into structure from buffer for QueryBestSize +func queryBestSizeReply(buf []byte) *QueryBestSizeReply { + v := new(QueryBestSizeReply) + b := 1 // skip reply determinant + + b += 1 // padding + + v.Sequence = Get16(buf[b:]) + b += 2 + + v.Length = Get32(buf[b:]) // 4-byte units + b += 4 + + v.Width = Get16(buf[b:]) + b += 2 + + v.Height = Get16(buf[b:]) + b += 2 + + return v } // Write request to wire for QueryBestSize -func (c *Conn) QueryBestSizeRequest(Class byte, Drawable Id, Width uint16, Height uint16) *Cookie { +func queryBestSizeRequest(Class byte, Drawable Id, Width uint16, Height uint16) []byte { size := 12 b := 0 buf := make([]byte, size) @@ -10183,75 +11778,23 @@ func (c *Conn) QueryBestSizeRequest(Class byte, Drawable Id, Width uint16, Heigh Put16(buf[b:], Height) b += 2 - return c.sendRequest(true, buf) -} - -// Request reply for QueryBestSize -// size: 12 -type QueryBestSizeReply struct { - Sequence uint16 - Length uint32 - // padding: 1 bytes - Width uint16 - Height uint16 -} - -// Read reply QueryBestSize -func (c *Conn) QueryBestSizeReply(cook *Cookie) (*QueryBestSizeReply, error) { - buf, err := c.waitForReply(cook) - if err != nil { - return nil, err - } - - v := new(QueryBestSizeReply) - b := 1 // skip reply determinant - - b += 1 // padding - - v.Sequence = Get16(buf[b:]) - b += 2 - - v.Length = Get32(buf[b:]) // 4-byte units - b += 4 - - v.Width = Get16(buf[b:]) - b += 2 - - v.Height = Get16(buf[b:]) - b += 2 - - return v, nil + return buf } // Request QueryExtension -// size: (8 + pad((int(NameLen) * 1))) -func (c *Conn) QueryExtension(NameLen uint16, Name string) (*QueryExtensionReply, error) { - return c.QueryExtensionReply(c.QueryExtensionRequest(NameLen, Name)) +// size: pad((8 + pad((int(NameLen) * 1)))) +type QueryExtensionCookie cookie + +func (c *Conn) QueryExtension(NameLen uint16, Name string) QueryExtensionCookie { + cookie := c.newCookie(true, true) + c.newRequest(queryExtensionRequest(NameLen, Name), cookie) + return QueryExtensionCookie(cookie) } -// Write request to wire for QueryExtension -func (c *Conn) QueryExtensionRequest(NameLen uint16, Name string) *Cookie { - size := (8 + pad((int(NameLen) * 1))) - b := 0 - buf := make([]byte, size) - - buf[b] = 98 // request opcode - b += 1 - - b += 1 // padding - - Put16(buf[b:], uint16(size/4)) // write request size in 4-byte units - b += 2 - - Put16(buf[b:], NameLen) - b += 2 - - b += 2 // padding - - copy(buf[b:], Name[:NameLen]) - b += pad(int(NameLen)) - - return c.sendRequest(true, buf) +func (c *Conn) QueryExtensionUnchecked(NameLen uint16, Name string) QueryExtensionCookie { + cookie := c.newCookie(false, true) + c.newRequest(queryExtensionRequest(NameLen, Name), cookie) + return QueryExtensionCookie(cookie) } // Request reply for QueryExtension @@ -10266,13 +11809,17 @@ type QueryExtensionReply struct { FirstError byte } -// Read reply QueryExtension -func (c *Conn) QueryExtensionReply(cook *Cookie) (*QueryExtensionReply, error) { - buf, err := c.waitForReply(cook) +// Waits and reads reply data from request QueryExtension +func (cook QueryExtensionCookie) Reply() (*QueryExtensionReply, error) { + buf, err := cookie(cook).reply() if err != nil { return nil, err } + return queryExtensionReply(buf), nil +} +// Read reply into structure from buffer for QueryExtension +func queryExtensionReply(buf []byte) *QueryExtensionReply { v := new(QueryExtensionReply) b := 1 // skip reply determinant @@ -10300,25 +11847,48 @@ func (c *Conn) QueryExtensionReply(cook *Cookie) (*QueryExtensionReply, error) { v.FirstError = buf[b] b += 1 - return v, nil + return v } -// Request ListExtensions -// size: 3 -func (c *Conn) ListExtensions() (*ListExtensionsReply, error) { - return c.ListExtensionsReply(c.ListExtensionsRequest()) -} - -// Write request to wire for ListExtensions -func (c *Conn) ListExtensionsRequest() *Cookie { - size := 3 +// Write request to wire for QueryExtension +func queryExtensionRequest(NameLen uint16, Name string) []byte { + size := pad((8 + pad((int(NameLen) * 1)))) b := 0 buf := make([]byte, size) - buf[b] = 99 // request opcode + buf[b] = 98 // request opcode b += 1 - return c.sendRequest(true, buf) + b += 1 // padding + + Put16(buf[b:], uint16(size/4)) // write request size in 4-byte units + b += 2 + + Put16(buf[b:], NameLen) + b += 2 + + b += 2 // padding + + copy(buf[b:], Name[:NameLen]) + b += pad(int(NameLen)) + + return buf +} + +// Request ListExtensions +// size: 4 +type ListExtensionsCookie cookie + +func (c *Conn) ListExtensions() ListExtensionsCookie { + cookie := c.newCookie(true, true) + c.newRequest(listExtensionsRequest(), cookie) + return ListExtensionsCookie(cookie) +} + +func (c *Conn) ListExtensionsUnchecked() ListExtensionsCookie { + cookie := c.newCookie(false, true) + c.newRequest(listExtensionsRequest(), cookie) + return ListExtensionsCookie(cookie) } // Request reply for ListExtensions @@ -10331,13 +11901,17 @@ type ListExtensionsReply struct { Names []Str // size: StrListSize(Names) } -// Read reply ListExtensions -func (c *Conn) ListExtensionsReply(cook *Cookie) (*ListExtensionsReply, error) { - buf, err := c.waitForReply(cook) +// Waits and reads reply data from request ListExtensions +func (cook ListExtensionsCookie) Reply() (*ListExtensionsReply, error) { + buf, err := cookie(cook).reply() if err != nil { return nil, err } + return listExtensionsReply(buf), nil +} +// Read reply into structure from buffer for ListExtensions +func listExtensionsReply(buf []byte) *ListExtensionsReply { v := new(ListExtensionsReply) b := 1 // skip reply determinant @@ -10355,14 +11929,41 @@ func (c *Conn) ListExtensionsReply(cook *Cookie) (*ListExtensionsReply, error) { v.Names = make([]Str, v.NamesLen) b += ReadStrList(buf[b:], v.Names) - return v, nil + return v +} + +// Write request to wire for ListExtensions +func listExtensionsRequest() []byte { + size := 4 + b := 0 + buf := make([]byte, size) + + buf[b] = 99 // request opcode + b += 1 + + return buf } // Request ChangeKeyboardMapping -// size: (8 + pad(((int(KeycodeCount) * int(KeysymsPerKeycode)) * 4))) +// size: pad((8 + pad(((int(KeycodeCount) * int(KeysymsPerKeycode)) * 4)))) +type ChangeKeyboardMappingCookie cookie + // Write request to wire for ChangeKeyboardMapping -func (c *Conn) ChangeKeyboardMapping(KeycodeCount byte, FirstKeycode Keycode, KeysymsPerKeycode byte, Keysyms []Keysym) { - size := (8 + pad(((int(KeycodeCount) * int(KeysymsPerKeycode)) * 4))) +func (c *Conn) ChangeKeyboardMapping(KeycodeCount byte, FirstKeycode Keycode, KeysymsPerKeycode byte, Keysyms []Keysym) ChangeKeyboardMappingCookie { + cookie := c.newCookie(false, false) + c.newRequest(changeKeyboardMappingRequest(KeycodeCount, FirstKeycode, KeysymsPerKeycode, Keysyms), cookie) + return ChangeKeyboardMappingCookie(cookie) +} + +func (c *Conn) ChangeKeyboardMappingChecked(KeycodeCount byte, FirstKeycode Keycode, KeysymsPerKeycode byte, Keysyms []Keysym) ChangeKeyboardMappingCookie { + cookie := c.newCookie(true, false) + c.newRequest(changeKeyboardMappingRequest(KeycodeCount, FirstKeycode, KeysymsPerKeycode, Keysyms), cookie) + return ChangeKeyboardMappingCookie(cookie) +} + +// Write request to wire for ChangeKeyboardMapping +func changeKeyboardMappingRequest(KeycodeCount byte, FirstKeycode Keycode, KeysymsPerKeycode byte, Keysyms []Keysym) []byte { + size := pad((8 + pad(((int(KeycodeCount) * int(KeysymsPerKeycode)) * 4)))) b := 0 buf := make([]byte, size) @@ -10389,36 +11990,23 @@ func (c *Conn) ChangeKeyboardMapping(KeycodeCount byte, FirstKeycode Keycode, Ke } b = pad(b) - c.sendRequest(false, buf) + return buf } // Request GetKeyboardMapping -// size: 6 -func (c *Conn) GetKeyboardMapping(FirstKeycode Keycode, Count byte) (*GetKeyboardMappingReply, error) { - return c.GetKeyboardMappingReply(c.GetKeyboardMappingRequest(FirstKeycode, Count)) +// size: 8 +type GetKeyboardMappingCookie cookie + +func (c *Conn) GetKeyboardMapping(FirstKeycode Keycode, Count byte) GetKeyboardMappingCookie { + cookie := c.newCookie(true, true) + c.newRequest(getKeyboardMappingRequest(FirstKeycode, Count), cookie) + return GetKeyboardMappingCookie(cookie) } -// Write request to wire for GetKeyboardMapping -func (c *Conn) GetKeyboardMappingRequest(FirstKeycode Keycode, Count byte) *Cookie { - size := 6 - b := 0 - buf := make([]byte, size) - - buf[b] = 101 // request opcode - b += 1 - - b += 1 // padding - - Put16(buf[b:], uint16(size/4)) // write request size in 4-byte units - b += 2 - - buf[b] = byte(FirstKeycode) - b += 1 - - buf[b] = Count - b += 1 - - return c.sendRequest(true, buf) +func (c *Conn) GetKeyboardMappingUnchecked(FirstKeycode Keycode, Count byte) GetKeyboardMappingCookie { + cookie := c.newCookie(false, true) + c.newRequest(getKeyboardMappingRequest(FirstKeycode, Count), cookie) + return GetKeyboardMappingCookie(cookie) } // Request reply for GetKeyboardMapping @@ -10431,13 +12019,17 @@ type GetKeyboardMappingReply struct { Keysyms []Keysym // size: pad((int(Length) * 4)) } -// Read reply GetKeyboardMapping -func (c *Conn) GetKeyboardMappingReply(cook *Cookie) (*GetKeyboardMappingReply, error) { - buf, err := c.waitForReply(cook) +// Waits and reads reply data from request GetKeyboardMapping +func (cook GetKeyboardMappingCookie) Reply() (*GetKeyboardMappingReply, error) { + buf, err := cookie(cook).reply() if err != nil { return nil, err } + return getKeyboardMappingReply(buf), nil +} +// Read reply into structure from buffer for GetKeyboardMapping +func getKeyboardMappingReply(buf []byte) *GetKeyboardMappingReply { v := new(GetKeyboardMappingReply) b := 1 // skip reply determinant @@ -10459,14 +12051,52 @@ func (c *Conn) GetKeyboardMappingReply(cook *Cookie) (*GetKeyboardMappingReply, } b = pad(b) - return v, nil + return v +} + +// Write request to wire for GetKeyboardMapping +func getKeyboardMappingRequest(FirstKeycode Keycode, Count byte) []byte { + size := 8 + b := 0 + buf := make([]byte, size) + + buf[b] = 101 // request opcode + b += 1 + + b += 1 // padding + + Put16(buf[b:], uint16(size/4)) // write request size in 4-byte units + b += 2 + + buf[b] = byte(FirstKeycode) + b += 1 + + buf[b] = Count + b += 1 + + return buf } // Request ChangeKeyboardControl -// size: (4 + (4 + pad((4 * popCount(int(ValueMask)))))) +// size: pad((4 + (4 + pad((4 * popCount(int(ValueMask))))))) +type ChangeKeyboardControlCookie cookie + // Write request to wire for ChangeKeyboardControl -func (c *Conn) ChangeKeyboardControl(ValueMask uint32, ValueList []uint32) { - size := (4 + (4 + pad((4 * popCount(int(ValueMask)))))) +func (c *Conn) ChangeKeyboardControl(ValueMask uint32, ValueList []uint32) ChangeKeyboardControlCookie { + cookie := c.newCookie(false, false) + c.newRequest(changeKeyboardControlRequest(ValueMask, ValueList), cookie) + return ChangeKeyboardControlCookie(cookie) +} + +func (c *Conn) ChangeKeyboardControlChecked(ValueMask uint32, ValueList []uint32) ChangeKeyboardControlCookie { + cookie := c.newCookie(true, false) + c.newRequest(changeKeyboardControlRequest(ValueMask, ValueList), cookie) + return ChangeKeyboardControlCookie(cookie) +} + +// Write request to wire for ChangeKeyboardControl +func changeKeyboardControlRequest(ValueMask uint32, ValueList []uint32) []byte { + size := pad((4 + (4 + pad((4 * popCount(int(ValueMask))))))) b := 0 buf := make([]byte, size) @@ -10486,25 +12116,23 @@ func (c *Conn) ChangeKeyboardControl(ValueMask uint32, ValueList []uint32) { } b = pad(b) - c.sendRequest(false, buf) + return buf } // Request GetKeyboardControl -// size: 3 -func (c *Conn) GetKeyboardControl() (*GetKeyboardControlReply, error) { - return c.GetKeyboardControlReply(c.GetKeyboardControlRequest()) +// size: 4 +type GetKeyboardControlCookie cookie + +func (c *Conn) GetKeyboardControl() GetKeyboardControlCookie { + cookie := c.newCookie(true, true) + c.newRequest(getKeyboardControlRequest(), cookie) + return GetKeyboardControlCookie(cookie) } -// Write request to wire for GetKeyboardControl -func (c *Conn) GetKeyboardControlRequest() *Cookie { - size := 3 - b := 0 - buf := make([]byte, size) - - buf[b] = 103 // request opcode - b += 1 - - return c.sendRequest(true, buf) +func (c *Conn) GetKeyboardControlUnchecked() GetKeyboardControlCookie { + cookie := c.newCookie(false, true) + c.newRequest(getKeyboardControlRequest(), cookie) + return GetKeyboardControlCookie(cookie) } // Request reply for GetKeyboardControl @@ -10522,13 +12150,17 @@ type GetKeyboardControlReply struct { AutoRepeats []byte // size: pad(32) } -// Read reply GetKeyboardControl -func (c *Conn) GetKeyboardControlReply(cook *Cookie) (*GetKeyboardControlReply, error) { - buf, err := c.waitForReply(cook) +// Waits and reads reply data from request GetKeyboardControl +func (cook GetKeyboardControlCookie) Reply() (*GetKeyboardControlReply, error) { + buf, err := cookie(cook).reply() if err != nil { return nil, err } + return getKeyboardControlReply(buf), nil +} +// Read reply into structure from buffer for GetKeyboardControl +func getKeyboardControlReply(buf []byte) *GetKeyboardControlReply { v := new(GetKeyboardControlReply) b := 1 // skip reply determinant @@ -10562,13 +12194,40 @@ func (c *Conn) GetKeyboardControlReply(cook *Cookie) (*GetKeyboardControlReply, copy(v.AutoRepeats[:32], buf[b:]) b += pad(int(32)) - return v, nil + return v +} + +// Write request to wire for GetKeyboardControl +func getKeyboardControlRequest() []byte { + size := 4 + b := 0 + buf := make([]byte, size) + + buf[b] = 103 // request opcode + b += 1 + + return buf } // Request Bell // size: 4 +type BellCookie cookie + // Write request to wire for Bell -func (c *Conn) Bell(Percent int8) { +func (c *Conn) Bell(Percent int8) BellCookie { + cookie := c.newCookie(false, false) + c.newRequest(bellRequest(Percent), cookie) + return BellCookie(cookie) +} + +func (c *Conn) BellChecked(Percent int8) BellCookie { + cookie := c.newCookie(true, false) + c.newRequest(bellRequest(Percent), cookie) + return BellCookie(cookie) +} + +// Write request to wire for Bell +func bellRequest(Percent int8) []byte { size := 4 b := 0 buf := make([]byte, size) @@ -10579,13 +12238,28 @@ func (c *Conn) Bell(Percent int8) { buf[b] = byte(Percent) b += 1 - c.sendRequest(false, buf) + return buf } // Request ChangePointerControl // size: 12 +type ChangePointerControlCookie cookie + // Write request to wire for ChangePointerControl -func (c *Conn) ChangePointerControl(AccelerationNumerator int16, AccelerationDenominator int16, Threshold int16, DoAcceleration bool, DoThreshold bool) { +func (c *Conn) ChangePointerControl(AccelerationNumerator int16, AccelerationDenominator int16, Threshold int16, DoAcceleration bool, DoThreshold bool) ChangePointerControlCookie { + cookie := c.newCookie(false, false) + c.newRequest(changePointerControlRequest(AccelerationNumerator, AccelerationDenominator, Threshold, DoAcceleration, DoThreshold), cookie) + return ChangePointerControlCookie(cookie) +} + +func (c *Conn) ChangePointerControlChecked(AccelerationNumerator int16, AccelerationDenominator int16, Threshold int16, DoAcceleration bool, DoThreshold bool) ChangePointerControlCookie { + cookie := c.newCookie(true, false) + c.newRequest(changePointerControlRequest(AccelerationNumerator, AccelerationDenominator, Threshold, DoAcceleration, DoThreshold), cookie) + return ChangePointerControlCookie(cookie) +} + +// Write request to wire for ChangePointerControl +func changePointerControlRequest(AccelerationNumerator int16, AccelerationDenominator int16, Threshold int16, DoAcceleration bool, DoThreshold bool) []byte { size := 12 b := 0 buf := make([]byte, size) @@ -10621,25 +12295,23 @@ func (c *Conn) ChangePointerControl(AccelerationNumerator int16, AccelerationDen } b += 1 - c.sendRequest(false, buf) + return buf } // Request GetPointerControl -// size: 3 -func (c *Conn) GetPointerControl() (*GetPointerControlReply, error) { - return c.GetPointerControlReply(c.GetPointerControlRequest()) +// size: 4 +type GetPointerControlCookie cookie + +func (c *Conn) GetPointerControl() GetPointerControlCookie { + cookie := c.newCookie(true, true) + c.newRequest(getPointerControlRequest(), cookie) + return GetPointerControlCookie(cookie) } -// Write request to wire for GetPointerControl -func (c *Conn) GetPointerControlRequest() *Cookie { - size := 3 - b := 0 - buf := make([]byte, size) - - buf[b] = 106 // request opcode - b += 1 - - return c.sendRequest(true, buf) +func (c *Conn) GetPointerControlUnchecked() GetPointerControlCookie { + cookie := c.newCookie(false, true) + c.newRequest(getPointerControlRequest(), cookie) + return GetPointerControlCookie(cookie) } // Request reply for GetPointerControl @@ -10654,13 +12326,17 @@ type GetPointerControlReply struct { // padding: 18 bytes } -// Read reply GetPointerControl -func (c *Conn) GetPointerControlReply(cook *Cookie) (*GetPointerControlReply, error) { - buf, err := c.waitForReply(cook) +// Waits and reads reply data from request GetPointerControl +func (cook GetPointerControlCookie) Reply() (*GetPointerControlReply, error) { + buf, err := cookie(cook).reply() if err != nil { return nil, err } + return getPointerControlReply(buf), nil +} +// Read reply into structure from buffer for GetPointerControl +func getPointerControlReply(buf []byte) *GetPointerControlReply { v := new(GetPointerControlReply) b := 1 // skip reply determinant @@ -10683,14 +12359,41 @@ func (c *Conn) GetPointerControlReply(cook *Cookie) (*GetPointerControlReply, er b += 18 // padding - return v, nil + return v +} + +// Write request to wire for GetPointerControl +func getPointerControlRequest() []byte { + size := 4 + b := 0 + buf := make([]byte, size) + + buf[b] = 106 // request opcode + b += 1 + + return buf } // Request SetScreenSaver -// size: 10 +// size: 12 +type SetScreenSaverCookie cookie + // Write request to wire for SetScreenSaver -func (c *Conn) SetScreenSaver(Timeout int16, Interval int16, PreferBlanking byte, AllowExposures byte) { - size := 10 +func (c *Conn) SetScreenSaver(Timeout int16, Interval int16, PreferBlanking byte, AllowExposures byte) SetScreenSaverCookie { + cookie := c.newCookie(false, false) + c.newRequest(setScreenSaverRequest(Timeout, Interval, PreferBlanking, AllowExposures), cookie) + return SetScreenSaverCookie(cookie) +} + +func (c *Conn) SetScreenSaverChecked(Timeout int16, Interval int16, PreferBlanking byte, AllowExposures byte) SetScreenSaverCookie { + cookie := c.newCookie(true, false) + c.newRequest(setScreenSaverRequest(Timeout, Interval, PreferBlanking, AllowExposures), cookie) + return SetScreenSaverCookie(cookie) +} + +// Write request to wire for SetScreenSaver +func setScreenSaverRequest(Timeout int16, Interval int16, PreferBlanking byte, AllowExposures byte) []byte { + size := 12 b := 0 buf := make([]byte, size) @@ -10714,25 +12417,23 @@ func (c *Conn) SetScreenSaver(Timeout int16, Interval int16, PreferBlanking byte buf[b] = AllowExposures b += 1 - c.sendRequest(false, buf) + return buf } // Request GetScreenSaver -// size: 3 -func (c *Conn) GetScreenSaver() (*GetScreenSaverReply, error) { - return c.GetScreenSaverReply(c.GetScreenSaverRequest()) +// size: 4 +type GetScreenSaverCookie cookie + +func (c *Conn) GetScreenSaver() GetScreenSaverCookie { + cookie := c.newCookie(true, true) + c.newRequest(getScreenSaverRequest(), cookie) + return GetScreenSaverCookie(cookie) } -// Write request to wire for GetScreenSaver -func (c *Conn) GetScreenSaverRequest() *Cookie { - size := 3 - b := 0 - buf := make([]byte, size) - - buf[b] = 108 // request opcode - b += 1 - - return c.sendRequest(true, buf) +func (c *Conn) GetScreenSaverUnchecked() GetScreenSaverCookie { + cookie := c.newCookie(false, true) + c.newRequest(getScreenSaverRequest(), cookie) + return GetScreenSaverCookie(cookie) } // Request reply for GetScreenSaver @@ -10748,13 +12449,17 @@ type GetScreenSaverReply struct { // padding: 18 bytes } -// Read reply GetScreenSaver -func (c *Conn) GetScreenSaverReply(cook *Cookie) (*GetScreenSaverReply, error) { - buf, err := c.waitForReply(cook) +// Waits and reads reply data from request GetScreenSaver +func (cook GetScreenSaverCookie) Reply() (*GetScreenSaverReply, error) { + buf, err := cookie(cook).reply() if err != nil { return nil, err } + return getScreenSaverReply(buf), nil +} +// Read reply into structure from buffer for GetScreenSaver +func getScreenSaverReply(buf []byte) *GetScreenSaverReply { v := new(GetScreenSaverReply) b := 1 // skip reply determinant @@ -10780,14 +12485,41 @@ func (c *Conn) GetScreenSaverReply(cook *Cookie) (*GetScreenSaverReply, error) { b += 18 // padding - return v, nil + return v +} + +// Write request to wire for GetScreenSaver +func getScreenSaverRequest() []byte { + size := 4 + b := 0 + buf := make([]byte, size) + + buf[b] = 108 // request opcode + b += 1 + + return buf } // Request ChangeHosts -// size: (8 + pad((int(AddressLen) * 1))) +// size: pad((8 + pad((int(AddressLen) * 1)))) +type ChangeHostsCookie cookie + // Write request to wire for ChangeHosts -func (c *Conn) ChangeHosts(Mode byte, Family byte, AddressLen uint16, Address []byte) { - size := (8 + pad((int(AddressLen) * 1))) +func (c *Conn) ChangeHosts(Mode byte, Family byte, AddressLen uint16, Address []byte) ChangeHostsCookie { + cookie := c.newCookie(false, false) + c.newRequest(changeHostsRequest(Mode, Family, AddressLen, Address), cookie) + return ChangeHostsCookie(cookie) +} + +func (c *Conn) ChangeHostsChecked(Mode byte, Family byte, AddressLen uint16, Address []byte) ChangeHostsCookie { + cookie := c.newCookie(true, false) + c.newRequest(changeHostsRequest(Mode, Family, AddressLen, Address), cookie) + return ChangeHostsCookie(cookie) +} + +// Write request to wire for ChangeHosts +func changeHostsRequest(Mode byte, Family byte, AddressLen uint16, Address []byte) []byte { + size := pad((8 + pad((int(AddressLen) * 1)))) b := 0 buf := make([]byte, size) @@ -10811,25 +12543,23 @@ func (c *Conn) ChangeHosts(Mode byte, Family byte, AddressLen uint16, Address [] copy(buf[b:], Address[:AddressLen]) b += pad(int(AddressLen)) - c.sendRequest(false, buf) + return buf } // Request ListHosts -// size: 3 -func (c *Conn) ListHosts() (*ListHostsReply, error) { - return c.ListHostsReply(c.ListHostsRequest()) +// size: 4 +type ListHostsCookie cookie + +func (c *Conn) ListHosts() ListHostsCookie { + cookie := c.newCookie(true, true) + c.newRequest(listHostsRequest(), cookie) + return ListHostsCookie(cookie) } -// Write request to wire for ListHosts -func (c *Conn) ListHostsRequest() *Cookie { - size := 3 - b := 0 - buf := make([]byte, size) - - buf[b] = 110 // request opcode - b += 1 - - return c.sendRequest(true, buf) +func (c *Conn) ListHostsUnchecked() ListHostsCookie { + cookie := c.newCookie(false, true) + c.newRequest(listHostsRequest(), cookie) + return ListHostsCookie(cookie) } // Request reply for ListHosts @@ -10843,13 +12573,17 @@ type ListHostsReply struct { Hosts []Host // size: HostListSize(Hosts) } -// Read reply ListHosts -func (c *Conn) ListHostsReply(cook *Cookie) (*ListHostsReply, error) { - buf, err := c.waitForReply(cook) +// Waits and reads reply data from request ListHosts +func (cook ListHostsCookie) Reply() (*ListHostsReply, error) { + buf, err := cookie(cook).reply() if err != nil { return nil, err } + return listHostsReply(buf), nil +} +// Read reply into structure from buffer for ListHosts +func listHostsReply(buf []byte) *ListHostsReply { v := new(ListHostsReply) b := 1 // skip reply determinant @@ -10870,13 +12604,40 @@ func (c *Conn) ListHostsReply(cook *Cookie) (*ListHostsReply, error) { v.Hosts = make([]Host, v.HostsLen) b += ReadHostList(buf[b:], v.Hosts) - return v, nil + return v +} + +// Write request to wire for ListHosts +func listHostsRequest() []byte { + size := 4 + b := 0 + buf := make([]byte, size) + + buf[b] = 110 // request opcode + b += 1 + + return buf } // Request SetAccessControl // size: 4 +type SetAccessControlCookie cookie + // Write request to wire for SetAccessControl -func (c *Conn) SetAccessControl(Mode byte) { +func (c *Conn) SetAccessControl(Mode byte) SetAccessControlCookie { + cookie := c.newCookie(false, false) + c.newRequest(setAccessControlRequest(Mode), cookie) + return SetAccessControlCookie(cookie) +} + +func (c *Conn) SetAccessControlChecked(Mode byte) SetAccessControlCookie { + cookie := c.newCookie(true, false) + c.newRequest(setAccessControlRequest(Mode), cookie) + return SetAccessControlCookie(cookie) +} + +// Write request to wire for SetAccessControl +func setAccessControlRequest(Mode byte) []byte { size := 4 b := 0 buf := make([]byte, size) @@ -10887,13 +12648,28 @@ func (c *Conn) SetAccessControl(Mode byte) { buf[b] = Mode b += 1 - c.sendRequest(false, buf) + return buf } // Request SetCloseDownMode // size: 4 +type SetCloseDownModeCookie cookie + // Write request to wire for SetCloseDownMode -func (c *Conn) SetCloseDownMode(Mode byte) { +func (c *Conn) SetCloseDownMode(Mode byte) SetCloseDownModeCookie { + cookie := c.newCookie(false, false) + c.newRequest(setCloseDownModeRequest(Mode), cookie) + return SetCloseDownModeCookie(cookie) +} + +func (c *Conn) SetCloseDownModeChecked(Mode byte) SetCloseDownModeCookie { + cookie := c.newCookie(true, false) + c.newRequest(setCloseDownModeRequest(Mode), cookie) + return SetCloseDownModeCookie(cookie) +} + +// Write request to wire for SetCloseDownMode +func setCloseDownModeRequest(Mode byte) []byte { size := 4 b := 0 buf := make([]byte, size) @@ -10904,13 +12680,28 @@ func (c *Conn) SetCloseDownMode(Mode byte) { buf[b] = Mode b += 1 - c.sendRequest(false, buf) + return buf } // Request KillClient // size: 8 +type KillClientCookie cookie + // Write request to wire for KillClient -func (c *Conn) KillClient(Resource uint32) { +func (c *Conn) KillClient(Resource uint32) KillClientCookie { + cookie := c.newCookie(false, false) + c.newRequest(killClientRequest(Resource), cookie) + return KillClientCookie(cookie) +} + +func (c *Conn) KillClientChecked(Resource uint32) KillClientCookie { + cookie := c.newCookie(true, false) + c.newRequest(killClientRequest(Resource), cookie) + return KillClientCookie(cookie) +} + +// Write request to wire for KillClient +func killClientRequest(Resource uint32) []byte { size := 8 b := 0 buf := make([]byte, size) @@ -10926,14 +12717,29 @@ func (c *Conn) KillClient(Resource uint32) { Put32(buf[b:], Resource) b += 4 - c.sendRequest(false, buf) + return buf } // Request RotateProperties -// size: (12 + pad((int(AtomsLen) * 4))) +// size: pad((12 + pad((int(AtomsLen) * 4)))) +type RotatePropertiesCookie cookie + // Write request to wire for RotateProperties -func (c *Conn) RotateProperties(Window Id, AtomsLen uint16, Delta int16, Atoms []Id) { - size := (12 + pad((int(AtomsLen) * 4))) +func (c *Conn) RotateProperties(Window Id, AtomsLen uint16, Delta int16, Atoms []Id) RotatePropertiesCookie { + cookie := c.newCookie(false, false) + c.newRequest(rotatePropertiesRequest(Window, AtomsLen, Delta, Atoms), cookie) + return RotatePropertiesCookie(cookie) +} + +func (c *Conn) RotatePropertiesChecked(Window Id, AtomsLen uint16, Delta int16, Atoms []Id) RotatePropertiesCookie { + cookie := c.newCookie(true, false) + c.newRequest(rotatePropertiesRequest(Window, AtomsLen, Delta, Atoms), cookie) + return RotatePropertiesCookie(cookie) +} + +// Write request to wire for RotateProperties +func rotatePropertiesRequest(Window Id, AtomsLen uint16, Delta int16, Atoms []Id) []byte { + size := pad((12 + pad((int(AtomsLen) * 4)))) b := 0 buf := make([]byte, size) @@ -10960,13 +12766,28 @@ func (c *Conn) RotateProperties(Window Id, AtomsLen uint16, Delta int16, Atoms [ } b = pad(b) - c.sendRequest(false, buf) + return buf } // Request ForceScreenSaver // size: 4 +type ForceScreenSaverCookie cookie + // Write request to wire for ForceScreenSaver -func (c *Conn) ForceScreenSaver(Mode byte) { +func (c *Conn) ForceScreenSaver(Mode byte) ForceScreenSaverCookie { + cookie := c.newCookie(false, false) + c.newRequest(forceScreenSaverRequest(Mode), cookie) + return ForceScreenSaverCookie(cookie) +} + +func (c *Conn) ForceScreenSaverChecked(Mode byte) ForceScreenSaverCookie { + cookie := c.newCookie(true, false) + c.newRequest(forceScreenSaverRequest(Mode), cookie) + return ForceScreenSaverCookie(cookie) +} + +// Write request to wire for ForceScreenSaver +func forceScreenSaverRequest(Mode byte) []byte { size := 4 b := 0 buf := make([]byte, size) @@ -10977,18 +12798,56 @@ func (c *Conn) ForceScreenSaver(Mode byte) { buf[b] = Mode b += 1 - c.sendRequest(false, buf) + return buf } // Request SetPointerMapping -// size: (4 + pad((int(MapLen) * 1))) -func (c *Conn) SetPointerMapping(MapLen byte, Map []byte) (*SetPointerMappingReply, error) { - return c.SetPointerMappingReply(c.SetPointerMappingRequest(MapLen, Map)) +// size: pad((4 + pad((int(MapLen) * 1)))) +type SetPointerMappingCookie cookie + +func (c *Conn) SetPointerMapping(MapLen byte, Map []byte) SetPointerMappingCookie { + cookie := c.newCookie(true, true) + c.newRequest(setPointerMappingRequest(MapLen, Map), cookie) + return SetPointerMappingCookie(cookie) +} + +func (c *Conn) SetPointerMappingUnchecked(MapLen byte, Map []byte) SetPointerMappingCookie { + cookie := c.newCookie(false, true) + c.newRequest(setPointerMappingRequest(MapLen, Map), cookie) + return SetPointerMappingCookie(cookie) +} + +// Request reply for SetPointerMapping +// size: 8 +type SetPointerMappingReply struct { + Sequence uint16 + Length uint32 + Status byte +} + +// Waits and reads reply data from request SetPointerMapping +func (cook SetPointerMappingCookie) Reply() (*SetPointerMappingReply, error) { + buf, err := cookie(cook).reply() + if err != nil { + return nil, err + } + return setPointerMappingReply(buf), nil +} + +// Read reply into structure from buffer for SetPointerMapping +func setPointerMappingReply(buf []byte) *SetPointerMappingReply { + v := new(SetPointerMappingReply) + b := 1 // skip reply determinant + + v.Status = buf[b] + b += 1 + + return v } // Write request to wire for SetPointerMapping -func (c *Conn) SetPointerMappingRequest(MapLen byte, Map []byte) *Cookie { - size := (4 + pad((int(MapLen) * 1))) +func setPointerMappingRequest(MapLen byte, Map []byte) []byte { + size := pad((4 + pad((int(MapLen) * 1)))) b := 0 buf := make([]byte, size) @@ -11004,49 +12863,23 @@ func (c *Conn) SetPointerMappingRequest(MapLen byte, Map []byte) *Cookie { copy(buf[b:], Map[:MapLen]) b += pad(int(MapLen)) - return c.sendRequest(true, buf) -} - -// Request reply for SetPointerMapping -// size: 8 -type SetPointerMappingReply struct { - Sequence uint16 - Length uint32 - Status byte -} - -// Read reply SetPointerMapping -func (c *Conn) SetPointerMappingReply(cook *Cookie) (*SetPointerMappingReply, error) { - buf, err := c.waitForReply(cook) - if err != nil { - return nil, err - } - - v := new(SetPointerMappingReply) - b := 1 // skip reply determinant - - v.Status = buf[b] - b += 1 - - return v, nil + return buf } // Request GetPointerMapping -// size: 3 -func (c *Conn) GetPointerMapping() (*GetPointerMappingReply, error) { - return c.GetPointerMappingReply(c.GetPointerMappingRequest()) +// size: 4 +type GetPointerMappingCookie cookie + +func (c *Conn) GetPointerMapping() GetPointerMappingCookie { + cookie := c.newCookie(true, true) + c.newRequest(getPointerMappingRequest(), cookie) + return GetPointerMappingCookie(cookie) } -// Write request to wire for GetPointerMapping -func (c *Conn) GetPointerMappingRequest() *Cookie { - size := 3 - b := 0 - buf := make([]byte, size) - - buf[b] = 117 // request opcode - b += 1 - - return c.sendRequest(true, buf) +func (c *Conn) GetPointerMappingUnchecked() GetPointerMappingCookie { + cookie := c.newCookie(false, true) + c.newRequest(getPointerMappingRequest(), cookie) + return GetPointerMappingCookie(cookie) } // Request reply for GetPointerMapping @@ -11059,13 +12892,17 @@ type GetPointerMappingReply struct { Map []byte // size: pad((int(MapLen) * 1)) } -// Read reply GetPointerMapping -func (c *Conn) GetPointerMappingReply(cook *Cookie) (*GetPointerMappingReply, error) { - buf, err := c.waitForReply(cook) +// Waits and reads reply data from request GetPointerMapping +func (cook GetPointerMappingCookie) Reply() (*GetPointerMappingReply, error) { + buf, err := cookie(cook).reply() if err != nil { return nil, err } + return getPointerMappingReply(buf), nil +} +// Read reply into structure from buffer for GetPointerMapping +func getPointerMappingReply(buf []byte) *GetPointerMappingReply { v := new(GetPointerMappingReply) b := 1 // skip reply determinant @@ -11084,18 +12921,68 @@ func (c *Conn) GetPointerMappingReply(cook *Cookie) (*GetPointerMappingReply, er copy(v.Map[:v.MapLen], buf[b:]) b += pad(int(v.MapLen)) - return v, nil + return v +} + +// Write request to wire for GetPointerMapping +func getPointerMappingRequest() []byte { + size := 4 + b := 0 + buf := make([]byte, size) + + buf[b] = 117 // request opcode + b += 1 + + return buf } // Request SetModifierMapping -// size: (4 + pad(((int(KeycodesPerModifier) * 8) * 1))) -func (c *Conn) SetModifierMapping(KeycodesPerModifier byte, Keycodes []Keycode) (*SetModifierMappingReply, error) { - return c.SetModifierMappingReply(c.SetModifierMappingRequest(KeycodesPerModifier, Keycodes)) +// size: pad((4 + pad(((int(KeycodesPerModifier) * 8) * 1)))) +type SetModifierMappingCookie cookie + +func (c *Conn) SetModifierMapping(KeycodesPerModifier byte, Keycodes []Keycode) SetModifierMappingCookie { + cookie := c.newCookie(true, true) + c.newRequest(setModifierMappingRequest(KeycodesPerModifier, Keycodes), cookie) + return SetModifierMappingCookie(cookie) +} + +func (c *Conn) SetModifierMappingUnchecked(KeycodesPerModifier byte, Keycodes []Keycode) SetModifierMappingCookie { + cookie := c.newCookie(false, true) + c.newRequest(setModifierMappingRequest(KeycodesPerModifier, Keycodes), cookie) + return SetModifierMappingCookie(cookie) +} + +// Request reply for SetModifierMapping +// size: 8 +type SetModifierMappingReply struct { + Sequence uint16 + Length uint32 + Status byte +} + +// Waits and reads reply data from request SetModifierMapping +func (cook SetModifierMappingCookie) Reply() (*SetModifierMappingReply, error) { + buf, err := cookie(cook).reply() + if err != nil { + return nil, err + } + return setModifierMappingReply(buf), nil +} + +// Read reply into structure from buffer for SetModifierMapping +func setModifierMappingReply(buf []byte) *SetModifierMappingReply { + v := new(SetModifierMappingReply) + b := 1 // skip reply determinant + + v.Status = buf[b] + b += 1 + + return v } // Write request to wire for SetModifierMapping -func (c *Conn) SetModifierMappingRequest(KeycodesPerModifier byte, Keycodes []Keycode) *Cookie { - size := (4 + pad(((int(KeycodesPerModifier) * 8) * 1))) +func setModifierMappingRequest(KeycodesPerModifier byte, Keycodes []Keycode) []byte { + size := pad((4 + pad(((int(KeycodesPerModifier) * 8) * 1)))) b := 0 buf := make([]byte, size) @@ -11114,49 +13001,23 @@ func (c *Conn) SetModifierMappingRequest(KeycodesPerModifier byte, Keycodes []Ke } b = pad(b) - return c.sendRequest(true, buf) -} - -// Request reply for SetModifierMapping -// size: 8 -type SetModifierMappingReply struct { - Sequence uint16 - Length uint32 - Status byte -} - -// Read reply SetModifierMapping -func (c *Conn) SetModifierMappingReply(cook *Cookie) (*SetModifierMappingReply, error) { - buf, err := c.waitForReply(cook) - if err != nil { - return nil, err - } - - v := new(SetModifierMappingReply) - b := 1 // skip reply determinant - - v.Status = buf[b] - b += 1 - - return v, nil + return buf } // Request GetModifierMapping -// size: 3 -func (c *Conn) GetModifierMapping() (*GetModifierMappingReply, error) { - return c.GetModifierMappingReply(c.GetModifierMappingRequest()) +// size: 4 +type GetModifierMappingCookie cookie + +func (c *Conn) GetModifierMapping() GetModifierMappingCookie { + cookie := c.newCookie(true, true) + c.newRequest(getModifierMappingRequest(), cookie) + return GetModifierMappingCookie(cookie) } -// Write request to wire for GetModifierMapping -func (c *Conn) GetModifierMappingRequest() *Cookie { - size := 3 - b := 0 - buf := make([]byte, size) - - buf[b] = 119 // request opcode - b += 1 - - return c.sendRequest(true, buf) +func (c *Conn) GetModifierMappingUnchecked() GetModifierMappingCookie { + cookie := c.newCookie(false, true) + c.newRequest(getModifierMappingRequest(), cookie) + return GetModifierMappingCookie(cookie) } // Request reply for GetModifierMapping @@ -11169,13 +13030,17 @@ type GetModifierMappingReply struct { Keycodes []Keycode // size: pad(((int(KeycodesPerModifier) * 8) * 1)) } -// Read reply GetModifierMapping -func (c *Conn) GetModifierMappingReply(cook *Cookie) (*GetModifierMappingReply, error) { - buf, err := c.waitForReply(cook) +// Waits and reads reply data from request GetModifierMapping +func (cook GetModifierMappingCookie) Reply() (*GetModifierMappingReply, error) { + buf, err := cookie(cook).reply() if err != nil { return nil, err } + return getModifierMappingReply(buf), nil +} +// Read reply into structure from buffer for GetModifierMapping +func getModifierMappingReply(buf []byte) *GetModifierMappingReply { v := new(GetModifierMappingReply) b := 1 // skip reply determinant @@ -11197,19 +13062,46 @@ func (c *Conn) GetModifierMappingReply(cook *Cookie) (*GetModifierMappingReply, } b = pad(b) - return v, nil + return v +} + +// Write request to wire for GetModifierMapping +func getModifierMappingRequest() []byte { + size := 4 + b := 0 + buf := make([]byte, size) + + buf[b] = 119 // request opcode + b += 1 + + return buf } // Request NoOperation -// size: 3 +// size: 4 +type NoOperationCookie cookie + // Write request to wire for NoOperation -func (c *Conn) NoOperation() { - size := 3 +func (c *Conn) NoOperation() NoOperationCookie { + cookie := c.newCookie(false, false) + c.newRequest(noOperationRequest(), cookie) + return NoOperationCookie(cookie) +} + +func (c *Conn) NoOperationChecked() NoOperationCookie { + cookie := c.newCookie(true, false) + c.newRequest(noOperationRequest(), cookie) + return NoOperationCookie(cookie) +} + +// Write request to wire for NoOperation +func noOperationRequest() []byte { + size := 4 b := 0 buf := make([]byte, size) buf[b] = 127 // request opcode b += 1 - c.sendRequest(false, buf) + return buf }