// Code generated by wlbgen. DO NOT EDIT. // Protocol: ext_foreign_toplevel_list_v1 // Source: ext-foreign-toplevel-list-v1.xml // Upstream protocol copyright and license: // Copyright © 2018 Ilia Bozhinov // Copyright © 2020 Isaac Freund // Copyright © 2022 wb9688 // Copyright © 2023 i509VCB // // 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 extforeigntoplevellist import ( "sync" "github.com/bnema/wlturbo/wl" ) // ExtForeignToplevelListInterface is the protocol interface name. const ExtForeignToplevelListInterface = "ext_foreign_toplevel_list_v1" // ExtForeignToplevelList is the generated binding for ext_foreign_toplevel_list_v1 version 1. type ExtForeignToplevelList struct { wl.BaseProxy // handlersMu guards the handler slices: a client may register or replace // handlers while another goroutine dispatches events. handlersMu sync.Mutex onToplevel []func(toplevelObject *ExtForeignToplevelHandle) onFinished []func() } // NewExtForeignToplevelList returns an unbound ExtForeignToplevelList. func NewExtForeignToplevelList(ctx *wl.Context) *ExtForeignToplevelList { obj := &ExtForeignToplevelList{} obj.SetContext(ctx) ctx.Register(obj) return obj } // This request indicates that the client no longer wishes to receive events for new toplevels. The Wayland protocol is asynchronous, meaning the compositor may send further toplevel events until the stop request is processed. The client should wait for a ext_foreign_toplevel_list_v1.finished event before destroying this object. func (o *ExtForeignToplevelList) Stop() error { if err := o.Context().RequestArgs(wl.Request{Proxy: o, Opcode: 0, Name: "ext_foreign_toplevel_list_v1.stop"}); err != nil { return err } return nil } // This request should be called either when the client will no longer use the ext_foreign_toplevel_list_v1 or after the finished event has been received to allow destruction of the object. If a client wishes to destroy this object it should send a ext_foreign_toplevel_list_v1.stop request and wait for a ext_foreign_toplevel_list_v1.finished event, then destroy the handles and then this object. func (o *ExtForeignToplevelList) Destroy() error { if err := o.Context().RequestArgs(wl.Request{Proxy: o, Opcode: 1, Name: "ext_foreign_toplevel_list_v1.destroy", Destructor: true}); err != nil { return err } return nil } // OnToplevel registers a handler for the toplevel 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 *ExtForeignToplevelList) OnToplevel(handler func(toplevelObject *ExtForeignToplevelHandle)) { if handler == nil { return } o.handlersMu.Lock() defer o.handlersMu.Unlock() o.onToplevel = append(o.onToplevel, handler) } // handlersForToplevel returns the handlers registered for toplevel, taken // under the lock so a handler may register another handler while events are // being dispatched. func (o *ExtForeignToplevelList) handlersForToplevel() []func(toplevelObject *ExtForeignToplevelHandle) { o.handlersMu.Lock() defer o.handlersMu.Unlock() return o.onToplevel } // 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 *ExtForeignToplevelList) 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 *ExtForeignToplevelList) handlersForFinished() []func() { o.handlersMu.Lock() defer o.handlersMu.Unlock() return o.onFinished } // EventSignature returns the declared event argument types in wire order. func (o *ExtForeignToplevelList) EventSignature(opcode uint16) (string, bool) { switch opcode { case 0: return "new_id,", true case 1: return "", true default: return "", false } } // Dispatch decodes one event on ext_foreign_toplevel_list_v1 and calls the registered handlers. func (o *ExtForeignToplevelList) Dispatch(event *wl.Event) { switch event.Opcode { case 0: // toplevel toplevelID := event.Uint32() toplevelObject := &ExtForeignToplevelHandle{} toplevelObject.SetContext(o.Context()) toplevelObject.SetID(toplevelID) toplevelObject.SetVersion(o.Version()) o.Context().Register(toplevelObject) for i, handler := range o.handlersForToplevel() { _ = i handler(toplevelObject) } case 1: // finished for i, handler := range o.handlersForFinished() { _ = i handler() } default: } } // ExtForeignToplevelHandleInterface is the protocol interface name. const ExtForeignToplevelHandleInterface = "ext_foreign_toplevel_handle_v1" // ExtForeignToplevelHandle is the generated binding for ext_foreign_toplevel_handle_v1 version 1. type ExtForeignToplevelHandle struct { wl.BaseProxy // handlersMu guards the handler slices: a client may register or replace // handlers while another goroutine dispatches events. handlersMu sync.Mutex onClosed []func() onDone []func() onTitle []func(title string) onAppId []func(appId string) onIdentifier []func(identifier string) } // NewExtForeignToplevelHandle returns an unbound ExtForeignToplevelHandle. func NewExtForeignToplevelHandle(ctx *wl.Context) *ExtForeignToplevelHandle { obj := &ExtForeignToplevelHandle{} obj.SetContext(ctx) ctx.Register(obj) return obj } // This request should be used when the client will no longer use the handle or after the closed event has been received to allow destruction of the object. When a handle is destroyed, a new handle may not be created by the server until the toplevel is unmapped and then remapped. Destroying a toplevel handle is not recommended unless the client is cleaning up child objects before destroying the ext_foreign_toplevel_list_v1 object, the toplevel was closed or the toplevel handle will not be used in the future. Other protocols which extend the ext_foreign_toplevel_handle_v1 interface should require destructors for extension interfaces be called before allowing the toplevel handle to be destroyed. func (o *ExtForeignToplevelHandle) Destroy() error { if err := o.Context().RequestArgs(wl.Request{Proxy: o, Opcode: 0, Name: "ext_foreign_toplevel_handle_v1.destroy", Destructor: true}); err != nil { return err } return nil } // OnClosed registers a handler for the closed 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 *ExtForeignToplevelHandle) OnClosed(handler func()) { if handler == nil { return } o.handlersMu.Lock() defer o.handlersMu.Unlock() o.onClosed = append(o.onClosed, handler) } // handlersForClosed returns the handlers registered for closed, taken // under the lock so a handler may register another handler while events are // being dispatched. func (o *ExtForeignToplevelHandle) handlersForClosed() []func() { o.handlersMu.Lock() defer o.handlersMu.Unlock() return o.onClosed } // 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 *ExtForeignToplevelHandle) 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 *ExtForeignToplevelHandle) handlersForDone() []func() { o.handlersMu.Lock() defer o.handlersMu.Unlock() return o.onDone } // OnTitle registers a handler for the title 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 *ExtForeignToplevelHandle) OnTitle(handler func(title string)) { if handler == nil { return } o.handlersMu.Lock() defer o.handlersMu.Unlock() o.onTitle = append(o.onTitle, handler) } // handlersForTitle returns the handlers registered for title, taken // under the lock so a handler may register another handler while events are // being dispatched. func (o *ExtForeignToplevelHandle) handlersForTitle() []func(title string) { o.handlersMu.Lock() defer o.handlersMu.Unlock() return o.onTitle } // OnAppId registers a handler for the app_id 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 *ExtForeignToplevelHandle) OnAppId(handler func(appId string)) { if handler == nil { return } o.handlersMu.Lock() defer o.handlersMu.Unlock() o.onAppId = append(o.onAppId, handler) } // handlersForAppId returns the handlers registered for app_id, taken // under the lock so a handler may register another handler while events are // being dispatched. func (o *ExtForeignToplevelHandle) handlersForAppId() []func(appId string) { o.handlersMu.Lock() defer o.handlersMu.Unlock() return o.onAppId } // OnIdentifier registers a handler for the identifier 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 *ExtForeignToplevelHandle) OnIdentifier(handler func(identifier string)) { if handler == nil { return } o.handlersMu.Lock() defer o.handlersMu.Unlock() o.onIdentifier = append(o.onIdentifier, handler) } // handlersForIdentifier returns the handlers registered for identifier, taken // under the lock so a handler may register another handler while events are // being dispatched. func (o *ExtForeignToplevelHandle) handlersForIdentifier() []func(identifier string) { o.handlersMu.Lock() defer o.handlersMu.Unlock() return o.onIdentifier } // EventSignature returns the declared event argument types in wire order. func (o *ExtForeignToplevelHandle) EventSignature(opcode uint16) (string, bool) { switch opcode { case 0: return "", true case 1: return "", true case 2: return "string,", true case 3: return "string,", true case 4: return "string,", true default: return "", false } } // Dispatch decodes one event on ext_foreign_toplevel_handle_v1 and calls the registered handlers. func (o *ExtForeignToplevelHandle) Dispatch(event *wl.Event) { switch event.Opcode { case 0: // closed for i, handler := range o.handlersForClosed() { _ = i handler() } case 1: // done for i, handler := range o.handlersForDone() { _ = i handler() } case 2: // title title := event.String() for i, handler := range o.handlersForTitle() { _ = i handler(title) } case 3: // app_id appId := event.String() for i, handler := range o.handlersForAppId() { _ = i handler(appId) } case 4: // identifier identifier := event.String() for i, handler := range o.handlersForIdentifier() { _ = i handler(identifier) } default: } }