github.com/BurntSushi/xgb@v0.0.0-20210121224620-deaf085860bc/damage/damage.go (about) 1 // Package damage is the X client API for the DAMAGE extension. 2 package damage 3 4 // This file is automatically generated from damage.xml. Edit at your peril! 5 6 import ( 7 "github.com/BurntSushi/xgb" 8 9 "github.com/BurntSushi/xgb/xfixes" 10 "github.com/BurntSushi/xgb/xproto" 11 ) 12 13 // Init must be called before using the DAMAGE extension. 14 func Init(c *xgb.Conn) error { 15 reply, err := xproto.QueryExtension(c, 6, "DAMAGE").Reply() 16 switch { 17 case err != nil: 18 return err 19 case !reply.Present: 20 return xgb.Errorf("No extension named DAMAGE could be found on on the server.") 21 } 22 23 c.ExtLock.Lock() 24 c.Extensions["DAMAGE"] = reply.MajorOpcode 25 c.ExtLock.Unlock() 26 for evNum, fun := range xgb.NewExtEventFuncs["DAMAGE"] { 27 xgb.NewEventFuncs[int(reply.FirstEvent)+evNum] = fun 28 } 29 for errNum, fun := range xgb.NewExtErrorFuncs["DAMAGE"] { 30 xgb.NewErrorFuncs[int(reply.FirstError)+errNum] = fun 31 } 32 return nil 33 } 34 35 func init() { 36 xgb.NewExtEventFuncs["DAMAGE"] = make(map[int]xgb.NewEventFun) 37 xgb.NewExtErrorFuncs["DAMAGE"] = make(map[int]xgb.NewErrorFun) 38 } 39 40 // BadBadDamage is the error number for a BadBadDamage. 41 const BadBadDamage = 0 42 43 type BadDamageError struct { 44 Sequence uint16 45 NiceName string 46 } 47 48 // BadDamageErrorNew constructs a BadDamageError value that implements xgb.Error from a byte slice. 49 func BadDamageErrorNew(buf []byte) xgb.Error { 50 v := BadDamageError{} 51 v.NiceName = "BadDamage" 52 53 b := 1 // skip error determinant 54 b += 1 // don't read error number 55 56 v.Sequence = xgb.Get16(buf[b:]) 57 b += 2 58 59 return v 60 } 61 62 // SequenceId returns the sequence id attached to the BadBadDamage error. 63 // This is mostly used internally. 64 func (err BadDamageError) SequenceId() uint16 { 65 return err.Sequence 66 } 67 68 // BadId returns the 'BadValue' number if one exists for the BadBadDamage error. If no bad value exists, 0 is returned. 69 func (err BadDamageError) BadId() uint32 { 70 return 0 71 } 72 73 // Error returns a rudimentary string representation of the BadBadDamage error. 74 75 func (err BadDamageError) Error() string { 76 fieldVals := make([]string, 0, 0) 77 fieldVals = append(fieldVals, "NiceName: "+err.NiceName) 78 fieldVals = append(fieldVals, xgb.Sprintf("Sequence: %d", err.Sequence)) 79 return "BadBadDamage {" + xgb.StringsJoin(fieldVals, ", ") + "}" 80 } 81 82 func init() { 83 xgb.NewExtErrorFuncs["DAMAGE"][0] = BadDamageErrorNew 84 } 85 86 type Damage uint32 87 88 func NewDamageId(c *xgb.Conn) (Damage, error) { 89 id, err := c.NewId() 90 if err != nil { 91 return 0, err 92 } 93 return Damage(id), nil 94 } 95 96 // Notify is the event number for a NotifyEvent. 97 const Notify = 0 98 99 type NotifyEvent struct { 100 Sequence uint16 101 Level byte 102 Drawable xproto.Drawable 103 Damage Damage 104 Timestamp xproto.Timestamp 105 Area xproto.Rectangle 106 Geometry xproto.Rectangle 107 } 108 109 // NotifyEventNew constructs a NotifyEvent value that implements xgb.Event from a byte slice. 110 func NotifyEventNew(buf []byte) xgb.Event { 111 v := NotifyEvent{} 112 b := 1 // don't read event number 113 114 v.Level = buf[b] 115 b += 1 116 117 v.Sequence = xgb.Get16(buf[b:]) 118 b += 2 119 120 v.Drawable = xproto.Drawable(xgb.Get32(buf[b:])) 121 b += 4 122 123 v.Damage = Damage(xgb.Get32(buf[b:])) 124 b += 4 125 126 v.Timestamp = xproto.Timestamp(xgb.Get32(buf[b:])) 127 b += 4 128 129 v.Area = xproto.Rectangle{} 130 b += xproto.RectangleRead(buf[b:], &v.Area) 131 132 v.Geometry = xproto.Rectangle{} 133 b += xproto.RectangleRead(buf[b:], &v.Geometry) 134 135 return v 136 } 137 138 // Bytes writes a NotifyEvent value to a byte slice. 139 func (v NotifyEvent) Bytes() []byte { 140 buf := make([]byte, 32) 141 b := 0 142 143 // write event number 144 buf[b] = 0 145 b += 1 146 147 buf[b] = v.Level 148 b += 1 149 150 b += 2 // skip sequence number 151 152 xgb.Put32(buf[b:], uint32(v.Drawable)) 153 b += 4 154 155 xgb.Put32(buf[b:], uint32(v.Damage)) 156 b += 4 157 158 xgb.Put32(buf[b:], uint32(v.Timestamp)) 159 b += 4 160 161 { 162 structBytes := v.Area.Bytes() 163 copy(buf[b:], structBytes) 164 b += len(structBytes) 165 } 166 167 { 168 structBytes := v.Geometry.Bytes() 169 copy(buf[b:], structBytes) 170 b += len(structBytes) 171 } 172 173 return buf 174 } 175 176 // SequenceId returns the sequence id attached to the Notify event. 177 // Events without a sequence number (KeymapNotify) return 0. 178 // This is mostly used internally. 179 func (v NotifyEvent) SequenceId() uint16 { 180 return v.Sequence 181 } 182 183 // String is a rudimentary string representation of NotifyEvent. 184 func (v NotifyEvent) String() string { 185 fieldVals := make([]string, 0, 6) 186 fieldVals = append(fieldVals, xgb.Sprintf("Sequence: %d", v.Sequence)) 187 fieldVals = append(fieldVals, xgb.Sprintf("Level: %d", v.Level)) 188 fieldVals = append(fieldVals, xgb.Sprintf("Drawable: %d", v.Drawable)) 189 fieldVals = append(fieldVals, xgb.Sprintf("Damage: %d", v.Damage)) 190 fieldVals = append(fieldVals, xgb.Sprintf("Timestamp: %d", v.Timestamp)) 191 return "Notify {" + xgb.StringsJoin(fieldVals, ", ") + "}" 192 } 193 194 func init() { 195 xgb.NewExtEventFuncs["DAMAGE"][0] = NotifyEventNew 196 } 197 198 const ( 199 ReportLevelRawRectangles = 0 200 ReportLevelDeltaRectangles = 1 201 ReportLevelBoundingBox = 2 202 ReportLevelNonEmpty = 3 203 ) 204 205 // Skipping definition for base type 'Bool' 206 207 // Skipping definition for base type 'Byte' 208 209 // Skipping definition for base type 'Card8' 210 211 // Skipping definition for base type 'Char' 212 213 // Skipping definition for base type 'Void' 214 215 // Skipping definition for base type 'Double' 216 217 // Skipping definition for base type 'Float' 218 219 // Skipping definition for base type 'Int16' 220 221 // Skipping definition for base type 'Int32' 222 223 // Skipping definition for base type 'Int8' 224 225 // Skipping definition for base type 'Card16' 226 227 // Skipping definition for base type 'Card32' 228 229 // AddCookie is a cookie used only for Add requests. 230 type AddCookie struct { 231 *xgb.Cookie 232 } 233 234 // Add sends an unchecked request. 235 // If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. 236 func Add(c *xgb.Conn, Drawable xproto.Drawable, Region xfixes.Region) AddCookie { 237 c.ExtLock.RLock() 238 defer c.ExtLock.RUnlock() 239 if _, ok := c.Extensions["DAMAGE"]; !ok { 240 panic("Cannot issue request 'Add' using the uninitialized extension 'DAMAGE'. damage.Init(connObj) must be called first.") 241 } 242 cookie := c.NewCookie(false, false) 243 c.NewRequest(addRequest(c, Drawable, Region), cookie) 244 return AddCookie{cookie} 245 } 246 247 // AddChecked sends a checked request. 248 // If an error occurs, it can be retrieved using AddCookie.Check() 249 func AddChecked(c *xgb.Conn, Drawable xproto.Drawable, Region xfixes.Region) AddCookie { 250 c.ExtLock.RLock() 251 defer c.ExtLock.RUnlock() 252 if _, ok := c.Extensions["DAMAGE"]; !ok { 253 panic("Cannot issue request 'Add' using the uninitialized extension 'DAMAGE'. damage.Init(connObj) must be called first.") 254 } 255 cookie := c.NewCookie(true, false) 256 c.NewRequest(addRequest(c, Drawable, Region), cookie) 257 return AddCookie{cookie} 258 } 259 260 // Check returns an error if one occurred for checked requests that are not expecting a reply. 261 // This cannot be called for requests expecting a reply, nor for unchecked requests. 262 func (cook AddCookie) Check() error { 263 return cook.Cookie.Check() 264 } 265 266 // Write request to wire for Add 267 // addRequest writes a Add request to a byte slice. 268 func addRequest(c *xgb.Conn, Drawable xproto.Drawable, Region xfixes.Region) []byte { 269 size := 12 270 b := 0 271 buf := make([]byte, size) 272 273 c.ExtLock.RLock() 274 buf[b] = c.Extensions["DAMAGE"] 275 c.ExtLock.RUnlock() 276 b += 1 277 278 buf[b] = 4 // request opcode 279 b += 1 280 281 xgb.Put16(buf[b:], uint16(size/4)) // write request size in 4-byte units 282 b += 2 283 284 xgb.Put32(buf[b:], uint32(Drawable)) 285 b += 4 286 287 xgb.Put32(buf[b:], uint32(Region)) 288 b += 4 289 290 return buf 291 } 292 293 // CreateCookie is a cookie used only for Create requests. 294 type CreateCookie struct { 295 *xgb.Cookie 296 } 297 298 // Create sends an unchecked request. 299 // If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. 300 func Create(c *xgb.Conn, Damage Damage, Drawable xproto.Drawable, Level byte) CreateCookie { 301 c.ExtLock.RLock() 302 defer c.ExtLock.RUnlock() 303 if _, ok := c.Extensions["DAMAGE"]; !ok { 304 panic("Cannot issue request 'Create' using the uninitialized extension 'DAMAGE'. damage.Init(connObj) must be called first.") 305 } 306 cookie := c.NewCookie(false, false) 307 c.NewRequest(createRequest(c, Damage, Drawable, Level), cookie) 308 return CreateCookie{cookie} 309 } 310 311 // CreateChecked sends a checked request. 312 // If an error occurs, it can be retrieved using CreateCookie.Check() 313 func CreateChecked(c *xgb.Conn, Damage Damage, Drawable xproto.Drawable, Level byte) CreateCookie { 314 c.ExtLock.RLock() 315 defer c.ExtLock.RUnlock() 316 if _, ok := c.Extensions["DAMAGE"]; !ok { 317 panic("Cannot issue request 'Create' using the uninitialized extension 'DAMAGE'. damage.Init(connObj) must be called first.") 318 } 319 cookie := c.NewCookie(true, false) 320 c.NewRequest(createRequest(c, Damage, Drawable, Level), cookie) 321 return CreateCookie{cookie} 322 } 323 324 // Check returns an error if one occurred for checked requests that are not expecting a reply. 325 // This cannot be called for requests expecting a reply, nor for unchecked requests. 326 func (cook CreateCookie) Check() error { 327 return cook.Cookie.Check() 328 } 329 330 // Write request to wire for Create 331 // createRequest writes a Create request to a byte slice. 332 func createRequest(c *xgb.Conn, Damage Damage, Drawable xproto.Drawable, Level byte) []byte { 333 size := 16 334 b := 0 335 buf := make([]byte, size) 336 337 c.ExtLock.RLock() 338 buf[b] = c.Extensions["DAMAGE"] 339 c.ExtLock.RUnlock() 340 b += 1 341 342 buf[b] = 1 // request opcode 343 b += 1 344 345 xgb.Put16(buf[b:], uint16(size/4)) // write request size in 4-byte units 346 b += 2 347 348 xgb.Put32(buf[b:], uint32(Damage)) 349 b += 4 350 351 xgb.Put32(buf[b:], uint32(Drawable)) 352 b += 4 353 354 buf[b] = Level 355 b += 1 356 357 b += 3 // padding 358 359 return buf 360 } 361 362 // DestroyCookie is a cookie used only for Destroy requests. 363 type DestroyCookie struct { 364 *xgb.Cookie 365 } 366 367 // Destroy sends an unchecked request. 368 // If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. 369 func Destroy(c *xgb.Conn, Damage Damage) DestroyCookie { 370 c.ExtLock.RLock() 371 defer c.ExtLock.RUnlock() 372 if _, ok := c.Extensions["DAMAGE"]; !ok { 373 panic("Cannot issue request 'Destroy' using the uninitialized extension 'DAMAGE'. damage.Init(connObj) must be called first.") 374 } 375 cookie := c.NewCookie(false, false) 376 c.NewRequest(destroyRequest(c, Damage), cookie) 377 return DestroyCookie{cookie} 378 } 379 380 // DestroyChecked sends a checked request. 381 // If an error occurs, it can be retrieved using DestroyCookie.Check() 382 func DestroyChecked(c *xgb.Conn, Damage Damage) DestroyCookie { 383 c.ExtLock.RLock() 384 defer c.ExtLock.RUnlock() 385 if _, ok := c.Extensions["DAMAGE"]; !ok { 386 panic("Cannot issue request 'Destroy' using the uninitialized extension 'DAMAGE'. damage.Init(connObj) must be called first.") 387 } 388 cookie := c.NewCookie(true, false) 389 c.NewRequest(destroyRequest(c, Damage), cookie) 390 return DestroyCookie{cookie} 391 } 392 393 // Check returns an error if one occurred for checked requests that are not expecting a reply. 394 // This cannot be called for requests expecting a reply, nor for unchecked requests. 395 func (cook DestroyCookie) Check() error { 396 return cook.Cookie.Check() 397 } 398 399 // Write request to wire for Destroy 400 // destroyRequest writes a Destroy request to a byte slice. 401 func destroyRequest(c *xgb.Conn, Damage Damage) []byte { 402 size := 8 403 b := 0 404 buf := make([]byte, size) 405 406 c.ExtLock.RLock() 407 buf[b] = c.Extensions["DAMAGE"] 408 c.ExtLock.RUnlock() 409 b += 1 410 411 buf[b] = 2 // request opcode 412 b += 1 413 414 xgb.Put16(buf[b:], uint16(size/4)) // write request size in 4-byte units 415 b += 2 416 417 xgb.Put32(buf[b:], uint32(Damage)) 418 b += 4 419 420 return buf 421 } 422 423 // QueryVersionCookie is a cookie used only for QueryVersion requests. 424 type QueryVersionCookie struct { 425 *xgb.Cookie 426 } 427 428 // QueryVersion sends a checked request. 429 // If an error occurs, it will be returned with the reply by calling QueryVersionCookie.Reply() 430 func QueryVersion(c *xgb.Conn, ClientMajorVersion uint32, ClientMinorVersion uint32) QueryVersionCookie { 431 c.ExtLock.RLock() 432 defer c.ExtLock.RUnlock() 433 if _, ok := c.Extensions["DAMAGE"]; !ok { 434 panic("Cannot issue request 'QueryVersion' using the uninitialized extension 'DAMAGE'. damage.Init(connObj) must be called first.") 435 } 436 cookie := c.NewCookie(true, true) 437 c.NewRequest(queryVersionRequest(c, ClientMajorVersion, ClientMinorVersion), cookie) 438 return QueryVersionCookie{cookie} 439 } 440 441 // QueryVersionUnchecked sends an unchecked request. 442 // If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. 443 func QueryVersionUnchecked(c *xgb.Conn, ClientMajorVersion uint32, ClientMinorVersion uint32) QueryVersionCookie { 444 c.ExtLock.RLock() 445 defer c.ExtLock.RUnlock() 446 if _, ok := c.Extensions["DAMAGE"]; !ok { 447 panic("Cannot issue request 'QueryVersion' using the uninitialized extension 'DAMAGE'. damage.Init(connObj) must be called first.") 448 } 449 cookie := c.NewCookie(false, true) 450 c.NewRequest(queryVersionRequest(c, ClientMajorVersion, ClientMinorVersion), cookie) 451 return QueryVersionCookie{cookie} 452 } 453 454 // QueryVersionReply represents the data returned from a QueryVersion request. 455 type QueryVersionReply struct { 456 Sequence uint16 // sequence number of the request for this reply 457 Length uint32 // number of bytes in this reply 458 // padding: 1 bytes 459 MajorVersion uint32 460 MinorVersion uint32 461 // padding: 16 bytes 462 } 463 464 // Reply blocks and returns the reply data for a QueryVersion request. 465 func (cook QueryVersionCookie) Reply() (*QueryVersionReply, error) { 466 buf, err := cook.Cookie.Reply() 467 if err != nil { 468 return nil, err 469 } 470 if buf == nil { 471 return nil, nil 472 } 473 return queryVersionReply(buf), nil 474 } 475 476 // queryVersionReply reads a byte slice into a QueryVersionReply value. 477 func queryVersionReply(buf []byte) *QueryVersionReply { 478 v := new(QueryVersionReply) 479 b := 1 // skip reply determinant 480 481 b += 1 // padding 482 483 v.Sequence = xgb.Get16(buf[b:]) 484 b += 2 485 486 v.Length = xgb.Get32(buf[b:]) // 4-byte units 487 b += 4 488 489 v.MajorVersion = xgb.Get32(buf[b:]) 490 b += 4 491 492 v.MinorVersion = xgb.Get32(buf[b:]) 493 b += 4 494 495 b += 16 // padding 496 497 return v 498 } 499 500 // Write request to wire for QueryVersion 501 // queryVersionRequest writes a QueryVersion request to a byte slice. 502 func queryVersionRequest(c *xgb.Conn, ClientMajorVersion uint32, ClientMinorVersion uint32) []byte { 503 size := 12 504 b := 0 505 buf := make([]byte, size) 506 507 c.ExtLock.RLock() 508 buf[b] = c.Extensions["DAMAGE"] 509 c.ExtLock.RUnlock() 510 b += 1 511 512 buf[b] = 0 // request opcode 513 b += 1 514 515 xgb.Put16(buf[b:], uint16(size/4)) // write request size in 4-byte units 516 b += 2 517 518 xgb.Put32(buf[b:], ClientMajorVersion) 519 b += 4 520 521 xgb.Put32(buf[b:], ClientMinorVersion) 522 b += 4 523 524 return buf 525 } 526 527 // SubtractCookie is a cookie used only for Subtract requests. 528 type SubtractCookie struct { 529 *xgb.Cookie 530 } 531 532 // Subtract sends an unchecked request. 533 // If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. 534 func Subtract(c *xgb.Conn, Damage Damage, Repair xfixes.Region, Parts xfixes.Region) SubtractCookie { 535 c.ExtLock.RLock() 536 defer c.ExtLock.RUnlock() 537 if _, ok := c.Extensions["DAMAGE"]; !ok { 538 panic("Cannot issue request 'Subtract' using the uninitialized extension 'DAMAGE'. damage.Init(connObj) must be called first.") 539 } 540 cookie := c.NewCookie(false, false) 541 c.NewRequest(subtractRequest(c, Damage, Repair, Parts), cookie) 542 return SubtractCookie{cookie} 543 } 544 545 // SubtractChecked sends a checked request. 546 // If an error occurs, it can be retrieved using SubtractCookie.Check() 547 func SubtractChecked(c *xgb.Conn, Damage Damage, Repair xfixes.Region, Parts xfixes.Region) SubtractCookie { 548 c.ExtLock.RLock() 549 defer c.ExtLock.RUnlock() 550 if _, ok := c.Extensions["DAMAGE"]; !ok { 551 panic("Cannot issue request 'Subtract' using the uninitialized extension 'DAMAGE'. damage.Init(connObj) must be called first.") 552 } 553 cookie := c.NewCookie(true, false) 554 c.NewRequest(subtractRequest(c, Damage, Repair, Parts), cookie) 555 return SubtractCookie{cookie} 556 } 557 558 // Check returns an error if one occurred for checked requests that are not expecting a reply. 559 // This cannot be called for requests expecting a reply, nor for unchecked requests. 560 func (cook SubtractCookie) Check() error { 561 return cook.Cookie.Check() 562 } 563 564 // Write request to wire for Subtract 565 // subtractRequest writes a Subtract request to a byte slice. 566 func subtractRequest(c *xgb.Conn, Damage Damage, Repair xfixes.Region, Parts xfixes.Region) []byte { 567 size := 16 568 b := 0 569 buf := make([]byte, size) 570 571 c.ExtLock.RLock() 572 buf[b] = c.Extensions["DAMAGE"] 573 c.ExtLock.RUnlock() 574 b += 1 575 576 buf[b] = 3 // request opcode 577 b += 1 578 579 xgb.Put16(buf[b:], uint16(size/4)) // write request size in 4-byte units 580 b += 2 581 582 xgb.Put32(buf[b:], uint32(Damage)) 583 b += 4 584 585 xgb.Put32(buf[b:], uint32(Repair)) 586 b += 4 587 588 xgb.Put32(buf[b:], uint32(Parts)) 589 b += 4 590 591 return buf 592 }