| 1 |
// Package xcmisc is the X client API for the XC-MISC extension. |
| 2 |
package xcmisc |
| 3 |
|
| 4 |
// This file is automatically generated from xc_misc.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 XC-MISC extension. |
| 13 |
func Init(c *xgb.Conn) error { |
| 14 |
reply, err := xproto.QueryExtension(c, 7, "XC-MISC").Reply() |
| 15 |
switch { |
| 16 |
case err != nil: |
| 17 |
return err |
| 18 |
case !reply.Present: |
| 19 |
return xgb.Errorf("No extension named XC-MISC could be found on on the server.") |
| 20 |
} |
| 21 |
|
| 22 |
c.ExtLock.Lock() |
| 23 |
c.Extensions["XC-MISC"] = reply.MajorOpcode |
| 24 |
c.ExtLock.Unlock() |
| 25 |
for evNum, fun := range xgb.NewExtEventFuncs["XC-MISC"] { |
| 26 |
xgb.NewEventFuncs[int(reply.FirstEvent)+evNum] = fun |
| 27 |
} |
| 28 |
for errNum, fun := range xgb.NewExtErrorFuncs["XC-MISC"] { |
| 29 |
xgb.NewErrorFuncs[int(reply.FirstError)+errNum] = fun |
| 30 |
} |
| 31 |
return nil |
| 32 |
} |
| 33 |
|
| 34 |
func init() { |
| 35 |
xgb.NewExtEventFuncs["XC-MISC"] = make(map[int]xgb.NewEventFun) |
| 36 |
xgb.NewExtErrorFuncs["XC-MISC"] = 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 |
// GetVersionCookie is a cookie used only for GetVersion requests. |
| 64 |
type GetVersionCookie struct { |
| 65 |
*xgb.Cookie |
| 66 |
} |
| 67 |
|
| 68 |
// GetVersion sends a checked request. |
| 69 |
// If an error occurs, it will be returned with the reply by calling GetVersionCookie.Reply() |
| 70 |
func GetVersion(c *xgb.Conn, ClientMajorVersion uint16, ClientMinorVersion uint16) GetVersionCookie { |
| 71 |
c.ExtLock.RLock() |
| 72 |
defer c.ExtLock.RUnlock() |
| 73 |
if _, ok := c.Extensions["XC-MISC"]; !ok { |
| 74 |
panic("Cannot issue request 'GetVersion' using the uninitialized extension 'XC-MISC'. xcmisc.Init(connObj) must be called first.") |
| 75 |
} |
| 76 |
cookie := c.NewCookie(true, true) |
| 77 |
c.NewRequest(getVersionRequest(c, ClientMajorVersion, ClientMinorVersion), cookie) |
| 78 |
return GetVersionCookie{cookie} |
| 79 |
} |
| 80 |
|
| 81 |
// GetVersionUnchecked sends an unchecked request. |
| 82 |
// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. |
| 83 |
func GetVersionUnchecked(c *xgb.Conn, ClientMajorVersion uint16, ClientMinorVersion uint16) GetVersionCookie { |
| 84 |
c.ExtLock.RLock() |
| 85 |
defer c.ExtLock.RUnlock() |
| 86 |
if _, ok := c.Extensions["XC-MISC"]; !ok { |
| 87 |
panic("Cannot issue request 'GetVersion' using the uninitialized extension 'XC-MISC'. xcmisc.Init(connObj) must be called first.") |
| 88 |
} |
| 89 |
cookie := c.NewCookie(false, true) |
| 90 |
c.NewRequest(getVersionRequest(c, ClientMajorVersion, ClientMinorVersion), cookie) |
| 91 |
return GetVersionCookie{cookie} |
| 92 |
} |
| 93 |
|
| 94 |
// GetVersionReply represents the data returned from a GetVersion request. |
| 95 |
type GetVersionReply 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 |
ServerMajorVersion uint16 |
| 100 |
ServerMinorVersion uint16 |
| 101 |
} |
| 102 |
|
| 103 |
// Reply blocks and returns the reply data for a GetVersion request. |
| 104 |
func (cook GetVersionCookie) Reply() (*GetVersionReply, error) { |
| 105 |
buf, err := cook.Cookie.Reply() |
| 106 |
if err != nil { |
| 107 |
return nil, err |
| 108 |
} |
| 109 |
if buf == nil { |
| 110 |
return nil, nil |
| 111 |
} |
| 112 |
return getVersionReply(buf), nil |
| 113 |
} |
| 114 |
|
| 115 |
// getVersionReply reads a byte slice into a GetVersionReply value. |
| 116 |
func getVersionReply(buf []byte) *GetVersionReply { |
| 117 |
v := new(GetVersionReply) |
| 118 |
b := 1 // skip reply determinant |
| 119 |
|
| 120 |
b += 1 // padding |
| 121 |
|
| 122 |
v.Sequence = xgb.Get16(buf[b:]) |
| 123 |
b += 2 |
| 124 |
|
| 125 |
v.Length = xgb.Get32(buf[b:]) // 4-byte units |
| 126 |
b += 4 |
| 127 |
|
| 128 |
v.ServerMajorVersion = xgb.Get16(buf[b:]) |
| 129 |
b += 2 |
| 130 |
|
| 131 |
v.ServerMinorVersion = xgb.Get16(buf[b:]) |
| 132 |
b += 2 |
| 133 |
|
| 134 |
return v |
| 135 |
} |
| 136 |
|
| 137 |
// Write request to wire for GetVersion |
| 138 |
// getVersionRequest writes a GetVersion request to a byte slice. |
| 139 |
func getVersionRequest(c *xgb.Conn, ClientMajorVersion uint16, ClientMinorVersion uint16) []byte { |
| 140 |
size := 8 |
| 141 |
b := 0 |
| 142 |
buf := make([]byte, size) |
| 143 |
|
| 144 |
c.ExtLock.RLock() |
| 145 |
buf[b] = c.Extensions["XC-MISC"] |
| 146 |
c.ExtLock.RUnlock() |
| 147 |
b += 1 |
| 148 |
|
| 149 |
buf[b] = 0 // request opcode |
| 150 |
b += 1 |
| 151 |
|
| 152 |
xgb.Put16(buf[b:], uint16(size/4)) // write request size in 4-byte units |
| 153 |
b += 2 |
| 154 |
|
| 155 |
xgb.Put16(buf[b:], ClientMajorVersion) |
| 156 |
b += 2 |
| 157 |
|
| 158 |
xgb.Put16(buf[b:], ClientMinorVersion) |
| 159 |
b += 2 |
| 160 |
|
| 161 |
return buf |
| 162 |
} |
| 163 |
|
| 164 |
// GetXIDListCookie is a cookie used only for GetXIDList requests. |
| 165 |
type GetXIDListCookie struct { |
| 166 |
*xgb.Cookie |
| 167 |
} |
| 168 |
|
| 169 |
// GetXIDList sends a checked request. |
| 170 |
// If an error occurs, it will be returned with the reply by calling GetXIDListCookie.Reply() |
| 171 |
func GetXIDList(c *xgb.Conn, Count uint32) GetXIDListCookie { |
| 172 |
c.ExtLock.RLock() |
| 173 |
defer c.ExtLock.RUnlock() |
| 174 |
if _, ok := c.Extensions["XC-MISC"]; !ok { |
| 175 |
panic("Cannot issue request 'GetXIDList' using the uninitialized extension 'XC-MISC'. xcmisc.Init(connObj) must be called first.") |
| 176 |
} |
| 177 |
cookie := c.NewCookie(true, true) |
| 178 |
c.NewRequest(getXIDListRequest(c, Count), cookie) |
| 179 |
return GetXIDListCookie{cookie} |
| 180 |
} |
| 181 |
|
| 182 |
// GetXIDListUnchecked sends an unchecked request. |
| 183 |
// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. |
| 184 |
func GetXIDListUnchecked(c *xgb.Conn, Count uint32) GetXIDListCookie { |
| 185 |
c.ExtLock.RLock() |
| 186 |
defer c.ExtLock.RUnlock() |
| 187 |
if _, ok := c.Extensions["XC-MISC"]; !ok { |
| 188 |
panic("Cannot issue request 'GetXIDList' using the uninitialized extension 'XC-MISC'. xcmisc.Init(connObj) must be called first.") |
| 189 |
} |
| 190 |
cookie := c.NewCookie(false, true) |
| 191 |
c.NewRequest(getXIDListRequest(c, Count), cookie) |
| 192 |
return GetXIDListCookie{cookie} |
| 193 |
} |
| 194 |
|
| 195 |
// GetXIDListReply represents the data returned from a GetXIDList request. |
| 196 |
type GetXIDListReply struct { |
| 197 |
Sequence uint16 // sequence number of the request for this reply |
| 198 |
Length uint32 // number of bytes in this reply |
| 199 |
// padding: 1 bytes |
| 200 |
IdsLen uint32 |
| 201 |
// padding: 20 bytes |
| 202 |
Ids []uint32 // size: xgb.Pad((int(IdsLen) * 4)) |
| 203 |
} |
| 204 |
|
| 205 |
// Reply blocks and returns the reply data for a GetXIDList request. |
| 206 |
func (cook GetXIDListCookie) Reply() (*GetXIDListReply, error) { |
| 207 |
buf, err := cook.Cookie.Reply() |
| 208 |
if err != nil { |
| 209 |
return nil, err |
| 210 |
} |
| 211 |
if buf == nil { |
| 212 |
return nil, nil |
| 213 |
} |
| 214 |
return getXIDListReply(buf), nil |
| 215 |
} |
| 216 |
|
| 217 |
// getXIDListReply reads a byte slice into a GetXIDListReply value. |
| 218 |
func getXIDListReply(buf []byte) *GetXIDListReply { |
| 219 |
v := new(GetXIDListReply) |
| 220 |
b := 1 // skip reply determinant |
| 221 |
|
| 222 |
b += 1 // padding |
| 223 |
|
| 224 |
v.Sequence = xgb.Get16(buf[b:]) |
| 225 |
b += 2 |
| 226 |
|
| 227 |
v.Length = xgb.Get32(buf[b:]) // 4-byte units |
| 228 |
b += 4 |
| 229 |
|
| 230 |
v.IdsLen = xgb.Get32(buf[b:]) |
| 231 |
b += 4 |
| 232 |
|
| 233 |
b += 20 // padding |
| 234 |
|
| 235 |
v.Ids = make([]uint32, v.IdsLen) |
| 236 |
for i := 0; i < int(v.IdsLen); i++ { |
| 237 |
v.Ids[i] = xgb.Get32(buf[b:]) |
| 238 |
b += 4 |
| 239 |
} |
| 240 |
|
| 241 |
return v |
| 242 |
} |
| 243 |
|
| 244 |
// Write request to wire for GetXIDList |
| 245 |
// getXIDListRequest writes a GetXIDList request to a byte slice. |
| 246 |
func getXIDListRequest(c *xgb.Conn, Count uint32) []byte { |
| 247 |
size := 8 |
| 248 |
b := 0 |
| 249 |
buf := make([]byte, size) |
| 250 |
|
| 251 |
c.ExtLock.RLock() |
| 252 |
buf[b] = c.Extensions["XC-MISC"] |
| 253 |
c.ExtLock.RUnlock() |
| 254 |
b += 1 |
| 255 |
|
| 256 |
buf[b] = 2 // request opcode |
| 257 |
b += 1 |
| 258 |
|
| 259 |
xgb.Put16(buf[b:], uint16(size/4)) // write request size in 4-byte units |
| 260 |
b += 2 |
| 261 |
|
| 262 |
xgb.Put32(buf[b:], Count) |
| 263 |
b += 4 |
| 264 |
|
| 265 |
return buf |
| 266 |
} |
| 267 |
|
| 268 |
// GetXIDRangeCookie is a cookie used only for GetXIDRange requests. |
| 269 |
type GetXIDRangeCookie struct { |
| 270 |
*xgb.Cookie |
| 271 |
} |
| 272 |
|
| 273 |
// GetXIDRange sends a checked request. |
| 274 |
// If an error occurs, it will be returned with the reply by calling GetXIDRangeCookie.Reply() |
| 275 |
func GetXIDRange(c *xgb.Conn) GetXIDRangeCookie { |
| 276 |
c.ExtLock.RLock() |
| 277 |
defer c.ExtLock.RUnlock() |
| 278 |
if _, ok := c.Extensions["XC-MISC"]; !ok { |
| 279 |
panic("Cannot issue request 'GetXIDRange' using the uninitialized extension 'XC-MISC'. xcmisc.Init(connObj) must be called first.") |
| 280 |
} |
| 281 |
cookie := c.NewCookie(true, true) |
| 282 |
c.NewRequest(getXIDRangeRequest(c), cookie) |
| 283 |
return GetXIDRangeCookie{cookie} |
| 284 |
} |
| 285 |
|
| 286 |
// GetXIDRangeUnchecked sends an unchecked request. |
| 287 |
// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. |
| 288 |
func GetXIDRangeUnchecked(c *xgb.Conn) GetXIDRangeCookie { |
| 289 |
c.ExtLock.RLock() |
| 290 |
defer c.ExtLock.RUnlock() |
| 291 |
if _, ok := c.Extensions["XC-MISC"]; !ok { |
| 292 |
panic("Cannot issue request 'GetXIDRange' using the uninitialized extension 'XC-MISC'. xcmisc.Init(connObj) must be called first.") |
| 293 |
} |
| 294 |
cookie := c.NewCookie(false, true) |
| 295 |
c.NewRequest(getXIDRangeRequest(c), cookie) |
| 296 |
return GetXIDRangeCookie{cookie} |
| 297 |
} |
| 298 |
|
| 299 |
// GetXIDRangeReply represents the data returned from a GetXIDRange request. |
| 300 |
type GetXIDRangeReply struct { |
| 301 |
Sequence uint16 // sequence number of the request for this reply |
| 302 |
Length uint32 // number of bytes in this reply |
| 303 |
// padding: 1 bytes |
| 304 |
StartId uint32 |
| 305 |
Count uint32 |
| 306 |
} |
| 307 |
|
| 308 |
// Reply blocks and returns the reply data for a GetXIDRange request. |
| 309 |
func (cook GetXIDRangeCookie) Reply() (*GetXIDRangeReply, error) { |
| 310 |
buf, err := cook.Cookie.Reply() |
| 311 |
if err != nil { |
| 312 |
return nil, err |
| 313 |
} |
| 314 |
if buf == nil { |
| 315 |
return nil, nil |
| 316 |
} |
| 317 |
return getXIDRangeReply(buf), nil |
| 318 |
} |
| 319 |
|
| 320 |
// getXIDRangeReply reads a byte slice into a GetXIDRangeReply value. |
| 321 |
func getXIDRangeReply(buf []byte) *GetXIDRangeReply { |
| 322 |
v := new(GetXIDRangeReply) |
| 323 |
b := 1 // skip reply determinant |
| 324 |
|
| 325 |
b += 1 // padding |
| 326 |
|
| 327 |
v.Sequence = xgb.Get16(buf[b:]) |
| 328 |
b += 2 |
| 329 |
|
| 330 |
v.Length = xgb.Get32(buf[b:]) // 4-byte units |
| 331 |
b += 4 |
| 332 |
|
| 333 |
v.StartId = xgb.Get32(buf[b:]) |
| 334 |
b += 4 |
| 335 |
|
| 336 |
v.Count = xgb.Get32(buf[b:]) |
| 337 |
b += 4 |
| 338 |
|
| 339 |
return v |
| 340 |
} |
| 341 |
|
| 342 |
// Write request to wire for GetXIDRange |
| 343 |
// getXIDRangeRequest writes a GetXIDRange request to a byte slice. |
| 344 |
func getXIDRangeRequest(c *xgb.Conn) []byte { |
| 345 |
size := 4 |
| 346 |
b := 0 |
| 347 |
buf := make([]byte, size) |
| 348 |
|
| 349 |
c.ExtLock.RLock() |
| 350 |
buf[b] = c.Extensions["XC-MISC"] |
| 351 |
c.ExtLock.RUnlock() |
| 352 |
b += 1 |
| 353 |
|
| 354 |
buf[b] = 1 // request opcode |
| 355 |
b += 1 |
| 356 |
|
| 357 |
xgb.Put16(buf[b:], uint16(size/4)) // write request size in 4-byte units |
| 358 |
b += 2 |
| 359 |
|
| 360 |
return buf |
| 361 |
} |