Debian Codegraph @

client.go

raw symbols SCIP
1 // package wl acts as a client for the wayland wayland protocol.
2
3 // generated by wl-scanner
4 // https://github.com/dkolbly/wl-scanner
5 // from: https://cgit.freedesktop.org/wayland/wayland/plain/protocol/wayland.xml
6 // on 2018-02-19 14:50:40 -0600
7 package wl
8
9 import (
10 "context"
11 "sync"
12 )
13
14 type DisplayErrorEvent struct {
15 EventContext context.Context
16 ObjectId Proxy
17 Code uint32
18 Message string
19 }
20
21 type DisplayErrorHandler interface {
22 HandleDisplayError(DisplayErrorEvent)
23 }
24
25 func (p *Display) AddErrorHandler(h DisplayErrorHandler) {
26 if h != nil {
27 p.mu.Lock()
28 p.errorHandlers = append(p.errorHandlers, h)
29 p.mu.Unlock()
30 }
31 }
32
33 func (p *Display) RemoveErrorHandler(h DisplayErrorHandler) {
34 p.mu.Lock()
35 defer p.mu.Unlock()
36
37 for i, e := range p.errorHandlers {
38 if e == h {
39 p.errorHandlers = append(p.errorHandlers[:i], p.errorHandlers[i+1:]...)
40 break
41 }
42 }
43 }
44
45 type DisplayDeleteIdEvent struct {
46 EventContext context.Context
47 Id uint32
48 }
49
50 type DisplayDeleteIdHandler interface {
51 HandleDisplayDeleteId(DisplayDeleteIdEvent)
52 }
53
54 func (p *Display) AddDeleteIdHandler(h DisplayDeleteIdHandler) {
55 if h != nil {
56 p.mu.Lock()
57 p.deleteIdHandlers = append(p.deleteIdHandlers, h)
58 p.mu.Unlock()
59 }
60 }
61
62 func (p *Display) RemoveDeleteIdHandler(h DisplayDeleteIdHandler) {
63 p.mu.Lock()
64 defer p.mu.Unlock()
65
66 for i, e := range p.deleteIdHandlers {
67 if e == h {
68 p.deleteIdHandlers = append(p.deleteIdHandlers[:i], p.deleteIdHandlers[i+1:]...)
69 break
70 }
71 }
72 }
73
74 func (p *Display) Dispatch(ctx context.Context, event *Event) {
75 switch event.Opcode {
76 case 0:
77 if len(p.errorHandlers) > 0 {
78 ev := DisplayErrorEvent{}
79 ev.EventContext = ctx
80 ev.ObjectId = event.Proxy(p.Context())
81 ev.Code = event.Uint32()
82 ev.Message = event.String()
83 p.mu.RLock()
84 for _, h := range p.errorHandlers {
85 h.HandleDisplayError(ev)
86 }
87 p.mu.RUnlock()
88 }
89 case 1:
90 if len(p.deleteIdHandlers) > 0 {
91 ev := DisplayDeleteIdEvent{}
92 ev.EventContext = ctx
93 ev.Id = event.Uint32()
94 p.mu.RLock()
95 for _, h := range p.deleteIdHandlers {
96 h.HandleDisplayDeleteId(ev)
97 }
98 p.mu.RUnlock()
99 }
100 }
101 }
102
103 type Display struct {
104 BaseProxy
105 mu sync.RWMutex
106 errorHandlers []DisplayErrorHandler
107 deleteIdHandlers []DisplayDeleteIdHandler
108 }
109
110 func NewDisplay(ctx *Context) *Display {
111 ret := new(Display)
112 ctx.Register(ret)
113 return ret
114 }
115
116 // Sync will asynchronous roundtrip.
117 //
118 //
119 // The sync request asks the server to emit the 'done' event
120 // on the returned wl_callback object. Since requests are
121 // handled in-order and events are delivered in-order, this can
122 // be used as a barrier to ensure all previous requests and the
123 // resulting events have been handled.
124 //
125 // The object returned by this request will be destroyed by the
126 // compositor after the callback is fired and as such the client must not
127 // attempt to use it after that point.
128 //
129 // The callback_data passed in the callback is the event serial.
130 //
131 func (p *Display) Sync() (*Callback, error) {
132 ret := NewCallback(p.Context())
133 return ret, p.Context().SendRequest(p, 0, Proxy(ret))
134 }
135
136 // GetRegistry will get global registry object.
137 //
138 //
139 // This request creates a registry object that allows the client
140 // to list and bind the global objects available from the
141 // compositor.
142 //
143 // It should be noted that the server side resources consumed in
144 // response to a get_registry request can only be released when the
145 // client disconnects, not when the client side proxy is destroyed.
146 // Therefore, clients should invoke get_registry as infrequently as
147 // possible to avoid wasting memory.
148 //
149 func (p *Display) GetRegistry() (*Registry, error) {
150 ret := NewRegistry(p.Context())
151 return ret, p.Context().SendRequest(p, 1, Proxy(ret))
152 }
153
154 const (
155 DisplayErrorInvalidObject = 0
156 DisplayErrorInvalidMethod = 1
157 DisplayErrorNoMemory = 2
158 )
159
160 type RegistryGlobalEvent struct {
161 EventContext context.Context
162 Name uint32
163 Interface string
164 Version uint32
165 }
166
167 type RegistryGlobalHandler interface {
168 HandleRegistryGlobal(RegistryGlobalEvent)
169 }
170
171 func (p *Registry) AddGlobalHandler(h RegistryGlobalHandler) {
172 if h != nil {
173 p.mu.Lock()
174 p.globalHandlers = append(p.globalHandlers, h)
175 p.mu.Unlock()
176 }
177 }
178
179 func (p *Registry) RemoveGlobalHandler(h RegistryGlobalHandler) {
180 p.mu.Lock()
181 defer p.mu.Unlock()
182
183 for i, e := range p.globalHandlers {
184 if e == h {
185 p.globalHandlers = append(p.globalHandlers[:i], p.globalHandlers[i+1:]...)
186 break
187 }
188 }
189 }
190
191 type RegistryGlobalRemoveEvent struct {
192 EventContext context.Context
193 Name uint32
194 }
195
196 type RegistryGlobalRemoveHandler interface {
197 HandleRegistryGlobalRemove(RegistryGlobalRemoveEvent)
198 }
199
200 func (p *Registry) AddGlobalRemoveHandler(h RegistryGlobalRemoveHandler) {
201 if h != nil {
202 p.mu.Lock()
203 p.globalRemoveHandlers = append(p.globalRemoveHandlers, h)
204 p.mu.Unlock()
205 }
206 }
207
208 func (p *Registry) RemoveGlobalRemoveHandler(h RegistryGlobalRemoveHandler) {
209 p.mu.Lock()
210 defer p.mu.Unlock()
211
212 for i, e := range p.globalRemoveHandlers {
213 if e == h {
214 p.globalRemoveHandlers = append(p.globalRemoveHandlers[:i], p.globalRemoveHandlers[i+1:]...)
215 break
216 }
217 }
218 }
219
220 func (p *Registry) Dispatch(ctx context.Context, event *Event) {
221 switch event.Opcode {
222 case 0:
223 if len(p.globalHandlers) > 0 {
224 ev := RegistryGlobalEvent{}
225 ev.EventContext = ctx
226 ev.Name = event.Uint32()
227 ev.Interface = event.String()
228 ev.Version = event.Uint32()
229 p.mu.RLock()
230 for _, h := range p.globalHandlers {
231 h.HandleRegistryGlobal(ev)
232 }
233 p.mu.RUnlock()
234 }
235 case 1:
236 if len(p.globalRemoveHandlers) > 0 {
237 ev := RegistryGlobalRemoveEvent{}
238 ev.EventContext = ctx
239 ev.Name = event.Uint32()
240 p.mu.RLock()
241 for _, h := range p.globalRemoveHandlers {
242 h.HandleRegistryGlobalRemove(ev)
243 }
244 p.mu.RUnlock()
245 }
246 }
247 }
248
249 type Registry struct {
250 BaseProxy
251 mu sync.RWMutex
252 globalHandlers []RegistryGlobalHandler
253 globalRemoveHandlers []RegistryGlobalRemoveHandler
254 }
255
256 func NewRegistry(ctx *Context) *Registry {
257 ret := new(Registry)
258 ctx.Register(ret)
259 return ret
260 }
261
262 // Bind will bind an object to the display.
263 //
264 //
265 // Binds a new, client-created object to the server using the
266 // specified name as the identifier.
267 //
268 func (p *Registry) Bind(name uint32, iface string, version uint32, id Proxy) error {
269 return p.Context().SendRequest(p, 0, name, iface, version, id)
270 }
271
272 type CallbackDoneEvent struct {
273 EventContext context.Context
274 CallbackData uint32
275 }
276
277 type CallbackDoneHandler interface {
278 HandleCallbackDone(CallbackDoneEvent)
279 }
280
281 func (p *Callback) AddDoneHandler(h CallbackDoneHandler) {
282 if h != nil {
283 p.mu.Lock()
284 p.doneHandlers = append(p.doneHandlers, h)
285 p.mu.Unlock()
286 }
287 }
288
289 func (p *Callback) RemoveDoneHandler(h CallbackDoneHandler) {
290 p.mu.Lock()
291 defer p.mu.Unlock()
292
293 for i, e := range p.doneHandlers {
294 if e == h {
295 p.doneHandlers = append(p.doneHandlers[:i], p.doneHandlers[i+1:]...)
296 break
297 }
298 }
299 }
300
301 func (p *Callback) Dispatch(ctx context.Context, event *Event) {
302 switch event.Opcode {
303 case 0:
304 if len(p.doneHandlers) > 0 {
305 ev := CallbackDoneEvent{}
306 ev.EventContext = ctx
307 ev.CallbackData = event.Uint32()
308 p.mu.RLock()
309 for _, h := range p.doneHandlers {
310 h.HandleCallbackDone(ev)
311 }
312 p.mu.RUnlock()
313 }
314 }
315 }
316
317 type Callback struct {
318 BaseProxy
319 mu sync.RWMutex
320 doneHandlers []CallbackDoneHandler
321 }
322
323 func NewCallback(ctx *Context) *Callback {
324 ret := new(Callback)
325 ctx.Register(ret)
326 return ret
327 }
328
329 type Compositor struct {
330 BaseProxy
331 }
332
333 func NewCompositor(ctx *Context) *Compositor {
334 ret := new(Compositor)
335 ctx.Register(ret)
336 return ret
337 }
338
339 // CreateSurface will create new surface.
340 //
341 //
342 // Ask the compositor to create a new surface.
343 //
344 func (p *Compositor) CreateSurface() (*Surface, error) {
345 ret := NewSurface(p.Context())
346 return ret, p.Context().SendRequest(p, 0, Proxy(ret))
347 }
348
349 // CreateRegion will create new region.
350 //
351 //
352 // Ask the compositor to create a new region.
353 //
354 func (p *Compositor) CreateRegion() (*Region, error) {
355 ret := NewRegion(p.Context())
356 return ret, p.Context().SendRequest(p, 1, Proxy(ret))
357 }
358
359 type ShmPool struct {
360 BaseProxy
361 }
362
363 func NewShmPool(ctx *Context) *ShmPool {
364 ret := new(ShmPool)
365 ctx.Register(ret)
366 return ret
367 }
368
369 // CreateBuffer will create a buffer from the pool.
370 //
371 //
372 // Create a wl_buffer object from the pool.
373 //
374 // The buffer is created offset bytes into the pool and has
375 // width and height as specified. The stride argument specifies
376 // the number of bytes from the beginning of one row to the beginning
377 // of the next. The format is the pixel format of the buffer and
378 // must be one of those advertised through the wl_shm.format event.
379 //
380 // A buffer will keep a reference to the pool it was created from
381 // so it is valid to destroy the pool immediately after creating
382 // a buffer from it.
383 //
384 func (p *ShmPool) CreateBuffer(offset int32, width int32, height int32, stride int32, format uint32) (*Buffer, error) {
385 ret := NewBuffer(p.Context())
386 return ret, p.Context().SendRequest(p, 0, Proxy(ret), offset, width, height, stride, format)
387 }
388
389 // Destroy will destroy the pool.
390 //
391 //
392 // Destroy the shared memory pool.
393 //
394 // The mmapped memory will be released when all
395 // buffers that have been created from this pool
396 // are gone.
397 //
398 func (p *ShmPool) Destroy() error {
399 return p.Context().SendRequest(p, 1)
400 }
401
402 // Resize will change the size of the pool mapping.
403 //
404 //
405 // This request will cause the server to remap the backing memory
406 // for the pool from the file descriptor passed when the pool was
407 // created, but using the new size. This request can only be
408 // used to make the pool bigger.
409 //
410 func (p *ShmPool) Resize(size int32) error {
411 return p.Context().SendRequest(p, 2, size)
412 }
413
414 type ShmFormatEvent struct {
415 EventContext context.Context
416 Format uint32
417 }
418
419 type ShmFormatHandler interface {
420 HandleShmFormat(ShmFormatEvent)
421 }
422
423 func (p *Shm) AddFormatHandler(h ShmFormatHandler) {
424 if h != nil {
425 p.mu.Lock()
426 p.formatHandlers = append(p.formatHandlers, h)
427 p.mu.Unlock()
428 }
429 }
430
431 func (p *Shm) RemoveFormatHandler(h ShmFormatHandler) {
432 p.mu.Lock()
433 defer p.mu.Unlock()
434
435 for i, e := range p.formatHandlers {
436 if e == h {
437 p.formatHandlers = append(p.formatHandlers[:i], p.formatHandlers[i+1:]...)
438 break
439 }
440 }
441 }
442
443 func (p *Shm) Dispatch(ctx context.Context, event *Event) {
444 switch event.Opcode {
445 case 0:
446 if len(p.formatHandlers) > 0 {
447 ev := ShmFormatEvent{}
448 ev.EventContext = ctx
449 ev.Format = event.Uint32()
450 p.mu.RLock()
451 for _, h := range p.formatHandlers {
452 h.HandleShmFormat(ev)
453 }
454 p.mu.RUnlock()
455 }
456 }
457 }
458
459 type Shm struct {
460 BaseProxy
461 mu sync.RWMutex
462 formatHandlers []ShmFormatHandler
463 }
464
465 func NewShm(ctx *Context) *Shm {
466 ret := new(Shm)
467 ctx.Register(ret)
468 return ret
469 }
470
471 // CreatePool will create a shm pool.
472 //
473 //
474 // Create a new wl_shm_pool object.
475 //
476 // The pool can be used to create shared memory based buffer
477 // objects. The server will mmap size bytes of the passed file
478 // descriptor, to use as backing memory for the pool.
479 //
480 func (p *Shm) CreatePool(fd uintptr, size int32) (*ShmPool, error) {
481 ret := NewShmPool(p.Context())
482 return ret, p.Context().SendRequest(p, 0, Proxy(ret), fd, size)
483 }
484
485 const (
486 ShmErrorInvalidFormat = 0
487 ShmErrorInvalidStride = 1
488 ShmErrorInvalidFd = 2
489 )
490
491 const (
492 ShmFormatArgb8888 = 0
493 ShmFormatXrgb8888 = 1
494 ShmFormatC8 = 0x20203843
495 ShmFormatRgb332 = 0x38424752
496 ShmFormatBgr233 = 0x38524742
497 ShmFormatXrgb4444 = 0x32315258
498 ShmFormatXbgr4444 = 0x32314258
499 ShmFormatRgbx4444 = 0x32315852
500 ShmFormatBgrx4444 = 0x32315842
501 ShmFormatArgb4444 = 0x32315241
502 ShmFormatAbgr4444 = 0x32314241
503 ShmFormatRgba4444 = 0x32314152
504 ShmFormatBgra4444 = 0x32314142
505 ShmFormatXrgb1555 = 0x35315258
506 ShmFormatXbgr1555 = 0x35314258
507 ShmFormatRgbx5551 = 0x35315852
508 ShmFormatBgrx5551 = 0x35315842
509 ShmFormatArgb1555 = 0x35315241
510 ShmFormatAbgr1555 = 0x35314241
511 ShmFormatRgba5551 = 0x35314152
512 ShmFormatBgra5551 = 0x35314142
513 ShmFormatRgb565 = 0x36314752
514 ShmFormatBgr565 = 0x36314742
515 ShmFormatRgb888 = 0x34324752
516 ShmFormatBgr888 = 0x34324742
517 ShmFormatXbgr8888 = 0x34324258
518 ShmFormatRgbx8888 = 0x34325852
519 ShmFormatBgrx8888 = 0x34325842
520 ShmFormatAbgr8888 = 0x34324241
521 ShmFormatRgba8888 = 0x34324152
522 ShmFormatBgra8888 = 0x34324142
523 ShmFormatXrgb2101010 = 0x30335258
524 ShmFormatXbgr2101010 = 0x30334258
525 ShmFormatRgbx1010102 = 0x30335852
526 ShmFormatBgrx1010102 = 0x30335842
527 ShmFormatArgb2101010 = 0x30335241
528 ShmFormatAbgr2101010 = 0x30334241
529 ShmFormatRgba1010102 = 0x30334152
530 ShmFormatBgra1010102 = 0x30334142
531 ShmFormatYuyv = 0x56595559
532 ShmFormatYvyu = 0x55595659
533 ShmFormatUyvy = 0x59565955
534 ShmFormatVyuy = 0x59555956
535 ShmFormatAyuv = 0x56555941
536 ShmFormatNv12 = 0x3231564e
537 ShmFormatNv21 = 0x3132564e
538 ShmFormatNv16 = 0x3631564e
539 ShmFormatNv61 = 0x3136564e
540 ShmFormatYuv410 = 0x39565559
541 ShmFormatYvu410 = 0x39555659
542 ShmFormatYuv411 = 0x31315559
543 ShmFormatYvu411 = 0x31315659
544 ShmFormatYuv420 = 0x32315559
545 ShmFormatYvu420 = 0x32315659
546 ShmFormatYuv422 = 0x36315559
547 ShmFormatYvu422 = 0x36315659
548 ShmFormatYuv444 = 0x34325559
549 ShmFormatYvu444 = 0x34325659
550 )
551
552 type BufferReleaseEvent struct {
553 EventContext context.Context
554 }
555
556 type BufferReleaseHandler interface {
557 HandleBufferRelease(BufferReleaseEvent)
558 }
559
560 func (p *Buffer) AddReleaseHandler(h BufferReleaseHandler) {
561 if h != nil {
562 p.mu.Lock()
563 p.releaseHandlers = append(p.releaseHandlers, h)
564 p.mu.Unlock()
565 }
566 }
567
568 func (p *Buffer) RemoveReleaseHandler(h BufferReleaseHandler) {
569 p.mu.Lock()
570 defer p.mu.Unlock()
571
572 for i, e := range p.releaseHandlers {
573 if e == h {
574 p.releaseHandlers = append(p.releaseHandlers[:i], p.releaseHandlers[i+1:]...)
575 break
576 }
577 }
578 }
579
580 func (p *Buffer) Dispatch(ctx context.Context, event *Event) {
581 switch event.Opcode {
582 case 0:
583 if len(p.releaseHandlers) > 0 {
584 ev := BufferReleaseEvent{}
585 ev.EventContext = ctx
586 p.mu.RLock()
587 for _, h := range p.releaseHandlers {
588 h.HandleBufferRelease(ev)
589 }
590 p.mu.RUnlock()
591 }
592 }
593 }
594
595 type Buffer struct {
596 BaseProxy
597 mu sync.RWMutex
598 releaseHandlers []BufferReleaseHandler
599 }
600
601 func NewBuffer(ctx *Context) *Buffer {
602 ret := new(Buffer)
603 ctx.Register(ret)
604 return ret
605 }
606
607 // Destroy will destroy a buffer.
608 //
609 //
610 // Destroy a buffer. If and how you need to release the backing
611 // storage is defined by the buffer factory interface.
612 //
613 // For possible side-effects to a surface, see wl_surface.attach.
614 //
615 func (p *Buffer) Destroy() error {
616 return p.Context().SendRequest(p, 0)
617 }
618
619 type DataOfferOfferEvent struct {
620 EventContext context.Context
621 MimeType string
622 }
623
624 type DataOfferOfferHandler interface {
625 HandleDataOfferOffer(DataOfferOfferEvent)
626 }
627
628 func (p *DataOffer) AddOfferHandler(h DataOfferOfferHandler) {
629 if h != nil {
630 p.mu.Lock()
631 p.offerHandlers = append(p.offerHandlers, h)
632 p.mu.Unlock()
633 }
634 }
635
636 func (p *DataOffer) RemoveOfferHandler(h DataOfferOfferHandler) {
637 p.mu.Lock()
638 defer p.mu.Unlock()
639
640 for i, e := range p.offerHandlers {
641 if e == h {
642 p.offerHandlers = append(p.offerHandlers[:i], p.offerHandlers[i+1:]...)
643 break
644 }
645 }
646 }
647
648 type DataOfferSourceActionsEvent struct {
649 EventContext context.Context
650 SourceActions uint32
651 }
652
653 type DataOfferSourceActionsHandler interface {
654 HandleDataOfferSourceActions(DataOfferSourceActionsEvent)
655 }
656
657 func (p *DataOffer) AddSourceActionsHandler(h DataOfferSourceActionsHandler) {
658 if h != nil {
659 p.mu.Lock()
660 p.sourceActionsHandlers = append(p.sourceActionsHandlers, h)
661 p.mu.Unlock()
662 }
663 }
664
665 func (p *DataOffer) RemoveSourceActionsHandler(h DataOfferSourceActionsHandler) {
666 p.mu.Lock()
667 defer p.mu.Unlock()
668
669 for i, e := range p.sourceActionsHandlers {
670 if e == h {
671 p.sourceActionsHandlers = append(p.sourceActionsHandlers[:i], p.sourceActionsHandlers[i+1:]...)
672 break
673 }
674 }
675 }
676
677 type DataOfferActionEvent struct {
678 EventContext context.Context
679 DndAction uint32
680 }
681
682 type DataOfferActionHandler interface {
683 HandleDataOfferAction(DataOfferActionEvent)
684 }
685
686 func (p *DataOffer) AddActionHandler(h DataOfferActionHandler) {
687 if h != nil {
688 p.mu.Lock()
689 p.actionHandlers = append(p.actionHandlers, h)
690 p.mu.Unlock()
691 }
692 }
693
694 func (p *DataOffer) RemoveActionHandler(h DataOfferActionHandler) {
695 p.mu.Lock()
696 defer p.mu.Unlock()
697
698 for i, e := range p.actionHandlers {
699 if e == h {
700 p.actionHandlers = append(p.actionHandlers[:i], p.actionHandlers[i+1:]...)
701 break
702 }
703 }
704 }
705
706 func (p *DataOffer) Dispatch(ctx context.Context, event *Event) {
707 switch event.Opcode {
708 case 0:
709 if len(p.offerHandlers) > 0 {
710 ev := DataOfferOfferEvent{}
711 ev.EventContext = ctx
712 ev.MimeType = event.String()
713 p.mu.RLock()
714 for _, h := range p.offerHandlers {
715 h.HandleDataOfferOffer(ev)
716 }
717 p.mu.RUnlock()
718 }
719 case 1:
720 if len(p.sourceActionsHandlers) > 0 {
721 ev := DataOfferSourceActionsEvent{}
722 ev.EventContext = ctx
723 ev.SourceActions = event.Uint32()
724 p.mu.RLock()
725 for _, h := range p.sourceActionsHandlers {
726 h.HandleDataOfferSourceActions(ev)
727 }
728 p.mu.RUnlock()
729 }
730 case 2:
731 if len(p.actionHandlers) > 0 {
732 ev := DataOfferActionEvent{}
733 ev.EventContext = ctx
734 ev.DndAction = event.Uint32()
735 p.mu.RLock()
736 for _, h := range p.actionHandlers {
737 h.HandleDataOfferAction(ev)
738 }
739 p.mu.RUnlock()
740 }
741 }
742 }
743
744 type DataOffer struct {
745 BaseProxy
746 mu sync.RWMutex
747 offerHandlers []DataOfferOfferHandler
748 sourceActionsHandlers []DataOfferSourceActionsHandler
749 actionHandlers []DataOfferActionHandler
750 }
751
752 func NewDataOffer(ctx *Context) *DataOffer {
753 ret := new(DataOffer)
754 ctx.Register(ret)
755 return ret
756 }
757
758 // Accept will accept one of the offered mime types.
759 //
760 //
761 // Indicate that the client can accept the given mime type, or
762 // NULL for not accepted.
763 //
764 // For objects of version 2 or older, this request is used by the
765 // client to give feedback whether the client can receive the given
766 // mime type, or NULL if none is accepted; the feedback does not
767 // determine whether the drag-and-drop operation succeeds or not.
768 //
769 // For objects of version 3 or newer, this request determines the
770 // final result of the drag-and-drop operation. If the end result
771 // is that no mime types were accepted, the drag-and-drop operation
772 // will be cancelled and the corresponding drag source will receive
773 // wl_data_source.cancelled. Clients may still use this event in
774 // conjunction with wl_data_source.action for feedback.
775 //
776 func (p *DataOffer) Accept(serial uint32, mime_type string) error {
777 return p.Context().SendRequest(p, 0, serial, mime_type)
778 }
779
780 // Receive will request that the data is transferred.
781 //
782 //
783 // To transfer the offered data, the client issues this request
784 // and indicates the mime type it wants to receive. The transfer
785 // happens through the passed file descriptor (typically created
786 // with the pipe system call). The source client writes the data
787 // in the mime type representation requested and then closes the
788 // file descriptor.
789 //
790 // The receiving client reads from the read end of the pipe until
791 // EOF and then closes its end, at which point the transfer is
792 // complete.
793 //
794 // This request may happen multiple times for different mime types,
795 // both before and after wl_data_device.drop. Drag-and-drop destination
796 // clients may preemptively fetch data or examine it more closely to
797 // determine acceptance.
798 //
799 func (p *DataOffer) Receive(mime_type string, fd uintptr) error {
800 return p.Context().SendRequest(p, 1, mime_type, fd)
801 }
802
803 // Destroy will destroy data offer.
804 //
805 //
806 // Destroy the data offer.
807 //
808 func (p *DataOffer) Destroy() error {
809 return p.Context().SendRequest(p, 2)
810 }
811
812 // Finish will the offer will no longer be used.
813 //
814 //
815 // Notifies the compositor that the drag destination successfully
816 // finished the drag-and-drop operation.
817 //
818 // Upon receiving this request, the compositor will emit
819 // wl_data_source.dnd_finished on the drag source client.
820 //
821 // It is a client error to perform other requests than
822 // wl_data_offer.destroy after this one. It is also an error to perform
823 // this request after a NULL mime type has been set in
824 // wl_data_offer.accept or no action was received through
825 // wl_data_offer.action.
826 //
827 func (p *DataOffer) Finish() error {
828 return p.Context().SendRequest(p, 3)
829 }
830
831 // SetActions will set the available/preferred drag-and-drop actions.
832 //
833 //
834 // Sets the actions that the destination side client supports for
835 // this operation. This request may trigger the emission of
836 // wl_data_source.action and wl_data_offer.action events if the compositor
837 // needs to change the selected action.
838 //
839 // This request can be called multiple times throughout the
840 // drag-and-drop operation, typically in response to wl_data_device.enter
841 // or wl_data_device.motion events.
842 //
843 // This request determines the final result of the drag-and-drop
844 // operation. If the end result is that no action is accepted,
845 // the drag source will receive wl_drag_source.cancelled.
846 //
847 // The dnd_actions argument must contain only values expressed in the
848 // wl_data_device_manager.dnd_actions enum, and the preferred_action
849 // argument must only contain one of those values set, otherwise it
850 // will result in a protocol error.
851 //
852 // While managing an "ask" action, the destination drag-and-drop client
853 // may perform further wl_data_offer.receive requests, and is expected
854 // to perform one last wl_data_offer.set_actions request with a preferred
855 // action other than "ask" (and optionally wl_data_offer.accept) before
856 // requesting wl_data_offer.finish, in order to convey the action selected
857 // by the user. If the preferred action is not in the
858 // wl_data_offer.source_actions mask, an error will be raised.
859 //
860 // If the "ask" action is dismissed (e.g. user cancellation), the client
861 // is expected to perform wl_data_offer.destroy right away.
862 //
863 // This request can only be made on drag-and-drop offers, a protocol error
864 // will be raised otherwise.
865 //
866 func (p *DataOffer) SetActions(dnd_actions uint32, preferred_action uint32) error {
867 return p.Context().SendRequest(p, 4, dnd_actions, preferred_action)
868 }
869
870 const (
871 DataOfferErrorInvalidFinish = 0
872 DataOfferErrorInvalidActionMask = 1
873 DataOfferErrorInvalidAction = 2
874 DataOfferErrorInvalidOffer = 3
875 )
876
877 type DataSourceTargetEvent struct {
878 EventContext context.Context
879 MimeType string
880 }
881
882 type DataSourceTargetHandler interface {
883 HandleDataSourceTarget(DataSourceTargetEvent)
884 }
885
886 func (p *DataSource) AddTargetHandler(h DataSourceTargetHandler) {
887 if h != nil {
888 p.mu.Lock()
889 p.targetHandlers = append(p.targetHandlers, h)
890 p.mu.Unlock()
891 }
892 }
893
894 func (p *DataSource) RemoveTargetHandler(h DataSourceTargetHandler) {
895 p.mu.Lock()
896 defer p.mu.Unlock()
897
898 for i, e := range p.targetHandlers {
899 if e == h {
900 p.targetHandlers = append(p.targetHandlers[:i], p.targetHandlers[i+1:]...)
901 break
902 }
903 }
904 }
905
906 type DataSourceSendEvent struct {
907 EventContext context.Context
908 MimeType string
909 Fd uintptr
910 }
911
912 type DataSourceSendHandler interface {
913 HandleDataSourceSend(DataSourceSendEvent)
914 }
915
916 func (p *DataSource) AddSendHandler(h DataSourceSendHandler) {
917 if h != nil {
918 p.mu.Lock()
919 p.sendHandlers = append(p.sendHandlers, h)
920 p.mu.Unlock()
921 }
922 }
923
924 func (p *DataSource) RemoveSendHandler(h DataSourceSendHandler) {
925 p.mu.Lock()
926 defer p.mu.Unlock()
927
928 for i, e := range p.sendHandlers {
929 if e == h {
930 p.sendHandlers = append(p.sendHandlers[:i], p.sendHandlers[i+1:]...)
931 break
932 }
933 }
934 }
935
936 type DataSourceCancelledEvent struct {
937 EventContext context.Context
938 }
939
940 type DataSourceCancelledHandler interface {
941 HandleDataSourceCancelled(DataSourceCancelledEvent)
942 }
943
944 func (p *DataSource) AddCancelledHandler(h DataSourceCancelledHandler) {
945 if h != nil {
946 p.mu.Lock()
947 p.cancelledHandlers = append(p.cancelledHandlers, h)
948 p.mu.Unlock()
949 }
950 }
951
952 func (p *DataSource) RemoveCancelledHandler(h DataSourceCancelledHandler) {
953 p.mu.Lock()
954 defer p.mu.Unlock()
955
956 for i, e := range p.cancelledHandlers {
957 if e == h {
958 p.cancelledHandlers = append(p.cancelledHandlers[:i], p.cancelledHandlers[i+1:]...)
959 break
960 }
961 }
962 }
963
964 type DataSourceDndDropPerformedEvent struct {
965 EventContext context.Context
966 }
967
968 type DataSourceDndDropPerformedHandler interface {
969 HandleDataSourceDndDropPerformed(DataSourceDndDropPerformedEvent)
970 }
971
972 func (p *DataSource) AddDndDropPerformedHandler(h DataSourceDndDropPerformedHandler) {
973 if h != nil {
974 p.mu.Lock()
975 p.dndDropPerformedHandlers = append(p.dndDropPerformedHandlers, h)
976 p.mu.Unlock()
977 }
978 }
979
980 func (p *DataSource) RemoveDndDropPerformedHandler(h DataSourceDndDropPerformedHandler) {
981 p.mu.Lock()
982 defer p.mu.Unlock()
983
984 for i, e := range p.dndDropPerformedHandlers {
985 if e == h {
986 p.dndDropPerformedHandlers = append(p.dndDropPerformedHandlers[:i], p.dndDropPerformedHandlers[i+1:]...)
987 break
988 }
989 }
990 }
991
992 type DataSourceDndFinishedEvent struct {
993 EventContext context.Context
994 }
995
996 type DataSourceDndFinishedHandler interface {
997 HandleDataSourceDndFinished(DataSourceDndFinishedEvent)
998 }
999
1000 func (p *DataSource) AddDndFinishedHandler(h DataSourceDndFinishedHandler) {
1001 if h != nil {
1002 p.mu.Lock()
1003 p.dndFinishedHandlers = append(p.dndFinishedHandlers, h)
1004 p.mu.Unlock()
1005 }
1006 }
1007
1008 func (p *DataSource) RemoveDndFinishedHandler(h DataSourceDndFinishedHandler) {
1009 p.mu.Lock()
1010 defer p.mu.Unlock()
1011
1012 for i, e := range p.dndFinishedHandlers {
1013 if e == h {
1014 p.dndFinishedHandlers = append(p.dndFinishedHandlers[:i], p.dndFinishedHandlers[i+1:]...)
1015 break
1016 }
1017 }
1018 }
1019
1020 type DataSourceActionEvent struct {
1021 EventContext context.Context
1022 DndAction uint32
1023 }
1024
1025 type DataSourceActionHandler interface {
1026 HandleDataSourceAction(DataSourceActionEvent)
1027 }
1028
1029 func (p *DataSource) AddActionHandler(h DataSourceActionHandler) {
1030 if h != nil {
1031 p.mu.Lock()
1032 p.actionHandlers = append(p.actionHandlers, h)
1033 p.mu.Unlock()
1034 }
1035 }
1036
1037 func (p *DataSource) RemoveActionHandler(h DataSourceActionHandler) {
1038 p.mu.Lock()
1039 defer p.mu.Unlock()
1040
1041 for i, e := range p.actionHandlers {
1042 if e == h {
1043 p.actionHandlers = append(p.actionHandlers[:i], p.actionHandlers[i+1:]...)
1044 break
1045 }
1046 }
1047 }
1048
1049 func (p *DataSource) Dispatch(ctx context.Context, event *Event) {
1050 switch event.Opcode {
1051 case 0:
1052 if len(p.targetHandlers) > 0 {
1053 ev := DataSourceTargetEvent{}
1054 ev.EventContext = ctx
1055 ev.MimeType = event.String()
1056 p.mu.RLock()
1057 for _, h := range p.targetHandlers {
1058 h.HandleDataSourceTarget(ev)
1059 }
1060 p.mu.RUnlock()
1061 }
1062 case 1:
1063 if len(p.sendHandlers) > 0 {
1064 ev := DataSourceSendEvent{}
1065 ev.EventContext = ctx
1066 ev.MimeType = event.String()
1067 ev.Fd = event.FD()
1068 p.mu.RLock()
1069 for _, h := range p.sendHandlers {
1070 h.HandleDataSourceSend(ev)
1071 }
1072 p.mu.RUnlock()
1073 }
1074 case 2:
1075 if len(p.cancelledHandlers) > 0 {
1076 ev := DataSourceCancelledEvent{}
1077 ev.EventContext = ctx
1078 p.mu.RLock()
1079 for _, h := range p.cancelledHandlers {
1080 h.HandleDataSourceCancelled(ev)
1081 }
1082 p.mu.RUnlock()
1083 }
1084 case 3:
1085 if len(p.dndDropPerformedHandlers) > 0 {
1086 ev := DataSourceDndDropPerformedEvent{}
1087 ev.EventContext = ctx
1088 p.mu.RLock()
1089 for _, h := range p.dndDropPerformedHandlers {
1090 h.HandleDataSourceDndDropPerformed(ev)
1091 }
1092 p.mu.RUnlock()
1093 }
1094 case 4:
1095 if len(p.dndFinishedHandlers) > 0 {
1096 ev := DataSourceDndFinishedEvent{}
1097 ev.EventContext = ctx
1098 p.mu.RLock()
1099 for _, h := range p.dndFinishedHandlers {
1100 h.HandleDataSourceDndFinished(ev)
1101 }
1102 p.mu.RUnlock()
1103 }
1104 case 5:
1105 if len(p.actionHandlers) > 0 {
1106 ev := DataSourceActionEvent{}
1107 ev.EventContext = ctx
1108 ev.DndAction = event.Uint32()
1109 p.mu.RLock()
1110 for _, h := range p.actionHandlers {
1111 h.HandleDataSourceAction(ev)
1112 }
1113 p.mu.RUnlock()
1114 }
1115 }
1116 }
1117
1118 type DataSource struct {
1119 BaseProxy
1120 mu sync.RWMutex
1121 targetHandlers []DataSourceTargetHandler
1122 sendHandlers []DataSourceSendHandler
1123 cancelledHandlers []DataSourceCancelledHandler
1124 dndDropPerformedHandlers []DataSourceDndDropPerformedHandler
1125 dndFinishedHandlers []DataSourceDndFinishedHandler
1126 actionHandlers []DataSourceActionHandler
1127 }
1128
1129 func NewDataSource(ctx *Context) *DataSource {
1130 ret := new(DataSource)
1131 ctx.Register(ret)
1132 return ret
1133 }
1134
1135 // Offer will add an offered mime type.
1136 //
1137 //
1138 // This request adds a mime type to the set of mime types
1139 // advertised to targets. Can be called several times to offer
1140 // multiple types.
1141 //
1142 func (p *DataSource) Offer(mime_type string) error {
1143 return p.Context().SendRequest(p, 0, mime_type)
1144 }
1145
1146 // Destroy will destroy the data source.
1147 //
1148 //
1149 // Destroy the data source.
1150 //
1151 func (p *DataSource) Destroy() error {
1152 return p.Context().SendRequest(p, 1)
1153 }
1154
1155 // SetActions will set the available drag-and-drop actions.
1156 //
1157 //
1158 // Sets the actions that the source side client supports for this
1159 // operation. This request may trigger wl_data_source.action and
1160 // wl_data_offer.action events if the compositor needs to change the
1161 // selected action.
1162 //
1163 // The dnd_actions argument must contain only values expressed in the
1164 // wl_data_device_manager.dnd_actions enum, otherwise it will result
1165 // in a protocol error.
1166 //
1167 // This request must be made once only, and can only be made on sources
1168 // used in drag-and-drop, so it must be performed before
1169 // wl_data_device.start_drag. Attempting to use the source other than
1170 // for drag-and-drop will raise a protocol error.
1171 //
1172 func (p *DataSource) SetActions(dnd_actions uint32) error {
1173 return p.Context().SendRequest(p, 2, dnd_actions)
1174 }
1175
1176 const (
1177 DataSourceErrorInvalidActionMask = 0
1178 DataSourceErrorInvalidSource = 1
1179 )
1180
1181 type DataDeviceDataOfferEvent struct {
1182 EventContext context.Context
1183 Id *DataOffer
1184 }
1185
1186 type DataDeviceDataOfferHandler interface {
1187 HandleDataDeviceDataOffer(DataDeviceDataOfferEvent)
1188 }
1189
1190 func (p *DataDevice) AddDataOfferHandler(h DataDeviceDataOfferHandler) {
1191 if h != nil {
1192 p.mu.Lock()
1193 p.dataOfferHandlers = append(p.dataOfferHandlers, h)
1194 p.mu.Unlock()
1195 }
1196 }
1197
1198 func (p *DataDevice) RemoveDataOfferHandler(h DataDeviceDataOfferHandler) {
1199 p.mu.Lock()
1200 defer p.mu.Unlock()
1201
1202 for i, e := range p.dataOfferHandlers {
1203 if e == h {
1204 p.dataOfferHandlers = append(p.dataOfferHandlers[:i], p.dataOfferHandlers[i+1:]...)
1205 break
1206 }
1207 }
1208 }
1209
1210 type DataDeviceEnterEvent struct {
1211 EventContext context.Context
1212 Serial uint32
1213 Surface *Surface
1214 X float32
1215 Y float32
1216 Id *DataOffer
1217 }
1218
1219 type DataDeviceEnterHandler interface {
1220 HandleDataDeviceEnter(DataDeviceEnterEvent)
1221 }
1222
1223 func (p *DataDevice) AddEnterHandler(h DataDeviceEnterHandler) {
1224 if h != nil {
1225 p.mu.Lock()
1226 p.enterHandlers = append(p.enterHandlers, h)
1227 p.mu.Unlock()
1228 }
1229 }
1230
1231 func (p *DataDevice) RemoveEnterHandler(h DataDeviceEnterHandler) {
1232 p.mu.Lock()
1233 defer p.mu.Unlock()
1234
1235 for i, e := range p.enterHandlers {
1236 if e == h {
1237 p.enterHandlers = append(p.enterHandlers[:i], p.enterHandlers[i+1:]...)
1238 break
1239 }
1240 }
1241 }
1242
1243 type DataDeviceLeaveEvent struct {
1244 EventContext context.Context
1245 }
1246
1247 type DataDeviceLeaveHandler interface {
1248 HandleDataDeviceLeave(DataDeviceLeaveEvent)
1249 }
1250
1251 func (p *DataDevice) AddLeaveHandler(h DataDeviceLeaveHandler) {
1252 if h != nil {
1253 p.mu.Lock()
1254 p.leaveHandlers = append(p.leaveHandlers, h)
1255 p.mu.Unlock()
1256 }
1257 }
1258
1259 func (p *DataDevice) RemoveLeaveHandler(h DataDeviceLeaveHandler) {
1260 p.mu.Lock()
1261 defer p.mu.Unlock()
1262
1263 for i, e := range p.leaveHandlers {
1264 if e == h {
1265 p.leaveHandlers = append(p.leaveHandlers[:i], p.leaveHandlers[i+1:]...)
1266 break
1267 }
1268 }
1269 }
1270
1271 type DataDeviceMotionEvent struct {
1272 EventContext context.Context
1273 Time uint32
1274 X float32
1275 Y float32
1276 }
1277
1278 type DataDeviceMotionHandler interface {
1279 HandleDataDeviceMotion(DataDeviceMotionEvent)
1280 }
1281
1282 func (p *DataDevice) AddMotionHandler(h DataDeviceMotionHandler) {
1283 if h != nil {
1284 p.mu.Lock()
1285 p.motionHandlers = append(p.motionHandlers, h)
1286 p.mu.Unlock()
1287 }
1288 }
1289
1290 func (p *DataDevice) RemoveMotionHandler(h DataDeviceMotionHandler) {
1291 p.mu.Lock()
1292 defer p.mu.Unlock()
1293
1294 for i, e := range p.motionHandlers {
1295 if e == h {
1296 p.motionHandlers = append(p.motionHandlers[:i], p.motionHandlers[i+1:]...)
1297 break
1298 }
1299 }
1300 }
1301
1302 type DataDeviceDropEvent struct {
1303 EventContext context.Context
1304 }
1305
1306 type DataDeviceDropHandler interface {
1307 HandleDataDeviceDrop(DataDeviceDropEvent)
1308 }
1309
1310 func (p *DataDevice) AddDropHandler(h DataDeviceDropHandler) {
1311 if h != nil {
1312 p.mu.Lock()
1313 p.dropHandlers = append(p.dropHandlers, h)
1314 p.mu.Unlock()
1315 }
1316 }
1317
1318 func (p *DataDevice) RemoveDropHandler(h DataDeviceDropHandler) {
1319 p.mu.Lock()
1320 defer p.mu.Unlock()
1321
1322 for i, e := range p.dropHandlers {
1323 if e == h {
1324 p.dropHandlers = append(p.dropHandlers[:i], p.dropHandlers[i+1:]...)
1325 break
1326 }
1327 }
1328 }
1329
1330 type DataDeviceSelectionEvent struct {
1331 EventContext context.Context
1332 Id *DataOffer
1333 }
1334
1335 type DataDeviceSelectionHandler interface {
1336 HandleDataDeviceSelection(DataDeviceSelectionEvent)
1337 }
1338
1339 func (p *DataDevice) AddSelectionHandler(h DataDeviceSelectionHandler) {
1340 if h != nil {
1341 p.mu.Lock()
1342 p.selectionHandlers = append(p.selectionHandlers, h)
1343 p.mu.Unlock()
1344 }
1345 }
1346
1347 func (p *DataDevice) RemoveSelectionHandler(h DataDeviceSelectionHandler) {
1348 p.mu.Lock()
1349 defer p.mu.Unlock()
1350
1351 for i, e := range p.selectionHandlers {
1352 if e == h {
1353 p.selectionHandlers = append(p.selectionHandlers[:i], p.selectionHandlers[i+1:]...)
1354 break
1355 }
1356 }
1357 }
1358
1359 func (p *DataDevice) Dispatch(ctx context.Context, event *Event) {
1360 switch event.Opcode {
1361 case 0:
1362 if len(p.dataOfferHandlers) > 0 {
1363 ev := DataDeviceDataOfferEvent{}
1364 ev.EventContext = ctx
1365 ev.Id = event.Proxy(p.Context()).(*DataOffer)
1366 p.mu.RLock()
1367 for _, h := range p.dataOfferHandlers {
1368 h.HandleDataDeviceDataOffer(ev)
1369 }
1370 p.mu.RUnlock()
1371 }
1372 case 1:
1373 if len(p.enterHandlers) > 0 {
1374 ev := DataDeviceEnterEvent{}
1375 ev.EventContext = ctx
1376 ev.Serial = event.Uint32()
1377 ev.Surface = event.Proxy(p.Context()).(*Surface)
1378 ev.X = event.Float32()
1379 ev.Y = event.Float32()
1380 ev.Id = event.Proxy(p.Context()).(*DataOffer)
1381 p.mu.RLock()
1382 for _, h := range p.enterHandlers {
1383 h.HandleDataDeviceEnter(ev)
1384 }
1385 p.mu.RUnlock()
1386 }
1387 case 2:
1388 if len(p.leaveHandlers) > 0 {
1389 ev := DataDeviceLeaveEvent{}
1390 ev.EventContext = ctx
1391 p.mu.RLock()
1392 for _, h := range p.leaveHandlers {
1393 h.HandleDataDeviceLeave(ev)
1394 }
1395 p.mu.RUnlock()
1396 }
1397 case 3:
1398 if len(p.motionHandlers) > 0 {
1399 ev := DataDeviceMotionEvent{}
1400 ev.EventContext = ctx
1401 ev.Time = event.Uint32()
1402 ev.X = event.Float32()
1403 ev.Y = event.Float32()
1404 p.mu.RLock()
1405 for _, h := range p.motionHandlers {
1406 h.HandleDataDeviceMotion(ev)
1407 }
1408 p.mu.RUnlock()
1409 }
1410 case 4:
1411 if len(p.dropHandlers) > 0 {
1412 ev := DataDeviceDropEvent{}
1413 ev.EventContext = ctx
1414 p.mu.RLock()
1415 for _, h := range p.dropHandlers {
1416 h.HandleDataDeviceDrop(ev)
1417 }
1418 p.mu.RUnlock()
1419 }
1420 case 5:
1421 if len(p.selectionHandlers) > 0 {
1422 ev := DataDeviceSelectionEvent{}
1423 ev.EventContext = ctx
1424 ev.Id = event.Proxy(p.Context()).(*DataOffer)
1425 p.mu.RLock()
1426 for _, h := range p.selectionHandlers {
1427 h.HandleDataDeviceSelection(ev)
1428 }
1429 p.mu.RUnlock()
1430 }
1431 }
1432 }
1433
1434 type DataDevice struct {
1435 BaseProxy
1436 mu sync.RWMutex
1437 dataOfferHandlers []DataDeviceDataOfferHandler
1438 enterHandlers []DataDeviceEnterHandler
1439 leaveHandlers []DataDeviceLeaveHandler
1440 motionHandlers []DataDeviceMotionHandler
1441 dropHandlers []DataDeviceDropHandler
1442 selectionHandlers []DataDeviceSelectionHandler
1443 }
1444
1445 func NewDataDevice(ctx *Context) *DataDevice {
1446 ret := new(DataDevice)
1447 ctx.Register(ret)
1448 return ret
1449 }
1450
1451 // StartDrag will start drag-and-drop operation.
1452 //
1453 //
1454 // This request asks the compositor to start a drag-and-drop
1455 // operation on behalf of the client.
1456 //
1457 // The source argument is the data source that provides the data
1458 // for the eventual data transfer. If source is NULL, enter, leave
1459 // and motion events are sent only to the client that initiated the
1460 // drag and the client is expected to handle the data passing
1461 // internally.
1462 //
1463 // The origin surface is the surface where the drag originates and
1464 // the client must have an active implicit grab that matches the
1465 // serial.
1466 //
1467 // The icon surface is an optional (can be NULL) surface that
1468 // provides an icon to be moved around with the cursor. Initially,
1469 // the top-left corner of the icon surface is placed at the cursor
1470 // hotspot, but subsequent wl_surface.attach request can move the
1471 // relative position. Attach requests must be confirmed with
1472 // wl_surface.commit as usual. The icon surface is given the role of
1473 // a drag-and-drop icon. If the icon surface already has another role,
1474 // it raises a protocol error.
1475 //
1476 // The current and pending input regions of the icon wl_surface are
1477 // cleared, and wl_surface.set_input_region is ignored until the
1478 // wl_surface is no longer used as the icon surface. When the use
1479 // as an icon ends, the current and pending input regions become
1480 // undefined, and the wl_surface is unmapped.
1481 //
1482 func (p *DataDevice) StartDrag(source *DataSource, origin *Surface, icon *Surface, serial uint32) error {
1483 return p.Context().SendRequest(p, 0, source, origin, icon, serial)
1484 }
1485
1486 // SetSelection will copy data to the selection.
1487 //
1488 //
1489 // This request asks the compositor to set the selection
1490 // to the data from the source on behalf of the client.
1491 //
1492 // To unset the selection, set the source to NULL.
1493 //
1494 func (p *DataDevice) SetSelection(source *DataSource, serial uint32) error {
1495 return p.Context().SendRequest(p, 1, source, serial)
1496 }
1497
1498 // Release will destroy data device.
1499 //
1500 //
1501 // This request destroys the data device.
1502 //
1503 func (p *DataDevice) Release() error {
1504 return p.Context().SendRequest(p, 2)
1505 }
1506
1507 const (
1508 DataDeviceErrorRole = 0
1509 )
1510
1511 type DataDeviceManager struct {
1512 BaseProxy
1513 }
1514
1515 func NewDataDeviceManager(ctx *Context) *DataDeviceManager {
1516 ret := new(DataDeviceManager)
1517 ctx.Register(ret)
1518 return ret
1519 }
1520
1521 // CreateDataSource will create a new data source.
1522 //
1523 //
1524 // Create a new data source.
1525 //
1526 func (p *DataDeviceManager) CreateDataSource() (*DataSource, error) {
1527 ret := NewDataSource(p.Context())
1528 return ret, p.Context().SendRequest(p, 0, Proxy(ret))
1529 }
1530
1531 // GetDataDevice will create a new data device.
1532 //
1533 //
1534 // Create a new data device for a given seat.
1535 //
1536 func (p *DataDeviceManager) GetDataDevice(seat *Seat) (*DataDevice, error) {
1537 ret := NewDataDevice(p.Context())
1538 return ret, p.Context().SendRequest(p, 1, Proxy(ret), seat)
1539 }
1540
1541 const (
1542 DataDeviceManagerDndActionNone = 0
1543 DataDeviceManagerDndActionCopy = 1
1544 DataDeviceManagerDndActionMove = 2
1545 DataDeviceManagerDndActionAsk = 4
1546 )
1547
1548 type Shell struct {
1549 BaseProxy
1550 }
1551
1552 func NewShell(ctx *Context) *Shell {
1553 ret := new(Shell)
1554 ctx.Register(ret)
1555 return ret
1556 }
1557
1558 // GetShellSurface will create a shell surface from a surface.
1559 //
1560 //
1561 // Create a shell surface for an existing surface. This gives
1562 // the wl_surface the role of a shell surface. If the wl_surface
1563 // already has another role, it raises a protocol error.
1564 //
1565 // Only one shell surface can be associated with a given surface.
1566 //
1567 func (p *Shell) GetShellSurface(surface *Surface) (*ShellSurface, error) {
1568 ret := NewShellSurface(p.Context())
1569 return ret, p.Context().SendRequest(p, 0, Proxy(ret), surface)
1570 }
1571
1572 const (
1573 ShellErrorRole = 0
1574 )
1575
1576 type ShellSurfacePingEvent struct {
1577 EventContext context.Context
1578 Serial uint32
1579 }
1580
1581 type ShellSurfacePingHandler interface {
1582 HandleShellSurfacePing(ShellSurfacePingEvent)
1583 }
1584
1585 func (p *ShellSurface) AddPingHandler(h ShellSurfacePingHandler) {
1586 if h != nil {
1587 p.mu.Lock()
1588 p.pingHandlers = append(p.pingHandlers, h)
1589 p.mu.Unlock()
1590 }
1591 }
1592
1593 func (p *ShellSurface) RemovePingHandler(h ShellSurfacePingHandler) {
1594 p.mu.Lock()
1595 defer p.mu.Unlock()
1596
1597 for i, e := range p.pingHandlers {
1598 if e == h {
1599 p.pingHandlers = append(p.pingHandlers[:i], p.pingHandlers[i+1:]...)
1600 break
1601 }
1602 }
1603 }
1604
1605 type ShellSurfaceConfigureEvent struct {
1606 EventContext context.Context
1607 Edges uint32
1608 Width int32
1609 Height int32
1610 }
1611
1612 type ShellSurfaceConfigureHandler interface {
1613 HandleShellSurfaceConfigure(ShellSurfaceConfigureEvent)
1614 }
1615
1616 func (p *ShellSurface) AddConfigureHandler(h ShellSurfaceConfigureHandler) {
1617 if h != nil {
1618 p.mu.Lock()
1619 p.configureHandlers = append(p.configureHandlers, h)
1620 p.mu.Unlock()
1621 }
1622 }
1623
1624 func (p *ShellSurface) RemoveConfigureHandler(h ShellSurfaceConfigureHandler) {
1625 p.mu.Lock()
1626 defer p.mu.Unlock()
1627
1628 for i, e := range p.configureHandlers {
1629 if e == h {
1630 p.configureHandlers = append(p.configureHandlers[:i], p.configureHandlers[i+1:]...)
1631 break
1632 }
1633 }
1634 }
1635
1636 type ShellSurfacePopupDoneEvent struct {
1637 EventContext context.Context
1638 }
1639
1640 type ShellSurfacePopupDoneHandler interface {
1641 HandleShellSurfacePopupDone(ShellSurfacePopupDoneEvent)
1642 }
1643
1644 func (p *ShellSurface) AddPopupDoneHandler(h ShellSurfacePopupDoneHandler) {
1645 if h != nil {
1646 p.mu.Lock()
1647 p.popupDoneHandlers = append(p.popupDoneHandlers, h)
1648 p.mu.Unlock()
1649 }
1650 }
1651
1652 func (p *ShellSurface) RemovePopupDoneHandler(h ShellSurfacePopupDoneHandler) {
1653 p.mu.Lock()
1654 defer p.mu.Unlock()
1655
1656 for i, e := range p.popupDoneHandlers {
1657 if e == h {
1658 p.popupDoneHandlers = append(p.popupDoneHandlers[:i], p.popupDoneHandlers[i+1:]...)
1659 break
1660 }
1661 }
1662 }
1663
1664 func (p *ShellSurface) Dispatch(ctx context.Context, event *Event) {
1665 switch event.Opcode {
1666 case 0:
1667 if len(p.pingHandlers) > 0 {
1668 ev := ShellSurfacePingEvent{}
1669 ev.EventContext = ctx
1670 ev.Serial = event.Uint32()
1671 p.mu.RLock()
1672 for _, h := range p.pingHandlers {
1673 h.HandleShellSurfacePing(ev)
1674 }
1675 p.mu.RUnlock()
1676 }
1677 case 1:
1678 if len(p.configureHandlers) > 0 {
1679 ev := ShellSurfaceConfigureEvent{}
1680 ev.EventContext = ctx
1681 ev.Edges = event.Uint32()
1682 ev.Width = event.Int32()
1683 ev.Height = event.Int32()
1684 p.mu.RLock()
1685 for _, h := range p.configureHandlers {
1686 h.HandleShellSurfaceConfigure(ev)
1687 }
1688 p.mu.RUnlock()
1689 }
1690 case 2:
1691 if len(p.popupDoneHandlers) > 0 {
1692 ev := ShellSurfacePopupDoneEvent{}
1693 ev.EventContext = ctx
1694 p.mu.RLock()
1695 for _, h := range p.popupDoneHandlers {
1696 h.HandleShellSurfacePopupDone(ev)
1697 }
1698 p.mu.RUnlock()
1699 }
1700 }
1701 }
1702
1703 type ShellSurface struct {
1704 BaseProxy
1705 mu sync.RWMutex
1706 pingHandlers []ShellSurfacePingHandler
1707 configureHandlers []ShellSurfaceConfigureHandler
1708 popupDoneHandlers []ShellSurfacePopupDoneHandler
1709 }
1710
1711 func NewShellSurface(ctx *Context) *ShellSurface {
1712 ret := new(ShellSurface)
1713 ctx.Register(ret)
1714 return ret
1715 }
1716
1717 // Pong will respond to a ping event.
1718 //
1719 //
1720 // A client must respond to a ping event with a pong request or
1721 // the client may be deemed unresponsive.
1722 //
1723 func (p *ShellSurface) Pong(serial uint32) error {
1724 return p.Context().SendRequest(p, 0, serial)
1725 }
1726
1727 // Move will start an interactive move.
1728 //
1729 //
1730 // Start a pointer-driven move of the surface.
1731 //
1732 // This request must be used in response to a button press event.
1733 // The server may ignore move requests depending on the state of
1734 // the surface (e.g. fullscreen or maximized).
1735 //
1736 func (p *ShellSurface) Move(seat *Seat, serial uint32) error {
1737 return p.Context().SendRequest(p, 1, seat, serial)
1738 }
1739
1740 // Resize will start an interactive resize.
1741 //
1742 //
1743 // Start a pointer-driven resizing of the surface.
1744 //
1745 // This request must be used in response to a button press event.
1746 // The server may ignore resize requests depending on the state of
1747 // the surface (e.g. fullscreen or maximized).
1748 //
1749 func (p *ShellSurface) Resize(seat *Seat, serial uint32, edges uint32) error {
1750 return p.Context().SendRequest(p, 2, seat, serial, edges)
1751 }
1752
1753 // SetToplevel will make the surface a toplevel surface.
1754 //
1755 //
1756 // Map the surface as a toplevel surface.
1757 //
1758 // A toplevel surface is not fullscreen, maximized or transient.
1759 //
1760 func (p *ShellSurface) SetToplevel() error {
1761 return p.Context().SendRequest(p, 3)
1762 }
1763
1764 // SetTransient will make the surface a transient surface.
1765 //
1766 //
1767 // Map the surface relative to an existing surface.
1768 //
1769 // The x and y arguments specify the location of the upper left
1770 // corner of the surface relative to the upper left corner of the
1771 // parent surface, in surface-local coordinates.
1772 //
1773 // The flags argument controls details of the transient behaviour.
1774 //
1775 func (p *ShellSurface) SetTransient(parent *Surface, x int32, y int32, flags uint32) error {
1776 return p.Context().SendRequest(p, 4, parent, x, y, flags)
1777 }
1778
1779 // SetFullscreen will make the surface a fullscreen surface.
1780 //
1781 //
1782 // Map the surface as a fullscreen surface.
1783 //
1784 // If an output parameter is given then the surface will be made
1785 // fullscreen on that output. If the client does not specify the
1786 // output then the compositor will apply its policy - usually
1787 // choosing the output on which the surface has the biggest surface
1788 // area.
1789 //
1790 // The client may specify a method to resolve a size conflict
1791 // between the output size and the surface size - this is provided
1792 // through the method parameter.
1793 //
1794 // The framerate parameter is used only when the method is set
1795 // to "driver", to indicate the preferred framerate. A value of 0
1796 // indicates that the client does not care about framerate. The
1797 // framerate is specified in mHz, that is framerate of 60000 is 60Hz.
1798 //
1799 // A method of "scale" or "driver" implies a scaling operation of
1800 // the surface, either via a direct scaling operation or a change of
1801 // the output mode. This will override any kind of output scaling, so
1802 // that mapping a surface with a buffer size equal to the mode can
1803 // fill the screen independent of buffer_scale.
1804 //
1805 // A method of "fill" means we don't scale up the buffer, however
1806 // any output scale is applied. This means that you may run into
1807 // an edge case where the application maps a buffer with the same
1808 // size of the output mode but buffer_scale 1 (thus making a
1809 // surface larger than the output). In this case it is allowed to
1810 // downscale the results to fit the screen.
1811 //
1812 // The compositor must reply to this request with a configure event
1813 // with the dimensions for the output on which the surface will
1814 // be made fullscreen.
1815 //
1816 func (p *ShellSurface) SetFullscreen(method uint32, framerate uint32, output *Output) error {
1817 return p.Context().SendRequest(p, 5, method, framerate, output)
1818 }
1819
1820 // SetPopup will make the surface a popup surface.
1821 //
1822 //
1823 // Map the surface as a popup.
1824 //
1825 // A popup surface is a transient surface with an added pointer
1826 // grab.
1827 //
1828 // An existing implicit grab will be changed to owner-events mode,
1829 // and the popup grab will continue after the implicit grab ends
1830 // (i.e. releasing the mouse button does not cause the popup to
1831 // be unmapped).
1832 //
1833 // The popup grab continues until the window is destroyed or a
1834 // mouse button is pressed in any other client's window. A click
1835 // in any of the client's surfaces is reported as normal, however,
1836 // clicks in other clients' surfaces will be discarded and trigger
1837 // the callback.
1838 //
1839 // The x and y arguments specify the location of the upper left
1840 // corner of the surface relative to the upper left corner of the
1841 // parent surface, in surface-local coordinates.
1842 //
1843 func (p *ShellSurface) SetPopup(seat *Seat, serial uint32, parent *Surface, x int32, y int32, flags uint32) error {
1844 return p.Context().SendRequest(p, 6, seat, serial, parent, x, y, flags)
1845 }
1846
1847 // SetMaximized will make the surface a maximized surface.
1848 //
1849 //
1850 // Map the surface as a maximized surface.
1851 //
1852 // If an output parameter is given then the surface will be
1853 // maximized on that output. If the client does not specify the
1854 // output then the compositor will apply its policy - usually
1855 // choosing the output on which the surface has the biggest surface
1856 // area.
1857 //
1858 // The compositor will reply with a configure event telling
1859 // the expected new surface size. The operation is completed
1860 // on the next buffer attach to this surface.
1861 //
1862 // A maximized surface typically fills the entire output it is
1863 // bound to, except for desktop elements such as panels. This is
1864 // the main difference between a maximized shell surface and a
1865 // fullscreen shell surface.
1866 //
1867 // The details depend on the compositor implementation.
1868 //
1869 func (p *ShellSurface) SetMaximized(output *Output) error {
1870 return p.Context().SendRequest(p, 7, output)
1871 }
1872
1873 // SetTitle will set surface title.
1874 //
1875 //
1876 // Set a short title for the surface.
1877 //
1878 // This string may be used to identify the surface in a task bar,
1879 // window list, or other user interface elements provided by the
1880 // compositor.
1881 //
1882 // The string must be encoded in UTF-8.
1883 //
1884 func (p *ShellSurface) SetTitle(title string) error {
1885 return p.Context().SendRequest(p, 8, title)
1886 }
1887
1888 // SetClass will set surface class.
1889 //
1890 //
1891 // Set a class for the surface.
1892 //
1893 // The surface class identifies the general class of applications
1894 // to which the surface belongs. A common convention is to use the
1895 // file name (or the full path if it is a non-standard location) of
1896 // the application's .desktop file as the class.
1897 //
1898 func (p *ShellSurface) SetClass(class_ string) error {
1899 return p.Context().SendRequest(p, 9, class_)
1900 }
1901
1902 const (
1903 ShellSurfaceResizeNone = 0
1904 ShellSurfaceResizeTop = 1
1905 ShellSurfaceResizeBottom = 2
1906 ShellSurfaceResizeLeft = 4
1907 ShellSurfaceResizeTopLeft = 5
1908 ShellSurfaceResizeBottomLeft = 6
1909 ShellSurfaceResizeRight = 8
1910 ShellSurfaceResizeTopRight = 9
1911 ShellSurfaceResizeBottomRight = 10
1912 )
1913
1914 const (
1915 ShellSurfaceTransientInactive = 0x1
1916 )
1917
1918 const (
1919 ShellSurfaceFullscreenMethodDefault = 0
1920 ShellSurfaceFullscreenMethodScale = 1
1921 ShellSurfaceFullscreenMethodDriver = 2
1922 ShellSurfaceFullscreenMethodFill = 3
1923 )
1924
1925 type SurfaceEnterEvent struct {
1926 EventContext context.Context
1927 Output *Output
1928 }
1929
1930 type SurfaceEnterHandler interface {
1931 HandleSurfaceEnter(SurfaceEnterEvent)
1932 }
1933
1934 func (p *Surface) AddEnterHandler(h SurfaceEnterHandler) {
1935 if h != nil {
1936 p.mu.Lock()
1937 p.enterHandlers = append(p.enterHandlers, h)
1938 p.mu.Unlock()
1939 }
1940 }
1941
1942 func (p *Surface) RemoveEnterHandler(h SurfaceEnterHandler) {
1943 p.mu.Lock()
1944 defer p.mu.Unlock()
1945
1946 for i, e := range p.enterHandlers {
1947 if e == h {
1948 p.enterHandlers = append(p.enterHandlers[:i], p.enterHandlers[i+1:]...)
1949 break
1950 }
1951 }
1952 }
1953
1954 type SurfaceLeaveEvent struct {
1955 EventContext context.Context
1956 Output *Output
1957 }
1958
1959 type SurfaceLeaveHandler interface {
1960 HandleSurfaceLeave(SurfaceLeaveEvent)
1961 }
1962
1963 func (p *Surface) AddLeaveHandler(h SurfaceLeaveHandler) {
1964 if h != nil {
1965 p.mu.Lock()
1966 p.leaveHandlers = append(p.leaveHandlers, h)
1967 p.mu.Unlock()
1968 }
1969 }
1970
1971 func (p *Surface) RemoveLeaveHandler(h SurfaceLeaveHandler) {
1972 p.mu.Lock()
1973 defer p.mu.Unlock()
1974
1975 for i, e := range p.leaveHandlers {
1976 if e == h {
1977 p.leaveHandlers = append(p.leaveHandlers[:i], p.leaveHandlers[i+1:]...)
1978 break
1979 }
1980 }
1981 }
1982
1983 func (p *Surface) Dispatch(ctx context.Context, event *Event) {
1984 switch event.Opcode {
1985 case 0:
1986 if len(p.enterHandlers) > 0 {
1987 ev := SurfaceEnterEvent{}
1988 ev.EventContext = ctx
1989 ev.Output = event.Proxy(p.Context()).(*Output)
1990 p.mu.RLock()
1991 for _, h := range p.enterHandlers {
1992 h.HandleSurfaceEnter(ev)
1993 }
1994 p.mu.RUnlock()
1995 }
1996 case 1:
1997 if len(p.leaveHandlers) > 0 {
1998 ev := SurfaceLeaveEvent{}
1999 ev.EventContext = ctx
2000 ev.Output = event.Proxy(p.Context()).(*Output)
2001 p.mu.RLock()
2002 for _, h := range p.leaveHandlers {
2003 h.HandleSurfaceLeave(ev)
2004 }
2005 p.mu.RUnlock()
2006 }
2007 }
2008 }
2009
2010 type Surface struct {
2011 BaseProxy
2012 mu sync.RWMutex
2013 enterHandlers []SurfaceEnterHandler
2014 leaveHandlers []SurfaceLeaveHandler
2015 }
2016
2017 func NewSurface(ctx *Context) *Surface {
2018 ret := new(Surface)
2019 ctx.Register(ret)
2020 return ret
2021 }
2022
2023 // Destroy will delete surface.
2024 //
2025 //
2026 // Deletes the surface and invalidates its object ID.
2027 //
2028 func (p *Surface) Destroy() error {
2029 return p.Context().SendRequest(p, 0)
2030 }
2031
2032 // Attach will set the surface contents.
2033 //
2034 //
2035 // Set a buffer as the content of this surface.
2036 //
2037 // The new size of the surface is calculated based on the buffer
2038 // size transformed by the inverse buffer_transform and the
2039 // inverse buffer_scale. This means that the supplied buffer
2040 // must be an integer multiple of the buffer_scale.
2041 //
2042 // The x and y arguments specify the location of the new pending
2043 // buffer's upper left corner, relative to the current buffer's upper
2044 // left corner, in surface-local coordinates. In other words, the
2045 // x and y, combined with the new surface size define in which
2046 // directions the surface's size changes.
2047 //
2048 // Surface contents are double-buffered state, see wl_surface.commit.
2049 //
2050 // The initial surface contents are void; there is no content.
2051 // wl_surface.attach assigns the given wl_buffer as the pending
2052 // wl_buffer. wl_surface.commit makes the pending wl_buffer the new
2053 // surface contents, and the size of the surface becomes the size
2054 // calculated from the wl_buffer, as described above. After commit,
2055 // there is no pending buffer until the next attach.
2056 //
2057 // Committing a pending wl_buffer allows the compositor to read the
2058 // pixels in the wl_buffer. The compositor may access the pixels at
2059 // any time after the wl_surface.commit request. When the compositor
2060 // will not access the pixels anymore, it will send the
2061 // wl_buffer.release event. Only after receiving wl_buffer.release,
2062 // the client may reuse the wl_buffer. A wl_buffer that has been
2063 // attached and then replaced by another attach instead of committed
2064 // will not receive a release event, and is not used by the
2065 // compositor.
2066 //
2067 // Destroying the wl_buffer after wl_buffer.release does not change
2068 // the surface contents. However, if the client destroys the
2069 // wl_buffer before receiving the wl_buffer.release event, the surface
2070 // contents become undefined immediately.
2071 //
2072 // If wl_surface.attach is sent with a NULL wl_buffer, the
2073 // following wl_surface.commit will remove the surface content.
2074 //
2075 func (p *Surface) Attach(buffer *Buffer, x int32, y int32) error {
2076 return p.Context().SendRequest(p, 1, buffer, x, y)
2077 }
2078
2079 // Damage will mark part of the surface damaged.
2080 //
2081 //
2082 // This request is used to describe the regions where the pending
2083 // buffer is different from the current surface contents, and where
2084 // the surface therefore needs to be repainted. The compositor
2085 // ignores the parts of the damage that fall outside of the surface.
2086 //
2087 // Damage is double-buffered state, see wl_surface.commit.
2088 //
2089 // The damage rectangle is specified in surface-local coordinates,
2090 // where x and y specify the upper left corner of the damage rectangle.
2091 //
2092 // The initial value for pending damage is empty: no damage.
2093 // wl_surface.damage adds pending damage: the new pending damage
2094 // is the union of old pending damage and the given rectangle.
2095 //
2096 // wl_surface.commit assigns pending damage as the current damage,
2097 // and clears pending damage. The server will clear the current
2098 // damage as it repaints the surface.
2099 //
2100 // Alternatively, damage can be posted with wl_surface.damage_buffer
2101 // which uses buffer coordinates instead of surface coordinates,
2102 // and is probably the preferred and intuitive way of doing this.
2103 //
2104 func (p *Surface) Damage(x int32, y int32, width int32, height int32) error {
2105 return p.Context().SendRequest(p, 2, x, y, width, height)
2106 }
2107
2108 // Frame will request a frame throttling hint.
2109 //
2110 //
2111 // Request a notification when it is a good time to start drawing a new
2112 // frame, by creating a frame callback. This is useful for throttling
2113 // redrawing operations, and driving animations.
2114 //
2115 // When a client is animating on a wl_surface, it can use the 'frame'
2116 // request to get notified when it is a good time to draw and commit the
2117 // next frame of animation. If the client commits an update earlier than
2118 // that, it is likely that some updates will not make it to the display,
2119 // and the client is wasting resources by drawing too often.
2120 //
2121 // The frame request will take effect on the next wl_surface.commit.
2122 // The notification will only be posted for one frame unless
2123 // requested again. For a wl_surface, the notifications are posted in
2124 // the order the frame requests were committed.
2125 //
2126 // The server must send the notifications so that a client
2127 // will not send excessive updates, while still allowing
2128 // the highest possible update rate for clients that wait for the reply
2129 // before drawing again. The server should give some time for the client
2130 // to draw and commit after sending the frame callback events to let it
2131 // hit the next output refresh.
2132 //
2133 // A server should avoid signaling the frame callbacks if the
2134 // surface is not visible in any way, e.g. the surface is off-screen,
2135 // or completely obscured by other opaque surfaces.
2136 //
2137 // The object returned by this request will be destroyed by the
2138 // compositor after the callback is fired and as such the client must not
2139 // attempt to use it after that point.
2140 //
2141 // The callback_data passed in the callback is the current time, in
2142 // milliseconds, with an undefined base.
2143 //
2144 func (p *Surface) Frame() (*Callback, error) {
2145 ret := NewCallback(p.Context())
2146 return ret, p.Context().SendRequest(p, 3, Proxy(ret))
2147 }
2148
2149 // SetOpaqueRegion will set opaque region.
2150 //
2151 //
2152 // This request sets the region of the surface that contains
2153 // opaque content.
2154 //
2155 // The opaque region is an optimization hint for the compositor
2156 // that lets it optimize the redrawing of content behind opaque
2157 // regions. Setting an opaque region is not required for correct
2158 // behaviour, but marking transparent content as opaque will result
2159 // in repaint artifacts.
2160 //
2161 // The opaque region is specified in surface-local coordinates.
2162 //
2163 // The compositor ignores the parts of the opaque region that fall
2164 // outside of the surface.
2165 //
2166 // Opaque region is double-buffered state, see wl_surface.commit.
2167 //
2168 // wl_surface.set_opaque_region changes the pending opaque region.
2169 // wl_surface.commit copies the pending region to the current region.
2170 // Otherwise, the pending and current regions are never changed.
2171 //
2172 // The initial value for an opaque region is empty. Setting the pending
2173 // opaque region has copy semantics, and the wl_region object can be
2174 // destroyed immediately. A NULL wl_region causes the pending opaque
2175 // region to be set to empty.
2176 //
2177 func (p *Surface) SetOpaqueRegion(region *Region) error {
2178 return p.Context().SendRequest(p, 4, region)
2179 }
2180
2181 // SetInputRegion will set input region.
2182 //
2183 //
2184 // This request sets the region of the surface that can receive
2185 // pointer and touch events.
2186 //
2187 // Input events happening outside of this region will try the next
2188 // surface in the server surface stack. The compositor ignores the
2189 // parts of the input region that fall outside of the surface.
2190 //
2191 // The input region is specified in surface-local coordinates.
2192 //
2193 // Input region is double-buffered state, see wl_surface.commit.
2194 //
2195 // wl_surface.set_input_region changes the pending input region.
2196 // wl_surface.commit copies the pending region to the current region.
2197 // Otherwise the pending and current regions are never changed,
2198 // except cursor and icon surfaces are special cases, see
2199 // wl_pointer.set_cursor and wl_data_device.start_drag.
2200 //
2201 // The initial value for an input region is infinite. That means the
2202 // whole surface will accept input. Setting the pending input region
2203 // has copy semantics, and the wl_region object can be destroyed
2204 // immediately. A NULL wl_region causes the input region to be set
2205 // to infinite.
2206 //
2207 func (p *Surface) SetInputRegion(region *Region) error {
2208 return p.Context().SendRequest(p, 5, region)
2209 }
2210
2211 // Commit will commit pending surface state.
2212 //
2213 //
2214 // Surface state (input, opaque, and damage regions, attached buffers,
2215 // etc.) is double-buffered. Protocol requests modify the pending state,
2216 // as opposed to the current state in use by the compositor. A commit
2217 // request atomically applies all pending state, replacing the current
2218 // state. After commit, the new pending state is as documented for each
2219 // related request.
2220 //
2221 // On commit, a pending wl_buffer is applied first, and all other state
2222 // second. This means that all coordinates in double-buffered state are
2223 // relative to the new wl_buffer coming into use, except for
2224 // wl_surface.attach itself. If there is no pending wl_buffer, the
2225 // coordinates are relative to the current surface contents.
2226 //
2227 // All requests that need a commit to become effective are documented
2228 // to affect double-buffered state.
2229 //
2230 // Other interfaces may add further double-buffered surface state.
2231 //
2232 func (p *Surface) Commit() error {
2233 return p.Context().SendRequest(p, 6)
2234 }
2235
2236 // SetBufferTransform will sets the buffer transformation.
2237 //
2238 //
2239 // This request sets an optional transformation on how the compositor
2240 // interprets the contents of the buffer attached to the surface. The
2241 // accepted values for the transform parameter are the values for
2242 // wl_output.transform.
2243 //
2244 // Buffer transform is double-buffered state, see wl_surface.commit.
2245 //
2246 // A newly created surface has its buffer transformation set to normal.
2247 //
2248 // wl_surface.set_buffer_transform changes the pending buffer
2249 // transformation. wl_surface.commit copies the pending buffer
2250 // transformation to the current one. Otherwise, the pending and current
2251 // values are never changed.
2252 //
2253 // The purpose of this request is to allow clients to render content
2254 // according to the output transform, thus permitting the compositor to
2255 // use certain optimizations even if the display is rotated. Using
2256 // hardware overlays and scanning out a client buffer for fullscreen
2257 // surfaces are examples of such optimizations. Those optimizations are
2258 // highly dependent on the compositor implementation, so the use of this
2259 // request should be considered on a case-by-case basis.
2260 //
2261 // Note that if the transform value includes 90 or 270 degree rotation,
2262 // the width of the buffer will become the surface height and the height
2263 // of the buffer will become the surface width.
2264 //
2265 // If transform is not one of the values from the
2266 // wl_output.transform enum the invalid_transform protocol error
2267 // is raised.
2268 //
2269 func (p *Surface) SetBufferTransform(transform int32) error {
2270 return p.Context().SendRequest(p, 7, transform)
2271 }
2272
2273 // SetBufferScale will sets the buffer scaling factor.
2274 //
2275 //
2276 // This request sets an optional scaling factor on how the compositor
2277 // interprets the contents of the buffer attached to the window.
2278 //
2279 // Buffer scale is double-buffered state, see wl_surface.commit.
2280 //
2281 // A newly created surface has its buffer scale set to 1.
2282 //
2283 // wl_surface.set_buffer_scale changes the pending buffer scale.
2284 // wl_surface.commit copies the pending buffer scale to the current one.
2285 // Otherwise, the pending and current values are never changed.
2286 //
2287 // The purpose of this request is to allow clients to supply higher
2288 // resolution buffer data for use on high resolution outputs. It is
2289 // intended that you pick the same buffer scale as the scale of the
2290 // output that the surface is displayed on. This means the compositor
2291 // can avoid scaling when rendering the surface on that output.
2292 //
2293 // Note that if the scale is larger than 1, then you have to attach
2294 // a buffer that is larger (by a factor of scale in each dimension)
2295 // than the desired surface size.
2296 //
2297 // If scale is not positive the invalid_scale protocol error is
2298 // raised.
2299 //
2300 func (p *Surface) SetBufferScale(scale int32) error {
2301 return p.Context().SendRequest(p, 8, scale)
2302 }
2303
2304 // DamageBuffer will mark part of the surface damaged using buffer coordinates.
2305 //
2306 //
2307 // This request is used to describe the regions where the pending
2308 // buffer is different from the current surface contents, and where
2309 // the surface therefore needs to be repainted. The compositor
2310 // ignores the parts of the damage that fall outside of the surface.
2311 //
2312 // Damage is double-buffered state, see wl_surface.commit.
2313 //
2314 // The damage rectangle is specified in buffer coordinates,
2315 // where x and y specify the upper left corner of the damage rectangle.
2316 //
2317 // The initial value for pending damage is empty: no damage.
2318 // wl_surface.damage_buffer adds pending damage: the new pending
2319 // damage is the union of old pending damage and the given rectangle.
2320 //
2321 // wl_surface.commit assigns pending damage as the current damage,
2322 // and clears pending damage. The server will clear the current
2323 // damage as it repaints the surface.
2324 //
2325 // This request differs from wl_surface.damage in only one way - it
2326 // takes damage in buffer coordinates instead of surface-local
2327 // coordinates. While this generally is more intuitive than surface
2328 // coordinates, it is especially desirable when using wp_viewport
2329 // or when a drawing library (like EGL) is unaware of buffer scale
2330 // and buffer transform.
2331 //
2332 // Note: Because buffer transformation changes and damage requests may
2333 // be interleaved in the protocol stream, it is impossible to determine
2334 // the actual mapping between surface and buffer damage until
2335 // wl_surface.commit time. Therefore, compositors wishing to take both
2336 // kinds of damage into account will have to accumulate damage from the
2337 // two requests separately and only transform from one to the other
2338 // after receiving the wl_surface.commit.
2339 //
2340 func (p *Surface) DamageBuffer(x int32, y int32, width int32, height int32) error {
2341 return p.Context().SendRequest(p, 9, x, y, width, height)
2342 }
2343
2344 const (
2345 SurfaceErrorInvalidScale = 0
2346 SurfaceErrorInvalidTransform = 1
2347 )
2348
2349 type SeatCapabilitiesEvent struct {
2350 EventContext context.Context
2351 Capabilities uint32
2352 }
2353
2354 type SeatCapabilitiesHandler interface {
2355 HandleSeatCapabilities(SeatCapabilitiesEvent)
2356 }
2357
2358 func (p *Seat) AddCapabilitiesHandler(h SeatCapabilitiesHandler) {
2359 if h != nil {
2360 p.mu.Lock()
2361 p.capabilitiesHandlers = append(p.capabilitiesHandlers, h)
2362 p.mu.Unlock()
2363 }
2364 }
2365
2366 func (p *Seat) RemoveCapabilitiesHandler(h SeatCapabilitiesHandler) {
2367 p.mu.Lock()
2368 defer p.mu.Unlock()
2369
2370 for i, e := range p.capabilitiesHandlers {
2371 if e == h {
2372 p.capabilitiesHandlers = append(p.capabilitiesHandlers[:i], p.capabilitiesHandlers[i+1:]...)
2373 break
2374 }
2375 }
2376 }
2377
2378 type SeatNameEvent struct {
2379 EventContext context.Context
2380 Name string
2381 }
2382
2383 type SeatNameHandler interface {
2384 HandleSeatName(SeatNameEvent)
2385 }
2386
2387 func (p *Seat) AddNameHandler(h SeatNameHandler) {
2388 if h != nil {
2389 p.mu.Lock()
2390 p.nameHandlers = append(p.nameHandlers, h)
2391 p.mu.Unlock()
2392 }
2393 }
2394
2395 func (p *Seat) RemoveNameHandler(h SeatNameHandler) {
2396 p.mu.Lock()
2397 defer p.mu.Unlock()
2398
2399 for i, e := range p.nameHandlers {
2400 if e == h {
2401 p.nameHandlers = append(p.nameHandlers[:i], p.nameHandlers[i+1:]...)
2402 break
2403 }
2404 }
2405 }
2406
2407 func (p *Seat) Dispatch(ctx context.Context, event *Event) {
2408 switch event.Opcode {
2409 case 0:
2410 if len(p.capabilitiesHandlers) > 0 {
2411 ev := SeatCapabilitiesEvent{}
2412 ev.EventContext = ctx
2413 ev.Capabilities = event.Uint32()
2414 p.mu.RLock()
2415 for _, h := range p.capabilitiesHandlers {
2416 h.HandleSeatCapabilities(ev)
2417 }
2418 p.mu.RUnlock()
2419 }
2420 case 1:
2421 if len(p.nameHandlers) > 0 {
2422 ev := SeatNameEvent{}
2423 ev.EventContext = ctx
2424 ev.Name = event.String()
2425 p.mu.RLock()
2426 for _, h := range p.nameHandlers {
2427 h.HandleSeatName(ev)
2428 }
2429 p.mu.RUnlock()
2430 }
2431 }
2432 }
2433
2434 type Seat struct {
2435 BaseProxy
2436 mu sync.RWMutex
2437 capabilitiesHandlers []SeatCapabilitiesHandler
2438 nameHandlers []SeatNameHandler
2439 }
2440
2441 func NewSeat(ctx *Context) *Seat {
2442 ret := new(Seat)
2443 ctx.Register(ret)
2444 return ret
2445 }
2446
2447 // GetPointer will return pointer object.
2448 //
2449 //
2450 // The ID provided will be initialized to the wl_pointer interface
2451 // for this seat.
2452 //
2453 // This request only takes effect if the seat has the pointer
2454 // capability, or has had the pointer capability in the past.
2455 // It is a protocol violation to issue this request on a seat that has
2456 // never had the pointer capability.
2457 //
2458 func (p *Seat) GetPointer() (*Pointer, error) {
2459 ret := NewPointer(p.Context())
2460 return ret, p.Context().SendRequest(p, 0, Proxy(ret))
2461 }
2462
2463 // GetKeyboard will return keyboard object.
2464 //
2465 //
2466 // The ID provided will be initialized to the wl_keyboard interface
2467 // for this seat.
2468 //
2469 // This request only takes effect if the seat has the keyboard
2470 // capability, or has had the keyboard capability in the past.
2471 // It is a protocol violation to issue this request on a seat that has
2472 // never had the keyboard capability.
2473 //
2474 func (p *Seat) GetKeyboard() (*Keyboard, error) {
2475 ret := NewKeyboard(p.Context())
2476 return ret, p.Context().SendRequest(p, 1, Proxy(ret))
2477 }
2478
2479 // GetTouch will return touch object.
2480 //
2481 //
2482 // The ID provided will be initialized to the wl_touch interface
2483 // for this seat.
2484 //
2485 // This request only takes effect if the seat has the touch
2486 // capability, or has had the touch capability in the past.
2487 // It is a protocol violation to issue this request on a seat that has
2488 // never had the touch capability.
2489 //
2490 func (p *Seat) GetTouch() (*Touch, error) {
2491 ret := NewTouch(p.Context())
2492 return ret, p.Context().SendRequest(p, 2, Proxy(ret))
2493 }
2494
2495 // Release will release the seat object.
2496 //
2497 //
2498 // Using this request a client can tell the server that it is not going to
2499 // use the seat object anymore.
2500 //
2501 func (p *Seat) Release() error {
2502 return p.Context().SendRequest(p, 3)
2503 }
2504
2505 const (
2506 SeatCapabilityPointer = 1
2507 SeatCapabilityKeyboard = 2
2508 SeatCapabilityTouch = 4
2509 )
2510
2511 type PointerEnterEvent struct {
2512 EventContext context.Context
2513 Serial uint32
2514 Surface *Surface
2515 SurfaceX float32
2516 SurfaceY float32
2517 }
2518
2519 type PointerEnterHandler interface {
2520 HandlePointerEnter(PointerEnterEvent)
2521 }
2522
2523 func (p *Pointer) AddEnterHandler(h PointerEnterHandler) {
2524 if h != nil {
2525 p.mu.Lock()
2526 p.enterHandlers = append(p.enterHandlers, h)
2527 p.mu.Unlock()
2528 }
2529 }
2530
2531 func (p *Pointer) RemoveEnterHandler(h PointerEnterHandler) {
2532 p.mu.Lock()
2533 defer p.mu.Unlock()
2534
2535 for i, e := range p.enterHandlers {
2536 if e == h {
2537 p.enterHandlers = append(p.enterHandlers[:i], p.enterHandlers[i+1:]...)
2538 break
2539 }
2540 }
2541 }
2542
2543 type PointerLeaveEvent struct {
2544 EventContext context.Context
2545 Serial uint32
2546 Surface *Surface
2547 }
2548
2549 type PointerLeaveHandler interface {
2550 HandlePointerLeave(PointerLeaveEvent)
2551 }
2552
2553 func (p *Pointer) AddLeaveHandler(h PointerLeaveHandler) {
2554 if h != nil {
2555 p.mu.Lock()
2556 p.leaveHandlers = append(p.leaveHandlers, h)
2557 p.mu.Unlock()
2558 }
2559 }
2560
2561 func (p *Pointer) RemoveLeaveHandler(h PointerLeaveHandler) {
2562 p.mu.Lock()
2563 defer p.mu.Unlock()
2564
2565 for i, e := range p.leaveHandlers {
2566 if e == h {
2567 p.leaveHandlers = append(p.leaveHandlers[:i], p.leaveHandlers[i+1:]...)
2568 break
2569 }
2570 }
2571 }
2572
2573 type PointerMotionEvent struct {
2574 EventContext context.Context
2575 Time uint32
2576 SurfaceX float32
2577 SurfaceY float32
2578 }
2579
2580 type PointerMotionHandler interface {
2581 HandlePointerMotion(PointerMotionEvent)
2582 }
2583
2584 func (p *Pointer) AddMotionHandler(h PointerMotionHandler) {
2585 if h != nil {
2586 p.mu.Lock()
2587 p.motionHandlers = append(p.motionHandlers, h)
2588 p.mu.Unlock()
2589 }
2590 }
2591
2592 func (p *Pointer) RemoveMotionHandler(h PointerMotionHandler) {
2593 p.mu.Lock()
2594 defer p.mu.Unlock()
2595
2596 for i, e := range p.motionHandlers {
2597 if e == h {
2598 p.motionHandlers = append(p.motionHandlers[:i], p.motionHandlers[i+1:]...)
2599 break
2600 }
2601 }
2602 }
2603
2604 type PointerButtonEvent struct {
2605 EventContext context.Context
2606 Serial uint32
2607 Time uint32
2608 Button uint32
2609 State uint32
2610 }
2611
2612 type PointerButtonHandler interface {
2613 HandlePointerButton(PointerButtonEvent)
2614 }
2615
2616 func (p *Pointer) AddButtonHandler(h PointerButtonHandler) {
2617 if h != nil {
2618 p.mu.Lock()
2619 p.buttonHandlers = append(p.buttonHandlers, h)
2620 p.mu.Unlock()
2621 }
2622 }
2623
2624 func (p *Pointer) RemoveButtonHandler(h PointerButtonHandler) {
2625 p.mu.Lock()
2626 defer p.mu.Unlock()
2627
2628 for i, e := range p.buttonHandlers {
2629 if e == h {
2630 p.buttonHandlers = append(p.buttonHandlers[:i], p.buttonHandlers[i+1:]...)
2631 break
2632 }
2633 }
2634 }
2635
2636 type PointerAxisEvent struct {
2637 EventContext context.Context
2638 Time uint32
2639 Axis uint32
2640 Value float32
2641 }
2642
2643 type PointerAxisHandler interface {
2644 HandlePointerAxis(PointerAxisEvent)
2645 }
2646
2647 func (p *Pointer) AddAxisHandler(h PointerAxisHandler) {
2648 if h != nil {
2649 p.mu.Lock()
2650 p.axisHandlers = append(p.axisHandlers, h)
2651 p.mu.Unlock()
2652 }
2653 }
2654
2655 func (p *Pointer) RemoveAxisHandler(h PointerAxisHandler) {
2656 p.mu.Lock()
2657 defer p.mu.Unlock()
2658
2659 for i, e := range p.axisHandlers {
2660 if e == h {
2661 p.axisHandlers = append(p.axisHandlers[:i], p.axisHandlers[i+1:]...)
2662 break
2663 }
2664 }
2665 }
2666
2667 type PointerFrameEvent struct {
2668 EventContext context.Context
2669 }
2670
2671 type PointerFrameHandler interface {
2672 HandlePointerFrame(PointerFrameEvent)
2673 }
2674
2675 func (p *Pointer) AddFrameHandler(h PointerFrameHandler) {
2676 if h != nil {
2677 p.mu.Lock()
2678 p.frameHandlers = append(p.frameHandlers, h)
2679 p.mu.Unlock()
2680 }
2681 }
2682
2683 func (p *Pointer) RemoveFrameHandler(h PointerFrameHandler) {
2684 p.mu.Lock()
2685 defer p.mu.Unlock()
2686
2687 for i, e := range p.frameHandlers {
2688 if e == h {
2689 p.frameHandlers = append(p.frameHandlers[:i], p.frameHandlers[i+1:]...)
2690 break
2691 }
2692 }
2693 }
2694
2695 type PointerAxisSourceEvent struct {
2696 EventContext context.Context
2697 AxisSource uint32
2698 }
2699
2700 type PointerAxisSourceHandler interface {
2701 HandlePointerAxisSource(PointerAxisSourceEvent)
2702 }
2703
2704 func (p *Pointer) AddAxisSourceHandler(h PointerAxisSourceHandler) {
2705 if h != nil {
2706 p.mu.Lock()
2707 p.axisSourceHandlers = append(p.axisSourceHandlers, h)
2708 p.mu.Unlock()
2709 }
2710 }
2711
2712 func (p *Pointer) RemoveAxisSourceHandler(h PointerAxisSourceHandler) {
2713 p.mu.Lock()
2714 defer p.mu.Unlock()
2715
2716 for i, e := range p.axisSourceHandlers {
2717 if e == h {
2718 p.axisSourceHandlers = append(p.axisSourceHandlers[:i], p.axisSourceHandlers[i+1:]...)
2719 break
2720 }
2721 }
2722 }
2723
2724 type PointerAxisStopEvent struct {
2725 EventContext context.Context
2726 Time uint32
2727 Axis uint32
2728 }
2729
2730 type PointerAxisStopHandler interface {
2731 HandlePointerAxisStop(PointerAxisStopEvent)
2732 }
2733
2734 func (p *Pointer) AddAxisStopHandler(h PointerAxisStopHandler) {
2735 if h != nil {
2736 p.mu.Lock()
2737 p.axisStopHandlers = append(p.axisStopHandlers, h)
2738 p.mu.Unlock()
2739 }
2740 }
2741
2742 func (p *Pointer) RemoveAxisStopHandler(h PointerAxisStopHandler) {
2743 p.mu.Lock()
2744 defer p.mu.Unlock()
2745
2746 for i, e := range p.axisStopHandlers {
2747 if e == h {
2748 p.axisStopHandlers = append(p.axisStopHandlers[:i], p.axisStopHandlers[i+1:]...)
2749 break
2750 }
2751 }
2752 }
2753
2754 type PointerAxisDiscreteEvent struct {
2755 EventContext context.Context
2756 Axis uint32
2757 Discrete int32
2758 }
2759
2760 type PointerAxisDiscreteHandler interface {
2761 HandlePointerAxisDiscrete(PointerAxisDiscreteEvent)
2762 }
2763
2764 func (p *Pointer) AddAxisDiscreteHandler(h PointerAxisDiscreteHandler) {
2765 if h != nil {
2766 p.mu.Lock()
2767 p.axisDiscreteHandlers = append(p.axisDiscreteHandlers, h)
2768 p.mu.Unlock()
2769 }
2770 }
2771
2772 func (p *Pointer) RemoveAxisDiscreteHandler(h PointerAxisDiscreteHandler) {
2773 p.mu.Lock()
2774 defer p.mu.Unlock()
2775
2776 for i, e := range p.axisDiscreteHandlers {
2777 if e == h {
2778 p.axisDiscreteHandlers = append(p.axisDiscreteHandlers[:i], p.axisDiscreteHandlers[i+1:]...)
2779 break
2780 }
2781 }
2782 }
2783
2784 func (p *Pointer) Dispatch(ctx context.Context, event *Event) {
2785 switch event.Opcode {
2786 case 0:
2787 if len(p.enterHandlers) > 0 {
2788 ev := PointerEnterEvent{}
2789 ev.EventContext = ctx
2790 ev.Serial = event.Uint32()
2791 ev.Surface = event.Proxy(p.Context()).(*Surface)
2792 ev.SurfaceX = event.Float32()
2793 ev.SurfaceY = event.Float32()
2794 p.mu.RLock()
2795 for _, h := range p.enterHandlers {
2796 h.HandlePointerEnter(ev)
2797 }
2798 p.mu.RUnlock()
2799 }
2800 case 1:
2801 if len(p.leaveHandlers) > 0 {
2802 ev := PointerLeaveEvent{}
2803 ev.EventContext = ctx
2804 ev.Serial = event.Uint32()
2805 ev.Surface = event.Proxy(p.Context()).(*Surface)
2806 p.mu.RLock()
2807 for _, h := range p.leaveHandlers {
2808 h.HandlePointerLeave(ev)
2809 }
2810 p.mu.RUnlock()
2811 }
2812 case 2:
2813 if len(p.motionHandlers) > 0 {
2814 ev := PointerMotionEvent{}
2815 ev.EventContext = ctx
2816 ev.Time = event.Uint32()
2817 ev.SurfaceX = event.Float32()
2818 ev.SurfaceY = event.Float32()
2819 p.mu.RLock()
2820 for _, h := range p.motionHandlers {
2821 h.HandlePointerMotion(ev)
2822 }
2823 p.mu.RUnlock()
2824 }
2825 case 3:
2826 if len(p.buttonHandlers) > 0 {
2827 ev := PointerButtonEvent{}
2828 ev.EventContext = ctx
2829 ev.Serial = event.Uint32()
2830 ev.Time = event.Uint32()
2831 ev.Button = event.Uint32()
2832 ev.State = event.Uint32()
2833 p.mu.RLock()
2834 for _, h := range p.buttonHandlers {
2835 h.HandlePointerButton(ev)
2836 }
2837 p.mu.RUnlock()
2838 }
2839 case 4:
2840 if len(p.axisHandlers) > 0 {
2841 ev := PointerAxisEvent{}
2842 ev.EventContext = ctx
2843 ev.Time = event.Uint32()
2844 ev.Axis = event.Uint32()
2845 ev.Value = event.Float32()
2846 p.mu.RLock()
2847 for _, h := range p.axisHandlers {
2848 h.HandlePointerAxis(ev)
2849 }
2850 p.mu.RUnlock()
2851 }
2852 case 5:
2853 if len(p.frameHandlers) > 0 {
2854 ev := PointerFrameEvent{}
2855 ev.EventContext = ctx
2856 p.mu.RLock()
2857 for _, h := range p.frameHandlers {
2858 h.HandlePointerFrame(ev)
2859 }
2860 p.mu.RUnlock()
2861 }
2862 case 6:
2863 if len(p.axisSourceHandlers) > 0 {
2864 ev := PointerAxisSourceEvent{}
2865 ev.EventContext = ctx
2866 ev.AxisSource = event.Uint32()
2867 p.mu.RLock()
2868 for _, h := range p.axisSourceHandlers {
2869 h.HandlePointerAxisSource(ev)
2870 }
2871 p.mu.RUnlock()
2872 }
2873 case 7:
2874 if len(p.axisStopHandlers) > 0 {
2875 ev := PointerAxisStopEvent{}
2876 ev.EventContext = ctx
2877 ev.Time = event.Uint32()
2878 ev.Axis = event.Uint32()
2879 p.mu.RLock()
2880 for _, h := range p.axisStopHandlers {
2881 h.HandlePointerAxisStop(ev)
2882 }
2883 p.mu.RUnlock()
2884 }
2885 case 8:
2886 if len(p.axisDiscreteHandlers) > 0 {
2887 ev := PointerAxisDiscreteEvent{}
2888 ev.EventContext = ctx
2889 ev.Axis = event.Uint32()
2890 ev.Discrete = event.Int32()
2891 p.mu.RLock()
2892 for _, h := range p.axisDiscreteHandlers {
2893 h.HandlePointerAxisDiscrete(ev)
2894 }
2895 p.mu.RUnlock()
2896 }
2897 }
2898 }
2899
2900 type Pointer struct {
2901 BaseProxy
2902 mu sync.RWMutex
2903 enterHandlers []PointerEnterHandler
2904 leaveHandlers []PointerLeaveHandler
2905 motionHandlers []PointerMotionHandler
2906 buttonHandlers []PointerButtonHandler
2907 axisHandlers []PointerAxisHandler
2908 frameHandlers []PointerFrameHandler
2909 axisSourceHandlers []PointerAxisSourceHandler
2910 axisStopHandlers []PointerAxisStopHandler
2911 axisDiscreteHandlers []PointerAxisDiscreteHandler
2912 }
2913
2914 func NewPointer(ctx *Context) *Pointer {
2915 ret := new(Pointer)
2916 ctx.Register(ret)
2917 return ret
2918 }
2919
2920 // SetCursor will set the pointer surface.
2921 //
2922 //
2923 // Set the pointer surface, i.e., the surface that contains the
2924 // pointer image (cursor). This request gives the surface the role
2925 // of a cursor. If the surface already has another role, it raises
2926 // a protocol error.
2927 //
2928 // The cursor actually changes only if the pointer
2929 // focus for this device is one of the requesting client's surfaces
2930 // or the surface parameter is the current pointer surface. If
2931 // there was a previous surface set with this request it is
2932 // replaced. If surface is NULL, the pointer image is hidden.
2933 //
2934 // The parameters hotspot_x and hotspot_y define the position of
2935 // the pointer surface relative to the pointer location. Its
2936 // top-left corner is always at (x, y) - (hotspot_x, hotspot_y),
2937 // where (x, y) are the coordinates of the pointer location, in
2938 // surface-local coordinates.
2939 //
2940 // On surface.attach requests to the pointer surface, hotspot_x
2941 // and hotspot_y are decremented by the x and y parameters
2942 // passed to the request. Attach must be confirmed by
2943 // wl_surface.commit as usual.
2944 //
2945 // The hotspot can also be updated by passing the currently set
2946 // pointer surface to this request with new values for hotspot_x
2947 // and hotspot_y.
2948 //
2949 // The current and pending input regions of the wl_surface are
2950 // cleared, and wl_surface.set_input_region is ignored until the
2951 // wl_surface is no longer used as the cursor. When the use as a
2952 // cursor ends, the current and pending input regions become
2953 // undefined, and the wl_surface is unmapped.
2954 //
2955 func (p *Pointer) SetCursor(serial uint32, surface *Surface, hotspot_x int32, hotspot_y int32) error {
2956 return p.Context().SendRequest(p, 0, serial, surface, hotspot_x, hotspot_y)
2957 }
2958
2959 // Release will release the pointer object.
2960 //
2961 //
2962 // Using this request a client can tell the server that it is not going to
2963 // use the pointer object anymore.
2964 //
2965 // This request destroys the pointer proxy object, so clients must not call
2966 // wl_pointer_destroy() after using this request.
2967 //
2968 func (p *Pointer) Release() error {
2969 return p.Context().SendRequest(p, 1)
2970 }
2971
2972 const (
2973 PointerErrorRole = 0
2974 )
2975
2976 const (
2977 PointerButtonStateReleased = 0
2978 PointerButtonStatePressed = 1
2979 )
2980
2981 const (
2982 PointerAxisVerticalScroll = 0
2983 PointerAxisHorizontalScroll = 1
2984 )
2985
2986 const (
2987 PointerAxisSourceWheel = 0
2988 PointerAxisSourceFinger = 1
2989 PointerAxisSourceContinuous = 2
2990 PointerAxisSourceWheelTilt = 3
2991 )
2992
2993 type KeyboardKeymapEvent struct {
2994 EventContext context.Context
2995 Format uint32
2996 Fd uintptr
2997 Size uint32
2998 }
2999
3000 type KeyboardKeymapHandler interface {
3001 HandleKeyboardKeymap(KeyboardKeymapEvent)
3002 }
3003
3004 func (p *Keyboard) AddKeymapHandler(h KeyboardKeymapHandler) {
3005 if h != nil {
3006 p.mu.Lock()
3007 p.keymapHandlers = append(p.keymapHandlers, h)
3008 p.mu.Unlock()
3009 }
3010 }
3011
3012 func (p *Keyboard) RemoveKeymapHandler(h KeyboardKeymapHandler) {
3013 p.mu.Lock()
3014 defer p.mu.Unlock()
3015
3016 for i, e := range p.keymapHandlers {
3017 if e == h {
3018 p.keymapHandlers = append(p.keymapHandlers[:i], p.keymapHandlers[i+1:]...)
3019 break
3020 }
3021 }
3022 }
3023
3024 type KeyboardEnterEvent struct {
3025 EventContext context.Context
3026 Serial uint32
3027 Surface *Surface
3028 Keys []int32
3029 }
3030
3031 type KeyboardEnterHandler interface {
3032 HandleKeyboardEnter(KeyboardEnterEvent)
3033 }
3034
3035 func (p *Keyboard) AddEnterHandler(h KeyboardEnterHandler) {
3036 if h != nil {
3037 p.mu.Lock()
3038 p.enterHandlers = append(p.enterHandlers, h)
3039 p.mu.Unlock()
3040 }
3041 }
3042
3043 func (p *Keyboard) RemoveEnterHandler(h KeyboardEnterHandler) {
3044 p.mu.Lock()
3045 defer p.mu.Unlock()
3046
3047 for i, e := range p.enterHandlers {
3048 if e == h {
3049 p.enterHandlers = append(p.enterHandlers[:i], p.enterHandlers[i+1:]...)
3050 break
3051 }
3052 }
3053 }
3054
3055 type KeyboardLeaveEvent struct {
3056 EventContext context.Context
3057 Serial uint32
3058 Surface *Surface
3059 }
3060
3061 type KeyboardLeaveHandler interface {
3062 HandleKeyboardLeave(KeyboardLeaveEvent)
3063 }
3064
3065 func (p *Keyboard) AddLeaveHandler(h KeyboardLeaveHandler) {
3066 if h != nil {
3067 p.mu.Lock()
3068 p.leaveHandlers = append(p.leaveHandlers, h)
3069 p.mu.Unlock()
3070 }
3071 }
3072
3073 func (p *Keyboard) RemoveLeaveHandler(h KeyboardLeaveHandler) {
3074 p.mu.Lock()
3075 defer p.mu.Unlock()
3076
3077 for i, e := range p.leaveHandlers {
3078 if e == h {
3079 p.leaveHandlers = append(p.leaveHandlers[:i], p.leaveHandlers[i+1:]...)
3080 break
3081 }
3082 }
3083 }
3084
3085 type KeyboardKeyEvent struct {
3086 EventContext context.Context
3087 Serial uint32
3088 Time uint32
3089 Key uint32
3090 State uint32
3091 }
3092
3093 type KeyboardKeyHandler interface {
3094 HandleKeyboardKey(KeyboardKeyEvent)
3095 }
3096
3097 func (p *Keyboard) AddKeyHandler(h KeyboardKeyHandler) {
3098 if h != nil {
3099 p.mu.Lock()
3100 p.keyHandlers = append(p.keyHandlers, h)
3101 p.mu.Unlock()
3102 }
3103 }
3104
3105 func (p *Keyboard) RemoveKeyHandler(h KeyboardKeyHandler) {
3106 p.mu.Lock()
3107 defer p.mu.Unlock()
3108
3109 for i, e := range p.keyHandlers {
3110 if e == h {
3111 p.keyHandlers = append(p.keyHandlers[:i], p.keyHandlers[i+1:]...)
3112 break
3113 }
3114 }
3115 }
3116
3117 type KeyboardModifiersEvent struct {
3118 EventContext context.Context
3119 Serial uint32
3120 ModsDepressed uint32
3121 ModsLatched uint32
3122 ModsLocked uint32
3123 Group uint32
3124 }
3125
3126 type KeyboardModifiersHandler interface {
3127 HandleKeyboardModifiers(KeyboardModifiersEvent)
3128 }
3129
3130 func (p *Keyboard) AddModifiersHandler(h KeyboardModifiersHandler) {
3131 if h != nil {
3132 p.mu.Lock()
3133 p.modifiersHandlers = append(p.modifiersHandlers, h)
3134 p.mu.Unlock()
3135 }
3136 }
3137
3138 func (p *Keyboard) RemoveModifiersHandler(h KeyboardModifiersHandler) {
3139 p.mu.Lock()
3140 defer p.mu.Unlock()
3141
3142 for i, e := range p.modifiersHandlers {
3143 if e == h {
3144 p.modifiersHandlers = append(p.modifiersHandlers[:i], p.modifiersHandlers[i+1:]...)
3145 break
3146 }
3147 }
3148 }
3149
3150 type KeyboardRepeatInfoEvent struct {
3151 EventContext context.Context
3152 Rate int32
3153 Delay int32
3154 }
3155
3156 type KeyboardRepeatInfoHandler interface {
3157 HandleKeyboardRepeatInfo(KeyboardRepeatInfoEvent)
3158 }
3159
3160 func (p *Keyboard) AddRepeatInfoHandler(h KeyboardRepeatInfoHandler) {
3161 if h != nil {
3162 p.mu.Lock()
3163 p.repeatInfoHandlers = append(p.repeatInfoHandlers, h)
3164 p.mu.Unlock()
3165 }
3166 }
3167
3168 func (p *Keyboard) RemoveRepeatInfoHandler(h KeyboardRepeatInfoHandler) {
3169 p.mu.Lock()
3170 defer p.mu.Unlock()
3171
3172 for i, e := range p.repeatInfoHandlers {
3173 if e == h {
3174 p.repeatInfoHandlers = append(p.repeatInfoHandlers[:i], p.repeatInfoHandlers[i+1:]...)
3175 break
3176 }
3177 }
3178 }
3179
3180 func (p *Keyboard) Dispatch(ctx context.Context, event *Event) {
3181 switch event.Opcode {
3182 case 0:
3183 if len(p.keymapHandlers) > 0 {
3184 ev := KeyboardKeymapEvent{}
3185 ev.EventContext = ctx
3186 ev.Format = event.Uint32()
3187 ev.Fd = event.FD()
3188 ev.Size = event.Uint32()
3189 p.mu.RLock()
3190 for _, h := range p.keymapHandlers {
3191 h.HandleKeyboardKeymap(ev)
3192 }
3193 p.mu.RUnlock()
3194 }
3195 case 1:
3196 if len(p.enterHandlers) > 0 {
3197 ev := KeyboardEnterEvent{}
3198 ev.EventContext = ctx
3199 ev.Serial = event.Uint32()
3200 ev.Surface = event.Proxy(p.Context()).(*Surface)
3201 ev.Keys = event.Array()
3202 p.mu.RLock()
3203 for _, h := range p.enterHandlers {
3204 h.HandleKeyboardEnter(ev)
3205 }
3206 p.mu.RUnlock()
3207 }
3208 case 2:
3209 if len(p.leaveHandlers) > 0 {
3210 ev := KeyboardLeaveEvent{}
3211 ev.EventContext = ctx
3212 ev.Serial = event.Uint32()
3213 ev.Surface = event.Proxy(p.Context()).(*Surface)
3214 p.mu.RLock()
3215 for _, h := range p.leaveHandlers {
3216 h.HandleKeyboardLeave(ev)
3217 }
3218 p.mu.RUnlock()
3219 }
3220 case 3:
3221 if len(p.keyHandlers) > 0 {
3222 ev := KeyboardKeyEvent{}
3223 ev.EventContext = ctx
3224 ev.Serial = event.Uint32()
3225 ev.Time = event.Uint32()
3226 ev.Key = event.Uint32()
3227 ev.State = event.Uint32()
3228 p.mu.RLock()
3229 for _, h := range p.keyHandlers {
3230 h.HandleKeyboardKey(ev)
3231 }
3232 p.mu.RUnlock()
3233 }
3234 case 4:
3235 if len(p.modifiersHandlers) > 0 {
3236 ev := KeyboardModifiersEvent{}
3237 ev.EventContext = ctx
3238 ev.Serial = event.Uint32()
3239 ev.ModsDepressed = event.Uint32()
3240 ev.ModsLatched = event.Uint32()
3241 ev.ModsLocked = event.Uint32()
3242 ev.Group = event.Uint32()
3243 p.mu.RLock()
3244 for _, h := range p.modifiersHandlers {
3245 h.HandleKeyboardModifiers(ev)
3246 }
3247 p.mu.RUnlock()
3248 }
3249 case 5:
3250 if len(p.repeatInfoHandlers) > 0 {
3251 ev := KeyboardRepeatInfoEvent{}
3252 ev.EventContext = ctx
3253 ev.Rate = event.Int32()
3254 ev.Delay = event.Int32()
3255 p.mu.RLock()
3256 for _, h := range p.repeatInfoHandlers {
3257 h.HandleKeyboardRepeatInfo(ev)
3258 }
3259 p.mu.RUnlock()
3260 }
3261 }
3262 }
3263
3264 type Keyboard struct {
3265 BaseProxy
3266 mu sync.RWMutex
3267 keymapHandlers []KeyboardKeymapHandler
3268 enterHandlers []KeyboardEnterHandler
3269 leaveHandlers []KeyboardLeaveHandler
3270 keyHandlers []KeyboardKeyHandler
3271 modifiersHandlers []KeyboardModifiersHandler
3272 repeatInfoHandlers []KeyboardRepeatInfoHandler
3273 }
3274
3275 func NewKeyboard(ctx *Context) *Keyboard {
3276 ret := new(Keyboard)
3277 ctx.Register(ret)
3278 return ret
3279 }
3280
3281 // Release will release the keyboard object.
3282 //
3283 //
3284 func (p *Keyboard) Release() error {
3285 return p.Context().SendRequest(p, 0)
3286 }
3287
3288 const (
3289 KeyboardKeymapFormatNoKeymap = 0
3290 KeyboardKeymapFormatXkbV1 = 1
3291 )
3292
3293 const (
3294 KeyboardKeyStateReleased = 0
3295 KeyboardKeyStatePressed = 1
3296 )
3297
3298 type TouchDownEvent struct {
3299 EventContext context.Context
3300 Serial uint32
3301 Time uint32
3302 Surface *Surface
3303 Id int32
3304 X float32
3305 Y float32
3306 }
3307
3308 type TouchDownHandler interface {
3309 HandleTouchDown(TouchDownEvent)
3310 }
3311
3312 func (p *Touch) AddDownHandler(h TouchDownHandler) {
3313 if h != nil {
3314 p.mu.Lock()
3315 p.downHandlers = append(p.downHandlers, h)
3316 p.mu.Unlock()
3317 }
3318 }
3319
3320 func (p *Touch) RemoveDownHandler(h TouchDownHandler) {
3321 p.mu.Lock()
3322 defer p.mu.Unlock()
3323
3324 for i, e := range p.downHandlers {
3325 if e == h {
3326 p.downHandlers = append(p.downHandlers[:i], p.downHandlers[i+1:]...)
3327 break
3328 }
3329 }
3330 }
3331
3332 type TouchUpEvent struct {
3333 EventContext context.Context
3334 Serial uint32
3335 Time uint32
3336 Id int32
3337 }
3338
3339 type TouchUpHandler interface {
3340 HandleTouchUp(TouchUpEvent)
3341 }
3342
3343 func (p *Touch) AddUpHandler(h TouchUpHandler) {
3344 if h != nil {
3345 p.mu.Lock()
3346 p.upHandlers = append(p.upHandlers, h)
3347 p.mu.Unlock()
3348 }
3349 }
3350
3351 func (p *Touch) RemoveUpHandler(h TouchUpHandler) {
3352 p.mu.Lock()
3353 defer p.mu.Unlock()
3354
3355 for i, e := range p.upHandlers {
3356 if e == h {
3357 p.upHandlers = append(p.upHandlers[:i], p.upHandlers[i+1:]...)
3358 break
3359 }
3360 }
3361 }
3362
3363 type TouchMotionEvent struct {
3364 EventContext context.Context
3365 Time uint32
3366 Id int32
3367 X float32
3368 Y float32
3369 }
3370
3371 type TouchMotionHandler interface {
3372 HandleTouchMotion(TouchMotionEvent)
3373 }
3374
3375 func (p *Touch) AddMotionHandler(h TouchMotionHandler) {
3376 if h != nil {
3377 p.mu.Lock()
3378 p.motionHandlers = append(p.motionHandlers, h)
3379 p.mu.Unlock()
3380 }
3381 }
3382
3383 func (p *Touch) RemoveMotionHandler(h TouchMotionHandler) {
3384 p.mu.Lock()
3385 defer p.mu.Unlock()
3386
3387 for i, e := range p.motionHandlers {
3388 if e == h {
3389 p.motionHandlers = append(p.motionHandlers[:i], p.motionHandlers[i+1:]...)
3390 break
3391 }
3392 }
3393 }
3394
3395 type TouchFrameEvent struct {
3396 EventContext context.Context
3397 }
3398
3399 type TouchFrameHandler interface {
3400 HandleTouchFrame(TouchFrameEvent)
3401 }
3402
3403 func (p *Touch) AddFrameHandler(h TouchFrameHandler) {
3404 if h != nil {
3405 p.mu.Lock()
3406 p.frameHandlers = append(p.frameHandlers, h)
3407 p.mu.Unlock()
3408 }
3409 }
3410
3411 func (p *Touch) RemoveFrameHandler(h TouchFrameHandler) {
3412 p.mu.Lock()
3413 defer p.mu.Unlock()
3414
3415 for i, e := range p.frameHandlers {
3416 if e == h {
3417 p.frameHandlers = append(p.frameHandlers[:i], p.frameHandlers[i+1:]...)
3418 break
3419 }
3420 }
3421 }
3422
3423 type TouchCancelEvent struct {
3424 EventContext context.Context
3425 }
3426
3427 type TouchCancelHandler interface {
3428 HandleTouchCancel(TouchCancelEvent)
3429 }
3430
3431 func (p *Touch) AddCancelHandler(h TouchCancelHandler) {
3432 if h != nil {
3433 p.mu.Lock()
3434 p.cancelHandlers = append(p.cancelHandlers, h)
3435 p.mu.Unlock()
3436 }
3437 }
3438
3439 func (p *Touch) RemoveCancelHandler(h TouchCancelHandler) {
3440 p.mu.Lock()
3441 defer p.mu.Unlock()
3442
3443 for i, e := range p.cancelHandlers {
3444 if e == h {
3445 p.cancelHandlers = append(p.cancelHandlers[:i], p.cancelHandlers[i+1:]...)
3446 break
3447 }
3448 }
3449 }
3450
3451 type TouchShapeEvent struct {
3452 EventContext context.Context
3453 Id int32
3454 Major float32
3455 Minor float32
3456 }
3457
3458 type TouchShapeHandler interface {
3459 HandleTouchShape(TouchShapeEvent)
3460 }
3461
3462 func (p *Touch) AddShapeHandler(h TouchShapeHandler) {
3463 if h != nil {
3464 p.mu.Lock()
3465 p.shapeHandlers = append(p.shapeHandlers, h)
3466 p.mu.Unlock()
3467 }
3468 }
3469
3470 func (p *Touch) RemoveShapeHandler(h TouchShapeHandler) {
3471 p.mu.Lock()
3472 defer p.mu.Unlock()
3473
3474 for i, e := range p.shapeHandlers {
3475 if e == h {
3476 p.shapeHandlers = append(p.shapeHandlers[:i], p.shapeHandlers[i+1:]...)
3477 break
3478 }
3479 }
3480 }
3481
3482 type TouchOrientationEvent struct {
3483 EventContext context.Context
3484 Id int32
3485 Orientation float32
3486 }
3487
3488 type TouchOrientationHandler interface {
3489 HandleTouchOrientation(TouchOrientationEvent)
3490 }
3491
3492 func (p *Touch) AddOrientationHandler(h TouchOrientationHandler) {
3493 if h != nil {
3494 p.mu.Lock()
3495 p.orientationHandlers = append(p.orientationHandlers, h)
3496 p.mu.Unlock()
3497 }
3498 }
3499
3500 func (p *Touch) RemoveOrientationHandler(h TouchOrientationHandler) {
3501 p.mu.Lock()
3502 defer p.mu.Unlock()
3503
3504 for i, e := range p.orientationHandlers {
3505 if e == h {
3506 p.orientationHandlers = append(p.orientationHandlers[:i], p.orientationHandlers[i+1:]...)
3507 break
3508 }
3509 }
3510 }
3511
3512 func (p *Touch) Dispatch(ctx context.Context, event *Event) {
3513 switch event.Opcode {
3514 case 0:
3515 if len(p.downHandlers) > 0 {
3516 ev := TouchDownEvent{}
3517 ev.EventContext = ctx
3518 ev.Serial = event.Uint32()
3519 ev.Time = event.Uint32()
3520 ev.Surface = event.Proxy(p.Context()).(*Surface)
3521 ev.Id = event.Int32()
3522 ev.X = event.Float32()
3523 ev.Y = event.Float32()
3524 p.mu.RLock()
3525 for _, h := range p.downHandlers {
3526 h.HandleTouchDown(ev)
3527 }
3528 p.mu.RUnlock()
3529 }
3530 case 1:
3531 if len(p.upHandlers) > 0 {
3532 ev := TouchUpEvent{}
3533 ev.EventContext = ctx
3534 ev.Serial = event.Uint32()
3535 ev.Time = event.Uint32()
3536 ev.Id = event.Int32()
3537 p.mu.RLock()
3538 for _, h := range p.upHandlers {
3539 h.HandleTouchUp(ev)
3540 }
3541 p.mu.RUnlock()
3542 }
3543 case 2:
3544 if len(p.motionHandlers) > 0 {
3545 ev := TouchMotionEvent{}
3546 ev.EventContext = ctx
3547 ev.Time = event.Uint32()
3548 ev.Id = event.Int32()
3549 ev.X = event.Float32()
3550 ev.Y = event.Float32()
3551 p.mu.RLock()
3552 for _, h := range p.motionHandlers {
3553 h.HandleTouchMotion(ev)
3554 }
3555 p.mu.RUnlock()
3556 }
3557 case 3:
3558 if len(p.frameHandlers) > 0 {
3559 ev := TouchFrameEvent{}
3560 ev.EventContext = ctx
3561 p.mu.RLock()
3562 for _, h := range p.frameHandlers {
3563 h.HandleTouchFrame(ev)
3564 }
3565 p.mu.RUnlock()
3566 }
3567 case 4:
3568 if len(p.cancelHandlers) > 0 {
3569 ev := TouchCancelEvent{}
3570 ev.EventContext = ctx
3571 p.mu.RLock()
3572 for _, h := range p.cancelHandlers {
3573 h.HandleTouchCancel(ev)
3574 }
3575 p.mu.RUnlock()
3576 }
3577 case 5:
3578 if len(p.shapeHandlers) > 0 {
3579 ev := TouchShapeEvent{}
3580 ev.EventContext = ctx
3581 ev.Id = event.Int32()
3582 ev.Major = event.Float32()
3583 ev.Minor = event.Float32()
3584 p.mu.RLock()
3585 for _, h := range p.shapeHandlers {
3586 h.HandleTouchShape(ev)
3587 }
3588 p.mu.RUnlock()
3589 }
3590 case 6:
3591 if len(p.orientationHandlers) > 0 {
3592 ev := TouchOrientationEvent{}
3593 ev.EventContext = ctx
3594 ev.Id = event.Int32()
3595 ev.Orientation = event.Float32()
3596 p.mu.RLock()
3597 for _, h := range p.orientationHandlers {
3598 h.HandleTouchOrientation(ev)
3599 }
3600 p.mu.RUnlock()
3601 }
3602 }
3603 }
3604
3605 type Touch struct {
3606 BaseProxy
3607 mu sync.RWMutex
3608 downHandlers []TouchDownHandler
3609 upHandlers []TouchUpHandler
3610 motionHandlers []TouchMotionHandler
3611 frameHandlers []TouchFrameHandler
3612 cancelHandlers []TouchCancelHandler
3613 shapeHandlers []TouchShapeHandler
3614 orientationHandlers []TouchOrientationHandler
3615 }
3616
3617 func NewTouch(ctx *Context) *Touch {
3618 ret := new(Touch)
3619 ctx.Register(ret)
3620 return ret
3621 }
3622
3623 // Release will release the touch object.
3624 //
3625 //
3626 func (p *Touch) Release() error {
3627 return p.Context().SendRequest(p, 0)
3628 }
3629
3630 type OutputGeometryEvent struct {
3631 EventContext context.Context
3632 X int32
3633 Y int32
3634 PhysicalWidth int32
3635 PhysicalHeight int32
3636 Subpixel int32
3637 Make string
3638 Model string
3639 Transform int32
3640 }
3641
3642 type OutputGeometryHandler interface {
3643 HandleOutputGeometry(OutputGeometryEvent)
3644 }
3645
3646 func (p *Output) AddGeometryHandler(h OutputGeometryHandler) {
3647 if h != nil {
3648 p.mu.Lock()
3649 p.geometryHandlers = append(p.geometryHandlers, h)
3650 p.mu.Unlock()
3651 }
3652 }
3653
3654 func (p *Output) RemoveGeometryHandler(h OutputGeometryHandler) {
3655 p.mu.Lock()
3656 defer p.mu.Unlock()
3657
3658 for i, e := range p.geometryHandlers {
3659 if e == h {
3660 p.geometryHandlers = append(p.geometryHandlers[:i], p.geometryHandlers[i+1:]...)
3661 break
3662 }
3663 }
3664 }
3665
3666 type OutputModeEvent struct {
3667 EventContext context.Context
3668 Flags uint32
3669 Width int32
3670 Height int32
3671 Refresh int32
3672 }
3673
3674 type OutputModeHandler interface {
3675 HandleOutputMode(OutputModeEvent)
3676 }
3677
3678 func (p *Output) AddModeHandler(h OutputModeHandler) {
3679 if h != nil {
3680 p.mu.Lock()
3681 p.modeHandlers = append(p.modeHandlers, h)
3682 p.mu.Unlock()
3683 }
3684 }
3685
3686 func (p *Output) RemoveModeHandler(h OutputModeHandler) {
3687 p.mu.Lock()
3688 defer p.mu.Unlock()
3689
3690 for i, e := range p.modeHandlers {
3691 if e == h {
3692 p.modeHandlers = append(p.modeHandlers[:i], p.modeHandlers[i+1:]...)
3693 break
3694 }
3695 }
3696 }
3697
3698 type OutputDoneEvent struct {
3699 EventContext context.Context
3700 }
3701
3702 type OutputDoneHandler interface {
3703 HandleOutputDone(OutputDoneEvent)
3704 }
3705
3706 func (p *Output) AddDoneHandler(h OutputDoneHandler) {
3707 if h != nil {
3708 p.mu.Lock()
3709 p.doneHandlers = append(p.doneHandlers, h)
3710 p.mu.Unlock()
3711 }
3712 }
3713
3714 func (p *Output) RemoveDoneHandler(h OutputDoneHandler) {
3715 p.mu.Lock()
3716 defer p.mu.Unlock()
3717
3718 for i, e := range p.doneHandlers {
3719 if e == h {
3720 p.doneHandlers = append(p.doneHandlers[:i], p.doneHandlers[i+1:]...)
3721 break
3722 }
3723 }
3724 }
3725
3726 type OutputScaleEvent struct {
3727 EventContext context.Context
3728 Factor int32
3729 }
3730
3731 type OutputScaleHandler interface {
3732 HandleOutputScale(OutputScaleEvent)
3733 }
3734
3735 func (p *Output) AddScaleHandler(h OutputScaleHandler) {
3736 if h != nil {
3737 p.mu.Lock()
3738 p.scaleHandlers = append(p.scaleHandlers, h)
3739 p.mu.Unlock()
3740 }
3741 }
3742
3743 func (p *Output) RemoveScaleHandler(h OutputScaleHandler) {
3744 p.mu.Lock()
3745 defer p.mu.Unlock()
3746
3747 for i, e := range p.scaleHandlers {
3748 if e == h {
3749 p.scaleHandlers = append(p.scaleHandlers[:i], p.scaleHandlers[i+1:]...)
3750 break
3751 }
3752 }
3753 }
3754
3755 func (p *Output) Dispatch(ctx context.Context, event *Event) {
3756 switch event.Opcode {
3757 case 0:
3758 if len(p.geometryHandlers) > 0 {
3759 ev := OutputGeometryEvent{}
3760 ev.EventContext = ctx
3761 ev.X = event.Int32()
3762 ev.Y = event.Int32()
3763 ev.PhysicalWidth = event.Int32()
3764 ev.PhysicalHeight = event.Int32()
3765 ev.Subpixel = event.Int32()
3766 ev.Make = event.String()
3767 ev.Model = event.String()
3768 ev.Transform = event.Int32()
3769 p.mu.RLock()
3770 for _, h := range p.geometryHandlers {
3771 h.HandleOutputGeometry(ev)
3772 }
3773 p.mu.RUnlock()
3774 }
3775 case 1:
3776 if len(p.modeHandlers) > 0 {
3777 ev := OutputModeEvent{}
3778 ev.EventContext = ctx
3779 ev.Flags = event.Uint32()
3780 ev.Width = event.Int32()
3781 ev.Height = event.Int32()
3782 ev.Refresh = event.Int32()
3783 p.mu.RLock()
3784 for _, h := range p.modeHandlers {
3785 h.HandleOutputMode(ev)
3786 }
3787 p.mu.RUnlock()
3788 }
3789 case 2:
3790 if len(p.doneHandlers) > 0 {
3791 ev := OutputDoneEvent{}
3792 ev.EventContext = ctx
3793 p.mu.RLock()
3794 for _, h := range p.doneHandlers {
3795 h.HandleOutputDone(ev)
3796 }
3797 p.mu.RUnlock()
3798 }
3799 case 3:
3800 if len(p.scaleHandlers) > 0 {
3801 ev := OutputScaleEvent{}
3802 ev.EventContext = ctx
3803 ev.Factor = event.Int32()
3804 p.mu.RLock()
3805 for _, h := range p.scaleHandlers {
3806 h.HandleOutputScale(ev)
3807 }
3808 p.mu.RUnlock()
3809 }
3810 }
3811 }
3812
3813 type Output struct {
3814 BaseProxy
3815 mu sync.RWMutex
3816 geometryHandlers []OutputGeometryHandler
3817 modeHandlers []OutputModeHandler
3818 doneHandlers []OutputDoneHandler
3819 scaleHandlers []OutputScaleHandler
3820 }
3821
3822 func NewOutput(ctx *Context) *Output {
3823 ret := new(Output)
3824 ctx.Register(ret)
3825 return ret
3826 }
3827
3828 // Release will release the output object.
3829 //
3830 //
3831 // Using this request a client can tell the server that it is not going to
3832 // use the output object anymore.
3833 //
3834 func (p *Output) Release() error {
3835 return p.Context().SendRequest(p, 0)
3836 }
3837
3838 const (
3839 OutputSubpixelUnknown = 0
3840 OutputSubpixelNone = 1
3841 OutputSubpixelHorizontalRgb = 2
3842 OutputSubpixelHorizontalBgr = 3
3843 OutputSubpixelVerticalRgb = 4
3844 OutputSubpixelVerticalBgr = 5
3845 )
3846
3847 const (
3848 OutputTransformNormal = 0
3849 OutputTransform90 = 1
3850 OutputTransform180 = 2
3851 OutputTransform270 = 3
3852 OutputTransformFlipped = 4
3853 OutputTransformFlipped90 = 5
3854 OutputTransformFlipped180 = 6
3855 OutputTransformFlipped270 = 7
3856 )
3857
3858 const (
3859 OutputModeCurrent = 0x1
3860 OutputModePreferred = 0x2
3861 )
3862
3863 type Region struct {
3864 BaseProxy
3865 }
3866
3867 func NewRegion(ctx *Context) *Region {
3868 ret := new(Region)
3869 ctx.Register(ret)
3870 return ret
3871 }
3872
3873 // Destroy will destroy region.
3874 //
3875 //
3876 // Destroy the region. This will invalidate the object ID.
3877 //
3878 func (p *Region) Destroy() error {
3879 return p.Context().SendRequest(p, 0)
3880 }
3881
3882 // Add will add rectangle to region.
3883 //
3884 //
3885 // Add the specified rectangle to the region.
3886 //
3887 func (p *Region) Add(x int32, y int32, width int32, height int32) error {
3888 return p.Context().SendRequest(p, 1, x, y, width, height)
3889 }
3890
3891 // Subtract will subtract rectangle from region.
3892 //
3893 //
3894 // Subtract the specified rectangle from the region.
3895 //
3896 func (p *Region) Subtract(x int32, y int32, width int32, height int32) error {
3897 return p.Context().SendRequest(p, 2, x, y, width, height)
3898 }
3899
3900 type Subcompositor struct {
3901 BaseProxy
3902 }
3903
3904 func NewSubcompositor(ctx *Context) *Subcompositor {
3905 ret := new(Subcompositor)
3906 ctx.Register(ret)
3907 return ret
3908 }
3909
3910 // Destroy will unbind from the subcompositor interface.
3911 //
3912 //
3913 // Informs the server that the client will not be using this
3914 // protocol object anymore. This does not affect any other
3915 // objects, wl_subsurface objects included.
3916 //
3917 func (p *Subcompositor) Destroy() error {
3918 return p.Context().SendRequest(p, 0)
3919 }
3920
3921 // GetSubsurface will give a surface the role sub-surface.
3922 //
3923 //
3924 // Create a sub-surface interface for the given surface, and
3925 // associate it with the given parent surface. This turns a
3926 // plain wl_surface into a sub-surface.
3927 //
3928 // The to-be sub-surface must not already have another role, and it
3929 // must not have an existing wl_subsurface object. Otherwise a protocol
3930 // error is raised.
3931 //
3932 // Adding sub-surfaces to a parent is a double-buffered operation on the
3933 // parent (see wl_surface.commit). The effect of adding a sub-surface
3934 // becomes visible on the next time the state of the parent surface is
3935 // applied.
3936 //
3937 // This request modifies the behaviour of wl_surface.commit request on
3938 // the sub-surface, see the documentation on wl_subsurface interface.
3939 //
3940 func (p *Subcompositor) GetSubsurface(surface *Surface, parent *Surface) (*Subsurface, error) {
3941 ret := NewSubsurface(p.Context())
3942 return ret, p.Context().SendRequest(p, 1, Proxy(ret), surface, parent)
3943 }
3944
3945 const (
3946 SubcompositorErrorBadSurface = 0
3947 )
3948
3949 type Subsurface struct {
3950 BaseProxy
3951 }
3952
3953 func NewSubsurface(ctx *Context) *Subsurface {
3954 ret := new(Subsurface)
3955 ctx.Register(ret)
3956 return ret
3957 }
3958
3959 // Destroy will remove sub-surface interface.
3960 //
3961 //
3962 // The sub-surface interface is removed from the wl_surface object
3963 // that was turned into a sub-surface with a
3964 // wl_subcompositor.get_subsurface request. The wl_surface's association
3965 // to the parent is deleted, and the wl_surface loses its role as
3966 // a sub-surface. The wl_surface is unmapped immediately.
3967 //
3968 func (p *Subsurface) Destroy() error {
3969 return p.Context().SendRequest(p, 0)
3970 }
3971
3972 // SetPosition will reposition the sub-surface.
3973 //
3974 //
3975 // This schedules a sub-surface position change.
3976 // The sub-surface will be moved so that its origin (top left
3977 // corner pixel) will be at the location x, y of the parent surface
3978 // coordinate system. The coordinates are not restricted to the parent
3979 // surface area. Negative values are allowed.
3980 //
3981 // The scheduled coordinates will take effect whenever the state of the
3982 // parent surface is applied. When this happens depends on whether the
3983 // parent surface is in synchronized mode or not. See
3984 // wl_subsurface.set_sync and wl_subsurface.set_desync for details.
3985 //
3986 // If more than one set_position request is invoked by the client before
3987 // the commit of the parent surface, the position of a new request always
3988 // replaces the scheduled position from any previous request.
3989 //
3990 // The initial position is 0, 0.
3991 //
3992 func (p *Subsurface) SetPosition(x int32, y int32) error {
3993 return p.Context().SendRequest(p, 1, x, y)
3994 }
3995
3996 // PlaceAbove will restack the sub-surface.
3997 //
3998 //
3999 // This sub-surface is taken from the stack, and put back just
4000 // above the reference surface, changing the z-order of the sub-surfaces.
4001 // The reference surface must be one of the sibling surfaces, or the
4002 // parent surface. Using any other surface, including this sub-surface,
4003 // will cause a protocol error.
4004 //
4005 // The z-order is double-buffered. Requests are handled in order and
4006 // applied immediately to a pending state. The final pending state is
4007 // copied to the active state the next time the state of the parent
4008 // surface is applied. When this happens depends on whether the parent
4009 // surface is in synchronized mode or not. See wl_subsurface.set_sync and
4010 // wl_subsurface.set_desync for details.
4011 //
4012 // A new sub-surface is initially added as the top-most in the stack
4013 // of its siblings and parent.
4014 //
4015 func (p *Subsurface) PlaceAbove(sibling *Surface) error {
4016 return p.Context().SendRequest(p, 2, sibling)
4017 }
4018
4019 // PlaceBelow will restack the sub-surface.
4020 //
4021 //
4022 // The sub-surface is placed just below the reference surface.
4023 // See wl_subsurface.place_above.
4024 //
4025 func (p *Subsurface) PlaceBelow(sibling *Surface) error {
4026 return p.Context().SendRequest(p, 3, sibling)
4027 }
4028
4029 // SetSync will set sub-surface to synchronized mode.
4030 //
4031 //
4032 // Change the commit behaviour of the sub-surface to synchronized
4033 // mode, also described as the parent dependent mode.
4034 //
4035 // In synchronized mode, wl_surface.commit on a sub-surface will
4036 // accumulate the committed state in a cache, but the state will
4037 // not be applied and hence will not change the compositor output.
4038 // The cached state is applied to the sub-surface immediately after
4039 // the parent surface's state is applied. This ensures atomic
4040 // updates of the parent and all its synchronized sub-surfaces.
4041 // Applying the cached state will invalidate the cache, so further
4042 // parent surface commits do not (re-)apply old state.
4043 //
4044 // See wl_subsurface for the recursive effect of this mode.
4045 //
4046 func (p *Subsurface) SetSync() error {
4047 return p.Context().SendRequest(p, 4)
4048 }
4049
4050 // SetDesync will set sub-surface to desynchronized mode.
4051 //
4052 //
4053 // Change the commit behaviour of the sub-surface to desynchronized
4054 // mode, also described as independent or freely running mode.
4055 //
4056 // In desynchronized mode, wl_surface.commit on a sub-surface will
4057 // apply the pending state directly, without caching, as happens
4058 // normally with a wl_surface. Calling wl_surface.commit on the
4059 // parent surface has no effect on the sub-surface's wl_surface
4060 // state. This mode allows a sub-surface to be updated on its own.
4061 //
4062 // If cached state exists when wl_surface.commit is called in
4063 // desynchronized mode, the pending state is added to the cached
4064 // state, and applied as a whole. This invalidates the cache.
4065 //
4066 // Note: even if a sub-surface is set to desynchronized, a parent
4067 // sub-surface may override it to behave as synchronized. For details,
4068 // see wl_subsurface.
4069 //
4070 // If a surface's parent surface behaves as desynchronized, then
4071 // the cached state is applied on set_desync.
4072 //
4073 func (p *Subsurface) SetDesync() error {
4074 return p.Context().SendRequest(p, 5)
4075 }
4076
4077 const (
4078 SubsurfaceErrorBadSurface = 0
4079 )