1
2 package res
3
4
5
6 import (
7 "github.com/jezek/xgb"
8
9 "github.com/jezek/xgb/xproto"
10 )
11
12
13 func Init(c *xgb.Conn) error {
14 reply, err := xproto.QueryExtension(c, 10, "X-Resource").Reply()
15 switch {
16 case err != nil:
17 return err
18 case !reply.Present:
19 return xgb.Errorf("No extension named X-Resource could be found on on the server.")
20 }
21
22 c.ExtLock.Lock()
23 c.Extensions["X-Resource"] = reply.MajorOpcode
24 c.ExtLock.Unlock()
25 for evNum, fun := range xgb.NewExtEventFuncs["X-Resource"] {
26 xgb.NewEventFuncs[int(reply.FirstEvent)+evNum] = fun
27 }
28 for errNum, fun := range xgb.NewExtErrorFuncs["X-Resource"] {
29 xgb.NewErrorFuncs[int(reply.FirstError)+errNum] = fun
30 }
31 return nil
32 }
33
34 func init() {
35 xgb.NewExtEventFuncs["X-Resource"] = make(map[int]xgb.NewEventFun)
36 xgb.NewExtErrorFuncs["X-Resource"] = make(map[int]xgb.NewErrorFun)
37 }
38
39 type Client struct {
40 ResourceBase uint32
41 ResourceMask uint32
42 }
43
44
45 func ClientRead(buf []byte, v *Client) int {
46 b := 0
47
48 v.ResourceBase = xgb.Get32(buf[b:])
49 b += 4
50
51 v.ResourceMask = xgb.Get32(buf[b:])
52 b += 4
53
54 return b
55 }
56
57
58 func ClientReadList(buf []byte, dest []Client) int {
59 b := 0
60 for i := 0; i < len(dest); i++ {
61 dest[i] = Client{}
62 b += ClientRead(buf[b:], &dest[i])
63 }
64 return xgb.Pad(b)
65 }
66
67
68 func (v Client) Bytes() []byte {
69 buf := make([]byte, 8)
70 b := 0
71
72 xgb.Put32(buf[b:], v.ResourceBase)
73 b += 4
74
75 xgb.Put32(buf[b:], v.ResourceMask)
76 b += 4
77
78 return buf[:b]
79 }
80
81
82 func ClientListBytes(buf []byte, list []Client) int {
83 b := 0
84 var structBytes []byte
85 for _, item := range list {
86 structBytes = item.Bytes()
87 copy(buf[b:], structBytes)
88 b += len(structBytes)
89 }
90 return xgb.Pad(b)
91 }
92
93 const (
94 ClientIdMaskClientXID = 1
95 ClientIdMaskLocalClientPID = 2
96 )
97
98 type ClientIdSpec struct {
99 Client uint32
100 Mask uint32
101 }
102
103
104 func ClientIdSpecRead(buf []byte, v *ClientIdSpec) int {
105 b := 0
106
107 v.Client = xgb.Get32(buf[b:])
108 b += 4
109
110 v.Mask = xgb.Get32(buf[b:])
111 b += 4
112
113 return b
114 }
115
116
117 func ClientIdSpecReadList(buf []byte, dest []ClientIdSpec) int {
118 b := 0
119 for i := 0; i < len(dest); i++ {
120 dest[i] = ClientIdSpec{}
121 b += ClientIdSpecRead(buf[b:], &dest[i])
122 }
123 return xgb.Pad(b)
124 }
125
126
127 func (v ClientIdSpec) Bytes() []byte {
128 buf := make([]byte, 8)
129 b := 0
130
131 xgb.Put32(buf[b:], v.Client)
132 b += 4
133
134 xgb.Put32(buf[b:], v.Mask)
135 b += 4
136
137 return buf[:b]
138 }
139
140
141 func ClientIdSpecListBytes(buf []byte, list []ClientIdSpec) int {
142 b := 0
143 var structBytes []byte
144 for _, item := range list {
145 structBytes = item.Bytes()
146 copy(buf[b:], structBytes)
147 b += len(structBytes)
148 }
149 return xgb.Pad(b)
150 }
151
152 type ClientIdValue struct {
153 Spec ClientIdSpec
154 Length uint32
155 Value []uint32
156 }
157
158
159 func ClientIdValueRead(buf []byte, v *ClientIdValue) int {
160 b := 0
161
162 v.Spec = ClientIdSpec{}
163 b += ClientIdSpecRead(buf[b:], &v.Spec)
164
165 v.Length = xgb.Get32(buf[b:])
166 b += 4
167
168 v.Value = make([]uint32, v.Length)
169 for i := 0; i < int(v.Length); i++ {
170 v.Value[i] = xgb.Get32(buf[b:])
171 b += 4
172 }
173
174 return b
175 }
176
177
178 func ClientIdValueReadList(buf []byte, dest []ClientIdValue) int {
179 b := 0
180 for i := 0; i < len(dest); i++ {
181 dest[i] = ClientIdValue{}
182 b += ClientIdValueRead(buf[b:], &dest[i])
183 }
184 return xgb.Pad(b)
185 }
186
187
188 func (v ClientIdValue) Bytes() []byte {
189 buf := make([]byte, (12 + xgb.Pad((int(v.Length) * 4))))
190 b := 0
191
192 {
193 structBytes := v.Spec.Bytes()
194 copy(buf[b:], structBytes)
195 b += len(structBytes)
196 }
197
198 xgb.Put32(buf[b:], v.Length)
199 b += 4
200
201 for i := 0; i < int(v.Length); i++ {
202 xgb.Put32(buf[b:], v.Value[i])
203 b += 4
204 }
205
206 return buf[:b]
207 }
208
209
210 func ClientIdValueListBytes(buf []byte, list []ClientIdValue) int {
211 b := 0
212 var structBytes []byte
213 for _, item := range list {
214 structBytes = item.Bytes()
215 copy(buf[b:], structBytes)
216 b += len(structBytes)
217 }
218 return xgb.Pad(b)
219 }
220
221
222 func ClientIdValueListSize(list []ClientIdValue) int {
223 size := 0
224 for _, item := range list {
225 size += (12 + xgb.Pad((int(item.Length) * 4)))
226 }
227 return size
228 }
229
230 type ResourceIdSpec struct {
231 Resource uint32
232 Type uint32
233 }
234
235
236 func ResourceIdSpecRead(buf []byte, v *ResourceIdSpec) int {
237 b := 0
238
239 v.Resource = xgb.Get32(buf[b:])
240 b += 4
241
242 v.Type = xgb.Get32(buf[b:])
243 b += 4
244
245 return b
246 }
247
248
249 func ResourceIdSpecReadList(buf []byte, dest []ResourceIdSpec) int {
250 b := 0
251 for i := 0; i < len(dest); i++ {
252 dest[i] = ResourceIdSpec{}
253 b += ResourceIdSpecRead(buf[b:], &dest[i])
254 }
255 return xgb.Pad(b)
256 }
257
258
259 func (v ResourceIdSpec) Bytes() []byte {
260 buf := make([]byte, 8)
261 b := 0
262
263 xgb.Put32(buf[b:], v.Resource)
264 b += 4
265
266 xgb.Put32(buf[b:], v.Type)
267 b += 4
268
269 return buf[:b]
270 }
271
272
273 func ResourceIdSpecListBytes(buf []byte, list []ResourceIdSpec) int {
274 b := 0
275 var structBytes []byte
276 for _, item := range list {
277 structBytes = item.Bytes()
278 copy(buf[b:], structBytes)
279 b += len(structBytes)
280 }
281 return xgb.Pad(b)
282 }
283
284 type ResourceSizeSpec struct {
285 Spec ResourceIdSpec
286 Bytes_ uint32
287 RefCount uint32
288 UseCount uint32
289 }
290
291
292 func ResourceSizeSpecRead(buf []byte, v *ResourceSizeSpec) int {
293 b := 0
294
295 v.Spec = ResourceIdSpec{}
296 b += ResourceIdSpecRead(buf[b:], &v.Spec)
297
298 v.Bytes_ = xgb.Get32(buf[b:])
299 b += 4
300
301 v.RefCount = xgb.Get32(buf[b:])
302 b += 4
303
304 v.UseCount = xgb.Get32(buf[b:])
305 b += 4
306
307 return b
308 }
309
310
311 func ResourceSizeSpecReadList(buf []byte, dest []ResourceSizeSpec) int {
312 b := 0
313 for i := 0; i < len(dest); i++ {
314 dest[i] = ResourceSizeSpec{}
315 b += ResourceSizeSpecRead(buf[b:], &dest[i])
316 }
317 return xgb.Pad(b)
318 }
319
320
321 func (v ResourceSizeSpec) Bytes() []byte {
322 buf := make([]byte, 20)
323 b := 0
324
325 {
326 structBytes := v.Spec.Bytes()
327 copy(buf[b:], structBytes)
328 b += len(structBytes)
329 }
330
331 xgb.Put32(buf[b:], v.Bytes_)
332 b += 4
333
334 xgb.Put32(buf[b:], v.RefCount)
335 b += 4
336
337 xgb.Put32(buf[b:], v.UseCount)
338 b += 4
339
340 return buf[:b]
341 }
342
343
344 func ResourceSizeSpecListBytes(buf []byte, list []ResourceSizeSpec) int {
345 b := 0
346 var structBytes []byte
347 for _, item := range list {
348 structBytes = item.Bytes()
349 copy(buf[b:], structBytes)
350 b += len(structBytes)
351 }
352 return xgb.Pad(b)
353 }
354
355 type ResourceSizeValue struct {
356 Size ResourceSizeSpec
357 NumCrossReferences uint32
358 CrossReferences []ResourceSizeSpec
359 }
360
361
362 func ResourceSizeValueRead(buf []byte, v *ResourceSizeValue) int {
363 b := 0
364
365 v.Size = ResourceSizeSpec{}
366 b += ResourceSizeSpecRead(buf[b:], &v.Size)
367
368 v.NumCrossReferences = xgb.Get32(buf[b:])
369 b += 4
370
371 v.CrossReferences = make([]ResourceSizeSpec, v.NumCrossReferences)
372 b += ResourceSizeSpecReadList(buf[b:], v.CrossReferences)
373
374 return b
375 }
376
377
378 func ResourceSizeValueReadList(buf []byte, dest []ResourceSizeValue) int {
379 b := 0
380 for i := 0; i < len(dest); i++ {
381 dest[i] = ResourceSizeValue{}
382 b += ResourceSizeValueRead(buf[b:], &dest[i])
383 }
384 return xgb.Pad(b)
385 }
386
387
388 func (v ResourceSizeValue) Bytes() []byte {
389 buf := make([]byte, (24 + xgb.Pad((int(v.NumCrossReferences) * 20))))
390 b := 0
391
392 {
393 structBytes := v.Size.Bytes()
394 copy(buf[b:], structBytes)
395 b += len(structBytes)
396 }
397
398 xgb.Put32(buf[b:], v.NumCrossReferences)
399 b += 4
400
401 b += ResourceSizeSpecListBytes(buf[b:], v.CrossReferences)
402
403 return buf[:b]
404 }
405
406
407 func ResourceSizeValueListBytes(buf []byte, list []ResourceSizeValue) int {
408 b := 0
409 var structBytes []byte
410 for _, item := range list {
411 structBytes = item.Bytes()
412 copy(buf[b:], structBytes)
413 b += len(structBytes)
414 }
415 return xgb.Pad(b)
416 }
417
418
419 func ResourceSizeValueListSize(list []ResourceSizeValue) int {
420 size := 0
421 for _, item := range list {
422 size += (24 + xgb.Pad((int(item.NumCrossReferences) * 20)))
423 }
424 return size
425 }
426
427 type Type struct {
428 ResourceType xproto.Atom
429 Count uint32
430 }
431
432
433 func TypeRead(buf []byte, v *Type) int {
434 b := 0
435
436 v.ResourceType = xproto.Atom(xgb.Get32(buf[b:]))
437 b += 4
438
439 v.Count = xgb.Get32(buf[b:])
440 b += 4
441
442 return b
443 }
444
445
446 func TypeReadList(buf []byte, dest []Type) int {
447 b := 0
448 for i := 0; i < len(dest); i++ {
449 dest[i] = Type{}
450 b += TypeRead(buf[b:], &dest[i])
451 }
452 return xgb.Pad(b)
453 }
454
455
456 func (v Type) Bytes() []byte {
457 buf := make([]byte, 8)
458 b := 0
459
460 xgb.Put32(buf[b:], uint32(v.ResourceType))
461 b += 4
462
463 xgb.Put32(buf[b:], v.Count)
464 b += 4
465
466 return buf[:b]
467 }
468
469
470 func TypeListBytes(buf []byte, list []Type) int {
471 b := 0
472 var structBytes []byte
473 for _, item := range list {
474 structBytes = item.Bytes()
475 copy(buf[b:], structBytes)
476 b += len(structBytes)
477 }
478 return xgb.Pad(b)
479 }
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506 type QueryClientIdsCookie struct {
507 *xgb.Cookie
508 }
509
510
511
512 func QueryClientIds(c *xgb.Conn, NumSpecs uint32, Specs []ClientIdSpec) QueryClientIdsCookie {
513 c.ExtLock.RLock()
514 defer c.ExtLock.RUnlock()
515 if _, ok := c.Extensions["X-Resource"]; !ok {
516 panic("Cannot issue request 'QueryClientIds' using the uninitialized extension 'X-Resource'. res.Init(connObj) must be called first.")
517 }
518 cookie := c.NewCookie(true, true)
519 c.NewRequest(queryClientIdsRequest(c, NumSpecs, Specs), cookie)
520 return QueryClientIdsCookie{cookie}
521 }
522
523
524
525 func QueryClientIdsUnchecked(c *xgb.Conn, NumSpecs uint32, Specs []ClientIdSpec) QueryClientIdsCookie {
526 c.ExtLock.RLock()
527 defer c.ExtLock.RUnlock()
528 if _, ok := c.Extensions["X-Resource"]; !ok {
529 panic("Cannot issue request 'QueryClientIds' using the uninitialized extension 'X-Resource'. res.Init(connObj) must be called first.")
530 }
531 cookie := c.NewCookie(false, true)
532 c.NewRequest(queryClientIdsRequest(c, NumSpecs, Specs), cookie)
533 return QueryClientIdsCookie{cookie}
534 }
535
536
537 type QueryClientIdsReply struct {
538 Sequence uint16
539 Length uint32
540
541 NumIds uint32
542
543 Ids []ClientIdValue
544 }
545
546
547 func (cook QueryClientIdsCookie) Reply() (*QueryClientIdsReply, error) {
548 buf, err := cook.Cookie.Reply()
549 if err != nil {
550 return nil, err
551 }
552 if buf == nil {
553 return nil, nil
554 }
555 return queryClientIdsReply(buf), nil
556 }
557
558
559 func queryClientIdsReply(buf []byte) *QueryClientIdsReply {
560 v := new(QueryClientIdsReply)
561 b := 1
562
563 b += 1
564
565 v.Sequence = xgb.Get16(buf[b:])
566 b += 2
567
568 v.Length = xgb.Get32(buf[b:])
569 b += 4
570
571 v.NumIds = xgb.Get32(buf[b:])
572 b += 4
573
574 b += 20
575
576 v.Ids = make([]ClientIdValue, v.NumIds)
577 b += ClientIdValueReadList(buf[b:], v.Ids)
578
579 return v
580 }
581
582
583
584 func queryClientIdsRequest(c *xgb.Conn, NumSpecs uint32, Specs []ClientIdSpec) []byte {
585 size := xgb.Pad((8 + xgb.Pad((int(NumSpecs) * 8))))
586 b := 0
587 buf := make([]byte, size)
588
589 c.ExtLock.RLock()
590 buf[b] = c.Extensions["X-Resource"]
591 c.ExtLock.RUnlock()
592 b += 1
593
594 buf[b] = 4
595 b += 1
596
597 xgb.Put16(buf[b:], uint16(size/4))
598 b += 2
599
600 xgb.Put32(buf[b:], NumSpecs)
601 b += 4
602
603 b += ClientIdSpecListBytes(buf[b:], Specs)
604
605 return buf
606 }
607
608
609 type QueryClientPixmapBytesCookie struct {
610 *xgb.Cookie
611 }
612
613
614
615 func QueryClientPixmapBytes(c *xgb.Conn, Xid uint32) QueryClientPixmapBytesCookie {
616 c.ExtLock.RLock()
617 defer c.ExtLock.RUnlock()
618 if _, ok := c.Extensions["X-Resource"]; !ok {
619 panic("Cannot issue request 'QueryClientPixmapBytes' using the uninitialized extension 'X-Resource'. res.Init(connObj) must be called first.")
620 }
621 cookie := c.NewCookie(true, true)
622 c.NewRequest(queryClientPixmapBytesRequest(c, Xid), cookie)
623 return QueryClientPixmapBytesCookie{cookie}
624 }
625
626
627
628 func QueryClientPixmapBytesUnchecked(c *xgb.Conn, Xid uint32) QueryClientPixmapBytesCookie {
629 c.ExtLock.RLock()
630 defer c.ExtLock.RUnlock()
631 if _, ok := c.Extensions["X-Resource"]; !ok {
632 panic("Cannot issue request 'QueryClientPixmapBytes' using the uninitialized extension 'X-Resource'. res.Init(connObj) must be called first.")
633 }
634 cookie := c.NewCookie(false, true)
635 c.NewRequest(queryClientPixmapBytesRequest(c, Xid), cookie)
636 return QueryClientPixmapBytesCookie{cookie}
637 }
638
639
640 type QueryClientPixmapBytesReply struct {
641 Sequence uint16
642 Length uint32
643
644 Bytes_ uint32
645 BytesOverflow uint32
646 }
647
648
649 func (cook QueryClientPixmapBytesCookie) Reply() (*QueryClientPixmapBytesReply, error) {
650 buf, err := cook.Cookie.Reply()
651 if err != nil {
652 return nil, err
653 }
654 if buf == nil {
655 return nil, nil
656 }
657 return queryClientPixmapBytesReply(buf), nil
658 }
659
660
661 func queryClientPixmapBytesReply(buf []byte) *QueryClientPixmapBytesReply {
662 v := new(QueryClientPixmapBytesReply)
663 b := 1
664
665 b += 1
666
667 v.Sequence = xgb.Get16(buf[b:])
668 b += 2
669
670 v.Length = xgb.Get32(buf[b:])
671 b += 4
672
673 v.Bytes_ = xgb.Get32(buf[b:])
674 b += 4
675
676 v.BytesOverflow = xgb.Get32(buf[b:])
677 b += 4
678
679 return v
680 }
681
682
683
684 func queryClientPixmapBytesRequest(c *xgb.Conn, Xid uint32) []byte {
685 size := 8
686 b := 0
687 buf := make([]byte, size)
688
689 c.ExtLock.RLock()
690 buf[b] = c.Extensions["X-Resource"]
691 c.ExtLock.RUnlock()
692 b += 1
693
694 buf[b] = 3
695 b += 1
696
697 xgb.Put16(buf[b:], uint16(size/4))
698 b += 2
699
700 xgb.Put32(buf[b:], Xid)
701 b += 4
702
703 return buf
704 }
705
706
707 type QueryClientResourcesCookie struct {
708 *xgb.Cookie
709 }
710
711
712
713 func QueryClientResources(c *xgb.Conn, Xid uint32) QueryClientResourcesCookie {
714 c.ExtLock.RLock()
715 defer c.ExtLock.RUnlock()
716 if _, ok := c.Extensions["X-Resource"]; !ok {
717 panic("Cannot issue request 'QueryClientResources' using the uninitialized extension 'X-Resource'. res.Init(connObj) must be called first.")
718 }
719 cookie := c.NewCookie(true, true)
720 c.NewRequest(queryClientResourcesRequest(c, Xid), cookie)
721 return QueryClientResourcesCookie{cookie}
722 }
723
724
725
726 func QueryClientResourcesUnchecked(c *xgb.Conn, Xid uint32) QueryClientResourcesCookie {
727 c.ExtLock.RLock()
728 defer c.ExtLock.RUnlock()
729 if _, ok := c.Extensions["X-Resource"]; !ok {
730 panic("Cannot issue request 'QueryClientResources' using the uninitialized extension 'X-Resource'. res.Init(connObj) must be called first.")
731 }
732 cookie := c.NewCookie(false, true)
733 c.NewRequest(queryClientResourcesRequest(c, Xid), cookie)
734 return QueryClientResourcesCookie{cookie}
735 }
736
737
738 type QueryClientResourcesReply struct {
739 Sequence uint16
740 Length uint32
741
742 NumTypes uint32
743
744 Types []Type
745 }
746
747
748 func (cook QueryClientResourcesCookie) Reply() (*QueryClientResourcesReply, error) {
749 buf, err := cook.Cookie.Reply()
750 if err != nil {
751 return nil, err
752 }
753 if buf == nil {
754 return nil, nil
755 }
756 return queryClientResourcesReply(buf), nil
757 }
758
759
760 func queryClientResourcesReply(buf []byte) *QueryClientResourcesReply {
761 v := new(QueryClientResourcesReply)
762 b := 1
763
764 b += 1
765
766 v.Sequence = xgb.Get16(buf[b:])
767 b += 2
768
769 v.Length = xgb.Get32(buf[b:])
770 b += 4
771
772 v.NumTypes = xgb.Get32(buf[b:])
773 b += 4
774
775 b += 20
776
777 v.Types = make([]Type, v.NumTypes)
778 b += TypeReadList(buf[b:], v.Types)
779
780 return v
781 }
782
783
784
785 func queryClientResourcesRequest(c *xgb.Conn, Xid uint32) []byte {
786 size := 8
787 b := 0
788 buf := make([]byte, size)
789
790 c.ExtLock.RLock()
791 buf[b] = c.Extensions["X-Resource"]
792 c.ExtLock.RUnlock()
793 b += 1
794
795 buf[b] = 2
796 b += 1
797
798 xgb.Put16(buf[b:], uint16(size/4))
799 b += 2
800
801 xgb.Put32(buf[b:], Xid)
802 b += 4
803
804 return buf
805 }
806
807
808 type QueryClientsCookie struct {
809 *xgb.Cookie
810 }
811
812
813
814 func QueryClients(c *xgb.Conn) QueryClientsCookie {
815 c.ExtLock.RLock()
816 defer c.ExtLock.RUnlock()
817 if _, ok := c.Extensions["X-Resource"]; !ok {
818 panic("Cannot issue request 'QueryClients' using the uninitialized extension 'X-Resource'. res.Init(connObj) must be called first.")
819 }
820 cookie := c.NewCookie(true, true)
821 c.NewRequest(queryClientsRequest(c), cookie)
822 return QueryClientsCookie{cookie}
823 }
824
825
826
827 func QueryClientsUnchecked(c *xgb.Conn) QueryClientsCookie {
828 c.ExtLock.RLock()
829 defer c.ExtLock.RUnlock()
830 if _, ok := c.Extensions["X-Resource"]; !ok {
831 panic("Cannot issue request 'QueryClients' using the uninitialized extension 'X-Resource'. res.Init(connObj) must be called first.")
832 }
833 cookie := c.NewCookie(false, true)
834 c.NewRequest(queryClientsRequest(c), cookie)
835 return QueryClientsCookie{cookie}
836 }
837
838
839 type QueryClientsReply struct {
840 Sequence uint16
841 Length uint32
842
843 NumClients uint32
844
845 Clients []Client
846 }
847
848
849 func (cook QueryClientsCookie) Reply() (*QueryClientsReply, error) {
850 buf, err := cook.Cookie.Reply()
851 if err != nil {
852 return nil, err
853 }
854 if buf == nil {
855 return nil, nil
856 }
857 return queryClientsReply(buf), nil
858 }
859
860
861 func queryClientsReply(buf []byte) *QueryClientsReply {
862 v := new(QueryClientsReply)
863 b := 1
864
865 b += 1
866
867 v.Sequence = xgb.Get16(buf[b:])
868 b += 2
869
870 v.Length = xgb.Get32(buf[b:])
871 b += 4
872
873 v.NumClients = xgb.Get32(buf[b:])
874 b += 4
875
876 b += 20
877
878 v.Clients = make([]Client, v.NumClients)
879 b += ClientReadList(buf[b:], v.Clients)
880
881 return v
882 }
883
884
885
886 func queryClientsRequest(c *xgb.Conn) []byte {
887 size := 4
888 b := 0
889 buf := make([]byte, size)
890
891 c.ExtLock.RLock()
892 buf[b] = c.Extensions["X-Resource"]
893 c.ExtLock.RUnlock()
894 b += 1
895
896 buf[b] = 1
897 b += 1
898
899 xgb.Put16(buf[b:], uint16(size/4))
900 b += 2
901
902 return buf
903 }
904
905
906 type QueryResourceBytesCookie struct {
907 *xgb.Cookie
908 }
909
910
911
912 func QueryResourceBytes(c *xgb.Conn, Client uint32, NumSpecs uint32, Specs []ResourceIdSpec) QueryResourceBytesCookie {
913 c.ExtLock.RLock()
914 defer c.ExtLock.RUnlock()
915 if _, ok := c.Extensions["X-Resource"]; !ok {
916 panic("Cannot issue request 'QueryResourceBytes' using the uninitialized extension 'X-Resource'. res.Init(connObj) must be called first.")
917 }
918 cookie := c.NewCookie(true, true)
919 c.NewRequest(queryResourceBytesRequest(c, Client, NumSpecs, Specs), cookie)
920 return QueryResourceBytesCookie{cookie}
921 }
922
923
924
925 func QueryResourceBytesUnchecked(c *xgb.Conn, Client uint32, NumSpecs uint32, Specs []ResourceIdSpec) QueryResourceBytesCookie {
926 c.ExtLock.RLock()
927 defer c.ExtLock.RUnlock()
928 if _, ok := c.Extensions["X-Resource"]; !ok {
929 panic("Cannot issue request 'QueryResourceBytes' using the uninitialized extension 'X-Resource'. res.Init(connObj) must be called first.")
930 }
931 cookie := c.NewCookie(false, true)
932 c.NewRequest(queryResourceBytesRequest(c, Client, NumSpecs, Specs), cookie)
933 return QueryResourceBytesCookie{cookie}
934 }
935
936
937 type QueryResourceBytesReply struct {
938 Sequence uint16
939 Length uint32
940
941 NumSizes uint32
942
943 Sizes []ResourceSizeValue
944 }
945
946
947 func (cook QueryResourceBytesCookie) Reply() (*QueryResourceBytesReply, error) {
948 buf, err := cook.Cookie.Reply()
949 if err != nil {
950 return nil, err
951 }
952 if buf == nil {
953 return nil, nil
954 }
955 return queryResourceBytesReply(buf), nil
956 }
957
958
959 func queryResourceBytesReply(buf []byte) *QueryResourceBytesReply {
960 v := new(QueryResourceBytesReply)
961 b := 1
962
963 b += 1
964
965 v.Sequence = xgb.Get16(buf[b:])
966 b += 2
967
968 v.Length = xgb.Get32(buf[b:])
969 b += 4
970
971 v.NumSizes = xgb.Get32(buf[b:])
972 b += 4
973
974 b += 20
975
976 v.Sizes = make([]ResourceSizeValue, v.NumSizes)
977 b += ResourceSizeValueReadList(buf[b:], v.Sizes)
978
979 return v
980 }
981
982
983
984 func queryResourceBytesRequest(c *xgb.Conn, Client uint32, NumSpecs uint32, Specs []ResourceIdSpec) []byte {
985 size := xgb.Pad((12 + xgb.Pad((int(NumSpecs) * 8))))
986 b := 0
987 buf := make([]byte, size)
988
989 c.ExtLock.RLock()
990 buf[b] = c.Extensions["X-Resource"]
991 c.ExtLock.RUnlock()
992 b += 1
993
994 buf[b] = 5
995 b += 1
996
997 xgb.Put16(buf[b:], uint16(size/4))
998 b += 2
999
1000 xgb.Put32(buf[b:], Client)
1001 b += 4
1002
1003 xgb.Put32(buf[b:], NumSpecs)
1004 b += 4
1005
1006 b += ResourceIdSpecListBytes(buf[b:], Specs)
1007
1008 return buf
1009 }
1010
1011
1012 type QueryVersionCookie struct {
1013 *xgb.Cookie
1014 }
1015
1016
1017
1018 func QueryVersion(c *xgb.Conn, ClientMajor byte, ClientMinor byte) QueryVersionCookie {
1019 c.ExtLock.RLock()
1020 defer c.ExtLock.RUnlock()
1021 if _, ok := c.Extensions["X-Resource"]; !ok {
1022 panic("Cannot issue request 'QueryVersion' using the uninitialized extension 'X-Resource'. res.Init(connObj) must be called first.")
1023 }
1024 cookie := c.NewCookie(true, true)
1025 c.NewRequest(queryVersionRequest(c, ClientMajor, ClientMinor), cookie)
1026 return QueryVersionCookie{cookie}
1027 }
1028
1029
1030
1031 func QueryVersionUnchecked(c *xgb.Conn, ClientMajor byte, ClientMinor byte) QueryVersionCookie {
1032 c.ExtLock.RLock()
1033 defer c.ExtLock.RUnlock()
1034 if _, ok := c.Extensions["X-Resource"]; !ok {
1035 panic("Cannot issue request 'QueryVersion' using the uninitialized extension 'X-Resource'. res.Init(connObj) must be called first.")
1036 }
1037 cookie := c.NewCookie(false, true)
1038 c.NewRequest(queryVersionRequest(c, ClientMajor, ClientMinor), cookie)
1039 return QueryVersionCookie{cookie}
1040 }
1041
1042
1043 type QueryVersionReply struct {
1044 Sequence uint16
1045 Length uint32
1046
1047 ServerMajor uint16
1048 ServerMinor uint16
1049 }
1050
1051
1052 func (cook QueryVersionCookie) Reply() (*QueryVersionReply, error) {
1053 buf, err := cook.Cookie.Reply()
1054 if err != nil {
1055 return nil, err
1056 }
1057 if buf == nil {
1058 return nil, nil
1059 }
1060 return queryVersionReply(buf), nil
1061 }
1062
1063
1064 func queryVersionReply(buf []byte) *QueryVersionReply {
1065 v := new(QueryVersionReply)
1066 b := 1
1067
1068 b += 1
1069
1070 v.Sequence = xgb.Get16(buf[b:])
1071 b += 2
1072
1073 v.Length = xgb.Get32(buf[b:])
1074 b += 4
1075
1076 v.ServerMajor = xgb.Get16(buf[b:])
1077 b += 2
1078
1079 v.ServerMinor = xgb.Get16(buf[b:])
1080 b += 2
1081
1082 return v
1083 }
1084
1085
1086
1087 func queryVersionRequest(c *xgb.Conn, ClientMajor byte, ClientMinor byte) []byte {
1088 size := 8
1089 b := 0
1090 buf := make([]byte, size)
1091
1092 c.ExtLock.RLock()
1093 buf[b] = c.Extensions["X-Resource"]
1094 c.ExtLock.RUnlock()
1095 b += 1
1096
1097 buf[b] = 0
1098 b += 1
1099
1100 xgb.Put16(buf[b:], uint16(size/4))
1101 b += 2
1102
1103 buf[b] = ClientMajor
1104 b += 1
1105
1106 buf[b] = ClientMinor
1107 b += 1
1108
1109 return buf
1110 }
1111
View as plain text