1// Code generated by wlbgen. DO NOT EDIT.
2// Protocol: fractional_scale_v1
3// Source: fractional-scale-v1.xml
4
5// Upstream protocol copyright and license:
6// Copyright © 2022 Kenny Levinsen
7//
8// Permission is hereby granted, free of charge, to any person obtaining a
9// copy of this software and associated documentation files (the "Software"),
10// to deal in the Software without restriction, including without limitation
11// the rights to use, copy, modify, merge, publish, distribute, sublicense,
12// and/or sell copies of the Software, and to permit persons to whom the
13// Software is furnished to do so, subject to the following conditions:
14//
15// The above copyright notice and this permission notice (including the next
16// paragraph) shall be included in all copies or substantial portions of the
17// Software.
18//
19// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
22// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
24// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
25// DEALINGS IN THE SOFTWARE.
26
27package fractionalscale
28
29import (
30 "sync"
31
32 cross_wl_surface "github.com/bnema/go-wayland-bindings/client/wayland"
33 "github.com/bnema/wlturbo/wl"
34)
35
36// ERROR_FRACTIONAL_SCALE_EXISTS is the error fractional_scale_exists value.
37const ERROR_FRACTIONAL_SCALE_EXISTS = 0
38
39// WpFractionalScaleManagerInterface is the protocol interface name.
40const WpFractionalScaleManagerInterface = "wp_fractional_scale_manager_v1"
41
42// WpFractionalScaleManager is the generated binding for wp_fractional_scale_manager_v1 version 1.
43type WpFractionalScaleManager struct {
44 wl.BaseProxy
45}
46
47// NewWpFractionalScaleManager returns an unbound WpFractionalScaleManager.
48func NewWpFractionalScaleManager(ctx *wl.Context) *WpFractionalScaleManager {
49 obj := &WpFractionalScaleManager{}
50 obj.SetContext(ctx)
51 ctx.Register(obj)
52 return obj
53}
54
55// 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.
56func (o *WpFractionalScaleManager) Destroy() error {
57 if err := o.Context().RequestArgs(wl.Request{Proxy: o, Opcode: 0, Name: "wp_fractional_scale_manager_v1.destroy", Destructor: true}); err != nil {
58 return err
59 }
60 return nil
61}
62
63// 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.
64func (o *WpFractionalScaleManager) GetFractionalScale(surface *cross_wl_surface.Surface) (*WpFractionalScale, error) {
65 var arg1 wl.Object
66 if surface != nil {
67 arg1 = surface
68 }
69 child := &WpFractionalScale{}
70 child.SetContext(o.Context())
71 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 {
72 return nil, err
73 }
74 return child, nil
75}
76
77// EventSignature returns the declared event argument types in wire order.
78func (o *WpFractionalScaleManager) EventSignature(opcode uint16) (string, bool) {
79 switch opcode {
80 default:
81 return "", false
82 }
83}
84
85// Dispatch decodes one event on wp_fractional_scale_manager_v1 and calls the registered handlers.
86func (o *WpFractionalScaleManager) Dispatch(event *wl.Event) {
87 switch event.Opcode {
88 default:
89 }
90}
91
92// WpFractionalScaleInterface is the protocol interface name.
93const WpFractionalScaleInterface = "wp_fractional_scale_v1"
94
95// WpFractionalScale is the generated binding for wp_fractional_scale_v1 version 1.
96type WpFractionalScale struct {
97 wl.BaseProxy
98 // handlersMu guards the handler slices: a client may register or replace
99 // handlers while another goroutine dispatches events.
100 handlersMu sync.Mutex
101 onPreferredScale []func(scale uint32)
102}
103
104// NewWpFractionalScale returns an unbound WpFractionalScale.
105func NewWpFractionalScale(ctx *wl.Context) *WpFractionalScale {
106 obj := &WpFractionalScale{}
107 obj.SetContext(ctx)
108 ctx.Register(obj)
109 return obj
110}
111
112// Destroy the fractional scale object. When this object is destroyed, preferred_scale events will no longer be sent.
113func (o *WpFractionalScale) Destroy() error {
114 if err := o.Context().RequestArgs(wl.Request{Proxy: o, Opcode: 0, Name: "wp_fractional_scale_v1.destroy", Destructor: true}); err != nil {
115 return err
116 }
117 return nil
118}
119
120// OnPreferredScale registers a handler for the preferred_scale event.
121//
122// Handlers are appended, so a second call adds another handler rather than
123// replacing the first. Registration is safe while another goroutine dispatches.
124func (o *WpFractionalScale) OnPreferredScale(handler func(scale uint32)) {
125 if handler == nil {
126 return
127 }
128 o.handlersMu.Lock()
129 defer o.handlersMu.Unlock()
130 o.onPreferredScale = append(o.onPreferredScale, handler)
131}
132
133// handlersForPreferredScale returns the handlers registered for preferred_scale, taken
134// under the lock so a handler may register another handler while events are
135// being dispatched.
136func (o *WpFractionalScale) handlersForPreferredScale() []func(scale uint32) {
137 o.handlersMu.Lock()
138 defer o.handlersMu.Unlock()
139 return o.onPreferredScale
140}
141
142// EventSignature returns the declared event argument types in wire order.
143func (o *WpFractionalScale) EventSignature(opcode uint16) (string, bool) {
144 switch opcode {
145 case 0:
146 return "uint,", true
147 default:
148 return "", false
149 }
150}
151
152// Dispatch decodes one event on wp_fractional_scale_v1 and calls the registered handlers.
153func (o *WpFractionalScale) Dispatch(event *wl.Event) {
154 switch event.Opcode {
155 case 0: // preferred_scale
156 scale := event.Uint32()
157
158 for i, handler := range o.handlersForPreferredScale() {
159 _ = i
160 handler(scale)
161 }
162 default:
163 }
164}