1// Code generated by wlbgen. DO NOT EDIT.
2// Protocol: xdg_foreign_unstable_v2
3// Source: xdg-foreign-unstable-v2.xml
4
5// Upstream protocol copyright and license:
6// Copyright © 2015-2016 Red Hat Inc.
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 xdgforeign
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// ZXDG_EXPORTER_V2_ERROR_INVALID_SURFACE is the error invalid_surface value.
37const ZXDG_EXPORTER_V2_ERROR_INVALID_SURFACE = 0
38
39// ZXDG_IMPORTED_V2_ERROR_INVALID_SURFACE is the error invalid_surface value.
40const ZXDG_IMPORTED_V2_ERROR_INVALID_SURFACE = 0
41
42// ZxdgExporterInterface is the protocol interface name.
43const ZxdgExporterInterface = "zxdg_exporter_v2"
44
45// ZxdgExporter is the generated binding for zxdg_exporter_v2 version 1.
46type ZxdgExporter struct {
47 wl.BaseProxy
48}
49
50// NewZxdgExporter returns an unbound ZxdgExporter.
51func NewZxdgExporter(ctx *wl.Context) *ZxdgExporter {
52 obj := &ZxdgExporter{}
53 obj.SetContext(ctx)
54 ctx.Register(obj)
55 return obj
56}
57
58// Notify the compositor that the xdg_exporter object will no longer be used.
59func (o *ZxdgExporter) Destroy() error {
60 if err := o.Context().RequestArgs(wl.Request{Proxy: o, Opcode: 0, Name: "zxdg_exporter_v2.destroy", Destructor: true}); err != nil {
61 return err
62 }
63 return nil
64}
65
66// The export_toplevel request exports the passed surface so that it can later be imported via xdg_importer. When called, a new xdg_exported object will be created and xdg_exported.handle will be sent immediately. See the corresponding interface and event for details. A surface may be exported multiple times, and each exported handle may be used to create an xdg_imported multiple times. Only xdg_toplevel equivalent surfaces may be exported, otherwise an invalid_surface protocol error is sent.
67func (o *ZxdgExporter) ExportToplevel(surface *cross_wl_surface.Surface) (*ZxdgExported, error) {
68 var arg1 wl.Object
69 if surface != nil {
70 arg1 = surface
71 }
72 child := &ZxdgExported{}
73 child.SetContext(o.Context())
74 if err := o.Context().RequestArgs(wl.Request{Proxy: o, Opcode: 1, Name: "zxdg_exporter_v2.export_toplevel", Child: child}, wl.ArgObject(child), wl.ArgObject(arg1)); err != nil {
75 return nil, err
76 }
77 return child, nil
78}
79
80// EventSignature returns the declared event argument types in wire order.
81func (o *ZxdgExporter) EventSignature(opcode uint16) (string, bool) {
82 switch opcode {
83 default:
84 return "", false
85 }
86}
87
88// Dispatch decodes one event on zxdg_exporter_v2 and calls the registered handlers.
89func (o *ZxdgExporter) Dispatch(event *wl.Event) {
90 switch event.Opcode {
91 default:
92 }
93}
94
95// ZxdgImporterInterface is the protocol interface name.
96const ZxdgImporterInterface = "zxdg_importer_v2"
97
98// ZxdgImporter is the generated binding for zxdg_importer_v2 version 1.
99type ZxdgImporter struct {
100 wl.BaseProxy
101}
102
103// NewZxdgImporter returns an unbound ZxdgImporter.
104func NewZxdgImporter(ctx *wl.Context) *ZxdgImporter {
105 obj := &ZxdgImporter{}
106 obj.SetContext(ctx)
107 ctx.Register(obj)
108 return obj
109}
110
111// Notify the compositor that the xdg_importer object will no longer be used.
112func (o *ZxdgImporter) Destroy() error {
113 if err := o.Context().RequestArgs(wl.Request{Proxy: o, Opcode: 0, Name: "zxdg_importer_v2.destroy", Destructor: true}); err != nil {
114 return err
115 }
116 return nil
117}
118
119// The import_toplevel request imports a surface from any client given a handle retrieved by exporting said surface using xdg_exporter.export_toplevel. When called, a new xdg_imported object will be created. This new object represents the imported surface, and the importing client can manipulate its relationship using it. See xdg_imported for details.
120func (o *ZxdgImporter) ImportToplevel(handle string) (*ZxdgImported, error) {
121 child := &ZxdgImported{}
122 child.SetContext(o.Context())
123 if err := o.Context().RequestArgs(wl.Request{Proxy: o, Opcode: 1, Name: "zxdg_importer_v2.import_toplevel", Child: child}, wl.ArgObject(child), wl.ArgString(handle)); err != nil {
124 return nil, err
125 }
126 return child, nil
127}
128
129// EventSignature returns the declared event argument types in wire order.
130func (o *ZxdgImporter) EventSignature(opcode uint16) (string, bool) {
131 switch opcode {
132 default:
133 return "", false
134 }
135}
136
137// Dispatch decodes one event on zxdg_importer_v2 and calls the registered handlers.
138func (o *ZxdgImporter) Dispatch(event *wl.Event) {
139 switch event.Opcode {
140 default:
141 }
142}
143
144// ZxdgExportedInterface is the protocol interface name.
145const ZxdgExportedInterface = "zxdg_exported_v2"
146
147// ZxdgExported is the generated binding for zxdg_exported_v2 version 1.
148type ZxdgExported struct {
149 wl.BaseProxy
150 // handlersMu guards the handler slices: a client may register or replace
151 // handlers while another goroutine dispatches events.
152 handlersMu sync.Mutex
153 onHandle []func(handle string)
154}
155
156// NewZxdgExported returns an unbound ZxdgExported.
157func NewZxdgExported(ctx *wl.Context) *ZxdgExported {
158 obj := &ZxdgExported{}
159 obj.SetContext(ctx)
160 ctx.Register(obj)
161 return obj
162}
163
164// Revoke the previously exported surface. This invalidates any relationship the importer may have set up using the xdg_imported created given the handle sent via xdg_exported.handle.
165func (o *ZxdgExported) Destroy() error {
166 if err := o.Context().RequestArgs(wl.Request{Proxy: o, Opcode: 0, Name: "zxdg_exported_v2.destroy", Destructor: true}); err != nil {
167 return err
168 }
169 return nil
170}
171
172// OnHandle registers a handler for the handle event.
173//
174// Handlers are appended, so a second call adds another handler rather than
175// replacing the first. Registration is safe while another goroutine dispatches.
176func (o *ZxdgExported) OnHandle(handler func(handle string)) {
177 if handler == nil {
178 return
179 }
180 o.handlersMu.Lock()
181 defer o.handlersMu.Unlock()
182 o.onHandle = append(o.onHandle, handler)
183}
184
185// handlersForHandle returns the handlers registered for handle, taken
186// under the lock so a handler may register another handler while events are
187// being dispatched.
188func (o *ZxdgExported) handlersForHandle() []func(handle string) {
189 o.handlersMu.Lock()
190 defer o.handlersMu.Unlock()
191 return o.onHandle
192}
193
194// EventSignature returns the declared event argument types in wire order.
195func (o *ZxdgExported) EventSignature(opcode uint16) (string, bool) {
196 switch opcode {
197 case 0:
198 return "string,", true
199 default:
200 return "", false
201 }
202}
203
204// Dispatch decodes one event on zxdg_exported_v2 and calls the registered handlers.
205func (o *ZxdgExported) Dispatch(event *wl.Event) {
206 switch event.Opcode {
207 case 0: // handle
208 handle := event.String()
209
210 for i, handler := range o.handlersForHandle() {
211 _ = i
212 handler(handle)
213 }
214 default:
215 }
216}
217
218// ZxdgImportedInterface is the protocol interface name.
219const ZxdgImportedInterface = "zxdg_imported_v2"
220
221// ZxdgImported is the generated binding for zxdg_imported_v2 version 1.
222type ZxdgImported struct {
223 wl.BaseProxy
224 // handlersMu guards the handler slices: a client may register or replace
225 // handlers while another goroutine dispatches events.
226 handlersMu sync.Mutex
227 onDestroyed []func()
228}
229
230// NewZxdgImported returns an unbound ZxdgImported.
231func NewZxdgImported(ctx *wl.Context) *ZxdgImported {
232 obj := &ZxdgImported{}
233 obj.SetContext(ctx)
234 ctx.Register(obj)
235 return obj
236}
237
238// Notify the compositor that it will no longer use the xdg_imported object. Any relationship that may have been set up will at this point be invalidated.
239func (o *ZxdgImported) Destroy() error {
240 if err := o.Context().RequestArgs(wl.Request{Proxy: o, Opcode: 0, Name: "zxdg_imported_v2.destroy", Destructor: true}); err != nil {
241 return err
242 }
243 return nil
244}
245
246// Set the imported surface as the parent of some surface of the client. The passed surface must be an xdg_toplevel equivalent, otherwise an invalid_surface protocol error is sent. Calling this function sets up a surface to surface relation with the same stacking and positioning semantics as xdg_toplevel.set_parent.
247func (o *ZxdgImported) SetParentOf(surface *cross_wl_surface.Surface) error {
248 var arg0 wl.Object
249 if surface != nil {
250 arg0 = surface
251 }
252 if err := o.Context().RequestArgs(wl.Request{Proxy: o, Opcode: 1, Name: "zxdg_imported_v2.set_parent_of"}, wl.ArgObject(arg0)); err != nil {
253 return err
254 }
255 return nil
256}
257
258// OnDestroyed registers a handler for the destroyed event.
259//
260// Handlers are appended, so a second call adds another handler rather than
261// replacing the first. Registration is safe while another goroutine dispatches.
262func (o *ZxdgImported) OnDestroyed(handler func()) {
263 if handler == nil {
264 return
265 }
266 o.handlersMu.Lock()
267 defer o.handlersMu.Unlock()
268 o.onDestroyed = append(o.onDestroyed, handler)
269}
270
271// handlersForDestroyed returns the handlers registered for destroyed, taken
272// under the lock so a handler may register another handler while events are
273// being dispatched.
274func (o *ZxdgImported) handlersForDestroyed() []func() {
275 o.handlersMu.Lock()
276 defer o.handlersMu.Unlock()
277 return o.onDestroyed
278}
279
280// EventSignature returns the declared event argument types in wire order.
281func (o *ZxdgImported) EventSignature(opcode uint16) (string, bool) {
282 switch opcode {
283 case 0:
284 return "", true
285 default:
286 return "", false
287 }
288}
289
290// Dispatch decodes one event on zxdg_imported_v2 and calls the registered handlers.
291func (o *ZxdgImported) Dispatch(event *wl.Event) {
292 switch event.Opcode {
293 case 0: // destroyed
294
295 for i, handler := range o.handlersForDestroyed() {
296 _ = i
297 handler()
298 }
299 default:
300 }
301}