1
2 package composite
3
4
5
6 import (
7 "github.com/jezek/xgb"
8
9 "github.com/jezek/xgb/xfixes"
10 "github.com/jezek/xgb/xproto"
11 )
12
13
14 func Init(c *xgb.Conn) error {
15 reply, err := xproto.QueryExtension(c, 9, "Composite").Reply()
16 switch {
17 case err != nil:
18 return err
19 case !reply.Present:
20 return xgb.Errorf("No extension named Composite could be found on on the server.")
21 }
22
23 c.ExtLock.Lock()
24 c.Extensions["Composite"] = reply.MajorOpcode
25 c.ExtLock.Unlock()
26 for evNum, fun := range xgb.NewExtEventFuncs["Composite"] {
27 xgb.NewEventFuncs[int(reply.FirstEvent)+evNum] = fun
28 }
29 for errNum, fun := range xgb.NewExtErrorFuncs["Composite"] {
30 xgb.NewErrorFuncs[int(reply.FirstError)+errNum] = fun
31 }
32 return nil
33 }
34
35 func init() {
36 xgb.NewExtEventFuncs["Composite"] = make(map[int]xgb.NewEventFun)
37 xgb.NewExtErrorFuncs["Composite"] = make(map[int]xgb.NewErrorFun)
38 }
39
40 const (
41 RedirectAutomatic = 0
42 RedirectManual = 1
43 )
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70 type CreateRegionFromBorderClipCookie struct {
71 *xgb.Cookie
72 }
73
74
75
76 func CreateRegionFromBorderClip(c *xgb.Conn, Region xfixes.Region, Window xproto.Window) CreateRegionFromBorderClipCookie {
77 c.ExtLock.RLock()
78 defer c.ExtLock.RUnlock()
79 if _, ok := c.Extensions["Composite"]; !ok {
80 panic("Cannot issue request 'CreateRegionFromBorderClip' using the uninitialized extension 'Composite'. composite.Init(connObj) must be called first.")
81 }
82 cookie := c.NewCookie(false, false)
83 c.NewRequest(createRegionFromBorderClipRequest(c, Region, Window), cookie)
84 return CreateRegionFromBorderClipCookie{cookie}
85 }
86
87
88
89 func CreateRegionFromBorderClipChecked(c *xgb.Conn, Region xfixes.Region, Window xproto.Window) CreateRegionFromBorderClipCookie {
90 c.ExtLock.RLock()
91 defer c.ExtLock.RUnlock()
92 if _, ok := c.Extensions["Composite"]; !ok {
93 panic("Cannot issue request 'CreateRegionFromBorderClip' using the uninitialized extension 'Composite'. composite.Init(connObj) must be called first.")
94 }
95 cookie := c.NewCookie(true, false)
96 c.NewRequest(createRegionFromBorderClipRequest(c, Region, Window), cookie)
97 return CreateRegionFromBorderClipCookie{cookie}
98 }
99
100
101
102 func (cook CreateRegionFromBorderClipCookie) Check() error {
103 return cook.Cookie.Check()
104 }
105
106
107
108 func createRegionFromBorderClipRequest(c *xgb.Conn, Region xfixes.Region, Window xproto.Window) []byte {
109 size := 12
110 b := 0
111 buf := make([]byte, size)
112
113 c.ExtLock.RLock()
114 buf[b] = c.Extensions["Composite"]
115 c.ExtLock.RUnlock()
116 b += 1
117
118 buf[b] = 5
119 b += 1
120
121 xgb.Put16(buf[b:], uint16(size/4))
122 b += 2
123
124 xgb.Put32(buf[b:], uint32(Region))
125 b += 4
126
127 xgb.Put32(buf[b:], uint32(Window))
128 b += 4
129
130 return buf
131 }
132
133
134 type GetOverlayWindowCookie struct {
135 *xgb.Cookie
136 }
137
138
139
140 func GetOverlayWindow(c *xgb.Conn, Window xproto.Window) GetOverlayWindowCookie {
141 c.ExtLock.RLock()
142 defer c.ExtLock.RUnlock()
143 if _, ok := c.Extensions["Composite"]; !ok {
144 panic("Cannot issue request 'GetOverlayWindow' using the uninitialized extension 'Composite'. composite.Init(connObj) must be called first.")
145 }
146 cookie := c.NewCookie(true, true)
147 c.NewRequest(getOverlayWindowRequest(c, Window), cookie)
148 return GetOverlayWindowCookie{cookie}
149 }
150
151
152
153 func GetOverlayWindowUnchecked(c *xgb.Conn, Window xproto.Window) GetOverlayWindowCookie {
154 c.ExtLock.RLock()
155 defer c.ExtLock.RUnlock()
156 if _, ok := c.Extensions["Composite"]; !ok {
157 panic("Cannot issue request 'GetOverlayWindow' using the uninitialized extension 'Composite'. composite.Init(connObj) must be called first.")
158 }
159 cookie := c.NewCookie(false, true)
160 c.NewRequest(getOverlayWindowRequest(c, Window), cookie)
161 return GetOverlayWindowCookie{cookie}
162 }
163
164
165 type GetOverlayWindowReply struct {
166 Sequence uint16
167 Length uint32
168
169 OverlayWin xproto.Window
170
171 }
172
173
174 func (cook GetOverlayWindowCookie) Reply() (*GetOverlayWindowReply, error) {
175 buf, err := cook.Cookie.Reply()
176 if err != nil {
177 return nil, err
178 }
179 if buf == nil {
180 return nil, nil
181 }
182 return getOverlayWindowReply(buf), nil
183 }
184
185
186 func getOverlayWindowReply(buf []byte) *GetOverlayWindowReply {
187 v := new(GetOverlayWindowReply)
188 b := 1
189
190 b += 1
191
192 v.Sequence = xgb.Get16(buf[b:])
193 b += 2
194
195 v.Length = xgb.Get32(buf[b:])
196 b += 4
197
198 v.OverlayWin = xproto.Window(xgb.Get32(buf[b:]))
199 b += 4
200
201 b += 20
202
203 return v
204 }
205
206
207
208 func getOverlayWindowRequest(c *xgb.Conn, Window xproto.Window) []byte {
209 size := 8
210 b := 0
211 buf := make([]byte, size)
212
213 c.ExtLock.RLock()
214 buf[b] = c.Extensions["Composite"]
215 c.ExtLock.RUnlock()
216 b += 1
217
218 buf[b] = 7
219 b += 1
220
221 xgb.Put16(buf[b:], uint16(size/4))
222 b += 2
223
224 xgb.Put32(buf[b:], uint32(Window))
225 b += 4
226
227 return buf
228 }
229
230
231 type NameWindowPixmapCookie struct {
232 *xgb.Cookie
233 }
234
235
236
237 func NameWindowPixmap(c *xgb.Conn, Window xproto.Window, Pixmap xproto.Pixmap) NameWindowPixmapCookie {
238 c.ExtLock.RLock()
239 defer c.ExtLock.RUnlock()
240 if _, ok := c.Extensions["Composite"]; !ok {
241 panic("Cannot issue request 'NameWindowPixmap' using the uninitialized extension 'Composite'. composite.Init(connObj) must be called first.")
242 }
243 cookie := c.NewCookie(false, false)
244 c.NewRequest(nameWindowPixmapRequest(c, Window, Pixmap), cookie)
245 return NameWindowPixmapCookie{cookie}
246 }
247
248
249
250 func NameWindowPixmapChecked(c *xgb.Conn, Window xproto.Window, Pixmap xproto.Pixmap) NameWindowPixmapCookie {
251 c.ExtLock.RLock()
252 defer c.ExtLock.RUnlock()
253 if _, ok := c.Extensions["Composite"]; !ok {
254 panic("Cannot issue request 'NameWindowPixmap' using the uninitialized extension 'Composite'. composite.Init(connObj) must be called first.")
255 }
256 cookie := c.NewCookie(true, false)
257 c.NewRequest(nameWindowPixmapRequest(c, Window, Pixmap), cookie)
258 return NameWindowPixmapCookie{cookie}
259 }
260
261
262
263 func (cook NameWindowPixmapCookie) Check() error {
264 return cook.Cookie.Check()
265 }
266
267
268
269 func nameWindowPixmapRequest(c *xgb.Conn, Window xproto.Window, Pixmap xproto.Pixmap) []byte {
270 size := 12
271 b := 0
272 buf := make([]byte, size)
273
274 c.ExtLock.RLock()
275 buf[b] = c.Extensions["Composite"]
276 c.ExtLock.RUnlock()
277 b += 1
278
279 buf[b] = 6
280 b += 1
281
282 xgb.Put16(buf[b:], uint16(size/4))
283 b += 2
284
285 xgb.Put32(buf[b:], uint32(Window))
286 b += 4
287
288 xgb.Put32(buf[b:], uint32(Pixmap))
289 b += 4
290
291 return buf
292 }
293
294
295 type QueryVersionCookie struct {
296 *xgb.Cookie
297 }
298
299
300
301 func QueryVersion(c *xgb.Conn, ClientMajorVersion uint32, ClientMinorVersion uint32) QueryVersionCookie {
302 c.ExtLock.RLock()
303 defer c.ExtLock.RUnlock()
304 if _, ok := c.Extensions["Composite"]; !ok {
305 panic("Cannot issue request 'QueryVersion' using the uninitialized extension 'Composite'. composite.Init(connObj) must be called first.")
306 }
307 cookie := c.NewCookie(true, true)
308 c.NewRequest(queryVersionRequest(c, ClientMajorVersion, ClientMinorVersion), cookie)
309 return QueryVersionCookie{cookie}
310 }
311
312
313
314 func QueryVersionUnchecked(c *xgb.Conn, ClientMajorVersion uint32, ClientMinorVersion uint32) QueryVersionCookie {
315 c.ExtLock.RLock()
316 defer c.ExtLock.RUnlock()
317 if _, ok := c.Extensions["Composite"]; !ok {
318 panic("Cannot issue request 'QueryVersion' using the uninitialized extension 'Composite'. composite.Init(connObj) must be called first.")
319 }
320 cookie := c.NewCookie(false, true)
321 c.NewRequest(queryVersionRequest(c, ClientMajorVersion, ClientMinorVersion), cookie)
322 return QueryVersionCookie{cookie}
323 }
324
325
326 type QueryVersionReply struct {
327 Sequence uint16
328 Length uint32
329
330 MajorVersion uint32
331 MinorVersion uint32
332
333 }
334
335
336 func (cook QueryVersionCookie) Reply() (*QueryVersionReply, error) {
337 buf, err := cook.Cookie.Reply()
338 if err != nil {
339 return nil, err
340 }
341 if buf == nil {
342 return nil, nil
343 }
344 return queryVersionReply(buf), nil
345 }
346
347
348 func queryVersionReply(buf []byte) *QueryVersionReply {
349 v := new(QueryVersionReply)
350 b := 1
351
352 b += 1
353
354 v.Sequence = xgb.Get16(buf[b:])
355 b += 2
356
357 v.Length = xgb.Get32(buf[b:])
358 b += 4
359
360 v.MajorVersion = xgb.Get32(buf[b:])
361 b += 4
362
363 v.MinorVersion = xgb.Get32(buf[b:])
364 b += 4
365
366 b += 16
367
368 return v
369 }
370
371
372
373 func queryVersionRequest(c *xgb.Conn, ClientMajorVersion uint32, ClientMinorVersion uint32) []byte {
374 size := 12
375 b := 0
376 buf := make([]byte, size)
377
378 c.ExtLock.RLock()
379 buf[b] = c.Extensions["Composite"]
380 c.ExtLock.RUnlock()
381 b += 1
382
383 buf[b] = 0
384 b += 1
385
386 xgb.Put16(buf[b:], uint16(size/4))
387 b += 2
388
389 xgb.Put32(buf[b:], ClientMajorVersion)
390 b += 4
391
392 xgb.Put32(buf[b:], ClientMinorVersion)
393 b += 4
394
395 return buf
396 }
397
398
399 type RedirectSubwindowsCookie struct {
400 *xgb.Cookie
401 }
402
403
404
405 func RedirectSubwindows(c *xgb.Conn, Window xproto.Window, Update byte) RedirectSubwindowsCookie {
406 c.ExtLock.RLock()
407 defer c.ExtLock.RUnlock()
408 if _, ok := c.Extensions["Composite"]; !ok {
409 panic("Cannot issue request 'RedirectSubwindows' using the uninitialized extension 'Composite'. composite.Init(connObj) must be called first.")
410 }
411 cookie := c.NewCookie(false, false)
412 c.NewRequest(redirectSubwindowsRequest(c, Window, Update), cookie)
413 return RedirectSubwindowsCookie{cookie}
414 }
415
416
417
418 func RedirectSubwindowsChecked(c *xgb.Conn, Window xproto.Window, Update byte) RedirectSubwindowsCookie {
419 c.ExtLock.RLock()
420 defer c.ExtLock.RUnlock()
421 if _, ok := c.Extensions["Composite"]; !ok {
422 panic("Cannot issue request 'RedirectSubwindows' using the uninitialized extension 'Composite'. composite.Init(connObj) must be called first.")
423 }
424 cookie := c.NewCookie(true, false)
425 c.NewRequest(redirectSubwindowsRequest(c, Window, Update), cookie)
426 return RedirectSubwindowsCookie{cookie}
427 }
428
429
430
431 func (cook RedirectSubwindowsCookie) Check() error {
432 return cook.Cookie.Check()
433 }
434
435
436
437 func redirectSubwindowsRequest(c *xgb.Conn, Window xproto.Window, Update byte) []byte {
438 size := 12
439 b := 0
440 buf := make([]byte, size)
441
442 c.ExtLock.RLock()
443 buf[b] = c.Extensions["Composite"]
444 c.ExtLock.RUnlock()
445 b += 1
446
447 buf[b] = 2
448 b += 1
449
450 xgb.Put16(buf[b:], uint16(size/4))
451 b += 2
452
453 xgb.Put32(buf[b:], uint32(Window))
454 b += 4
455
456 buf[b] = Update
457 b += 1
458
459 b += 3
460
461 return buf
462 }
463
464
465 type RedirectWindowCookie struct {
466 *xgb.Cookie
467 }
468
469
470
471 func RedirectWindow(c *xgb.Conn, Window xproto.Window, Update byte) RedirectWindowCookie {
472 c.ExtLock.RLock()
473 defer c.ExtLock.RUnlock()
474 if _, ok := c.Extensions["Composite"]; !ok {
475 panic("Cannot issue request 'RedirectWindow' using the uninitialized extension 'Composite'. composite.Init(connObj) must be called first.")
476 }
477 cookie := c.NewCookie(false, false)
478 c.NewRequest(redirectWindowRequest(c, Window, Update), cookie)
479 return RedirectWindowCookie{cookie}
480 }
481
482
483
484 func RedirectWindowChecked(c *xgb.Conn, Window xproto.Window, Update byte) RedirectWindowCookie {
485 c.ExtLock.RLock()
486 defer c.ExtLock.RUnlock()
487 if _, ok := c.Extensions["Composite"]; !ok {
488 panic("Cannot issue request 'RedirectWindow' using the uninitialized extension 'Composite'. composite.Init(connObj) must be called first.")
489 }
490 cookie := c.NewCookie(true, false)
491 c.NewRequest(redirectWindowRequest(c, Window, Update), cookie)
492 return RedirectWindowCookie{cookie}
493 }
494
495
496
497 func (cook RedirectWindowCookie) Check() error {
498 return cook.Cookie.Check()
499 }
500
501
502
503 func redirectWindowRequest(c *xgb.Conn, Window xproto.Window, Update byte) []byte {
504 size := 12
505 b := 0
506 buf := make([]byte, size)
507
508 c.ExtLock.RLock()
509 buf[b] = c.Extensions["Composite"]
510 c.ExtLock.RUnlock()
511 b += 1
512
513 buf[b] = 1
514 b += 1
515
516 xgb.Put16(buf[b:], uint16(size/4))
517 b += 2
518
519 xgb.Put32(buf[b:], uint32(Window))
520 b += 4
521
522 buf[b] = Update
523 b += 1
524
525 b += 3
526
527 return buf
528 }
529
530
531 type ReleaseOverlayWindowCookie struct {
532 *xgb.Cookie
533 }
534
535
536
537 func ReleaseOverlayWindow(c *xgb.Conn, Window xproto.Window) ReleaseOverlayWindowCookie {
538 c.ExtLock.RLock()
539 defer c.ExtLock.RUnlock()
540 if _, ok := c.Extensions["Composite"]; !ok {
541 panic("Cannot issue request 'ReleaseOverlayWindow' using the uninitialized extension 'Composite'. composite.Init(connObj) must be called first.")
542 }
543 cookie := c.NewCookie(false, false)
544 c.NewRequest(releaseOverlayWindowRequest(c, Window), cookie)
545 return ReleaseOverlayWindowCookie{cookie}
546 }
547
548
549
550 func ReleaseOverlayWindowChecked(c *xgb.Conn, Window xproto.Window) ReleaseOverlayWindowCookie {
551 c.ExtLock.RLock()
552 defer c.ExtLock.RUnlock()
553 if _, ok := c.Extensions["Composite"]; !ok {
554 panic("Cannot issue request 'ReleaseOverlayWindow' using the uninitialized extension 'Composite'. composite.Init(connObj) must be called first.")
555 }
556 cookie := c.NewCookie(true, false)
557 c.NewRequest(releaseOverlayWindowRequest(c, Window), cookie)
558 return ReleaseOverlayWindowCookie{cookie}
559 }
560
561
562
563 func (cook ReleaseOverlayWindowCookie) Check() error {
564 return cook.Cookie.Check()
565 }
566
567
568
569 func releaseOverlayWindowRequest(c *xgb.Conn, Window xproto.Window) []byte {
570 size := 8
571 b := 0
572 buf := make([]byte, size)
573
574 c.ExtLock.RLock()
575 buf[b] = c.Extensions["Composite"]
576 c.ExtLock.RUnlock()
577 b += 1
578
579 buf[b] = 8
580 b += 1
581
582 xgb.Put16(buf[b:], uint16(size/4))
583 b += 2
584
585 xgb.Put32(buf[b:], uint32(Window))
586 b += 4
587
588 return buf
589 }
590
591
592 type UnredirectSubwindowsCookie struct {
593 *xgb.Cookie
594 }
595
596
597
598 func UnredirectSubwindows(c *xgb.Conn, Window xproto.Window, Update byte) UnredirectSubwindowsCookie {
599 c.ExtLock.RLock()
600 defer c.ExtLock.RUnlock()
601 if _, ok := c.Extensions["Composite"]; !ok {
602 panic("Cannot issue request 'UnredirectSubwindows' using the uninitialized extension 'Composite'. composite.Init(connObj) must be called first.")
603 }
604 cookie := c.NewCookie(false, false)
605 c.NewRequest(unredirectSubwindowsRequest(c, Window, Update), cookie)
606 return UnredirectSubwindowsCookie{cookie}
607 }
608
609
610
611 func UnredirectSubwindowsChecked(c *xgb.Conn, Window xproto.Window, Update byte) UnredirectSubwindowsCookie {
612 c.ExtLock.RLock()
613 defer c.ExtLock.RUnlock()
614 if _, ok := c.Extensions["Composite"]; !ok {
615 panic("Cannot issue request 'UnredirectSubwindows' using the uninitialized extension 'Composite'. composite.Init(connObj) must be called first.")
616 }
617 cookie := c.NewCookie(true, false)
618 c.NewRequest(unredirectSubwindowsRequest(c, Window, Update), cookie)
619 return UnredirectSubwindowsCookie{cookie}
620 }
621
622
623
624 func (cook UnredirectSubwindowsCookie) Check() error {
625 return cook.Cookie.Check()
626 }
627
628
629
630 func unredirectSubwindowsRequest(c *xgb.Conn, Window xproto.Window, Update byte) []byte {
631 size := 12
632 b := 0
633 buf := make([]byte, size)
634
635 c.ExtLock.RLock()
636 buf[b] = c.Extensions["Composite"]
637 c.ExtLock.RUnlock()
638 b += 1
639
640 buf[b] = 4
641 b += 1
642
643 xgb.Put16(buf[b:], uint16(size/4))
644 b += 2
645
646 xgb.Put32(buf[b:], uint32(Window))
647 b += 4
648
649 buf[b] = Update
650 b += 1
651
652 b += 3
653
654 return buf
655 }
656
657
658 type UnredirectWindowCookie struct {
659 *xgb.Cookie
660 }
661
662
663
664 func UnredirectWindow(c *xgb.Conn, Window xproto.Window, Update byte) UnredirectWindowCookie {
665 c.ExtLock.RLock()
666 defer c.ExtLock.RUnlock()
667 if _, ok := c.Extensions["Composite"]; !ok {
668 panic("Cannot issue request 'UnredirectWindow' using the uninitialized extension 'Composite'. composite.Init(connObj) must be called first.")
669 }
670 cookie := c.NewCookie(false, false)
671 c.NewRequest(unredirectWindowRequest(c, Window, Update), cookie)
672 return UnredirectWindowCookie{cookie}
673 }
674
675
676
677 func UnredirectWindowChecked(c *xgb.Conn, Window xproto.Window, Update byte) UnredirectWindowCookie {
678 c.ExtLock.RLock()
679 defer c.ExtLock.RUnlock()
680 if _, ok := c.Extensions["Composite"]; !ok {
681 panic("Cannot issue request 'UnredirectWindow' using the uninitialized extension 'Composite'. composite.Init(connObj) must be called first.")
682 }
683 cookie := c.NewCookie(true, false)
684 c.NewRequest(unredirectWindowRequest(c, Window, Update), cookie)
685 return UnredirectWindowCookie{cookie}
686 }
687
688
689
690 func (cook UnredirectWindowCookie) Check() error {
691 return cook.Cookie.Check()
692 }
693
694
695
696 func unredirectWindowRequest(c *xgb.Conn, Window xproto.Window, Update byte) []byte {
697 size := 12
698 b := 0
699 buf := make([]byte, size)
700
701 c.ExtLock.RLock()
702 buf[b] = c.Extensions["Composite"]
703 c.ExtLock.RUnlock()
704 b += 1
705
706 buf[b] = 3
707 b += 1
708
709 xgb.Put16(buf[b:], uint16(size/4))
710 b += 2
711
712 xgb.Put32(buf[b:], uint32(Window))
713 b += 4
714
715 buf[b] = Update
716 b += 1
717
718 b += 3
719
720 return buf
721 }
722
View as plain text