1// Code generated by wlbgen. DO NOT EDIT.
2// Protocol: fullscreen_shell_unstable_v1
3// Source: fullscreen-shell-unstable-v1.xml
4
5// Upstream protocol copyright and license:
6// Copyright © 2016 Yong Bakos
7// Copyright © 2015 Jason Ekstrand
8// Copyright © 2015 Jonas Ådahl
9//
10// Permission is hereby granted, free of charge, to any person obtaining a
11// copy of this software and associated documentation files (the "Software"),
12// to deal in the Software without restriction, including without limitation
13// the rights to use, copy, modify, merge, publish, distribute, sublicense,
14// and/or sell copies of the Software, and to permit persons to whom the
15// Software is furnished to do so, subject to the following conditions:
16//
17// The above copyright notice and this permission notice (including the next
18// paragraph) shall be included in all copies or substantial portions of the
19// Software.
20//
21// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
22// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
23// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
24// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
25// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
26// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
27// DEALINGS IN THE SOFTWARE.
28
29package fullscreenshell
30
31import (
32 "sync"
33
34 cross_wl_output "github.com/bnema/go-wayland-bindings/client/wayland"
35 cross_wl_surface "github.com/bnema/go-wayland-bindings/client/wayland"
36 "github.com/bnema/wlturbo/wl"
37)
38
39// CAPABILITY_ARBITRARY_MODES is the capability arbitrary_modes value.
40const CAPABILITY_ARBITRARY_MODES = 1
41
42// CAPABILITY_CURSOR_PLANE is the capability cursor_plane value.
43const CAPABILITY_CURSOR_PLANE = 2
44
45// PRESENT_METHOD_DEFAULT is the present_method default value.
46const PRESENT_METHOD_DEFAULT = 0
47
48// PRESENT_METHOD_CENTER is the present_method center value.
49const PRESENT_METHOD_CENTER = 1
50
51// PRESENT_METHOD_ZOOM is the present_method zoom value.
52const PRESENT_METHOD_ZOOM = 2
53
54// PRESENT_METHOD_ZOOM_CROP is the present_method zoom_crop value.
55const PRESENT_METHOD_ZOOM_CROP = 3
56
57// PRESENT_METHOD_STRETCH is the present_method stretch value.
58const PRESENT_METHOD_STRETCH = 4
59
60// ERROR_INVALID_METHOD is the error invalid_method value.
61const ERROR_INVALID_METHOD = 0
62
63// ERROR_ROLE is the error role value.
64const ERROR_ROLE = 1
65
66// FullscreenShellInterface is the protocol interface name.
67const FullscreenShellInterface = "zwp_fullscreen_shell_v1"
68
69// FullscreenShell is the generated binding for zwp_fullscreen_shell_v1 version 1.
70type FullscreenShell struct {
71 wl.BaseProxy
72 // handlersMu guards the handler slices: a client may register or replace
73 // handlers while another goroutine dispatches events.
74 handlersMu sync.Mutex
75 onCapability []func(capability uint32)
76}
77
78// NewFullscreenShell returns an unbound FullscreenShell.
79func NewFullscreenShell(ctx *wl.Context) *FullscreenShell {
80 obj := &FullscreenShell{}
81 obj.SetContext(ctx)
82 ctx.Register(obj)
83 return obj
84}
85
86// Release the binding from the wl_fullscreen_shell interface. This destroys the server-side object and frees this binding. If the client binds to wl_fullscreen_shell multiple times, it may wish to free some of those bindings.
87func (o *FullscreenShell) Release() error {
88 if err := o.Context().RequestArgs(wl.Request{Proxy: o, Opcode: 0, Name: "zwp_fullscreen_shell_v1.release", Destructor: true}); err != nil {
89 return err
90 }
91 return nil
92}
93
94// Present a surface on the given output. If the output is null, the compositor will present the surface on whatever display (or displays) it thinks best. In particular, this may replace any or all surfaces currently presented so it should not be used in combination with placing surfaces on specific outputs. The method parameter is a hint to the compositor for how the surface is to be presented. In particular, it tells the compositor how to handle a size mismatch between the presented surface and the output. The compositor is free to ignore this parameter. The "zoom", "zoom_crop", and "stretch" methods imply a scaling operation on the surface. This will override any kind of output scaling, so the buffer_scale property of the surface is effectively ignored. This request gives the surface the role of a fullscreen shell surface. If the surface already has another role, it raises a role protocol error.
95func (o *FullscreenShell) PresentSurface(surface *cross_wl_surface.Surface, method uint32, output *cross_wl_output.Output) error {
96 var arg0 wl.Object
97 if surface != nil {
98 arg0 = surface
99 }
100 var arg2 wl.Object
101 if output != nil {
102 arg2 = output
103 }
104 if err := o.Context().RequestArgs(wl.Request{Proxy: o, Opcode: 1, Name: "zwp_fullscreen_shell_v1.present_surface"}, wl.ArgObject(arg0), wl.ArgUint(method), wl.ArgObject(arg2)); err != nil {
105 return err
106 }
107 return nil
108}
109
110// Presents a surface on the given output for a particular mode. If the current size of the output differs from that of the surface, the compositor will attempt to change the size of the output to match the surface. The result of the mode-switch operation will be returned via the provided wl_fullscreen_shell_mode_feedback object. If the current output mode matches the one requested or if the compositor successfully switches the mode to match the surface, then the mode_successful event will be sent and the output will contain the contents of the given surface. If the compositor cannot match the output size to the surface size, the mode_failed will be sent and the output will contain the contents of the previously presented surface (if any). If another surface is presented on the given output before either of these has a chance to happen, the present_cancelled event will be sent. Due to race conditions and other issues unknown to the client, no mode-switch operation is guaranteed to succeed. However, if the mode is one advertised by wl_output.mode or if the compositor advertises the ARBITRARY_MODES capability, then the client should expect that the mode-switch operation will usually succeed. If the size of the presented surface changes, the resulting output is undefined. The compositor may attempt to change the output mode to compensate. However, there is no guarantee that a suitable mode will be found and the client has no way to be notified of success or failure. The framerate parameter specifies the desired framerate for the output in mHz. The compositor is free to ignore this parameter. A value of 0 indicates that the client has no preference. If the value of wl_output.scale differs from wl_surface.buffer_scale, then the compositor may choose a mode that matches either the buffer size or the surface size. In either case, the surface will fill the output. This request gives the surface the role of a fullscreen shell surface. If the surface already has another role, it raises a role protocol error.
111func (o *FullscreenShell) PresentSurfaceForMode(surface *cross_wl_surface.Surface, output *cross_wl_output.Output, framerate int32) (*FullscreenShellModeFeedback, error) {
112 var arg0 wl.Object
113 if surface != nil {
114 arg0 = surface
115 }
116 var arg1 wl.Object
117 if output != nil {
118 arg1 = output
119 }
120 child := &FullscreenShellModeFeedback{}
121 child.SetContext(o.Context())
122 if err := o.Context().RequestArgs(wl.Request{Proxy: o, Opcode: 2, Name: "zwp_fullscreen_shell_v1.present_surface_for_mode", Child: child}, wl.ArgObject(arg0), wl.ArgObject(arg1), wl.ArgInt(framerate), wl.ArgObject(child)); err != nil {
123 return nil, err
124 }
125 return child, nil
126}
127
128// OnCapability registers a handler for the capability event.
129//
130// Handlers are appended, so a second call adds another handler rather than
131// replacing the first. Registration is safe while another goroutine dispatches.
132func (o *FullscreenShell) OnCapability(handler func(capability uint32)) {
133 if handler == nil {
134 return
135 }
136 o.handlersMu.Lock()
137 defer o.handlersMu.Unlock()
138 o.onCapability = append(o.onCapability, handler)
139}
140
141// handlersForCapability returns the handlers registered for capability, taken
142// under the lock so a handler may register another handler while events are
143// being dispatched.
144func (o *FullscreenShell) handlersForCapability() []func(capability uint32) {
145 o.handlersMu.Lock()
146 defer o.handlersMu.Unlock()
147 return o.onCapability
148}
149
150// EventSignature returns the declared event argument types in wire order.
151func (o *FullscreenShell) EventSignature(opcode uint16) (string, bool) {
152 switch opcode {
153 case 0:
154 return "uint,", true
155 default:
156 return "", false
157 }
158}
159
160// Dispatch decodes one event on zwp_fullscreen_shell_v1 and calls the registered handlers.
161func (o *FullscreenShell) Dispatch(event *wl.Event) {
162 switch event.Opcode {
163 case 0: // capability
164 capability := event.Uint32()
165
166 for i, handler := range o.handlersForCapability() {
167 _ = i
168 handler(capability)
169 }
170 default:
171 }
172}
173
174// FullscreenShellModeFeedbackInterface is the protocol interface name.
175const FullscreenShellModeFeedbackInterface = "zwp_fullscreen_shell_mode_feedback_v1"
176
177// FullscreenShellModeFeedback is the generated binding for zwp_fullscreen_shell_mode_feedback_v1 version 1.
178type FullscreenShellModeFeedback struct {
179 wl.BaseProxy
180 // handlersMu guards the handler slices: a client may register or replace
181 // handlers while another goroutine dispatches events.
182 handlersMu sync.Mutex
183 onModeSuccessful []func()
184 onModeFailed []func()
185 onPresentCancelled []func()
186}
187
188// NewFullscreenShellModeFeedback returns an unbound FullscreenShellModeFeedback.
189func NewFullscreenShellModeFeedback(ctx *wl.Context) *FullscreenShellModeFeedback {
190 obj := &FullscreenShellModeFeedback{}
191 obj.SetContext(ctx)
192 ctx.Register(obj)
193 return obj
194}
195
196// OnModeSuccessful registers a handler for the mode_successful event.
197//
198// Handlers are appended, so a second call adds another handler rather than
199// replacing the first. Registration is safe while another goroutine dispatches.
200func (o *FullscreenShellModeFeedback) OnModeSuccessful(handler func()) {
201 if handler == nil {
202 return
203 }
204 o.handlersMu.Lock()
205 defer o.handlersMu.Unlock()
206 o.onModeSuccessful = append(o.onModeSuccessful, handler)
207}
208
209// handlersForModeSuccessful returns the handlers registered for mode_successful, taken
210// under the lock so a handler may register another handler while events are
211// being dispatched.
212func (o *FullscreenShellModeFeedback) handlersForModeSuccessful() []func() {
213 o.handlersMu.Lock()
214 defer o.handlersMu.Unlock()
215 return o.onModeSuccessful
216}
217
218// OnModeFailed registers a handler for the mode_failed event.
219//
220// Handlers are appended, so a second call adds another handler rather than
221// replacing the first. Registration is safe while another goroutine dispatches.
222func (o *FullscreenShellModeFeedback) OnModeFailed(handler func()) {
223 if handler == nil {
224 return
225 }
226 o.handlersMu.Lock()
227 defer o.handlersMu.Unlock()
228 o.onModeFailed = append(o.onModeFailed, handler)
229}
230
231// handlersForModeFailed returns the handlers registered for mode_failed, taken
232// under the lock so a handler may register another handler while events are
233// being dispatched.
234func (o *FullscreenShellModeFeedback) handlersForModeFailed() []func() {
235 o.handlersMu.Lock()
236 defer o.handlersMu.Unlock()
237 return o.onModeFailed
238}
239
240// OnPresentCancelled registers a handler for the present_cancelled event.
241//
242// Handlers are appended, so a second call adds another handler rather than
243// replacing the first. Registration is safe while another goroutine dispatches.
244func (o *FullscreenShellModeFeedback) OnPresentCancelled(handler func()) {
245 if handler == nil {
246 return
247 }
248 o.handlersMu.Lock()
249 defer o.handlersMu.Unlock()
250 o.onPresentCancelled = append(o.onPresentCancelled, handler)
251}
252
253// handlersForPresentCancelled returns the handlers registered for present_cancelled, taken
254// under the lock so a handler may register another handler while events are
255// being dispatched.
256func (o *FullscreenShellModeFeedback) handlersForPresentCancelled() []func() {
257 o.handlersMu.Lock()
258 defer o.handlersMu.Unlock()
259 return o.onPresentCancelled
260}
261
262// EventSignature returns the declared event argument types in wire order.
263func (o *FullscreenShellModeFeedback) EventSignature(opcode uint16) (string, bool) {
264 switch opcode {
265 case 0:
266 return "", true
267 case 1:
268 return "", true
269 case 2:
270 return "", true
271 default:
272 return "", false
273 }
274}
275
276// Dispatch decodes one event on zwp_fullscreen_shell_mode_feedback_v1 and calls the registered handlers.
277func (o *FullscreenShellModeFeedback) Dispatch(event *wl.Event) {
278 switch event.Opcode {
279 case 0: // mode_successful
280
281 for i, handler := range o.handlersForModeSuccessful() {
282 _ = i
283 handler()
284 }
285 o.Context().Unregister(o)
286 case 1: // mode_failed
287
288 for i, handler := range o.handlersForModeFailed() {
289 _ = i
290 handler()
291 }
292 o.Context().Unregister(o)
293 case 2: // present_cancelled
294
295 for i, handler := range o.handlersForPresentCancelled() {
296 _ = i
297 handler()
298 }
299 o.Context().Unregister(o)
300 default:
301 }
302}