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