github.com/BurntSushi/xgb@v0.0.0-20210121224620-deaf085860bc/xprint/xprint.go (about) 1 // Package xprint is the X client API for the XpExtension extension. 2 package xprint 3 4 // This file is automatically generated from xprint.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 XpExtension extension. 13 func Init(c *xgb.Conn) error { 14 reply, err := xproto.QueryExtension(c, 11, "XpExtension").Reply() 15 switch { 16 case err != nil: 17 return err 18 case !reply.Present: 19 return xgb.Errorf("No extension named XpExtension could be found on on the server.") 20 } 21 22 c.ExtLock.Lock() 23 c.Extensions["XpExtension"] = reply.MajorOpcode 24 c.ExtLock.Unlock() 25 for evNum, fun := range xgb.NewExtEventFuncs["XpExtension"] { 26 xgb.NewEventFuncs[int(reply.FirstEvent)+evNum] = fun 27 } 28 for errNum, fun := range xgb.NewExtErrorFuncs["XpExtension"] { 29 xgb.NewErrorFuncs[int(reply.FirstError)+errNum] = fun 30 } 31 return nil 32 } 33 34 func init() { 35 xgb.NewExtEventFuncs["XpExtension"] = make(map[int]xgb.NewEventFun) 36 xgb.NewExtErrorFuncs["XpExtension"] = make(map[int]xgb.NewErrorFun) 37 } 38 39 const ( 40 AttrJobAttr = 1 41 AttrDocAttr = 2 42 AttrPageAttr = 3 43 AttrPrinterAttr = 4 44 AttrServerAttr = 5 45 AttrMediumAttr = 6 46 AttrSpoolerAttr = 7 47 ) 48 49 // AttributNotify is the event number for a AttributNotifyEvent. 50 const AttributNotify = 1 51 52 type AttributNotifyEvent struct { 53 Sequence uint16 54 Detail byte 55 Context Pcontext 56 } 57 58 // AttributNotifyEventNew constructs a AttributNotifyEvent value that implements xgb.Event from a byte slice. 59 func AttributNotifyEventNew(buf []byte) xgb.Event { 60 v := AttributNotifyEvent{} 61 b := 1 // don't read event number 62 63 v.Detail = buf[b] 64 b += 1 65 66 v.Sequence = xgb.Get16(buf[b:]) 67 b += 2 68 69 v.Context = Pcontext(xgb.Get32(buf[b:])) 70 b += 4 71 72 return v 73 } 74 75 // Bytes writes a AttributNotifyEvent value to a byte slice. 76 func (v AttributNotifyEvent) Bytes() []byte { 77 buf := make([]byte, 32) 78 b := 0 79 80 // write event number 81 buf[b] = 1 82 b += 1 83 84 buf[b] = v.Detail 85 b += 1 86 87 b += 2 // skip sequence number 88 89 xgb.Put32(buf[b:], uint32(v.Context)) 90 b += 4 91 92 return buf 93 } 94 95 // SequenceId returns the sequence id attached to the AttributNotify event. 96 // Events without a sequence number (KeymapNotify) return 0. 97 // This is mostly used internally. 98 func (v AttributNotifyEvent) SequenceId() uint16 { 99 return v.Sequence 100 } 101 102 // String is a rudimentary string representation of AttributNotifyEvent. 103 func (v AttributNotifyEvent) String() string { 104 fieldVals := make([]string, 0, 2) 105 fieldVals = append(fieldVals, xgb.Sprintf("Sequence: %d", v.Sequence)) 106 fieldVals = append(fieldVals, xgb.Sprintf("Detail: %d", v.Detail)) 107 fieldVals = append(fieldVals, xgb.Sprintf("Context: %d", v.Context)) 108 return "AttributNotify {" + xgb.StringsJoin(fieldVals, ", ") + "}" 109 } 110 111 func init() { 112 xgb.NewExtEventFuncs["XpExtension"][1] = AttributNotifyEventNew 113 } 114 115 // BadBadContext is the error number for a BadBadContext. 116 const BadBadContext = 0 117 118 type BadContextError struct { 119 Sequence uint16 120 NiceName string 121 } 122 123 // BadContextErrorNew constructs a BadContextError value that implements xgb.Error from a byte slice. 124 func BadContextErrorNew(buf []byte) xgb.Error { 125 v := BadContextError{} 126 v.NiceName = "BadContext" 127 128 b := 1 // skip error determinant 129 b += 1 // don't read error number 130 131 v.Sequence = xgb.Get16(buf[b:]) 132 b += 2 133 134 return v 135 } 136 137 // SequenceId returns the sequence id attached to the BadBadContext error. 138 // This is mostly used internally. 139 func (err BadContextError) SequenceId() uint16 { 140 return err.Sequence 141 } 142 143 // BadId returns the 'BadValue' number if one exists for the BadBadContext error. If no bad value exists, 0 is returned. 144 func (err BadContextError) BadId() uint32 { 145 return 0 146 } 147 148 // Error returns a rudimentary string representation of the BadBadContext error. 149 150 func (err BadContextError) Error() string { 151 fieldVals := make([]string, 0, 0) 152 fieldVals = append(fieldVals, "NiceName: "+err.NiceName) 153 fieldVals = append(fieldVals, xgb.Sprintf("Sequence: %d", err.Sequence)) 154 return "BadBadContext {" + xgb.StringsJoin(fieldVals, ", ") + "}" 155 } 156 157 func init() { 158 xgb.NewExtErrorFuncs["XpExtension"][0] = BadContextErrorNew 159 } 160 161 // BadBadSequence is the error number for a BadBadSequence. 162 const BadBadSequence = 1 163 164 type BadSequenceError struct { 165 Sequence uint16 166 NiceName string 167 } 168 169 // BadSequenceErrorNew constructs a BadSequenceError value that implements xgb.Error from a byte slice. 170 func BadSequenceErrorNew(buf []byte) xgb.Error { 171 v := BadSequenceError{} 172 v.NiceName = "BadSequence" 173 174 b := 1 // skip error determinant 175 b += 1 // don't read error number 176 177 v.Sequence = xgb.Get16(buf[b:]) 178 b += 2 179 180 return v 181 } 182 183 // SequenceId returns the sequence id attached to the BadBadSequence error. 184 // This is mostly used internally. 185 func (err BadSequenceError) SequenceId() uint16 { 186 return err.Sequence 187 } 188 189 // BadId returns the 'BadValue' number if one exists for the BadBadSequence error. If no bad value exists, 0 is returned. 190 func (err BadSequenceError) BadId() uint32 { 191 return 0 192 } 193 194 // Error returns a rudimentary string representation of the BadBadSequence error. 195 196 func (err BadSequenceError) Error() string { 197 fieldVals := make([]string, 0, 0) 198 fieldVals = append(fieldVals, "NiceName: "+err.NiceName) 199 fieldVals = append(fieldVals, xgb.Sprintf("Sequence: %d", err.Sequence)) 200 return "BadBadSequence {" + xgb.StringsJoin(fieldVals, ", ") + "}" 201 } 202 203 func init() { 204 xgb.NewExtErrorFuncs["XpExtension"][1] = BadSequenceErrorNew 205 } 206 207 const ( 208 DetailStartJobNotify = 1 209 DetailEndJobNotify = 2 210 DetailStartDocNotify = 3 211 DetailEndDocNotify = 4 212 DetailStartPageNotify = 5 213 DetailEndPageNotify = 6 214 ) 215 216 const ( 217 EvMaskNoEventMask = 0 218 EvMaskPrintMask = 1 219 EvMaskAttributeMask = 2 220 ) 221 222 const ( 223 GetDocFinished = 0 224 GetDocSecondConsumer = 1 225 ) 226 227 // Notify is the event number for a NotifyEvent. 228 const Notify = 0 229 230 type NotifyEvent struct { 231 Sequence uint16 232 Detail byte 233 Context Pcontext 234 Cancel bool 235 } 236 237 // NotifyEventNew constructs a NotifyEvent value that implements xgb.Event from a byte slice. 238 func NotifyEventNew(buf []byte) xgb.Event { 239 v := NotifyEvent{} 240 b := 1 // don't read event number 241 242 v.Detail = buf[b] 243 b += 1 244 245 v.Sequence = xgb.Get16(buf[b:]) 246 b += 2 247 248 v.Context = Pcontext(xgb.Get32(buf[b:])) 249 b += 4 250 251 if buf[b] == 1 { 252 v.Cancel = true 253 } else { 254 v.Cancel = false 255 } 256 b += 1 257 258 return v 259 } 260 261 // Bytes writes a NotifyEvent value to a byte slice. 262 func (v NotifyEvent) Bytes() []byte { 263 buf := make([]byte, 32) 264 b := 0 265 266 // write event number 267 buf[b] = 0 268 b += 1 269 270 buf[b] = v.Detail 271 b += 1 272 273 b += 2 // skip sequence number 274 275 xgb.Put32(buf[b:], uint32(v.Context)) 276 b += 4 277 278 if v.Cancel { 279 buf[b] = 1 280 } else { 281 buf[b] = 0 282 } 283 b += 1 284 285 return buf 286 } 287 288 // SequenceId returns the sequence id attached to the Notify event. 289 // Events without a sequence number (KeymapNotify) return 0. 290 // This is mostly used internally. 291 func (v NotifyEvent) SequenceId() uint16 { 292 return v.Sequence 293 } 294 295 // String is a rudimentary string representation of NotifyEvent. 296 func (v NotifyEvent) String() string { 297 fieldVals := make([]string, 0, 3) 298 fieldVals = append(fieldVals, xgb.Sprintf("Sequence: %d", v.Sequence)) 299 fieldVals = append(fieldVals, xgb.Sprintf("Detail: %d", v.Detail)) 300 fieldVals = append(fieldVals, xgb.Sprintf("Context: %d", v.Context)) 301 fieldVals = append(fieldVals, xgb.Sprintf("Cancel: %t", v.Cancel)) 302 return "Notify {" + xgb.StringsJoin(fieldVals, ", ") + "}" 303 } 304 305 func init() { 306 xgb.NewExtEventFuncs["XpExtension"][0] = NotifyEventNew 307 } 308 309 type Pcontext uint32 310 311 func NewPcontextId(c *xgb.Conn) (Pcontext, error) { 312 id, err := c.NewId() 313 if err != nil { 314 return 0, err 315 } 316 return Pcontext(id), nil 317 } 318 319 type Printer struct { 320 NameLen uint32 321 Name []String8 // size: xgb.Pad((int(NameLen) * 1)) 322 DescLen uint32 323 Description []String8 // size: xgb.Pad((int(DescLen) * 1)) 324 } 325 326 // PrinterRead reads a byte slice into a Printer value. 327 func PrinterRead(buf []byte, v *Printer) int { 328 b := 0 329 330 v.NameLen = xgb.Get32(buf[b:]) 331 b += 4 332 333 v.Name = make([]String8, v.NameLen) 334 for i := 0; i < int(v.NameLen); i++ { 335 v.Name[i] = String8(buf[b]) 336 b += 1 337 } 338 339 v.DescLen = xgb.Get32(buf[b:]) 340 b += 4 341 342 v.Description = make([]String8, v.DescLen) 343 for i := 0; i < int(v.DescLen); i++ { 344 v.Description[i] = String8(buf[b]) 345 b += 1 346 } 347 348 return b 349 } 350 351 // PrinterReadList reads a byte slice into a list of Printer values. 352 func PrinterReadList(buf []byte, dest []Printer) int { 353 b := 0 354 for i := 0; i < len(dest); i++ { 355 dest[i] = Printer{} 356 b += PrinterRead(buf[b:], &dest[i]) 357 } 358 return xgb.Pad(b) 359 } 360 361 // Bytes writes a Printer value to a byte slice. 362 func (v Printer) Bytes() []byte { 363 buf := make([]byte, (((4 + xgb.Pad((int(v.NameLen) * 1))) + 4) + xgb.Pad((int(v.DescLen) * 1)))) 364 b := 0 365 366 xgb.Put32(buf[b:], v.NameLen) 367 b += 4 368 369 for i := 0; i < int(v.NameLen); i++ { 370 buf[b] = byte(v.Name[i]) 371 b += 1 372 } 373 374 xgb.Put32(buf[b:], v.DescLen) 375 b += 4 376 377 for i := 0; i < int(v.DescLen); i++ { 378 buf[b] = byte(v.Description[i]) 379 b += 1 380 } 381 382 return buf[:b] 383 } 384 385 // PrinterListBytes writes a list of Printer values to a byte slice. 386 func PrinterListBytes(buf []byte, list []Printer) int { 387 b := 0 388 var structBytes []byte 389 for _, item := range list { 390 structBytes = item.Bytes() 391 copy(buf[b:], structBytes) 392 b += len(structBytes) 393 } 394 return xgb.Pad(b) 395 } 396 397 // PrinterListSize computes the size (bytes) of a list of Printer values. 398 func PrinterListSize(list []Printer) int { 399 size := 0 400 for _, item := range list { 401 size += (((4 + xgb.Pad((int(item.NameLen) * 1))) + 4) + xgb.Pad((int(item.DescLen) * 1))) 402 } 403 return size 404 } 405 406 type String8 byte 407 408 // Skipping definition for base type 'Bool' 409 410 // Skipping definition for base type 'Byte' 411 412 // Skipping definition for base type 'Card8' 413 414 // Skipping definition for base type 'Char' 415 416 // Skipping definition for base type 'Void' 417 418 // Skipping definition for base type 'Double' 419 420 // Skipping definition for base type 'Float' 421 422 // Skipping definition for base type 'Int16' 423 424 // Skipping definition for base type 'Int32' 425 426 // Skipping definition for base type 'Int8' 427 428 // Skipping definition for base type 'Card16' 429 430 // Skipping definition for base type 'Card32' 431 432 // CreateContextCookie is a cookie used only for CreateContext requests. 433 type CreateContextCookie struct { 434 *xgb.Cookie 435 } 436 437 // CreateContext sends an unchecked request. 438 // If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. 439 func CreateContext(c *xgb.Conn, ContextId uint32, PrinterNameLen uint32, LocaleLen uint32, PrinterName []String8, Locale []String8) CreateContextCookie { 440 c.ExtLock.RLock() 441 defer c.ExtLock.RUnlock() 442 if _, ok := c.Extensions["XpExtension"]; !ok { 443 panic("Cannot issue request 'CreateContext' using the uninitialized extension 'XpExtension'. xprint.Init(connObj) must be called first.") 444 } 445 cookie := c.NewCookie(false, false) 446 c.NewRequest(createContextRequest(c, ContextId, PrinterNameLen, LocaleLen, PrinterName, Locale), cookie) 447 return CreateContextCookie{cookie} 448 } 449 450 // CreateContextChecked sends a checked request. 451 // If an error occurs, it can be retrieved using CreateContextCookie.Check() 452 func CreateContextChecked(c *xgb.Conn, ContextId uint32, PrinterNameLen uint32, LocaleLen uint32, PrinterName []String8, Locale []String8) CreateContextCookie { 453 c.ExtLock.RLock() 454 defer c.ExtLock.RUnlock() 455 if _, ok := c.Extensions["XpExtension"]; !ok { 456 panic("Cannot issue request 'CreateContext' using the uninitialized extension 'XpExtension'. xprint.Init(connObj) must be called first.") 457 } 458 cookie := c.NewCookie(true, false) 459 c.NewRequest(createContextRequest(c, ContextId, PrinterNameLen, LocaleLen, PrinterName, Locale), cookie) 460 return CreateContextCookie{cookie} 461 } 462 463 // Check returns an error if one occurred for checked requests that are not expecting a reply. 464 // This cannot be called for requests expecting a reply, nor for unchecked requests. 465 func (cook CreateContextCookie) Check() error { 466 return cook.Cookie.Check() 467 } 468 469 // Write request to wire for CreateContext 470 // createContextRequest writes a CreateContext request to a byte slice. 471 func createContextRequest(c *xgb.Conn, ContextId uint32, PrinterNameLen uint32, LocaleLen uint32, PrinterName []String8, Locale []String8) []byte { 472 size := xgb.Pad(((16 + xgb.Pad((int(PrinterNameLen) * 1))) + xgb.Pad((int(LocaleLen) * 1)))) 473 b := 0 474 buf := make([]byte, size) 475 476 c.ExtLock.RLock() 477 buf[b] = c.Extensions["XpExtension"] 478 c.ExtLock.RUnlock() 479 b += 1 480 481 buf[b] = 2 // request opcode 482 b += 1 483 484 xgb.Put16(buf[b:], uint16(size/4)) // write request size in 4-byte units 485 b += 2 486 487 xgb.Put32(buf[b:], ContextId) 488 b += 4 489 490 xgb.Put32(buf[b:], PrinterNameLen) 491 b += 4 492 493 xgb.Put32(buf[b:], LocaleLen) 494 b += 4 495 496 for i := 0; i < int(PrinterNameLen); i++ { 497 buf[b] = byte(PrinterName[i]) 498 b += 1 499 } 500 501 for i := 0; i < int(LocaleLen); i++ { 502 buf[b] = byte(Locale[i]) 503 b += 1 504 } 505 506 return buf 507 } 508 509 // PrintDestroyContextCookie is a cookie used only for PrintDestroyContext requests. 510 type PrintDestroyContextCookie struct { 511 *xgb.Cookie 512 } 513 514 // PrintDestroyContext sends an unchecked request. 515 // If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. 516 func PrintDestroyContext(c *xgb.Conn, Context uint32) PrintDestroyContextCookie { 517 c.ExtLock.RLock() 518 defer c.ExtLock.RUnlock() 519 if _, ok := c.Extensions["XpExtension"]; !ok { 520 panic("Cannot issue request 'PrintDestroyContext' using the uninitialized extension 'XpExtension'. xprint.Init(connObj) must be called first.") 521 } 522 cookie := c.NewCookie(false, false) 523 c.NewRequest(printDestroyContextRequest(c, Context), cookie) 524 return PrintDestroyContextCookie{cookie} 525 } 526 527 // PrintDestroyContextChecked sends a checked request. 528 // If an error occurs, it can be retrieved using PrintDestroyContextCookie.Check() 529 func PrintDestroyContextChecked(c *xgb.Conn, Context uint32) PrintDestroyContextCookie { 530 c.ExtLock.RLock() 531 defer c.ExtLock.RUnlock() 532 if _, ok := c.Extensions["XpExtension"]; !ok { 533 panic("Cannot issue request 'PrintDestroyContext' using the uninitialized extension 'XpExtension'. xprint.Init(connObj) must be called first.") 534 } 535 cookie := c.NewCookie(true, false) 536 c.NewRequest(printDestroyContextRequest(c, Context), cookie) 537 return PrintDestroyContextCookie{cookie} 538 } 539 540 // Check returns an error if one occurred for checked requests that are not expecting a reply. 541 // This cannot be called for requests expecting a reply, nor for unchecked requests. 542 func (cook PrintDestroyContextCookie) Check() error { 543 return cook.Cookie.Check() 544 } 545 546 // Write request to wire for PrintDestroyContext 547 // printDestroyContextRequest writes a PrintDestroyContext request to a byte slice. 548 func printDestroyContextRequest(c *xgb.Conn, Context uint32) []byte { 549 size := 8 550 b := 0 551 buf := make([]byte, size) 552 553 c.ExtLock.RLock() 554 buf[b] = c.Extensions["XpExtension"] 555 c.ExtLock.RUnlock() 556 b += 1 557 558 buf[b] = 5 // request opcode 559 b += 1 560 561 xgb.Put16(buf[b:], uint16(size/4)) // write request size in 4-byte units 562 b += 2 563 564 xgb.Put32(buf[b:], Context) 565 b += 4 566 567 return buf 568 } 569 570 // PrintEndDocCookie is a cookie used only for PrintEndDoc requests. 571 type PrintEndDocCookie struct { 572 *xgb.Cookie 573 } 574 575 // PrintEndDoc sends an unchecked request. 576 // If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. 577 func PrintEndDoc(c *xgb.Conn, Cancel bool) PrintEndDocCookie { 578 c.ExtLock.RLock() 579 defer c.ExtLock.RUnlock() 580 if _, ok := c.Extensions["XpExtension"]; !ok { 581 panic("Cannot issue request 'PrintEndDoc' using the uninitialized extension 'XpExtension'. xprint.Init(connObj) must be called first.") 582 } 583 cookie := c.NewCookie(false, false) 584 c.NewRequest(printEndDocRequest(c, Cancel), cookie) 585 return PrintEndDocCookie{cookie} 586 } 587 588 // PrintEndDocChecked sends a checked request. 589 // If an error occurs, it can be retrieved using PrintEndDocCookie.Check() 590 func PrintEndDocChecked(c *xgb.Conn, Cancel bool) PrintEndDocCookie { 591 c.ExtLock.RLock() 592 defer c.ExtLock.RUnlock() 593 if _, ok := c.Extensions["XpExtension"]; !ok { 594 panic("Cannot issue request 'PrintEndDoc' using the uninitialized extension 'XpExtension'. xprint.Init(connObj) must be called first.") 595 } 596 cookie := c.NewCookie(true, false) 597 c.NewRequest(printEndDocRequest(c, Cancel), cookie) 598 return PrintEndDocCookie{cookie} 599 } 600 601 // Check returns an error if one occurred for checked requests that are not expecting a reply. 602 // This cannot be called for requests expecting a reply, nor for unchecked requests. 603 func (cook PrintEndDocCookie) Check() error { 604 return cook.Cookie.Check() 605 } 606 607 // Write request to wire for PrintEndDoc 608 // printEndDocRequest writes a PrintEndDoc request to a byte slice. 609 func printEndDocRequest(c *xgb.Conn, Cancel bool) []byte { 610 size := 8 611 b := 0 612 buf := make([]byte, size) 613 614 c.ExtLock.RLock() 615 buf[b] = c.Extensions["XpExtension"] 616 c.ExtLock.RUnlock() 617 b += 1 618 619 buf[b] = 10 // request opcode 620 b += 1 621 622 xgb.Put16(buf[b:], uint16(size/4)) // write request size in 4-byte units 623 b += 2 624 625 if Cancel { 626 buf[b] = 1 627 } else { 628 buf[b] = 0 629 } 630 b += 1 631 632 return buf 633 } 634 635 // PrintEndJobCookie is a cookie used only for PrintEndJob requests. 636 type PrintEndJobCookie struct { 637 *xgb.Cookie 638 } 639 640 // PrintEndJob sends an unchecked request. 641 // If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. 642 func PrintEndJob(c *xgb.Conn, Cancel bool) PrintEndJobCookie { 643 c.ExtLock.RLock() 644 defer c.ExtLock.RUnlock() 645 if _, ok := c.Extensions["XpExtension"]; !ok { 646 panic("Cannot issue request 'PrintEndJob' using the uninitialized extension 'XpExtension'. xprint.Init(connObj) must be called first.") 647 } 648 cookie := c.NewCookie(false, false) 649 c.NewRequest(printEndJobRequest(c, Cancel), cookie) 650 return PrintEndJobCookie{cookie} 651 } 652 653 // PrintEndJobChecked sends a checked request. 654 // If an error occurs, it can be retrieved using PrintEndJobCookie.Check() 655 func PrintEndJobChecked(c *xgb.Conn, Cancel bool) PrintEndJobCookie { 656 c.ExtLock.RLock() 657 defer c.ExtLock.RUnlock() 658 if _, ok := c.Extensions["XpExtension"]; !ok { 659 panic("Cannot issue request 'PrintEndJob' using the uninitialized extension 'XpExtension'. xprint.Init(connObj) must be called first.") 660 } 661 cookie := c.NewCookie(true, false) 662 c.NewRequest(printEndJobRequest(c, Cancel), cookie) 663 return PrintEndJobCookie{cookie} 664 } 665 666 // Check returns an error if one occurred for checked requests that are not expecting a reply. 667 // This cannot be called for requests expecting a reply, nor for unchecked requests. 668 func (cook PrintEndJobCookie) Check() error { 669 return cook.Cookie.Check() 670 } 671 672 // Write request to wire for PrintEndJob 673 // printEndJobRequest writes a PrintEndJob request to a byte slice. 674 func printEndJobRequest(c *xgb.Conn, Cancel bool) []byte { 675 size := 8 676 b := 0 677 buf := make([]byte, size) 678 679 c.ExtLock.RLock() 680 buf[b] = c.Extensions["XpExtension"] 681 c.ExtLock.RUnlock() 682 b += 1 683 684 buf[b] = 8 // request opcode 685 b += 1 686 687 xgb.Put16(buf[b:], uint16(size/4)) // write request size in 4-byte units 688 b += 2 689 690 if Cancel { 691 buf[b] = 1 692 } else { 693 buf[b] = 0 694 } 695 b += 1 696 697 return buf 698 } 699 700 // PrintEndPageCookie is a cookie used only for PrintEndPage requests. 701 type PrintEndPageCookie struct { 702 *xgb.Cookie 703 } 704 705 // PrintEndPage sends an unchecked request. 706 // If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. 707 func PrintEndPage(c *xgb.Conn, Cancel bool) PrintEndPageCookie { 708 c.ExtLock.RLock() 709 defer c.ExtLock.RUnlock() 710 if _, ok := c.Extensions["XpExtension"]; !ok { 711 panic("Cannot issue request 'PrintEndPage' using the uninitialized extension 'XpExtension'. xprint.Init(connObj) must be called first.") 712 } 713 cookie := c.NewCookie(false, false) 714 c.NewRequest(printEndPageRequest(c, Cancel), cookie) 715 return PrintEndPageCookie{cookie} 716 } 717 718 // PrintEndPageChecked sends a checked request. 719 // If an error occurs, it can be retrieved using PrintEndPageCookie.Check() 720 func PrintEndPageChecked(c *xgb.Conn, Cancel bool) PrintEndPageCookie { 721 c.ExtLock.RLock() 722 defer c.ExtLock.RUnlock() 723 if _, ok := c.Extensions["XpExtension"]; !ok { 724 panic("Cannot issue request 'PrintEndPage' using the uninitialized extension 'XpExtension'. xprint.Init(connObj) must be called first.") 725 } 726 cookie := c.NewCookie(true, false) 727 c.NewRequest(printEndPageRequest(c, Cancel), cookie) 728 return PrintEndPageCookie{cookie} 729 } 730 731 // Check returns an error if one occurred for checked requests that are not expecting a reply. 732 // This cannot be called for requests expecting a reply, nor for unchecked requests. 733 func (cook PrintEndPageCookie) Check() error { 734 return cook.Cookie.Check() 735 } 736 737 // Write request to wire for PrintEndPage 738 // printEndPageRequest writes a PrintEndPage request to a byte slice. 739 func printEndPageRequest(c *xgb.Conn, Cancel bool) []byte { 740 size := 8 741 b := 0 742 buf := make([]byte, size) 743 744 c.ExtLock.RLock() 745 buf[b] = c.Extensions["XpExtension"] 746 c.ExtLock.RUnlock() 747 b += 1 748 749 buf[b] = 14 // request opcode 750 b += 1 751 752 xgb.Put16(buf[b:], uint16(size/4)) // write request size in 4-byte units 753 b += 2 754 755 if Cancel { 756 buf[b] = 1 757 } else { 758 buf[b] = 0 759 } 760 b += 1 761 762 b += 3 // padding 763 764 return buf 765 } 766 767 // PrintGetAttributesCookie is a cookie used only for PrintGetAttributes requests. 768 type PrintGetAttributesCookie struct { 769 *xgb.Cookie 770 } 771 772 // PrintGetAttributes sends a checked request. 773 // If an error occurs, it will be returned with the reply by calling PrintGetAttributesCookie.Reply() 774 func PrintGetAttributes(c *xgb.Conn, Context Pcontext, Pool byte) PrintGetAttributesCookie { 775 c.ExtLock.RLock() 776 defer c.ExtLock.RUnlock() 777 if _, ok := c.Extensions["XpExtension"]; !ok { 778 panic("Cannot issue request 'PrintGetAttributes' using the uninitialized extension 'XpExtension'. xprint.Init(connObj) must be called first.") 779 } 780 cookie := c.NewCookie(true, true) 781 c.NewRequest(printGetAttributesRequest(c, Context, Pool), cookie) 782 return PrintGetAttributesCookie{cookie} 783 } 784 785 // PrintGetAttributesUnchecked sends an unchecked request. 786 // If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. 787 func PrintGetAttributesUnchecked(c *xgb.Conn, Context Pcontext, Pool byte) PrintGetAttributesCookie { 788 c.ExtLock.RLock() 789 defer c.ExtLock.RUnlock() 790 if _, ok := c.Extensions["XpExtension"]; !ok { 791 panic("Cannot issue request 'PrintGetAttributes' using the uninitialized extension 'XpExtension'. xprint.Init(connObj) must be called first.") 792 } 793 cookie := c.NewCookie(false, true) 794 c.NewRequest(printGetAttributesRequest(c, Context, Pool), cookie) 795 return PrintGetAttributesCookie{cookie} 796 } 797 798 // PrintGetAttributesReply represents the data returned from a PrintGetAttributes request. 799 type PrintGetAttributesReply struct { 800 Sequence uint16 // sequence number of the request for this reply 801 Length uint32 // number of bytes in this reply 802 // padding: 1 bytes 803 StringLen uint32 804 // padding: 20 bytes 805 Attributes []String8 // size: xgb.Pad((int(StringLen) * 1)) 806 } 807 808 // Reply blocks and returns the reply data for a PrintGetAttributes request. 809 func (cook PrintGetAttributesCookie) Reply() (*PrintGetAttributesReply, error) { 810 buf, err := cook.Cookie.Reply() 811 if err != nil { 812 return nil, err 813 } 814 if buf == nil { 815 return nil, nil 816 } 817 return printGetAttributesReply(buf), nil 818 } 819 820 // printGetAttributesReply reads a byte slice into a PrintGetAttributesReply value. 821 func printGetAttributesReply(buf []byte) *PrintGetAttributesReply { 822 v := new(PrintGetAttributesReply) 823 b := 1 // skip reply determinant 824 825 b += 1 // padding 826 827 v.Sequence = xgb.Get16(buf[b:]) 828 b += 2 829 830 v.Length = xgb.Get32(buf[b:]) // 4-byte units 831 b += 4 832 833 v.StringLen = xgb.Get32(buf[b:]) 834 b += 4 835 836 b += 20 // padding 837 838 v.Attributes = make([]String8, v.StringLen) 839 for i := 0; i < int(v.StringLen); i++ { 840 v.Attributes[i] = String8(buf[b]) 841 b += 1 842 } 843 844 return v 845 } 846 847 // Write request to wire for PrintGetAttributes 848 // printGetAttributesRequest writes a PrintGetAttributes request to a byte slice. 849 func printGetAttributesRequest(c *xgb.Conn, Context Pcontext, Pool byte) []byte { 850 size := 12 851 b := 0 852 buf := make([]byte, size) 853 854 c.ExtLock.RLock() 855 buf[b] = c.Extensions["XpExtension"] 856 c.ExtLock.RUnlock() 857 b += 1 858 859 buf[b] = 17 // request opcode 860 b += 1 861 862 xgb.Put16(buf[b:], uint16(size/4)) // write request size in 4-byte units 863 b += 2 864 865 xgb.Put32(buf[b:], uint32(Context)) 866 b += 4 867 868 buf[b] = Pool 869 b += 1 870 871 b += 3 // padding 872 873 return buf 874 } 875 876 // PrintGetContextCookie is a cookie used only for PrintGetContext requests. 877 type PrintGetContextCookie struct { 878 *xgb.Cookie 879 } 880 881 // PrintGetContext sends a checked request. 882 // If an error occurs, it will be returned with the reply by calling PrintGetContextCookie.Reply() 883 func PrintGetContext(c *xgb.Conn) PrintGetContextCookie { 884 c.ExtLock.RLock() 885 defer c.ExtLock.RUnlock() 886 if _, ok := c.Extensions["XpExtension"]; !ok { 887 panic("Cannot issue request 'PrintGetContext' using the uninitialized extension 'XpExtension'. xprint.Init(connObj) must be called first.") 888 } 889 cookie := c.NewCookie(true, true) 890 c.NewRequest(printGetContextRequest(c), cookie) 891 return PrintGetContextCookie{cookie} 892 } 893 894 // PrintGetContextUnchecked sends an unchecked request. 895 // If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. 896 func PrintGetContextUnchecked(c *xgb.Conn) PrintGetContextCookie { 897 c.ExtLock.RLock() 898 defer c.ExtLock.RUnlock() 899 if _, ok := c.Extensions["XpExtension"]; !ok { 900 panic("Cannot issue request 'PrintGetContext' using the uninitialized extension 'XpExtension'. xprint.Init(connObj) must be called first.") 901 } 902 cookie := c.NewCookie(false, true) 903 c.NewRequest(printGetContextRequest(c), cookie) 904 return PrintGetContextCookie{cookie} 905 } 906 907 // PrintGetContextReply represents the data returned from a PrintGetContext request. 908 type PrintGetContextReply struct { 909 Sequence uint16 // sequence number of the request for this reply 910 Length uint32 // number of bytes in this reply 911 // padding: 1 bytes 912 Context uint32 913 } 914 915 // Reply blocks and returns the reply data for a PrintGetContext request. 916 func (cook PrintGetContextCookie) Reply() (*PrintGetContextReply, error) { 917 buf, err := cook.Cookie.Reply() 918 if err != nil { 919 return nil, err 920 } 921 if buf == nil { 922 return nil, nil 923 } 924 return printGetContextReply(buf), nil 925 } 926 927 // printGetContextReply reads a byte slice into a PrintGetContextReply value. 928 func printGetContextReply(buf []byte) *PrintGetContextReply { 929 v := new(PrintGetContextReply) 930 b := 1 // skip reply determinant 931 932 b += 1 // padding 933 934 v.Sequence = xgb.Get16(buf[b:]) 935 b += 2 936 937 v.Length = xgb.Get32(buf[b:]) // 4-byte units 938 b += 4 939 940 v.Context = xgb.Get32(buf[b:]) 941 b += 4 942 943 return v 944 } 945 946 // Write request to wire for PrintGetContext 947 // printGetContextRequest writes a PrintGetContext request to a byte slice. 948 func printGetContextRequest(c *xgb.Conn) []byte { 949 size := 4 950 b := 0 951 buf := make([]byte, size) 952 953 c.ExtLock.RLock() 954 buf[b] = c.Extensions["XpExtension"] 955 c.ExtLock.RUnlock() 956 b += 1 957 958 buf[b] = 4 // request opcode 959 b += 1 960 961 xgb.Put16(buf[b:], uint16(size/4)) // write request size in 4-byte units 962 b += 2 963 964 return buf 965 } 966 967 // PrintGetDocumentDataCookie is a cookie used only for PrintGetDocumentData requests. 968 type PrintGetDocumentDataCookie struct { 969 *xgb.Cookie 970 } 971 972 // PrintGetDocumentData sends a checked request. 973 // If an error occurs, it will be returned with the reply by calling PrintGetDocumentDataCookie.Reply() 974 func PrintGetDocumentData(c *xgb.Conn, Context Pcontext, MaxBytes uint32) PrintGetDocumentDataCookie { 975 c.ExtLock.RLock() 976 defer c.ExtLock.RUnlock() 977 if _, ok := c.Extensions["XpExtension"]; !ok { 978 panic("Cannot issue request 'PrintGetDocumentData' using the uninitialized extension 'XpExtension'. xprint.Init(connObj) must be called first.") 979 } 980 cookie := c.NewCookie(true, true) 981 c.NewRequest(printGetDocumentDataRequest(c, Context, MaxBytes), cookie) 982 return PrintGetDocumentDataCookie{cookie} 983 } 984 985 // PrintGetDocumentDataUnchecked sends an unchecked request. 986 // If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. 987 func PrintGetDocumentDataUnchecked(c *xgb.Conn, Context Pcontext, MaxBytes uint32) PrintGetDocumentDataCookie { 988 c.ExtLock.RLock() 989 defer c.ExtLock.RUnlock() 990 if _, ok := c.Extensions["XpExtension"]; !ok { 991 panic("Cannot issue request 'PrintGetDocumentData' using the uninitialized extension 'XpExtension'. xprint.Init(connObj) must be called first.") 992 } 993 cookie := c.NewCookie(false, true) 994 c.NewRequest(printGetDocumentDataRequest(c, Context, MaxBytes), cookie) 995 return PrintGetDocumentDataCookie{cookie} 996 } 997 998 // PrintGetDocumentDataReply represents the data returned from a PrintGetDocumentData request. 999 type PrintGetDocumentDataReply struct { 1000 Sequence uint16 // sequence number of the request for this reply 1001 Length uint32 // number of bytes in this reply 1002 // padding: 1 bytes 1003 StatusCode uint32 1004 FinishedFlag uint32 1005 DataLen uint32 1006 // padding: 12 bytes 1007 Data []byte // size: xgb.Pad((int(DataLen) * 1)) 1008 } 1009 1010 // Reply blocks and returns the reply data for a PrintGetDocumentData request. 1011 func (cook PrintGetDocumentDataCookie) Reply() (*PrintGetDocumentDataReply, error) { 1012 buf, err := cook.Cookie.Reply() 1013 if err != nil { 1014 return nil, err 1015 } 1016 if buf == nil { 1017 return nil, nil 1018 } 1019 return printGetDocumentDataReply(buf), nil 1020 } 1021 1022 // printGetDocumentDataReply reads a byte slice into a PrintGetDocumentDataReply value. 1023 func printGetDocumentDataReply(buf []byte) *PrintGetDocumentDataReply { 1024 v := new(PrintGetDocumentDataReply) 1025 b := 1 // skip reply determinant 1026 1027 b += 1 // padding 1028 1029 v.Sequence = xgb.Get16(buf[b:]) 1030 b += 2 1031 1032 v.Length = xgb.Get32(buf[b:]) // 4-byte units 1033 b += 4 1034 1035 v.StatusCode = xgb.Get32(buf[b:]) 1036 b += 4 1037 1038 v.FinishedFlag = xgb.Get32(buf[b:]) 1039 b += 4 1040 1041 v.DataLen = xgb.Get32(buf[b:]) 1042 b += 4 1043 1044 b += 12 // padding 1045 1046 v.Data = make([]byte, v.DataLen) 1047 copy(v.Data[:v.DataLen], buf[b:]) 1048 b += int(v.DataLen) 1049 1050 return v 1051 } 1052 1053 // Write request to wire for PrintGetDocumentData 1054 // printGetDocumentDataRequest writes a PrintGetDocumentData request to a byte slice. 1055 func printGetDocumentDataRequest(c *xgb.Conn, Context Pcontext, MaxBytes uint32) []byte { 1056 size := 12 1057 b := 0 1058 buf := make([]byte, size) 1059 1060 c.ExtLock.RLock() 1061 buf[b] = c.Extensions["XpExtension"] 1062 c.ExtLock.RUnlock() 1063 b += 1 1064 1065 buf[b] = 12 // request opcode 1066 b += 1 1067 1068 xgb.Put16(buf[b:], uint16(size/4)) // write request size in 4-byte units 1069 b += 2 1070 1071 xgb.Put32(buf[b:], uint32(Context)) 1072 b += 4 1073 1074 xgb.Put32(buf[b:], MaxBytes) 1075 b += 4 1076 1077 return buf 1078 } 1079 1080 // PrintGetImageResolutionCookie is a cookie used only for PrintGetImageResolution requests. 1081 type PrintGetImageResolutionCookie struct { 1082 *xgb.Cookie 1083 } 1084 1085 // PrintGetImageResolution sends a checked request. 1086 // If an error occurs, it will be returned with the reply by calling PrintGetImageResolutionCookie.Reply() 1087 func PrintGetImageResolution(c *xgb.Conn, Context Pcontext) PrintGetImageResolutionCookie { 1088 c.ExtLock.RLock() 1089 defer c.ExtLock.RUnlock() 1090 if _, ok := c.Extensions["XpExtension"]; !ok { 1091 panic("Cannot issue request 'PrintGetImageResolution' using the uninitialized extension 'XpExtension'. xprint.Init(connObj) must be called first.") 1092 } 1093 cookie := c.NewCookie(true, true) 1094 c.NewRequest(printGetImageResolutionRequest(c, Context), cookie) 1095 return PrintGetImageResolutionCookie{cookie} 1096 } 1097 1098 // PrintGetImageResolutionUnchecked sends an unchecked request. 1099 // If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. 1100 func PrintGetImageResolutionUnchecked(c *xgb.Conn, Context Pcontext) PrintGetImageResolutionCookie { 1101 c.ExtLock.RLock() 1102 defer c.ExtLock.RUnlock() 1103 if _, ok := c.Extensions["XpExtension"]; !ok { 1104 panic("Cannot issue request 'PrintGetImageResolution' using the uninitialized extension 'XpExtension'. xprint.Init(connObj) must be called first.") 1105 } 1106 cookie := c.NewCookie(false, true) 1107 c.NewRequest(printGetImageResolutionRequest(c, Context), cookie) 1108 return PrintGetImageResolutionCookie{cookie} 1109 } 1110 1111 // PrintGetImageResolutionReply represents the data returned from a PrintGetImageResolution request. 1112 type PrintGetImageResolutionReply struct { 1113 Sequence uint16 // sequence number of the request for this reply 1114 Length uint32 // number of bytes in this reply 1115 // padding: 1 bytes 1116 ImageResolution uint16 1117 } 1118 1119 // Reply blocks and returns the reply data for a PrintGetImageResolution request. 1120 func (cook PrintGetImageResolutionCookie) Reply() (*PrintGetImageResolutionReply, error) { 1121 buf, err := cook.Cookie.Reply() 1122 if err != nil { 1123 return nil, err 1124 } 1125 if buf == nil { 1126 return nil, nil 1127 } 1128 return printGetImageResolutionReply(buf), nil 1129 } 1130 1131 // printGetImageResolutionReply reads a byte slice into a PrintGetImageResolutionReply value. 1132 func printGetImageResolutionReply(buf []byte) *PrintGetImageResolutionReply { 1133 v := new(PrintGetImageResolutionReply) 1134 b := 1 // skip reply determinant 1135 1136 b += 1 // padding 1137 1138 v.Sequence = xgb.Get16(buf[b:]) 1139 b += 2 1140 1141 v.Length = xgb.Get32(buf[b:]) // 4-byte units 1142 b += 4 1143 1144 v.ImageResolution = xgb.Get16(buf[b:]) 1145 b += 2 1146 1147 return v 1148 } 1149 1150 // Write request to wire for PrintGetImageResolution 1151 // printGetImageResolutionRequest writes a PrintGetImageResolution request to a byte slice. 1152 func printGetImageResolutionRequest(c *xgb.Conn, Context Pcontext) []byte { 1153 size := 8 1154 b := 0 1155 buf := make([]byte, size) 1156 1157 c.ExtLock.RLock() 1158 buf[b] = c.Extensions["XpExtension"] 1159 c.ExtLock.RUnlock() 1160 b += 1 1161 1162 buf[b] = 24 // request opcode 1163 b += 1 1164 1165 xgb.Put16(buf[b:], uint16(size/4)) // write request size in 4-byte units 1166 b += 2 1167 1168 xgb.Put32(buf[b:], uint32(Context)) 1169 b += 4 1170 1171 return buf 1172 } 1173 1174 // PrintGetOneAttributesCookie is a cookie used only for PrintGetOneAttributes requests. 1175 type PrintGetOneAttributesCookie struct { 1176 *xgb.Cookie 1177 } 1178 1179 // PrintGetOneAttributes sends a checked request. 1180 // If an error occurs, it will be returned with the reply by calling PrintGetOneAttributesCookie.Reply() 1181 func PrintGetOneAttributes(c *xgb.Conn, Context Pcontext, NameLen uint32, Pool byte, Name []String8) PrintGetOneAttributesCookie { 1182 c.ExtLock.RLock() 1183 defer c.ExtLock.RUnlock() 1184 if _, ok := c.Extensions["XpExtension"]; !ok { 1185 panic("Cannot issue request 'PrintGetOneAttributes' using the uninitialized extension 'XpExtension'. xprint.Init(connObj) must be called first.") 1186 } 1187 cookie := c.NewCookie(true, true) 1188 c.NewRequest(printGetOneAttributesRequest(c, Context, NameLen, Pool, Name), cookie) 1189 return PrintGetOneAttributesCookie{cookie} 1190 } 1191 1192 // PrintGetOneAttributesUnchecked sends an unchecked request. 1193 // If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. 1194 func PrintGetOneAttributesUnchecked(c *xgb.Conn, Context Pcontext, NameLen uint32, Pool byte, Name []String8) PrintGetOneAttributesCookie { 1195 c.ExtLock.RLock() 1196 defer c.ExtLock.RUnlock() 1197 if _, ok := c.Extensions["XpExtension"]; !ok { 1198 panic("Cannot issue request 'PrintGetOneAttributes' using the uninitialized extension 'XpExtension'. xprint.Init(connObj) must be called first.") 1199 } 1200 cookie := c.NewCookie(false, true) 1201 c.NewRequest(printGetOneAttributesRequest(c, Context, NameLen, Pool, Name), cookie) 1202 return PrintGetOneAttributesCookie{cookie} 1203 } 1204 1205 // PrintGetOneAttributesReply represents the data returned from a PrintGetOneAttributes request. 1206 type PrintGetOneAttributesReply struct { 1207 Sequence uint16 // sequence number of the request for this reply 1208 Length uint32 // number of bytes in this reply 1209 // padding: 1 bytes 1210 ValueLen uint32 1211 // padding: 20 bytes 1212 Value []String8 // size: xgb.Pad((int(ValueLen) * 1)) 1213 } 1214 1215 // Reply blocks and returns the reply data for a PrintGetOneAttributes request. 1216 func (cook PrintGetOneAttributesCookie) Reply() (*PrintGetOneAttributesReply, error) { 1217 buf, err := cook.Cookie.Reply() 1218 if err != nil { 1219 return nil, err 1220 } 1221 if buf == nil { 1222 return nil, nil 1223 } 1224 return printGetOneAttributesReply(buf), nil 1225 } 1226 1227 // printGetOneAttributesReply reads a byte slice into a PrintGetOneAttributesReply value. 1228 func printGetOneAttributesReply(buf []byte) *PrintGetOneAttributesReply { 1229 v := new(PrintGetOneAttributesReply) 1230 b := 1 // skip reply determinant 1231 1232 b += 1 // padding 1233 1234 v.Sequence = xgb.Get16(buf[b:]) 1235 b += 2 1236 1237 v.Length = xgb.Get32(buf[b:]) // 4-byte units 1238 b += 4 1239 1240 v.ValueLen = xgb.Get32(buf[b:]) 1241 b += 4 1242 1243 b += 20 // padding 1244 1245 v.Value = make([]String8, v.ValueLen) 1246 for i := 0; i < int(v.ValueLen); i++ { 1247 v.Value[i] = String8(buf[b]) 1248 b += 1 1249 } 1250 1251 return v 1252 } 1253 1254 // Write request to wire for PrintGetOneAttributes 1255 // printGetOneAttributesRequest writes a PrintGetOneAttributes request to a byte slice. 1256 func printGetOneAttributesRequest(c *xgb.Conn, Context Pcontext, NameLen uint32, Pool byte, Name []String8) []byte { 1257 size := xgb.Pad((16 + xgb.Pad((int(NameLen) * 1)))) 1258 b := 0 1259 buf := make([]byte, size) 1260 1261 c.ExtLock.RLock() 1262 buf[b] = c.Extensions["XpExtension"] 1263 c.ExtLock.RUnlock() 1264 b += 1 1265 1266 buf[b] = 19 // request opcode 1267 b += 1 1268 1269 xgb.Put16(buf[b:], uint16(size/4)) // write request size in 4-byte units 1270 b += 2 1271 1272 xgb.Put32(buf[b:], uint32(Context)) 1273 b += 4 1274 1275 xgb.Put32(buf[b:], NameLen) 1276 b += 4 1277 1278 buf[b] = Pool 1279 b += 1 1280 1281 b += 3 // padding 1282 1283 for i := 0; i < int(NameLen); i++ { 1284 buf[b] = byte(Name[i]) 1285 b += 1 1286 } 1287 1288 return buf 1289 } 1290 1291 // PrintGetPageDimensionsCookie is a cookie used only for PrintGetPageDimensions requests. 1292 type PrintGetPageDimensionsCookie struct { 1293 *xgb.Cookie 1294 } 1295 1296 // PrintGetPageDimensions sends a checked request. 1297 // If an error occurs, it will be returned with the reply by calling PrintGetPageDimensionsCookie.Reply() 1298 func PrintGetPageDimensions(c *xgb.Conn, Context Pcontext) PrintGetPageDimensionsCookie { 1299 c.ExtLock.RLock() 1300 defer c.ExtLock.RUnlock() 1301 if _, ok := c.Extensions["XpExtension"]; !ok { 1302 panic("Cannot issue request 'PrintGetPageDimensions' using the uninitialized extension 'XpExtension'. xprint.Init(connObj) must be called first.") 1303 } 1304 cookie := c.NewCookie(true, true) 1305 c.NewRequest(printGetPageDimensionsRequest(c, Context), cookie) 1306 return PrintGetPageDimensionsCookie{cookie} 1307 } 1308 1309 // PrintGetPageDimensionsUnchecked sends an unchecked request. 1310 // If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. 1311 func PrintGetPageDimensionsUnchecked(c *xgb.Conn, Context Pcontext) PrintGetPageDimensionsCookie { 1312 c.ExtLock.RLock() 1313 defer c.ExtLock.RUnlock() 1314 if _, ok := c.Extensions["XpExtension"]; !ok { 1315 panic("Cannot issue request 'PrintGetPageDimensions' using the uninitialized extension 'XpExtension'. xprint.Init(connObj) must be called first.") 1316 } 1317 cookie := c.NewCookie(false, true) 1318 c.NewRequest(printGetPageDimensionsRequest(c, Context), cookie) 1319 return PrintGetPageDimensionsCookie{cookie} 1320 } 1321 1322 // PrintGetPageDimensionsReply represents the data returned from a PrintGetPageDimensions request. 1323 type PrintGetPageDimensionsReply struct { 1324 Sequence uint16 // sequence number of the request for this reply 1325 Length uint32 // number of bytes in this reply 1326 // padding: 1 bytes 1327 Width uint16 1328 Height uint16 1329 OffsetX uint16 1330 OffsetY uint16 1331 ReproducibleWidth uint16 1332 ReproducibleHeight uint16 1333 } 1334 1335 // Reply blocks and returns the reply data for a PrintGetPageDimensions request. 1336 func (cook PrintGetPageDimensionsCookie) Reply() (*PrintGetPageDimensionsReply, error) { 1337 buf, err := cook.Cookie.Reply() 1338 if err != nil { 1339 return nil, err 1340 } 1341 if buf == nil { 1342 return nil, nil 1343 } 1344 return printGetPageDimensionsReply(buf), nil 1345 } 1346 1347 // printGetPageDimensionsReply reads a byte slice into a PrintGetPageDimensionsReply value. 1348 func printGetPageDimensionsReply(buf []byte) *PrintGetPageDimensionsReply { 1349 v := new(PrintGetPageDimensionsReply) 1350 b := 1 // skip reply determinant 1351 1352 b += 1 // padding 1353 1354 v.Sequence = xgb.Get16(buf[b:]) 1355 b += 2 1356 1357 v.Length = xgb.Get32(buf[b:]) // 4-byte units 1358 b += 4 1359 1360 v.Width = xgb.Get16(buf[b:]) 1361 b += 2 1362 1363 v.Height = xgb.Get16(buf[b:]) 1364 b += 2 1365 1366 v.OffsetX = xgb.Get16(buf[b:]) 1367 b += 2 1368 1369 v.OffsetY = xgb.Get16(buf[b:]) 1370 b += 2 1371 1372 v.ReproducibleWidth = xgb.Get16(buf[b:]) 1373 b += 2 1374 1375 v.ReproducibleHeight = xgb.Get16(buf[b:]) 1376 b += 2 1377 1378 return v 1379 } 1380 1381 // Write request to wire for PrintGetPageDimensions 1382 // printGetPageDimensionsRequest writes a PrintGetPageDimensions request to a byte slice. 1383 func printGetPageDimensionsRequest(c *xgb.Conn, Context Pcontext) []byte { 1384 size := 8 1385 b := 0 1386 buf := make([]byte, size) 1387 1388 c.ExtLock.RLock() 1389 buf[b] = c.Extensions["XpExtension"] 1390 c.ExtLock.RUnlock() 1391 b += 1 1392 1393 buf[b] = 21 // request opcode 1394 b += 1 1395 1396 xgb.Put16(buf[b:], uint16(size/4)) // write request size in 4-byte units 1397 b += 2 1398 1399 xgb.Put32(buf[b:], uint32(Context)) 1400 b += 4 1401 1402 return buf 1403 } 1404 1405 // PrintGetPrinterListCookie is a cookie used only for PrintGetPrinterList requests. 1406 type PrintGetPrinterListCookie struct { 1407 *xgb.Cookie 1408 } 1409 1410 // PrintGetPrinterList sends a checked request. 1411 // If an error occurs, it will be returned with the reply by calling PrintGetPrinterListCookie.Reply() 1412 func PrintGetPrinterList(c *xgb.Conn, PrinterNameLen uint32, LocaleLen uint32, PrinterName []String8, Locale []String8) PrintGetPrinterListCookie { 1413 c.ExtLock.RLock() 1414 defer c.ExtLock.RUnlock() 1415 if _, ok := c.Extensions["XpExtension"]; !ok { 1416 panic("Cannot issue request 'PrintGetPrinterList' using the uninitialized extension 'XpExtension'. xprint.Init(connObj) must be called first.") 1417 } 1418 cookie := c.NewCookie(true, true) 1419 c.NewRequest(printGetPrinterListRequest(c, PrinterNameLen, LocaleLen, PrinterName, Locale), cookie) 1420 return PrintGetPrinterListCookie{cookie} 1421 } 1422 1423 // PrintGetPrinterListUnchecked sends an unchecked request. 1424 // If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. 1425 func PrintGetPrinterListUnchecked(c *xgb.Conn, PrinterNameLen uint32, LocaleLen uint32, PrinterName []String8, Locale []String8) PrintGetPrinterListCookie { 1426 c.ExtLock.RLock() 1427 defer c.ExtLock.RUnlock() 1428 if _, ok := c.Extensions["XpExtension"]; !ok { 1429 panic("Cannot issue request 'PrintGetPrinterList' using the uninitialized extension 'XpExtension'. xprint.Init(connObj) must be called first.") 1430 } 1431 cookie := c.NewCookie(false, true) 1432 c.NewRequest(printGetPrinterListRequest(c, PrinterNameLen, LocaleLen, PrinterName, Locale), cookie) 1433 return PrintGetPrinterListCookie{cookie} 1434 } 1435 1436 // PrintGetPrinterListReply represents the data returned from a PrintGetPrinterList request. 1437 type PrintGetPrinterListReply struct { 1438 Sequence uint16 // sequence number of the request for this reply 1439 Length uint32 // number of bytes in this reply 1440 // padding: 1 bytes 1441 ListCount uint32 1442 // padding: 20 bytes 1443 Printers []Printer // size: PrinterListSize(Printers) 1444 } 1445 1446 // Reply blocks and returns the reply data for a PrintGetPrinterList request. 1447 func (cook PrintGetPrinterListCookie) Reply() (*PrintGetPrinterListReply, error) { 1448 buf, err := cook.Cookie.Reply() 1449 if err != nil { 1450 return nil, err 1451 } 1452 if buf == nil { 1453 return nil, nil 1454 } 1455 return printGetPrinterListReply(buf), nil 1456 } 1457 1458 // printGetPrinterListReply reads a byte slice into a PrintGetPrinterListReply value. 1459 func printGetPrinterListReply(buf []byte) *PrintGetPrinterListReply { 1460 v := new(PrintGetPrinterListReply) 1461 b := 1 // skip reply determinant 1462 1463 b += 1 // padding 1464 1465 v.Sequence = xgb.Get16(buf[b:]) 1466 b += 2 1467 1468 v.Length = xgb.Get32(buf[b:]) // 4-byte units 1469 b += 4 1470 1471 v.ListCount = xgb.Get32(buf[b:]) 1472 b += 4 1473 1474 b += 20 // padding 1475 1476 v.Printers = make([]Printer, v.ListCount) 1477 b += PrinterReadList(buf[b:], v.Printers) 1478 1479 return v 1480 } 1481 1482 // Write request to wire for PrintGetPrinterList 1483 // printGetPrinterListRequest writes a PrintGetPrinterList request to a byte slice. 1484 func printGetPrinterListRequest(c *xgb.Conn, PrinterNameLen uint32, LocaleLen uint32, PrinterName []String8, Locale []String8) []byte { 1485 size := xgb.Pad(((12 + xgb.Pad((int(PrinterNameLen) * 1))) + xgb.Pad((int(LocaleLen) * 1)))) 1486 b := 0 1487 buf := make([]byte, size) 1488 1489 c.ExtLock.RLock() 1490 buf[b] = c.Extensions["XpExtension"] 1491 c.ExtLock.RUnlock() 1492 b += 1 1493 1494 buf[b] = 1 // request opcode 1495 b += 1 1496 1497 xgb.Put16(buf[b:], uint16(size/4)) // write request size in 4-byte units 1498 b += 2 1499 1500 xgb.Put32(buf[b:], PrinterNameLen) 1501 b += 4 1502 1503 xgb.Put32(buf[b:], LocaleLen) 1504 b += 4 1505 1506 for i := 0; i < int(PrinterNameLen); i++ { 1507 buf[b] = byte(PrinterName[i]) 1508 b += 1 1509 } 1510 1511 for i := 0; i < int(LocaleLen); i++ { 1512 buf[b] = byte(Locale[i]) 1513 b += 1 1514 } 1515 1516 return buf 1517 } 1518 1519 // PrintGetScreenOfContextCookie is a cookie used only for PrintGetScreenOfContext requests. 1520 type PrintGetScreenOfContextCookie struct { 1521 *xgb.Cookie 1522 } 1523 1524 // PrintGetScreenOfContext sends a checked request. 1525 // If an error occurs, it will be returned with the reply by calling PrintGetScreenOfContextCookie.Reply() 1526 func PrintGetScreenOfContext(c *xgb.Conn) PrintGetScreenOfContextCookie { 1527 c.ExtLock.RLock() 1528 defer c.ExtLock.RUnlock() 1529 if _, ok := c.Extensions["XpExtension"]; !ok { 1530 panic("Cannot issue request 'PrintGetScreenOfContext' using the uninitialized extension 'XpExtension'. xprint.Init(connObj) must be called first.") 1531 } 1532 cookie := c.NewCookie(true, true) 1533 c.NewRequest(printGetScreenOfContextRequest(c), cookie) 1534 return PrintGetScreenOfContextCookie{cookie} 1535 } 1536 1537 // PrintGetScreenOfContextUnchecked sends an unchecked request. 1538 // If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. 1539 func PrintGetScreenOfContextUnchecked(c *xgb.Conn) PrintGetScreenOfContextCookie { 1540 c.ExtLock.RLock() 1541 defer c.ExtLock.RUnlock() 1542 if _, ok := c.Extensions["XpExtension"]; !ok { 1543 panic("Cannot issue request 'PrintGetScreenOfContext' using the uninitialized extension 'XpExtension'. xprint.Init(connObj) must be called first.") 1544 } 1545 cookie := c.NewCookie(false, true) 1546 c.NewRequest(printGetScreenOfContextRequest(c), cookie) 1547 return PrintGetScreenOfContextCookie{cookie} 1548 } 1549 1550 // PrintGetScreenOfContextReply represents the data returned from a PrintGetScreenOfContext request. 1551 type PrintGetScreenOfContextReply struct { 1552 Sequence uint16 // sequence number of the request for this reply 1553 Length uint32 // number of bytes in this reply 1554 // padding: 1 bytes 1555 Root xproto.Window 1556 } 1557 1558 // Reply blocks and returns the reply data for a PrintGetScreenOfContext request. 1559 func (cook PrintGetScreenOfContextCookie) Reply() (*PrintGetScreenOfContextReply, error) { 1560 buf, err := cook.Cookie.Reply() 1561 if err != nil { 1562 return nil, err 1563 } 1564 if buf == nil { 1565 return nil, nil 1566 } 1567 return printGetScreenOfContextReply(buf), nil 1568 } 1569 1570 // printGetScreenOfContextReply reads a byte slice into a PrintGetScreenOfContextReply value. 1571 func printGetScreenOfContextReply(buf []byte) *PrintGetScreenOfContextReply { 1572 v := new(PrintGetScreenOfContextReply) 1573 b := 1 // skip reply determinant 1574 1575 b += 1 // padding 1576 1577 v.Sequence = xgb.Get16(buf[b:]) 1578 b += 2 1579 1580 v.Length = xgb.Get32(buf[b:]) // 4-byte units 1581 b += 4 1582 1583 v.Root = xproto.Window(xgb.Get32(buf[b:])) 1584 b += 4 1585 1586 return v 1587 } 1588 1589 // Write request to wire for PrintGetScreenOfContext 1590 // printGetScreenOfContextRequest writes a PrintGetScreenOfContext request to a byte slice. 1591 func printGetScreenOfContextRequest(c *xgb.Conn) []byte { 1592 size := 4 1593 b := 0 1594 buf := make([]byte, size) 1595 1596 c.ExtLock.RLock() 1597 buf[b] = c.Extensions["XpExtension"] 1598 c.ExtLock.RUnlock() 1599 b += 1 1600 1601 buf[b] = 6 // request opcode 1602 b += 1 1603 1604 xgb.Put16(buf[b:], uint16(size/4)) // write request size in 4-byte units 1605 b += 2 1606 1607 return buf 1608 } 1609 1610 // PrintInputSelectedCookie is a cookie used only for PrintInputSelected requests. 1611 type PrintInputSelectedCookie struct { 1612 *xgb.Cookie 1613 } 1614 1615 // PrintInputSelected sends a checked request. 1616 // If an error occurs, it will be returned with the reply by calling PrintInputSelectedCookie.Reply() 1617 func PrintInputSelected(c *xgb.Conn, Context Pcontext) PrintInputSelectedCookie { 1618 c.ExtLock.RLock() 1619 defer c.ExtLock.RUnlock() 1620 if _, ok := c.Extensions["XpExtension"]; !ok { 1621 panic("Cannot issue request 'PrintInputSelected' using the uninitialized extension 'XpExtension'. xprint.Init(connObj) must be called first.") 1622 } 1623 cookie := c.NewCookie(true, true) 1624 c.NewRequest(printInputSelectedRequest(c, Context), cookie) 1625 return PrintInputSelectedCookie{cookie} 1626 } 1627 1628 // PrintInputSelectedUnchecked sends an unchecked request. 1629 // If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. 1630 func PrintInputSelectedUnchecked(c *xgb.Conn, Context Pcontext) PrintInputSelectedCookie { 1631 c.ExtLock.RLock() 1632 defer c.ExtLock.RUnlock() 1633 if _, ok := c.Extensions["XpExtension"]; !ok { 1634 panic("Cannot issue request 'PrintInputSelected' using the uninitialized extension 'XpExtension'. xprint.Init(connObj) must be called first.") 1635 } 1636 cookie := c.NewCookie(false, true) 1637 c.NewRequest(printInputSelectedRequest(c, Context), cookie) 1638 return PrintInputSelectedCookie{cookie} 1639 } 1640 1641 // PrintInputSelectedReply represents the data returned from a PrintInputSelected request. 1642 type PrintInputSelectedReply struct { 1643 Sequence uint16 // sequence number of the request for this reply 1644 Length uint32 // number of bytes in this reply 1645 // padding: 1 bytes 1646 EventMask uint32 1647 EventList []uint32 1648 AllEventsMask uint32 1649 AllEventsList []uint32 1650 } 1651 1652 // Reply blocks and returns the reply data for a PrintInputSelected request. 1653 func (cook PrintInputSelectedCookie) Reply() (*PrintInputSelectedReply, error) { 1654 buf, err := cook.Cookie.Reply() 1655 if err != nil { 1656 return nil, err 1657 } 1658 if buf == nil { 1659 return nil, nil 1660 } 1661 return printInputSelectedReply(buf), nil 1662 } 1663 1664 // printInputSelectedReply reads a byte slice into a PrintInputSelectedReply value. 1665 func printInputSelectedReply(buf []byte) *PrintInputSelectedReply { 1666 v := new(PrintInputSelectedReply) 1667 b := 1 // skip reply determinant 1668 1669 b += 1 // padding 1670 1671 v.Sequence = xgb.Get16(buf[b:]) 1672 b += 2 1673 1674 v.Length = xgb.Get32(buf[b:]) // 4-byte units 1675 b += 4 1676 1677 v.EventMask = xgb.Get32(buf[b:]) 1678 b += 4 1679 1680 v.EventList = make([]uint32, xgb.PopCount(int(v.EventMask))) 1681 for i := 0; i < xgb.PopCount(int(v.EventMask)); i++ { 1682 v.EventList[i] = xgb.Get32(buf[b:]) 1683 b += 4 1684 } 1685 b = xgb.Pad(b) 1686 1687 v.AllEventsMask = xgb.Get32(buf[b:]) 1688 b += 4 1689 1690 v.AllEventsList = make([]uint32, xgb.PopCount(int(v.AllEventsMask))) 1691 for i := 0; i < xgb.PopCount(int(v.AllEventsMask)); i++ { 1692 v.AllEventsList[i] = xgb.Get32(buf[b:]) 1693 b += 4 1694 } 1695 b = xgb.Pad(b) 1696 1697 return v 1698 } 1699 1700 // Write request to wire for PrintInputSelected 1701 // printInputSelectedRequest writes a PrintInputSelected request to a byte slice. 1702 func printInputSelectedRequest(c *xgb.Conn, Context Pcontext) []byte { 1703 size := 8 1704 b := 0 1705 buf := make([]byte, size) 1706 1707 c.ExtLock.RLock() 1708 buf[b] = c.Extensions["XpExtension"] 1709 c.ExtLock.RUnlock() 1710 b += 1 1711 1712 buf[b] = 16 // request opcode 1713 b += 1 1714 1715 xgb.Put16(buf[b:], uint16(size/4)) // write request size in 4-byte units 1716 b += 2 1717 1718 xgb.Put32(buf[b:], uint32(Context)) 1719 b += 4 1720 1721 return buf 1722 } 1723 1724 // PrintPutDocumentDataCookie is a cookie used only for PrintPutDocumentData requests. 1725 type PrintPutDocumentDataCookie struct { 1726 *xgb.Cookie 1727 } 1728 1729 // PrintPutDocumentData sends an unchecked request. 1730 // If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. 1731 func PrintPutDocumentData(c *xgb.Conn, Drawable xproto.Drawable, LenData uint32, LenFmt uint16, LenOptions uint16, Data []byte, DocFormat []String8, Options []String8) PrintPutDocumentDataCookie { 1732 c.ExtLock.RLock() 1733 defer c.ExtLock.RUnlock() 1734 if _, ok := c.Extensions["XpExtension"]; !ok { 1735 panic("Cannot issue request 'PrintPutDocumentData' using the uninitialized extension 'XpExtension'. xprint.Init(connObj) must be called first.") 1736 } 1737 cookie := c.NewCookie(false, false) 1738 c.NewRequest(printPutDocumentDataRequest(c, Drawable, LenData, LenFmt, LenOptions, Data, DocFormat, Options), cookie) 1739 return PrintPutDocumentDataCookie{cookie} 1740 } 1741 1742 // PrintPutDocumentDataChecked sends a checked request. 1743 // If an error occurs, it can be retrieved using PrintPutDocumentDataCookie.Check() 1744 func PrintPutDocumentDataChecked(c *xgb.Conn, Drawable xproto.Drawable, LenData uint32, LenFmt uint16, LenOptions uint16, Data []byte, DocFormat []String8, Options []String8) PrintPutDocumentDataCookie { 1745 c.ExtLock.RLock() 1746 defer c.ExtLock.RUnlock() 1747 if _, ok := c.Extensions["XpExtension"]; !ok { 1748 panic("Cannot issue request 'PrintPutDocumentData' using the uninitialized extension 'XpExtension'. xprint.Init(connObj) must be called first.") 1749 } 1750 cookie := c.NewCookie(true, false) 1751 c.NewRequest(printPutDocumentDataRequest(c, Drawable, LenData, LenFmt, LenOptions, Data, DocFormat, Options), cookie) 1752 return PrintPutDocumentDataCookie{cookie} 1753 } 1754 1755 // Check returns an error if one occurred for checked requests that are not expecting a reply. 1756 // This cannot be called for requests expecting a reply, nor for unchecked requests. 1757 func (cook PrintPutDocumentDataCookie) Check() error { 1758 return cook.Cookie.Check() 1759 } 1760 1761 // Write request to wire for PrintPutDocumentData 1762 // printPutDocumentDataRequest writes a PrintPutDocumentData request to a byte slice. 1763 func printPutDocumentDataRequest(c *xgb.Conn, Drawable xproto.Drawable, LenData uint32, LenFmt uint16, LenOptions uint16, Data []byte, DocFormat []String8, Options []String8) []byte { 1764 size := xgb.Pad((((16 + xgb.Pad((int(LenData) * 1))) + xgb.Pad((len(DocFormat) * 1))) + xgb.Pad((len(Options) * 1)))) 1765 b := 0 1766 buf := make([]byte, size) 1767 1768 c.ExtLock.RLock() 1769 buf[b] = c.Extensions["XpExtension"] 1770 c.ExtLock.RUnlock() 1771 b += 1 1772 1773 buf[b] = 11 // request opcode 1774 b += 1 1775 1776 xgb.Put16(buf[b:], uint16(size/4)) // write request size in 4-byte units 1777 b += 2 1778 1779 xgb.Put32(buf[b:], uint32(Drawable)) 1780 b += 4 1781 1782 xgb.Put32(buf[b:], LenData) 1783 b += 4 1784 1785 xgb.Put16(buf[b:], LenFmt) 1786 b += 2 1787 1788 xgb.Put16(buf[b:], LenOptions) 1789 b += 2 1790 1791 copy(buf[b:], Data[:LenData]) 1792 b += int(LenData) 1793 1794 for i := 0; i < int(len(DocFormat)); i++ { 1795 buf[b] = byte(DocFormat[i]) 1796 b += 1 1797 } 1798 1799 for i := 0; i < int(len(Options)); i++ { 1800 buf[b] = byte(Options[i]) 1801 b += 1 1802 } 1803 1804 return buf 1805 } 1806 1807 // PrintQueryScreensCookie is a cookie used only for PrintQueryScreens requests. 1808 type PrintQueryScreensCookie struct { 1809 *xgb.Cookie 1810 } 1811 1812 // PrintQueryScreens sends a checked request. 1813 // If an error occurs, it will be returned with the reply by calling PrintQueryScreensCookie.Reply() 1814 func PrintQueryScreens(c *xgb.Conn) PrintQueryScreensCookie { 1815 c.ExtLock.RLock() 1816 defer c.ExtLock.RUnlock() 1817 if _, ok := c.Extensions["XpExtension"]; !ok { 1818 panic("Cannot issue request 'PrintQueryScreens' using the uninitialized extension 'XpExtension'. xprint.Init(connObj) must be called first.") 1819 } 1820 cookie := c.NewCookie(true, true) 1821 c.NewRequest(printQueryScreensRequest(c), cookie) 1822 return PrintQueryScreensCookie{cookie} 1823 } 1824 1825 // PrintQueryScreensUnchecked sends an unchecked request. 1826 // If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. 1827 func PrintQueryScreensUnchecked(c *xgb.Conn) PrintQueryScreensCookie { 1828 c.ExtLock.RLock() 1829 defer c.ExtLock.RUnlock() 1830 if _, ok := c.Extensions["XpExtension"]; !ok { 1831 panic("Cannot issue request 'PrintQueryScreens' using the uninitialized extension 'XpExtension'. xprint.Init(connObj) must be called first.") 1832 } 1833 cookie := c.NewCookie(false, true) 1834 c.NewRequest(printQueryScreensRequest(c), cookie) 1835 return PrintQueryScreensCookie{cookie} 1836 } 1837 1838 // PrintQueryScreensReply represents the data returned from a PrintQueryScreens request. 1839 type PrintQueryScreensReply struct { 1840 Sequence uint16 // sequence number of the request for this reply 1841 Length uint32 // number of bytes in this reply 1842 // padding: 1 bytes 1843 ListCount uint32 1844 // padding: 20 bytes 1845 Roots []xproto.Window // size: xgb.Pad((int(ListCount) * 4)) 1846 } 1847 1848 // Reply blocks and returns the reply data for a PrintQueryScreens request. 1849 func (cook PrintQueryScreensCookie) Reply() (*PrintQueryScreensReply, error) { 1850 buf, err := cook.Cookie.Reply() 1851 if err != nil { 1852 return nil, err 1853 } 1854 if buf == nil { 1855 return nil, nil 1856 } 1857 return printQueryScreensReply(buf), nil 1858 } 1859 1860 // printQueryScreensReply reads a byte slice into a PrintQueryScreensReply value. 1861 func printQueryScreensReply(buf []byte) *PrintQueryScreensReply { 1862 v := new(PrintQueryScreensReply) 1863 b := 1 // skip reply determinant 1864 1865 b += 1 // padding 1866 1867 v.Sequence = xgb.Get16(buf[b:]) 1868 b += 2 1869 1870 v.Length = xgb.Get32(buf[b:]) // 4-byte units 1871 b += 4 1872 1873 v.ListCount = xgb.Get32(buf[b:]) 1874 b += 4 1875 1876 b += 20 // padding 1877 1878 v.Roots = make([]xproto.Window, v.ListCount) 1879 for i := 0; i < int(v.ListCount); i++ { 1880 v.Roots[i] = xproto.Window(xgb.Get32(buf[b:])) 1881 b += 4 1882 } 1883 1884 return v 1885 } 1886 1887 // Write request to wire for PrintQueryScreens 1888 // printQueryScreensRequest writes a PrintQueryScreens request to a byte slice. 1889 func printQueryScreensRequest(c *xgb.Conn) []byte { 1890 size := 4 1891 b := 0 1892 buf := make([]byte, size) 1893 1894 c.ExtLock.RLock() 1895 buf[b] = c.Extensions["XpExtension"] 1896 c.ExtLock.RUnlock() 1897 b += 1 1898 1899 buf[b] = 22 // request opcode 1900 b += 1 1901 1902 xgb.Put16(buf[b:], uint16(size/4)) // write request size in 4-byte units 1903 b += 2 1904 1905 return buf 1906 } 1907 1908 // PrintQueryVersionCookie is a cookie used only for PrintQueryVersion requests. 1909 type PrintQueryVersionCookie struct { 1910 *xgb.Cookie 1911 } 1912 1913 // PrintQueryVersion sends a checked request. 1914 // If an error occurs, it will be returned with the reply by calling PrintQueryVersionCookie.Reply() 1915 func PrintQueryVersion(c *xgb.Conn) PrintQueryVersionCookie { 1916 c.ExtLock.RLock() 1917 defer c.ExtLock.RUnlock() 1918 if _, ok := c.Extensions["XpExtension"]; !ok { 1919 panic("Cannot issue request 'PrintQueryVersion' using the uninitialized extension 'XpExtension'. xprint.Init(connObj) must be called first.") 1920 } 1921 cookie := c.NewCookie(true, true) 1922 c.NewRequest(printQueryVersionRequest(c), cookie) 1923 return PrintQueryVersionCookie{cookie} 1924 } 1925 1926 // PrintQueryVersionUnchecked sends an unchecked request. 1927 // If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. 1928 func PrintQueryVersionUnchecked(c *xgb.Conn) PrintQueryVersionCookie { 1929 c.ExtLock.RLock() 1930 defer c.ExtLock.RUnlock() 1931 if _, ok := c.Extensions["XpExtension"]; !ok { 1932 panic("Cannot issue request 'PrintQueryVersion' using the uninitialized extension 'XpExtension'. xprint.Init(connObj) must be called first.") 1933 } 1934 cookie := c.NewCookie(false, true) 1935 c.NewRequest(printQueryVersionRequest(c), cookie) 1936 return PrintQueryVersionCookie{cookie} 1937 } 1938 1939 // PrintQueryVersionReply represents the data returned from a PrintQueryVersion request. 1940 type PrintQueryVersionReply struct { 1941 Sequence uint16 // sequence number of the request for this reply 1942 Length uint32 // number of bytes in this reply 1943 // padding: 1 bytes 1944 MajorVersion uint16 1945 MinorVersion uint16 1946 } 1947 1948 // Reply blocks and returns the reply data for a PrintQueryVersion request. 1949 func (cook PrintQueryVersionCookie) Reply() (*PrintQueryVersionReply, error) { 1950 buf, err := cook.Cookie.Reply() 1951 if err != nil { 1952 return nil, err 1953 } 1954 if buf == nil { 1955 return nil, nil 1956 } 1957 return printQueryVersionReply(buf), nil 1958 } 1959 1960 // printQueryVersionReply reads a byte slice into a PrintQueryVersionReply value. 1961 func printQueryVersionReply(buf []byte) *PrintQueryVersionReply { 1962 v := new(PrintQueryVersionReply) 1963 b := 1 // skip reply determinant 1964 1965 b += 1 // padding 1966 1967 v.Sequence = xgb.Get16(buf[b:]) 1968 b += 2 1969 1970 v.Length = xgb.Get32(buf[b:]) // 4-byte units 1971 b += 4 1972 1973 v.MajorVersion = xgb.Get16(buf[b:]) 1974 b += 2 1975 1976 v.MinorVersion = xgb.Get16(buf[b:]) 1977 b += 2 1978 1979 return v 1980 } 1981 1982 // Write request to wire for PrintQueryVersion 1983 // printQueryVersionRequest writes a PrintQueryVersion request to a byte slice. 1984 func printQueryVersionRequest(c *xgb.Conn) []byte { 1985 size := 4 1986 b := 0 1987 buf := make([]byte, size) 1988 1989 c.ExtLock.RLock() 1990 buf[b] = c.Extensions["XpExtension"] 1991 c.ExtLock.RUnlock() 1992 b += 1 1993 1994 buf[b] = 0 // request opcode 1995 b += 1 1996 1997 xgb.Put16(buf[b:], uint16(size/4)) // write request size in 4-byte units 1998 b += 2 1999 2000 return buf 2001 } 2002 2003 // PrintRehashPrinterListCookie is a cookie used only for PrintRehashPrinterList requests. 2004 type PrintRehashPrinterListCookie struct { 2005 *xgb.Cookie 2006 } 2007 2008 // PrintRehashPrinterList sends an unchecked request. 2009 // If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. 2010 func PrintRehashPrinterList(c *xgb.Conn) PrintRehashPrinterListCookie { 2011 c.ExtLock.RLock() 2012 defer c.ExtLock.RUnlock() 2013 if _, ok := c.Extensions["XpExtension"]; !ok { 2014 panic("Cannot issue request 'PrintRehashPrinterList' using the uninitialized extension 'XpExtension'. xprint.Init(connObj) must be called first.") 2015 } 2016 cookie := c.NewCookie(false, false) 2017 c.NewRequest(printRehashPrinterListRequest(c), cookie) 2018 return PrintRehashPrinterListCookie{cookie} 2019 } 2020 2021 // PrintRehashPrinterListChecked sends a checked request. 2022 // If an error occurs, it can be retrieved using PrintRehashPrinterListCookie.Check() 2023 func PrintRehashPrinterListChecked(c *xgb.Conn) PrintRehashPrinterListCookie { 2024 c.ExtLock.RLock() 2025 defer c.ExtLock.RUnlock() 2026 if _, ok := c.Extensions["XpExtension"]; !ok { 2027 panic("Cannot issue request 'PrintRehashPrinterList' using the uninitialized extension 'XpExtension'. xprint.Init(connObj) must be called first.") 2028 } 2029 cookie := c.NewCookie(true, false) 2030 c.NewRequest(printRehashPrinterListRequest(c), cookie) 2031 return PrintRehashPrinterListCookie{cookie} 2032 } 2033 2034 // Check returns an error if one occurred for checked requests that are not expecting a reply. 2035 // This cannot be called for requests expecting a reply, nor for unchecked requests. 2036 func (cook PrintRehashPrinterListCookie) Check() error { 2037 return cook.Cookie.Check() 2038 } 2039 2040 // Write request to wire for PrintRehashPrinterList 2041 // printRehashPrinterListRequest writes a PrintRehashPrinterList request to a byte slice. 2042 func printRehashPrinterListRequest(c *xgb.Conn) []byte { 2043 size := 4 2044 b := 0 2045 buf := make([]byte, size) 2046 2047 c.ExtLock.RLock() 2048 buf[b] = c.Extensions["XpExtension"] 2049 c.ExtLock.RUnlock() 2050 b += 1 2051 2052 buf[b] = 20 // request opcode 2053 b += 1 2054 2055 xgb.Put16(buf[b:], uint16(size/4)) // write request size in 4-byte units 2056 b += 2 2057 2058 return buf 2059 } 2060 2061 // PrintSelectInputCookie is a cookie used only for PrintSelectInput requests. 2062 type PrintSelectInputCookie struct { 2063 *xgb.Cookie 2064 } 2065 2066 // PrintSelectInput sends an unchecked request. 2067 // If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. 2068 func PrintSelectInput(c *xgb.Conn, Context Pcontext, EventMask uint32, EventList []uint32) PrintSelectInputCookie { 2069 c.ExtLock.RLock() 2070 defer c.ExtLock.RUnlock() 2071 if _, ok := c.Extensions["XpExtension"]; !ok { 2072 panic("Cannot issue request 'PrintSelectInput' using the uninitialized extension 'XpExtension'. xprint.Init(connObj) must be called first.") 2073 } 2074 cookie := c.NewCookie(false, false) 2075 c.NewRequest(printSelectInputRequest(c, Context, EventMask, EventList), cookie) 2076 return PrintSelectInputCookie{cookie} 2077 } 2078 2079 // PrintSelectInputChecked sends a checked request. 2080 // If an error occurs, it can be retrieved using PrintSelectInputCookie.Check() 2081 func PrintSelectInputChecked(c *xgb.Conn, Context Pcontext, EventMask uint32, EventList []uint32) PrintSelectInputCookie { 2082 c.ExtLock.RLock() 2083 defer c.ExtLock.RUnlock() 2084 if _, ok := c.Extensions["XpExtension"]; !ok { 2085 panic("Cannot issue request 'PrintSelectInput' using the uninitialized extension 'XpExtension'. xprint.Init(connObj) must be called first.") 2086 } 2087 cookie := c.NewCookie(true, false) 2088 c.NewRequest(printSelectInputRequest(c, Context, EventMask, EventList), cookie) 2089 return PrintSelectInputCookie{cookie} 2090 } 2091 2092 // Check returns an error if one occurred for checked requests that are not expecting a reply. 2093 // This cannot be called for requests expecting a reply, nor for unchecked requests. 2094 func (cook PrintSelectInputCookie) Check() error { 2095 return cook.Cookie.Check() 2096 } 2097 2098 // Write request to wire for PrintSelectInput 2099 // printSelectInputRequest writes a PrintSelectInput request to a byte slice. 2100 func printSelectInputRequest(c *xgb.Conn, Context Pcontext, EventMask uint32, EventList []uint32) []byte { 2101 size := xgb.Pad((8 + (4 + xgb.Pad((4 * xgb.PopCount(int(EventMask))))))) 2102 b := 0 2103 buf := make([]byte, size) 2104 2105 c.ExtLock.RLock() 2106 buf[b] = c.Extensions["XpExtension"] 2107 c.ExtLock.RUnlock() 2108 b += 1 2109 2110 buf[b] = 15 // request opcode 2111 b += 1 2112 2113 xgb.Put16(buf[b:], uint16(size/4)) // write request size in 4-byte units 2114 b += 2 2115 2116 xgb.Put32(buf[b:], uint32(Context)) 2117 b += 4 2118 2119 xgb.Put32(buf[b:], EventMask) 2120 b += 4 2121 for i := 0; i < xgb.PopCount(int(EventMask)); i++ { 2122 xgb.Put32(buf[b:], EventList[i]) 2123 b += 4 2124 } 2125 b = xgb.Pad(b) 2126 2127 return buf 2128 } 2129 2130 // PrintSetAttributesCookie is a cookie used only for PrintSetAttributes requests. 2131 type PrintSetAttributesCookie struct { 2132 *xgb.Cookie 2133 } 2134 2135 // PrintSetAttributes sends an unchecked request. 2136 // If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. 2137 func PrintSetAttributes(c *xgb.Conn, Context Pcontext, StringLen uint32, Pool byte, Rule byte, Attributes []String8) PrintSetAttributesCookie { 2138 c.ExtLock.RLock() 2139 defer c.ExtLock.RUnlock() 2140 if _, ok := c.Extensions["XpExtension"]; !ok { 2141 panic("Cannot issue request 'PrintSetAttributes' using the uninitialized extension 'XpExtension'. xprint.Init(connObj) must be called first.") 2142 } 2143 cookie := c.NewCookie(false, false) 2144 c.NewRequest(printSetAttributesRequest(c, Context, StringLen, Pool, Rule, Attributes), cookie) 2145 return PrintSetAttributesCookie{cookie} 2146 } 2147 2148 // PrintSetAttributesChecked sends a checked request. 2149 // If an error occurs, it can be retrieved using PrintSetAttributesCookie.Check() 2150 func PrintSetAttributesChecked(c *xgb.Conn, Context Pcontext, StringLen uint32, Pool byte, Rule byte, Attributes []String8) PrintSetAttributesCookie { 2151 c.ExtLock.RLock() 2152 defer c.ExtLock.RUnlock() 2153 if _, ok := c.Extensions["XpExtension"]; !ok { 2154 panic("Cannot issue request 'PrintSetAttributes' using the uninitialized extension 'XpExtension'. xprint.Init(connObj) must be called first.") 2155 } 2156 cookie := c.NewCookie(true, false) 2157 c.NewRequest(printSetAttributesRequest(c, Context, StringLen, Pool, Rule, Attributes), cookie) 2158 return PrintSetAttributesCookie{cookie} 2159 } 2160 2161 // Check returns an error if one occurred for checked requests that are not expecting a reply. 2162 // This cannot be called for requests expecting a reply, nor for unchecked requests. 2163 func (cook PrintSetAttributesCookie) Check() error { 2164 return cook.Cookie.Check() 2165 } 2166 2167 // Write request to wire for PrintSetAttributes 2168 // printSetAttributesRequest writes a PrintSetAttributes request to a byte slice. 2169 func printSetAttributesRequest(c *xgb.Conn, Context Pcontext, StringLen uint32, Pool byte, Rule byte, Attributes []String8) []byte { 2170 size := xgb.Pad((16 + xgb.Pad((len(Attributes) * 1)))) 2171 b := 0 2172 buf := make([]byte, size) 2173 2174 c.ExtLock.RLock() 2175 buf[b] = c.Extensions["XpExtension"] 2176 c.ExtLock.RUnlock() 2177 b += 1 2178 2179 buf[b] = 18 // request opcode 2180 b += 1 2181 2182 xgb.Put16(buf[b:], uint16(size/4)) // write request size in 4-byte units 2183 b += 2 2184 2185 xgb.Put32(buf[b:], uint32(Context)) 2186 b += 4 2187 2188 xgb.Put32(buf[b:], StringLen) 2189 b += 4 2190 2191 buf[b] = Pool 2192 b += 1 2193 2194 buf[b] = Rule 2195 b += 1 2196 2197 b += 2 // padding 2198 2199 for i := 0; i < int(len(Attributes)); i++ { 2200 buf[b] = byte(Attributes[i]) 2201 b += 1 2202 } 2203 2204 return buf 2205 } 2206 2207 // PrintSetContextCookie is a cookie used only for PrintSetContext requests. 2208 type PrintSetContextCookie struct { 2209 *xgb.Cookie 2210 } 2211 2212 // PrintSetContext sends an unchecked request. 2213 // If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. 2214 func PrintSetContext(c *xgb.Conn, Context uint32) PrintSetContextCookie { 2215 c.ExtLock.RLock() 2216 defer c.ExtLock.RUnlock() 2217 if _, ok := c.Extensions["XpExtension"]; !ok { 2218 panic("Cannot issue request 'PrintSetContext' using the uninitialized extension 'XpExtension'. xprint.Init(connObj) must be called first.") 2219 } 2220 cookie := c.NewCookie(false, false) 2221 c.NewRequest(printSetContextRequest(c, Context), cookie) 2222 return PrintSetContextCookie{cookie} 2223 } 2224 2225 // PrintSetContextChecked sends a checked request. 2226 // If an error occurs, it can be retrieved using PrintSetContextCookie.Check() 2227 func PrintSetContextChecked(c *xgb.Conn, Context uint32) PrintSetContextCookie { 2228 c.ExtLock.RLock() 2229 defer c.ExtLock.RUnlock() 2230 if _, ok := c.Extensions["XpExtension"]; !ok { 2231 panic("Cannot issue request 'PrintSetContext' using the uninitialized extension 'XpExtension'. xprint.Init(connObj) must be called first.") 2232 } 2233 cookie := c.NewCookie(true, false) 2234 c.NewRequest(printSetContextRequest(c, Context), cookie) 2235 return PrintSetContextCookie{cookie} 2236 } 2237 2238 // Check returns an error if one occurred for checked requests that are not expecting a reply. 2239 // This cannot be called for requests expecting a reply, nor for unchecked requests. 2240 func (cook PrintSetContextCookie) Check() error { 2241 return cook.Cookie.Check() 2242 } 2243 2244 // Write request to wire for PrintSetContext 2245 // printSetContextRequest writes a PrintSetContext request to a byte slice. 2246 func printSetContextRequest(c *xgb.Conn, Context uint32) []byte { 2247 size := 8 2248 b := 0 2249 buf := make([]byte, size) 2250 2251 c.ExtLock.RLock() 2252 buf[b] = c.Extensions["XpExtension"] 2253 c.ExtLock.RUnlock() 2254 b += 1 2255 2256 buf[b] = 3 // request opcode 2257 b += 1 2258 2259 xgb.Put16(buf[b:], uint16(size/4)) // write request size in 4-byte units 2260 b += 2 2261 2262 xgb.Put32(buf[b:], Context) 2263 b += 4 2264 2265 return buf 2266 } 2267 2268 // PrintSetImageResolutionCookie is a cookie used only for PrintSetImageResolution requests. 2269 type PrintSetImageResolutionCookie struct { 2270 *xgb.Cookie 2271 } 2272 2273 // PrintSetImageResolution sends a checked request. 2274 // If an error occurs, it will be returned with the reply by calling PrintSetImageResolutionCookie.Reply() 2275 func PrintSetImageResolution(c *xgb.Conn, Context Pcontext, ImageResolution uint16) PrintSetImageResolutionCookie { 2276 c.ExtLock.RLock() 2277 defer c.ExtLock.RUnlock() 2278 if _, ok := c.Extensions["XpExtension"]; !ok { 2279 panic("Cannot issue request 'PrintSetImageResolution' using the uninitialized extension 'XpExtension'. xprint.Init(connObj) must be called first.") 2280 } 2281 cookie := c.NewCookie(true, true) 2282 c.NewRequest(printSetImageResolutionRequest(c, Context, ImageResolution), cookie) 2283 return PrintSetImageResolutionCookie{cookie} 2284 } 2285 2286 // PrintSetImageResolutionUnchecked sends an unchecked request. 2287 // If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. 2288 func PrintSetImageResolutionUnchecked(c *xgb.Conn, Context Pcontext, ImageResolution uint16) PrintSetImageResolutionCookie { 2289 c.ExtLock.RLock() 2290 defer c.ExtLock.RUnlock() 2291 if _, ok := c.Extensions["XpExtension"]; !ok { 2292 panic("Cannot issue request 'PrintSetImageResolution' using the uninitialized extension 'XpExtension'. xprint.Init(connObj) must be called first.") 2293 } 2294 cookie := c.NewCookie(false, true) 2295 c.NewRequest(printSetImageResolutionRequest(c, Context, ImageResolution), cookie) 2296 return PrintSetImageResolutionCookie{cookie} 2297 } 2298 2299 // PrintSetImageResolutionReply represents the data returned from a PrintSetImageResolution request. 2300 type PrintSetImageResolutionReply struct { 2301 Sequence uint16 // sequence number of the request for this reply 2302 Length uint32 // number of bytes in this reply 2303 Status bool 2304 PreviousResolutions uint16 2305 } 2306 2307 // Reply blocks and returns the reply data for a PrintSetImageResolution request. 2308 func (cook PrintSetImageResolutionCookie) Reply() (*PrintSetImageResolutionReply, error) { 2309 buf, err := cook.Cookie.Reply() 2310 if err != nil { 2311 return nil, err 2312 } 2313 if buf == nil { 2314 return nil, nil 2315 } 2316 return printSetImageResolutionReply(buf), nil 2317 } 2318 2319 // printSetImageResolutionReply reads a byte slice into a PrintSetImageResolutionReply value. 2320 func printSetImageResolutionReply(buf []byte) *PrintSetImageResolutionReply { 2321 v := new(PrintSetImageResolutionReply) 2322 b := 1 // skip reply determinant 2323 2324 if buf[b] == 1 { 2325 v.Status = true 2326 } else { 2327 v.Status = false 2328 } 2329 b += 1 2330 2331 v.Sequence = xgb.Get16(buf[b:]) 2332 b += 2 2333 2334 v.Length = xgb.Get32(buf[b:]) // 4-byte units 2335 b += 4 2336 2337 v.PreviousResolutions = xgb.Get16(buf[b:]) 2338 b += 2 2339 2340 return v 2341 } 2342 2343 // Write request to wire for PrintSetImageResolution 2344 // printSetImageResolutionRequest writes a PrintSetImageResolution request to a byte slice. 2345 func printSetImageResolutionRequest(c *xgb.Conn, Context Pcontext, ImageResolution uint16) []byte { 2346 size := 12 2347 b := 0 2348 buf := make([]byte, size) 2349 2350 c.ExtLock.RLock() 2351 buf[b] = c.Extensions["XpExtension"] 2352 c.ExtLock.RUnlock() 2353 b += 1 2354 2355 buf[b] = 23 // request opcode 2356 b += 1 2357 2358 xgb.Put16(buf[b:], uint16(size/4)) // write request size in 4-byte units 2359 b += 2 2360 2361 xgb.Put32(buf[b:], uint32(Context)) 2362 b += 4 2363 2364 xgb.Put16(buf[b:], ImageResolution) 2365 b += 2 2366 2367 return buf 2368 } 2369 2370 // PrintStartDocCookie is a cookie used only for PrintStartDoc requests. 2371 type PrintStartDocCookie struct { 2372 *xgb.Cookie 2373 } 2374 2375 // PrintStartDoc sends an unchecked request. 2376 // If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. 2377 func PrintStartDoc(c *xgb.Conn, DriverMode byte) PrintStartDocCookie { 2378 c.ExtLock.RLock() 2379 defer c.ExtLock.RUnlock() 2380 if _, ok := c.Extensions["XpExtension"]; !ok { 2381 panic("Cannot issue request 'PrintStartDoc' using the uninitialized extension 'XpExtension'. xprint.Init(connObj) must be called first.") 2382 } 2383 cookie := c.NewCookie(false, false) 2384 c.NewRequest(printStartDocRequest(c, DriverMode), cookie) 2385 return PrintStartDocCookie{cookie} 2386 } 2387 2388 // PrintStartDocChecked sends a checked request. 2389 // If an error occurs, it can be retrieved using PrintStartDocCookie.Check() 2390 func PrintStartDocChecked(c *xgb.Conn, DriverMode byte) PrintStartDocCookie { 2391 c.ExtLock.RLock() 2392 defer c.ExtLock.RUnlock() 2393 if _, ok := c.Extensions["XpExtension"]; !ok { 2394 panic("Cannot issue request 'PrintStartDoc' using the uninitialized extension 'XpExtension'. xprint.Init(connObj) must be called first.") 2395 } 2396 cookie := c.NewCookie(true, false) 2397 c.NewRequest(printStartDocRequest(c, DriverMode), cookie) 2398 return PrintStartDocCookie{cookie} 2399 } 2400 2401 // Check returns an error if one occurred for checked requests that are not expecting a reply. 2402 // This cannot be called for requests expecting a reply, nor for unchecked requests. 2403 func (cook PrintStartDocCookie) Check() error { 2404 return cook.Cookie.Check() 2405 } 2406 2407 // Write request to wire for PrintStartDoc 2408 // printStartDocRequest writes a PrintStartDoc request to a byte slice. 2409 func printStartDocRequest(c *xgb.Conn, DriverMode byte) []byte { 2410 size := 8 2411 b := 0 2412 buf := make([]byte, size) 2413 2414 c.ExtLock.RLock() 2415 buf[b] = c.Extensions["XpExtension"] 2416 c.ExtLock.RUnlock() 2417 b += 1 2418 2419 buf[b] = 9 // request opcode 2420 b += 1 2421 2422 xgb.Put16(buf[b:], uint16(size/4)) // write request size in 4-byte units 2423 b += 2 2424 2425 buf[b] = DriverMode 2426 b += 1 2427 2428 return buf 2429 } 2430 2431 // PrintStartJobCookie is a cookie used only for PrintStartJob requests. 2432 type PrintStartJobCookie struct { 2433 *xgb.Cookie 2434 } 2435 2436 // PrintStartJob sends an unchecked request. 2437 // If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. 2438 func PrintStartJob(c *xgb.Conn, OutputMode byte) PrintStartJobCookie { 2439 c.ExtLock.RLock() 2440 defer c.ExtLock.RUnlock() 2441 if _, ok := c.Extensions["XpExtension"]; !ok { 2442 panic("Cannot issue request 'PrintStartJob' using the uninitialized extension 'XpExtension'. xprint.Init(connObj) must be called first.") 2443 } 2444 cookie := c.NewCookie(false, false) 2445 c.NewRequest(printStartJobRequest(c, OutputMode), cookie) 2446 return PrintStartJobCookie{cookie} 2447 } 2448 2449 // PrintStartJobChecked sends a checked request. 2450 // If an error occurs, it can be retrieved using PrintStartJobCookie.Check() 2451 func PrintStartJobChecked(c *xgb.Conn, OutputMode byte) PrintStartJobCookie { 2452 c.ExtLock.RLock() 2453 defer c.ExtLock.RUnlock() 2454 if _, ok := c.Extensions["XpExtension"]; !ok { 2455 panic("Cannot issue request 'PrintStartJob' using the uninitialized extension 'XpExtension'. xprint.Init(connObj) must be called first.") 2456 } 2457 cookie := c.NewCookie(true, false) 2458 c.NewRequest(printStartJobRequest(c, OutputMode), cookie) 2459 return PrintStartJobCookie{cookie} 2460 } 2461 2462 // Check returns an error if one occurred for checked requests that are not expecting a reply. 2463 // This cannot be called for requests expecting a reply, nor for unchecked requests. 2464 func (cook PrintStartJobCookie) Check() error { 2465 return cook.Cookie.Check() 2466 } 2467 2468 // Write request to wire for PrintStartJob 2469 // printStartJobRequest writes a PrintStartJob request to a byte slice. 2470 func printStartJobRequest(c *xgb.Conn, OutputMode byte) []byte { 2471 size := 8 2472 b := 0 2473 buf := make([]byte, size) 2474 2475 c.ExtLock.RLock() 2476 buf[b] = c.Extensions["XpExtension"] 2477 c.ExtLock.RUnlock() 2478 b += 1 2479 2480 buf[b] = 7 // request opcode 2481 b += 1 2482 2483 xgb.Put16(buf[b:], uint16(size/4)) // write request size in 4-byte units 2484 b += 2 2485 2486 buf[b] = OutputMode 2487 b += 1 2488 2489 return buf 2490 } 2491 2492 // PrintStartPageCookie is a cookie used only for PrintStartPage requests. 2493 type PrintStartPageCookie struct { 2494 *xgb.Cookie 2495 } 2496 2497 // PrintStartPage sends an unchecked request. 2498 // If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent. 2499 func PrintStartPage(c *xgb.Conn, Window xproto.Window) PrintStartPageCookie { 2500 c.ExtLock.RLock() 2501 defer c.ExtLock.RUnlock() 2502 if _, ok := c.Extensions["XpExtension"]; !ok { 2503 panic("Cannot issue request 'PrintStartPage' using the uninitialized extension 'XpExtension'. xprint.Init(connObj) must be called first.") 2504 } 2505 cookie := c.NewCookie(false, false) 2506 c.NewRequest(printStartPageRequest(c, Window), cookie) 2507 return PrintStartPageCookie{cookie} 2508 } 2509 2510 // PrintStartPageChecked sends a checked request. 2511 // If an error occurs, it can be retrieved using PrintStartPageCookie.Check() 2512 func PrintStartPageChecked(c *xgb.Conn, Window xproto.Window) PrintStartPageCookie { 2513 c.ExtLock.RLock() 2514 defer c.ExtLock.RUnlock() 2515 if _, ok := c.Extensions["XpExtension"]; !ok { 2516 panic("Cannot issue request 'PrintStartPage' using the uninitialized extension 'XpExtension'. xprint.Init(connObj) must be called first.") 2517 } 2518 cookie := c.NewCookie(true, false) 2519 c.NewRequest(printStartPageRequest(c, Window), cookie) 2520 return PrintStartPageCookie{cookie} 2521 } 2522 2523 // Check returns an error if one occurred for checked requests that are not expecting a reply. 2524 // This cannot be called for requests expecting a reply, nor for unchecked requests. 2525 func (cook PrintStartPageCookie) Check() error { 2526 return cook.Cookie.Check() 2527 } 2528 2529 // Write request to wire for PrintStartPage 2530 // printStartPageRequest writes a PrintStartPage request to a byte slice. 2531 func printStartPageRequest(c *xgb.Conn, Window xproto.Window) []byte { 2532 size := 8 2533 b := 0 2534 buf := make([]byte, size) 2535 2536 c.ExtLock.RLock() 2537 buf[b] = c.Extensions["XpExtension"] 2538 c.ExtLock.RUnlock() 2539 b += 1 2540 2541 buf[b] = 13 // request opcode 2542 b += 1 2543 2544 xgb.Put16(buf[b:], uint16(size/4)) // write request size in 4-byte units 2545 b += 2 2546 2547 xgb.Put32(buf[b:], uint32(Window)) 2548 b += 4 2549 2550 return buf 2551 }