// Code generated by wlbgen. DO NOT EDIT. // Protocol: relative_pointer_unstable_v1 // Source: relative-pointer-unstable-v1.xml // Upstream protocol copyright and license: // Copyright © 2014 Jonas Ådahl // Copyright © 2015 Red Hat Inc. // // 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 relativepointer import ( "sync" cross_wl_pointer "github.com/bnema/go-wayland-bindings/client/wayland" "github.com/bnema/wlturbo/wl" ) // RelativePointerManagerInterface is the protocol interface name. const RelativePointerManagerInterface = "zwp_relative_pointer_manager_v1" // RelativePointerManager is the generated binding for zwp_relative_pointer_manager_v1 version 1. type RelativePointerManager struct { wl.BaseProxy } // NewRelativePointerManager returns an unbound RelativePointerManager. func NewRelativePointerManager(ctx *wl.Context) *RelativePointerManager { obj := &RelativePointerManager{} obj.SetContext(ctx) ctx.Register(obj) return obj } // Used by the client to notify the server that it will no longer use this relative pointer manager object. func (o *RelativePointerManager) Destroy() error { if err := o.Context().RequestArgs(wl.Request{Proxy: o, Opcode: 0, Name: "zwp_relative_pointer_manager_v1.destroy", Destructor: true}); err != nil { return err } return nil } // Create a relative pointer interface given a wl_pointer object. See the wp_relative_pointer interface for more details. func (o *RelativePointerManager) GetRelativePointer(pointer *cross_wl_pointer.Pointer) (*RelativePointer, error) { var arg1 wl.Object if pointer != nil { arg1 = pointer } child := &RelativePointer{} child.SetContext(o.Context()) if err := o.Context().RequestArgs(wl.Request{Proxy: o, Opcode: 1, Name: "zwp_relative_pointer_manager_v1.get_relative_pointer", Child: child}, wl.ArgObject(child), wl.ArgObject(arg1)); err != nil { return nil, err } return child, nil } // EventSignature returns the declared event argument types in wire order. func (o *RelativePointerManager) EventSignature(opcode uint16) (string, bool) { switch opcode { default: return "", false } } // Dispatch decodes one event on zwp_relative_pointer_manager_v1 and calls the registered handlers. func (o *RelativePointerManager) Dispatch(event *wl.Event) { switch event.Opcode { default: } } // RelativePointerInterface is the protocol interface name. const RelativePointerInterface = "zwp_relative_pointer_v1" // RelativePointer is the generated binding for zwp_relative_pointer_v1 version 1. type RelativePointer struct { wl.BaseProxy // handlersMu guards the handler slices: a client may register or replace // handlers while another goroutine dispatches events. handlersMu sync.Mutex onRelativeMotion []func(utimeHi uint32, utimeLo uint32, dx wl.Fixed, dy wl.Fixed, dxUnaccel wl.Fixed, dyUnaccel wl.Fixed) } // NewRelativePointer returns an unbound RelativePointer. func NewRelativePointer(ctx *wl.Context) *RelativePointer { obj := &RelativePointer{} obj.SetContext(ctx) ctx.Register(obj) return obj } // release the relative pointer object func (o *RelativePointer) Destroy() error { if err := o.Context().RequestArgs(wl.Request{Proxy: o, Opcode: 0, Name: "zwp_relative_pointer_v1.destroy", Destructor: true}); err != nil { return err } return nil } // OnRelativeMotion registers a handler for the relative_motion 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 *RelativePointer) OnRelativeMotion(handler func(utimeHi uint32, utimeLo uint32, dx wl.Fixed, dy wl.Fixed, dxUnaccel wl.Fixed, dyUnaccel wl.Fixed)) { if handler == nil { return } o.handlersMu.Lock() defer o.handlersMu.Unlock() o.onRelativeMotion = append(o.onRelativeMotion, handler) } // handlersForRelativeMotion returns the handlers registered for relative_motion, taken // under the lock so a handler may register another handler while events are // being dispatched. func (o *RelativePointer) handlersForRelativeMotion() []func(utimeHi uint32, utimeLo uint32, dx wl.Fixed, dy wl.Fixed, dxUnaccel wl.Fixed, dyUnaccel wl.Fixed) { o.handlersMu.Lock() defer o.handlersMu.Unlock() return o.onRelativeMotion } // EventSignature returns the declared event argument types in wire order. func (o *RelativePointer) EventSignature(opcode uint16) (string, bool) { switch opcode { case 0: return "uint,uint,fixed,fixed,fixed,fixed,", true default: return "", false } } // Dispatch decodes one event on zwp_relative_pointer_v1 and calls the registered handlers. func (o *RelativePointer) Dispatch(event *wl.Event) { switch event.Opcode { case 0: // relative_motion utimeHi := event.Uint32() utimeLo := event.Uint32() dx := event.Fixed() dy := event.Fixed() dxUnaccel := event.Fixed() dyUnaccel := event.Fixed() for i, handler := range o.handlersForRelativeMotion() { _ = i handler(utimeHi, utimeLo, dx, dy, dxUnaccel, dyUnaccel) } default: } }