Debian Codegraph @

dpms/dpms.go

raw
1 // Package dpms is the X client API for the DPMS extension.
2 package dpms
3
4 // This file is automatically generated from dpms.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 DPMS extension.
13 func Init(c *xgb.Conn) error {
14 reply, err := xproto.QueryExtension(c, 4, "DPMS").Reply()
15 switch {
16 case err != nil:
17 return err
18 case !reply.Present:
19 return xgb.Errorf("No extension named DPMS could be found on on the server.")
20 }
21
22 c.ExtLock.Lock()
23 c.Extensions["DPMS"] = reply.MajorOpcode
24 c.ExtLock.Unlock()
25 for evNum, fun := range xgb.NewExtEventFuncs["DPMS"] {
26 xgb.NewEventFuncs[int(reply.FirstEvent)+evNum] = fun
27 }
28 for errNum, fun := range xgb.NewExtErrorFuncs["DPMS"] {
29 xgb.NewErrorFuncs[int(reply.FirstError)+errNum] = fun
30 }
31 return nil
32 }
33
34 func init() {
35 xgb.NewExtEventFuncs["DPMS"] = make(map[int]xgb.NewEventFun)
36 xgb.NewExtErrorFuncs["DPMS"] = make(map[int]xgb.NewErrorFun)
37 }
38
39 const (
40 DPMSModeOn = 0
41 DPMSModeStandby = 1
42 DPMSModeSuspend = 2
43 DPMSModeOff = 3
44 )
45
46 // Skipping definition for base type 'Bool'
47
48 // Skipping definition for base type 'Byte'
49
50 // Skipping definition for base type 'Card8'
51
52 // Skipping definition for base type 'Char'
53
54 // Skipping definition for base type 'Void'
55
56 // Skipping definition for base type 'Double'
57
58 // Skipping definition for base type 'Float'
59
60 // Skipping definition for base type 'Int16'
61
62 // Skipping definition for base type 'Int32'
63
64 // Skipping definition for base type 'Int8'
65
66 // Skipping definition for base type 'Card16'
67
68 // Skipping definition for base type 'Card32'
69
70 // CapableCookie is a cookie used only for Capable requests.
71 type CapableCookie struct {
72 *xgb.Cookie
73 }
74
75 // Capable sends a checked request.
76 // If an error occurs, it will be returned with the reply by calling CapableCookie.Reply()
77 func Capable(c *xgb.Conn) CapableCookie {
78 c.ExtLock.RLock()
79 defer c.ExtLock.RUnlock()
80 if _, ok := c.Extensions["DPMS"]; !ok {
81 panic("Cannot issue request 'Capable' using the uninitialized extension 'DPMS'. dpms.Init(connObj) must be called first.")
82 }
83 cookie := c.NewCookie(true, true)
84 c.NewRequest(capableRequest(c), cookie)
85 return CapableCookie{cookie}
86 }
87
88 // CapableUnchecked sends an unchecked request.
89 // If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent.
90 func CapableUnchecked(c *xgb.Conn) CapableCookie {
91 c.ExtLock.RLock()
92 defer c.ExtLock.RUnlock()
93 if _, ok := c.Extensions["DPMS"]; !ok {
94 panic("Cannot issue request 'Capable' using the uninitialized extension 'DPMS'. dpms.Init(connObj) must be called first.")
95 }
96 cookie := c.NewCookie(false, true)
97 c.NewRequest(capableRequest(c), cookie)
98 return CapableCookie{cookie}
99 }
100
101 // CapableReply represents the data returned from a Capable request.
102 type CapableReply struct {
103 Sequence uint16 // sequence number of the request for this reply
104 Length uint32 // number of bytes in this reply
105 // padding: 1 bytes
106 Capable bool
107 // padding: 23 bytes
108 }
109
110 // Reply blocks and returns the reply data for a Capable request.
111 func (cook CapableCookie) Reply() (*CapableReply, error) {
112 buf, err := cook.Cookie.Reply()
113 if err != nil {
114 return nil, err
115 }
116 if buf == nil {
117 return nil, nil
118 }
119 return capableReply(buf), nil
120 }
121
122 // capableReply reads a byte slice into a CapableReply value.
123 func capableReply(buf []byte) *CapableReply {
124 v := new(CapableReply)
125 b := 1 // skip reply determinant
126
127 b += 1 // padding
128
129 v.Sequence = xgb.Get16(buf[b:])
130 b += 2
131
132 v.Length = xgb.Get32(buf[b:]) // 4-byte units
133 b += 4
134
135 if buf[b] == 1 {
136 v.Capable = true
137 } else {
138 v.Capable = false
139 }
140 b += 1
141
142 b += 23 // padding
143
144 return v
145 }
146
147 // Write request to wire for Capable
148 // capableRequest writes a Capable request to a byte slice.
149 func capableRequest(c *xgb.Conn) []byte {
150 size := 4
151 b := 0
152 buf := make([]byte, size)
153
154 c.ExtLock.RLock()
155 buf[b] = c.Extensions["DPMS"]
156 c.ExtLock.RUnlock()
157 b += 1
158
159 buf[b] = 1 // request opcode
160 b += 1
161
162 xgb.Put16(buf[b:], uint16(size/4)) // write request size in 4-byte units
163 b += 2
164
165 return buf
166 }
167
168 // DisableCookie is a cookie used only for Disable requests.
169 type DisableCookie struct {
170 *xgb.Cookie
171 }
172
173 // Disable sends an unchecked request.
174 // If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent.
175 func Disable(c *xgb.Conn) DisableCookie {
176 c.ExtLock.RLock()
177 defer c.ExtLock.RUnlock()
178 if _, ok := c.Extensions["DPMS"]; !ok {
179 panic("Cannot issue request 'Disable' using the uninitialized extension 'DPMS'. dpms.Init(connObj) must be called first.")
180 }
181 cookie := c.NewCookie(false, false)
182 c.NewRequest(disableRequest(c), cookie)
183 return DisableCookie{cookie}
184 }
185
186 // DisableChecked sends a checked request.
187 // If an error occurs, it can be retrieved using DisableCookie.Check()
188 func DisableChecked(c *xgb.Conn) DisableCookie {
189 c.ExtLock.RLock()
190 defer c.ExtLock.RUnlock()
191 if _, ok := c.Extensions["DPMS"]; !ok {
192 panic("Cannot issue request 'Disable' using the uninitialized extension 'DPMS'. dpms.Init(connObj) must be called first.")
193 }
194 cookie := c.NewCookie(true, false)
195 c.NewRequest(disableRequest(c), cookie)
196 return DisableCookie{cookie}
197 }
198
199 // Check returns an error if one occurred for checked requests that are not expecting a reply.
200 // This cannot be called for requests expecting a reply, nor for unchecked requests.
201 func (cook DisableCookie) Check() error {
202 return cook.Cookie.Check()
203 }
204
205 // Write request to wire for Disable
206 // disableRequest writes a Disable request to a byte slice.
207 func disableRequest(c *xgb.Conn) []byte {
208 size := 4
209 b := 0
210 buf := make([]byte, size)
211
212 c.ExtLock.RLock()
213 buf[b] = c.Extensions["DPMS"]
214 c.ExtLock.RUnlock()
215 b += 1
216
217 buf[b] = 5 // request opcode
218 b += 1
219
220 xgb.Put16(buf[b:], uint16(size/4)) // write request size in 4-byte units
221 b += 2
222
223 return buf
224 }
225
226 // EnableCookie is a cookie used only for Enable requests.
227 type EnableCookie struct {
228 *xgb.Cookie
229 }
230
231 // Enable sends an unchecked request.
232 // If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent.
233 func Enable(c *xgb.Conn) EnableCookie {
234 c.ExtLock.RLock()
235 defer c.ExtLock.RUnlock()
236 if _, ok := c.Extensions["DPMS"]; !ok {
237 panic("Cannot issue request 'Enable' using the uninitialized extension 'DPMS'. dpms.Init(connObj) must be called first.")
238 }
239 cookie := c.NewCookie(false, false)
240 c.NewRequest(enableRequest(c), cookie)
241 return EnableCookie{cookie}
242 }
243
244 // EnableChecked sends a checked request.
245 // If an error occurs, it can be retrieved using EnableCookie.Check()
246 func EnableChecked(c *xgb.Conn) EnableCookie {
247 c.ExtLock.RLock()
248 defer c.ExtLock.RUnlock()
249 if _, ok := c.Extensions["DPMS"]; !ok {
250 panic("Cannot issue request 'Enable' using the uninitialized extension 'DPMS'. dpms.Init(connObj) must be called first.")
251 }
252 cookie := c.NewCookie(true, false)
253 c.NewRequest(enableRequest(c), cookie)
254 return EnableCookie{cookie}
255 }
256
257 // Check returns an error if one occurred for checked requests that are not expecting a reply.
258 // This cannot be called for requests expecting a reply, nor for unchecked requests.
259 func (cook EnableCookie) Check() error {
260 return cook.Cookie.Check()
261 }
262
263 // Write request to wire for Enable
264 // enableRequest writes a Enable request to a byte slice.
265 func enableRequest(c *xgb.Conn) []byte {
266 size := 4
267 b := 0
268 buf := make([]byte, size)
269
270 c.ExtLock.RLock()
271 buf[b] = c.Extensions["DPMS"]
272 c.ExtLock.RUnlock()
273 b += 1
274
275 buf[b] = 4 // request opcode
276 b += 1
277
278 xgb.Put16(buf[b:], uint16(size/4)) // write request size in 4-byte units
279 b += 2
280
281 return buf
282 }
283
284 // ForceLevelCookie is a cookie used only for ForceLevel requests.
285 type ForceLevelCookie struct {
286 *xgb.Cookie
287 }
288
289 // ForceLevel sends an unchecked request.
290 // If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent.
291 func ForceLevel(c *xgb.Conn, PowerLevel uint16) ForceLevelCookie {
292 c.ExtLock.RLock()
293 defer c.ExtLock.RUnlock()
294 if _, ok := c.Extensions["DPMS"]; !ok {
295 panic("Cannot issue request 'ForceLevel' using the uninitialized extension 'DPMS'. dpms.Init(connObj) must be called first.")
296 }
297 cookie := c.NewCookie(false, false)
298 c.NewRequest(forceLevelRequest(c, PowerLevel), cookie)
299 return ForceLevelCookie{cookie}
300 }
301
302 // ForceLevelChecked sends a checked request.
303 // If an error occurs, it can be retrieved using ForceLevelCookie.Check()
304 func ForceLevelChecked(c *xgb.Conn, PowerLevel uint16) ForceLevelCookie {
305 c.ExtLock.RLock()
306 defer c.ExtLock.RUnlock()
307 if _, ok := c.Extensions["DPMS"]; !ok {
308 panic("Cannot issue request 'ForceLevel' using the uninitialized extension 'DPMS'. dpms.Init(connObj) must be called first.")
309 }
310 cookie := c.NewCookie(true, false)
311 c.NewRequest(forceLevelRequest(c, PowerLevel), cookie)
312 return ForceLevelCookie{cookie}
313 }
314
315 // Check returns an error if one occurred for checked requests that are not expecting a reply.
316 // This cannot be called for requests expecting a reply, nor for unchecked requests.
317 func (cook ForceLevelCookie) Check() error {
318 return cook.Cookie.Check()
319 }
320
321 // Write request to wire for ForceLevel
322 // forceLevelRequest writes a ForceLevel request to a byte slice.
323 func forceLevelRequest(c *xgb.Conn, PowerLevel uint16) []byte {
324 size := 8
325 b := 0
326 buf := make([]byte, size)
327
328 c.ExtLock.RLock()
329 buf[b] = c.Extensions["DPMS"]
330 c.ExtLock.RUnlock()
331 b += 1
332
333 buf[b] = 6 // request opcode
334 b += 1
335
336 xgb.Put16(buf[b:], uint16(size/4)) // write request size in 4-byte units
337 b += 2
338
339 xgb.Put16(buf[b:], PowerLevel)
340 b += 2
341
342 return buf
343 }
344
345 // GetTimeoutsCookie is a cookie used only for GetTimeouts requests.
346 type GetTimeoutsCookie struct {
347 *xgb.Cookie
348 }
349
350 // GetTimeouts sends a checked request.
351 // If an error occurs, it will be returned with the reply by calling GetTimeoutsCookie.Reply()
352 func GetTimeouts(c *xgb.Conn) GetTimeoutsCookie {
353 c.ExtLock.RLock()
354 defer c.ExtLock.RUnlock()
355 if _, ok := c.Extensions["DPMS"]; !ok {
356 panic("Cannot issue request 'GetTimeouts' using the uninitialized extension 'DPMS'. dpms.Init(connObj) must be called first.")
357 }
358 cookie := c.NewCookie(true, true)
359 c.NewRequest(getTimeoutsRequest(c), cookie)
360 return GetTimeoutsCookie{cookie}
361 }
362
363 // GetTimeoutsUnchecked sends an unchecked request.
364 // If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent.
365 func GetTimeoutsUnchecked(c *xgb.Conn) GetTimeoutsCookie {
366 c.ExtLock.RLock()
367 defer c.ExtLock.RUnlock()
368 if _, ok := c.Extensions["DPMS"]; !ok {
369 panic("Cannot issue request 'GetTimeouts' using the uninitialized extension 'DPMS'. dpms.Init(connObj) must be called first.")
370 }
371 cookie := c.NewCookie(false, true)
372 c.NewRequest(getTimeoutsRequest(c), cookie)
373 return GetTimeoutsCookie{cookie}
374 }
375
376 // GetTimeoutsReply represents the data returned from a GetTimeouts request.
377 type GetTimeoutsReply struct {
378 Sequence uint16 // sequence number of the request for this reply
379 Length uint32 // number of bytes in this reply
380 // padding: 1 bytes
381 StandbyTimeout uint16
382 SuspendTimeout uint16
383 OffTimeout uint16
384 // padding: 18 bytes
385 }
386
387 // Reply blocks and returns the reply data for a GetTimeouts request.
388 func (cook GetTimeoutsCookie) Reply() (*GetTimeoutsReply, error) {
389 buf, err := cook.Cookie.Reply()
390 if err != nil {
391 return nil, err
392 }
393 if buf == nil {
394 return nil, nil
395 }
396 return getTimeoutsReply(buf), nil
397 }
398
399 // getTimeoutsReply reads a byte slice into a GetTimeoutsReply value.
400 func getTimeoutsReply(buf []byte) *GetTimeoutsReply {
401 v := new(GetTimeoutsReply)
402 b := 1 // skip reply determinant
403
404 b += 1 // padding
405
406 v.Sequence = xgb.Get16(buf[b:])
407 b += 2
408
409 v.Length = xgb.Get32(buf[b:]) // 4-byte units
410 b += 4
411
412 v.StandbyTimeout = xgb.Get16(buf[b:])
413 b += 2
414
415 v.SuspendTimeout = xgb.Get16(buf[b:])
416 b += 2
417
418 v.OffTimeout = xgb.Get16(buf[b:])
419 b += 2
420
421 b += 18 // padding
422
423 return v
424 }
425
426 // Write request to wire for GetTimeouts
427 // getTimeoutsRequest writes a GetTimeouts request to a byte slice.
428 func getTimeoutsRequest(c *xgb.Conn) []byte {
429 size := 4
430 b := 0
431 buf := make([]byte, size)
432
433 c.ExtLock.RLock()
434 buf[b] = c.Extensions["DPMS"]
435 c.ExtLock.RUnlock()
436 b += 1
437
438 buf[b] = 2 // request opcode
439 b += 1
440
441 xgb.Put16(buf[b:], uint16(size/4)) // write request size in 4-byte units
442 b += 2
443
444 return buf
445 }
446
447 // GetVersionCookie is a cookie used only for GetVersion requests.
448 type GetVersionCookie struct {
449 *xgb.Cookie
450 }
451
452 // GetVersion sends a checked request.
453 // If an error occurs, it will be returned with the reply by calling GetVersionCookie.Reply()
454 func GetVersion(c *xgb.Conn, ClientMajorVersion uint16, ClientMinorVersion uint16) GetVersionCookie {
455 c.ExtLock.RLock()
456 defer c.ExtLock.RUnlock()
457 if _, ok := c.Extensions["DPMS"]; !ok {
458 panic("Cannot issue request 'GetVersion' using the uninitialized extension 'DPMS'. dpms.Init(connObj) must be called first.")
459 }
460 cookie := c.NewCookie(true, true)
461 c.NewRequest(getVersionRequest(c, ClientMajorVersion, ClientMinorVersion), cookie)
462 return GetVersionCookie{cookie}
463 }
464
465 // GetVersionUnchecked sends an unchecked request.
466 // If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent.
467 func GetVersionUnchecked(c *xgb.Conn, ClientMajorVersion uint16, ClientMinorVersion uint16) GetVersionCookie {
468 c.ExtLock.RLock()
469 defer c.ExtLock.RUnlock()
470 if _, ok := c.Extensions["DPMS"]; !ok {
471 panic("Cannot issue request 'GetVersion' using the uninitialized extension 'DPMS'. dpms.Init(connObj) must be called first.")
472 }
473 cookie := c.NewCookie(false, true)
474 c.NewRequest(getVersionRequest(c, ClientMajorVersion, ClientMinorVersion), cookie)
475 return GetVersionCookie{cookie}
476 }
477
478 // GetVersionReply represents the data returned from a GetVersion request.
479 type GetVersionReply struct {
480 Sequence uint16 // sequence number of the request for this reply
481 Length uint32 // number of bytes in this reply
482 // padding: 1 bytes
483 ServerMajorVersion uint16
484 ServerMinorVersion uint16
485 }
486
487 // Reply blocks and returns the reply data for a GetVersion request.
488 func (cook GetVersionCookie) Reply() (*GetVersionReply, error) {
489 buf, err := cook.Cookie.Reply()
490 if err != nil {
491 return nil, err
492 }
493 if buf == nil {
494 return nil, nil
495 }
496 return getVersionReply(buf), nil
497 }
498
499 // getVersionReply reads a byte slice into a GetVersionReply value.
500 func getVersionReply(buf []byte) *GetVersionReply {
501 v := new(GetVersionReply)
502 b := 1 // skip reply determinant
503
504 b += 1 // padding
505
506 v.Sequence = xgb.Get16(buf[b:])
507 b += 2
508
509 v.Length = xgb.Get32(buf[b:]) // 4-byte units
510 b += 4
511
512 v.ServerMajorVersion = xgb.Get16(buf[b:])
513 b += 2
514
515 v.ServerMinorVersion = xgb.Get16(buf[b:])
516 b += 2
517
518 return v
519 }
520
521 // Write request to wire for GetVersion
522 // getVersionRequest writes a GetVersion request to a byte slice.
523 func getVersionRequest(c *xgb.Conn, ClientMajorVersion uint16, ClientMinorVersion uint16) []byte {
524 size := 8
525 b := 0
526 buf := make([]byte, size)
527
528 c.ExtLock.RLock()
529 buf[b] = c.Extensions["DPMS"]
530 c.ExtLock.RUnlock()
531 b += 1
532
533 buf[b] = 0 // request opcode
534 b += 1
535
536 xgb.Put16(buf[b:], uint16(size/4)) // write request size in 4-byte units
537 b += 2
538
539 xgb.Put16(buf[b:], ClientMajorVersion)
540 b += 2
541
542 xgb.Put16(buf[b:], ClientMinorVersion)
543 b += 2
544
545 return buf
546 }
547
548 // InfoCookie is a cookie used only for Info requests.
549 type InfoCookie struct {
550 *xgb.Cookie
551 }
552
553 // Info sends a checked request.
554 // If an error occurs, it will be returned with the reply by calling InfoCookie.Reply()
555 func Info(c *xgb.Conn) InfoCookie {
556 c.ExtLock.RLock()
557 defer c.ExtLock.RUnlock()
558 if _, ok := c.Extensions["DPMS"]; !ok {
559 panic("Cannot issue request 'Info' using the uninitialized extension 'DPMS'. dpms.Init(connObj) must be called first.")
560 }
561 cookie := c.NewCookie(true, true)
562 c.NewRequest(infoRequest(c), cookie)
563 return InfoCookie{cookie}
564 }
565
566 // InfoUnchecked sends an unchecked request.
567 // If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent.
568 func InfoUnchecked(c *xgb.Conn) InfoCookie {
569 c.ExtLock.RLock()
570 defer c.ExtLock.RUnlock()
571 if _, ok := c.Extensions["DPMS"]; !ok {
572 panic("Cannot issue request 'Info' using the uninitialized extension 'DPMS'. dpms.Init(connObj) must be called first.")
573 }
574 cookie := c.NewCookie(false, true)
575 c.NewRequest(infoRequest(c), cookie)
576 return InfoCookie{cookie}
577 }
578
579 // InfoReply represents the data returned from a Info request.
580 type InfoReply struct {
581 Sequence uint16 // sequence number of the request for this reply
582 Length uint32 // number of bytes in this reply
583 // padding: 1 bytes
584 PowerLevel uint16
585 State bool
586 // padding: 21 bytes
587 }
588
589 // Reply blocks and returns the reply data for a Info request.
590 func (cook InfoCookie) Reply() (*InfoReply, error) {
591 buf, err := cook.Cookie.Reply()
592 if err != nil {
593 return nil, err
594 }
595 if buf == nil {
596 return nil, nil
597 }
598 return infoReply(buf), nil
599 }
600
601 // infoReply reads a byte slice into a InfoReply value.
602 func infoReply(buf []byte) *InfoReply {
603 v := new(InfoReply)
604 b := 1 // skip reply determinant
605
606 b += 1 // padding
607
608 v.Sequence = xgb.Get16(buf[b:])
609 b += 2
610
611 v.Length = xgb.Get32(buf[b:]) // 4-byte units
612 b += 4
613
614 v.PowerLevel = xgb.Get16(buf[b:])
615 b += 2
616
617 if buf[b] == 1 {
618 v.State = true
619 } else {
620 v.State = false
621 }
622 b += 1
623
624 b += 21 // padding
625
626 return v
627 }
628
629 // Write request to wire for Info
630 // infoRequest writes a Info request to a byte slice.
631 func infoRequest(c *xgb.Conn) []byte {
632 size := 4
633 b := 0
634 buf := make([]byte, size)
635
636 c.ExtLock.RLock()
637 buf[b] = c.Extensions["DPMS"]
638 c.ExtLock.RUnlock()
639 b += 1
640
641 buf[b] = 7 // request opcode
642 b += 1
643
644 xgb.Put16(buf[b:], uint16(size/4)) // write request size in 4-byte units
645 b += 2
646
647 return buf
648 }
649
650 // SetTimeoutsCookie is a cookie used only for SetTimeouts requests.
651 type SetTimeoutsCookie struct {
652 *xgb.Cookie
653 }
654
655 // SetTimeouts sends an unchecked request.
656 // If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent.
657 func SetTimeouts(c *xgb.Conn, StandbyTimeout uint16, SuspendTimeout uint16, OffTimeout uint16) SetTimeoutsCookie {
658 c.ExtLock.RLock()
659 defer c.ExtLock.RUnlock()
660 if _, ok := c.Extensions["DPMS"]; !ok {
661 panic("Cannot issue request 'SetTimeouts' using the uninitialized extension 'DPMS'. dpms.Init(connObj) must be called first.")
662 }
663 cookie := c.NewCookie(false, false)
664 c.NewRequest(setTimeoutsRequest(c, StandbyTimeout, SuspendTimeout, OffTimeout), cookie)
665 return SetTimeoutsCookie{cookie}
666 }
667
668 // SetTimeoutsChecked sends a checked request.
669 // If an error occurs, it can be retrieved using SetTimeoutsCookie.Check()
670 func SetTimeoutsChecked(c *xgb.Conn, StandbyTimeout uint16, SuspendTimeout uint16, OffTimeout uint16) SetTimeoutsCookie {
671 c.ExtLock.RLock()
672 defer c.ExtLock.RUnlock()
673 if _, ok := c.Extensions["DPMS"]; !ok {
674 panic("Cannot issue request 'SetTimeouts' using the uninitialized extension 'DPMS'. dpms.Init(connObj) must be called first.")
675 }
676 cookie := c.NewCookie(true, false)
677 c.NewRequest(setTimeoutsRequest(c, StandbyTimeout, SuspendTimeout, OffTimeout), cookie)
678 return SetTimeoutsCookie{cookie}
679 }
680
681 // Check returns an error if one occurred for checked requests that are not expecting a reply.
682 // This cannot be called for requests expecting a reply, nor for unchecked requests.
683 func (cook SetTimeoutsCookie) Check() error {
684 return cook.Cookie.Check()
685 }
686
687 // Write request to wire for SetTimeouts
688 // setTimeoutsRequest writes a SetTimeouts request to a byte slice.
689 func setTimeoutsRequest(c *xgb.Conn, StandbyTimeout uint16, SuspendTimeout uint16, OffTimeout uint16) []byte {
690 size := 12
691 b := 0
692 buf := make([]byte, size)
693
694 c.ExtLock.RLock()
695 buf[b] = c.Extensions["DPMS"]
696 c.ExtLock.RUnlock()
697 b += 1
698
699 buf[b] = 3 // request opcode
700 b += 1
701
702 xgb.Put16(buf[b:], uint16(size/4)) // write request size in 4-byte units
703 b += 2
704
705 xgb.Put16(buf[b:], StandbyTimeout)
706 b += 2
707
708 xgb.Put16(buf[b:], SuspendTimeout)
709 b += 2
710
711 xgb.Put16(buf[b:], OffTimeout)
712 b += 2
713
714 return buf
715 }