2012-05-11 02:06:22 +02:00
|
|
|
// Package bigreq is the X client API for the BIG-REQUESTS extension.
|
2012-05-10 23:01:42 +02:00
|
|
|
package bigreq
|
|
|
|
|
2013-08-12 02:45:36 +02:00
|
|
|
// This file is automatically generated from bigreq.xml. Edit at your peril!
|
2012-05-10 23:01:42 +02:00
|
|
|
|
|
|
|
import (
|
2018-09-08 19:57:27 +02:00
|
|
|
xgb "janouch.name/haven/nexgb"
|
2012-05-10 23:01:42 +02:00
|
|
|
|
2018-09-08 19:57:27 +02:00
|
|
|
"janouch.name/haven/nexgb/xproto"
|
2012-05-10 23:01:42 +02:00
|
|
|
)
|
|
|
|
|
2018-09-21 08:37:21 +02:00
|
|
|
const (
|
|
|
|
MajorVersion = 0
|
|
|
|
MinorVersion = 0
|
|
|
|
)
|
|
|
|
|
2012-05-10 23:01:42 +02:00
|
|
|
// Init must be called before using the BIG-REQUESTS extension.
|
|
|
|
func Init(c *xgb.Conn) error {
|
|
|
|
reply, err := xproto.QueryExtension(c, 12, "BIG-REQUESTS").Reply()
|
|
|
|
switch {
|
|
|
|
case err != nil:
|
|
|
|
return err
|
|
|
|
case !reply.Present:
|
|
|
|
return xgb.Errorf("No extension named BIG-REQUESTS could be found on on the server.")
|
|
|
|
}
|
|
|
|
|
2016-03-01 15:41:38 +01:00
|
|
|
c.ExtLock.Lock()
|
2012-05-10 23:01:42 +02:00
|
|
|
c.Extensions["BIG-REQUESTS"] = reply.MajorOpcode
|
2016-03-01 15:41:38 +01:00
|
|
|
c.ExtLock.Unlock()
|
2012-05-10 23:01:42 +02:00
|
|
|
for evNum, fun := range xgb.NewExtEventFuncs["BIG-REQUESTS"] {
|
|
|
|
xgb.NewEventFuncs[int(reply.FirstEvent)+evNum] = fun
|
|
|
|
}
|
|
|
|
for errNum, fun := range xgb.NewExtErrorFuncs["BIG-REQUESTS"] {
|
|
|
|
xgb.NewErrorFuncs[int(reply.FirstError)+errNum] = fun
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func init() {
|
|
|
|
xgb.NewExtEventFuncs["BIG-REQUESTS"] = make(map[int]xgb.NewEventFun)
|
|
|
|
xgb.NewExtErrorFuncs["BIG-REQUESTS"] = make(map[int]xgb.NewErrorFun)
|
|
|
|
}
|
|
|
|
|
2013-08-12 02:43:26 +02:00
|
|
|
// Skipping definition for base type 'Bool'
|
2012-05-11 02:06:22 +02:00
|
|
|
|
|
|
|
// Skipping definition for base type 'Byte'
|
|
|
|
|
2013-08-12 02:43:26 +02:00
|
|
|
// Skipping definition for base type 'Card8'
|
2012-05-10 23:01:42 +02:00
|
|
|
|
|
|
|
// Skipping definition for base type 'Char'
|
|
|
|
|
2013-08-12 02:43:26 +02:00
|
|
|
// Skipping definition for base type 'Void'
|
2012-05-10 23:01:42 +02:00
|
|
|
|
|
|
|
// Skipping definition for base type 'Double'
|
|
|
|
|
2012-05-27 00:24:52 +02:00
|
|
|
// Skipping definition for base type 'Float'
|
|
|
|
|
2012-06-05 06:14:34 +02:00
|
|
|
// Skipping definition for base type 'Int16'
|
|
|
|
|
|
|
|
// Skipping definition for base type 'Int32'
|
|
|
|
|
2013-08-12 02:43:26 +02:00
|
|
|
// Skipping definition for base type 'Int8'
|
|
|
|
|
|
|
|
// Skipping definition for base type 'Card16'
|
|
|
|
|
|
|
|
// Skipping definition for base type 'Card32'
|
|
|
|
|
2012-05-11 05:57:34 +02:00
|
|
|
// EnableCookie is a cookie used only for Enable requests.
|
2012-05-10 23:01:42 +02:00
|
|
|
type EnableCookie struct {
|
|
|
|
*xgb.Cookie
|
|
|
|
}
|
|
|
|
|
2012-05-11 05:57:34 +02:00
|
|
|
// Enable sends a checked request.
|
2018-09-30 16:32:47 +02:00
|
|
|
// If an error occurs, it will be returned with the reply by calling EnableCookie.Reply.
|
2012-05-10 23:01:42 +02:00
|
|
|
func Enable(c *xgb.Conn) EnableCookie {
|
2016-03-01 15:41:38 +01:00
|
|
|
c.ExtLock.RLock()
|
|
|
|
defer c.ExtLock.RUnlock()
|
2012-05-12 05:58:52 +02:00
|
|
|
if _, ok := c.Extensions["BIG-REQUESTS"]; !ok {
|
|
|
|
panic("Cannot issue request 'Enable' using the uninitialized extension 'BIG-REQUESTS'. bigreq.Init(connObj) must be called first.")
|
|
|
|
}
|
2012-05-10 23:01:42 +02:00
|
|
|
cookie := c.NewCookie(true, true)
|
|
|
|
c.NewRequest(enableRequest(c), cookie)
|
|
|
|
return EnableCookie{cookie}
|
|
|
|
}
|
|
|
|
|
2012-05-11 05:57:34 +02:00
|
|
|
// EnableUnchecked sends an unchecked request.
|
|
|
|
// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent.
|
2012-05-10 23:01:42 +02:00
|
|
|
func EnableUnchecked(c *xgb.Conn) EnableCookie {
|
2016-03-01 15:41:38 +01:00
|
|
|
c.ExtLock.RLock()
|
|
|
|
defer c.ExtLock.RUnlock()
|
2012-05-12 05:58:52 +02:00
|
|
|
if _, ok := c.Extensions["BIG-REQUESTS"]; !ok {
|
|
|
|
panic("Cannot issue request 'Enable' using the uninitialized extension 'BIG-REQUESTS'. bigreq.Init(connObj) must be called first.")
|
|
|
|
}
|
2012-05-10 23:01:42 +02:00
|
|
|
cookie := c.NewCookie(false, true)
|
|
|
|
c.NewRequest(enableRequest(c), cookie)
|
|
|
|
return EnableCookie{cookie}
|
|
|
|
}
|
|
|
|
|
2012-05-11 05:57:34 +02:00
|
|
|
// EnableReply represents the data returned from a Enable request.
|
2012-05-10 23:01:42 +02:00
|
|
|
type EnableReply struct {
|
2012-05-11 05:57:34 +02:00
|
|
|
Sequence uint16 // sequence number of the request for this reply
|
|
|
|
Length uint32 // number of bytes in this reply
|
2012-05-10 23:01:42 +02:00
|
|
|
// padding: 1 bytes
|
|
|
|
MaximumRequestLength uint32
|
|
|
|
}
|
|
|
|
|
2012-05-11 05:57:34 +02:00
|
|
|
// Reply blocks and returns the reply data for a Enable request.
|
2012-05-10 23:01:42 +02:00
|
|
|
func (cook EnableCookie) Reply() (*EnableReply, error) {
|
|
|
|
buf, err := cook.Cookie.Reply()
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
if buf == nil {
|
|
|
|
return nil, nil
|
|
|
|
}
|
|
|
|
return enableReply(buf), nil
|
|
|
|
}
|
|
|
|
|
2012-05-11 05:57:34 +02:00
|
|
|
// enableReply reads a byte slice into a EnableReply value.
|
2012-05-10 23:01:42 +02:00
|
|
|
func enableReply(buf []byte) *EnableReply {
|
|
|
|
v := new(EnableReply)
|
|
|
|
b := 1 // skip reply determinant
|
|
|
|
|
|
|
|
b += 1 // padding
|
|
|
|
|
|
|
|
v.Sequence = xgb.Get16(buf[b:])
|
|
|
|
b += 2
|
|
|
|
|
|
|
|
v.Length = xgb.Get32(buf[b:]) // 4-byte units
|
|
|
|
b += 4
|
|
|
|
|
|
|
|
v.MaximumRequestLength = xgb.Get32(buf[b:])
|
|
|
|
b += 4
|
|
|
|
|
|
|
|
return v
|
|
|
|
}
|
|
|
|
|
2018-09-30 16:32:47 +02:00
|
|
|
// enableRequest writes a Enable request to a byte slice for transfer.
|
2012-05-10 23:01:42 +02:00
|
|
|
func enableRequest(c *xgb.Conn) []byte {
|
|
|
|
size := 4
|
|
|
|
b := 0
|
|
|
|
buf := make([]byte, size)
|
|
|
|
|
2016-03-01 15:41:38 +01:00
|
|
|
c.ExtLock.RLock()
|
2012-05-10 23:01:42 +02:00
|
|
|
buf[b] = c.Extensions["BIG-REQUESTS"]
|
2016-03-01 15:41:38 +01:00
|
|
|
c.ExtLock.RUnlock()
|
2012-05-10 23:01:42 +02:00
|
|
|
b += 1
|
|
|
|
|
|
|
|
buf[b] = 0 // request opcode
|
|
|
|
b += 1
|
|
|
|
|
|
|
|
xgb.Put16(buf[b:], uint16(size/4)) // write request size in 4-byte units
|
|
|
|
b += 2
|
|
|
|
|
|
|
|
return buf
|
|
|
|
}
|