aboutsummaryrefslogtreecommitdiff
path: root/nexgb/bigreq
diff options
context:
space:
mode:
authorPřemysl Janouch <p@janouch.name>2018-09-08 16:54:17 +0200
committerPřemysl Janouch <p@janouch.name>2018-09-08 16:54:17 +0200
commit3173202cc1e08762c6e156a8fffd23269a5ddb2b (patch)
tree95c4a06f8384d41b15e9c22afac0a387de79dc51 /nexgb/bigreq
parent632b3ae494d45755525644fe5d04475c95aae364 (diff)
parent3906399e7c2a40fbaf355de572cf50a314083f64 (diff)
downloadhaven-3173202cc1e08762c6e156a8fffd23269a5ddb2b.tar.gz
haven-3173202cc1e08762c6e156a8fffd23269a5ddb2b.tar.xz
haven-3173202cc1e08762c6e156a8fffd23269a5ddb2b.zip
Merge aarzilli/xgb, branch xcb1.12 as nexgb
History has been linearized and rewritten to stay under the new subdirectory. I want to make changes incompatible to BurntSushi/xgb. The history begs for being thrown away entirely because of its quality and because it doesn't cover the Google period but it is still useful for copyright tracking.
Diffstat (limited to 'nexgb/bigreq')
-rw-r--r--nexgb/bigreq/bigreq.go152
1 files changed, 152 insertions, 0 deletions
diff --git a/nexgb/bigreq/bigreq.go b/nexgb/bigreq/bigreq.go
new file mode 100644
index 0000000..6590376
--- /dev/null
+++ b/nexgb/bigreq/bigreq.go
@@ -0,0 +1,152 @@
+// Package bigreq is the X client API for the BIG-REQUESTS extension.
+package bigreq
+
+// This file is automatically generated from bigreq.xml. Edit at your peril!
+
+import (
+ "github.com/BurntSushi/xgb"
+
+ "github.com/BurntSushi/xgb/xproto"
+)
+
+// 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.")
+ }
+
+ c.ExtLock.Lock()
+ c.Extensions["BIG-REQUESTS"] = reply.MajorOpcode
+ c.ExtLock.Unlock()
+ 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)
+}
+
+// Skipping definition for base type 'Bool'
+
+// Skipping definition for base type 'Byte'
+
+// Skipping definition for base type 'Card8'
+
+// Skipping definition for base type 'Char'
+
+// Skipping definition for base type 'Void'
+
+// Skipping definition for base type 'Double'
+
+// Skipping definition for base type 'Float'
+
+// Skipping definition for base type 'Int16'
+
+// Skipping definition for base type 'Int32'
+
+// Skipping definition for base type 'Int8'
+
+// Skipping definition for base type 'Card16'
+
+// Skipping definition for base type 'Card32'
+
+// EnableCookie is a cookie used only for Enable requests.
+type EnableCookie struct {
+ *xgb.Cookie
+}
+
+// Enable sends a checked request.
+// If an error occurs, it will be returned with the reply by calling EnableCookie.Reply()
+func Enable(c *xgb.Conn) EnableCookie {
+ c.ExtLock.RLock()
+ defer c.ExtLock.RUnlock()
+ 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.")
+ }
+ cookie := c.NewCookie(true, true)
+ c.NewRequest(enableRequest(c), cookie)
+ return EnableCookie{cookie}
+}
+
+// EnableUnchecked sends an unchecked request.
+// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent.
+func EnableUnchecked(c *xgb.Conn) EnableCookie {
+ c.ExtLock.RLock()
+ defer c.ExtLock.RUnlock()
+ 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.")
+ }
+ cookie := c.NewCookie(false, true)
+ c.NewRequest(enableRequest(c), cookie)
+ return EnableCookie{cookie}
+}
+
+// EnableReply represents the data returned from a Enable request.
+type EnableReply struct {
+ Sequence uint16 // sequence number of the request for this reply
+ Length uint32 // number of bytes in this reply
+ // padding: 1 bytes
+ MaximumRequestLength uint32
+}
+
+// Reply blocks and returns the reply data for a Enable request.
+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
+}
+
+// enableReply reads a byte slice into a EnableReply value.
+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
+}
+
+// Write request to wire for Enable
+// enableRequest writes a Enable request to a byte slice.
+func enableRequest(c *xgb.Conn) []byte {
+ size := 4
+ b := 0
+ buf := make([]byte, size)
+
+ c.ExtLock.RLock()
+ buf[b] = c.Extensions["BIG-REQUESTS"]
+ c.ExtLock.RUnlock()
+ 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
+}