// Code generated by wlbgen. DO NOT EDIT. // Protocol: wp_primary_selection_unstable_v1 // Source: primary-selection-unstable-v1.xml // Upstream protocol copyright and license: // Copyright © 2015, 2016 Red Hat // // 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 primaryselection import ( "sync" cross_wl_seat "github.com/bnema/go-wayland-bindings/client/wayland" "github.com/bnema/wlturbo/wl" ) // PrimarySelectionDeviceManagerInterface is the protocol interface name. const PrimarySelectionDeviceManagerInterface = "zwp_primary_selection_device_manager_v1" // PrimarySelectionDeviceManager is the generated binding for zwp_primary_selection_device_manager_v1 version 1. type PrimarySelectionDeviceManager struct { wl.BaseProxy } // NewPrimarySelectionDeviceManager returns an unbound PrimarySelectionDeviceManager. func NewPrimarySelectionDeviceManager(ctx *wl.Context) *PrimarySelectionDeviceManager { obj := &PrimarySelectionDeviceManager{} obj.SetContext(ctx) ctx.Register(obj) return obj } // Create a new primary selection source. func (o *PrimarySelectionDeviceManager) CreateSource() (*PrimarySelectionSource, error) { child := &PrimarySelectionSource{} child.SetContext(o.Context()) if err := o.Context().RequestArgs(wl.Request{Proxy: o, Opcode: 0, Name: "zwp_primary_selection_device_manager_v1.create_source", Child: child}, wl.ArgObject(child)); err != nil { return nil, err } return child, nil } // Create a new data device for a given seat. func (o *PrimarySelectionDeviceManager) GetDevice(seat *cross_wl_seat.Seat) (*PrimarySelectionDevice, error) { var arg1 wl.Object if seat != nil { arg1 = seat } child := &PrimarySelectionDevice{} child.SetContext(o.Context()) if err := o.Context().RequestArgs(wl.Request{Proxy: o, Opcode: 1, Name: "zwp_primary_selection_device_manager_v1.get_device", Child: child}, wl.ArgObject(child), wl.ArgObject(arg1)); err != nil { return nil, err } return child, nil } // Destroy the primary selection device manager. func (o *PrimarySelectionDeviceManager) Destroy() error { if err := o.Context().RequestArgs(wl.Request{Proxy: o, Opcode: 2, Name: "zwp_primary_selection_device_manager_v1.destroy", Destructor: true}); err != nil { return err } return nil } // EventSignature returns the declared event argument types in wire order. func (o *PrimarySelectionDeviceManager) EventSignature(opcode uint16) (string, bool) { switch opcode { default: return "", false } } // Dispatch decodes one event on zwp_primary_selection_device_manager_v1 and calls the registered handlers. func (o *PrimarySelectionDeviceManager) Dispatch(event *wl.Event) { switch event.Opcode { default: } } // PrimarySelectionDeviceInterface is the protocol interface name. const PrimarySelectionDeviceInterface = "zwp_primary_selection_device_v1" // PrimarySelectionDevice is the generated binding for zwp_primary_selection_device_v1 version 1. type PrimarySelectionDevice 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(offerObject *PrimarySelectionOffer) onSelection []func(idID uint32) } // NewPrimarySelectionDevice returns an unbound PrimarySelectionDevice. func NewPrimarySelectionDevice(ctx *wl.Context) *PrimarySelectionDevice { obj := &PrimarySelectionDevice{} obj.SetContext(ctx) ctx.Register(obj) return obj } // Replaces the current selection. The previous owner of the primary selection will receive a wp_primary_selection_source.cancelled event. To unset the selection, set the source to NULL. func (o *PrimarySelectionDevice) SetSelection(source *PrimarySelectionSource, serial uint32) error { var arg0 wl.Object if source != nil { arg0 = source } if err := o.Context().RequestArgs(wl.Request{Proxy: o, Opcode: 0, Name: "zwp_primary_selection_device_v1.set_selection"}, wl.ArgObject(arg0), wl.ArgUint(serial)); err != nil { return err } return nil } // Destroy the primary selection device. func (o *PrimarySelectionDevice) Destroy() error { if err := o.Context().RequestArgs(wl.Request{Proxy: o, Opcode: 1, Name: "zwp_primary_selection_device_v1.destroy", Destructor: true}); 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 *PrimarySelectionDevice) OnDataOffer(handler func(offerObject *PrimarySelectionOffer)) { 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 *PrimarySelectionDevice) handlersForDataOffer() []func(offerObject *PrimarySelectionOffer) { 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 *PrimarySelectionDevice) 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 *PrimarySelectionDevice) handlersForSelection() []func(idID uint32) { o.handlersMu.Lock() defer o.handlersMu.Unlock() return o.onSelection } // EventSignature returns the declared event argument types in wire order. func (o *PrimarySelectionDevice) EventSignature(opcode uint16) (string, bool) { switch opcode { case 0: return "new_id,", true case 1: return "object,", true default: return "", false } } // Dispatch decodes one event on zwp_primary_selection_device_v1 and calls the registered handlers. func (o *PrimarySelectionDevice) Dispatch(event *wl.Event) { switch event.Opcode { case 0: // data_offer offerID := event.Uint32() offerObject := &PrimarySelectionOffer{} offerObject.SetContext(o.Context()) offerObject.SetID(offerID) offerObject.SetVersion(o.Version()) o.Context().Register(offerObject) for i, handler := range o.handlersForDataOffer() { _ = i handler(offerObject) } case 1: // selection idID := event.Uint32() for i, handler := range o.handlersForSelection() { _ = i handler(idID) } default: } } // PrimarySelectionOfferInterface is the protocol interface name. const PrimarySelectionOfferInterface = "zwp_primary_selection_offer_v1" // PrimarySelectionOffer is the generated binding for zwp_primary_selection_offer_v1 version 1. type PrimarySelectionOffer 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) } // NewPrimarySelectionOffer returns an unbound PrimarySelectionOffer. func NewPrimarySelectionOffer(ctx *wl.Context) *PrimarySelectionOffer { obj := &PrimarySelectionOffer{} obj.SetContext(ctx) ctx.Register(obj) return obj } // To transfer the contents of the primary selection clipboard, the client issues this request and indicates the mime type that 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 closes its end, at which point the transfer is complete. func (o *PrimarySelectionOffer) Receive(mimeType string, fd int) error { if err := o.Context().RequestArgs(wl.Request{Proxy: o, Opcode: 0, Name: "zwp_primary_selection_offer_v1.receive", FDs: []int{fd}}, wl.ArgString(mimeType), wl.ArgFD()); err != nil { return err } return nil } // Destroy the primary selection offer. func (o *PrimarySelectionOffer) Destroy() error { if err := o.Context().RequestArgs(wl.Request{Proxy: o, Opcode: 1, Name: "zwp_primary_selection_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 *PrimarySelectionOffer) 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 *PrimarySelectionOffer) 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 *PrimarySelectionOffer) EventSignature(opcode uint16) (string, bool) { switch opcode { case 0: return "string,", true default: return "", false } } // Dispatch decodes one event on zwp_primary_selection_offer_v1 and calls the registered handlers. func (o *PrimarySelectionOffer) Dispatch(event *wl.Event) { switch event.Opcode { case 0: // offer mimeType := event.String() for i, handler := range o.handlersForOffer() { _ = i handler(mimeType) } default: } } // PrimarySelectionSourceInterface is the protocol interface name. const PrimarySelectionSourceInterface = "zwp_primary_selection_source_v1" // PrimarySelectionSource is the generated binding for zwp_primary_selection_source_v1 version 1. type PrimarySelectionSource 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() } // NewPrimarySelectionSource returns an unbound PrimarySelectionSource. func NewPrimarySelectionSource(ctx *wl.Context) *PrimarySelectionSource { obj := &PrimarySelectionSource{} 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. func (o *PrimarySelectionSource) Offer(mimeType string) error { if err := o.Context().RequestArgs(wl.Request{Proxy: o, Opcode: 0, Name: "zwp_primary_selection_source_v1.offer"}, wl.ArgString(mimeType)); err != nil { return err } return nil } // Destroy the primary selection source. func (o *PrimarySelectionSource) Destroy() error { if err := o.Context().RequestArgs(wl.Request{Proxy: o, Opcode: 1, Name: "zwp_primary_selection_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 *PrimarySelectionSource) 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 *PrimarySelectionSource) 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 *PrimarySelectionSource) 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 *PrimarySelectionSource) handlersForCancelled() []func() { o.handlersMu.Lock() defer o.handlersMu.Unlock() return o.onCancelled } // EventSignature returns the declared event argument types in wire order. func (o *PrimarySelectionSource) 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 zwp_primary_selection_source_v1 and calls the registered handlers. func (o *PrimarySelectionSource) 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: } }