Debian Codegraph @

ge/ge.go

raw
1 // Package ge is the X client API for the Generic Event Extension extension.
2 package ge
3
4 // This file is automatically generated from ge.xml. Edit at your peril!
5
6 import (
7 "github.com/BurntSushi/xgb"
8
9 "github.com/BurntSushi/xgb/xproto"
10 )
11
12 // Init must be called before using the Generic Event Extension extension.
13 func Init(c *xgb.Conn) error {
14 reply, err := xproto.QueryExtension(c, 23, "Generic Event Extension").Reply()
15 switch {
16 case err != nil:
17 return err
18 case !reply.Present:
19 return xgb.Errorf("No extension named Generic Event Extension could be found on on the server.")
20 }
21
22 c.ExtLock.Lock()
23 c.Extensions["Generic Event Extension"] = reply.MajorOpcode
24 c.ExtLock.Unlock()
25 for evNum, fun := range xgb.NewExtEventFuncs["Generic Event Extension"] {
26 xgb.NewEventFuncs[int(reply.FirstEvent)+evNum] = fun
27 }
28 for errNum, fun := range xgb.NewExtErrorFuncs["Generic Event Extension"] {
29 xgb.NewErrorFuncs[int(reply.FirstError)+errNum] = fun
30 }
31 return nil
32 }
33
34 func init() {
35 xgb.NewExtEventFuncs["Generic Event Extension"] = make(map[int]xgb.NewEventFun)
36 xgb.NewExtErrorFuncs["Generic Event Extension"] = make(map[int]xgb.NewErrorFun)
37 }
38
39 // Skipping definition for base type 'Bool'
40
41 // Skipping definition for base type 'Byte'
42
43 // Skipping definition for base type 'Card8'
44
45 // Skipping definition for base type 'Char'
46
47 // Skipping definition for base type 'Void'
48
49 // Skipping definition for base type 'Double'
50
51 // Skipping definition for base type 'Float'
52
53 // Skipping definition for base type 'Int16'
54
55 // Skipping definition for base type 'Int32'
56
57 // Skipping definition for base type 'Int8'
58
59 // Skipping definition for base type 'Card16'
60
61 // Skipping definition for base type 'Card32'
62
63 // QueryVersionCookie is a cookie used only for QueryVersion requests.
64 type QueryVersionCookie struct {
65 *xgb.Cookie
66 }
67
68 // QueryVersion sends a checked request.
69 // If an error occurs, it will be returned with the reply by calling QueryVersionCookie.Reply()
70 func QueryVersion(c *xgb.Conn, ClientMajorVersion uint16, ClientMinorVersion uint16) QueryVersionCookie {
71 c.ExtLock.RLock()
72 defer c.ExtLock.RUnlock()
73 if _, ok := c.Extensions["Generic Event Extension"]; !ok {
74 panic("Cannot issue request 'QueryVersion' using the uninitialized extension 'Generic Event Extension'. ge.Init(connObj) must be called first.")
75 }
76 cookie := c.NewCookie(true, true)
77 c.NewRequest(queryVersionRequest(c, ClientMajorVersion, ClientMinorVersion), cookie)
78 return QueryVersionCookie{cookie}
79 }
80
81 // QueryVersionUnchecked sends an unchecked request.
82 // If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent.
83 func QueryVersionUnchecked(c *xgb.Conn, ClientMajorVersion uint16, ClientMinorVersion uint16) QueryVersionCookie {
84 c.ExtLock.RLock()
85 defer c.ExtLock.RUnlock()
86 if _, ok := c.Extensions["Generic Event Extension"]; !ok {
87 panic("Cannot issue request 'QueryVersion' using the uninitialized extension 'Generic Event Extension'. ge.Init(connObj) must be called first.")
88 }
89 cookie := c.NewCookie(false, true)
90 c.NewRequest(queryVersionRequest(c, ClientMajorVersion, ClientMinorVersion), cookie)
91 return QueryVersionCookie{cookie}
92 }
93
94 // QueryVersionReply represents the data returned from a QueryVersion request.
95 type QueryVersionReply struct {
96 Sequence uint16 // sequence number of the request for this reply
97 Length uint32 // number of bytes in this reply
98 // padding: 1 bytes
99 MajorVersion uint16
100 MinorVersion uint16
101 // padding: 20 bytes
102 }
103
104 // Reply blocks and returns the reply data for a QueryVersion request.
105 func (cook QueryVersionCookie) Reply() (*QueryVersionReply, error) {
106 buf, err := cook.Cookie.Reply()
107 if err != nil {
108 return nil, err
109 }
110 if buf == nil {
111 return nil, nil
112 }
113 return queryVersionReply(buf), nil
114 }
115
116 // queryVersionReply reads a byte slice into a QueryVersionReply value.
117 func queryVersionReply(buf []byte) *QueryVersionReply {
118 v := new(QueryVersionReply)
119 b := 1 // skip reply determinant
120
121 b += 1 // padding
122
123 v.Sequence = xgb.Get16(buf[b:])
124 b += 2
125
126 v.Length = xgb.Get32(buf[b:]) // 4-byte units
127 b += 4
128
129 v.MajorVersion = xgb.Get16(buf[b:])
130 b += 2
131
132 v.MinorVersion = xgb.Get16(buf[b:])
133 b += 2
134
135 b += 20 // padding
136
137 return v
138 }
139
140 // Write request to wire for QueryVersion
141 // queryVersionRequest writes a QueryVersion request to a byte slice.
142 func queryVersionRequest(c *xgb.Conn, ClientMajorVersion uint16, ClientMinorVersion uint16) []byte {
143 size := 8
144 b := 0
145 buf := make([]byte, size)
146
147 c.ExtLock.RLock()
148 buf[b] = c.Extensions["Generic Event Extension"]
149 c.ExtLock.RUnlock()
150 b += 1
151
152 buf[b] = 0 // request opcode
153 b += 1
154
155 xgb.Put16(buf[b:], uint16(size/4)) // write request size in 4-byte units
156 b += 2
157
158 xgb.Put16(buf[b:], ClientMajorVersion)
159 b += 2
160
161 xgb.Put16(buf[b:], ClientMinorVersion)
162 b += 2
163
164 return buf
165 }