go-tg-screenshot-bot
945 строк · 25.7 Кб
1// Package shm is the X client API for the MIT-SHM extension.
2package shm
3
4// This file is automatically generated from shm.xml. Edit at your peril!
5
6import (
7"github.com/jezek/xgb"
8
9"github.com/jezek/xgb/xproto"
10)
11
12// Init must be called before using the MIT-SHM extension.
13func Init(c *xgb.Conn) error {
14reply, err := xproto.QueryExtension(c, 7, "MIT-SHM").Reply()
15switch {
16case err != nil:
17return err
18case !reply.Present:
19return xgb.Errorf("No extension named MIT-SHM could be found on on the server.")
20}
21
22c.ExtLock.Lock()
23c.Extensions["MIT-SHM"] = reply.MajorOpcode
24c.ExtLock.Unlock()
25for evNum, fun := range xgb.NewExtEventFuncs["MIT-SHM"] {
26xgb.NewEventFuncs[int(reply.FirstEvent)+evNum] = fun
27}
28for errNum, fun := range xgb.NewExtErrorFuncs["MIT-SHM"] {
29xgb.NewErrorFuncs[int(reply.FirstError)+errNum] = fun
30}
31return nil
32}
33
34func init() {
35xgb.NewExtEventFuncs["MIT-SHM"] = make(map[int]xgb.NewEventFun)
36xgb.NewExtErrorFuncs["MIT-SHM"] = make(map[int]xgb.NewErrorFun)
37}
38
39// BadBadSeg is the error number for a BadBadSeg.
40const BadBadSeg = 0
41
42type BadSegError xproto.ValueError
43
44// BadSegErrorNew constructs a BadSegError value that implements xgb.Error from a byte slice.
45func BadSegErrorNew(buf []byte) xgb.Error {
46v := BadSegError(xproto.ValueErrorNew(buf).(xproto.ValueError))
47v.NiceName = "BadSeg"
48return v
49}
50
51// SequenceId returns the sequence id attached to the BadBadSeg error.
52// This is mostly used internally.
53func (err BadSegError) SequenceId() uint16 {
54return err.Sequence
55}
56
57// BadId returns the 'BadValue' number if one exists for the BadBadSeg error. If no bad value exists, 0 is returned.
58func (err BadSegError) BadId() uint32 {
59return 0
60}
61
62// Error returns a rudimentary string representation of the BadBadSeg error.
63func (err BadSegError) Error() string {
64fieldVals := make([]string, 0, 4)
65fieldVals = append(fieldVals, "NiceName: "+err.NiceName)
66fieldVals = append(fieldVals, xgb.Sprintf("Sequence: %d", err.Sequence))
67fieldVals = append(fieldVals, xgb.Sprintf("BadValue: %d", err.BadValue))
68fieldVals = append(fieldVals, xgb.Sprintf("MinorOpcode: %d", err.MinorOpcode))
69fieldVals = append(fieldVals, xgb.Sprintf("MajorOpcode: %d", err.MajorOpcode))
70return "BadBadSeg {" + xgb.StringsJoin(fieldVals, ", ") + "}"
71}
72
73func init() {
74xgb.NewExtErrorFuncs["MIT-SHM"][0] = BadSegErrorNew
75}
76
77// Completion is the event number for a CompletionEvent.
78const Completion = 0
79
80type CompletionEvent struct {
81Sequence uint16
82// padding: 1 bytes
83Drawable xproto.Drawable
84MinorEvent uint16
85MajorEvent byte
86// padding: 1 bytes
87Shmseg Seg
88Offset uint32
89}
90
91// CompletionEventNew constructs a CompletionEvent value that implements xgb.Event from a byte slice.
92func CompletionEventNew(buf []byte) xgb.Event {
93v := CompletionEvent{}
94b := 1 // don't read event number
95
96b += 1 // padding
97
98v.Sequence = xgb.Get16(buf[b:])
99b += 2
100
101v.Drawable = xproto.Drawable(xgb.Get32(buf[b:]))
102b += 4
103
104v.MinorEvent = xgb.Get16(buf[b:])
105b += 2
106
107v.MajorEvent = buf[b]
108b += 1
109
110b += 1 // padding
111
112v.Shmseg = Seg(xgb.Get32(buf[b:]))
113b += 4
114
115v.Offset = xgb.Get32(buf[b:])
116b += 4
117
118return v
119}
120
121// Bytes writes a CompletionEvent value to a byte slice.
122func (v CompletionEvent) Bytes() []byte {
123buf := make([]byte, 32)
124b := 0
125
126// write event number
127buf[b] = 0
128b += 1
129
130b += 1 // padding
131
132b += 2 // skip sequence number
133
134xgb.Put32(buf[b:], uint32(v.Drawable))
135b += 4
136
137xgb.Put16(buf[b:], v.MinorEvent)
138b += 2
139
140buf[b] = v.MajorEvent
141b += 1
142
143b += 1 // padding
144
145xgb.Put32(buf[b:], uint32(v.Shmseg))
146b += 4
147
148xgb.Put32(buf[b:], v.Offset)
149b += 4
150
151return buf
152}
153
154// SequenceId returns the sequence id attached to the Completion event.
155// Events without a sequence number (KeymapNotify) return 0.
156// This is mostly used internally.
157func (v CompletionEvent) SequenceId() uint16 {
158return v.Sequence
159}
160
161// String is a rudimentary string representation of CompletionEvent.
162func (v CompletionEvent) String() string {
163fieldVals := make([]string, 0, 7)
164fieldVals = append(fieldVals, xgb.Sprintf("Sequence: %d", v.Sequence))
165fieldVals = append(fieldVals, xgb.Sprintf("Drawable: %d", v.Drawable))
166fieldVals = append(fieldVals, xgb.Sprintf("MinorEvent: %d", v.MinorEvent))
167fieldVals = append(fieldVals, xgb.Sprintf("MajorEvent: %d", v.MajorEvent))
168fieldVals = append(fieldVals, xgb.Sprintf("Shmseg: %d", v.Shmseg))
169fieldVals = append(fieldVals, xgb.Sprintf("Offset: %d", v.Offset))
170return "Completion {" + xgb.StringsJoin(fieldVals, ", ") + "}"
171}
172
173func init() {
174xgb.NewExtEventFuncs["MIT-SHM"][0] = CompletionEventNew
175}
176
177type Seg uint32
178
179func NewSegId(c *xgb.Conn) (Seg, error) {
180id, err := c.NewId()
181if err != nil {
182return 0, err
183}
184return Seg(id), nil
185}
186
187// Skipping definition for base type 'Bool'
188
189// Skipping definition for base type 'Byte'
190
191// Skipping definition for base type 'Card8'
192
193// Skipping definition for base type 'Char'
194
195// Skipping definition for base type 'Void'
196
197// Skipping definition for base type 'Double'
198
199// Skipping definition for base type 'Float'
200
201// Skipping definition for base type 'Int16'
202
203// Skipping definition for base type 'Int32'
204
205// Skipping definition for base type 'Int8'
206
207// Skipping definition for base type 'Card16'
208
209// Skipping definition for base type 'Card32'
210
211// AttachCookie is a cookie used only for Attach requests.
212type AttachCookie struct {
213*xgb.Cookie
214}
215
216// Attach sends an unchecked request.
217// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent.
218func Attach(c *xgb.Conn, Shmseg Seg, Shmid uint32, ReadOnly bool) AttachCookie {
219c.ExtLock.RLock()
220defer c.ExtLock.RUnlock()
221if _, ok := c.Extensions["MIT-SHM"]; !ok {
222panic("Cannot issue request 'Attach' using the uninitialized extension 'MIT-SHM'. shm.Init(connObj) must be called first.")
223}
224cookie := c.NewCookie(false, false)
225c.NewRequest(attachRequest(c, Shmseg, Shmid, ReadOnly), cookie)
226return AttachCookie{cookie}
227}
228
229// AttachChecked sends a checked request.
230// If an error occurs, it can be retrieved using AttachCookie.Check()
231func AttachChecked(c *xgb.Conn, Shmseg Seg, Shmid uint32, ReadOnly bool) AttachCookie {
232c.ExtLock.RLock()
233defer c.ExtLock.RUnlock()
234if _, ok := c.Extensions["MIT-SHM"]; !ok {
235panic("Cannot issue request 'Attach' using the uninitialized extension 'MIT-SHM'. shm.Init(connObj) must be called first.")
236}
237cookie := c.NewCookie(true, false)
238c.NewRequest(attachRequest(c, Shmseg, Shmid, ReadOnly), cookie)
239return AttachCookie{cookie}
240}
241
242// Check returns an error if one occurred for checked requests that are not expecting a reply.
243// This cannot be called for requests expecting a reply, nor for unchecked requests.
244func (cook AttachCookie) Check() error {
245return cook.Cookie.Check()
246}
247
248// Write request to wire for Attach
249// attachRequest writes a Attach request to a byte slice.
250func attachRequest(c *xgb.Conn, Shmseg Seg, Shmid uint32, ReadOnly bool) []byte {
251size := 16
252b := 0
253buf := make([]byte, size)
254
255c.ExtLock.RLock()
256buf[b] = c.Extensions["MIT-SHM"]
257c.ExtLock.RUnlock()
258b += 1
259
260buf[b] = 1 // request opcode
261b += 1
262
263xgb.Put16(buf[b:], uint16(size/4)) // write request size in 4-byte units
264b += 2
265
266xgb.Put32(buf[b:], uint32(Shmseg))
267b += 4
268
269xgb.Put32(buf[b:], Shmid)
270b += 4
271
272if ReadOnly {
273buf[b] = 1
274} else {
275buf[b] = 0
276}
277b += 1
278
279b += 3 // padding
280
281return buf
282}
283
284// AttachFdCookie is a cookie used only for AttachFd requests.
285type AttachFdCookie struct {
286*xgb.Cookie
287}
288
289// AttachFd sends an unchecked request.
290// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent.
291func AttachFd(c *xgb.Conn, Shmseg Seg, ReadOnly bool) AttachFdCookie {
292c.ExtLock.RLock()
293defer c.ExtLock.RUnlock()
294if _, ok := c.Extensions["MIT-SHM"]; !ok {
295panic("Cannot issue request 'AttachFd' using the uninitialized extension 'MIT-SHM'. shm.Init(connObj) must be called first.")
296}
297cookie := c.NewCookie(false, false)
298c.NewRequest(attachFdRequest(c, Shmseg, ReadOnly), cookie)
299return AttachFdCookie{cookie}
300}
301
302// AttachFdChecked sends a checked request.
303// If an error occurs, it can be retrieved using AttachFdCookie.Check()
304func AttachFdChecked(c *xgb.Conn, Shmseg Seg, ReadOnly bool) AttachFdCookie {
305c.ExtLock.RLock()
306defer c.ExtLock.RUnlock()
307if _, ok := c.Extensions["MIT-SHM"]; !ok {
308panic("Cannot issue request 'AttachFd' using the uninitialized extension 'MIT-SHM'. shm.Init(connObj) must be called first.")
309}
310cookie := c.NewCookie(true, false)
311c.NewRequest(attachFdRequest(c, Shmseg, ReadOnly), cookie)
312return AttachFdCookie{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.
317func (cook AttachFdCookie) Check() error {
318return cook.Cookie.Check()
319}
320
321// Write request to wire for AttachFd
322// attachFdRequest writes a AttachFd request to a byte slice.
323func attachFdRequest(c *xgb.Conn, Shmseg Seg, ReadOnly bool) []byte {
324size := 12
325b := 0
326buf := make([]byte, size)
327
328c.ExtLock.RLock()
329buf[b] = c.Extensions["MIT-SHM"]
330c.ExtLock.RUnlock()
331b += 1
332
333buf[b] = 6 // request opcode
334b += 1
335
336xgb.Put16(buf[b:], uint16(size/4)) // write request size in 4-byte units
337b += 2
338
339xgb.Put32(buf[b:], uint32(Shmseg))
340b += 4
341
342if ReadOnly {
343buf[b] = 1
344} else {
345buf[b] = 0
346}
347b += 1
348
349b += 3 // padding
350
351return buf
352}
353
354// CreatePixmapCookie is a cookie used only for CreatePixmap requests.
355type CreatePixmapCookie struct {
356*xgb.Cookie
357}
358
359// CreatePixmap sends an unchecked request.
360// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent.
361func CreatePixmap(c *xgb.Conn, Pid xproto.Pixmap, Drawable xproto.Drawable, Width uint16, Height uint16, Depth byte, Shmseg Seg, Offset uint32) CreatePixmapCookie {
362c.ExtLock.RLock()
363defer c.ExtLock.RUnlock()
364if _, ok := c.Extensions["MIT-SHM"]; !ok {
365panic("Cannot issue request 'CreatePixmap' using the uninitialized extension 'MIT-SHM'. shm.Init(connObj) must be called first.")
366}
367cookie := c.NewCookie(false, false)
368c.NewRequest(createPixmapRequest(c, Pid, Drawable, Width, Height, Depth, Shmseg, Offset), cookie)
369return CreatePixmapCookie{cookie}
370}
371
372// CreatePixmapChecked sends a checked request.
373// If an error occurs, it can be retrieved using CreatePixmapCookie.Check()
374func CreatePixmapChecked(c *xgb.Conn, Pid xproto.Pixmap, Drawable xproto.Drawable, Width uint16, Height uint16, Depth byte, Shmseg Seg, Offset uint32) CreatePixmapCookie {
375c.ExtLock.RLock()
376defer c.ExtLock.RUnlock()
377if _, ok := c.Extensions["MIT-SHM"]; !ok {
378panic("Cannot issue request 'CreatePixmap' using the uninitialized extension 'MIT-SHM'. shm.Init(connObj) must be called first.")
379}
380cookie := c.NewCookie(true, false)
381c.NewRequest(createPixmapRequest(c, Pid, Drawable, Width, Height, Depth, Shmseg, Offset), cookie)
382return CreatePixmapCookie{cookie}
383}
384
385// Check returns an error if one occurred for checked requests that are not expecting a reply.
386// This cannot be called for requests expecting a reply, nor for unchecked requests.
387func (cook CreatePixmapCookie) Check() error {
388return cook.Cookie.Check()
389}
390
391// Write request to wire for CreatePixmap
392// createPixmapRequest writes a CreatePixmap request to a byte slice.
393func createPixmapRequest(c *xgb.Conn, Pid xproto.Pixmap, Drawable xproto.Drawable, Width uint16, Height uint16, Depth byte, Shmseg Seg, Offset uint32) []byte {
394size := 28
395b := 0
396buf := make([]byte, size)
397
398c.ExtLock.RLock()
399buf[b] = c.Extensions["MIT-SHM"]
400c.ExtLock.RUnlock()
401b += 1
402
403buf[b] = 5 // request opcode
404b += 1
405
406xgb.Put16(buf[b:], uint16(size/4)) // write request size in 4-byte units
407b += 2
408
409xgb.Put32(buf[b:], uint32(Pid))
410b += 4
411
412xgb.Put32(buf[b:], uint32(Drawable))
413b += 4
414
415xgb.Put16(buf[b:], Width)
416b += 2
417
418xgb.Put16(buf[b:], Height)
419b += 2
420
421buf[b] = Depth
422b += 1
423
424b += 3 // padding
425
426xgb.Put32(buf[b:], uint32(Shmseg))
427b += 4
428
429xgb.Put32(buf[b:], Offset)
430b += 4
431
432return buf
433}
434
435// CreateSegmentCookie is a cookie used only for CreateSegment requests.
436type CreateSegmentCookie struct {
437*xgb.Cookie
438}
439
440// CreateSegment sends a checked request.
441// If an error occurs, it will be returned with the reply by calling CreateSegmentCookie.Reply()
442func CreateSegment(c *xgb.Conn, Shmseg Seg, Size uint32, ReadOnly bool) CreateSegmentCookie {
443c.ExtLock.RLock()
444defer c.ExtLock.RUnlock()
445if _, ok := c.Extensions["MIT-SHM"]; !ok {
446panic("Cannot issue request 'CreateSegment' using the uninitialized extension 'MIT-SHM'. shm.Init(connObj) must be called first.")
447}
448cookie := c.NewCookie(true, true)
449c.NewRequest(createSegmentRequest(c, Shmseg, Size, ReadOnly), cookie)
450return CreateSegmentCookie{cookie}
451}
452
453// CreateSegmentUnchecked sends an unchecked request.
454// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent.
455func CreateSegmentUnchecked(c *xgb.Conn, Shmseg Seg, Size uint32, ReadOnly bool) CreateSegmentCookie {
456c.ExtLock.RLock()
457defer c.ExtLock.RUnlock()
458if _, ok := c.Extensions["MIT-SHM"]; !ok {
459panic("Cannot issue request 'CreateSegment' using the uninitialized extension 'MIT-SHM'. shm.Init(connObj) must be called first.")
460}
461cookie := c.NewCookie(false, true)
462c.NewRequest(createSegmentRequest(c, Shmseg, Size, ReadOnly), cookie)
463return CreateSegmentCookie{cookie}
464}
465
466// CreateSegmentReply represents the data returned from a CreateSegment request.
467type CreateSegmentReply struct {
468Sequence uint16 // sequence number of the request for this reply
469Length uint32 // number of bytes in this reply
470Nfd byte
471// padding: 24 bytes
472}
473
474// Reply blocks and returns the reply data for a CreateSegment request.
475func (cook CreateSegmentCookie) Reply() (*CreateSegmentReply, error) {
476buf, err := cook.Cookie.Reply()
477if err != nil {
478return nil, err
479}
480if buf == nil {
481return nil, nil
482}
483return createSegmentReply(buf), nil
484}
485
486// createSegmentReply reads a byte slice into a CreateSegmentReply value.
487func createSegmentReply(buf []byte) *CreateSegmentReply {
488v := new(CreateSegmentReply)
489b := 1 // skip reply determinant
490
491v.Nfd = buf[b]
492b += 1
493
494v.Sequence = xgb.Get16(buf[b:])
495b += 2
496
497v.Length = xgb.Get32(buf[b:]) // 4-byte units
498b += 4
499
500b += 24 // padding
501
502return v
503}
504
505// Write request to wire for CreateSegment
506// createSegmentRequest writes a CreateSegment request to a byte slice.
507func createSegmentRequest(c *xgb.Conn, Shmseg Seg, Size uint32, ReadOnly bool) []byte {
508size := 16
509b := 0
510buf := make([]byte, size)
511
512c.ExtLock.RLock()
513buf[b] = c.Extensions["MIT-SHM"]
514c.ExtLock.RUnlock()
515b += 1
516
517buf[b] = 7 // request opcode
518b += 1
519
520xgb.Put16(buf[b:], uint16(size/4)) // write request size in 4-byte units
521b += 2
522
523xgb.Put32(buf[b:], uint32(Shmseg))
524b += 4
525
526xgb.Put32(buf[b:], Size)
527b += 4
528
529if ReadOnly {
530buf[b] = 1
531} else {
532buf[b] = 0
533}
534b += 1
535
536b += 3 // padding
537
538return buf
539}
540
541// DetachCookie is a cookie used only for Detach requests.
542type DetachCookie struct {
543*xgb.Cookie
544}
545
546// Detach sends an unchecked request.
547// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent.
548func Detach(c *xgb.Conn, Shmseg Seg) DetachCookie {
549c.ExtLock.RLock()
550defer c.ExtLock.RUnlock()
551if _, ok := c.Extensions["MIT-SHM"]; !ok {
552panic("Cannot issue request 'Detach' using the uninitialized extension 'MIT-SHM'. shm.Init(connObj) must be called first.")
553}
554cookie := c.NewCookie(false, false)
555c.NewRequest(detachRequest(c, Shmseg), cookie)
556return DetachCookie{cookie}
557}
558
559// DetachChecked sends a checked request.
560// If an error occurs, it can be retrieved using DetachCookie.Check()
561func DetachChecked(c *xgb.Conn, Shmseg Seg) DetachCookie {
562c.ExtLock.RLock()
563defer c.ExtLock.RUnlock()
564if _, ok := c.Extensions["MIT-SHM"]; !ok {
565panic("Cannot issue request 'Detach' using the uninitialized extension 'MIT-SHM'. shm.Init(connObj) must be called first.")
566}
567cookie := c.NewCookie(true, false)
568c.NewRequest(detachRequest(c, Shmseg), cookie)
569return DetachCookie{cookie}
570}
571
572// Check returns an error if one occurred for checked requests that are not expecting a reply.
573// This cannot be called for requests expecting a reply, nor for unchecked requests.
574func (cook DetachCookie) Check() error {
575return cook.Cookie.Check()
576}
577
578// Write request to wire for Detach
579// detachRequest writes a Detach request to a byte slice.
580func detachRequest(c *xgb.Conn, Shmseg Seg) []byte {
581size := 8
582b := 0
583buf := make([]byte, size)
584
585c.ExtLock.RLock()
586buf[b] = c.Extensions["MIT-SHM"]
587c.ExtLock.RUnlock()
588b += 1
589
590buf[b] = 2 // request opcode
591b += 1
592
593xgb.Put16(buf[b:], uint16(size/4)) // write request size in 4-byte units
594b += 2
595
596xgb.Put32(buf[b:], uint32(Shmseg))
597b += 4
598
599return buf
600}
601
602// GetImageCookie is a cookie used only for GetImage requests.
603type GetImageCookie struct {
604*xgb.Cookie
605}
606
607// GetImage sends a checked request.
608// If an error occurs, it will be returned with the reply by calling GetImageCookie.Reply()
609func GetImage(c *xgb.Conn, Drawable xproto.Drawable, X int16, Y int16, Width uint16, Height uint16, PlaneMask uint32, Format byte, Shmseg Seg, Offset uint32) GetImageCookie {
610c.ExtLock.RLock()
611defer c.ExtLock.RUnlock()
612if _, ok := c.Extensions["MIT-SHM"]; !ok {
613panic("Cannot issue request 'GetImage' using the uninitialized extension 'MIT-SHM'. shm.Init(connObj) must be called first.")
614}
615cookie := c.NewCookie(true, true)
616c.NewRequest(getImageRequest(c, Drawable, X, Y, Width, Height, PlaneMask, Format, Shmseg, Offset), cookie)
617return GetImageCookie{cookie}
618}
619
620// GetImageUnchecked sends an unchecked request.
621// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent.
622func GetImageUnchecked(c *xgb.Conn, Drawable xproto.Drawable, X int16, Y int16, Width uint16, Height uint16, PlaneMask uint32, Format byte, Shmseg Seg, Offset uint32) GetImageCookie {
623c.ExtLock.RLock()
624defer c.ExtLock.RUnlock()
625if _, ok := c.Extensions["MIT-SHM"]; !ok {
626panic("Cannot issue request 'GetImage' using the uninitialized extension 'MIT-SHM'. shm.Init(connObj) must be called first.")
627}
628cookie := c.NewCookie(false, true)
629c.NewRequest(getImageRequest(c, Drawable, X, Y, Width, Height, PlaneMask, Format, Shmseg, Offset), cookie)
630return GetImageCookie{cookie}
631}
632
633// GetImageReply represents the data returned from a GetImage request.
634type GetImageReply struct {
635Sequence uint16 // sequence number of the request for this reply
636Length uint32 // number of bytes in this reply
637Depth byte
638Visual xproto.Visualid
639Size uint32
640}
641
642// Reply blocks and returns the reply data for a GetImage request.
643func (cook GetImageCookie) Reply() (*GetImageReply, error) {
644buf, err := cook.Cookie.Reply()
645if err != nil {
646return nil, err
647}
648if buf == nil {
649return nil, nil
650}
651return getImageReply(buf), nil
652}
653
654// getImageReply reads a byte slice into a GetImageReply value.
655func getImageReply(buf []byte) *GetImageReply {
656v := new(GetImageReply)
657b := 1 // skip reply determinant
658
659v.Depth = buf[b]
660b += 1
661
662v.Sequence = xgb.Get16(buf[b:])
663b += 2
664
665v.Length = xgb.Get32(buf[b:]) // 4-byte units
666b += 4
667
668v.Visual = xproto.Visualid(xgb.Get32(buf[b:]))
669b += 4
670
671v.Size = xgb.Get32(buf[b:])
672b += 4
673
674return v
675}
676
677// Write request to wire for GetImage
678// getImageRequest writes a GetImage request to a byte slice.
679func getImageRequest(c *xgb.Conn, Drawable xproto.Drawable, X int16, Y int16, Width uint16, Height uint16, PlaneMask uint32, Format byte, Shmseg Seg, Offset uint32) []byte {
680size := 32
681b := 0
682buf := make([]byte, size)
683
684c.ExtLock.RLock()
685buf[b] = c.Extensions["MIT-SHM"]
686c.ExtLock.RUnlock()
687b += 1
688
689buf[b] = 4 // request opcode
690b += 1
691
692xgb.Put16(buf[b:], uint16(size/4)) // write request size in 4-byte units
693b += 2
694
695xgb.Put32(buf[b:], uint32(Drawable))
696b += 4
697
698xgb.Put16(buf[b:], uint16(X))
699b += 2
700
701xgb.Put16(buf[b:], uint16(Y))
702b += 2
703
704xgb.Put16(buf[b:], Width)
705b += 2
706
707xgb.Put16(buf[b:], Height)
708b += 2
709
710xgb.Put32(buf[b:], PlaneMask)
711b += 4
712
713buf[b] = Format
714b += 1
715
716b += 3 // padding
717
718xgb.Put32(buf[b:], uint32(Shmseg))
719b += 4
720
721xgb.Put32(buf[b:], Offset)
722b += 4
723
724return buf
725}
726
727// PutImageCookie is a cookie used only for PutImage requests.
728type PutImageCookie struct {
729*xgb.Cookie
730}
731
732// PutImage sends an unchecked request.
733// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent.
734func PutImage(c *xgb.Conn, Drawable xproto.Drawable, Gc xproto.Gcontext, TotalWidth uint16, TotalHeight uint16, SrcX uint16, SrcY uint16, SrcWidth uint16, SrcHeight uint16, DstX int16, DstY int16, Depth byte, Format byte, SendEvent byte, Shmseg Seg, Offset uint32) PutImageCookie {
735c.ExtLock.RLock()
736defer c.ExtLock.RUnlock()
737if _, ok := c.Extensions["MIT-SHM"]; !ok {
738panic("Cannot issue request 'PutImage' using the uninitialized extension 'MIT-SHM'. shm.Init(connObj) must be called first.")
739}
740cookie := c.NewCookie(false, false)
741c.NewRequest(putImageRequest(c, Drawable, Gc, TotalWidth, TotalHeight, SrcX, SrcY, SrcWidth, SrcHeight, DstX, DstY, Depth, Format, SendEvent, Shmseg, Offset), cookie)
742return PutImageCookie{cookie}
743}
744
745// PutImageChecked sends a checked request.
746// If an error occurs, it can be retrieved using PutImageCookie.Check()
747func PutImageChecked(c *xgb.Conn, Drawable xproto.Drawable, Gc xproto.Gcontext, TotalWidth uint16, TotalHeight uint16, SrcX uint16, SrcY uint16, SrcWidth uint16, SrcHeight uint16, DstX int16, DstY int16, Depth byte, Format byte, SendEvent byte, Shmseg Seg, Offset uint32) PutImageCookie {
748c.ExtLock.RLock()
749defer c.ExtLock.RUnlock()
750if _, ok := c.Extensions["MIT-SHM"]; !ok {
751panic("Cannot issue request 'PutImage' using the uninitialized extension 'MIT-SHM'. shm.Init(connObj) must be called first.")
752}
753cookie := c.NewCookie(true, false)
754c.NewRequest(putImageRequest(c, Drawable, Gc, TotalWidth, TotalHeight, SrcX, SrcY, SrcWidth, SrcHeight, DstX, DstY, Depth, Format, SendEvent, Shmseg, Offset), cookie)
755return PutImageCookie{cookie}
756}
757
758// Check returns an error if one occurred for checked requests that are not expecting a reply.
759// This cannot be called for requests expecting a reply, nor for unchecked requests.
760func (cook PutImageCookie) Check() error {
761return cook.Cookie.Check()
762}
763
764// Write request to wire for PutImage
765// putImageRequest writes a PutImage request to a byte slice.
766func putImageRequest(c *xgb.Conn, Drawable xproto.Drawable, Gc xproto.Gcontext, TotalWidth uint16, TotalHeight uint16, SrcX uint16, SrcY uint16, SrcWidth uint16, SrcHeight uint16, DstX int16, DstY int16, Depth byte, Format byte, SendEvent byte, Shmseg Seg, Offset uint32) []byte {
767size := 40
768b := 0
769buf := make([]byte, size)
770
771c.ExtLock.RLock()
772buf[b] = c.Extensions["MIT-SHM"]
773c.ExtLock.RUnlock()
774b += 1
775
776buf[b] = 3 // request opcode
777b += 1
778
779xgb.Put16(buf[b:], uint16(size/4)) // write request size in 4-byte units
780b += 2
781
782xgb.Put32(buf[b:], uint32(Drawable))
783b += 4
784
785xgb.Put32(buf[b:], uint32(Gc))
786b += 4
787
788xgb.Put16(buf[b:], TotalWidth)
789b += 2
790
791xgb.Put16(buf[b:], TotalHeight)
792b += 2
793
794xgb.Put16(buf[b:], SrcX)
795b += 2
796
797xgb.Put16(buf[b:], SrcY)
798b += 2
799
800xgb.Put16(buf[b:], SrcWidth)
801b += 2
802
803xgb.Put16(buf[b:], SrcHeight)
804b += 2
805
806xgb.Put16(buf[b:], uint16(DstX))
807b += 2
808
809xgb.Put16(buf[b:], uint16(DstY))
810b += 2
811
812buf[b] = Depth
813b += 1
814
815buf[b] = Format
816b += 1
817
818buf[b] = SendEvent
819b += 1
820
821b += 1 // padding
822
823xgb.Put32(buf[b:], uint32(Shmseg))
824b += 4
825
826xgb.Put32(buf[b:], Offset)
827b += 4
828
829return buf
830}
831
832// QueryVersionCookie is a cookie used only for QueryVersion requests.
833type QueryVersionCookie struct {
834*xgb.Cookie
835}
836
837// QueryVersion sends a checked request.
838// If an error occurs, it will be returned with the reply by calling QueryVersionCookie.Reply()
839func QueryVersion(c *xgb.Conn) QueryVersionCookie {
840c.ExtLock.RLock()
841defer c.ExtLock.RUnlock()
842if _, ok := c.Extensions["MIT-SHM"]; !ok {
843panic("Cannot issue request 'QueryVersion' using the uninitialized extension 'MIT-SHM'. shm.Init(connObj) must be called first.")
844}
845cookie := c.NewCookie(true, true)
846c.NewRequest(queryVersionRequest(c), cookie)
847return QueryVersionCookie{cookie}
848}
849
850// QueryVersionUnchecked sends an unchecked request.
851// If an error occurs, it can only be retrieved using xgb.WaitForEvent or xgb.PollForEvent.
852func QueryVersionUnchecked(c *xgb.Conn) QueryVersionCookie {
853c.ExtLock.RLock()
854defer c.ExtLock.RUnlock()
855if _, ok := c.Extensions["MIT-SHM"]; !ok {
856panic("Cannot issue request 'QueryVersion' using the uninitialized extension 'MIT-SHM'. shm.Init(connObj) must be called first.")
857}
858cookie := c.NewCookie(false, true)
859c.NewRequest(queryVersionRequest(c), cookie)
860return QueryVersionCookie{cookie}
861}
862
863// QueryVersionReply represents the data returned from a QueryVersion request.
864type QueryVersionReply struct {
865Sequence uint16 // sequence number of the request for this reply
866Length uint32 // number of bytes in this reply
867SharedPixmaps bool
868MajorVersion uint16
869MinorVersion uint16
870Uid uint16
871Gid uint16
872PixmapFormat byte
873// padding: 15 bytes
874}
875
876// Reply blocks and returns the reply data for a QueryVersion request.
877func (cook QueryVersionCookie) Reply() (*QueryVersionReply, error) {
878buf, err := cook.Cookie.Reply()
879if err != nil {
880return nil, err
881}
882if buf == nil {
883return nil, nil
884}
885return queryVersionReply(buf), nil
886}
887
888// queryVersionReply reads a byte slice into a QueryVersionReply value.
889func queryVersionReply(buf []byte) *QueryVersionReply {
890v := new(QueryVersionReply)
891b := 1 // skip reply determinant
892
893if buf[b] == 1 {
894v.SharedPixmaps = true
895} else {
896v.SharedPixmaps = false
897}
898b += 1
899
900v.Sequence = xgb.Get16(buf[b:])
901b += 2
902
903v.Length = xgb.Get32(buf[b:]) // 4-byte units
904b += 4
905
906v.MajorVersion = xgb.Get16(buf[b:])
907b += 2
908
909v.MinorVersion = xgb.Get16(buf[b:])
910b += 2
911
912v.Uid = xgb.Get16(buf[b:])
913b += 2
914
915v.Gid = xgb.Get16(buf[b:])
916b += 2
917
918v.PixmapFormat = buf[b]
919b += 1
920
921b += 15 // padding
922
923return v
924}
925
926// Write request to wire for QueryVersion
927// queryVersionRequest writes a QueryVersion request to a byte slice.
928func queryVersionRequest(c *xgb.Conn) []byte {
929size := 4
930b := 0
931buf := make([]byte, size)
932
933c.ExtLock.RLock()
934buf[b] = c.Extensions["MIT-SHM"]
935c.ExtLock.RUnlock()
936b += 1
937
938buf[b] = 0 // request opcode
939b += 1
940
941xgb.Put16(buf[b:], uint16(size/4)) // write request size in 4-byte units
942b += 2
943
944return buf
945}
946