// Code generated by wlbgen. DO NOT EDIT. // Protocol: ext_image_copy_capture_v1 // Source: ext-image-copy-capture-v1.xml // Upstream protocol copyright and license: // Copyright © 2021-2023 Andri Yngvason // Copyright © 2024 Simon Ser // // Permission is hereby granted, free of charge, to any person obtaining a // copy of this software and associated documentation files (the "Software"), // to deal in the Software without restriction, including without limitation // the rights to use, copy, modify, merge, publish, distribute, sublicense, // and/or sell copies of the Software, and to permit persons to whom the // Software is furnished to do so, subject to the following conditions: // // The above copyright notice and this permission notice (including the next // paragraph) shall be included in all copies or substantial portions of the // Software. // // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL // THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER // DEALINGS IN THE SOFTWARE. package extimagecopycapture import ( "sync" cross_ext_image_capture_source_v1 "github.com/bnema/go-wayland-bindings/client/extimagecapturesource" cross_wl_buffer "github.com/bnema/go-wayland-bindings/client/wayland" cross_wl_pointer "github.com/bnema/go-wayland-bindings/client/wayland" "github.com/bnema/wlturbo/wl" ) // ERROR_INVALID_OPTION is the error invalid_option value. const ERROR_INVALID_OPTION = 1 // OPTIONS_PAINT_CURSORS is the options paint_cursors value. const OPTIONS_PAINT_CURSORS = 1 // ERROR_DUPLICATE_FRAME is the error duplicate_frame value. const ERROR_DUPLICATE_FRAME = 1 // ERROR_NO_BUFFER is the error no_buffer value. const ERROR_NO_BUFFER = 1 // ERROR_INVALID_BUFFER_DAMAGE is the error invalid_buffer_damage value. const ERROR_INVALID_BUFFER_DAMAGE = 2 // ERROR_ALREADY_CAPTURED is the error already_captured value. const ERROR_ALREADY_CAPTURED = 3 // FAILURE_REASON_UNKNOWN is the failure_reason unknown value. const FAILURE_REASON_UNKNOWN = 0 // FAILURE_REASON_BUFFER_CONSTRAINTS is the failure_reason buffer_constraints value. const FAILURE_REASON_BUFFER_CONSTRAINTS = 1 // FAILURE_REASON_STOPPED is the failure_reason stopped value. const FAILURE_REASON_STOPPED = 2 // ERROR_DUPLICATE_SESSION is the error duplicate_session value. const ERROR_DUPLICATE_SESSION = 1 // ExtImageCopyCaptureManagerInterface is the protocol interface name. const ExtImageCopyCaptureManagerInterface = "ext_image_copy_capture_manager_v1" // ExtImageCopyCaptureManager is the generated binding for ext_image_copy_capture_manager_v1 version 1. type ExtImageCopyCaptureManager struct { wl.BaseProxy } // NewExtImageCopyCaptureManager returns an unbound ExtImageCopyCaptureManager. func NewExtImageCopyCaptureManager(ctx *wl.Context) *ExtImageCopyCaptureManager { obj := &ExtImageCopyCaptureManager{} obj.SetContext(ctx) ctx.Register(obj) return obj } // Create a capturing session for an image capture source. If the paint_cursors option is set, cursors shall be composited onto the captured frame. The cursor must not be composited onto the frame if this flag is not set. If the options bitfield is invalid, the invalid_option protocol error is sent. func (o *ExtImageCopyCaptureManager) CreateSession(source *cross_ext_image_capture_source_v1.ExtImageCaptureSource, options uint32) (*ExtImageCopyCaptureSession, error) { var arg1 wl.Object if source != nil { arg1 = source } child := &ExtImageCopyCaptureSession{} child.SetContext(o.Context()) if err := o.Context().RequestArgs(wl.Request{Proxy: o, Opcode: 0, Name: "ext_image_copy_capture_manager_v1.create_session", Child: child}, wl.ArgObject(child), wl.ArgObject(arg1), wl.ArgUint(options)); err != nil { return nil, err } return child, nil } // Create a cursor capturing session for the pointer of an image capture source. func (o *ExtImageCopyCaptureManager) CreatePointerCursorSession(source *cross_ext_image_capture_source_v1.ExtImageCaptureSource, pointer *cross_wl_pointer.Pointer) (*ExtImageCopyCaptureCursorSession, error) { var arg1 wl.Object if source != nil { arg1 = source } var arg2 wl.Object if pointer != nil { arg2 = pointer } child := &ExtImageCopyCaptureCursorSession{} child.SetContext(o.Context()) if err := o.Context().RequestArgs(wl.Request{Proxy: o, Opcode: 1, Name: "ext_image_copy_capture_manager_v1.create_pointer_cursor_session", Child: child}, wl.ArgObject(child), wl.ArgObject(arg1), wl.ArgObject(arg2)); err != nil { return nil, err } return child, nil } // Destroy the manager object. Other objects created via this interface are unaffected. func (o *ExtImageCopyCaptureManager) Destroy() error { if err := o.Context().RequestArgs(wl.Request{Proxy: o, Opcode: 2, Name: "ext_image_copy_capture_manager_v1.destroy", Destructor: true}); err != nil { return err } return nil } // EventSignature returns the declared event argument types in wire order. func (o *ExtImageCopyCaptureManager) EventSignature(opcode uint16) (string, bool) { switch opcode { default: return "", false } } // Dispatch decodes one event on ext_image_copy_capture_manager_v1 and calls the registered handlers. func (o *ExtImageCopyCaptureManager) Dispatch(event *wl.Event) { switch event.Opcode { default: } } // ExtImageCopyCaptureSessionInterface is the protocol interface name. const ExtImageCopyCaptureSessionInterface = "ext_image_copy_capture_session_v1" // ExtImageCopyCaptureSession is the generated binding for ext_image_copy_capture_session_v1 version 1. type ExtImageCopyCaptureSession struct { wl.BaseProxy // handlersMu guards the handler slices: a client may register or replace // handlers while another goroutine dispatches events. handlersMu sync.Mutex onBufferSize []func(width uint32, height uint32) onShmFormat []func(format uint32) onDmabufDevice []func(device []byte) onDmabufFormat []func(format uint32, modifiers []byte) onDone []func() onStopped []func() } // NewExtImageCopyCaptureSession returns an unbound ExtImageCopyCaptureSession. func NewExtImageCopyCaptureSession(ctx *wl.Context) *ExtImageCopyCaptureSession { obj := &ExtImageCopyCaptureSession{} obj.SetContext(ctx) ctx.Register(obj) return obj } // Create a capture frame for this session. At most one frame object can exist for a given session at any time. If a client sends a create_frame request before a previous frame object has been destroyed, the duplicate_frame protocol error is raised. func (o *ExtImageCopyCaptureSession) CreateFrame() (*ExtImageCopyCaptureFrame, error) { child := &ExtImageCopyCaptureFrame{} child.SetContext(o.Context()) if err := o.Context().RequestArgs(wl.Request{Proxy: o, Opcode: 0, Name: "ext_image_copy_capture_session_v1.create_frame", Child: child}, wl.ArgObject(child)); err != nil { return nil, err } return child, nil } // Destroys the session. This request can be sent at any time by the client. This request doesn't affect ext_image_copy_capture_frame_v1 objects created by this object. func (o *ExtImageCopyCaptureSession) Destroy() error { if err := o.Context().RequestArgs(wl.Request{Proxy: o, Opcode: 1, Name: "ext_image_copy_capture_session_v1.destroy", Destructor: true}); err != nil { return err } return nil } // OnBufferSize registers a handler for the buffer_size event. // // Handlers are appended, so a second call adds another handler rather than // replacing the first. Registration is safe while another goroutine dispatches. func (o *ExtImageCopyCaptureSession) OnBufferSize(handler func(width uint32, height uint32)) { if handler == nil { return } o.handlersMu.Lock() defer o.handlersMu.Unlock() o.onBufferSize = append(o.onBufferSize, handler) } // handlersForBufferSize returns the handlers registered for buffer_size, taken // under the lock so a handler may register another handler while events are // being dispatched. func (o *ExtImageCopyCaptureSession) handlersForBufferSize() []func(width uint32, height uint32) { o.handlersMu.Lock() defer o.handlersMu.Unlock() return o.onBufferSize } // OnShmFormat registers a handler for the shm_format event. // // Handlers are appended, so a second call adds another handler rather than // replacing the first. Registration is safe while another goroutine dispatches. func (o *ExtImageCopyCaptureSession) OnShmFormat(handler func(format uint32)) { if handler == nil { return } o.handlersMu.Lock() defer o.handlersMu.Unlock() o.onShmFormat = append(o.onShmFormat, handler) } // handlersForShmFormat returns the handlers registered for shm_format, taken // under the lock so a handler may register another handler while events are // being dispatched. func (o *ExtImageCopyCaptureSession) handlersForShmFormat() []func(format uint32) { o.handlersMu.Lock() defer o.handlersMu.Unlock() return o.onShmFormat } // OnDmabufDevice registers a handler for the dmabuf_device event. // // Handlers are appended, so a second call adds another handler rather than // replacing the first. Registration is safe while another goroutine dispatches. func (o *ExtImageCopyCaptureSession) OnDmabufDevice(handler func(device []byte)) { if handler == nil { return } o.handlersMu.Lock() defer o.handlersMu.Unlock() o.onDmabufDevice = append(o.onDmabufDevice, handler) } // handlersForDmabufDevice returns the handlers registered for dmabuf_device, taken // under the lock so a handler may register another handler while events are // being dispatched. func (o *ExtImageCopyCaptureSession) handlersForDmabufDevice() []func(device []byte) { o.handlersMu.Lock() defer o.handlersMu.Unlock() return o.onDmabufDevice } // OnDmabufFormat registers a handler for the dmabuf_format event. // // Handlers are appended, so a second call adds another handler rather than // replacing the first. Registration is safe while another goroutine dispatches. func (o *ExtImageCopyCaptureSession) OnDmabufFormat(handler func(format uint32, modifiers []byte)) { if handler == nil { return } o.handlersMu.Lock() defer o.handlersMu.Unlock() o.onDmabufFormat = append(o.onDmabufFormat, handler) } // handlersForDmabufFormat returns the handlers registered for dmabuf_format, taken // under the lock so a handler may register another handler while events are // being dispatched. func (o *ExtImageCopyCaptureSession) handlersForDmabufFormat() []func(format uint32, modifiers []byte) { o.handlersMu.Lock() defer o.handlersMu.Unlock() return o.onDmabufFormat } // OnDone registers a handler for the done event. // // Handlers are appended, so a second call adds another handler rather than // replacing the first. Registration is safe while another goroutine dispatches. func (o *ExtImageCopyCaptureSession) OnDone(handler func()) { if handler == nil { return } o.handlersMu.Lock() defer o.handlersMu.Unlock() o.onDone = append(o.onDone, handler) } // handlersForDone returns the handlers registered for done, taken // under the lock so a handler may register another handler while events are // being dispatched. func (o *ExtImageCopyCaptureSession) handlersForDone() []func() { o.handlersMu.Lock() defer o.handlersMu.Unlock() return o.onDone } // OnStopped registers a handler for the stopped event. // // Handlers are appended, so a second call adds another handler rather than // replacing the first. Registration is safe while another goroutine dispatches. func (o *ExtImageCopyCaptureSession) OnStopped(handler func()) { if handler == nil { return } o.handlersMu.Lock() defer o.handlersMu.Unlock() o.onStopped = append(o.onStopped, handler) } // handlersForStopped returns the handlers registered for stopped, taken // under the lock so a handler may register another handler while events are // being dispatched. func (o *ExtImageCopyCaptureSession) handlersForStopped() []func() { o.handlersMu.Lock() defer o.handlersMu.Unlock() return o.onStopped } // EventSignature returns the declared event argument types in wire order. func (o *ExtImageCopyCaptureSession) EventSignature(opcode uint16) (string, bool) { switch opcode { case 0: return "uint,uint,", true case 1: return "uint,", true case 2: return "array,", true case 3: return "uint,array,", true case 4: return "", true case 5: return "", true default: return "", false } } // Dispatch decodes one event on ext_image_copy_capture_session_v1 and calls the registered handlers. func (o *ExtImageCopyCaptureSession) Dispatch(event *wl.Event) { switch event.Opcode { case 0: // buffer_size width := event.Uint32() height := event.Uint32() for i, handler := range o.handlersForBufferSize() { _ = i handler(width, height) } case 1: // shm_format format := event.Uint32() for i, handler := range o.handlersForShmFormat() { _ = i handler(format) } case 2: // dmabuf_device device := event.Array() for i, handler := range o.handlersForDmabufDevice() { _ = i handler(device) } case 3: // dmabuf_format format := event.Uint32() modifiers := event.Array() for i, handler := range o.handlersForDmabufFormat() { _ = i handler(format, modifiers) } case 4: // done for i, handler := range o.handlersForDone() { _ = i handler() } case 5: // stopped for i, handler := range o.handlersForStopped() { _ = i handler() } default: } } // ExtImageCopyCaptureFrameInterface is the protocol interface name. const ExtImageCopyCaptureFrameInterface = "ext_image_copy_capture_frame_v1" // ExtImageCopyCaptureFrame is the generated binding for ext_image_copy_capture_frame_v1 version 1. type ExtImageCopyCaptureFrame struct { wl.BaseProxy // handlersMu guards the handler slices: a client may register or replace // handlers while another goroutine dispatches events. handlersMu sync.Mutex onTransform []func(transform uint32) onDamage []func(x int32, y int32, width int32, height int32) onPresentationTime []func(tvSecHi uint32, tvSecLo uint32, tvNsec uint32) onReady []func() onFailed []func(reason uint32) } // NewExtImageCopyCaptureFrame returns an unbound ExtImageCopyCaptureFrame. func NewExtImageCopyCaptureFrame(ctx *wl.Context) *ExtImageCopyCaptureFrame { obj := &ExtImageCopyCaptureFrame{} obj.SetContext(ctx) ctx.Register(obj) return obj } // Destroys the frame. This request can be sent at any time by the client. func (o *ExtImageCopyCaptureFrame) Destroy() error { if err := o.Context().RequestArgs(wl.Request{Proxy: o, Opcode: 0, Name: "ext_image_copy_capture_frame_v1.destroy", Destructor: true}); err != nil { return err } return nil } // Attach a buffer to the session. The wl_buffer.release request is unused. The new buffer replaces any previously attached buffer. This request must not be sent after capture, or else the already_captured protocol error is raised. func (o *ExtImageCopyCaptureFrame) AttachBuffer(buffer *cross_wl_buffer.Buffer) error { var arg0 wl.Object if buffer != nil { arg0 = buffer } if err := o.Context().RequestArgs(wl.Request{Proxy: o, Opcode: 1, Name: "ext_image_copy_capture_frame_v1.attach_buffer"}, wl.ArgObject(arg0)); err != nil { return err } return nil } // Apply damage to the buffer which is to be captured next. This request may be sent multiple times to describe a region. The client indicates the accumulated damage since this wl_buffer was last captured. During capture, the compositor will update the buffer with at least the union of the region passed by the client and the region advertised by ext_image_copy_capture_frame_v1.damage. When a wl_buffer is captured for the first time, or when the client doesn't track damage, the client must damage the whole buffer. This is for optimisation purposes. The compositor may use this information to reduce copying. These coordinates originate from the upper left corner of the buffer. If x or y are strictly negative, or if width or height are negative or zero, the invalid_buffer_damage protocol error is raised. This request must not be sent after capture, or else the already_captured protocol error is raised. func (o *ExtImageCopyCaptureFrame) DamageBuffer(x int32, y int32, width int32, height int32) error { if err := o.Context().RequestArgs(wl.Request{Proxy: o, Opcode: 2, Name: "ext_image_copy_capture_frame_v1.damage_buffer"}, wl.ArgInt(x), wl.ArgInt(y), wl.ArgInt(width), wl.ArgInt(height)); err != nil { return err } return nil } // Capture a frame. Unless this is the first successful captured frame performed in this session, the compositor may wait an indefinite amount of time for the source content to change before performing the copy. This request may only be sent once, or else the already_captured protocol error is raised. A buffer must be attached before this request is sent, or else the no_buffer protocol error is raised. func (o *ExtImageCopyCaptureFrame) Capture() error { if err := o.Context().RequestArgs(wl.Request{Proxy: o, Opcode: 3, Name: "ext_image_copy_capture_frame_v1.capture"}); err != nil { return err } return nil } // OnTransform registers a handler for the transform event. // // Handlers are appended, so a second call adds another handler rather than // replacing the first. Registration is safe while another goroutine dispatches. func (o *ExtImageCopyCaptureFrame) OnTransform(handler func(transform uint32)) { if handler == nil { return } o.handlersMu.Lock() defer o.handlersMu.Unlock() o.onTransform = append(o.onTransform, handler) } // handlersForTransform returns the handlers registered for transform, taken // under the lock so a handler may register another handler while events are // being dispatched. func (o *ExtImageCopyCaptureFrame) handlersForTransform() []func(transform uint32) { o.handlersMu.Lock() defer o.handlersMu.Unlock() return o.onTransform } // OnDamage registers a handler for the damage event. // // Handlers are appended, so a second call adds another handler rather than // replacing the first. Registration is safe while another goroutine dispatches. func (o *ExtImageCopyCaptureFrame) OnDamage(handler func(x int32, y int32, width int32, height int32)) { if handler == nil { return } o.handlersMu.Lock() defer o.handlersMu.Unlock() o.onDamage = append(o.onDamage, handler) } // handlersForDamage returns the handlers registered for damage, taken // under the lock so a handler may register another handler while events are // being dispatched. func (o *ExtImageCopyCaptureFrame) handlersForDamage() []func(x int32, y int32, width int32, height int32) { o.handlersMu.Lock() defer o.handlersMu.Unlock() return o.onDamage } // OnPresentationTime registers a handler for the presentation_time event. // // Handlers are appended, so a second call adds another handler rather than // replacing the first. Registration is safe while another goroutine dispatches. func (o *ExtImageCopyCaptureFrame) OnPresentationTime(handler func(tvSecHi uint32, tvSecLo uint32, tvNsec uint32)) { if handler == nil { return } o.handlersMu.Lock() defer o.handlersMu.Unlock() o.onPresentationTime = append(o.onPresentationTime, handler) } // handlersForPresentationTime returns the handlers registered for presentation_time, taken // under the lock so a handler may register another handler while events are // being dispatched. func (o *ExtImageCopyCaptureFrame) handlersForPresentationTime() []func(tvSecHi uint32, tvSecLo uint32, tvNsec uint32) { o.handlersMu.Lock() defer o.handlersMu.Unlock() return o.onPresentationTime } // OnReady registers a handler for the ready event. // // Handlers are appended, so a second call adds another handler rather than // replacing the first. Registration is safe while another goroutine dispatches. func (o *ExtImageCopyCaptureFrame) OnReady(handler func()) { if handler == nil { return } o.handlersMu.Lock() defer o.handlersMu.Unlock() o.onReady = append(o.onReady, handler) } // handlersForReady returns the handlers registered for ready, taken // under the lock so a handler may register another handler while events are // being dispatched. func (o *ExtImageCopyCaptureFrame) handlersForReady() []func() { o.handlersMu.Lock() defer o.handlersMu.Unlock() return o.onReady } // OnFailed registers a handler for the failed event. // // Handlers are appended, so a second call adds another handler rather than // replacing the first. Registration is safe while another goroutine dispatches. func (o *ExtImageCopyCaptureFrame) OnFailed(handler func(reason uint32)) { if handler == nil { return } o.handlersMu.Lock() defer o.handlersMu.Unlock() o.onFailed = append(o.onFailed, handler) } // handlersForFailed returns the handlers registered for failed, taken // under the lock so a handler may register another handler while events are // being dispatched. func (o *ExtImageCopyCaptureFrame) handlersForFailed() []func(reason uint32) { o.handlersMu.Lock() defer o.handlersMu.Unlock() return o.onFailed } // EventSignature returns the declared event argument types in wire order. func (o *ExtImageCopyCaptureFrame) EventSignature(opcode uint16) (string, bool) { switch opcode { case 0: return "uint,", true case 1: return "int,int,int,int,", true case 2: return "uint,uint,uint,", true case 3: return "", true case 4: return "uint,", true default: return "", false } } // Dispatch decodes one event on ext_image_copy_capture_frame_v1 and calls the registered handlers. func (o *ExtImageCopyCaptureFrame) Dispatch(event *wl.Event) { switch event.Opcode { case 0: // transform transform := event.Uint32() for i, handler := range o.handlersForTransform() { _ = i handler(transform) } case 1: // damage x := event.Int32() y := event.Int32() width := event.Int32() height := event.Int32() for i, handler := range o.handlersForDamage() { _ = i handler(x, y, width, height) } case 2: // presentation_time tvSecHi := event.Uint32() tvSecLo := event.Uint32() tvNsec := event.Uint32() for i, handler := range o.handlersForPresentationTime() { _ = i handler(tvSecHi, tvSecLo, tvNsec) } case 3: // ready for i, handler := range o.handlersForReady() { _ = i handler() } case 4: // failed reason := event.Uint32() for i, handler := range o.handlersForFailed() { _ = i handler(reason) } default: } } // ExtImageCopyCaptureCursorSessionInterface is the protocol interface name. const ExtImageCopyCaptureCursorSessionInterface = "ext_image_copy_capture_cursor_session_v1" // ExtImageCopyCaptureCursorSession is the generated binding for ext_image_copy_capture_cursor_session_v1 version 1. type ExtImageCopyCaptureCursorSession struct { wl.BaseProxy // handlersMu guards the handler slices: a client may register or replace // handlers while another goroutine dispatches events. handlersMu sync.Mutex onEnter []func() onLeave []func() onPosition []func(x int32, y int32) onHotspot []func(x int32, y int32) } // NewExtImageCopyCaptureCursorSession returns an unbound ExtImageCopyCaptureCursorSession. func NewExtImageCopyCaptureCursorSession(ctx *wl.Context) *ExtImageCopyCaptureCursorSession { obj := &ExtImageCopyCaptureCursorSession{} obj.SetContext(ctx) ctx.Register(obj) return obj } // Destroys the session. This request can be sent at any time by the client. This request doesn't affect ext_image_copy_capture_frame_v1 objects created by this object. func (o *ExtImageCopyCaptureCursorSession) Destroy() error { if err := o.Context().RequestArgs(wl.Request{Proxy: o, Opcode: 0, Name: "ext_image_copy_capture_cursor_session_v1.destroy", Destructor: true}); err != nil { return err } return nil } // Gets the image copy capture session for this cursor session. The session will produce frames of the cursor image. The compositor may pause the session when the cursor leaves the captured area. This request must not be sent more than once, or else the duplicate_session protocol error is raised. func (o *ExtImageCopyCaptureCursorSession) GetCaptureSession() (*ExtImageCopyCaptureSession, error) { child := &ExtImageCopyCaptureSession{} child.SetContext(o.Context()) if err := o.Context().RequestArgs(wl.Request{Proxy: o, Opcode: 1, Name: "ext_image_copy_capture_cursor_session_v1.get_capture_session", Child: child}, wl.ArgObject(child)); err != nil { return nil, err } return child, nil } // OnEnter registers a handler for the enter event. // // Handlers are appended, so a second call adds another handler rather than // replacing the first. Registration is safe while another goroutine dispatches. func (o *ExtImageCopyCaptureCursorSession) OnEnter(handler func()) { if handler == nil { return } o.handlersMu.Lock() defer o.handlersMu.Unlock() o.onEnter = append(o.onEnter, handler) } // handlersForEnter returns the handlers registered for enter, taken // under the lock so a handler may register another handler while events are // being dispatched. func (o *ExtImageCopyCaptureCursorSession) handlersForEnter() []func() { o.handlersMu.Lock() defer o.handlersMu.Unlock() return o.onEnter } // OnLeave registers a handler for the leave event. // // Handlers are appended, so a second call adds another handler rather than // replacing the first. Registration is safe while another goroutine dispatches. func (o *ExtImageCopyCaptureCursorSession) OnLeave(handler func()) { if handler == nil { return } o.handlersMu.Lock() defer o.handlersMu.Unlock() o.onLeave = append(o.onLeave, handler) } // handlersForLeave returns the handlers registered for leave, taken // under the lock so a handler may register another handler while events are // being dispatched. func (o *ExtImageCopyCaptureCursorSession) handlersForLeave() []func() { o.handlersMu.Lock() defer o.handlersMu.Unlock() return o.onLeave } // OnPosition registers a handler for the position event. // // Handlers are appended, so a second call adds another handler rather than // replacing the first. Registration is safe while another goroutine dispatches. func (o *ExtImageCopyCaptureCursorSession) OnPosition(handler func(x int32, y int32)) { if handler == nil { return } o.handlersMu.Lock() defer o.handlersMu.Unlock() o.onPosition = append(o.onPosition, handler) } // handlersForPosition returns the handlers registered for position, taken // under the lock so a handler may register another handler while events are // being dispatched. func (o *ExtImageCopyCaptureCursorSession) handlersForPosition() []func(x int32, y int32) { o.handlersMu.Lock() defer o.handlersMu.Unlock() return o.onPosition } // OnHotspot registers a handler for the hotspot event. // // Handlers are appended, so a second call adds another handler rather than // replacing the first. Registration is safe while another goroutine dispatches. func (o *ExtImageCopyCaptureCursorSession) OnHotspot(handler func(x int32, y int32)) { if handler == nil { return } o.handlersMu.Lock() defer o.handlersMu.Unlock() o.onHotspot = append(o.onHotspot, handler) } // handlersForHotspot returns the handlers registered for hotspot, taken // under the lock so a handler may register another handler while events are // being dispatched. func (o *ExtImageCopyCaptureCursorSession) handlersForHotspot() []func(x int32, y int32) { o.handlersMu.Lock() defer o.handlersMu.Unlock() return o.onHotspot } // EventSignature returns the declared event argument types in wire order. func (o *ExtImageCopyCaptureCursorSession) EventSignature(opcode uint16) (string, bool) { switch opcode { case 0: return "", true case 1: return "", true case 2: return "int,int,", true case 3: return "int,int,", true default: return "", false } } // Dispatch decodes one event on ext_image_copy_capture_cursor_session_v1 and calls the registered handlers. func (o *ExtImageCopyCaptureCursorSession) Dispatch(event *wl.Event) { switch event.Opcode { case 0: // enter for i, handler := range o.handlersForEnter() { _ = i handler() } case 1: // leave for i, handler := range o.handlersForLeave() { _ = i handler() } case 2: // position x := event.Int32() y := event.Int32() for i, handler := range o.handlersForPosition() { _ = i handler(x, y) } case 3: // hotspot x := event.Int32() y := event.Int32() for i, handler := range o.handlersForHotspot() { _ = i handler(x, y) } default: } }