// Code generated by wlbgen. DO NOT EDIT. // Protocol: fractional_scale_v1 // Source: fractional-scale-v1.xml // Upstream protocol copyright and license: // Copyright © 2022 Kenny Levinsen // // 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 fractionalscale import ( "sync" cross_wl_surface "github.com/bnema/go-wayland-bindings/client/wayland" "github.com/bnema/wlturbo/wl" ) // ERROR_FRACTIONAL_SCALE_EXISTS is the error fractional_scale_exists value. const ERROR_FRACTIONAL_SCALE_EXISTS = 0 // WpFractionalScaleManagerInterface is the protocol interface name. const WpFractionalScaleManagerInterface = "wp_fractional_scale_manager_v1" // WpFractionalScaleManager is the generated binding for wp_fractional_scale_manager_v1 version 1. type WpFractionalScaleManager struct { wl.BaseProxy } // NewWpFractionalScaleManager returns an unbound WpFractionalScaleManager. func NewWpFractionalScaleManager(ctx *wl.Context) *WpFractionalScaleManager { obj := &WpFractionalScaleManager{} obj.SetContext(ctx) ctx.Register(obj) return obj } // Informs the server that the client will not be using this protocol object anymore. This does not affect any other objects, wp_fractional_scale_v1 objects included. func (o *WpFractionalScaleManager) Destroy() error { if err := o.Context().RequestArgs(wl.Request{Proxy: o, Opcode: 0, Name: "wp_fractional_scale_manager_v1.destroy", Destructor: true}); err != nil { return err } return nil } // Create an add-on object for the the wl_surface to let the compositor request fractional scales. If the given wl_surface already has a wp_fractional_scale_v1 object associated, the fractional_scale_exists protocol error is raised. func (o *WpFractionalScaleManager) GetFractionalScale(surface *cross_wl_surface.Surface) (*WpFractionalScale, error) { var arg1 wl.Object if surface != nil { arg1 = surface } child := &WpFractionalScale{} child.SetContext(o.Context()) if err := o.Context().RequestArgs(wl.Request{Proxy: o, Opcode: 1, Name: "wp_fractional_scale_manager_v1.get_fractional_scale", 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 *WpFractionalScaleManager) EventSignature(opcode uint16) (string, bool) { switch opcode { default: return "", false } } // Dispatch decodes one event on wp_fractional_scale_manager_v1 and calls the registered handlers. func (o *WpFractionalScaleManager) Dispatch(event *wl.Event) { switch event.Opcode { default: } } // WpFractionalScaleInterface is the protocol interface name. const WpFractionalScaleInterface = "wp_fractional_scale_v1" // WpFractionalScale is the generated binding for wp_fractional_scale_v1 version 1. type WpFractionalScale struct { wl.BaseProxy // handlersMu guards the handler slices: a client may register or replace // handlers while another goroutine dispatches events. handlersMu sync.Mutex onPreferredScale []func(scale uint32) } // NewWpFractionalScale returns an unbound WpFractionalScale. func NewWpFractionalScale(ctx *wl.Context) *WpFractionalScale { obj := &WpFractionalScale{} obj.SetContext(ctx) ctx.Register(obj) return obj } // Destroy the fractional scale object. When this object is destroyed, preferred_scale events will no longer be sent. func (o *WpFractionalScale) Destroy() error { if err := o.Context().RequestArgs(wl.Request{Proxy: o, Opcode: 0, Name: "wp_fractional_scale_v1.destroy", Destructor: true}); err != nil { return err } return nil } // OnPreferredScale registers a handler for the preferred_scale 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 *WpFractionalScale) OnPreferredScale(handler func(scale uint32)) { if handler == nil { return } o.handlersMu.Lock() defer o.handlersMu.Unlock() o.onPreferredScale = append(o.onPreferredScale, handler) } // handlersForPreferredScale returns the handlers registered for preferred_scale, taken // under the lock so a handler may register another handler while events are // being dispatched. func (o *WpFractionalScale) handlersForPreferredScale() []func(scale uint32) { o.handlersMu.Lock() defer o.handlersMu.Unlock() return o.onPreferredScale } // EventSignature returns the declared event argument types in wire order. func (o *WpFractionalScale) EventSignature(opcode uint16) (string, bool) { switch opcode { case 0: return "uint,", true default: return "", false } } // Dispatch decodes one event on wp_fractional_scale_v1 and calls the registered handlers. func (o *WpFractionalScale) Dispatch(event *wl.Event) { switch event.Opcode { case 0: // preferred_scale scale := event.Uint32() for i, handler := range o.handlersForPreferredScale() { _ = i handler(scale) } default: } }