// Code generated by wlturbo-scanner. DO NOT EDIT. // Protocol: ext_data_control_v1 // Source: ext-data-control-v1.xml // Upstream protocol copyright and license: // Copyright © 2018 Simon Ser // Copyright © 2019 Ivan Molodetskikh // Copyright © 2024 Neal Gompa // // Permission to use, copy, modify, distribute, and sell this // software and its documentation for any purpose is hereby granted // without fee, provided that the above copyright notice appear in // all copies and that both that copyright notice and this permission // notice appear in supporting documentation, and that the name of // the copyright holders not be used in advertising or publicity // pertaining to distribution of the software without specific, // written prior permission. The copyright holders make no // representations about the suitability of this software for any // purpose. It is provided "as is" without express or implied // warranty. // // THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS // SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND // FITNESS, IN NO EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY // SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES // WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN // AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, // ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF // THIS SOFTWARE. package datacontrol import ( "sync" cross_wl_seat "github.com/bnema/wlturbo/protocol/core" "github.com/bnema/wlturbo/wl" ) // ERROR_USED_SOURCE is the error used_source value. const ERROR_USED_SOURCE = 1 // ERROR_INVALID_OFFER is the error invalid_offer value. const ERROR_INVALID_OFFER = 1 // ExtDataControlManagerInterface is the protocol interface name. const ExtDataControlManagerInterface = "ext_data_control_manager_v1" // ExtDataControlManager is the generated binding for ext_data_control_manager_v1 version 1. type ExtDataControlManager struct { wl.BaseProxy } // NewExtDataControlManager returns an unbound ExtDataControlManager. func NewExtDataControlManager(ctx *wl.Context) *ExtDataControlManager { obj := &ExtDataControlManager{} obj.SetContext(ctx) ctx.Register(obj) return obj } // Create a new data source. func (o *ExtDataControlManager) CreateDataSource() (*ExtDataControlSource, error) { child := &ExtDataControlSource{} child.SetContext(o.Context()) if err := o.Context().RequestArgs(wl.Request{Proxy: o, Opcode: 0, Name: "ext_data_control_manager_v1.create_data_source", Child: child}, wl.ArgObject(child)); err != nil { return nil, err } return child, nil } // Create a data device that can be used to manage a seat's selection. func (o *ExtDataControlManager) GetDataDevice(seat *cross_wl_seat.Seat) (*ExtDataControlDevice, error) { var arg1 wl.Object if seat != nil { arg1 = seat } child := &ExtDataControlDevice{} child.SetContext(o.Context()) if err := o.Context().RequestArgs(wl.Request{Proxy: o, Opcode: 1, Name: "ext_data_control_manager_v1.get_data_device", Child: child}, wl.ArgObject(child), wl.ArgObject(arg1)); err != nil { return nil, err } return child, nil } // All objects created by the manager will still remain valid, until their appropriate destroy request has been called. func (o *ExtDataControlManager) Destroy() error { if err := o.Context().RequestArgs(wl.Request{Proxy: o, Opcode: 2, Name: "ext_data_control_manager_v1.destroy", Destructor: true}); err != nil { return err } return nil } // EventSignature returns the declared event argument types in wire order. func (o *ExtDataControlManager) EventSignature(opcode uint16) (string, bool) { switch opcode { default: return "", false } } // Dispatch decodes one event on ext_data_control_manager_v1 and calls the registered handlers. func (o *ExtDataControlManager) Dispatch(event *wl.Event) { switch event.Opcode { default: } } // ExtDataControlDeviceInterface is the protocol interface name. const ExtDataControlDeviceInterface = "ext_data_control_device_v1" // ExtDataControlDevice is the generated binding for ext_data_control_device_v1 version 1. type ExtDataControlDevice struct { wl.BaseProxy // handlersMu guards the handler slices: a client may register or replace // handlers while another goroutine dispatches events. handlersMu sync.Mutex onDataOffer []func(idObject *ExtDataControlOffer) onSelection []func(idID uint32) onFinished []func() onPrimarySelection []func(idID uint32) } // NewExtDataControlDevice returns an unbound ExtDataControlDevice. func NewExtDataControlDevice(ctx *wl.Context) *ExtDataControlDevice { obj := &ExtDataControlDevice{} obj.SetContext(ctx) ctx.Register(obj) return obj } // This request asks the compositor to set the selection to the data from the source on behalf of the client. The given source may not be used in any further set_selection or set_primary_selection requests. Attempting to use a previously used source triggers the used_source protocol error. To unset the selection, set the source to NULL. func (o *ExtDataControlDevice) SetSelection(source *ExtDataControlSource) error { var arg0 wl.Object if source != nil { arg0 = source } if err := o.Context().RequestArgs(wl.Request{Proxy: o, Opcode: 0, Name: "ext_data_control_device_v1.set_selection"}, wl.ArgObject(arg0)); err != nil { return err } return nil } // Destroys the data device object. func (o *ExtDataControlDevice) Destroy() error { if err := o.Context().RequestArgs(wl.Request{Proxy: o, Opcode: 1, Name: "ext_data_control_device_v1.destroy", Destructor: true}); err != nil { return err } return nil } // This request asks the compositor to set the primary selection to the data from the source on behalf of the client. The given source may not be used in any further set_selection or set_primary_selection requests. Attempting to use a previously used source triggers the used_source protocol error. To unset the primary selection, set the source to NULL. The compositor will ignore this request if it does not support primary selection. func (o *ExtDataControlDevice) SetPrimarySelection(source *ExtDataControlSource) error { var arg0 wl.Object if source != nil { arg0 = source } if err := o.Context().RequestArgs(wl.Request{Proxy: o, Opcode: 2, Name: "ext_data_control_device_v1.set_primary_selection"}, wl.ArgObject(arg0)); err != nil { return err } return nil } // OnDataOffer registers a handler for the data_offer 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 *ExtDataControlDevice) OnDataOffer(handler func(idObject *ExtDataControlOffer)) { if handler == nil { return } o.handlersMu.Lock() defer o.handlersMu.Unlock() o.onDataOffer = append(o.onDataOffer, handler) } // handlersForDataOffer returns the handlers registered for data_offer, taken // under the lock so a handler may register another handler while events are // being dispatched. func (o *ExtDataControlDevice) handlersForDataOffer() []func(idObject *ExtDataControlOffer) { o.handlersMu.Lock() defer o.handlersMu.Unlock() return o.onDataOffer } // OnSelection registers a handler for the selection 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 *ExtDataControlDevice) OnSelection(handler func(idID uint32)) { if handler == nil { return } o.handlersMu.Lock() defer o.handlersMu.Unlock() o.onSelection = append(o.onSelection, handler) } // handlersForSelection returns the handlers registered for selection, taken // under the lock so a handler may register another handler while events are // being dispatched. func (o *ExtDataControlDevice) handlersForSelection() []func(idID uint32) { o.handlersMu.Lock() defer o.handlersMu.Unlock() return o.onSelection } // OnFinished registers a handler for the finished 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 *ExtDataControlDevice) OnFinished(handler func()) { if handler == nil { return } o.handlersMu.Lock() defer o.handlersMu.Unlock() o.onFinished = append(o.onFinished, handler) } // handlersForFinished returns the handlers registered for finished, taken // under the lock so a handler may register another handler while events are // being dispatched. func (o *ExtDataControlDevice) handlersForFinished() []func() { o.handlersMu.Lock() defer o.handlersMu.Unlock() return o.onFinished } // OnPrimarySelection registers a handler for the primary_selection 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 *ExtDataControlDevice) OnPrimarySelection(handler func(idID uint32)) { if handler == nil { return } o.handlersMu.Lock() defer o.handlersMu.Unlock() o.onPrimarySelection = append(o.onPrimarySelection, handler) } // handlersForPrimarySelection returns the handlers registered for primary_selection, taken // under the lock so a handler may register another handler while events are // being dispatched. func (o *ExtDataControlDevice) handlersForPrimarySelection() []func(idID uint32) { o.handlersMu.Lock() defer o.handlersMu.Unlock() return o.onPrimarySelection } // EventSignature returns the declared event argument types in wire order. func (o *ExtDataControlDevice) EventSignature(opcode uint16) (string, bool) { switch opcode { case 0: return "new_id,", true case 1: return "object,", true case 2: return "", true case 3: return "object,", true default: return "", false } } // Dispatch decodes one event on ext_data_control_device_v1 and calls the registered handlers. func (o *ExtDataControlDevice) Dispatch(event *wl.Event) { switch event.Opcode { case 0: // data_offer idID := event.Uint32() idObject := &ExtDataControlOffer{} idObject.SetContext(o.Context()) idObject.SetID(idID) idObject.SetVersion(o.Version()) o.Context().Register(idObject) for i, handler := range o.handlersForDataOffer() { _ = i handler(idObject) } case 1: // selection idID := event.Uint32() for i, handler := range o.handlersForSelection() { _ = i handler(idID) } case 2: // finished for i, handler := range o.handlersForFinished() { _ = i handler() } case 3: // primary_selection idID := event.Uint32() for i, handler := range o.handlersForPrimarySelection() { _ = i handler(idID) } default: } } // ExtDataControlSourceInterface is the protocol interface name. const ExtDataControlSourceInterface = "ext_data_control_source_v1" // ExtDataControlSource is the generated binding for ext_data_control_source_v1 version 1. type ExtDataControlSource struct { wl.BaseProxy // handlersMu guards the handler slices: a client may register or replace // handlers while another goroutine dispatches events. handlersMu sync.Mutex onSend []func(mimeType string, fd *wl.OwnedFD) onCancelled []func() } // NewExtDataControlSource returns an unbound ExtDataControlSource. func NewExtDataControlSource(ctx *wl.Context) *ExtDataControlSource { obj := &ExtDataControlSource{} obj.SetContext(ctx) ctx.Register(obj) return obj } // This request adds a MIME type to the set of MIME types advertised to targets. Can be called several times to offer multiple types. Calling this after ext_data_control_device.set_selection is a protocol error. func (o *ExtDataControlSource) Offer(mimeType string) error { if err := o.Context().RequestArgs(wl.Request{Proxy: o, Opcode: 0, Name: "ext_data_control_source_v1.offer"}, wl.ArgString(mimeType)); err != nil { return err } return nil } // Destroys the data source object. func (o *ExtDataControlSource) Destroy() error { if err := o.Context().RequestArgs(wl.Request{Proxy: o, Opcode: 1, Name: "ext_data_control_source_v1.destroy", Destructor: true}); err != nil { return err } return nil } // OnSend registers a handler for the send 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 *ExtDataControlSource) OnSend(handler func(mimeType string, fd *wl.OwnedFD)) { if handler == nil { return } o.handlersMu.Lock() defer o.handlersMu.Unlock() o.onSend = append(o.onSend, handler) } // handlersForSend returns the handlers registered for send, taken // under the lock so a handler may register another handler while events are // being dispatched. func (o *ExtDataControlSource) handlersForSend() []func(mimeType string, fd *wl.OwnedFD) { o.handlersMu.Lock() defer o.handlersMu.Unlock() return o.onSend } // OnCancelled registers a handler for the cancelled 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 *ExtDataControlSource) OnCancelled(handler func()) { if handler == nil { return } o.handlersMu.Lock() defer o.handlersMu.Unlock() o.onCancelled = append(o.onCancelled, handler) } // handlersForCancelled returns the handlers registered for cancelled, taken // under the lock so a handler may register another handler while events are // being dispatched. func (o *ExtDataControlSource) handlersForCancelled() []func() { o.handlersMu.Lock() defer o.handlersMu.Unlock() return o.onCancelled } // EventSignature returns the declared event argument types in wire order. func (o *ExtDataControlSource) EventSignature(opcode uint16) (string, bool) { switch opcode { case 0: return "string,fd,", true case 1: return "", true default: return "", false } } // Dispatch decodes one event on ext_data_control_source_v1 and calls the registered handlers. func (o *ExtDataControlSource) Dispatch(event *wl.Event) { switch event.Opcode { case 0: // send mimeType := event.String() fd := event.FD() ownedfd := fd defer ownedfd.Close() for i, handler := range o.handlersForSend() { if i > 0 { fd = nil } handler(mimeType, fd) } case 1: // cancelled for i, handler := range o.handlersForCancelled() { _ = i handler() } default: } } // ExtDataControlOfferInterface is the protocol interface name. const ExtDataControlOfferInterface = "ext_data_control_offer_v1" // ExtDataControlOffer is the generated binding for ext_data_control_offer_v1 version 1. type ExtDataControlOffer struct { wl.BaseProxy // handlersMu guards the handler slices: a client may register or replace // handlers while another goroutine dispatches events. handlersMu sync.Mutex onOffer []func(mimeType string) } // NewExtDataControlOffer returns an unbound ExtDataControlOffer. func NewExtDataControlOffer(ctx *wl.Context) *ExtDataControlOffer { obj := &ExtDataControlOffer{} obj.SetContext(ctx) ctx.Register(obj) return obj } // To transfer the offered data, the client issues this request and indicates the MIME type it wants to receive. The transfer happens through the passed file descriptor (typically created with the pipe system call). The source client writes the data in the MIME type representation requested and then closes the file descriptor. The receiving client reads from the read end of the pipe until EOF and then closes its end, at which point the transfer is complete. This request may happen multiple times for different MIME types. func (o *ExtDataControlOffer) Receive(mimeType string, fd int) error { if err := o.Context().RequestArgs(wl.Request{Proxy: o, Opcode: 0, Name: "ext_data_control_offer_v1.receive", FDs: []int{fd}}, wl.ArgString(mimeType), wl.ArgFD()); err != nil { return err } return nil } // Destroys the data offer object. func (o *ExtDataControlOffer) Destroy() error { if err := o.Context().RequestArgs(wl.Request{Proxy: o, Opcode: 1, Name: "ext_data_control_offer_v1.destroy", Destructor: true}); err != nil { return err } return nil } // OnOffer registers a handler for the offer 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 *ExtDataControlOffer) OnOffer(handler func(mimeType string)) { if handler == nil { return } o.handlersMu.Lock() defer o.handlersMu.Unlock() o.onOffer = append(o.onOffer, handler) } // handlersForOffer returns the handlers registered for offer, taken // under the lock so a handler may register another handler while events are // being dispatched. func (o *ExtDataControlOffer) handlersForOffer() []func(mimeType string) { o.handlersMu.Lock() defer o.handlersMu.Unlock() return o.onOffer } // EventSignature returns the declared event argument types in wire order. func (o *ExtDataControlOffer) EventSignature(opcode uint16) (string, bool) { switch opcode { case 0: return "string,", true default: return "", false } } // Dispatch decodes one event on ext_data_control_offer_v1 and calls the registered handlers. func (o *ExtDataControlOffer) Dispatch(event *wl.Event) { switch event.Opcode { case 0: // offer mimeType := event.String() for i, handler := range o.handlersForOffer() { _ = i handler(mimeType) } default: } }